pi-better-server 0.5.0 → 0.6.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/package.json +4 -1
- package/scripts/copy-pi-test-providers.mjs +10 -0
- package/scripts/event-publication/README.md +26 -0
- package/scripts/event-publication/commit.mjs +21 -0
- package/scripts/event-publication/measure.mjs +37 -5
- package/scripts/event-publication/writer.mjs +3 -8
- package/scripts/measure-full-runtime/probe.mjs +4 -2
- package/scripts/measure-full-runtime/recovery-trace-loader.mjs +51 -0
- package/scripts/measure-full-runtime/recovery-trace.mjs +16 -0
- package/scripts/measure-shared-reads.mjs +2 -1
- package/scripts/private-runtime/package-lock.json +18 -0
- package/scripts/private-runtime/package.json +4 -1
- package/scripts/source-provenance.mjs +2 -2
- package/scripts/test-on-pi.sh +2 -9
- package/src/handshake.ts +1 -1
- package/src/hosted-session.ts +32 -4
- package/src/maintenance.ts +35 -7
- package/src/registry.ts +28 -4
- package/src/runtime/attempt-invalidation.ts +54 -0
- package/src/runtime/background-history.ts +151 -45
- package/src/runtime/background-policy.ts +9 -4
- package/src/runtime/background-tools.ts +131 -23
- package/src/runtime/background.ts +351 -68
- package/src/runtime/cancellation.ts +28 -7
- package/src/runtime/catalog-sources.ts +199 -0
- package/src/runtime/catalog.ts +53 -21
- package/src/runtime/client.ts +22 -2
- package/src/runtime/domain/assignment-inbox.mjs +119 -0
- package/src/runtime/domain/assignment-observation.d.mts +1 -1
- package/src/runtime/domain/assignment-observation.mjs +43 -35
- package/src/runtime/domain/background/process-identity.mjs +20 -2
- package/src/runtime/domain/background/process.mjs +3 -3
- package/src/runtime/domain/background/registry.mjs +61 -3
- package/src/runtime/domain/background/types.mjs +1 -0
- package/src/runtime/domain/background-service/adapter-contract.domain.mjs +1 -1
- package/src/runtime/domain/background-service/adapter-contract.ts +1 -1
- package/src/runtime/domain/background-service/goal-provider.domain.mjs +35 -16
- package/src/runtime/domain/background-service/goal-provider.ts +31 -16
- package/src/runtime/domain/background-service/index.domain.mjs +6 -9
- package/src/runtime/domain/background-service/index.ts +6 -9
- package/src/runtime/domain/background-service/managed-authority.domain.mjs +6 -3
- package/src/runtime/domain/background-service/managed-authority.ts +5 -3
- package/src/runtime/domain/background-service/managed-client.domain.mjs +21 -7
- package/src/runtime/domain/background-service/managed-client.ts +20 -7
- package/src/runtime/domain/background-service/managed-frontend.domain.mjs +75 -17
- package/src/runtime/domain/background-service/managed-frontend.ts +62 -17
- package/src/runtime/domain/background-service/navigator-provider.domain.mjs +16 -5
- package/src/runtime/domain/background-service/navigator-provider.ts +15 -5
- package/src/runtime/domain/background-service/observed-wait-client.domain.mjs +6 -0
- package/src/runtime/domain/background-service/observed-wait-client.ts +10 -0
- package/src/runtime/domain/background-service/observed-waits.domain.mjs +170 -27
- package/src/runtime/domain/background-service/observed-waits.ts +154 -30
- package/src/runtime/domain/background-service/process-identity.domain.mjs +20 -2
- package/src/runtime/domain/background-service/process-identity.ts +18 -2
- package/src/runtime/domain/background-service/process.domain.mjs +3 -3
- package/src/runtime/domain/background-service/process.ts +3 -3
- package/src/runtime/domain/background-service/registry.domain.mjs +61 -3
- package/src/runtime/domain/background-service/registry.ts +53 -5
- package/src/runtime/domain/background-service/runtime.domain.mjs +32 -16
- package/src/runtime/domain/background-service/runtime.ts +19 -9
- package/src/runtime/domain/background-service/sandbox.domain.mjs +14 -15
- package/src/runtime/domain/background-service/sandbox.ts +14 -11
- package/src/runtime/domain/background-service/shared-callback-batcher.domain.mjs +8 -1
- package/src/runtime/domain/background-service/shared-callback-batcher.ts +11 -2
- package/src/runtime/domain/background-service/shared-navigator-panels.domain.mjs +24 -2
- package/src/runtime/domain/background-service/shared-navigator-panels.ts +26 -4
- package/src/runtime/domain/background-service/shared-navigator.domain.mjs +218 -13
- package/src/runtime/domain/background-service/shared-navigator.ts +197 -14
- package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/assignment-observation.mjs +53 -41
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-changes.ts +73 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/assignment-outcomes.ts +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.domain.mjs +11 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/background-requests.ts +14 -3
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.domain.mjs +4 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/discovery.ts +5 -3
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.domain.mjs +44 -4
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/operations.ts +50 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.domain.mjs +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/result-supervision.ts +12 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.domain.mjs +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/rows.ts +2 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +42 -21
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +40 -24
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +21 -3
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +34 -8
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.domain.mjs +23 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/subagent-launch.ts +24 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.domain.mjs +1 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/types.ts +5 -1
- package/src/runtime/domain/background-service/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/background-service/shared-work-client.mjs +174 -7
- package/src/runtime/domain/background-service/supervisor/generated/process-identity.mjs +20 -2
- package/src/runtime/domain/background-service/supervisor/generated/process.mjs +3 -3
- package/src/runtime/domain/background-service/task-diagnostics.domain.mjs +1 -1
- package/src/runtime/domain/background-service/task-diagnostics.ts +1 -1
- package/src/runtime/domain/background-service/tools.domain.mjs +31 -24
- package/src/runtime/domain/background-service/tools.ts +41 -38
- package/src/runtime/domain/background-service/types.domain.mjs +1 -0
- package/src/runtime/domain/background-service/types.ts +3 -1
- package/src/runtime/domain/background-service/work-observation.domain.mjs +46 -20
- package/src/runtime/domain/background-service/work-observation.ts +46 -19
- package/src/runtime/domain/catalog/catalog-store.d.mts +9 -1
- package/src/runtime/domain/catalog/catalog-store.mjs +20 -22
- package/src/runtime/domain/coordinator/src/assignment-changes.mjs +75 -0
- package/src/runtime/domain/coordinator/src/assignment-outcomes.mjs +2 -0
- package/src/runtime/domain/coordinator/src/background-requests.mjs +11 -2
- package/src/runtime/domain/coordinator/src/discovery.mjs +4 -2
- package/src/runtime/domain/coordinator/src/operations.mjs +44 -4
- package/src/runtime/domain/coordinator/src/result-supervision.mjs +12 -0
- package/src/runtime/domain/coordinator/src/rows.mjs +2 -0
- package/src/runtime/domain/coordinator/src/schema.mjs +42 -21
- package/src/runtime/domain/coordinator/src/store.mjs +21 -3
- package/src/runtime/domain/coordinator/src/subagent-launch.mjs +23 -1
- package/src/runtime/domain/coordinator/src/types.mjs +1 -1
- package/src/runtime/domain/health-observation.d.mts +3 -1
- package/src/runtime/domain/health-observation.mjs +189 -190
- package/src/runtime/domain/log-cursor.d.mts +2 -0
- package/src/runtime/domain/log-cursor.mjs +85 -16
- package/src/runtime/domain/parse.d.mts +4 -1
- package/src/runtime/domain/parse.mjs +50 -5
- package/src/runtime/domain/sandbox-policy/README.md +61 -63
- package/src/runtime/domain/sandbox-policy/commands.domain.mjs +11 -8
- package/src/runtime/domain/sandbox-policy/commands.ts +12 -7
- package/src/runtime/domain/sandbox-policy/index.domain.mjs +53 -9
- package/src/runtime/domain/sandbox-policy/index.ts +52 -9
- package/src/runtime/domain/sandbox-policy/package.json +1 -1
- package/src/runtime/domain/sandbox-policy/permission-settings.domain.mjs +5 -2
- package/src/runtime/domain/sandbox-policy/permission-settings.ts +9 -2
- package/src/runtime/domain/sandbox-policy/permissions-page.domain.mjs +56 -137
- package/src/runtime/domain/sandbox-policy/permissions-page.ts +52 -130
- package/src/runtime/domain/sandbox-policy/permissions.domain.mjs +1 -6
- package/src/runtime/domain/sandbox-policy/permissions.ts +1 -6
- package/src/runtime/domain/sandbox-policy/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/sandbox-policy/shared-task-exec.domain.mjs +14 -1
- package/src/runtime/domain/sandbox-policy/shared-task-exec.ts +12 -1
- package/src/runtime/domain/sandbox-policy/shared-task-process-identity.domain.mjs +140 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-identity.ts +126 -0
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.domain.mjs +3 -2
- package/src/runtime/domain/sandbox-policy/shared-task-process-list.ts +8 -2
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.domain.mjs +4 -3
- package/src/runtime/domain/sandbox-policy/shared-task-sandbox.ts +5 -3
- package/src/runtime/domain/sandbox-policy/shared-task-tools.domain.mjs +8 -5
- package/src/runtime/domain/sandbox-policy/shared-task-tools.ts +8 -5
- package/src/runtime/domain/subagents/README.md +1 -1
- package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +12 -6
- package/src/runtime/domain/subagents/assignment-outcomes.ts +11 -5
- package/src/runtime/domain/subagents/assignment-report.domain.mjs +87 -24
- package/src/runtime/domain/subagents/assignment-report.ts +83 -19
- package/src/runtime/domain/subagents/catalog-host-admission.domain.mjs +21 -3
- package/src/runtime/domain/subagents/catalog-host-admission.ts +19 -3
- package/src/runtime/domain/subagents/catalog-preferences.ts +1 -1
- package/src/runtime/domain/subagents/catalog-resolver.domain.mjs +35 -1
- package/src/runtime/domain/subagents/catalog-resolver.ts +35 -1
- package/src/runtime/domain/subagents/catalog-store.domain.mjs +20 -22
- package/src/runtime/domain/subagents/catalog-store.ts +27 -20
- package/src/runtime/domain/subagents/child-apply-patch.domain.mjs +13 -0
- package/src/runtime/domain/subagents/child-apply-patch.ts +13 -0
- package/src/runtime/domain/subagents/child-dependencies.mjs +27 -15
- package/src/runtime/domain/subagents/child-operations.domain.mjs +80 -2
- package/src/runtime/domain/subagents/child-operations.ts +80 -1
- package/src/runtime/domain/subagents/child-preflight.mjs +9 -2
- package/src/runtime/domain/subagents/child-process-list.domain.mjs +7 -0
- package/src/runtime/domain/subagents/child-process-list.ts +8 -0
- package/src/runtime/domain/subagents/config.domain.mjs +49 -2
- package/src/runtime/domain/subagents/config.ts +46 -2
- package/src/runtime/domain/subagents/continuation-authority.domain.mjs +5 -1
- package/src/runtime/domain/subagents/continuation-authority.ts +3 -1
- package/src/runtime/domain/subagents/continuation-runtime.domain.mjs +89 -0
- package/src/runtime/domain/subagents/continuation-runtime.ts +88 -0
- package/src/runtime/domain/subagents/extensions.mjs +11 -13
- package/src/runtime/domain/subagents/finalization.domain.mjs +12 -0
- package/src/runtime/domain/subagents/finalization.ts +15 -0
- package/src/runtime/domain/subagents/goal-provider.domain.mjs +44 -2
- package/src/runtime/domain/subagents/goal-provider.ts +44 -2
- package/src/runtime/domain/subagents/health-observation.domain.mjs +189 -190
- package/src/runtime/domain/subagents/health-observation.ts +43 -48
- package/src/runtime/domain/subagents/index.domain.mjs +296 -123
- package/src/runtime/domain/subagents/index.ts +257 -98
- package/src/runtime/domain/subagents/launch-context.domain.mjs +24 -0
- package/src/runtime/domain/subagents/launch-context.ts +23 -0
- package/src/runtime/domain/subagents/launch-digest.mjs +6 -0
- package/src/runtime/domain/subagents/log-cursor.domain.mjs +85 -16
- package/src/runtime/domain/subagents/log-cursor.ts +91 -15
- package/src/runtime/domain/subagents/managed-launch-bootstrap.mjs +2 -2
- package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +6 -3
- package/src/runtime/domain/subagents/managed-launch-client.ts +6 -3
- package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +222 -14
- package/src/runtime/domain/subagents/managed-launch-host.ts +168 -15
- package/src/runtime/domain/subagents/managed-launch-journal.mjs +1 -5
- package/src/runtime/domain/subagents/managed-launch-port.ts +4 -0
- package/src/runtime/domain/subagents/operation-bridge-types.domain.mjs +27 -2
- package/src/runtime/domain/subagents/operation-bridge-types.ts +27 -2
- package/src/runtime/domain/subagents/owned-exit.domain.mjs +12 -0
- package/src/runtime/domain/subagents/owned-exit.ts +12 -0
- package/src/runtime/domain/subagents/package.json +1 -1
- package/src/runtime/domain/subagents/parse.domain.mjs +50 -5
- package/src/runtime/domain/subagents/parse.ts +48 -6
- package/src/runtime/domain/subagents/permission-policy.domain.mjs +32 -8
- package/src/runtime/domain/subagents/permission-policy.ts +41 -8
- package/src/runtime/domain/subagents/process-identity.mjs +33 -0
- package/src/runtime/domain/subagents/registry.domain.mjs +47 -33
- package/src/runtime/domain/subagents/registry.ts +54 -33
- package/src/runtime/domain/subagents/shared-callback-batcher.domain.mjs +8 -1
- package/src/runtime/domain/subagents/shared-callback-batcher.ts +11 -2
- package/src/runtime/domain/subagents/shared-catalog.domain.mjs +6 -23
- package/src/runtime/domain/subagents/shared-catalog.ts +6 -14
- package/src/runtime/domain/subagents/shared-navigator-panels.domain.mjs +24 -2
- package/src/runtime/domain/subagents/shared-navigator-panels.ts +26 -4
- package/src/runtime/domain/subagents/shared-navigator.domain.mjs +218 -13
- package/src/runtime/domain/subagents/shared-navigator.ts +197 -14
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-inbox.mjs +144 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/assignment-observation.mjs +53 -41
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.domain.mjs +75 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-changes.ts +73 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.domain.mjs +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/assignment-outcomes.ts +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.domain.mjs +11 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/background-requests.ts +14 -3
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.domain.mjs +4 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/discovery.ts +5 -3
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.domain.mjs +44 -4
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/operations.ts +50 -2
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.domain.mjs +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/result-supervision.ts +12 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.domain.mjs +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/rows.ts +2 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +42 -21
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +40 -24
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +21 -3
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +34 -8
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.domain.mjs +23 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/subagent-launch.ts +24 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.domain.mjs +1 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/types.ts +5 -1
- package/src/runtime/domain/subagents/shared-sandbox-core.ts +1 -1
- package/src/runtime/domain/subagents/shared-task-exec.domain.mjs +14 -1
- package/src/runtime/domain/subagents/shared-task-exec.ts +12 -1
- package/src/runtime/domain/subagents/shared-task-process-identity.domain.mjs +140 -0
- package/src/runtime/domain/subagents/shared-task-process-identity.ts +126 -0
- package/src/runtime/domain/subagents/shared-task-process-list.domain.mjs +3 -2
- package/src/runtime/domain/subagents/shared-task-process-list.ts +8 -2
- package/src/runtime/domain/subagents/shared-task-sandbox.domain.mjs +4 -3
- package/src/runtime/domain/subagents/shared-task-sandbox.ts +5 -3
- package/src/runtime/domain/subagents/shared-task-tools.domain.mjs +8 -5
- package/src/runtime/domain/subagents/shared-task-tools.ts +8 -5
- package/src/runtime/domain/subagents/shared-work-client.mjs +174 -7
- package/src/runtime/domain/subagents/subagent-tools.domain.mjs +22 -38
- package/src/runtime/domain/subagents/subagent-tools.ts +28 -34
- package/src/runtime/domain/subagents/task-policy.domain.mjs +1 -1
- package/src/runtime/domain/subagents/task-policy.ts +3 -1
- package/src/runtime/domain/subagents/timing.domain.mjs +10 -1
- package/src/runtime/domain/subagents/timing.ts +10 -1
- package/src/runtime/domain/subagents/work-observation.domain.mjs +77 -16
- package/src/runtime/domain/subagents/work-observation.ts +71 -16
- package/src/runtime/domain/subagents/worker-operations-host.domain.mjs +9 -4
- package/src/runtime/domain/subagents/worker-operations-host.ts +12 -4
- package/src/runtime/domain/subagents/worker-waits.domain.mjs +89 -35
- package/src/runtime/domain/subagents/worker-waits.ts +93 -34
- package/src/runtime/health-config.ts +27 -11
- package/src/runtime/log-checkpoints.ts +117 -0
- package/src/runtime/mutation-store.ts +5 -4
- package/src/runtime/queries.ts +25 -2
- package/src/runtime/query-executor.ts +149 -28
- package/src/runtime/query-worker.mjs +106 -21
- package/src/runtime/read-model.ts +846 -120
- package/src/runtime/read-watchdog-probe.ts +4 -0
- package/src/runtime/result-supervision.ts +188 -16
- package/src/runtime/source-watch.ts +175 -0
- package/src/runtime/subagent-launch.ts +11 -4
- package/src/runtime/work-budget.ts +130 -0
- package/src/runtime/work-client.d.mts +8 -0
- package/src/runtime/work-client.mjs +150 -7
- package/src/server.ts +104 -23
- package/src/session-activity.ts +26 -4
- package/src/version.ts +1 -1
|
@@ -1,11 +1,97 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-subagents/shared-navigator.ts. Do not edit directly.
|
|
2
2
|
import { truncateToWidth as piTruncateToWidth, visibleWidth as piVisibleWidth } from "@earendil-works/pi-tui";
|
|
3
|
+
import { readHarnessSetting, updateHarnessSetting } from "./shared-harness-settings.domain.mjs";
|
|
3
4
|
import { createRenderScheduler } from "./shared-render-scheduler.domain.mjs";
|
|
4
5
|
import { setNavigatorPanel } from "./shared-navigator-panels.domain.mjs";
|
|
5
6
|
export default function navigatorExtension() {
|
|
6
7
|
// Internal shared package. Pi may scan its symlink in the extension directory
|
|
7
8
|
// for sibling relative imports; loading it directly should be harmless.
|
|
8
9
|
}
|
|
10
|
+
export function getNavigatorView() { return state().view ?? "flatten"; }
|
|
11
|
+
export function loadNavigatorView() {
|
|
12
|
+
const value = readHarnessSetting("navigatorView");
|
|
13
|
+
state().view = value === "tree" ? "tree" : "flatten";
|
|
14
|
+
}
|
|
15
|
+
export function setNavigatorView(value) {
|
|
16
|
+
if (value !== "tree" && value !== "flatten")
|
|
17
|
+
throw new Error("View must be tree or flatten.");
|
|
18
|
+
updateHarnessSetting("navigatorView", () => value);
|
|
19
|
+
state().view = value;
|
|
20
|
+
refreshBackgroundWorkNavigator();
|
|
21
|
+
}
|
|
22
|
+
/** UI time is independent of worker time; repeated refreshes never renew it. */
|
|
23
|
+
export function createTerminalRowRetention(retentionMs = 30_000) {
|
|
24
|
+
const held = new Map();
|
|
25
|
+
const dismissed = new Set();
|
|
26
|
+
return {
|
|
27
|
+
clear() { held.clear(); dismissed.clear(); },
|
|
28
|
+
dismiss(id) { held.delete(id); dismissed.add(id); },
|
|
29
|
+
merge(rows, now) {
|
|
30
|
+
const result = [];
|
|
31
|
+
const present = new Set(rows.map(row => row.id));
|
|
32
|
+
for (const id of dismissed)
|
|
33
|
+
if (!present.has(id))
|
|
34
|
+
dismissed.delete(id);
|
|
35
|
+
for (const row of rows) {
|
|
36
|
+
if (dismissed.has(row.id))
|
|
37
|
+
continue;
|
|
38
|
+
const terminal = ["completed", "succeeded", "failed", "cancelled", "killed", "lost", "timed_out"].includes(row.status);
|
|
39
|
+
if (!terminal) {
|
|
40
|
+
held.delete(row.id);
|
|
41
|
+
result.push(row);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
let entry = held.get(row.id);
|
|
45
|
+
if (!entry) {
|
|
46
|
+
entry = { row, until: now + retentionMs };
|
|
47
|
+
held.set(row.id, entry);
|
|
48
|
+
}
|
|
49
|
+
entry.row = { ...row, expiresAt: entry.until };
|
|
50
|
+
if (now < entry.until)
|
|
51
|
+
result.push(entry.row);
|
|
52
|
+
}
|
|
53
|
+
for (const [id, entry] of held) {
|
|
54
|
+
if (present.has(id))
|
|
55
|
+
continue;
|
|
56
|
+
if (now < entry.until)
|
|
57
|
+
result.push(entry.row);
|
|
58
|
+
else
|
|
59
|
+
held.delete(id);
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** A frontend-only diagnostic, never an execution record or authority to retry. */
|
|
66
|
+
export async function observeNavigatorLaunch(ctx, providerId, key, name, launch) {
|
|
67
|
+
const scope = JSON.stringify([ctx.cwd, ctx.sessionManager?.getSessionId?.()]);
|
|
68
|
+
const report = (error) => {
|
|
69
|
+
const s = state();
|
|
70
|
+
if (!isNavigatorUiAvailable(s.uiCtx) || s.observationScope !== scope)
|
|
71
|
+
return;
|
|
72
|
+
const id = `launch-error-${key}`;
|
|
73
|
+
const primary = error instanceof Error ? error.message : String(error);
|
|
74
|
+
const failures = s.launchFailures ??= new Map();
|
|
75
|
+
const identity = rowKey(providerId, id);
|
|
76
|
+
failures.set(identity, { providerId, id, name, status: "failed", statusTone: "failed", kind: "launch-error", elapsed: "", primary,
|
|
77
|
+
secondary: "Launch failed or was not confirmed; inspect before retrying.", sortStartedAt: Date.now() });
|
|
78
|
+
// Diagnostics are session-local and bounded, including expired tombstones.
|
|
79
|
+
if (failures.size > 128)
|
|
80
|
+
failures.delete(failures.keys().next().value);
|
|
81
|
+
refreshBackgroundWorkNavigator();
|
|
82
|
+
};
|
|
83
|
+
try {
|
|
84
|
+
const result = await launch();
|
|
85
|
+
const response = result;
|
|
86
|
+
if (response?.isError)
|
|
87
|
+
report(response.content?.filter(item => item.type === "text").map(item => item.text).join("\n") || "Launch request failed");
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
report(error);
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
9
95
|
const GLOBAL_KEY = Symbol.for("pi-better-harness.navigator.state");
|
|
10
96
|
const FACTORY_MARK = "__piBetterHarnessNavigatorFactory";
|
|
11
97
|
const FACTORY_REFRESH = "__piBetterHarnessNavigatorRefresh";
|
|
@@ -96,6 +182,20 @@ export function ensureBackgroundWorkNavigator(ctx, deps, owner) {
|
|
|
96
182
|
if (!isNavigatorUiAvailable(ctx))
|
|
97
183
|
return;
|
|
98
184
|
const s = state();
|
|
185
|
+
if (s.view === undefined) {
|
|
186
|
+
try {
|
|
187
|
+
loadNavigatorView();
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
s.view = "flatten";
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const scope = JSON.stringify([ctx.cwd, ctx.sessionManager?.getSessionId?.()]);
|
|
194
|
+
if (s.observationScope !== scope) {
|
|
195
|
+
s.terminalRows?.clear();
|
|
196
|
+
s.launchFailures?.clear();
|
|
197
|
+
}
|
|
198
|
+
s.observationScope = scope;
|
|
99
199
|
s.uiCtx = ctx;
|
|
100
200
|
s.uiOwner = owner;
|
|
101
201
|
s.deps = {
|
|
@@ -142,6 +242,9 @@ export function disposeBackgroundWorkNavigator(ctx, owner) {
|
|
|
142
242
|
stopMainListWidget();
|
|
143
243
|
const activeCtx = ctx ?? s.uiCtx;
|
|
144
244
|
s.uiCtx = undefined;
|
|
245
|
+
s.terminalRows?.clear();
|
|
246
|
+
s.launchFailures?.clear();
|
|
247
|
+
s.observationScope = undefined;
|
|
145
248
|
s.uiOwner = undefined;
|
|
146
249
|
if (activeCtx && isNavigatorUiAvailable(activeCtx)) {
|
|
147
250
|
try {
|
|
@@ -243,7 +346,7 @@ function refreshMainListWidget() {
|
|
|
243
346
|
}
|
|
244
347
|
if (!s.mainListWidgetInstalled) {
|
|
245
348
|
try {
|
|
246
|
-
setNavigatorPanel(ctx, MAIN_LIST_WIDGET_KEY, (tui, theme) => createMainListWidget(tui, theme, deps), { placement: "aboveEditor" });
|
|
349
|
+
setNavigatorPanel(ctx, MAIN_LIST_WIDGET_KEY, (tui, theme, layout) => createMainListWidget(tui, theme, deps, layout), { placement: "aboveEditor" });
|
|
247
350
|
s.mainListWidgetInstalled = true;
|
|
248
351
|
}
|
|
249
352
|
catch { /* ignore */ }
|
|
@@ -301,7 +404,7 @@ function createPointerNavigation(targetAt, activate) {
|
|
|
301
404
|
},
|
|
302
405
|
};
|
|
303
406
|
}
|
|
304
|
-
function createMainListWidget(tui, theme, deps) {
|
|
407
|
+
function createMainListWidget(tui, theme, deps, panelLayout = { availableRows: () => Infinity }) {
|
|
305
408
|
const requestRender = () => tui.requestRender?.();
|
|
306
409
|
state().mainListRequestRender = requestRender;
|
|
307
410
|
// navigatorId per rendered line, so a pointer row resolves by structure, never by row text.
|
|
@@ -339,8 +442,23 @@ function createMainListWidget(tui, theme, deps) {
|
|
|
339
442
|
}
|
|
340
443
|
lineWidth = renderWidth(width);
|
|
341
444
|
// The leading gap line belongs to the widget too, so its slot stays ownerless.
|
|
445
|
+
let rawLines = ["", ...layout.lines];
|
|
342
446
|
lineOwners = [undefined, ...layout.owners];
|
|
343
|
-
const
|
|
447
|
+
const budget = Math.max(0, Math.floor(panelLayout.availableRows()));
|
|
448
|
+
if (rawLines.length > budget) {
|
|
449
|
+
const selected = state().mainListFocused ? lineOwners.indexOf(state().mainListSelectedId) : -1;
|
|
450
|
+
const count = Math.max(0, budget - 1);
|
|
451
|
+
const start = selected >= 0 ? Math.max(0, Math.min(selected - Math.floor(count / 2), rawLines.length - count)) : 2;
|
|
452
|
+
rawLines = rawLines.slice(start, start + count);
|
|
453
|
+
lineOwners = lineOwners.slice(start, start + count);
|
|
454
|
+
const visible = new Set(lineOwners.filter(Boolean));
|
|
455
|
+
if (budget > 0) {
|
|
456
|
+
const hidden = rows.length - visible.size;
|
|
457
|
+
rawLines.push(deps.truncate(hidden ? ` +${hidden} tasks` : ` ${rows.length} tasks`, renderWidth(width)));
|
|
458
|
+
lineOwners.push(undefined);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
const lines = rawLines.map((line, index) => pointer.hovered && lineOwners[index] === pointer.hovered ? highlightPointerTarget(theme, line, lineWidth) : line);
|
|
344
462
|
state().lastMainListLines = lines;
|
|
345
463
|
return lines;
|
|
346
464
|
},
|
|
@@ -383,6 +501,12 @@ function listRows(now = Date.now()) {
|
|
|
383
501
|
catch {
|
|
384
502
|
providerRows = [];
|
|
385
503
|
}
|
|
504
|
+
providerRows = [...providerRows, ...[...(state().launchFailures?.values() ?? [])].filter(row => row.providerId === provider.id)];
|
|
505
|
+
const retention = state().terminalRows ??= new Map();
|
|
506
|
+
if (!retention.has(provider.id))
|
|
507
|
+
retention.set(provider.id, createTerminalRowRetention());
|
|
508
|
+
if (isNavigatorUiAvailable(state().uiCtx))
|
|
509
|
+
providerRows = retention.get(provider.id).merge(providerRows, now);
|
|
386
510
|
const orderedProviderRows = [...providerRows].sort((a, b) => b.sortStartedAt - a.sortStartedAt || rowDisplayName(a).localeCompare(rowDisplayName(b)));
|
|
387
511
|
let showSection = orderedProviderRows.length > 0 || provider.parentRow !== undefined;
|
|
388
512
|
try {
|
|
@@ -391,7 +515,7 @@ function listRows(now = Date.now()) {
|
|
|
391
515
|
catch {
|
|
392
516
|
showSection = false;
|
|
393
517
|
}
|
|
394
|
-
if (!showSection)
|
|
518
|
+
if (!showSection && !(getNavigatorView() === "tree" && provider.parentRow))
|
|
395
519
|
continue;
|
|
396
520
|
let parentRow = null;
|
|
397
521
|
try {
|
|
@@ -412,7 +536,51 @@ function listRows(now = Date.now()) {
|
|
|
412
536
|
rows.push({ ...row, navigatorId: rowKey(provider.id, row.id), providerLabel: provider.label });
|
|
413
537
|
}
|
|
414
538
|
}
|
|
415
|
-
|
|
539
|
+
const conversations = mergeAgentAttempts(rows);
|
|
540
|
+
return getNavigatorView() === "tree" ? treeRows(conversations) : conversations;
|
|
541
|
+
}
|
|
542
|
+
/** A resumed execution is still the same agent in either layout. */
|
|
543
|
+
export function mergeAgentAttempts(rows) {
|
|
544
|
+
const latest = new Map();
|
|
545
|
+
for (const row of rows) {
|
|
546
|
+
if (row.providerId !== "subagents" || !row.agentId)
|
|
547
|
+
continue;
|
|
548
|
+
const previous = latest.get(row.agentId);
|
|
549
|
+
if (!previous || row.sortStartedAt > previous.sortStartedAt
|
|
550
|
+
|| (row.sortStartedAt === previous.sortStartedAt && row.id > previous.id))
|
|
551
|
+
latest.set(row.agentId, row);
|
|
552
|
+
}
|
|
553
|
+
return rows.filter(row => row.providerId !== "subagents" || !row.agentId || latest.get(row.agentId) === row);
|
|
554
|
+
}
|
|
555
|
+
/** Two levels only: agents are peers, tasks attach by captured conversation. */
|
|
556
|
+
export function treeRows(rows) {
|
|
557
|
+
const agents = new Map();
|
|
558
|
+
for (const row of rows.filter(row => row.providerId === "subagents")) {
|
|
559
|
+
const key = row.agentId ?? row.id;
|
|
560
|
+
const prior = agents.get(key);
|
|
561
|
+
if (!prior || row.sortStartedAt > prior.sortStartedAt)
|
|
562
|
+
agents.set(key, row);
|
|
563
|
+
}
|
|
564
|
+
const tasks = rows.filter(row => row.providerId !== "subagents");
|
|
565
|
+
const ordered = [...agents.entries()].sort(([a], [b]) => a === "main" ? -1 : b === "main" ? 1 : 0);
|
|
566
|
+
const result = [], attached = new Set();
|
|
567
|
+
for (const [key, agent] of ordered) {
|
|
568
|
+
const children = tasks.filter(row => (row.parentAgentId ?? "main") === key);
|
|
569
|
+
result.push({ ...agent, treeDepth: 0 });
|
|
570
|
+
children.forEach((row, i) => { result.push({ ...row, treeDepth: 1, lastChild: i === children.length - 1 }); attached.add(row); });
|
|
571
|
+
}
|
|
572
|
+
// Never hide live work when its owner's observation has not arrived yet.
|
|
573
|
+
const missing = new Map();
|
|
574
|
+
for (const row of tasks)
|
|
575
|
+
if (!attached.has(row)) {
|
|
576
|
+
const key = row.parentAgentId ?? "main";
|
|
577
|
+
missing.set(key, [...(missing.get(key) ?? []), row]);
|
|
578
|
+
}
|
|
579
|
+
for (const [key, children] of missing)
|
|
580
|
+
children.forEach((row, i) => result.push({ ...row,
|
|
581
|
+
treeDepth: 1, lastChild: i === children.length - 1,
|
|
582
|
+
ownerGroupLabel: i === 0 ? (key === "main" ? "Main" : `Agent ${key} · not running`) : undefined }));
|
|
583
|
+
return result;
|
|
416
584
|
}
|
|
417
585
|
function rowDisplayName(row) {
|
|
418
586
|
return singleLine(row.name || row.id);
|
|
@@ -476,6 +644,17 @@ function buildMainListLayout(rows, width, truncate, fg, options = {}) {
|
|
|
476
644
|
lines.push(line);
|
|
477
645
|
owners.push(owner);
|
|
478
646
|
};
|
|
647
|
+
if (getNavigatorView() === "tree") {
|
|
648
|
+
push(providerGroupLabel("work", fg));
|
|
649
|
+
for (const row of rows) {
|
|
650
|
+
if (row.ownerGroupLabel)
|
|
651
|
+
push(` ${dim(row.ownerGroupLabel, fg)}`);
|
|
652
|
+
push(formatMainListRow(row, options.focused === true && row.navigatorId === options.selectedId, fg, width), row.navigatorId);
|
|
653
|
+
}
|
|
654
|
+
push("");
|
|
655
|
+
push(shortcutsLine(options.focused === true, fg));
|
|
656
|
+
return { lines: lines.map(line => safeTruncate(line, width, truncate)), owners };
|
|
657
|
+
}
|
|
479
658
|
const grouped = new Map();
|
|
480
659
|
for (const row of rows) {
|
|
481
660
|
const existing = grouped.get(row.providerLabel) ?? [];
|
|
@@ -502,8 +681,9 @@ function buildMainListLayout(rows, width, truncate, fg, options = {}) {
|
|
|
502
681
|
return { lines: lines.map((line) => safeTruncate(line, width, truncate)), owners };
|
|
503
682
|
}
|
|
504
683
|
function shortcutsLine(focused, fg) {
|
|
684
|
+
const selected = state().mainListRows?.find(row => row.navigatorId === state().mainListSelectedId);
|
|
505
685
|
const keys = focused
|
|
506
|
-
?
|
|
686
|
+
? `↑↓ switch · Enter detail${selected?.readOnly || selected?.parentRow ? "" : " · x stop"} · Esc unfocus`
|
|
507
687
|
: "← work navigator";
|
|
508
688
|
return dim(keys, fg);
|
|
509
689
|
}
|
|
@@ -512,7 +692,7 @@ function providerGroupLabel(label, fg) {
|
|
|
512
692
|
return fg("warning", normalized);
|
|
513
693
|
}
|
|
514
694
|
function formatMainListRow(row, selected, fg, width) {
|
|
515
|
-
const prefix = selected ? fg("accent", "› ") : " ";
|
|
695
|
+
const prefix = (selected ? fg("accent", "› ") : " ") + (row.treeDepth === 1 ? dim(` ${row.lastChild ? "└─" : "├─"} `, fg) : "");
|
|
516
696
|
const name = row.name || row.id;
|
|
517
697
|
const indicator = statusIndicator(row);
|
|
518
698
|
const status = fg(indicator.color, indicator.glyph);
|
|
@@ -545,16 +725,20 @@ function statusIndicator(row, now = Date.now()) {
|
|
|
545
725
|
void now;
|
|
546
726
|
if (row.statusTone !== "running")
|
|
547
727
|
return { glyph: statusGlyph(row), color: toneColor(row.statusTone, row.status) };
|
|
548
|
-
|
|
728
|
+
const glyph = row.treeDepth === 1 && row.providerId === "background-tasks" ? ">_" : RUNNING_DOT_GLYPH;
|
|
729
|
+
return { glyph, color: "accent" };
|
|
549
730
|
}
|
|
550
731
|
function mainListSignature(rows, options = {}) {
|
|
551
732
|
return JSON.stringify({
|
|
733
|
+
view: getNavigatorView(),
|
|
552
734
|
focused: options.focused === true,
|
|
553
735
|
closeHint: options.closeHint ?? null,
|
|
554
736
|
selectedId: options.focused === true ? options.selectedId ?? null : null,
|
|
555
737
|
rows: rows.map((row) => ({
|
|
556
738
|
navigatorId: row.navigatorId,
|
|
557
739
|
providerLabel: row.providerLabel,
|
|
740
|
+
parentAgentId: row.parentAgentId,
|
|
741
|
+
agentId: row.agentId,
|
|
558
742
|
parentRow: row.parentRow === true,
|
|
559
743
|
providerId: row.providerId,
|
|
560
744
|
id: row.id,
|
|
@@ -578,6 +762,9 @@ function stableFacts(facts) {
|
|
|
578
762
|
return (facts ?? []).filter((fact) => !/\bleft$/.test(singleLine(fact)));
|
|
579
763
|
}
|
|
580
764
|
function rowSummary(row) {
|
|
765
|
+
if (getNavigatorView() === "tree" && row.providerId === "background-tasks") {
|
|
766
|
+
return [singleLine(row.status).replaceAll("_", " "), ...(row.facts ?? []).map(singleLine)].join(" · ");
|
|
767
|
+
}
|
|
581
768
|
if (row.providerId === "subagents") {
|
|
582
769
|
const attention = row.facts?.map(singleLine).filter(Boolean);
|
|
583
770
|
if (attention?.length)
|
|
@@ -646,6 +833,9 @@ function prepareDetail(navigatorId, options) {
|
|
|
646
833
|
}
|
|
647
834
|
function detailFor(navigatorId, now = Date.now(), options) {
|
|
648
835
|
const { providerId, id } = splitRowKey(navigatorId);
|
|
836
|
+
const failed = state().launchFailures?.get(navigatorId);
|
|
837
|
+
if (failed)
|
|
838
|
+
return { providerId, id, title: failed.name ?? "Launch failed", status: "failed", statusTone: "failed", metadata: [], evidence: { label: "Launch error", text: failed.primary } };
|
|
649
839
|
const provider = state().providers.get(providerId);
|
|
650
840
|
if (!provider)
|
|
651
841
|
return null;
|
|
@@ -657,20 +847,29 @@ function detailFor(navigatorId, now = Date.now(), options) {
|
|
|
657
847
|
}
|
|
658
848
|
}
|
|
659
849
|
function closeFor(row) {
|
|
660
|
-
if (row.parentRow)
|
|
850
|
+
if (row.parentRow || row.readOnly)
|
|
661
851
|
return { action: "not-closable", providerId: row.providerId, id: row.id };
|
|
662
852
|
const provider = state().providers.get(row.providerId);
|
|
853
|
+
if (state().launchFailures?.delete(row.navigatorId)) {
|
|
854
|
+
state().terminalRows?.get(row.providerId)?.dismiss(row.id);
|
|
855
|
+
return { action: "dismissed", providerId: row.providerId, id: row.id };
|
|
856
|
+
}
|
|
663
857
|
if (!provider)
|
|
664
858
|
return { action: "missing", providerId: row.providerId, id: row.id };
|
|
665
859
|
try {
|
|
666
|
-
|
|
860
|
+
const outcome = provider.close(row.id);
|
|
861
|
+
if (["dismissed", "stopped-and-dismissed"].includes(outcome.action)
|
|
862
|
+
|| outcome.action === "requested" && ["completed", "succeeded", "failed", "cancelled", "killed", "lost", "timed_out"].includes(row.status)) {
|
|
863
|
+
state().terminalRows?.get(row.providerId)?.dismiss(row.id);
|
|
864
|
+
}
|
|
865
|
+
return outcome;
|
|
667
866
|
}
|
|
668
867
|
catch {
|
|
669
868
|
return { action: "missing", providerId: row.providerId, id: row.id };
|
|
670
869
|
}
|
|
671
870
|
}
|
|
672
871
|
function closeHintFor(row) {
|
|
673
|
-
if (!row || row.parentRow)
|
|
872
|
+
if (!row || row.parentRow || row.readOnly)
|
|
674
873
|
return null;
|
|
675
874
|
const provider = state().providers.get(row.providerId);
|
|
676
875
|
if (!provider)
|
|
@@ -734,6 +933,10 @@ function wrapEditor(inner, deps) {
|
|
|
734
933
|
}
|
|
735
934
|
function handleMainListInput(data, deps) {
|
|
736
935
|
const s = state();
|
|
936
|
+
if (!s.mainListFocused && deps.isOpenTrigger(data)) {
|
|
937
|
+
for (const provider of s.providers.values())
|
|
938
|
+
provider.onOpen?.();
|
|
939
|
+
}
|
|
737
940
|
const rows = listRows();
|
|
738
941
|
if (rows.length === 0) {
|
|
739
942
|
// Every row is gone, but an overlay that lost focus may still be mounted: Esc still closes it.
|
|
@@ -813,7 +1016,7 @@ function dismissOverlay() {
|
|
|
813
1016
|
}
|
|
814
1017
|
function handleMainListCloseKey() {
|
|
815
1018
|
const row = selectedMainListRow();
|
|
816
|
-
if (!row || row.parentRow)
|
|
1019
|
+
if (!row || row.parentRow || row.readOnly)
|
|
817
1020
|
return;
|
|
818
1021
|
const s = state();
|
|
819
1022
|
const now = Date.now();
|
|
@@ -855,6 +1058,8 @@ function openNavigator() {
|
|
|
855
1058
|
const deps = s.deps;
|
|
856
1059
|
if (!ctx || !deps || !isNavigatorUiAvailable(ctx))
|
|
857
1060
|
return;
|
|
1061
|
+
for (const provider of s.providers.values())
|
|
1062
|
+
provider.onOpen?.();
|
|
858
1063
|
const rows = listRows();
|
|
859
1064
|
if (rows.length === 0)
|
|
860
1065
|
return;
|
|
@@ -1056,7 +1261,7 @@ function createOverlayComponent(initialRows, deps, tui, theme, done, onClosed, i
|
|
|
1056
1261
|
}
|
|
1057
1262
|
function handleCloseKey() {
|
|
1058
1263
|
const row = selectedRow();
|
|
1059
|
-
if (!row || row.parentRow)
|
|
1264
|
+
if (!row || row.parentRow || row.readOnly)
|
|
1060
1265
|
return;
|
|
1061
1266
|
const now = Date.now();
|
|
1062
1267
|
if (closeArm?.id === row.navigatorId && now >= closeArm.armedAt && now < closeArm.armedAt + CLOSE_ARM_MS) {
|