pi-herdsman 0.42.0 → 0.43.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 +48 -12
- package/README.md +3 -0
- package/SKILL.md +11 -11
- package/dist/agents/generalist.md +2 -2
- package/dist/agents/implementer.md +2 -2
- package/dist/agents/researcher.md +1 -0
- package/dist/agents/reviewer.md +2 -2
- package/dist/agents/scout.md +2 -2
- package/dist/agents/validator.md +2 -2
- package/dist/coordinators/chief.md +1 -1
- package/dist/coordinators/managed-lead.md +2 -1
- package/dist/coordinators/manager.md +5 -5
- package/dist/coordinators/orchestrator-lead.md +1 -1
- package/dist/index.js +1555 -439
- package/dist/index.js.map +3 -3
- package/dist/peer-bridge.js +16 -1
- package/dist/peer-bridge.js.map +2 -2
- package/docs/concepts/coordination.md +3 -2
- package/docs/concepts/lifecycle.md +4 -3
- package/docs/coordination-api.md +41 -0
- package/docs/development/smoke-testing.md +19 -12
- package/docs/guides/agent-definitions.md +12 -4
- package/docs/guides/handoffs.md +10 -5
- package/docs/guides/project-orchestration.md +17 -6
- package/docs/reference/agent-definition-schema.md +29 -11
- package/docs/reference/agent-states.md +13 -8
- package/docs/reference/agent.md +2 -0
- package/docs/reference/ask-owner.md +7 -4
- package/docs/reference/configuration.md +10 -8
- package/docs/reference/staff.md +7 -6
- package/docs/reference/status-widget.md +53 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1075,6 +1075,39 @@ function observeMailbox(directory2, relevant, reconcile, onError) {
|
|
|
1075
1075
|
watcher = void 0;
|
|
1076
1076
|
};
|
|
1077
1077
|
}
|
|
1078
|
+
function observeNewAgentStates(onNew, onError) {
|
|
1079
|
+
let known = /* @__PURE__ */ new Set();
|
|
1080
|
+
const scan = () => {
|
|
1081
|
+
const present = /* @__PURE__ */ new Set();
|
|
1082
|
+
let names2 = [];
|
|
1083
|
+
try {
|
|
1084
|
+
names2 = readdirSync3(root);
|
|
1085
|
+
} catch (error2) {
|
|
1086
|
+
if (error2.code !== "ENOENT") throw error2;
|
|
1087
|
+
}
|
|
1088
|
+
for (const name of names2)
|
|
1089
|
+
if (MAILBOX_DIRECTORY.test(name) && existsSync(file(join3(root, name), "state.json")))
|
|
1090
|
+
present.add(name);
|
|
1091
|
+
return present;
|
|
1092
|
+
};
|
|
1093
|
+
try {
|
|
1094
|
+
known = scan();
|
|
1095
|
+
} catch (error2) {
|
|
1096
|
+
onError(error2);
|
|
1097
|
+
}
|
|
1098
|
+
return observeMailbox(
|
|
1099
|
+
root,
|
|
1100
|
+
(name) => MAILBOX_DIRECTORY.test(name),
|
|
1101
|
+
() => {
|
|
1102
|
+
const previous = known;
|
|
1103
|
+
known = scan();
|
|
1104
|
+
if ([...known].some((name) => !previous.has(name))) onNew();
|
|
1105
|
+
},
|
|
1106
|
+
(error2) => {
|
|
1107
|
+
if (error2?.code !== "ENOENT") onError(error2);
|
|
1108
|
+
}
|
|
1109
|
+
);
|
|
1110
|
+
}
|
|
1078
1111
|
function agentMailboxPath(workspaceId, agentLabel) {
|
|
1079
1112
|
return join3(
|
|
1080
1113
|
root,
|
|
@@ -2047,6 +2080,7 @@ function prepareMessageInput(text, files, cwd, operation, heading, options = {})
|
|
|
2047
2080
|
${text}`, ...sections] : [...sections, `${heading}:
|
|
2048
2081
|
${text}`]).join("\n\n");
|
|
2049
2082
|
const fits = options.fits ?? ((value2, bindings) => (options.serializedBytes ? options.serializedBytes(value2, bindings) : Buffer.byteLength(value2, "utf8")) <= (options.mailboxLimitBytes ?? MAILBOX_PROTOCOL_LIMIT_BYTES));
|
|
2083
|
+
const capacityMessage = (file2) => file2.bytes > (options.inlineLimitBytes ?? MAILBOX_PROTOCOL_LIMIT_BYTES) ? `Attachment is ${file2.bytes} bytes; per-file inline limit is ${options.inlineLimitBytes ?? MAILBOX_PROTOCOL_LIMIT_BYTES} bytes: ${file2.input}` : `Attachment could not fit within the configured message limit: ${file2.input}`;
|
|
2050
2084
|
if (!fits(rendered(), resultBindings))
|
|
2051
2085
|
fail(
|
|
2052
2086
|
"invalid_request",
|
|
@@ -2087,7 +2121,7 @@ ${text}`]).join("\n\n");
|
|
|
2087
2121
|
if (options.requireInline)
|
|
2088
2122
|
fail(
|
|
2089
2123
|
"invalid_request",
|
|
2090
|
-
`Attachment
|
|
2124
|
+
`Attachment changed between validation and reading: ${file2.input}`,
|
|
2091
2125
|
operation
|
|
2092
2126
|
);
|
|
2093
2127
|
continue;
|
|
@@ -2110,12 +2144,9 @@ ${text}`
|
|
|
2110
2144
|
);
|
|
2111
2145
|
if (cannotInline && !verified) {
|
|
2112
2146
|
if (options.requireInline)
|
|
2113
|
-
fail(
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
operation,
|
|
2117
|
-
{ details: { capacity: true } }
|
|
2118
|
-
);
|
|
2147
|
+
fail("invalid_request", capacityMessage(file2), operation, {
|
|
2148
|
+
details: { capacity: true }
|
|
2149
|
+
});
|
|
2119
2150
|
continue;
|
|
2120
2151
|
}
|
|
2121
2152
|
bytes = Buffer.allocUnsafe(current.size);
|
|
@@ -2150,12 +2181,9 @@ ${text}`
|
|
|
2150
2181
|
);
|
|
2151
2182
|
if (cannotInline) {
|
|
2152
2183
|
if (options.requireInline)
|
|
2153
|
-
fail(
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
operation,
|
|
2157
|
-
{ details: { capacity: true } }
|
|
2158
|
-
);
|
|
2184
|
+
fail("invalid_request", capacityMessage(file2), operation, {
|
|
2185
|
+
details: { capacity: true }
|
|
2186
|
+
});
|
|
2159
2187
|
continue;
|
|
2160
2188
|
}
|
|
2161
2189
|
} catch (error2) {
|
|
@@ -2201,11 +2229,12 @@ ${text}`
|
|
|
2201
2229
|
transportSections[index] = renderMessageFile(file2, markers[index]);
|
|
2202
2230
|
attachmentTexts[index] = content;
|
|
2203
2231
|
if (!fits(rendered(), resultBindings)) {
|
|
2232
|
+
const actualBytes = options.fits ? void 0 : options.serializedBytes ? options.serializedBytes(rendered(), resultBindings) : Buffer.byteLength(rendered(), "utf8");
|
|
2204
2233
|
sections[index] = prior;
|
|
2205
2234
|
if (options.requireInline)
|
|
2206
2235
|
fail(
|
|
2207
2236
|
"invalid_request",
|
|
2208
|
-
`Attachment could not
|
|
2237
|
+
actualBytes === void 0 ? `Attachment could not fit within the configured message limit: ${file2.input}` : `Mailbox payload is ${actualBytes} bytes; configured limit is ${options.mailboxLimitBytes ?? MAILBOX_PROTOCOL_LIMIT_BYTES} bytes while embedding ${file2.input}`,
|
|
2209
2238
|
operation,
|
|
2210
2239
|
{ details: { capacity: true } }
|
|
2211
2240
|
);
|
|
@@ -2292,7 +2321,7 @@ import {
|
|
|
2292
2321
|
import { execFileSync } from "node:child_process";
|
|
2293
2322
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
2294
2323
|
import { homedir as homedir2 } from "node:os";
|
|
2295
|
-
import { dirname as dirname4, isAbsolute, join as join4, resolve as resolve2, sep } from "node:path";
|
|
2324
|
+
import { dirname as dirname4, isAbsolute, join as join4, relative, resolve as resolve2, sep } from "node:path";
|
|
2296
2325
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
2297
2326
|
import {
|
|
2298
2327
|
CONFIG_DIR_NAME,
|
|
@@ -2313,8 +2342,8 @@ function markdownFiles(root2) {
|
|
|
2313
2342
|
return (entry.isFile() || entry.isSymbolicLink()) && entry.name.endsWith(".md") ? [path] : [];
|
|
2314
2343
|
});
|
|
2315
2344
|
}
|
|
2316
|
-
function readAgentDefinitions(root2) {
|
|
2317
|
-
const definitions = markdownFiles(root2).filter((path) => !path.endsWith(".example.md")).sort().
|
|
2345
|
+
function readAgentDefinitions(root2, category, onWarning) {
|
|
2346
|
+
const definitions = markdownFiles(root2).filter((path) => !path.endsWith(".example.md")).sort().flatMap((path) => {
|
|
2318
2347
|
const content = readFileSync5(path, "utf8").replace(/^\uFEFF/u, "");
|
|
2319
2348
|
let parsed;
|
|
2320
2349
|
try {
|
|
@@ -2325,6 +2354,18 @@ function readAgentDefinitions(root2) {
|
|
|
2325
2354
|
}
|
|
2326
2355
|
if (!isPlainObject(parsed.frontmatter))
|
|
2327
2356
|
throw new Error(`${path}: frontmatter must be a YAML mapping`);
|
|
2357
|
+
const name = parsed.frontmatter.name;
|
|
2358
|
+
if (category && typeof name === "string" && name.length > 0 && isReservedRoleDefinition(name) !== (category === "role")) {
|
|
2359
|
+
const destination = join4(
|
|
2360
|
+
dirname4(root2),
|
|
2361
|
+
category === "agent" ? "coordinators" : "agents",
|
|
2362
|
+
relative(root2, path)
|
|
2363
|
+
);
|
|
2364
|
+
onWarning?.(
|
|
2365
|
+
`${path}: definition belongs in ${destination}; file excluded from discovery`
|
|
2366
|
+
);
|
|
2367
|
+
return [];
|
|
2368
|
+
}
|
|
2328
2369
|
const frontmatter = parsed.frontmatter;
|
|
2329
2370
|
const definition = {
|
|
2330
2371
|
name: typeof frontmatter.name === "string" ? frontmatter.name : "",
|
|
@@ -2333,7 +2374,7 @@ function readAgentDefinitions(root2) {
|
|
|
2333
2374
|
body: resolveBodyFileReferences(parsed.body, path)
|
|
2334
2375
|
};
|
|
2335
2376
|
validateDefinition(definition, { allowBodyMode: true });
|
|
2336
|
-
return definition;
|
|
2377
|
+
return [definition];
|
|
2337
2378
|
});
|
|
2338
2379
|
const pathsByName = /* @__PURE__ */ new Map();
|
|
2339
2380
|
for (const definition of definitions)
|
|
@@ -2449,12 +2490,12 @@ function configuredToolPolicy(definition, requiredTools) {
|
|
|
2449
2490
|
excluded
|
|
2450
2491
|
};
|
|
2451
2492
|
}
|
|
2452
|
-
function readOptionalAgentDefinitions(root2) {
|
|
2493
|
+
function readOptionalAgentDefinitions(root2, category, onWarning) {
|
|
2453
2494
|
const stats = statSync3(root2, { throwIfNoEntry: false });
|
|
2454
2495
|
if (!stats) return [];
|
|
2455
2496
|
if (!stats.isDirectory())
|
|
2456
2497
|
throw new Error(`agent directory is not a directory: ${root2}`);
|
|
2457
|
-
return readAgentDefinitions(root2);
|
|
2498
|
+
return readAgentDefinitions(root2, category, onWarning);
|
|
2458
2499
|
}
|
|
2459
2500
|
function assertNoLegacyCoordinatorProfiles(legacy, canonical) {
|
|
2460
2501
|
const stats = statSync3(legacy, { throwIfNoEntry: false });
|
|
@@ -2587,6 +2628,11 @@ function discoverEffectiveDefinitions(options = {}, category = "agent", validate
|
|
|
2587
2628
|
const bundled = readAgentDefinitions(
|
|
2588
2629
|
role2 ? BUILTIN_ROLE_DIR : BUILTIN_AGENT_DIR
|
|
2589
2630
|
);
|
|
2631
|
+
for (const definition of bundled)
|
|
2632
|
+
if (isReservedRoleDefinition(definition.name) !== role2)
|
|
2633
|
+
throw new Error(
|
|
2634
|
+
`${definition.path}: ${role2 ? "non-coordinator name in coordinators directory" : "reserved coordinator name in agents directory; use coordinators"}`
|
|
2635
|
+
);
|
|
2590
2636
|
const directory2 = role2 ? "coordinators" : "agents";
|
|
2591
2637
|
const privateRoot = options.projectRoot ? privateRepositoryRoot(options.projectRoot) : void 0;
|
|
2592
2638
|
if (role2) {
|
|
@@ -2607,21 +2653,20 @@ function discoverEffectiveDefinitions(options = {}, category = "agent", validate
|
|
|
2607
2653
|
);
|
|
2608
2654
|
}
|
|
2609
2655
|
const project = options.projectRoot ? readOptionalAgentDefinitions(
|
|
2610
|
-
join4(options.projectRoot, CONFIG_DIR_NAME, directory2)
|
|
2656
|
+
join4(options.projectRoot, CONFIG_DIR_NAME, directory2),
|
|
2657
|
+
category,
|
|
2658
|
+
options.onWarning
|
|
2611
2659
|
) : [];
|
|
2612
|
-
const privateRepository = privateRoot ? readOptionalAgentDefinitions(
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
`${definition.path}: ${role2 ? "non-coordinator name in coordinators directory" : "reserved coordinator name in agents directory; use coordinators"}`
|
|
2623
|
-
);
|
|
2624
|
-
}
|
|
2660
|
+
const privateRepository = privateRoot ? readOptionalAgentDefinitions(
|
|
2661
|
+
join4(privateRoot, directory2),
|
|
2662
|
+
category,
|
|
2663
|
+
options.onWarning
|
|
2664
|
+
) : [];
|
|
2665
|
+
const user = readOptionalAgentDefinitions(
|
|
2666
|
+
join4(getAgentDir(), directory2),
|
|
2667
|
+
category,
|
|
2668
|
+
options.onWarning
|
|
2669
|
+
);
|
|
2625
2670
|
const definitions = new Map(
|
|
2626
2671
|
bundled.map((definition) => [definition.name, definition])
|
|
2627
2672
|
);
|
|
@@ -2681,9 +2726,26 @@ function withDefaultEnabled(definition) {
|
|
|
2681
2726
|
}
|
|
2682
2727
|
};
|
|
2683
2728
|
}
|
|
2684
|
-
|
|
2729
|
+
function notifyDefinitionWarning(ctx, message) {
|
|
2730
|
+
const manager = ctx.sessionManager;
|
|
2731
|
+
const sessionId = manager.getSessionId();
|
|
2732
|
+
let state = definitionWarningSessions.get(manager);
|
|
2733
|
+
if (!state || state.sessionId !== sessionId) {
|
|
2734
|
+
state = { sessionId, messages: /* @__PURE__ */ new Set() };
|
|
2735
|
+
definitionWarningSessions.set(manager, state);
|
|
2736
|
+
}
|
|
2737
|
+
if (state.messages.has(message)) return;
|
|
2738
|
+
state.messages.add(message);
|
|
2739
|
+
if (ctx.hasUI) ctx.ui.notify(message, "warning");
|
|
2740
|
+
else process.emitWarning(message, { code: "PI_HERDSMAN_DEFINITION" });
|
|
2741
|
+
}
|
|
2742
|
+
async function contextAgentDefinitions(ctx, onWarning) {
|
|
2685
2743
|
const projectTrusted = ctx.isProjectTrusted();
|
|
2686
2744
|
const options = projectTrusted ? { projectRoot: ctx.cwd } : {};
|
|
2745
|
+
options.onWarning = (message) => {
|
|
2746
|
+
notifyDefinitionWarning(ctx, message);
|
|
2747
|
+
onWarning?.(message);
|
|
2748
|
+
};
|
|
2687
2749
|
const effective = discoverAgentDefinitions(options);
|
|
2688
2750
|
return {
|
|
2689
2751
|
projectTrusted,
|
|
@@ -2934,8 +2996,17 @@ function configuredModel(frontmatter) {
|
|
|
2934
2996
|
return typeof frontmatter.model === "string" && frontmatter.model ? frontmatter.model : void 0;
|
|
2935
2997
|
}
|
|
2936
2998
|
function resolveChildModel(input) {
|
|
2937
|
-
if (input.configured !== void 0 && input.configured.trim() !== "")
|
|
2938
|
-
|
|
2999
|
+
if (input.configured !== void 0 && input.configured.trim() !== "") {
|
|
3000
|
+
const model = input.configured;
|
|
3001
|
+
let extensionDiscovery = false;
|
|
3002
|
+
for (let slash = model.lastIndexOf("/"); slash > 0; slash = model.lastIndexOf("/", slash - 1)) {
|
|
3003
|
+
if (input.isForeignProvider(model.slice(0, slash).trim().toLowerCase())) {
|
|
3004
|
+
extensionDiscovery = true;
|
|
3005
|
+
break;
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
return { kind: "use", model, extensionDiscovery };
|
|
3009
|
+
}
|
|
2939
3010
|
if (input.inherited === void 0) {
|
|
2940
3011
|
const saved = input.saved;
|
|
2941
3012
|
return {
|
|
@@ -3117,7 +3188,7 @@ function agentLaunchArgs(agent, options) {
|
|
|
3117
3188
|
args.push("--append-system-prompt", `<active_agent name="${agent.name}"/>`);
|
|
3118
3189
|
return args;
|
|
3119
3190
|
}
|
|
3120
|
-
var VALID_THINKING_LEVELS, THINKING_LEVELS, SYSTEM_PROMPT_MODES, BODY_MODES, STRING_FIELDS, BOOLEAN_CAPABILITY_FIELDS, ARRAY_FIELDS, SUPPORTED_FIELDS, BODY_FILE_REFERENCE, BUILTIN_AGENT_DIR, BUILTIN_ROLE_DIR, FLEXIBLE_LEAD_DEFINITION_NAME, ORCHESTRATOR_LEAD_DEFINITION_NAME, MANAGED_LEAD_DEFINITION_NAME, MANAGER_DEFINITION_NAME, CHIEF_DEFINITION_NAME, RESERVED_ROLE_DEFINITION_NAMES, RESERVED_ROLE_DEFINITION_NAME_SET, RUNTIME_LEAD_FIELDS, AGENT_COORDINATION_TOOLS;
|
|
3191
|
+
var VALID_THINKING_LEVELS, THINKING_LEVELS, SYSTEM_PROMPT_MODES, BODY_MODES, STRING_FIELDS, BOOLEAN_CAPABILITY_FIELDS, ARRAY_FIELDS, SUPPORTED_FIELDS, BODY_FILE_REFERENCE, BUILTIN_AGENT_DIR, BUILTIN_ROLE_DIR, FLEXIBLE_LEAD_DEFINITION_NAME, ORCHESTRATOR_LEAD_DEFINITION_NAME, MANAGED_LEAD_DEFINITION_NAME, MANAGER_DEFINITION_NAME, CHIEF_DEFINITION_NAME, RESERVED_ROLE_DEFINITION_NAMES, RESERVED_ROLE_DEFINITION_NAME_SET, RUNTIME_LEAD_FIELDS, AGENT_COORDINATION_TOOLS, definitionWarningSessions;
|
|
3121
3192
|
var init_agent_definitions = __esm({
|
|
3122
3193
|
"extension/agent-definitions.ts"() {
|
|
3123
3194
|
"use strict";
|
|
@@ -3207,6 +3278,7 @@ var init_agent_definitions = __esm({
|
|
|
3207
3278
|
"inspect_agent",
|
|
3208
3279
|
"read_agent_transcript"
|
|
3209
3280
|
];
|
|
3281
|
+
definitionWarningSessions = /* @__PURE__ */ new WeakMap();
|
|
3210
3282
|
}
|
|
3211
3283
|
});
|
|
3212
3284
|
|
|
@@ -5385,6 +5457,34 @@ function sessionLeadRoleState(entries, sessionId) {
|
|
|
5385
5457
|
}
|
|
5386
5458
|
return state;
|
|
5387
5459
|
}
|
|
5460
|
+
function validSenderEnvironment(value2) {
|
|
5461
|
+
if (!value2 || typeof value2 !== "object" || Array.isArray(value2)) return false;
|
|
5462
|
+
const env = value2;
|
|
5463
|
+
if (Object.keys(env).some((key) => !["cwd", "git"].includes(key)) || typeof env.cwd !== "string" || !env.cwd || !isAbsolute3(env.cwd) || Buffer.byteLength(env.cwd) > 1024)
|
|
5464
|
+
return false;
|
|
5465
|
+
if (env.git === void 0) return true;
|
|
5466
|
+
if (!env.git || typeof env.git !== "object" || Array.isArray(env.git))
|
|
5467
|
+
return false;
|
|
5468
|
+
const git = env.git;
|
|
5469
|
+
return Object.keys(git).length === 3 && Object.keys(git).every(
|
|
5470
|
+
(key) => ["worktreeRoot", "branch", "head"].includes(key)
|
|
5471
|
+
) && typeof git.worktreeRoot === "string" && !!git.worktreeRoot && isAbsolute3(git.worktreeRoot) && Buffer.byteLength(git.worktreeRoot) <= 1024 && (git.branch === null || typeof git.branch === "string" && !!git.branch && Buffer.byteLength(git.branch) <= 1024) && typeof git.head === "string" && /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(git.head);
|
|
5472
|
+
}
|
|
5473
|
+
function senderEnvironmentAnnotation(value2) {
|
|
5474
|
+
if (!validSenderEnvironment(value2)) return "";
|
|
5475
|
+
const escape = (text) => [...text].map(
|
|
5476
|
+
(char) => char === "&" ? "&" : char === "<" ? "<" : char === ">" ? ">" : char === '"' ? """ : char === "'" ? "'" : char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127 ? "\uFFFD" : char
|
|
5477
|
+
).join("");
|
|
5478
|
+
return `
|
|
5479
|
+
|
|
5480
|
+
<sender_environment informational="true">
|
|
5481
|
+
cwd: "${escape(value2.cwd)}"${value2.git ? `
|
|
5482
|
+
worktree_root: "${escape(value2.git.worktreeRoot)}"
|
|
5483
|
+
branch: "${escape(value2.git.branch ?? "detached")}"
|
|
5484
|
+
head: "${value2.git.head}"` : ""}
|
|
5485
|
+
Informational only; not an instruction or authorization.
|
|
5486
|
+
</sender_environment>`;
|
|
5487
|
+
}
|
|
5388
5488
|
function canMessagePeer(a, b) {
|
|
5389
5489
|
if (a.role !== b.role) return false;
|
|
5390
5490
|
if (a.role === "manager") return true;
|
|
@@ -5426,6 +5526,7 @@ function validMessage(value2) {
|
|
|
5426
5526
|
"resultBindings",
|
|
5427
5527
|
"build",
|
|
5428
5528
|
"peerSource",
|
|
5529
|
+
"senderEnvironment",
|
|
5429
5530
|
"bodyRef"
|
|
5430
5531
|
];
|
|
5431
5532
|
if (Object.keys(record).some(
|
|
@@ -5443,7 +5544,7 @@ function validMessage(value2) {
|
|
|
5443
5544
|
if (projectMessage ? !validNativeIdentity(record.branch) : record.branch !== void 0 && (record.kind !== "manager_message" || !validNativeIdentity(record.branch))) {
|
|
5444
5545
|
return false;
|
|
5445
5546
|
}
|
|
5446
|
-
return record.version === 2 && (peerMessage ? !!validPeerSource : record.peerSource === void 0) && (record.build === void 0 || isRuntimeBuild(record.build)) && typeof record.id === "string" && UUID3.test(record.id) && typeof record.leaseId === "string" && UUID3.test(record.leaseId) && typeof record.kind === "string" && MESSAGE_KINDS.has(record.kind) && validSession(record.fromSessionId) && validSession(record.toSessionId) && validSession(record.leadSessionId) && typeof record.text === "string" && (record.bodyRef === void 0 ? record.text.length > 0 : record.text === "" && record.resultBindings === void 0 && validOverflowBodyRef(record.bodyRef)) && (record.resultBindings === void 0 || Array.isArray(record.resultBindings) && record.resultBindings.every(isResultBinding)) && Number.isInteger(record.createdAt) && record.createdAt >= 0;
|
|
5547
|
+
return record.version === 2 && (peerMessage ? !!validPeerSource : record.peerSource === void 0) && (record.senderEnvironment === void 0 || validSenderEnvironment(record.senderEnvironment)) && (record.build === void 0 || isRuntimeBuild(record.build)) && typeof record.id === "string" && UUID3.test(record.id) && typeof record.leaseId === "string" && UUID3.test(record.leaseId) && typeof record.kind === "string" && MESSAGE_KINDS.has(record.kind) && validSession(record.fromSessionId) && validSession(record.toSessionId) && validSession(record.leadSessionId) && typeof record.text === "string" && (record.bodyRef === void 0 ? record.text.length > 0 : record.text === "" && record.resultBindings === void 0 && validOverflowBodyRef(record.bodyRef)) && (record.resultBindings === void 0 || Array.isArray(record.resultBindings) && record.resultBindings.every(isResultBinding)) && Number.isInteger(record.createdAt) && record.createdAt >= 0;
|
|
5447
5548
|
}
|
|
5448
5549
|
function chiefMessageBytes(record) {
|
|
5449
5550
|
return Buffer.byteLength(`${JSON.stringify(record)}
|
|
@@ -5510,6 +5611,7 @@ function coordinationMessageDigest(record) {
|
|
|
5510
5611
|
text: record.text,
|
|
5511
5612
|
resultBindings: record.resultBindings,
|
|
5512
5613
|
peerSource: record.peerSource,
|
|
5614
|
+
...record.senderEnvironment ? { senderEnvironment: record.senderEnvironment } : {},
|
|
5513
5615
|
createdAt: record.createdAt
|
|
5514
5616
|
};
|
|
5515
5617
|
return createHash8("sha256").update(JSON.stringify(canonical(content))).digest("hex");
|
|
@@ -6043,7 +6145,7 @@ function deliveredMessageContent(record, senderTarget) {
|
|
|
6043
6145
|
const content = record.kind === "project_assignment" ? `Project assignment for branch ${record.branch}:
|
|
6044
6146
|
|
|
6045
6147
|
${record.text}` : `${prefix}${record.text}`;
|
|
6046
|
-
return content;
|
|
6148
|
+
return content + senderEnvironmentAnnotation(record.senderEnvironment);
|
|
6047
6149
|
}
|
|
6048
6150
|
async function drainCoordinationInbox(options) {
|
|
6049
6151
|
let delivered = 0;
|
|
@@ -6214,6 +6316,7 @@ async function drainCoordinationInbox(options) {
|
|
|
6214
6316
|
leadSessionId: record.leadSessionId,
|
|
6215
6317
|
...senderTarget ? { senderTarget } : {},
|
|
6216
6318
|
...record.branch ? { branch: record.branch } : {},
|
|
6319
|
+
...record.senderEnvironment ? { senderEnvironment: record.senderEnvironment } : {},
|
|
6217
6320
|
...record.kind === "peer_message" ? { digest: coordinationMessageDigest(record) } : {}
|
|
6218
6321
|
}
|
|
6219
6322
|
},
|
|
@@ -7298,7 +7401,8 @@ function validProjectMessage(value2) {
|
|
|
7298
7401
|
"kind",
|
|
7299
7402
|
"createdAt",
|
|
7300
7403
|
"resultBindings",
|
|
7301
|
-
"bodyRef"
|
|
7404
|
+
"bodyRef",
|
|
7405
|
+
"senderEnvironment"
|
|
7302
7406
|
].includes(key)
|
|
7303
7407
|
) && Object.keys(r).length >= 7 && [
|
|
7304
7408
|
"version",
|
|
@@ -7308,7 +7412,7 @@ function validProjectMessage(value2) {
|
|
|
7308
7412
|
"fromSessionId",
|
|
7309
7413
|
"text",
|
|
7310
7414
|
"createdAt"
|
|
7311
|
-
].every((key) => Object.hasOwn(r, key)) && r.version === 2 && UUID3.test(String(r.id)) && validNativeIdentity(r.repoKey) && validNativeIdentity(r.branch) && validSession(r.fromSessionId) && typeof r.text === "string" && (r.bodyRef === void 0 ? r.text.length > 0 : r.text === "" && r.resultBindings === void 0 && validOverflowBodyRef(r.bodyRef)) && (r.kind === void 0 || [
|
|
7415
|
+
].every((key) => Object.hasOwn(r, key)) && r.version === 2 && (r.senderEnvironment === void 0 || validSenderEnvironment(r.senderEnvironment)) && UUID3.test(String(r.id)) && validNativeIdentity(r.repoKey) && validNativeIdentity(r.branch) && validSession(r.fromSessionId) && typeof r.text === "string" && (r.bodyRef === void 0 ? r.text.length > 0 : r.text === "" && r.resultBindings === void 0 && validOverflowBodyRef(r.bodyRef)) && (r.kind === void 0 || [
|
|
7312
7416
|
"supervisor_message",
|
|
7313
7417
|
"direct_response",
|
|
7314
7418
|
"herd_settlement",
|
|
@@ -7999,7 +8103,7 @@ import {
|
|
|
7999
8103
|
writeFileSync as writeFileSync4
|
|
8000
8104
|
} from "node:fs";
|
|
8001
8105
|
import { homedir as homedir3 } from "node:os";
|
|
8002
|
-
import { basename as basename6, dirname as dirname6, isAbsolute as isAbsolute4, join as join7, relative, sep as sep2 } from "node:path";
|
|
8106
|
+
import { basename as basename6, dirname as dirname6, isAbsolute as isAbsolute4, join as join7, relative as relative2, sep as sep2 } from "node:path";
|
|
8003
8107
|
function populateMenuFrame(container, theme, title, body, footer, help) {
|
|
8004
8108
|
container.clear();
|
|
8005
8109
|
container.addChild(new DynamicBorder((line) => theme.fg("border", line)));
|
|
@@ -8548,23 +8652,76 @@ function supervisionActivityMarker(state, activeAgents) {
|
|
|
8548
8652
|
function supervisionLeadMarker(lead) {
|
|
8549
8653
|
return supervisionActivityMarker(
|
|
8550
8654
|
lead.runtimeState,
|
|
8551
|
-
lead.agentCounts?.active ?? 0
|
|
8655
|
+
(lead.agentCounts?.active ?? 0) + (lead.leadCounts?.active ?? 0)
|
|
8552
8656
|
);
|
|
8553
8657
|
}
|
|
8554
8658
|
function lifecycleColor(state) {
|
|
8555
8659
|
return STATE_COLOR[lifecycleLabel(state)] ?? "muted";
|
|
8556
8660
|
}
|
|
8661
|
+
function headerActivity(local, active) {
|
|
8662
|
+
const marker = supervisionActivityMarker(local, active ? 1 : 0);
|
|
8663
|
+
return {
|
|
8664
|
+
marker,
|
|
8665
|
+
color: marker === "\u25C9" ? "accent" : lifecycleColor(local)
|
|
8666
|
+
};
|
|
8667
|
+
}
|
|
8668
|
+
function activeStaffSnapshot(reports, fresh) {
|
|
8669
|
+
return fresh && presentationReports(reports).some(
|
|
8670
|
+
(report) => report.compatibility !== "incompatible" && (["working", "starting", "settling"].includes(report.runtimeState) || (report.agentCounts?.active ?? 0) > 0 || (report.leadCounts?.active ?? 0) > 0)
|
|
8671
|
+
);
|
|
8672
|
+
}
|
|
8557
8673
|
function supervisionLeadColor(lead) {
|
|
8558
8674
|
return supervisionLeadMarker(lead) === "\u25C9" ? "accent" : lifecycleColor(lead.runtimeState);
|
|
8559
8675
|
}
|
|
8676
|
+
function formatGitChangeStats(git) {
|
|
8677
|
+
return git.additions !== void 0 && git.deletions !== void 0 && git.changedFiles !== void 0 ? git.additions + git.deletions > 0 ? `+${git.additions} -${git.deletions}` : git.changedFiles > 0 ? `${git.changedFiles}f` : "\xB10" : "";
|
|
8678
|
+
}
|
|
8679
|
+
function formatGitHeaderNumeric(git, theme) {
|
|
8680
|
+
const stats = formatGitChangeStats(git);
|
|
8681
|
+
if (!stats) return "";
|
|
8682
|
+
const lineChanges = git.additions !== void 0 && git.deletions !== void 0 && git.additions + git.deletions > 0;
|
|
8683
|
+
return [
|
|
8684
|
+
lineChanges ? themed(
|
|
8685
|
+
theme,
|
|
8686
|
+
git.additions > 0 ? "success" : "muted",
|
|
8687
|
+
`+${git.additions}`
|
|
8688
|
+
) : themed(theme, "muted", stats),
|
|
8689
|
+
lineChanges ? ` ${themed(
|
|
8690
|
+
theme,
|
|
8691
|
+
git.deletions > 0 ? "error" : "muted",
|
|
8692
|
+
`-${git.deletions}`
|
|
8693
|
+
)}` : "",
|
|
8694
|
+
git.dirty ? themed(theme, "warning", "*") : ""
|
|
8695
|
+
].join("");
|
|
8696
|
+
}
|
|
8697
|
+
function formatGitHeaderSuffix(git, theme, width) {
|
|
8698
|
+
const stats = formatGitChangeStats(git);
|
|
8699
|
+
const numeric = stats ? `${stats}${git.dirty ? "*" : ""}` : "";
|
|
8700
|
+
const styledNumeric = formatGitHeaderNumeric(git, theme);
|
|
8701
|
+
const branch = git.checkedOutBranch ? `\u2387 ${git.checkedOutBranch}` : "";
|
|
8702
|
+
if (!branch)
|
|
8703
|
+
return numeric && visibleWidth(numeric) <= width ? styledNumeric : !numeric && git.dirty && width >= 1 ? themed(theme, "warning", "*") : "";
|
|
8704
|
+
const dirtyMarker = !numeric && git.dirty ? "*" : "";
|
|
8705
|
+
const branchWidth = width - (numeric ? visibleWidth(numeric) + 1 : 0) - visibleWidth(dirtyMarker);
|
|
8706
|
+
if (branchWidth < visibleWidth("\u2387 \u2026"))
|
|
8707
|
+
return numeric && visibleWidth(numeric) <= width ? styledNumeric : "";
|
|
8708
|
+
const shownBranch = truncateToWidth(branch, branchWidth, "\u2026");
|
|
8709
|
+
if (visibleWidth(shownBranch) > branchWidth) return "";
|
|
8710
|
+
return `${themed(theme, "muted", shownBranch)}${dirtyMarker ? themed(theme, "warning", dirtyMarker) : ""}${numeric ? ` ${styledNumeric}` : ""}`;
|
|
8711
|
+
}
|
|
8560
8712
|
function identifyingLabelVisible(text, label, width) {
|
|
8561
8713
|
const start = text.lastIndexOf(label);
|
|
8562
8714
|
return label.length > 0 && start >= 0 && visibleWidth(text.slice(0, start + label.length)) <= width;
|
|
8563
8715
|
}
|
|
8564
|
-
function renderSupervisionHeader(label, status, width, theme) {
|
|
8565
|
-
const marker =
|
|
8566
|
-
|
|
8567
|
-
|
|
8716
|
+
function renderSupervisionHeader(role2, label, status, width, theme, local = "unknown", activeDescendants = false) {
|
|
8717
|
+
const { marker: markerValue, color } = headerActivity(
|
|
8718
|
+
local,
|
|
8719
|
+
activeDescendants
|
|
8720
|
+
);
|
|
8721
|
+
const marker = themed(theme, color, markerValue);
|
|
8722
|
+
const markerWidth = visibleWidth(markerValue);
|
|
8723
|
+
const roleText = themed(theme, "text", theme?.bold?.(role2) ?? role2);
|
|
8724
|
+
const identity = `${roleText}${themed(theme, "muted", label.slice(role2.length))}`;
|
|
8568
8725
|
const freshnessText = status === "fresh" ? "" : `\xB7 ${status}`;
|
|
8569
8726
|
const freshness = freshnessText ? themed(theme, "warning", freshnessText) : "";
|
|
8570
8727
|
if (!freshness)
|
|
@@ -8596,7 +8753,15 @@ function renderSupervisionRows(reports, width, options = {}, selectedLead, getGi
|
|
|
8596
8753
|
if (status === "unavailable")
|
|
8597
8754
|
return [
|
|
8598
8755
|
{
|
|
8599
|
-
text: renderSupervisionHeader(
|
|
8756
|
+
text: renderSupervisionHeader(
|
|
8757
|
+
role2,
|
|
8758
|
+
role2,
|
|
8759
|
+
status,
|
|
8760
|
+
width,
|
|
8761
|
+
options.theme,
|
|
8762
|
+
options.localActivity,
|
|
8763
|
+
options.activeDescendants
|
|
8764
|
+
)
|
|
8600
8765
|
}
|
|
8601
8766
|
];
|
|
8602
8767
|
const displays = orderedSupervisionLeads(presentationReports(reports));
|
|
@@ -8617,10 +8782,13 @@ function renderSupervisionRows(reports, width, options = {}, selectedLead, getGi
|
|
|
8617
8782
|
const project = managerSnapshot && "project" in managerSnapshot ? managerSnapshot.project : void 0;
|
|
8618
8783
|
const headerText = role2 === "manager" ? `manager${project ? ` \xB7 ${project}` : ""}` : `chief \xB7 ${supervisionCountLabel(managers, leads)}${incompatible ? ` \xB7 ${incompatible} incompatible` : ""}`;
|
|
8619
8784
|
const header = renderSupervisionHeader(
|
|
8785
|
+
role2,
|
|
8620
8786
|
headerText,
|
|
8621
8787
|
status,
|
|
8622
8788
|
width,
|
|
8623
|
-
options.theme
|
|
8789
|
+
options.theme,
|
|
8790
|
+
options.localActivity,
|
|
8791
|
+
options.activeDescendants
|
|
8624
8792
|
);
|
|
8625
8793
|
if (managerSnapshot && "leads" in managerSnapshot && !("managers" in managerSnapshot)) {
|
|
8626
8794
|
const items = managerSupervisionItems(managerSnapshot);
|
|
@@ -8673,7 +8841,7 @@ function renderSupervisionRows(reports, width, options = {}, selectedLead, getGi
|
|
|
8673
8841
|
const elapsed = metadata[index].elapsed;
|
|
8674
8842
|
const context = metadata[index].context;
|
|
8675
8843
|
const git = metadata[index].git;
|
|
8676
|
-
const diff = git
|
|
8844
|
+
const diff = git ? formatGitChangeStats(git) : "";
|
|
8677
8845
|
const changedBranch = git?.checkedOutBranch !== void 0 && git.checkedOutBranch !== item.work.branch;
|
|
8678
8846
|
const optionsToFit = [
|
|
8679
8847
|
...context ? [{ value: context, kind: "context" }] : [],
|
|
@@ -8929,6 +9097,29 @@ function formatSupervisionContext(snapshot, options) {
|
|
|
8929
9097
|
]
|
|
8930
9098
|
];
|
|
8931
9099
|
const sections = [];
|
|
9100
|
+
const gitLines = [
|
|
9101
|
+
...options.git?.managerSession ? [
|
|
9102
|
+
" manager_session:",
|
|
9103
|
+
` cwd: ${supervisionValue(options.git.managerSession.cwd)}`,
|
|
9104
|
+
` worktree_root: ${supervisionValue(options.git.managerSession.worktreeRoot)}`,
|
|
9105
|
+
` branch: ${supervisionValue(options.git.managerSession.branch ?? "detached")}`,
|
|
9106
|
+
` head: ${options.git.managerSession.head}`
|
|
9107
|
+
] : [],
|
|
9108
|
+
...options.git?.manager ? [
|
|
9109
|
+
" manager_checkout:",
|
|
9110
|
+
` branch: ${supervisionValue(options.git.manager.branch ?? "detached")}`,
|
|
9111
|
+
` head: ${options.git.manager.head}`
|
|
9112
|
+
] : [],
|
|
9113
|
+
...[...options.git?.assignments ?? /* @__PURE__ */ new Map()].map(
|
|
9114
|
+
([assignment, observation]) => ` assignment ${supervisionValue(assignment)}: checkout_branch=${supervisionValue(observation.branch ?? "detached")} head=${observation.head}`
|
|
9115
|
+
),
|
|
9116
|
+
...[...options.git?.supervisedLeads ?? []].flatMap(
|
|
9117
|
+
([session, observation]) => options.targets?.has(session) ? [
|
|
9118
|
+
` supervised_lead ${supervisionValue(options.targets.get(session))}: checkout_branch=${supervisionValue(observation.branch ?? "detached")} head=${observation.head}`
|
|
9119
|
+
] : []
|
|
9120
|
+
)
|
|
9121
|
+
];
|
|
9122
|
+
const gitSection = gitLines.length ? ["git_observations:", ...gitLines].join("\n") : void 0;
|
|
8932
9123
|
if (snapshot?.diagnostics?.length)
|
|
8933
9124
|
sections.push(
|
|
8934
9125
|
[
|
|
@@ -9023,6 +9214,7 @@ function formatSupervisionContext(snapshot, options) {
|
|
|
9023
9214
|
included.pop();
|
|
9024
9215
|
included.push(...notice);
|
|
9025
9216
|
}
|
|
9217
|
+
if (gitSection && fits([...included, gitSection])) included.push(gitSection);
|
|
9026
9218
|
return [...included, closing].join("\n");
|
|
9027
9219
|
}
|
|
9028
9220
|
function boundedWidgetRows(supervision, agents, maxRows, width) {
|
|
@@ -9040,28 +9232,49 @@ function boundedWidgetRows(supervision, agents, maxRows, width) {
|
|
|
9040
9232
|
{ text: safeLine("\u2026 more", width) }
|
|
9041
9233
|
];
|
|
9042
9234
|
}
|
|
9043
|
-
function createSupervisionWidget(getLeads, getStatus, role2 = "chief", theme, onFocus, getGitSummary, ownedAgents, getMaxRows = () => 8) {
|
|
9235
|
+
function createSupervisionWidget(getLeads, getStatus, role2 = "chief", theme, onFocus, getGitSummary, ownedAgents, getMaxRows = () => 8, getHeaderGitSummary, getLocalActivity) {
|
|
9044
9236
|
let renderedWidth = -1;
|
|
9045
9237
|
let hits = [];
|
|
9046
9238
|
return {
|
|
9047
9239
|
render(width) {
|
|
9048
9240
|
renderedWidth = width;
|
|
9241
|
+
const status = getStatus();
|
|
9242
|
+
const supervision = getLeads();
|
|
9049
9243
|
const snapshot = ownedAgents?.getSnapshot();
|
|
9244
|
+
const activeOwned = !!snapshot && !snapshot.stale && !snapshot.unavailable && snapshot.agents.some(
|
|
9245
|
+
(agent) => ["working", "starting", "settling"].includes(agent.state)
|
|
9246
|
+
);
|
|
9247
|
+
const activeDescendants = activeStaffSnapshot(supervision, status === "fresh") || activeOwned;
|
|
9050
9248
|
const showAgents = !!snapshot && (snapshot.agents.length > 0 || snapshot.stale || snapshot.unavailable);
|
|
9051
9249
|
const rows = renderSupervisionRows(
|
|
9052
|
-
|
|
9250
|
+
supervision,
|
|
9053
9251
|
width,
|
|
9054
9252
|
{
|
|
9055
|
-
status
|
|
9253
|
+
status,
|
|
9056
9254
|
ordinaryCap: getMaxRows(),
|
|
9057
9255
|
childCap: getMaxRows(),
|
|
9058
9256
|
role: role2,
|
|
9059
9257
|
theme,
|
|
9060
|
-
hasFollowingGroup: showAgents
|
|
9258
|
+
hasFollowingGroup: showAgents,
|
|
9259
|
+
localActivity: getLocalActivity?.() ?? "unknown",
|
|
9260
|
+
activeDescendants
|
|
9061
9261
|
},
|
|
9062
9262
|
void 0,
|
|
9063
9263
|
getGitSummary
|
|
9064
9264
|
).filter(({ text }, index) => index === 0 || text.length > 0);
|
|
9265
|
+
if (role2 === "manager" && status === "fresh") {
|
|
9266
|
+
const git = getHeaderGitSummary?.();
|
|
9267
|
+
if (git && rows[0]) {
|
|
9268
|
+
const header = rows[0].text;
|
|
9269
|
+
const suffix = formatGitHeaderSuffix(
|
|
9270
|
+
git,
|
|
9271
|
+
theme,
|
|
9272
|
+
width - visibleWidth(header) - 2
|
|
9273
|
+
);
|
|
9274
|
+
if (suffix && visibleWidth(header) + 2 + visibleWidth(suffix) <= width)
|
|
9275
|
+
rows[0].text = `${header}${" ".repeat(width - visibleWidth(header) - visibleWidth(suffix))}${suffix}`;
|
|
9276
|
+
}
|
|
9277
|
+
}
|
|
9065
9278
|
const agentRows = [];
|
|
9066
9279
|
if (showAgents && snapshot) {
|
|
9067
9280
|
const freshness = snapshot.unavailable ? "unavailable" : snapshot.stale ? "stale" : String(snapshot.agents.length);
|
|
@@ -9268,14 +9481,13 @@ function safeDisplaySegment(value2) {
|
|
|
9268
9481
|
return code <= 31 || code === 127 ? " " : character;
|
|
9269
9482
|
}).replace(/\s+/gu, " ").trim();
|
|
9270
9483
|
}
|
|
9271
|
-
function renderBreadcrumb(segments, width) {
|
|
9484
|
+
function renderBreadcrumb(segments, width, marker = "?", theme) {
|
|
9272
9485
|
if (width <= 0) return { text: "", hits: [] };
|
|
9273
9486
|
const visible = segments.map((segment) => ({ ...segment, text: safeDisplaySegment(segment.text) })).filter((segment) => segment.text);
|
|
9274
9487
|
const current = visible.at(-1) ?? { text: "?" };
|
|
9275
|
-
const marker = "\u25CF";
|
|
9276
9488
|
if (width <= visibleWidth(marker))
|
|
9277
9489
|
return { text: truncateToWidth(marker, width, ""), hits: [] };
|
|
9278
|
-
const prefix = `${marker} `;
|
|
9490
|
+
const prefix = `${marker}${themed(theme, "muted", " ")}`;
|
|
9279
9491
|
const available = width - visibleWidth(prefix);
|
|
9280
9492
|
if (available <= 0) return { text: marker, hits: [] };
|
|
9281
9493
|
const currentText = tailTruncate(current.text, available);
|
|
@@ -9286,7 +9498,10 @@ function renderBreadcrumb(segments, width) {
|
|
|
9286
9498
|
if (visibleWidth(candidateText) <= width) included.unshift(visible[index]);
|
|
9287
9499
|
else break;
|
|
9288
9500
|
}
|
|
9289
|
-
const text = `${prefix}${included.map((
|
|
9501
|
+
const text = `${prefix}${included.map((segment, index) => {
|
|
9502
|
+
const role2 = index === included.length - 1 && segment.role && segment.text.startsWith(segment.role) ? segment.role : void 0;
|
|
9503
|
+
return role2 ? `${themed(theme, "text", theme?.bold?.(role2) ?? role2)}${themed(theme, "muted", segment.text.slice(role2.length))}` : themed(theme, "muted", segment.text);
|
|
9504
|
+
}).join(" \u2192 ")}`;
|
|
9290
9505
|
const hits = [];
|
|
9291
9506
|
let x = visibleWidth(prefix);
|
|
9292
9507
|
included.forEach((segment, index) => {
|
|
@@ -9364,7 +9579,7 @@ function formatAgentDefinitions(definitions) {
|
|
|
9364
9579
|
function displayHomePath(path) {
|
|
9365
9580
|
const home = homedir3();
|
|
9366
9581
|
if (!isAbsolute4(path)) return path;
|
|
9367
|
-
const remainder =
|
|
9582
|
+
const remainder = relative2(home, path);
|
|
9368
9583
|
if (remainder === "") return "~";
|
|
9369
9584
|
if (remainder !== ".." && !remainder.startsWith(`..${sep2}`))
|
|
9370
9585
|
return `~/${remainder}`;
|
|
@@ -9666,8 +9881,8 @@ function formatToolModelResult(action, v) {
|
|
|
9666
9881
|
}
|
|
9667
9882
|
if (action === "interrupt") {
|
|
9668
9883
|
return [
|
|
9669
|
-
`Interrupt accepted for agent ${value(v.agent) || "unknown"}.`,
|
|
9670
|
-
"The current Pi operation was asked to stop and the replacement instruction continues the same assignment.",
|
|
9884
|
+
v.delivered_as === "steer" ? `Interrupt request delivered via steering for agent ${value(v.agent) || "unknown"}.` : `Interrupt accepted for agent ${value(v.agent) || "unknown"}.`,
|
|
9885
|
+
v.delivered_as === "steer" ? value(v.note) || "The agent was waiting for child work. The message was delivered via steering; nothing was interrupted." : "The current Pi operation was asked to stop and the replacement instruction continues the same assignment.",
|
|
9671
9886
|
...value(v.session_id) ? [`Session: ${v.session_id}`] : [],
|
|
9672
9887
|
...value(v.request_id) ? [`Request: ${v.request_id}`] : [],
|
|
9673
9888
|
...value(v.assignment_request_id) ? [`Assignment request: ${v.assignment_request_id}`] : [],
|
|
@@ -9740,6 +9955,7 @@ function formatToolModelResult(action, v) {
|
|
|
9740
9955
|
...value(v.request_id) ? [`Request: ${v.request_id}`] : [],
|
|
9741
9956
|
...value(v.assignment_request_id) ? [`Assignment request: ${v.assignment_request_id}`] : [],
|
|
9742
9957
|
...action === "reply" && value(v.ask_id) ? [`Ask: ${v.ask_id}`] : [],
|
|
9958
|
+
...value(v.history_warning) ? [`History warning: ${value(v.history_warning)}`] : [],
|
|
9743
9959
|
...(action === "delegate" || action === "continue") && v.evidence && typeof v.evidence === "object" ? (() => {
|
|
9744
9960
|
const evidence = v.evidence;
|
|
9745
9961
|
const lines = [
|
|
@@ -10626,6 +10842,7 @@ function renderCoordinationMessage(kind, message, options, theme) {
|
|
|
10626
10842
|
toDisplayName: optionalString("toDisplayName"),
|
|
10627
10843
|
kind: projectKind
|
|
10628
10844
|
};
|
|
10845
|
+
const senderEnvironment = validSenderEnvironment(rawDetails.senderEnvironment) ? rawDetails.senderEnvironment : void 0;
|
|
10629
10846
|
const branch = d?.branch ?? "project work";
|
|
10630
10847
|
const messageContent = contentText(message.content ?? "");
|
|
10631
10848
|
let heading = "";
|
|
@@ -10662,7 +10879,8 @@ function renderCoordinationMessage(kind, message, options, theme) {
|
|
|
10662
10879
|
break;
|
|
10663
10880
|
}
|
|
10664
10881
|
}
|
|
10665
|
-
|
|
10882
|
+
const annotation = senderEnvironment ? senderEnvironmentAnnotation(senderEnvironment) : "";
|
|
10883
|
+
let body = annotation && messageContent.endsWith(annotation) ? messageContent.slice(0, -annotation.length) : messageContent;
|
|
10666
10884
|
if (prefix && body.startsWith(prefix)) body = body.slice(prefix.length);
|
|
10667
10885
|
const content = new Container();
|
|
10668
10886
|
content.addChild(new WidthSafeText(heading, 0, 0));
|
|
@@ -10671,7 +10889,15 @@ function renderCoordinationMessage(kind, message, options, theme) {
|
|
|
10671
10889
|
...d?.branch ? [`branch: ${d.branch}`] : [],
|
|
10672
10890
|
...senderRole && d?.fromSessionId ? [`from session: ${d.fromSessionId}`] : [],
|
|
10673
10891
|
...senderRole && d?.toSessionId ? [`to session: ${d.toSessionId}`] : [],
|
|
10674
|
-
...!senderRole && kind !== "project_assignment" && (d?.fromSessionId ?? d?.leadSessionId) ? [`session: ${d?.fromSessionId ?? d?.leadSessionId}`] : []
|
|
10892
|
+
...!senderRole && kind !== "project_assignment" && (d?.fromSessionId ?? d?.leadSessionId) ? [`session: ${d?.fromSessionId ?? d?.leadSessionId}`] : [],
|
|
10893
|
+
...senderEnvironment ? [
|
|
10894
|
+
`sender cwd: ${senderEnvironment.cwd}`,
|
|
10895
|
+
...senderEnvironment.git ? [
|
|
10896
|
+
`worktree: ${senderEnvironment.git.worktreeRoot}`,
|
|
10897
|
+
`checked-out branch: ${senderEnvironment.git.branch ?? "detached"}`,
|
|
10898
|
+
`HEAD: ${senderEnvironment.git.head}`
|
|
10899
|
+
] : []
|
|
10900
|
+
] : []
|
|
10675
10901
|
];
|
|
10676
10902
|
if (metadata.length) {
|
|
10677
10903
|
content.addChild(new Spacer(1));
|
|
@@ -10927,8 +11153,15 @@ function renderAgentLostMessage(message, options, theme) {
|
|
|
10927
11153
|
options.outputPad ?? 0
|
|
10928
11154
|
);
|
|
10929
11155
|
}
|
|
10930
|
-
function createStatusWidget(invalidate, theme, onFocus, getMaxRows) {
|
|
10931
|
-
return new StatusWidget(
|
|
11156
|
+
function createStatusWidget(invalidate, theme, onFocus, getMaxRows, getGitSummary, getLocalActivity) {
|
|
11157
|
+
return new StatusWidget(
|
|
11158
|
+
invalidate,
|
|
11159
|
+
theme,
|
|
11160
|
+
onFocus,
|
|
11161
|
+
getMaxRows,
|
|
11162
|
+
getGitSummary,
|
|
11163
|
+
getLocalActivity
|
|
11164
|
+
);
|
|
10932
11165
|
}
|
|
10933
11166
|
var LIFECYCLE, animates, STATE_COLOR, MIN_TASK_WIDTH, STATUS_LAYOUTS, SUPERVISION_GROUPS, SUPERVISION_CONTEXT_MAX_BYTES, remoteDiagnosticMessages, maxRemoteDiagnostics, WidthSafeText, spinner, StatusWidget;
|
|
10934
11167
|
var init_presentation = __esm({
|
|
@@ -11017,10 +11250,14 @@ var init_presentation = __esm({
|
|
|
11017
11250
|
renderedWidth = -1;
|
|
11018
11251
|
hits = [];
|
|
11019
11252
|
getMaxRows;
|
|
11020
|
-
|
|
11253
|
+
getGitSummary;
|
|
11254
|
+
getLocalActivity;
|
|
11255
|
+
constructor(invalidateUI, theme, onFocus, getMaxRows = () => 8, getGitSummary, getLocalActivity = () => "unknown") {
|
|
11021
11256
|
this.invalidateUI = invalidateUI;
|
|
11022
11257
|
this.getMaxRows = getMaxRows;
|
|
11023
11258
|
this.onFocus = onFocus;
|
|
11259
|
+
this.getGitSummary = getGitSummary;
|
|
11260
|
+
this.getLocalActivity = getLocalActivity;
|
|
11024
11261
|
this.theme = theme ?? {
|
|
11025
11262
|
fg: (_color, text) => text,
|
|
11026
11263
|
bold: (text) => text
|
|
@@ -11047,6 +11284,13 @@ var init_presentation = __esm({
|
|
|
11047
11284
|
}
|
|
11048
11285
|
render(width) {
|
|
11049
11286
|
const s = this.snapshot;
|
|
11287
|
+
const local = this.getLocalActivity();
|
|
11288
|
+
const marker = headerActivity(
|
|
11289
|
+
local,
|
|
11290
|
+
!s.stale && !s.unavailable && s.agents.some(
|
|
11291
|
+
(agent) => ["working", "starting", "settling"].includes(agent.state)
|
|
11292
|
+
)
|
|
11293
|
+
).marker;
|
|
11050
11294
|
this.renderedWidth = width;
|
|
11051
11295
|
this.hits = [];
|
|
11052
11296
|
const availableWidth = Math.max(0, width);
|
|
@@ -11062,12 +11306,19 @@ var init_presentation = __esm({
|
|
|
11062
11306
|
const freshnessSuffixWidth = visibleWidth(freshnessSuffix);
|
|
11063
11307
|
const breadcrumbSegments = s.breadcrumb ?? [{ text: "?" }];
|
|
11064
11308
|
const fullIdentityWidth = visibleWidth(
|
|
11065
|
-
renderBreadcrumb(
|
|
11309
|
+
renderBreadcrumb(
|
|
11310
|
+
breadcrumbSegments,
|
|
11311
|
+
Number.MAX_SAFE_INTEGER,
|
|
11312
|
+
marker,
|
|
11313
|
+
this.theme
|
|
11314
|
+
).text
|
|
11066
11315
|
);
|
|
11067
11316
|
const reservedSuffixWidth = freshness && fullSuffixWidth + fullIdentityWidth <= availableWidth ? fullSuffixWidth : freshnessSuffixWidth || (fullSuffixWidth + fullIdentityWidth <= availableWidth ? fullSuffixWidth : 0);
|
|
11068
11317
|
const renderedBreadcrumb = renderBreadcrumb(
|
|
11069
11318
|
breadcrumbSegments,
|
|
11070
|
-
Math.max(0, availableWidth - reservedSuffixWidth)
|
|
11319
|
+
Math.max(0, availableWidth - reservedSuffixWidth),
|
|
11320
|
+
marker,
|
|
11321
|
+
this.theme
|
|
11071
11322
|
);
|
|
11072
11323
|
const breadcrumb = renderedBreadcrumb.text;
|
|
11073
11324
|
if (!s.stale && !s.unavailable) this.hits.push(...renderedBreadcrumb.hits);
|
|
@@ -11098,14 +11349,30 @@ var init_presentation = __esm({
|
|
|
11098
11349
|
);
|
|
11099
11350
|
if (visibleWidth(breadcrumb) + visibleWidth(shownExecution) + visibleWidth(tools) + visibleWidth(run2) + visibleWidth(suffixText) > availableWidth)
|
|
11100
11351
|
run2 = "";
|
|
11101
|
-
const
|
|
11352
|
+
const markerColor = headerActivity(local, marker === "\u25C9").color;
|
|
11353
|
+
const styledBreadcrumb = breadcrumb.startsWith(marker) ? `${this.theme.fg(markerColor, marker)}${breadcrumb.slice(marker.length)}` : breadcrumb;
|
|
11102
11354
|
const styledExecution = shownExecution ? this.theme.fg("muted", shownExecution) : "";
|
|
11103
11355
|
const styledTools = tools ? this.theme.fg("muted", tools) : "";
|
|
11104
11356
|
const styledRun = run2 ? this.theme.fg("accent", run2) : "";
|
|
11105
11357
|
const styledSuffix = !suffixText ? "" : s.unavailable ? this.theme.fg("warning", suffixText) : s.stale ? `${includeCounts ? this.theme.fg("muted", `${breadcrumb ? " " : ""}${counts} \xB7 `) : breadcrumb ? " " : ""}${this.theme.fg("warning", "stale")}` : this.theme.fg("muted", suffixText);
|
|
11106
|
-
const
|
|
11107
|
-
const compactStaleHeader = s.stale && !s.unavailable && !breadcrumb && visibleWidth(
|
|
11108
|
-
|
|
11358
|
+
const builtHeader = `${styledBreadcrumb}${styledExecution}${styledTools}${styledRun}${styledSuffix}`;
|
|
11359
|
+
const compactStaleHeader = s.stale && !s.unavailable && !breadcrumb && visibleWidth(`${marker} stale`) <= availableWidth ? `${this.theme.fg(markerColor, marker)} ${this.theme.fg("warning", "stale")}` : builtHeader;
|
|
11360
|
+
let header = truncateToWidth(compactStaleHeader, availableWidth, "\u2026");
|
|
11361
|
+
const observedGit = !s.stale && !s.unavailable ? this.getGitSummary?.() : void 0;
|
|
11362
|
+
const gitSummary = observedGit && s.execution?.kind === "managed" && s.execution.lifecycle !== "assigned" ? observedGit.checkedOutBranch ? {
|
|
11363
|
+
dirty: observedGit.dirty,
|
|
11364
|
+
checkedOutBranch: observedGit.checkedOutBranch
|
|
11365
|
+
} : void 0 : observedGit;
|
|
11366
|
+
if (gitSummary) {
|
|
11367
|
+
const suffix = formatGitHeaderSuffix(
|
|
11368
|
+
gitSummary,
|
|
11369
|
+
this.theme,
|
|
11370
|
+
availableWidth - visibleWidth(header) - 2
|
|
11371
|
+
);
|
|
11372
|
+
if (suffix && visibleWidth(header) + 2 + visibleWidth(suffix) <= availableWidth)
|
|
11373
|
+
header = `${header}${" ".repeat(availableWidth - visibleWidth(header) - visibleWidth(suffix))}${suffix}`;
|
|
11374
|
+
}
|
|
11375
|
+
const out = [header];
|
|
11109
11376
|
if (s.identityOnly) return out;
|
|
11110
11377
|
const rows = renderStatusRows(s.agents, {
|
|
11111
11378
|
now: observedNow,
|
|
@@ -12751,6 +13018,9 @@ import {
|
|
|
12751
13018
|
} from "node:fs";
|
|
12752
13019
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
12753
13020
|
import { basename as basename7, dirname as dirname7, join as join8 } from "node:path";
|
|
13021
|
+
function validManagerMergeSetting(value2) {
|
|
13022
|
+
return typeof value2 === "boolean" || value2 === "divergent";
|
|
13023
|
+
}
|
|
12754
13024
|
function validByteLimit(value2) {
|
|
12755
13025
|
return typeof value2 === "number" && Number.isInteger(value2) && value2 >= MIN_BYTE_LIMIT && value2 <= MAX_BYTE_LIMIT;
|
|
12756
13026
|
}
|
|
@@ -12777,7 +13047,7 @@ function containsControlCharacter(value2) {
|
|
|
12777
13047
|
}
|
|
12778
13048
|
function validManagerMergeOverrides(value2) {
|
|
12779
13049
|
return !!value2 && typeof value2 === "object" && !Array.isArray(value2) && Object.entries(value2).every(
|
|
12780
|
-
([repoKey, enabled]) => validRepoIdentity(repoKey) &&
|
|
13050
|
+
([repoKey, enabled]) => validRepoIdentity(repoKey) && validManagerMergeSetting(enabled)
|
|
12781
13051
|
);
|
|
12782
13052
|
}
|
|
12783
13053
|
function parseRawConfig(content) {
|
|
@@ -12834,7 +13104,7 @@ function parseRawConfig(content) {
|
|
|
12834
13104
|
result.managerGitBootstrapWithoutConfirmation = record.managerGitBootstrapWithoutConfirmation;
|
|
12835
13105
|
}
|
|
12836
13106
|
if ("managerMergeEnabled" in record) {
|
|
12837
|
-
if (
|
|
13107
|
+
if (!validManagerMergeSetting(record.managerMergeEnabled))
|
|
12838
13108
|
throw new Error("Invalid Pi Herdsman config field managerMergeEnabled");
|
|
12839
13109
|
result.managerMergeEnabled = record.managerMergeEnabled;
|
|
12840
13110
|
}
|
|
@@ -12869,12 +13139,17 @@ function effectiveMergePolicy(config, repoKey) {
|
|
|
12869
13139
|
if (!validRepoIdentity(repoKey))
|
|
12870
13140
|
throw new Error("A verified repository identity is required");
|
|
12871
13141
|
const override = config.managerMergeOverrides[repoKey];
|
|
12872
|
-
|
|
13142
|
+
const setting = !Object.hasOwn(config.managerMergeOverrides, repoKey) ? config.managerMergeEnabled : override;
|
|
13143
|
+
return {
|
|
13144
|
+
enabled: setting !== false,
|
|
13145
|
+
allowDivergence: setting === "divergent",
|
|
13146
|
+
source: Object.hasOwn(config.managerMergeOverrides, repoKey) ? "repository" : "global"
|
|
13147
|
+
};
|
|
12873
13148
|
}
|
|
12874
13149
|
function setManagerMergeOverride(repoKey, enabled) {
|
|
12875
|
-
if (!validRepoIdentity(repoKey) || enabled !== void 0 &&
|
|
13150
|
+
if (!validRepoIdentity(repoKey) || enabled !== void 0 && !validManagerMergeSetting(enabled))
|
|
12876
13151
|
throw new Error(
|
|
12877
|
-
"A verified repository identity and optional
|
|
13152
|
+
"A verified repository identity and optional merge policy are required"
|
|
12878
13153
|
);
|
|
12879
13154
|
const path = herdsmanConfigPath();
|
|
12880
13155
|
const release = claimProcessLock(`${path}.lock`, {
|
|
@@ -13127,7 +13402,7 @@ function updateConfig(key, value2) {
|
|
|
13127
13402
|
throw new Error(
|
|
13128
13403
|
"Invalid Pi Herdsman config field managerGitBootstrapWithoutConfirmation"
|
|
13129
13404
|
);
|
|
13130
|
-
if (key === "managerMergeEnabled" &&
|
|
13405
|
+
if (key === "managerMergeEnabled" && !validManagerMergeSetting(value2))
|
|
13131
13406
|
throw new Error("Invalid Pi Herdsman config field managerMergeEnabled");
|
|
13132
13407
|
if (key === "managerMergeOverrides" && !validManagerMergeOverrides(value2))
|
|
13133
13408
|
throw new Error(
|
|
@@ -13218,7 +13493,7 @@ import { setTimeout as delay } from "node:timers/promises";
|
|
|
13218
13493
|
import { StringEnum } from "@earendil-works/pi-ai";
|
|
13219
13494
|
import { Type } from "typebox";
|
|
13220
13495
|
function rootStatusBreadcrumb(role2) {
|
|
13221
|
-
return [{ text: role2 ?? "owner/controller" }];
|
|
13496
|
+
return [{ text: role2 ?? "owner/controller", ...role2 ? { role: role2 } : {} }];
|
|
13222
13497
|
}
|
|
13223
13498
|
function buildAgentStatusSnapshot(view, ctx, host) {
|
|
13224
13499
|
const ownerSessionId = ctx.sessionManager.getSessionId();
|
|
@@ -13275,6 +13550,35 @@ function buildAgentStatusSnapshot(view, ctx, host) {
|
|
|
13275
13550
|
refreshedAt: Date.now()
|
|
13276
13551
|
};
|
|
13277
13552
|
}
|
|
13553
|
+
function observeLocalHeaderActivity(pi, invalidate) {
|
|
13554
|
+
let promptSession;
|
|
13555
|
+
pi.on("ui_prompt_start", (_event, ctx) => {
|
|
13556
|
+
promptSession = ctx.sessionManager.getSessionId();
|
|
13557
|
+
invalidate();
|
|
13558
|
+
});
|
|
13559
|
+
pi.on("ui_prompt_end", (_event, ctx) => {
|
|
13560
|
+
if (promptSession === ctx.sessionManager.getSessionId())
|
|
13561
|
+
promptSession = void 0;
|
|
13562
|
+
invalidate();
|
|
13563
|
+
});
|
|
13564
|
+
pi.on("agent_start", invalidate);
|
|
13565
|
+
pi.on("agent_settled", invalidate);
|
|
13566
|
+
pi.on("session_start", () => {
|
|
13567
|
+
promptSession = void 0;
|
|
13568
|
+
invalidate();
|
|
13569
|
+
});
|
|
13570
|
+
pi.on("session_shutdown", () => {
|
|
13571
|
+
promptSession = void 0;
|
|
13572
|
+
});
|
|
13573
|
+
return (ctx) => {
|
|
13574
|
+
try {
|
|
13575
|
+
if (ctx.isIdle()) return "idle";
|
|
13576
|
+
return promptSession === ctx.sessionManager.getSessionId() ? "blocked" : "working";
|
|
13577
|
+
} catch {
|
|
13578
|
+
return "unknown";
|
|
13579
|
+
}
|
|
13580
|
+
};
|
|
13581
|
+
}
|
|
13278
13582
|
function createAgentStatusRuntime() {
|
|
13279
13583
|
let options;
|
|
13280
13584
|
let statusWidget;
|
|
@@ -13291,6 +13595,7 @@ function createAgentStatusRuntime() {
|
|
|
13291
13595
|
}
|
|
13292
13596
|
};
|
|
13293
13597
|
let statusTimer;
|
|
13598
|
+
let stopNewAgentWatch;
|
|
13294
13599
|
let statusContext;
|
|
13295
13600
|
let statusGeneration = 0;
|
|
13296
13601
|
let statusWidgetGeneration = 0;
|
|
@@ -13362,6 +13667,13 @@ function createAgentStatusRuntime() {
|
|
|
13362
13667
|
lastValidStatus = snapshot;
|
|
13363
13668
|
reconcilePendingStarts(snapshot);
|
|
13364
13669
|
publishStatus(snapshot);
|
|
13670
|
+
if (statusWidget) {
|
|
13671
|
+
try {
|
|
13672
|
+
configured.onFreshStatus?.(ctx, snapshot);
|
|
13673
|
+
} catch {
|
|
13674
|
+
}
|
|
13675
|
+
}
|
|
13676
|
+
syncNewAgentWatch(ctx, generation);
|
|
13365
13677
|
} catch {
|
|
13366
13678
|
if (generation === statusGeneration && ctx === statusContext)
|
|
13367
13679
|
publishStatus(
|
|
@@ -13390,8 +13702,40 @@ function createAgentStatusRuntime() {
|
|
|
13390
13702
|
const clearTimer = () => {
|
|
13391
13703
|
if (statusTimer) clearInterval(statusTimer);
|
|
13392
13704
|
statusTimer = void 0;
|
|
13705
|
+
stopNewAgentWatch?.();
|
|
13706
|
+
stopNewAgentWatch = void 0;
|
|
13707
|
+
};
|
|
13708
|
+
const syncNewAgentWatch = (ctx, generation) => {
|
|
13709
|
+
if (!presentedStatus.agents.length || !statusTimer) {
|
|
13710
|
+
stopNewAgentWatch?.();
|
|
13711
|
+
stopNewAgentWatch = void 0;
|
|
13712
|
+
return;
|
|
13713
|
+
}
|
|
13714
|
+
if (stopNewAgentWatch) return;
|
|
13715
|
+
let lastError;
|
|
13716
|
+
stopNewAgentWatch = observeNewAgentStates(
|
|
13717
|
+
() => {
|
|
13718
|
+
lastError = void 0;
|
|
13719
|
+
void refresh(ctx, generation);
|
|
13720
|
+
},
|
|
13721
|
+
(error2) => {
|
|
13722
|
+
const message = String(error2).replace(/^Error: /u, "");
|
|
13723
|
+
if (message === lastError) return;
|
|
13724
|
+
lastError = message;
|
|
13725
|
+
if (generation === statusGeneration && ctx === statusContext)
|
|
13726
|
+
ctx.ui.notify(
|
|
13727
|
+
`Agent status cannot watch for new agents (${message}); the view refreshes every 10 seconds instead`,
|
|
13728
|
+
"warning"
|
|
13729
|
+
);
|
|
13730
|
+
}
|
|
13731
|
+
);
|
|
13732
|
+
void refresh(ctx, generation);
|
|
13393
13733
|
};
|
|
13394
13734
|
const removeWidget = () => {
|
|
13735
|
+
try {
|
|
13736
|
+
options?.onWidgetStop?.();
|
|
13737
|
+
} catch {
|
|
13738
|
+
}
|
|
13395
13739
|
if (statusWidget) {
|
|
13396
13740
|
statusContext?.ui.setWidget("pi-herdsman", void 0);
|
|
13397
13741
|
statusWidget.dispose();
|
|
@@ -13411,6 +13755,8 @@ function createAgentStatusRuntime() {
|
|
|
13411
13755
|
void refresh(statusContext, statusGeneration);
|
|
13412
13756
|
},
|
|
13413
13757
|
getSnapshot: () => presentedStatus,
|
|
13758
|
+
invalidateWidget: () => statusWidget?.invalidate(),
|
|
13759
|
+
isWidgetActive: () => !!statusWidget,
|
|
13414
13760
|
startObserver: (ctx, onChange) => {
|
|
13415
13761
|
if (ctx.mode !== "tui" || !ctx.hasUI) return;
|
|
13416
13762
|
const primed = statusPrimed && ctx === statusContext;
|
|
@@ -13422,6 +13768,7 @@ function createAgentStatusRuntime() {
|
|
|
13422
13768
|
requestActive = true;
|
|
13423
13769
|
statusTimer = setInterval(() => void refresh(ctx, generation), 1e4);
|
|
13424
13770
|
statusTimer.unref?.();
|
|
13771
|
+
syncNewAgentWatch(ctx, generation);
|
|
13425
13772
|
statusPrimed = false;
|
|
13426
13773
|
publishStatus(presentedStatus);
|
|
13427
13774
|
if (!primed) void refresh(ctx, generation);
|
|
@@ -13440,6 +13787,7 @@ function createAgentStatusRuntime() {
|
|
|
13440
13787
|
const primed = statusPrimed && ctx === statusContext;
|
|
13441
13788
|
const generation = ctx === statusContext && requestActive ? statusGeneration : ++statusGeneration;
|
|
13442
13789
|
clearTimer();
|
|
13790
|
+
removeWidget();
|
|
13443
13791
|
statusContext = ctx;
|
|
13444
13792
|
ctx.ui.setWidget("pi-herdsman", (tui, theme) => {
|
|
13445
13793
|
let widget;
|
|
@@ -13463,27 +13811,34 @@ function createAgentStatusRuntime() {
|
|
|
13463
13811
|
if (generation === statusGeneration) focusInFlight = false;
|
|
13464
13812
|
});
|
|
13465
13813
|
},
|
|
13466
|
-
() => statusWidgetMaxRows
|
|
13814
|
+
() => statusWidgetMaxRows,
|
|
13815
|
+
() => options?.getGitSummary?.(),
|
|
13816
|
+
() => options?.getLocalActivity?.(ctx) ?? "unknown"
|
|
13467
13817
|
);
|
|
13468
13818
|
widget.setSnapshot(widgetSnapshot(presentedStatus, true));
|
|
13469
13819
|
if (generation === statusGeneration && ctx === statusContext) {
|
|
13470
13820
|
statusWidget = widget;
|
|
13471
13821
|
statusWidgetGeneration = generation;
|
|
13822
|
+
if (primed) {
|
|
13823
|
+
try {
|
|
13824
|
+
options?.onFreshStatus?.(ctx, lastValidStatus);
|
|
13825
|
+
} catch {
|
|
13826
|
+
}
|
|
13827
|
+
}
|
|
13472
13828
|
} else widget.dispose();
|
|
13473
13829
|
return widget;
|
|
13474
13830
|
});
|
|
13475
13831
|
requestActive = true;
|
|
13476
13832
|
statusTimer = setInterval(() => void refresh(ctx, generation), 1e4);
|
|
13477
13833
|
statusTimer.unref?.();
|
|
13834
|
+
syncNewAgentWatch(ctx, generation);
|
|
13478
13835
|
statusPrimed = false;
|
|
13479
13836
|
if (!primed) void refresh(ctx, generation);
|
|
13480
13837
|
},
|
|
13481
13838
|
clear: () => {
|
|
13482
13839
|
++statusGeneration;
|
|
13483
13840
|
clearTimer();
|
|
13484
|
-
|
|
13485
|
-
statusWidget?.dispose();
|
|
13486
|
-
statusWidget = void 0;
|
|
13841
|
+
removeWidget();
|
|
13487
13842
|
requestActive = false;
|
|
13488
13843
|
focusInFlight = false;
|
|
13489
13844
|
statusPrimed = false;
|
|
@@ -13520,10 +13875,10 @@ function createAgentStatusRuntime() {
|
|
|
13520
13875
|
shutdown: () => {
|
|
13521
13876
|
++statusGeneration;
|
|
13522
13877
|
clearTimer();
|
|
13878
|
+
removeWidget();
|
|
13523
13879
|
statusRefresh = false;
|
|
13524
13880
|
statusInFlight = false;
|
|
13525
13881
|
focusInFlight = false;
|
|
13526
|
-
removeWidget();
|
|
13527
13882
|
statusWidgetGeneration = 0;
|
|
13528
13883
|
statusContext = void 0;
|
|
13529
13884
|
requestActive = false;
|
|
@@ -13927,48 +14282,120 @@ function closedAssignmentReceipt(entries, ownerSessionId, child) {
|
|
|
13927
14282
|
return [];
|
|
13928
14283
|
const message = entry.message;
|
|
13929
14284
|
const details = message?.details;
|
|
13930
|
-
const
|
|
13931
|
-
if (message?.role !== "toolResult" || !(message.toolName === "close_agent" && details?.action === "close" || message.toolName === "stop_agent" && details?.action === "stop") || message.isError === true || details?.ok !== true || details.cleanup_error !== void 0 || details.cleanup_errors !== void 0 || !validClosedProof(
|
|
14285
|
+
const proof = details?.closed_assignment;
|
|
14286
|
+
if (message?.role !== "toolResult" || !(message.toolName === "close_agent" && details?.action === "close" || message.toolName === "stop_agent" && details?.action === "stop") || message.isError === true || details?.ok !== true || details.cleanup_error !== void 0 || details.cleanup_errors !== void 0 || !validClosedProof(proof, ownerSessionId, child))
|
|
13932
14287
|
return [];
|
|
13933
|
-
return [{ index, proof
|
|
14288
|
+
return [{ index, proof }];
|
|
13934
14289
|
});
|
|
13935
14290
|
const stopped = entries.flatMap((entry, index) => {
|
|
13936
14291
|
if (!entry || typeof entry !== "object" || !("type" in entry) || entry.type !== "custom" || !("customType" in entry) || entry.customType !== STOP_CLOSURE_ENTRY)
|
|
13937
14292
|
return [];
|
|
13938
14293
|
const data = entry.data;
|
|
13939
|
-
const
|
|
13940
|
-
if (data?.version !== 1 || !validClosedProof(
|
|
14294
|
+
const proof = data?.proof;
|
|
14295
|
+
if (data?.version !== 1 || !validClosedProof(proof, ownerSessionId, child))
|
|
13941
14296
|
return [];
|
|
13942
|
-
return [{ index, proof
|
|
14297
|
+
return [{ index, proof }];
|
|
13943
14298
|
});
|
|
13944
14299
|
closed.push(...stopped);
|
|
13945
14300
|
const latestAccepted = accepted.at(-1);
|
|
13946
14301
|
const matches = latestAccepted ? closed.filter(
|
|
13947
|
-
({ index, proof
|
|
14302
|
+
({ index, proof }) => latestAccepted.index < index && latestAccepted.requestId === proof.request_id
|
|
13948
14303
|
) : [];
|
|
13949
|
-
if (!matches.length
|
|
13950
|
-
const
|
|
13951
|
-
|
|
13952
|
-
|
|
13953
|
-
|
|
13954
|
-
return
|
|
13955
|
-
|
|
13956
|
-
|
|
13957
|
-
|
|
13958
|
-
|
|
13959
|
-
|
|
13960
|
-
|
|
13961
|
-
|
|
13962
|
-
|
|
13963
|
-
|
|
13964
|
-
|
|
14304
|
+
if (!matches.length) return void 0;
|
|
14305
|
+
const proofs = [];
|
|
14306
|
+
for (const { proof } of matches)
|
|
14307
|
+
if (!proofs.some((candidate) => isDeepStrictEqual2(candidate, proof)))
|
|
14308
|
+
proofs.push(proof);
|
|
14309
|
+
return proofs.length === 1 ? proofs[0] : void 0;
|
|
14310
|
+
}
|
|
14311
|
+
function acceptedAssignmentEvidence(entries, ownerSessionId, unavailable) {
|
|
14312
|
+
const parsed = entries.flatMap((entry, index) => {
|
|
14313
|
+
let details;
|
|
14314
|
+
let action;
|
|
14315
|
+
let legacyResult = false;
|
|
14316
|
+
if (entry && typeof entry === "object" && "type" in entry && entry.type === "custom" && "customType" in entry && entry.customType === ACCEPTED_ASSIGNMENT_ENTRY) {
|
|
14317
|
+
const data = entry.data;
|
|
14318
|
+
const fields = [
|
|
14319
|
+
"version",
|
|
14320
|
+
"action",
|
|
14321
|
+
"owner_session_id",
|
|
14322
|
+
"session_id",
|
|
14323
|
+
"session_path",
|
|
14324
|
+
"request_id",
|
|
14325
|
+
"agent",
|
|
14326
|
+
"definition"
|
|
14327
|
+
];
|
|
14328
|
+
if (!data || typeof data !== "object" || Array.isArray(data) || data.version !== 1 || Object.keys(data).length !== fields.length || !fields.every((field) => Object.hasOwn(data, field)))
|
|
14329
|
+
return [];
|
|
14330
|
+
details = data;
|
|
14331
|
+
action = data.action;
|
|
14332
|
+
} else if (entry && typeof entry === "object" && "type" in entry && entry.type === "message" && "message" in entry) {
|
|
14333
|
+
const message = entry.message;
|
|
14334
|
+
legacyResult = true;
|
|
14335
|
+
if (message?.role !== "toolResult" || message.isError === true || message.details?.ok !== true)
|
|
14336
|
+
return [];
|
|
14337
|
+
const actions = {
|
|
14338
|
+
delegate_agent: "delegate",
|
|
14339
|
+
agent_delegate: "delegate",
|
|
14340
|
+
continue_agent: "continue",
|
|
14341
|
+
agent_continue: "continue"
|
|
14342
|
+
};
|
|
14343
|
+
action = actions[message.toolName];
|
|
14344
|
+
details = message.details;
|
|
14345
|
+
} else return [];
|
|
14346
|
+
if (action !== "delegate" && action !== "continue" || !validId(details?.owner_session_id) || !validId(details?.session_id) || !validId(details?.request_id) || typeof details?.session_path !== "string" || typeof details?.agent !== "string" || !details.agent.trim() || typeof details?.definition !== "string" || !details.definition.trim()) {
|
|
14347
|
+
if (legacyResult && details?.owner_session_id === ownerSessionId)
|
|
14348
|
+
unavailable?.();
|
|
13965
14349
|
return [];
|
|
14350
|
+
}
|
|
14351
|
+
const assignmentAction = action;
|
|
13966
14352
|
try {
|
|
13967
|
-
return
|
|
14353
|
+
return [
|
|
14354
|
+
{
|
|
14355
|
+
index,
|
|
14356
|
+
action: assignmentAction,
|
|
14357
|
+
ownerSessionId: details.owner_session_id,
|
|
14358
|
+
sessionId: details.session_id,
|
|
14359
|
+
sessionPath: canonicalSessionPath(details.session_path),
|
|
14360
|
+
requestId: details.request_id,
|
|
14361
|
+
agent: details.agent,
|
|
14362
|
+
definition: details.definition
|
|
14363
|
+
}
|
|
14364
|
+
];
|
|
13968
14365
|
} catch {
|
|
14366
|
+
if (legacyResult && details.owner_session_id === ownerSessionId)
|
|
14367
|
+
unavailable?.();
|
|
13969
14368
|
return [];
|
|
13970
14369
|
}
|
|
13971
14370
|
});
|
|
14371
|
+
const byRequest = /* @__PURE__ */ new Map();
|
|
14372
|
+
for (const item of parsed)
|
|
14373
|
+
byRequest.set(item.requestId, [
|
|
14374
|
+
...byRequest.get(item.requestId) ?? [],
|
|
14375
|
+
item
|
|
14376
|
+
]);
|
|
14377
|
+
return [...byRequest.values()].flatMap((items) => {
|
|
14378
|
+
const identities = new Set(
|
|
14379
|
+
items.map(({ index: _index, ...identity }) => JSON.stringify(identity))
|
|
14380
|
+
);
|
|
14381
|
+
if (identities.size !== 1) return [];
|
|
14382
|
+
return [
|
|
14383
|
+
items.reduce(
|
|
14384
|
+
(earliest, item) => item.index < earliest.index ? item : earliest
|
|
14385
|
+
)
|
|
14386
|
+
];
|
|
14387
|
+
}).filter((receipt) => receipt.ownerSessionId === ownerSessionId).sort((a, b) => a.index - b.index);
|
|
14388
|
+
}
|
|
14389
|
+
function acceptedAssignmentReceipts(entries, ownerSessionId, child) {
|
|
14390
|
+
let path;
|
|
14391
|
+
try {
|
|
14392
|
+
path = canonicalSessionPath(child.path);
|
|
14393
|
+
} catch {
|
|
14394
|
+
return [];
|
|
14395
|
+
}
|
|
14396
|
+
return acceptedAssignmentEvidence(entries, ownerSessionId).filter(
|
|
14397
|
+
(receipt) => receipt.sessionId === child.id && receipt.sessionPath === path && receipt.agent === child.label && receipt.definition === child.definition
|
|
14398
|
+
).map(({ index, requestId }) => ({ index, requestId }));
|
|
13972
14399
|
}
|
|
13973
14400
|
function closedAssignmentChildren(entries, ownerSessionId) {
|
|
13974
14401
|
const candidates = ownedAssignmentChildren(entries, ownerSessionId, true);
|
|
@@ -14141,13 +14568,15 @@ function statusBreadcrumb(snapshot, candidate, identity, sameIdentity) {
|
|
|
14141
14568
|
return [
|
|
14142
14569
|
{ text: "?" },
|
|
14143
14570
|
{
|
|
14144
|
-
text: identity.definition && identity.label ? displayIdentity(identity.definition, identity.label) : identity.definition ?? "?"
|
|
14571
|
+
text: identity.definition && identity.label ? displayIdentity(identity.definition, identity.label) : identity.definition ?? "?",
|
|
14572
|
+
...identity.definition ? { role: identity.definition } : {}
|
|
14145
14573
|
}
|
|
14146
14574
|
];
|
|
14147
14575
|
const definitions = [
|
|
14148
14576
|
{
|
|
14149
14577
|
text: displayIdentity(current.agentDefinition, current.state.agentLabel),
|
|
14150
|
-
sessionId: current.state.piSessionId
|
|
14578
|
+
sessionId: current.state.piSessionId,
|
|
14579
|
+
role: current.agentDefinition
|
|
14151
14580
|
}
|
|
14152
14581
|
];
|
|
14153
14582
|
const visited = /* @__PURE__ */ new Set([current.state.piSessionId]);
|
|
@@ -14164,7 +14593,8 @@ function statusBreadcrumb(snapshot, candidate, identity, sameIdentity) {
|
|
|
14164
14593
|
visited.add(parent.state.piSessionId);
|
|
14165
14594
|
definitions.push({
|
|
14166
14595
|
text: displayIdentity(parent.agentDefinition, parent.state.agentLabel),
|
|
14167
|
-
sessionId: parent.state.piSessionId
|
|
14596
|
+
sessionId: parent.state.piSessionId,
|
|
14597
|
+
role: parent.agentDefinition
|
|
14168
14598
|
});
|
|
14169
14599
|
ownerSessionId = parent.state.ownerSessionId;
|
|
14170
14600
|
continue;
|
|
@@ -14177,7 +14607,11 @@ function statusBreadcrumb(snapshot, candidate, identity, sameIdentity) {
|
|
|
14177
14607
|
(root2) => root2.sessionId === ownerSessionId
|
|
14178
14608
|
);
|
|
14179
14609
|
return roots.length === 1 ? [
|
|
14180
|
-
{
|
|
14610
|
+
{
|
|
14611
|
+
text: roots[0].role,
|
|
14612
|
+
sessionId: ownerSessionId,
|
|
14613
|
+
role: roots[0].role
|
|
14614
|
+
},
|
|
14181
14615
|
...definitions.reverse()
|
|
14182
14616
|
] : [{ text: "?" }, ...definitions.reverse()];
|
|
14183
14617
|
}
|
|
@@ -14541,34 +14975,25 @@ function ownedAssignmentResult(entry, ownerSessionId, unavailable) {
|
|
|
14541
14975
|
label: data.agentLabel
|
|
14542
14976
|
};
|
|
14543
14977
|
}
|
|
14544
|
-
function ownedAssignmentToolResult(entry, ownerSessionId, unavailable) {
|
|
14545
|
-
if (!entry || typeof entry !== "object" || !("type" in entry) || entry.type !== "message" || !("message" in entry))
|
|
14546
|
-
return void 0;
|
|
14547
|
-
const message = entry.message;
|
|
14548
|
-
if (!message || typeof message !== "object" || !("role" in message) || message.role !== "toolResult" || !("toolName" in message) || message.toolName !== "delegate_agent" && message.toolName !== "continue_agent" && message.toolName !== "agent_delegate" && message.toolName !== "agent_continue" || "isError" in message && message.isError === true || !("details" in message))
|
|
14549
|
-
return void 0;
|
|
14550
|
-
const details = message.details;
|
|
14551
|
-
if (!details || typeof details !== "object" || Array.isArray(details) || !("ok" in details) || details.ok !== true || !("owner_session_id" in details) || details.owner_session_id !== ownerSessionId)
|
|
14552
|
-
return void 0;
|
|
14553
|
-
if (!("session_id" in details) || typeof details.session_id !== "string" || !validId(details.session_id) || !("session_path" in details) || typeof details.session_path !== "string" || !details.session_path.trim() || !("agent" in details) || typeof details.agent !== "string" || !details.agent.trim() || !("definition" in details) || typeof details.definition !== "string" || !details.definition.trim()) {
|
|
14554
|
-
unavailable();
|
|
14555
|
-
return void 0;
|
|
14556
|
-
}
|
|
14557
|
-
return {
|
|
14558
|
-
id: details.session_id,
|
|
14559
|
-
path: details.session_path,
|
|
14560
|
-
label: details.agent,
|
|
14561
|
-
definition: details.definition
|
|
14562
|
-
};
|
|
14563
|
-
}
|
|
14564
14978
|
function ownedAssignmentChildren(entries, ownerSessionId, includeReceipts = false, unavailable) {
|
|
14565
14979
|
const children = /* @__PURE__ */ new Map();
|
|
14566
|
-
|
|
14567
|
-
const
|
|
14568
|
-
|
|
14980
|
+
if (includeReceipts) {
|
|
14981
|
+
for (const receipt of acceptedAssignmentEvidence(
|
|
14982
|
+
entries,
|
|
14569
14983
|
ownerSessionId,
|
|
14570
|
-
|
|
14571
|
-
)
|
|
14984
|
+
unavailable
|
|
14985
|
+
)) {
|
|
14986
|
+
const child = {
|
|
14987
|
+
id: receipt.sessionId,
|
|
14988
|
+
path: receipt.sessionPath,
|
|
14989
|
+
definition: receipt.definition,
|
|
14990
|
+
label: receipt.agent
|
|
14991
|
+
};
|
|
14992
|
+
children.set(`${child.id}\0${child.path}`, child);
|
|
14993
|
+
}
|
|
14994
|
+
}
|
|
14995
|
+
for (const entry of entries) {
|
|
14996
|
+
const child = ownedAssignmentResult(entry, ownerSessionId, unavailable);
|
|
14572
14997
|
if (!child) continue;
|
|
14573
14998
|
try {
|
|
14574
14999
|
const path = canonicalSessionPath(child.path);
|
|
@@ -15454,7 +15879,7 @@ async function managedAgentSnapshots(pi, ctx, dependencies, signal, proveRoot =
|
|
|
15454
15879
|
const waitingForChildren = !!state.activeRequestId && pendingDirectChildWork && (lifecycleState === "idle" || lifecycleState === "done") && !completionPending && !handoffPending && !state.resultError;
|
|
15455
15880
|
const existingLiveProjection = waitingForChildren ? "blocked" : liveState;
|
|
15456
15881
|
const projectedState = completionPending || state.resultError ? "settling" : presence.kind === "lost" ? "lost" : presence.kind === "unknown" ? "unknown" : existingLiveProjection;
|
|
15457
|
-
const steerable = presence.kind === "live" && !state.pendingAskId && projectedState === "working";
|
|
15882
|
+
const steerable = presence.kind === "live" && !state.pendingAskId && (projectedState === "working" || waitingForChildren);
|
|
15458
15883
|
const now = Date.now();
|
|
15459
15884
|
const listed = {
|
|
15460
15885
|
label: state.agentLabel,
|
|
@@ -16225,6 +16650,15 @@ function createAgentController(pi, options) {
|
|
|
16225
16650
|
operation,
|
|
16226
16651
|
`Agent ${current.agentLabel}`
|
|
16227
16652
|
);
|
|
16653
|
+
if (kind === "steer" && readUnacknowledgedRequest(runtime.mailboxPath, current))
|
|
16654
|
+
fail(
|
|
16655
|
+
"agent_busy",
|
|
16656
|
+
"Agent has an unacknowledged control request",
|
|
16657
|
+
operation,
|
|
16658
|
+
{
|
|
16659
|
+
nextAction: "Resolve the pending control request before steering again."
|
|
16660
|
+
}
|
|
16661
|
+
);
|
|
16228
16662
|
if (current.lastAck) {
|
|
16229
16663
|
try {
|
|
16230
16664
|
removeRequest(runtime.mailboxPath, current.lastAck.requestId);
|
|
@@ -16264,11 +16698,67 @@ function createAgentController(pi, options) {
|
|
|
16264
16698
|
let acknowledgementObserved = false;
|
|
16265
16699
|
options.onChanged();
|
|
16266
16700
|
try {
|
|
16267
|
-
|
|
16268
|
-
|
|
16269
|
-
|
|
16270
|
-
|
|
16271
|
-
|
|
16701
|
+
let state;
|
|
16702
|
+
try {
|
|
16703
|
+
state = await waitForState(
|
|
16704
|
+
runtime.mailboxPath,
|
|
16705
|
+
(candidate) => candidate.lastAck?.requestId === requestId,
|
|
16706
|
+
{ timeoutMs: 5e3, signal }
|
|
16707
|
+
);
|
|
16708
|
+
} catch (error2) {
|
|
16709
|
+
if (kind !== "steer" || !["TimeoutError", "AbortError"].includes(error2?.name))
|
|
16710
|
+
throw error2;
|
|
16711
|
+
const reconcileRelease = tryClaimAssignmentLock(runtime.mailboxPath);
|
|
16712
|
+
if (!reconcileRelease)
|
|
16713
|
+
fail(
|
|
16714
|
+
"internal_failure",
|
|
16715
|
+
"Steering outcome is indeterminate; the assignment lock is occupied",
|
|
16716
|
+
operation
|
|
16717
|
+
);
|
|
16718
|
+
try {
|
|
16719
|
+
const current = readAgentState(runtime.mailboxPath);
|
|
16720
|
+
if (!current || !sameIdentity(current, {
|
|
16721
|
+
version: current.version,
|
|
16722
|
+
build: options.build,
|
|
16723
|
+
runId: runtime.runId,
|
|
16724
|
+
ownerSessionId: runtime.ownerSessionId,
|
|
16725
|
+
workspaceId: runtime.workspaceId,
|
|
16726
|
+
agentLabel: runtime.label,
|
|
16727
|
+
paneId: runtime.paneId,
|
|
16728
|
+
rootSessionId: runtime.rootSessionId,
|
|
16729
|
+
piSessionId: runtime.piSessionId ?? "",
|
|
16730
|
+
piSessionFile: runtime.piSessionFile,
|
|
16731
|
+
cwd: runtime.cwd,
|
|
16732
|
+
updatedAt: current.updatedAt
|
|
16733
|
+
}))
|
|
16734
|
+
fail(
|
|
16735
|
+
"internal_failure",
|
|
16736
|
+
"Steering outcome is indeterminate; agent identity changed",
|
|
16737
|
+
operation
|
|
16738
|
+
);
|
|
16739
|
+
if (current.lastAck?.requestId === requestId) state = current;
|
|
16740
|
+
else {
|
|
16741
|
+
const pending = readRequest(runtime.mailboxPath, requestId);
|
|
16742
|
+
if (!pending || !isDeepStrictEqual2(pending, request))
|
|
16743
|
+
fail(
|
|
16744
|
+
"internal_failure",
|
|
16745
|
+
"Steering outcome is indeterminate; the exact request is no longer present",
|
|
16746
|
+
operation
|
|
16747
|
+
);
|
|
16748
|
+
removeRequest(runtime.mailboxPath, requestId);
|
|
16749
|
+
fail(
|
|
16750
|
+
"agent_busy",
|
|
16751
|
+
"Steering request was cancelled before receiver acknowledgement",
|
|
16752
|
+
operation,
|
|
16753
|
+
{
|
|
16754
|
+
nextAction: "The instruction was not confirmed; refresh list_agents before deciding whether to steer again."
|
|
16755
|
+
}
|
|
16756
|
+
);
|
|
16757
|
+
}
|
|
16758
|
+
} finally {
|
|
16759
|
+
reconcileRelease();
|
|
16760
|
+
}
|
|
16761
|
+
}
|
|
16272
16762
|
if (!state || state.lastAck?.requestId !== requestId)
|
|
16273
16763
|
fail(
|
|
16274
16764
|
"internal_failure",
|
|
@@ -16411,18 +16901,22 @@ function createAgentController(pi, options) {
|
|
|
16411
16901
|
};
|
|
16412
16902
|
}
|
|
16413
16903
|
const operation = params.action;
|
|
16414
|
-
|
|
16904
|
+
const fallbackToSteer = operation === "interrupt" && controlState === "blocked" && agent.steerable === true;
|
|
16905
|
+
const kind = fallbackToSteer ? "steer" : operation;
|
|
16906
|
+
if (kind === "steer" && agent.steerable !== true) {
|
|
16907
|
+
const current = readAgentState(runtime.mailboxPath);
|
|
16908
|
+
const pendingRequest = current ? readUnacknowledgedRequest(runtime.mailboxPath, current) : void 0;
|
|
16909
|
+
const nextAction = current?.pendingAskId ? "Answer the pending ask_owner question with reply_agent." : controlState === "settling" || pendingRequest ? "Allow the current control or completion transition to finish." : controlState === "unknown" ? "Diagnose or recover the exact managed session before steering." : "Refresh list_agents after the underlying state changes and use steer_agent only when available_tools includes it.";
|
|
16415
16910
|
fail(
|
|
16416
16911
|
"agent_busy",
|
|
16417
16912
|
`Agent is not currently accepting steering: ${controlState}`,
|
|
16418
16913
|
"steer",
|
|
16419
|
-
{
|
|
16420
|
-
nextAction: "Refresh with list_agents and use steer_agent only when available_tools includes it."
|
|
16421
|
-
}
|
|
16914
|
+
{ nextAction }
|
|
16422
16915
|
);
|
|
16423
|
-
|
|
16424
|
-
|
|
16425
|
-
|
|
16916
|
+
}
|
|
16917
|
+
if (kind === "steer" && !runtime.activeRequestId)
|
|
16918
|
+
fail("agent_busy", "Agent has no active assignment", operation);
|
|
16919
|
+
if (operation === "interrupt" && controlState !== "working" && !fallbackToSteer)
|
|
16426
16920
|
fail(
|
|
16427
16921
|
"agent_busy",
|
|
16428
16922
|
`Agent has no interruptible active operation: ${controlState}`,
|
|
@@ -16431,7 +16925,7 @@ function createAgentController(pi, options) {
|
|
|
16431
16925
|
nextAction: "Use interrupt_agent only when available_tools includes it. Use steer_agent for non-preemptive assignment changes."
|
|
16432
16926
|
}
|
|
16433
16927
|
);
|
|
16434
|
-
if (
|
|
16928
|
+
if (operation === "interrupt" && !runtime.activeRequestId)
|
|
16435
16929
|
fail("agent_busy", "Agent has no active assignment", operation);
|
|
16436
16930
|
let askId;
|
|
16437
16931
|
let createdAt = Date.now();
|
|
@@ -16475,7 +16969,6 @@ function createAgentController(pi, options) {
|
|
|
16475
16969
|
"reply"
|
|
16476
16970
|
);
|
|
16477
16971
|
}
|
|
16478
|
-
const kind = operation;
|
|
16479
16972
|
const limits = readConfig();
|
|
16480
16973
|
const manager = await options.managerEvidence?.(
|
|
16481
16974
|
context,
|
|
@@ -16530,6 +17023,10 @@ function createAgentController(pi, options) {
|
|
|
16530
17023
|
return {
|
|
16531
17024
|
ok: true,
|
|
16532
17025
|
action: operation,
|
|
17026
|
+
...fallbackToSteer ? {
|
|
17027
|
+
delivered_as: "steer",
|
|
17028
|
+
note: "Agent was waiting for child work. Message delivered via steering; nothing was interrupted."
|
|
17029
|
+
} : {},
|
|
16533
17030
|
agent: runtime.label,
|
|
16534
17031
|
presentation_agent_definition: runtime.agentDefinition,
|
|
16535
17032
|
request_id: sentRequestId,
|
|
@@ -18802,14 +19299,16 @@ This batch was not embedded. Use read_evidence to retrieve the items relevant to
|
|
|
18802
19299
|
"PI_OFFLINE=1"
|
|
18803
19300
|
];
|
|
18804
19301
|
const registeredProviderIds = new Set(
|
|
18805
|
-
ctx.modelRegistry?.getRegisteredProviderIds?.() ?? []
|
|
19302
|
+
(ctx.modelRegistry?.getRegisteredProviderIds?.() ?? []).map(
|
|
19303
|
+
(id) => id.toLowerCase()
|
|
19304
|
+
)
|
|
18806
19305
|
);
|
|
18807
19306
|
const childModel = resolveChildModel({
|
|
18808
19307
|
configured: configuredModel(effectiveDefinition.frontmatter),
|
|
18809
19308
|
inherited: !resumed && ctx.model ? { provider: ctx.model.provider, token: modelToken(ctx.model) } : void 0,
|
|
18810
19309
|
saved: resumed?.savedModel,
|
|
18811
19310
|
savedUnresolved: resumed?.savedModelUnresolved,
|
|
18812
|
-
isForeignProvider: (providerId) => registeredProviderIds.has(providerId),
|
|
19311
|
+
isForeignProvider: (providerId) => registeredProviderIds.has(providerId.toLowerCase()),
|
|
18813
19312
|
isKnownModel: (provider, id) => ctx.modelRegistry.find(provider, id) !== void 0
|
|
18814
19313
|
});
|
|
18815
19314
|
if ((resumed?.savedModel || resumed?.savedModelUnresolved) && !configuredModel(effectiveDefinition.frontmatter))
|
|
@@ -19173,6 +19672,23 @@ ${result.stderr ?? ""}`.trim(),
|
|
|
19173
19672
|
}
|
|
19174
19673
|
);
|
|
19175
19674
|
accepted = true;
|
|
19675
|
+
let historyWarning;
|
|
19676
|
+
try {
|
|
19677
|
+
if (ctx.sessionManager.getSessionId() !== runtime.ownerSessionId)
|
|
19678
|
+
throw new Error("Owner session changed");
|
|
19679
|
+
pi.appendEntry(ACCEPTED_ASSIGNMENT_ENTRY, {
|
|
19680
|
+
version: 1,
|
|
19681
|
+
action: p.action,
|
|
19682
|
+
owner_session_id: runtime.ownerSessionId,
|
|
19683
|
+
session_id: runtime.piSessionId,
|
|
19684
|
+
session_path: runtime.piSessionFile,
|
|
19685
|
+
request_id: requestId,
|
|
19686
|
+
agent: label,
|
|
19687
|
+
definition: agentDefinition
|
|
19688
|
+
});
|
|
19689
|
+
} catch {
|
|
19690
|
+
historyWarning = "Assignment accepted, but its history receipt could not be saved. Historical continuation may be unavailable.";
|
|
19691
|
+
}
|
|
19176
19692
|
options.onChanged();
|
|
19177
19693
|
const inlineNames = new Set(
|
|
19178
19694
|
(assignmentInput?.attachments ?? []).filter((attachment) => attachment.inline && attachment.ref).map((attachment) => attachment.ref)
|
|
@@ -19199,7 +19715,8 @@ ${result.stderr ?? ""}`.trim(),
|
|
|
19199
19715
|
session_id: runtime.piSessionId,
|
|
19200
19716
|
session_path: runtime.piSessionFile,
|
|
19201
19717
|
request_id: requestId,
|
|
19202
|
-
evidence: evidenceReceipt
|
|
19718
|
+
evidence: evidenceReceipt,
|
|
19719
|
+
...historyWarning ? { history_warning: historyWarning } : {}
|
|
19203
19720
|
};
|
|
19204
19721
|
} catch (caught) {
|
|
19205
19722
|
if (historicalMailboxPreflightFailed) throw caught;
|
|
@@ -19375,7 +19892,7 @@ ${result.stderr ?? ""}`.trim(),
|
|
|
19375
19892
|
pi.registerTool({
|
|
19376
19893
|
name: "read_evidence",
|
|
19377
19894
|
label: "Read accepted evidence",
|
|
19378
|
-
exposure: "
|
|
19895
|
+
exposure: "direct",
|
|
19379
19896
|
description: "Read a bounded page from evidence accepted by this assigned project Lead.",
|
|
19380
19897
|
parameters: Type.Object(
|
|
19381
19898
|
{
|
|
@@ -19482,7 +19999,7 @@ ${result.stderr ?? ""}`.trim(),
|
|
|
19482
19999
|
{ agent: Type.String({ pattern: AGENT_LABEL_PATTERN.source }) },
|
|
19483
20000
|
{ additionalProperties: false }
|
|
19484
20001
|
);
|
|
19485
|
-
const agentExposure = "
|
|
20002
|
+
const agentExposure = "direct";
|
|
19486
20003
|
const agentExecutionMode = "sequential";
|
|
19487
20004
|
const agentTool = {
|
|
19488
20005
|
name: "list_agents",
|
|
@@ -19505,6 +20022,16 @@ ${result.stderr ?? ""}`.trim(),
|
|
|
19505
20022
|
p = raw;
|
|
19506
20023
|
presentationAction = p.action;
|
|
19507
20024
|
const value2 = await action(ctx, p, signal);
|
|
20025
|
+
if (p.action === "stop" && value2.ok === true && value2.closed_assignment && value2.cleanup_error === void 0 && value2.cleanup_errors === void 0) {
|
|
20026
|
+
try {
|
|
20027
|
+
pi.appendEntry(STOP_CLOSURE_ENTRY, {
|
|
20028
|
+
version: 1,
|
|
20029
|
+
proof: value2.closed_assignment
|
|
20030
|
+
});
|
|
20031
|
+
} catch {
|
|
20032
|
+
value2.history_warning = "Agent stopped, but its clean-stop receipt could not be saved.";
|
|
20033
|
+
}
|
|
20034
|
+
}
|
|
19508
20035
|
options.onChanged();
|
|
19509
20036
|
if (controllerScope.kind === "root" && (p.action === "delegate" || p.action === "continue") && value2.ok === true)
|
|
19510
20037
|
onAssignmentStarted?.(ctx);
|
|
@@ -19602,6 +20129,7 @@ ${result.stderr ?? ""}`.trim(),
|
|
|
19602
20129
|
...agentTool,
|
|
19603
20130
|
name: "delegate_agent",
|
|
19604
20131
|
label: "delegate agent",
|
|
20132
|
+
exposure: "direct",
|
|
19605
20133
|
description: "Start one fresh bounded assignment. Choose the most focused eligible Agent definition capable of completing the full task. Use a general-purpose definition when broader capabilities are needed or no focused definition fits.",
|
|
19606
20134
|
parameters: agentDelegateParameters,
|
|
19607
20135
|
promptSnippet: void 0,
|
|
@@ -19620,6 +20148,7 @@ ${result.stderr ?? ""}`.trim(),
|
|
|
19620
20148
|
...agentTool,
|
|
19621
20149
|
name: "continue_agent",
|
|
19622
20150
|
label: "continue agent",
|
|
20151
|
+
exposure: "direct",
|
|
19623
20152
|
description: "Start one bounded assignment from an eligible historical managed-Agent Pi session selected by a directly owned result ref, exact path, or UUID. Retired sessions cannot be continued while context retirement is enabled.",
|
|
19624
20153
|
parameters: agentContinueParameters,
|
|
19625
20154
|
promptSnippet: void 0,
|
|
@@ -19656,7 +20185,7 @@ ${result.stderr ?? ""}`.trim(),
|
|
|
19656
20185
|
...agentTool,
|
|
19657
20186
|
name: "interrupt_agent",
|
|
19658
20187
|
label: "interrupt agent",
|
|
19659
|
-
description: "Cancel a live Agent's current Pi operation and continue the same assignment with replacement direction.",
|
|
20188
|
+
description: "Cancel a live Agent's current Pi operation and continue the same assignment with replacement direction. If the Agent is blocked waiting for verified direct-child work, the message is delivered via steering instead; no operation is interrupted.",
|
|
19660
20189
|
parameters: agentMessageParameters,
|
|
19661
20190
|
promptSnippet: void 0,
|
|
19662
20191
|
promptGuidelines: [FILE_HANDOFF_GUIDANCE],
|
|
@@ -20731,7 +21260,7 @@ function collectSessionUsage(ctx, ownedChildren, openOwnedSession, leadRoots = [
|
|
|
20731
21260
|
breakdown
|
|
20732
21261
|
};
|
|
20733
21262
|
}
|
|
20734
|
-
var delegationLockPath, claimDelegationLock, waitForDelegationLock, SHARED_AGENT_INSTRUCTIONS, INTEGRATION_SESSION_RETRY_MS, INTEGRATION_SESSION_RETRIES, HEALTH_STALE_AFTER_MS, HEALTH_STALE_SCAN_MS, HEALTH_STALE_DIAGNOSTIC_TIMEOUT_MS, HEALTH_STALE_DIAGNOSTIC_LINES, HEALTH_ATTENTION_REPEAT_MIN_MS, HEALTH_ATTENTION_FIRST_REPEAT_MS, AGENT_LABEL_PATTERN, validAgentLabel, modelToken, messageLimits, AGENT_DEFINITION_ENTRY, AGENT_EXECUTION_OWNERSHIP_GUIDANCE, AGENT_UNRESOLVED_GUIDANCE, AGENT_DELEGATION_GUIDANCE, AGENT_HANDOFF_GUIDANCE, LEAD_SCOPE_DESCRIPTION, DELEGATING_AGENT_SCOPE_DESCRIPTION, STOP_CLOSURE_ENTRY, RESULT_REF_ENTRY, TRANSCRIPT_MAX_BYTES, TRANSCRIPT_TOOL_RESULT_MAX_BYTES, TRANSCRIPT_TOOL_RESULT_OMISSION;
|
|
21263
|
+
var delegationLockPath, claimDelegationLock, waitForDelegationLock, SHARED_AGENT_INSTRUCTIONS, INTEGRATION_SESSION_RETRY_MS, INTEGRATION_SESSION_RETRIES, HEALTH_STALE_AFTER_MS, HEALTH_STALE_SCAN_MS, HEALTH_STALE_DIAGNOSTIC_TIMEOUT_MS, HEALTH_STALE_DIAGNOSTIC_LINES, HEALTH_ATTENTION_REPEAT_MIN_MS, HEALTH_ATTENTION_FIRST_REPEAT_MS, AGENT_LABEL_PATTERN, validAgentLabel, modelToken, messageLimits, AGENT_DEFINITION_ENTRY, AGENT_EXECUTION_OWNERSHIP_GUIDANCE, AGENT_UNRESOLVED_GUIDANCE, AGENT_DELEGATION_GUIDANCE, AGENT_HANDOFF_GUIDANCE, LEAD_SCOPE_DESCRIPTION, DELEGATING_AGENT_SCOPE_DESCRIPTION, STOP_CLOSURE_ENTRY, ACCEPTED_ASSIGNMENT_ENTRY, RESULT_REF_ENTRY, TRANSCRIPT_MAX_BYTES, TRANSCRIPT_TOOL_RESULT_MAX_BYTES, TRANSCRIPT_TOOL_RESULT_OMISSION;
|
|
20735
21264
|
var init_agent_controller = __esm({
|
|
20736
21265
|
"extension/agent-controller.ts"() {
|
|
20737
21266
|
"use strict";
|
|
@@ -20808,12 +21337,13 @@ Do not silently broaden scope or make an unapproved scope, architecture,
|
|
|
20808
21337
|
security, protocol, repository-boundary, product, or operational decision.
|
|
20809
21338
|
|
|
20810
21339
|
Use ask_owner only when a decision from your exact direct owner is genuinely
|
|
20811
|
-
required to continue correctly.
|
|
20812
|
-
|
|
20813
|
-
|
|
20814
|
-
|
|
20815
|
-
|
|
20816
|
-
|
|
21340
|
+
required to continue correctly. Explicit attachments must be supported UTF-8
|
|
21341
|
+
text fully embedded within the applicable per-file and complete-message
|
|
21342
|
+
budgets. Call ask_owner alone as the final tool call of the turn. Wait for the
|
|
21343
|
+
direct owner's reply only after the tool confirms the question was sent; if
|
|
21344
|
+
rejected, address the error or report a non-empty blocker. Keep at most one
|
|
21345
|
+
question outstanding. Do not guess the answer. The reply resumes the same
|
|
21346
|
+
assignment.
|
|
20817
21347
|
|
|
20818
21348
|
Treat inactivity as advisory, not proof of a hang. Preserve exact identity and
|
|
20819
21349
|
cleanup evidence on failure. Do not blindly retry destructive cleanup or
|
|
@@ -20874,6 +21404,7 @@ direct-agent work. If unresolved direct-agent work exists, every such agent
|
|
|
20874
21404
|
must itself be validly waiting on an owner answer; ordinary active or
|
|
20875
21405
|
pending-result agent work still blocks escalation.`;
|
|
20876
21406
|
STOP_CLOSURE_ENTRY = "pi-herdsman-agent-closed-assignment";
|
|
21407
|
+
ACCEPTED_ASSIGNMENT_ENTRY = "pi-herdsman-agent-accepted-assignment";
|
|
20877
21408
|
RESULT_REF_ENTRY = "pi-herdsman-result-ref";
|
|
20878
21409
|
TRANSCRIPT_MAX_BYTES = 16 * 1024;
|
|
20879
21410
|
TRANSCRIPT_TOOL_RESULT_MAX_BYTES = 4 * 1024;
|
|
@@ -20919,7 +21450,7 @@ __export(managed_agent_runtime_exports, {
|
|
|
20919
21450
|
sessionContextRetired: () => sessionContextRetired,
|
|
20920
21451
|
validateManagedAgentIdentity: () => validateManagedAgentIdentity
|
|
20921
21452
|
});
|
|
20922
|
-
import { isAbsolute as isAbsolute5, resolve as resolve5 } from "node:path";
|
|
21453
|
+
import { isAbsolute as isAbsolute5, join as join10, resolve as resolve5 } from "node:path";
|
|
20923
21454
|
import { existsSync as existsSync2, realpathSync as realpathSync5 } from "node:fs";
|
|
20924
21455
|
import { buildSessionProjection as buildSessionProjection2 } from "@earendil-works/pi-coding-agent";
|
|
20925
21456
|
import { contentText as contentText3 } from "@earendil-works/pi-ai";
|
|
@@ -21631,7 +22162,8 @@ function createManagedAgentLeafStatus(options) {
|
|
|
21631
22162
|
text: process.env.PI_HERDSMAN_AGENT_DEFINITION && process.env.PI_HERDSMAN_LABEL ? displayIdentity(
|
|
21632
22163
|
process.env.PI_HERDSMAN_AGENT_DEFINITION,
|
|
21633
22164
|
process.env.PI_HERDSMAN_LABEL
|
|
21634
|
-
) : process.env.PI_HERDSMAN_AGENT_DEFINITION ?? "?"
|
|
22165
|
+
) : process.env.PI_HERDSMAN_AGENT_DEFINITION ?? "?",
|
|
22166
|
+
...process.env.PI_HERDSMAN_AGENT_DEFINITION ? { role: process.env.PI_HERDSMAN_AGENT_DEFINITION } : {}
|
|
21635
22167
|
}
|
|
21636
22168
|
],
|
|
21637
22169
|
...ownToolsSnapshot(),
|
|
@@ -21643,6 +22175,9 @@ function createManagedAgentLeafStatus(options) {
|
|
|
21643
22175
|
};
|
|
21644
22176
|
return {
|
|
21645
22177
|
reset,
|
|
22178
|
+
invalidate() {
|
|
22179
|
+
widget?.invalidate();
|
|
22180
|
+
},
|
|
21646
22181
|
captureOwnTools(tools) {
|
|
21647
22182
|
ownTools = tools;
|
|
21648
22183
|
},
|
|
@@ -21670,7 +22205,9 @@ function createManagedAgentLeafStatus(options) {
|
|
|
21670
22205
|
if (activeGeneration === generation) focusInFlight = false;
|
|
21671
22206
|
});
|
|
21672
22207
|
},
|
|
21673
|
-
() => statusWidgetMaxRows
|
|
22208
|
+
() => statusWidgetMaxRows,
|
|
22209
|
+
void 0,
|
|
22210
|
+
() => options.getLocalActivity?.(ctx) ?? "unknown"
|
|
21674
22211
|
);
|
|
21675
22212
|
next.setSnapshot({
|
|
21676
22213
|
agents: [],
|
|
@@ -21682,7 +22219,8 @@ function createManagedAgentLeafStatus(options) {
|
|
|
21682
22219
|
text: process.env.PI_HERDSMAN_AGENT_DEFINITION && process.env.PI_HERDSMAN_LABEL ? displayIdentity(
|
|
21683
22220
|
process.env.PI_HERDSMAN_AGENT_DEFINITION,
|
|
21684
22221
|
process.env.PI_HERDSMAN_LABEL
|
|
21685
|
-
) : process.env.PI_HERDSMAN_AGENT_DEFINITION ?? "?"
|
|
22222
|
+
) : process.env.PI_HERDSMAN_AGENT_DEFINITION ?? "?",
|
|
22223
|
+
...process.env.PI_HERDSMAN_AGENT_DEFINITION ? { role: process.env.PI_HERDSMAN_AGENT_DEFINITION } : {}
|
|
21686
22224
|
}
|
|
21687
22225
|
],
|
|
21688
22226
|
...ownToolsSnapshot(),
|
|
@@ -21834,7 +22372,7 @@ function registerManagedAgentAttachHandoffTool(pi, execute) {
|
|
|
21834
22372
|
pi.registerTool({
|
|
21835
22373
|
name: ATTACH_HANDOFF_TOOL,
|
|
21836
22374
|
label: "Attach handoff evidence",
|
|
21837
|
-
exposure: "
|
|
22375
|
+
exposure: "direct",
|
|
21838
22376
|
promptSnippet: "Select reusable results for this assignment's final handoff",
|
|
21839
22377
|
description: "Select verified semantic result references for your eventual completion to your direct owner. This is non-blocking and does not send evidence now. Use only exact result:<agent>#<index> references; text-only mentions do not grant access.",
|
|
21840
22378
|
executionMode: "sequential",
|
|
@@ -21873,7 +22411,7 @@ function registerManagedAgentAskOwnerTool(pi, execute) {
|
|
|
21873
22411
|
exposure: "model-only",
|
|
21874
22412
|
promptSnippet: "Ask this managed agent's direct owner for a required decision",
|
|
21875
22413
|
promptGuidelines: [FILE_HANDOFF_GUIDANCE],
|
|
21876
|
-
description: "Ask your direct owner for a decision that is required to continue. Call this alone as the final tool call of the turn
|
|
22414
|
+
description: "Ask your direct owner for a decision that is required to continue. Call this alone as the final tool call of the turn. Wait for the reply only after the tool confirms the question was sent; if rejected, address the error or report a non-empty blocker. Only one question may be outstanding.",
|
|
21877
22415
|
executionMode: "sequential",
|
|
21878
22416
|
parameters: Type2.Object(
|
|
21879
22417
|
{
|
|
@@ -22484,7 +23022,7 @@ function registerManagedAgentSettlementHandlers(pi, execution, options) {
|
|
|
22484
23022
|
} : {
|
|
22485
23023
|
error: {
|
|
22486
23024
|
code: aborted ? "aborted" : handoffSelectionError || outcome === "error" ? "execution_error" : "empty_result",
|
|
22487
|
-
message: aborted ? "Agent execution was cancelled" : handoffSelectionError ? "Selected handoff evidence could not be verified" : outcome === "error" ? "Agent model execution failed" : "Agent produced no assistant text"
|
|
23025
|
+
message: aborted ? "Agent execution was cancelled" : handoffSelectionError ? "Selected handoff evidence could not be verified" : outcome === "error" ? "Agent model execution failed" : observation?.requestId === state.activeRequestId && observation.askOwnerCapacityError ? `Agent produced no assistant text. Earlier in this execution, ask_owner rejected its attachments: ${observation.askOwnerCapacityError}. The question was not sent.` : "Agent produced no assistant text"
|
|
22488
23026
|
}
|
|
22489
23027
|
},
|
|
22490
23028
|
contextUsage: ctx.getContextUsage(),
|
|
@@ -22636,6 +23174,8 @@ function registerManagedAgentShutdownHandler(pi, execution, options) {
|
|
|
22636
23174
|
});
|
|
22637
23175
|
}
|
|
22638
23176
|
function registerManagedAgentRuntime(pi, options) {
|
|
23177
|
+
let leafStatus;
|
|
23178
|
+
let getLocalActivity = () => "unknown";
|
|
22639
23179
|
pi.on("tool_call", (event) => {
|
|
22640
23180
|
if (event.toolName !== "bash" && event.toolName !== "powershell") return;
|
|
22641
23181
|
const tool = pi.getAllTools().find((candidate) => candidate.name === event.toolName);
|
|
@@ -22672,6 +23212,7 @@ function registerManagedAgentRuntime(pi, options) {
|
|
|
22672
23212
|
depth: agentDepth
|
|
22673
23213
|
};
|
|
22674
23214
|
options.statusRuntime.configure({
|
|
23215
|
+
getLocalActivity: (ctx) => getLocalActivity(ctx),
|
|
22675
23216
|
pendingStartEntries: () => controller.pendingStartEntries(),
|
|
22676
23217
|
hasPendingStart: (label) => controller.hasPendingStart(label),
|
|
22677
23218
|
clearPendingStart: (label, expected) => controller.clearPendingStart(label, expected),
|
|
@@ -22786,7 +23327,7 @@ This is the session-start definition snapshot. Use list_agents for live Agent st
|
|
|
22786
23327
|
});
|
|
22787
23328
|
const execution = createManagedAgentExecutionState();
|
|
22788
23329
|
const metadataPublisher = createManagedAgentMetadataPublisher(pi);
|
|
22789
|
-
|
|
23330
|
+
leafStatus = createManagedAgentLeafStatus({
|
|
22790
23331
|
snapshot: (ctx, signal) => managedAgentSnapshots(
|
|
22791
23332
|
pi,
|
|
22792
23333
|
ctx,
|
|
@@ -22800,6 +23341,7 @@ This is the session-start definition snapshot. Use list_agents for live Agent st
|
|
|
22800
23341
|
identity: (ctx) => managedAgentEnvironmentIdentity(ctx, options.build),
|
|
22801
23342
|
sameIdentity: sameManagedAgentIdentity,
|
|
22802
23343
|
signal: () => metadataPublisher.signal,
|
|
23344
|
+
getLocalActivity: (ctx) => getLocalActivity(ctx),
|
|
22803
23345
|
focusTarget: async (ctx, intent, isCurrent) => {
|
|
22804
23346
|
if (intent.kind !== "session")
|
|
22805
23347
|
throw new Error("Manager navigation is unavailable from an Agent.");
|
|
@@ -22968,52 +23510,60 @@ This is the session-start definition snapshot. Use list_agents for live Agent st
|
|
|
22968
23510
|
};
|
|
22969
23511
|
}
|
|
22970
23512
|
);
|
|
22971
|
-
|
|
22972
|
-
|
|
22973
|
-
|
|
22974
|
-
|
|
22975
|
-
|
|
22976
|
-
|
|
22977
|
-
|
|
22978
|
-
|
|
22979
|
-
|
|
22980
|
-
|
|
22981
|
-
|
|
22982
|
-
|
|
22983
|
-
|
|
22984
|
-
|
|
22985
|
-
|
|
22986
|
-
|
|
22987
|
-
|
|
22988
|
-
|
|
22989
|
-
|
|
22990
|
-
|
|
22991
|
-
|
|
22992
|
-
requireInline: true,
|
|
22993
|
-
serializedBytes: (text, bindings) => askRecordBytes(state, askId, text, createdAt, bindings)
|
|
22994
|
-
}
|
|
22995
|
-
),
|
|
22996
|
-
checkMailboxSize: (bytes, limit) => {
|
|
22997
|
-
if (bytes > limit)
|
|
22998
|
-
fail(
|
|
22999
|
-
"invalid_request",
|
|
23000
|
-
`Mailbox payload is ${bytes} bytes; configured limit is ${limit} bytes`,
|
|
23001
|
-
"ask_owner"
|
|
23002
|
-
);
|
|
23003
|
-
},
|
|
23004
|
-
claimLock: (mailbox, state) => options.claimAssignmentLock(mailbox, "ask_owner", {
|
|
23005
|
-
label: state.agentLabel,
|
|
23006
|
-
paneId: state.paneId
|
|
23007
|
-
}),
|
|
23008
|
-
readState: readAgentState,
|
|
23009
|
-
writeState: writeAgentState,
|
|
23010
|
-
writeAsk,
|
|
23011
|
-
removeAsk,
|
|
23012
|
-
latest: (value2) => {
|
|
23013
|
-
execution.latest = value2;
|
|
23513
|
+
const executeAskOwner = createManagedAgentAskOwnerHandler({
|
|
23514
|
+
state: () => execution.assignment,
|
|
23515
|
+
setState: (state) => {
|
|
23516
|
+
execution.assignment = state;
|
|
23517
|
+
},
|
|
23518
|
+
sameIdentity: sameManagedAgentIdentity,
|
|
23519
|
+
eligible: requestState.eligibleToAsk,
|
|
23520
|
+
rejectionReason: requestState.askRejectionReason,
|
|
23521
|
+
isSoleToolCall: (ctx) => currentTurnIsSoleToolCall(ctx, "ask_owner"),
|
|
23522
|
+
messageLimits: options.messageLimits,
|
|
23523
|
+
prepare: async (ctx, question, files, state, askId, createdAt, limits) => prepareMessageInput(
|
|
23524
|
+
question,
|
|
23525
|
+
options.resolveMessageFiles(ctx, files, "ask_owner"),
|
|
23526
|
+
state.cwd,
|
|
23527
|
+
"ask_owner",
|
|
23528
|
+
"Question",
|
|
23529
|
+
{
|
|
23530
|
+
inlineLimitBytes: limits.inline.bytes,
|
|
23531
|
+
mailboxLimitBytes: limits.mailbox.bytes,
|
|
23532
|
+
requireInline: true,
|
|
23533
|
+
serializedBytes: (text, bindings) => askRecordBytes(state, askId, text, createdAt, bindings)
|
|
23014
23534
|
}
|
|
23015
|
-
|
|
23016
|
-
|
|
23535
|
+
),
|
|
23536
|
+
checkMailboxSize: (bytes, limit) => {
|
|
23537
|
+
if (bytes > limit)
|
|
23538
|
+
fail(
|
|
23539
|
+
"invalid_request",
|
|
23540
|
+
`Mailbox payload is ${bytes} bytes; configured limit is ${limit} bytes`,
|
|
23541
|
+
"ask_owner",
|
|
23542
|
+
{ details: { capacity: true } }
|
|
23543
|
+
);
|
|
23544
|
+
},
|
|
23545
|
+
claimLock: (mailbox, state) => options.claimAssignmentLock(mailbox, "ask_owner", {
|
|
23546
|
+
label: state.agentLabel,
|
|
23547
|
+
paneId: state.paneId
|
|
23548
|
+
}),
|
|
23549
|
+
readState: readAgentState,
|
|
23550
|
+
writeState: writeAgentState,
|
|
23551
|
+
writeAsk,
|
|
23552
|
+
removeAsk,
|
|
23553
|
+
latest: (value2) => {
|
|
23554
|
+
execution.latest = value2;
|
|
23555
|
+
}
|
|
23556
|
+
});
|
|
23557
|
+
registerManagedAgentAskOwnerTool(pi, async (...args) => {
|
|
23558
|
+
const observation = execution.observation;
|
|
23559
|
+
try {
|
|
23560
|
+
return await executeAskOwner(...args);
|
|
23561
|
+
} catch (error2) {
|
|
23562
|
+
if (error2 instanceof OperationError && error2.detail.operation === "ask_owner" && error2.detail.details?.capacity === true && observation?.requestId && observation === execution.observation && execution.assignment?.activeRequestId === observation.requestId && !execution.assignment.pendingAskId)
|
|
23563
|
+
observation.askOwnerCapacityError = error2.message.slice(0, 512);
|
|
23564
|
+
throw error2;
|
|
23565
|
+
}
|
|
23566
|
+
});
|
|
23017
23567
|
const prepareDelegatingRoster = async (ctx) => {
|
|
23018
23568
|
startupDefinitionRoster = void 0;
|
|
23019
23569
|
if (!delegationEnabled) return;
|
|
@@ -23151,6 +23701,10 @@ This is the session-start definition snapshot. Use list_agents for live Agent st
|
|
|
23151
23701
|
hasActiveAssignment: () => !!execution.assignment?.activeRequestId,
|
|
23152
23702
|
reportConfigError: (ctx, error2) => options.appendError(ctx, "pi_herdsman_config_error", error2)
|
|
23153
23703
|
});
|
|
23704
|
+
getLocalActivity = observeLocalHeaderActivity(pi, () => {
|
|
23705
|
+
options.statusRuntime.invalidateWidget();
|
|
23706
|
+
leafStatus?.invalidate();
|
|
23707
|
+
});
|
|
23154
23708
|
}
|
|
23155
23709
|
function createManagedAgentRequestState(pi, options) {
|
|
23156
23710
|
let requestPumpErrorReported = false;
|
|
@@ -23158,18 +23712,24 @@ function createManagedAgentRequestState(pi, options) {
|
|
|
23158
23712
|
const acknowledge = (requestId, accepted, code, message) => {
|
|
23159
23713
|
const state = options.state();
|
|
23160
23714
|
if (!state) return false;
|
|
23161
|
-
const
|
|
23162
|
-
|
|
23163
|
-
|
|
23164
|
-
|
|
23165
|
-
|
|
23166
|
-
|
|
23167
|
-
...
|
|
23168
|
-
|
|
23169
|
-
|
|
23170
|
-
|
|
23171
|
-
|
|
23172
|
-
|
|
23715
|
+
const mailbox = process.env.PI_HERDSMAN_MAILBOX;
|
|
23716
|
+
let requestPresent = false;
|
|
23717
|
+
const next = options.mutateState((current) => {
|
|
23718
|
+
if (!readRequest(mailbox, requestId)) return current;
|
|
23719
|
+
requestPresent = true;
|
|
23720
|
+
return {
|
|
23721
|
+
...current,
|
|
23722
|
+
lastAck: {
|
|
23723
|
+
requestId,
|
|
23724
|
+
accepted,
|
|
23725
|
+
...code ? { code } : {},
|
|
23726
|
+
...message ? { message } : {},
|
|
23727
|
+
acknowledgedAt: Date.now()
|
|
23728
|
+
},
|
|
23729
|
+
updatedAt: Date.now()
|
|
23730
|
+
};
|
|
23731
|
+
});
|
|
23732
|
+
if (requestPresent && next) {
|
|
23173
23733
|
acknowledgementErrorReported = false;
|
|
23174
23734
|
return true;
|
|
23175
23735
|
}
|
|
@@ -23184,6 +23744,7 @@ function createManagedAgentRequestState(pi, options) {
|
|
|
23184
23744
|
try {
|
|
23185
23745
|
const current = readAgentState(mailbox);
|
|
23186
23746
|
if (!current || !options.sameIdentity(current, state)) return;
|
|
23747
|
+
if (!existsSync2(join10(mailbox, `request-${requestId}.json`))) return;
|
|
23187
23748
|
const next = {
|
|
23188
23749
|
...current,
|
|
23189
23750
|
lastAck: {
|
|
@@ -23787,7 +24348,7 @@ import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
|
23787
24348
|
// package.json
|
|
23788
24349
|
var package_default = {
|
|
23789
24350
|
name: "pi-herdsman",
|
|
23790
|
-
version: "0.
|
|
24351
|
+
version: "0.43.0",
|
|
23791
24352
|
type: "module",
|
|
23792
24353
|
description: "Asynchronous Pi subagents and agent fleet orchestration for parallel coding agents with nested delegation, background work, and supervision in herdr.",
|
|
23793
24354
|
license: "Apache-2.0",
|
|
@@ -24107,7 +24668,7 @@ function requiredFiles(id, files, retained, cwd, operation) {
|
|
|
24107
24668
|
});
|
|
24108
24669
|
}
|
|
24109
24670
|
function createLeadProjectRuntime(host) {
|
|
24110
|
-
const stopClosureEntry =
|
|
24671
|
+
const stopClosureEntry = STOP_CLOSURE_ENTRY;
|
|
24111
24672
|
const stopClosureProof = (branch, ownerSessionId, closed) => {
|
|
24112
24673
|
return acceptedCloseProof(branch, ownerSessionId, closed);
|
|
24113
24674
|
};
|
|
@@ -25636,6 +26197,7 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
25636
26197
|
"HEAD"
|
|
25637
26198
|
]);
|
|
25638
26199
|
const targetHead = await output(targetPath, ["rev-parse", "HEAD"]);
|
|
26200
|
+
const initialTargetHead = targetHead;
|
|
25639
26201
|
const clean = async (path) => {
|
|
25640
26202
|
const status = await runGit(path, [
|
|
25641
26203
|
"status",
|
|
@@ -25695,8 +26257,34 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
25695
26257
|
return false;
|
|
25696
26258
|
throw new Error("Git ancestry could not be verified");
|
|
25697
26259
|
};
|
|
26260
|
+
const verifyPreviouslyIntegratedMerges = async (head) => {
|
|
26261
|
+
const history = await runGit(targetPath, [
|
|
26262
|
+
"log",
|
|
26263
|
+
"--format=%H %P",
|
|
26264
|
+
"--min-parents=2",
|
|
26265
|
+
"--ancestry-path",
|
|
26266
|
+
`${expectedHead}..${head}`
|
|
26267
|
+
]);
|
|
26268
|
+
if (history.code !== 0 || history.killed || history.stderr?.trim())
|
|
26269
|
+
return false;
|
|
26270
|
+
for (const line of String(history.stdout ?? "").trim().split("\n")) {
|
|
26271
|
+
if (!line) continue;
|
|
26272
|
+
const [mergeHead, ...parents] = line.split(/\s+/);
|
|
26273
|
+
if (!mergeHead || !/^[0-9a-f]{40,64}$/i.test(mergeHead) || parents.length < 2 || parents.some((parent) => !/^[0-9a-f]{40,64}$/i.test(parent)))
|
|
26274
|
+
return false;
|
|
26275
|
+
const firstParent = parents[0];
|
|
26276
|
+
if (await ancestry(expectedHead, firstParent)) continue;
|
|
26277
|
+
const includesAcceptedSource = await Promise.all(
|
|
26278
|
+
parents.slice(1).map((parent) => ancestry(expectedHead, parent))
|
|
26279
|
+
);
|
|
26280
|
+
if (!includesAcceptedSource.some(Boolean)) continue;
|
|
26281
|
+
return false;
|
|
26282
|
+
}
|
|
26283
|
+
return true;
|
|
26284
|
+
};
|
|
25698
26285
|
const initiallyIntegrated = await ancestry(expectedHead, targetHead);
|
|
25699
|
-
|
|
26286
|
+
const initiallyFastForwardable = initiallyIntegrated ? false : await ancestry(targetHead, expectedHead);
|
|
26287
|
+
if (!initiallyIntegrated && !initiallyFastForwardable && !permission().allowDivergence)
|
|
25700
26288
|
return {
|
|
25701
26289
|
content: [
|
|
25702
26290
|
{
|
|
@@ -25712,6 +26300,7 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
25712
26300
|
source_head: expectedHead,
|
|
25713
26301
|
target_head: targetHead,
|
|
25714
26302
|
status: "needs_update",
|
|
26303
|
+
reason: "divergent_fast_forward_only",
|
|
25715
26304
|
integrated: false,
|
|
25716
26305
|
checkout_removed: false,
|
|
25717
26306
|
assignment_retired: false
|
|
@@ -25758,7 +26347,27 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
25758
26347
|
"rev-parse",
|
|
25759
26348
|
"HEAD"
|
|
25760
26349
|
]);
|
|
25761
|
-
if (
|
|
26350
|
+
if (await ancestry(expectedHead, preStopTarget)) {
|
|
26351
|
+
if (!await verifyPreviouslyIntegratedMerges(preStopTarget))
|
|
26352
|
+
return {
|
|
26353
|
+
kind: "blocked",
|
|
26354
|
+
targetHead: preStopTarget,
|
|
26355
|
+
targetBranch,
|
|
26356
|
+
integrated: true,
|
|
26357
|
+
reason: "already_integrated_divergent_merge_unverified"
|
|
26358
|
+
};
|
|
26359
|
+
return {
|
|
26360
|
+
kind: "integrated",
|
|
26361
|
+
targetHead: preStopTarget,
|
|
26362
|
+
targetBranch,
|
|
26363
|
+
alreadyIntegrated: true
|
|
26364
|
+
};
|
|
26365
|
+
}
|
|
26366
|
+
const preStopFastForward = await ancestry(
|
|
26367
|
+
preStopTarget,
|
|
26368
|
+
expectedHead
|
|
26369
|
+
);
|
|
26370
|
+
if (!preStopFastForward && !permission().allowDivergence)
|
|
25762
26371
|
return {
|
|
25763
26372
|
kind: "tool-result",
|
|
25764
26373
|
result: {
|
|
@@ -25776,12 +26385,84 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
25776
26385
|
source_head: expectedHead,
|
|
25777
26386
|
target_head: preStopTarget,
|
|
25778
26387
|
status: "needs_update",
|
|
26388
|
+
reason: "divergent_fast_forward_only",
|
|
25779
26389
|
integrated: false,
|
|
25780
26390
|
checkout_removed: false,
|
|
25781
26391
|
assignment_retired: false
|
|
25782
26392
|
}
|
|
25783
26393
|
}
|
|
25784
26394
|
};
|
|
26395
|
+
let expectedMergeTree;
|
|
26396
|
+
if (!preStopFastForward) {
|
|
26397
|
+
if (preStopTarget !== initialTargetHead)
|
|
26398
|
+
return {
|
|
26399
|
+
kind: "blocked",
|
|
26400
|
+
targetHead: preStopTarget,
|
|
26401
|
+
targetBranch,
|
|
26402
|
+
integrated: false,
|
|
26403
|
+
reason: "target_changed_before_merge"
|
|
26404
|
+
};
|
|
26405
|
+
let preview;
|
|
26406
|
+
try {
|
|
26407
|
+
preview = await runGit(targetPath, [
|
|
26408
|
+
"merge-tree",
|
|
26409
|
+
"--write-tree",
|
|
26410
|
+
preStopTarget,
|
|
26411
|
+
expectedHead
|
|
26412
|
+
]);
|
|
26413
|
+
} catch {
|
|
26414
|
+
return {
|
|
26415
|
+
kind: "blocked",
|
|
26416
|
+
targetHead: preStopTarget,
|
|
26417
|
+
targetBranch,
|
|
26418
|
+
integrated: false,
|
|
26419
|
+
reason: operationSignal?.aborted ? "merge_preview_interrupted" : "merge_preview_unavailable"
|
|
26420
|
+
};
|
|
26421
|
+
}
|
|
26422
|
+
if (preview.killed || operationSignal?.aborted)
|
|
26423
|
+
return {
|
|
26424
|
+
kind: "blocked",
|
|
26425
|
+
targetHead: preStopTarget,
|
|
26426
|
+
targetBranch,
|
|
26427
|
+
integrated: false,
|
|
26428
|
+
reason: "merge_preview_interrupted"
|
|
26429
|
+
};
|
|
26430
|
+
if (preview.code === 1)
|
|
26431
|
+
return {
|
|
26432
|
+
kind: "tool-result",
|
|
26433
|
+
result: {
|
|
26434
|
+
content: [
|
|
26435
|
+
{
|
|
26436
|
+
type: "text",
|
|
26437
|
+
text: `Branch ${branch} conflicts with target ${targetBranch}; the Lead was not stopped and neither checkout was changed.`
|
|
26438
|
+
}
|
|
26439
|
+
],
|
|
26440
|
+
details: {
|
|
26441
|
+
ok: false,
|
|
26442
|
+
action: "merge",
|
|
26443
|
+
branch,
|
|
26444
|
+
target_branch: targetBranch,
|
|
26445
|
+
source_head: expectedHead,
|
|
26446
|
+
target_head: preStopTarget,
|
|
26447
|
+
status: "needs_update",
|
|
26448
|
+
reason: "merge_conflict",
|
|
26449
|
+
integrated: false,
|
|
26450
|
+
checkout_removed: false,
|
|
26451
|
+
assignment_retired: false
|
|
26452
|
+
}
|
|
26453
|
+
}
|
|
26454
|
+
};
|
|
26455
|
+
const tree = String(preview.stdout ?? "").trim();
|
|
26456
|
+
if (preview.code !== 0 || !/^[0-9a-f]{40,64}$/i.test(tree))
|
|
26457
|
+
return {
|
|
26458
|
+
kind: "blocked",
|
|
26459
|
+
targetHead: preStopTarget,
|
|
26460
|
+
targetBranch,
|
|
26461
|
+
integrated: false,
|
|
26462
|
+
reason: "merge_preview_unavailable"
|
|
26463
|
+
};
|
|
26464
|
+
expectedMergeTree = tree;
|
|
26465
|
+
}
|
|
25785
26466
|
if (current.liveLead)
|
|
25786
26467
|
await stopExecution(
|
|
25787
26468
|
current.assignment.id,
|
|
@@ -25836,14 +26517,23 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
25836
26517
|
throw new Error(
|
|
25837
26518
|
"Primary target branch changed before integration"
|
|
25838
26519
|
);
|
|
25839
|
-
if (await ancestry(expectedHead, currentTarget))
|
|
26520
|
+
if (await ancestry(expectedHead, currentTarget)) {
|
|
26521
|
+
if (!await verifyPreviouslyIntegratedMerges(currentTarget))
|
|
26522
|
+
return {
|
|
26523
|
+
kind: "blocked",
|
|
26524
|
+
targetHead: currentTarget,
|
|
26525
|
+
targetBranch,
|
|
26526
|
+
integrated: true,
|
|
26527
|
+
reason: "already_integrated_divergent_merge_unverified"
|
|
26528
|
+
};
|
|
25840
26529
|
return {
|
|
25841
26530
|
kind: "integrated",
|
|
25842
26531
|
targetHead: currentTarget,
|
|
25843
26532
|
targetBranch,
|
|
25844
26533
|
alreadyIntegrated: true
|
|
25845
26534
|
};
|
|
25846
|
-
|
|
26535
|
+
}
|
|
26536
|
+
if (!await ancestry(currentTarget, expectedHead) && !permission().allowDivergence)
|
|
25847
26537
|
return {
|
|
25848
26538
|
kind: "tool-result",
|
|
25849
26539
|
result: {
|
|
@@ -25867,14 +26557,22 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
25867
26557
|
}
|
|
25868
26558
|
}
|
|
25869
26559
|
};
|
|
25870
|
-
if (!
|
|
26560
|
+
if (!preStopFastForward && currentTarget !== preStopTarget)
|
|
26561
|
+
return {
|
|
26562
|
+
kind: "blocked",
|
|
26563
|
+
targetHead: currentTarget,
|
|
26564
|
+
targetBranch,
|
|
26565
|
+
integrated: false,
|
|
26566
|
+
reason: "target_changed_before_merge"
|
|
26567
|
+
};
|
|
26568
|
+
if (!permission().enabled || !preStopFastForward && !permission().allowDivergence)
|
|
25871
26569
|
throw new Error(
|
|
25872
26570
|
"Manager local merge permission was revoked"
|
|
25873
26571
|
);
|
|
25874
26572
|
let mergeError;
|
|
25875
26573
|
const merged = await runGit(targetPath, [
|
|
25876
26574
|
"merge",
|
|
25877
|
-
"--ff-only",
|
|
26575
|
+
...preStopFastForward ? ["--ff-only"] : ["--no-ff", "--no-edit", "-s", "ort"],
|
|
25878
26576
|
"--no-autostash",
|
|
25879
26577
|
"--no-overwrite-ignore",
|
|
25880
26578
|
expectedHead
|
|
@@ -25908,6 +26606,20 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
25908
26606
|
["merge-base", "--is-ancestor", expectedHead, "HEAD"],
|
|
25909
26607
|
{ cwd: targetPath, timeout: 1e4 }
|
|
25910
26608
|
);
|
|
26609
|
+
const parents = !preStopFastForward ? await host.pi.exec(
|
|
26610
|
+
"git",
|
|
26611
|
+
["show", "-s", "--format=%P", "HEAD"],
|
|
26612
|
+
{ cwd: targetPath, timeout: 1e4 }
|
|
26613
|
+
) : void 0;
|
|
26614
|
+
const mergedTree = !preStopFastForward ? await host.pi.exec("git", ["rev-parse", "HEAD^{tree}"], {
|
|
26615
|
+
cwd: targetPath,
|
|
26616
|
+
timeout: 1e4
|
|
26617
|
+
}) : void 0;
|
|
26618
|
+
const containsOriginalTarget = !preStopFastForward ? await host.pi.exec(
|
|
26619
|
+
"git",
|
|
26620
|
+
["merge-base", "--is-ancestor", preStopTarget, "HEAD"],
|
|
26621
|
+
{ cwd: targetPath, timeout: 1e4 }
|
|
26622
|
+
) : void 0;
|
|
25911
26623
|
const observedBranch = await host.pi.exec(
|
|
25912
26624
|
"git",
|
|
25913
26625
|
["symbolic-ref", "--quiet", "--short", "HEAD"],
|
|
@@ -25944,13 +26656,14 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
25944
26656
|
const observedHead = observed.code === 0 && !observed.killed ? String(observed.stdout ?? "").trim() : "";
|
|
25945
26657
|
const integrationVerified = !!observedHead && containsAccepted.code === 0 && !containsAccepted.killed && observedBranch.code === 0 && !observedBranch.killed && !observedBranch.stderr?.trim() && String(observedBranch.stdout ?? "").trim() === targetBranch;
|
|
25946
26658
|
const gitStateClean = status.code === 0 && !status.killed && !status.stderr?.trim() && !status.stdout?.trim() && index.code === 0 && !index.killed && !index.stdout?.trim() && !stateUnknown && operationStates.length === 0;
|
|
25947
|
-
|
|
26659
|
+
const divergentVerified = preStopFastForward || !!parents && parents.code === 0 && !parents.killed && String(parents.stdout ?? "").trim() === `${preStopTarget} ${expectedHead}` && !!mergedTree && mergedTree.code === 0 && !mergedTree.killed && String(mergedTree.stdout ?? "").trim() === expectedMergeTree && containsOriginalTarget?.code === 0 && !containsOriginalTarget.killed;
|
|
26660
|
+
if (!integrationVerified || !gitStateClean || !divergentVerified || merged.code !== 0 && !interrupted)
|
|
25948
26661
|
return {
|
|
25949
26662
|
kind: "blocked",
|
|
25950
26663
|
targetHead: observedHead || currentTarget,
|
|
25951
26664
|
targetBranch,
|
|
25952
26665
|
integrated: integrationVerified,
|
|
25953
|
-
reason: !integrationVerified ? "accepted_revision_not_verified_after_merge" : `git_state_after_merge:${stateUnknown ? "unknown" : operationStates.join(",") || (index.stdout?.trim() ? "unmerged_index" : status.stdout?.trim() ? "dirty_worktree" : mergeError || merged.stderr || "merge_failed")}`
|
|
26666
|
+
reason: !integrationVerified ? "accepted_revision_not_verified_after_merge" : !divergentVerified ? "divergent_merge_verification_failed" : `git_state_after_merge:${stateUnknown ? "unknown" : operationStates.join(",") || (index.stdout?.trim() ? "unmerged_index" : status.stdout?.trim() ? "dirty_worktree" : mergeError || merged.stderr || "merge_failed")}`
|
|
25954
26667
|
};
|
|
25955
26668
|
return {
|
|
25956
26669
|
kind: "integrated",
|
|
@@ -26133,6 +26846,7 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
26133
26846
|
);
|
|
26134
26847
|
const presentationTask = operation.action === "resume" ? projectTaskSummary(currentAssignment.text) : void 0;
|
|
26135
26848
|
const id = operation.action === "resume" ? currentAssignment.id : operation.id;
|
|
26849
|
+
let resumeSenderEnvironment;
|
|
26136
26850
|
const resumeRecord = (text, resultBindings, createdAt) => ({
|
|
26137
26851
|
version: 2,
|
|
26138
26852
|
build: HERDSMAN_BUILD2,
|
|
@@ -26144,6 +26858,7 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
26144
26858
|
leadSessionId: id,
|
|
26145
26859
|
branch: currentAssignment.branch,
|
|
26146
26860
|
text,
|
|
26861
|
+
...resumeSenderEnvironment ? { senderEnvironment: resumeSenderEnvironment } : {},
|
|
26147
26862
|
...resultBindings.length ? { resultBindings: [...resultBindings] } : {},
|
|
26148
26863
|
createdAt
|
|
26149
26864
|
});
|
|
@@ -26151,6 +26866,7 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
26151
26866
|
let resumeEvidenceScope;
|
|
26152
26867
|
const prepareResumeHandoff = async () => {
|
|
26153
26868
|
if (operation.action !== "resume") return;
|
|
26869
|
+
resumeSenderEnvironment = await captureSenderEnvironment(host.pi, ctx);
|
|
26154
26870
|
resumeMessageId ??= randomUUID12();
|
|
26155
26871
|
try {
|
|
26156
26872
|
const handoff = await prepareStaffHandoffEvidence(
|
|
@@ -26219,6 +26935,7 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
26219
26935
|
leadSessionId: id,
|
|
26220
26936
|
branch: currentAssignment.branch,
|
|
26221
26937
|
text: "Project assignment ready.",
|
|
26938
|
+
...resumeSenderEnvironment ? { senderEnvironment: resumeSenderEnvironment } : {},
|
|
26222
26939
|
createdAt
|
|
26223
26940
|
});
|
|
26224
26941
|
};
|
|
@@ -26753,13 +27470,18 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
26753
27470
|
}
|
|
26754
27471
|
const definition = discoverRoleDefinition(
|
|
26755
27472
|
MANAGED_LEAD_DEFINITION_NAME,
|
|
26756
|
-
|
|
27473
|
+
{
|
|
27474
|
+
...projectTrusted ? { projectRoot: cwd } : {},
|
|
27475
|
+
onWarning: (message) => notifyDefinitionWarning(ctx, message)
|
|
27476
|
+
}
|
|
26757
27477
|
);
|
|
26758
27478
|
const body = expandAgentBodyFiles(definition.body, [], operationName);
|
|
26759
27479
|
const effectiveDefinition = body === definition.body ? definition : { ...definition, body };
|
|
26760
27480
|
if (body) promptPaths.push(...writePrivatePromptSnapshots([body]));
|
|
26761
27481
|
const registeredProviderIds = new Set(
|
|
26762
|
-
ctx.modelRegistry?.getRegisteredProviderIds?.() ?? []
|
|
27482
|
+
(ctx.modelRegistry?.getRegisteredProviderIds?.() ?? []).map(
|
|
27483
|
+
(id2) => id2.toLowerCase()
|
|
27484
|
+
)
|
|
26763
27485
|
);
|
|
26764
27486
|
const modelDecision = resolveChildModel({
|
|
26765
27487
|
configured: configuredModel(effectiveDefinition.frontmatter),
|
|
@@ -26769,7 +27491,7 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
26769
27491
|
} : void 0,
|
|
26770
27492
|
saved: operation.action === "resume" && savedModel?.kind === "resolved" ? savedModel.model : void 0,
|
|
26771
27493
|
savedUnresolved: operation.action === "resume" && (savedModel === void 0 || savedModel.kind === "unresolved"),
|
|
26772
|
-
isForeignProvider: (providerId) => registeredProviderIds.has(providerId),
|
|
27494
|
+
isForeignProvider: (providerId) => registeredProviderIds.has(providerId.toLowerCase()),
|
|
26773
27495
|
isKnownModel: (provider, modelId) => ctx.modelRegistry.find(provider, modelId) !== void 0
|
|
26774
27496
|
});
|
|
26775
27497
|
const launchArgs = agentLaunchArgs(effectiveDefinition, {
|
|
@@ -26930,7 +27652,8 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
26930
27652
|
`Lead ${assignment.id}`
|
|
26931
27653
|
);
|
|
26932
27654
|
assignment = await bindLeadSessionFile(assignment, lead, signal);
|
|
26933
|
-
if (operation.action !== "resume")
|
|
27655
|
+
if (operation.action !== "resume") {
|
|
27656
|
+
const senderEnvironment = await captureSenderEnvironment(host.pi, ctx);
|
|
26934
27657
|
writeChiefMessage2({
|
|
26935
27658
|
version: 2,
|
|
26936
27659
|
build: HERDSMAN_BUILD2,
|
|
@@ -26942,8 +27665,10 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
26942
27665
|
leadSessionId,
|
|
26943
27666
|
branch: assignment.branch,
|
|
26944
27667
|
text: "Project assignment ready.",
|
|
27668
|
+
...senderEnvironment ? { senderEnvironment } : {},
|
|
26945
27669
|
createdAt: Date.now()
|
|
26946
27670
|
});
|
|
27671
|
+
}
|
|
26947
27672
|
let rediscovered;
|
|
26948
27673
|
while (Date.now() < deadline) {
|
|
26949
27674
|
const exact = (await liveLead(ctx, assignment.id)).filter(
|
|
@@ -27564,6 +28289,7 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
27564
28289
|
throw error2;
|
|
27565
28290
|
}
|
|
27566
28291
|
try {
|
|
28292
|
+
const senderEnvironment = activeRole() === "manager" ? await captureSenderEnvironment(host.pi, ctx) : void 0;
|
|
27567
28293
|
const prepared = await prepareCoordinationInput(
|
|
27568
28294
|
ctx,
|
|
27569
28295
|
params.message,
|
|
@@ -27581,6 +28307,7 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
27581
28307
|
leadSessionId: reportSession(lead),
|
|
27582
28308
|
...initialAssignment ? { branch: initialAssignment.branch } : {},
|
|
27583
28309
|
text: candidate,
|
|
28310
|
+
...senderEnvironment ? { senderEnvironment } : {},
|
|
27584
28311
|
...resultBindings.length ? { resultBindings: [...resultBindings] } : {},
|
|
27585
28312
|
createdAt
|
|
27586
28313
|
})
|
|
@@ -27616,6 +28343,7 @@ Subsequent explicitly requested removals here can proceed without a per-removal
|
|
|
27616
28343
|
leadSessionId: reportSession(lead),
|
|
27617
28344
|
...initialAssignment ? { branch: initialAssignment.branch } : {},
|
|
27618
28345
|
text: prepared.text,
|
|
28346
|
+
...senderEnvironment ? { senderEnvironment } : {},
|
|
27619
28347
|
...prepared.resultBindings.length ? { resultBindings: prepared.resultBindings } : {},
|
|
27620
28348
|
createdAt
|
|
27621
28349
|
};
|
|
@@ -28003,6 +28731,7 @@ function parseGitWorktreeInventory(output) {
|
|
|
28003
28731
|
return void 0;
|
|
28004
28732
|
worktrees.push({
|
|
28005
28733
|
path,
|
|
28734
|
+
...!bare && head ? { head } : {},
|
|
28006
28735
|
...branch ? { branch } : {},
|
|
28007
28736
|
...detached ? { detached: true } : {},
|
|
28008
28737
|
...locked ? { locked: true } : {},
|
|
@@ -28013,6 +28742,43 @@ function parseGitWorktreeInventory(output) {
|
|
|
28013
28742
|
return void 0;
|
|
28014
28743
|
return worktrees;
|
|
28015
28744
|
}
|
|
28745
|
+
async function captureSenderEnvironment(pi, ctx) {
|
|
28746
|
+
const cwd = ctx.cwd;
|
|
28747
|
+
if (typeof cwd !== "string" || !isAbsolute6(cwd) || !cwd || Buffer.byteLength(cwd) > 1024)
|
|
28748
|
+
return void 0;
|
|
28749
|
+
try {
|
|
28750
|
+
const rootResult = await pi.exec("git", ["rev-parse", "--show-toplevel"], {
|
|
28751
|
+
cwd,
|
|
28752
|
+
signal: ctx.signal,
|
|
28753
|
+
timeout: 3e3
|
|
28754
|
+
});
|
|
28755
|
+
const root2 = String(rootResult.stdout ?? "").trim();
|
|
28756
|
+
if (rootResult.code !== 0 || rootResult.killed || rootResult.stderr?.trim() || !isAbsolute6(root2) || Buffer.byteLength(root2) > 1024)
|
|
28757
|
+
return { cwd };
|
|
28758
|
+
const inventoryResult = await pi.exec(
|
|
28759
|
+
"git",
|
|
28760
|
+
["worktree", "list", "--porcelain", "-z"],
|
|
28761
|
+
{ cwd, signal: ctx.signal, timeout: 3e3 }
|
|
28762
|
+
);
|
|
28763
|
+
if (inventoryResult.code !== 0 || inventoryResult.killed || inventoryResult.stderr?.trim())
|
|
28764
|
+
return { cwd };
|
|
28765
|
+
const matches = parseGitWorktreeInventory(String(inventoryResult.stdout ?? ""))?.filter(
|
|
28766
|
+
(entry2) => !entry2.prunable && sameDirectory(entry2.path, root2)
|
|
28767
|
+
) ?? [];
|
|
28768
|
+
const entry = matches.length === 1 ? matches[0] : void 0;
|
|
28769
|
+
if (!entry?.head || !entry.detached && !entry.branch) return { cwd };
|
|
28770
|
+
return {
|
|
28771
|
+
cwd,
|
|
28772
|
+
git: {
|
|
28773
|
+
worktreeRoot: root2,
|
|
28774
|
+
branch: entry.detached ? null : entry.branch,
|
|
28775
|
+
head: entry.head
|
|
28776
|
+
}
|
|
28777
|
+
};
|
|
28778
|
+
} catch {
|
|
28779
|
+
return { cwd };
|
|
28780
|
+
}
|
|
28781
|
+
}
|
|
28016
28782
|
|
|
28017
28783
|
// extension/lead/commands.ts
|
|
28018
28784
|
init_config();
|
|
@@ -28145,9 +28911,13 @@ function createLeadCommandRuntime(host) {
|
|
|
28145
28911
|
async openDefinitionsMenu(ctx) {
|
|
28146
28912
|
let selectedSection = "agents";
|
|
28147
28913
|
const selectedDefinitions = {};
|
|
28148
|
-
const loadDefinitions = async (section, includeProject = true) => section === "agents" ? (await host.contextAgentDefinitions(ctx)).definitions : discoverRoleDefinitions(
|
|
28149
|
-
includeProject && ctx.isProjectTrusted() ? { projectRoot: ctx.cwd } : {}
|
|
28150
|
-
|
|
28914
|
+
const loadDefinitions = async (section, includeProject = true, onWarning) => section === "agents" ? (await host.contextAgentDefinitions(ctx, onWarning)).definitions : discoverRoleDefinitions({
|
|
28915
|
+
...includeProject && ctx.isProjectTrusted() ? { projectRoot: ctx.cwd } : {},
|
|
28916
|
+
onWarning: (message) => {
|
|
28917
|
+
notifyDefinitionWarning(ctx, message);
|
|
28918
|
+
onWarning?.(message);
|
|
28919
|
+
}
|
|
28920
|
+
});
|
|
28151
28921
|
const resolveDefinition = async (name) => {
|
|
28152
28922
|
const loaded = await loadDefinitions(
|
|
28153
28923
|
isReservedRoleDefinition(name) ? "roles" : "agents"
|
|
@@ -28175,8 +28945,13 @@ function createLeadCommandRuntime(host) {
|
|
|
28175
28945
|
if (section !== "agents" && section !== "roles") return;
|
|
28176
28946
|
selectedSection = section;
|
|
28177
28947
|
definitionList: while (true) {
|
|
28178
|
-
const
|
|
28179
|
-
|
|
28948
|
+
const warnings = [];
|
|
28949
|
+
const availableDefinitions = await loadDefinitions(
|
|
28950
|
+
section,
|
|
28951
|
+
true,
|
|
28952
|
+
(message) => warnings.push(message)
|
|
28953
|
+
);
|
|
28954
|
+
if (!availableDefinitions.length && !warnings.length) {
|
|
28180
28955
|
ctx.ui.notify(
|
|
28181
28956
|
`No ${section === "agents" ? "Agent definitions" : "Coordinator profiles"} are available.`
|
|
28182
28957
|
);
|
|
@@ -28204,6 +28979,16 @@ function createLeadCommandRuntime(host) {
|
|
|
28204
28979
|
...typeof definition2.frontmatter.description === "string" ? { help: definition2.frontmatter.description } : {}
|
|
28205
28980
|
};
|
|
28206
28981
|
});
|
|
28982
|
+
let warningValue = "__definition_warnings__";
|
|
28983
|
+
while (availableDefinitions.some(({ name }) => name === warningValue))
|
|
28984
|
+
warningValue += "_";
|
|
28985
|
+
if (warnings.length)
|
|
28986
|
+
options.unshift({
|
|
28987
|
+
value: warningValue,
|
|
28988
|
+
label: `\u26A0 ${warnings.length} misplaced definition(s)`,
|
|
28989
|
+
description: "Select to inspect paths",
|
|
28990
|
+
help: warnings[0]
|
|
28991
|
+
});
|
|
28207
28992
|
const selected = await host.selectMenu(
|
|
28208
28993
|
ctx,
|
|
28209
28994
|
section === "agents" ? "Agents" : "Coordinators",
|
|
@@ -28212,6 +28997,10 @@ function createLeadCommandRuntime(host) {
|
|
|
28212
28997
|
);
|
|
28213
28998
|
if (selected === void 0) break definitionList;
|
|
28214
28999
|
if (!selected) continue;
|
|
29000
|
+
if (selected === warningValue) {
|
|
29001
|
+
for (const warning of warnings) ctx.ui.notify(warning, "warning");
|
|
29002
|
+
continue;
|
|
29003
|
+
}
|
|
28215
29004
|
const selectedEntry = availableDefinitions.find(
|
|
28216
29005
|
(definition2) => definition2.name === selected
|
|
28217
29006
|
);
|
|
@@ -28698,8 +29487,8 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
28698
29487
|
{
|
|
28699
29488
|
value: "manager-merge",
|
|
28700
29489
|
label: "Manager local merge",
|
|
28701
|
-
description: `Global ${config.managerMergeEnabled ? "
|
|
28702
|
-
help: "
|
|
29490
|
+
description: `Global ${config.managerMergeEnabled === "divergent" ? "conflict-free merges" : config.managerMergeEnabled ? "fast-forward only" : "off"}`,
|
|
29491
|
+
help: "Choose whether Managers may integrate accepted local branches only by fast-forward or also by clean divergent merge, with guarded cleanup."
|
|
28703
29492
|
},
|
|
28704
29493
|
{
|
|
28705
29494
|
value: "status-widget-rows",
|
|
@@ -28837,17 +29626,29 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
28837
29626
|
`Global ${key === "contextRetirement" ? "context retirement" : key === "autoActivateManager" ? "Manager auto-start" : "Manager Git setup confirmation skip"}: ${enabled ? "on" : "off"}`
|
|
28838
29627
|
);
|
|
28839
29628
|
} else if (selected === "manager-merge") {
|
|
28840
|
-
const
|
|
28841
|
-
|
|
29629
|
+
const current = host.readConfig().managerMergeEnabled;
|
|
29630
|
+
const choice = await host.selectMenu(
|
|
29631
|
+
ctx,
|
|
29632
|
+
"Global Manager local merge",
|
|
29633
|
+
[
|
|
29634
|
+
{ value: "off", label: "Off" },
|
|
29635
|
+
{ value: "fast-forward", label: "Fast-forward only" },
|
|
29636
|
+
{ value: "divergent", label: "Conflict-free merges" }
|
|
29637
|
+
],
|
|
29638
|
+
current === false ? "off" : current === true ? "fast-forward" : "divergent"
|
|
29639
|
+
);
|
|
29640
|
+
if (!choice) continue;
|
|
29641
|
+
const setting = choice === "off" ? false : choice === "fast-forward" ? true : "divergent";
|
|
29642
|
+
if (setting !== false && (current === false || setting === "divergent" && current !== "divergent")) {
|
|
28842
29643
|
const confirm = await ctx.ui.input(
|
|
28843
|
-
"Enable Manager
|
|
29644
|
+
setting === "divergent" ? "Enable conflict-free divergent Manager merges? Git may create a new merge commit, and successful integration can automatically remove the exact source worktree. Type enable to confirm." : "Enable fast-forward Manager integration and automatic cleanup of successfully integrated source worktrees. Type enable to confirm.",
|
|
28844
29645
|
void 0
|
|
28845
29646
|
);
|
|
28846
29647
|
if (confirm !== "enable") continue;
|
|
28847
29648
|
}
|
|
28848
|
-
host.updateConfig("managerMergeEnabled",
|
|
29649
|
+
host.updateConfig("managerMergeEnabled", setting);
|
|
28849
29650
|
ctx.ui.notify(
|
|
28850
|
-
`Global Manager local merge: ${
|
|
29651
|
+
`Global Manager local merge: ${setting === "divergent" ? "conflict-free merges" : setting ? "fast-forward only" : "off"}`
|
|
28851
29652
|
);
|
|
28852
29653
|
}
|
|
28853
29654
|
}
|
|
@@ -28912,8 +29713,8 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
28912
29713
|
...mergePolicy ? [
|
|
28913
29714
|
{
|
|
28914
29715
|
value: "merge-permission",
|
|
28915
|
-
label: `Manager local merge \xB7 ${mergePolicy.enabled ? "
|
|
28916
|
-
help: `Controls local
|
|
29716
|
+
label: `Manager local merge \xB7 ${!mergePolicy.enabled ? "off" : mergePolicy.allowDivergence ? "conflict-free merges" : "fast-forward only"} (${mergePolicy.source})`,
|
|
29717
|
+
help: `Controls local integration and guarded cleanup for verified repository ${mergePolicy.repoKey}.`
|
|
28917
29718
|
}
|
|
28918
29719
|
] : []
|
|
28919
29720
|
];
|
|
@@ -28959,18 +29760,19 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
28959
29760
|
[
|
|
28960
29761
|
{
|
|
28961
29762
|
value: "inherit",
|
|
28962
|
-
label: `Inherit global (${global3 ? "
|
|
29763
|
+
label: `Inherit global (${global3 === "divergent" ? "conflict-free merges" : global3 ? "fast-forward only" : "off"})`
|
|
28963
29764
|
},
|
|
28964
|
-
{ value: "
|
|
28965
|
-
{ value: "
|
|
29765
|
+
{ value: "off", label: "Off" },
|
|
29766
|
+
{ value: "fast-forward", label: "Fast-forward only" },
|
|
29767
|
+
{ value: "divergent", label: "Conflict-free merges" }
|
|
28966
29768
|
],
|
|
28967
|
-
current.source === "global" ? "inherit" : current.enabled ? "
|
|
29769
|
+
current.source === "global" ? "inherit" : !current.enabled ? "off" : current.allowDivergence ? "divergent" : "fast-forward"
|
|
28968
29770
|
);
|
|
28969
29771
|
if (!choice2) continue;
|
|
28970
|
-
const enabled = choice2 === "inherit" ? void 0 : choice2 === "
|
|
28971
|
-
if (enabled
|
|
29772
|
+
const enabled = choice2 === "inherit" ? void 0 : choice2 === "off" ? false : choice2 === "fast-forward" ? true : "divergent";
|
|
29773
|
+
if (enabled !== void 0 && enabled !== false && (current.source !== "repository" || !current.enabled || enabled === "divergent" && !current.allowDivergence)) {
|
|
28972
29774
|
const confirm = await ctx.ui.input(
|
|
28973
|
-
"
|
|
29775
|
+
enabled === "divergent" ? "Enable conflict-free divergent Manager merges? Git may create a new merge commit, and successful integration can automatically remove the exact source worktree. Type enable to confirm." : "Enable fast-forward Manager integration and automatic cleanup of successfully integrated source worktrees. Type enable to confirm.",
|
|
28974
29776
|
void 0
|
|
28975
29777
|
);
|
|
28976
29778
|
if (confirm !== "enable") continue;
|
|
@@ -28982,7 +29784,7 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
28982
29784
|
);
|
|
28983
29785
|
setManagerMergeOverride(mergePolicy.repoKey, enabled);
|
|
28984
29786
|
ctx.ui.notify(
|
|
28985
|
-
`Manager local merge ${enabled === void 0 ? "inherits global" : enabled ? "enabled" : "disabled"} for ${mergePolicy.repoKey}.`
|
|
29787
|
+
`Manager local merge ${enabled === void 0 ? "inherits global" : enabled === "divergent" ? "allows conflict-free merges" : enabled ? "allows fast-forward only" : "disabled"} for ${mergePolicy.repoKey}.`
|
|
28986
29788
|
);
|
|
28987
29789
|
continue;
|
|
28988
29790
|
}
|
|
@@ -29260,7 +30062,7 @@ import { lstatSync as lstatSync7, realpathSync as realpathSync7, statSync as sta
|
|
|
29260
30062
|
import {
|
|
29261
30063
|
dirname as dirname8,
|
|
29262
30064
|
isAbsolute as isAbsolute7,
|
|
29263
|
-
join as
|
|
30065
|
+
join as join13,
|
|
29264
30066
|
resolve as resolve7,
|
|
29265
30067
|
toNamespacedPath
|
|
29266
30068
|
} from "node:path";
|
|
@@ -29290,7 +30092,7 @@ import {
|
|
|
29290
30092
|
} from "node:fs";
|
|
29291
30093
|
import { createHash as createHash11, randomUUID as randomUUID13 } from "node:crypto";
|
|
29292
30094
|
import { spawn } from "node:child_process";
|
|
29293
|
-
import { join as
|
|
30095
|
+
import { join as join11 } from "node:path";
|
|
29294
30096
|
function peerRecoveryRequest(request, expectedDataRoot) {
|
|
29295
30097
|
return JSON.stringify({ ...request, expectedDataRoot });
|
|
29296
30098
|
}
|
|
@@ -29349,7 +30151,7 @@ function resolveRemotePeerOutboundRetry(outbound, status, snapshot) {
|
|
|
29349
30151
|
return { kind: "retry", envelope: JSON.stringify(envelope) };
|
|
29350
30152
|
}
|
|
29351
30153
|
function outboundDirectoryPath() {
|
|
29352
|
-
return
|
|
30154
|
+
return join11(herdsmanDataRoot(), "runtime", "peers-v2", "remote-outbound");
|
|
29353
30155
|
}
|
|
29354
30156
|
function outboundDirectory() {
|
|
29355
30157
|
const path = outboundDirectoryPath();
|
|
@@ -29360,7 +30162,7 @@ function outboundDirectory() {
|
|
|
29360
30162
|
function tryClaimRemotePeerOutbound(id) {
|
|
29361
30163
|
try {
|
|
29362
30164
|
return acquireProcessLock(
|
|
29363
|
-
|
|
30165
|
+
join11(outboundDirectory(), `${id}.delivery.lock`),
|
|
29364
30166
|
{ name: "peer outbound delivery" }
|
|
29365
30167
|
).release;
|
|
29366
30168
|
} catch (error2) {
|
|
@@ -29373,7 +30175,7 @@ function persistRemotePeerOutbound(outbound) {
|
|
|
29373
30175
|
const recordBytes = Buffer.byteLength(JSON.stringify(outbound), "utf8");
|
|
29374
30176
|
if (!UUID4.test(outbound.id) || frameBytes > PEER_TRANSPORT_FRAME_LIMIT_BYTES || recordBytes > OUTBOUND_RECORD_LIMIT_BYTES)
|
|
29375
30177
|
throw new Error("invalid remote peer outbound record");
|
|
29376
|
-
const path =
|
|
30178
|
+
const path = join11(outboundDirectory(), `${outbound.id}.json`);
|
|
29377
30179
|
writeFileSync6(path, `${JSON.stringify(outbound)}
|
|
29378
30180
|
`, {
|
|
29379
30181
|
encoding: "utf8",
|
|
@@ -29383,7 +30185,7 @@ function persistRemotePeerOutbound(outbound) {
|
|
|
29383
30185
|
});
|
|
29384
30186
|
}
|
|
29385
30187
|
function retargetRemotePeerOutbound(id, digest, recipientSession, envelope) {
|
|
29386
|
-
const path =
|
|
30188
|
+
const path = join11(outboundDirectory(), `${id}.json`);
|
|
29387
30189
|
const lock = acquireProcessLock(`${path}.lock`, {
|
|
29388
30190
|
name: "peer outbound update"
|
|
29389
30191
|
});
|
|
@@ -29429,7 +30231,7 @@ function loadRemotePeerOutbound(path, id) {
|
|
|
29429
30231
|
function readRemotePeerOutbound(id) {
|
|
29430
30232
|
if (!UUID4.test(id)) return void 0;
|
|
29431
30233
|
return loadRemotePeerOutbound(
|
|
29432
|
-
|
|
30234
|
+
join11(outboundDirectoryPath(), `${id}.json`),
|
|
29433
30235
|
id
|
|
29434
30236
|
);
|
|
29435
30237
|
}
|
|
@@ -29437,7 +30239,7 @@ function listRemotePeerOutbounds() {
|
|
|
29437
30239
|
const directory2 = outboundDirectory();
|
|
29438
30240
|
return readdirSync7(directory2).filter((name) => UUID4.test(name.slice(0, -5)) && name.endsWith(".json")).flatMap((name) => {
|
|
29439
30241
|
const outbound = loadRemotePeerOutbound(
|
|
29440
|
-
|
|
30242
|
+
join11(directory2, name),
|
|
29441
30243
|
name.slice(0, -5)
|
|
29442
30244
|
);
|
|
29443
30245
|
return outbound ? [outbound] : [];
|
|
@@ -29446,7 +30248,7 @@ function listRemotePeerOutbounds() {
|
|
|
29446
30248
|
function removeRemotePeerOutbound(id) {
|
|
29447
30249
|
if (!UUID4.test(id)) return;
|
|
29448
30250
|
try {
|
|
29449
|
-
unlinkSync10(
|
|
30251
|
+
unlinkSync10(join11(outboundDirectory(), `${id}.json`));
|
|
29450
30252
|
} catch (error2) {
|
|
29451
30253
|
if (error2.code !== "ENOENT") throw error2;
|
|
29452
30254
|
}
|
|
@@ -29618,7 +30420,7 @@ import {
|
|
|
29618
30420
|
unlinkSync as unlinkSync11,
|
|
29619
30421
|
writeFileSync as writeFileSync7
|
|
29620
30422
|
} from "node:fs";
|
|
29621
|
-
import { join as
|
|
30423
|
+
import { join as join12 } from "node:path";
|
|
29622
30424
|
function resolvePeerResultBindings(bindings, existingRefs) {
|
|
29623
30425
|
const accepted = [];
|
|
29624
30426
|
const conflicts = [];
|
|
@@ -29653,7 +30455,7 @@ function assertPeerDataRoot(actual, expected) {
|
|
|
29653
30455
|
throw new Error("peer endpoint data root does not match the active route");
|
|
29654
30456
|
}
|
|
29655
30457
|
function directory() {
|
|
29656
|
-
const path =
|
|
30458
|
+
const path = join12(herdsmanDataRoot(), "runtime", "peer-correspondences");
|
|
29657
30459
|
mkdirSync10(path, { recursive: true, mode: 448 });
|
|
29658
30460
|
chmodSync9(path, 448);
|
|
29659
30461
|
return path;
|
|
@@ -29674,7 +30476,7 @@ function valid(value2) {
|
|
|
29674
30476
|
);
|
|
29675
30477
|
}
|
|
29676
30478
|
function save(c) {
|
|
29677
|
-
const path =
|
|
30479
|
+
const path = join12(directory(), `${c.id}.json`);
|
|
29678
30480
|
const tmp = `${path}.${randomUUID14()}.tmp`;
|
|
29679
30481
|
writeFileSync7(tmp, `${JSON.stringify(c)}
|
|
29680
30482
|
`, {
|
|
@@ -29689,7 +30491,7 @@ function mutate(id, action) {
|
|
|
29689
30491
|
const deadline = Date.now() + 15e3;
|
|
29690
30492
|
while (!lock) {
|
|
29691
30493
|
try {
|
|
29692
|
-
lock = acquireProcessLock(
|
|
30494
|
+
lock = acquireProcessLock(join12(directory(), `${id}.lock`), {
|
|
29693
30495
|
name: "peer correspondence mutation"
|
|
29694
30496
|
});
|
|
29695
30497
|
} catch (error2) {
|
|
@@ -29752,7 +30554,7 @@ function storePeerCorrespondence(c) {
|
|
|
29752
30554
|
}
|
|
29753
30555
|
function readPeerCorrespondence(id) {
|
|
29754
30556
|
if (!ID.test(id)) throw new Error("invalid peer correspondence id");
|
|
29755
|
-
const path =
|
|
30557
|
+
const path = join12(
|
|
29756
30558
|
herdsmanDataRoot(),
|
|
29757
30559
|
"runtime",
|
|
29758
30560
|
"peer-correspondences",
|
|
@@ -29800,7 +30602,7 @@ function listPeerCorrespondences() {
|
|
|
29800
30602
|
return [];
|
|
29801
30603
|
try {
|
|
29802
30604
|
const c = JSON.parse(
|
|
29803
|
-
readFileSync10(
|
|
30605
|
+
readFileSync10(join12(directory(), name), "utf8")
|
|
29804
30606
|
);
|
|
29805
30607
|
return valid(c) ? [c] : [];
|
|
29806
30608
|
} catch {
|
|
@@ -30336,7 +31138,7 @@ function createLeadCoordinationRuntime(host) {
|
|
|
30336
31138
|
if (!recipientContext || !source) return false;
|
|
30337
31139
|
return canMessagePeer(source, recipientContext);
|
|
30338
31140
|
};
|
|
30339
|
-
const queuePeerRecord = async (text, targetSessionId, ctx, expectedSender, expectedTarget, recordId = randomUUID15(), createdAt = Date.now(), resultBindings = [], verifyEvidence) => {
|
|
31141
|
+
const queuePeerRecord = async (text, targetSessionId, ctx, expectedSender, expectedTarget, recordId = randomUUID15(), createdAt = Date.now(), resultBindings = [], verifyEvidence, capturedEnvironment) => {
|
|
30340
31142
|
if (controllerScope?.kind !== "root" || leadRuntime.chiefMode !== "inactive" || leadRuntime.roleSuspended)
|
|
30341
31143
|
throw new Error("Peer is unavailable in this role");
|
|
30342
31144
|
if (leadRuntime.controllerRole === "manager" && (!leadRuntime.managerLease || (await currentManager(ctx))?.leaseId !== leadRuntime.managerLease.descriptor.leaseId))
|
|
@@ -30389,6 +31191,7 @@ function createLeadCoordinationRuntime(host) {
|
|
|
30389
31191
|
"peer_message",
|
|
30390
31192
|
`peer ${target.piSessionId}`
|
|
30391
31193
|
);
|
|
31194
|
+
const senderEnvironment = capturedEnvironment === void 0 ? await captureSenderEnvironment(host.pi, ctx) : capturedEnvironment;
|
|
30392
31195
|
const record = {
|
|
30393
31196
|
version: 2,
|
|
30394
31197
|
build: HERDSMAN_BUILD2,
|
|
@@ -30400,6 +31203,7 @@ function createLeadCoordinationRuntime(host) {
|
|
|
30400
31203
|
leadSessionId: sender.piSessionId,
|
|
30401
31204
|
peerSource: senderContext,
|
|
30402
31205
|
text,
|
|
31206
|
+
...senderEnvironment ? { senderEnvironment } : {},
|
|
30403
31207
|
...resultBindings.length ? { resultBindings: [...resultBindings] } : {},
|
|
30404
31208
|
createdAt
|
|
30405
31209
|
};
|
|
@@ -30431,7 +31235,7 @@ function createLeadCoordinationRuntime(host) {
|
|
|
30431
31235
|
};
|
|
30432
31236
|
return !verifyEvidence && senderContext.role === "manager" && targetContext.role === "manager" ? publish() : withProjectAssignmentAuthority(publish);
|
|
30433
31237
|
};
|
|
30434
|
-
const queueChiefRecord = async (kind, text, ctx, recordId, createdAt = Date.now(), runtimeOverride, expectedSupervisor, resultBindings = [], verifyEvidence) => {
|
|
31238
|
+
const queueChiefRecord = async (kind, text, ctx, recordId, createdAt = Date.now(), runtimeOverride, expectedSupervisor, resultBindings = [], verifyEvidence, capturedEnvironment) => {
|
|
30435
31239
|
assertCurrentLeadCoordination(ctx);
|
|
30436
31240
|
if (leadRuntime.controllerRole === "manager" && (!leadRuntime.managerLease || (await currentManager(ctx))?.leaseId !== leadRuntime.managerLease.descriptor.leaseId))
|
|
30437
31241
|
throw new Error("Manager lease is no longer active");
|
|
@@ -30442,6 +31246,7 @@ function createLeadCoordinationRuntime(host) {
|
|
|
30442
31246
|
const leadSessionId = ctx.sessionManager.getSessionId();
|
|
30443
31247
|
if (chief.piSessionId === leadSessionId)
|
|
30444
31248
|
throw new Error("Supervisor target is invalid");
|
|
31249
|
+
const senderEnvironment = capturedEnvironment === void 0 ? await captureSenderEnvironment(host.pi, ctx) : capturedEnvironment;
|
|
30445
31250
|
const record = {
|
|
30446
31251
|
version: 2,
|
|
30447
31252
|
build: HERDSMAN_BUILD2,
|
|
@@ -30452,6 +31257,7 @@ function createLeadCoordinationRuntime(host) {
|
|
|
30452
31257
|
toSessionId: chief.piSessionId,
|
|
30453
31258
|
leadSessionId,
|
|
30454
31259
|
text,
|
|
31260
|
+
...senderEnvironment ? { senderEnvironment } : {},
|
|
30455
31261
|
...resultBindings.length ? { resultBindings: [...resultBindings] } : {},
|
|
30456
31262
|
createdAt
|
|
30457
31263
|
};
|
|
@@ -30645,6 +31451,7 @@ function createLeadCoordinationRuntime(host) {
|
|
|
30645
31451
|
const recordId = randomUUID15();
|
|
30646
31452
|
const createdAt = Date.now();
|
|
30647
31453
|
const evidenceScope = hasManagerEvidenceSelectors(params.files ?? []) ? await host.managerEvidence?.(ctx, params.files ?? []) : void 0;
|
|
31454
|
+
const senderEnvironment = await captureSenderEnvironment(host.pi, ctx);
|
|
30648
31455
|
const prepared = await prepareCoordinationInput(
|
|
30649
31456
|
ctx,
|
|
30650
31457
|
params.message,
|
|
@@ -30667,6 +31474,7 @@ function createLeadCoordinationRuntime(host) {
|
|
|
30667
31474
|
toSessionId: chief.piSessionId,
|
|
30668
31475
|
leadSessionId: ctx.sessionManager.getSessionId(),
|
|
30669
31476
|
text: candidate,
|
|
31477
|
+
...senderEnvironment ? { senderEnvironment } : {},
|
|
30670
31478
|
...resultBindings.length ? { resultBindings: [...resultBindings] } : {},
|
|
30671
31479
|
createdAt
|
|
30672
31480
|
})
|
|
@@ -30681,7 +31489,8 @@ function createLeadCoordinationRuntime(host) {
|
|
|
30681
31489
|
void 0,
|
|
30682
31490
|
void 0,
|
|
30683
31491
|
prepared.resultBindings,
|
|
30684
|
-
evidenceScope?.verify
|
|
31492
|
+
evidenceScope?.verify,
|
|
31493
|
+
senderEnvironment ?? null
|
|
30685
31494
|
);
|
|
30686
31495
|
};
|
|
30687
31496
|
if (evidenceScope) await evidenceScope.revalidate(queue);
|
|
@@ -31358,6 +32167,7 @@ ${receivedRefs.join("\n")}` : ""}`,
|
|
|
31358
32167
|
"Peer is unavailable or outside the permitted project scope. Run `list_peers` again."
|
|
31359
32168
|
);
|
|
31360
32169
|
const evidenceScope = hasManagerEvidenceSelectors(params.files ?? []) ? await host.managerEvidence?.(ctx, params.files ?? []) : void 0;
|
|
32170
|
+
const senderEnvironment = remoteRoute ? null : await captureSenderEnvironment(host.pi, ctx);
|
|
31361
32171
|
const prepared = await prepareCoordinationInput(
|
|
31362
32172
|
ctx,
|
|
31363
32173
|
params.message,
|
|
@@ -31381,6 +32191,7 @@ ${receivedRefs.join("\n")}` : ""}`,
|
|
|
31381
32191
|
leadSessionId: sender.piSessionId,
|
|
31382
32192
|
peerSource: remoteRoute && activeRole() === "lead" ? { role: "lead", remoteOrdinary: true } : submissionSource,
|
|
31383
32193
|
text: candidate,
|
|
32194
|
+
...senderEnvironment ? { senderEnvironment } : {},
|
|
31384
32195
|
...resultBindings.length ? { resultBindings: [...resultBindings] } : {},
|
|
31385
32196
|
createdAt
|
|
31386
32197
|
})
|
|
@@ -31585,7 +32396,8 @@ ${receivedRefs.join("\n")}` : ""}`,
|
|
|
31585
32396
|
recordId,
|
|
31586
32397
|
createdAt,
|
|
31587
32398
|
prepared.resultBindings,
|
|
31588
|
-
evidenceScope?.verify
|
|
32399
|
+
evidenceScope?.verify,
|
|
32400
|
+
senderEnvironment
|
|
31589
32401
|
);
|
|
31590
32402
|
};
|
|
31591
32403
|
if (evidenceScope) await evidenceScope.revalidate(queue);
|
|
@@ -31781,14 +32593,15 @@ ${receivedRefs.join("\n")}` : ""}`,
|
|
|
31781
32593
|
message.kind,
|
|
31782
32594
|
message.branch,
|
|
31783
32595
|
message.fromSessionId
|
|
31784
|
-
) + message.text,
|
|
32596
|
+
) + message.text + senderEnvironmentAnnotation(message.senderEnvironment),
|
|
31785
32597
|
display: true,
|
|
31786
32598
|
details: {
|
|
31787
32599
|
id: message.id,
|
|
31788
32600
|
repoKey: message.repoKey,
|
|
31789
32601
|
branch: message.branch,
|
|
31790
32602
|
fromSessionId: message.fromSessionId,
|
|
31791
|
-
kind: message.kind
|
|
32603
|
+
kind: message.kind,
|
|
32604
|
+
...message.senderEnvironment ? { senderEnvironment: message.senderEnvironment } : {}
|
|
31792
32605
|
}
|
|
31793
32606
|
},
|
|
31794
32607
|
backlog && !actionableFailure ? { triggerTurn: false } : { deliverAs: "followUp", triggerTurn: true }
|
|
@@ -31919,6 +32732,116 @@ function sessionLeadExecutionState(entries, sessionId) {
|
|
|
31919
32732
|
}
|
|
31920
32733
|
return state;
|
|
31921
32734
|
}
|
|
32735
|
+
async function readGitWorktreeState(git, cwd) {
|
|
32736
|
+
const status = (await git(cwd, [
|
|
32737
|
+
"--no-optional-locks",
|
|
32738
|
+
"status",
|
|
32739
|
+
"--porcelain=v2",
|
|
32740
|
+
"--branch",
|
|
32741
|
+
"-z",
|
|
32742
|
+
"--untracked-files=normal"
|
|
32743
|
+
])).split("\0");
|
|
32744
|
+
let headerEnd = 0;
|
|
32745
|
+
const headers = /* @__PURE__ */ new Map();
|
|
32746
|
+
while (headerEnd < status.length && status[headerEnd]?.startsWith("# ")) {
|
|
32747
|
+
const match = /^# (branch\.(?:head|oid)) (.*)$/u.exec(status[headerEnd]);
|
|
32748
|
+
if (match) headers.set(match[1], match[2]);
|
|
32749
|
+
headerEnd++;
|
|
32750
|
+
}
|
|
32751
|
+
const branchHead = headers.get("branch.head");
|
|
32752
|
+
const oid = headers.get("branch.oid");
|
|
32753
|
+
const checkedOutBranch = branchHead === "(detached)" ? "detached" : branchHead;
|
|
32754
|
+
if (!checkedOutBranch || checkedOutBranch === "(unknown)" || !/^(?:detached|[^\s\0]+)$/u.test(checkedOutBranch) || !oid || oid !== "(initial)" && !/^[0-9a-f]{40,64}$/iu.test(oid))
|
|
32755
|
+
return void 0;
|
|
32756
|
+
return {
|
|
32757
|
+
checkedOutBranch,
|
|
32758
|
+
dirty: status.slice(headerEnd).some((entry) => entry.length > 0),
|
|
32759
|
+
...oid === "(initial)" ? {} : { head: oid }
|
|
32760
|
+
};
|
|
32761
|
+
}
|
|
32762
|
+
async function observeGitChangeSummary(git, checkoutPath, repoKey, comparisonHead) {
|
|
32763
|
+
const root2 = (await git(checkoutPath, ["rev-parse", "--show-toplevel"])).trim();
|
|
32764
|
+
const common = resolve7(
|
|
32765
|
+
checkoutPath,
|
|
32766
|
+
(await git(checkoutPath, ["rev-parse", "--git-common-dir"])).trim()
|
|
32767
|
+
);
|
|
32768
|
+
if (!sameDirectory(root2, checkoutPath) || !sameDirectory(common, repoKey))
|
|
32769
|
+
return void 0;
|
|
32770
|
+
const state = await readGitWorktreeState(git, checkoutPath);
|
|
32771
|
+
if (!state) return void 0;
|
|
32772
|
+
let additions;
|
|
32773
|
+
let deletions;
|
|
32774
|
+
let changedFiles;
|
|
32775
|
+
let comparisonSha;
|
|
32776
|
+
if (state.head) {
|
|
32777
|
+
try {
|
|
32778
|
+
const head = (await comparisonHead()).trim();
|
|
32779
|
+
if (/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u.test(head)) {
|
|
32780
|
+
const bases = (await git(checkoutPath, ["merge-base", "--all", head, state.head])).trim().split(/\s+/u);
|
|
32781
|
+
if (bases.length === 1 && /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u.test(bases[0]))
|
|
32782
|
+
comparisonSha = bases[0];
|
|
32783
|
+
}
|
|
32784
|
+
} catch {
|
|
32785
|
+
}
|
|
32786
|
+
}
|
|
32787
|
+
if (comparisonSha) {
|
|
32788
|
+
try {
|
|
32789
|
+
const output = await git(checkoutPath, [
|
|
32790
|
+
"--no-optional-locks",
|
|
32791
|
+
"diff",
|
|
32792
|
+
"--numstat",
|
|
32793
|
+
"-z",
|
|
32794
|
+
"--find-renames",
|
|
32795
|
+
comparisonSha,
|
|
32796
|
+
"--"
|
|
32797
|
+
]);
|
|
32798
|
+
const records = output.split("\0");
|
|
32799
|
+
let valid2 = output === "" || output.endsWith("\0");
|
|
32800
|
+
if (valid2) records.pop();
|
|
32801
|
+
let added = 0, deleted = 0, files = 0;
|
|
32802
|
+
for (let i = 0; valid2 && i < records.length; ) {
|
|
32803
|
+
const match = /^(\d+|-)\t(\d+|-)\t(.*)$/su.exec(records[i++]);
|
|
32804
|
+
if (!match) {
|
|
32805
|
+
valid2 = false;
|
|
32806
|
+
break;
|
|
32807
|
+
}
|
|
32808
|
+
const [, a, d, path] = match;
|
|
32809
|
+
if (!path && (!records[i++] || !records[i++])) {
|
|
32810
|
+
valid2 = false;
|
|
32811
|
+
break;
|
|
32812
|
+
}
|
|
32813
|
+
if (a === "-" && d === "-") {
|
|
32814
|
+
files++;
|
|
32815
|
+
continue;
|
|
32816
|
+
}
|
|
32817
|
+
if (!/^\d+$/u.test(a) || !/^\d+$/u.test(d)) {
|
|
32818
|
+
valid2 = false;
|
|
32819
|
+
break;
|
|
32820
|
+
}
|
|
32821
|
+
added += Number(a);
|
|
32822
|
+
deleted += Number(d);
|
|
32823
|
+
files++;
|
|
32824
|
+
if (!Number.isSafeInteger(added) || !Number.isSafeInteger(deleted)) {
|
|
32825
|
+
valid2 = false;
|
|
32826
|
+
break;
|
|
32827
|
+
}
|
|
32828
|
+
}
|
|
32829
|
+
if (valid2) {
|
|
32830
|
+
additions = added;
|
|
32831
|
+
deletions = deleted;
|
|
32832
|
+
changedFiles = files;
|
|
32833
|
+
}
|
|
32834
|
+
} catch {
|
|
32835
|
+
}
|
|
32836
|
+
}
|
|
32837
|
+
return {
|
|
32838
|
+
dirty: state.dirty,
|
|
32839
|
+
additions,
|
|
32840
|
+
deletions,
|
|
32841
|
+
changedFiles,
|
|
32842
|
+
checkedOutBranch: state.checkedOutBranch
|
|
32843
|
+
};
|
|
32844
|
+
}
|
|
31922
32845
|
function createLeadShutdownRuntime(host) {
|
|
31923
32846
|
const isRoot = () => host.isRoot();
|
|
31924
32847
|
let shutDown = false;
|
|
@@ -32264,6 +33187,13 @@ function createLeadAgentEventRuntime(host) {
|
|
|
32264
33187
|
sections.pi_herdsman_role = host.roleCharter(ctx);
|
|
32265
33188
|
return;
|
|
32266
33189
|
}
|
|
33190
|
+
try {
|
|
33191
|
+
if (host.currentLeadAllowedTools?.() !== void 0)
|
|
33192
|
+
host.reconcileRoleTools?.();
|
|
33193
|
+
} catch (error2) {
|
|
33194
|
+
host.setActiveTools([]);
|
|
33195
|
+
throw error2;
|
|
33196
|
+
}
|
|
32267
33197
|
const activeLead = host.isActiveLead() && !host.isRoleSuspended();
|
|
32268
33198
|
const supervisorStateMessage2 = activeLead ? await host.prepareLeadSupervisorStateMessage(ctx) : void 0;
|
|
32269
33199
|
if (supervisorStateMessage2) host.sendMessage(supervisorStateMessage2);
|
|
@@ -32313,7 +33243,21 @@ This is the session-start definition snapshot. Use list_agents for live Agent st
|
|
|
32313
33243
|
reason: "Tool is unavailable in the active Chief profile."
|
|
32314
33244
|
};
|
|
32315
33245
|
}
|
|
32316
|
-
if (!host.isActiveManager())
|
|
33246
|
+
if (!host.isActiveManager()) {
|
|
33247
|
+
try {
|
|
33248
|
+
const allowed = host.currentLeadAllowedTools?.();
|
|
33249
|
+
if (!allowed || allowed.includes(event.toolName)) return void 0;
|
|
33250
|
+
} catch {
|
|
33251
|
+
return {
|
|
33252
|
+
block: true,
|
|
33253
|
+
reason: "Lead tool authorization is unavailable."
|
|
33254
|
+
};
|
|
33255
|
+
}
|
|
33256
|
+
return {
|
|
33257
|
+
block: true,
|
|
33258
|
+
reason: "Tool is unavailable in the active Lead profile."
|
|
33259
|
+
};
|
|
33260
|
+
}
|
|
32317
33261
|
try {
|
|
32318
33262
|
if ((host.currentManagerAllowedTools?.(ctx) ?? host.managerTools ?? []).includes(event.toolName))
|
|
32319
33263
|
return void 0;
|
|
@@ -32332,6 +33276,9 @@ This is the session-start definition snapshot. Use list_agents for live Agent st
|
|
|
32332
33276
|
}
|
|
32333
33277
|
function registerLeadRuntime(pi, options) {
|
|
32334
33278
|
const statusRuntime = createAgentStatusRuntime();
|
|
33279
|
+
let invalidateSupervisionWidget = () => {
|
|
33280
|
+
};
|
|
33281
|
+
let getLocalActivity = () => "unknown";
|
|
32335
33282
|
const leadRuntime = options.leadRuntime ?? createLeadRuntimeState();
|
|
32336
33283
|
const leadToolState = options.leadToolState ?? createLeadToolState(
|
|
32337
33284
|
() => pi.getAllTools(),
|
|
@@ -32343,6 +33290,7 @@ function registerLeadRuntime(pi, options) {
|
|
|
32343
33290
|
options.onLeadRuntimeReady?.(leadRuntime, leadToolState);
|
|
32344
33291
|
let leadExecution;
|
|
32345
33292
|
let sessionKind;
|
|
33293
|
+
let verifiedManagedAssignment;
|
|
32346
33294
|
let managedLifecycle = "unavailable";
|
|
32347
33295
|
let assignmentVerificationGeneration = 0;
|
|
32348
33296
|
let leadExecutionPending = false;
|
|
@@ -32354,10 +33302,10 @@ function registerLeadRuntime(pi, options) {
|
|
|
32354
33302
|
let inheritedProjection;
|
|
32355
33303
|
const prepareSupervisoryProfile = (ctx, role2) => {
|
|
32356
33304
|
const name = role2 === "manager" ? MANAGER_DEFINITION_NAME : CHIEF_DEFINITION_NAME;
|
|
32357
|
-
const definition = options.commandHost.discoverRoleDefinition(
|
|
32358
|
-
|
|
32359
|
-
|
|
32360
|
-
);
|
|
33305
|
+
const definition = options.commandHost.discoverRoleDefinition(name, {
|
|
33306
|
+
...ctx.isProjectTrusted() ? { projectRoot: ctx.cwd } : {},
|
|
33307
|
+
onWarning: (message) => notifyDefinitionWarning(ctx, message)
|
|
33308
|
+
});
|
|
32361
33309
|
const prepared = {
|
|
32362
33310
|
...definition,
|
|
32363
33311
|
body: expandAgentBodyFiles(definition.body, [], `${role2} role profile`)
|
|
@@ -32458,7 +33406,18 @@ function registerLeadRuntime(pi, options) {
|
|
|
32458
33406
|
validateRoleAgentDefinitionReferences(
|
|
32459
33407
|
profile.definition,
|
|
32460
33408
|
discoverAgentDefinitions(
|
|
32461
|
-
leadRuntime.leadContext.isProjectTrusted() ? {
|
|
33409
|
+
leadRuntime.leadContext.isProjectTrusted() ? {
|
|
33410
|
+
projectRoot: leadRuntime.leadContext.cwd,
|
|
33411
|
+
onWarning: (message) => notifyDefinitionWarning(
|
|
33412
|
+
leadRuntime.leadContext,
|
|
33413
|
+
message
|
|
33414
|
+
)
|
|
33415
|
+
} : {
|
|
33416
|
+
onWarning: (message) => notifyDefinitionWarning(
|
|
33417
|
+
leadRuntime.leadContext,
|
|
33418
|
+
message
|
|
33419
|
+
)
|
|
33420
|
+
}
|
|
32462
33421
|
)
|
|
32463
33422
|
);
|
|
32464
33423
|
return new Set(profile.definition.frontmatter.agents ?? []);
|
|
@@ -32599,6 +33558,10 @@ function registerLeadRuntime(pi, options) {
|
|
|
32599
33558
|
state: leadRuntime,
|
|
32600
33559
|
activeRole: () => activeLeadRole(leadRuntime),
|
|
32601
33560
|
pi,
|
|
33561
|
+
getLocalActivity: (ctx) => getLocalActivity(ctx),
|
|
33562
|
+
onActivityChange: (invalidate) => {
|
|
33563
|
+
invalidateSupervisionWidget = invalidate;
|
|
33564
|
+
},
|
|
32602
33565
|
isCurrentChief: (ctx) => leadRuntime.chiefMode === "active" && !!leadRuntime.chiefLease && leadRuntime.chiefLease.descriptor.piSessionId === ctx.sessionManager.getSessionId(),
|
|
32603
33566
|
currentManager: (...args) => roleTransitions.currentManager(...args),
|
|
32604
33567
|
resolveEffectiveSupervisor: (...args) => roleTransitions.resolveEffectiveSupervisor(...args),
|
|
@@ -32921,17 +33884,21 @@ function registerLeadRuntime(pi, options) {
|
|
|
32921
33884
|
return restrictLeadAgentTools(tools, policy, leadRuntime.leadContext);
|
|
32922
33885
|
};
|
|
32923
33886
|
if (!sessionKind) return [];
|
|
32924
|
-
|
|
32925
|
-
|
|
32926
|
-
|
|
32927
|
-
|
|
32928
|
-
|
|
33887
|
+
const managedRecoveryTools = () => leadRuntime.leadContext ? ownedAgentManagementTools(leadRuntime.leadContext) : [];
|
|
33888
|
+
if (sessionKind.kind === "managed") {
|
|
33889
|
+
if (managedLifecycle !== "assigned" || leadRuntime.roleSuspended || leadRuntime.chiefMode === "suspended" || leadExecutionPending || !leadExecution?.valid || !leadExecution.managed)
|
|
33890
|
+
return managedRecoveryTools();
|
|
33891
|
+
const definition = leadExecution.definition;
|
|
33892
|
+
const managedBaseline = definition.frontmatter.noTools === true && definition.frontmatter.tools === void 0 ? [] : baseline;
|
|
32929
33893
|
return restrict(
|
|
32930
33894
|
leadToolState.appendRegisteredTools(
|
|
32931
|
-
leadToolState.
|
|
33895
|
+
leadToolState.projectLeadTools(managedBaseline, definition),
|
|
32932
33896
|
["read_evidence"]
|
|
32933
33897
|
)
|
|
32934
33898
|
);
|
|
33899
|
+
}
|
|
33900
|
+
if (leadExecutionPending)
|
|
33901
|
+
return restrict(leadToolState.normalizeLeadTools([]));
|
|
32935
33902
|
if (!leadExecution)
|
|
32936
33903
|
return restrict(leadToolState.normalizeLeadTools(baseline));
|
|
32937
33904
|
if (!leadExecution.valid)
|
|
@@ -32951,6 +33918,7 @@ function registerLeadRuntime(pi, options) {
|
|
|
32951
33918
|
const roleTransitionControllerScope = { kind: "root" };
|
|
32952
33919
|
const roleTransitionServices = {
|
|
32953
33920
|
...roleHost,
|
|
33921
|
+
isManagedSession: () => sessionKind?.kind === "managed",
|
|
32954
33922
|
prepareSupervisoryProfile,
|
|
32955
33923
|
commitSupervisoryProfile,
|
|
32956
33924
|
currentSupervisoryProfile,
|
|
@@ -33342,10 +34310,14 @@ function registerLeadRuntime(pi, options) {
|
|
|
33342
34310
|
if (isLead && sessionKind?.kind === "managed") {
|
|
33343
34311
|
const previous = managedLifecycle;
|
|
33344
34312
|
try {
|
|
33345
|
-
await currentProjectAssignment(ctx);
|
|
34313
|
+
const assignment = await currentProjectAssignment(ctx);
|
|
34314
|
+
verifiedManagedAssignment = assignment ? { sessionId: sessionKind.sessionId, assignment } : void 0;
|
|
33346
34315
|
} catch {
|
|
34316
|
+
verifiedManagedAssignment = void 0;
|
|
33347
34317
|
}
|
|
33348
34318
|
if (previous !== managedLifecycle) roleTransitions.reconcileRoleTools();
|
|
34319
|
+
} else {
|
|
34320
|
+
verifiedManagedAssignment = void 0;
|
|
33349
34321
|
}
|
|
33350
34322
|
const snapshot = buildAgentStatusSnapshot(view, ctx, {
|
|
33351
34323
|
...options.statusSnapshotHost,
|
|
@@ -33435,14 +34407,124 @@ function registerLeadRuntime(pi, options) {
|
|
|
33435
34407
|
}
|
|
33436
34408
|
);
|
|
33437
34409
|
};
|
|
34410
|
+
let leadGitCache;
|
|
34411
|
+
let leadGitLastAttemptAt = 0;
|
|
34412
|
+
let leadGitSampling;
|
|
34413
|
+
let leadGitAbort;
|
|
34414
|
+
let leadGitGeneration = 0;
|
|
34415
|
+
let leadGitIdentity;
|
|
34416
|
+
let leadGitContext;
|
|
34417
|
+
const cancelLeadGitSampling = (resetRate = true) => {
|
|
34418
|
+
leadGitGeneration++;
|
|
34419
|
+
leadGitAbort?.abort();
|
|
34420
|
+
leadGitAbort = void 0;
|
|
34421
|
+
leadGitSampling = void 0;
|
|
34422
|
+
leadGitCache = void 0;
|
|
34423
|
+
leadGitIdentity = void 0;
|
|
34424
|
+
leadGitContext = void 0;
|
|
34425
|
+
if (resetRate) leadGitLastAttemptAt = 0;
|
|
34426
|
+
};
|
|
34427
|
+
const sameLeadGitIdentity = (left, right) => left.sessionId === right.sessionId && left.comparison === right.comparison && left.repoKey === right.repoKey && left.assignmentBranch === right.assignmentBranch && sameDirectory(left.checkoutPath, right.checkoutPath);
|
|
34428
|
+
const sampleLeadGit = (ctx, snapshot) => {
|
|
34429
|
+
const verified = verifiedManagedAssignment;
|
|
34430
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
34431
|
+
const assignment = verified?.assignment;
|
|
34432
|
+
const comparison = sessionKind?.kind === "managed" && managedLifecycle === "assigned" && verified?.sessionId === sessionId && !!assignment;
|
|
34433
|
+
if (activeLeadRole(leadRuntime) !== "lead" || !sessionKind || sessionKind.sessionId !== sessionId || snapshot.stale || snapshot.unavailable || !statusRuntime.isWidgetActive()) {
|
|
34434
|
+
cancelLeadGitSampling();
|
|
34435
|
+
return;
|
|
34436
|
+
}
|
|
34437
|
+
const identity = {
|
|
34438
|
+
sessionId,
|
|
34439
|
+
checkoutPath: ctx.cwd,
|
|
34440
|
+
comparison,
|
|
34441
|
+
...comparison ? { repoKey: assignment.repoKey, assignmentBranch: assignment.branch } : {}
|
|
34442
|
+
};
|
|
34443
|
+
if (leadGitIdentity && !sameLeadGitIdentity(leadGitIdentity, identity))
|
|
34444
|
+
cancelLeadGitSampling();
|
|
34445
|
+
leadGitIdentity = identity;
|
|
34446
|
+
leadGitContext = ctx;
|
|
34447
|
+
if (leadGitCache && !sameLeadGitIdentity(leadGitCache.identity, identity))
|
|
34448
|
+
leadGitCache = void 0;
|
|
34449
|
+
if (leadGitSampling) return;
|
|
34450
|
+
if (Date.now() - leadGitLastAttemptAt < 3e4) return;
|
|
34451
|
+
leadGitLastAttemptAt = Date.now();
|
|
34452
|
+
const generation = ++leadGitGeneration;
|
|
34453
|
+
const abort = new AbortController();
|
|
34454
|
+
leadGitAbort = abort;
|
|
34455
|
+
const contextSignal = ctx.signal;
|
|
34456
|
+
const abortFromContext = () => abort.abort(contextSignal?.reason);
|
|
34457
|
+
contextSignal?.addEventListener("abort", abortFromContext, { once: true });
|
|
34458
|
+
const deadline = setTimeout(() => abort.abort(), 15e3);
|
|
34459
|
+
deadline.unref?.();
|
|
34460
|
+
const stillCurrent = () => {
|
|
34461
|
+
const latest = statusRuntime.getSnapshot();
|
|
34462
|
+
return generation === leadGitGeneration && statusRuntime.isWidgetActive() && activeLeadRole(leadRuntime) === "lead" && sessionKind?.sessionId === identity.sessionId && ctx.sessionManager.getSessionId() === identity.sessionId && (!identity.comparison || managedLifecycle === "assigned" && verifiedManagedAssignment?.sessionId === identity.sessionId && verifiedManagedAssignment.assignment.repoKey === identity.repoKey && verifiedManagedAssignment.assignment.branch === identity.assignmentBranch) && sameDirectory(ctx.cwd, identity.checkoutPath) && !latest.stale && !latest.unavailable && leadGitIdentity !== void 0 && sameLeadGitIdentity(leadGitIdentity, identity);
|
|
34463
|
+
};
|
|
34464
|
+
const current = () => !abort.signal.aborted && stillCurrent();
|
|
34465
|
+
const git = async (cwd, args) => {
|
|
34466
|
+
if (!current()) throw new Error("Git sampling cancelled");
|
|
34467
|
+
const result = await pi.exec("git", args, {
|
|
34468
|
+
cwd,
|
|
34469
|
+
signal: abort.signal,
|
|
34470
|
+
timeout: 3e3
|
|
34471
|
+
});
|
|
34472
|
+
if (!current() || result.code !== 0 || result.killed)
|
|
34473
|
+
throw new Error("Git observation unavailable");
|
|
34474
|
+
return String(result.stdout ?? "");
|
|
34475
|
+
};
|
|
34476
|
+
const sampling = (async () => {
|
|
34477
|
+
let summary;
|
|
34478
|
+
try {
|
|
34479
|
+
if (identity.comparison) {
|
|
34480
|
+
summary = await observeGitChangeSummary(
|
|
34481
|
+
git,
|
|
34482
|
+
identity.checkoutPath,
|
|
34483
|
+
identity.repoKey,
|
|
34484
|
+
async () => git(identity.checkoutPath, [
|
|
34485
|
+
"rev-parse",
|
|
34486
|
+
"--verify",
|
|
34487
|
+
"main-worktree/HEAD^{commit}"
|
|
34488
|
+
])
|
|
34489
|
+
);
|
|
34490
|
+
} else {
|
|
34491
|
+
const state = await readGitWorktreeState(git, identity.checkoutPath);
|
|
34492
|
+
summary = state ? { dirty: state.dirty, checkedOutBranch: state.checkedOutBranch } : void 0;
|
|
34493
|
+
}
|
|
34494
|
+
} catch {
|
|
34495
|
+
}
|
|
34496
|
+
if (!stillCurrent()) return;
|
|
34497
|
+
leadGitCache = summary && !abort.signal.aborted ? { identity, summary } : void 0;
|
|
34498
|
+
statusRuntime.invalidateWidget();
|
|
34499
|
+
})().finally(() => {
|
|
34500
|
+
clearTimeout(deadline);
|
|
34501
|
+
contextSignal?.removeEventListener("abort", abortFromContext);
|
|
34502
|
+
if (leadGitSampling === sampling) {
|
|
34503
|
+
leadGitSampling = void 0;
|
|
34504
|
+
if (leadGitAbort === abort) leadGitAbort = void 0;
|
|
34505
|
+
}
|
|
34506
|
+
});
|
|
34507
|
+
leadGitSampling = sampling;
|
|
34508
|
+
};
|
|
33438
34509
|
statusRuntime.configure({
|
|
34510
|
+
getLocalActivity: (ctx) => getLocalActivity(ctx),
|
|
33439
34511
|
...options.statusSnapshotHost,
|
|
33440
34512
|
pendingStartEntries: () => controller.pendingStartEntries(),
|
|
33441
34513
|
hasPendingStart: (label) => controller.hasPendingStart(label),
|
|
33442
34514
|
clearPendingStart: (label, expected) => controller.clearPendingStart(label, expected),
|
|
33443
34515
|
loadSnapshot: (ctx) => loadStatusSnapshot(ctx, controller.sessionSignal(), false),
|
|
33444
34516
|
runtimeForLabel: (label) => controller.runtimeForLabel(label),
|
|
33445
|
-
focusTarget
|
|
34517
|
+
focusTarget,
|
|
34518
|
+
getGitSummary: () => {
|
|
34519
|
+
const snapshot = statusRuntime.getSnapshot();
|
|
34520
|
+
const cached = leadGitCache;
|
|
34521
|
+
const identity = cached?.identity;
|
|
34522
|
+
if (!identity || activeLeadRole(leadRuntime) !== "lead" || !sessionKind || sessionKind.sessionId !== identity.sessionId || leadGitContext?.sessionManager.getSessionId() !== identity.sessionId || snapshot.stale || snapshot.unavailable || !sameDirectory(identity.checkoutPath, leadGitContext.cwd))
|
|
34523
|
+
return void 0;
|
|
34524
|
+
return !identity.comparison || managedLifecycle === "assigned" && verifiedManagedAssignment?.sessionId === identity.sessionId && verifiedManagedAssignment.assignment.repoKey === identity.repoKey && verifiedManagedAssignment.assignment.branch === identity.assignmentBranch ? cached.summary : void 0;
|
|
34525
|
+
},
|
|
34526
|
+
onFreshStatus: sampleLeadGit,
|
|
34527
|
+
onWidgetStop: () => cancelLeadGitSampling()
|
|
33446
34528
|
});
|
|
33447
34529
|
let projectRuntime;
|
|
33448
34530
|
const projectHost = options.projectHost;
|
|
@@ -33750,17 +34832,18 @@ function registerLeadRuntime(pi, options) {
|
|
|
33750
34832
|
};
|
|
33751
34833
|
const resolveExecutionDefinition = (ctx, mode, definitions) => {
|
|
33752
34834
|
const name = mode === "flexible" ? FLEXIBLE_LEAD_DEFINITION_NAME : ORCHESTRATOR_LEAD_DEFINITION_NAME;
|
|
33753
|
-
const definition = definitions ? definitions.find((candidate) => candidate.name === name) : options.commandHost.discoverRoleDefinition(
|
|
33754
|
-
|
|
33755
|
-
|
|
33756
|
-
);
|
|
34835
|
+
const definition = definitions ? definitions.find((candidate) => candidate.name === name) : options.commandHost.discoverRoleDefinition(name, {
|
|
34836
|
+
...ctx.isProjectTrusted() ? { projectRoot: ctx.cwd } : {},
|
|
34837
|
+
onWarning: (message) => notifyDefinitionWarning(ctx, message)
|
|
34838
|
+
});
|
|
33757
34839
|
if (!definition) throw new Error(`Lead definition ${name} not found`);
|
|
33758
34840
|
if (definitions && definition.frontmatter.agents?.length)
|
|
33759
34841
|
validateRoleAgentDefinitionReferences(
|
|
33760
34842
|
definition,
|
|
33761
|
-
discoverAgentDefinitions(
|
|
33762
|
-
ctx.isProjectTrusted() ? { projectRoot: ctx.cwd } : {}
|
|
33763
|
-
|
|
34843
|
+
discoverAgentDefinitions({
|
|
34844
|
+
...ctx.isProjectTrusted() ? { projectRoot: ctx.cwd } : {},
|
|
34845
|
+
onWarning: (message) => notifyDefinitionWarning(ctx, message)
|
|
34846
|
+
})
|
|
33764
34847
|
);
|
|
33765
34848
|
return {
|
|
33766
34849
|
...definition,
|
|
@@ -33771,10 +34854,10 @@ function registerLeadRuntime(pi, options) {
|
|
|
33771
34854
|
)
|
|
33772
34855
|
};
|
|
33773
34856
|
};
|
|
33774
|
-
const managedLeadDefinition = (ctx) => options.commandHost.discoverRoleDefinition(
|
|
33775
|
-
|
|
33776
|
-
|
|
33777
|
-
);
|
|
34857
|
+
const managedLeadDefinition = (ctx) => options.commandHost.discoverRoleDefinition(MANAGED_LEAD_DEFINITION_NAME, {
|
|
34858
|
+
...ctx.isProjectTrusted() ? { projectRoot: ctx.cwd } : {},
|
|
34859
|
+
onWarning: (message) => notifyDefinitionWarning(ctx, message)
|
|
34860
|
+
});
|
|
33778
34861
|
const verifyManagedLeadModelRestoration = async (ctx, signal) => {
|
|
33779
34862
|
if (sessionKind?.kind !== "managed") return;
|
|
33780
34863
|
coordinationRuntime.invalidateStartupCoordinationState(
|
|
@@ -34021,6 +35104,19 @@ function registerLeadRuntime(pi, options) {
|
|
|
34021
35104
|
};
|
|
34022
35105
|
const agentEvents = createLeadAgentEventRuntime({
|
|
34023
35106
|
...options.agentEventOptions,
|
|
35107
|
+
currentLeadAllowedTools: () => {
|
|
35108
|
+
if (sessionKind?.kind === "managed") {
|
|
35109
|
+
if (managedLifecycle !== "assigned" || leadExecutionPending || leadRuntime.roleSuspended || leadRuntime.chiefMode === "suspended" || !leadExecution?.valid || !leadExecution.managed)
|
|
35110
|
+
return executionTools();
|
|
35111
|
+
const policy2 = leadExecution.definition.frontmatter;
|
|
35112
|
+
return policy2.tools !== void 0 || (policy2.excludeTools?.length ?? 0) > 0 || policy2.noTools === true ? executionTools() : void 0;
|
|
35113
|
+
}
|
|
35114
|
+
if (activeLeadRole(leadRuntime) !== "lead" || leadRuntime.roleSuspended || !leadExecution || leadExecution.managed)
|
|
35115
|
+
return void 0;
|
|
35116
|
+
if (!leadExecution.valid) return executionTools();
|
|
35117
|
+
const policy = leadExecution.definition.frontmatter;
|
|
35118
|
+
return policy.tools !== void 0 || (policy.excludeTools?.length ?? 0) > 0 ? executionTools() : void 0;
|
|
35119
|
+
},
|
|
34024
35120
|
executionPrompt: () => leadExecution && !leadExecution.managed && leadExecution.valid ? leadExecution.definition.body : void 0,
|
|
34025
35121
|
leadInboxRuntime: inboxRuntime,
|
|
34026
35122
|
herdRun: herdRunRuntime,
|
|
@@ -34043,9 +35139,10 @@ function registerLeadRuntime(pi, options) {
|
|
|
34043
35139
|
discoverSessionDefinitions: async (ctx) => {
|
|
34044
35140
|
let roleDefinitions = [];
|
|
34045
35141
|
try {
|
|
34046
|
-
roleDefinitions = discoverRoleDefinitions(
|
|
34047
|
-
ctx.isProjectTrusted() ? { projectRoot: ctx.cwd } : {}
|
|
34048
|
-
|
|
35142
|
+
roleDefinitions = discoverRoleDefinitions({
|
|
35143
|
+
...ctx.isProjectTrusted() ? { projectRoot: ctx.cwd } : {},
|
|
35144
|
+
onWarning: (message) => notifyDefinitionWarning(ctx, message)
|
|
35145
|
+
});
|
|
34049
35146
|
} catch (error2) {
|
|
34050
35147
|
options.sessionStartOptions.appendDefinitionError(ctx, error2);
|
|
34051
35148
|
}
|
|
@@ -34189,6 +35286,10 @@ This session belongs to a managed Agent restored without its authorized launch c
|
|
|
34189
35286
|
inheritedProjection = void 0;
|
|
34190
35287
|
return shutdown.shutdown(ctx);
|
|
34191
35288
|
});
|
|
35289
|
+
getLocalActivity = observeLocalHeaderActivity(pi, () => {
|
|
35290
|
+
statusRuntime.invalidateWidget();
|
|
35291
|
+
invalidateSupervisionWidget();
|
|
35292
|
+
});
|
|
34192
35293
|
return {
|
|
34193
35294
|
roleTransitions,
|
|
34194
35295
|
publishLeadRole,
|
|
@@ -34870,6 +35971,7 @@ function createLeadSupervisionRuntime(host) {
|
|
|
34870
35971
|
let statusConfigError;
|
|
34871
35972
|
let widgetFocusInFlight = false;
|
|
34872
35973
|
let supervisionWidgetGeneration = 0;
|
|
35974
|
+
let managerHeaderGit;
|
|
34873
35975
|
const gitSummaries = /* @__PURE__ */ new Map();
|
|
34874
35976
|
let gitSampling;
|
|
34875
35977
|
let gitLastAttemptAt = 0;
|
|
@@ -34880,6 +35982,7 @@ function createLeadSupervisionRuntime(host) {
|
|
|
34880
35982
|
gitAbort = void 0;
|
|
34881
35983
|
gitSampling = void 0;
|
|
34882
35984
|
gitSummaries.clear();
|
|
35985
|
+
managerHeaderGit = void 0;
|
|
34883
35986
|
if (resetRate) gitLastAttemptAt = 0;
|
|
34884
35987
|
};
|
|
34885
35988
|
const generation = (ctx) => [
|
|
@@ -34907,10 +36010,6 @@ function createLeadSupervisionRuntime(host) {
|
|
|
34907
36010
|
const entries = host.managerSupervisionItems(value2).slice(0, statusWidgetMaxRows - 1).filter(
|
|
34908
36011
|
(item) => item.kind === "work" && (item.work.status === "active" || item.work.status === "paused") && !!item.work.checkoutPath
|
|
34909
36012
|
);
|
|
34910
|
-
if (!entries.length) {
|
|
34911
|
-
gitSummaries.clear();
|
|
34912
|
-
return;
|
|
34913
|
-
}
|
|
34914
36013
|
gitLastAttemptAt = Date.now();
|
|
34915
36014
|
const abort = new AbortController();
|
|
34916
36015
|
gitAbort = abort;
|
|
@@ -34921,6 +36020,7 @@ function createLeadSupervisionRuntime(host) {
|
|
|
34921
36020
|
overallTimeout.unref?.();
|
|
34922
36021
|
const run2 = async () => {
|
|
34923
36022
|
const next = /* @__PURE__ */ new Map();
|
|
36023
|
+
let headerSummary;
|
|
34924
36024
|
const current = () => !abort.signal.aborted && uiContext === ctx && generation(ctx) === expectedGeneration && host.activeRole() === "manager" && !host.state.roleSuspended;
|
|
34925
36025
|
const git = async (cwd, args) => {
|
|
34926
36026
|
if (!current()) throw new Error("Git sampling cancelled");
|
|
@@ -34944,132 +36044,50 @@ function createLeadSupervisionRuntime(host) {
|
|
|
34944
36044
|
managerCheckoutPath,
|
|
34945
36045
|
host.state.managerLease.descriptor.repoKey
|
|
34946
36046
|
)) {
|
|
34947
|
-
if (current())
|
|
36047
|
+
if (current()) {
|
|
36048
|
+
gitSummaries.clear();
|
|
36049
|
+
managerHeaderGit = void 0;
|
|
36050
|
+
}
|
|
34948
36051
|
return;
|
|
34949
36052
|
}
|
|
34950
36053
|
let managerHead;
|
|
36054
|
+
try {
|
|
36055
|
+
const state = await readGitWorktreeState(git, managerCheckoutPath);
|
|
36056
|
+
if (state) {
|
|
36057
|
+
headerSummary = {
|
|
36058
|
+
dirty: state.dirty,
|
|
36059
|
+
checkedOutBranch: state.checkedOutBranch
|
|
36060
|
+
};
|
|
36061
|
+
managerHead = state.head;
|
|
36062
|
+
}
|
|
36063
|
+
} catch {
|
|
36064
|
+
}
|
|
34951
36065
|
for (const item of entries) {
|
|
34952
36066
|
if (!current()) return;
|
|
34953
36067
|
if (item.kind !== "work") continue;
|
|
34954
36068
|
const work = item.work;
|
|
34955
36069
|
const checkoutPath = work.checkoutPath;
|
|
34956
36070
|
try {
|
|
34957
|
-
|
|
36071
|
+
const summary = await observeGitChangeSummary(
|
|
36072
|
+
git,
|
|
34958
36073
|
checkoutPath,
|
|
34959
|
-
host.state.managerLease.descriptor.repoKey
|
|
34960
|
-
|
|
34961
|
-
|
|
34962
|
-
|
|
34963
|
-
|
|
34964
|
-
|
|
34965
|
-
|
|
34966
|
-
|
|
34967
|
-
"-z",
|
|
34968
|
-
"--untracked-files=normal"
|
|
34969
|
-
])).split("\0");
|
|
34970
|
-
let headerEnd = 0;
|
|
34971
|
-
const headers = /* @__PURE__ */ new Map();
|
|
34972
|
-
while (headerEnd < status2.length && status2[headerEnd]?.startsWith("# ")) {
|
|
34973
|
-
const match = /^# (branch\.(?:head|oid)) (.*)$/u.exec(
|
|
34974
|
-
status2[headerEnd]
|
|
34975
|
-
);
|
|
34976
|
-
if (match) headers.set(match[1], match[2]);
|
|
34977
|
-
headerEnd++;
|
|
34978
|
-
}
|
|
34979
|
-
const leadHead = headers.get("branch.oid");
|
|
34980
|
-
const branchHead = headers.get("branch.head");
|
|
34981
|
-
if (!branchHead || !leadHead || !/^[0-9a-f]{40,64}$/iu.test(leadHead))
|
|
34982
|
-
continue;
|
|
34983
|
-
const checkedOutBranch = branchHead === "(detached)" ? "detached" : branchHead;
|
|
34984
|
-
if (checkedOutBranch === "(unknown)" || !/^(?:detached|[^\s\0]+)$/u.test(checkedOutBranch))
|
|
34985
|
-
continue;
|
|
34986
|
-
const dirty = status2.slice(headerEnd).some((entry) => entry.length > 0);
|
|
34987
|
-
let additions;
|
|
34988
|
-
let deletions;
|
|
34989
|
-
let changedFiles;
|
|
34990
|
-
let comparisonSha;
|
|
34991
|
-
try {
|
|
34992
|
-
managerHead ??= (await git(managerCheckoutPath, [
|
|
34993
|
-
"rev-parse",
|
|
34994
|
-
"--verify",
|
|
34995
|
-
"HEAD^{commit}"
|
|
34996
|
-
])).trim();
|
|
34997
|
-
if (/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u.test(managerHead)) {
|
|
34998
|
-
const bases = (await git(checkoutPath, [
|
|
34999
|
-
"merge-base",
|
|
35000
|
-
"--all",
|
|
35001
|
-
managerHead,
|
|
35002
|
-
leadHead
|
|
35003
|
-
])).trim().split(/\s+/u);
|
|
35004
|
-
if (bases.length === 1 && /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u.test(bases[0]))
|
|
35005
|
-
comparisonSha = bases[0];
|
|
35006
|
-
}
|
|
35007
|
-
} catch {
|
|
35008
|
-
}
|
|
35009
|
-
if (comparisonSha) {
|
|
35010
|
-
try {
|
|
35011
|
-
const output = await git(checkoutPath, [
|
|
35012
|
-
"--no-optional-locks",
|
|
35013
|
-
"diff",
|
|
35014
|
-
"--numstat",
|
|
35015
|
-
"-z",
|
|
35016
|
-
"--find-renames",
|
|
35017
|
-
comparisonSha,
|
|
35018
|
-
"--"
|
|
35019
|
-
]);
|
|
35020
|
-
const records = output.split("\0");
|
|
35021
|
-
let valid2 = output === "" || output.endsWith("\0");
|
|
35022
|
-
if (valid2) records.pop();
|
|
35023
|
-
let added = 0, deleted = 0, files = 0;
|
|
35024
|
-
for (let i = 0; valid2 && i < records.length; ) {
|
|
35025
|
-
const match = /^(\d+|-)\t(\d+|-)\t(.*)$/su.exec(
|
|
35026
|
-
records[i++]
|
|
35027
|
-
);
|
|
35028
|
-
if (!match) {
|
|
35029
|
-
valid2 = false;
|
|
35030
|
-
break;
|
|
35031
|
-
}
|
|
35032
|
-
const [, a, d, path] = match;
|
|
35033
|
-
if (!path && (!records[i++] || !records[i++])) {
|
|
35034
|
-
valid2 = false;
|
|
35035
|
-
break;
|
|
35036
|
-
}
|
|
35037
|
-
if (a === "-" && d === "-") {
|
|
35038
|
-
files++;
|
|
35039
|
-
continue;
|
|
35040
|
-
}
|
|
35041
|
-
if (!/^\d+$/u.test(a) || !/^\d+$/u.test(d)) {
|
|
35042
|
-
valid2 = false;
|
|
35043
|
-
break;
|
|
35044
|
-
}
|
|
35045
|
-
added += Number(a);
|
|
35046
|
-
deleted += Number(d);
|
|
35047
|
-
files++;
|
|
35048
|
-
if (!Number.isSafeInteger(added) || !Number.isSafeInteger(deleted)) {
|
|
35049
|
-
valid2 = false;
|
|
35050
|
-
break;
|
|
35051
|
-
}
|
|
35052
|
-
}
|
|
35053
|
-
if (valid2) {
|
|
35054
|
-
additions = added;
|
|
35055
|
-
deletions = deleted;
|
|
35056
|
-
changedFiles = files;
|
|
35057
|
-
}
|
|
35058
|
-
} catch {
|
|
36074
|
+
host.state.managerLease.descriptor.repoKey,
|
|
36075
|
+
async () => {
|
|
36076
|
+
managerHead ??= (await git(managerCheckoutPath, [
|
|
36077
|
+
"rev-parse",
|
|
36078
|
+
"--verify",
|
|
36079
|
+
"HEAD^{commit}"
|
|
36080
|
+
])).trim();
|
|
36081
|
+
return managerHead;
|
|
35059
36082
|
}
|
|
35060
|
-
|
|
36083
|
+
);
|
|
36084
|
+
if (!summary) continue;
|
|
35061
36085
|
next.set(work.session, {
|
|
35062
36086
|
generation: expectedGeneration,
|
|
35063
36087
|
checkoutPath,
|
|
35064
36088
|
branch: work.branch,
|
|
35065
36089
|
managerCheckoutPath,
|
|
35066
|
-
summary
|
|
35067
|
-
dirty,
|
|
35068
|
-
additions,
|
|
35069
|
-
deletions,
|
|
35070
|
-
changedFiles,
|
|
35071
|
-
checkedOutBranch
|
|
35072
|
-
}
|
|
36090
|
+
summary
|
|
35073
36091
|
});
|
|
35074
36092
|
} catch {
|
|
35075
36093
|
}
|
|
@@ -35077,9 +36095,18 @@ function createLeadSupervisionRuntime(host) {
|
|
|
35077
36095
|
if (!current()) return;
|
|
35078
36096
|
gitSummaries.clear();
|
|
35079
36097
|
for (const [session, result] of next) gitSummaries.set(session, result);
|
|
36098
|
+
managerHeaderGit = headerSummary ? {
|
|
36099
|
+
generation: expectedGeneration,
|
|
36100
|
+
checkoutPath: managerCheckoutPath,
|
|
36101
|
+
repoKey: host.state.managerLease.descriptor.repoKey,
|
|
36102
|
+
summary: headerSummary
|
|
36103
|
+
} : void 0;
|
|
35080
36104
|
renderWidget?.();
|
|
35081
36105
|
} catch {
|
|
35082
|
-
if (current())
|
|
36106
|
+
if (current()) {
|
|
36107
|
+
gitSummaries.clear();
|
|
36108
|
+
managerHeaderGit = void 0;
|
|
36109
|
+
}
|
|
35083
36110
|
}
|
|
35084
36111
|
};
|
|
35085
36112
|
const sampling = run2().finally(() => {
|
|
@@ -35708,6 +36735,79 @@ Origin: ${"sourceAssignmentId" in entry ? `project assignment ${entry.sourceAssi
|
|
|
35708
36735
|
if (!isCurrent()) return;
|
|
35709
36736
|
const contextStatus = status(ctx);
|
|
35710
36737
|
const targets = /* @__PURE__ */ new Map();
|
|
36738
|
+
let git;
|
|
36739
|
+
if (host.activeRole() === "manager" && contextStatus === "fresh" && snapshot && "managerCheckoutPath" in snapshot && snapshot.managerCheckoutPath && "work" in snapshot) {
|
|
36740
|
+
try {
|
|
36741
|
+
const checkout = snapshot.managerCheckoutPath;
|
|
36742
|
+
const common = await host.pi.exec(
|
|
36743
|
+
"git",
|
|
36744
|
+
["rev-parse", "--path-format=absolute", "--git-common-dir"],
|
|
36745
|
+
{ cwd: checkout, signal: ctx.signal, timeout: 3e3 }
|
|
36746
|
+
);
|
|
36747
|
+
const managerAuthority = await host.currentManager(ctx);
|
|
36748
|
+
if (common.code === 0 && !common.killed && !common.stderr?.trim() && managerAuthority && sameDirectory(
|
|
36749
|
+
String(common.stdout ?? "").trim(),
|
|
36750
|
+
managerAuthority.repoKey
|
|
36751
|
+
)) {
|
|
36752
|
+
const sessionRootResult = ctx.cwd ? await host.pi.exec("git", ["rev-parse", "--show-toplevel"], {
|
|
36753
|
+
cwd: ctx.cwd,
|
|
36754
|
+
signal: ctx.signal,
|
|
36755
|
+
timeout: 3e3
|
|
36756
|
+
}) : void 0;
|
|
36757
|
+
const sessionRoot = sessionRootResult?.code === 0 && !sessionRootResult.killed && !sessionRootResult.stderr?.trim() ? String(sessionRootResult.stdout ?? "").trim() : void 0;
|
|
36758
|
+
const result = await host.pi.exec(
|
|
36759
|
+
"git",
|
|
36760
|
+
["worktree", "list", "--porcelain", "-z"],
|
|
36761
|
+
{ cwd: checkout, signal: ctx.signal, timeout: 3e3 }
|
|
36762
|
+
);
|
|
36763
|
+
const inventory = result.code === 0 && !result.killed && !result.stderr?.trim() ? parseGitWorktreeInventory(String(result.stdout ?? "")) : void 0;
|
|
36764
|
+
const observation = (path) => {
|
|
36765
|
+
const matches = inventory?.filter(
|
|
36766
|
+
(entry2) => !entry2.prunable && sameDirectory(entry2.path, path)
|
|
36767
|
+
) ?? [];
|
|
36768
|
+
const entry = matches.length === 1 ? matches[0] : void 0;
|
|
36769
|
+
return entry?.head && (entry.detached || entry.branch) ? {
|
|
36770
|
+
branch: entry.detached ? null : entry.branch,
|
|
36771
|
+
head: entry.head
|
|
36772
|
+
} : void 0;
|
|
36773
|
+
};
|
|
36774
|
+
const manager = observation(checkout);
|
|
36775
|
+
const managerSessionObservation = sessionRoot ? observation(sessionRoot) : void 0;
|
|
36776
|
+
const managerSession = sessionRoot && managerSessionObservation ? {
|
|
36777
|
+
cwd: ctx.cwd,
|
|
36778
|
+
worktreeRoot: sessionRoot,
|
|
36779
|
+
...managerSessionObservation
|
|
36780
|
+
} : void 0;
|
|
36781
|
+
if (manager) {
|
|
36782
|
+
const assignments = /* @__PURE__ */ new Map();
|
|
36783
|
+
const supervisedLeads = /* @__PURE__ */ new Map();
|
|
36784
|
+
for (const work of snapshot.work ?? [])
|
|
36785
|
+
if (work.checkoutPath) {
|
|
36786
|
+
const observed = observation(work.checkoutPath);
|
|
36787
|
+
if (observed) assignments.set(work.branch, observed);
|
|
36788
|
+
}
|
|
36789
|
+
if ("openWorkspaces" in snapshot)
|
|
36790
|
+
for (const lead of snapshot.leads ?? []) {
|
|
36791
|
+
if (lead.relationship !== "supervised") continue;
|
|
36792
|
+
const workspaces = snapshot.openWorkspaces?.filter(
|
|
36793
|
+
(workspace2) => workspace2.workspaceId === lead.workspaceId
|
|
36794
|
+
) ?? [];
|
|
36795
|
+
if (workspaces.length !== 1) continue;
|
|
36796
|
+
const observed = observation(workspaces[0].path);
|
|
36797
|
+
if (observed) supervisedLeads.set(lead.lead, observed);
|
|
36798
|
+
}
|
|
36799
|
+
git = {
|
|
36800
|
+
manager,
|
|
36801
|
+
...managerSession ? { managerSession } : {},
|
|
36802
|
+
assignments,
|
|
36803
|
+
supervisedLeads
|
|
36804
|
+
};
|
|
36805
|
+
}
|
|
36806
|
+
}
|
|
36807
|
+
} catch {
|
|
36808
|
+
}
|
|
36809
|
+
}
|
|
36810
|
+
if (!isCurrent()) return;
|
|
35711
36811
|
const candidates = [];
|
|
35712
36812
|
if (contextStatus !== "unavailable" && snapshot) {
|
|
35713
36813
|
for (const report of host.presentationReports(snapshot)) {
|
|
@@ -35727,7 +36827,8 @@ Origin: ${"sourceAssignmentId" in entry ? `project assignment ${entry.sourceAssi
|
|
|
35727
36827
|
{
|
|
35728
36828
|
status: contextStatus,
|
|
35729
36829
|
role: host.activeRole() === "manager" ? "manager" : "chief",
|
|
35730
|
-
targets
|
|
36830
|
+
targets,
|
|
36831
|
+
...git ? { git } : {}
|
|
35731
36832
|
}
|
|
35732
36833
|
);
|
|
35733
36834
|
for (const candidate of candidates)
|
|
@@ -35759,6 +36860,7 @@ Origin: ${"sourceAssignmentId" in entry ? `project assignment ${entry.sourceAssi
|
|
|
35759
36860
|
widgetFocusInFlight = false;
|
|
35760
36861
|
ctx.ui.setWidget("pi-herdsman-staff", (tui, theme) => {
|
|
35761
36862
|
renderWidget = () => tui.requestRender();
|
|
36863
|
+
host.onActivityChange?.(() => renderWidget?.());
|
|
35762
36864
|
return createSupervisionWidget(
|
|
35763
36865
|
() => snapshot,
|
|
35764
36866
|
() => status(ctx),
|
|
@@ -35816,7 +36918,14 @@ Origin: ${"sourceAssignmentId" in entry ? `project assignment ${entry.sourceAssi
|
|
|
35816
36918
|
});
|
|
35817
36919
|
}
|
|
35818
36920
|
},
|
|
35819
|
-
() => statusWidgetMaxRows
|
|
36921
|
+
() => statusWidgetMaxRows,
|
|
36922
|
+
() => {
|
|
36923
|
+
const cached = managerHeaderGit;
|
|
36924
|
+
const currentSnapshot = isProjectSnapshot(snapshot) ? snapshot : void 0;
|
|
36925
|
+
const lease = host.state.managerLease;
|
|
36926
|
+
return cached && host.activeRole() === "manager" && status(ctx) === "fresh" && currentSnapshot?.managerCheckoutPath && cached.generation === generation(ctx) && cached.checkoutPath === currentSnapshot.managerCheckoutPath && cached.repoKey === lease?.descriptor.repoKey ? cached.summary : void 0;
|
|
36927
|
+
},
|
|
36928
|
+
() => host.getLocalActivity?.(ctx) ?? "unknown"
|
|
35820
36929
|
);
|
|
35821
36930
|
});
|
|
35822
36931
|
} catch {
|
|
@@ -37734,6 +38843,7 @@ function createLeadRoleTransitions(state, host) {
|
|
|
37734
38843
|
}
|
|
37735
38844
|
};
|
|
37736
38845
|
const publishProjectMessage = async (ctx, assignment, message, files = [], operation = "message_supervisor", reportId, kind, signal) => {
|
|
38846
|
+
const senderEnvironment = await captureSenderEnvironment(host.pi, ctx);
|
|
37737
38847
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
37738
38848
|
const runtime = host.supervisionRuntime();
|
|
37739
38849
|
const current = host.readProjectAssignment(
|
|
@@ -37758,6 +38868,7 @@ function createLeadRoleTransitions(state, host) {
|
|
|
37758
38868
|
fromSessionId: sessionId,
|
|
37759
38869
|
text: candidate,
|
|
37760
38870
|
...kind ? { kind } : {},
|
|
38871
|
+
...senderEnvironment ? { senderEnvironment } : {},
|
|
37761
38872
|
...resultBindings.length ? { resultBindings: [...resultBindings] } : {},
|
|
37762
38873
|
createdAt
|
|
37763
38874
|
})
|
|
@@ -37770,6 +38881,7 @@ function createLeadRoleTransitions(state, host) {
|
|
|
37770
38881
|
fromSessionId: sessionId,
|
|
37771
38882
|
text: prepared.text,
|
|
37772
38883
|
...kind ? { kind } : {},
|
|
38884
|
+
...senderEnvironment ? { senderEnvironment } : {},
|
|
37773
38885
|
...prepared.resultBindings.length ? { resultBindings: prepared.resultBindings } : {},
|
|
37774
38886
|
createdAt
|
|
37775
38887
|
};
|
|
@@ -38561,7 +39673,7 @@ function createLeadRoleTransitions(state, host) {
|
|
|
38561
39673
|
return void 0;
|
|
38562
39674
|
};
|
|
38563
39675
|
const bootstrapLock = host.acquireProcessLock(
|
|
38564
|
-
|
|
39676
|
+
join13(
|
|
38565
39677
|
herdsmanTempRoot(),
|
|
38566
39678
|
"locks",
|
|
38567
39679
|
`manager-bootstrap-${createHash14("sha256").update(target).digest("hex")}`
|
|
@@ -38986,6 +40098,10 @@ function createLeadRoleTransitions(state, host) {
|
|
|
38986
40098
|
}
|
|
38987
40099
|
if (state.roleSuspended || state.chiefMode === "suspended") {
|
|
38988
40100
|
host.setInheritedProjection?.(void 0);
|
|
40101
|
+
if (host.isManagedSession?.()) {
|
|
40102
|
+
host.pi.setActiveTools(host.executionTools?.() ?? []);
|
|
40103
|
+
return;
|
|
40104
|
+
}
|
|
38989
40105
|
const baseline = host.normalizeBaseTools(
|
|
38990
40106
|
host.getLeadTools() ?? host.pi.getActiveTools()
|
|
38991
40107
|
);
|
|
@@ -40521,7 +41637,7 @@ ${summary}`,
|
|
|
40521
41637
|
supervisorTool = {
|
|
40522
41638
|
name: "message_supervisor",
|
|
40523
41639
|
label: "message supervisor",
|
|
40524
|
-
exposure: "
|
|
41640
|
+
exposure: "direct",
|
|
40525
41641
|
promptSnippet: "Send nonblocking material coordination to your direct supervisor",
|
|
40526
41642
|
description: "Send a nonblocking question, clarification, warning, risk, decision, scope change, or evidence only when it is material or needed by your direct supervisor. Avoid unsolicited routine progress updates and duplicate result announcements.",
|
|
40527
41643
|
executionMode: "sequential",
|
|
@@ -40540,7 +41656,7 @@ ${summary}`,
|
|
|
40540
41656
|
peerTool = {
|
|
40541
41657
|
name: "message_peer",
|
|
40542
41658
|
label: "message peer",
|
|
40543
|
-
exposure: "
|
|
41659
|
+
exposure: "direct",
|
|
40544
41660
|
promptSnippet: "Discover same-role peers, including remote ordinary Leads, and reply through existing correspondences",
|
|
40545
41661
|
description: "Send task-relevant communication needed by another eligible coordinator, not routine broadcasts or gratuitous acknowledgments. Send to an eligible same-role Lead or Manager using its stable target. Ordinary Leads and Managers may discover eligible same-role peers on reachable saved Herdr machines; remote Leads must be ordinary and unassigned. An existing return correspondence may allow a reply-only target without independent discovery or current availability. Use only the exact target from list_peers; optional name/workspace labels are advisory display context.",
|
|
40546
41662
|
executionMode: "sequential",
|
|
@@ -40556,7 +41672,7 @@ ${summary}`,
|
|
|
40556
41672
|
name: "message_staff",
|
|
40557
41673
|
label: "message staff",
|
|
40558
41674
|
defaultActive: false,
|
|
40559
|
-
exposure: "
|
|
41675
|
+
exposure: "direct",
|
|
40560
41676
|
promptSnippet: "Supervise direct reports; Managers may delegate new linked-worktree Leads",
|
|
40561
41677
|
executionMode: "sequential",
|
|
40562
41678
|
parameters: staffMessageParameters,
|
|
@@ -40698,7 +41814,7 @@ ${summary}`,
|
|
|
40698
41814
|
...staffTool,
|
|
40699
41815
|
name: "integrate_branch",
|
|
40700
41816
|
label: "integrate branch",
|
|
40701
|
-
description: "Integrate an assigned local branch into the verified primary branch using fast-forward
|
|
41817
|
+
description: "Integrate an assigned local branch into the verified primary branch using fast-forward Git, or a clean divergent merge when explicitly authorized. Supply the exact full source SHA accepted after validation. A divergent merge may create a merge commit; actual conflicts are distinguished from divergent ancestry. Merge preflight failure/conflict occurs before stopping the Lead. If a later step fails after execution stops, it is not automatically restarted. Git integration does not prove tests or semantic acceptance. Verified integration triggers separately guarded cleanup; integration and cleanup can complete separately, so do not treat integration alone as full finalization.",
|
|
40702
41818
|
parameters: Type3.Object(
|
|
40703
41819
|
{
|
|
40704
41820
|
branch: Type3.String({
|
|
@@ -41010,7 +42126,7 @@ ${summary}`,
|
|
|
41010
42126
|
pi.registerTool({
|
|
41011
42127
|
name: "read_evidence",
|
|
41012
42128
|
label: "Read accepted evidence",
|
|
41013
|
-
exposure: "
|
|
42129
|
+
exposure: "direct",
|
|
41014
42130
|
description: "Read a bounded page from evidence accepted by this managed Agent.",
|
|
41015
42131
|
parameters: Type3.Object(
|
|
41016
42132
|
{
|