@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/dist/lib/inspector.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Inspector
|
|
3
|
-
* Zones:
|
|
4
|
-
* Owns
|
|
2
|
+
* Actor Inspector evidence readers.
|
|
3
|
+
* Zones: owned actor-instance inventory and captured Recipe projection
|
|
4
|
+
* Owns actor-instance TUI evidence; Trace, Control, and execution parsing stay in their domains.
|
|
5
5
|
*/
|
|
6
6
|
import * as fs from "node:fs";
|
|
7
7
|
import * as path from "node:path";
|
|
8
|
-
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
9
|
-
import * as Limits from "./limits.js";
|
|
10
|
-
import * as Paths from "./paths.js";
|
|
11
8
|
import * as SessionEvidence from "./session-evidence.js";
|
|
12
|
-
import { readJsonFileResilient
|
|
9
|
+
import { readJsonFileResilient } from "./state-readers.js";
|
|
10
|
+
function matchesOwner(stateDir, ownerId) {
|
|
11
|
+
const meta = readJsonFileResilient(path.join(stateDir, "run.json"), {}).value;
|
|
12
|
+
return meta.ownerId === ownerId;
|
|
13
|
+
}
|
|
13
14
|
export function readActorInspectorRuns(stateRoot, ownerId) {
|
|
14
15
|
try {
|
|
15
16
|
return fs
|
|
@@ -27,7 +28,8 @@ export function readActorInspectorRuns(stateRoot, ownerId) {
|
|
|
27
28
|
...(typeof runMeta.run_instance_id === "string"
|
|
28
29
|
? { runInstanceId: runMeta.run_instance_id }
|
|
29
30
|
: {}),
|
|
30
|
-
status: String(progress.phase ??
|
|
31
|
+
status: String(progress.phase ??
|
|
32
|
+
(Object.keys(result).length ? "terminal" : "unknown")),
|
|
31
33
|
...(typeof progress.updatedAt === "string"
|
|
32
34
|
? { updatedAt: progress.updatedAt }
|
|
33
35
|
: typeof result.completedAt === "string"
|
|
@@ -35,14 +37,10 @@ export function readActorInspectorRuns(stateRoot, ownerId) {
|
|
|
35
37
|
: {}),
|
|
36
38
|
}];
|
|
37
39
|
})
|
|
38
|
-
.sort((left, right) =>
|
|
39
|
-
|
|
40
|
-
return recency || right.run.localeCompare(left.run);
|
|
41
|
-
});
|
|
40
|
+
.sort((left, right) => String(right.updatedAt ?? "").localeCompare(String(left.updatedAt ?? "")) ||
|
|
41
|
+
right.run.localeCompare(left.run));
|
|
42
42
|
}
|
|
43
|
-
catch
|
|
44
|
-
if (error.code === "ENOENT")
|
|
45
|
-
return [];
|
|
43
|
+
catch {
|
|
46
44
|
return [];
|
|
47
45
|
}
|
|
48
46
|
}
|
|
@@ -50,16 +48,15 @@ export function readActorInspectorRecipe(stateDir) {
|
|
|
50
48
|
const result = readJsonFileResilient(path.join(stateDir, "run.json"), {});
|
|
51
49
|
const meta = result.value;
|
|
52
50
|
const contexts = Array.isArray(meta.recipe_context_records)
|
|
53
|
-
? meta.recipe_context_records
|
|
54
|
-
.filter((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry)))
|
|
51
|
+
? meta.recipe_context_records.filter((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry)))
|
|
55
52
|
: [];
|
|
56
53
|
const primary = contexts.find((entry) => entry.depth === 0) ?? contexts[0];
|
|
57
|
-
const definition = primary?.recipe &&
|
|
54
|
+
const definition = primary?.recipe &&
|
|
55
|
+
typeof primary.recipe === "object" &&
|
|
58
56
|
!Array.isArray(primary.recipe)
|
|
59
57
|
? primary.recipe
|
|
60
58
|
: undefined;
|
|
61
|
-
const
|
|
62
|
-
const redactedRecord = (value) => redacted(Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== undefined)));
|
|
59
|
+
const redactedRecord = (value) => SessionEvidence.redactSessionEvidenceValue(Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== undefined)));
|
|
63
60
|
return {
|
|
64
61
|
composition: contexts.map((entry) => redactedRecord({
|
|
65
62
|
...(typeof entry.alias === "string" ? { alias: entry.alias } : {}),
|
|
@@ -68,9 +65,7 @@ export function readActorInspectorRecipe(stateDir) {
|
|
|
68
65
|
import_path: entry.import_path,
|
|
69
66
|
name: entry.name,
|
|
70
67
|
})),
|
|
71
|
-
...(definition
|
|
72
|
-
? { definition: redactedRecord(definition) }
|
|
73
|
-
: {}),
|
|
68
|
+
...(definition ? { definition: redactedRecord(definition) } : {}),
|
|
74
69
|
diagnostics: result.diagnostics.map((diagnostic) => diagnostic.message),
|
|
75
70
|
identity: redactedRecord({
|
|
76
71
|
run: meta.run,
|
|
@@ -83,651 +78,10 @@ export function readActorInspectorRecipe(stateDir) {
|
|
|
83
78
|
template: meta.template,
|
|
84
79
|
values: meta.values,
|
|
85
80
|
model_policy: meta.model_policy,
|
|
86
|
-
|
|
81
|
+
control: meta.control,
|
|
87
82
|
artifacts: meta.artifacts,
|
|
88
83
|
notification_policy: meta.notification_policy,
|
|
89
84
|
retire_when: meta.retire_when,
|
|
90
85
|
}),
|
|
91
86
|
};
|
|
92
87
|
}
|
|
93
|
-
function ownedSessionPath(stateDir, sessionFile) {
|
|
94
|
-
if (path.isAbsolute(sessionFile))
|
|
95
|
-
return undefined;
|
|
96
|
-
const sessionsRoot = path.resolve(stateDir, "sessions");
|
|
97
|
-
const resolved = path.resolve(stateDir, sessionFile);
|
|
98
|
-
if (!resolved.startsWith(`${sessionsRoot}${path.sep}`))
|
|
99
|
-
return undefined;
|
|
100
|
-
try {
|
|
101
|
-
const canonicalRoot = fs.realpathSync(sessionsRoot);
|
|
102
|
-
const canonicalFile = fs.realpathSync(resolved);
|
|
103
|
-
return canonicalFile.startsWith(`${canonicalRoot}${path.sep}`)
|
|
104
|
-
? canonicalFile
|
|
105
|
-
: undefined;
|
|
106
|
-
}
|
|
107
|
-
catch {
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
export function readActorInspectorTurns(stateDir) {
|
|
112
|
-
const evidence = readJsonFileResilient(path.join(stateDir, "review-evidence.json"), {}).value;
|
|
113
|
-
const commands = Array.isArray(evidence.commands)
|
|
114
|
-
? evidence.commands
|
|
115
|
-
: [];
|
|
116
|
-
const recordedFiles = new Set(commands.flatMap((command) => (Array.isArray(command.session_files) ? command.session_files : []).filter((file) => typeof file === "string")));
|
|
117
|
-
let discoveredCommands = [];
|
|
118
|
-
try {
|
|
119
|
-
const sessionsDir = path.join(stateDir, "sessions");
|
|
120
|
-
discoveredCommands = fs
|
|
121
|
-
.readdirSync(sessionsDir, { withFileTypes: true })
|
|
122
|
-
.filter((entry) => entry.isDirectory())
|
|
123
|
-
.flatMap((entry) => {
|
|
124
|
-
const files = fs
|
|
125
|
-
.readdirSync(path.join(sessionsDir, entry.name), {
|
|
126
|
-
withFileTypes: true,
|
|
127
|
-
})
|
|
128
|
-
.filter((file) => file.isFile() && file.name.endsWith(".jsonl"))
|
|
129
|
-
.map((file) => path.posix.join("sessions", entry.name, file.name))
|
|
130
|
-
.filter((file) => !recordedFiles.has(file));
|
|
131
|
-
return files.length > 0
|
|
132
|
-
? [{ id: entry.name, session_files: files, stage: "subagent" }]
|
|
133
|
-
: [];
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
catch {
|
|
137
|
-
discoveredCommands = [];
|
|
138
|
-
}
|
|
139
|
-
return [...commands, ...discoveredCommands].flatMap((command) => (Array.isArray(command.session_files) ? command.session_files : [])
|
|
140
|
-
.filter((file) => typeof file === "string")
|
|
141
|
-
.flatMap((file) => {
|
|
142
|
-
const sessionPath = ownedSessionPath(stateDir, file);
|
|
143
|
-
if (!sessionPath)
|
|
144
|
-
return [];
|
|
145
|
-
const session = SessionEvidence.readSessionEvidence(sessionPath);
|
|
146
|
-
return session.turns.map((turn) => ({
|
|
147
|
-
...turn,
|
|
148
|
-
commandId: String(command.id ?? "unknown"),
|
|
149
|
-
diagnostics: session.diagnostics.map((item) => `${item.line === undefined ? "" : `line ${item.line}: `}${item.message}`),
|
|
150
|
-
...(typeof command.prompt_bytes === "number"
|
|
151
|
-
? { promptBytes: command.prompt_bytes }
|
|
152
|
-
: {}),
|
|
153
|
-
...(typeof command.prompt_file === "string"
|
|
154
|
-
? { promptFile: command.prompt_file }
|
|
155
|
-
: {}),
|
|
156
|
-
...(command.recipe_context !== undefined
|
|
157
|
-
? { recipeContext: command.recipe_context }
|
|
158
|
-
: {}),
|
|
159
|
-
sessionFile: file,
|
|
160
|
-
sessionTruncated: session.truncated,
|
|
161
|
-
...(typeof command.stage === "string" ? { stage: command.stage } : {}),
|
|
162
|
-
}));
|
|
163
|
-
})).map((turn, index) => ({ ...turn, index: index + 1 }));
|
|
164
|
-
}
|
|
165
|
-
function asRecord(value) {
|
|
166
|
-
return value && typeof value === "object" && !Array.isArray(value)
|
|
167
|
-
? value
|
|
168
|
-
: {};
|
|
169
|
-
}
|
|
170
|
-
function readJsonLines(file) {
|
|
171
|
-
return readJsonlFileResilient(file).records;
|
|
172
|
-
}
|
|
173
|
-
function previewValue(value, maxLength = Limits.INSPECTOR_BODY_PREVIEW_CHARS) {
|
|
174
|
-
if (value === undefined)
|
|
175
|
-
return undefined;
|
|
176
|
-
const redacted = SessionEvidence.redactSessionEvidenceValue(value);
|
|
177
|
-
const text = typeof redacted === "string" ? redacted : JSON.stringify(redacted);
|
|
178
|
-
const compact = text.replaceAll(/\s+/g, " ").trim();
|
|
179
|
-
if (!compact)
|
|
180
|
-
return undefined;
|
|
181
|
-
return compact.length > maxLength
|
|
182
|
-
? `${compact.slice(0, Math.max(0, maxLength - 1))}…`
|
|
183
|
-
: compact;
|
|
184
|
-
}
|
|
185
|
-
function channelFor(message) {
|
|
186
|
-
if (message.to.startsWith("room:"))
|
|
187
|
-
return "room";
|
|
188
|
-
if (message.to === "coordinator" || message.to.startsWith("session:"))
|
|
189
|
-
return "broadcast";
|
|
190
|
-
return "direct";
|
|
191
|
-
}
|
|
192
|
-
function previewFromMessage(run, message, timestamp, displayNames = {}) {
|
|
193
|
-
const to = typeof message.to === "string" ? message.to : undefined;
|
|
194
|
-
const type = typeof message.type === "string" ? message.type : undefined;
|
|
195
|
-
if (!to || !type)
|
|
196
|
-
return undefined;
|
|
197
|
-
const from = typeof message.from === "string" ? message.from : undefined;
|
|
198
|
-
const summary = typeof message.summary === "string" ? message.summary : undefined;
|
|
199
|
-
const body = asRecord(message.body);
|
|
200
|
-
const metadata = asRecord(message.metadata);
|
|
201
|
-
const eventId = typeof message.id === "string" && message.id.trim()
|
|
202
|
-
? message.id.trim()
|
|
203
|
-
: undefined;
|
|
204
|
-
const display = from
|
|
205
|
-
? typeof body.display === "string" && body.display.trim()
|
|
206
|
-
? body.display.trim()
|
|
207
|
-
: displayNames[from]
|
|
208
|
-
: undefined;
|
|
209
|
-
return {
|
|
210
|
-
...(previewValue(message.body)
|
|
211
|
-
? { body_preview: previewValue(message.body) }
|
|
212
|
-
: {}),
|
|
213
|
-
channel: channelFor({ to }),
|
|
214
|
-
...(eventId ? { event_id: eventId } : {}),
|
|
215
|
-
...(from ? { from } : {}),
|
|
216
|
-
...(display ? { from_display: display } : {}),
|
|
217
|
-
...(metadata.requires_response === true ? { needs_response: true } : {}),
|
|
218
|
-
run,
|
|
219
|
-
...(summary ? { summary } : {}),
|
|
220
|
-
timestamp,
|
|
221
|
-
to,
|
|
222
|
-
type,
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
function readRoomRosterRecords(stateDir, room) {
|
|
226
|
-
return readJsonFileResilient(path.join(stateDir, "rooms", room, "roster.json"), {}).value;
|
|
227
|
-
}
|
|
228
|
-
function memberDisplay(_address, member) {
|
|
229
|
-
const display = typeof member.display === "string" ? member.display.trim() : "";
|
|
230
|
-
return display || undefined;
|
|
231
|
-
}
|
|
232
|
-
function readRoomDisplayNames(stateDir, room) {
|
|
233
|
-
const roster = readRoomRosterRecords(stateDir, room);
|
|
234
|
-
return Object.fromEntries(Object.entries(roster).flatMap(([address, member]) => {
|
|
235
|
-
const display = memberDisplay(address, member);
|
|
236
|
-
return display ? [[address, display]] : [];
|
|
237
|
-
}));
|
|
238
|
-
}
|
|
239
|
-
function readRoomPreviews(run, stateDir) {
|
|
240
|
-
const roomsDir = path.join(stateDir, "rooms");
|
|
241
|
-
try {
|
|
242
|
-
const previews = fs
|
|
243
|
-
.readdirSync(roomsDir, { withFileTypes: true })
|
|
244
|
-
.filter((entry) => entry.isDirectory())
|
|
245
|
-
.flatMap((entry) => {
|
|
246
|
-
const displayNames = readRoomDisplayNames(stateDir, entry.name);
|
|
247
|
-
return readJsonLines(path.join(roomsDir, entry.name, "messages.jsonl"))
|
|
248
|
-
.map((message) => previewFromMessage(run, message, String(message.received_at ?? message.timestamp ?? ""), displayNames))
|
|
249
|
-
.filter((preview) => Boolean(preview));
|
|
250
|
-
});
|
|
251
|
-
return previews;
|
|
252
|
-
}
|
|
253
|
-
catch (error) {
|
|
254
|
-
if (error.code === "ENOENT")
|
|
255
|
-
return [];
|
|
256
|
-
return [];
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
function readInboxPreviews(run, stateDir) {
|
|
260
|
-
return readJsonLines(path.join(stateDir, "inbox.jsonl"))
|
|
261
|
-
.map((message) => previewFromMessage(run, message, String(message.received_at ?? message.timestamp ?? "")))
|
|
262
|
-
.filter((preview) => Boolean(preview));
|
|
263
|
-
}
|
|
264
|
-
function readBranchInboxPreviews(run, stateDir) {
|
|
265
|
-
const branchesDir = path.join(stateDir, "branches");
|
|
266
|
-
try {
|
|
267
|
-
return fs
|
|
268
|
-
.readdirSync(branchesDir, { withFileTypes: true })
|
|
269
|
-
.filter((entry) => entry.isDirectory())
|
|
270
|
-
.flatMap((entry) => readJsonLines(path.join(branchesDir, entry.name, "inbox.jsonl"))
|
|
271
|
-
.map((message) => {
|
|
272
|
-
const preview = previewFromMessage(run, message, String(message.queued_at ??
|
|
273
|
-
message.received_at ??
|
|
274
|
-
message.timestamp ??
|
|
275
|
-
""));
|
|
276
|
-
if (!preview)
|
|
277
|
-
return undefined;
|
|
278
|
-
return {
|
|
279
|
-
...preview,
|
|
280
|
-
branch: entry.name,
|
|
281
|
-
...(typeof message.id === "string"
|
|
282
|
-
? { message_id: message.id }
|
|
283
|
-
: {}),
|
|
284
|
-
...(typeof message.status === "string"
|
|
285
|
-
? { inbox_status: message.status }
|
|
286
|
-
: {}),
|
|
287
|
-
};
|
|
288
|
-
})
|
|
289
|
-
.filter((preview) => Boolean(preview)));
|
|
290
|
-
}
|
|
291
|
-
catch (error) {
|
|
292
|
-
if (error.code === "ENOENT")
|
|
293
|
-
return [];
|
|
294
|
-
return [];
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
function readOutboxPreviews(run, stateDir) {
|
|
298
|
-
return readJsonLines(path.join(stateDir, "outbox.jsonl"))
|
|
299
|
-
.map((event) => {
|
|
300
|
-
const message = asRecord(event.message ?? event);
|
|
301
|
-
return previewFromMessage(run, message, String(event.timestamp ?? event.created_at ?? event.emitted_at ?? ""));
|
|
302
|
-
})
|
|
303
|
-
.filter((preview) => Boolean(preview));
|
|
304
|
-
}
|
|
305
|
-
function getRunOwnerId(stateDir) {
|
|
306
|
-
const meta = readJsonFileResilient(path.join(stateDir, "run.json"), undefined).value;
|
|
307
|
-
return typeof meta?.ownerId === "string" ? meta.ownerId : undefined;
|
|
308
|
-
}
|
|
309
|
-
function matchesOwner(stateDir, ownerId) {
|
|
310
|
-
return ownerId === undefined || getRunOwnerId(stateDir) === ownerId;
|
|
311
|
-
}
|
|
312
|
-
export function inspectorPreviewReadKey(preview) {
|
|
313
|
-
return [
|
|
314
|
-
preview.channel,
|
|
315
|
-
preview.run,
|
|
316
|
-
preview.branch ?? "",
|
|
317
|
-
preview.event_id ?? preview.message_id ?? preview.timestamp,
|
|
318
|
-
preview.from ?? "",
|
|
319
|
-
preview.to,
|
|
320
|
-
preview.type,
|
|
321
|
-
].join("|");
|
|
322
|
-
}
|
|
323
|
-
function isUnreadPreview(preview, readKeys) {
|
|
324
|
-
if (readKeys?.has(inspectorPreviewReadKey(preview)))
|
|
325
|
-
return false;
|
|
326
|
-
return (preview.inbox_status === "queued" ||
|
|
327
|
-
(preview.inbox_status === undefined && preview.branch !== undefined));
|
|
328
|
-
}
|
|
329
|
-
function matchesBranchFilter(preview, branch) {
|
|
330
|
-
const name = branch?.trim();
|
|
331
|
-
if (!name)
|
|
332
|
-
return true;
|
|
333
|
-
if (preview.branch !== undefined)
|
|
334
|
-
return preview.branch === name;
|
|
335
|
-
const address = `branch:${preview.run}/${name}`;
|
|
336
|
-
return preview.from === address || preview.to === address;
|
|
337
|
-
}
|
|
338
|
-
function matchesPreviewFilter(preview, options) {
|
|
339
|
-
if (options.channels?.length && !options.channels.includes(preview.channel)) {
|
|
340
|
-
return false;
|
|
341
|
-
}
|
|
342
|
-
const readKeys = options.readKeys ? new Set(options.readKeys) : undefined;
|
|
343
|
-
if (options.unreadOnly && !isUnreadPreview(preview, readKeys))
|
|
344
|
-
return false;
|
|
345
|
-
if (!matchesBranchFilter(preview, options.branch))
|
|
346
|
-
return false;
|
|
347
|
-
const mention = options.mention?.trim().toLowerCase();
|
|
348
|
-
if (!mention)
|
|
349
|
-
return true;
|
|
350
|
-
return [
|
|
351
|
-
preview.branch,
|
|
352
|
-
preview.from,
|
|
353
|
-
preview.from_display,
|
|
354
|
-
preview.inbox_status,
|
|
355
|
-
preview.to,
|
|
356
|
-
preview.type,
|
|
357
|
-
preview.summary,
|
|
358
|
-
preview.body_preview,
|
|
359
|
-
].some((value) => value?.toLowerCase().includes(mention));
|
|
360
|
-
}
|
|
361
|
-
function limitRoomPreviewsPerRun(previews, limitPerRun) {
|
|
362
|
-
if (!Number.isFinite(limitPerRun))
|
|
363
|
-
return previews;
|
|
364
|
-
const limit = Math.max(0, Number(limitPerRun));
|
|
365
|
-
const remainingByRun = new Map();
|
|
366
|
-
const keep = new Set();
|
|
367
|
-
for (let index = previews.length - 1; index >= 0; index -= 1) {
|
|
368
|
-
const preview = previews[index];
|
|
369
|
-
if (preview.channel !== "room") {
|
|
370
|
-
keep.add(preview);
|
|
371
|
-
continue;
|
|
372
|
-
}
|
|
373
|
-
const remaining = remainingByRun.get(preview.run) ?? limit;
|
|
374
|
-
if (remaining <= 0) {
|
|
375
|
-
remainingByRun.set(preview.run, 0);
|
|
376
|
-
continue;
|
|
377
|
-
}
|
|
378
|
-
keep.add(preview);
|
|
379
|
-
remainingByRun.set(preview.run, remaining - 1);
|
|
380
|
-
}
|
|
381
|
-
return previews.filter((preview) => keep.has(preview));
|
|
382
|
-
}
|
|
383
|
-
export function readActorInspectorPreviews(stateRoot = Paths.getRunStateRoot(), limit = 8, options = {}) {
|
|
384
|
-
try {
|
|
385
|
-
const previews = fs
|
|
386
|
-
.readdirSync(stateRoot, { withFileTypes: true })
|
|
387
|
-
.filter((entry) => entry.isDirectory())
|
|
388
|
-
.flatMap((entry) => {
|
|
389
|
-
const stateDir = path.join(stateRoot, entry.name);
|
|
390
|
-
if (!matchesOwner(stateDir, options.ownerId))
|
|
391
|
-
return [];
|
|
392
|
-
if (options.run && entry.name !== options.run)
|
|
393
|
-
return [];
|
|
394
|
-
return [
|
|
395
|
-
...readRoomPreviews(entry.name, stateDir),
|
|
396
|
-
...readInboxPreviews(entry.name, stateDir),
|
|
397
|
-
...readBranchInboxPreviews(entry.name, stateDir),
|
|
398
|
-
...readOutboxPreviews(entry.name, stateDir),
|
|
399
|
-
];
|
|
400
|
-
})
|
|
401
|
-
.filter((preview) => preview.timestamp)
|
|
402
|
-
.sort((a, b) => a.timestamp.localeCompare(b.timestamp));
|
|
403
|
-
const currentRun = options.currentRunOnly
|
|
404
|
-
? previews.at(-1)?.run
|
|
405
|
-
: undefined;
|
|
406
|
-
const sequenced = previews
|
|
407
|
-
.filter((preview) => !currentRun || preview.run === currentRun)
|
|
408
|
-
.filter((preview) => matchesPreviewFilter(preview, options))
|
|
409
|
-
.map((preview, index) => ({
|
|
410
|
-
...preview,
|
|
411
|
-
sequence: index + 1,
|
|
412
|
-
stripe: index % 2 === 1,
|
|
413
|
-
}));
|
|
414
|
-
return limitRoomPreviewsPerRun(sequenced, options.roomLimitPerRun).slice(-Math.max(1, limit));
|
|
415
|
-
}
|
|
416
|
-
catch (error) {
|
|
417
|
-
if (error.code === "ENOENT")
|
|
418
|
-
return [];
|
|
419
|
-
return [];
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
function shorten(value, maxLength, options = { preserveSpaces: true }) {
|
|
423
|
-
if (!value)
|
|
424
|
-
return "-";
|
|
425
|
-
const compact = options.preserveSpaces === false
|
|
426
|
-
? value.replaceAll(/\s+/g, "_")
|
|
427
|
-
: value.replaceAll(/\s+/g, " ").trim();
|
|
428
|
-
if (maxLength <= 1)
|
|
429
|
-
return compact.slice(0, Math.max(0, maxLength));
|
|
430
|
-
return compact.length > maxLength
|
|
431
|
-
? `${compact.slice(0, Math.max(0, maxLength - 1))}…`
|
|
432
|
-
: compact;
|
|
433
|
-
}
|
|
434
|
-
function actorName(address) {
|
|
435
|
-
if (!address)
|
|
436
|
-
return "unknown";
|
|
437
|
-
const branch = /^branch:[^/]+\/(.+)$/.exec(address);
|
|
438
|
-
if (branch)
|
|
439
|
-
return branch[1] || address;
|
|
440
|
-
const run = /^run:(.+)$/.exec(address);
|
|
441
|
-
if (run)
|
|
442
|
-
return run[1] || address;
|
|
443
|
-
return address;
|
|
444
|
-
}
|
|
445
|
-
function roomName(address) {
|
|
446
|
-
const room = /^room:([^/]+)(?:\/(main))?$/.exec(address);
|
|
447
|
-
return room ? room[1] : undefined;
|
|
448
|
-
}
|
|
449
|
-
function routeActorText(preview) {
|
|
450
|
-
return preview.from_display || actorName(preview.from);
|
|
451
|
-
}
|
|
452
|
-
function routeText(preview) {
|
|
453
|
-
const actor = routeActorText(preview);
|
|
454
|
-
if (preview.channel === "room")
|
|
455
|
-
return `${actor} # all`;
|
|
456
|
-
if (preview.channel === "broadcast")
|
|
457
|
-
return `${actor} ⇢ ${preview.to}`;
|
|
458
|
-
return `${actor} → ${actorName(preview.to)}`;
|
|
459
|
-
}
|
|
460
|
-
function attentionMarker(preview) {
|
|
461
|
-
return preview.needs_response ? "! " : "";
|
|
462
|
-
}
|
|
463
|
-
function style(styleFn, text) {
|
|
464
|
-
return styleFn ? styleFn(text) : text;
|
|
465
|
-
}
|
|
466
|
-
function previewText(preview) {
|
|
467
|
-
return preview.summary || preview.body_preview || "-";
|
|
468
|
-
}
|
|
469
|
-
function propertyValue(value) {
|
|
470
|
-
if (value === undefined)
|
|
471
|
-
return "";
|
|
472
|
-
if (typeof value === "string")
|
|
473
|
-
return value;
|
|
474
|
-
if (typeof value === "number" || typeof value === "boolean")
|
|
475
|
-
return String(value);
|
|
476
|
-
return JSON.stringify(value);
|
|
477
|
-
}
|
|
478
|
-
function displayWidth(value) {
|
|
479
|
-
return visibleWidth(value);
|
|
480
|
-
}
|
|
481
|
-
const lineSegmenter = new Intl.Segmenter();
|
|
482
|
-
function boundedLine(value, width) {
|
|
483
|
-
if (width <= 0)
|
|
484
|
-
return "";
|
|
485
|
-
if (visibleWidth(value) <= width)
|
|
486
|
-
return value;
|
|
487
|
-
const ellipsis = "…";
|
|
488
|
-
const ellipsisWidth = visibleWidth(ellipsis);
|
|
489
|
-
if (width <= ellipsisWidth)
|
|
490
|
-
return ellipsis.slice(0, width);
|
|
491
|
-
let output = "";
|
|
492
|
-
let used = 0;
|
|
493
|
-
const maxTextWidth = width - ellipsisWidth;
|
|
494
|
-
for (const { segment } of lineSegmenter.segment(value)) {
|
|
495
|
-
const segmentWidth = visibleWidth(segment);
|
|
496
|
-
if (used + segmentWidth > maxTextWidth)
|
|
497
|
-
break;
|
|
498
|
-
output += segment;
|
|
499
|
-
used += segmentWidth;
|
|
500
|
-
}
|
|
501
|
-
return `${output}${ellipsis}`;
|
|
502
|
-
}
|
|
503
|
-
function padLine(plain, rendered, width, styles) {
|
|
504
|
-
const boundedPlain = boundedLine(plain, width);
|
|
505
|
-
const visible = boundedPlain === plain ? rendered : style(styles.preview, boundedPlain);
|
|
506
|
-
const padding = Math.max(0, width - visibleWidth(boundedPlain));
|
|
507
|
-
return `${visible}${" ".repeat(padding)}`;
|
|
508
|
-
}
|
|
509
|
-
function renderCompactInspectorEntry(preview, width, sequenceWidth, routeWidth, typeWidth, styles, stripe) {
|
|
510
|
-
const separator = " ";
|
|
511
|
-
const prefix = " ";
|
|
512
|
-
const suffix = " ";
|
|
513
|
-
const contentWidth = Math.max(8, width - prefix.length - suffix.length);
|
|
514
|
-
const sequence = String(preview.sequence ?? 0).padStart(sequenceWidth, " ");
|
|
515
|
-
const sequencePrefix = `${sequence}${separator}`;
|
|
516
|
-
const route = `${attentionMarker(preview)}${routeText(preview)}`;
|
|
517
|
-
const routePadding = " ".repeat(Math.max(0, routeWidth - displayWidth(route)));
|
|
518
|
-
const typePadding = " ".repeat(Math.max(0, typeWidth - displayWidth(preview.type)));
|
|
519
|
-
const headline = previewText(preview);
|
|
520
|
-
const lead = `${sequencePrefix}${route}${routePadding}${separator}${preview.type}${typePadding}${separator}`;
|
|
521
|
-
const visibleHeadline = boundedLine(headline, Math.max(0, contentWidth - displayWidth(lead)));
|
|
522
|
-
const plain = `${lead}${visibleHeadline}`;
|
|
523
|
-
const rendered = [
|
|
524
|
-
style(styles.muted, sequencePrefix),
|
|
525
|
-
style(styles.target, route),
|
|
526
|
-
routePadding,
|
|
527
|
-
separator,
|
|
528
|
-
style(styles.type, preview.type),
|
|
529
|
-
typePadding,
|
|
530
|
-
separator,
|
|
531
|
-
style(styles.preview, visibleHeadline),
|
|
532
|
-
].join("");
|
|
533
|
-
const line = `${prefix}${padLine(plain, rendered, contentWidth, styles)}${suffix}`;
|
|
534
|
-
if (stripe && styles.stripe)
|
|
535
|
-
return [styles.stripe(line)];
|
|
536
|
-
if (!stripe && styles.stripeAlt)
|
|
537
|
-
return [styles.stripeAlt(line)];
|
|
538
|
-
return [line];
|
|
539
|
-
}
|
|
540
|
-
function renderInspectorEntry(preview, width, sequenceWidth, routeWidth, typeWidth, summaryWidth, styles, stripe) {
|
|
541
|
-
const separator = " ";
|
|
542
|
-
const prefix = " ";
|
|
543
|
-
const suffix = " ";
|
|
544
|
-
const contentWidth = Math.max(8, width - prefix.length - suffix.length);
|
|
545
|
-
const sequence = String(preview.sequence ?? 0).padStart(sequenceWidth, " ");
|
|
546
|
-
const sequencePrefix = `${sequence}${separator}`;
|
|
547
|
-
const route = `${attentionMarker(preview)}${routeText(preview)}`;
|
|
548
|
-
const type = preview.type;
|
|
549
|
-
const summary = preview.summary?.trim() ?? "";
|
|
550
|
-
const body = preview.body_preview?.trim() || (!summary ? previewText(preview) : "-");
|
|
551
|
-
const visibleRoute = boundedLine(route, routeWidth);
|
|
552
|
-
const visibleType = boundedLine(type, typeWidth);
|
|
553
|
-
const boundedRoutePadding = " ".repeat(Math.max(0, routeWidth - displayWidth(visibleRoute)));
|
|
554
|
-
const boundedTypePadding = " ".repeat(Math.max(0, typeWidth - displayWidth(visibleType)));
|
|
555
|
-
const leadParts = [
|
|
556
|
-
style(styles.muted, sequencePrefix),
|
|
557
|
-
style(styles.target, visibleRoute),
|
|
558
|
-
boundedRoutePadding,
|
|
559
|
-
separator,
|
|
560
|
-
style(styles.type, visibleType),
|
|
561
|
-
boundedTypePadding,
|
|
562
|
-
separator,
|
|
563
|
-
];
|
|
564
|
-
let lead = `${sequencePrefix}${visibleRoute}${boundedRoutePadding}${separator}${visibleType}${boundedTypePadding}${separator}`;
|
|
565
|
-
if (summary) {
|
|
566
|
-
const visibleSummary = boundedLine(summary, summaryWidth);
|
|
567
|
-
const summaryPadding = " ".repeat(Math.max(0, summaryWidth - displayWidth(visibleSummary)));
|
|
568
|
-
lead += `${visibleSummary}${summaryPadding}${separator}`;
|
|
569
|
-
leadParts.push(style(styles.preview, visibleSummary), summaryPadding, separator);
|
|
570
|
-
}
|
|
571
|
-
const visibleBody = boundedLine(body, Math.max(0, contentWidth - displayWidth(lead)));
|
|
572
|
-
const plain = `${lead}${visibleBody}`;
|
|
573
|
-
const rendered = `${leadParts.join("")}${style(styles.preview, visibleBody)}`;
|
|
574
|
-
const line = `${prefix}${padLine(plain, rendered, contentWidth, styles)}${suffix}`;
|
|
575
|
-
if (stripe && styles.stripe)
|
|
576
|
-
return [styles.stripe(line)];
|
|
577
|
-
if (!stripe && styles.stripeAlt)
|
|
578
|
-
return [styles.stripeAlt(line)];
|
|
579
|
-
return [line];
|
|
580
|
-
}
|
|
581
|
-
export function readActorInspectorRoster(stateRoot = Paths.getRunStateRoot(), run, room = "main") {
|
|
582
|
-
const stateDir = path.join(stateRoot, run);
|
|
583
|
-
const roster = readRoomRosterRecords(stateDir, room);
|
|
584
|
-
return Object.entries(roster).map(([address, member]) => ({
|
|
585
|
-
address,
|
|
586
|
-
...(memberDisplay(address, member)
|
|
587
|
-
? { display: memberDisplay(address, member) }
|
|
588
|
-
: {}),
|
|
589
|
-
...(typeof member.role === "string" ? { role: member.role } : {}),
|
|
590
|
-
...(typeof member.status === "string" ? { status: member.status } : {}),
|
|
591
|
-
}));
|
|
592
|
-
}
|
|
593
|
-
function rosterRoleText(role) {
|
|
594
|
-
const roleLabel = role?.split(";")[0] ?? "";
|
|
595
|
-
const cleaned = roleLabel
|
|
596
|
-
.replaceAll(/\s*\([^)]*\)\s*$/g, "")
|
|
597
|
-
.trim()
|
|
598
|
-
.toLowerCase();
|
|
599
|
-
if (!cleaned || cleaned === "actor")
|
|
600
|
-
return undefined;
|
|
601
|
-
return cleaned.replaceAll(/\s+/g, "-");
|
|
602
|
-
}
|
|
603
|
-
function rosterMemberText(member) {
|
|
604
|
-
const name = member.display || actorName(member.address);
|
|
605
|
-
const role = rosterRoleText(member.role);
|
|
606
|
-
if (role === "run")
|
|
607
|
-
return `run/${name}`;
|
|
608
|
-
return role ? `${name}/${role}` : name;
|
|
609
|
-
}
|
|
610
|
-
function isRosterMemberActive(member) {
|
|
611
|
-
const status = member.status?.trim().toLowerCase();
|
|
612
|
-
return (!status ||
|
|
613
|
-
status === "present" ||
|
|
614
|
-
status === "active" ||
|
|
615
|
-
status === "running");
|
|
616
|
-
}
|
|
617
|
-
export function renderInspectorRosterLine(members, width = 80, styles = {}) {
|
|
618
|
-
return renderInspectorRosterPanel(members, width, styles)?.[0];
|
|
619
|
-
}
|
|
620
|
-
export function renderInspectorRosterPanel(members, width = 80, styles = {}) {
|
|
621
|
-
if (members.length === 0)
|
|
622
|
-
return undefined;
|
|
623
|
-
const safeWidth = Math.max(1, width);
|
|
624
|
-
const innerWidth = Math.max(1, safeWidth - 2);
|
|
625
|
-
const prefix = `roster ${members.length}: `;
|
|
626
|
-
const tokens = members.map((member) => ({
|
|
627
|
-
active: isRosterMemberActive(member),
|
|
628
|
-
text: rosterMemberText(member),
|
|
629
|
-
}));
|
|
630
|
-
const lines = [];
|
|
631
|
-
let plain = prefix;
|
|
632
|
-
let rendered = style(styles.muted, prefix);
|
|
633
|
-
const flush = () => {
|
|
634
|
-
const visible = boundedLine(plain, innerWidth);
|
|
635
|
-
const line = visible === plain ? rendered : style(styles.muted, visible);
|
|
636
|
-
lines.push(` ${line}${" ".repeat(Math.max(0, innerWidth - displayWidth(visible)))} `);
|
|
637
|
-
};
|
|
638
|
-
for (const token of tokens) {
|
|
639
|
-
const separator = plain === prefix ? "" : ", ";
|
|
640
|
-
const nextPlain = `${plain}${separator}${token.text}`;
|
|
641
|
-
const renderedToken = style(token.active ? styles.target : styles.muted, token.text);
|
|
642
|
-
if (plain !== prefix && displayWidth(nextPlain) > innerWidth) {
|
|
643
|
-
flush();
|
|
644
|
-
plain = ` ${token.text}`;
|
|
645
|
-
rendered = `${style(styles.muted, " ")}${renderedToken}`;
|
|
646
|
-
continue;
|
|
647
|
-
}
|
|
648
|
-
plain = nextPlain;
|
|
649
|
-
rendered = `${rendered}${style(styles.muted, separator)}${renderedToken}`;
|
|
650
|
-
}
|
|
651
|
-
flush();
|
|
652
|
-
return lines;
|
|
653
|
-
}
|
|
654
|
-
export function renderInspectorItemView(previews, width = 80, styles = {}, options) {
|
|
655
|
-
const preview = previews.find((item) => item.sequence === options.sequence);
|
|
656
|
-
if (!preview)
|
|
657
|
-
return undefined;
|
|
658
|
-
const safeWidth = Math.max(1, width);
|
|
659
|
-
const prefix = " ";
|
|
660
|
-
const suffix = " ";
|
|
661
|
-
const contentWidth = Math.max(8, safeWidth - prefix.length - suffix.length);
|
|
662
|
-
const rawEntries = [
|
|
663
|
-
["channel", preview.channel],
|
|
664
|
-
["run", preview.run],
|
|
665
|
-
["event_id", preview.event_id],
|
|
666
|
-
["from", preview.from],
|
|
667
|
-
["from_display", preview.from_display],
|
|
668
|
-
["to", preview.to],
|
|
669
|
-
["type", preview.type],
|
|
670
|
-
["summary", preview.summary],
|
|
671
|
-
["body", preview.body_preview],
|
|
672
|
-
["message_id", preview.message_id],
|
|
673
|
-
["needs_response", preview.needs_response],
|
|
674
|
-
["timestamp", preview.timestamp],
|
|
675
|
-
["stripe", preview.stripe],
|
|
676
|
-
];
|
|
677
|
-
const entries = rawEntries
|
|
678
|
-
.filter((entry) => entry[1] !== undefined)
|
|
679
|
-
.map(([key, value]) => [key, propertyValue(value)]);
|
|
680
|
-
const keyWidth = Math.max(1, ...entries.map(([key]) => displayWidth(key)));
|
|
681
|
-
const sequenceText = String(preview.sequence ?? options.sequence);
|
|
682
|
-
const sequencePadding = " ".repeat(Math.max(0, keyWidth - displayWidth(sequenceText)));
|
|
683
|
-
const headerSeparator = " ";
|
|
684
|
-
const route = routeText(preview);
|
|
685
|
-
const visibleRoute = boundedLine(route, Math.max(0, contentWidth - keyWidth - headerSeparator.length));
|
|
686
|
-
const headerPlain = `${sequenceText}${sequencePadding}${headerSeparator}${visibleRoute}`;
|
|
687
|
-
const header = `${style(styles.muted, sequenceText)}${sequencePadding}${headerSeparator}${style(styles.target, visibleRoute)}`;
|
|
688
|
-
const headerPadding = Math.max(0, contentWidth - visibleWidth(headerPlain));
|
|
689
|
-
const lines = [`${prefix}${header}${" ".repeat(headerPadding)}${suffix}`, ""];
|
|
690
|
-
for (const [key, value] of entries) {
|
|
691
|
-
const keyPadding = " ".repeat(Math.max(0, keyWidth - displayWidth(key)));
|
|
692
|
-
const separator = " ";
|
|
693
|
-
const valueWidth = Math.max(0, contentWidth - keyWidth - separator.length);
|
|
694
|
-
const visibleValue = boundedLine(value, valueWidth);
|
|
695
|
-
const plain = `${key}${keyPadding}${separator}${visibleValue}`;
|
|
696
|
-
const rendered = `${style(styles.muted, key)}${keyPadding}${separator}${style(styles.preview, visibleValue)}`;
|
|
697
|
-
const padding = Math.max(0, contentWidth - visibleWidth(plain));
|
|
698
|
-
lines.push(`${prefix}${rendered}${" ".repeat(padding)}${suffix}`);
|
|
699
|
-
}
|
|
700
|
-
return lines;
|
|
701
|
-
}
|
|
702
|
-
export function renderInspectorWidget(previews, width = 80, styles = {}, options = {}) {
|
|
703
|
-
if (previews.length === 0)
|
|
704
|
-
return undefined;
|
|
705
|
-
const safeWidth = Math.max(1, width);
|
|
706
|
-
void options;
|
|
707
|
-
const visible = previews.map((preview, index) => ({
|
|
708
|
-
preview: { ...preview, sequence: preview.sequence ?? index + 1 },
|
|
709
|
-
stripe: preview.stripe ?? index % 2 === 1,
|
|
710
|
-
}));
|
|
711
|
-
const sequenceWidth = Math.max(1, ...visible.map(({ preview }) => String(preview.sequence ?? 0).length));
|
|
712
|
-
const lines = [];
|
|
713
|
-
const separatorWidth = 2;
|
|
714
|
-
const sequencePrefixWidth = sequenceWidth + separatorWidth;
|
|
715
|
-
const fixedSeparatorsWidth = separatorWidth * 3;
|
|
716
|
-
const availableForColumns = Math.max(0, safeWidth - 1 - sequencePrefixWidth - fixedSeparatorsWidth);
|
|
717
|
-
const naturalRouteWidth = Math.max(...visible.map(({ preview }) => displayWidth(`${attentionMarker(preview)}${routeText(preview)}`)));
|
|
718
|
-
const naturalTypeWidth = Math.max(...visible.map(({ preview }) => displayWidth(preview.type)));
|
|
719
|
-
const routeWidth = Math.min(naturalRouteWidth, Math.max(4, Math.floor(availableForColumns * 0.35)));
|
|
720
|
-
const typeWidth = Math.min(naturalTypeWidth, Math.max(4, Math.floor(availableForColumns * 0.25)));
|
|
721
|
-
const messageWidth = Math.max(0, availableForColumns - routeWidth - typeWidth);
|
|
722
|
-
const summaryWidths = visible
|
|
723
|
-
.map(({ preview }) => preview.summary?.trim())
|
|
724
|
-
.filter((summary) => Boolean(summary))
|
|
725
|
-
.map((summary) => displayWidth(summary));
|
|
726
|
-
const summaryWidth = summaryWidths.length
|
|
727
|
-
? Math.min(Math.max(...summaryWidths), Math.max(1, Math.floor(messageWidth * 0.5)))
|
|
728
|
-
: 0;
|
|
729
|
-
for (const { preview, stripe } of visible) {
|
|
730
|
-
lines.push(...renderInspectorEntry(preview, safeWidth, sequenceWidth, routeWidth, typeWidth, summaryWidth, styles, stripe));
|
|
731
|
-
}
|
|
732
|
-
return lines;
|
|
733
|
-
}
|