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,8 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { createProcessListToolDefinition } from "./shared-task-process-list.ts";
|
|
3
|
+
|
|
4
|
+
/** Keep the fixed, bounded inventory contract when no task sandbox is active. */
|
|
5
|
+
export default function childProcessList(pi: ExtensionAPI): void {
|
|
6
|
+
const tool = createProcessListToolDefinition(process.cwd(), { requireLaunchPlan: () => ({ confined: false }) }, () => "read");
|
|
7
|
+
pi.registerTool(tool as Parameters<ExtensionAPI["registerTool"]>[0]);
|
|
8
|
+
}
|
|
@@ -9,12 +9,13 @@
|
|
|
9
9
|
* `defaultTools` absent → the built-in SAFE_DEFAULT_TOOLS.
|
|
10
10
|
* `defaultSkills` absent → the child discovers the user-level skills catalog.
|
|
11
11
|
*/
|
|
12
|
-
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
12
|
+
import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
13
13
|
import { fileURLToPath } from "node:url";
|
|
14
14
|
import { dirname, isAbsolute, join } from "node:path";
|
|
15
15
|
import { homedir } from "node:os";
|
|
16
|
+
import { toolPackage, supportsChildProvider } from "./shared-task-tools.domain.mjs";
|
|
16
17
|
import { SELF_SPEC } from "./extensions.domain.mjs";
|
|
17
|
-
import { installedPackage } from "./child-dependencies.mjs";
|
|
18
|
+
import { installedPackage, packageRoot } from "./child-dependencies.mjs";
|
|
18
19
|
import { isDelegationMode } from "./delegation.domain.mjs";
|
|
19
20
|
import { normalizeSkillExposure } from "./skills.domain.mjs";
|
|
20
21
|
import { validatedTimingMinutes } from "./timing.domain.mjs";
|
|
@@ -169,6 +170,52 @@ function writeConfigSettings(settings, path) {
|
|
|
169
170
|
export function normalizeTools(list) {
|
|
170
171
|
return list.split(",").map((t) => t.trim()).filter(Boolean).join(",");
|
|
171
172
|
}
|
|
173
|
+
export const ORDINARY_TOOL_PROVIDERS = {
|
|
174
|
+
apply_patch: join(selfDir(), "child-apply-patch.ts"),
|
|
175
|
+
process_list: join(selfDir(), "child-process-list.ts"),
|
|
176
|
+
};
|
|
177
|
+
/** Check the owning package even when a mapping points directly to one of its files. */
|
|
178
|
+
export function supportedChildEntrypoint(name, pkg, path) {
|
|
179
|
+
return supportsChildProvider(name, pkg, packageRoot(path) ?? path);
|
|
180
|
+
}
|
|
181
|
+
/** Capture exact user-installed entrypoints already active in the foreground. */
|
|
182
|
+
export function activeChildProviders(pi) {
|
|
183
|
+
const active = new Set(pi.getActiveTools?.() ?? []);
|
|
184
|
+
const paths = new Map();
|
|
185
|
+
const seen = new Set();
|
|
186
|
+
for (const tool of pi.getAllTools?.() ?? []) {
|
|
187
|
+
if (!active.has(tool.name))
|
|
188
|
+
continue;
|
|
189
|
+
// The SDK reports active names. Conflicting registrations have no unique owner.
|
|
190
|
+
if (seen.has(tool.name)) {
|
|
191
|
+
paths.delete(tool.name);
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
seen.add(tool.name);
|
|
195
|
+
if (tool.sourceInfo?.scope !== "user")
|
|
196
|
+
continue;
|
|
197
|
+
const owner = toolPackage(tool);
|
|
198
|
+
if (!owner || !supportsChildProvider(tool.name, owner.package, owner.root))
|
|
199
|
+
continue;
|
|
200
|
+
try {
|
|
201
|
+
const path = realpathSync(tool.sourceInfo.path);
|
|
202
|
+
if (!statSync(path).isFile() || !supportedChildEntrypoint(tool.name, owner.package, path))
|
|
203
|
+
continue;
|
|
204
|
+
paths.set(tool.name, path);
|
|
205
|
+
}
|
|
206
|
+
catch { /* An unavailable entrypoint cannot supply a new worker. */ }
|
|
207
|
+
}
|
|
208
|
+
return Object.fromEntries(paths);
|
|
209
|
+
}
|
|
210
|
+
export function ordinaryChildConfig(config, activeProviders = {}) {
|
|
211
|
+
const packaged = config.toolExtensions === null ? undefined : bundledConfig().toolExtensions;
|
|
212
|
+
return { ...config, toolExtensions: { ...activeProviders, ...ORDINARY_TOOL_PROVIDERS, ...packaged, ...config.toolExtensions } };
|
|
213
|
+
}
|
|
214
|
+
export function addEditablePatch(names, excluded) {
|
|
215
|
+
const editable = names.some(name => (name === "edit" || name === "write") && !excluded.has(name));
|
|
216
|
+
if (editable && !excluded.has("apply_patch") && !names.includes("apply_patch"))
|
|
217
|
+
names.push("apply_patch");
|
|
218
|
+
}
|
|
172
219
|
/** This package's own root — the extension dir, which is also `self`. */
|
|
173
220
|
export function selfDir() {
|
|
174
221
|
return dirname(fileURLToPath(import.meta.url));
|
|
@@ -9,12 +9,14 @@
|
|
|
9
9
|
* `defaultSkills` absent → the child discovers the user-level skills catalog.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
12
|
+
import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
13
13
|
import { fileURLToPath } from "node:url";
|
|
14
14
|
import { dirname, isAbsolute, join } from "node:path";
|
|
15
15
|
import { homedir } from "node:os";
|
|
16
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
17
|
+
import { toolPackage, supportsChildProvider } from "./shared-task-tools.ts";
|
|
16
18
|
import { SELF_SPEC } from "./extensions.ts";
|
|
17
|
-
import { installedPackage } from "./child-dependencies.mjs";
|
|
19
|
+
import { installedPackage, packageRoot } from "./child-dependencies.mjs";
|
|
18
20
|
import { isDelegationMode, type DelegationMode } from "./delegation.ts";
|
|
19
21
|
import { normalizeSkillExposure } from "./skills.ts";
|
|
20
22
|
import { validatedTimingMinutes, type TimingSettings } from "./timing.ts";
|
|
@@ -251,6 +253,48 @@ export function normalizeTools(list: string): string {
|
|
|
251
253
|
return list.split(",").map((t) => t.trim()).filter(Boolean).join(",");
|
|
252
254
|
}
|
|
253
255
|
|
|
256
|
+
export const ORDINARY_TOOL_PROVIDERS: Readonly<Record<string, string>> = {
|
|
257
|
+
apply_patch: join(selfDir(), "child-apply-patch.ts"),
|
|
258
|
+
process_list: join(selfDir(), "child-process-list.ts"),
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
/** Check the owning package even when a mapping points directly to one of its files. */
|
|
262
|
+
export function supportedChildEntrypoint(name: string, pkg: string, path: string): boolean {
|
|
263
|
+
return supportsChildProvider(name, pkg, packageRoot(path) ?? path);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** Capture exact user-installed entrypoints already active in the foreground. */
|
|
267
|
+
export function activeChildProviders(pi: Pick<ExtensionAPI, "getActiveTools" | "getAllTools">): Record<string, string> {
|
|
268
|
+
const active = new Set(pi.getActiveTools?.() ?? []);
|
|
269
|
+
const paths = new Map<string, string>();
|
|
270
|
+
const seen = new Set<string>();
|
|
271
|
+
for (const tool of pi.getAllTools?.() ?? []) {
|
|
272
|
+
if (!active.has(tool.name)) continue;
|
|
273
|
+
// The SDK reports active names. Conflicting registrations have no unique owner.
|
|
274
|
+
if (seen.has(tool.name)) { paths.delete(tool.name); continue; }
|
|
275
|
+
seen.add(tool.name);
|
|
276
|
+
if (tool.sourceInfo?.scope !== "user") continue;
|
|
277
|
+
const owner = toolPackage(tool);
|
|
278
|
+
if (!owner || !supportsChildProvider(tool.name, owner.package, owner.root)) continue;
|
|
279
|
+
try {
|
|
280
|
+
const path = realpathSync(tool.sourceInfo.path);
|
|
281
|
+
if (!statSync(path).isFile() || !supportedChildEntrypoint(tool.name, owner.package, path)) continue;
|
|
282
|
+
paths.set(tool.name, path);
|
|
283
|
+
} catch { /* An unavailable entrypoint cannot supply a new worker. */ }
|
|
284
|
+
}
|
|
285
|
+
return Object.fromEntries(paths);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export function ordinaryChildConfig(config: SubagentConfig, activeProviders: Record<string, string> = {}): SubagentConfig {
|
|
289
|
+
const packaged = config.toolExtensions === null ? undefined : bundledConfig().toolExtensions;
|
|
290
|
+
return { ...config, toolExtensions: { ...activeProviders, ...ORDINARY_TOOL_PROVIDERS, ...packaged, ...config.toolExtensions } };
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export function addEditablePatch(names: string[], excluded: ReadonlySet<string>): void {
|
|
294
|
+
const editable = names.some(name => (name === "edit" || name === "write") && !excluded.has(name));
|
|
295
|
+
if (editable && !excluded.has("apply_patch") && !names.includes("apply_patch")) names.push("apply_patch");
|
|
296
|
+
}
|
|
297
|
+
|
|
254
298
|
/** This package's own root — the extension dir, which is also `self`. */
|
|
255
299
|
export function selfDir(): string {
|
|
256
300
|
return dirname(fileURLToPath(import.meta.url));
|
|
@@ -13,8 +13,12 @@ export function intersectContinuationPermissions(captured, current) {
|
|
|
13
13
|
const intersect = (old, fresh) => {
|
|
14
14
|
if (!old || !fresh)
|
|
15
15
|
throw new Error("Continuation permission profile unavailable");
|
|
16
|
+
if (!fresh.enabled)
|
|
17
|
+
return old.enabled ? { ...old } : { ...fresh };
|
|
18
|
+
if (!old.enabled)
|
|
19
|
+
return { ...fresh };
|
|
16
20
|
const access = ["off", "read", "write", "read-write"];
|
|
17
|
-
const value = { ...fresh
|
|
21
|
+
const value = { ...fresh };
|
|
18
22
|
for (const key of ["projectFiles", "outsideProject", "storedCredentials"]) {
|
|
19
23
|
if (!access.includes(old[key]) || !access.includes(fresh[key]))
|
|
20
24
|
throw new Error("Invalid continuation permission profile");
|
|
@@ -10,8 +10,10 @@ export function intersectContinuationPermissions(captured: any, current: any): a
|
|
|
10
10
|
.sort((a, b) => a.name.localeCompare(b.name) || a.package.localeCompare(b.package)) };
|
|
11
11
|
const intersect = (old: any, fresh: any) => {
|
|
12
12
|
if (!old || !fresh) throw new Error("Continuation permission profile unavailable");
|
|
13
|
+
if (!fresh.enabled) return old.enabled ? { ...old } : { ...fresh };
|
|
14
|
+
if (!old.enabled) return { ...fresh };
|
|
13
15
|
const access = ["off", "read", "write", "read-write"];
|
|
14
|
-
const value = { ...fresh
|
|
16
|
+
const value = { ...fresh };
|
|
15
17
|
for (const key of ["projectFiles", "outsideProject", "storedCredentials"]) {
|
|
16
18
|
if (!access.includes(old[key]) || !access.includes(fresh[key])) throw new Error("Invalid continuation permission profile");
|
|
17
19
|
value[key] = access[Math.min(access.indexOf(old[key]), access.indexOf(fresh[key]))];
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-subagents/continuation-runtime.ts. Do not edit directly.
|
|
2
|
+
/** Select a saved, installed worker closure without changing the server owner. */
|
|
3
|
+
import { readFileSync, realpathSync, statSync } from "node:fs";
|
|
4
|
+
import { basename, dirname, join, normalize, sep } from "node:path";
|
|
5
|
+
const DOMAIN = join("src", "runtime", "domain", "subagents");
|
|
6
|
+
export function managedRuntimeRoot(domain) {
|
|
7
|
+
if (!domain.endsWith(`${sep}${DOMAIN}`))
|
|
8
|
+
return undefined;
|
|
9
|
+
const root = domain.slice(0, -(DOMAIN.length + 1));
|
|
10
|
+
return basename(dirname(root)) === "releases" && /^[a-f0-9]{64}$/.test(basename(root)) ? root : undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Only sibling, published releases are eligible. User extensions retain their
|
|
14
|
+
* original identity check. Permission policy is still generated by the current
|
|
15
|
+
* server; a saved runtime does not grandfather its previous permission grants.
|
|
16
|
+
* Published releases are retained by the installer (it removes staging only).
|
|
17
|
+
* Any future release GC must treat LaunchRecipe.runtimeRoot as a reference.
|
|
18
|
+
*/
|
|
19
|
+
export function selectContinuationRuntime(options) {
|
|
20
|
+
const current = managedRuntimeRoot(options.currentDir);
|
|
21
|
+
if (!current || !options.recipe)
|
|
22
|
+
return undefined;
|
|
23
|
+
const recipe = options.recipe;
|
|
24
|
+
// Upgrade recipes written before runtimeRoot existed using the mandatory
|
|
25
|
+
// harness control, never a user-selected/custom extension path.
|
|
26
|
+
const args = recipe.baseExtensionArgs ?? recipe.extensionArgs ?? [];
|
|
27
|
+
const steer = args.find((value, index) => args[index - 1] === "--extension" && value.endsWith(`${sep}${DOMAIN}${sep}child-steer.ts`));
|
|
28
|
+
const saved = recipe.runtimeRoot ?? (steer ? managedRuntimeRoot(dirname(steer)) : undefined);
|
|
29
|
+
if (!saved || saved === current)
|
|
30
|
+
return undefined;
|
|
31
|
+
const unavailable = (detail) => {
|
|
32
|
+
throw new Error(`Cannot resume: saved runtime ${basename(saved)} unavailable (${detail}). Restore that release or explicitly launch a replacement conversation; no worker was started.`);
|
|
33
|
+
};
|
|
34
|
+
if (normalize(saved) !== saved || dirname(saved) !== dirname(current) || !/^[a-f0-9]{64}$/.test(basename(saved))) {
|
|
35
|
+
return unavailable("not a sibling managed release");
|
|
36
|
+
}
|
|
37
|
+
function manifest(root) {
|
|
38
|
+
let value;
|
|
39
|
+
try {
|
|
40
|
+
if (realpathSync(root) !== root)
|
|
41
|
+
return unavailable("release path is not canonical");
|
|
42
|
+
value = JSON.parse(readFileSync(join(root, "runtime.json"), "utf8"));
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return unavailable("missing or unreadable release manifest");
|
|
46
|
+
}
|
|
47
|
+
if (value.format !== 1 || value.root !== root || value.build?.contentId !== basename(root)
|
|
48
|
+
|| value.node !== join(root, "node/bin/node") || value.installRoot !== dirname(dirname(root))) {
|
|
49
|
+
return unavailable("invalid release manifest");
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
const before = manifest(saved), now = manifest(current);
|
|
54
|
+
// These releases share the existing v1 worker admission/policy/bridge wire
|
|
55
|
+
// formats. Refuse SDK, Node, platform or protocol transitions rather than
|
|
56
|
+
// assuming that a new server can host any historic worker.
|
|
57
|
+
if (before.build.protocolVersion !== 1 || now.build.protocolVersion !== 1
|
|
58
|
+
|| ["piSdkVersion", "nodeVersion", "platform"].some(key => !before.build[key] || before.build[key] !== now.build[key])) {
|
|
59
|
+
throw new Error(`Cannot resume: saved runtime ${basename(saved)} is incompatible with the current worker protocol, SDK or platform. Explicit replacement is required; no worker was started.`);
|
|
60
|
+
}
|
|
61
|
+
function required(path, directory = false) {
|
|
62
|
+
try {
|
|
63
|
+
const stat = statSync(path);
|
|
64
|
+
if (realpathSync(path) !== path || !(stat.isFile() || directory && stat.isDirectory()))
|
|
65
|
+
return unavailable("worker file is missing or redirected");
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return unavailable("worker file is missing or unreadable");
|
|
69
|
+
}
|
|
70
|
+
return path;
|
|
71
|
+
}
|
|
72
|
+
const node = required(before.node);
|
|
73
|
+
const mapPath = (path) => path.startsWith(`${current}${sep}`)
|
|
74
|
+
? required(join(saved, path.slice(current.length + 1)), true) : path;
|
|
75
|
+
return {
|
|
76
|
+
root: saved,
|
|
77
|
+
mapPath,
|
|
78
|
+
mapArgs: values => values.map((value, index) => values[index - 1] === "--extension" ? mapPath(value) : value),
|
|
79
|
+
command: command => {
|
|
80
|
+
// Only executable slots are rewritten. A prompt or arbitrary CLI
|
|
81
|
+
// value that happens to contain a runtime path must stay untouched.
|
|
82
|
+
const fileArgs = [...command.fileArgs];
|
|
83
|
+
fileArgs[0] = mapPath(fileArgs[0]);
|
|
84
|
+
if (basename(fileArgs[0]) === "task-runtime.mjs")
|
|
85
|
+
fileArgs[1] = mapPath(fileArgs[1]);
|
|
86
|
+
return { file: node, fileArgs };
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** Select a saved, installed worker closure without changing the server owner. */
|
|
2
|
+
import { readFileSync, realpathSync, statSync } from "node:fs";
|
|
3
|
+
import { basename, dirname, join, normalize, sep } from "node:path";
|
|
4
|
+
|
|
5
|
+
const DOMAIN = join("src", "runtime", "domain", "subagents");
|
|
6
|
+
type Recipe = { runtimeRoot?: string; baseExtensionArgs?: readonly string[]; extensionArgs?: readonly string[] };
|
|
7
|
+
type Command = { file: string; fileArgs: string[] };
|
|
8
|
+
|
|
9
|
+
export function managedRuntimeRoot(domain: string): string | undefined {
|
|
10
|
+
if (!domain.endsWith(`${sep}${DOMAIN}`)) return undefined;
|
|
11
|
+
const root = domain.slice(0, -(DOMAIN.length + 1));
|
|
12
|
+
return basename(dirname(root)) === "releases" && /^[a-f0-9]{64}$/.test(basename(root)) ? root : undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ContinuationRuntime {
|
|
16
|
+
root: string;
|
|
17
|
+
mapPath(path: string): string;
|
|
18
|
+
mapArgs(args: readonly string[]): string[];
|
|
19
|
+
command(command: Command): Command;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Only sibling, published releases are eligible. User extensions retain their
|
|
24
|
+
* original identity check. Permission policy is still generated by the current
|
|
25
|
+
* server; a saved runtime does not grandfather its previous permission grants.
|
|
26
|
+
* Published releases are retained by the installer (it removes staging only).
|
|
27
|
+
* Any future release GC must treat LaunchRecipe.runtimeRoot as a reference.
|
|
28
|
+
*/
|
|
29
|
+
export function selectContinuationRuntime(options: { currentDir: string; recipe?: Recipe }): ContinuationRuntime | undefined {
|
|
30
|
+
const current = managedRuntimeRoot(options.currentDir);
|
|
31
|
+
if (!current || !options.recipe) return undefined;
|
|
32
|
+
const recipe = options.recipe;
|
|
33
|
+
// Upgrade recipes written before runtimeRoot existed using the mandatory
|
|
34
|
+
// harness control, never a user-selected/custom extension path.
|
|
35
|
+
const args = recipe.baseExtensionArgs ?? recipe.extensionArgs ?? [];
|
|
36
|
+
const steer = args.find((value, index) => args[index - 1] === "--extension" && value.endsWith(`${sep}${DOMAIN}${sep}child-steer.ts`));
|
|
37
|
+
const saved = recipe.runtimeRoot ?? (steer ? managedRuntimeRoot(dirname(steer)) : undefined);
|
|
38
|
+
if (!saved || saved === current) return undefined;
|
|
39
|
+
const unavailable = (detail: string): never => {
|
|
40
|
+
throw new Error(`Cannot resume: saved runtime ${basename(saved)} unavailable (${detail}). Restore that release or explicitly launch a replacement conversation; no worker was started.`);
|
|
41
|
+
};
|
|
42
|
+
if (normalize(saved) !== saved || dirname(saved) !== dirname(current) || !/^[a-f0-9]{64}$/.test(basename(saved))) {
|
|
43
|
+
return unavailable("not a sibling managed release");
|
|
44
|
+
}
|
|
45
|
+
function manifest(root: string) {
|
|
46
|
+
let value;
|
|
47
|
+
try {
|
|
48
|
+
if (realpathSync(root) !== root) return unavailable("release path is not canonical");
|
|
49
|
+
value = JSON.parse(readFileSync(join(root, "runtime.json"), "utf8"));
|
|
50
|
+
} catch { return unavailable("missing or unreadable release manifest"); }
|
|
51
|
+
if (value.format !== 1 || value.root !== root || value.build?.contentId !== basename(root)
|
|
52
|
+
|| value.node !== join(root, "node/bin/node") || value.installRoot !== dirname(dirname(root))) {
|
|
53
|
+
return unavailable("invalid release manifest");
|
|
54
|
+
}
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
const before = manifest(saved), now = manifest(current);
|
|
58
|
+
// These releases share the existing v1 worker admission/policy/bridge wire
|
|
59
|
+
// formats. Refuse SDK, Node, platform or protocol transitions rather than
|
|
60
|
+
// assuming that a new server can host any historic worker.
|
|
61
|
+
if (before.build.protocolVersion !== 1 || now.build.protocolVersion !== 1
|
|
62
|
+
|| ["piSdkVersion", "nodeVersion", "platform"].some(key => !before.build[key] || before.build[key] !== now.build[key])) {
|
|
63
|
+
throw new Error(`Cannot resume: saved runtime ${basename(saved)} is incompatible with the current worker protocol, SDK or platform. Explicit replacement is required; no worker was started.`);
|
|
64
|
+
}
|
|
65
|
+
function required(path: string, directory = false): string {
|
|
66
|
+
try {
|
|
67
|
+
const stat = statSync(path);
|
|
68
|
+
if (realpathSync(path) !== path || !(stat.isFile() || directory && stat.isDirectory())) return unavailable("worker file is missing or redirected");
|
|
69
|
+
} catch { return unavailable("worker file is missing or unreadable"); }
|
|
70
|
+
return path;
|
|
71
|
+
}
|
|
72
|
+
const node = required(before.node);
|
|
73
|
+
const mapPath = (path: string): string => path.startsWith(`${current}${sep}`)
|
|
74
|
+
? required(join(saved, path.slice(current.length + 1)), true) : path;
|
|
75
|
+
return {
|
|
76
|
+
root: saved,
|
|
77
|
+
mapPath,
|
|
78
|
+
mapArgs: values => values.map((value, index) => values[index - 1] === "--extension" ? mapPath(value) : value),
|
|
79
|
+
command: command => {
|
|
80
|
+
// Only executable slots are rewritten. A prompt or arbitrary CLI
|
|
81
|
+
// value that happens to contain a runtime path must stay untouched.
|
|
82
|
+
const fileArgs = [...command.fileArgs];
|
|
83
|
+
fileArgs[0] = mapPath(fileArgs[0]!);
|
|
84
|
+
if (basename(fileArgs[0]!) === "task-runtime.mjs") fileArgs[1] = mapPath(fileArgs[1]!);
|
|
85
|
+
return { file: node, fileArgs };
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
* A builtin needs no extension, so it never counts as unmapped.
|
|
35
35
|
*/
|
|
36
36
|
// codemode is supplied by the harness child adapter, not a discovered package.
|
|
37
|
-
export const BUILTIN_TOOLS = ["read", "bash", "edit", "write", "codemode"];
|
|
37
|
+
export const BUILTIN_TOOLS = ["read", "bash", "edit", "write", "grep", "find", "ls", "codemode"];
|
|
38
38
|
/** Marker spec meaning "this extension's own package" (for allow_nested). */
|
|
39
39
|
export const SELF_SPEC = "self";
|
|
40
40
|
/**
|
|
@@ -87,11 +87,11 @@ export function toolList(tools) {
|
|
|
87
87
|
* @returns {{mode: "isolated"|"clean"|"inherit", specs: string[], unmapped: string[], reasons: Record<string,string[]>}}
|
|
88
88
|
* mode — "isolated" passes --no-extensions + explicit -e (the default);
|
|
89
89
|
* "clean" passes --no-extensions with no -e;
|
|
90
|
-
* "inherit"
|
|
90
|
+
* "inherit" keeps discovery and adds explicitly selected mappings.
|
|
91
91
|
* specs — extension specs to load, deduped, in a stable order.
|
|
92
92
|
* unmapped — requested tools that are neither builtin nor mapped to an
|
|
93
|
-
* extension.
|
|
94
|
-
*
|
|
93
|
+
* extension. Admission rejects a known missing required provider.
|
|
94
|
+
* Preflight verifies registrations supplied by loaded extensions.
|
|
95
95
|
* reasons — spec -> what pulled it in, for the spawn diagnostic.
|
|
96
96
|
*/
|
|
97
97
|
export function resolveExtensions(a = {}) {
|
|
@@ -107,13 +107,11 @@ export function resolveExtensions(a = {}) {
|
|
|
107
107
|
};
|
|
108
108
|
// allow_nested is honored in every mode: it is an explicit caller request,
|
|
109
109
|
// and without our own package loaded the child has no subagent tools at all.
|
|
110
|
-
|
|
110
|
+
const inherit = cfg.inheritExtensions === true;
|
|
111
|
+
if (a.allowNested && !inherit)
|
|
111
112
|
add(SELF_SPEC, "allow_nested");
|
|
112
|
-
if (cfg.inheritExtensions === true) {
|
|
113
|
-
return { mode: "inherit", specs: [], unmapped: [], reasons: {} };
|
|
114
|
-
}
|
|
115
113
|
if (a.clean === true) {
|
|
116
|
-
return { mode: "clean", specs, unmapped: [], reasons };
|
|
114
|
+
return { mode: inherit ? "inherit" : "clean", specs, unmapped: [], reasons };
|
|
117
115
|
}
|
|
118
116
|
const toolMap = cfg.toolExtensions ?? {};
|
|
119
117
|
const unmapped = [];
|
|
@@ -122,13 +120,15 @@ export function resolveExtensions(a = {}) {
|
|
|
122
120
|
continue;
|
|
123
121
|
const mapped = toSpecList(toolMap[tool]);
|
|
124
122
|
if (mapped.length === 0) {
|
|
125
|
-
if (!unmapped.includes(tool))
|
|
123
|
+
if (!inherit && !unmapped.includes(tool))
|
|
126
124
|
unmapped.push(tool);
|
|
127
125
|
continue;
|
|
128
126
|
}
|
|
129
127
|
for (const spec of mapped)
|
|
130
128
|
add(spec, `tool:${tool}`);
|
|
131
129
|
}
|
|
130
|
+
if (inherit)
|
|
131
|
+
return { mode: "inherit", specs, unmapped, reasons };
|
|
132
132
|
// Model auth is not tool-shaped: xai/grok needs pi-xai-oauth loaded or the
|
|
133
133
|
// child cannot authenticate at all, whatever tools it was granted. A user
|
|
134
134
|
// entry for a provider wins over the built-in one, including an empty list
|
|
@@ -150,9 +150,7 @@ export function resolveExtensions(a = {}) {
|
|
|
150
150
|
* @returns {{args: string[], missing: string[]}}
|
|
151
151
|
*/
|
|
152
152
|
export function extensionArgs(resolution, resolvePath) {
|
|
153
|
-
|
|
154
|
-
return { args: [], missing: [] };
|
|
155
|
-
const args = ["--no-extensions"];
|
|
153
|
+
const args = resolution.mode === "inherit" ? [] : ["--no-extensions"];
|
|
156
154
|
const missing = [];
|
|
157
155
|
for (const spec of resolution.specs) {
|
|
158
156
|
const path = resolvePath(spec);
|
|
@@ -15,6 +15,18 @@ import { parseRunForLifecycle } from "./parse.domain.mjs";
|
|
|
15
15
|
import { canExitFinalize, effectiveStatus, isFinalResultStatus, readMeta, updateParkRecord, writeMeta, } from "./registry.domain.mjs";
|
|
16
16
|
import { fmtElapsed, fmtSpend } from "./widget.domain.mjs";
|
|
17
17
|
import { evaluateParkDisposition } from "./worker-waits.domain.mjs";
|
|
18
|
+
import { reconcileRun } from "./health.domain.mjs";
|
|
19
|
+
/** The current management owner calls this only for an interrupted, unobserved writer. */
|
|
20
|
+
export function reconcileInterruptedRun(meta, probe, now, hooks = {}) {
|
|
21
|
+
const reconciliation = reconcileRun(meta, probe, now);
|
|
22
|
+
if ((meta.status === "running" || meta.status === "orphaned") && meta.supervisionInterruptedAt !== undefined && reconciliation.status === "lost") {
|
|
23
|
+
const run = parseRunForLifecycle(meta.id);
|
|
24
|
+
if (run.sawEnd && run.unmatchedToolCalls.length === 0) {
|
|
25
|
+
return { reconciliation, finalization: finalizeRun(meta.id, null, hooks) };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return { reconciliation };
|
|
29
|
+
}
|
|
18
30
|
/**
|
|
19
31
|
* Finalize a run once its child exits. Idempotent: a run already marked
|
|
20
32
|
* terminal is left alone. Persists lifecycle classification + failureReason
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
} from "./registry.ts";
|
|
27
27
|
import { fmtElapsed, fmtSpend } from "./widget.ts";
|
|
28
28
|
import { evaluateParkDisposition, type ParkDisposition } from "./worker-waits.ts";
|
|
29
|
+
import { reconcileRun, type ProcessProbe, type ReconcileResult } from "./health.ts";
|
|
29
30
|
|
|
30
31
|
export interface FinalizeHooks {
|
|
31
32
|
renderWidget?: () => void;
|
|
@@ -45,6 +46,20 @@ export interface FinalizeResult {
|
|
|
45
46
|
park?: ParkDisposition;
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
/** The current management owner calls this only for an interrupted, unobserved writer. */
|
|
50
|
+
export function reconcileInterruptedRun(meta: RunMeta, probe: ProcessProbe, now: number, hooks: FinalizeHooks = {}): {
|
|
51
|
+
reconciliation: ReconcileResult; finalization?: FinalizeResult;
|
|
52
|
+
} {
|
|
53
|
+
const reconciliation = reconcileRun(meta, probe, now);
|
|
54
|
+
if ((meta.status === "running" || meta.status === "orphaned") && meta.supervisionInterruptedAt !== undefined && reconciliation.status === "lost") {
|
|
55
|
+
const run = parseRunForLifecycle(meta.id);
|
|
56
|
+
if (run.sawEnd && run.unmatchedToolCalls.length === 0) {
|
|
57
|
+
return { reconciliation, finalization: finalizeRun(meta.id, null, hooks) };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { reconciliation };
|
|
61
|
+
}
|
|
62
|
+
|
|
48
63
|
/**
|
|
49
64
|
* Finalize a run once its child exits. Idempotent: a run already marked
|
|
50
65
|
* terminal is left alone. Persists lifecycle classification + failureReason
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-subagents/goal-provider.ts. Do not edit directly.
|
|
2
|
+
import { activateWorkObservation, hasWorkObservationContext, workObservation, onWorkObservation } from "./work-observation.domain.mjs";
|
|
2
3
|
import { belongsToOrigin, effectiveStatus, isPendingPark, listMetasForParent, onMetaChanged, readParkRecord, } from "./registry.domain.mjs";
|
|
3
4
|
const GOAL_READY_EVENT = "pi-better-goal:ready";
|
|
4
5
|
const GOAL_REGISTER_PROVIDER_EVENT = "pi-better-goal:register-provider";
|
|
@@ -30,13 +31,40 @@ function parkActivity(meta) {
|
|
|
30
31
|
...(record.resumedBy ? { resumedBy: record.resumedBy } : {}),
|
|
31
32
|
};
|
|
32
33
|
}
|
|
34
|
+
function observedActivity(observed, ctx) {
|
|
35
|
+
if (observed?.status !== "ready")
|
|
36
|
+
throw new Error(observed?.reason ?? "Subagent activity is unverified");
|
|
37
|
+
return {
|
|
38
|
+
providerId: "subagents", label: "Subagents", nextDeadline: observed.nextDeadline ?? null,
|
|
39
|
+
items: observed.rows.filter((row) => !ctx || (belongsToOrigin(row.meta, { cwd: ctx.cwd, sessionId: ctx.sessionManager.getSessionId() }) &&
|
|
40
|
+
(!row.meta.callbackOrigin?.branchId || ctx.sessionManager.getBranch().some(entry => entry.id === row.meta.callbackOrigin.branchId)))).map((row) => {
|
|
41
|
+
const status = row.assignment.state;
|
|
42
|
+
const active = status === "running" || status === "waiting";
|
|
43
|
+
return { id: row.meta.id, label: row.meta.name, status, active, terminal: !active,
|
|
44
|
+
attention: !active && status !== "completed", unhealthy: row.meta.status === "orphaned",
|
|
45
|
+
startedAt: row.meta.startedAt, endedAt: row.meta.endedAt,
|
|
46
|
+
details: { assignment: row.assignment, sourceRevision: row.sourceRevision } };
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
33
50
|
export function registerSubagentsGoalProvider(pi) {
|
|
34
51
|
const emitProvider = () => {
|
|
35
52
|
pi.events?.emit(GOAL_REGISTER_PROVIDER_EVENT, {
|
|
36
53
|
id: "subagents",
|
|
37
54
|
label: "Subagents",
|
|
38
55
|
scope: "session",
|
|
39
|
-
|
|
56
|
+
activityVersion: 1,
|
|
57
|
+
getActivity: (ctx, options) => {
|
|
58
|
+
const observed = workObservation();
|
|
59
|
+
if (!observed && options?.cachedOnly) {
|
|
60
|
+
return { providerId: "subagents", coverage: "unverified", items: [], nextDeadline: null };
|
|
61
|
+
}
|
|
62
|
+
if (!observed && hasWorkObservationContext()) {
|
|
63
|
+
return activateWorkObservation().then(() => observedActivity(workObservation(), ctx));
|
|
64
|
+
}
|
|
65
|
+
if (observed) {
|
|
66
|
+
return observedActivity(observed, ctx);
|
|
67
|
+
}
|
|
40
68
|
let sessionId;
|
|
41
69
|
try {
|
|
42
70
|
sessionId = ctx?.sessionManager?.getSessionId();
|
|
@@ -47,9 +75,11 @@ export function registerSubagentsGoalProvider(pi) {
|
|
|
47
75
|
const origin = ctx ? { cwd: ctx.cwd, sessionId } : undefined;
|
|
48
76
|
return {
|
|
49
77
|
providerId: "subagents",
|
|
78
|
+
nextDeadline: null,
|
|
50
79
|
label: "Subagents",
|
|
51
80
|
items: listMetasForParent(process.pid)
|
|
52
81
|
.filter((meta) => !origin || belongsToOrigin(meta, origin))
|
|
82
|
+
.filter((meta) => !ctx || !meta.callbackOrigin?.branchId || ctx.sessionManager.getBranch().some(entry => entry.id === meta.callbackOrigin?.branchId))
|
|
53
83
|
.map((meta) => {
|
|
54
84
|
const status = effectiveStatus(meta);
|
|
55
85
|
const active = status === "running" || status === "orphaned";
|
|
@@ -72,7 +102,19 @@ export function registerSubagentsGoalProvider(pi) {
|
|
|
72
102
|
}),
|
|
73
103
|
};
|
|
74
104
|
},
|
|
75
|
-
onActivityChanged:
|
|
105
|
+
onActivityChanged: (notify, ctx) => {
|
|
106
|
+
const offObservation = onWorkObservation(notify);
|
|
107
|
+
const offMeta = onMetaChanged((meta) => {
|
|
108
|
+
if (ctx && meta) {
|
|
109
|
+
if (!belongsToOrigin(meta, { cwd: ctx.cwd, sessionId: ctx.sessionManager.getSessionId() }))
|
|
110
|
+
return;
|
|
111
|
+
if (meta.callbackOrigin?.branchId && !ctx.sessionManager.getBranch().some(entry => entry.id === meta.callbackOrigin?.branchId))
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
notify();
|
|
115
|
+
});
|
|
116
|
+
return () => { offObservation(); offMeta(); };
|
|
117
|
+
},
|
|
76
118
|
});
|
|
77
119
|
};
|
|
78
120
|
if (!goalReadySubscriptions.has(pi)) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { activateWorkObservation, hasWorkObservationContext, workObservation, onWorkObservation } from "./work-observation.ts";
|
|
2
3
|
import {
|
|
3
4
|
belongsToOrigin,
|
|
4
5
|
effectiveStatus,
|
|
@@ -38,13 +39,42 @@ function parkActivity(meta: Parameters<typeof effectiveStatus>[0]): Record<strin
|
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
function observedActivity(observed: any, ctx?: ExtensionContext) {
|
|
43
|
+
if (observed?.status !== "ready") throw new Error(observed?.reason ?? "Subagent activity is unverified");
|
|
44
|
+
return {
|
|
45
|
+
providerId: "subagents", label: "Subagents", nextDeadline: observed.nextDeadline ?? null,
|
|
46
|
+
items: observed.rows.filter((row: any) => !ctx || (
|
|
47
|
+
belongsToOrigin(row.meta, { cwd: ctx.cwd, sessionId: ctx.sessionManager.getSessionId() }) &&
|
|
48
|
+
(!row.meta.callbackOrigin?.branchId || ctx.sessionManager.getBranch().some(entry => entry.id === row.meta.callbackOrigin.branchId))
|
|
49
|
+
)).map((row: any) => {
|
|
50
|
+
const status = row.assignment.state;
|
|
51
|
+
const active = status === "running" || status === "waiting";
|
|
52
|
+
return { id: row.meta.id, label: row.meta.name, status, active, terminal: !active,
|
|
53
|
+
attention: !active && status !== "completed", unhealthy: row.meta.status === "orphaned",
|
|
54
|
+
startedAt: row.meta.startedAt, endedAt: row.meta.endedAt,
|
|
55
|
+
details: { assignment: row.assignment, sourceRevision: row.sourceRevision } };
|
|
56
|
+
}),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
41
60
|
export function registerSubagentsGoalProvider(pi: ExtensionAPI): void {
|
|
42
61
|
const emitProvider = (): void => {
|
|
43
62
|
pi.events?.emit(GOAL_REGISTER_PROVIDER_EVENT, {
|
|
44
63
|
id: "subagents",
|
|
45
64
|
label: "Subagents",
|
|
46
65
|
scope: "session",
|
|
47
|
-
|
|
66
|
+
activityVersion: 1,
|
|
67
|
+
getActivity: (ctx?: ExtensionContext, options?: { cachedOnly?: boolean }) => {
|
|
68
|
+
const observed = workObservation();
|
|
69
|
+
if (!observed && options?.cachedOnly) {
|
|
70
|
+
return { providerId: "subagents", coverage: "unverified", items: [], nextDeadline: null };
|
|
71
|
+
}
|
|
72
|
+
if (!observed && hasWorkObservationContext()) {
|
|
73
|
+
return activateWorkObservation().then(() => observedActivity(workObservation(), ctx));
|
|
74
|
+
}
|
|
75
|
+
if (observed) {
|
|
76
|
+
return observedActivity(observed, ctx);
|
|
77
|
+
}
|
|
48
78
|
let sessionId: string | undefined;
|
|
49
79
|
try {
|
|
50
80
|
sessionId = ctx?.sessionManager?.getSessionId();
|
|
@@ -54,9 +84,11 @@ export function registerSubagentsGoalProvider(pi: ExtensionAPI): void {
|
|
|
54
84
|
const origin = ctx ? { cwd: ctx.cwd, sessionId } : undefined;
|
|
55
85
|
return {
|
|
56
86
|
providerId: "subagents",
|
|
87
|
+
nextDeadline: null,
|
|
57
88
|
label: "Subagents",
|
|
58
89
|
items: listMetasForParent(process.pid)
|
|
59
90
|
.filter((meta) => !origin || belongsToOrigin(meta, origin))
|
|
91
|
+
.filter((meta) => !ctx || !meta.callbackOrigin?.branchId || ctx.sessionManager.getBranch().some(entry => entry.id === meta.callbackOrigin?.branchId))
|
|
60
92
|
.map((meta) => {
|
|
61
93
|
const status = effectiveStatus(meta);
|
|
62
94
|
const active = status === "running" || status === "orphaned";
|
|
@@ -79,7 +111,17 @@ export function registerSubagentsGoalProvider(pi: ExtensionAPI): void {
|
|
|
79
111
|
}),
|
|
80
112
|
};
|
|
81
113
|
},
|
|
82
|
-
onActivityChanged:
|
|
114
|
+
onActivityChanged: (notify: () => void, ctx?: ExtensionContext) => {
|
|
115
|
+
const offObservation = onWorkObservation(notify);
|
|
116
|
+
const offMeta = onMetaChanged((meta) => {
|
|
117
|
+
if (ctx && meta) {
|
|
118
|
+
if (!belongsToOrigin(meta, { cwd: ctx.cwd, sessionId: ctx.sessionManager.getSessionId() })) return;
|
|
119
|
+
if (meta.callbackOrigin?.branchId && !ctx.sessionManager.getBranch().some(entry => entry.id === meta.callbackOrigin?.branchId)) return;
|
|
120
|
+
}
|
|
121
|
+
notify();
|
|
122
|
+
});
|
|
123
|
+
return () => { offObservation(); offMeta(); };
|
|
124
|
+
},
|
|
83
125
|
});
|
|
84
126
|
};
|
|
85
127
|
if (!goalReadySubscriptions.has(pi)) {
|