zob-harness 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.pi/adapters/registry.json +103 -0
- package/.pi/agents/architecture-cartographer.md +53 -0
- package/.pi/agents/chief-vision.md +39 -0
- package/.pi/agents/clarifier.md +58 -0
- package/.pi/agents/context-steward.md +52 -0
- package/.pi/agents/doc-steward.md +34 -0
- package/.pi/agents/explore.md +49 -0
- package/.pi/agents/factory.md +41 -0
- package/.pi/agents/implementer.md +44 -0
- package/.pi/agents/librarian.md +32 -0
- package/.pi/agents/oracle-merge.md +50 -0
- package/.pi/agents/oracle.md +55 -0
- package/.pi/agents/pattern-miner.md +53 -0
- package/.pi/agents/planner.md +39 -0
- package/.pi/agents/project-dna-golden-evaluator.md +32 -0
- package/.pi/agents/project-dna-ontology-steward.md +30 -0
- package/.pi/agents/project-dna-oracle.md +56 -0
- package/.pi/agents/project-dna-orchestrator.md +60 -0
- package/.pi/agents/project-dna-query-steward.md +38 -0
- package/.pi/agents/project-dna-safety-preflight.md +54 -0
- package/.pi/agents/project-dna-test-linker.md +27 -0
- package/.pi/agents/qa.md +38 -0
- package/.pi/agents/refactor-cartographer.md +28 -0
- package/.pi/agents/refactor-mover.md +31 -0
- package/.pi/agents/refactor-oracle.md +49 -0
- package/.pi/agents/repo-scout.md +60 -0
- package/.pi/agents/sample-architect.md +48 -0
- package/.pi/agents/specifier.md +57 -0
- package/.pi/agents/symbol-range-curator.md +41 -0
- package/.pi/agents/synthesis.md +52 -0
- package/.pi/agents/temp-agent-creator.md +35 -0
- package/.pi/autonomy-policy.json +67 -0
- package/.pi/budget-policy.json +54 -0
- package/.pi/capabilities/zob-public-runtime-capabilities.json +1700 -0
- package/.pi/chains/explore-plan-oracle.json +78 -0
- package/.pi/chains/explore-spec-clarify-plan-oracle.json +64 -0
- package/.pi/chains/explore-spec-plan-oracle.json +53 -0
- package/.pi/chains/spec-clarify-plan-oracle.json +53 -0
- package/.pi/chains/spec-factory-oracle.json +42 -0
- package/.pi/chains/spec-plan-oracle.json +42 -0
- package/.pi/compute-profiles/defaults.json +19 -0
- package/.pi/compute-profiles/overrides.json +13 -0
- package/.pi/compute-profiles/risk-rules.json +16 -0
- package/.pi/daemon-policy.json +80 -0
- package/.pi/damage-control-rules.json +45 -0
- package/.pi/extensions/zob-child-safety/index.ts +212 -0
- package/.pi/extensions/zob-harness/AGENTS.md +28 -0
- package/.pi/extensions/zob-harness/index.ts +391 -0
- package/.pi/extensions/zob-harness/src/AGENTS.md +25 -0
- package/.pi/extensions/zob-harness/src/agents.ts +82 -0
- package/.pi/extensions/zob-harness/src/autonomous-runtime.ts +2912 -0
- package/.pi/extensions/zob-harness/src/autonomy-readiness.ts +778 -0
- package/.pi/extensions/zob-harness/src/budget-policy.ts +308 -0
- package/.pi/extensions/zob-harness/src/capabilities.ts +249 -0
- package/.pi/extensions/zob-harness/src/child-runner.ts +249 -0
- package/.pi/extensions/zob-harness/src/chronicle.ts +262 -0
- package/.pi/extensions/zob-harness/src/compute-profile.ts +602 -0
- package/.pi/extensions/zob-harness/src/compute-workflow-shape.ts +168 -0
- package/.pi/extensions/zob-harness/src/coms-v2/AGENTS.md +16 -0
- package/.pi/extensions/zob-harness/src/coms-v2/envelope.ts +121 -0
- package/.pi/extensions/zob-harness/src/coms-v2/identity.ts +53 -0
- package/.pi/extensions/zob-harness/src/coms-v2/ledger-bridge.ts +67 -0
- package/.pi/extensions/zob-harness/src/coms-v2/local-transport.ts +147 -0
- package/.pi/extensions/zob-harness/src/coms-v2/pending-replies.ts +80 -0
- package/.pi/extensions/zob-harness/src/coms-v2/policy.ts +125 -0
- package/.pi/extensions/zob-harness/src/coms-v2/presence.ts +55 -0
- package/.pi/extensions/zob-harness/src/coms-v2/registry.ts +113 -0
- package/.pi/extensions/zob-harness/src/coms-v2/response-capture.ts +50 -0
- package/.pi/extensions/zob-harness/src/coms-v2/transcript-capture.ts +164 -0
- package/.pi/extensions/zob-harness/src/coms-v2/types.ts +149 -0
- package/.pi/extensions/zob-harness/src/coms-v2/zpeer-profile.ts +140 -0
- package/.pi/extensions/zob-harness/src/coms-v2/zpeer.ts +452 -0
- package/.pi/extensions/zob-harness/src/constants.ts +108 -0
- package/.pi/extensions/zob-harness/src/context-gbrain.ts +465 -0
- package/.pi/extensions/zob-harness/src/daemon-policy.ts +223 -0
- package/.pi/extensions/zob-harness/src/daemon-readiness.ts +134 -0
- package/.pi/extensions/zob-harness/src/daemon-runtime.ts +393 -0
- package/.pi/extensions/zob-harness/src/factory/AGENTS.md +24 -0
- package/.pi/extensions/zob-harness/src/factory/agentic-plan.ts +65 -0
- package/.pi/extensions/zob-harness/src/factory/quarantine.ts +319 -0
- package/.pi/extensions/zob-harness/src/factory/run.ts +520 -0
- package/.pi/extensions/zob-harness/src/factory/validation.ts +454 -0
- package/.pi/extensions/zob-harness/src/factory-selector.ts +318 -0
- package/.pi/extensions/zob-harness/src/full-autonomy-test.ts +226 -0
- package/.pi/extensions/zob-harness/src/git-ops.ts +868 -0
- package/.pi/extensions/zob-harness/src/goal-room.ts +178 -0
- package/.pi/extensions/zob-harness/src/goal-runtime.ts +1569 -0
- package/.pi/extensions/zob-harness/src/goal-todo-imports.ts +111 -0
- package/.pi/extensions/zob-harness/src/goal-todo-types.ts +231 -0
- package/.pi/extensions/zob-harness/src/goal-todos.ts +1410 -0
- package/.pi/extensions/zob-harness/src/goal.ts +152 -0
- package/.pi/extensions/zob-harness/src/governed-requests.ts +436 -0
- package/.pi/extensions/zob-harness/src/interactive-autonomy.ts +595 -0
- package/.pi/extensions/zob-harness/src/launch-apply.ts +313 -0
- package/.pi/extensions/zob-harness/src/merge-queue.ts +290 -0
- package/.pi/extensions/zob-harness/src/mission-control.ts +573 -0
- package/.pi/extensions/zob-harness/src/model-availability.ts +52 -0
- package/.pi/extensions/zob-harness/src/model-routing.ts +429 -0
- package/.pi/extensions/zob-harness/src/orchestration/AGENTS.md +23 -0
- package/.pi/extensions/zob-harness/src/orchestration/adaptive-delegation.ts +547 -0
- package/.pi/extensions/zob-harness/src/orchestration/adaptive-workflow.ts +585 -0
- package/.pi/extensions/zob-harness/src/orchestration/lead-plan.ts +192 -0
- package/.pi/extensions/zob-harness/src/orchestration/plan.ts +168 -0
- package/.pi/extensions/zob-harness/src/orchestration/room.ts +346 -0
- package/.pi/extensions/zob-harness/src/orchestration/run.ts +134 -0
- package/.pi/extensions/zob-harness/src/orchestration/supervised-readonly.ts +1147 -0
- package/.pi/extensions/zob-harness/src/orchestration/widget-readers.ts +132 -0
- package/.pi/extensions/zob-harness/src/output-contracts.ts +656 -0
- package/.pi/extensions/zob-harness/src/project-dna.ts +533 -0
- package/.pi/extensions/zob-harness/src/promotion/AGENTS.md +24 -0
- package/.pi/extensions/zob-harness/src/promotion/candidate.ts +336 -0
- package/.pi/extensions/zob-harness/src/promotion/coms.ts +127 -0
- package/.pi/extensions/zob-harness/src/promotion/documentation.ts +142 -0
- package/.pi/extensions/zob-harness/src/promotion/factory.ts +107 -0
- package/.pi/extensions/zob-harness/src/promotion/ledger.ts +2 -0
- package/.pi/extensions/zob-harness/src/promotion/temp-agent.ts +151 -0
- package/.pi/extensions/zob-harness/src/promotion/types.ts +149 -0
- package/.pi/extensions/zob-harness/src/promotion/validate.ts +6 -0
- package/.pi/extensions/zob-harness/src/promotion/write-lane.ts +162 -0
- package/.pi/extensions/zob-harness/src/prompt-packs.ts +239 -0
- package/.pi/extensions/zob-harness/src/queue.ts +386 -0
- package/.pi/extensions/zob-harness/src/rules.ts +225 -0
- package/.pi/extensions/zob-harness/src/runtime/AGENTS.md +26 -0
- package/.pi/extensions/zob-harness/src/runtime/adaptive-zmode.ts +116 -0
- package/.pi/extensions/zob-harness/src/runtime/auto-compaction.ts +715 -0
- package/.pi/extensions/zob-harness/src/runtime/commands.ts +1315 -0
- package/.pi/extensions/zob-harness/src/runtime/compaction-policy.ts +516 -0
- package/.pi/extensions/zob-harness/src/runtime/delegation-click-markers.ts +141 -0
- package/.pi/extensions/zob-harness/src/runtime/delegation-feed.ts +415 -0
- package/.pi/extensions/zob-harness/src/runtime/delegation-markdown.ts +97 -0
- package/.pi/extensions/zob-harness/src/runtime/delegation-monitor.ts +553 -0
- package/.pi/extensions/zob-harness/src/runtime/delegation-mouse.ts +205 -0
- package/.pi/extensions/zob-harness/src/runtime/delegation-overlay.ts +434 -0
- package/.pi/extensions/zob-harness/src/runtime/events.ts +736 -0
- package/.pi/extensions/zob-harness/src/runtime/goal-todo-overlay.ts +214 -0
- package/.pi/extensions/zob-harness/src/runtime/mode-intent.ts +144 -0
- package/.pi/extensions/zob-harness/src/runtime/plan-capture.ts +270 -0
- package/.pi/extensions/zob-harness/src/runtime/state.ts +403 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-autonomous.ts +117 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-compute.ts +136 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-coms.ts +365 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-context.ts +70 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-delegation.ts +1854 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-factory.ts +810 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-goal-room.ts +46 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-governed-requests.ts +38 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-merge-queue.ts +61 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-mission-control.ts +77 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-orchestration.ts +106 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-project-dna.ts +123 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-worker-pool.ts +93 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-workspace-claims.ts +62 -0
- package/.pi/extensions/zob-harness/src/runtime/tools-zcommit.ts +147 -0
- package/.pi/extensions/zob-harness/src/runtime/widget.ts +353 -0
- package/.pi/extensions/zob-harness/src/runtime/zobHarness.ts +60 -0
- package/.pi/extensions/zob-harness/src/safety.ts +338 -0
- package/.pi/extensions/zob-harness/src/sandbox.ts +1508 -0
- package/.pi/extensions/zob-harness/src/schemas-project-dna.ts +47 -0
- package/.pi/extensions/zob-harness/src/schemas.ts +695 -0
- package/.pi/extensions/zob-harness/src/telemetry.ts +373 -0
- package/.pi/extensions/zob-harness/src/topology/AGENTS.md +22 -0
- package/.pi/extensions/zob-harness/src/topology/chains.ts +236 -0
- package/.pi/extensions/zob-harness/src/topology/coms.ts +211 -0
- package/.pi/extensions/zob-harness/src/topology/orchestration-profiles.ts +204 -0
- package/.pi/extensions/zob-harness/src/topology/teams.ts +113 -0
- package/.pi/extensions/zob-harness/src/types/core.ts +47 -0
- package/.pi/extensions/zob-harness/src/types.ts +939 -0
- package/.pi/extensions/zob-harness/src/utils/AGENTS.md +22 -0
- package/.pi/extensions/zob-harness/src/utils/formatting.ts +34 -0
- package/.pi/extensions/zob-harness/src/utils/hashing.ts +11 -0
- package/.pi/extensions/zob-harness/src/utils/json.ts +28 -0
- package/.pi/extensions/zob-harness/src/utils/paths.ts +54 -0
- package/.pi/extensions/zob-harness/src/utils/records.ts +25 -0
- package/.pi/extensions/zob-harness/src/utils/resources.ts +38 -0
- package/.pi/extensions/zob-harness/src/worker-pool.ts +672 -0
- package/.pi/extensions/zob-harness/src/workspace-claims.ts +297 -0
- package/.pi/extensions/zob-switch/index.ts +180 -0
- package/.pi/factories/budget-preflight-dry-run/batch-manifest.json +59 -0
- package/.pi/factories/budget-preflight-dry-run/factory.json +94 -0
- package/.pi/factories/budget-preflight-dry-run/pilot-manifest.json +50 -0
- package/.pi/factories/budget-preflight-dry-run/smoke-manifest.json +43 -0
- package/.pi/factories/code-review-matrix/batch-manifest.json +61 -0
- package/.pi/factories/code-review-matrix/factory.json +163 -0
- package/.pi/factories/code-review-matrix/pilot-manifest.json +41 -0
- package/.pi/factories/code-review-matrix/smoke-manifest.json +35 -0
- package/.pi/factories/factory-forge/batch-manifest.json +56 -0
- package/.pi/factories/factory-forge/factory.json +84 -0
- package/.pi/factories/factory-forge/pilot-manifest.json +32 -0
- package/.pi/factories/factory-forge/smoke-manifest.json +19 -0
- package/.pi/factories/opencode-pattern-canonizer/batch-manifest.json +54 -0
- package/.pi/factories/opencode-pattern-canonizer/factory.json +86 -0
- package/.pi/factories/opencode-pattern-canonizer/pilot-manifest.json +39 -0
- package/.pi/factories/opencode-pattern-canonizer/smoke-manifest.json +26 -0
- package/.pi/factories/project-dna/README.md +182 -0
- package/.pi/factories/project-dna/batch-manifest.json +37 -0
- package/.pi/factories/project-dna/example-project-dna-manifest-v2.json +80 -0
- package/.pi/factories/project-dna/example-project-dna-manifest.json +58 -0
- package/.pi/factories/project-dna/factory.json +131 -0
- package/.pi/factories/project-dna/golden-cases-smoke.json +62 -0
- package/.pi/factories/project-dna/pi-agentic-ontology.json +88 -0
- package/.pi/factories/project-dna/pilot-manifest.json +32 -0
- package/.pi/factories/project-dna/schemas/benchmark-suite.schema.json +27 -0
- package/.pi/factories/project-dna/schemas/code-knowledge-graph.schema.json +97 -0
- package/.pi/factories/project-dna/schemas/context-pack.schema.json +43 -0
- package/.pi/factories/project-dna/schemas/golden-case.schema.json +36 -0
- package/.pi/factories/project-dna/schemas/manifest-v2.schema.json +128 -0
- package/.pi/factories/project-dna/schemas/manifest.schema.json +77 -0
- package/.pi/factories/project-dna/schemas/ontology.schema.json +45 -0
- package/.pi/factories/project-dna/schemas/project-fingerprint.schema.json +28 -0
- package/.pi/factories/project-dna/schemas/query-steward-report.schema.json +52 -0
- package/.pi/factories/project-dna/smoke-manifest.json +27 -0
- package/.pi/factories/roadmap-smoke-lots/batch-manifest.json +49 -0
- package/.pi/factories/roadmap-smoke-lots/factory.json +89 -0
- package/.pi/factories/roadmap-smoke-lots/pilot-manifest.json +50 -0
- package/.pi/factories/roadmap-smoke-lots/smoke-manifest.json +35 -0
- package/.pi/git-policy.json +120 -0
- package/.pi/mission-control/zob_coms_transport.json +64 -0
- package/.pi/model-catalog.example.json +345 -0
- package/.pi/model-economy.example.json +196 -0
- package/.pi/model-routing.json +86 -0
- package/.pi/orchestrations/adaptive-chief-vision.json +193 -0
- package/.pi/orchestrations/ceo-feature-build.json +182 -0
- package/.pi/orchestrations/readonly-dynamic-smoke.json +75 -0
- package/.pi/output-contracts/agent-event.v1.json +19 -0
- package/.pi/output-contracts/base.v1.json +24 -0
- package/.pi/output-contracts/brain-lookup.v1.json +21 -0
- package/.pi/output-contracts/clarification.v1.json +21 -0
- package/.pi/output-contracts/context-pack.v1.json +20 -0
- package/.pi/output-contracts/context-request.v1.json +21 -0
- package/.pi/output-contracts/context-steward.v1.json +19 -0
- package/.pi/output-contracts/context-writeback-proposal.v1.json +18 -0
- package/.pi/output-contracts/delegation-request.v1.json +21 -0
- package/.pi/output-contracts/explore.v1.json +52 -0
- package/.pi/output-contracts/factory.v1.json +48 -0
- package/.pi/output-contracts/guidance-steward.v1.json +18 -0
- package/.pi/output-contracts/implement.v1.json +40 -0
- package/.pi/output-contracts/launch-authorization.v1.json +21 -0
- package/.pi/output-contracts/lead-plan.v1.json +22 -0
- package/.pi/output-contracts/mission-readiness.v1.json +20 -0
- package/.pi/output-contracts/oracle-merge.v1.json +44 -0
- package/.pi/output-contracts/oracle-request.v1.json +20 -0
- package/.pi/output-contracts/oracle.v1.json +44 -0
- package/.pi/output-contracts/orchestration-profile.v1.json +22 -0
- package/.pi/output-contracts/plan.v1.json +48 -0
- package/.pi/output-contracts/prompt-pack.v1.json +20 -0
- package/.pi/output-contracts/qa.v1.json +40 -0
- package/.pi/output-contracts/research.v1.json +36 -0
- package/.pi/output-contracts/spec.v1.json +22 -0
- package/.pi/output-contracts/synthesis.v1.json +44 -0
- package/.pi/output-contracts/temp-agent-card.v1.json +23 -0
- package/.pi/output-contracts/todo-child-result.v1.json +20 -0
- package/.pi/output-contracts/todo-child-result.v2.json +22 -0
- package/.pi/output-contracts/todo-claim-validation.v1.json +22 -0
- package/.pi/output-contracts/todo-split-request.v1.json +20 -0
- package/.pi/prompts/adaptive-workflow.md +63 -0
- package/.pi/prompts/autonomous-runtime.md +15 -0
- package/.pi/prompts/benchmark-contender.md +15 -0
- package/.pi/prompts/benchmark-judge.md +19 -0
- package/.pi/prompts/clarify-spec.md +20 -0
- package/.pi/prompts/compute-plan.md +36 -0
- package/.pi/prompts/compute-preview.md +42 -0
- package/.pi/prompts/contract.md +29 -0
- package/.pi/prompts/explore.md +13 -0
- package/.pi/prompts/factory-run.md +36 -0
- package/.pi/prompts/factory.md +20 -0
- package/.pi/prompts/implement.md +27 -0
- package/.pi/prompts/model-catalog.md +68 -0
- package/.pi/prompts/model-economy.md +64 -0
- package/.pi/prompts/oracle-merge.md +18 -0
- package/.pi/prompts/oracle.md +13 -0
- package/.pi/prompts/orchestrator.md +48 -0
- package/.pi/prompts/parallel-review.md +21 -0
- package/.pi/prompts/plan.md +21 -0
- package/.pi/prompts/project-dna.md +90 -0
- package/.pi/prompts/refactor-oracle.md +23 -0
- package/.pi/prompts/refactor-slice.md +24 -0
- package/.pi/prompts/research.md +20 -0
- package/.pi/prompts/spec.md +19 -0
- package/.pi/prompts/synthesis.md +18 -0
- package/.pi/rules/always.md +38 -0
- package/.pi/rules/docs.md +32 -0
- package/.pi/rules/factory.md +44 -0
- package/.pi/rules/oracle.md +34 -0
- package/.pi/rules/orchestration.md +44 -0
- package/.pi/rules/project.md +34 -0
- package/.pi/rules/prompts.md +43 -0
- package/.pi/rules/runtime.md +43 -0
- package/.pi/rules/sandbox.md +43 -0
- package/.pi/settings.json +28 -0
- package/.pi/skills/zob-agentic-access/SKILL.md +20 -0
- package/.pi/skills/zob-autonomous-runtime/SKILL.md +41 -0
- package/.pi/skills/zob-commit/SKILL.md +79 -0
- package/.pi/skills/zob-compaction-policy/SKILL.md +92 -0
- package/.pi/skills/zob-compute-profile/SKILL.md +108 -0
- package/.pi/skills/zob-coms-safety/SKILL.md +54 -0
- package/.pi/skills/zob-coms-v2-live/SKILL.md +47 -0
- package/.pi/skills/zob-delegation-routing/SKILL.md +82 -0
- package/.pi/skills/zob-factory/SKILL.md +28 -0
- package/.pi/skills/zob-goal-todo-tree/SKILL.md +279 -0
- package/.pi/skills/zob-harness/SKILL.md +68 -0
- package/.pi/skills/zob-mission-control-coms/SKILL.md +39 -0
- package/.pi/skills/zob-oracle/SKILL.md +21 -0
- package/.pi/skills/zob-owner-pool-drill-writer/SKILL.md +244 -0
- package/.pi/skills/zob-owner-pool-launcher/SKILL.md +261 -0
- package/.pi/skills/zob-project-dna/SKILL.md +275 -0
- package/.pi/skills/zob-sandbox/SKILL.md +29 -0
- package/.pi/skills/zob-spec/SKILL.md +25 -0
- package/.pi/skills/zob-split-refactor/SKILL.md +39 -0
- package/.pi/skills/zob-tool-router/SKILL.md +104 -0
- package/.pi/teams/zob-core.json +122 -0
- package/AGENTS.md +89 -0
- package/CONTRIBUTING.md +56 -0
- package/LICENSE +21 -0
- package/README.md +360 -0
- package/SECURITY.md +35 -0
- package/SOURCE_INDEX.md +46 -0
- package/package.json +135 -0
- package/scripts/README.md +57 -0
- package/scripts/autonomy/mission-readiness-secret-smoke.mjs +90 -0
- package/scripts/compute-profile/plan-workflow.mjs +85 -0
- package/scripts/compute-profile/preview.mjs +242 -0
- package/scripts/compute-profile/regression-smoke.mjs +38 -0
- package/scripts/compute-profile/summarize.mjs +72 -0
- package/scripts/compute-profile/validate-policy.mjs +50 -0
- package/scripts/compute-profile/validate-preview.mjs +95 -0
- package/scripts/compute-profile/validate-workflow.mjs +58 -0
- package/scripts/git-ops/commit-policy-smoke.mjs +221 -0
- package/scripts/goal-todo/child-goal-ref-smoke.mjs +252 -0
- package/scripts/harness-switch/static-smoke.mjs +43 -0
- package/scripts/model-catalog/validate-economy.mjs +223 -0
- package/scripts/model-catalog/validate.mjs +199 -0
- package/scripts/package-surface/validate-script-refs.mjs +190 -0
- package/scripts/path-policy/validate-smoke.mjs +103 -0
- package/scripts/project-dna/bench-smoke.mjs +217 -0
- package/scripts/project-dna/build-capsules.mjs +207 -0
- package/scripts/project-dna/build-sample-spec.mjs +140 -0
- package/scripts/project-dna/emit-golden-cases.mjs +75 -0
- package/scripts/project-dna/emit-ontology.mjs +75 -0
- package/scripts/project-dna/generate-sample.mjs +302 -0
- package/scripts/project-dna/oracle-review-smoke.mjs +157 -0
- package/scripts/project-dna/plan-workflow.mjs +289 -0
- package/scripts/project-dna/query-context.mjs +276 -0
- package/scripts/project-dna/query-steward.mjs +149 -0
- package/scripts/project-dna/scan.mjs +553 -0
- package/scripts/project-dna/validate-5of5.mjs +159 -0
- package/scripts/project-dna/validate-golden-cases.mjs +78 -0
- package/scripts/project-dna/validate-ontology.mjs +97 -0
- package/scripts/project-dna/validate-sample-project.mjs +105 -0
- package/scripts/project-dna/validate-scaffold.mjs +383 -0
- package/scripts/project-dna/validate-scan-artifacts.mjs +187 -0
- package/scripts/project-dna/validate-workflow.mjs +166 -0
- package/scripts/start-pi.sh +4 -0
- package/scripts/worker-pool/static-smoke.mjs +54 -0
- package/scripts/zpeer-local-e2e-smoke.mjs +395 -0
- package/scripts/zpeer-static-smoke.mjs +129 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
import { closeSync, existsSync, openSync, readFileSync, readSync, statSync } from "node:fs";
|
|
2
|
+
import { resolve, sep } from "node:path";
|
|
3
|
+
|
|
4
|
+
import type { ChildResult, DelegationFailureKind } from "../types.js";
|
|
5
|
+
import { isRecord } from "../utils/records.js";
|
|
6
|
+
|
|
7
|
+
export type DelegationRunSource = "delegate_agent" | "delegate_task";
|
|
8
|
+
export type DelegationRunMode = "single" | "parallel" | "chain";
|
|
9
|
+
export type DelegationRunStatus = "queued" | "running" | "preflight_failed" | "complete" | "failed" | "aborted";
|
|
10
|
+
export type DelegationSortMode = "active" | "latest" | "duration" | "agent";
|
|
11
|
+
export type DelegationVerdict = "pass" | "warn" | "fail" | "inconclusive";
|
|
12
|
+
export type DelegationConfidence = "high" | "medium" | "low";
|
|
13
|
+
|
|
14
|
+
export interface DelegationSignalBadge {
|
|
15
|
+
verdict?: DelegationVerdict;
|
|
16
|
+
confidence?: DelegationConfidence;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface DelegationRunView {
|
|
20
|
+
id: string;
|
|
21
|
+
parentToolCallId: string;
|
|
22
|
+
source: DelegationRunSource;
|
|
23
|
+
mode: DelegationRunMode;
|
|
24
|
+
index?: number;
|
|
25
|
+
agent: string;
|
|
26
|
+
taskPreview: string;
|
|
27
|
+
status: DelegationRunStatus;
|
|
28
|
+
startedAtMs: number;
|
|
29
|
+
endedAtMs?: number;
|
|
30
|
+
outputPreview: string;
|
|
31
|
+
stderrPreview: string;
|
|
32
|
+
sessionPath?: string;
|
|
33
|
+
exitCode?: number;
|
|
34
|
+
gatePassed?: boolean;
|
|
35
|
+
gateErrors?: string[];
|
|
36
|
+
failureKind?: DelegationFailureKind;
|
|
37
|
+
stopReason?: string;
|
|
38
|
+
stopCondition?: string;
|
|
39
|
+
errorMessage?: string;
|
|
40
|
+
childChangedPaths?: ChildResult["childChangedPaths"];
|
|
41
|
+
usage?: ChildResult["usage"];
|
|
42
|
+
model?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface DelegationMonitorState {
|
|
46
|
+
runs: DelegationRunView[];
|
|
47
|
+
maxRuns: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface DelegationGroupView {
|
|
51
|
+
parentToolCallId: string;
|
|
52
|
+
source: DelegationRunSource;
|
|
53
|
+
mode: DelegationRunMode;
|
|
54
|
+
startedAtMs: number;
|
|
55
|
+
running: number;
|
|
56
|
+
complete: number;
|
|
57
|
+
failed: number;
|
|
58
|
+
runs: DelegationRunView[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface DelegationSummary {
|
|
62
|
+
total: number;
|
|
63
|
+
queued: number;
|
|
64
|
+
running: number;
|
|
65
|
+
complete: number;
|
|
66
|
+
failed: number;
|
|
67
|
+
preflightFailed: number;
|
|
68
|
+
aborted: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const PREVIEW_LIMIT = 48_000;
|
|
72
|
+
const TRANSCRIPT_MAX_BYTES = 240_000;
|
|
73
|
+
const TRANSCRIPT_MAX_LINES = 1_200;
|
|
74
|
+
const WIDGET_COMPLETE_TTL_MS = 30_000;
|
|
75
|
+
const WIDGET_FAILURE_TTL_MS = 120_000;
|
|
76
|
+
|
|
77
|
+
function capPreview(text: string | undefined, limit = PREVIEW_LIMIT): string {
|
|
78
|
+
const value = text ?? "";
|
|
79
|
+
if (value.length <= limit) return value;
|
|
80
|
+
const head = Math.floor(limit * 0.6);
|
|
81
|
+
const tail = Math.max(0, limit - head);
|
|
82
|
+
return `${value.slice(0, head)}\n\n[… ${value.length - limit} chars omitted from delegation preview …]\n\n${value.slice(-tail)}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function taskPreview(task: string, limit = 180): string {
|
|
86
|
+
const compact = task.replace(/\s+/g, " ").trim();
|
|
87
|
+
return compact.length <= limit ? compact : `${compact.slice(0, limit - 1)}…`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function terminalRank(status: DelegationRunStatus): number {
|
|
91
|
+
switch (status) {
|
|
92
|
+
case "running": return 0;
|
|
93
|
+
case "queued": return 1;
|
|
94
|
+
case "failed": return 2;
|
|
95
|
+
case "preflight_failed": return 3;
|
|
96
|
+
case "aborted": return 4;
|
|
97
|
+
case "complete": return 5;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function isTerminalStatus(status: DelegationRunStatus): boolean {
|
|
102
|
+
return status === "preflight_failed" || status === "complete" || status === "failed" || status === "aborted";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function normalizeRepoLocalPath(path: string): string {
|
|
106
|
+
return resolve(path);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function isInside(root: string, candidate: string): boolean {
|
|
110
|
+
const normalizedRoot = normalizeRepoLocalPath(root);
|
|
111
|
+
const normalizedCandidate = normalizeRepoLocalPath(candidate);
|
|
112
|
+
return normalizedCandidate === normalizedRoot || normalizedCandidate.startsWith(`${normalizedRoot}${sep}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function textFromContent(content: unknown): string {
|
|
116
|
+
if (typeof content === "string") return content;
|
|
117
|
+
if (!Array.isArray(content)) return "";
|
|
118
|
+
const parts: string[] = [];
|
|
119
|
+
for (const part of content) {
|
|
120
|
+
if (!isRecord(part) || typeof part.type !== "string") continue;
|
|
121
|
+
if (part.type === "text" && typeof part.text === "string") parts.push(part.text);
|
|
122
|
+
else if (part.type === "thinking" && typeof part.thinking === "string") parts.push(`[thinking]\n${part.thinking}`);
|
|
123
|
+
else if (part.type === "toolCall") {
|
|
124
|
+
const name = typeof part.name === "string" ? part.name : "tool";
|
|
125
|
+
const args = isRecord(part.arguments) ? JSON.stringify(part.arguments) : "{}";
|
|
126
|
+
parts.push(`[tool call: ${name}] ${args}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return parts.join("\n");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function readCappedFile(path: string, size: number, maxBytes: number): string {
|
|
133
|
+
if (size <= maxBytes) return readFileSync(path, "utf8");
|
|
134
|
+
const headBytes = Math.floor(maxBytes * 0.55);
|
|
135
|
+
const tailBytes = Math.max(0, maxBytes - headBytes);
|
|
136
|
+
const head = Buffer.alloc(headBytes);
|
|
137
|
+
const tail = Buffer.alloc(tailBytes);
|
|
138
|
+
const fd = openSync(path, "r");
|
|
139
|
+
try {
|
|
140
|
+
readSync(fd, head, 0, headBytes, 0);
|
|
141
|
+
readSync(fd, tail, 0, tailBytes, Math.max(0, size - tailBytes));
|
|
142
|
+
} finally {
|
|
143
|
+
closeSync(fd);
|
|
144
|
+
}
|
|
145
|
+
return `${head.toString("utf8")}\n{\"type\":\"custom\",\"customType\":\"zob-transcript-truncated\",\"data\":{\"omittedBytes\":${size - maxBytes}}}\n${tail.toString("utf8")}`;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function formatSessionEntry(line: string): string[] {
|
|
149
|
+
let parsed: unknown;
|
|
150
|
+
try {
|
|
151
|
+
parsed = JSON.parse(line);
|
|
152
|
+
} catch {
|
|
153
|
+
return [];
|
|
154
|
+
}
|
|
155
|
+
if (!isRecord(parsed)) return [];
|
|
156
|
+
|
|
157
|
+
if (parsed.type === "session") {
|
|
158
|
+
const cwd = typeof parsed.cwd === "string" ? ` cwd=${parsed.cwd}` : "";
|
|
159
|
+
return [`[session]${cwd}`];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (parsed.type === "message" && isRecord(parsed.message)) {
|
|
163
|
+
const message = parsed.message;
|
|
164
|
+
const role = typeof message.role === "string" ? message.role : "message";
|
|
165
|
+
const text = textFromContent(message.content);
|
|
166
|
+
if (role === "toolResult") {
|
|
167
|
+
const toolName = typeof message.toolName === "string" ? message.toolName : "tool";
|
|
168
|
+
const isError = message.isError === true ? " error" : "";
|
|
169
|
+
return [`[tool result: ${toolName}${isError}]`, ...(text ? text.split("\n") : ["(no text content)"])];
|
|
170
|
+
}
|
|
171
|
+
return [`[${role}]`, ...(text ? text.split("\n") : ["(no text content)"])];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (parsed.type === "custom" && typeof parsed.customType === "string") {
|
|
175
|
+
return [`[custom: ${parsed.customType}] ${JSON.stringify(parsed.data ?? {})}`];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (parsed.type === "custom_message") {
|
|
179
|
+
const customType = typeof parsed.customType === "string" ? parsed.customType : "custom";
|
|
180
|
+
const text = textFromContent(parsed.content);
|
|
181
|
+
return [`[custom message: ${customType}]`, ...(text ? text.split("\n") : ["(no text content)"])];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (parsed.type === "model_change") {
|
|
185
|
+
const provider = typeof parsed.provider === "string" ? parsed.provider : "";
|
|
186
|
+
const model = typeof parsed.modelId === "string" ? parsed.modelId : "";
|
|
187
|
+
return [`[model] ${provider}/${model}`.replace(/^\[model\] \/?/, "[model] ")];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (parsed.type === "thinking_level_change" && typeof parsed.thinkingLevel === "string") return [`[thinking] ${parsed.thinkingLevel}`];
|
|
191
|
+
if (parsed.type === "compaction" && typeof parsed.summary === "string") return ["[compaction]", parsed.summary];
|
|
192
|
+
if (parsed.type === "branch_summary" && typeof parsed.summary === "string") return ["[branch summary]", parsed.summary];
|
|
193
|
+
|
|
194
|
+
return [];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function createDelegationMonitorState(maxRuns = 60): DelegationMonitorState {
|
|
198
|
+
return { runs: [], maxRuns };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function delegationDurationMs(run: DelegationRunView, nowMs = Date.now()): number {
|
|
202
|
+
return Math.max(0, (run.endedAtMs ?? nowMs) - run.startedAtMs);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function formatDuration(durationMs: number): string {
|
|
206
|
+
const safe = Math.max(0, Math.floor(durationMs));
|
|
207
|
+
const tenths = Math.floor((safe % 1000) / 100);
|
|
208
|
+
const totalSeconds = Math.floor(safe / 1000);
|
|
209
|
+
const seconds = totalSeconds % 60;
|
|
210
|
+
const minutes = Math.floor(totalSeconds / 60) % 60;
|
|
211
|
+
const hours = Math.floor(totalSeconds / 3600);
|
|
212
|
+
const pad2 = (value: number): string => String(value).padStart(2, "0");
|
|
213
|
+
if (hours > 0) return `${hours}:${pad2(minutes)}:${pad2(seconds)}`;
|
|
214
|
+
return `${pad2(minutes)}:${pad2(seconds)}.${tenths}`;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export function formatDelegationCost(cost: number | undefined): string {
|
|
218
|
+
if (typeof cost !== "number" || !Number.isFinite(cost) || cost <= 0) return "$0.0000";
|
|
219
|
+
if (cost < 0.0001) return "<$0.0001";
|
|
220
|
+
if (cost < 1) return `$${cost.toFixed(4)}`;
|
|
221
|
+
if (cost < 10) return `$${cost.toFixed(3)}`;
|
|
222
|
+
return `$${cost.toFixed(2)}`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function delegationCost(run: DelegationRunView | undefined): number {
|
|
226
|
+
return run?.usage?.cost ?? 0;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function formatTokenCount(value: number): string {
|
|
230
|
+
const safe = Math.max(0, Math.floor(value));
|
|
231
|
+
if (safe < 1_000) return String(safe);
|
|
232
|
+
if (safe < 1_000_000) return `${(safe / 1_000).toFixed(safe < 10_000 ? 1 : 0)}k`;
|
|
233
|
+
return `${(safe / 1_000_000).toFixed(1)}m`;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function formatDelegationCostLabel(run: DelegationRunView | undefined): string {
|
|
237
|
+
if (run?.usage) return formatDelegationCost(run.usage.cost);
|
|
238
|
+
if (run?.status === "queued" || run?.status === "running") return "cost pending";
|
|
239
|
+
return "cost unavailable";
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function formatDelegationContextLabel(run: DelegationRunView | undefined): string {
|
|
243
|
+
if (run?.usage) return `ctx ${formatTokenCount(run.usage.contextTokens)} tok`;
|
|
244
|
+
if (run?.status === "queued" || run?.status === "running") return "ctx pending";
|
|
245
|
+
return "ctx unavailable";
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function formatDelegationModelLabel(run: DelegationRunView | { model?: string } | undefined, limit = 48): string {
|
|
249
|
+
if (!run?.model) return "";
|
|
250
|
+
const value = run.model.replace(/^\//, "").trim();
|
|
251
|
+
if (!value) return "";
|
|
252
|
+
return value.length <= limit ? value : `${value.slice(0, limit - 1)}…`;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function stripSignalControlSequences(text: string): string {
|
|
256
|
+
return text
|
|
257
|
+
.replace(/\x1b\][\s\S]*?(?:\x07|\x1b\\)/g, "")
|
|
258
|
+
.replace(/\x1b[PX^_][\s\S]*?\x1b\\/g, "")
|
|
259
|
+
.replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, "")
|
|
260
|
+
.replace(/\x1b[@-Z\\-_]/g, "")
|
|
261
|
+
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, "");
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function normalizeVerdict(value: string | undefined): DelegationVerdict | undefined {
|
|
265
|
+
const normalized = value?.trim().toLowerCase();
|
|
266
|
+
if (normalized === "pass") return "pass";
|
|
267
|
+
if (normalized === "warn" || normalized === "warning") return "warn";
|
|
268
|
+
if (normalized === "fail" || normalized === "failed") return "fail";
|
|
269
|
+
if (normalized === "inconclusive") return "inconclusive";
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function normalizeConfidence(value: string | undefined): DelegationConfidence | undefined {
|
|
274
|
+
const normalized = value?.trim().toLowerCase();
|
|
275
|
+
if (normalized === "high") return "high";
|
|
276
|
+
if (normalized === "medium" || normalized === "med") return "medium";
|
|
277
|
+
if (normalized === "low") return "low";
|
|
278
|
+
return undefined;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export function extractDelegationSignalBadge(text: string | undefined): DelegationSignalBadge | undefined {
|
|
282
|
+
if (!text?.trim()) return undefined;
|
|
283
|
+
const source = stripSignalControlSequences(text.slice(0, 48_000));
|
|
284
|
+
const verdictMatch = source.match(/<verdict>\s*(PASS|WARN|WARNING|FAIL|FAILED|INCONCLUSIVE)\s*<\/verdict>/i)
|
|
285
|
+
?? source.match(/(?:^|\n)\s*(?:[-*]\s*)?verdict\s*[:=]\s*(PASS|WARN|WARNING|FAIL|FAILED|INCONCLUSIVE)\b/i);
|
|
286
|
+
const confidenceMatch = source.match(/<confidence>\s*(HIGH|MEDIUM|MED|LOW)\s*<\/confidence>/i)
|
|
287
|
+
?? source.match(/(?:^|\n)\s*(?:[-*]\s*)?confidence\s*[:=]\s*(HIGH|MEDIUM|MED|LOW)\b/i);
|
|
288
|
+
const verdict = normalizeVerdict(verdictMatch?.[1]);
|
|
289
|
+
const confidence = normalizeConfidence(confidenceMatch?.[1]);
|
|
290
|
+
return verdict || confidence ? { verdict, confidence } : undefined;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export function delegationSignalBadge(run: DelegationRunView | undefined): DelegationSignalBadge | undefined {
|
|
294
|
+
return extractDelegationSignalBadge(run?.outputPreview);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export function formatDelegationSignalBadge(badge: DelegationSignalBadge | undefined): string {
|
|
298
|
+
if (!badge) return "";
|
|
299
|
+
const verdict = badge.verdict === "pass"
|
|
300
|
+
? "✓ PASS"
|
|
301
|
+
: badge.verdict === "warn"
|
|
302
|
+
? "⚠ WARN"
|
|
303
|
+
: badge.verdict === "fail"
|
|
304
|
+
? "✗ FAIL"
|
|
305
|
+
: badge.verdict === "inconclusive"
|
|
306
|
+
? "? INC"
|
|
307
|
+
: "";
|
|
308
|
+
const confidence = badge.confidence === "high" ? "H" : badge.confidence === "medium" ? "M" : badge.confidence === "low" ? "L" : "";
|
|
309
|
+
return [verdict, confidence ? `◆ ${confidence}` : ""].filter(Boolean).join(" ");
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export function delegationSignalColor(badge: DelegationSignalBadge | undefined): "success" | "warning" | "error" | "muted" {
|
|
313
|
+
if (badge?.verdict === "pass") return "success";
|
|
314
|
+
if (badge?.verdict === "warn" || badge?.verdict === "inconclusive") return "warning";
|
|
315
|
+
if (badge?.verdict === "fail") return "error";
|
|
316
|
+
if (badge?.confidence === "high") return "success";
|
|
317
|
+
if (badge?.confidence === "medium") return "warning";
|
|
318
|
+
if (badge?.confidence === "low") return "error";
|
|
319
|
+
return "muted";
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export function statusIcon(status: DelegationRunStatus): string {
|
|
323
|
+
switch (status) {
|
|
324
|
+
case "queued": return "○";
|
|
325
|
+
case "running": return "●";
|
|
326
|
+
case "preflight_failed": return "▲";
|
|
327
|
+
case "complete": return "✓";
|
|
328
|
+
case "failed": return "✗";
|
|
329
|
+
case "aborted": return "■";
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export function summarizeDelegations(state: DelegationMonitorState): DelegationSummary {
|
|
334
|
+
const summary: DelegationSummary = { total: state.runs.length, queued: 0, running: 0, complete: 0, failed: 0, preflightFailed: 0, aborted: 0 };
|
|
335
|
+
for (const run of state.runs) {
|
|
336
|
+
if (run.status === "queued") summary.queued++;
|
|
337
|
+
else if (run.status === "running") summary.running++;
|
|
338
|
+
else if (run.status === "complete") summary.complete++;
|
|
339
|
+
else if (run.status === "failed") summary.failed++;
|
|
340
|
+
else if (run.status === "preflight_failed") summary.preflightFailed++;
|
|
341
|
+
else if (run.status === "aborted") summary.aborted++;
|
|
342
|
+
}
|
|
343
|
+
return summary;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export function hasActiveDelegations(state: DelegationMonitorState): boolean {
|
|
347
|
+
return state.runs.some((run) => run.status === "queued" || run.status === "running");
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export function listDelegationRuns(state: DelegationMonitorState, sort: DelegationSortMode = "active", nowMs = Date.now()): DelegationRunView[] {
|
|
351
|
+
const runs = [...state.runs];
|
|
352
|
+
runs.sort((a, b) => {
|
|
353
|
+
if (sort === "agent") return a.agent.localeCompare(b.agent) || b.startedAtMs - a.startedAtMs;
|
|
354
|
+
if (sort === "duration") return delegationDurationMs(b, nowMs) - delegationDurationMs(a, nowMs) || b.startedAtMs - a.startedAtMs;
|
|
355
|
+
if (sort === "latest") return b.startedAtMs - a.startedAtMs || (a.index ?? 0) - (b.index ?? 0);
|
|
356
|
+
return terminalRank(a.status) - terminalRank(b.status) || b.startedAtMs - a.startedAtMs || (a.index ?? 0) - (b.index ?? 0);
|
|
357
|
+
});
|
|
358
|
+
return runs;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export function shouldShowRunInWidget(run: DelegationRunView, nowMs = Date.now()): boolean {
|
|
362
|
+
if (run.status === "queued" || run.status === "running") return true;
|
|
363
|
+
if (!run.endedAtMs) return false;
|
|
364
|
+
const ageMs = Math.max(0, nowMs - run.endedAtMs);
|
|
365
|
+
if (run.status === "complete") return ageMs <= WIDGET_COMPLETE_TTL_MS;
|
|
366
|
+
return ageMs <= WIDGET_FAILURE_TTL_MS;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export function listWidgetDelegationRuns(state: DelegationMonitorState, nowMs = Date.now()): DelegationRunView[] {
|
|
370
|
+
return state.runs.filter((run) => shouldShowRunInWidget(run, nowMs));
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export function buildDelegationGroups(state: DelegationMonitorState, sort: DelegationSortMode = "active", nowMs = Date.now()): DelegationGroupView[] {
|
|
374
|
+
const groupsById = new Map<string, DelegationGroupView>();
|
|
375
|
+
for (const run of state.runs) {
|
|
376
|
+
const existing = groupsById.get(run.parentToolCallId);
|
|
377
|
+
const group = existing ?? {
|
|
378
|
+
parentToolCallId: run.parentToolCallId,
|
|
379
|
+
source: run.source,
|
|
380
|
+
mode: run.mode,
|
|
381
|
+
startedAtMs: run.startedAtMs,
|
|
382
|
+
running: 0,
|
|
383
|
+
complete: 0,
|
|
384
|
+
failed: 0,
|
|
385
|
+
runs: [],
|
|
386
|
+
};
|
|
387
|
+
group.startedAtMs = Math.min(group.startedAtMs, run.startedAtMs);
|
|
388
|
+
group.runs.push(run);
|
|
389
|
+
groupsById.set(run.parentToolCallId, group);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const groups = [...groupsById.values()].map((group) => {
|
|
393
|
+
group.running = group.runs.filter((run) => run.status === "queued" || run.status === "running").length;
|
|
394
|
+
group.complete = group.runs.filter((run) => run.status === "complete").length;
|
|
395
|
+
group.failed = group.runs.filter((run) => run.status === "failed" || run.status === "preflight_failed" || run.status === "aborted").length;
|
|
396
|
+
group.runs = group.mode === "chain"
|
|
397
|
+
? [...group.runs].sort((a, b) => (a.index ?? 0) - (b.index ?? 0))
|
|
398
|
+
: listDelegationRuns({ runs: group.runs, maxRuns: group.runs.length }, sort, nowMs);
|
|
399
|
+
return group;
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
groups.sort((a, b) => {
|
|
403
|
+
if (a.running !== b.running) return b.running - a.running;
|
|
404
|
+
if (a.failed !== b.failed) return b.failed - a.failed;
|
|
405
|
+
return b.startedAtMs - a.startedAtMs;
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
return groups;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
export function buildWidgetDelegationGroups(state: DelegationMonitorState, sort: DelegationSortMode = "active", nowMs = Date.now()): DelegationGroupView[] {
|
|
412
|
+
const visibleRuns = listWidgetDelegationRuns(state, nowMs);
|
|
413
|
+
return buildDelegationGroups({ runs: visibleRuns, maxRuns: state.maxRuns }, sort, nowMs);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
export function startDelegationRun(state: DelegationMonitorState, input: {
|
|
417
|
+
id: string;
|
|
418
|
+
parentToolCallId: string;
|
|
419
|
+
source: DelegationRunSource;
|
|
420
|
+
mode: DelegationRunMode;
|
|
421
|
+
index?: number;
|
|
422
|
+
agent: string;
|
|
423
|
+
task: string;
|
|
424
|
+
startedAtMs: number;
|
|
425
|
+
}): DelegationRunView {
|
|
426
|
+
const existingIndex = state.runs.findIndex((run) => run.id === input.id);
|
|
427
|
+
const run: DelegationRunView = {
|
|
428
|
+
id: input.id,
|
|
429
|
+
parentToolCallId: input.parentToolCallId,
|
|
430
|
+
source: input.source,
|
|
431
|
+
mode: input.mode,
|
|
432
|
+
index: input.index,
|
|
433
|
+
agent: input.agent,
|
|
434
|
+
taskPreview: taskPreview(input.task),
|
|
435
|
+
status: "running",
|
|
436
|
+
startedAtMs: input.startedAtMs,
|
|
437
|
+
outputPreview: "",
|
|
438
|
+
stderrPreview: "",
|
|
439
|
+
};
|
|
440
|
+
if (existingIndex >= 0) state.runs[existingIndex] = run;
|
|
441
|
+
else state.runs.push(run);
|
|
442
|
+
trimDelegationRuns(state);
|
|
443
|
+
return run;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
export function updateDelegationRun(state: DelegationMonitorState, id: string, patch: Partial<Omit<DelegationRunView, "id" | "startedAtMs">>): DelegationRunView | undefined {
|
|
447
|
+
const run = state.runs.find((candidate) => candidate.id === id);
|
|
448
|
+
if (!run) return undefined;
|
|
449
|
+
if (patch.parentToolCallId !== undefined) run.parentToolCallId = patch.parentToolCallId;
|
|
450
|
+
if (patch.source !== undefined) run.source = patch.source;
|
|
451
|
+
if (patch.mode !== undefined) run.mode = patch.mode;
|
|
452
|
+
if (patch.index !== undefined) run.index = patch.index;
|
|
453
|
+
if (patch.agent !== undefined) run.agent = patch.agent;
|
|
454
|
+
if (patch.taskPreview !== undefined) run.taskPreview = patch.taskPreview;
|
|
455
|
+
if (patch.status !== undefined) run.status = patch.status;
|
|
456
|
+
if (patch.endedAtMs !== undefined) run.endedAtMs = patch.endedAtMs;
|
|
457
|
+
if (patch.outputPreview !== undefined) run.outputPreview = capPreview(patch.outputPreview);
|
|
458
|
+
if (patch.stderrPreview !== undefined) run.stderrPreview = capPreview(patch.stderrPreview);
|
|
459
|
+
if (patch.sessionPath !== undefined) run.sessionPath = patch.sessionPath;
|
|
460
|
+
if (patch.exitCode !== undefined) run.exitCode = patch.exitCode;
|
|
461
|
+
if (patch.gatePassed !== undefined) run.gatePassed = patch.gatePassed;
|
|
462
|
+
if (patch.gateErrors !== undefined) run.gateErrors = patch.gateErrors;
|
|
463
|
+
if (patch.failureKind !== undefined) run.failureKind = patch.failureKind;
|
|
464
|
+
if (patch.stopReason !== undefined) run.stopReason = patch.stopReason;
|
|
465
|
+
if (patch.stopCondition !== undefined) run.stopCondition = patch.stopCondition;
|
|
466
|
+
if (patch.errorMessage !== undefined) run.errorMessage = patch.errorMessage;
|
|
467
|
+
if (patch.usage !== undefined) run.usage = patch.usage;
|
|
468
|
+
if (patch.model !== undefined) run.model = patch.model;
|
|
469
|
+
return run;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
export function finishDelegationRun(state: DelegationMonitorState, id: string, patch: Partial<Omit<DelegationRunView, "id" | "startedAtMs">> & { endedAtMs: number; status: DelegationRunStatus }): DelegationRunView | undefined {
|
|
473
|
+
const next = { ...patch };
|
|
474
|
+
if (patch.outputPreview !== undefined) next.outputPreview = capPreview(patch.outputPreview);
|
|
475
|
+
if (patch.stderrPreview !== undefined) next.stderrPreview = capPreview(patch.stderrPreview);
|
|
476
|
+
return updateDelegationRun(state, id, next);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
export function trimDelegationRuns(state: DelegationMonitorState): void {
|
|
480
|
+
if (state.runs.length <= state.maxRuns) return;
|
|
481
|
+
const terminal = state.runs.filter((run) => isTerminalStatus(run.status)).sort((a, b) => a.startedAtMs - b.startedAtMs);
|
|
482
|
+
const toRemove = new Set<string>();
|
|
483
|
+
while (state.runs.length - toRemove.size > state.maxRuns && terminal.length > 0) {
|
|
484
|
+
const next = terminal.shift();
|
|
485
|
+
if (next) toRemove.add(next.id);
|
|
486
|
+
}
|
|
487
|
+
if (state.runs.length - toRemove.size > state.maxRuns) {
|
|
488
|
+
for (const run of [...state.runs].sort((a, b) => a.startedAtMs - b.startedAtMs)) {
|
|
489
|
+
if (state.runs.length - toRemove.size <= state.maxRuns) break;
|
|
490
|
+
toRemove.add(run.id);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
state.runs = state.runs.filter((run) => !toRemove.has(run.id));
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
export function readChildTranscript(sessionPath: string | undefined, options: { repoRoot?: string; maxBytes?: number; maxLines?: number } = {}): string[] {
|
|
497
|
+
if (!sessionPath) return [];
|
|
498
|
+
const resolved = resolve(sessionPath);
|
|
499
|
+
if (options.repoRoot && !isInside(options.repoRoot, resolved)) return [`[blocked] child session path is outside repo root: ${sessionPath}`];
|
|
500
|
+
if (!existsSync(resolved)) return [`[missing] child session file not found: ${sessionPath}`];
|
|
501
|
+
|
|
502
|
+
const maxBytes = options.maxBytes ?? TRANSCRIPT_MAX_BYTES;
|
|
503
|
+
const maxLines = options.maxLines ?? TRANSCRIPT_MAX_LINES;
|
|
504
|
+
const size = statSync(resolved).size;
|
|
505
|
+
const source = readCappedFile(resolved, size, maxBytes);
|
|
506
|
+
const rendered: string[] = [];
|
|
507
|
+
|
|
508
|
+
for (const line of source.split("\n")) {
|
|
509
|
+
if (!line.trim()) continue;
|
|
510
|
+
const entryLines = formatSessionEntry(line);
|
|
511
|
+
if (entryLines.length === 0) continue;
|
|
512
|
+
if (rendered.length > 0) rendered.push("");
|
|
513
|
+
rendered.push(...entryLines);
|
|
514
|
+
if (rendered.length >= maxLines) {
|
|
515
|
+
rendered.push(`[… transcript capped at ${maxLines} lines …]`);
|
|
516
|
+
break;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
if (rendered.length === 0) return [`[empty] no renderable child conversation entries in ${sessionPath}`];
|
|
521
|
+
if (size > maxBytes) rendered.unshift(`[… child session capped to ${maxBytes} bytes from ${size} bytes …]`, "");
|
|
522
|
+
return rendered;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
export function buildDelegationLogLines(run: DelegationRunView | undefined, repoRoot: string): string[] {
|
|
526
|
+
if (!run) return ["No delegation selected."];
|
|
527
|
+
const transcript = readChildTranscript(run.sessionPath, { repoRoot });
|
|
528
|
+
const transcriptReady = transcript.length > 0 && !transcript[0]?.startsWith("[missing]");
|
|
529
|
+
|
|
530
|
+
const lines = [
|
|
531
|
+
`[delegation ${run.id}]`,
|
|
532
|
+
`agent: ${run.agent}`,
|
|
533
|
+
run.model ? `model: ${run.model}` : undefined,
|
|
534
|
+
`status: ${run.status}`,
|
|
535
|
+
`duration: ${formatDuration(delegationDurationMs(run))}`,
|
|
536
|
+
run.sessionPath ? `session: ${run.sessionPath}` : "session: not captured yet",
|
|
537
|
+
`cost: ${formatDelegationCostLabel(run)}`,
|
|
538
|
+
`context: ${formatDelegationContextLabel(run)}`,
|
|
539
|
+
run.usage ? `usage: turns=${run.usage.turns} input=${run.usage.input} output=${run.usage.output} cacheRead=${run.usage.cacheRead} cacheWrite=${run.usage.cacheWrite} context=${run.usage.contextTokens}` : undefined,
|
|
540
|
+
run.failureKind ? `failureKind: ${run.failureKind}` : undefined,
|
|
541
|
+
run.gateErrors?.length ? `gateErrors: ${run.gateErrors.join("; ")}` : undefined,
|
|
542
|
+
"",
|
|
543
|
+
"[task preview]",
|
|
544
|
+
run.taskPreview || "(empty)",
|
|
545
|
+
].filter((line): line is string => typeof line === "string");
|
|
546
|
+
|
|
547
|
+
if (run.outputPreview.trim()) lines.push("", "[assistant output preview]", ...run.outputPreview.split("\n").slice(0, 20));
|
|
548
|
+
if (run.stderrPreview.trim()) lines.push("", "[stderr preview]", ...run.stderrPreview.split("\n").slice(0, 20));
|
|
549
|
+
if (transcriptReady) lines.push("", "[conversation]", ...transcript);
|
|
550
|
+
else if (transcript.length > 0) lines.push("", ...transcript);
|
|
551
|
+
if (!transcriptReady && !run.outputPreview.trim() && !run.stderrPreview.trim()) lines.push("", "No output captured yet.");
|
|
552
|
+
return lines;
|
|
553
|
+
}
|