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
|
@@ -15,10 +15,12 @@
|
|
|
15
15
|
import type { RunTiming } from "./timing.ts";
|
|
16
16
|
import { assignmentRetainsEvidence } from "./assignment-outcomes.ts";
|
|
17
17
|
import type { SkillExposureSource } from "./skills.ts";
|
|
18
|
-
import {
|
|
18
|
+
import { processStartToken } from "./process-identity.mjs";
|
|
19
|
+
export { processStartToken } from "./process-identity.mjs";
|
|
19
20
|
import { createHash, randomBytes } from "node:crypto";
|
|
20
21
|
import { closeSync, existsSync, fsyncSync, linkSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
21
22
|
import { createRequire } from "node:module";
|
|
23
|
+
import { readFile, readdir } from "node:fs/promises";
|
|
22
24
|
import { tmpdir } from "node:os";
|
|
23
25
|
import { basename, dirname, join } from "node:path";
|
|
24
26
|
import { processExists } from "./spawn.ts";
|
|
@@ -42,6 +44,7 @@ export type RunStatus = "running" | "completed" | "failed" | "killed" | "orphane
|
|
|
42
44
|
export interface RunCallbackOrigin {
|
|
43
45
|
cwd: string;
|
|
44
46
|
sessionId?: string;
|
|
47
|
+
branchId?: string | null;
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
/**
|
|
@@ -110,6 +113,8 @@ export interface LaunchRecipe {
|
|
|
110
113
|
effort?: string;
|
|
111
114
|
/** Effective tool allowlist (already adjusted for confinement). */
|
|
112
115
|
tools: string;
|
|
116
|
+
/** Inherited trusted tools may be registered but inactive in the child. Older recipes are strict. */
|
|
117
|
+
optionalTrustedTools?: string[];
|
|
113
118
|
excludeTools?: string;
|
|
114
119
|
/**
|
|
115
120
|
* Effective skill exposure: absent means discovery of the user catalog,
|
|
@@ -130,10 +135,14 @@ export interface LaunchRecipe {
|
|
|
130
135
|
role?: string | readonly string[];
|
|
131
136
|
alias?: string;
|
|
132
137
|
catalog?: CatalogLaunchSnapshot;
|
|
138
|
+
/** Absent on recipes that predate explicit ordinary worker providers. */
|
|
139
|
+
toolLoadingVersion?: 1;
|
|
133
140
|
/** Resolved extension arguments; a changed implementation requires explicit replacement. */
|
|
134
141
|
extensionArgs?: string[];
|
|
135
142
|
/** Provider/tool runtime arguments, excluding permission-dependent trusted tools. */
|
|
136
143
|
baseExtensionArgs?: string[];
|
|
144
|
+
/** Published worker closure retained for this conversation across server upgrades. */
|
|
145
|
+
runtimeRoot?: string;
|
|
137
146
|
/** Initial trusted implementations survive revocation so re-grants cannot replace them. */
|
|
138
147
|
trustedExtensions?: { name: string; package: string; loadPath: string }[];
|
|
139
148
|
}
|
|
@@ -244,6 +253,8 @@ export interface RunMeta {
|
|
|
244
253
|
completionCallbackSuppressedReason?: string;
|
|
245
254
|
outcomeDeliveryDeferredReason?: string;
|
|
246
255
|
assignmentReport?: { version: 1; assignmentId: string; attemptId: string; digest: string; path: string };
|
|
256
|
+
/** Latest authenticated refusal, cleared when a corrected report is retained. */
|
|
257
|
+
assignmentReportRejection?: { reason: string; rejectedAt: number };
|
|
247
258
|
orphanedCallbackSuppressedAt?: number;
|
|
248
259
|
orphanedCallbackSuppressedReason?: string;
|
|
249
260
|
lostCallbackSuppressedAt?: number;
|
|
@@ -522,6 +533,28 @@ export function listParkRecordCandidates(metas: readonly RunMeta[] = listMetas()
|
|
|
522
533
|
|| (volatileIds.has(meta.id) && existsSync(parkRecordPath(meta.id))));
|
|
523
534
|
}
|
|
524
535
|
|
|
536
|
+
/** Read recovery sidecars in batches so a large registry does not block socket replies. */
|
|
537
|
+
export async function* scanParkRecords(metas: readonly RunMeta[] = listMetas()): AsyncGenerator<{ meta: RunMeta; record: ParkRecord }> {
|
|
538
|
+
const runs = join(baseDir(), "runs");
|
|
539
|
+
const volatileIds = new Set(await readdir(runs).catch(() => [] as string[]));
|
|
540
|
+
const batchSize = 32;
|
|
541
|
+
for (let offset = 0; offset < metas.length; offset += batchSize) {
|
|
542
|
+
const batch = await Promise.all(metas.slice(offset, offset + batchSize).map(async (meta) => {
|
|
543
|
+
if (!meta.park && !volatileIds.has(meta.id)) return;
|
|
544
|
+
try {
|
|
545
|
+
const record = parseParkRecord(JSON.parse(await readFile(join(runs, meta.id, "park.json"), "utf-8")));
|
|
546
|
+
if (record) return { meta, record };
|
|
547
|
+
} catch (error) {
|
|
548
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT" && meta.park) {
|
|
549
|
+
const record = readMeta(meta.id)?.park;
|
|
550
|
+
if (record) return { meta, record };
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}));
|
|
554
|
+
for (const entry of batch) if (entry) yield entry;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
525
558
|
/**
|
|
526
559
|
* How long a launch attempt that never produced a child is kept before a sweep
|
|
527
560
|
* reclaims it. Launch preparation takes seconds; the grace only exists so a
|
|
@@ -797,33 +830,6 @@ let ownStartKnown = false;
|
|
|
797
830
|
let ownStartCache: string | undefined;
|
|
798
831
|
const foreignStartCache = new Map<number, { token: string | undefined; at: number }>();
|
|
799
832
|
|
|
800
|
-
/** Best-effort process start identity. Unavailable does not prove the pid is dead. */
|
|
801
|
-
export function processStartToken(pid: number): string | undefined {
|
|
802
|
-
if (process.platform === "linux") {
|
|
803
|
-
try {
|
|
804
|
-
const stat = readFileSync(`/proc/${pid}/stat`, "utf-8");
|
|
805
|
-
const close = stat.lastIndexOf(") ");
|
|
806
|
-
if (close >= 0) {
|
|
807
|
-
const starttime = stat.slice(close + 2).split(" ")[19];
|
|
808
|
-
if (starttime && /^\d+$/.test(starttime)) return starttime;
|
|
809
|
-
}
|
|
810
|
-
} catch (error) {
|
|
811
|
-
if (errnoOf(error) !== "ENOENT" && errnoOf(error) !== "EACCES") return undefined;
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
try {
|
|
815
|
-
const out = execFileSync("ps", ["-o", "lstart=", "-p", String(pid)], {
|
|
816
|
-
encoding: "utf-8",
|
|
817
|
-
timeout: 1_000,
|
|
818
|
-
env: { ...process.env, LC_ALL: "C" },
|
|
819
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
820
|
-
}).trim().replace(/\s+/g, " ");
|
|
821
|
-
return out === "" ? undefined : out;
|
|
822
|
-
} catch {
|
|
823
|
-
return undefined;
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
|
|
827
833
|
function ownStartToken(): string | undefined {
|
|
828
834
|
if (ownStartKnown) return ownStartCache;
|
|
829
835
|
ownStartCache = processStartToken(process.pid);
|
|
@@ -1177,7 +1183,7 @@ export function setMetaWriteBarrierForTests(barrier: (() => void) | undefined):
|
|
|
1177
1183
|
// cross-process index changes before any cached IDs are reused.
|
|
1178
1184
|
const indexIdsCache = new Map<string, { ids: Set<string>; signature: string }>();
|
|
1179
1185
|
const initializedIndexes = new Set<string>();
|
|
1180
|
-
const metaChangedListeners = new Set<() => void>();
|
|
1186
|
+
const metaChangedListeners = new Set<(meta?: RunMeta) => void>();
|
|
1181
1187
|
const registryIo = { fullDirectoryReads: 0, indexDirectoryReads: 0, metadataFileReads: 0, indexRevisionChecks: 0 };
|
|
1182
1188
|
|
|
1183
1189
|
export interface RegistryIoMetrics {
|
|
@@ -1251,10 +1257,23 @@ export function observeArchivePublication(id: string, error?: unknown): void {
|
|
|
1251
1257
|
} catch { /* the journal is best-effort; retaining the run is the safety net */ }
|
|
1252
1258
|
}
|
|
1253
1259
|
|
|
1254
|
-
export function writeMeta(meta: RunMeta, options: {
|
|
1260
|
+
export function writeMeta(meta: RunMeta, options: {
|
|
1261
|
+
ifAbsent?: boolean;
|
|
1262
|
+
/** Build a field update from current metadata under the existing run lock. */
|
|
1263
|
+
patch?: (current: Readonly<RunMeta>) => Partial<RunMeta> | undefined;
|
|
1264
|
+
} = {}): void {
|
|
1265
|
+
if (options.patch && !readMeta(meta.id)) return;
|
|
1255
1266
|
mkdirSync(runDir(meta.id), { recursive: true });
|
|
1267
|
+
let written = false;
|
|
1256
1268
|
withRunMetaLock(meta.id, (owns) => {
|
|
1257
1269
|
if (options.ifAbsent && existsSync(metaPathFor(meta.id))) return;
|
|
1270
|
+
if (options.patch) {
|
|
1271
|
+
const current = readMeta(meta.id);
|
|
1272
|
+
if (!current) return;
|
|
1273
|
+
const patch = options.patch(current);
|
|
1274
|
+
if (!patch) return;
|
|
1275
|
+
meta = { ...current, ...patch, id: meta.id };
|
|
1276
|
+
}
|
|
1258
1277
|
metaWriteBarrier?.();
|
|
1259
1278
|
if (!owns()) throw new MetadataLockLost();
|
|
1260
1279
|
writeMetaFile(meta);
|
|
@@ -1273,13 +1292,15 @@ export function writeMeta(meta: RunMeta, options: { ifAbsent?: boolean } = {}):
|
|
|
1273
1292
|
}
|
|
1274
1293
|
}
|
|
1275
1294
|
owns();
|
|
1295
|
+
written = true;
|
|
1276
1296
|
});
|
|
1297
|
+
if (options.patch && !written) return;
|
|
1277
1298
|
for (const listener of metaChangedListeners) {
|
|
1278
|
-
try { listener(); } catch { /* best effort */ }
|
|
1299
|
+
try { listener(meta); } catch { /* best effort */ }
|
|
1279
1300
|
}
|
|
1280
1301
|
}
|
|
1281
1302
|
|
|
1282
|
-
export function onMetaChanged(listener: () => void): () => void {
|
|
1303
|
+
export function onMetaChanged(listener: (meta?: RunMeta) => void): () => void {
|
|
1283
1304
|
metaChangedListeners.add(listener);
|
|
1284
1305
|
return () => metaChangedListeners.delete(listener);
|
|
1285
1306
|
}
|
|
@@ -1341,7 +1362,7 @@ export function removeMetaArtifacts(meta: RunMeta, options: RemoveMetaArtifactsO
|
|
|
1341
1362
|
removeIndexEntry(join(baseDir(), "by-parent-active", String(meta.spawnPid)), meta.id);
|
|
1342
1363
|
removeIndexEntry(join(baseDir(), "by-origin", originKey(originOf(meta))), meta.id);
|
|
1343
1364
|
for (const listener of metaChangedListeners) {
|
|
1344
|
-
try { listener(); } catch { /* best effort */ }
|
|
1365
|
+
try { listener(meta); } catch { /* best effort */ }
|
|
1345
1366
|
}
|
|
1346
1367
|
return true;
|
|
1347
1368
|
} catch {
|
|
@@ -400,6 +400,7 @@ export function createCallbackBatcher(host, options = {}) {
|
|
|
400
400
|
const pending = new Map();
|
|
401
401
|
const inFlight = new Set();
|
|
402
402
|
const urgentInFlight = new Set();
|
|
403
|
+
const urgentSettlements = new Set();
|
|
403
404
|
const handedOff = new Map();
|
|
404
405
|
const activeTools = new Set();
|
|
405
406
|
let sequence = 0;
|
|
@@ -583,7 +584,9 @@ export function createCallbackBatcher(host, options = {}) {
|
|
|
583
584
|
const handoff = host.sendMessage({ customType: event.customType, content: formatUrgentCallback(event, { maxBytes }), display: true,
|
|
584
585
|
...(event.receiptId ? { details: { urgentEventId: event.receiptId } } : {}) }, { deliverAs: "followUp", triggerTurn: true });
|
|
585
586
|
if (isPromiseLike(handoff)) {
|
|
586
|
-
|
|
587
|
+
const settlement = Promise.resolve(handoff).then(() => acknowledge(), () => false).finally(() => { urgentInFlight.delete(key); urgentSettlements.delete(settlement); });
|
|
588
|
+
urgentSettlements.add(settlement);
|
|
589
|
+
return settlement;
|
|
587
590
|
}
|
|
588
591
|
const acknowledged = acknowledge();
|
|
589
592
|
urgentInFlight.delete(key);
|
|
@@ -634,6 +637,10 @@ export function createCallbackBatcher(host, options = {}) {
|
|
|
634
637
|
return pending.size > 0 ? api.flush() : true;
|
|
635
638
|
},
|
|
636
639
|
deliverUrgent,
|
|
640
|
+
async settled() {
|
|
641
|
+
await flushPromise;
|
|
642
|
+
await Promise.all([...urgentSettlements]);
|
|
643
|
+
},
|
|
637
644
|
cancel() {
|
|
638
645
|
cancelTimer();
|
|
639
646
|
pending.clear();
|
|
@@ -210,6 +210,8 @@ export interface CallbackBatcher {
|
|
|
210
210
|
toolEnded(toolCallId: string): Promise<boolean>;
|
|
211
211
|
deliverUrgent(event: UrgentCallbackEvent): boolean | Promise<boolean>;
|
|
212
212
|
cancel(): void;
|
|
213
|
+
/** Await already-started handoffs after the owner has cancelled scheduling. */
|
|
214
|
+
settled(): Promise<void>;
|
|
213
215
|
pendingCount(): number;
|
|
214
216
|
}
|
|
215
217
|
|
|
@@ -568,6 +570,7 @@ export function createCallbackBatcher(
|
|
|
568
570
|
const pending = new Map<string, PendingEvent>();
|
|
569
571
|
const inFlight = new Set<string>();
|
|
570
572
|
const urgentInFlight = new Set<string>();
|
|
573
|
+
const urgentSettlements = new Set<Promise<boolean>>();
|
|
571
574
|
const handedOff = new Map<string, number>();
|
|
572
575
|
const activeTools = new Set<string>();
|
|
573
576
|
let sequence = 0;
|
|
@@ -750,10 +753,12 @@ export function createCallbackBatcher(
|
|
|
750
753
|
{ deliverAs: "followUp", triggerTurn: true },
|
|
751
754
|
);
|
|
752
755
|
if (isPromiseLike(handoff)) {
|
|
753
|
-
|
|
756
|
+
const settlement = Promise.resolve(handoff).then(
|
|
754
757
|
() => acknowledge(),
|
|
755
758
|
() => false,
|
|
756
|
-
).finally(() => urgentInFlight.delete(key));
|
|
759
|
+
).finally(() => { urgentInFlight.delete(key); urgentSettlements.delete(settlement); });
|
|
760
|
+
urgentSettlements.add(settlement);
|
|
761
|
+
return settlement;
|
|
757
762
|
}
|
|
758
763
|
const acknowledged = acknowledge();
|
|
759
764
|
urgentInFlight.delete(key);
|
|
@@ -800,6 +805,10 @@ export function createCallbackBatcher(
|
|
|
800
805
|
return pending.size > 0 ? api.flush() : true;
|
|
801
806
|
},
|
|
802
807
|
deliverUrgent,
|
|
808
|
+
async settled() {
|
|
809
|
+
await flushPromise;
|
|
810
|
+
await Promise.all([...urgentSettlements]);
|
|
811
|
+
},
|
|
803
812
|
cancel() {
|
|
804
813
|
cancelTimer();
|
|
805
814
|
pending.clear();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-subagents/shared-catalog.ts. Do not edit directly.
|
|
2
2
|
import { readFileSync, realpathSync } from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { connectWorkClient } from "./shared-work-client.mjs";
|
|
5
5
|
import { catalogSnapshotFromWire, defaultUserRoot } from "./catalog-store.domain.mjs";
|
|
6
6
|
import { catalogHostAuthority } from "./catalog-host-admission.domain.mjs";
|
|
7
7
|
/** Short-lived catalog connection. No transcript or permission authority travels here. */
|
|
@@ -59,29 +59,12 @@ export async function openSharedCatalog(cwd, userRoot = defaultUserRoot(), sessi
|
|
|
59
59
|
}
|
|
60
60
|
/** Retry connection establishment only; never replay a Catalog edit or authorization failure. */
|
|
61
61
|
export async function connectCatalogClient(agentDir, serverDir, ensure = ensureCatalogRuntime) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
await client.ready;
|
|
66
|
-
return client;
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
client.close();
|
|
70
|
-
throw error;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
try {
|
|
74
|
-
return await connect();
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
if (!["ENOENT", "ECONNREFUSED"].includes(error.code ?? ""))
|
|
78
|
-
throw error;
|
|
79
|
-
await ensure(agentDir);
|
|
80
|
-
return connect();
|
|
81
|
-
}
|
|
62
|
+
return connectWorkClient(join(serverDir, "pi-server.sock"), agentDir, ["runtime-catalog-v1"], {
|
|
63
|
+
recover: ({ timeoutMs, signal }) => ensure(agentDir, serverDir, timeoutMs, signal),
|
|
64
|
+
});
|
|
82
65
|
}
|
|
83
|
-
async function ensureCatalogRuntime(agentDir) {
|
|
66
|
+
async function ensureCatalogRuntime(agentDir, serverDir, timeoutMs, signal) {
|
|
84
67
|
const path = "./runtime-client/src/runtime/client.mjs";
|
|
85
68
|
const { ensureRuntime } = await import(path);
|
|
86
|
-
await ensureRuntime({ agentDir });
|
|
69
|
+
await ensureRuntime({ agentDir, serverDir, timeoutMs, signal });
|
|
87
70
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync, realpathSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { WorkClient } from "./shared-work-client.mjs";
|
|
3
|
+
import { WorkClient, connectWorkClient } from "./shared-work-client.mjs";
|
|
4
4
|
import { catalogSnapshotFromWire, defaultUserRoot, type CatalogSnapshot } from "./catalog-store.ts";
|
|
5
5
|
import type { AgentSessionOverrides } from "./agent-session-settings.ts";
|
|
6
6
|
import { catalogHostAuthority } from "./catalog-host-admission.ts";
|
|
@@ -49,21 +49,13 @@ export async function openSharedCatalog(cwd: string, userRoot = defaultUserRoot(
|
|
|
49
49
|
|
|
50
50
|
/** Retry connection establishment only; never replay a Catalog edit or authorization failure. */
|
|
51
51
|
export async function connectCatalogClient(agentDir: string, serverDir: string, ensure = ensureCatalogRuntime): Promise<WorkClient> {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
catch (error) { client.close(); throw error; }
|
|
56
|
-
};
|
|
57
|
-
try { return await connect(); }
|
|
58
|
-
catch (error) {
|
|
59
|
-
if (!["ENOENT", "ECONNREFUSED"].includes((error as NodeJS.ErrnoException).code ?? "")) throw error;
|
|
60
|
-
await ensure(agentDir);
|
|
61
|
-
return connect();
|
|
62
|
-
}
|
|
52
|
+
return connectWorkClient(join(serverDir, "pi-server.sock"), agentDir, ["runtime-catalog-v1"], {
|
|
53
|
+
recover: ({ timeoutMs, signal }) => ensure(agentDir, serverDir, timeoutMs, signal),
|
|
54
|
+
});
|
|
63
55
|
}
|
|
64
56
|
|
|
65
|
-
async function ensureCatalogRuntime(agentDir: string): Promise<void> {
|
|
57
|
+
async function ensureCatalogRuntime(agentDir: string, serverDir?: string, timeoutMs?: number, signal?: AbortSignal): Promise<void> {
|
|
66
58
|
const path = "./runtime-client/src/runtime/client.mjs";
|
|
67
59
|
const { ensureRuntime } = await import(path);
|
|
68
|
-
await ensureRuntime({ agentDir });
|
|
60
|
+
await ensureRuntime({ agentDir, serverDir, timeoutMs, signal });
|
|
69
61
|
}
|
|
@@ -42,15 +42,34 @@ function buildPanels(s) {
|
|
|
42
42
|
if (!s.tui || !s.theme)
|
|
43
43
|
return;
|
|
44
44
|
for (const panel of orderedPanels(s))
|
|
45
|
-
panel.component ??= panel.factory(s.tui, s.theme);
|
|
45
|
+
panel.component ??= panel.factory(s.tui, s.theme, { availableRows: () => s.availableRows ?? Infinity });
|
|
46
|
+
}
|
|
47
|
+
// Count the editor, footer and other siblings following the host in regular mode.
|
|
48
|
+
// Never render ancestors here: they contain this host and would recurse.
|
|
49
|
+
function rowsAfter(root, target, width) {
|
|
50
|
+
if (root === target)
|
|
51
|
+
return 0;
|
|
52
|
+
const children = root.children;
|
|
53
|
+
if (!children)
|
|
54
|
+
return undefined;
|
|
55
|
+
for (let i = children.length - 1; i >= 0; i--) {
|
|
56
|
+
const after = rowsAfter(children[i], target, width);
|
|
57
|
+
if (after !== undefined)
|
|
58
|
+
return after + children.slice(i + 1).reduce((sum, child) => sum + child.render(width).length, 0);
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
46
61
|
}
|
|
47
62
|
function renderPanels(s, width) {
|
|
48
63
|
buildPanels(s);
|
|
49
64
|
const lines = [];
|
|
50
65
|
s.ranges = [];
|
|
66
|
+
const after = s.sticky && s.tui && s.host ? rowsAfter(s.tui, s.host, width) : undefined;
|
|
67
|
+
const height = s.tui?.terminal?.rows;
|
|
68
|
+
const budget = after !== undefined && height ? Math.max(0, height - after) : Infinity;
|
|
51
69
|
for (const panel of orderedPanels(s)) {
|
|
52
70
|
if (!panel.component)
|
|
53
71
|
continue;
|
|
72
|
+
s.availableRows = Math.max(0, budget - lines.length);
|
|
54
73
|
const rendered = panel.component.render(width);
|
|
55
74
|
s.ranges.push({ start: lines.length, end: lines.length + rendered.length, component: panel.component });
|
|
56
75
|
lines.push(...rendered);
|
|
@@ -110,6 +129,7 @@ function clearHost(s) {
|
|
|
110
129
|
disposePanels(s);
|
|
111
130
|
s.mounted = false;
|
|
112
131
|
s.tui = undefined;
|
|
132
|
+
s.host = undefined;
|
|
113
133
|
s.theme = undefined;
|
|
114
134
|
}
|
|
115
135
|
function adoptContext(s, ctx) {
|
|
@@ -131,7 +151,7 @@ function mountHost(s) {
|
|
|
131
151
|
s.tui = tui;
|
|
132
152
|
s.theme = theme;
|
|
133
153
|
buildPanels(s);
|
|
134
|
-
|
|
154
|
+
const host = {
|
|
135
155
|
render(width) {
|
|
136
156
|
const lines = renderPanels(s, width);
|
|
137
157
|
if (s.sticky)
|
|
@@ -147,6 +167,8 @@ function mountHost(s) {
|
|
|
147
167
|
},
|
|
148
168
|
dispose() { disposePanels(s); s.mounted = false; },
|
|
149
169
|
};
|
|
170
|
+
s.host = host;
|
|
171
|
+
return host;
|
|
150
172
|
}, { placement: "aboveEditor" });
|
|
151
173
|
}
|
|
152
174
|
function changeSticky(value, ctx) {
|
|
@@ -9,7 +9,8 @@ export const NAVIGATOR_ENTRY_TYPE = "pi-better-harness-navigator-panels";
|
|
|
9
9
|
export const NAVIGATOR_STICKY_SETTING_ID = "navigator-sticky";
|
|
10
10
|
type MouseEvent = { type: string; button: string; x: number; y: number; width: number; shift?: boolean; alt?: boolean; ctrl?: boolean };
|
|
11
11
|
type PanelComponent = Component & { dispose?(): void; handleMouse?(event: MouseEvent): { handled: true; render: boolean } | undefined };
|
|
12
|
-
export type
|
|
12
|
+
export type NavigatorPanelLayout = { availableRows(): number };
|
|
13
|
+
export type NavigatorPanelFactory = (tui: TUI, theme: Theme, layout: NavigatorPanelLayout) => PanelComponent;
|
|
13
14
|
type Panel = { factory: NavigatorPanelFactory; component?: PanelComponent | undefined };
|
|
14
15
|
type Preference = { version: 1; sticky: boolean };
|
|
15
16
|
type Owner = { pi: ExtensionAPI; stop?: (() => void) | undefined };
|
|
@@ -23,6 +24,8 @@ type State = {
|
|
|
23
24
|
mounted: boolean;
|
|
24
25
|
tui?: TUI | undefined;
|
|
25
26
|
theme?: Theme | undefined;
|
|
27
|
+
host?: Component | undefined;
|
|
28
|
+
availableRows?: number | undefined;
|
|
26
29
|
anchor?: string | undefined;
|
|
27
30
|
pendingAnchor: boolean;
|
|
28
31
|
generation: number;
|
|
@@ -61,14 +64,30 @@ function orderedPanels(s: State): Panel[] {
|
|
|
61
64
|
}
|
|
62
65
|
function buildPanels(s: State): void {
|
|
63
66
|
if (!s.tui || !s.theme) return;
|
|
64
|
-
for (const panel of orderedPanels(s)) panel.component ??= panel.factory(s.tui, s.theme);
|
|
67
|
+
for (const panel of orderedPanels(s)) panel.component ??= panel.factory(s.tui, s.theme, { availableRows: () => s.availableRows ?? Infinity });
|
|
68
|
+
}
|
|
69
|
+
// Count the editor, footer and other siblings following the host in regular mode.
|
|
70
|
+
// Never render ancestors here: they contain this host and would recurse.
|
|
71
|
+
function rowsAfter(root: object, target: Component, width: number): number | undefined {
|
|
72
|
+
if (root === target) return 0;
|
|
73
|
+
const children = (root as Component & { children?: Component[] }).children;
|
|
74
|
+
if (!children) return undefined;
|
|
75
|
+
for (let i = children.length - 1; i >= 0; i--) {
|
|
76
|
+
const after = rowsAfter(children[i]!, target, width);
|
|
77
|
+
if (after !== undefined) return after + children.slice(i + 1).reduce((sum, child) => sum + child.render(width).length, 0);
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
65
80
|
}
|
|
66
81
|
function renderPanels(s: State, width: number): string[] {
|
|
67
82
|
buildPanels(s);
|
|
68
83
|
const lines: string[] = [];
|
|
69
84
|
s.ranges = [];
|
|
85
|
+
const after = s.sticky && s.tui && s.host ? rowsAfter(s.tui, s.host, width) : undefined;
|
|
86
|
+
const height = s.tui?.terminal?.rows;
|
|
87
|
+
const budget = after !== undefined && height ? Math.max(0, height - after) : Infinity;
|
|
70
88
|
for (const panel of orderedPanels(s)) {
|
|
71
89
|
if (!panel.component) continue;
|
|
90
|
+
s.availableRows = Math.max(0, budget - lines.length);
|
|
72
91
|
const rendered = panel.component.render(width);
|
|
73
92
|
s.ranges.push({ start: lines.length, end: lines.length + rendered.length, component: panel.component });
|
|
74
93
|
lines.push(...rendered);
|
|
@@ -115,6 +134,7 @@ function clearHost(s: State): void {
|
|
|
115
134
|
disposePanels(s);
|
|
116
135
|
s.mounted = false;
|
|
117
136
|
s.tui = undefined;
|
|
137
|
+
s.host = undefined;
|
|
118
138
|
s.theme = undefined;
|
|
119
139
|
}
|
|
120
140
|
function adoptContext(s: State, ctx: ExtensionContext): void {
|
|
@@ -134,7 +154,7 @@ function mountHost(s: State): void {
|
|
|
134
154
|
s.tui = tui;
|
|
135
155
|
s.theme = theme;
|
|
136
156
|
buildPanels(s);
|
|
137
|
-
|
|
157
|
+
const host: PanelComponent = {
|
|
138
158
|
render(width: number) {
|
|
139
159
|
const lines = renderPanels(s, width);
|
|
140
160
|
if (s.sticky) return lines;
|
|
@@ -147,6 +167,8 @@ function mountHost(s: State): void {
|
|
|
147
167
|
},
|
|
148
168
|
dispose() { disposePanels(s); s.mounted = false; },
|
|
149
169
|
};
|
|
170
|
+
s.host = host;
|
|
171
|
+
return host;
|
|
150
172
|
}, { placement: "aboveEditor" });
|
|
151
173
|
}
|
|
152
174
|
function changeSticky(value: string, ctx: ExtensionContext): void {
|
|
@@ -247,4 +269,4 @@ export function __resetNavigatorPanelsForTests(): void {
|
|
|
247
269
|
s.anchor = undefined;
|
|
248
270
|
s.sticky = true;
|
|
249
271
|
s.control = undefined;
|
|
250
|
-
}
|
|
272
|
+
}
|