@xzzpig/pi-subagents 0.24.2 → 0.25.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 +22 -0
- package/bundle/agent-management.js +4 -4
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/chunk-34TUUBRN.js +1107 -0
- package/bundle/{chunk-SW2VMNIU.js → chunk-5OD3OWTE.js} +2 -2
- package/bundle/{chunk-XWWUDWUW.js → chunk-5YEOWNSD.js} +371 -135
- package/bundle/{chunk-EUPJB4S7.js → chunk-5Z7JAORM.js} +196 -1219
- package/bundle/{chunk-LCDJWBVM.js → chunk-66JNFRFS.js} +1 -1
- package/bundle/{chunk-4UH4WS4G.js → chunk-6MNRKUHY.js} +23 -12
- package/bundle/{chunk-ED55MIC2.js → chunk-CGFF4WA3.js} +42 -19
- package/bundle/{chunk-TMHVDPYW.js → chunk-DLVPMML3.js} +263 -154
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-355ECEP2.js → chunk-IH7LQVEE.js} +29 -14
- package/bundle/{chunk-CYY5UMJU.js → chunk-IJWITCC6.js} +411 -249
- package/bundle/{chunk-RU522D5W.js → chunk-IKFKH5EL.js} +369 -50
- package/bundle/{chunk-Z6TFJ6BR.js → chunk-INWSUNI6.js} +1 -1
- package/bundle/{chunk-JEA2ZKUA.js → chunk-IUDEI6FJ.js} +35 -200
- package/bundle/{chunk-WW76JRIX.js → chunk-JAXVBXGF.js} +1 -1
- package/bundle/{chunk-ICNYIALB.js → chunk-JH5H4CYJ.js} +784 -474
- package/bundle/{chunk-35GII5EF.js → chunk-JWFLPSTP.js} +41 -117
- package/bundle/{chunk-224WMDIV.js → chunk-KCJFGKVK.js} +350 -123
- package/bundle/{chunk-RB4GELQA.js → chunk-LPJEKHOY.js} +1 -1
- package/bundle/chunk-LYKG4FKH.js +523 -0
- package/bundle/{chunk-X6LOM3Z4.js → chunk-LZ3HBDTR.js} +161 -78
- package/bundle/{chunk-FG6SQJAR.js → chunk-OGPOCGWX.js} +24 -6
- package/bundle/{chunk-BQ2OAB4Q.js → chunk-OSVXFWPG.js} +67 -30
- package/bundle/{chunk-FJWI64H7.js → chunk-RMSABUN3.js} +27 -13
- package/bundle/{chunk-H36HBZB2.js → chunk-SJPABBZG.js} +2 -2
- package/bundle/{chunk-3U633XDZ.js → chunk-U3ZDUUTM.js} +11 -3
- package/bundle/{chunk-LVWU2HOO.js → chunk-ULGMXABL.js} +16 -7
- package/bundle/{chunk-WPW4V6HM.js → chunk-W7ZA6TYD.js} +2 -2
- package/bundle/{chunk-V2KFIGFH.js → chunk-XAC2XNAP.js} +503 -304
- package/bundle/{chunk-O4D5PBVI.js → chunk-YWXILP5N.js} +3 -2
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +12 -10
- package/bundle/project-panes.js +3 -3
- package/bundle/workflow-resources.js +1 -1
- package/docs/agents.md +27 -6
- package/docs/configuration.md +20 -8
- package/docs/extension-api.md +18 -1
- package/docs/models.md +6 -2
- package/docs/observability.md +2 -0
- package/docs/tool-reference.md +7 -1
- package/docs/workflows.md +30 -2
- package/package.json +2 -2
- package/skills/pi-subagents/SKILL.md +15 -6
- package/skills/pi-subagents/references/prompting-and-roles.md +1 -0
- package/src/agents/agent-management.d.ts +1 -0
- package/src/agents/agent-management.js +46 -18
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agent-serializer.d.ts +2 -0
- package/src/agents/agent-serializer.js +1 -1
- package/src/agents/agents.d.ts +2 -3
- package/src/agents/agents.js +46 -20
- package/src/agents/frontmatter.js +1 -8
- package/src/agents/global-npm-root.d.ts +1 -0
- package/src/agents/global-npm-root.js +11 -3
- package/src/agents/skills.d.ts +0 -3
- package/src/agents/skills.js +0 -3
- package/src/api/preflight.d.ts +3 -1
- package/src/api/preflight.js +2 -0
- package/src/extension/config.d.ts +1 -0
- package/src/extension/config.js +13 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +51 -37
- package/src/extension/public-execution.d.ts +1 -0
- package/src/extension/public-execution.js +4 -0
- package/src/extension/reply-workflow-script.js +24 -4
- package/src/extension/schemas.d.ts +12 -3
- package/src/extension/schemas.js +7 -3
- package/src/extension/session-switch.d.ts +25 -0
- package/src/extension/session-switch.js +138 -0
- package/src/extension/subagent-guide.d.ts +1 -1
- package/src/extension/subagent-guide.js +1 -1
- package/src/extension/subagent-launch-tool.d.ts +25 -0
- package/src/extension/subagent-launch-tool.js +48 -0
- package/src/extension/tool-activation.js +55 -15
- package/src/extension/tool-description.d.ts +1 -1
- package/src/extension/tool-description.js +14 -8
- package/src/inspectors/herdr/actions.d.ts +0 -1
- package/src/inspectors/herdr/actions.js +0 -1
- package/src/inspectors/session-roots-codec.d.ts +0 -1
- package/src/inspectors/session-roots-codec.js +0 -1
- package/src/inspectors/tmux/actions.d.ts +0 -1
- package/src/inspectors/tmux/actions.js +0 -1
- package/src/integrations/herdr-status.js +3 -8
- package/src/intercom/native-supervisor-channel.js +65 -9
- package/src/runs/background/async-execution.d.ts +7 -10
- package/src/runs/background/async-execution.js +66 -29
- package/src/runs/background/async-job-tracker.js +12 -0
- package/src/runs/background/async-resume.d.ts +2 -1
- package/src/runs/background/async-resume.js +114 -40
- package/src/runs/background/async-retention.d.ts +0 -2
- package/src/runs/background/async-retention.js +17 -6
- package/src/runs/background/async-status.d.ts +2 -0
- package/src/runs/background/async-status.js +4 -0
- package/src/runs/background/auto-drain.js +2 -1
- package/src/runs/background/boot-id.d.ts +1 -3
- package/src/runs/background/boot-id.js +1 -3
- package/src/runs/background/completion-batcher.d.ts +3 -4
- package/src/runs/background/completion-batcher.js +2 -3
- package/src/runs/background/control-channel.d.ts +0 -6
- package/src/runs/background/control-channel.js +0 -6
- package/src/runs/background/fleet-view.js +2 -3
- package/src/runs/background/notify.d.ts +0 -2
- package/src/runs/background/notify.js +0 -2
- package/src/runs/background/result-watcher.d.ts +1 -0
- package/src/runs/background/result-watcher.js +59 -29
- package/src/runs/background/resume-guidance.js +4 -2
- package/src/runs/background/retained-children.js +2 -1
- package/src/runs/background/run-child-session.d.ts +2 -3
- package/src/runs/background/run-child-session.js +5 -8
- package/src/runs/background/run-status.js +9 -7
- package/src/runs/background/runner-aliases.js +15 -0
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/steering.d.ts +2 -11
- package/src/runs/background/steering.js +11 -6
- package/src/runs/background/subagent-runner.d.ts +2 -6
- package/src/runs/background/subagent-runner.js +88 -70
- package/src/runs/background/subagent-wait.js +12 -15
- package/src/runs/background/wait-config.d.ts +2 -0
- package/src/runs/background/wait-config.js +17 -3
- package/src/runs/background/wait-subscriptions.js +124 -12
- package/src/runs/background/wait-tool.js +4 -2
- package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
- package/src/runs/background/workflow-terminal-proof.js +0 -1
- package/src/runs/foreground/async-steering-action.js +24 -9
- package/src/runs/foreground/async-stop-action.d.ts +1 -1
- package/src/runs/foreground/async-stop-action.js +9 -1
- package/src/runs/foreground/execution.d.ts +0 -3
- package/src/runs/foreground/execution.js +56 -24
- package/src/runs/foreground/prompt-audit.js +1 -0
- package/src/runs/foreground/subagent-executor.d.ts +5 -10
- package/src/runs/foreground/subagent-executor.js +164 -49
- package/src/runs/shared/acceptance.js +69 -26
- package/src/runs/shared/async-status-projection.d.ts +2 -0
- package/src/runs/shared/async-status-projection.js +10 -0
- package/src/runs/shared/child-commands.js +15 -2
- package/src/runs/shared/child-hooks.d.ts +1 -7
- package/src/runs/shared/child-hooks.js +13 -5
- package/src/runs/shared/child-launch.js +6 -2
- package/src/runs/shared/child-runtime-config.d.ts +0 -1
- package/src/runs/shared/child-session.d.ts +6 -5
- package/src/runs/shared/child-session.js +85 -38
- package/src/runs/shared/child-tool-plan.d.ts +0 -1
- package/src/runs/shared/child-tool-plan.js +0 -1
- package/src/runs/shared/claude-code-adapter.js +11 -0
- package/src/runs/shared/external-cli-contract.d.ts +49 -0
- package/src/runs/shared/external-cli-contract.js +18 -13
- package/src/runs/shared/external-cli-runner.js +26 -6
- package/src/runs/shared/herdr-connection.js +2 -1
- package/src/runs/shared/herdr-pane-host.d.ts +2 -2
- package/src/runs/shared/herdr-pane-host.js +17 -1
- package/src/runs/shared/herdr-placed-run.js +51 -24
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- package/src/runs/shared/mcp-config-sources.d.ts +4 -1
- package/src/runs/shared/mcp-config-sources.js +1 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -3
- package/src/runs/shared/mcp-direct-tool-allowlist.js +26 -17
- package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
- package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
- package/src/runs/shared/model-resolution.d.ts +20 -5
- package/src/runs/shared/model-resolution.js +55 -50
- package/src/runs/shared/model-scope.d.ts +1 -5
- package/src/runs/shared/model-scope.js +1 -5
- package/src/runs/shared/mutation-evidence.d.ts +1 -1
- package/src/runs/shared/mutation-evidence.js +52 -7
- package/src/runs/shared/nested-events.d.ts +1 -0
- package/src/runs/shared/nested-events.js +1 -1
- package/src/runs/shared/parallel-utils.d.ts +0 -1
- package/src/runs/shared/permissions.js +5 -3
- package/src/runs/shared/placement-host.d.ts +5 -1
- package/src/runs/shared/rex-pane-host.d.ts +0 -1
- package/src/runs/shared/rex-pane-host.js +0 -2
- package/src/runs/shared/run-launch-folder.d.ts +12 -0
- package/src/runs/shared/run-launch-folder.js +21 -0
- package/src/runs/shared/runner-launcher.d.ts +12 -1
- package/src/runs/shared/runner-launcher.js +16 -0
- package/src/runs/shared/single-output.d.ts +3 -3
- package/src/runs/shared/single-output.js +5 -3
- package/src/runs/shared/structured-output.d.ts +8 -0
- package/src/runs/shared/structured-output.js +40 -5
- package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
- package/src/runs/shared/subagent-prompt-runtime.js +18 -4
- package/src/runs/shared/supervisor-wait-timer.d.ts +16 -0
- package/src/runs/shared/supervisor-wait-timer.js +61 -0
- package/src/runs/shared/tool-timeout.js +2 -1
- package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
- package/src/runs/shared/worktree-cleanup-plan.js +0 -1
- package/src/runs/shared/worktree.d.ts +3 -0
- package/src/runs/shared/worktree.js +20 -0
- package/src/shared/artifacts.d.ts +1 -0
- package/src/shared/artifacts.js +132 -22
- package/src/shared/capacity-resilient-json.d.ts +1 -1
- package/src/shared/child-cache-retention.d.ts +1 -2
- package/src/shared/child-cache-retention.js +1 -2
- package/src/shared/fleet-transcript-reader.d.ts +51 -0
- package/src/shared/fleet-transcript-reader.js +333 -0
- package/src/shared/formatters.d.ts +0 -18
- package/src/shared/formatters.js +0 -18
- package/src/shared/pruned-fork.js +2 -2
- package/src/shared/reported-progress.d.ts +1 -0
- package/src/shared/reported-progress.js +12 -0
- package/src/shared/session-succession.d.ts +16 -1
- package/src/shared/session-succession.js +41 -2
- package/src/shared/session-warnings.d.ts +7 -0
- package/src/shared/session-warnings.js +26 -0
- package/src/shared/settings.d.ts +0 -23
- package/src/shared/settings.js +3 -35
- package/src/shared/status-format.d.ts +1 -0
- package/src/shared/status-format.js +1 -1
- package/src/shared/types.d.ts +108 -59
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +3 -15
- package/src/shared/utils.js +4 -22
- package/src/shared/wait-tool-name.d.ts +8 -0
- package/src/shared/wait-tool-name.js +13 -0
- package/src/slash/slash-commands.js +2 -1
- package/src/slash/subagent-cost.d.ts +3 -2
- package/src/slash/subagent-cost.js +22 -3
- package/src/slash/subagents-admin.js +0 -1
- package/src/tui/fleet-status.d.ts +0 -5
- package/src/tui/fleet-status.js +4 -24
- package/src/tui/fleet.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +194 -68
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/model-selection.js +2 -2
- package/src/watchdog/permission-arbiter.js +1 -0
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/review.d.ts +0 -5
- package/src/watchdog/review.js +4 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.d.ts +2 -0
- package/src/workflows/scripted-workflow.js +344 -59
- package/src/workflows/structured-workflow-scripts.d.ts +4 -3
- package/src/workflows/structured-workflow-scripts.js +32 -11
- package/src/workflows/workflow-launch-record.d.ts +15 -6
- package/src/workflows/workflow-launch-record.js +30 -12
- package/src/workflows/workflow-receipt.js +36 -53
- package/src/workflows/workflow-resources.js +4 -4
- package/src/workflows/workflow-resume-claim.d.ts +2 -0
- package/src/workflows/workflow-resume-claim.js +3 -3
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +13 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +81 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +4 -1
- package/bundle/chunk-U4ODUYAG.js +0 -235
package/bundle/chunk-U4ODUYAG.js
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getAgentDir
|
|
3
|
-
} from "./chunk-V2KFIGFH.js";
|
|
4
|
-
import {
|
|
5
|
-
TEMP_ARTIFACTS_DIR
|
|
6
|
-
} from "./chunk-UQDHXMUG.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
|
-
};
|