@vicary/pi-subagents 0.86.0 → 0.88.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.
Files changed (122) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/bundle/agents.js +3 -3
  3. package/bundle/child-tool-plan.js +2 -2
  4. package/bundle/{chunk-PYOAIN3V.js → chunk-2DIEL4WG.js} +2 -2
  5. package/bundle/{chunk-GJGTMLPE.js → chunk-3DT5X2QC.js} +483 -477
  6. package/bundle/{chunk-374MZFF4.js → chunk-3MFYKBKI.js} +23 -13
  7. package/bundle/{chunk-77ASNIEM.js → chunk-47ZN7NKR.js} +1 -1
  8. package/bundle/{chunk-QGO6HXHG.js → chunk-4MVDMA5C.js} +88 -64
  9. package/bundle/{chunk-3RKFH2UZ.js → chunk-6EUQPQY7.js} +31 -14
  10. package/bundle/{chunk-6VD7BGIC.js → chunk-6PR44R7E.js} +7 -2
  11. package/bundle/{chunk-DD22RXYJ.js → chunk-AOSILI5R.js} +200 -64
  12. package/bundle/{chunk-WHC2XHGF.js → chunk-BW5JLKIU.js} +174 -56
  13. package/bundle/{chunk-7ZUFN6ME.js → chunk-CKLZ5FGU.js} +2 -2
  14. package/bundle/{chunk-ZPY5QZCS.js → chunk-CYKNHFXB.js} +1 -1
  15. package/bundle/{chunk-YK3QYNLE.js → chunk-GDR2ILWY.js} +1 -1
  16. package/bundle/{chunk-7QA7ZA46.js → chunk-IZEKQEY4.js} +9 -9
  17. package/bundle/{chunk-CJHFDQFJ.js → chunk-JYHTDTOZ.js} +10 -6
  18. package/bundle/{chunk-NAFLUJ26.js → chunk-KXW62VBU.js} +1 -1
  19. package/bundle/{chunk-S2Q75LP3.js → chunk-L4YY2TOE.js} +1 -1
  20. package/bundle/{chunk-2DITXA3H.js → chunk-NVGQE2H2.js} +12 -12
  21. package/bundle/{chunk-BU6PFPVX.js → chunk-PJSOS2Q4.js} +12 -7
  22. package/bundle/{chunk-UR7OW5S7.js → chunk-RHYVKQQL.js} +11 -5
  23. package/bundle/{chunk-BGXEAYUM.js → chunk-SVIXQDIV.js} +20 -5
  24. package/bundle/{chunk-GLVJMI6R.js → chunk-TDJKY2NE.js} +14 -5
  25. package/bundle/{chunk-XOFYXQKZ.js → chunk-V7SZMS6W.js} +2 -2
  26. package/bundle/{chunk-NF7IEKBH.js → chunk-W2BZS6UC.js} +27 -13
  27. package/bundle/{chunk-5H4BICQZ.js → chunk-W6HIYD2Z.js} +1 -1
  28. package/bundle/{chunk-LGINOOY5.js → chunk-XIA5GSEU.js} +2 -2
  29. package/bundle/{chunk-QFLPV64W.js → chunk-XZXYPZUT.js} +46 -32
  30. package/bundle/chunk-YDZ7BZD5.js +523 -0
  31. package/bundle/{chunk-WN2E5XHN.js → chunk-YZPVALSQ.js} +30 -5
  32. package/bundle/control-channel.js +2 -2
  33. package/bundle/index.js +1 -1
  34. package/bundle/intercom-bridge.js +2 -2
  35. package/bundle/preflight.js +12 -10
  36. package/bundle/project-panes.js +3 -3
  37. package/bundle/workflow-resources.js +1 -1
  38. package/docs/agents.md +4 -4
  39. package/docs/configuration.md +14 -4
  40. package/docs/extension-api.md +2 -0
  41. package/docs/models.md +6 -2
  42. package/docs/observability.md +2 -0
  43. package/docs/tool-reference.md +5 -1
  44. package/package.json +3 -3
  45. package/skills/pi-subagents/SKILL.md +15 -6
  46. package/skills/pi-subagents/references/prompting-and-roles.md +1 -0
  47. package/src/agents/agent-management.d.ts +1 -0
  48. package/src/agents/agent-management.js +22 -10
  49. package/src/agents/agent-serializer.d.ts +2 -0
  50. package/src/agents/agent-serializer.js +1 -1
  51. package/src/agents/agents.d.ts +1 -0
  52. package/src/agents/agents.js +39 -14
  53. package/src/api/preflight.d.ts +3 -1
  54. package/src/api/preflight.js +2 -0
  55. package/src/extension/config.d.ts +9 -0
  56. package/src/extension/config.js +13 -0
  57. package/src/extension/index.js +8 -5
  58. package/src/extension/schemas.d.ts +4 -0
  59. package/src/extension/schemas.js +2 -0
  60. package/src/extension/tool-activation.js +20 -3
  61. package/src/runs/background/async-execution.d.ts +2 -1
  62. package/src/runs/background/async-execution.js +4 -2
  63. package/src/runs/background/async-resume.js +2 -1
  64. package/src/runs/background/async-retention.d.ts +0 -2
  65. package/src/runs/background/async-retention.js +11 -5
  66. package/src/runs/background/async-status.d.ts +2 -0
  67. package/src/runs/background/async-status.js +4 -0
  68. package/src/runs/background/run-child-session.d.ts +2 -2
  69. package/src/runs/background/run-child-session.js +4 -7
  70. package/src/runs/background/runner-aliases.js +15 -0
  71. package/src/runs/background/steering.d.ts +2 -11
  72. package/src/runs/background/steering.js +11 -6
  73. package/src/runs/background/subagent-runner.d.ts +0 -2
  74. package/src/runs/background/subagent-runner.js +73 -58
  75. package/src/runs/background/wait-subscriptions.js +124 -12
  76. package/src/runs/foreground/async-steering-action.js +24 -9
  77. package/src/runs/foreground/async-stop-action.d.ts +1 -1
  78. package/src/runs/foreground/async-stop-action.js +9 -1
  79. package/src/runs/foreground/execution.js +33 -15
  80. package/src/runs/foreground/prompt-audit.js +1 -0
  81. package/src/runs/foreground/subagent-executor.d.ts +2 -8
  82. package/src/runs/foreground/subagent-executor.js +57 -23
  83. package/src/runs/shared/async-status-projection.d.ts +2 -0
  84. package/src/runs/shared/async-status-projection.js +10 -0
  85. package/src/runs/shared/child-session.d.ts +5 -4
  86. package/src/runs/shared/child-session.js +64 -36
  87. package/src/runs/shared/herdr-placed-run.js +3 -2
  88. package/src/runs/shared/mcp-config-sources.d.ts +4 -1
  89. package/src/runs/shared/mcp-config-sources.js +1 -1
  90. package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -3
  91. package/src/runs/shared/mcp-direct-tool-allowlist.js +26 -17
  92. package/src/runs/shared/model-resolution.d.ts +19 -4
  93. package/src/runs/shared/model-resolution.js +50 -51
  94. package/src/runs/shared/subagent-prompt-runtime.js +14 -2
  95. package/src/runs/shared/supervisor-wait-timer.d.ts +16 -0
  96. package/src/runs/shared/supervisor-wait-timer.js +61 -0
  97. package/src/shared/artifacts.d.ts +1 -0
  98. package/src/shared/artifacts.js +132 -22
  99. package/src/shared/pruned-fork.js +2 -2
  100. package/src/shared/reported-progress.d.ts +1 -0
  101. package/src/shared/reported-progress.js +12 -0
  102. package/src/shared/status-format.d.ts +1 -0
  103. package/src/shared/status-format.js +1 -1
  104. package/src/shared/types.d.ts +23 -0
  105. package/src/shared/utils.d.ts +3 -1
  106. package/src/shared/utils.js +4 -0
  107. package/src/tui/render.js +33 -2
  108. package/src/watchdog/model-selection.js +2 -2
  109. package/src/watchdog/permission-arbiter.js +1 -0
  110. package/src/watchdog/review.d.ts +0 -5
  111. package/src/watchdog/review.js +4 -3
  112. package/src/workflows/scripted-workflow.d.ts +2 -0
  113. package/src/workflows/scripted-workflow.js +103 -39
  114. package/src/workflows/structured-workflow-scripts.d.ts +4 -3
  115. package/src/workflows/structured-workflow-scripts.js +32 -11
  116. package/src/workflows/workflow-resources.js +4 -4
  117. package/src/workflows/workflow-resume-claim.d.ts +2 -0
  118. package/src/workflows/workflow-resume-claim.js +1 -1
  119. package/src/workflows/workflow-resume.d.ts +1 -1
  120. package/src/workflows/workflow-resume.js +3 -1
  121. package/src/workflows/workflow-script-worker.js +3 -1
  122. package/bundle/chunk-GRJHIXYF.js +0 -235
@@ -1,235 +0,0 @@
1
- import {
2
- getAgentDir
3
- } from "./chunk-QGO6HXHG.js";
4
- import {
5
- TEMP_ARTIFACTS_DIR
6
- } from "./chunk-JEZOSEWG.js";
7
-
8
- // src/shared/artifacts.ts
9
- import * as fs from "node:fs";
10
- import * as path from "node:path";
11
- var CLEANUP_MARKER_FILE = ".last-cleanup";
12
- var PROJECT_SUBAGENTS_RELATIVE_DIR = ".pi/subagents";
13
- var PROJECT_ARTIFACT_PATHS = [
14
- `${PROJECT_SUBAGENTS_RELATIVE_DIR}/artifacts/output.md`,
15
- `${PROJECT_SUBAGENTS_RELATIVE_DIR}/artifacts/run_worker_input.md`,
16
- `${PROJECT_SUBAGENTS_RELATIVE_DIR}/artifacts/run_worker_output.md`,
17
- `${PROJECT_SUBAGENTS_RELATIVE_DIR}/artifacts/run_worker.jsonl`,
18
- `${PROJECT_SUBAGENTS_RELATIVE_DIR}/artifacts/run_worker_transcript.jsonl`,
19
- `${PROJECT_SUBAGENTS_RELATIVE_DIR}/artifacts/run_worker_meta.json`,
20
- `${PROJECT_SUBAGENTS_RELATIVE_DIR}/artifacts/progress/run/progress.md`,
21
- `${PROJECT_SUBAGENTS_RELATIVE_DIR}/artifacts/outputs/output.md`,
22
- `${PROJECT_SUBAGENTS_RELATIVE_DIR}/artifacts/outputs/run/output.md`,
23
- `${PROJECT_SUBAGENTS_RELATIVE_DIR}/chain-runs/run.json`
24
- ];
25
- function globMatchesPath(pattern, filePath) {
26
- let expression = "^";
27
- for (let index = 0; index < pattern.length; index += 1) {
28
- const character = pattern[index];
29
- if (character === void 0) break;
30
- if (character === "*" && pattern[index + 1] === "*") {
31
- index += 1;
32
- if (pattern[index + 1] === "/") {
33
- index += 1;
34
- expression += "(?:.*/)?";
35
- } else {
36
- expression += ".*";
37
- }
38
- } else if (character === "*") {
39
- expression += "[^/]*";
40
- } else if (character === "?") {
41
- expression += "[^/]";
42
- } else if (character === "[") {
43
- const end = pattern.indexOf("]", index + 1);
44
- if (end === -1) expression += "\\[";
45
- else {
46
- expression += pattern.slice(index, end + 1);
47
- index = end;
48
- }
49
- } else {
50
- expression += character.replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
51
- }
52
- }
53
- try {
54
- return new RegExp(`${expression}$`).test(filePath);
55
- } catch {
56
- return false;
57
- }
58
- }
59
- function normalizePattern(pattern) {
60
- return pattern.replace(/^\.\//, "").replace(/^\//, "").replace(/\/+$/, "");
61
- }
62
- function patternMatchesArtifactPath(pattern, artifactPath) {
63
- const normalized = normalizePattern(pattern);
64
- return normalized === PROJECT_SUBAGENTS_RELATIVE_DIR || normalized === "*" || artifactPath.startsWith(`${normalized}/`) || globMatchesPath(normalized, artifactPath);
65
- }
66
- function ignoreFileExcludesProjectArtifacts(filePath) {
67
- if (!fs.existsSync(filePath)) return false;
68
- try {
69
- const excluded = /* @__PURE__ */ new Set();
70
- for (const rawLine of fs.readFileSync(filePath, "utf-8").split(/\r?\n/)) {
71
- const line = rawLine.trim();
72
- if (!line || line.startsWith("#")) continue;
73
- const negated = line.startsWith("!");
74
- const pattern = negated ? line.slice(1) : line;
75
- for (const artifactPath of PROJECT_ARTIFACT_PATHS) {
76
- if (!patternMatchesArtifactPath(pattern, artifactPath)) continue;
77
- if (negated) excluded.delete(artifactPath);
78
- else excluded.add(artifactPath);
79
- }
80
- }
81
- return excluded.size === PROJECT_ARTIFACT_PATHS.length;
82
- } catch {
83
- return false;
84
- }
85
- }
86
- function filesIncludeProjectArtifacts(files) {
87
- if (!Array.isArray(files)) return void 0;
88
- const included = /* @__PURE__ */ new Set();
89
- for (const entry of files) {
90
- if (typeof entry !== "string") continue;
91
- const negated = entry.startsWith("!");
92
- const pattern = negated ? entry.slice(1) : entry;
93
- for (const artifactPath of PROJECT_ARTIFACT_PATHS) {
94
- if (!patternMatchesArtifactPath(pattern, artifactPath)) continue;
95
- if (negated) included.delete(artifactPath);
96
- else included.add(artifactPath);
97
- }
98
- }
99
- return included.size > 0;
100
- }
101
- function getProjectArtifactPackagingWarning(cwd) {
102
- const packagePath = path.join(cwd, "package.json");
103
- if (!fs.existsSync(packagePath)) return void 0;
104
- let packageJson;
105
- try {
106
- const parsed = JSON.parse(fs.readFileSync(packagePath, "utf-8"));
107
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return void 0;
108
- packageJson = parsed;
109
- } catch {
110
- return void 0;
111
- }
112
- const filesIncludeArtifacts = filesIncludeProjectArtifacts(packageJson.files);
113
- if (filesIncludeArtifacts === false) return void 0;
114
- const npmIgnorePath = path.join(cwd, ".npmignore");
115
- const ignorePath = fs.existsSync(npmIgnorePath) ? npmIgnorePath : path.join(cwd, ".gitignore");
116
- if (filesIncludeArtifacts === void 0 && ignoreFileExcludesProjectArtifacts(ignorePath)) return void 0;
117
- return "Project-scoped subagent artifacts can be included when this package is published. Add '.pi/subagents/' to .npmignore, restrict package.json files, or set artifactDir to 'session' or 'temp'.";
118
- }
119
- function getProjectSubagentsDir(cwd) {
120
- return path.join(cwd, PROJECT_SUBAGENTS_RELATIVE_DIR);
121
- }
122
- function getProjectArtifactsDir(cwd) {
123
- return path.join(getProjectSubagentsDir(cwd), "artifacts");
124
- }
125
- function getArtifactsDir(sessionFile, projectCwd, dirPreference = "session") {
126
- switch (dirPreference) {
127
- case "session":
128
- if (sessionFile) {
129
- const sessionDir = path.dirname(sessionFile);
130
- return path.join(sessionDir, "subagent-artifacts");
131
- }
132
- return TEMP_ARTIFACTS_DIR;
133
- case "temp":
134
- return TEMP_ARTIFACTS_DIR;
135
- case "project":
136
- if (projectCwd) return getProjectArtifactsDir(projectCwd);
137
- if (sessionFile) {
138
- const sessionDir = path.dirname(sessionFile);
139
- return path.join(sessionDir, "subagent-artifacts");
140
- }
141
- return TEMP_ARTIFACTS_DIR;
142
- default:
143
- throw new Error(`Unsupported artifactDir ${JSON.stringify(dirPreference)}; expected "project", "session", or "temp".`);
144
- }
145
- }
146
- function getArtifactPaths(artifactsDir, runId, agent, index) {
147
- const suffix = index !== void 0 ? `_${index}` : "";
148
- const safeAgent = agent.replace(/[^\w.-]/g, "_");
149
- const base = `${runId}_${safeAgent}${suffix}`;
150
- return {
151
- inputPath: path.join(artifactsDir, `${base}_input.md`),
152
- outputPath: path.join(artifactsDir, `${base}_output.md`),
153
- jsonlPath: path.join(artifactsDir, `${base}.jsonl`),
154
- transcriptPath: path.join(artifactsDir, `${base}_transcript.jsonl`),
155
- metadataPath: path.join(artifactsDir, `${base}_meta.json`)
156
- };
157
- }
158
- function ensureArtifactsDir(dir) {
159
- fs.mkdirSync(dir, { recursive: true });
160
- }
161
- function writeArtifact(filePath, content) {
162
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
163
- fs.writeFileSync(filePath, content, "utf-8");
164
- }
165
- function formatOutputArtifactContent(input) {
166
- if (input.output.trim() || !input.error) return input.output;
167
- const lines = ["Subagent run failed before producing output.", "", "Error:", input.error];
168
- if (input.transcriptPath) lines.push("", `Transcript: ${input.transcriptPath}`);
169
- if (input.metadataPath) lines.push(`Metadata: ${input.metadataPath}`);
170
- return lines.join("\n");
171
- }
172
- function writeMetadata(filePath, metadata) {
173
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
174
- fs.writeFileSync(filePath, JSON.stringify(metadata, null, 2), "utf-8");
175
- }
176
- function appendJsonl(filePath, line) {
177
- fs.appendFileSync(filePath, `${line}
178
- `);
179
- }
180
- function cleanupOldArtifacts(dir, maxAgeDays) {
181
- if (maxAgeDays <= 0 || !fs.existsSync(dir)) return;
182
- const markerPath = path.join(dir, CLEANUP_MARKER_FILE);
183
- const now = Date.now();
184
- if (fs.existsSync(markerPath)) {
185
- const stat = fs.statSync(markerPath);
186
- if (now - stat.mtimeMs < 24 * 60 * 60 * 1e3) return;
187
- }
188
- const maxAgeMs = maxAgeDays * 24 * 60 * 60 * 1e3;
189
- const cutoff = now - maxAgeMs;
190
- for (const file of fs.readdirSync(dir)) {
191
- if (file === CLEANUP_MARKER_FILE) continue;
192
- const filePath = path.join(dir, file);
193
- try {
194
- const stat = fs.statSync(filePath);
195
- if (stat.mtimeMs < cutoff) {
196
- fs.unlinkSync(filePath);
197
- }
198
- } catch {
199
- }
200
- }
201
- fs.writeFileSync(markerPath, String(now));
202
- }
203
- function cleanupAllArtifactDirs(maxAgeDays) {
204
- cleanupOldArtifacts(TEMP_ARTIFACTS_DIR, maxAgeDays);
205
- const sessionsBase = path.join(getAgentDir(), "sessions");
206
- if (!fs.existsSync(sessionsBase)) return;
207
- let dirs;
208
- try {
209
- dirs = fs.readdirSync(sessionsBase);
210
- } catch {
211
- return;
212
- }
213
- for (const dir of dirs) {
214
- const artifactsDir = path.join(sessionsBase, dir, "subagent-artifacts");
215
- try {
216
- cleanupOldArtifacts(artifactsDir, maxAgeDays);
217
- } catch {
218
- }
219
- }
220
- }
221
-
222
- export {
223
- PROJECT_SUBAGENTS_RELATIVE_DIR,
224
- getProjectArtifactPackagingWarning,
225
- getProjectSubagentsDir,
226
- getArtifactsDir,
227
- getArtifactPaths,
228
- ensureArtifactsDir,
229
- writeArtifact,
230
- formatOutputArtifactContent,
231
- writeMetadata,
232
- appendJsonl,
233
- cleanupOldArtifacts,
234
- cleanupAllArtifactDirs
235
- };