@llblab/pi-actors 0.42.3 → 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/AGENTS.md +121 -175
- package/CHANGELOG.md +12 -0
- package/README.md +113 -276
- package/dist/fixtures/protocol/control-endpoint.json +6 -0
- package/dist/fixtures/protocol/control-record.json +9 -0
- package/dist/fixtures/protocol/recipe-summary.json +4 -12
- package/dist/fixtures/protocol/trace-event.json +9 -0
- package/dist/lib/async-runs.d.ts +14 -38
- package/dist/lib/async-runs.js +158 -108
- package/dist/lib/control.d.ts +12 -0
- package/dist/lib/control.js +84 -0
- package/dist/lib/execution-sessions.d.ts +17 -0
- package/dist/lib/execution-sessions.js +85 -0
- package/dist/lib/file-state.d.ts +1 -0
- package/dist/lib/file-state.js +17 -5
- package/dist/lib/inspector-actions.d.ts +2 -2
- package/dist/lib/inspector-actions.js +2 -2
- package/dist/lib/inspector-command.js +3 -3
- package/dist/lib/inspector-overlay.d.ts +52 -70
- package/dist/lib/inspector-overlay.js +532 -905
- package/dist/lib/inspector.d.ts +3 -71
- package/dist/lib/inspector.js +19 -665
- package/dist/lib/limits.d.ts +4 -2
- package/dist/lib/limits.js +4 -2
- package/dist/lib/observability.d.ts +16 -16
- package/dist/lib/observability.js +43 -82
- package/dist/lib/prompts.d.ts +1 -1
- package/dist/lib/prompts.js +2 -2
- package/dist/lib/recipe-control.d.ts +7 -0
- package/dist/lib/recipe-control.js +39 -0
- package/dist/lib/recipes-discovery.js +2 -0
- package/dist/lib/recipes-references.d.ts +1 -14
- package/dist/lib/recipes-references.js +6 -21
- package/dist/lib/review-projection.js +1 -5
- package/dist/lib/run-ui-runtime.js +2 -2
- package/dist/lib/runs-control-delivery.d.ts +21 -0
- package/dist/lib/runs-control-delivery.js +127 -0
- package/dist/lib/runs-controls.d.ts +35 -0
- package/dist/lib/runs-controls.js +144 -0
- package/dist/lib/runs-retention.d.ts +7 -0
- package/dist/lib/runs-retention.js +27 -3
- package/dist/lib/runs-start.js +4 -2
- package/dist/lib/runs-status.js +11 -6
- package/dist/lib/runs-trace.d.ts +24 -0
- package/dist/lib/runs-trace.js +98 -0
- package/dist/lib/runtime-notifier.d.ts +1 -1
- package/dist/lib/runtime-notifier.js +1 -1
- package/dist/lib/tools-inspect.d.ts +3 -3
- package/dist/lib/tools-inspect.js +203 -708
- package/dist/lib/tools-local.js +2 -10
- package/dist/lib/tools-message.d.ts +7 -7
- package/dist/lib/tools-message.js +95 -396
- package/dist/lib/tools-response.d.ts +1 -4
- package/dist/lib/tools-response.js +5 -39
- package/dist/lib/tools-spawn.js +16 -28
- package/dist/lib/tools.js +1 -2
- package/dist/lib/trace-projection.d.ts +22 -0
- package/dist/lib/trace-projection.js +165 -0
- package/dist/recipes/draft-review.json +0 -10
- package/dist/recipes/lens-swarm.json +0 -14
- package/dist/recipes/music-player.json +10 -19
- package/dist/recipes/pipeline-architect-coordinator.json +0 -11
- package/dist/recipes/pipeline-artifact-bundle.json +1 -22
- package/dist/recipes/pipeline-artifact-report.json +1 -18
- package/dist/recipes/pipeline-artifact-write.json +1 -18
- package/dist/recipes/pipeline-async-run-ops.json +0 -12
- package/dist/recipes/pipeline-checkpoint-continuation.json +0 -14
- package/dist/recipes/pipeline-development-tasking.json +0 -12
- package/dist/recipes/pipeline-docs-maintenance.json +0 -12
- package/dist/recipes/pipeline-media-library.json +0 -12
- package/dist/recipes/pipeline-quorum-review.json +0 -12
- package/dist/recipes/pipeline-release-readiness.json +0 -12
- package/dist/recipes/pipeline-release-summary.json +0 -12
- package/dist/recipes/pipeline-repo-health.json +0 -12
- package/dist/recipes/pipeline-research-synthesis.json +0 -11
- package/dist/recipes/pipeline-review-readiness.json +0 -12
- package/dist/recipes/resource-locker.json +27 -0
- package/dist/recipes/subagent-artifact.json +0 -9
- package/dist/recipes/subagent-checkpoint.json +0 -10
- package/dist/recipes/subagent-conflict-report.json +0 -11
- package/dist/recipes/subagent-contradiction-map.json +0 -11
- package/dist/recipes/subagent-critic.json +0 -11
- package/dist/recipes/subagent-evidence-map.json +0 -11
- package/dist/recipes/subagent-followup.json +0 -10
- package/dist/recipes/subagent-judge.json +0 -11
- package/dist/recipes/subagent-merge.json +0 -11
- package/dist/recipes/subagent-normalize.json +0 -11
- package/dist/recipes/subagent-plan.json +0 -11
- package/dist/recipes/subagent-preflight.json +0 -11
- package/dist/recipes/subagent-prompt.json +0 -10
- package/dist/recipes/subagent-quorum.json +0 -10
- package/dist/recipes/subagent-review-coordinator.json +0 -14
- package/dist/recipes/subagent-review.json +0 -11
- package/dist/recipes/subagent-task-card.json +0 -11
- package/dist/recipes/subagent-tools.json +0 -10
- package/dist/recipes/subagent-verify.json +0 -11
- package/dist/recipes/subagents-prompts.json +0 -10
- package/dist/recipes/tool-review.json +0 -10
- package/dist/scripts/async-runner.mjs +25 -25
- package/dist/scripts/conformance.mjs +4 -2
- package/dist/scripts/locker.mjs +200 -66
- package/dist/scripts/music-player.mjs +159 -150
- package/dist/scripts/recipe-utils.mjs +6 -96
- package/dist/scripts/release-gates.mjs +60 -0
- package/dist/scripts/validate-recipe.mjs +3 -53
- package/dist/skills/actors/SKILL.md +53 -266
- package/dist/skills/swarm/SKILL.md +11 -33
- package/docs/0.43-baseline.md +44 -0
- package/docs/README.md +3 -3
- package/docs/actor-inspector.md +26 -64
- package/docs/actors-deep-reference.md +92 -50
- package/docs/async-runs.md +81 -328
- package/docs/command-templates.md +2 -2
- package/docs/component-recipes.md +30 -133
- package/docs/recipe-library.md +57 -182
- package/docs/task-first-recipes.md +10 -12
- package/docs/template-recipes.md +76 -289
- package/docs/tool-registry.md +41 -161
- package/fixtures/protocol/control-endpoint.json +6 -0
- package/fixtures/protocol/control-record.json +9 -0
- package/fixtures/protocol/recipe-summary.json +4 -12
- package/fixtures/protocol/trace-event.json +9 -0
- package/lib/async-runs.ts +202 -201
- package/lib/control.ts +102 -0
- package/lib/execution-sessions.ts +111 -0
- package/lib/file-state.ts +17 -4
- package/lib/inspector-actions.ts +2 -2
- package/lib/inspector-command.ts +3 -3
- package/lib/inspector-overlay.ts +577 -1121
- package/lib/inspector.ts +46 -979
- package/lib/limits.ts +4 -2
- package/lib/observability.ts +60 -101
- package/lib/prompts.ts +2 -2
- package/lib/recipe-control.ts +45 -0
- package/lib/recipes-discovery.ts +2 -0
- package/lib/recipes-references.ts +9 -45
- package/lib/review-projection.ts +1 -5
- package/lib/run-ui-runtime.ts +2 -2
- package/lib/runs-control-delivery.ts +181 -0
- package/lib/runs-controls.ts +204 -0
- package/lib/runs-retention.ts +38 -3
- package/lib/runs-start.ts +4 -2
- package/lib/runs-status.ts +11 -6
- package/lib/runs-trace.ts +132 -0
- package/lib/runtime-notifier.ts +1 -1
- package/lib/tools-inspect.ts +240 -901
- package/lib/tools-local.ts +2 -12
- package/lib/tools-message.ts +112 -519
- package/lib/tools-response.ts +5 -52
- package/lib/tools-spawn.ts +16 -32
- package/lib/tools.ts +1 -2
- package/lib/trace-projection.ts +221 -0
- package/package.json +2 -1
- package/recipes/draft-review.json +0 -10
- package/recipes/lens-swarm.json +0 -14
- package/recipes/music-player.json +10 -19
- package/recipes/pipeline-architect-coordinator.json +0 -11
- package/recipes/pipeline-artifact-bundle.json +1 -22
- package/recipes/pipeline-artifact-report.json +1 -18
- package/recipes/pipeline-artifact-write.json +1 -18
- package/recipes/pipeline-async-run-ops.json +0 -12
- package/recipes/pipeline-checkpoint-continuation.json +0 -14
- package/recipes/pipeline-development-tasking.json +0 -12
- package/recipes/pipeline-docs-maintenance.json +0 -12
- package/recipes/pipeline-media-library.json +0 -12
- package/recipes/pipeline-quorum-review.json +0 -12
- package/recipes/pipeline-release-readiness.json +0 -12
- package/recipes/pipeline-release-summary.json +0 -12
- package/recipes/pipeline-repo-health.json +0 -12
- package/recipes/pipeline-research-synthesis.json +0 -11
- package/recipes/pipeline-review-readiness.json +0 -12
- package/recipes/resource-locker.json +27 -0
- package/recipes/subagent-artifact.json +0 -9
- package/recipes/subagent-checkpoint.json +0 -10
- package/recipes/subagent-conflict-report.json +0 -11
- package/recipes/subagent-contradiction-map.json +0 -11
- package/recipes/subagent-critic.json +0 -11
- package/recipes/subagent-evidence-map.json +0 -11
- package/recipes/subagent-followup.json +0 -10
- package/recipes/subagent-judge.json +0 -11
- package/recipes/subagent-merge.json +0 -11
- package/recipes/subagent-normalize.json +0 -11
- package/recipes/subagent-plan.json +0 -11
- package/recipes/subagent-preflight.json +0 -11
- package/recipes/subagent-prompt.json +0 -10
- package/recipes/subagent-quorum.json +0 -10
- package/recipes/subagent-review-coordinator.json +0 -14
- package/recipes/subagent-review.json +0 -11
- package/recipes/subagent-task-card.json +0 -11
- package/recipes/subagent-tools.json +0 -10
- package/recipes/subagent-verify.json +0 -11
- package/recipes/subagents-prompts.json +0 -10
- package/recipes/tool-review.json +0 -10
- package/scripts/async-runner.mjs +25 -25
- package/scripts/conformance.mjs +4 -2
- package/scripts/locker.mjs +200 -66
- package/scripts/music-player.mjs +159 -150
- package/scripts/recipe-utils.mjs +6 -96
- package/scripts/release-gates.mjs +60 -0
- package/scripts/validate-recipe.mjs +3 -53
- package/skills/actors/SKILL.md +53 -266
- package/skills/swarm/SKILL.md +11 -33
- package/dist/fixtures/protocol/actor-message-branch.json +0 -13
- package/dist/fixtures/protocol/mailbox-contract.json +0 -15
- package/dist/fixtures/protocol/room-message.json +0 -11
- package/dist/fixtures/protocol/room-roster.json +0 -11
- package/dist/fixtures/protocol/run-inbox-message.json +0 -9
- package/dist/fixtures/protocol/run-outbox-event.json +0 -9
- package/dist/lib/mailbox-loop.d.ts +0 -41
- package/dist/lib/mailbox-loop.js +0 -60
- package/dist/lib/messages.d.ts +0 -25
- package/dist/lib/messages.js +0 -122
- package/dist/lib/rooms.d.ts +0 -104
- package/dist/lib/rooms.js +0 -647
- package/dist/lib/runs-mailbox.d.ts +0 -25
- package/dist/lib/runs-mailbox.js +0 -146
- package/dist/lib/runs-messages.d.ts +0 -15
- package/dist/lib/runs-messages.js +0 -179
- package/dist/lib/runs-outbox.d.ts +0 -41
- package/dist/lib/runs-outbox.js +0 -87
- package/dist/lib/tools-mailbox.d.ts +0 -8
- package/dist/lib/tools-mailbox.js +0 -48
- package/dist/recipes/actor-worker.json +0 -39
- package/dist/recipes/coordinator-locker.json +0 -45
- package/dist/recipes/locker.json +0 -45
- package/dist/recipes/pipeline-room-swarm.json +0 -50
- package/dist/recipes/subagent-message.json +0 -32
- package/dist/recipes/utility-actor-message.json +0 -23
- package/dist/scripts/actor-worker.mjs +0 -214
- package/dist/scripts/coordinator.mjs +0 -799
- package/docs/actor-messages.md +0 -225
- package/fixtures/protocol/actor-message-branch.json +0 -13
- package/fixtures/protocol/mailbox-contract.json +0 -15
- package/fixtures/protocol/room-message.json +0 -11
- package/fixtures/protocol/room-roster.json +0 -11
- package/fixtures/protocol/run-inbox-message.json +0 -9
- package/fixtures/protocol/run-outbox-event.json +0 -9
- package/lib/mailbox-loop.ts +0 -144
- package/lib/messages.ts +0 -151
- package/lib/rooms.ts +0 -939
- package/lib/runs-mailbox.ts +0 -208
- package/lib/runs-messages.ts +0 -252
- package/lib/runs-outbox.ts +0 -144
- package/lib/tools-mailbox.ts +0 -56
- package/recipes/actor-worker.json +0 -39
- package/recipes/coordinator-locker.json +0 -45
- package/recipes/locker.json +0 -45
- package/recipes/pipeline-room-swarm.json +0 -50
- package/recipes/subagent-message.json +0 -32
- package/recipes/utility-actor-message.json +0 -23
- package/scripts/actor-worker.mjs +0 -214
- package/scripts/coordinator.mjs +0 -799
package/lib/tools-inspect.ts
CHANGED
|
@@ -1,489 +1,267 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Public inspect tool behavior
|
|
3
|
-
* Zones:
|
|
4
|
-
* Owns
|
|
2
|
+
* Public inspect tool behavior.
|
|
3
|
+
* Zones: Run Recipe/Trace/Control views and runtime/recipe/tool diagnostics
|
|
4
|
+
* Owns exact inspect target/view dispatch; source projection stays in domain modules.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
9
|
-
import { dirname, join } from "node:path";
|
|
10
|
-
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { join } from "node:path";
|
|
11
8
|
|
|
12
9
|
import * as AsyncRuns from "./async-runs.ts";
|
|
10
|
+
import * as Inspector from "./inspector.ts";
|
|
13
11
|
import * as Limits from "./limits.ts";
|
|
14
|
-
import * as Messages from "./messages.ts";
|
|
15
12
|
import * as Paths from "./paths.ts";
|
|
16
13
|
import * as RecipesDiscovery from "./recipes-discovery.ts";
|
|
17
14
|
import * as ReviewDiagnostics from "./review-diagnostics.ts";
|
|
18
|
-
import * as
|
|
15
|
+
import * as RunsControls from "./runs-controls.ts";
|
|
16
|
+
import * as RunControlDelivery from "./runs-control-delivery.ts";
|
|
17
|
+
import * as RunsTrace from "./runs-trace.ts";
|
|
19
18
|
import * as Schema from "./schema.ts";
|
|
20
19
|
import * as ToolsAccess from "./tools-access.ts";
|
|
21
|
-
import * as ToolsMailbox from "./tools-mailbox.ts";
|
|
22
20
|
import * as ToolsResponse from "./tools-response.ts";
|
|
21
|
+
import * as TraceProjection from "./trace-projection.ts";
|
|
23
22
|
|
|
24
23
|
const asRecord = ToolsResponse.asRecord;
|
|
25
24
|
const maybeJsonText = ToolsResponse.maybeJsonText;
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
`automatic_reviews draft=${String(draft.phase ?? "idle")} tool=${String(tool.phase ?? "idle")}`,
|
|
34
|
-
`lineages=${String(diagnostics.lineage_count ?? 0)} revision_snapshots=${String(diagnostics.revision_snapshots ?? 0)}`,
|
|
35
|
-
].join("\n");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function compactRunMessages(messages: AsyncRuns.RunOutboxEvent[]): string {
|
|
39
|
-
if (messages.length === 0) return "\n(no actor messages)";
|
|
40
|
-
return `\n${messages
|
|
41
|
-
.map((message) =>
|
|
42
|
-
[
|
|
43
|
-
`run=${message.run}`,
|
|
44
|
-
`type=${message.event}`,
|
|
45
|
-
`level=${message.level}`,
|
|
46
|
-
`summary=${message.summary.replaceAll(/\s+/g, "_")}`,
|
|
47
|
-
].join(" "),
|
|
48
|
-
)
|
|
49
|
-
.join("\n")}`;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function compactRoomPreviews(previews: Rooms.RoomMessagePreview[]): string {
|
|
53
|
-
if (previews.length === 0) return "\n(no room message previews)";
|
|
54
|
-
return `\n${previews
|
|
55
|
-
.map((preview) =>
|
|
56
|
-
[
|
|
57
|
-
`ts=${preview.timestamp}`,
|
|
58
|
-
preview.from ? `from=${preview.from}` : "",
|
|
59
|
-
`to=${preview.to}`,
|
|
60
|
-
`type=${preview.type}`,
|
|
61
|
-
preview.summary
|
|
62
|
-
? `summary=${ToolsResponse.compactPreview(preview.summary)}`
|
|
63
|
-
: "",
|
|
64
|
-
preview.body_preview
|
|
65
|
-
? `body=${ToolsResponse.compactPreview(preview.body_preview)}`
|
|
66
|
-
: "",
|
|
67
|
-
]
|
|
68
|
-
.filter(Boolean)
|
|
69
|
-
.join(" "),
|
|
70
|
-
)
|
|
71
|
-
.join("\n")}`;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function compactRoomMessages(messages: Rooms.RoomTimelineEntry[]): string {
|
|
75
|
-
if (messages.length === 0) return "\n(no room messages)";
|
|
76
|
-
return `\n${messages
|
|
77
|
-
.map((message) =>
|
|
78
|
-
[
|
|
79
|
-
`ts=${message.received_at}`,
|
|
80
|
-
`from=${String(message.from ?? "<unknown>")}`,
|
|
81
|
-
`to=${message.to}`,
|
|
82
|
-
`type=${message.type}`,
|
|
83
|
-
`summary=${String(message.summary ?? "").replaceAll(/\s+/g, "_")}`,
|
|
84
|
-
ToolsResponse.compactPreview(message.body)
|
|
85
|
-
? `body=${ToolsResponse.compactPreview(message.body)}`
|
|
86
|
-
: "",
|
|
87
|
-
]
|
|
88
|
-
.filter(Boolean)
|
|
89
|
-
.join(" "),
|
|
90
|
-
)
|
|
91
|
-
.join("\n")}`;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function compactRoomContacts(contacts: Rooms.RoomContact[]): string {
|
|
95
|
-
if (contacts.length === 0) return "\n(no room contacts)";
|
|
96
|
-
return `\n${contacts
|
|
97
|
-
.map((contact) =>
|
|
98
|
-
[
|
|
99
|
-
`address=${contact.address}`,
|
|
100
|
-
contact.role !== undefined ? `role=${String(contact.role)}` : "",
|
|
101
|
-
contact.parent !== undefined ? `parent=${String(contact.parent)}` : "",
|
|
102
|
-
contact.caps !== undefined
|
|
103
|
-
? `caps=${Array.isArray(contact.caps) ? contact.caps.join(",") : String(contact.caps)}`
|
|
104
|
-
: "",
|
|
105
|
-
contact.claim !== undefined
|
|
106
|
-
? `claim=${String(contact.claim).replaceAll(/\s+/g, "_")}`
|
|
107
|
-
: "",
|
|
108
|
-
contact.status !== undefined ? `status=${String(contact.status)}` : "",
|
|
109
|
-
]
|
|
110
|
-
.filter(Boolean)
|
|
111
|
-
.join(" "),
|
|
112
|
-
)
|
|
113
|
-
.join("\n")}`;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function compactRoomRoster(roster: Record<string, Rooms.RoomMember>): string {
|
|
117
|
-
const members = Object.values(roster);
|
|
118
|
-
if (members.length === 0) return "\n(no room members)";
|
|
119
|
-
return `\n${members
|
|
120
|
-
.map((member) =>
|
|
121
|
-
[
|
|
122
|
-
`address=${member.address}`,
|
|
123
|
-
`role=${String(member.role ?? "")}`,
|
|
124
|
-
member.parent !== undefined ? `parent=${String(member.parent)}` : "",
|
|
125
|
-
member.caps !== undefined
|
|
126
|
-
? `caps=${Array.isArray(member.caps) ? member.caps.join(",") : String(member.caps)}`
|
|
127
|
-
: "",
|
|
128
|
-
member.claim !== undefined
|
|
129
|
-
? `claim=${String(member.claim).replaceAll(/\s+/g, "_")}`
|
|
130
|
-
: "",
|
|
131
|
-
`status=${String(member.status ?? "")}`,
|
|
132
|
-
`last_seen=${member.last_seen}`,
|
|
133
|
-
].join(" "),
|
|
134
|
-
)
|
|
135
|
-
.join("\n")}`;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function compactRoomStatus(status: Rooms.RoomStatus): string {
|
|
139
|
-
return `\nroom=${status.room} messages=${status.message_count} roster=${status.roster_count}${status.diagnostics_count ? ` diagnostics=${status.diagnostics_count}` : ""}${status.last_message_at ? ` last_message_at=${status.last_message_at}` : ""}${status.last_message_from ? ` last_from=${status.last_message_from}` : ""}${status.last_message_type ? ` last_type=${status.last_message_type}` : ""}${status.last_message_summary ? ` last_summary=${ToolsResponse.compactPreview(status.last_message_summary)}` : ""}`;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function compactCommunicationSnapshot(
|
|
143
|
-
snapshot: Rooms.ActorCommunicationSnapshot | undefined,
|
|
144
|
-
): string {
|
|
145
|
-
if (!snapshot) return "\n(no communication snapshot)";
|
|
146
|
-
return `\nself=${snapshot.self} root=${snapshot.root} rooms=${snapshot.rooms.length} updated_at=${snapshot.updated_at}`;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function compactArtifactPath(value: unknown): string {
|
|
150
|
-
if (typeof value === "string") return value;
|
|
151
|
-
const record = asRecord(value);
|
|
152
|
-
return String(record.path ?? "<missing>");
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function readBoundedReviewEvidence(
|
|
156
|
-
status: Record<string, unknown>,
|
|
157
|
-
limit: number,
|
|
158
|
-
): Record<string, unknown> | undefined {
|
|
159
|
-
const evidenceFile = status.evidenceFile;
|
|
160
|
-
if (typeof evidenceFile !== "string" || !existsSync(evidenceFile))
|
|
161
|
-
return undefined;
|
|
162
|
-
try {
|
|
163
|
-
const manifest = asRecord(JSON.parse(readFileSync(evidenceFile, "utf8")));
|
|
164
|
-
const commands = Array.isArray(manifest.commands) ? manifest.commands : [];
|
|
165
|
-
const bounded = commands.slice(-Math.max(1, limit));
|
|
166
|
-
return {
|
|
167
|
-
...manifest,
|
|
168
|
-
commands: bounded,
|
|
169
|
-
commands_total: commands.length,
|
|
170
|
-
...(bounded.length < commands.length ? { commands_truncated: true } : {}),
|
|
171
|
-
};
|
|
172
|
-
} catch {
|
|
173
|
-
return {
|
|
174
|
-
status: "invalid",
|
|
175
|
-
error: "review evidence manifest is unreadable",
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function compactActorFiles(status: Record<string, unknown>): string {
|
|
181
|
-
const run = String(status.run ?? "<unknown>");
|
|
182
|
-
const artifacts = asRecord(status.artifacts);
|
|
183
|
-
const files = [
|
|
184
|
-
status.stdoutLog,
|
|
185
|
-
status.stderrLog,
|
|
186
|
-
status.eventsFile,
|
|
187
|
-
status.outboxFile,
|
|
188
|
-
status.evidenceFile,
|
|
189
|
-
status.state_dir
|
|
190
|
-
? `${String(status.state_dir)}/communication.json`
|
|
191
|
-
: undefined,
|
|
192
|
-
status.state_dir ? `${String(status.state_dir)}/result.json` : undefined,
|
|
193
|
-
].filter((file): file is string => typeof file === "string");
|
|
194
|
-
const artifactText = Object.keys(artifacts).length
|
|
195
|
-
? ` artifacts=${Object.entries(artifacts)
|
|
196
|
-
.map(([key, value]) => `${key}:${compactArtifactPath(value)}`)
|
|
197
|
-
.join(",")}`
|
|
198
|
-
: "";
|
|
199
|
-
const nextActions = ToolsResponse.artifactNextActions(run, artifacts);
|
|
200
|
-
const nextText = nextActions.length
|
|
201
|
-
? ` next=${nextActions.map((action) => action.replaceAll(/\s+/g, "_")).join("|")}`
|
|
202
|
-
: "";
|
|
203
|
-
return `\nrun=${run}${artifactText}${files.length ? ` files=${files.join(",")}` : ""}${nextText}`;
|
|
26
|
+
export interface InspectToolDeps<TContext = unknown> {
|
|
27
|
+
getRunStatus?: (runOrDir: string) => Record<string, any>;
|
|
28
|
+
getTool?: (name: string) => any | undefined;
|
|
29
|
+
listRuns?: () => Array<Record<string, any>>;
|
|
30
|
+
packagedRecipeRoot?: string;
|
|
31
|
+
recipeRoot?: string;
|
|
204
32
|
}
|
|
205
33
|
|
|
206
|
-
function
|
|
207
|
-
currentSession: string,
|
|
208
|
-
allRuns: Array<Record<string, unknown>>,
|
|
209
|
-
): Record<string, unknown> {
|
|
210
|
-
const otherRuns = allRuns.filter(
|
|
211
|
-
(run) => run.ownerId && run.ownerId !== currentSession,
|
|
212
|
-
);
|
|
34
|
+
function runtimeStatus(): Record<string, unknown> {
|
|
213
35
|
return {
|
|
214
|
-
|
|
215
|
-
|
|
36
|
+
automatic_review: process.env.PI_ACTORS_AUTOMATIC_REVIEW !== "off",
|
|
37
|
+
run_root: Paths.getRunStateRoot(),
|
|
38
|
+
version: process.env.npm_package_version ?? "unknown",
|
|
216
39
|
};
|
|
217
40
|
}
|
|
218
41
|
|
|
219
|
-
function
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
): string {
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
? `other_runs=${String(summary.other_runs)}`
|
|
230
|
-
: "",
|
|
231
|
-
]
|
|
232
|
-
.filter(Boolean)
|
|
233
|
-
.join(" ");
|
|
234
|
-
if (runs.length === 0)
|
|
235
|
-
return `\nsession=${session} runs=0${suffix ? ` ${suffix}` : ""}`;
|
|
236
|
-
return `\nsession=${session} runs=${runs.length}${suffix ? ` ${suffix}` : ""}\n${runs
|
|
42
|
+
function runtimeRuns(
|
|
43
|
+
ctx: unknown,
|
|
44
|
+
deps: InspectToolDeps,
|
|
45
|
+
status: string | undefined,
|
|
46
|
+
): Record<string, unknown> {
|
|
47
|
+
const session = ToolsAccess.getContextSessionId(ctx);
|
|
48
|
+
const listed = deps.listRuns
|
|
49
|
+
? deps.listRuns()
|
|
50
|
+
: AsyncRuns.listRuns(undefined, status);
|
|
51
|
+
const runs = listed
|
|
237
52
|
.map((run) => {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
return tokens.join(" ");
|
|
53
|
+
try {
|
|
54
|
+
return deps.getRunStatus
|
|
55
|
+
? deps.getRunStatus(String(run.state_dir ?? run.run))
|
|
56
|
+
: AsyncRuns.getRunStatus(String(run.state_dir ?? run.run));
|
|
57
|
+
} catch {
|
|
58
|
+
return run;
|
|
59
|
+
}
|
|
246
60
|
})
|
|
247
|
-
.
|
|
61
|
+
.filter((run) => !session || !run.ownerId || run.ownerId === session);
|
|
62
|
+
return { ...(session ? { owner_session: session } : {}), runs };
|
|
248
63
|
}
|
|
249
64
|
|
|
250
|
-
function
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
65
|
+
function runtimeTriage(
|
|
66
|
+
ctx: unknown,
|
|
67
|
+
deps: InspectToolDeps,
|
|
68
|
+
): Record<string, unknown> {
|
|
69
|
+
const inventory = runtimeRuns(ctx, deps, undefined);
|
|
70
|
+
const runs = inventory.runs as Array<Record<string, unknown>>;
|
|
71
|
+
const failed = runs.filter((run) => run.status === "failed");
|
|
72
|
+
const staleControls = runs.flatMap((run) => {
|
|
73
|
+
const stateDir = typeof run.state_dir === "string" ? run.state_dir : undefined;
|
|
74
|
+
if (!stateDir) return [];
|
|
75
|
+
return RunsControls.readRunControlsFromStateDir(stateDir)
|
|
76
|
+
.filter((control) => control.status === "queued" || control.status === "claimed")
|
|
77
|
+
.map((control) => ({ run: run.run, control }));
|
|
78
|
+
});
|
|
79
|
+
const attentionEvents = runs.flatMap((run) => {
|
|
80
|
+
const stateDir = typeof run.state_dir === "string" ? run.state_dir : undefined;
|
|
81
|
+
if (!stateDir) return [];
|
|
82
|
+
return RunsTrace.readRunTraceEvents(stateDir)
|
|
83
|
+
.filter((event) => event.attention === "notify" || event.attention === "followup")
|
|
84
|
+
.map((event) => ({
|
|
85
|
+
run: run.run,
|
|
86
|
+
id: event.id,
|
|
87
|
+
kind: event.kind,
|
|
88
|
+
attention: event.attention,
|
|
89
|
+
summary: event.summary,
|
|
90
|
+
ts: event.ts,
|
|
91
|
+
}));
|
|
92
|
+
});
|
|
274
93
|
return {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
94
|
+
...inventory,
|
|
95
|
+
failed_runs: failed,
|
|
96
|
+
stale_controls: staleControls.slice(0, 40),
|
|
97
|
+
attention_events: attentionEvents.slice(-40).reverse(),
|
|
98
|
+
next_actions: [
|
|
99
|
+
...(failed.length ? ["inspect target=runtime view=runs status=failed"] : []),
|
|
100
|
+
...(staleControls.length
|
|
101
|
+
? staleControls.slice(0, 3).map((entry) =>
|
|
102
|
+
`inspect target=run:${String(entry.run)} view=control`,
|
|
103
|
+
)
|
|
104
|
+
: []),
|
|
105
|
+
...(attentionEvents.length
|
|
106
|
+
? attentionEvents.slice(-3).map((entry) =>
|
|
107
|
+
`inspect target=run:${String(entry.run)} view=trace source=runtime`,
|
|
108
|
+
)
|
|
109
|
+
: []),
|
|
110
|
+
],
|
|
284
111
|
};
|
|
285
112
|
}
|
|
286
113
|
|
|
287
|
-
function
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
return
|
|
114
|
+
function compactRuntime(view: string, details: Record<string, unknown>): string {
|
|
115
|
+
if (view === "runs") {
|
|
116
|
+
return `\nruntime runs=${(details.runs as unknown[] | undefined)?.length ?? 0}`;
|
|
117
|
+
}
|
|
118
|
+
if (view === "triage") {
|
|
119
|
+
return `\nruntime failed=${(details.failed_runs as unknown[] | undefined)?.length ?? 0} stale_controls=${(details.stale_controls as unknown[] | undefined)?.length ?? 0} attention=${(details.attention_events as unknown[] | undefined)?.length ?? 0}`;
|
|
120
|
+
}
|
|
121
|
+
return `\nruntime version=${String(details.version ?? "unknown")} automatic_review=${String(details.automatic_review)}`;
|
|
295
122
|
}
|
|
296
123
|
|
|
297
|
-
function
|
|
298
|
-
|
|
124
|
+
function inspectRuntime(
|
|
125
|
+
view: string,
|
|
126
|
+
input: Record<string, unknown>,
|
|
127
|
+
ctx: unknown,
|
|
128
|
+
deps: InspectToolDeps,
|
|
299
129
|
): Record<string, unknown> {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
try {
|
|
308
|
-
for (const message of AsyncRuns.readRunInboxMessages(stateDir, 200)) {
|
|
309
|
-
if (!isStaleClaim(message, now)) continue;
|
|
310
|
-
staleClaims.push({
|
|
311
|
-
run: runId,
|
|
312
|
-
id: message.id,
|
|
313
|
-
claimed_at: message.claimed_at,
|
|
314
|
-
claimed_by: message.claimed_by,
|
|
315
|
-
type: message.type,
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
} catch {}
|
|
319
|
-
try {
|
|
320
|
-
for (const event of AsyncRuns.readRunEvents(stateDir, 80)) {
|
|
321
|
-
if (event.metadata?.requires_response !== true) continue;
|
|
322
|
-
attentionMessages.push({
|
|
323
|
-
run: runId,
|
|
324
|
-
id: event.id,
|
|
325
|
-
summary: event.summary,
|
|
326
|
-
type: event.type ?? event.event,
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
} catch {}
|
|
130
|
+
if (view === "status") return runtimeStatus();
|
|
131
|
+
if (view === "runs") {
|
|
132
|
+
return runtimeRuns(
|
|
133
|
+
ctx,
|
|
134
|
+
deps,
|
|
135
|
+
typeof input.status === "string" ? input.status : undefined,
|
|
136
|
+
);
|
|
330
137
|
}
|
|
331
|
-
|
|
138
|
+
if (view === "triage") return runtimeTriage(ctx, deps);
|
|
139
|
+
throw new Error("inspect runtime supports view=status, view=runs, or view=triage.");
|
|
332
140
|
}
|
|
333
141
|
|
|
334
|
-
function
|
|
335
|
-
|
|
336
|
-
const labels = Array.isArray(recipe.risk_labels)
|
|
337
|
-
? recipe.risk_labels.map((label) => String(label))
|
|
338
|
-
: [];
|
|
339
|
-
return labels.some((label) => label !== "risk.long_running");
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
function getPiActorsTriage(
|
|
343
|
-
ctx: unknown,
|
|
142
|
+
function inspectRecipes(
|
|
143
|
+
view: string,
|
|
344
144
|
deps: InspectToolDeps,
|
|
345
145
|
): Record<string, unknown> {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
357
|
-
const visibleRuns = currentSession
|
|
358
|
-
? allRuns.filter(
|
|
359
|
-
(run) => !run.ownerId || run.ownerId === currentSession,
|
|
360
|
-
)
|
|
361
|
-
: allRuns;
|
|
362
|
-
const activeRuns = visibleRuns.filter((run) => run.status === "running");
|
|
363
|
-
const failedRuns = visibleRuns.filter((run) => run.status === "failed");
|
|
364
|
-
const otherRuns = currentSession
|
|
365
|
-
? allRuns.filter((run) => run.ownerId && run.ownerId !== currentSession)
|
|
366
|
-
: [];
|
|
146
|
+
if (
|
|
147
|
+
view !== "status" &&
|
|
148
|
+
view !== "summary" &&
|
|
149
|
+
view !== "doctor" &&
|
|
150
|
+
view !== "imports" &&
|
|
151
|
+
view !== "reviews"
|
|
152
|
+
) {
|
|
153
|
+
throw new Error(
|
|
154
|
+
"inspect recipes supports view=status, view=summary, view=doctor, view=imports, or view=reviews.",
|
|
155
|
+
);
|
|
156
|
+
}
|
|
367
157
|
const recipeRoot = deps.recipeRoot ?? Paths.getRecipeRoot();
|
|
158
|
+
if (view === "reviews") {
|
|
159
|
+
return ReviewDiagnostics.readAutomaticReviewDiagnostics({ recipeRoot });
|
|
160
|
+
}
|
|
368
161
|
const discovered = RecipesDiscovery.discoverRecipeSources([
|
|
369
162
|
{ root: recipeRoot, defaultTool: true, mutableUsage: true },
|
|
370
163
|
{ root: deps.packagedRecipeRoot ?? Paths.getPackagedRecipeRoot() },
|
|
371
164
|
]);
|
|
372
|
-
const
|
|
165
|
+
const summary = {
|
|
373
166
|
...RecipesDiscovery.summarizeDiscovery(discovered),
|
|
374
167
|
drafts: RecipesDiscovery.listDraftRecipes(join(recipeRoot, "drafts")),
|
|
375
168
|
};
|
|
376
|
-
const activeRecipes = Array.isArray(recipeSummary.active)
|
|
377
|
-
? (recipeSummary.active as Array<Record<string, unknown>>)
|
|
378
|
-
: [];
|
|
379
|
-
const highRiskRecipes = activeRecipes.filter(isTriageHighRiskRecipe);
|
|
380
|
-
const signals = getRunTriageSignals(visibleRuns);
|
|
381
|
-
const attentionMessages = signals.attention_messages as Array<
|
|
382
|
-
Record<string, unknown>
|
|
383
|
-
>;
|
|
384
|
-
const staleClaims = signals.stale_claims as Array<Record<string, unknown>>;
|
|
385
|
-
const invalidRecipes = Array.isArray(recipeSummary.invalid)
|
|
386
|
-
? (recipeSummary.invalid as Array<Record<string, unknown>>)
|
|
387
|
-
: [];
|
|
388
|
-
const remediations = Array.isArray(recipeSummary.remediations)
|
|
389
|
-
? (recipeSummary.remediations as Array<Record<string, unknown>>)
|
|
390
|
-
: [];
|
|
391
|
-
const drafts = Array.isArray(recipeSummary.drafts)
|
|
392
|
-
? (recipeSummary.drafts as Array<Record<string, unknown>>)
|
|
393
|
-
: [];
|
|
394
|
-
const nextActions = [
|
|
395
|
-
invalidRecipes.length || remediations.length
|
|
396
|
-
? "inspect target=recipes view=doctor"
|
|
397
|
-
: "",
|
|
398
|
-
drafts.length ? "inspect target=recipes view=summary verbose=true" : "",
|
|
399
|
-
failedRuns[0]?.run
|
|
400
|
-
? `inspect target=run:${String(failedRuns[0].run)} view=tail lines=80`
|
|
401
|
-
: "",
|
|
402
|
-
attentionMessages[0]?.run
|
|
403
|
-
? `inspect target=run:${String(attentionMessages[0].run)} view=messages`
|
|
404
|
-
: "",
|
|
405
|
-
activeRuns.length
|
|
406
|
-
? "inspect target=session:all view=runs status=active"
|
|
407
|
-
: "",
|
|
408
|
-
].filter(Boolean);
|
|
409
169
|
return {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
active_runs: activeRuns.map((run) => ({
|
|
413
|
-
run: run.run,
|
|
414
|
-
ownerId: run.ownerId,
|
|
415
|
-
recipe: run.recipe,
|
|
416
|
-
status: run.status,
|
|
417
|
-
})),
|
|
418
|
-
other_session_runs: otherRuns.length,
|
|
419
|
-
invalid_recipes: invalidRecipes,
|
|
420
|
-
blocking_recipes: remediations.filter((item) =>
|
|
421
|
-
String(item.kind ?? "").startsWith("blocking_"),
|
|
422
|
-
),
|
|
423
|
-
high_risk_recipes: highRiskRecipes.map((recipe) => ({
|
|
424
|
-
id: recipe.id,
|
|
425
|
-
path: recipe.path,
|
|
426
|
-
risk_labels: recipe.risk_labels,
|
|
427
|
-
})),
|
|
428
|
-
draft_recipes: drafts,
|
|
429
|
-
stale_claims: staleClaims,
|
|
430
|
-
recent_failed_runs: failedRuns.slice(0, 5).map((run) => ({
|
|
431
|
-
run: run.run,
|
|
432
|
-
recipe: run.recipe,
|
|
433
|
-
status: run.status,
|
|
434
|
-
})),
|
|
435
|
-
attention_messages: attentionMessages.slice(-10),
|
|
436
|
-
next_actions: [...new Set(nextActions)].slice(0, 5),
|
|
170
|
+
...summary,
|
|
171
|
+
next_actions: ToolsResponse.recipeRegistryNextActions(summary, view),
|
|
437
172
|
};
|
|
438
173
|
}
|
|
439
174
|
|
|
440
|
-
function
|
|
441
|
-
|
|
442
|
-
const
|
|
443
|
-
|
|
444
|
-
: 0;
|
|
445
|
-
const invalidRecipes = Array.isArray(summary.invalid_recipes)
|
|
446
|
-
? summary.invalid_recipes.length
|
|
447
|
-
: 0;
|
|
448
|
-
const blockingRecipes = Array.isArray(summary.blocking_recipes)
|
|
449
|
-
? summary.blocking_recipes.length
|
|
450
|
-
: 0;
|
|
451
|
-
const highRiskRecipes = Array.isArray(summary.high_risk_recipes)
|
|
452
|
-
? summary.high_risk_recipes.length
|
|
453
|
-
: 0;
|
|
454
|
-
const drafts = Array.isArray(summary.draft_recipes)
|
|
455
|
-
? summary.draft_recipes.length
|
|
456
|
-
: 0;
|
|
457
|
-
const staleClaims = Array.isArray(summary.stale_claims)
|
|
458
|
-
? summary.stale_claims.length
|
|
459
|
-
: 0;
|
|
460
|
-
const failedRuns = Array.isArray(summary.recent_failed_runs)
|
|
461
|
-
? summary.recent_failed_runs.length
|
|
462
|
-
: 0;
|
|
463
|
-
const attention = Array.isArray(summary.attention_messages)
|
|
464
|
-
? summary.attention_messages.length
|
|
465
|
-
: 0;
|
|
466
|
-
const nextActions = Array.isArray(summary.next_actions)
|
|
467
|
-
? (summary.next_actions as string[])
|
|
468
|
-
: [];
|
|
469
|
-
return `\ntriage version=${String(runtime.version ?? "unknown")} mode=${String(runtime.mode ?? "unknown")} active_runs=${activeRuns} other_runs=${String(summary.other_session_runs ?? 0)} invalid_recipes=${invalidRecipes} blocking_recipes=${blockingRecipes} high_risk_recipes=${highRiskRecipes} drafts=${drafts} stale_claims=${staleClaims} failed_runs=${failedRuns} attention=${attention}${ToolsResponse.compactNextActions(nextActions)}`;
|
|
175
|
+
function parseRunTarget(target: string): string | undefined {
|
|
176
|
+
if (!target.startsWith("run:")) return undefined;
|
|
177
|
+
const run = target.slice(4);
|
|
178
|
+
return run && /^[A-Za-z0-9_.-]+$/.test(run) ? run : undefined;
|
|
470
179
|
}
|
|
471
180
|
|
|
472
|
-
function
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
181
|
+
function inspectRun(
|
|
182
|
+
run: string,
|
|
183
|
+
view: string,
|
|
184
|
+
input: Record<string, unknown>,
|
|
185
|
+
ctx: unknown,
|
|
186
|
+
deps: InspectToolDeps,
|
|
187
|
+
): Record<string, unknown> {
|
|
188
|
+
if (view !== "recipe" && view !== "trace" && view !== "control") {
|
|
189
|
+
throw new Error("inspect run:<id> supports view=recipe, view=trace, or view=control.");
|
|
190
|
+
}
|
|
191
|
+
const status = deps.getRunStatus
|
|
192
|
+
? deps.getRunStatus(run)
|
|
193
|
+
: ToolsAccess.assertRunAccessibleToContext(run, ctx);
|
|
194
|
+
const stateDir = String(status.state_dir);
|
|
195
|
+
if (view === "recipe") {
|
|
196
|
+
return Inspector.readActorInspectorRecipe(stateDir) as unknown as Record<string, unknown>;
|
|
197
|
+
}
|
|
198
|
+
if (view === "trace") {
|
|
199
|
+
const source = typeof input.source === "string" ? input.source : "all";
|
|
200
|
+
if (
|
|
201
|
+
source !== "all" &&
|
|
202
|
+
source !== "lifecycle" &&
|
|
203
|
+
source !== "control" &&
|
|
204
|
+
source !== "process" &&
|
|
205
|
+
source !== "agent" &&
|
|
206
|
+
source !== "artifact" &&
|
|
207
|
+
source !== "runtime"
|
|
208
|
+
) {
|
|
209
|
+
throw new Error(`unsupported Trace source: ${source}`);
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
run,
|
|
213
|
+
source,
|
|
214
|
+
items: TraceProjection.projectRunTrace(stateDir, {
|
|
215
|
+
artifacts: status.artifacts as
|
|
216
|
+
| Record<string, AsyncRuns.RunArtifactDeclaration>
|
|
217
|
+
| undefined,
|
|
218
|
+
limit: Number(input.lines || Limits.DEFAULT_INSPECT_LINES),
|
|
219
|
+
source,
|
|
220
|
+
}),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
const runInstanceId = String(status.run_instance_id ?? "");
|
|
224
|
+
return {
|
|
225
|
+
run,
|
|
226
|
+
run_instance_id: runInstanceId,
|
|
227
|
+
status: status.status,
|
|
228
|
+
actor_actions: Array.isArray(status.control) ? status.control : [],
|
|
229
|
+
runtime_actions: status.status === "running" ? ["kill"] : ["archive", "prune"],
|
|
230
|
+
endpoint: runInstanceId
|
|
231
|
+
? RunControlDelivery.readRunControlEndpoint(stateDir, runInstanceId)
|
|
232
|
+
: undefined,
|
|
233
|
+
recent_controls: RunsControls.readRunControlsFromStateDir(stateDir)
|
|
234
|
+
.slice(-Math.max(1, Number(input.lines || 20)))
|
|
235
|
+
.reverse(),
|
|
236
|
+
};
|
|
479
237
|
}
|
|
480
238
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
239
|
+
function inspectTool(
|
|
240
|
+
name: string,
|
|
241
|
+
view: string,
|
|
242
|
+
deps: InspectToolDeps,
|
|
243
|
+
): Record<string, unknown> {
|
|
244
|
+
if (!name || !/^[A-Za-z0-9_.-]+$/.test(name)) {
|
|
245
|
+
throw new Error(`invalid tool target: tool:${name}`);
|
|
246
|
+
}
|
|
247
|
+
if (view !== "status" && view !== "schema") {
|
|
248
|
+
throw new Error("inspect tool:<name> supports view=status or view=schema.");
|
|
249
|
+
}
|
|
250
|
+
const tool = deps.getTool?.(name);
|
|
251
|
+
if (!tool) throw new Error(`registered tool not found: ${name}`);
|
|
252
|
+
return {
|
|
253
|
+
name,
|
|
254
|
+
description: tool.description,
|
|
255
|
+
parameters: tool.parameters,
|
|
256
|
+
promptSnippet: tool.promptSnippet,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function compactResult(target: string, view: string, details: Record<string, unknown>): string {
|
|
261
|
+
if (target === "runtime") return compactRuntime(view, details);
|
|
262
|
+
if (target === "recipes") return ToolsResponse.compactRecipeRegistry(details);
|
|
263
|
+
if (target.startsWith("tool:")) return `\ntool=${target.slice(5)} view=${view}`;
|
|
264
|
+
return `\nrun=${target.slice(4)} view=${view}`;
|
|
487
265
|
}
|
|
488
266
|
|
|
489
267
|
export function createInspectToolDefinition<TContext = unknown>(
|
|
@@ -493,23 +271,18 @@ export function createInspectToolDefinition<TContext = unknown>(
|
|
|
493
271
|
name: "inspect",
|
|
494
272
|
label: "Inspect",
|
|
495
273
|
description:
|
|
496
|
-
"
|
|
274
|
+
"Inspect a Run's Recipe, Trace, or Control evidence, or runtime/recipe/tool diagnostics.",
|
|
497
275
|
parameters: Schema.objectSchema(
|
|
498
276
|
{
|
|
499
|
-
lines: Schema.stringSchema(
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
status: Schema.stringSchema(
|
|
503
|
-
"Optional session run filter: all, running, active, terminal, done, failed, cancelled, killed, or exited.",
|
|
504
|
-
),
|
|
505
|
-
target: Schema.stringSchema(
|
|
506
|
-
"Actor address to inspect, e.g. run:<id> or tool:<name>; advanced: branch:<run>/<branch>, room:<run>, coordinator, session:<id>, session:all.",
|
|
507
|
-
),
|
|
508
|
-
verbose: Schema.booleanSchema(
|
|
509
|
-
"Return full JSON instead of compact text where available.",
|
|
277
|
+
lines: Schema.stringSchema("Bounded item count for Trace or recent Controls."),
|
|
278
|
+
source: Schema.stringSchema(
|
|
279
|
+
"Optional Trace source: all, lifecycle, control, process, agent, artifact, or runtime.",
|
|
510
280
|
),
|
|
281
|
+
status: Schema.stringSchema("Optional runtime Run status filter."),
|
|
282
|
+
target: Schema.stringSchema("Target: run:<id>, runtime, recipes, or tool:<name>."),
|
|
283
|
+
verbose: Schema.booleanSchema("Return full JSON instead of compact text."),
|
|
511
284
|
view: Schema.stringSchema(
|
|
512
|
-
"
|
|
285
|
+
"Run view recipe|trace|control, or target-specific management view.",
|
|
513
286
|
),
|
|
514
287
|
},
|
|
515
288
|
["target", "view"],
|
|
@@ -524,467 +297,33 @@ export function createInspectToolDefinition<TContext = unknown>(
|
|
|
524
297
|
const input = asRecord(params);
|
|
525
298
|
const target = String(input.target ?? "");
|
|
526
299
|
const view = String(input.view ?? "");
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
)
|
|
300
|
+
let details: Record<string, unknown>;
|
|
301
|
+
if (target === "runtime") {
|
|
302
|
+
details = inspectRuntime(view, input, ctx, deps);
|
|
303
|
+
} else if (target === "recipes") {
|
|
304
|
+
details = inspectRecipes(view, deps);
|
|
305
|
+
} else {
|
|
306
|
+
const run = parseRunTarget(target);
|
|
307
|
+
if (run) details = inspectRun(run, view, input, ctx, deps);
|
|
308
|
+
else if (target.startsWith("tool:")) {
|
|
309
|
+
details = inspectTool(target.slice(5), view, deps);
|
|
310
|
+
} else {
|
|
535
311
|
throw new Error(
|
|
536
|
-
|
|
312
|
+
`unsupported inspect target: ${target}; use run:<id>, runtime, recipes, or tool:<name>`,
|
|
537
313
|
);
|
|
538
314
|
}
|
|
539
|
-
if (view === "reviews") {
|
|
540
|
-
const diagnostics = ReviewDiagnostics.readAutomaticReviewDiagnostics({
|
|
541
|
-
recipeRoot: deps.recipeRoot ?? Paths.getRecipeRoot(),
|
|
542
|
-
});
|
|
543
|
-
return {
|
|
544
|
-
content: [{
|
|
545
|
-
type: "text" as const,
|
|
546
|
-
text: maybeJsonText(
|
|
547
|
-
diagnostics,
|
|
548
|
-
input.verbose === true,
|
|
549
|
-
compactAutomaticReviewDiagnostics(diagnostics),
|
|
550
|
-
),
|
|
551
|
-
}],
|
|
552
|
-
details: diagnostics,
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
const discovered = RecipesDiscovery.discoverRecipeSources([
|
|
556
|
-
{
|
|
557
|
-
root: deps.recipeRoot ?? Paths.getRecipeRoot(),
|
|
558
|
-
defaultTool: true,
|
|
559
|
-
mutableUsage: true,
|
|
560
|
-
},
|
|
561
|
-
{ root: deps.packagedRecipeRoot ?? Paths.getPackagedRecipeRoot() },
|
|
562
|
-
]);
|
|
563
|
-
const recipeRoot = deps.recipeRoot ?? Paths.getRecipeRoot();
|
|
564
|
-
const summaryBase = {
|
|
565
|
-
...RecipesDiscovery.summarizeDiscovery(discovered),
|
|
566
|
-
drafts: RecipesDiscovery.listDraftRecipes(join(recipeRoot, "drafts")),
|
|
567
|
-
};
|
|
568
|
-
const summary = {
|
|
569
|
-
...summaryBase,
|
|
570
|
-
next_actions: ToolsResponse.recipeRegistryNextActions(
|
|
571
|
-
summaryBase,
|
|
572
|
-
view,
|
|
573
|
-
),
|
|
574
|
-
};
|
|
575
|
-
return {
|
|
576
|
-
content: [
|
|
577
|
-
{
|
|
578
|
-
type: "text" as const,
|
|
579
|
-
text: maybeJsonText(
|
|
580
|
-
summary,
|
|
581
|
-
input.verbose === true,
|
|
582
|
-
view === "doctor"
|
|
583
|
-
? ToolsResponse.compactRecipeDoctor(summary)
|
|
584
|
-
: view === "imports"
|
|
585
|
-
? ToolsResponse.compactRecipeImports(summary)
|
|
586
|
-
: ToolsResponse.compactRecipeRegistry(summary),
|
|
587
|
-
),
|
|
588
|
-
},
|
|
589
|
-
],
|
|
590
|
-
details: summary,
|
|
591
|
-
};
|
|
592
315
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
"inspect coordinator supports view=status or view=runs.",
|
|
598
|
-
);
|
|
599
|
-
}
|
|
600
|
-
const session = ToolsAccess.requireContextSessionId(
|
|
601
|
-
ctx,
|
|
602
|
-
"inspect coordinator",
|
|
603
|
-
);
|
|
604
|
-
const allRuns = AsyncRuns.listRuns(
|
|
605
|
-
undefined,
|
|
606
|
-
typeof input.status === "string" ? input.status : undefined,
|
|
607
|
-
).map((run) => AsyncRuns.getRunStatus(String(run.state_dir)));
|
|
608
|
-
const runs = allRuns.filter((run) => run.ownerId === session);
|
|
609
|
-
const sessionSummary = summarizeOtherSessions(session, allRuns);
|
|
610
|
-
return {
|
|
611
|
-
content: [
|
|
612
|
-
{
|
|
613
|
-
type: "text" as const,
|
|
614
|
-
text: maybeJsonText(
|
|
615
|
-
{ session, runs, ...sessionSummary },
|
|
616
|
-
input.verbose === true,
|
|
617
|
-
compactSessionRuns(session, runs, sessionSummary),
|
|
618
|
-
),
|
|
619
|
-
},
|
|
620
|
-
],
|
|
621
|
-
details: { session, runs, ...sessionSummary },
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
if (address.kind === "session") {
|
|
625
|
-
if (view !== "status" && view !== "runs") {
|
|
626
|
-
throw new Error(
|
|
627
|
-
"inspect session:<id> supports view=status or view=runs.",
|
|
628
|
-
);
|
|
629
|
-
}
|
|
630
|
-
const allRuns = AsyncRuns.listRuns(
|
|
631
|
-
undefined,
|
|
632
|
-
typeof input.status === "string" ? input.status : undefined,
|
|
633
|
-
).map((run) => AsyncRuns.getRunStatus(String(run.state_dir)));
|
|
634
|
-
const runs = allRuns.filter(
|
|
635
|
-
(run) => address.value === "all" || run.ownerId === address.value,
|
|
636
|
-
);
|
|
637
|
-
const sessionSummary =
|
|
638
|
-
address.value === "all"
|
|
639
|
-
? {}
|
|
640
|
-
: summarizeOtherSessions(address.value || "", allRuns);
|
|
641
|
-
return {
|
|
642
|
-
content: [
|
|
643
|
-
{
|
|
644
|
-
type: "text" as const,
|
|
645
|
-
text: maybeJsonText(
|
|
646
|
-
{ session: address.value, runs, ...sessionSummary },
|
|
647
|
-
input.verbose === true,
|
|
648
|
-
compactSessionRuns(address.value || "", runs, sessionSummary),
|
|
649
|
-
),
|
|
650
|
-
},
|
|
651
|
-
],
|
|
652
|
-
details: { session: address.value, runs, ...sessionSummary },
|
|
653
|
-
};
|
|
654
|
-
}
|
|
655
|
-
if (address.kind === "tool" && address.value) {
|
|
656
|
-
if (address.value === "pi-actors") {
|
|
657
|
-
if (view !== "status" && view !== "triage") {
|
|
658
|
-
throw new Error(
|
|
659
|
-
"inspect tool:pi-actors supports view=status or view=triage.",
|
|
660
|
-
);
|
|
661
|
-
}
|
|
662
|
-
const details =
|
|
663
|
-
view === "triage"
|
|
664
|
-
? getPiActorsTriage(ctx, deps)
|
|
665
|
-
: getPiActorsRuntimeStatus();
|
|
666
|
-
return {
|
|
667
|
-
content: [
|
|
668
|
-
{
|
|
669
|
-
type: "text" as const,
|
|
670
|
-
text: maybeJsonText(
|
|
671
|
-
details,
|
|
672
|
-
input.verbose === true,
|
|
673
|
-
view === "triage"
|
|
674
|
-
? compactPiActorsTriage(details)
|
|
675
|
-
: compactPiActorsRuntimeStatus(details),
|
|
676
|
-
),
|
|
677
|
-
},
|
|
678
|
-
],
|
|
316
|
+
return {
|
|
317
|
+
content: [{
|
|
318
|
+
type: "text" as const,
|
|
319
|
+
text: maybeJsonText(
|
|
679
320
|
details,
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
}
|
|
687
|
-
const tool = deps.getTool?.(address.value);
|
|
688
|
-
if (!tool) throw new Error(`tool actor not found: ${address.value}`);
|
|
689
|
-
const details = {
|
|
690
|
-
name: address.value,
|
|
691
|
-
description: tool.description,
|
|
692
|
-
parameters: tool.parameters,
|
|
693
|
-
promptSnippet: tool.promptSnippet,
|
|
694
|
-
};
|
|
695
|
-
return {
|
|
696
|
-
content: [
|
|
697
|
-
{
|
|
698
|
-
type: "text" as const,
|
|
699
|
-
text: maybeJsonText(
|
|
700
|
-
details,
|
|
701
|
-
input.verbose === true || view === "schema",
|
|
702
|
-
compactToolActor(address.value, details),
|
|
703
|
-
),
|
|
704
|
-
},
|
|
705
|
-
],
|
|
706
|
-
details,
|
|
707
|
-
};
|
|
708
|
-
}
|
|
709
|
-
if (address.kind === "room" && address.value && address.room) {
|
|
710
|
-
const status = ToolsAccess.assertRunAccessibleToContext(
|
|
711
|
-
address.value,
|
|
712
|
-
ctx,
|
|
713
|
-
);
|
|
714
|
-
const stateDir = String(status.state_dir ?? "");
|
|
715
|
-
if (!stateDir)
|
|
716
|
-
throw new Error(`room:${address.value} has no run state directory.`);
|
|
717
|
-
if (view === "status") {
|
|
718
|
-
const status = Rooms.getRoomStatus(stateDir, address.room);
|
|
719
|
-
return {
|
|
720
|
-
content: [
|
|
721
|
-
{
|
|
722
|
-
type: "text" as const,
|
|
723
|
-
text: maybeJsonText(
|
|
724
|
-
status,
|
|
725
|
-
input.verbose === true,
|
|
726
|
-
compactRoomStatus(status),
|
|
727
|
-
),
|
|
728
|
-
},
|
|
729
|
-
],
|
|
730
|
-
details: status,
|
|
731
|
-
};
|
|
732
|
-
}
|
|
733
|
-
if (view === "previews") {
|
|
734
|
-
const previews = Rooms.readRoomMessagePreviews(
|
|
735
|
-
stateDir,
|
|
736
|
-
address.room,
|
|
737
|
-
Number(input.lines || Limits.DEFAULT_INSPECT_LINES),
|
|
738
|
-
);
|
|
739
|
-
return {
|
|
740
|
-
content: [
|
|
741
|
-
{
|
|
742
|
-
type: "text" as const,
|
|
743
|
-
text: maybeJsonText(
|
|
744
|
-
previews,
|
|
745
|
-
input.verbose === true,
|
|
746
|
-
compactRoomPreviews(previews),
|
|
747
|
-
),
|
|
748
|
-
},
|
|
749
|
-
],
|
|
750
|
-
details: { previews },
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
if (view === "messages") {
|
|
754
|
-
const messages = Rooms.readRoomMessages(
|
|
755
|
-
stateDir,
|
|
756
|
-
address.room,
|
|
757
|
-
Number(input.lines || Limits.DEFAULT_INSPECT_LINES),
|
|
758
|
-
);
|
|
759
|
-
return {
|
|
760
|
-
content: [
|
|
761
|
-
{
|
|
762
|
-
type: "text" as const,
|
|
763
|
-
text: maybeJsonText(
|
|
764
|
-
messages,
|
|
765
|
-
input.verbose === true,
|
|
766
|
-
compactRoomMessages(messages),
|
|
767
|
-
),
|
|
768
|
-
},
|
|
769
|
-
],
|
|
770
|
-
details: { messages },
|
|
771
|
-
};
|
|
772
|
-
}
|
|
773
|
-
if (view === "contacts") {
|
|
774
|
-
const contacts = Rooms.readRoomContacts(stateDir, address.room);
|
|
775
|
-
return {
|
|
776
|
-
content: [
|
|
777
|
-
{
|
|
778
|
-
type: "text" as const,
|
|
779
|
-
text: maybeJsonText(
|
|
780
|
-
contacts,
|
|
781
|
-
input.verbose === true,
|
|
782
|
-
compactRoomContacts(contacts),
|
|
783
|
-
),
|
|
784
|
-
},
|
|
785
|
-
],
|
|
786
|
-
details: { contacts },
|
|
787
|
-
};
|
|
788
|
-
}
|
|
789
|
-
if (view === "roster") {
|
|
790
|
-
const roster = Rooms.readRoomRoster(stateDir, address.room);
|
|
791
|
-
return {
|
|
792
|
-
content: [
|
|
793
|
-
{
|
|
794
|
-
type: "text" as const,
|
|
795
|
-
text: maybeJsonText(
|
|
796
|
-
roster,
|
|
797
|
-
input.verbose === true,
|
|
798
|
-
compactRoomRoster(roster),
|
|
799
|
-
),
|
|
800
|
-
},
|
|
801
|
-
],
|
|
802
|
-
details: { roster },
|
|
803
|
-
};
|
|
804
|
-
}
|
|
805
|
-
throw new Error(
|
|
806
|
-
"inspect room:<run> supports view=status, view=messages, view=previews, view=roster, or view=contacts.",
|
|
807
|
-
);
|
|
808
|
-
}
|
|
809
|
-
const runId =
|
|
810
|
-
address.kind === "run" || address.kind === "branch"
|
|
811
|
-
? address.value
|
|
812
|
-
: undefined;
|
|
813
|
-
if (!runId)
|
|
814
|
-
throw new Error(
|
|
815
|
-
"inspect target must be run:<id>, branch:<run>/<branch>, coordinator, session:<id>, or tool:<name>.",
|
|
816
|
-
);
|
|
817
|
-
if (address.kind === "branch") {
|
|
818
|
-
if (view !== "mailbox")
|
|
819
|
-
throw new Error(
|
|
820
|
-
"inspect branch:<run>/<branch> supports view=mailbox.",
|
|
821
|
-
);
|
|
822
|
-
const status = ToolsAccess.assertRunAccessibleToContext(runId, ctx);
|
|
823
|
-
const branchInbox = Rooms.readBranchInboxDiagnostics(
|
|
824
|
-
String(status.state_dir ?? ""),
|
|
825
|
-
runId,
|
|
826
|
-
target,
|
|
827
|
-
Number(input.lines || Limits.DEFAULT_INSPECT_LINES),
|
|
828
|
-
);
|
|
829
|
-
const messages = branchInbox.messages;
|
|
830
|
-
return {
|
|
831
|
-
content: [
|
|
832
|
-
{
|
|
833
|
-
type: "text" as const,
|
|
834
|
-
text: maybeJsonText(
|
|
835
|
-
input.verbose === true ? branchInbox : messages,
|
|
836
|
-
input.verbose === true,
|
|
837
|
-
`${ToolsResponse.compactBranchInbox(messages.map((message) => ({ ...message })))}${branchInbox.corrupted > 0 ? `\ncorrupted=${branchInbox.corrupted}` : ""}`,
|
|
838
|
-
),
|
|
839
|
-
},
|
|
840
|
-
],
|
|
841
|
-
details: { corrupted: branchInbox.corrupted, messages },
|
|
842
|
-
};
|
|
843
|
-
}
|
|
844
|
-
switch (view) {
|
|
845
|
-
case "status": {
|
|
846
|
-
const status = ToolsAccess.assertRunAccessibleToContext(runId, ctx);
|
|
847
|
-
return {
|
|
848
|
-
content: [
|
|
849
|
-
{
|
|
850
|
-
type: "text" as const,
|
|
851
|
-
text: maybeJsonText(
|
|
852
|
-
status,
|
|
853
|
-
input.verbose === true,
|
|
854
|
-
ToolsResponse.compactAsyncRunStatus(status),
|
|
855
|
-
),
|
|
856
|
-
},
|
|
857
|
-
],
|
|
858
|
-
details: status,
|
|
859
|
-
};
|
|
860
|
-
}
|
|
861
|
-
case "tail": {
|
|
862
|
-
ToolsAccess.assertRunAccessibleToContext(runId, ctx);
|
|
863
|
-
const text = AsyncRuns.tailRun(
|
|
864
|
-
runId,
|
|
865
|
-
Number(input.lines || Limits.DEFAULT_INSPECT_LINES),
|
|
866
|
-
);
|
|
867
|
-
return {
|
|
868
|
-
content: [{ type: "text" as const, text: `\n${text}` }],
|
|
869
|
-
details: {},
|
|
870
|
-
};
|
|
871
|
-
}
|
|
872
|
-
case "messages": {
|
|
873
|
-
ToolsAccess.assertRunAccessibleToContext(runId, ctx);
|
|
874
|
-
const messages = AsyncRuns.readRunEvents(
|
|
875
|
-
runId,
|
|
876
|
-
Number(input.lines || Limits.DEFAULT_INSPECT_LINES),
|
|
877
|
-
);
|
|
878
|
-
return {
|
|
879
|
-
content: [
|
|
880
|
-
{
|
|
881
|
-
type: "text" as const,
|
|
882
|
-
text: maybeJsonText(
|
|
883
|
-
messages,
|
|
884
|
-
input.verbose === true,
|
|
885
|
-
compactRunMessages(messages),
|
|
886
|
-
),
|
|
887
|
-
},
|
|
888
|
-
],
|
|
889
|
-
details: { messages },
|
|
890
|
-
};
|
|
891
|
-
}
|
|
892
|
-
case "artifacts":
|
|
893
|
-
case "files": {
|
|
894
|
-
const status = ToolsAccess.assertRunAccessibleToContext(runId, ctx);
|
|
895
|
-
const artifactManifest = AsyncRuns.resolveArtifactManifest(
|
|
896
|
-
status.artifacts as
|
|
897
|
-
| Record<string, AsyncRuns.RunArtifactDeclaration>
|
|
898
|
-
| undefined,
|
|
899
|
-
);
|
|
900
|
-
const reviewEvidence = readBoundedReviewEvidence(
|
|
901
|
-
status,
|
|
902
|
-
Number(input.lines || Limits.DEFAULT_INSPECT_LINES),
|
|
903
|
-
);
|
|
904
|
-
const details = artifactManifest
|
|
905
|
-
? {
|
|
906
|
-
...status,
|
|
907
|
-
...(reviewEvidence ? { review_evidence: reviewEvidence } : {}),
|
|
908
|
-
artifact_manifest: artifactManifest,
|
|
909
|
-
next_actions: ToolsResponse.artifactNextActions(
|
|
910
|
-
status.run ?? runId,
|
|
911
|
-
asRecord(status.artifacts),
|
|
912
|
-
),
|
|
913
|
-
}
|
|
914
|
-
: {
|
|
915
|
-
...status,
|
|
916
|
-
...(reviewEvidence ? { review_evidence: reviewEvidence } : {}),
|
|
917
|
-
};
|
|
918
|
-
return {
|
|
919
|
-
content: [
|
|
920
|
-
{
|
|
921
|
-
type: "text" as const,
|
|
922
|
-
text: maybeJsonText(
|
|
923
|
-
details,
|
|
924
|
-
input.verbose === true,
|
|
925
|
-
compactActorFiles(status),
|
|
926
|
-
),
|
|
927
|
-
},
|
|
928
|
-
],
|
|
929
|
-
details,
|
|
930
|
-
};
|
|
931
|
-
}
|
|
932
|
-
case "mailbox": {
|
|
933
|
-
const status = ToolsAccess.assertRunAccessibleToContext(runId, ctx);
|
|
934
|
-
const mailbox = asRecord(status.mailbox);
|
|
935
|
-
const normalizedMailbox =
|
|
936
|
-
ToolsMailbox.normalizeMailboxContracts(mailbox);
|
|
937
|
-
const messages = AsyncRuns.readRunInboxMessages(
|
|
938
|
-
runId,
|
|
939
|
-
Number(input.lines || Limits.DEFAULT_INSPECT_LINES),
|
|
940
|
-
);
|
|
941
|
-
const details = {
|
|
942
|
-
mailbox,
|
|
943
|
-
normalized_mailbox: normalizedMailbox,
|
|
944
|
-
messages,
|
|
945
|
-
};
|
|
946
|
-
return {
|
|
947
|
-
content: [
|
|
948
|
-
{
|
|
949
|
-
type: "text" as const,
|
|
950
|
-
text: maybeJsonText(
|
|
951
|
-
details,
|
|
952
|
-
input.verbose === true,
|
|
953
|
-
ToolsResponse.compactRunMailbox(
|
|
954
|
-
String(status.run ?? runId),
|
|
955
|
-
mailbox,
|
|
956
|
-
messages,
|
|
957
|
-
),
|
|
958
|
-
),
|
|
959
|
-
},
|
|
960
|
-
],
|
|
961
|
-
details,
|
|
962
|
-
};
|
|
963
|
-
}
|
|
964
|
-
case "communication": {
|
|
965
|
-
const status = ToolsAccess.assertRunAccessibleToContext(runId, ctx);
|
|
966
|
-
const snapshot = Rooms.readCommunicationSnapshot(
|
|
967
|
-
String(status.state_dir ?? ""),
|
|
968
|
-
);
|
|
969
|
-
return {
|
|
970
|
-
content: [
|
|
971
|
-
{
|
|
972
|
-
type: "text" as const,
|
|
973
|
-
text: maybeJsonText(
|
|
974
|
-
snapshot ?? {},
|
|
975
|
-
input.verbose === true,
|
|
976
|
-
compactCommunicationSnapshot(snapshot),
|
|
977
|
-
),
|
|
978
|
-
},
|
|
979
|
-
],
|
|
980
|
-
details: { communication: snapshot },
|
|
981
|
-
};
|
|
982
|
-
}
|
|
983
|
-
default:
|
|
984
|
-
throw new Error(
|
|
985
|
-
"inspect view must be one of: status, tail, messages, artifacts, files, mailbox, communication; branch targets support mailbox.",
|
|
986
|
-
);
|
|
987
|
-
}
|
|
321
|
+
input.verbose === true || (target.startsWith("tool:") && view === "schema"),
|
|
322
|
+
compactResult(target, view, details),
|
|
323
|
+
),
|
|
324
|
+
}],
|
|
325
|
+
details,
|
|
326
|
+
};
|
|
988
327
|
},
|
|
989
328
|
};
|
|
990
329
|
}
|