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
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-subagents/launch-context.ts. Do not edit directly.
|
|
2
|
+
/** Capture the invoking foreground before launch preparation can yield. */
|
|
3
|
+
export function captureLaunchContext(ctx) {
|
|
4
|
+
const manager = ctx?.sessionManager;
|
|
5
|
+
if (!manager)
|
|
6
|
+
return ctx;
|
|
7
|
+
const sessionId = typeof manager.getSessionId === "function" ? manager.getSessionId() : undefined;
|
|
8
|
+
const branch = typeof manager.getBranch === "function" ? structuredClone(manager.getBranch()) : undefined;
|
|
9
|
+
const leafId = typeof manager.getLeafId === "function" ? manager.getLeafId() : undefined;
|
|
10
|
+
const sessionFile = typeof manager.getSessionFile === "function" ? manager.getSessionFile() : undefined;
|
|
11
|
+
const reads = {
|
|
12
|
+
...(typeof manager.getSessionId === "function" ? { getSessionId: () => sessionId } : {}),
|
|
13
|
+
...(typeof manager.getBranch === "function" ? { getBranch: () => branch } : {}),
|
|
14
|
+
...(typeof manager.getLeafId === "function" ? { getLeafId: () => leafId } : {}),
|
|
15
|
+
...(typeof manager.getSessionFile === "function" ? { getSessionFile: () => sessionFile } : {}),
|
|
16
|
+
};
|
|
17
|
+
const captured = new Proxy(manager, { get(target, key) {
|
|
18
|
+
if (Object.hasOwn(reads, key))
|
|
19
|
+
return reads[key];
|
|
20
|
+
const value = Reflect.get(target, key, target);
|
|
21
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
22
|
+
} });
|
|
23
|
+
return { ...ctx, sessionManager: captured };
|
|
24
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
/** Capture the invoking foreground before launch preparation can yield. */
|
|
4
|
+
export function captureLaunchContext(ctx: ExtensionContext): ExtensionContext {
|
|
5
|
+
const manager = ctx?.sessionManager;
|
|
6
|
+
if (!manager) return ctx;
|
|
7
|
+
const sessionId = typeof manager.getSessionId === "function" ? manager.getSessionId() : undefined;
|
|
8
|
+
const branch = typeof manager.getBranch === "function" ? structuredClone(manager.getBranch()) : undefined;
|
|
9
|
+
const leafId = typeof manager.getLeafId === "function" ? manager.getLeafId() : undefined;
|
|
10
|
+
const sessionFile = typeof manager.getSessionFile === "function" ? manager.getSessionFile() : undefined;
|
|
11
|
+
const reads = {
|
|
12
|
+
...(typeof manager.getSessionId === "function" ? { getSessionId: () => sessionId } : {}),
|
|
13
|
+
...(typeof manager.getBranch === "function" ? { getBranch: () => branch } : {}),
|
|
14
|
+
...(typeof manager.getLeafId === "function" ? { getLeafId: () => leafId } : {}),
|
|
15
|
+
...(typeof manager.getSessionFile === "function" ? { getSessionFile: () => sessionFile } : {}),
|
|
16
|
+
};
|
|
17
|
+
const captured = new Proxy(manager, { get(target, key) {
|
|
18
|
+
if (Object.hasOwn(reads, key)) return reads[key as keyof typeof reads];
|
|
19
|
+
const value = Reflect.get(target, key, target);
|
|
20
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
21
|
+
} });
|
|
22
|
+
return { ...ctx, sessionManager: captured };
|
|
23
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-subagents/launch-digest.mjs. Do not edit directly.
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
const ordered = value => value === null || typeof value !== "object" ? value
|
|
4
|
+
: Array.isArray(value) ? value.map(ordered)
|
|
5
|
+
: Object.fromEntries(Object.keys(value).sort().map(key => [key, ordered(value[key])]));
|
|
6
|
+
export const launchDigest = value => createHash("sha256").update(JSON.stringify(ordered(value))).digest("hex");
|
|
@@ -18,31 +18,68 @@
|
|
|
18
18
|
* cursor skips ahead rather than falling permanently behind, and
|
|
19
19
|
* `truncated` reports that bytes were never seen.
|
|
20
20
|
*/
|
|
21
|
-
import { closeSync, openSync, readSync, statSync } from "node:fs";
|
|
21
|
+
import { closeSync, openSync, readSync, statSync, fstatSync } from "node:fs";
|
|
22
22
|
/** Bytes of the log head kept to detect a rewrite behind our back. */
|
|
23
23
|
const HEAD_SAMPLE_BYTES = 256;
|
|
24
|
+
export const logReadMetrics = { bytes: 0, reads: 0, parsedEvents: 0, displayFolded: 0, healthFolded: 0 };
|
|
25
|
+
let batch;
|
|
26
|
+
/** Share identical ranges and decoding only during a synchronous observation. */
|
|
27
|
+
export function withLogReadBatch(observe) {
|
|
28
|
+
const previous = batch;
|
|
29
|
+
batch = { reads: new Map(), events: new Map(), ranges: new Map() };
|
|
30
|
+
try {
|
|
31
|
+
return observe();
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
batch = previous;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function parseLogEvent(line) {
|
|
38
|
+
if (batch?.events.has(line))
|
|
39
|
+
return batch.events.get(line);
|
|
40
|
+
const event = JSON.parse(line);
|
|
41
|
+
logReadMetrics.parsedEvents++;
|
|
42
|
+
batch?.events.set(line, event);
|
|
43
|
+
return event;
|
|
44
|
+
}
|
|
24
45
|
/** Default ceiling on a single read: also the cold-start tail window. */
|
|
25
46
|
export const DEFAULT_MAX_READ_BYTES = 32 * 1024 * 1024; // 32 MiB
|
|
26
47
|
function errText(err) {
|
|
27
48
|
return err instanceof Error ? err.message : String(err);
|
|
28
49
|
}
|
|
29
|
-
function readAt(fd, position, length) {
|
|
50
|
+
function readAt(fd, position, length, path) {
|
|
30
51
|
const buf = Buffer.allocUnsafe(length);
|
|
52
|
+
const ranges = batch?.ranges.get(path) ?? [];
|
|
31
53
|
let filled = 0;
|
|
32
54
|
while (filled < length) {
|
|
33
|
-
const
|
|
55
|
+
const at = position + filled;
|
|
56
|
+
const cached = ranges.find(range => range.start <= at && range.start + range.data.length > at);
|
|
57
|
+
if (cached) {
|
|
58
|
+
const offset = at - cached.start;
|
|
59
|
+
const n = Math.min(length - filled, cached.data.length - offset);
|
|
60
|
+
cached.data.copy(buf, filled, offset, offset + n);
|
|
61
|
+
filled += n;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const next = Math.min(position + length, ...ranges.filter(range => range.start > at).map(range => range.start));
|
|
65
|
+
const n = readSync(fd, buf, filled, next - at, at);
|
|
34
66
|
if (n <= 0)
|
|
35
67
|
break;
|
|
68
|
+
if (batch) {
|
|
69
|
+
ranges.push({ start: at, data: buf.subarray(filled, filled + n) });
|
|
70
|
+
batch.ranges.set(path, ranges);
|
|
71
|
+
}
|
|
36
72
|
filled += n;
|
|
73
|
+
logReadMetrics.bytes += n;
|
|
37
74
|
}
|
|
38
75
|
return filled === length ? buf : buf.subarray(0, filled);
|
|
39
76
|
}
|
|
40
77
|
/** Head sample as a byte-exact string, for rewrite detection. */
|
|
41
|
-
function readHead(fd, size) {
|
|
78
|
+
function readHead(fd, size, path) {
|
|
42
79
|
const length = Math.min(HEAD_SAMPLE_BYTES, size);
|
|
43
80
|
if (length <= 0)
|
|
44
81
|
return "";
|
|
45
|
-
return readAt(fd, 0, length).toString("latin1");
|
|
82
|
+
return readAt(fd, 0, length, path).toString("latin1");
|
|
46
83
|
}
|
|
47
84
|
/**
|
|
48
85
|
* Same log? Compare the prefix both samples cover, so a head that is still
|
|
@@ -62,7 +99,17 @@ function headsAgree(previous, current) {
|
|
|
62
99
|
* Passing `previous: undefined` starts cold: the last `maxBytes` of the log,
|
|
63
100
|
* with the leading partial line dropped.
|
|
64
101
|
*/
|
|
65
|
-
export function readAppendedLines(path, previous, maxBytes = DEFAULT_MAX_READ_BYTES) {
|
|
102
|
+
export function readAppendedLines(path, previous, maxBytes = DEFAULT_MAX_READ_BYTES, cumulative = false) {
|
|
103
|
+
const key = JSON.stringify([path, previous, maxBytes, cumulative]);
|
|
104
|
+
const cached = batch?.reads.get(key);
|
|
105
|
+
if (cached)
|
|
106
|
+
return cached;
|
|
107
|
+
const result = readLines(path, previous, maxBytes, cumulative);
|
|
108
|
+
batch?.reads.set(key, result);
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
function readLines(path, previous, maxBytes, cumulative) {
|
|
112
|
+
logReadMetrics.reads++;
|
|
66
113
|
const empty = (error) => ({
|
|
67
114
|
lines: [],
|
|
68
115
|
cursor: previous ?? { offset: 0, head: "" },
|
|
@@ -86,54 +133,76 @@ export function readAppendedLines(path, previous, maxBytes = DEFAULT_MAX_READ_BY
|
|
|
86
133
|
return empty(errText(err));
|
|
87
134
|
}
|
|
88
135
|
try {
|
|
89
|
-
const
|
|
136
|
+
const info = fstatSync(fd);
|
|
137
|
+
size = info.size;
|
|
138
|
+
const generation = `${info.dev}:${info.ino}:${info.birthtimeMs}`;
|
|
139
|
+
const head = readHead(fd, size, path);
|
|
90
140
|
// A log that shrank or whose head changed is a different log: the old
|
|
91
141
|
// offset would point into unrelated bytes. Compare only the prefix the
|
|
92
142
|
// two samples share, so a log still shorter than the sample window is
|
|
93
143
|
// not "rewritten" every time it grows.
|
|
94
144
|
const resumable = previous !== undefined
|
|
145
|
+
&& (previous.generation === undefined || previous.generation === generation)
|
|
146
|
+
&& !(previous.size === size && previous.modified !== undefined && previous.modified !== info.mtimeMs)
|
|
95
147
|
&& previous.offset <= size
|
|
96
148
|
&& headsAgree(previous.head, head);
|
|
97
149
|
const restarted = previous !== undefined && !resumable;
|
|
150
|
+
let coverageStart = resumable ? previous.coverageStart ?? 0 : 0;
|
|
151
|
+
let missing = resumable ? previous.missing : undefined;
|
|
152
|
+
let skipLeading = resumable ? previous.skipLeading : false;
|
|
153
|
+
const cursor = (offset) => ({ offset, head, generation, size, modified: info.mtimeMs, coverageStart, missing, skipLeading });
|
|
98
154
|
let start = resumable ? previous.offset : 0;
|
|
99
155
|
let truncated = false;
|
|
100
|
-
if (size - start > maxBytes) {
|
|
156
|
+
if (!cumulative && size - start > maxBytes) {
|
|
101
157
|
// Skip ahead instead of lagging: a chatty log must not push the
|
|
102
158
|
// cursor permanently into the past.
|
|
103
159
|
start = size - maxBytes;
|
|
160
|
+
coverageStart = start;
|
|
161
|
+
missing = [missing?.[0] ?? (resumable ? previous.offset : 0), start];
|
|
104
162
|
truncated = true;
|
|
105
163
|
}
|
|
106
164
|
// We begin mid-line whenever bytes were skipped.
|
|
107
|
-
const startedMidLine = truncated;
|
|
165
|
+
const startedMidLine = truncated || skipLeading;
|
|
108
166
|
if (size === start) {
|
|
109
|
-
return { lines: [], cursor:
|
|
167
|
+
return { lines: [], cursor: cursor(start), totalBytes: size, truncated, restarted };
|
|
110
168
|
}
|
|
111
|
-
const
|
|
169
|
+
const end = cumulative ? Math.min(size, start + maxBytes) : size;
|
|
170
|
+
const buf = readAt(fd, start, end - start, path);
|
|
112
171
|
const lastNewline = buf.lastIndexOf(0x0a);
|
|
113
172
|
if (lastNewline === -1) {
|
|
114
173
|
// No complete line yet. Hold position so the line can finish —
|
|
115
174
|
// unless it is an oversized partial we already skipped into, which
|
|
116
175
|
// would otherwise be re-read forever.
|
|
117
|
-
const
|
|
176
|
+
const oversized = cumulative && end < size;
|
|
177
|
+
if (oversized)
|
|
178
|
+
missing = [missing?.[0] ?? start, end];
|
|
179
|
+
if (oversized)
|
|
180
|
+
skipLeading = true;
|
|
181
|
+
const offset = startedMidLine || oversized ? start + buf.length : start;
|
|
118
182
|
const partial = startedMidLine ? undefined : buf.toString("utf-8");
|
|
119
|
-
return { lines: [], partial, cursor:
|
|
183
|
+
return { lines: [], partial: oversized ? undefined : partial, cursor: cursor(offset), totalBytes: size, truncated: truncated || oversized, restarted, more: end < size };
|
|
120
184
|
}
|
|
121
185
|
const text = buf.subarray(0, lastNewline + 1).toString("utf-8");
|
|
122
186
|
const lines = text.split("\n");
|
|
123
187
|
lines.pop(); // trailing "" after the final newline
|
|
124
|
-
if (startedMidLine)
|
|
188
|
+
if (startedMidLine) {
|
|
125
189
|
lines.shift(); // partial first line
|
|
190
|
+
missing = [missing?.[0] ?? 0, start + buf.indexOf(0x0a) + 1];
|
|
191
|
+
coverageStart = Math.max(coverageStart, missing[1]);
|
|
192
|
+
skipLeading = false;
|
|
193
|
+
}
|
|
126
194
|
// Anything after the final newline is unterminated: hand it over
|
|
127
195
|
// separately rather than pretending it is a line.
|
|
128
196
|
const trailing = buf.subarray(lastNewline + 1);
|
|
129
|
-
const partial = trailing.length > 0 ? trailing.toString("utf-8") : undefined;
|
|
197
|
+
const partial = end === size && trailing.length > 0 ? trailing.toString("utf-8") : undefined;
|
|
130
198
|
return {
|
|
131
199
|
lines,
|
|
132
200
|
partial,
|
|
133
|
-
cursor:
|
|
201
|
+
cursor: cursor(start + lastNewline + 1),
|
|
134
202
|
totalBytes: size,
|
|
135
203
|
truncated,
|
|
136
204
|
restarted,
|
|
205
|
+
more: end < size,
|
|
137
206
|
};
|
|
138
207
|
}
|
|
139
208
|
catch (err) {
|
|
@@ -18,11 +18,29 @@
|
|
|
18
18
|
* `truncated` reports that bytes were never seen.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
import { closeSync, openSync, readSync, statSync } from "node:fs";
|
|
21
|
+
import { closeSync, openSync, readSync, statSync, fstatSync } from "node:fs";
|
|
22
22
|
|
|
23
23
|
/** Bytes of the log head kept to detect a rewrite behind our back. */
|
|
24
24
|
const HEAD_SAMPLE_BYTES = 256;
|
|
25
25
|
|
|
26
|
+
export const logReadMetrics = { bytes: 0, reads: 0, parsedEvents: 0, displayFolded: 0, healthFolded: 0 };
|
|
27
|
+
let batch: { reads: Map<string, LogRead>; events: Map<string, unknown>; ranges: Map<string, Array<{ start: number; data: Buffer }>> } | undefined;
|
|
28
|
+
|
|
29
|
+
/** Share identical ranges and decoding only during a synchronous observation. */
|
|
30
|
+
export function withLogReadBatch<T>(observe: () => T): T {
|
|
31
|
+
const previous = batch;
|
|
32
|
+
batch = { reads: new Map(), events: new Map(), ranges: new Map() };
|
|
33
|
+
try { return observe(); } finally { batch = previous; }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function parseLogEvent(line: string): any {
|
|
37
|
+
if (batch?.events.has(line)) return batch.events.get(line);
|
|
38
|
+
const event = JSON.parse(line);
|
|
39
|
+
logReadMetrics.parsedEvents++;
|
|
40
|
+
batch?.events.set(line, event);
|
|
41
|
+
return event;
|
|
42
|
+
}
|
|
43
|
+
|
|
26
44
|
/** Default ceiling on a single read: also the cold-start tail window. */
|
|
27
45
|
export const DEFAULT_MAX_READ_BYTES = 32 * 1024 * 1024; // 32 MiB
|
|
28
46
|
|
|
@@ -31,6 +49,15 @@ export const DEFAULT_MAX_READ_BYTES = 32 * 1024 * 1024; // 32 MiB
|
|
|
31
49
|
* `readAppendedLines` and store the one it returns.
|
|
32
50
|
*/
|
|
33
51
|
export interface LogCursor {
|
|
52
|
+
/** First observed byte; a tail consumer never claims coverage before it. */
|
|
53
|
+
coverageStart?: number;
|
|
54
|
+
/** Bounded envelope of skipped byte ranges, exclusive end. */
|
|
55
|
+
missing?: [number, number];
|
|
56
|
+
/** An oversized record is being discarded up to its next newline. */
|
|
57
|
+
skipLeading?: boolean;
|
|
58
|
+
generation?: string;
|
|
59
|
+
size?: number;
|
|
60
|
+
modified?: number;
|
|
34
61
|
/** Byte offset of the first unread byte; always a line boundary. */
|
|
35
62
|
offset: number;
|
|
36
63
|
/** Head bytes (latin1, byte-exact) used to detect a rewritten log. */
|
|
@@ -38,6 +65,7 @@ export interface LogCursor {
|
|
|
38
65
|
}
|
|
39
66
|
|
|
40
67
|
export interface LogRead {
|
|
68
|
+
more?: boolean;
|
|
41
69
|
/** Complete lines appended since the previous cursor, in order. */
|
|
42
70
|
lines: string[];
|
|
43
71
|
/**
|
|
@@ -63,22 +91,38 @@ function errText(err: unknown): string {
|
|
|
63
91
|
return err instanceof Error ? err.message : String(err);
|
|
64
92
|
}
|
|
65
93
|
|
|
66
|
-
function readAt(fd: number, position: number, length: number): Buffer {
|
|
94
|
+
function readAt(fd: number, position: number, length: number, path: string): Buffer {
|
|
67
95
|
const buf = Buffer.allocUnsafe(length);
|
|
96
|
+
const ranges = batch?.ranges.get(path) ?? [];
|
|
68
97
|
let filled = 0;
|
|
69
98
|
while (filled < length) {
|
|
70
|
-
const
|
|
99
|
+
const at = position + filled;
|
|
100
|
+
const cached = ranges.find(range => range.start <= at && range.start + range.data.length > at);
|
|
101
|
+
if (cached) {
|
|
102
|
+
const offset = at - cached.start;
|
|
103
|
+
const n = Math.min(length - filled, cached.data.length - offset);
|
|
104
|
+
cached.data.copy(buf, filled, offset, offset + n);
|
|
105
|
+
filled += n;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const next = Math.min(position + length, ...ranges.filter(range => range.start > at).map(range => range.start));
|
|
109
|
+
const n = readSync(fd, buf, filled, next - at, at);
|
|
71
110
|
if (n <= 0) break;
|
|
111
|
+
if (batch) {
|
|
112
|
+
ranges.push({ start: at, data: buf.subarray(filled, filled + n) });
|
|
113
|
+
batch.ranges.set(path, ranges);
|
|
114
|
+
}
|
|
72
115
|
filled += n;
|
|
116
|
+
logReadMetrics.bytes += n;
|
|
73
117
|
}
|
|
74
118
|
return filled === length ? buf : buf.subarray(0, filled);
|
|
75
119
|
}
|
|
76
120
|
|
|
77
121
|
/** Head sample as a byte-exact string, for rewrite detection. */
|
|
78
|
-
function readHead(fd: number, size: number): string {
|
|
122
|
+
function readHead(fd: number, size: number, path: string): string {
|
|
79
123
|
const length = Math.min(HEAD_SAMPLE_BYTES, size);
|
|
80
124
|
if (length <= 0) return "";
|
|
81
|
-
return readAt(fd, 0, length).toString("latin1");
|
|
125
|
+
return readAt(fd, 0, length, path).toString("latin1");
|
|
82
126
|
}
|
|
83
127
|
|
|
84
128
|
/**
|
|
@@ -103,7 +147,18 @@ export function readAppendedLines(
|
|
|
103
147
|
path: string,
|
|
104
148
|
previous?: LogCursor,
|
|
105
149
|
maxBytes: number = DEFAULT_MAX_READ_BYTES,
|
|
150
|
+
cumulative = false,
|
|
106
151
|
): LogRead {
|
|
152
|
+
const key = JSON.stringify([path, previous, maxBytes, cumulative]);
|
|
153
|
+
const cached = batch?.reads.get(key);
|
|
154
|
+
if (cached) return cached;
|
|
155
|
+
const result = readLines(path, previous, maxBytes, cumulative);
|
|
156
|
+
batch?.reads.set(key, result);
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function readLines(path: string, previous: LogCursor | undefined, maxBytes: number, cumulative: boolean): LogRead {
|
|
161
|
+
logReadMetrics.reads++;
|
|
107
162
|
const empty = (error?: string): LogRead => ({
|
|
108
163
|
lines: [],
|
|
109
164
|
cursor: previous ?? { offset: 0, head: "" },
|
|
@@ -128,59 +183,80 @@ export function readAppendedLines(
|
|
|
128
183
|
}
|
|
129
184
|
|
|
130
185
|
try {
|
|
131
|
-
const
|
|
186
|
+
const info = fstatSync(fd);
|
|
187
|
+
size = info.size;
|
|
188
|
+
const generation = `${info.dev}:${info.ino}:${info.birthtimeMs}`;
|
|
189
|
+
const head = readHead(fd, size, path);
|
|
132
190
|
// A log that shrank or whose head changed is a different log: the old
|
|
133
191
|
// offset would point into unrelated bytes. Compare only the prefix the
|
|
134
192
|
// two samples share, so a log still shorter than the sample window is
|
|
135
193
|
// not "rewritten" every time it grows.
|
|
136
194
|
const resumable = previous !== undefined
|
|
195
|
+
&& (previous.generation === undefined || previous.generation === generation)
|
|
196
|
+
&& !(previous.size === size && previous.modified !== undefined && previous.modified !== info.mtimeMs)
|
|
137
197
|
&& previous.offset <= size
|
|
138
198
|
&& headsAgree(previous.head, head);
|
|
139
199
|
const restarted = previous !== undefined && !resumable;
|
|
140
200
|
|
|
201
|
+
let coverageStart = resumable ? previous!.coverageStart ?? 0 : 0;
|
|
202
|
+
let missing = resumable ? previous!.missing : undefined;
|
|
203
|
+
let skipLeading = resumable ? previous!.skipLeading : false;
|
|
204
|
+
const cursor = (offset: number): LogCursor => ({ offset, head, generation, size, modified: info.mtimeMs, coverageStart, missing, skipLeading });
|
|
141
205
|
let start = resumable ? previous!.offset : 0;
|
|
142
206
|
let truncated = false;
|
|
143
|
-
if (size - start > maxBytes) {
|
|
207
|
+
if (!cumulative && size - start > maxBytes) {
|
|
144
208
|
// Skip ahead instead of lagging: a chatty log must not push the
|
|
145
209
|
// cursor permanently into the past.
|
|
146
210
|
start = size - maxBytes;
|
|
211
|
+
coverageStart = start;
|
|
212
|
+
missing = [missing?.[0] ?? (resumable ? previous!.offset : 0), start];
|
|
147
213
|
truncated = true;
|
|
148
214
|
}
|
|
149
215
|
// We begin mid-line whenever bytes were skipped.
|
|
150
|
-
const startedMidLine = truncated;
|
|
216
|
+
const startedMidLine = truncated || skipLeading;
|
|
151
217
|
|
|
152
218
|
if (size === start) {
|
|
153
|
-
return { lines: [], cursor:
|
|
219
|
+
return { lines: [], cursor: cursor(start), totalBytes: size, truncated, restarted };
|
|
154
220
|
}
|
|
155
221
|
|
|
156
|
-
const
|
|
222
|
+
const end = cumulative ? Math.min(size, start + maxBytes) : size;
|
|
223
|
+
const buf = readAt(fd, start, end - start, path);
|
|
157
224
|
const lastNewline = buf.lastIndexOf(0x0a);
|
|
158
225
|
if (lastNewline === -1) {
|
|
159
226
|
// No complete line yet. Hold position so the line can finish —
|
|
160
227
|
// unless it is an oversized partial we already skipped into, which
|
|
161
228
|
// would otherwise be re-read forever.
|
|
162
|
-
const
|
|
229
|
+
const oversized = cumulative && end < size;
|
|
230
|
+
if (oversized) missing = [missing?.[0] ?? start, end];
|
|
231
|
+
if (oversized) skipLeading = true;
|
|
232
|
+
const offset = startedMidLine || oversized ? start + buf.length : start;
|
|
163
233
|
const partial = startedMidLine ? undefined : buf.toString("utf-8");
|
|
164
|
-
return { lines: [], partial, cursor:
|
|
234
|
+
return { lines: [], partial: oversized ? undefined : partial, cursor: cursor(offset), totalBytes: size, truncated: truncated || oversized, restarted, more: end < size };
|
|
165
235
|
}
|
|
166
236
|
|
|
167
237
|
const text = buf.subarray(0, lastNewline + 1).toString("utf-8");
|
|
168
238
|
const lines = text.split("\n");
|
|
169
239
|
lines.pop(); // trailing "" after the final newline
|
|
170
|
-
if (startedMidLine)
|
|
240
|
+
if (startedMidLine) {
|
|
241
|
+
lines.shift(); // partial first line
|
|
242
|
+
missing = [missing?.[0] ?? 0, start + buf.indexOf(0x0a) + 1];
|
|
243
|
+
coverageStart = Math.max(coverageStart, missing[1]);
|
|
244
|
+
skipLeading = false;
|
|
245
|
+
}
|
|
171
246
|
|
|
172
247
|
// Anything after the final newline is unterminated: hand it over
|
|
173
248
|
// separately rather than pretending it is a line.
|
|
174
249
|
const trailing = buf.subarray(lastNewline + 1);
|
|
175
|
-
const partial = trailing.length > 0 ? trailing.toString("utf-8") : undefined;
|
|
250
|
+
const partial = end === size && trailing.length > 0 ? trailing.toString("utf-8") : undefined;
|
|
176
251
|
|
|
177
252
|
return {
|
|
178
253
|
lines,
|
|
179
254
|
partial,
|
|
180
|
-
cursor:
|
|
255
|
+
cursor: cursor(start + lastNewline + 1),
|
|
181
256
|
totalBytes: size,
|
|
182
257
|
truncated,
|
|
183
258
|
restarted,
|
|
259
|
+
more: end < size,
|
|
184
260
|
};
|
|
185
261
|
} catch (err) {
|
|
186
262
|
return empty(errText(err));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-subagents/managed-launch-bootstrap.mjs. Do not edit directly.
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
|
-
import { processStartToken } from "./
|
|
5
|
-
import { launchDigest } from "./
|
|
4
|
+
import { processStartToken } from "./process-identity.mjs";
|
|
5
|
+
import { launchDigest } from "./launch-digest.mjs";
|
|
6
6
|
/** Runs before the Pi CLI or any worker extension can execute task code. */
|
|
7
7
|
export function verifyManagedBootstrap(env = process.env) {
|
|
8
8
|
if (!env.PI_MANAGED_SUBAGENT)
|
|
@@ -7,13 +7,16 @@ import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
|
7
7
|
import { currentSandboxPermissions } from "./permission-policy.domain.mjs";
|
|
8
8
|
import { ownerBindingFromContext, getWorkerOperationService, resolveProductionSchemas, DEFAULT_WORKER_BRIDGE_TOOLS } from "./worker-waits.domain.mjs";
|
|
9
9
|
import { processStartToken } from "./registry.domain.mjs";
|
|
10
|
-
import {
|
|
10
|
+
import { connectWorkClient } from "./shared-work-client.mjs";
|
|
11
11
|
import { catalogHostAuthority } from "./catalog-host-admission.domain.mjs";
|
|
12
12
|
import { openSharedCatalog } from "./shared-catalog.domain.mjs";
|
|
13
13
|
import { SANDBOX_POLICY_CHANNEL } from "./permission-policy.domain.mjs";
|
|
14
14
|
import { canonicalJson } from "./operation-bridge-types.domain.mjs";
|
|
15
|
+
import { activeChildProviders } from "./config.domain.mjs";
|
|
16
|
+
import { captureLaunchContext } from "./launch-context.domain.mjs";
|
|
15
17
|
/** The fixed Pi host issues execution grants. Catalog registration grants no execution. */
|
|
16
18
|
export async function submitManagedLaunch(pi, ctx, key, tool, params) {
|
|
19
|
+
ctx = captureLaunchContext(ctx);
|
|
17
20
|
mkdirSync(getAgentDir(), { recursive: true });
|
|
18
21
|
const root = realpathSync(getAgentDir());
|
|
19
22
|
const catalog = await openSharedCatalog(ctx.cwd, root);
|
|
@@ -21,12 +24,12 @@ export async function submitManagedLaunch(pi, ctx, key, tool, params) {
|
|
|
21
24
|
const registration = JSON.parse(readFileSync(join(root, "server-registration-v1.json"), "utf8"));
|
|
22
25
|
if (registration.agentDir !== root || registration.version !== 1)
|
|
23
26
|
throw new Error("Invalid runtime registration");
|
|
24
|
-
const client = new WorkClient(join(registration.serverDir, "pi-server.sock"), root, ["runtime-subagent-launch-v1"]);
|
|
25
27
|
const directory = join(root, "subagent-launch-admission");
|
|
26
28
|
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
27
29
|
const stat = lstatSync(directory);
|
|
28
30
|
if (!stat.isDirectory() || stat.isSymbolicLink() || stat.uid !== process.getuid?.() || (stat.mode & 0o077))
|
|
29
31
|
throw new Error("Unsafe launch admission directory");
|
|
32
|
+
const client = await connectWorkClient(join(registration.serverDir, "pi-server.sock"), root, ["runtime-subagent-launch-v1"]);
|
|
30
33
|
const id = randomUUID(), secret = randomBytes(32).toString("hex"), path = join(directory, `${id}.json`);
|
|
31
34
|
let unsubscribe;
|
|
32
35
|
try {
|
|
@@ -40,7 +43,7 @@ export async function submitManagedLaunch(pi, ctx, key, tool, params) {
|
|
|
40
43
|
const payload = { version: 1, id, secretHash: createHash("sha256").update(secret).digest("hex"), instanceId: hello.instanceId,
|
|
41
44
|
owner, pid: process.pid, start: processStartToken(process.pid), projectTrusted: ctx.isProjectTrusted(),
|
|
42
45
|
background: { available: getWorkerOperationService(pi)?.assignmentContinuation === 1 || nativeBackgroundCapability(pi), tools: [...resolveProductionSchemas(pi, DEFAULT_WORKER_BRIDGE_TOOLS).schemas.keys()] },
|
|
43
|
-
permissions: currentSandboxPermissions(pi) ?? {}, settings, model: ctx.model ? `${ctx.model.provider}/${ctx.model.id}` : undefined,
|
|
46
|
+
activeProviders: activeChildProviders(pi), permissions: currentSandboxPermissions(pi) ?? {}, settings, model: ctx.model ? `${ctx.model.provider}/${ctx.model.id}` : undefined,
|
|
44
47
|
catalogAuthority, key, tool, params };
|
|
45
48
|
const staging = `${path}.tmp`;
|
|
46
49
|
writeFileSync(staging, JSON.stringify(payload), { flag: "wx", mode: 0o600 });
|
|
@@ -6,25 +6,28 @@ import { getAgentDir, type ExtensionAPI, type ExtensionContext } from "@earendil
|
|
|
6
6
|
import { currentSandboxPermissions } from "./permission-policy.ts";
|
|
7
7
|
import { ownerBindingFromContext, getWorkerOperationService, resolveProductionSchemas, DEFAULT_WORKER_BRIDGE_TOOLS } from "./worker-waits.ts";
|
|
8
8
|
import { processStartToken } from "./registry.ts";
|
|
9
|
-
import {
|
|
9
|
+
import { connectWorkClient } from "./shared-work-client.mjs";
|
|
10
10
|
import { catalogHostAuthority } from "./catalog-host-admission.ts";
|
|
11
11
|
import { openSharedCatalog } from "./shared-catalog.ts";
|
|
12
12
|
import { SANDBOX_POLICY_CHANNEL } from "./permission-policy.ts";
|
|
13
13
|
import { canonicalJson } from "./operation-bridge-types.ts";
|
|
14
|
+
import { activeChildProviders } from "./config.ts";
|
|
15
|
+
import { captureLaunchContext } from "./launch-context.ts";
|
|
14
16
|
|
|
15
17
|
/** The fixed Pi host issues execution grants. Catalog registration grants no execution. */
|
|
16
18
|
export async function submitManagedLaunch(pi: ExtensionAPI, ctx: ExtensionContext, key: string, tool: string, params: unknown) {
|
|
19
|
+
ctx = captureLaunchContext(ctx);
|
|
17
20
|
mkdirSync(getAgentDir(), { recursive: true });
|
|
18
21
|
const root = realpathSync(getAgentDir());
|
|
19
22
|
const catalog = await openSharedCatalog(ctx.cwd, root);
|
|
20
23
|
catalog.close();
|
|
21
24
|
const registration = JSON.parse(readFileSync(join(root, "server-registration-v1.json"), "utf8"));
|
|
22
25
|
if (registration.agentDir !== root || registration.version !== 1) throw new Error("Invalid runtime registration");
|
|
23
|
-
const client = new WorkClient(join(registration.serverDir, "pi-server.sock"), root, ["runtime-subagent-launch-v1"]);
|
|
24
26
|
const directory = join(root, "subagent-launch-admission");
|
|
25
27
|
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
26
28
|
const stat = lstatSync(directory);
|
|
27
29
|
if (!stat.isDirectory() || stat.isSymbolicLink() || stat.uid !== process.getuid?.() || (stat.mode & 0o077)) throw new Error("Unsafe launch admission directory");
|
|
30
|
+
const client = await connectWorkClient(join(registration.serverDir, "pi-server.sock"), root, ["runtime-subagent-launch-v1"]);
|
|
28
31
|
const id = randomUUID(), secret = randomBytes(32).toString("hex"), path = join(directory, `${id}.json`);
|
|
29
32
|
let unsubscribe: unknown;
|
|
30
33
|
try {
|
|
@@ -37,7 +40,7 @@ export async function submitManagedLaunch(pi: ExtensionAPI, ctx: ExtensionContex
|
|
|
37
40
|
const payload = { version: 1, id, secretHash: createHash("sha256").update(secret).digest("hex"), instanceId: hello.instanceId,
|
|
38
41
|
owner, pid: process.pid, start: processStartToken(process.pid), projectTrusted: ctx.isProjectTrusted(),
|
|
39
42
|
background: { available: getWorkerOperationService(pi)?.assignmentContinuation === 1 || nativeBackgroundCapability(pi), tools: [...resolveProductionSchemas(pi, DEFAULT_WORKER_BRIDGE_TOOLS).schemas.keys()] },
|
|
40
|
-
permissions: currentSandboxPermissions(pi) ?? {}, settings, model: ctx.model ? `${ctx.model.provider}/${ctx.model.id}` : undefined,
|
|
43
|
+
activeProviders: activeChildProviders(pi), permissions: currentSandboxPermissions(pi) ?? {}, settings, model: ctx.model ? `${ctx.model.provider}/${ctx.model.id}` : undefined,
|
|
41
44
|
catalogAuthority, key, tool, params };
|
|
42
45
|
const staging = `${path}.tmp`;
|
|
43
46
|
writeFileSync(staging, JSON.stringify(payload), { flag: "wx", mode: 0o600 });
|