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,415 @@
|
|
|
1
|
+
import { closeSync, existsSync, openSync, readFileSync, readSync, statSync } from "node:fs";
|
|
2
|
+
import { resolve, sep } from "node:path";
|
|
3
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { Markdown, truncateToWidth, visibleWidth, type MarkdownTheme } from "@earendil-works/pi-tui";
|
|
5
|
+
|
|
6
|
+
import { delegationDurationMs, delegationSignalBadge, delegationSignalColor, formatDelegationContextLabel, formatDelegationCostLabel, formatDelegationModelLabel, formatDelegationSignalBadge, formatDuration, statusIcon, type DelegationRunView } from "./delegation-monitor.js";
|
|
7
|
+
import { sanitizeDelegationText } from "./delegation-markdown.js";
|
|
8
|
+
import { isRecord } from "../utils/records.js";
|
|
9
|
+
|
|
10
|
+
const FEED_MAX_BYTES = 240_000;
|
|
11
|
+
const FEED_MAX_LINES = 1_200;
|
|
12
|
+
const BLOCK_MAX_CHARS = 32_000;
|
|
13
|
+
|
|
14
|
+
type ThemeFg = Parameters<Theme["fg"]>[0];
|
|
15
|
+
type ThemeBg = Parameters<Theme["bg"]>[0];
|
|
16
|
+
|
|
17
|
+
interface SessionReadResult {
|
|
18
|
+
status: "ok" | "missing" | "blocked" | "empty";
|
|
19
|
+
path?: string;
|
|
20
|
+
text?: string;
|
|
21
|
+
note?: string;
|
|
22
|
+
fingerprint: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function normalizePath(path: string): string {
|
|
26
|
+
return resolve(path);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function isInside(root: string, candidate: string): boolean {
|
|
30
|
+
const normalizedRoot = normalizePath(root);
|
|
31
|
+
const normalizedCandidate = normalizePath(candidate);
|
|
32
|
+
return normalizedCandidate === normalizedRoot || normalizedCandidate.startsWith(`${normalizedRoot}${sep}`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function padToWidth(text: string, width: number): string {
|
|
36
|
+
const clipped = truncateToWidth(text, Math.max(1, width), "…");
|
|
37
|
+
return clipped + " ".repeat(Math.max(0, width - visibleWidth(clipped)));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function capText(text: string, limit = BLOCK_MAX_CHARS): string {
|
|
41
|
+
text = sanitizeDelegationText(text);
|
|
42
|
+
if (text.length <= limit) return text;
|
|
43
|
+
const head = Math.floor(limit * 0.6);
|
|
44
|
+
const tail = Math.max(0, limit - head);
|
|
45
|
+
return `${text.slice(0, head)}\n\n[… ${text.length - limit} chars omitted from subagent feed …]\n\n${text.slice(-tail)}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function readCapped(path: string, size: number, maxBytes: number): string {
|
|
49
|
+
if (size <= maxBytes) return readFileSync(path, "utf8");
|
|
50
|
+
const headBytes = Math.floor(maxBytes * 0.55);
|
|
51
|
+
const tailBytes = Math.max(0, maxBytes - headBytes);
|
|
52
|
+
const head = Buffer.alloc(headBytes);
|
|
53
|
+
const tail = Buffer.alloc(tailBytes);
|
|
54
|
+
const fd = openSync(path, "r");
|
|
55
|
+
try {
|
|
56
|
+
readSync(fd, head, 0, headBytes, 0);
|
|
57
|
+
readSync(fd, tail, 0, tailBytes, Math.max(0, size - tailBytes));
|
|
58
|
+
} finally {
|
|
59
|
+
closeSync(fd);
|
|
60
|
+
}
|
|
61
|
+
return `${head.toString("utf8")}\n{"type":"custom","customType":"zob-transcript-truncated","data":{"omittedBytes":${size - maxBytes}}}\n${tail.toString("utf8")}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function readSession(sessionPath: string | undefined, repoRoot: string): SessionReadResult {
|
|
65
|
+
if (!sessionPath) return { status: "missing", note: "Child session is not captured yet.", fingerprint: "no-session" };
|
|
66
|
+
const resolved = resolve(sessionPath);
|
|
67
|
+
if (!isInside(repoRoot, resolved)) {
|
|
68
|
+
return { status: "blocked", path: sessionPath, note: `Child session path is outside repo root: ${sessionPath}`, fingerprint: `blocked:${sessionPath}` };
|
|
69
|
+
}
|
|
70
|
+
if (!existsSync(resolved)) return { status: "missing", path: sessionPath, note: `Child session file not found yet: ${sessionPath}`, fingerprint: `missing:${sessionPath}` };
|
|
71
|
+
const stat = statSync(resolved);
|
|
72
|
+
const text = readCapped(resolved, stat.size, FEED_MAX_BYTES);
|
|
73
|
+
const status = text.trim() ? "ok" : "empty";
|
|
74
|
+
return {
|
|
75
|
+
status,
|
|
76
|
+
path: resolved,
|
|
77
|
+
text,
|
|
78
|
+
note: stat.size > FEED_MAX_BYTES ? `Child session capped to ${FEED_MAX_BYTES} bytes from ${stat.size} bytes.` : undefined,
|
|
79
|
+
fingerprint: `${resolved}:${stat.size}:${Math.floor(stat.mtimeMs)}`,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function sessionFingerprint(sessionPath: string | undefined, repoRoot: string): string {
|
|
84
|
+
if (!sessionPath) return "no-session";
|
|
85
|
+
const resolved = resolve(sessionPath);
|
|
86
|
+
if (!isInside(repoRoot, resolved)) return `blocked:${sessionPath}`;
|
|
87
|
+
if (!existsSync(resolved)) return `missing:${sessionPath}`;
|
|
88
|
+
const stat = statSync(resolved);
|
|
89
|
+
return `${resolved}:${stat.size}:${Math.floor(stat.mtimeMs)}`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function delegationFeedFingerprint(run: DelegationRunView | undefined, repoRoot: string): string {
|
|
93
|
+
if (!run) return "none";
|
|
94
|
+
return [
|
|
95
|
+
run.id,
|
|
96
|
+
run.status,
|
|
97
|
+
run.sessionPath ?? "",
|
|
98
|
+
sessionFingerprint(run.sessionPath, repoRoot),
|
|
99
|
+
run.outputPreview.length,
|
|
100
|
+
run.stderrPreview.length,
|
|
101
|
+
run.endedAtMs ?? "running",
|
|
102
|
+
run.exitCode ?? "",
|
|
103
|
+
run.gatePassed ?? "",
|
|
104
|
+
run.failureKind ?? "",
|
|
105
|
+
run.usage?.cost ?? "",
|
|
106
|
+
run.usage?.input ?? "",
|
|
107
|
+
run.usage?.output ?? "",
|
|
108
|
+
run.usage?.contextTokens ?? "",
|
|
109
|
+
(run.gateErrors ?? []).join(";"),
|
|
110
|
+
run.model ?? "",
|
|
111
|
+
].join("|");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function markdownTheme(theme: Theme): MarkdownTheme {
|
|
115
|
+
return {
|
|
116
|
+
heading: (text) => theme.fg("mdHeading", text),
|
|
117
|
+
link: (text) => theme.fg("mdLink", text),
|
|
118
|
+
linkUrl: (text) => theme.fg("mdLinkUrl", text),
|
|
119
|
+
code: (text) => theme.fg("mdCode", text),
|
|
120
|
+
codeBlock: (text) => theme.fg("mdCodeBlock", text),
|
|
121
|
+
codeBlockBorder: (text) => theme.fg("mdCodeBlockBorder", text),
|
|
122
|
+
quote: (text) => theme.fg("mdQuote", text),
|
|
123
|
+
quoteBorder: (text) => theme.fg("mdQuoteBorder", text),
|
|
124
|
+
hr: (text) => theme.fg("mdHr", text),
|
|
125
|
+
listBullet: (text) => theme.fg("mdListBullet", text),
|
|
126
|
+
bold: (text) => theme.bold(text),
|
|
127
|
+
italic: (text) => theme.italic(text),
|
|
128
|
+
strikethrough: (text) => theme.strikethrough(text),
|
|
129
|
+
underline: (text) => theme.underline(text),
|
|
130
|
+
codeBlockIndent: " ",
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function humanizeTag(value: string): string {
|
|
135
|
+
return value.replace(/[_-]+/g, " ").replace(/\b\w/g, (letter) => letter.toUpperCase());
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function normalizeMarkdownText(text: string): string {
|
|
139
|
+
return capText(text)
|
|
140
|
+
.split("\n")
|
|
141
|
+
.map((line) => {
|
|
142
|
+
const trimmed = line.trim();
|
|
143
|
+
const singleTag = trimmed.match(/^<([A-Za-z0-9_-]+)>([\s\S]*)<\/\1>$/);
|
|
144
|
+
if (singleTag) return `- **${humanizeTag(singleTag[1])}:** ${singleTag[2].trim() || "_empty_"}`;
|
|
145
|
+
const openTag = trimmed.match(/^<([A-Za-z0-9_-]+)>$/);
|
|
146
|
+
if (openTag) return `#### ${humanizeTag(openTag[1])}`;
|
|
147
|
+
if (/^<\/[A-Za-z0-9_-]+>$/.test(trimmed)) return "";
|
|
148
|
+
return line;
|
|
149
|
+
})
|
|
150
|
+
.join("\n")
|
|
151
|
+
.replace(/\n{3,}/g, "\n\n");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function renderMarkdown(text: string, width: number, theme: Theme, colorKey: ThemeFg = "text", paddingX = 1): string[] {
|
|
155
|
+
const normalized = normalizeMarkdownText(text).trim();
|
|
156
|
+
if (!normalized) return [];
|
|
157
|
+
const renderer = new Markdown(normalized, paddingX, 0, markdownTheme(theme), { color: (value) => theme.fg(colorKey, value) });
|
|
158
|
+
return renderer.render(Math.max(1, width));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function pushSpacer(lines: string[]): void {
|
|
162
|
+
if (lines.length > 0 && lines[lines.length - 1] !== "") lines.push("");
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function boxed(lines: string[], label: string, body: string, width: number, theme: Theme, bgKey: ThemeBg, textKey: ThemeFg): void {
|
|
166
|
+
pushSpacer(lines);
|
|
167
|
+
lines.push(theme.bg(bgKey, padToWidth(` ${label} `, width)));
|
|
168
|
+
for (const rendered of renderMarkdown(body, Math.max(1, width - 2), theme, textKey, 1)) {
|
|
169
|
+
lines.push(theme.bg(bgKey, padToWidth(rendered, width)));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function actionCard(lines: string[], title: string, details: string[], width: number, theme: Theme, status: "pending" | "success" | "error" = "pending"): void {
|
|
174
|
+
pushSpacer(lines);
|
|
175
|
+
const bgKey = status === "error" ? "toolErrorBg" : status === "success" ? "toolSuccessBg" : "toolPendingBg";
|
|
176
|
+
const titleKey = status === "error" ? "error" : status === "success" ? "success" : "toolTitle";
|
|
177
|
+
lines.push(theme.bg(bgKey, padToWidth(theme.fg(titleKey, theme.bold(` ${title}`)), width)));
|
|
178
|
+
for (const detail of details.filter(Boolean)) {
|
|
179
|
+
lines.push(theme.bg(bgKey, padToWidth(theme.fg("toolOutput", ` ${detail}`), width)));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function failureDetails(run: DelegationRunView, fallback: string): string[] {
|
|
184
|
+
const details: string[] = [];
|
|
185
|
+
if (run.errorMessage) details.push(`message: ${sanitizeDelegationText(run.errorMessage)}`);
|
|
186
|
+
if (run.stopReason) details.push(`stopReason: ${sanitizeDelegationText(run.stopReason)}`);
|
|
187
|
+
if (run.exitCode !== undefined) details.push(`exitCode: ${run.exitCode}`);
|
|
188
|
+
if (run.stopCondition) details.push(`stopCondition: ${sanitizeDelegationText(run.stopCondition)}`);
|
|
189
|
+
return details.length > 0 ? details : [fallback];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function contentText(content: unknown, options: { includeThinking?: boolean } = {}): string {
|
|
193
|
+
if (typeof content === "string") return sanitizeDelegationText(content);
|
|
194
|
+
if (!Array.isArray(content)) return "";
|
|
195
|
+
const parts: string[] = [];
|
|
196
|
+
for (const part of content) {
|
|
197
|
+
if (!isRecord(part) || typeof part.type !== "string") continue;
|
|
198
|
+
if (part.type === "text" && typeof part.text === "string") parts.push(sanitizeDelegationText(part.text));
|
|
199
|
+
else if (part.type === "thinking" && options.includeThinking && typeof part.thinking === "string") parts.push(sanitizeDelegationText(part.thinking));
|
|
200
|
+
else if (part.type === "image") parts.push("[image]");
|
|
201
|
+
}
|
|
202
|
+
return parts.join("\n");
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function summarizeValue(value: unknown): string {
|
|
206
|
+
if (typeof value === "string") {
|
|
207
|
+
const safeValue = sanitizeDelegationText(value);
|
|
208
|
+
const compact = safeValue.replace(/\s+/g, " ").trim();
|
|
209
|
+
if (!compact) return "empty string";
|
|
210
|
+
if (safeValue.includes("\n")) return `${safeValue.split("\n").length} lines · ${safeValue.length} chars`;
|
|
211
|
+
return compact.length <= 90 ? compact : `${compact.slice(0, 87)}…`;
|
|
212
|
+
}
|
|
213
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
214
|
+
if (Array.isArray(value)) return `${value.length} item${value.length === 1 ? "" : "s"}`;
|
|
215
|
+
if (isRecord(value)) return `object(${Object.keys(value).slice(0, 5).join(", ") || "empty"})`;
|
|
216
|
+
if (value === null || value === undefined) return "empty";
|
|
217
|
+
return String(value);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function toolArguments(part: Record<string, unknown>): Record<string, unknown> {
|
|
221
|
+
const direct = part.arguments ?? part.args ?? part.input;
|
|
222
|
+
return isRecord(direct) ? direct : {};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function toolName(part: Record<string, unknown>): string {
|
|
226
|
+
return typeof part.name === "string" ? part.name : typeof part.toolName === "string" ? part.toolName : "tool";
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function toolDetails(name: string, args: Record<string, unknown>): string[] {
|
|
230
|
+
const lower = name.toLowerCase();
|
|
231
|
+
const path = typeof args.path === "string" ? args.path : typeof args.file === "string" ? args.file : undefined;
|
|
232
|
+
if (lower === "read") return [path ? `file: ${path}` : "read file"];
|
|
233
|
+
if (lower === "write") {
|
|
234
|
+
const content = typeof args.content === "string" ? args.content : undefined;
|
|
235
|
+
return [path ? `file: ${path}` : "write file", content ? `content: ${content.split("\n").length} lines · ${content.length} chars` : undefined].filter((value): value is string => Boolean(value));
|
|
236
|
+
}
|
|
237
|
+
if (lower === "edit") {
|
|
238
|
+
const edits = Array.isArray(args.edits) ? args.edits.length : undefined;
|
|
239
|
+
return [path ? `file: ${path}` : "edit file", edits !== undefined ? `replacements: ${edits}` : undefined].filter((value): value is string => Boolean(value));
|
|
240
|
+
}
|
|
241
|
+
if (lower === "bash") {
|
|
242
|
+
const command = typeof args.command === "string" ? args.command : undefined;
|
|
243
|
+
return command ? [`$ ${command}`] : ["run shell command"];
|
|
244
|
+
}
|
|
245
|
+
if (lower === "delegate_agent") {
|
|
246
|
+
if (Array.isArray(args.tasks)) return [`parallel delegates: ${args.tasks.length}`];
|
|
247
|
+
if (Array.isArray(args.chain)) return [`chain delegates: ${args.chain.length}`];
|
|
248
|
+
return [typeof args.agent === "string" ? `agent: ${args.agent}` : "delegate agent"];
|
|
249
|
+
}
|
|
250
|
+
if (lower === "delegate_task") return [typeof args.agent === "string" ? `agent: ${args.agent}` : "delegate task"];
|
|
251
|
+
if (lower === "factory_run") return [`factory: ${summarizeValue(args.factory)}`, `mode: ${summarizeValue(args.mode)}`];
|
|
252
|
+
if (lower === "orchestrate_run") return [`goal: ${summarizeValue(args.goal)}`];
|
|
253
|
+
return Object.entries(args).slice(0, 6).map(([key, value]) => `${key}: ${summarizeValue(value)}`);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function renderToolCall(part: Record<string, unknown>, lines: string[], width: number, theme: Theme): void {
|
|
257
|
+
const name = toolName(part);
|
|
258
|
+
actionCard(lines, `◉ ${name}`, toolDetails(name, toolArguments(part)), width, theme, "pending");
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function renderToolResult(message: Record<string, unknown>, lines: string[], width: number, theme: Theme): void {
|
|
262
|
+
const name = typeof message.toolName === "string" ? message.toolName : "tool";
|
|
263
|
+
const isError = message.isError === true;
|
|
264
|
+
const text = contentText(message.content);
|
|
265
|
+
actionCard(lines, `${isError ? "✗" : "✓"} ${name}`, text ? [] : ["completed"], width, theme, isError ? "error" : "success");
|
|
266
|
+
if (text.trim()) lines.push(...renderMarkdown(text, width, theme, isError ? "error" : "toolOutput", 1));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function renderAssistantContent(message: Record<string, unknown>, lines: string[], width: number, theme: Theme): void {
|
|
270
|
+
const content = message.content;
|
|
271
|
+
if (typeof content === "string") {
|
|
272
|
+
pushSpacer(lines);
|
|
273
|
+
lines.push(...renderMarkdown(content, width, theme, "text", 1));
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
if (!Array.isArray(content)) return;
|
|
277
|
+
for (const part of content) {
|
|
278
|
+
if (!isRecord(part) || typeof part.type !== "string") continue;
|
|
279
|
+
if (part.type === "text" && typeof part.text === "string" && part.text.trim()) {
|
|
280
|
+
pushSpacer(lines);
|
|
281
|
+
lines.push(...renderMarkdown(part.text, width, theme, "text", 1));
|
|
282
|
+
} else if (part.type === "thinking" && typeof part.thinking === "string" && part.thinking.trim()) {
|
|
283
|
+
pushSpacer(lines);
|
|
284
|
+
for (const rendered of renderMarkdown(part.thinking, width, theme, "thinkingText", 1)) lines.push(theme.italic(rendered));
|
|
285
|
+
} else if (part.type === "toolCall") {
|
|
286
|
+
renderToolCall(part, lines, width, theme);
|
|
287
|
+
} else if (part.type === "image") {
|
|
288
|
+
actionCard(lines, "□ image", ["image content captured in child session"], width, theme, "pending");
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function renderBashExecution(message: Record<string, unknown>, lines: string[], width: number, theme: Theme): void {
|
|
294
|
+
const command = typeof message.command === "string" ? sanitizeDelegationText(message.command) : "bash";
|
|
295
|
+
const output = typeof message.output === "string" ? sanitizeDelegationText(message.output) : "";
|
|
296
|
+
const cancelled = message.cancelled === true;
|
|
297
|
+
const exitCode = typeof message.exitCode === "number" ? message.exitCode : undefined;
|
|
298
|
+
const status = cancelled || (exitCode !== undefined && exitCode !== 0) ? "error" : "success";
|
|
299
|
+
actionCard(lines, `$ ${command}`, [cancelled ? "cancelled" : exitCode !== undefined ? `exit ${exitCode}` : "running"], width, theme, status);
|
|
300
|
+
if (output.trim()) lines.push(...renderMarkdown(`\`\`\`text\n${capText(output, 12_000)}\n\`\`\``, width, theme, "toolOutput", 1));
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function renderMessageEntry(message: Record<string, unknown>, lines: string[], width: number, theme: Theme): void {
|
|
304
|
+
const role = typeof message.role === "string" ? message.role : "message";
|
|
305
|
+
if (role === "user") boxed(lines, "You / task", contentText(message.content), width, theme, "userMessageBg", "userMessageText");
|
|
306
|
+
else if (role === "assistant") renderAssistantContent(message, lines, width, theme);
|
|
307
|
+
else if (role === "toolResult") renderToolResult(message, lines, width, theme);
|
|
308
|
+
else if (role === "bashExecution") renderBashExecution(message, lines, width, theme);
|
|
309
|
+
else if (role === "custom") boxed(lines, typeof message.customType === "string" ? message.customType : "custom", contentText(message.content), width, theme, "customMessageBg", "customMessageText");
|
|
310
|
+
else if (role === "branchSummary" && typeof message.summary === "string") boxed(lines, "Branch summary", message.summary, width, theme, "customMessageBg", "customMessageText");
|
|
311
|
+
else if (role === "compactionSummary" && typeof message.summary === "string") boxed(lines, "Compaction", message.summary, width, theme, "customMessageBg", "customMessageText");
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function renderSessionEntry(entry: Record<string, unknown>, lines: string[], width: number, theme: Theme): void {
|
|
315
|
+
if (entry.type === "session") {
|
|
316
|
+
const cwd = typeof entry.cwd === "string" ? entry.cwd : "unknown cwd";
|
|
317
|
+
lines.push(theme.fg("dim", `session · ${cwd}`));
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (entry.type === "message" && isRecord(entry.message)) {
|
|
321
|
+
renderMessageEntry(entry.message, lines, width, theme);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (entry.type === "custom" && typeof entry.customType === "string") {
|
|
325
|
+
if (entry.customType === "zob-transcript-truncated" && isRecord(entry.data) && typeof entry.data.omittedBytes === "number") {
|
|
326
|
+
actionCard(lines, "… transcript capped", [`${entry.data.omittedBytes} bytes omitted`], width, theme, "pending");
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
actionCard(lines, `custom · ${entry.customType}`, isRecord(entry.data) ? Object.entries(entry.data).slice(0, 5).map(([key, value]) => `${key}: ${summarizeValue(value)}`) : [], width, theme, "pending");
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if (entry.type === "custom_message") {
|
|
333
|
+
const label = typeof entry.customType === "string" ? entry.customType : "custom message";
|
|
334
|
+
boxed(lines, label, contentText(entry.content), width, theme, "customMessageBg", "customMessageText");
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (entry.type === "model_change") {
|
|
338
|
+
const provider = typeof entry.provider === "string" ? entry.provider : "";
|
|
339
|
+
const model = typeof entry.modelId === "string" ? entry.modelId : "";
|
|
340
|
+
lines.push(theme.fg("muted", `model · ${provider}/${model}`.replace(/\/$/, "")));
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (entry.type === "thinking_level_change" && typeof entry.thinkingLevel === "string") {
|
|
344
|
+
lines.push(theme.fg("muted", `thinking · ${entry.thinkingLevel}`));
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
if ((entry.type === "compaction" || entry.type === "branch_summary") && typeof entry.summary === "string") {
|
|
348
|
+
boxed(lines, entry.type === "compaction" ? "Compaction" : "Branch summary", entry.summary, width, theme, "customMessageBg", "customMessageText");
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function sessionContainsPreview(sessionText: string | undefined, preview: string): boolean {
|
|
353
|
+
const trimmed = preview.trim();
|
|
354
|
+
if (!sessionText || trimmed.length < 40) return false;
|
|
355
|
+
return sessionText.includes(trimmed.slice(-Math.min(300, trimmed.length)));
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function capLines(lines: string[]): string[] {
|
|
359
|
+
if (lines.length <= FEED_MAX_LINES) return lines;
|
|
360
|
+
const head = Math.floor(FEED_MAX_LINES * 0.45);
|
|
361
|
+
const tail = Math.max(0, FEED_MAX_LINES - head - 2);
|
|
362
|
+
return [...lines.slice(0, head), "", `[… ${lines.length - FEED_MAX_LINES} rendered feed lines omitted …]`, "", ...lines.slice(-tail)];
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export function renderDelegationFeedLines(run: DelegationRunView | undefined, repoRoot: string, width: number, theme: Theme): string[] {
|
|
366
|
+
if (!run) return [theme.fg("muted", "No delegation selected.")];
|
|
367
|
+
const safeWidth = Math.max(20, width);
|
|
368
|
+
const lines: string[] = [];
|
|
369
|
+
const signalBadge = delegationSignalBadge(run);
|
|
370
|
+
const signalText = formatDelegationSignalBadge(signalBadge);
|
|
371
|
+
const modelLabel = formatDelegationModelLabel(run);
|
|
372
|
+
lines.push(theme.fg("dim", `${statusIcon(run.status)} ${run.agent}${signalText ? ` · ${theme.fg(delegationSignalColor(signalBadge), signalText)}` : ""}${modelLabel ? ` · ${theme.fg("muted", `(${modelLabel})`)}` : ""} · ${run.status}${run.failureKind ? ` · ${run.failureKind}` : ""} · ${formatDuration(delegationDurationMs(run))} · ${formatDelegationCostLabel(run)} · ${formatDelegationContextLabel(run)}`));
|
|
373
|
+
if (run.usage) lines.push(theme.fg("muted", `usage · in ${run.usage.input} · out ${run.usage.output} · cache ${run.usage.cacheRead}/${run.usage.cacheWrite} · context ${run.usage.contextTokens}`));
|
|
374
|
+
if (run.taskPreview) lines.push(theme.fg("muted", `task · ${sanitizeDelegationText(run.taskPreview)}`));
|
|
375
|
+
let renderedFailureSummary = false;
|
|
376
|
+
if (run.failureKind === "preflight" || run.failureKind === "config") {
|
|
377
|
+
renderedFailureSummary = true;
|
|
378
|
+
actionCard(lines, "blocked before child launch", [run.errorMessage ?? "Parent preflight/config blocked dispatch."], safeWidth, theme, "error");
|
|
379
|
+
}
|
|
380
|
+
if (run.failureKind === "output_gate") {
|
|
381
|
+
renderedFailureSummary = true;
|
|
382
|
+
actionCard(lines, "output-contract gate", ["Inspect exact gate errors before relaunching.", ...[...new Set(run.gateErrors ?? [])]], safeWidth, theme, "error");
|
|
383
|
+
}
|
|
384
|
+
if (run.failureKind === "child_runtime") {
|
|
385
|
+
renderedFailureSummary = true;
|
|
386
|
+
actionCard(lines, "child runtime failure", failureDetails(run, "Child process failed before producing a valid result."), safeWidth, theme, "error");
|
|
387
|
+
}
|
|
388
|
+
if (run.failureKind === "aborted" || run.status === "aborted") {
|
|
389
|
+
renderedFailureSummary = true;
|
|
390
|
+
actionCard(lines, "delegation aborted", failureDetails(run, "Delegation was aborted before completion."), safeWidth, theme, "error");
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const session = readSession(run.sessionPath, repoRoot);
|
|
394
|
+
if (session.note) lines.push(theme.fg(session.status === "blocked" ? "error" : "muted", session.note));
|
|
395
|
+
if (session.text) {
|
|
396
|
+
for (const rawLine of session.text.split("\n")) {
|
|
397
|
+
if (!rawLine.trim()) continue;
|
|
398
|
+
try {
|
|
399
|
+
const parsed = JSON.parse(rawLine) as unknown;
|
|
400
|
+
if (isRecord(parsed)) renderSessionEntry(parsed, lines, safeWidth, theme);
|
|
401
|
+
} catch {
|
|
402
|
+
// Ignore malformed partial JSON lines while the child process is actively appending.
|
|
403
|
+
}
|
|
404
|
+
if (lines.length > FEED_MAX_LINES + 100) break;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (run.outputPreview.trim() && (run.status === "running" || !sessionContainsPreview(session.text, run.outputPreview))) {
|
|
409
|
+
boxed(lines, run.status === "running" ? "Assistant live" : "Assistant output", run.outputPreview, safeWidth, theme, "customMessageBg", "customMessageText");
|
|
410
|
+
}
|
|
411
|
+
if (run.stderrPreview.trim()) actionCard(lines, "stderr", capText(run.stderrPreview, 8_000).split("\n").slice(0, 20), safeWidth, theme, "error");
|
|
412
|
+
if (run.errorMessage && !renderedFailureSummary) actionCard(lines, "error", [sanitizeDelegationText(run.errorMessage)], safeWidth, theme, "error");
|
|
413
|
+
if (lines.length <= 2 && !run.outputPreview.trim() && !run.stderrPreview.trim()) lines.push(theme.fg("muted", "Waiting for the child agent feed…"));
|
|
414
|
+
return capLines(lines);
|
|
415
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Markdown, type MarkdownTheme } from "@earendil-works/pi-tui";
|
|
3
|
+
|
|
4
|
+
import { buildDelegationLogLines, type DelegationRunView } from "./delegation-monitor.js";
|
|
5
|
+
|
|
6
|
+
export function sanitizeDelegationText(text: string): string {
|
|
7
|
+
return text
|
|
8
|
+
.replace(/\x1b\][\s\S]*?(?:\x07|\x1b\\)/g, "")
|
|
9
|
+
.replace(/\x1b[PX^_][\s\S]*?\x1b\\/g, "")
|
|
10
|
+
.replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, "")
|
|
11
|
+
.replace(/\x1b[@-Z\\-_]/g, "")
|
|
12
|
+
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, "");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function humanizeTag(value: string): string {
|
|
16
|
+
return value.replace(/[_-]+/g, " ").replace(/\b\w/g, (letter) => letter.toUpperCase());
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function inlineCode(value: string): string {
|
|
20
|
+
return `\`${value.replace(/`/g, "'")}\``;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function formatKeyValue(line: string): string | undefined {
|
|
24
|
+
const match = line.match(/^([A-Za-z][A-Za-z0-9 _/-]{1,40}):\s*(.*)$/);
|
|
25
|
+
if (!match) return undefined;
|
|
26
|
+
const key = match[1].trim();
|
|
27
|
+
const value = match[2].trim();
|
|
28
|
+
if (!value) return `- **${key}:** _empty_`;
|
|
29
|
+
if (/^(session|cwd|path|file)$/i.test(key)) return `- **${key}:** ${inlineCode(value)}`;
|
|
30
|
+
return `- **${key}:** ${value}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function prettifyLogLine(line: string): string | undefined {
|
|
34
|
+
line = sanitizeDelegationText(line);
|
|
35
|
+
const trimmed = line.trim();
|
|
36
|
+
if (!trimmed) return "";
|
|
37
|
+
|
|
38
|
+
const singleTag = trimmed.match(/^<([A-Za-z0-9_-]+)>([\s\S]*)<\/\1>$/);
|
|
39
|
+
if (singleTag) {
|
|
40
|
+
const value = singleTag[2].trim();
|
|
41
|
+
return `- **${humanizeTag(singleTag[1])}:** ${value || "_empty_"}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const openTag = trimmed.match(/^<([A-Za-z0-9_-]+)>$/);
|
|
45
|
+
if (openTag) return `#### ${humanizeTag(openTag[1])}`;
|
|
46
|
+
if (/^<\/[A-Za-z0-9_-]+>$/.test(trimmed)) return undefined;
|
|
47
|
+
|
|
48
|
+
const section = trimmed.match(/^\[([^\]]+)\](?:\s*(.*))?$/);
|
|
49
|
+
if (section) {
|
|
50
|
+
const label = section[1].trim();
|
|
51
|
+
const rest = section[2]?.trim() ?? "";
|
|
52
|
+
if (/^delegation\s+/i.test(label)) return `# ${label.replace(/^delegation\s+/i, "Delegation ")}`;
|
|
53
|
+
if (/^(assistant|user|system)$/i.test(label)) return `### ${humanizeTag(label)}`;
|
|
54
|
+
if (/^tool result:/i.test(label)) return `### Tool result: ${inlineCode(label.replace(/^tool result:\s*/i, ""))}`;
|
|
55
|
+
if (/^custom message:/i.test(label)) return `### Custom message: ${label.replace(/^custom message:\s*/i, "")}`;
|
|
56
|
+
if (/^(task preview|assistant output preview|stderr preview|conversation|session|model|thinking|compaction|branch summary)$/i.test(label)) {
|
|
57
|
+
const title = humanizeTag(label);
|
|
58
|
+
return rest ? `## ${title}\n${rest}` : `## ${title}`;
|
|
59
|
+
}
|
|
60
|
+
return rest ? `### ${humanizeTag(label)}\n${rest}` : `### ${humanizeTag(label)}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return formatKeyValue(trimmed) ?? line;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function buildDelegationMarkdown(run: DelegationRunView | undefined, repoRoot: string): string {
|
|
67
|
+
if (!run) return "_No delegation selected._";
|
|
68
|
+
const raw = buildDelegationLogLines(run, repoRoot);
|
|
69
|
+
const pretty = raw.map((line) => prettifyLogLine(sanitizeDelegationText(line))).filter((line): line is string => line !== undefined);
|
|
70
|
+
return pretty.join("\n").replace(/\n{3,}/g, "\n\n");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function markdownTheme(theme: Theme): MarkdownTheme {
|
|
74
|
+
return {
|
|
75
|
+
heading: (text) => theme.fg("mdHeading", text),
|
|
76
|
+
link: (text) => theme.fg("mdLink", text),
|
|
77
|
+
linkUrl: (text) => theme.fg("mdLinkUrl", text),
|
|
78
|
+
code: (text) => theme.fg("mdCode", text),
|
|
79
|
+
codeBlock: (text) => theme.fg("mdCodeBlock", text),
|
|
80
|
+
codeBlockBorder: (text) => theme.fg("mdCodeBlockBorder", text),
|
|
81
|
+
quote: (text) => theme.fg("mdQuote", text),
|
|
82
|
+
quoteBorder: (text) => theme.fg("mdQuoteBorder", text),
|
|
83
|
+
hr: (text) => theme.fg("mdHr", text),
|
|
84
|
+
listBullet: (text) => theme.fg("mdListBullet", text),
|
|
85
|
+
bold: (text) => theme.bold(text),
|
|
86
|
+
italic: (text) => theme.italic(text),
|
|
87
|
+
strikethrough: (text) => theme.strikethrough(text),
|
|
88
|
+
underline: (text) => theme.underline(text),
|
|
89
|
+
codeBlockIndent: " ",
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function renderDelegationMarkdownLines(run: DelegationRunView | undefined, repoRoot: string, width: number, theme: Theme): string[] {
|
|
94
|
+
const markdown = buildDelegationMarkdown(run, repoRoot);
|
|
95
|
+
const renderer = new Markdown(markdown, 0, 0, markdownTheme(theme), { color: (text) => theme.fg("text", text) });
|
|
96
|
+
return renderer.render(Math.max(1, width));
|
|
97
|
+
}
|