pi-crew 0.9.56 → 0.9.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1 -1
- package/CHANGELOG.md +29 -0
- package/README.md +53 -5
- package/dist/index.mjs +5350 -4350
- package/docs/README.md +54 -0
- package/package.json +12 -12
- package/skills/real-test-pi-crew/SKILL.md +93 -3
- package/src/agents/discover-agents.ts +68 -10
- package/src/benchmark/feedback-loop.ts +1 -1
- package/src/config/config.ts +2 -1
- package/src/config/types.ts +12 -0
- package/src/extension/action-suggestions.ts +16 -63
- package/src/extension/async-notifier.ts +3 -3
- package/src/extension/command-completions.ts +2 -2
- package/src/extension/crew-cleanup.ts +3 -3
- package/src/extension/crew-vibes/footer.ts +4 -2
- package/src/extension/cross-extension-rpc.ts +10 -5
- package/src/extension/knowledge-injection.ts +57 -10
- package/src/extension/register.ts +2 -2
- package/src/extension/registration/artifact-cleanup.ts +41 -3
- package/src/extension/registration/commands.ts +4 -4
- package/src/extension/registration/context-builder.ts +10 -10
- package/src/extension/registration/crash-recovery-cache.ts +3 -3
- package/src/extension/registration/foreground-run-controller.ts +1 -1
- package/src/extension/registration/lazy-configurers.ts +2 -2
- package/src/extension/registration/lifecycle-handlers.ts +12 -12
- package/src/extension/registration/lifecycle.ts +2 -2
- package/src/extension/registration/observability.ts +2 -2
- package/src/extension/registration/registration-types.ts +3 -3
- package/src/extension/registration/runtime-cleanup.ts +1 -1
- package/src/extension/registration/subagent-helpers.ts +2 -2
- package/src/extension/registration/subagent-manager-setup.ts +2 -2
- package/src/extension/registration/subagent-tools.ts +21 -16
- package/src/extension/registration/team-tool.ts +108 -17
- package/src/extension/registration/viewers.ts +3 -4
- package/src/extension/registration/wire-cross-extension.ts +7 -7
- package/src/extension/rpc-hmac.ts +3 -2
- package/src/extension/run-bundle-schema.ts +13 -4
- package/src/extension/run-export.ts +2 -2
- package/src/extension/run-index.ts +2 -3
- package/src/extension/run-maintenance.ts +57 -1
- package/src/extension/team-manager-command.ts +3 -1
- package/src/extension/team-tool/anchor.ts +8 -2
- package/src/extension/team-tool/api.ts +117 -39
- package/src/extension/team-tool/cancel.ts +23 -8
- package/src/extension/team-tool/chain-executor.ts +1 -1
- package/src/extension/team-tool/dispatch/automate.ts +17 -2
- package/src/extension/team-tool/dispatch/control.ts +17 -2
- package/src/extension/team-tool/dispatch/manage.ts +34 -2
- package/src/extension/team-tool/dispatch/run.ts +17 -2
- package/src/extension/team-tool/dispatch/status.ts +37 -5
- package/src/extension/team-tool/doctor.ts +2 -2
- package/src/extension/team-tool/explain.ts +1 -1
- package/src/extension/team-tool/goal-wrap.ts +5 -5
- package/src/extension/team-tool/goal.ts +30 -9
- package/src/extension/team-tool/handle-schedule.ts +37 -19
- package/src/extension/team-tool/inspect.ts +21 -5
- package/src/extension/team-tool/lifecycle-actions.ts +53 -10
- package/src/extension/team-tool/parallel-dispatch.ts +14 -5
- package/src/extension/team-tool/param-error.ts +24 -0
- package/src/extension/team-tool/respond.ts +20 -6
- package/src/extension/team-tool/run.ts +27 -17
- package/src/extension/team-tool/status.ts +11 -5
- package/src/extension/team-tool.ts +26 -19
- package/src/hooks/registry.ts +1 -1
- package/src/i18n.ts +22 -0
- package/src/observability/event-bus.ts +1 -1
- package/src/prompt/prompt-runtime.ts +2 -2
- package/src/runtime/README.md +35 -0
- package/src/runtime/agent-control.ts +1 -1
- package/src/runtime/anchor-manager.ts +0 -2
- package/src/runtime/async-runner.ts +1 -1
- package/src/runtime/attention-events.ts +1 -1
- package/src/runtime/auto-summarize.ts +0 -2
- package/src/runtime/background-runner.ts +103 -30
- package/src/runtime/{crew-broker-child.ts → broker/crew-broker-child.ts} +2 -2
- package/src/runtime/{crew-broker-client.ts → broker/crew-broker-client.ts} +4 -7
- package/src/runtime/{crew-broker.ts → broker/crew-broker.ts} +13 -21
- package/src/runtime/chain-runner.ts +50 -5
- package/src/runtime/{child-pi-constants.ts → child-pi/child-pi-constants.ts} +1 -1
- package/src/runtime/{child-pi-kill.ts → child-pi/child-pi-kill.ts} +3 -3
- package/src/runtime/{child-pi-spawn.ts → child-pi/child-pi-spawn.ts} +28 -12
- package/src/runtime/{child-pi-steering.ts → child-pi/child-pi-steering.ts} +1 -1
- package/src/runtime/{child-pi-streams.ts → child-pi/child-pi-streams.ts} +11 -4
- package/src/runtime/{child-pi-transcript.ts → child-pi/child-pi-transcript.ts} +6 -6
- package/src/runtime/{child-pi.ts → child-pi/child-pi.ts} +28 -72
- package/src/runtime/{compact-stages → compaction/compact-stages}/bounded-tail.ts +1 -1
- package/src/runtime/{compact-stages → compaction/compact-stages}/index.ts +2 -2
- package/src/runtime/{compaction-summary.ts → compaction/compaction-summary.ts} +3 -3
- package/src/runtime/{tool-output-pruner.ts → compaction/tool-output-pruner.ts} +1 -1
- package/src/runtime/custom-tools/irc-tool.ts +2 -2
- package/src/runtime/delivery-coordinator.ts +0 -3
- package/src/runtime/diagnostic-export.ts +3 -3
- package/src/runtime/foreground-control.ts +1 -1
- package/src/runtime/foreground-watchdog.ts +1 -1
- package/src/runtime/{adaptive-plan.ts → goal-workflow/adaptive-plan.ts} +8 -8
- package/src/runtime/{dynamic-workflow-context.ts → goal-workflow/dynamic-workflow-context.ts} +16 -16
- package/src/runtime/{dynamic-workflow-runner.ts → goal-workflow/dynamic-workflow-runner.ts} +10 -10
- package/src/runtime/{goal-achievement.ts → goal-workflow/goal-achievement.ts} +3 -3
- package/src/runtime/{goal-evaluator.ts → goal-workflow/goal-evaluator.ts} +8 -8
- package/src/runtime/{goal-loop-runner.ts → goal-workflow/goal-loop-runner.ts} +27 -25
- package/src/runtime/{goal-state-store.ts → goal-workflow/goal-state-store.ts} +8 -8
- package/src/runtime/{plan-templates.ts → goal-workflow/plan-templates.ts} +1 -1
- package/src/runtime/group-join.ts +3 -3
- package/src/runtime/handoff-manager.ts +0 -2
- package/src/runtime/{heartbeat-watcher.ts → heartbeat/heartbeat-watcher.ts} +7 -7
- package/src/runtime/iteration-hooks.ts +1 -1
- package/src/runtime/{live-agent-control.ts → live-session/live-agent-control.ts} +2 -2
- package/src/runtime/{live-agent-manager.ts → live-session/live-agent-manager.ts} +4 -4
- package/src/runtime/{live-session-runtime.ts → live-session/live-session-runtime.ts} +39 -41
- package/src/runtime/manifest-cache.ts +1 -1
- package/src/runtime/{model-fallback.ts → model/model-fallback.ts} +1 -1
- package/src/runtime/{pi-args.ts → model/pi-args.ts} +20 -5
- package/src/runtime/model/provider-extensions.ts +116 -0
- package/src/runtime/{runtime-policy.ts → model/runtime-policy.ts} +2 -2
- package/src/runtime/{runtime-resolver.ts → model/runtime-resolver.ts} +3 -3
- package/src/runtime/{runtime-warmup.ts → model/runtime-warmup.ts} +8 -8
- package/src/runtime/orphan-worker-registry.ts +1 -1
- package/src/runtime/{progress-tracker.ts → output/progress-tracker.ts} +1 -1
- package/src/runtime/{result-extractor.ts → output/result-extractor.ts} +4 -4
- package/src/runtime/{sidechain-output.ts → output/sidechain-output.ts} +2 -2
- package/src/runtime/{stream-preview.ts → output/stream-preview.ts} +1 -1
- package/src/runtime/{streaming-output.ts → output/streaming-output.ts} +2 -2
- package/src/runtime/{tool-progress.ts → output/tool-progress.ts} +1 -1
- package/src/runtime/parent-guard.ts +30 -10
- package/src/runtime/pipeline-runner.ts +2 -2
- package/src/runtime/policy-engine.ts +2 -2
- package/src/runtime/{cancellation.ts → process/cancellation.ts} +1 -1
- package/src/runtime/{post-exit-stdio-guard.ts → process/post-exit-stdio-guard.ts} +1 -1
- package/src/runtime/{process-lifecycle.ts → process/process-lifecycle.ts} +3 -3
- package/src/runtime/{checkpoint.ts → recovery/checkpoint.ts} +4 -4
- package/src/runtime/{crash-recovery.ts → recovery/crash-recovery.ts} +93 -21
- package/src/runtime/{overflow-recovery.ts → recovery/overflow-recovery.ts} +1 -1
- package/src/runtime/{recovery-recipes.ts → recovery/recovery-recipes.ts} +1 -1
- package/src/runtime/{retry-executor.ts → recovery/retry-executor.ts} +2 -2
- package/src/runtime/{retry-runner.ts → recovery/retry-runner.ts} +2 -8
- package/src/runtime/run-tracker.ts +1 -1
- package/src/runtime/run-worker.ts +3 -3
- package/src/runtime/{coalesce-tasks.ts → scheduling/coalesce-tasks.ts} +3 -3
- package/src/runtime/{concurrency.ts → scheduling/concurrency.ts} +1 -1
- package/src/runtime/{parallel-research.ts → scheduling/parallel-research.ts} +4 -2
- package/src/runtime/{run-coalesced-task-group.ts → scheduling/run-coalesced-task-group.ts} +95 -36
- package/src/runtime/{task-graph-scheduler.ts → scheduling/task-graph-scheduler.ts} +1 -1
- package/src/runtime/session-resources.ts +1 -1
- package/src/runtime/settings-store.ts +1 -1
- package/src/runtime/single-agent-compose.ts +1 -0
- package/src/runtime/stale-reconciler.ts +1 -1
- package/src/runtime/subagent-manager.ts +1 -1
- package/src/runtime/supervisor-contact.ts +1 -1
- package/src/runtime/task-output-context.ts +7 -5
- package/src/runtime/task-runner/child-executor.ts +62 -22
- package/src/runtime/task-runner/live-executor.ts +8 -8
- package/src/runtime/task-runner/post-execution.ts +12 -12
- package/src/runtime/task-runner/pre-execution.ts +6 -6
- package/src/runtime/task-runner/progress.ts +1 -1
- package/src/runtime/task-runner/run-projection.ts +1 -1
- package/src/runtime/task-runner/scaffold-executor.ts +1 -1
- package/src/runtime/task-runner/state-helpers.ts +2 -2
- package/src/runtime/task-runner.ts +4 -4
- package/src/runtime/team-runner.ts +380 -139
- package/src/runtime/{completion-guard.ts → verification/completion-guard.ts} +1 -1
- package/src/runtime/{green-contract.ts → verification/green-contract.ts} +1 -1
- package/src/runtime/{post-checks.ts → verification/post-checks.ts} +4 -4
- package/src/runtime/{verification-gates.ts → verification/verification-gates.ts} +5 -5
- package/src/runtime/{verification-integrity.ts → verification/verification-integrity.ts} +1 -1
- package/src/schema/config-schema.ts +1 -0
- package/src/schema/team-tool-schema.ts +133 -177
- package/src/state/README.md +44 -0
- package/src/state/atomic-write.ts +24 -3
- package/src/state/{locks.ts → coordination/locks.ts} +118 -38
- package/src/state/{mailbox.ts → coordination/mailbox.ts} +14 -8
- package/src/state/{schedule.ts → coordination/schedule.ts} +3 -3
- package/src/state/{task-claims.ts → coordination/task-claims.ts} +1 -1
- package/src/state/decision-ledger.ts +1 -1
- package/src/state/{event-log-rotation.ts → event-log/event-log-rotation.ts} +161 -31
- package/src/state/{event-log.ts → event-log/event-log.ts} +38 -26
- package/src/state/{jsonl-writer.ts → event-log/jsonl-writer.ts} +14 -6
- package/src/state/hook-instinct-bridge.ts +2 -2
- package/src/state/{active-run-registry.ts → stores/active-run-registry.ts} +7 -7
- package/src/state/{artifact-store.ts → stores/artifact-store.ts} +62 -4
- package/src/state/{blob-store.ts → stores/blob-store.ts} +3 -3
- package/src/state/{health-store.ts → stores/health-store.ts} +3 -3
- package/src/state/{instinct-store.ts → stores/instinct-store.ts} +3 -3
- package/src/state/{observation-store.ts → stores/observation-store.ts} +2 -2
- package/src/state/{run-cache.ts → stores/run-cache.ts} +4 -4
- package/src/state/{run-graph.ts → stores/run-graph.ts} +4 -4
- package/src/state/{run-metrics.ts → stores/run-metrics.ts} +3 -3
- package/src/state/{state-store.ts → stores/state-store.ts} +236 -17
- package/src/state/types.ts +27 -3
- package/src/ui/component.ts +55 -0
- package/src/ui/crew-select-list.ts +3 -1
- package/src/ui/dashboard-panes/agents-pane.ts +1 -1
- package/src/ui/dwf-phase-display.ts +1 -1
- package/src/ui/heartbeat-aggregator.ts +1 -1
- package/src/ui/keybinding-map.ts +179 -6
- package/src/ui/layout-primitives.ts +9 -5
- package/src/ui/live-conversation-overlay.ts +1 -1
- package/src/ui/live-run-sidebar.ts +1 -1
- package/src/ui/overlay-stack.ts +148 -0
- package/src/ui/overlays/agent-picker-overlay.ts +1 -1
- package/src/ui/overlays/mailbox-compose-overlay.ts +1 -1
- package/src/ui/overlays/mailbox-detail-overlay.ts +2 -2
- package/src/ui/powerbar-publisher.ts +1 -1
- package/src/ui/render-scheduler.ts +1 -1
- package/src/ui/run-action-dispatcher.ts +3 -3
- package/src/ui/run-dashboard.ts +5 -33
- package/src/ui/run-event-bus.ts +3 -3
- package/src/ui/run-snapshot-cache.ts +37 -18
- package/src/ui/settings-overlay.ts +13 -21
- package/src/ui/snapshot-types.ts +1 -1
- package/src/ui/status-colors.ts +0 -2
- package/src/ui/terminal-status.ts +1 -1
- package/src/ui/theme-adapter.ts +33 -13
- package/src/ui/tool-renderers/index.ts +8 -0
- package/src/ui/transcript-viewer.ts +37 -13
- package/src/ui/widget/index.ts +32 -9
- package/src/ui/widget/widget-formatters.ts +62 -4
- package/src/ui/widget/widget-model.ts +2 -2
- package/src/ui/widget/widget-renderer.ts +1 -1
- package/src/utils/conflict-detect.ts +58 -5
- package/src/utils/ndjson.ts +2 -2
- package/src/utils/socket-path.ts +1 -1
- package/src/workflows/workflow-config.ts +1 -1
- package/src/worktree/cleanup.ts +1 -1
- package/src/worktree/worktree-manager.ts +88 -39
- package/workflows/chain.workflow.md +2 -2
- package/index.bundle.ts +0 -25
- package/scripts/bench-check.mjs +0 -96
- package/scripts/bench-cold-start.mjs +0 -216
- package/scripts/build-bundle.mjs +0 -92
- package/scripts/check-all-skills.ts +0 -294
- package/scripts/check-bundle-size.mjs +0 -38
- package/scripts/check-bundle-staleness.mjs +0 -97
- package/scripts/check-conflict-markers.mjs +0 -91
- package/scripts/check-lazy-imports.mjs +0 -28
- package/scripts/dev-runner.mjs +0 -106
- package/scripts/profile-startup.mjs +0 -125
- package/scripts/release-smoke.mjs +0 -74
- package/scripts/run-bench.mjs +0 -47
- package/scripts/run-real-chain.ts +0 -41
- package/scripts/smoke-team-perf.ts +0 -43
- package/scripts/test-issue-29-crash.ts +0 -111
- package/scripts/test-issue-29-e2e.ts +0 -183
- package/scripts/test-issue-29-real-runtime.ts +0 -330
- package/scripts/test-issue-29-real-tasks.ts +0 -387
- package/scripts/test-issue-29-team-tool.ts +0 -105
- package/scripts/test-runner.mjs +0 -84
- package/scripts/verify-flicker-fix.ts +0 -109
- package/scripts/verify-skill.ts +0 -550
- package/scripts/watch-bundle.mjs +0 -259
- package/scripts/watchdog-harness.ts +0 -119
- package/src/adapters/claude-adapter.ts +0 -23
- package/src/adapters/codex-adapter.ts +0 -21
- package/src/adapters/cursor-adapter.ts +0 -17
- package/src/adapters/export-util.ts +0 -143
- package/src/adapters/index.ts +0 -15
- package/src/adapters/registry.ts +0 -18
- package/src/adapters/types.ts +0 -23
- package/src/runtime/code-summary.ts +0 -292
- package/src/runtime/cross-extension-rpc.ts +0 -143
- package/src/runtime/hidden-handoff.ts +0 -407
- package/src/runtime/prose-compressor.ts +0 -162
- package/src/subagents/async-entry.ts +0 -1
- package/src/subagents/index.ts +0 -3
- package/src/subagents/live/control.ts +0 -1
- package/src/subagents/live/manager.ts +0 -1
- package/src/subagents/live/realtime.ts +0 -1
- package/src/subagents/live/session-runtime.ts +0 -1
- package/src/subagents/manager.ts +0 -1
- package/src/subagents/spawn.ts +0 -1
- package/test-integration-check.ts +0 -118
- /package/src/runtime/{broker-issuer.ts → broker/broker-issuer.ts} +0 -0
- /package/src/runtime/{crew-broker-tokens.ts → broker/crew-broker-tokens.ts} +0 -0
- /package/src/runtime/{child-pi-pool.ts → child-pi/child-pi-pool.ts} +0 -0
- /package/src/runtime/{compact-pipeline.ts → compaction/compact-pipeline.ts} +0 -0
- /package/src/runtime/{compact-stages → compaction/compact-stages}/ansi-strip-stage.ts +0 -0
- /package/src/runtime/{compact-stages → compaction/compact-stages}/blank-collapse-stage.ts +0 -0
- /package/src/runtime/{compact-stages → compaction/compact-stages}/deduplicate-stage.ts +0 -0
- /package/src/runtime/{compact-stages → compaction/compact-stages}/head-snap-stage.ts +0 -0
- /package/src/runtime/{compact-stages → compaction/compact-stages}/tail-capture-stage.ts +0 -0
- /package/src/runtime/{compact-stages → compaction/compact-stages}/truncation-stage.ts +0 -0
- /package/src/runtime/{important-line-classifier.ts → compaction/important-line-classifier.ts} +0 -0
- /package/src/runtime/{heartbeat-gradient.ts → heartbeat/heartbeat-gradient.ts} +0 -0
- /package/src/runtime/{worker-heartbeat.ts → heartbeat/worker-heartbeat.ts} +0 -0
- /package/src/runtime/{worker-startup.ts → heartbeat/worker-startup.ts} +0 -0
- /package/src/runtime/{intercom-bridge.ts → live-session/intercom-bridge.ts} +0 -0
- /package/src/runtime/{live-control-realtime.ts → live-session/live-control-realtime.ts} +0 -0
- /package/src/runtime/{live-extension-bridge.ts → live-session/live-extension-bridge.ts} +0 -0
- /package/src/runtime/{live-irc.ts → live-session/live-irc.ts} +0 -0
- /package/src/runtime/{live-session-health.ts → live-session/live-session-health.ts} +0 -0
- /package/src/runtime/{model-resolver.ts → model/model-resolver.ts} +0 -0
- /package/src/runtime/{model-scope.ts → model/model-scope.ts} +0 -0
- /package/src/runtime/{output-validator.ts → output/output-validator.ts} +0 -0
- /package/src/runtime/{pi-json-output.ts → output/pi-json-output.ts} +0 -0
- /package/src/runtime/{progress-event-coalescer.ts → output/progress-event-coalescer.ts} +0 -0
- /package/src/runtime/{cancellation-token.ts → process/cancellation-token.ts} +0 -0
- /package/src/runtime/{zombie-scanner.ts → process/zombie-scanner.ts} +0 -0
- /package/src/runtime/{crash-classification.ts → recovery/crash-classification.ts} +0 -0
- /package/src/runtime/{batch-barrier.ts → scheduling/batch-barrier.ts} +0 -0
- /package/src/runtime/{global-worker-cap.ts → scheduling/global-worker-cap.ts} +0 -0
- /package/src/runtime/{parallel-utils.ts → scheduling/parallel-utils.ts} +0 -0
- /package/src/runtime/{scheduler.ts → scheduling/scheduler.ts} +0 -0
- /package/src/runtime/{semaphore.ts → scheduling/semaphore.ts} +0 -0
- /package/src/runtime/{task-graph.ts → scheduling/task-graph.ts} +0 -0
- /package/src/runtime/{verification-worktree.ts → verification/verification-worktree.ts} +0 -0
- /package/src/state/{event-reconstructor.ts → event-log/event-reconstructor.ts} +0 -0
- /package/src/state/{worker-atomic-writer.ts → event-log/worker-atomic-writer.ts} +0 -0
package/src/runtime/{dynamic-workflow-context.ts → goal-workflow/dynamic-workflow-context.ts}
RENAMED
|
@@ -24,23 +24,23 @@
|
|
|
24
24
|
|
|
25
25
|
import { randomBytes } from "node:crypto";
|
|
26
26
|
import type { TSchema } from "@sinclair/typebox";
|
|
27
|
-
import type { AgentConfig } from "
|
|
28
|
-
import { allAgents, discoverAgents } from "
|
|
29
|
-
import {
|
|
30
|
-
import { appendEvent } from "
|
|
31
|
-
import {
|
|
32
|
-
import type { TeamRunManifest } from "
|
|
33
|
-
import type { TeamConfig } from "
|
|
34
|
-
import { logInternalError } from "
|
|
35
|
-
import { cleanupAgentWorktreeAsync, prepareAgentWorktreeAsync } from "
|
|
36
|
-
import type { DwfCheckpointState } from "
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
27
|
+
import type { AgentConfig } from "../../agents/agent-config.ts";
|
|
28
|
+
import { allAgents, discoverAgents } from "../../agents/discover-agents.ts";
|
|
29
|
+
import { appendMailboxMessage, readMailbox } from "../../state/coordination/mailbox.ts";
|
|
30
|
+
import { appendEvent } from "../../state/event-log/event-log.ts";
|
|
31
|
+
import { writeArtifact } from "../../state/stores/artifact-store.ts";
|
|
32
|
+
import type { TeamRunManifest } from "../../state/types.ts";
|
|
33
|
+
import type { TeamConfig } from "../../teams/team-config.ts";
|
|
34
|
+
import { logInternalError } from "../../utils/internal-error.ts";
|
|
35
|
+
import { cleanupAgentWorktreeAsync, prepareAgentWorktreeAsync } from "../../worktree/worktree-manager.ts";
|
|
36
|
+
import type { DwfCheckpointState } from "../dwf-state-store.ts";
|
|
37
|
+
import { parsePiJsonOutput } from "../output/pi-json-output.ts";
|
|
38
|
+
import { extractStructuredResult } from "../output/result-extractor.ts";
|
|
39
|
+
import { executeWithRetry } from "../recovery/retry-executor.ts";
|
|
40
|
+
import { runWorker } from "../run-worker.ts";
|
|
41
|
+
import { mapConcurrent } from "../scheduling/parallel-utils.ts";
|
|
42
|
+
import { Semaphore } from "../scheduling/semaphore.ts";
|
|
39
43
|
import { renderPlanTemplate } from "./plan-templates.ts";
|
|
40
|
-
import { extractStructuredResult } from "./result-extractor.ts";
|
|
41
|
-
import { executeWithRetry } from "./retry-executor.ts";
|
|
42
|
-
import { runWorker } from "./run-worker.ts";
|
|
43
|
-
import { Semaphore } from "./semaphore.ts";
|
|
44
44
|
|
|
45
45
|
export interface AgentCallOpts {
|
|
46
46
|
prompt: string;
|
|
@@ -20,22 +20,22 @@
|
|
|
20
20
|
import { readFileSync } from "node:fs";
|
|
21
21
|
import { join } from "node:path";
|
|
22
22
|
import { transformSync } from "esbuild";
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import type { TeamRunManifest, TeamTaskState } from "
|
|
26
|
-
import { logInternalError } from "
|
|
27
|
-
import { packageRoot, projectCrewRoot, userPiRoot } from "
|
|
28
|
-
import { resolveRealContainedPath } from "
|
|
29
|
-
import type { DynamicWorkflowConfig } from "
|
|
30
|
-
import { assertDeterministicScript, isDeterminismCheckEnabled } from "
|
|
31
|
-
import { DwfStore } from "
|
|
23
|
+
import { appendEvent } from "../../state/event-log/event-log.ts";
|
|
24
|
+
import { writeArtifact } from "../../state/stores/artifact-store.ts";
|
|
25
|
+
import type { TeamRunManifest, TeamTaskState } from "../../state/types.ts";
|
|
26
|
+
import { logInternalError } from "../../utils/internal-error.ts";
|
|
27
|
+
import { packageRoot, projectCrewRoot, userPiRoot } from "../../utils/paths.ts";
|
|
28
|
+
import { resolveRealContainedPath } from "../../utils/safe-paths.ts";
|
|
29
|
+
import type { DynamicWorkflowConfig } from "../../workflows/workflow-config.ts";
|
|
30
|
+
import { assertDeterministicScript, isDeterminismCheckEnabled } from "../deterministic-ast.ts";
|
|
31
|
+
import { DwfStore } from "../dwf-state-store.ts";
|
|
32
32
|
import { getWorkflowFinalResult, getWorkflowPhaseState, makeWorkflowCtx } from "./dynamic-workflow-context.ts";
|
|
33
33
|
|
|
34
34
|
export interface RunDynamicWorkflowInput {
|
|
35
35
|
manifest: TeamRunManifest;
|
|
36
36
|
workflow: DynamicWorkflowConfig;
|
|
37
37
|
/** Optional team for role resolution (G4 tier 2). */
|
|
38
|
-
team?: import("
|
|
38
|
+
team?: import("../../teams/team-config.ts").TeamConfig;
|
|
39
39
|
signal: AbortSignal;
|
|
40
40
|
concurrency?: number;
|
|
41
41
|
modelOverride?: string;
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
* without breaking a legitimately-no-op run.
|
|
19
19
|
*/
|
|
20
20
|
import { spawnSync } from "node:child_process";
|
|
21
|
-
import type { TeamRunManifest, TeamTaskState } from "
|
|
22
|
-
import { findRepoRoot } from "
|
|
23
|
-
import type { WorkflowConfig } from "
|
|
21
|
+
import type { TeamRunManifest, TeamTaskState } from "../../state/types.ts";
|
|
22
|
+
import { findRepoRoot } from "../../utils/paths.ts";
|
|
23
|
+
import type { WorkflowConfig } from "../../workflows/workflow-config.ts";
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Roles whose job is to EDIT project source/test files (changes that appear in
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
import { existsSync, readFileSync } from "node:fs";
|
|
27
|
-
import type { AgentConfig } from "
|
|
28
|
-
import type { GoalVerdict } from "
|
|
29
|
-
import { logInternalError } from "
|
|
30
|
-
import { redactSecretString } from "
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
27
|
+
import type { AgentConfig } from "../../agents/agent-config.ts";
|
|
28
|
+
import type { GoalVerdict } from "../../state/types.ts";
|
|
29
|
+
import { logInternalError } from "../../utils/internal-error.ts";
|
|
30
|
+
import { redactSecretString } from "../../utils/redaction.ts";
|
|
31
|
+
import { parsePiJsonOutput } from "../output/pi-json-output.ts";
|
|
32
|
+
import { extractStructuredResult } from "../output/result-extractor.ts";
|
|
33
|
+
import { runWorker } from "../run-worker.ts";
|
|
34
|
+
import { collectToolCallsFromEvent } from "../verification/completion-guard.ts";
|
|
35
35
|
|
|
36
36
|
export interface GoalEvidence {
|
|
37
37
|
/** Tail slice of the turn's worker transcript (bounded ~8 KiB). */
|
|
@@ -17,23 +17,23 @@
|
|
|
17
17
|
import { randomBytes } from "node:crypto";
|
|
18
18
|
import { existsSync, readdirSync } from "node:fs";
|
|
19
19
|
import { createRequire } from "node:module";
|
|
20
|
-
import type { AgentConfig } from "
|
|
21
|
-
import { loadConfig } from "
|
|
22
|
-
import { effectiveRunConfig } from "
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import { collectRunMetrics } from "
|
|
26
|
-
import { createRunManifest, saveRunTasks } from "
|
|
27
|
-
import type { GoalLoopState, GoalLoopStatus, GoalVerdict, TeamRunManifest, TeamTaskState } from "
|
|
28
|
-
import type { TeamConfig } from "
|
|
29
|
-
import { logInternalError } from "
|
|
30
|
-
import type { WorkflowConfig } from "
|
|
20
|
+
import type { AgentConfig } from "../../agents/agent-config.ts";
|
|
21
|
+
import { loadConfig } from "../../config/config.ts";
|
|
22
|
+
import { effectiveRunConfig } from "../../extension/team-tool/config-patch.ts";
|
|
23
|
+
import { appendEvent } from "../../state/event-log/event-log.ts";
|
|
24
|
+
import { registerActiveRun, unregisterActiveRun } from "../../state/stores/active-run-registry.ts";
|
|
25
|
+
import { collectRunMetrics } from "../../state/stores/run-metrics.ts";
|
|
26
|
+
import { createRunManifest, saveRunTasks } from "../../state/stores/state-store.ts";
|
|
27
|
+
import type { GoalLoopState, GoalLoopStatus, GoalVerdict, TeamRunManifest, TeamTaskState } from "../../state/types.ts";
|
|
28
|
+
import type { TeamConfig } from "../../teams/team-config.ts";
|
|
29
|
+
import { logInternalError } from "../../utils/internal-error.ts";
|
|
30
|
+
import type { WorkflowConfig } from "../../workflows/workflow-config.ts";
|
|
31
|
+
import { resolveCrewRuntime } from "../model/runtime-resolver.ts";
|
|
32
|
+
import { executeTeamRun } from "../team-runner.ts";
|
|
33
|
+
import { compareSnapshot, snapshotManifests } from "../verification/verification-integrity.ts";
|
|
34
|
+
import { acquireWorkspaceLock, type WorkspaceLockHandle } from "../workspace-lock.ts";
|
|
31
35
|
import { bundleEvidence, evaluateGoal } from "./goal-evaluator.ts";
|
|
32
36
|
import { GoalStore } from "./goal-state-store.ts";
|
|
33
|
-
import { resolveCrewRuntime } from "./runtime-resolver.ts";
|
|
34
|
-
import { executeTeamRun } from "./team-runner.ts";
|
|
35
|
-
import { compareSnapshot, snapshotManifests } from "./verification-integrity.ts";
|
|
36
|
-
import { acquireWorkspaceLock, type WorkspaceLockHandle } from "./workspace-lock.ts";
|
|
37
37
|
|
|
38
38
|
/** Required minimal shape for the worker + agents discovery (P0 uses the goal's workerAgent). */
|
|
39
39
|
export interface GoalLoopRuntimeDeps {
|
|
@@ -62,8 +62,8 @@ export interface RunGoalLoopResult {
|
|
|
62
62
|
export const stubGoalEvaluator = async (
|
|
63
63
|
goal: GoalLoopState,
|
|
64
64
|
_turnRunId: string,
|
|
65
|
-
_m?: import("
|
|
66
|
-
_t?: import("
|
|
65
|
+
_m?: import("../../state/types.ts").TeamRunManifest,
|
|
66
|
+
_t?: import("../../state/types.ts").TeamTaskState[],
|
|
67
67
|
_s?: AbortSignal,
|
|
68
68
|
): Promise<GoalEvaluatorResult> => ({
|
|
69
69
|
verdict: {
|
|
@@ -84,8 +84,8 @@ export type GoalEvaluatorResult = {
|
|
|
84
84
|
export type GoalEvaluatorFn = (
|
|
85
85
|
goal: GoalLoopState,
|
|
86
86
|
turnRunId: string,
|
|
87
|
-
turnManifest: import("
|
|
88
|
-
turnTasks: import("
|
|
87
|
+
turnManifest: import("../../state/types.ts").TeamRunManifest,
|
|
88
|
+
turnTasks: import("../../state/types.ts").TeamTaskState[],
|
|
89
89
|
signal: AbortSignal,
|
|
90
90
|
) => Promise<GoalEvaluatorResult>;
|
|
91
91
|
|
|
@@ -98,8 +98,8 @@ export type GoalEvaluatorFn = (
|
|
|
98
98
|
export const realGoalEvaluator = async (
|
|
99
99
|
goal: GoalLoopState,
|
|
100
100
|
turnRunId: string,
|
|
101
|
-
turnManifest: import("
|
|
102
|
-
turnTasks: import("
|
|
101
|
+
turnManifest: import("../../state/types.ts").TeamRunManifest,
|
|
102
|
+
turnTasks: import("../../state/types.ts").TeamTaskState[],
|
|
103
103
|
signal: AbortSignal,
|
|
104
104
|
): Promise<GoalEvaluatorResult> => {
|
|
105
105
|
const transcriptPath = deriveTranscriptPath(turnManifest.artifactsRoot, turnTasks);
|
|
@@ -138,7 +138,7 @@ export const realGoalEvaluator = async (
|
|
|
138
138
|
if (!verificationCompromised) {
|
|
139
139
|
try {
|
|
140
140
|
// LAZY: defer dynamic import of ./verification-gates.ts to its call site.
|
|
141
|
-
const { executeVerificationCommands } = await import("
|
|
141
|
+
const { executeVerificationCommands } = await import("../verification/verification-gates.ts");
|
|
142
142
|
const contract = {
|
|
143
143
|
requiredGreenLevel: "none" as const,
|
|
144
144
|
commands: goal.verification.commands,
|
|
@@ -154,7 +154,9 @@ export const realGoalEvaluator = async (
|
|
|
154
154
|
try {
|
|
155
155
|
// LAZY: defer dynamic import of ./verification-worktree.ts to its call site.
|
|
156
156
|
// LAZY: defer dynamic import of ./verification-worktree.ts to its call site. Multi-line form breaks scripts/check-lazy-imports.mjs (which does `lines[lineNum - 2]`), so keep destructuring + await import on one line.
|
|
157
|
-
const { checkWorktreeSandboxAvailable, prepareVerificationWorktree } = await import(
|
|
157
|
+
const { checkWorktreeSandboxAvailable, prepareVerificationWorktree } = await import(
|
|
158
|
+
"../verification/verification-worktree.ts"
|
|
159
|
+
);
|
|
158
160
|
const availability = checkWorktreeSandboxAvailable(goal.cwd);
|
|
159
161
|
if (availability.available) {
|
|
160
162
|
const wt = prepareVerificationWorktree(goal.cwd, availability.commitSha);
|
|
@@ -272,7 +274,7 @@ function resolveGoalTurnWorkflow(goal: GoalLoopState): WorkflowConfig {
|
|
|
272
274
|
const requireFromHere = createRequire(import.meta.url);
|
|
273
275
|
const { discoverWorkflows, allWorkflows } = requireFromHere(
|
|
274
276
|
"../workflows/discover-workflows.ts",
|
|
275
|
-
) as typeof import("
|
|
277
|
+
) as typeof import("../../workflows/discover-workflows.ts");
|
|
276
278
|
const found = allWorkflows(discoverWorkflows(goal.cwd)).find((w) => w.name === wrapName && w.source === "builtin");
|
|
277
279
|
if (found) return found;
|
|
278
280
|
logInternalError(
|
|
@@ -474,7 +476,7 @@ function jaccardSimilarity(a: Set<string>, b: Set<string>): number {
|
|
|
474
476
|
|
|
475
477
|
/** Derive the worker transcript path from the turn's tasks (Fix P0-2). Falls back to dir scan.
|
|
476
478
|
* Exported for unit testing the path-derivation fix. */
|
|
477
|
-
export function deriveTranscriptPath(artifactsRoot: string, tasks: import("
|
|
479
|
+
export function deriveTranscriptPath(artifactsRoot: string, tasks: import("../../state/types.ts").TeamTaskState[]): string | undefined {
|
|
478
480
|
const transcriptsDir = `${artifactsRoot}/transcripts`;
|
|
479
481
|
// Primary: use the first task's id + attempt-0 (task-runner writes ${task.id}.attempt-${i}.jsonl).
|
|
480
482
|
const firstTask = tasks[0];
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* goal loop owns OUTER state) + §0c C10 (hardening: assertSafePathId + UUID goalId).
|
|
7
7
|
*
|
|
8
8
|
* Stores GoalLoopState as atomic JSON at <crewRoot>/state/goals/<goalId>.json.
|
|
9
|
-
* Modeled on ScheduleStore (state/schedule.ts:86) but with atomicWriteJson +
|
|
9
|
+
* Modeled on ScheduleStore (state/coordination/schedule.ts:86) but with atomicWriteJson +
|
|
10
10
|
* path-traversal defense (assertSafePathId on every public method).
|
|
11
11
|
*
|
|
12
12
|
* Per §0c C2: budget lives here (budgetUsed accumulates collectRunMetrics across turns);
|
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
|
|
16
16
|
import { closeSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, statSync, unlinkSync } from "node:fs";
|
|
17
17
|
import { dirname } from "node:path";
|
|
18
|
-
import { atomicWriteJson } from "
|
|
19
|
-
import { appendEvent } from "
|
|
20
|
-
import type { GoalLoopState, GoalLoopStatus } from "
|
|
21
|
-
import { createRunId } from "
|
|
22
|
-
import { logInternalError } from "
|
|
23
|
-
import { projectCrewRoot, userCrewRoot } from "
|
|
24
|
-
import { assertSafePathId } from "
|
|
18
|
+
import { atomicWriteJson } from "../../state/atomic-write.ts";
|
|
19
|
+
import { appendEvent } from "../../state/event-log/event-log.ts";
|
|
20
|
+
import type { GoalLoopState, GoalLoopStatus } from "../../state/types.ts";
|
|
21
|
+
import { createRunId } from "../../utils/ids.ts";
|
|
22
|
+
import { logInternalError } from "../../utils/internal-error.ts";
|
|
23
|
+
import { projectCrewRoot, userCrewRoot } from "../../utils/paths.ts";
|
|
24
|
+
import { assertSafePathId } from "../../utils/safe-paths.ts";
|
|
25
25
|
|
|
26
26
|
/** Default state-root resolver: project scope if a project crew-root exists, else user scope. */
|
|
27
27
|
function resolveGoalsRoot(cwd: string): string {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* deterministic scaffolding + LLM refinement.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { logInternalError } from "
|
|
12
|
+
import { logInternalError } from "../../utils/internal-error.ts";
|
|
13
13
|
|
|
14
14
|
// ── Types ────────────────────────────────────────────────────────────────
|
|
15
15
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CrewRuntimeConfig } from "../config/config.ts";
|
|
2
|
-
import {
|
|
3
|
-
import { appendEvent } from "../state/event-log.ts";
|
|
4
|
-
import {
|
|
2
|
+
import { appendMailboxMessage, findMailboxMessageByRequestId, readDeliveryState } from "../state/coordination/mailbox.ts";
|
|
3
|
+
import { appendEvent } from "../state/event-log/event-log.ts";
|
|
4
|
+
import { writeArtifact } from "../state/stores/artifact-store.ts";
|
|
5
5
|
import type { ArtifactDescriptor, TeamRunManifest, TeamTaskState } from "../state/types.ts";
|
|
6
6
|
import { aggregateTaskOutputs } from "./task-output-context.ts";
|
|
7
7
|
|
|
@@ -50,8 +50,6 @@ export function isValidHandoffSummary(value: unknown): value is HandoffSummary {
|
|
|
50
50
|
* - Detects task completion via agent_end hook
|
|
51
51
|
* - Generates structured summaries with token metrics, artifacts, decisions
|
|
52
52
|
* - Optionally collapses context to reduce token usage
|
|
53
|
-
*
|
|
54
|
-
* @see docs/pi-boomerang-integration-plan.md
|
|
55
53
|
*/
|
|
56
54
|
|
|
57
55
|
/**
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
-
import type { NotificationDescriptor } from "
|
|
4
|
-
import type { MetricRegistry } from "
|
|
5
|
-
import { appendEvent } from "
|
|
6
|
-
import { loadRunManifestById } from "
|
|
7
|
-
import type { TeamRunManifest } from "
|
|
8
|
-
import { logInternalError } from "
|
|
3
|
+
import type { NotificationDescriptor } from "../../extension/notification-router.ts";
|
|
4
|
+
import type { MetricRegistry } from "../../observability/metric-registry.ts";
|
|
5
|
+
import { appendEvent } from "../../state/event-log/event-log.ts";
|
|
6
|
+
import { loadRunManifestById } from "../../state/stores/state-store.ts";
|
|
7
|
+
import type { TeamRunManifest } from "../../state/types.ts";
|
|
8
|
+
import { logInternalError } from "../../utils/internal-error.ts";
|
|
9
|
+
import type { ManifestCache } from "../manifest-cache.ts";
|
|
9
10
|
import { DEFAULT_GRADIENT_THRESHOLDS, type GradientThresholds, type HeartbeatLevel, heartbeatAgeMs } from "./heartbeat-gradient.ts";
|
|
10
|
-
import type { ManifestCache } from "./manifest-cache.ts";
|
|
11
11
|
|
|
12
12
|
export interface HeartbeatWatcherRouter {
|
|
13
13
|
enqueue(notification: NotificationDescriptor): boolean;
|
|
@@ -10,7 +10,7 @@ import * as path from "node:path";
|
|
|
10
10
|
import { WINDOWS_ESSENTIAL_ENV_VARS } from "../utils/env-allowlist.ts";
|
|
11
11
|
import { sanitizeEnvSecrets } from "../utils/env-filter.ts";
|
|
12
12
|
import { resolveShellForScript } from "../utils/resolve-shell.ts";
|
|
13
|
-
import { HeadSnapStage } from "./compact-stages/index.ts";
|
|
13
|
+
import { HeadSnapStage } from "./compaction/compact-stages/index.ts";
|
|
14
14
|
import { DENIED_METRIC_NAMES } from "./metric-parser.ts";
|
|
15
15
|
|
|
16
16
|
/** Hook execution stage. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
-
import type { TeamRunManifest } from "
|
|
4
|
-
import { agentStateFile, ensureAgentStateDir } from "
|
|
3
|
+
import type { TeamRunManifest } from "../../state/types.ts";
|
|
4
|
+
import { agentStateFile, ensureAgentStateDir } from "../crew-agent-records.ts";
|
|
5
5
|
|
|
6
6
|
export type LiveAgentControlOperation = "steer" | "follow-up" | "stop" | "resume";
|
|
7
7
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { appendEvent } from "
|
|
2
|
-
import { logInternalError } from "
|
|
3
|
-
import type { CrewAgentRecord } from "
|
|
1
|
+
import type { appendEvent } from "../../state/event-log/event-log.ts";
|
|
2
|
+
import { logInternalError } from "../../utils/internal-error.ts";
|
|
3
|
+
import type { CrewAgentRecord } from "../crew-agent-runtime.ts";
|
|
4
|
+
import { checkProcessLiveness } from "../process-status.ts";
|
|
4
5
|
import type { IrcMessage } from "./live-irc.ts";
|
|
5
|
-
import { checkProcessLiveness } from "./process-status.ts";
|
|
6
6
|
|
|
7
7
|
const MAX_PENDING_MESSAGES = 1000;
|
|
8
8
|
|
|
@@ -1,17 +1,41 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
-
import type { AgentConfig } from "
|
|
4
|
-
import { resolveToolPolicy } from "
|
|
5
|
-
import type { CrewRuntimeConfig } from "
|
|
6
|
-
import { loadConfig } from "
|
|
7
|
-
import { DEFAULT_LIVE_SESSION } from "
|
|
8
|
-
import { appendEvent, appendEventFireAndForget } from "
|
|
9
|
-
import type { TeamRunManifest, TeamTaskState, UsageState } from "
|
|
10
|
-
import { logInternalError } from "
|
|
11
|
-
import { redactSecrets } from "
|
|
12
|
-
import type { WorkflowStep } from "
|
|
13
|
-
import { createIrcTool } from "
|
|
14
|
-
import { createSubmitResultTool } from "
|
|
3
|
+
import type { AgentConfig } from "../../agents/agent-config.ts";
|
|
4
|
+
import { resolveToolPolicy } from "../../agents/agent-config.ts";
|
|
5
|
+
import type { CrewRuntimeConfig } from "../../config/config.ts";
|
|
6
|
+
import { loadConfig } from "../../config/config.ts";
|
|
7
|
+
import { DEFAULT_LIVE_SESSION } from "../../config/defaults.ts";
|
|
8
|
+
import { appendEvent, appendEventFireAndForget } from "../../state/event-log/event-log.ts";
|
|
9
|
+
import type { TeamRunManifest, TeamTaskState, UsageState } from "../../state/types.ts";
|
|
10
|
+
import { logInternalError } from "../../utils/internal-error.ts";
|
|
11
|
+
import { redactSecrets } from "../../utils/redaction.ts";
|
|
12
|
+
import type { WorkflowStep } from "../../workflows/workflow-config.ts";
|
|
13
|
+
import { createIrcTool } from "../custom-tools/irc-tool.ts";
|
|
14
|
+
import { createSubmitResultTool } from "../custom-tools/submit-result-tool.ts";
|
|
15
|
+
import { buildMcpProxyFromSession } from "../mcp-proxy.ts";
|
|
16
|
+
import { buildConfiguredModelRouting } from "../model/model-fallback.ts";
|
|
17
|
+
import { readEnabledModelsPatterns } from "../model/model-scope.ts";
|
|
18
|
+
import { isLiveSessionRuntimeAvailable } from "../model/runtime-resolver.ts";
|
|
19
|
+
import { awaitRuntimeWarmup } from "../model/runtime-warmup.ts";
|
|
20
|
+
import { eventToSidechainType, sidechainOutputPath, writeSidechainEntry } from "../output/sidechain-output.ts";
|
|
21
|
+
// NOTE: buildMemoryBlock is intentionally NOT imported here. The agent memory
|
|
22
|
+
// block is injected via renderTaskPrompt().full (the USER prompt), which is
|
|
23
|
+
// shared by both the child-pi path (no system prompt) and the live-session
|
|
24
|
+
// path. Adding it to liveSystemPrompt() too duplicated the entire memory
|
|
25
|
+
// block (up to 200 lines) in both the user and system prompts. Keep memory
|
|
26
|
+
// in a single place: the shared user prompt. See G3 fix.
|
|
27
|
+
import { createStreamingOutput, type StreamingOutputHandle } from "../output/streaming-output.ts";
|
|
28
|
+
import { buildSensitivePathConstraint } from "../sensitive-paths.ts";
|
|
29
|
+
import { trackTaskUsage } from "../usage-tracker.ts";
|
|
30
|
+
import {
|
|
31
|
+
buildYieldReminder,
|
|
32
|
+
DEFAULT_YIELD_CONFIG,
|
|
33
|
+
extractYieldResult,
|
|
34
|
+
hasYieldInOutput,
|
|
35
|
+
isYieldEvent,
|
|
36
|
+
validateYieldData,
|
|
37
|
+
type YieldResult,
|
|
38
|
+
} from "../yield-handler.ts";
|
|
15
39
|
import { applyLiveAgentControlRequest, applyLiveAgentControlRequests, type LiveAgentControlCursor } from "./live-agent-control.ts";
|
|
16
40
|
import {
|
|
17
41
|
disposeLiveAgentSession,
|
|
@@ -28,32 +52,6 @@ import {
|
|
|
28
52
|
import { subscribeLiveControlRealtime } from "./live-control-realtime.ts";
|
|
29
53
|
import { buildExtensionBridge } from "./live-extension-bridge.ts";
|
|
30
54
|
import { collectLiveSessionHealth, formatLiveSessionDiagnostics } from "./live-session-health.ts";
|
|
31
|
-
import { buildMcpProxyFromSession } from "./mcp-proxy.ts";
|
|
32
|
-
import { buildConfiguredModelRouting } from "./model-fallback.ts";
|
|
33
|
-
import { readEnabledModelsPatterns } from "./model-scope.ts";
|
|
34
|
-
import { isLiveSessionRuntimeAvailable } from "./runtime-resolver.ts";
|
|
35
|
-
import { awaitRuntimeWarmup } from "./runtime-warmup.ts";
|
|
36
|
-
// prose-compressor imported for custom tool descriptions below;
|
|
37
|
-
// tool description compression for SDK-managed tools awaits SDK support.
|
|
38
|
-
import { buildSensitivePathConstraint } from "./sensitive-paths.ts";
|
|
39
|
-
import { eventToSidechainType, sidechainOutputPath, writeSidechainEntry } from "./sidechain-output.ts";
|
|
40
|
-
// NOTE: buildMemoryBlock is intentionally NOT imported here. The agent memory
|
|
41
|
-
// block is injected via renderTaskPrompt().full (the USER prompt), which is
|
|
42
|
-
// shared by both the child-pi path (no system prompt) and the live-session
|
|
43
|
-
// path. Adding it to liveSystemPrompt() too duplicated the entire memory
|
|
44
|
-
// block (up to 200 lines) in both the user and system prompts. Keep memory
|
|
45
|
-
// in a single place: the shared user prompt. See G3 fix.
|
|
46
|
-
import { createStreamingOutput, type StreamingOutputHandle } from "./streaming-output.ts";
|
|
47
|
-
import { trackTaskUsage } from "./usage-tracker.ts";
|
|
48
|
-
import {
|
|
49
|
-
buildYieldReminder,
|
|
50
|
-
DEFAULT_YIELD_CONFIG,
|
|
51
|
-
extractYieldResult,
|
|
52
|
-
hasYieldInOutput,
|
|
53
|
-
isYieldEvent,
|
|
54
|
-
validateYieldData,
|
|
55
|
-
type YieldResult,
|
|
56
|
-
} from "./yield-handler.ts";
|
|
57
55
|
|
|
58
56
|
/**
|
|
59
57
|
* Module-scoped latch for the optional peer dependency import. When N
|
|
@@ -537,9 +535,9 @@ export async function runLiveSessionTask(input: LiveSessionSpawnInput): Promise<
|
|
|
537
535
|
},
|
|
538
536
|
};
|
|
539
537
|
const mockSession = {
|
|
540
|
-
steer: async () =>
|
|
541
|
-
prompt: async () =>
|
|
542
|
-
abort: async () =>
|
|
538
|
+
steer: async () => undefined,
|
|
539
|
+
prompt: async () => undefined,
|
|
540
|
+
abort: async () => undefined,
|
|
543
541
|
};
|
|
544
542
|
registerLiveAgent(
|
|
545
543
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import { DEFAULT_CACHE, DEFAULT_PATHS } from "../config/defaults.ts";
|
|
4
|
-
import { activeRunEntries } from "../state/active-run-registry.ts";
|
|
4
|
+
import { activeRunEntries } from "../state/stores/active-run-registry.ts";
|
|
5
5
|
import type { TeamRunManifest } from "../state/types.ts";
|
|
6
6
|
import { closeWatcher, watchWithErrorHandler } from "../utils/fs-watch.ts";
|
|
7
7
|
import { findRepoRoot, projectCrewRoot, userCrewRoot } from "../utils/paths.ts";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as os from "node:os";
|
|
3
3
|
import * as path from "node:path";
|
|
4
|
-
import { errors } from "
|
|
4
|
+
import { errors } from "../../errors.ts";
|
|
5
5
|
import { fuzzyResolveModelId } from "./model-resolver.ts";
|
|
6
6
|
import { checkModelScope } from "./model-scope.ts";
|
|
7
7
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as os from "node:os";
|
|
3
3
|
import * as path from "node:path";
|
|
4
|
-
import type { AgentConfig } from "
|
|
5
|
-
import { resolveToolPolicy } from "
|
|
6
|
-
import { atomicWriteFile } from "
|
|
7
|
-
import { packageRoot, userPiRoot } from "
|
|
4
|
+
import type { AgentConfig } from "../../agents/agent-config.ts";
|
|
5
|
+
import { resolveToolPolicy } from "../../agents/agent-config.ts";
|
|
6
|
+
import { atomicWriteFile } from "../../state/atomic-write.ts";
|
|
7
|
+
import { packageRoot, userPiRoot } from "../../utils/paths.ts";
|
|
8
8
|
|
|
9
9
|
const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh"];
|
|
10
10
|
// FIX (2026-07-02): use packageRoot() instead of import.meta.url-relative path.
|
|
@@ -308,7 +308,22 @@ export function buildPiWorkerArgs(input: BuildPiWorkerArgsInput): BuildPiWorkerA
|
|
|
308
308
|
// would be nice but this path is sync and minimal — keeping parity
|
|
309
309
|
// with the rest of the agent loader's best-effort semantics).
|
|
310
310
|
const excluded = new Set((input.agent.excludeExtensions ?? []).map((name) => path.basename(name).toLowerCase()));
|
|
311
|
-
|
|
311
|
+
let allowed = input.agent.extensions.filter((ext) => !excluded.has(path.basename(ext).toLowerCase()));
|
|
312
|
+
// SEC-1: Defense-in-depth — deny untrusted project-sourced extensions
|
|
313
|
+
// unless explicitly trusted via PI_CREW_TRUST_PROJECT_AGENT_EXTENSIONS=1.
|
|
314
|
+
// Even if parseAgentFile missed the strip (e.g., agent was constructed
|
|
315
|
+
// at runtime), buildPiWorkerArgs must never emit --extension
|
|
316
|
+
// <attacker-path> for a project / project-pi agent. Both `project`
|
|
317
|
+
// (.crew/agents/) and `project-pi` (.pi/agents/) are repo-adjacent /
|
|
318
|
+
// untrusted sources. Only the trusted PROMPT_RUNTIME_EXTENSION_PATH is
|
|
319
|
+
// allowed through.
|
|
320
|
+
const extEnv = input.env ?? process.env;
|
|
321
|
+
if (
|
|
322
|
+
(input.agent.source === "project" || input.agent.source === "project-pi") &&
|
|
323
|
+
extEnv.PI_CREW_TRUST_PROJECT_AGENT_EXTENSIONS !== "1"
|
|
324
|
+
) {
|
|
325
|
+
allowed = allowed.filter((ext) => path.resolve(ext) === path.resolve(PROMPT_RUNTIME_EXTENSION_PATH));
|
|
326
|
+
}
|
|
312
327
|
for (const extension of [PROMPT_RUNTIME_EXTENSION_PATH, ...allowed]) args.push("--extension", extension);
|
|
313
328
|
} else {
|
|
314
329
|
args.push("--extension", PROMPT_RUNTIME_EXTENSION_PATH);
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* provider-extensions.ts — discover Pi provider extensions automatically.
|
|
3
|
+
*
|
|
4
|
+
* WHY: pi-crew spawns child-pi workers with `--no-extensions` (security
|
|
5
|
+
* posture: prevent untrusted user extensions from auto-loading). But that
|
|
6
|
+
* made extension-registered PROVIDERS (e.g. pi-commandcode-provider, installed
|
|
7
|
+
* via `pi install npm:...`) unresolvable inside subagents — every model from
|
|
8
|
+
* those providers fell back and died with 429s. Pi DOES load explicitly-passed
|
|
9
|
+
* `--extension <path>` even after `--no-extensions`, so the fix is to discover
|
|
10
|
+
* the user's installed provider packages and pass them explicitly.
|
|
11
|
+
*
|
|
12
|
+
* This module reads Pi's own package registry (`~/.pi/agent/settings.json`
|
|
13
|
+
* `packages` field + the npm install dir) and resolves each package to its
|
|
14
|
+
* extension entry point. That's the SANCTIONED channel — the user explicitly
|
|
15
|
+
* installed these via `pi install`, so they are trusted (unlike arbitrary
|
|
16
|
+
* `~/.pi/agent/extensions/*.ts` which may be tool extensions with deps that
|
|
17
|
+
* fail in child contexts).
|
|
18
|
+
*
|
|
19
|
+
* SECURITY: only packages the USER installed are auto-loaded. Project-local
|
|
20
|
+
* packages and `.pi/agent/extensions/*.ts` are NOT auto-discovered here (the
|
|
21
|
+
* existing SEC-1 gate in discover-agents.ts still strips project agents).
|
|
22
|
+
*/
|
|
23
|
+
import * as fs from "node:fs";
|
|
24
|
+
import * as path from "node:path";
|
|
25
|
+
import { userPiRoot } from "../../utils/paths.ts";
|
|
26
|
+
|
|
27
|
+
export interface DiscoveredProviderExtension {
|
|
28
|
+
/** Package specifier as written in settings.json packages (e.g. "npm:pi-commandcode-provider"). */
|
|
29
|
+
spec: string;
|
|
30
|
+
/** Resolved absolute path to the extension entry point. */
|
|
31
|
+
entryPath: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Resolve the extension entry point for an installed Pi package.
|
|
36
|
+
* Order: package.json `pi.extensions` (array) → `index.ts` → `index.mjs` → `index.js` → `src/index.ts`.
|
|
37
|
+
* Returns undefined when the package has no resolvable entry point.
|
|
38
|
+
*/
|
|
39
|
+
function resolvePackageEntry(pkgDir: string): string | undefined {
|
|
40
|
+
const pkgJsonPath = path.join(pkgDir, "package.json");
|
|
41
|
+
if (fs.existsSync(pkgJsonPath)) {
|
|
42
|
+
try {
|
|
43
|
+
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8")) as {
|
|
44
|
+
pi?: { extensions?: string[] };
|
|
45
|
+
type?: string;
|
|
46
|
+
main?: string;
|
|
47
|
+
};
|
|
48
|
+
const piExts = pkg.pi?.extensions;
|
|
49
|
+
if (Array.isArray(piExts) && piExts.length > 0) {
|
|
50
|
+
for (const rel of piExts) {
|
|
51
|
+
const abs = path.resolve(pkgDir, rel);
|
|
52
|
+
if (fs.existsSync(abs)) return abs;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Fall back to `main` when it points at a loadable entry (rare for extensions).
|
|
56
|
+
if (pkg.main?.endsWith(".ts")) {
|
|
57
|
+
const abs = path.resolve(pkgDir, pkg.main);
|
|
58
|
+
if (fs.existsSync(abs)) return abs;
|
|
59
|
+
}
|
|
60
|
+
} catch {
|
|
61
|
+
/* malformed package.json — fall through to filename probes */
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
for (const name of ["index.ts", "index.mjs", "index.js", "src/index.ts"]) {
|
|
65
|
+
const abs = path.join(pkgDir, name);
|
|
66
|
+
if (fs.existsSync(abs)) return abs;
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Discover provider extension entry points from Pi's installed package registry.
|
|
73
|
+
* Reads `~/.pi/agent/settings.json` → `packages` (npm: specs only — local
|
|
74
|
+
* relative paths are the pi-crew extension itself and other local work, which
|
|
75
|
+
* children already handle) and resolves each against `~/.pi/agent/npm/node_modules/`.
|
|
76
|
+
*
|
|
77
|
+
* Non-npm specs (local paths, git URLs) are skipped: they are not part of the
|
|
78
|
+
* npm registry dir and resolving them is outside this module's scope.
|
|
79
|
+
*/
|
|
80
|
+
export function discoverProviderExtensions(settingsPath?: string): DiscoveredProviderExtension[] {
|
|
81
|
+
const root = userPiRoot();
|
|
82
|
+
const settingsFile = settingsPath ?? path.join(root, "settings.json");
|
|
83
|
+
const out: DiscoveredProviderExtension[] = [];
|
|
84
|
+
if (!fs.existsSync(settingsFile)) return out;
|
|
85
|
+
let settings: { packages?: string[] };
|
|
86
|
+
try {
|
|
87
|
+
settings = JSON.parse(fs.readFileSync(settingsFile, "utf8")) as { packages?: string[] };
|
|
88
|
+
} catch {
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
// The npm registry dir lives beside settings.json (same agent root). When a
|
|
92
|
+
// custom settingsPath is supplied (tests), derive npmBase from IT so the
|
|
93
|
+
// package resolution stays consistent with the settings file being read.
|
|
94
|
+
const baseDir = path.dirname(settingsFile);
|
|
95
|
+
const npmBase = path.join(baseDir, "npm", "node_modules");
|
|
96
|
+
for (const spec of settings.packages ?? []) {
|
|
97
|
+
if (typeof spec !== "string") continue;
|
|
98
|
+
// Only npm: specs resolve into the npm registry dir. Skip local path
|
|
99
|
+
// packages (e.g. "../../source/my_pi/pi-crew") and git specs.
|
|
100
|
+
if (!spec.startsWith("npm:")) continue;
|
|
101
|
+
const pkgName = spec.slice(4);
|
|
102
|
+
// Scoped packages: "@scope/name" → "@scope/name"; plain: "name".
|
|
103
|
+
const pkgDir = path.join(npmBase, pkgName);
|
|
104
|
+
if (!fs.existsSync(pkgDir)) continue;
|
|
105
|
+
const entryPath = resolvePackageEntry(pkgDir);
|
|
106
|
+
if (entryPath) out.push({ spec, entryPath });
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Convenience: absolute entry paths of all discovered provider extensions.
|
|
113
|
+
*/
|
|
114
|
+
export function discoverProviderExtensionPaths(settingsPath?: string): string[] {
|
|
115
|
+
return discoverProviderExtensions(settingsPath).map((e) => e.entryPath);
|
|
116
|
+
}
|