pi-subagents 0.80.0 → 0.82.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 +66 -0
- package/bundle/agents.js +18 -0
- package/bundle/background-work.js +16 -0
- package/bundle/capability-ceiling.js +22 -0
- package/bundle/child-tool-plan.js +11 -0
- package/bundle/chunk-43SCHIMD.js +57 -0
- package/bundle/chunk-4QFZZV3O.js +57 -0
- package/bundle/chunk-4SDU2BZX.js +1190 -0
- package/bundle/chunk-52UBALJL.js +753 -0
- package/bundle/chunk-5LFLVSTM.js +260 -0
- package/bundle/chunk-5TYMSZX3.js +235 -0
- package/bundle/chunk-62OCY2S4.js +14 -0
- package/bundle/chunk-7F6RKT6W.js +132 -0
- package/bundle/chunk-7IVSUMQQ.js +1337 -0
- package/bundle/chunk-7J4ZXMY7.js +18 -0
- package/bundle/chunk-7PCKZHR5.js +1234 -0
- package/bundle/chunk-7YMXOYEU.js +1373 -0
- package/bundle/chunk-B5EKXDHE.js +16870 -0
- package/bundle/chunk-CIZQXJ5Q.js +8619 -0
- package/bundle/chunk-CTPAE36Y.js +94 -0
- package/bundle/chunk-D4EHT5SJ.js +14 -0
- package/bundle/chunk-GC4DSPMH.js +946 -0
- package/bundle/chunk-GJECHSAR.js +179 -0
- package/bundle/chunk-M2CTFYT3.js +4164 -0
- package/bundle/chunk-MHZ4G23A.js +1296 -0
- package/bundle/chunk-N2BN7BF5.js +159 -0
- package/bundle/chunk-NF7IEKBH.js +490 -0
- package/bundle/chunk-NGGAFDL6.js +742 -0
- package/bundle/chunk-NIXWDZZV.js +9 -0
- package/bundle/chunk-NRQ75MGH.js +8327 -0
- package/bundle/chunk-OYF6AFDY.js +458 -0
- package/bundle/chunk-PLCCBLPY.js +526 -0
- package/bundle/chunk-RMQFMMAT.js +416 -0
- package/bundle/chunk-SIJ4S3EN.js +276 -0
- package/bundle/chunk-UKG4V45O.js +228 -0
- package/bundle/chunk-VH5OAWVG.js +4096 -0
- package/bundle/chunk-W2SZ22EM.js +5462 -0
- package/bundle/chunk-WVD4UEL4.js +9367 -0
- package/bundle/chunk-XSWOTIA3.js +175 -0
- package/bundle/chunk-YFCK7H2S.js +129 -0
- package/bundle/chunk-YKEWIB4M.js +380 -0
- package/bundle/chunk-YYREO77V.js +137 -0
- package/bundle/chunk-Z7KVHQHL.js +173 -0
- package/bundle/chunk-ZLINIYTP.js +8613 -0
- package/bundle/chunk-ZQGSDHL6.js +128 -0
- package/bundle/control-channel.js +11 -0
- package/bundle/delegation.js +14 -0
- package/bundle/external-job-provider.js +20 -0
- package/bundle/external-runs.js +21 -0
- package/bundle/index.js +30 -0
- package/bundle/inspectors.js +8 -0
- package/bundle/intercom-bridge.js +11 -0
- package/bundle/preflight.js +425 -0
- package/bundle/project-panes.js +28 -0
- package/bundle/required-child-extensions.js +6 -0
- package/bundle/shared-types.js +8 -0
- package/bundle/workflow-resources.js +7 -0
- package/docs/agents.md +31 -0
- package/docs/configuration.md +9 -1
- package/docs/extension-api.md +27 -0
- package/docs/observability.md +6 -2
- package/docs/tool-reference.md +3 -1
- package/docs/workflows.md +16 -0
- package/package.json +19 -19
- package/skills/pi-subagents/references/execution-controls.md +5 -4
- package/src/agents/agent-management.js +3 -3
- package/src/agents/agent-memory.js +3 -1
- package/src/agents/agents.js +6 -6
- package/src/agents/frontmatter.d.ts +4 -0
- package/src/agents/frontmatter.js +24 -3
- package/src/agents/skills.js +2 -1
- package/src/api/delegation.d.ts +20 -0
- package/src/extension/config.js +3 -0
- package/src/extension/herdr-pi-bridge.js +17 -10
- package/src/extension/index.js +109 -9
- package/src/extension/schemas.js +3 -3
- package/src/intercom/native-supervisor-channel.js +20 -0
- package/src/missions/lifecycle.js +7 -1
- package/src/runs/background/active-async-capacity.d.ts +1 -0
- package/src/runs/background/active-async-capacity.js +9 -3
- package/src/runs/background/async-execution.js +20 -10
- package/src/runs/background/async-job-tracker.d.ts +6 -1
- package/src/runs/background/async-job-tracker.js +9 -4
- package/src/runs/background/async-status.d.ts +2 -0
- package/src/runs/background/async-status.js +21 -2
- package/src/runs/background/await-async-run.js +3 -7
- package/src/runs/background/boot-id.d.ts +12 -0
- package/src/runs/background/boot-id.js +47 -0
- package/src/runs/background/interrupted-elsewhere.d.ts +22 -0
- package/src/runs/background/interrupted-elsewhere.js +68 -0
- package/src/runs/background/notify.d.ts +2 -0
- package/src/runs/background/notify.js +13 -0
- package/src/runs/background/result-delivery-ownership.d.ts +6 -0
- package/src/runs/background/result-delivery-ownership.js +19 -1
- package/src/runs/background/result-watcher.d.ts +3 -1
- package/src/runs/background/result-watcher.js +24 -8
- package/src/runs/background/run-child-session.d.ts +1 -6
- package/src/runs/background/run-child-session.js +19 -1
- package/src/runs/background/run-status.js +2 -1
- package/src/runs/background/stale-run-reconciler.d.ts +25 -0
- package/src/runs/background/stale-run-reconciler.js +54 -13
- package/src/runs/background/subagent-runner-bootstrap.js +3 -0
- package/src/runs/background/subagent-runner.d.ts +4 -0
- package/src/runs/background/subagent-runner.js +13 -5
- package/src/runs/background/subagent-wait.d.ts +1 -1
- package/src/runs/background/subagent-wait.js +6 -1
- package/src/runs/background/terminal-run-index.d.ts +1 -0
- package/src/runs/background/terminal-run-index.js +4 -2
- package/src/runs/foreground/async-stop-action.js +3 -1
- package/src/runs/foreground/execution.js +45 -5
- package/src/runs/foreground/foreground-history.d.ts +16 -2
- package/src/runs/foreground/foreground-history.js +133 -31
- package/src/runs/foreground/subagent-executor.d.ts +11 -0
- package/src/runs/foreground/subagent-executor.js +277 -74
- package/src/runs/shared/child-launch.d.ts +2 -2
- package/src/runs/shared/child-session.d.ts +3 -2
- package/src/runs/shared/child-session.js +51 -8
- package/src/runs/shared/child-tool-plan.d.ts +7 -0
- package/src/runs/shared/child-tool-plan.js +21 -6
- package/src/runs/shared/herdr-connection.d.ts +17 -8
- package/src/runs/shared/herdr-connection.js +19 -7
- package/src/runs/shared/herdr-external-adapters.d.ts +3 -2
- package/src/runs/shared/herdr-external-adapters.js +1 -1
- package/src/runs/shared/herdr-machine.d.ts +12 -2
- package/src/runs/shared/herdr-machine.js +55 -9
- package/src/runs/shared/herdr-pane-host.d.ts +88 -0
- package/src/runs/shared/herdr-pane-host.js +155 -0
- package/src/runs/shared/herdr-placed-run.d.ts +27 -150
- package/src/runs/shared/herdr-placed-run.js +48 -395
- package/src/runs/shared/local-machine-access.d.ts +5 -0
- package/src/runs/shared/local-machine-access.js +28 -0
- package/src/runs/shared/orca-progress-tabs.d.ts +0 -1
- package/src/runs/shared/orca-progress-tabs.js +1 -24
- package/src/runs/shared/parallel-utils.d.ts +1 -1
- package/src/runs/shared/placed-run-owner.d.ts +49 -0
- package/src/runs/shared/placed-run-owner.js +93 -0
- package/src/runs/shared/placement-host.d.ts +99 -0
- package/src/runs/shared/placement-host.js +157 -0
- package/src/runs/shared/rex-machine.d.ts +25 -0
- package/src/runs/shared/rex-machine.js +83 -0
- package/src/runs/shared/rex-pane-host.d.ts +62 -0
- package/src/runs/shared/rex-pane-host.js +327 -0
- package/src/runs/shared/structured-output.d.ts +1 -0
- package/src/runs/shared/structured-output.js +1 -0
- package/src/shared/accessible-dir.js +4 -1
- package/src/shared/completion-owner.d.ts +5 -0
- package/src/shared/completion-owner.js +5 -0
- package/src/shared/provider-diagnostics.d.ts +9 -0
- package/src/shared/provider-diagnostics.js +75 -0
- package/src/shared/session-identity.d.ts +2 -0
- package/src/shared/session-identity.js +26 -0
- package/src/shared/types.d.ts +48 -6
- package/src/slash/delegation-adapters.d.ts +3 -1
- package/src/slash/delegation-adapters.js +7 -0
- package/src/slash/prompt-template-bridge.js +3 -1
- package/src/slash/subagents-admin.d.ts +1 -0
- package/src/slash/subagents-admin.js +1 -1
- package/src/tui/fleet-layout.d.ts +20 -0
- package/src/tui/fleet-layout.js +17 -0
- package/src/tui/fleet-viewport.d.ts +12 -0
- package/src/tui/fleet-viewport.js +35 -0
- package/src/tui/fleet.d.ts +6 -6
- package/src/tui/fleet.js +93 -66
- package/src/tui/render.d.ts +6 -0
- package/src/tui/render.js +3 -3
- package/src/tui/subagent-messages.js +1 -0
- package/src/workflows/scripted-workflow.d.ts +1 -1
- package/src/workflows/structured-workflow-scripts.d.ts +1 -0
- package/src/workflows/structured-workflow-scripts.js +5 -4
- package/src/workflows/workflow-auto-resume.d.ts +32 -0
- package/src/workflows/workflow-auto-resume.js +102 -0
- package/src/workflows/workflow-launch-record.d.ts +27 -0
- package/src/workflows/workflow-launch-record.js +48 -0
- package/src/workflows/workflow-resources.js +2 -2
- package/src/workflows/workflow-resume-claim.d.ts +82 -0
- package/src/workflows/workflow-resume-claim.js +210 -0
- package/src/workflows/workflow-resume.d.ts +56 -0
- package/src/workflows/workflow-resume.js +106 -0
- package/src/workflows/workflow-reuse.d.ts +15 -9
- package/src/workflows/workflow-reuse.js +77 -14
- package/src/workflows/workflow-revival.d.ts +2 -0
- package/src/workflows/workflow-revival.js +2 -1
- package/src/workflows/workflow-stop-cause.d.ts +6 -0
- package/src/workflows/workflow-stop-cause.js +8 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import {
|
|
2
|
+
appendAgentRefinementOverlay
|
|
3
|
+
} from "./chunk-PLCCBLPY.js";
|
|
4
|
+
import {
|
|
5
|
+
buildAgentMemoryInjection,
|
|
6
|
+
buildSkillInjection
|
|
7
|
+
} from "./chunk-CIZQXJ5Q.js";
|
|
8
|
+
|
|
9
|
+
// src/runs/shared/effective-system-prompt.ts
|
|
10
|
+
function appendSection(prompt, section) {
|
|
11
|
+
return prompt ? `${prompt}
|
|
12
|
+
|
|
13
|
+
${section}` : section;
|
|
14
|
+
}
|
|
15
|
+
function buildEffectiveSystemPrompt(input) {
|
|
16
|
+
let prompt = input.agent.systemPrompt?.trim() ?? "";
|
|
17
|
+
if (input.resolvedSkills.length > 0) prompt = appendSection(prompt, buildSkillInjection(input.resolvedSkills));
|
|
18
|
+
const memoryInjection = buildAgentMemoryInjection(input.agent, input.cwd);
|
|
19
|
+
if (memoryInjection) prompt = appendSection(prompt, memoryInjection);
|
|
20
|
+
prompt = appendAgentRefinementOverlay(prompt, { cwd: input.cwd, agentName: input.agent.name });
|
|
21
|
+
return prompt;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/shared/fork-context.ts
|
|
25
|
+
import * as fs from "node:fs";
|
|
26
|
+
import * as path from "node:path";
|
|
27
|
+
import { SessionManager } from "@earendil-works/pi-coding-agent";
|
|
28
|
+
function resolveSubagentContext(value) {
|
|
29
|
+
return value === "fork" ? "fork" : "fresh";
|
|
30
|
+
}
|
|
31
|
+
function resolveSubagentLaunchContext(input) {
|
|
32
|
+
if (input.explicitContext !== void 0) return input.explicitContext;
|
|
33
|
+
const preferredContext = input.defaultSubagentContext ?? input.agentDefaultContext ?? "fresh";
|
|
34
|
+
return preferredContext === "fork" && input.canUseImplicitFork ? "fork" : "fresh";
|
|
35
|
+
}
|
|
36
|
+
function canPreferFork(sessionManager) {
|
|
37
|
+
return canPreferForkFromSnapshot({
|
|
38
|
+
parentSessionFile: sessionManager.getSessionFile(),
|
|
39
|
+
leafId: sessionManager.getLeafId?.() ?? null
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function canPreferForkFromSnapshot(input) {
|
|
43
|
+
if (!input.parentSessionFile || !input.leafId) return false;
|
|
44
|
+
try {
|
|
45
|
+
return fs.existsSync(input.parentSessionFile);
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function isUnsafeAnthropicThinkingBlock(message, block, verbatim) {
|
|
51
|
+
if (!message || !block || typeof block !== "object" || !("type" in block)) return false;
|
|
52
|
+
if (verbatim) return block.type === "redacted_thinking";
|
|
53
|
+
const provider = typeof message.provider === "string" ? message.provider.toLowerCase() : "";
|
|
54
|
+
const api = typeof message.api === "string" ? message.api.toLowerCase() : "";
|
|
55
|
+
const model = typeof message.model === "string" ? message.model.toLowerCase() : "";
|
|
56
|
+
const isAnthropic = provider === "anthropic" || api === "anthropic-messages" || model.startsWith("anthropic/");
|
|
57
|
+
if (block.type === "redacted_thinking") return true;
|
|
58
|
+
if (block.type !== "thinking" || !isAnthropic) return false;
|
|
59
|
+
const record = block;
|
|
60
|
+
const signature = "thinkingSignature" in record ? record.thinkingSignature : "signature" in record ? record.signature : void 0;
|
|
61
|
+
return record.redacted === true || typeof signature === "string" && signature.length > 0;
|
|
62
|
+
}
|
|
63
|
+
function sanitizeUnsafeThinkingBlocks(entries, rewritten) {
|
|
64
|
+
let sanitized = false;
|
|
65
|
+
const entriesById = new Map(entries.flatMap((entry) => entry.id ? [[entry.id, entry]] : []));
|
|
66
|
+
for (const entry of entries) {
|
|
67
|
+
const targetMessage = entry.type === "context_edit" && entry.targetId ? entriesById.get(entry.targetId)?.message : entry.message;
|
|
68
|
+
const contentOwner = entry.type === "context_edit" ? entry.replacement : targetMessage;
|
|
69
|
+
if (targetMessage?.role !== "assistant" || !contentOwner || !Array.isArray(contentOwner.content)) continue;
|
|
70
|
+
const verbatim = !rewritten && entry.type !== "context_edit";
|
|
71
|
+
const filtered = contentOwner.content.filter((block) => !isUnsafeAnthropicThinkingBlock(targetMessage, block, verbatim));
|
|
72
|
+
if (filtered.length === contentOwner.content.length) continue;
|
|
73
|
+
contentOwner.content = filtered;
|
|
74
|
+
sanitized = true;
|
|
75
|
+
}
|
|
76
|
+
return sanitized;
|
|
77
|
+
}
|
|
78
|
+
function readSessionEntries(sessionFile) {
|
|
79
|
+
const lines = fs.readFileSync(sessionFile, "utf-8").split("\n").filter((line) => line.trim().length > 0);
|
|
80
|
+
return lines.map((line, index) => {
|
|
81
|
+
try {
|
|
82
|
+
return JSON.parse(line);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
const cause = error instanceof Error ? error : new Error(String(error));
|
|
85
|
+
throw new Error(`Unable to inspect forked session ${sessionFile}: invalid JSONL on line ${index + 1}: ${cause.message}`, { cause });
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function createForkContextResolver(sessionManager, requestedContext, options) {
|
|
90
|
+
if (resolveSubagentContext(requestedContext) !== "fork") {
|
|
91
|
+
return {
|
|
92
|
+
prepareSessionForIndex: async () => {
|
|
93
|
+
},
|
|
94
|
+
sessionFileForIndex: () => void 0
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const parentSessionFile = sessionManager.getSessionFile();
|
|
98
|
+
if (!parentSessionFile) {
|
|
99
|
+
throw new Error("Forked subagent context requires a persisted parent session.");
|
|
100
|
+
}
|
|
101
|
+
const leafId = sessionManager.getLeafId();
|
|
102
|
+
if (!leafId) {
|
|
103
|
+
throw new Error("Forked subagent context requires a current leaf to fork from.");
|
|
104
|
+
}
|
|
105
|
+
const openSession = options.openSession ?? sessionManager.openSession ?? ((file, dir) => SessionManager.open(file, dir));
|
|
106
|
+
const forksDir = path.join(
|
|
107
|
+
path.dirname(parentSessionFile),
|
|
108
|
+
path.basename(parentSessionFile, ".jsonl"),
|
|
109
|
+
"forks"
|
|
110
|
+
);
|
|
111
|
+
const cachedSessionFiles = /* @__PURE__ */ new Map();
|
|
112
|
+
const preparedIndexes = /* @__PURE__ */ new Set();
|
|
113
|
+
const preparationPromises = /* @__PURE__ */ new Map();
|
|
114
|
+
const resolveFork = (index = 0) => {
|
|
115
|
+
const cached = cachedSessionFiles.get(index);
|
|
116
|
+
if (cached) return cached;
|
|
117
|
+
try {
|
|
118
|
+
if (!fs.existsSync(parentSessionFile)) {
|
|
119
|
+
throw new Error(`Parent session file does not exist: ${parentSessionFile}. Pi has not persisted enough history to fork yet.`);
|
|
120
|
+
}
|
|
121
|
+
const sessionDir = path.join(forksDir, options.runDirName());
|
|
122
|
+
const sourceManager = openSession(parentSessionFile, sessionDir);
|
|
123
|
+
const sessionFile = sourceManager.createBranchedSession(leafId);
|
|
124
|
+
if (!sessionFile) {
|
|
125
|
+
throw new Error("Session manager did not return a forked session file.");
|
|
126
|
+
}
|
|
127
|
+
if (!fs.existsSync(sessionFile)) {
|
|
128
|
+
const header = sourceManager.getHeader?.();
|
|
129
|
+
const entries = sourceManager.getEntries?.();
|
|
130
|
+
if (!header || !entries) {
|
|
131
|
+
throw new Error(`Session manager returned a forked session file that does not exist and cannot be persisted by fallback: ${sessionFile}`);
|
|
132
|
+
}
|
|
133
|
+
sanitizeUnsafeThinkingBlocks(entries, Boolean(options.pruneSession));
|
|
134
|
+
fs.mkdirSync(path.dirname(sessionFile), { recursive: true });
|
|
135
|
+
fs.writeFileSync(sessionFile, `${[header, ...entries].map((entry) => JSON.stringify(entry)).join("\n")}
|
|
136
|
+
`, "utf-8");
|
|
137
|
+
} else {
|
|
138
|
+
const entries = readSessionEntries(sessionFile);
|
|
139
|
+
if (sanitizeUnsafeThinkingBlocks(entries, Boolean(options.pruneSession))) {
|
|
140
|
+
fs.writeFileSync(sessionFile, `${entries.map((entry) => JSON.stringify(entry)).join("\n")}
|
|
141
|
+
`, "utf-8");
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
cachedSessionFiles.set(index, sessionFile);
|
|
145
|
+
return sessionFile;
|
|
146
|
+
} catch (error) {
|
|
147
|
+
const cause = error instanceof Error ? error : new Error(String(error));
|
|
148
|
+
throw new Error(`Failed to create forked subagent session: ${cause.message}`, { cause });
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
return {
|
|
152
|
+
async prepareSessionForIndex(index = 0) {
|
|
153
|
+
const sessionFile = resolveFork(index);
|
|
154
|
+
if (!options.pruneSession || preparedIndexes.has(index)) return;
|
|
155
|
+
let preparation = preparationPromises.get(index);
|
|
156
|
+
if (!preparation) {
|
|
157
|
+
preparation = options.pruneSession(sessionFile).then(() => {
|
|
158
|
+
preparedIndexes.add(index);
|
|
159
|
+
});
|
|
160
|
+
preparationPromises.set(index, preparation);
|
|
161
|
+
}
|
|
162
|
+
await preparation;
|
|
163
|
+
},
|
|
164
|
+
sessionFileForIndex(index = 0) {
|
|
165
|
+
if (options.pruneSession && !preparedIndexes.has(index)) {
|
|
166
|
+
throw new Error(`Pruned fork session ${index} was used before pruning completed.`);
|
|
167
|
+
}
|
|
168
|
+
return resolveFork(index);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export {
|
|
174
|
+
buildEffectiveSystemPrompt,
|
|
175
|
+
resolveSubagentLaunchContext,
|
|
176
|
+
canPreferFork,
|
|
177
|
+
canPreferForkFromSnapshot,
|
|
178
|
+
createForkContextResolver
|
|
179
|
+
};
|