pi-crew 0.9.53 → 0.9.55
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/CHANGELOG.md +45 -0
- package/package.json +6 -3
- package/scripts/clean-strip-types.mjs +60 -0
- package/src/adapters/claude-adapter.ts +23 -0
- package/src/adapters/codex-adapter.ts +21 -0
- package/src/adapters/cursor-adapter.ts +17 -0
- package/src/adapters/export-util.ts +143 -0
- package/src/adapters/index.ts +15 -0
- package/src/adapters/registry.ts +18 -0
- package/src/adapters/types.ts +23 -0
- package/src/agents/agent-config.ts +194 -0
- package/src/agents/agent-search.ts +98 -0
- package/src/agents/agent-serializer.ts +38 -0
- package/src/agents/discover-agents.ts +623 -0
- package/src/benchmark/benchmark-runner.ts +313 -0
- package/src/benchmark/feedback-loop.ts +73 -0
- package/src/config/config.ts +1270 -0
- package/src/config/defaults.ts +193 -0
- package/src/config/drift-detector.ts +290 -0
- package/src/config/markers.ts +330 -0
- package/src/config/resilient-parser.ts +117 -0
- package/src/config/role-tools.ts +118 -0
- package/src/config/suggestions.ts +75 -0
- package/src/config/types.ts +280 -0
- package/src/errors.ts +194 -0
- package/src/extension/action-suggestions.ts +117 -0
- package/src/extension/async-notifier.ts +179 -0
- package/src/extension/autonomous-policy.ts +209 -0
- package/src/extension/command-completions.ts +120 -0
- package/src/extension/context-status-injection.ts +185 -0
- package/src/extension/crew-autocomplete.ts +131 -0
- package/src/extension/crew-cleanup.ts +168 -0
- package/src/extension/crew-input-router.ts +93 -0
- package/src/extension/crew-shortcuts.ts +87 -0
- package/src/extension/crew-vibes/cat-frames.ts +18 -0
- package/src/extension/crew-vibes/config.ts +195 -0
- package/src/extension/crew-vibes/figures.ts +101 -0
- package/src/extension/crew-vibes/font-detect.ts +71 -0
- package/src/extension/crew-vibes/footer.ts +292 -0
- package/src/extension/crew-vibes/index.ts +432 -0
- package/src/extension/crew-vibes/provider-usage.ts +396 -0
- package/src/extension/crew-vibes/render.ts +206 -0
- package/src/extension/crew-vibes/speed.ts +286 -0
- package/src/extension/cross-extension-rpc.ts +350 -0
- package/src/extension/help.ts +62 -0
- package/src/extension/import-index.ts +74 -0
- package/src/extension/knowledge-injection.ts +402 -0
- package/src/extension/management.ts +571 -0
- package/src/extension/message-renderers.ts +108 -0
- package/src/extension/notification-router.ts +152 -0
- package/src/extension/notification-sink.ts +54 -0
- package/src/extension/pi-api.ts +56 -0
- package/src/extension/plan-orchestrate.ts +302 -0
- package/src/extension/project-init.ts +170 -0
- package/src/extension/register.ts +113 -0
- package/src/extension/registration/artifact-cleanup.ts +20 -0
- package/src/extension/registration/command-registration.ts +58 -0
- package/src/extension/registration/command-utils.ts +58 -0
- package/src/extension/registration/commands.ts +1228 -0
- package/src/extension/registration/compaction-guard.ts +333 -0
- package/src/extension/registration/context-builder.ts +135 -0
- package/src/extension/registration/crash-recovery-cache.ts +54 -0
- package/src/extension/registration/foreground-run-controller.ts +238 -0
- package/src/extension/registration/hook-registration.ts +119 -0
- package/src/extension/registration/lazy-configurers.ts +124 -0
- package/src/extension/registration/lifecycle-handlers.ts +923 -0
- package/src/extension/registration/lifecycle.ts +259 -0
- package/src/extension/registration/observability.ts +322 -0
- package/src/extension/registration/registration-types.ts +158 -0
- package/src/extension/registration/runtime-cleanup.ts +230 -0
- package/src/extension/registration/subagent-helpers.ts +125 -0
- package/src/extension/registration/subagent-manager-setup.ts +330 -0
- package/src/extension/registration/subagent-tools.ts +456 -0
- package/src/extension/registration/team-tool.ts +225 -0
- package/src/extension/registration/tool-registration.ts +50 -0
- package/src/extension/registration/ui.ts +172 -0
- package/src/extension/registration/viewers.ts +121 -0
- package/src/extension/registration/wire-cross-extension.ts +37 -0
- package/src/extension/result-watcher.ts +139 -0
- package/src/extension/rpc-hmac.ts +256 -0
- package/src/extension/run-bundle-schema.ts +104 -0
- package/src/extension/run-export.ts +97 -0
- package/src/extension/run-import.ts +168 -0
- package/src/extension/run-index.ts +131 -0
- package/src/extension/run-maintenance.ts +190 -0
- package/src/extension/session-summary.ts +18 -0
- package/src/extension/team-manager-command.ts +153 -0
- package/src/extension/team-onboard.ts +180 -0
- package/src/extension/team-recommendation.ts +288 -0
- package/src/extension/team-tool/anchor.ts +172 -0
- package/src/extension/team-tool/api.ts +1244 -0
- package/src/extension/team-tool/auto-summarize.ts +142 -0
- package/src/extension/team-tool/cache-control.ts +19 -0
- package/src/extension/team-tool/cancel.ts +337 -0
- package/src/extension/team-tool/chain-dispatch.ts +95 -0
- package/src/extension/team-tool/chain-executor.ts +379 -0
- package/src/extension/team-tool/config-patch.ts +50 -0
- package/src/extension/team-tool/context.ts +149 -0
- package/src/extension/team-tool/destructive-gate.ts +52 -0
- package/src/extension/team-tool/dispatch/automate.ts +80 -0
- package/src/extension/team-tool/dispatch/control.ts +42 -0
- package/src/extension/team-tool/dispatch/index.ts +95 -0
- package/src/extension/team-tool/dispatch/manage.ts +161 -0
- package/src/extension/team-tool/dispatch/run.ts +53 -0
- package/src/extension/team-tool/dispatch/status.ts +187 -0
- package/src/extension/team-tool/doctor.ts +431 -0
- package/src/extension/team-tool/explain.ts +282 -0
- package/src/extension/team-tool/failure-patterns.ts +118 -0
- package/src/extension/team-tool/goal-wrap.ts +330 -0
- package/src/extension/team-tool/goal.ts +556 -0
- package/src/extension/team-tool/handle-schedule.ts +332 -0
- package/src/extension/team-tool/handle-settings.ts +520 -0
- package/src/extension/team-tool/health-monitor.ts +481 -0
- package/src/extension/team-tool/inspect.ts +88 -0
- package/src/extension/team-tool/intent-policy.ts +45 -0
- package/src/extension/team-tool/lifecycle-actions.ts +615 -0
- package/src/extension/team-tool/orchestrate.ts +98 -0
- package/src/extension/team-tool/parallel-dispatch.ts +183 -0
- package/src/extension/team-tool/plan.ts +50 -0
- package/src/extension/team-tool/respond.ts +150 -0
- package/src/extension/team-tool/run-deadline.ts +66 -0
- package/src/extension/team-tool/run-not-found.ts +49 -0
- package/src/extension/team-tool/run.ts +1051 -0
- package/src/extension/team-tool/status.ts +260 -0
- package/src/extension/team-tool/workflow-manage.ts +261 -0
- package/src/extension/team-tool-types.ts +26 -0
- package/src/extension/team-tool.ts +750 -0
- package/src/extension/tool-result.ts +16 -0
- package/src/extension/validate-resources.ts +108 -0
- package/src/hooks/registry.ts +200 -0
- package/src/hooks/types.ts +69 -0
- package/src/i18n.ts +212 -0
- package/src/observability/correlation.ts +50 -0
- package/src/observability/event-bus.ts +86 -0
- package/src/observability/event-to-metric.ts +170 -0
- package/src/observability/exporters/adapter.ts +27 -0
- package/src/observability/exporters/otlp-exporter.ts +356 -0
- package/src/observability/exporters/prometheus-exporter.ts +54 -0
- package/src/observability/metric-registry.ts +100 -0
- package/src/observability/metric-retention.ts +64 -0
- package/src/observability/metric-sink.ts +99 -0
- package/src/observability/metrics-primitives.ts +219 -0
- package/src/plugins/plugin-define.ts +6 -0
- package/src/plugins/plugin-registry.ts +32 -0
- package/src/plugins/plugins/index.ts +3 -0
- package/src/plugins/plugins/nextjs.ts +19 -0
- package/src/plugins/plugins/vite.ts +10 -0
- package/src/plugins/plugins/vitest.ts +9 -0
- package/src/prompt/prompt-runtime.ts +380 -0
- package/src/runtime/adaptive-plan.ts +563 -0
- package/src/runtime/agent-control.ts +215 -0
- package/src/runtime/agent-memory.ts +81 -0
- package/src/runtime/agent-observability.ts +122 -0
- package/src/runtime/anchor-manager.ts +475 -0
- package/src/runtime/async-marker.ts +32 -0
- package/src/runtime/async-runner.ts +381 -0
- package/src/runtime/attention-events.ts +28 -0
- package/src/runtime/auto-summarize.ts +344 -0
- package/src/runtime/background-runner.ts +840 -0
- package/src/runtime/batch-barrier.ts +147 -0
- package/src/runtime/broker-issuer.ts +39 -0
- package/src/runtime/cancellation-token.ts +99 -0
- package/src/runtime/cancellation.ts +99 -0
- package/src/runtime/capability-inventory.ts +137 -0
- package/src/runtime/chain-parser.ts +237 -0
- package/src/runtime/chain-runner.ts +606 -0
- package/src/runtime/checkpoint.ts +291 -0
- package/src/runtime/child-pi-constants.ts +42 -0
- package/src/runtime/child-pi-kill.ts +180 -0
- package/src/runtime/child-pi-pool.ts +68 -0
- package/src/runtime/child-pi-spawn.ts +287 -0
- package/src/runtime/child-pi-steering.ts +128 -0
- package/src/runtime/child-pi-streams.ts +296 -0
- package/src/runtime/child-pi-transcript.ts +169 -0
- package/src/runtime/child-pi.ts +1105 -0
- package/src/runtime/coalesce-tasks.ts +268 -0
- package/src/runtime/code-summary.ts +292 -0
- package/src/runtime/command-trace.ts +105 -0
- package/src/runtime/compact-pipeline.ts +56 -0
- package/src/runtime/compact-stages/ansi-strip-stage.ts +25 -0
- package/src/runtime/compact-stages/blank-collapse-stage.ts +31 -0
- package/src/runtime/compact-stages/deduplicate-stage.ts +34 -0
- package/src/runtime/compact-stages/head-snap-stage.ts +57 -0
- package/src/runtime/compact-stages/index.ts +23 -0
- package/src/runtime/compact-stages/tail-capture-stage.ts +77 -0
- package/src/runtime/compact-stages/truncation-stage.ts +74 -0
- package/src/runtime/compaction-summary.ts +278 -0
- package/src/runtime/completion-guard.ts +207 -0
- package/src/runtime/concurrency.ts +58 -0
- package/src/runtime/crash-classification.ts +229 -0
- package/src/runtime/crash-recovery.ts +594 -0
- package/src/runtime/crew-agent-records.ts +595 -0
- package/src/runtime/crew-agent-runtime.ts +62 -0
- package/src/runtime/crew-broker-child.ts +88 -0
- package/src/runtime/crew-broker-client.ts +673 -0
- package/src/runtime/crew-broker-tokens.ts +159 -0
- package/src/runtime/crew-broker.ts +1304 -0
- package/src/runtime/crew-hooks.ts +227 -0
- package/src/runtime/cross-extension-rpc.ts +143 -0
- package/src/runtime/custom-tools/irc-tool.ts +282 -0
- package/src/runtime/custom-tools/submit-result-tool.ts +102 -0
- package/src/runtime/deadletter.ts +47 -0
- package/src/runtime/delivery-coordinator.ts +211 -0
- package/src/runtime/delta-conflict.ts +348 -0
- package/src/runtime/deterministic-ast.ts +161 -0
- package/src/runtime/diagnostic-export.ts +171 -0
- package/src/runtime/direct-run.ts +45 -0
- package/src/runtime/dwf-state-store.ts +102 -0
- package/src/runtime/dynamic-workflow-context.ts +1013 -0
- package/src/runtime/dynamic-workflow-runner.ts +325 -0
- package/src/runtime/effectiveness.ts +90 -0
- package/src/runtime/errors/crew-errors.ts +162 -0
- package/src/runtime/event-stream-bridge.ts +98 -0
- package/src/runtime/foreground-control.ts +193 -0
- package/src/runtime/foreground-watchdog.ts +132 -0
- package/src/runtime/global-worker-cap.ts +96 -0
- package/src/runtime/goal-achievement.ts +148 -0
- package/src/runtime/goal-evaluator.ts +365 -0
- package/src/runtime/goal-loop-runner.ts +825 -0
- package/src/runtime/goal-state-store.ts +219 -0
- package/src/runtime/green-contract.ts +55 -0
- package/src/runtime/group-join.ts +267 -0
- package/src/runtime/handoff-manager.ts +598 -0
- package/src/runtime/heartbeat-gradient.ts +36 -0
- package/src/runtime/heartbeat-watcher.ts +239 -0
- package/src/runtime/hidden-handoff.ts +407 -0
- package/src/runtime/important-line-classifier.ts +140 -0
- package/src/runtime/intercom-bridge.ts +187 -0
- package/src/runtime/iteration-hooks.ts +305 -0
- package/src/runtime/live-agent-control.ts +136 -0
- package/src/runtime/live-agent-manager.ts +704 -0
- package/src/runtime/live-control-realtime.ts +56 -0
- package/src/runtime/live-extension-bridge.ts +148 -0
- package/src/runtime/live-irc.ts +97 -0
- package/src/runtime/live-session-health.ts +108 -0
- package/src/runtime/live-session-runtime.ts +1146 -0
- package/src/runtime/loop-gates.ts +128 -0
- package/src/runtime/manifest-cache.ts +375 -0
- package/src/runtime/mcp-proxy.ts +105 -0
- package/src/runtime/metric-parser.ts +36 -0
- package/src/runtime/model-fallback.ts +409 -0
- package/src/runtime/model-resolver.ts +126 -0
- package/src/runtime/model-scope.ts +158 -0
- package/src/runtime/orphan-worker-registry.ts +465 -0
- package/src/runtime/output-validator.ts +202 -0
- package/src/runtime/overflow-recovery.ts +206 -0
- package/src/runtime/parallel-research.ts +68 -0
- package/src/runtime/parallel-utils.ts +160 -0
- package/src/runtime/parent-guard.ts +134 -0
- package/src/runtime/path-overlap.ts +150 -0
- package/src/runtime/peer-dep.ts +292 -0
- package/src/runtime/per-write-validator.ts +181 -0
- package/src/runtime/phase-progress.ts +217 -0
- package/src/runtime/phase-tracker.ts +385 -0
- package/src/runtime/pi-args.ts +655 -0
- package/src/runtime/pi-json-output.ts +170 -0
- package/src/runtime/pi-spawn.ts +273 -0
- package/src/runtime/pipeline-runner.ts +523 -0
- package/src/runtime/plan-templates.ts +201 -0
- package/src/runtime/policy-engine.ts +115 -0
- package/src/runtime/post-checks.ts +142 -0
- package/src/runtime/post-exit-stdio-guard.ts +109 -0
- package/src/runtime/process-lifecycle.ts +491 -0
- package/src/runtime/process-status.ts +154 -0
- package/src/runtime/progress-event-coalescer.ts +44 -0
- package/src/runtime/progress-tracker.ts +124 -0
- package/src/runtime/prose-compressor.ts +162 -0
- package/src/runtime/recovery-recipes.ts +203 -0
- package/src/runtime/replace.ts +570 -0
- package/src/runtime/resilient-edit.ts +153 -0
- package/src/runtime/result-extractor.ts +217 -0
- package/src/runtime/retry-executor.ts +109 -0
- package/src/runtime/retry-runner.ts +336 -0
- package/src/runtime/role-permission.ts +59 -0
- package/src/runtime/run-coalesced-task-group.ts +308 -0
- package/src/runtime/run-drift.ts +219 -0
- package/src/runtime/run-tracker.ts +116 -0
- package/src/runtime/run-worker.ts +78 -0
- package/src/runtime/runtime-policy.ts +29 -0
- package/src/runtime/runtime-resolver.ts +172 -0
- package/src/runtime/runtime-warmup.ts +160 -0
- package/src/runtime/scheduler.ts +353 -0
- package/src/runtime/semaphore.ts +141 -0
- package/src/runtime/sensitive-paths.ts +93 -0
- package/src/runtime/session-resources.ts +25 -0
- package/src/runtime/session-snapshot.ts +59 -0
- package/src/runtime/session-usage.ts +79 -0
- package/src/runtime/settings-store.ts +155 -0
- package/src/runtime/sidechain-output.ts +35 -0
- package/src/runtime/single-agent-compose.ts +84 -0
- package/src/runtime/skill-effectiveness.ts +524 -0
- package/src/runtime/skill-instructions.ts +394 -0
- package/src/runtime/stale-reconciler.ts +680 -0
- package/src/runtime/stream-preview.ts +184 -0
- package/src/runtime/streaming-output.ts +50 -0
- package/src/runtime/subagent-manager.ts +561 -0
- package/src/runtime/subprocess-tool-registry.ts +70 -0
- package/src/runtime/supervisor-contact.ts +64 -0
- package/src/runtime/task-display.ts +52 -0
- package/src/runtime/task-graph-scheduler.ts +227 -0
- package/src/runtime/task-graph.ts +290 -0
- package/src/runtime/task-health.ts +83 -0
- package/src/runtime/task-id.ts +161 -0
- package/src/runtime/task-output-context.ts +602 -0
- package/src/runtime/task-packet.ts +268 -0
- package/src/runtime/task-quality.ts +199 -0
- package/src/runtime/task-runner/capabilities.ts +78 -0
- package/src/runtime/task-runner/child-executor.ts +790 -0
- package/src/runtime/task-runner/context-retrieval.ts +163 -0
- package/src/runtime/task-runner/live-executor.ts +227 -0
- package/src/runtime/task-runner/output-splitter.ts +152 -0
- package/src/runtime/task-runner/post-execution.ts +480 -0
- package/src/runtime/task-runner/pre-execution.ts +365 -0
- package/src/runtime/task-runner/progress.ts +157 -0
- package/src/runtime/task-runner/prompt-builder.ts +278 -0
- package/src/runtime/task-runner/prompt-pipeline.ts +88 -0
- package/src/runtime/task-runner/result-utils.ts +16 -0
- package/src/runtime/task-runner/retrieval-orchestrator.ts +310 -0
- package/src/runtime/task-runner/run-projection.ts +125 -0
- package/src/runtime/task-runner/scaffold-executor.ts +25 -0
- package/src/runtime/task-runner/state-helpers.ts +176 -0
- package/src/runtime/task-runner/tail-read.ts +34 -0
- package/src/runtime/task-runner.ts +216 -0
- package/src/runtime/team-runner-artifacts.ts +13 -0
- package/src/runtime/team-runner.ts +2396 -0
- package/src/runtime/tool-output-pruner.ts +333 -0
- package/src/runtime/tool-progress.ts +278 -0
- package/src/runtime/usage-tracker.ts +73 -0
- package/src/runtime/verification-gates.ts +579 -0
- package/src/runtime/verification-integrity.ts +108 -0
- package/src/runtime/verification-worktree.ts +186 -0
- package/src/runtime/worker-heartbeat.ts +25 -0
- package/src/runtime/worker-startup.ts +83 -0
- package/src/runtime/workflow-state.ts +195 -0
- package/src/runtime/workspace-lock.ts +443 -0
- package/src/runtime/workspace-tree.ts +312 -0
- package/src/runtime/yield-handler.ts +224 -0
- package/src/runtime/zombie-scanner.ts +298 -0
- package/src/schema/config-schema.ts +327 -0
- package/src/schema/team-tool-schema.ts +492 -0
- package/src/schema/validation-types.ts +159 -0
- package/src/skills/discover-skills.ts +203 -0
- package/src/skills/skill-templates.ts +456 -0
- package/src/skills/validate.ts +285 -0
- package/src/state/active-run-registry.ts +439 -0
- package/src/state/artifact-store.ts +176 -0
- package/src/state/atomic-write.ts +970 -0
- package/src/state/blob-store.ts +308 -0
- package/src/state/contracts.ts +160 -0
- package/src/state/crew-init.ts +269 -0
- package/src/state/decision-ledger.ts +372 -0
- package/src/state/event-log-rotation.ts +399 -0
- package/src/state/event-log.ts +1465 -0
- package/src/state/event-reconstructor.ts +229 -0
- package/src/state/gitignore-manager.ts +46 -0
- package/src/state/health-store.ts +79 -0
- package/src/state/hook-instinct-bridge.ts +94 -0
- package/src/state/hook-integrations.ts +51 -0
- package/src/state/instinct-store.ts +275 -0
- package/src/state/jsonl-writer.ts +107 -0
- package/src/state/locks.ts +562 -0
- package/src/state/mailbox.ts +916 -0
- package/src/state/observation-store.ts +176 -0
- package/src/state/run-cache.ts +193 -0
- package/src/state/run-graph.ts +183 -0
- package/src/state/run-metrics.ts +165 -0
- package/src/state/schedule.ts +166 -0
- package/src/state/session-state-map.ts +51 -0
- package/src/state/state-store.ts +973 -0
- package/src/state/task-claims.ts +61 -0
- package/src/state/tiered-eval.ts +480 -0
- package/src/state/types-eval.ts +58 -0
- package/src/state/types.ts +447 -0
- package/src/state/usage.ts +138 -0
- package/src/state/worker-atomic-writer.ts +198 -0
- package/src/subagents/async-entry.ts +1 -0
- package/src/subagents/index.ts +3 -0
- package/src/subagents/live/control.ts +1 -0
- package/src/subagents/live/manager.ts +1 -0
- package/src/subagents/live/realtime.ts +1 -0
- package/src/subagents/live/session-runtime.ts +1 -0
- package/src/subagents/manager.ts +1 -0
- package/src/subagents/spawn.ts +1 -0
- package/src/teams/discover-teams.ts +187 -0
- package/src/teams/team-config.ts +27 -0
- package/src/teams/team-serializer.ts +38 -0
- package/src/tools/safe-bash-extension.ts +54 -0
- package/src/tools/safe-bash.ts +505 -0
- package/src/types/diff.d.ts +18 -0
- package/src/types/new-api-types.ts +35 -0
- package/src/ui/agent-management-overlay.ts +160 -0
- package/src/ui/card-colors.ts +139 -0
- package/src/ui/crew-footer.ts +102 -0
- package/src/ui/crew-select-list.ts +112 -0
- package/src/ui/dashboard-panes/agents-pane.ts +164 -0
- package/src/ui/dashboard-panes/cancellation-pane.ts +66 -0
- package/src/ui/dashboard-panes/capability-pane.ts +77 -0
- package/src/ui/dashboard-panes/health-pane.ts +31 -0
- package/src/ui/dashboard-panes/mailbox-pane.ts +35 -0
- package/src/ui/dashboard-panes/metrics-pane.ts +37 -0
- package/src/ui/dashboard-panes/progress-pane.ts +38 -0
- package/src/ui/dashboard-panes/transcript-pane.ts +10 -0
- package/src/ui/deploy-bundled-themes.ts +71 -0
- package/src/ui/dwf-phase-display.ts +151 -0
- package/src/ui/dynamic-border.ts +35 -0
- package/src/ui/format-helpers.ts +31 -0
- package/src/ui/heartbeat-aggregator.ts +74 -0
- package/src/ui/key-utils.ts +42 -0
- package/src/ui/keybinding-map.ts +248 -0
- package/src/ui/layout-primitives.ts +106 -0
- package/src/ui/live-conversation-overlay.ts +183 -0
- package/src/ui/live-duration.ts +55 -0
- package/src/ui/live-run-sidebar.ts +293 -0
- package/src/ui/loaders.ts +6 -0
- package/src/ui/mascot.ts +449 -0
- package/src/ui/overlays/agent-picker-overlay.ts +66 -0
- package/src/ui/overlays/confirm-overlay.ts +60 -0
- package/src/ui/overlays/help-overlay.ts +177 -0
- package/src/ui/overlays/mailbox-compose-overlay.ts +181 -0
- package/src/ui/overlays/mailbox-compose-preview.ts +78 -0
- package/src/ui/overlays/mailbox-detail-overlay.ts +155 -0
- package/src/ui/pi-ui-compat.ts +68 -0
- package/src/ui/powerbar-publisher.ts +459 -0
- package/src/ui/render-coalescer.ts +101 -0
- package/src/ui/render-diff.ts +160 -0
- package/src/ui/render-scheduler.ts +278 -0
- package/src/ui/run-action-dispatcher.ts +182 -0
- package/src/ui/run-dashboard.ts +910 -0
- package/src/ui/run-event-bus.ts +381 -0
- package/src/ui/run-snapshot-cache.ts +1057 -0
- package/src/ui/settings-overlay.ts +1067 -0
- package/src/ui/shared-overlay-scheduler.ts +96 -0
- package/src/ui/snapshot-types.ts +90 -0
- package/src/ui/spinner.ts +17 -0
- package/src/ui/status-colors.ts +143 -0
- package/src/ui/syntax-highlight.ts +136 -0
- package/src/ui/terminal-status.ts +269 -0
- package/src/ui/theme-adapter.ts +271 -0
- package/src/ui/theme-discovery.ts +199 -0
- package/src/ui/tool-progress-formatter.ts +93 -0
- package/src/ui/tool-renderers/brief-mode.ts +225 -0
- package/src/ui/tool-renderers/index.ts +726 -0
- package/src/ui/transcript-cache.ts +128 -0
- package/src/ui/transcript-entries.ts +256 -0
- package/src/ui/transcript-viewer.ts +424 -0
- package/src/ui/widget/index.ts +418 -0
- package/src/ui/widget/widget-formatters.ts +182 -0
- package/src/ui/widget/widget-model.ts +110 -0
- package/src/ui/widget/widget-renderer.ts +182 -0
- package/src/ui/widget/widget-types.ts +36 -0
- package/src/utils/bm25-search.ts +235 -0
- package/src/utils/completion-dedupe.ts +63 -0
- package/src/utils/conflict-detect.ts +668 -0
- package/src/utils/env-allowlist.ts +30 -0
- package/src/utils/env-filter.ts +155 -0
- package/src/utils/file-coalescer.ts +98 -0
- package/src/utils/fingerprint.ts +180 -0
- package/src/utils/frontmatter.ts +70 -0
- package/src/utils/fs-watch.ts +37 -0
- package/src/utils/gh-protocol.ts +556 -0
- package/src/utils/git.ts +260 -0
- package/src/utils/guards.ts +107 -0
- package/src/utils/ids.ts +24 -0
- package/src/utils/incremental-reader.ts +220 -0
- package/src/utils/internal-error.ts +10 -0
- package/src/utils/names.ts +36 -0
- package/src/utils/ndjson.ts +115 -0
- package/src/utils/paths.ts +227 -0
- package/src/utils/project-detector.ts +160 -0
- package/src/utils/redaction.ts +370 -0
- package/src/utils/resolve-shell.ts +36 -0
- package/src/utils/run-watcher-registry.ts +152 -0
- package/src/utils/safe-paths.ts +393 -0
- package/src/utils/scan-cache.ts +144 -0
- package/src/utils/session-utils.ts +110 -0
- package/src/utils/sleep.ts +54 -0
- package/src/utils/socket-path.ts +164 -0
- package/src/utils/sse-parser.ts +131 -0
- package/src/utils/task-name-generator.ts +337 -0
- package/src/utils/timings.ts +33 -0
- package/src/utils/token-counter.ts +200 -0
- package/src/utils/visual.ts +207 -0
- package/src/workflows/cost-estimator.ts +34 -0
- package/src/workflows/discover-workflows.ts +308 -0
- package/src/workflows/intermediate-store.ts +166 -0
- package/src/workflows/preflight-validator.ts +168 -0
- package/src/workflows/topology-analyzer.ts +203 -0
- package/src/workflows/validate-workflow.ts +50 -0
- package/src/workflows/workflow-config.ts +75 -0
- package/src/workflows/workflow-serializer.ts +32 -0
- package/src/worktree/branch-freshness.ts +112 -0
- package/src/worktree/cleanup.ts +341 -0
- package/src/worktree/worktree-manager.ts +1204 -0
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Concrete `ChainTaskRunner` that executes each chain step as a REAL team run.
|
|
3
|
+
*
|
|
4
|
+
* This is the production wiring that makes `ChainRunner` (and Fix C's
|
|
5
|
+
* `__chainHistoryNotes`) reachable: previously `ChainRunner` had zero production
|
|
6
|
+
* callers and only existed with unit-test mock runners. Each step delegates to
|
|
7
|
+
* the existing `handleRun` (which owns config load, team/workflow discovery,
|
|
8
|
+
* worktree preconditions, manifest creation, and `executeTeamRun`), so the
|
|
9
|
+
* ~200 lines of run machinery are NOT duplicated.
|
|
10
|
+
*
|
|
11
|
+
* Context passage (the whole point of the chain feature): `enrichContextFromHandoffs`
|
|
12
|
+
* places `__chainHistory` + `__chainHistoryNotes` into `packet.context`; this
|
|
13
|
+
* executor serializes them into a `# Previous Steps in This Chain` block that is
|
|
14
|
+
* prepended to the step's goal. `handleRun` → `executeTeamRun` → worker prompt,
|
|
15
|
+
* so step N+1's worker sees step N's handoff summary and the Fix C markers.
|
|
16
|
+
*
|
|
17
|
+
* Circular-import avoidance: `handleRun` is received as an INJECTED function
|
|
18
|
+
* reference (dependency injection) rather than a static import. `run.ts` lazy-
|
|
19
|
+
* imports `chain-dispatch.ts`, which imports this file. A static import of
|
|
20
|
+
* `run.ts` here would create a `run.ts ↔ chain-executor.ts` cycle that races
|
|
21
|
+
* module-record instantiation under jiti. The DI pattern breaks the cycle.
|
|
22
|
+
*
|
|
23
|
+
* @see src/runtime/chain-runner.ts (runChain, enrichContextFromHandoffs — Fix C)
|
|
24
|
+
* @see src/extension/team-tool/run.ts (handleRun — the reused machinery)
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import * as fs from "node:fs";
|
|
28
|
+
import * as path from "node:path";
|
|
29
|
+
import type { ChainTaskRunner } from "../../runtime/chain-runner.ts";
|
|
30
|
+
import type { Decision, TaskPacket, TaskResult } from "../../runtime/handoff-manager.ts";
|
|
31
|
+
import { readIfSmallWithTee } from "../../runtime/task-output-context.ts";
|
|
32
|
+
import type { TeamToolParamsValue } from "../../schema/team-tool-schema.ts";
|
|
33
|
+
import { atomicWriteFile } from "../../state/atomic-write.ts";
|
|
34
|
+
import { createRunPaths, loadRunManifestById } from "../../state/state-store.ts";
|
|
35
|
+
import type { TeamRunManifest, TeamTaskState } from "../../state/types.ts";
|
|
36
|
+
import type { PiTeamsToolResult } from "../tool-result.ts";
|
|
37
|
+
import { textFromToolResult } from "../tool-result.ts";
|
|
38
|
+
import type { TeamContext } from "./context.ts";
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Signature of `handleRun`, declared locally (type-only) to break the
|
|
42
|
+
* import cycle with run.ts. Structurally identical to
|
|
43
|
+
* `(params, ctx) => Promise<PiTeamsToolResult>`.
|
|
44
|
+
*/
|
|
45
|
+
export type HandleRunFn = (params: TeamToolParamsValue, ctx: TeamContext) => Promise<PiTeamsToolResult>;
|
|
46
|
+
|
|
47
|
+
/** Per-step team/workflow/model overrides forwarded from the chain invocation. */
|
|
48
|
+
export interface ChainExecutorOverrides {
|
|
49
|
+
team?: string;
|
|
50
|
+
workflow?: string;
|
|
51
|
+
model?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Shape of one entry in `context.__chainHistory` produced by enrichContextFromHandoffs. */
|
|
55
|
+
interface ChainHistoryEntry {
|
|
56
|
+
step?: string;
|
|
57
|
+
outcome?: string;
|
|
58
|
+
filesCreated?: string[];
|
|
59
|
+
filesModified?: string[];
|
|
60
|
+
decisions?: Decision[];
|
|
61
|
+
nextSteps?: string[];
|
|
62
|
+
outputText?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Serialize `packet.context.__chainHistory` (+ `__chainHistoryNotes`) into a
|
|
67
|
+
* human-readable block prefixed with `# Previous Steps in This Chain`.
|
|
68
|
+
*
|
|
69
|
+
* This is the CRITICAL coupling that makes Fix C's `__chainHistoryNotes`
|
|
70
|
+
* markers visible to step N+1's worker: those markers travel as a sibling
|
|
71
|
+
* array on the context object, and only become worker-visible once formatted
|
|
72
|
+
* into the goal text here. Returns `""` when there is no history.
|
|
73
|
+
*
|
|
74
|
+
* Extracted as a pure function for unit testability (acceptance criterion 6c).
|
|
75
|
+
*/
|
|
76
|
+
export function formatChainHistory(context: Record<string, unknown>): string {
|
|
77
|
+
const history = context.__chainHistory;
|
|
78
|
+
if (!Array.isArray(history) || history.length === 0) {
|
|
79
|
+
return "";
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const lines: string[] = ["# Previous Steps in This Chain", ""];
|
|
83
|
+
|
|
84
|
+
for (const raw of history) {
|
|
85
|
+
if (!raw || typeof raw !== "object") continue;
|
|
86
|
+
const entry = raw as ChainHistoryEntry;
|
|
87
|
+
const stepName = entry.step ?? "unknown";
|
|
88
|
+
const outcome = entry.outcome ?? "unknown";
|
|
89
|
+
lines.push(`## Step ${stepName}: ${outcome}`);
|
|
90
|
+
lines.push(`Files created: ${entry.filesCreated?.length ? entry.filesCreated.join(", ") : "none"}`);
|
|
91
|
+
lines.push(`Files modified: ${entry.filesModified?.length ? entry.filesModified.join(", ") : "none"}`);
|
|
92
|
+
if (entry.decisions?.length) {
|
|
93
|
+
lines.push("Decisions:");
|
|
94
|
+
for (const d of entry.decisions) {
|
|
95
|
+
const rationale = d && typeof d === "object" && "rationale" in d ? String(d.rationale) : "(undocumented)";
|
|
96
|
+
const decisionOutcome = d && typeof d === "object" && "outcome" in d ? String(d.outcome) : "";
|
|
97
|
+
lines.push(`- ${rationale}${decisionOutcome ? ` → ${decisionOutcome}` : ""}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (entry.nextSteps?.length) {
|
|
101
|
+
lines.push("Next steps:");
|
|
102
|
+
for (const ns of entry.nextSteps) lines.push(`- ${ns}`);
|
|
103
|
+
}
|
|
104
|
+
if (entry.outputText) {
|
|
105
|
+
lines.push("Output:");
|
|
106
|
+
lines.push(entry.outputText);
|
|
107
|
+
}
|
|
108
|
+
lines.push("");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Append Fix C honesty markers verbatim — these note elided/oversized history.
|
|
112
|
+
const notes = context.__chainHistoryNotes;
|
|
113
|
+
if (Array.isArray(notes)) {
|
|
114
|
+
for (const note of notes) {
|
|
115
|
+
if (typeof note === "string" && note.length > 0) lines.push(note);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return lines.join("\n").trimEnd();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Map a completed team run's manifest+tasks → a chain `TaskResult`.
|
|
124
|
+
*
|
|
125
|
+
* Outcome is derived from the manifest status, cross-checked against task
|
|
126
|
+
* statuses (a run that completed but with a failed task reads as "partial").
|
|
127
|
+
* `usage.totalTokens` sums each task's input+output tokens; `duration` from
|
|
128
|
+
* manifest timestamps; `error` is best-effort from the first failed task or
|
|
129
|
+
* the manifest summary. `filesCreated`/`filesModified` are intentionally left
|
|
130
|
+
* unset — `TeamTaskState` does not carry them, so we never fabricate them.
|
|
131
|
+
*
|
|
132
|
+
* Extracted as a pure function for unit testability (acceptance criterion 6b).
|
|
133
|
+
*/
|
|
134
|
+
export function mapRunToTaskResult(manifest: TeamRunManifest, tasks: TeamTaskState[]): TaskResult {
|
|
135
|
+
// Determine outcome from manifest status.
|
|
136
|
+
let outcome: TaskResult["outcome"];
|
|
137
|
+
if (manifest.status === "completed") {
|
|
138
|
+
outcome = "success";
|
|
139
|
+
} else if (manifest.status === "failed" || manifest.status === "blocked" || manifest.status === "cancelled") {
|
|
140
|
+
outcome = "failure";
|
|
141
|
+
} else {
|
|
142
|
+
// queued / planning / running → not terminal yet
|
|
143
|
+
outcome = "partial";
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Cross-check tasks: if a manifest claims completed but a task failed, it is partial.
|
|
147
|
+
const hasFailed = tasks.some((t) => t.status === "failed" || t.status === "needs_attention");
|
|
148
|
+
const hasCompleted = tasks.some((t) => t.status === "completed");
|
|
149
|
+
if (hasFailed && (hasCompleted || outcome === "success")) {
|
|
150
|
+
outcome = "partial";
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Token usage: sum task input + output.
|
|
154
|
+
let totalTokens = 0;
|
|
155
|
+
for (const t of tasks) {
|
|
156
|
+
totalTokens += (t.usage?.input ?? 0) + (t.usage?.output ?? 0);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Duration from manifest timestamps.
|
|
160
|
+
let duration = 0;
|
|
161
|
+
const created = Date.parse(manifest.createdAt);
|
|
162
|
+
const updated = Date.parse(manifest.updatedAt);
|
|
163
|
+
if (!Number.isNaN(created) && !Number.isNaN(updated) && updated >= created) {
|
|
164
|
+
duration = updated - created;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Error: best-effort from first failed task, else manifest summary.
|
|
168
|
+
let error: string | undefined;
|
|
169
|
+
if (outcome !== "success") {
|
|
170
|
+
const failedTask = tasks.find((t) => t.status === "failed");
|
|
171
|
+
error = failedTask?.error ?? manifest.summary;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const taskResult: TaskResult = {
|
|
175
|
+
outcome,
|
|
176
|
+
usage: { totalTokens },
|
|
177
|
+
duration,
|
|
178
|
+
};
|
|
179
|
+
if (error) taskResult.error = error;
|
|
180
|
+
return taskResult;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Read completed tasks' result artifacts and concatenate their output text.
|
|
185
|
+
* Mirrors the pattern in task-output-context.ts:collectDependencyOutputContext
|
|
186
|
+
* (readIfSmallWithTee with baseDir = artifactsRoot).
|
|
187
|
+
*
|
|
188
|
+
* Returns the concatenated output text, or undefined if no artifacts were readable.
|
|
189
|
+
*/
|
|
190
|
+
export function readChainStepOutput(manifest: TeamRunManifest, tasks: TeamTaskState[]): string | undefined {
|
|
191
|
+
const parts: string[] = [];
|
|
192
|
+
for (const t of tasks) {
|
|
193
|
+
if (t.status !== "completed" || !t.resultArtifact?.path) continue;
|
|
194
|
+
const read = readIfSmallWithTee(t.resultArtifact.path, {
|
|
195
|
+
baseDir: manifest.artifactsRoot,
|
|
196
|
+
});
|
|
197
|
+
if (read?.content && read.content.trim().length > 0) {
|
|
198
|
+
parts.push(read.content.trim());
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return parts.length > 0 ? parts.join("\n\n") : undefined;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Concrete `ChainTaskRunner`: each step is a full team run via the injected
|
|
206
|
+
* `handleRun`. Step runIds are captured on `stepRunIds` so the dispatch can
|
|
207
|
+
* surface them in the summary and acceptance verification.
|
|
208
|
+
*
|
|
209
|
+
* Errors are intentionally NOT caught here — `runChain` wraps each step's
|
|
210
|
+
* `runTask` call in try/catch, records `outcome: "failure"`, and respects
|
|
211
|
+
* `continueOnError`. Letting exceptions propagate keeps the chain-runner's
|
|
212
|
+
* existing failure semantics intact.
|
|
213
|
+
*/
|
|
214
|
+
export class ChainTeamRunExecutor implements ChainTaskRunner {
|
|
215
|
+
/** RunId captured per executed step, in execution order. */
|
|
216
|
+
readonly stepRunIds: string[] = [];
|
|
217
|
+
|
|
218
|
+
private readonly handleRunRef: HandleRunFn;
|
|
219
|
+
private readonly ctx: TeamContext;
|
|
220
|
+
private readonly overrides: ChainExecutorOverrides;
|
|
221
|
+
|
|
222
|
+
constructor(opts: {
|
|
223
|
+
handleRun: HandleRunFn;
|
|
224
|
+
ctx: TeamContext;
|
|
225
|
+
overrides?: ChainExecutorOverrides;
|
|
226
|
+
}) {
|
|
227
|
+
this.handleRunRef = opts.handleRun;
|
|
228
|
+
this.ctx = opts.ctx;
|
|
229
|
+
this.overrides = opts.overrides ?? {};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async runTask(packet: TaskPacket): Promise<TaskResult> {
|
|
233
|
+
const context = packet.context ?? {};
|
|
234
|
+
|
|
235
|
+
// 1. Format chain history into the goal — this is how context reaches the worker.
|
|
236
|
+
// Mirrors the parentContext pattern in child-pi.ts (parent context + task delimiter).
|
|
237
|
+
const historyPrefix = formatChainHistory(context);
|
|
238
|
+
const enrichedGoal = historyPrefix ? `${historyPrefix}\n\n---\n# Current Chain Step\n${packet.goal}` : packet.goal;
|
|
239
|
+
|
|
240
|
+
// 2. Resolve team/workflow/model: step config (set by executeStep) → overrides → default.
|
|
241
|
+
const stepTeam = (context.__chainStepTeam as string | undefined) ?? this.overrides.team ?? "default";
|
|
242
|
+
const stepWorkflow = (context.__chainStepWorkflow as string | undefined) ?? this.overrides.workflow;
|
|
243
|
+
const stepModel = (context.__chainStepModel as string | undefined) ?? this.overrides.model;
|
|
244
|
+
|
|
245
|
+
// 3. Call handleRun for the heavy lifting. async:false forces each step to
|
|
246
|
+
// complete synchronously (overrides asyncByDefault) so the chain is sequential.
|
|
247
|
+
// NO `chain` key here — so the run.ts guard does not re-enter chain dispatch.
|
|
248
|
+
const runParams: TeamToolParamsValue = {
|
|
249
|
+
action: "run",
|
|
250
|
+
goal: enrichedGoal,
|
|
251
|
+
team: stepTeam,
|
|
252
|
+
async: false,
|
|
253
|
+
...(stepWorkflow ? { workflow: stepWorkflow } : {}),
|
|
254
|
+
...(stepModel ? { model: stepModel } : {}),
|
|
255
|
+
};
|
|
256
|
+
const runRes = await this.handleRunRef(runParams, this.ctx);
|
|
257
|
+
|
|
258
|
+
// 4. Extract runId + map to TaskResult. If no runId, the run was blocked before
|
|
259
|
+
// a manifest existed — map as a failure.
|
|
260
|
+
const runId = runRes.details?.runId;
|
|
261
|
+
if (!runId) {
|
|
262
|
+
return {
|
|
263
|
+
outcome: "failure",
|
|
264
|
+
error: textFromToolResult(runRes) || "Chain step produced no runId",
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
this.stepRunIds.push(runId);
|
|
268
|
+
|
|
269
|
+
const cwd = this.ctx.cwd ?? process.cwd();
|
|
270
|
+
const loaded = loadRunManifestById(cwd, runId);
|
|
271
|
+
if (!loaded) {
|
|
272
|
+
// Manifest not loadable — fall back to the tool result's own status.
|
|
273
|
+
return {
|
|
274
|
+
outcome: runRes.details?.status === "error" ? "failure" : "partial",
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
const result = mapRunToTaskResult(loaded.manifest, loaded.tasks);
|
|
278
|
+
const outputText = readChainStepOutput(loaded.manifest, loaded.tasks);
|
|
279
|
+
if (outputText) result.outputText = outputText;
|
|
280
|
+
return result;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// ─── test helpers (exported for unit/integration tests) ──────────────────
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Write a minimal valid run fixture (manifest + tasks + events) to `cwd`'s
|
|
288
|
+
* state root so `loadRunManifestById(cwd, runId)` validates and returns it.
|
|
289
|
+
* Used by integration tests to exercise `ChainTeamRunExecutor` with a mocked
|
|
290
|
+
* `handleRun` while still going through the REAL manifest loader + result mapper.
|
|
291
|
+
*/
|
|
292
|
+
export function writeRunFixture(
|
|
293
|
+
cwd: string,
|
|
294
|
+
runId: string,
|
|
295
|
+
opts: {
|
|
296
|
+
status?: TeamRunManifest["status"];
|
|
297
|
+
tasks?: TeamTaskState[];
|
|
298
|
+
summary?: string;
|
|
299
|
+
/** Worker result text to write to results/<taskId>.txt (sets resultArtifact on tasks). */
|
|
300
|
+
resultText?: string;
|
|
301
|
+
/** Task ID for the result artifact (default: "01_task"). */
|
|
302
|
+
taskId?: string;
|
|
303
|
+
},
|
|
304
|
+
): TeamRunManifest {
|
|
305
|
+
const paths = createRunPaths(cwd, runId);
|
|
306
|
+
fs.mkdirSync(paths.stateRoot, { recursive: true });
|
|
307
|
+
const now = new Date().toISOString();
|
|
308
|
+
const start = new Date(Date.now() - 10_000).toISOString();
|
|
309
|
+
const taskId = opts.taskId ?? "01_task";
|
|
310
|
+
|
|
311
|
+
// Build tasks: if resultText is provided without explicit tasks, create a
|
|
312
|
+
// default completed task carrying a resultArtifact pointing at the result file.
|
|
313
|
+
let tasks = opts.tasks;
|
|
314
|
+
if (opts.resultText) {
|
|
315
|
+
const resultArtifact = {
|
|
316
|
+
kind: "result" as const,
|
|
317
|
+
path: `results/${taskId}.txt`,
|
|
318
|
+
createdAt: now,
|
|
319
|
+
producer: "worker",
|
|
320
|
+
retention: "run" as const,
|
|
321
|
+
};
|
|
322
|
+
if (!tasks || tasks.length === 0) {
|
|
323
|
+
tasks = [
|
|
324
|
+
{
|
|
325
|
+
id: taskId,
|
|
326
|
+
runId,
|
|
327
|
+
role: "executor",
|
|
328
|
+
agent: "executor",
|
|
329
|
+
title: "(chain step fixture)",
|
|
330
|
+
status: "completed",
|
|
331
|
+
dependsOn: [],
|
|
332
|
+
cwd,
|
|
333
|
+
resultArtifact,
|
|
334
|
+
},
|
|
335
|
+
];
|
|
336
|
+
} else {
|
|
337
|
+
// Attach resultArtifact to the first task if it doesn't have one.
|
|
338
|
+
tasks = tasks.map((t, i) => (i === 0 && !t.resultArtifact ? { ...t, resultArtifact } : t));
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const manifest: TeamRunManifest = {
|
|
343
|
+
schemaVersion: 1,
|
|
344
|
+
runId,
|
|
345
|
+
team: "default",
|
|
346
|
+
workflow: "default",
|
|
347
|
+
goal: "(chain step fixture)",
|
|
348
|
+
status: opts.status ?? "completed",
|
|
349
|
+
workspaceMode: "single",
|
|
350
|
+
createdAt: start,
|
|
351
|
+
updatedAt: now,
|
|
352
|
+
cwd,
|
|
353
|
+
stateRoot: paths.stateRoot,
|
|
354
|
+
artifactsRoot: paths.artifactsRoot,
|
|
355
|
+
tasksPath: paths.tasksPath,
|
|
356
|
+
eventsPath: paths.eventsPath,
|
|
357
|
+
artifacts: [],
|
|
358
|
+
...(opts.summary ? { summary: opts.summary } : {}),
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
// Write the result artifact file + register on manifest if resultText provided.
|
|
362
|
+
if (opts.resultText) {
|
|
363
|
+
const resultDir = path.join(paths.artifactsRoot, "results");
|
|
364
|
+
fs.mkdirSync(resultDir, { recursive: true });
|
|
365
|
+
atomicWriteFile(path.join(resultDir, `${taskId}.txt`), opts.resultText);
|
|
366
|
+
manifest.artifacts.push({
|
|
367
|
+
kind: "result",
|
|
368
|
+
path: `results/${taskId}.txt`,
|
|
369
|
+
createdAt: now,
|
|
370
|
+
producer: "worker",
|
|
371
|
+
retention: "run",
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
atomicWriteFile(paths.manifestPath, JSON.stringify(manifest));
|
|
376
|
+
atomicWriteFile(paths.tasksPath, JSON.stringify(tasks ?? []));
|
|
377
|
+
atomicWriteFile(paths.eventsPath, "");
|
|
378
|
+
return manifest;
|
|
379
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { effectiveAutonomousConfig, type PiTeamsAutonomousConfig, type PiTeamsConfig, parseConfig } from "../../config/config.ts";
|
|
2
|
+
|
|
3
|
+
const DANGEROUS_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
4
|
+
|
|
5
|
+
/** Recursively strip dangerous prototype-pollution keys from all levels of an object. */
|
|
6
|
+
export function sanitizeObject<T>(obj: T): T {
|
|
7
|
+
if (obj === null || obj === undefined || typeof obj !== "object") return obj;
|
|
8
|
+
if (Array.isArray(obj)) return obj.map((item) => sanitizeObject(item)) as T;
|
|
9
|
+
const safe: Record<string, unknown> = {};
|
|
10
|
+
for (const key of Object.keys(obj as Record<string, unknown>)) {
|
|
11
|
+
if (DANGEROUS_KEYS.has(key)) continue;
|
|
12
|
+
safe[key] = sanitizeObject((obj as Record<string, unknown>)[key]);
|
|
13
|
+
}
|
|
14
|
+
return safe as T;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function autonomousPatchFromConfig(config: unknown): PiTeamsAutonomousConfig {
|
|
18
|
+
const rootPatch = parseConfig(config).autonomous;
|
|
19
|
+
if (rootPatch) return rootPatch;
|
|
20
|
+
return parseConfig({ autonomous: config }).autonomous ?? {};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function configPatchFromConfig(config: unknown): PiTeamsConfig {
|
|
24
|
+
return parseConfig(config);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function effectiveRunConfig(base: PiTeamsConfig, rawOverride: unknown): PiTeamsConfig {
|
|
28
|
+
const patch = sanitizeObject(parseConfig(rawOverride));
|
|
29
|
+
return {
|
|
30
|
+
...base,
|
|
31
|
+
...patch,
|
|
32
|
+
limits: patch.limits ? { ...(base.limits ?? {}), ...patch.limits } : base.limits,
|
|
33
|
+
runtime: patch.runtime ? { ...(base.runtime ?? {}), ...patch.runtime } : base.runtime,
|
|
34
|
+
control: patch.control ? { ...(base.control ?? {}), ...patch.control } : base.control,
|
|
35
|
+
worktree: patch.worktree ? { ...(base.worktree ?? {}), ...patch.worktree } : base.worktree,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function formatAutonomyStatus(config: PiTeamsAutonomousConfig | undefined, pathValue: string, updated: boolean): string {
|
|
40
|
+
const effective = effectiveAutonomousConfig(config);
|
|
41
|
+
return [
|
|
42
|
+
updated ? "Updated pi-crew autonomous mode." : "pi-crew autonomous mode:",
|
|
43
|
+
`Path: ${pathValue}`,
|
|
44
|
+
`Profile: ${effective.profile}`,
|
|
45
|
+
`Enabled: ${effective.enabled}`,
|
|
46
|
+
`Inject policy: ${effective.injectPolicy}`,
|
|
47
|
+
`Prefer async for long tasks: ${effective.preferAsyncForLongTasks}`,
|
|
48
|
+
`Allow worktree suggestion: ${effective.allowWorktreeSuggestion}`,
|
|
49
|
+
].join("\n");
|
|
50
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
import type { PiTeamsConfig } from "../../config/config.ts";
|
|
4
|
+
import type { MetricRegistry } from "../../observability/metric-registry.ts";
|
|
5
|
+
import type { RunSnapshotCache } from "../../ui/run-snapshot-cache.ts";
|
|
6
|
+
import type { TeamToolDetails } from "../team-tool-types.ts";
|
|
7
|
+
import { type PiTeamsToolResult, toolResult } from "../tool-result.ts";
|
|
8
|
+
|
|
9
|
+
export type TeamContext = Pick<ExtensionContext, "cwd"> &
|
|
10
|
+
Partial<Pick<ExtensionContext, "model">> & {
|
|
11
|
+
sessionId?: string;
|
|
12
|
+
modelRegistry?: unknown;
|
|
13
|
+
sessionManager?: { getBranch?: () => unknown[] };
|
|
14
|
+
events?: { emit?: (event: string, data: unknown) => void };
|
|
15
|
+
metricRegistry?: MetricRegistry;
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
startForegroundRun?: (runner: (signal?: AbortSignal) => Promise<void>, runId?: string) => void;
|
|
18
|
+
abortForegroundRun?: (runId: string) => boolean;
|
|
19
|
+
onRunStarted?: (runId: string) => void;
|
|
20
|
+
onJsonEvent?: (taskId: string, runId: string, event: unknown) => void;
|
|
21
|
+
config?: PiTeamsConfig;
|
|
22
|
+
getRunSnapshotCache?: (cwd: string) => RunSnapshotCache;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function withSessionId<T extends Pick<ExtensionContext, "sessionManager">>(ctx: T): T & { sessionId?: string } {
|
|
26
|
+
const sessionId = ctx.sessionManager?.getSessionId?.();
|
|
27
|
+
return sessionId ? { ...ctx, sessionId } : { ...ctx };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function result(text: string, details: TeamToolDetails, isError = false): PiTeamsToolResult {
|
|
31
|
+
return toolResult(text, details, isError);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function formatScoped(name: string, source: string, description: string): string {
|
|
35
|
+
return `- ${name} (${source}): ${description}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function extractTextContent(content: unknown): string {
|
|
39
|
+
if (typeof content === "string") return content;
|
|
40
|
+
if (!Array.isArray(content)) return "";
|
|
41
|
+
return content
|
|
42
|
+
.map((part) =>
|
|
43
|
+
part && typeof part === "object" && !Array.isArray(part) && typeof (part as { text?: unknown }).text === "string"
|
|
44
|
+
? (part as { text: string }).text
|
|
45
|
+
: "",
|
|
46
|
+
)
|
|
47
|
+
.filter(Boolean)
|
|
48
|
+
.join("\n");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Maximum character budget for inherited parent context (~3K tokens).
|
|
53
|
+
* When exceeded, oldest messages are dropped first (most-recent-first retention).
|
|
54
|
+
*/
|
|
55
|
+
export const MAX_PARENT_CONTEXT_CHARS = 12_000;
|
|
56
|
+
|
|
57
|
+
/** Maximum chars for a single assistant message before truncation. */
|
|
58
|
+
const MAX_ASSISTANT_MSG_CHARS = 500;
|
|
59
|
+
|
|
60
|
+
/** Truncated length for oversized assistant messages. */
|
|
61
|
+
const TRUNCATED_ASSISTANT_CHARS = 200;
|
|
62
|
+
|
|
63
|
+
/** Messages starting with these patterns and exceeding this size are likely
|
|
64
|
+
* file dumps / bash output — skip them to keep context relevant and compact. */
|
|
65
|
+
const NOISY_THRESHOLD = 1_000;
|
|
66
|
+
const NOISY_PREFIXES = ["```", "total ", "drwx", "-rw", "import ", "export "];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Check if a message looks like noisy file/tool output (code dumps, ls output,
|
|
70
|
+
* import lists) that bloats context without helping the subagent.
|
|
71
|
+
*/
|
|
72
|
+
function isNoisyContent(text: string): boolean {
|
|
73
|
+
if (text.length < NOISY_THRESHOLD) return false;
|
|
74
|
+
return NOISY_PREFIXES.some((prefix) => text.startsWith(prefix));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Build a compact parent conversation context for subagent inheritance.
|
|
79
|
+
*
|
|
80
|
+
* Extracts recent user messages, assistant reasoning, and compaction summaries
|
|
81
|
+
* from the parent session. Applies a character budget (most-recent-first
|
|
82
|
+
* retention) and filters noisy content (file dumps, long bash output) to keep
|
|
83
|
+
* the inherited context relevant without bloating the subagent's token budget.
|
|
84
|
+
*/
|
|
85
|
+
export function buildParentContext(ctx: TeamContext): string | undefined {
|
|
86
|
+
const branch = ctx.sessionManager?.getBranch?.();
|
|
87
|
+
if (!Array.isArray(branch) || branch.length === 0) return undefined;
|
|
88
|
+
const parts: string[] = [];
|
|
89
|
+
for (const entry of branch.slice(-20)) {
|
|
90
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
91
|
+
const record = entry as {
|
|
92
|
+
type?: unknown;
|
|
93
|
+
message?: unknown;
|
|
94
|
+
summary?: unknown;
|
|
95
|
+
};
|
|
96
|
+
// Compaction summaries are always valuable — keep in full.
|
|
97
|
+
if (record.type === "compaction" && typeof record.summary === "string") {
|
|
98
|
+
parts.push(`[Summary]: ${record.summary}`);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const message =
|
|
102
|
+
record.message && typeof record.message === "object" && !Array.isArray(record.message)
|
|
103
|
+
? (record.message as { role?: unknown; content?: unknown })
|
|
104
|
+
: undefined;
|
|
105
|
+
if (!message || (message.role !== "user" && message.role !== "assistant")) continue;
|
|
106
|
+
let text = extractTextContent(message.content).trim();
|
|
107
|
+
if (!text) continue;
|
|
108
|
+
// Filter: skip noisy content (file dumps, long bash output).
|
|
109
|
+
if (isNoisyContent(text)) continue;
|
|
110
|
+
// Truncate: long assistant messages get shortened to key points.
|
|
111
|
+
if (message.role === "assistant" && text.length > MAX_ASSISTANT_MSG_CHARS) {
|
|
112
|
+
text = `${text.slice(0, TRUNCATED_ASSISTANT_CHARS)}…`;
|
|
113
|
+
}
|
|
114
|
+
parts.push(`[${message.role === "user" ? "User" : "Assistant"}]: ${text}`);
|
|
115
|
+
}
|
|
116
|
+
if (!parts.length) return undefined;
|
|
117
|
+
|
|
118
|
+
// Budget: keep most-recent messages first, drop oldest when over budget.
|
|
119
|
+
let totalChars = 0;
|
|
120
|
+
const budgeted: string[] = [];
|
|
121
|
+
for (const part of [...parts].reverse()) {
|
|
122
|
+
if (totalChars + part.length > MAX_PARENT_CONTEXT_CHARS) break;
|
|
123
|
+
budgeted.unshift(part);
|
|
124
|
+
totalChars += part.length;
|
|
125
|
+
}
|
|
126
|
+
if (!budgeted.length) return undefined;
|
|
127
|
+
|
|
128
|
+
return [
|
|
129
|
+
`# Parent Conversation Context`,
|
|
130
|
+
"The following context was inherited from the parent Pi session. Treat it as reference-only.",
|
|
131
|
+
"",
|
|
132
|
+
budgeted.join("\n\n"),
|
|
133
|
+
].join("\n");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function configRecord(config: unknown): Record<string, unknown> {
|
|
137
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) return {};
|
|
138
|
+
// AUDIT-07 defense-in-depth: filter prototype-pollution keys. Callers (api, doctor,
|
|
139
|
+
// lifecycle-actions, intent-policy, team-tool) pass `params.config` from the team-tool
|
|
140
|
+
// invocation which is NOT sanitized by the same loadConfig/sanitizeObject path.
|
|
141
|
+
const obj = config as Record<string, unknown>;
|
|
142
|
+
const DANGEROUS_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
143
|
+
const safe: Record<string, unknown> = {};
|
|
144
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
145
|
+
if (DANGEROUS_KEYS.has(k)) continue;
|
|
146
|
+
safe[k] = v;
|
|
147
|
+
}
|
|
148
|
+
return safe;
|
|
149
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Permission gate logic for destructive team actions (delete/forget/prune/cleanup).
|
|
3
|
+
*
|
|
4
|
+
* Extracted from register.ts `pi.on("tool_call")` handler into a pure function
|
|
5
|
+
* so the gate logic is unit-testable in isolation (the handler itself is hard
|
|
6
|
+
* to test because it's an async event listener on the Pi extension API).
|
|
7
|
+
*
|
|
8
|
+
* Returns `undefined` when the action is ALLOWED, or a block `reason` string
|
|
9
|
+
* when it should be blocked. The handler wraps this and emits the `{block, reason}`
|
|
10
|
+
* shape Pi expects.
|
|
11
|
+
*
|
|
12
|
+
* Rules (in order):
|
|
13
|
+
* 1. Non-team / non-destructive actions → allowed (caller pre-filters, but safe).
|
|
14
|
+
* 2. `cleanup` with `dryRun=true` → ALWAYS allowed (a preview writes nothing,
|
|
15
|
+
* so gating it would block users from previewing what cleanup would do —
|
|
16
|
+
* this was a UX bug: team action=cleanup dryRun=true returned "requires
|
|
17
|
+
* confirm=true" even though it changed no files).
|
|
18
|
+
* 3. `confirm=true` on the input → allowed (explicit user intent).
|
|
19
|
+
* 4. `delete` with `force=true` → allowed (force bypasses reference checks).
|
|
20
|
+
* 5. Otherwise → blocked with a reason telling the user what to pass.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export const DESTRUCTIVE_TEAM_ACTIONS = new Set([
|
|
24
|
+
"delete",
|
|
25
|
+
"forget",
|
|
26
|
+
"prune",
|
|
27
|
+
"cleanup",
|
|
28
|
+
"workflow-create",
|
|
29
|
+
"workflow-save",
|
|
30
|
+
"workflow-delete",
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
export interface TeamToolInputLike {
|
|
34
|
+
action?: unknown;
|
|
35
|
+
confirm?: unknown;
|
|
36
|
+
force?: unknown;
|
|
37
|
+
dryRun?: unknown;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Decide whether a destructive team action should be blocked.
|
|
42
|
+
* @returns block reason string, or `undefined` to allow.
|
|
43
|
+
*/
|
|
44
|
+
export function shouldBlockDestructiveTeamAction(action: string | undefined, input: TeamToolInputLike): string | undefined {
|
|
45
|
+
if (!action || !DESTRUCTIVE_TEAM_ACTIONS.has(action)) return undefined;
|
|
46
|
+
// dryRun cleanup is a PREVIEW (no writes) — never needs confirm.
|
|
47
|
+
if (action === "cleanup" && input.dryRun === true) return undefined;
|
|
48
|
+
if (input.confirm === true) return undefined;
|
|
49
|
+
const forceBypassesReferenceChecks = action === "delete" && input.force === true;
|
|
50
|
+
if (forceBypassesReferenceChecks) return undefined;
|
|
51
|
+
return `Destructive action '${action}' requires confirm=true${action === "delete" ? " (or force=true to bypass reference checks)" : ""}.`;
|
|
52
|
+
}
|