pi-subagents 0.89.0 → 0.89.1
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 +15 -0
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/{chunk-WW6GQBBS.js → chunk-4FFKVLBG.js} +4 -4
- package/bundle/{chunk-JRO2CU4D.js → chunk-5TXWZB73.js} +1 -1
- package/bundle/{chunk-CHEABMO2.js → chunk-6D54VW3E.js} +19 -19
- package/bundle/{chunk-S77ZKDLS.js → chunk-77VQEATI.js} +1 -1
- package/bundle/{chunk-443LPCRI.js → chunk-BERAWSQQ.js} +5 -5
- package/bundle/{chunk-7W2IQFP4.js → chunk-C22YEYFZ.js} +4 -4
- package/bundle/{chunk-2I6YN6ET.js → chunk-CASL47ST.js} +8 -8
- package/bundle/{chunk-YX7R55CR.js → chunk-F6PTAPQ3.js} +12 -12
- package/bundle/{chunk-AZW4HXNU.js → chunk-IGZTXGPG.js} +98 -29
- package/bundle/{chunk-SLLZJ5EC.js → chunk-KCDPTXHT.js} +2 -2
- package/bundle/{chunk-X5ZOTDHO.js → chunk-LUNVS6KP.js} +11 -11
- package/bundle/{chunk-GHJ6BH5U.js → chunk-LWH7IGI3.js} +8 -0
- package/bundle/{chunk-NQ26PJSQ.js → chunk-MIX3MCIF.js} +4 -4
- package/bundle/{chunk-JFACGAJT.js → chunk-OUM6SEVD.js} +2 -2
- package/bundle/{chunk-UQT2EQ4U.js → chunk-Q4VH72JI.js} +2 -2
- package/bundle/{chunk-HZDLR73C.js → chunk-R3NH5XAL.js} +1 -1
- package/bundle/{chunk-PPPAEFRA.js → chunk-ROJH7KPK.js} +2 -2
- package/bundle/{chunk-6JD4XCA4.js → chunk-SG3NCWZW.js} +14 -6
- package/bundle/{chunk-KOLLMZ2X.js → chunk-SWGB2P5J.js} +1 -1
- package/bundle/{chunk-TGABNSG5.js → chunk-TDXVQPZW.js} +4 -4
- package/bundle/{chunk-4ALRHKGE.js → chunk-TRN65L4F.js} +1 -1
- package/bundle/{chunk-ZSCIHMUI.js → chunk-TXC7WIPL.js} +3 -2
- package/bundle/{chunk-HSHLPYCQ.js → chunk-URKQZHVH.js} +9 -9
- package/bundle/{chunk-A3INCQ6Z.js → chunk-UUW7P6KJ.js} +1 -1
- package/bundle/{chunk-EPMRDKQT.js → chunk-VEEUXJDO.js} +1 -1
- package/bundle/{chunk-NONHDYXE.js → chunk-YJIU5WF4.js} +1 -1
- package/bundle/{chunk-ETDE2VYK.js → chunk-YLU5JFW2.js} +2 -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 +8 -8
- package/bundle/project-panes.js +3 -3
- package/docs/agents.md +2 -2
- package/package.json +1 -1
- package/src/extension/herdr-pi-bridge.js +1 -1
- package/src/runs/background/async-job-tracker.js +85 -9
- package/src/runs/background/async-status.d.ts +2 -0
- package/src/runs/background/async-status.js +8 -3
- package/src/runs/shared/herdr-machine.js +3 -1
- package/src/runs/shared/subagent-prompt-runtime.js +6 -5
- package/src/shared/utils.d.ts +2 -0
- package/src/shared/utils.js +9 -0
|
@@ -7,37 +7,37 @@ import {
|
|
|
7
7
|
safeTranscriptEvent,
|
|
8
8
|
steerAsyncRun,
|
|
9
9
|
steerWorkflowForegroundTarget
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-BERAWSQQ.js";
|
|
11
11
|
import {
|
|
12
12
|
FLEET_STATUS_WIDGET_KEY,
|
|
13
13
|
runningTone,
|
|
14
14
|
stepTaskSummary
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-4FFKVLBG.js";
|
|
16
16
|
import {
|
|
17
17
|
foregroundChildStateLabel,
|
|
18
18
|
formatAsyncRunTranscript,
|
|
19
19
|
stopAsyncRun
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-C22YEYFZ.js";
|
|
21
21
|
import {
|
|
22
22
|
contextModeBadge,
|
|
23
23
|
contextModeLabel,
|
|
24
24
|
decodeUtf8Tail,
|
|
25
25
|
listAsyncRuns
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-SG3NCWZW.js";
|
|
27
27
|
import {
|
|
28
28
|
reportSessionWarning
|
|
29
29
|
} from "./chunk-HXRB42AF.js";
|
|
30
|
-
import "./chunk-
|
|
31
|
-
import "./chunk-
|
|
30
|
+
import "./chunk-KCDPTXHT.js";
|
|
31
|
+
import "./chunk-UUW7P6KJ.js";
|
|
32
32
|
import "./chunk-NIXWDZZV.js";
|
|
33
|
-
import "./chunk-
|
|
33
|
+
import "./chunk-YJIU5WF4.js";
|
|
34
34
|
import "./chunk-7F6RKT6W.js";
|
|
35
35
|
import "./chunk-YARY7JWU.js";
|
|
36
36
|
import "./chunk-7J4ZXMY7.js";
|
|
37
37
|
import {
|
|
38
38
|
getArtifactPaths,
|
|
39
39
|
getArtifactsDir
|
|
40
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-77VQEATI.js";
|
|
41
41
|
import {
|
|
42
42
|
snapshotExternalRuns
|
|
43
43
|
} from "./chunk-UKG4V45O.js";
|
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
formatTokens,
|
|
50
50
|
readStatus,
|
|
51
51
|
shortenPath
|
|
52
|
-
} from "./chunk-
|
|
52
|
+
} from "./chunk-LWH7IGI3.js";
|
|
53
53
|
import {
|
|
54
54
|
DIRS
|
|
55
55
|
} from "./chunk-JEZOSEWG.js";
|
|
@@ -11,13 +11,13 @@ import {
|
|
|
11
11
|
validateAuthorityPolicy,
|
|
12
12
|
validateMissionStoreConfig,
|
|
13
13
|
validateModelResponseAliases
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-KCDPTXHT.js";
|
|
15
15
|
import {
|
|
16
16
|
getAgentDir,
|
|
17
17
|
readStatus,
|
|
18
18
|
validatePermissionConfig,
|
|
19
19
|
writePrivateAtomicJson
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-LWH7IGI3.js";
|
|
21
21
|
import {
|
|
22
22
|
FLEET_KEYBINDING_ACTIONS,
|
|
23
23
|
RUNNER_LAUNCHER_NAME_PATTERN,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
requestAsyncStop
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-UUW7P6KJ.js";
|
|
4
4
|
import "./chunk-NIXWDZZV.js";
|
|
5
|
-
import "./chunk-
|
|
5
|
+
import "./chunk-LWH7IGI3.js";
|
|
6
6
|
import "./chunk-JEZOSEWG.js";
|
|
7
7
|
import "./chunk-YFCK7H2S.js";
|
|
8
8
|
import "./chunk-QXASAHIA.js";
|
package/bundle/index.js
CHANGED
|
@@ -17,7 +17,7 @@ function readInstalledPackageVersion() {
|
|
|
17
17
|
var loadedPackageVersion = readInstalledPackageVersion();
|
|
18
18
|
|
|
19
19
|
// index.ts
|
|
20
|
-
var registerExtension = process.env[HERDR_PI_MODE_ENV] === "1" ? (await import("./chunk-
|
|
20
|
+
var registerExtension = process.env[HERDR_PI_MODE_ENV] === "1" ? (await import("./chunk-F6PTAPQ3.js")).default : process.env.PI_SUBAGENT_CHILD === "1" ? void 0 : (await import("./chunk-IGZTXGPG.js")).default;
|
|
21
21
|
function registerSubagentExtension(pi) {
|
|
22
22
|
const installedVersion = readInstalledPackageVersion();
|
|
23
23
|
if (installedVersion !== loadedPackageVersion) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveIntercomSessionTarget
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YJIU5WF4.js";
|
|
4
4
|
import "./chunk-7F6RKT6W.js";
|
|
5
|
-
import "./chunk-
|
|
5
|
+
import "./chunk-LWH7IGI3.js";
|
|
6
6
|
import "./chunk-JEZOSEWG.js";
|
|
7
7
|
import "./chunk-YFCK7H2S.js";
|
|
8
8
|
import "./chunk-QXASAHIA.js";
|
package/bundle/preflight.js
CHANGED
|
@@ -2,22 +2,22 @@ import {
|
|
|
2
2
|
buildEffectiveSystemPrompt,
|
|
3
3
|
canPreferForkFromSnapshot,
|
|
4
4
|
resolveSubagentLaunchContext
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-ROJH7KPK.js";
|
|
6
|
+
import "./chunk-Q4VH72JI.js";
|
|
7
7
|
import {
|
|
8
8
|
loadConfig
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-YLU5JFW2.js";
|
|
10
10
|
import {
|
|
11
11
|
nestedResultsPath,
|
|
12
12
|
processTerminalCandidatePath,
|
|
13
13
|
processTerminalPath,
|
|
14
14
|
resultFilePath
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-KCDPTXHT.js";
|
|
16
16
|
import {
|
|
17
17
|
applyIntercomBridgeToAgent,
|
|
18
18
|
resolveIntercomBridge,
|
|
19
19
|
validateIntercomBridgeConfig
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-YJIU5WF4.js";
|
|
21
21
|
import {
|
|
22
22
|
AGENT_DEFINITION_PROJECTION_VERSION,
|
|
23
23
|
resolveLaunchBinding,
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
import {
|
|
27
27
|
applyThinkingSuffix,
|
|
28
28
|
resolvePiLaunchToolPlan
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-R3NH5XAL.js";
|
|
30
30
|
import {
|
|
31
31
|
assertRequiredChildExtensionsAdmitted,
|
|
32
32
|
resolveRequiredChildExtensions
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
import {
|
|
35
35
|
getArtifactPaths,
|
|
36
36
|
getArtifactsDir
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-77VQEATI.js";
|
|
38
38
|
import {
|
|
39
39
|
assertClaudeCodeModelScope,
|
|
40
40
|
assertThinkingWithinCeiling,
|
|
@@ -61,7 +61,7 @@ import {
|
|
|
61
61
|
resolveSkillsWithFallback,
|
|
62
62
|
resolveStepBehavior,
|
|
63
63
|
unknownAgentDiagnosticContext
|
|
64
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-LWH7IGI3.js";
|
|
65
65
|
import {
|
|
66
66
|
DIRS,
|
|
67
67
|
SUBAGENT_LIFECYCLE_ARTIFACT_VERSION,
|
package/bundle/project-panes.js
CHANGED
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
openProjectPane,
|
|
9
9
|
projectPaneBindingPath,
|
|
10
10
|
readProjectPaneBinding
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-OUM6SEVD.js";
|
|
12
12
|
import "./chunk-7J4ZXMY7.js";
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
13
|
+
import "./chunk-77VQEATI.js";
|
|
14
|
+
import "./chunk-LWH7IGI3.js";
|
|
15
15
|
import "./chunk-JEZOSEWG.js";
|
|
16
16
|
import "./chunk-YFCK7H2S.js";
|
|
17
17
|
import "./chunk-QXASAHIA.js";
|
package/docs/agents.md
CHANGED
|
@@ -269,7 +269,7 @@ A custom agent file that shadows a bundled agent replaces the bundled definition
|
|
|
269
269
|
|
|
270
270
|
Native Pi and the six code-owned Claude Code, Codex, and Cursor profiles can run on a Herdr machine (`herdr machine add <target> --label <name>`). Herdr owns each visible agent process in a fresh no-focus pane; SSH is used only as bounded transport for Herdr RPC and ownership checks. Herdr's catalog is the host allowlist; raw ssh targets are rejected.
|
|
271
271
|
|
|
272
|
-
For a pane on this machine you don't need a saved machine: run Pi inside Herdr and use `machine: "local"`.
|
|
272
|
+
For a pane on this machine you don't need a saved machine: run Pi inside Herdr and use `machine: "local"`. This means the herdr terminal multiplexer; terminals of Herdr Core (`hc`, the Herdr app's terminal server) are not supported.
|
|
273
273
|
|
|
274
274
|
`machine` is a top-level frontmatter key, a settings override (`subagents.agentOverrides.<agent>.machine`, project beats user, `false` clears a pin), and a launch option on the `subagent` tool, workflow `runs.run`, chain, parallel, and dynamic-fanout steps. The launch option wins. Placement survives `subagent({ action: "disable" })`, `reset`, and model profile switches.
|
|
275
275
|
|
|
@@ -575,7 +575,7 @@ How `tools` behaves:
|
|
|
575
575
|
|
|
576
576
|
An allowlisted name does not load the extension that registers it. Load that provider through `extensions`, `subagentOnlyExtensions`, a path-like `tools` entry, or (background children only) normal Pi extension discovery. Pi's built-in `codemode` is the exception: native children register the host SDK's official factory when codemode is permitted, without enabling it in the main session. On older Pi hosts without that factory, a child that requests codemode still reports it as unavailable; a capability ceiling that denies extensions prevents its registration.
|
|
577
577
|
|
|
578
|
-
An extension loaded in the child can also replace the tools sent to the model, as pi-fabric's code mode does when it offers only `fabric_exec`. A child with a `tools` allowlist then fails before its first model request, and the error names the allowlisted tools the request left out. Set `extensions: []` or list only the extensions the child needs, or omit `tools` to use that extension's tool surface.
|
|
578
|
+
An extension loaded in the child can also replace the tools sent to the model, as pi-fabric's code mode does when it offers only `fabric_exec`. A child with a `tools` allowlist then fails before its first model request, and the error names the active allowlisted tools the request left out. Set `extensions: []` or list only the extensions the child needs, or omit `tools` to use that extension's tool surface. An allowlisted tool that an extension keeps inactive, such as pi-web-access's `web_enable` loader, can be left out of a request without failing the child.
|
|
579
579
|
|
|
580
580
|
Ambient extensions depend on where the child runs. Local foreground children are sessions inside the parent Pi process and never load the parent's ambient extensions; otherwise the parent would start a second copy of each ambient extension, including this one. Background children are sessions inside the detached runner process and load the ambient extensions unless the agent sets `extensions` or the capability ceiling denies extensions. Local foreground children do inherit the providers the parent's extensions registered (`pi.registerProvider`), so their models resolve without loading those extensions again. The child gets the provider but not the registering extension's session hooks, so a provider that relies on its own hooks (for example to record each session's system prompt) can fail the child's first request; the foreground error then says so. Use `async: true` or list that extension in the agent's `subagentOnlyExtensions` or `extensions`. Pane-native remote foreground children instead use the remote machine's provider discovery and configuration. Agents that need MCP tools from an ambient adapter such as pi-mcp-adapter (including `mcp:` entries the adapter resolves) must therefore run as background children (`async: true`). A foreground launch of such an agent fails with a diagnostic that says exactly that.
|
|
581
581
|
|
package/package.json
CHANGED
|
@@ -171,7 +171,7 @@ export default function registerHerdrPiBridge(pi) {
|
|
|
171
171
|
else if (request.operation === "follow-up")
|
|
172
172
|
api.sendUserMessage(request.text ?? "", { deliverAs: "followUp" });
|
|
173
173
|
else if (request.operation === "abort")
|
|
174
|
-
|
|
174
|
+
ctx.abort();
|
|
175
175
|
else {
|
|
176
176
|
const entry = request.supervisorId ? supervisor.get(request.supervisorId) : undefined;
|
|
177
177
|
if (!entry)
|
|
@@ -3,11 +3,11 @@ import * as path from "node:path";
|
|
|
3
3
|
import { renderWidget, widgetRenderKey } from "../../tui/render.js";
|
|
4
4
|
import { formatControlNoticeMessage } from "../shared/subagent-control.js";
|
|
5
5
|
import { DIRS, SUBAGENT_CHILD_STATUS_EVENT, SUBAGENT_CONTROL_EVENT, SUBAGENT_CONTROL_INTERCOM_EVENT, SUBAGENT_JOBS_CHANGED_EVENT, SUBAGENT_STEERING_NOTICE_EVENT, WIDGET_ANIMATION_INTERVAL_MS, } from "../../shared/types.js";
|
|
6
|
-
import { readStatus, resolveWatchPath } from "../../shared/utils.js";
|
|
6
|
+
import { isStatusAccessError, readStatus, resolveWatchPath } from "../../shared/utils.js";
|
|
7
7
|
import { normalizeParallelGroups } from "./parallel-groups.js";
|
|
8
8
|
import { reconcileAsyncRun, reconcileNestedAsyncDescendants } from "./stale-run-reconciler.js";
|
|
9
9
|
import { findNestedRouteForRootId, hasLiveNestedDescendants, retainNestedLookupRoute, updateAsyncJobNestedProjection } from "../shared/nested-events.js";
|
|
10
|
-
import { listAsyncRuns } from "./async-status.js";
|
|
10
|
+
import { listAsyncRuns, summarizeAsyncStatus } from "./async-status.js";
|
|
11
11
|
import { EXTERNAL_JOB_BRIDGE_REQUEST_DIR, externalJobBridgeEligibility, serviceExternalJobBridgeRequests } from "../shared/external-job-bridge.js";
|
|
12
12
|
import { shouldUseNativeFsWatch } from "../../shared/watch-strategy.js";
|
|
13
13
|
import { parseWorkflowChildSummary } from "../../workflows/workflow-child-summary.js";
|
|
@@ -49,6 +49,12 @@ export function createAsyncJobTracker(pi, state, asyncDirRoot, options = {}) {
|
|
|
49
49
|
// Early native failure is visible before its publisher finishes. Retain only
|
|
50
50
|
// that scoped observation, using the existing liveness sweep to renew delivery.
|
|
51
51
|
const terminalPublications = new Map();
|
|
52
|
+
// Runs whose status.json this process may not read. An unreadable file says nothing about the
|
|
53
|
+
// runner, so the job keeps its last known state rather than reading as finished (#3295).
|
|
54
|
+
const unreadableStatusRuns = new Set();
|
|
55
|
+
// Restored runs whose status.json was unreadable, so their owner is unknown. Each is counted as
|
|
56
|
+
// this session's until a read shows otherwise; nothing writes to it before then.
|
|
57
|
+
const unverifiedRuns = new Set();
|
|
52
58
|
const supervisorNoticeTimers = new Map();
|
|
53
59
|
let rootWatcher;
|
|
54
60
|
let nextLivenessAt = Date.now() + livenessIntervalMs;
|
|
@@ -424,9 +430,53 @@ export function createAsyncJobTracker(pi, state, asyncDirRoot, options = {}) {
|
|
|
424
430
|
runningJobIds.delete(asyncId);
|
|
425
431
|
externalJobBridgeRuns.delete(asyncId);
|
|
426
432
|
terminalPublications.delete(asyncId);
|
|
433
|
+
unreadableStatusRuns.delete(asyncId);
|
|
434
|
+
unverifiedRuns.delete(asyncId);
|
|
427
435
|
clearSupervisorNotices(asyncId);
|
|
428
436
|
};
|
|
437
|
+
const forgetJob = (asyncId) => {
|
|
438
|
+
cancelCleanup(asyncId);
|
|
439
|
+
closeJobWatcher(asyncId);
|
|
440
|
+
state.asyncJobs.delete(asyncId);
|
|
441
|
+
state.fleetJobs?.delete(asyncId);
|
|
442
|
+
options.onJobCleanup?.(asyncId);
|
|
443
|
+
};
|
|
429
444
|
const refreshJob = (job) => {
|
|
445
|
+
if (unverifiedRuns.has(job.asyncId)) {
|
|
446
|
+
let stored = null;
|
|
447
|
+
let summary;
|
|
448
|
+
try {
|
|
449
|
+
stored = readStatus(job.asyncDir);
|
|
450
|
+
if (stored)
|
|
451
|
+
summary = summarizeAsyncStatus(job.asyncDir, stored);
|
|
452
|
+
}
|
|
453
|
+
catch (error) {
|
|
454
|
+
if (isStatusAccessError(error, job.asyncDir))
|
|
455
|
+
return false;
|
|
456
|
+
console.error(`[pi-subagents] Dropping restored async run '${job.asyncId}' at '${path.join(job.asyncDir, "status.json")}': ${error instanceof Error ? error.message : String(error)}.`);
|
|
457
|
+
}
|
|
458
|
+
const owners = state.currentSessionId ? ownerSessionIds(state.currentSessionId) : undefined;
|
|
459
|
+
if (!stored || !summary || (owners && !owners.has(stored.sessionId))) {
|
|
460
|
+
forgetJob(job.asyncId);
|
|
461
|
+
return true;
|
|
462
|
+
}
|
|
463
|
+
let restored;
|
|
464
|
+
try {
|
|
465
|
+
restored = summaryToJob(summary);
|
|
466
|
+
}
|
|
467
|
+
catch (error) {
|
|
468
|
+
if (!unreadableStatusRuns.has(job.asyncId)) {
|
|
469
|
+
unreadableStatusRuns.add(job.asyncId);
|
|
470
|
+
console.error(`Cannot read async control events for '${job.asyncDir}'; keeping it as running until they are readable:`, error);
|
|
471
|
+
}
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
// Become the job a normal restore would have made, but keep the placeholder's state so the
|
|
475
|
+
// refresh below sees any transition, and its cursor when restore could read events.jsonl.
|
|
476
|
+
Object.assign(job, restored, { status: job.status, controlEventCursor: job.controlEventCursor ?? restored.controlEventCursor });
|
|
477
|
+
rememberFleetJob(state, job);
|
|
478
|
+
unverifiedRuns.delete(job.asyncId);
|
|
479
|
+
}
|
|
430
480
|
const widgetExpanded = withLastUiContext((ctx) => ctx.ui.getToolsExpanded?.() ?? false) ?? false;
|
|
431
481
|
const widgetStateBefore = widgetRenderKey(job, widgetExpanded);
|
|
432
482
|
let nestedRefreshFailed = false;
|
|
@@ -475,6 +525,7 @@ export function createAsyncJobTracker(pi, state, asyncDirRoot, options = {}) {
|
|
|
475
525
|
},
|
|
476
526
|
});
|
|
477
527
|
const status = reconciliation.status ?? readStatus(job.asyncDir);
|
|
528
|
+
unreadableStatusRuns.delete(job.asyncId);
|
|
478
529
|
if (!bridgeAlreadyRequired) {
|
|
479
530
|
const bridgeEligibility = externalJobBridgeEligibility(status?.steps);
|
|
480
531
|
if (bridgeEligibility === "required")
|
|
@@ -612,6 +663,13 @@ export function createAsyncJobTracker(pi, state, asyncDirRoot, options = {}) {
|
|
|
612
663
|
console.error(`Failed to service external job bridge for '${job.asyncDir}':`, bridgeError);
|
|
613
664
|
}
|
|
614
665
|
}
|
|
666
|
+
if (isStatusAccessError(error, job.asyncDir)) {
|
|
667
|
+
if (!unreadableStatusRuns.has(job.asyncId)) {
|
|
668
|
+
unreadableStatusRuns.add(job.asyncId);
|
|
669
|
+
console.error(`Cannot read async status for '${job.asyncDir}'; keeping its last known state until it is readable:`, error);
|
|
670
|
+
}
|
|
671
|
+
return widgetRenderKey(job, widgetExpanded) !== widgetStateBefore;
|
|
672
|
+
}
|
|
615
673
|
if (job.status !== "failed") {
|
|
616
674
|
console.error(`Failed to read async status for '${job.asyncDir}':`, error);
|
|
617
675
|
job.status = "failed";
|
|
@@ -751,11 +809,7 @@ export function createAsyncJobTracker(pi, state, asyncDirRoot, options = {}) {
|
|
|
751
809
|
const owners = state.currentSessionId ? ownerSessionIds(state.currentSessionId) : undefined;
|
|
752
810
|
for (const job of state.asyncJobs.values()) {
|
|
753
811
|
if (owners && job.sessionId !== undefined && !owners.has(job.sessionId)) {
|
|
754
|
-
|
|
755
|
-
closeJobWatcher(job.asyncId);
|
|
756
|
-
state.asyncJobs.delete(job.asyncId);
|
|
757
|
-
state.fleetJobs?.delete(job.asyncId);
|
|
758
|
-
options.onJobCleanup?.(job.asyncId);
|
|
812
|
+
forgetJob(job.asyncId);
|
|
759
813
|
widgetChanged = true;
|
|
760
814
|
continue;
|
|
761
815
|
}
|
|
@@ -881,6 +935,8 @@ export function createAsyncJobTracker(pi, state, asyncDirRoot, options = {}) {
|
|
|
881
935
|
runningJobIds.clear();
|
|
882
936
|
externalJobBridgeRuns.clear();
|
|
883
937
|
terminalPublications.clear();
|
|
938
|
+
unreadableStatusRuns.clear();
|
|
939
|
+
unverifiedRuns.clear();
|
|
884
940
|
clearSupervisorNotices();
|
|
885
941
|
};
|
|
886
942
|
const resetJobs = (ctx) => {
|
|
@@ -907,9 +963,13 @@ export function createAsyncJobTracker(pi, state, asyncDirRoot, options = {}) {
|
|
|
907
963
|
if (!state.currentSessionId)
|
|
908
964
|
return;
|
|
909
965
|
let runs;
|
|
966
|
+
const unreadable = [];
|
|
910
967
|
try {
|
|
911
968
|
// A workflow whose Pi exited is repaired here, in the session that owns it, which then delivers its notice.
|
|
912
|
-
runs = listAsyncRuns(asyncDirRoot, {
|
|
969
|
+
runs = listAsyncRuns(asyncDirRoot, {
|
|
970
|
+
states: ["queued", "running"], sessionId: state.currentSessionId, resultsDir, kill: options.kill, now: options.now, adoptCompletionOwnerId: state.completionOwnerId,
|
|
971
|
+
onUnreadableActiveRun: (runId, asyncDir) => unreadable.push({ runId, asyncDir }),
|
|
972
|
+
}, observeStatus);
|
|
913
973
|
}
|
|
914
974
|
catch (error) {
|
|
915
975
|
console.error(`Failed to restore active async jobs from '${asyncDirRoot}':`, error);
|
|
@@ -923,8 +983,24 @@ export function createAsyncJobTracker(pi, state, asyncDirRoot, options = {}) {
|
|
|
923
983
|
rememberFleetJob(state, job);
|
|
924
984
|
watchJob(job);
|
|
925
985
|
}
|
|
986
|
+
// An unreadable run may still be working: idle must not be reported until a read settles it.
|
|
987
|
+
for (const { runId, asyncDir } of unreadable) {
|
|
988
|
+
if (state.asyncJobs.has(runId))
|
|
989
|
+
continue;
|
|
990
|
+
const job = { asyncId: runId, asyncDir, status: "running", sessionId: state.currentSessionId, updatedAt: Date.now() };
|
|
991
|
+
try {
|
|
992
|
+
job.controlEventCursor = restoredControlEventCursor(asyncDir);
|
|
993
|
+
}
|
|
994
|
+
catch {
|
|
995
|
+
// An unsearchable run directory: refreshJob reads the cursor once the run is verified.
|
|
996
|
+
}
|
|
997
|
+
state.asyncJobs.set(runId, job);
|
|
998
|
+
runningJobIds.add(runId);
|
|
999
|
+
unverifiedRuns.add(runId);
|
|
1000
|
+
watchJob(job);
|
|
1001
|
+
}
|
|
926
1002
|
state.statusProjectionSessionId = state.currentSessionId;
|
|
927
|
-
if (runs.length === 0)
|
|
1003
|
+
if (runs.length === 0 && unreadable.length === 0)
|
|
928
1004
|
return;
|
|
929
1005
|
ensurePoller();
|
|
930
1006
|
rerenderLastWidget();
|
|
@@ -148,6 +148,8 @@ interface AsyncRunListOptions {
|
|
|
148
148
|
adoptCompletionOwnerId?: string;
|
|
149
149
|
/** Receives the warning for a skipped corrupt terminal status, so an open TUI can show it as a notice instead of console output. */
|
|
150
150
|
onCorruptStatus?: (warning: string) => void;
|
|
151
|
+
/** Receives an active run kept in the index whose status.json this process may not read. */
|
|
152
|
+
onUnreadableActiveRun?: (runId: string, asyncDir: string) => void;
|
|
151
153
|
}
|
|
152
154
|
type TargetedAsyncRunResolution = {
|
|
153
155
|
kind: "exact";
|
|
@@ -3,7 +3,7 @@ import * as path from "node:path";
|
|
|
3
3
|
import { formatDuration, formatModelThinking, formatTokens, shortenPath } from "../../shared/formatters.js";
|
|
4
4
|
import { previewDisplayText } from "../../shared/display-text.js";
|
|
5
5
|
import { formatActivityLabel, formatParallelOutcome } from "../../shared/status-format.js";
|
|
6
|
-
import { readStatus } from "../../shared/utils.js";
|
|
6
|
+
import { isStatusAccessError, readStatus } from "../../shared/utils.js";
|
|
7
7
|
import { attachRootChildrenToSteps, buildNestedRouteIndex, findNestedRouteForRootId, projectNestedEvents } from "../shared/nested-events.js";
|
|
8
8
|
import { formatNestedRunStatusLines } from "../shared/nested-render.js";
|
|
9
9
|
import { formatRunFanoutBudget, getRunFanoutBudgetSnapshot, readRunFanoutBudgetDescriptor } from "../shared/run-fanout-budget.js";
|
|
@@ -40,6 +40,7 @@ function isAsyncStatusIsolationError(asyncDir, error) {
|
|
|
40
40
|
// Status path -> last logged signature. A corrupt run is re-scanned on every
|
|
41
41
|
// status poll, so the line repeats only when the file or the outcome changes.
|
|
42
42
|
const reportedCorruptStatus = new Map();
|
|
43
|
+
/** Returns whether the active-run marker is still in place. */
|
|
43
44
|
function isolateCorruptActiveRun(asyncDir, runId, error, now) {
|
|
44
45
|
const statusPath = path.join(asyncDir, "status.json");
|
|
45
46
|
const processTerminal = readProcessTerminal(asyncDir, { runId });
|
|
@@ -53,9 +54,11 @@ function isolateCorruptActiveRun(asyncDir, runId, error, now) {
|
|
|
53
54
|
const markerCanBeReleased = processTerminal?.state === "observed"
|
|
54
55
|
|| (markerAge !== undefined && markerAge > DEFAULT_STALE_TERMINAL_ACTIVE_MARKER_MS);
|
|
55
56
|
let markerAction = "active marker retained because runner liveness is unknown";
|
|
57
|
+
let retained = true;
|
|
56
58
|
if (markerCanBeReleased) {
|
|
57
59
|
try {
|
|
58
60
|
releaseActiveRunIndex(asyncDir);
|
|
61
|
+
retained = false;
|
|
59
62
|
markerAction = processTerminal?.state === "observed"
|
|
60
63
|
? "active marker released after observed process-terminal proof"
|
|
61
64
|
: "stale active marker released";
|
|
@@ -75,9 +78,10 @@ function isolateCorruptActiveRun(asyncDir, runId, error, now) {
|
|
|
75
78
|
}
|
|
76
79
|
const signature = `${fileSignature}\n${line}`;
|
|
77
80
|
if (reportedCorruptStatus.get(statusPath) === signature)
|
|
78
|
-
return;
|
|
81
|
+
return retained;
|
|
79
82
|
reportedCorruptStatus.set(statusPath, signature);
|
|
80
83
|
console.error(line);
|
|
84
|
+
return retained;
|
|
81
85
|
}
|
|
82
86
|
function isNotFoundError(error) {
|
|
83
87
|
return typeof error === "object"
|
|
@@ -464,7 +468,8 @@ export function listAsyncRuns(asyncDirRoot, options = {}, observeStatus) {
|
|
|
464
468
|
observeStatus?.(null);
|
|
465
469
|
if (!activeEntries.has(entry) || !isAsyncStatusIsolationError(asyncDir, error))
|
|
466
470
|
throw error;
|
|
467
|
-
isolateCorruptActiveRun(asyncDir, entry, error, options.now)
|
|
471
|
+
if (isolateCorruptActiveRun(asyncDir, entry, error, options.now) && isStatusAccessError(error, asyncDir))
|
|
472
|
+
options.onUnreadableActiveRun?.(entry, asyncDir);
|
|
468
473
|
continue;
|
|
469
474
|
}
|
|
470
475
|
if (!status) {
|
|
@@ -251,7 +251,9 @@ export function resolveMachinePlacement(input) {
|
|
|
251
251
|
return { machine: resolveHerdrLocalPlacement({ cwd: input.cwd, stepCwd: input.stepCwd, env, herdrBin: input.herdrBin }) };
|
|
252
252
|
if (env.REX_SESSION?.trim())
|
|
253
253
|
return { machine: resolveRexLocalPlacement({ cwd: input.cwd, stepCwd: input.stepCwd, env }) };
|
|
254
|
-
|
|
254
|
+
// Herdr Core (`hc`, the Herdr app's terminal server) is a different product from the herdr multiplexer, with a different CLI and protocol.
|
|
255
|
+
const core = env.HC_TERMINAL_ID?.trim() ? " It runs in a Herdr Core terminal (HC_TERMINAL_ID), which machine 'local' does not support." : "";
|
|
256
|
+
throw new Error(`Machine 'local' opens the child in a new tab of the terminal this Pi runs in, but this Pi is running in neither Herdr (HERDR_ENV=1 with HERDR_PANE_ID) nor Rex (REX_SESSION).${core}`);
|
|
255
257
|
}
|
|
256
258
|
if (settings?.rex)
|
|
257
259
|
return { machine: { provider: "rex", id: requested, target: settings.rex.ssh, cwd: validateRemoteCwd(remoteMachineCwd(input.stepCwd, settings.cwd, requested), requested) } };
|
|
@@ -232,7 +232,7 @@ function rewritesChildPrompt(config) {
|
|
|
232
232
|
/**
|
|
233
233
|
* An extension can replace the tools a request declares (pi-fabric's code mode sends only its own
|
|
234
234
|
* `fabric_exec`), and Pi only reports a throw from a request hook. This hook runs after every other
|
|
235
|
-
* extension's, so a child whose
|
|
235
|
+
* extension's, so a child whose active allowlisted tools were left out records why and stops
|
|
236
236
|
* before the provider gets the request. A request that declares them all passes through unchanged.
|
|
237
237
|
*/
|
|
238
238
|
function registerDeclaredToolCheck(pi, config, required) {
|
|
@@ -240,12 +240,13 @@ function registerDeclaredToolCheck(pi, config, required) {
|
|
|
240
240
|
const declared = new Set(getCurrentTools(event.messages).map((tool) => tool.name));
|
|
241
241
|
if (required.every((name) => declared.has(name)))
|
|
242
242
|
return undefined;
|
|
243
|
-
const
|
|
244
|
-
//
|
|
245
|
-
|
|
243
|
+
const active = new Set(pi.getActiveTools());
|
|
244
|
+
// Only an active tool must be declared: an extension may leave a registered tool inactive on
|
|
245
|
+
// purpose (pi-web-access's `web_enable`), and one that never registered is agent_start's case.
|
|
246
|
+
const undeclared = required.filter((name) => active.has(name) && !declared.has(name));
|
|
246
247
|
if (undeclared.length === 0)
|
|
247
248
|
return undefined;
|
|
248
|
-
const
|
|
249
|
+
const registered = new Set(pi.getAllTools().map((tool) => tool.name));
|
|
249
250
|
// A fork declares its parent's tools on purpose, to reuse the parent's prompt cache.
|
|
250
251
|
const uncallable = config.forkCacheKey ? [] : [...declared].filter((name) => !active.has(name));
|
|
251
252
|
config.toolDiagnostic?.({
|
package/src/shared/utils.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export declare function getProjectConfigDir(projectRoot: string): string;
|
|
|
11
11
|
export declare function getAgentDir(): string;
|
|
12
12
|
export declare function pruneStatusCacheForAsyncRoot(asyncDirRoot: string, runIds: Iterable<string>): number;
|
|
13
13
|
export declare function resolveChildCwd(baseCwd: string, childCwd: string | undefined): string;
|
|
14
|
+
/** A `readStatus(asyncDir)` error caused by permissions on that run's own status file, which says nothing about whether its runner is alive. */
|
|
15
|
+
export declare function isStatusAccessError(error: unknown, asyncDir: string): boolean;
|
|
14
16
|
export declare function readStatus(asyncDir: string): AsyncStatus | null;
|
|
15
17
|
export declare function getLastActivity(outputFile: string | undefined): string;
|
|
16
18
|
export declare function findLatestSessionFile(sessionDir: string): string | null;
|
package/src/shared/utils.js
CHANGED
|
@@ -119,6 +119,15 @@ function isNotFoundError(error) {
|
|
|
119
119
|
&& "code" in error
|
|
120
120
|
&& error.code === "ENOENT";
|
|
121
121
|
}
|
|
122
|
+
/** A `readStatus(asyncDir)` error caused by permissions on that run's own status file, which says nothing about whether its runner is alive. */
|
|
123
|
+
export function isStatusAccessError(error, asyncDir) {
|
|
124
|
+
const code = error?.cause?.code;
|
|
125
|
+
if (code !== "EACCES" && code !== "EPERM")
|
|
126
|
+
return false;
|
|
127
|
+
const message = error instanceof Error ? error.message : "";
|
|
128
|
+
const quotedPath = `'${path.join(asyncDir, "status.json")}':`;
|
|
129
|
+
return message.startsWith(`Failed to inspect async status file ${quotedPath}`) || message.startsWith(`Failed to read async status file ${quotedPath}`);
|
|
130
|
+
}
|
|
122
131
|
export function readStatus(asyncDir) {
|
|
123
132
|
if (Buffer.byteLength(path.basename(asyncDir), "utf-8") > 255) {
|
|
124
133
|
return null;
|