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,516 @@
|
|
|
1
|
+
import type { CompactionResult } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
import { goalTodoCompletionDiagnostics, summarizeGoalTodos } from "../goal-todos.js";
|
|
4
|
+
import { sha256 } from "../utils/hashing.js";
|
|
5
|
+
import type { HarnessRuntimeState } from "./state.js";
|
|
6
|
+
|
|
7
|
+
export const ZOB_COMPACTION_ENTRY_TYPE = "zob-compaction";
|
|
8
|
+
export const ZOB_COMPACTION_SUMMARY_SCHEMA = "zob.compaction-summary.v1";
|
|
9
|
+
export const ZOB_COMPACTION_DETAILS_SCHEMA = "zob.compaction-details.v1";
|
|
10
|
+
export const ZOB_COMPACTION_LEDGER_SCHEMA = "zob.compaction-ledger.v1";
|
|
11
|
+
export const ZOB_COMPACTION_TARGET_TOKENS = 5_000;
|
|
12
|
+
export const ZOB_COMPACTION_HARD_CAP_TOKENS = 8_000;
|
|
13
|
+
const INSTRUCTION_CHAR_LIMIT = ZOB_COMPACTION_HARD_CAP_TOKENS * 4;
|
|
14
|
+
const MAX_REF_COUNT = 24;
|
|
15
|
+
const MAX_TODO_COUNT = 12;
|
|
16
|
+
const MAX_DELEGATION_COUNT = 10;
|
|
17
|
+
const MAX_BLOCKER_COUNT = 8;
|
|
18
|
+
|
|
19
|
+
const CRITICAL_SKILL_REFS = [
|
|
20
|
+
".pi/skills/zob-compaction-policy/SKILL.md",
|
|
21
|
+
".pi/skills/zob-tool-router/SKILL.md",
|
|
22
|
+
".pi/skills/zob-harness/SKILL.md",
|
|
23
|
+
".pi/skills/zob-goal-todo-tree/SKILL.md",
|
|
24
|
+
".pi/skills/zob-delegation-routing/SKILL.md",
|
|
25
|
+
".pi/skills/zob-oracle/SKILL.md",
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const CRITICAL_DOC_REFS = [
|
|
29
|
+
"docs/ZOB_COMPACTION_POLICY.md",
|
|
30
|
+
"@earendil-works/pi-coding-agent/docs/compaction.md",
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
const ZERO_ACCESS_REF_PATTERN = /(^|\/)(\.env(?:\..*)?|[^/]+\.(?:pem|key))$|^~\/\.(?:ssh|aws)(?:\/|$)/i;
|
|
34
|
+
const BODY_LIKE_KEYS = new Set(["task", "prompt", "output", "body", "content", "patch", "diff", "transcript", "rawPrompt", "rawOutput", "rawDiff"]);
|
|
35
|
+
|
|
36
|
+
export interface ZobCompactionFileRefsInput {
|
|
37
|
+
readFiles?: string[];
|
|
38
|
+
modifiedFiles?: string[];
|
|
39
|
+
fileOps?: { read?: Iterable<string>; written?: Iterable<string>; edited?: Iterable<string> };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ZobCompactionInstructionInput extends ZobCompactionFileRefsInput {
|
|
43
|
+
reason?: "manual" | "threshold" | "overflow" | "goal_continuation" | "branch_summary" | "smoke" | string;
|
|
44
|
+
customInstructions?: string;
|
|
45
|
+
additionalCriticalRefs?: string[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface ZobTodoThreadItem {
|
|
49
|
+
id: string;
|
|
50
|
+
path: string;
|
|
51
|
+
title: string;
|
|
52
|
+
status: string;
|
|
53
|
+
owner: string;
|
|
54
|
+
required: boolean;
|
|
55
|
+
priority: string;
|
|
56
|
+
evidenceRefs: string[];
|
|
57
|
+
validationCommands: string[];
|
|
58
|
+
blocker?: string;
|
|
59
|
+
reviewNoShip?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ZobCompactionStateCapsule {
|
|
63
|
+
schema: "zob.compaction-capsule.v1";
|
|
64
|
+
generatedAt: string;
|
|
65
|
+
reason: string;
|
|
66
|
+
activeMode: string;
|
|
67
|
+
originalUserAsk?: string;
|
|
68
|
+
activeGoal?: {
|
|
69
|
+
activeGoal: string;
|
|
70
|
+
expectedOutput: string;
|
|
71
|
+
constraints: string;
|
|
72
|
+
validationEvidence: string;
|
|
73
|
+
};
|
|
74
|
+
runtimeGoal?: {
|
|
75
|
+
goalId: string;
|
|
76
|
+
objective: string;
|
|
77
|
+
status: string;
|
|
78
|
+
oracleStatus: string;
|
|
79
|
+
oracleVerdict?: string;
|
|
80
|
+
oracleNoShip?: boolean;
|
|
81
|
+
completionProposalNoShip?: boolean;
|
|
82
|
+
evidenceRefs: string[];
|
|
83
|
+
validationCommands: string[];
|
|
84
|
+
};
|
|
85
|
+
todoThread?: {
|
|
86
|
+
total: number;
|
|
87
|
+
done: number;
|
|
88
|
+
skipped: number;
|
|
89
|
+
open: number;
|
|
90
|
+
active: number;
|
|
91
|
+
blocked: number;
|
|
92
|
+
delegated: number;
|
|
93
|
+
claimReturned: number;
|
|
94
|
+
completionReady: boolean;
|
|
95
|
+
hardNoShip: boolean;
|
|
96
|
+
reviewNoShip: boolean;
|
|
97
|
+
effectiveNoShip: boolean;
|
|
98
|
+
completionBlockers: string[];
|
|
99
|
+
nextAgent?: string;
|
|
100
|
+
nextUser?: string;
|
|
101
|
+
activeOrOpenTodos: ZobTodoThreadItem[];
|
|
102
|
+
};
|
|
103
|
+
ruleProfile?: {
|
|
104
|
+
profile: string;
|
|
105
|
+
rulePacks: string[];
|
|
106
|
+
requiredValidation: string[];
|
|
107
|
+
oracleRequired: boolean | string;
|
|
108
|
+
noShipConditions: string[];
|
|
109
|
+
};
|
|
110
|
+
delegations: Array<{
|
|
111
|
+
runId: string;
|
|
112
|
+
source: string;
|
|
113
|
+
mode: string;
|
|
114
|
+
agent: string;
|
|
115
|
+
status: string;
|
|
116
|
+
gatePassed?: boolean;
|
|
117
|
+
failureKind?: string;
|
|
118
|
+
stopCondition?: string;
|
|
119
|
+
sessionPath?: string;
|
|
120
|
+
cost?: number;
|
|
121
|
+
contextTokens?: number;
|
|
122
|
+
}>;
|
|
123
|
+
fileRefs: {
|
|
124
|
+
readFiles: string[];
|
|
125
|
+
modifiedFiles: string[];
|
|
126
|
+
};
|
|
127
|
+
criticalRefs: {
|
|
128
|
+
skills: string[];
|
|
129
|
+
docs: string[];
|
|
130
|
+
additional: string[];
|
|
131
|
+
};
|
|
132
|
+
budgets: {
|
|
133
|
+
targetSummaryTokens: number;
|
|
134
|
+
hardCapSummaryTokens: number;
|
|
135
|
+
};
|
|
136
|
+
reloadRules: string[];
|
|
137
|
+
bodyPolicy: string[];
|
|
138
|
+
nextAction: string;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface ZobCompactionDetails {
|
|
142
|
+
schema: typeof ZOB_COMPACTION_DETAILS_SCHEMA;
|
|
143
|
+
summaryHash?: string;
|
|
144
|
+
firstKeptEntryId?: string;
|
|
145
|
+
tokensBefore?: number;
|
|
146
|
+
activeMode: string;
|
|
147
|
+
goalId?: string;
|
|
148
|
+
runtimeGoalStatus?: string;
|
|
149
|
+
todoCounts?: {
|
|
150
|
+
total: number;
|
|
151
|
+
open: number;
|
|
152
|
+
blocked: number;
|
|
153
|
+
delegated: number;
|
|
154
|
+
claimReturned: number;
|
|
155
|
+
};
|
|
156
|
+
noShip?: {
|
|
157
|
+
hardNoShip: boolean;
|
|
158
|
+
reviewNoShip: boolean;
|
|
159
|
+
effectiveNoShip: boolean;
|
|
160
|
+
};
|
|
161
|
+
delegationCounts: {
|
|
162
|
+
total: number;
|
|
163
|
+
running: number;
|
|
164
|
+
failed: number;
|
|
165
|
+
complete: number;
|
|
166
|
+
};
|
|
167
|
+
fileRefs: {
|
|
168
|
+
readFiles: string[];
|
|
169
|
+
modifiedFiles: string[];
|
|
170
|
+
};
|
|
171
|
+
criticalRefs: {
|
|
172
|
+
skills: string[];
|
|
173
|
+
docs: string[];
|
|
174
|
+
};
|
|
175
|
+
policy: {
|
|
176
|
+
targetSummaryTokens: number;
|
|
177
|
+
hardCapSummaryTokens: number;
|
|
178
|
+
refsNotBodies: true;
|
|
179
|
+
sourceOfTruth: string[];
|
|
180
|
+
};
|
|
181
|
+
bodyStored: false;
|
|
182
|
+
promptBodiesStored: false;
|
|
183
|
+
outputBodiesStored: false;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export interface ZobCompactionLedgerEntry extends Omit<ZobCompactionDetails, "schema"> {
|
|
187
|
+
schema: typeof ZOB_COMPACTION_LEDGER_SCHEMA;
|
|
188
|
+
event: "session_compact" | "session_tree";
|
|
189
|
+
fromExtension?: boolean;
|
|
190
|
+
at: string;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function nowIso(): string {
|
|
194
|
+
return new Date().toISOString();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function unique(items: string[]): string[] {
|
|
198
|
+
return [...new Set(items.filter((item) => item.trim().length > 0))];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function safeRef(ref: string): boolean {
|
|
202
|
+
return !ZERO_ACCESS_REF_PATTERN.test(ref.trim());
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function safeRefs(refs: string[], limit = MAX_REF_COUNT): string[] {
|
|
206
|
+
return unique(refs.map((ref) => ref.trim()).filter(safeRef)).slice(0, limit);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function iterableStrings(value: Iterable<string> | undefined): string[] {
|
|
210
|
+
return value ? [...value].filter((item) => typeof item === "string") : [];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function fileRefsFromInput(input: ZobCompactionFileRefsInput): { readFiles: string[]; modifiedFiles: string[] } {
|
|
214
|
+
const modified = safeRefs([
|
|
215
|
+
...(input.modifiedFiles ?? []),
|
|
216
|
+
...iterableStrings(input.fileOps?.written),
|
|
217
|
+
...iterableStrings(input.fileOps?.edited),
|
|
218
|
+
]);
|
|
219
|
+
const modifiedSet = new Set(modified);
|
|
220
|
+
const read = safeRefs([
|
|
221
|
+
...(input.readFiles ?? []),
|
|
222
|
+
...iterableStrings(input.fileOps?.read),
|
|
223
|
+
].filter((ref) => !modifiedSet.has(ref)));
|
|
224
|
+
return { readFiles: read, modifiedFiles: modified };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function truncate(value: string | undefined, limit = 420): string | undefined {
|
|
228
|
+
if (!value) return undefined;
|
|
229
|
+
const normalized = value.replace(/\s+/g, " ").trim();
|
|
230
|
+
return normalized.length <= limit ? normalized : `${normalized.slice(0, limit - 1)}…`;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function capArray(values: string[], limit: number, itemLimit = 220): string[] {
|
|
234
|
+
return values.slice(0, limit).map((value) => truncate(value, itemLimit) ?? "");
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function compactJson(value: unknown): string {
|
|
238
|
+
return JSON.stringify(value, null, 2);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function truncateInstruction(value: string): string {
|
|
242
|
+
if (value.length <= INSTRUCTION_CHAR_LIMIT) return value;
|
|
243
|
+
const keepHead = Math.floor(INSTRUCTION_CHAR_LIMIT * 0.82);
|
|
244
|
+
const keepTail = INSTRUCTION_CHAR_LIMIT - keepHead - 160;
|
|
245
|
+
return `${value.slice(0, keepHead)}\n\n[ZOB_COMPACTION_INSTRUCTIONS_TRUNCATED: keep blockers/no_ship/TODO/next_action; drop resolved detail]\n\n${value.slice(-keepTail)}`;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function todoItemLabel(item: { path: string; title: string; status: string }): string {
|
|
249
|
+
return `${item.path} ${item.title} [${item.status}]`;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export function buildZobCompactionStateCapsule(state: HarnessRuntimeState, input: ZobCompactionInstructionInput = {}): ZobCompactionStateCapsule {
|
|
253
|
+
const goal = state.runtimeGoal;
|
|
254
|
+
const goalId = goal?.goalId;
|
|
255
|
+
const todoState = state.goalTodos;
|
|
256
|
+
const todoSummary = goalId && todoState ? summarizeGoalTodos(todoState, goalId) : undefined;
|
|
257
|
+
const todoDiagnostics = goalId && todoState ? goalTodoCompletionDiagnostics(todoState, goalId) : undefined;
|
|
258
|
+
const goalTodos = goalId && todoState ? todoState.nodes.filter((node) => node.goalId === goalId) : [];
|
|
259
|
+
const activeOrOpenTodos = goalTodos
|
|
260
|
+
.filter((node) => node.status !== "done" && node.status !== "skipped")
|
|
261
|
+
.slice(0, MAX_TODO_COUNT)
|
|
262
|
+
.map((node): ZobTodoThreadItem => ({
|
|
263
|
+
id: node.id,
|
|
264
|
+
path: node.path,
|
|
265
|
+
title: truncate(node.title, 180) ?? node.title,
|
|
266
|
+
status: node.status,
|
|
267
|
+
owner: node.owner,
|
|
268
|
+
required: node.required,
|
|
269
|
+
priority: node.priority,
|
|
270
|
+
evidenceRefs: safeRefs(node.evidenceRefs, 4),
|
|
271
|
+
validationCommands: capArray(node.validationCommands, 4, 160),
|
|
272
|
+
blocker: truncate(node.blocker, 220),
|
|
273
|
+
reviewNoShip: node.reviewNoShip,
|
|
274
|
+
}));
|
|
275
|
+
const nextAgent = todoSummary?.nextAgent ? todoItemLabel(todoSummary.nextAgent) : undefined;
|
|
276
|
+
const nextUser = todoSummary?.nextUser ? todoItemLabel(todoSummary.nextUser) : undefined;
|
|
277
|
+
const delegations = (state.delegations?.runs ?? []).slice(0, MAX_DELEGATION_COUNT).map((run) => ({
|
|
278
|
+
runId: run.id,
|
|
279
|
+
source: run.source,
|
|
280
|
+
mode: run.mode,
|
|
281
|
+
agent: run.agent,
|
|
282
|
+
status: run.status,
|
|
283
|
+
gatePassed: run.gatePassed,
|
|
284
|
+
failureKind: run.failureKind,
|
|
285
|
+
stopCondition: run.stopCondition,
|
|
286
|
+
sessionPath: run.sessionPath && safeRef(run.sessionPath) ? run.sessionPath : undefined,
|
|
287
|
+
cost: run.usage?.cost,
|
|
288
|
+
contextTokens: run.usage?.contextTokens,
|
|
289
|
+
}));
|
|
290
|
+
const rules = state.activeRuleResolution;
|
|
291
|
+
return {
|
|
292
|
+
schema: "zob.compaction-capsule.v1",
|
|
293
|
+
generatedAt: nowIso(),
|
|
294
|
+
reason: input.reason ?? "compaction",
|
|
295
|
+
activeMode: state.activeMode,
|
|
296
|
+
originalUserAsk: truncate(state.activeGoal?.originalUserAsk ?? state.lastUserInputText, 520),
|
|
297
|
+
activeGoal: state.activeGoal
|
|
298
|
+
? {
|
|
299
|
+
activeGoal: truncate(state.activeGoal.activeGoal, 520) ?? "",
|
|
300
|
+
expectedOutput: truncate(state.activeGoal.expectedOutput, 360) ?? "",
|
|
301
|
+
constraints: truncate(state.activeGoal.constraints, 420) ?? "",
|
|
302
|
+
validationEvidence: truncate(state.activeGoal.validationEvidence, 420) ?? "",
|
|
303
|
+
}
|
|
304
|
+
: undefined,
|
|
305
|
+
runtimeGoal: goal
|
|
306
|
+
? {
|
|
307
|
+
goalId: goal.goalId,
|
|
308
|
+
objective: truncate(goal.objective, 620) ?? goal.objective,
|
|
309
|
+
status: goal.status,
|
|
310
|
+
oracleStatus: goal.oracle.status,
|
|
311
|
+
oracleVerdict: goal.oracle.verdict,
|
|
312
|
+
oracleNoShip: goal.oracle.noShip,
|
|
313
|
+
completionProposalNoShip: goal.completionProposal?.noShip,
|
|
314
|
+
evidenceRefs: safeRefs(goal.oracle.evidenceRefs, 8),
|
|
315
|
+
validationCommands: goal.completionProposal ? capArray(goal.completionProposal.validationCommands, 8, 160) : [],
|
|
316
|
+
}
|
|
317
|
+
: undefined,
|
|
318
|
+
todoThread: todoSummary && todoDiagnostics
|
|
319
|
+
? {
|
|
320
|
+
total: todoSummary.total,
|
|
321
|
+
done: todoSummary.done,
|
|
322
|
+
skipped: todoSummary.skipped,
|
|
323
|
+
open: todoSummary.open,
|
|
324
|
+
active: todoSummary.active,
|
|
325
|
+
blocked: todoSummary.blocked,
|
|
326
|
+
delegated: todoSummary.delegated,
|
|
327
|
+
claimReturned: todoSummary.claimReturned,
|
|
328
|
+
completionReady: todoDiagnostics.completionReady,
|
|
329
|
+
hardNoShip: todoDiagnostics.hardNoShip,
|
|
330
|
+
reviewNoShip: todoDiagnostics.reviewNoShip,
|
|
331
|
+
effectiveNoShip: todoDiagnostics.effectiveNoShip,
|
|
332
|
+
completionBlockers: capArray(todoDiagnostics.completionBlockers, MAX_BLOCKER_COUNT, 220),
|
|
333
|
+
nextAgent,
|
|
334
|
+
nextUser,
|
|
335
|
+
activeOrOpenTodos,
|
|
336
|
+
}
|
|
337
|
+
: undefined,
|
|
338
|
+
ruleProfile: rules
|
|
339
|
+
? {
|
|
340
|
+
profile: rules.profile,
|
|
341
|
+
rulePacks: rules.rulePacks,
|
|
342
|
+
requiredValidation: capArray(rules.requiredValidation, 8, 160),
|
|
343
|
+
oracleRequired: rules.oracleRequired,
|
|
344
|
+
noShipConditions: capArray(rules.noShipConditions, 8, 160),
|
|
345
|
+
}
|
|
346
|
+
: undefined,
|
|
347
|
+
delegations,
|
|
348
|
+
fileRefs: fileRefsFromInput(input),
|
|
349
|
+
criticalRefs: {
|
|
350
|
+
skills: safeRefs(CRITICAL_SKILL_REFS),
|
|
351
|
+
docs: safeRefs(CRITICAL_DOC_REFS),
|
|
352
|
+
additional: safeRefs(input.additionalCriticalRefs ?? []),
|
|
353
|
+
},
|
|
354
|
+
budgets: {
|
|
355
|
+
targetSummaryTokens: ZOB_COMPACTION_TARGET_TOKENS,
|
|
356
|
+
hardCapSummaryTokens: ZOB_COMPACTION_HARD_CAP_TOKENS,
|
|
357
|
+
},
|
|
358
|
+
reloadRules: [
|
|
359
|
+
"After compaction, trust persisted ZOB state and cited artifacts over summary prose.",
|
|
360
|
+
"Re-read critical skills/docs/files by path before applying detailed behavior or editing.",
|
|
361
|
+
"Re-check get_goal/get_goal_todos before completion, delegation, or oracle proposal.",
|
|
362
|
+
"Do not treat compacted tool output summaries as validation evidence; use commands/artifact refs.",
|
|
363
|
+
],
|
|
364
|
+
bodyPolicy: [
|
|
365
|
+
"Persist refs, hashes, statuses, counts, goal/TODO ids, and artifact paths only.",
|
|
366
|
+
"Do not persist raw prompt bodies, raw subagent outputs, raw tool outputs, raw diffs, secrets, or credentials in ZOB compaction details/ledgers.",
|
|
367
|
+
"The natural-language compaction summary should avoid verbatim prompt/output dumps and stay under the hard cap.",
|
|
368
|
+
],
|
|
369
|
+
nextAction: nextAgent ?? nextUser ?? "Resume from the latest user ask and verify live goal/TODO/evidence state before claiming completion.",
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export function buildZobCompactionInstructions(state: HarnessRuntimeState, input: ZobCompactionInstructionInput = {}): string {
|
|
374
|
+
const capsule = buildZobCompactionStateCapsule(state, input);
|
|
375
|
+
const custom = input.customInstructions?.trim();
|
|
376
|
+
const lines = [
|
|
377
|
+
"ZOB-AWARE COMPACTION INSTRUCTIONS",
|
|
378
|
+
`- Output a compact ${ZOB_COMPACTION_SUMMARY_SCHEMA} summary, not a continuation answer.`,
|
|
379
|
+
`- Target ${ZOB_COMPACTION_TARGET_TOKENS} tokens; hard cap ${ZOB_COMPACTION_HARD_CAP_TOKENS} tokens.`,
|
|
380
|
+
"- Preserve refs, decisions, state, evidence, blockers/no_ship, and next action; do not paste full skills/prompts/files/outputs.",
|
|
381
|
+
"- Mandatory sections: original_user_ask, active_mode, runtime_goal, todo_thread, work_thread, critical_refs, decisions, files, delegations, evidence, validations, blockers_no_ship, reload_rules, next_action, body_policy.",
|
|
382
|
+
"- Source-of-truth order after compaction: persisted ZOB state > repo files/artifacts > compaction summary > old model memory.",
|
|
383
|
+
"- If shrinking is needed, drop resolved detail first; never drop blockers, no_ship, active TODOs, evidence refs, waits, or next action.",
|
|
384
|
+
custom ? `- Operator/custom compaction focus: ${custom}` : undefined,
|
|
385
|
+
"",
|
|
386
|
+
"Transient ZOB continuity capsule; summarize it, do not store it verbatim:",
|
|
387
|
+
compactJson(capsule),
|
|
388
|
+
].filter((line): line is string => typeof line === "string");
|
|
389
|
+
return truncateInstruction(lines.join("\n"));
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function delegationCounts(state: HarnessRuntimeState): ZobCompactionDetails["delegationCounts"] {
|
|
393
|
+
return {
|
|
394
|
+
total: state.delegations.runs.length,
|
|
395
|
+
running: state.delegations.runs.filter((run) => run.status === "running" || run.status === "queued").length,
|
|
396
|
+
failed: state.delegations.runs.filter((run) => run.status === "failed" || run.status === "preflight_failed" || run.status === "aborted").length,
|
|
397
|
+
complete: state.delegations.runs.filter((run) => run.status === "complete").length,
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export function buildZobCompactionDetails(state: HarnessRuntimeState, input: ZobCompactionFileRefsInput & { summary?: string; firstKeptEntryId?: string; tokensBefore?: number } = {}): ZobCompactionDetails {
|
|
402
|
+
const goal = state.runtimeGoal;
|
|
403
|
+
const goalId = goal?.goalId;
|
|
404
|
+
const todoSummary = goalId ? summarizeGoalTodos(state.goalTodos, goalId) : undefined;
|
|
405
|
+
const todoDiagnostics = goalId ? goalTodoCompletionDiagnostics(state.goalTodos, goalId) : undefined;
|
|
406
|
+
return {
|
|
407
|
+
schema: ZOB_COMPACTION_DETAILS_SCHEMA,
|
|
408
|
+
summaryHash: input.summary ? sha256(input.summary) : undefined,
|
|
409
|
+
firstKeptEntryId: input.firstKeptEntryId,
|
|
410
|
+
tokensBefore: input.tokensBefore,
|
|
411
|
+
activeMode: state.activeMode,
|
|
412
|
+
goalId,
|
|
413
|
+
runtimeGoalStatus: goal?.status,
|
|
414
|
+
todoCounts: todoSummary
|
|
415
|
+
? {
|
|
416
|
+
total: todoSummary.total,
|
|
417
|
+
open: todoSummary.open,
|
|
418
|
+
blocked: todoSummary.blocked,
|
|
419
|
+
delegated: todoSummary.delegated,
|
|
420
|
+
claimReturned: todoSummary.claimReturned,
|
|
421
|
+
}
|
|
422
|
+
: undefined,
|
|
423
|
+
noShip: todoDiagnostics
|
|
424
|
+
? {
|
|
425
|
+
hardNoShip: todoDiagnostics.hardNoShip,
|
|
426
|
+
reviewNoShip: todoDiagnostics.reviewNoShip,
|
|
427
|
+
effectiveNoShip: todoDiagnostics.effectiveNoShip,
|
|
428
|
+
}
|
|
429
|
+
: undefined,
|
|
430
|
+
delegationCounts: delegationCounts(state),
|
|
431
|
+
fileRefs: fileRefsFromInput(input),
|
|
432
|
+
criticalRefs: {
|
|
433
|
+
skills: safeRefs(CRITICAL_SKILL_REFS),
|
|
434
|
+
docs: safeRefs(CRITICAL_DOC_REFS),
|
|
435
|
+
},
|
|
436
|
+
policy: {
|
|
437
|
+
targetSummaryTokens: ZOB_COMPACTION_TARGET_TOKENS,
|
|
438
|
+
hardCapSummaryTokens: ZOB_COMPACTION_HARD_CAP_TOKENS,
|
|
439
|
+
refsNotBodies: true,
|
|
440
|
+
sourceOfTruth: ["persisted_zob_state", "repo_files_and_artifacts", "compaction_summary", "old_model_memory"],
|
|
441
|
+
},
|
|
442
|
+
bodyStored: false,
|
|
443
|
+
promptBodiesStored: false,
|
|
444
|
+
outputBodiesStored: false,
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
export function buildZobCompactionLedgerEntry(state: HarnessRuntimeState, input: ZobCompactionFileRefsInput & { event: "session_compact" | "session_tree"; summary?: string; firstKeptEntryId?: string; tokensBefore?: number; fromExtension?: boolean }): ZobCompactionLedgerEntry {
|
|
449
|
+
return {
|
|
450
|
+
...buildZobCompactionDetails(state, input),
|
|
451
|
+
schema: ZOB_COMPACTION_LEDGER_SCHEMA,
|
|
452
|
+
event: input.event,
|
|
453
|
+
fromExtension: input.fromExtension,
|
|
454
|
+
at: nowIso(),
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
export function buildDeterministicZobCompactionSummary(state: HarnessRuntimeState, input: ZobCompactionInstructionInput = {}): string {
|
|
459
|
+
const capsule = buildZobCompactionStateCapsule(state, input);
|
|
460
|
+
const lines = [
|
|
461
|
+
`## schema\n${ZOB_COMPACTION_SUMMARY_SCHEMA}`,
|
|
462
|
+
`## original_user_ask\n${capsule.originalUserAsk ?? "unknown; inspect current user ask and persisted goal state"}`,
|
|
463
|
+
`## active_mode\n${capsule.activeMode}`,
|
|
464
|
+
`## runtime_goal\n${capsule.runtimeGoal ? compactJson(capsule.runtimeGoal) : "none"}`,
|
|
465
|
+
`## todo_thread\n${capsule.todoThread ? compactJson(capsule.todoThread) : "none"}`,
|
|
466
|
+
`## work_thread\nCurrent continuation reason: ${capsule.reason}. Next action: ${capsule.nextAction}`,
|
|
467
|
+
`## critical_refs\n${compactJson(capsule.criticalRefs)}`,
|
|
468
|
+
`## decisions\n- Preserve refs/state/evidence/blockers/next action instead of full bodies.\n- Trust persisted ZOB state and cited artifacts over compacted memory.`,
|
|
469
|
+
`## files\n${compactJson(capsule.fileRefs)}`,
|
|
470
|
+
`## delegations\n${compactJson(capsule.delegations)}`,
|
|
471
|
+
`## evidence\nRuntime evidence refs and validation commands are in runtime_goal/todo_thread; re-read artifacts before completion.`,
|
|
472
|
+
`## validations\n${capsule.ruleProfile ? compactJson(capsule.ruleProfile.requiredValidation) : "Re-run required validation from rule profile before completion."}`,
|
|
473
|
+
`## blockers_no_ship\n${capsule.todoThread ? compactJson({ hardNoShip: capsule.todoThread.hardNoShip, reviewNoShip: capsule.todoThread.reviewNoShip, effectiveNoShip: capsule.todoThread.effectiveNoShip, completionBlockers: capsule.todoThread.completionBlockers }) : "unknown; inspect get_goal/get_goal_todos before completion"}`,
|
|
474
|
+
`## reload_rules\n${capsule.reloadRules.map((rule) => `- ${rule}`).join("\n")}`,
|
|
475
|
+
`## next_action\n${capsule.nextAction}`,
|
|
476
|
+
`## body_policy\n${capsule.bodyPolicy.map((rule) => `- ${rule}`).join("\n")}`,
|
|
477
|
+
];
|
|
478
|
+
return truncateInstruction(lines.join("\n\n"));
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export function buildDeterministicZobCompactionResult(state: HarnessRuntimeState, preparation: { firstKeptEntryId: string; tokensBefore: number }, input: ZobCompactionInstructionInput = {}): CompactionResult<ZobCompactionDetails> {
|
|
482
|
+
const summary = buildDeterministicZobCompactionSummary(state, input);
|
|
483
|
+
return {
|
|
484
|
+
summary,
|
|
485
|
+
firstKeptEntryId: preparation.firstKeptEntryId,
|
|
486
|
+
tokensBefore: preparation.tokensBefore,
|
|
487
|
+
details: buildZobCompactionDetails(state, {
|
|
488
|
+
...input,
|
|
489
|
+
summary,
|
|
490
|
+
firstKeptEntryId: preparation.firstKeptEntryId,
|
|
491
|
+
tokensBefore: preparation.tokensBefore,
|
|
492
|
+
}),
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
export function withZobCompactionDetails<T>(state: HarnessRuntimeState, result: CompactionResult<T>, input: ZobCompactionFileRefsInput = {}): CompactionResult<ZobCompactionDetails> {
|
|
497
|
+
return {
|
|
498
|
+
...result,
|
|
499
|
+
details: buildZobCompactionDetails(state, {
|
|
500
|
+
...input,
|
|
501
|
+
summary: result.summary,
|
|
502
|
+
firstKeptEntryId: result.firstKeptEntryId,
|
|
503
|
+
tokensBefore: result.tokensBefore,
|
|
504
|
+
}),
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
export function zobCompactionBodyFreeViolations(value: unknown, path = "root"): string[] {
|
|
509
|
+
if (!value || typeof value !== "object") return [];
|
|
510
|
+
if (Array.isArray(value)) return value.flatMap((item, index) => zobCompactionBodyFreeViolations(item, `${path}[${index}]`));
|
|
511
|
+
return Object.entries(value as Record<string, unknown>).flatMap(([key, child]) => {
|
|
512
|
+
const current = `${path}.${key}`;
|
|
513
|
+
const self = BODY_LIKE_KEYS.has(key) ? [current] : [];
|
|
514
|
+
return [...self, ...zobCompactionBodyFreeViolations(child, current)];
|
|
515
|
+
});
|
|
516
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
2
|
+
|
|
3
|
+
const DELEGATE_VIEW_MARKER_PREFIX = "\x1b_zob-delegate:";
|
|
4
|
+
const DELEGATE_SELECT_MARKER_PREFIX = "\x1b_zob-delegate-select:";
|
|
5
|
+
const DELEGATE_CLOSE_MARKER = "\x1b_zob-delegate-close:\x07";
|
|
6
|
+
const VIEW_LABEL = "[view]";
|
|
7
|
+
const CLOSE_LABEL = "[close]";
|
|
8
|
+
|
|
9
|
+
export type DelegationClickAction = { kind: "view" | "select"; runId: string; agent?: string; status?: "queued" | "running" | "complete" | "failed" | "preflight_failed" | "aborted" } | { kind: "close" };
|
|
10
|
+
|
|
11
|
+
export function delegateViewLink(runId: string, label = VIEW_LABEL): string {
|
|
12
|
+
const safeRunId = sanitizeRunId(runId);
|
|
13
|
+
return `${label}${DELEGATE_VIEW_MARKER_PREFIX}${safeRunId}\x07`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function delegateSelectMarker(runId: string): string {
|
|
17
|
+
const safeRunId = sanitizeRunId(runId);
|
|
18
|
+
return `${DELEGATE_SELECT_MARKER_PREFIX}${safeRunId}\x07`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function delegateCloseButton(label = CLOSE_LABEL): string {
|
|
22
|
+
return `${label}${DELEGATE_CLOSE_MARKER}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function findDelegateRunIdAtColumn(line: string, column: number): string | undefined {
|
|
26
|
+
const action = findDelegateActionAtColumn(line, column);
|
|
27
|
+
return action?.kind === "view" ? action.runId : undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function findDelegateActionAtColumn(line: string, column: number, options: { wholeRowFallback?: boolean } = { wholeRowFallback: false }): DelegationClickAction | undefined {
|
|
31
|
+
let visibleColumn = 1;
|
|
32
|
+
let visibleText = "";
|
|
33
|
+
let pendingViewSpan: { start: number; end: number } | undefined;
|
|
34
|
+
let pendingCloseSpan: { start: number; end: number } | undefined;
|
|
35
|
+
for (let index = 0; index < line.length;) {
|
|
36
|
+
if (line.startsWith(DELEGATE_VIEW_MARKER_PREFIX, index)) {
|
|
37
|
+
const markerStart = index + DELEGATE_VIEW_MARKER_PREFIX.length;
|
|
38
|
+
const terminator = findEscapeTerminator(line, markerStart);
|
|
39
|
+
if (!terminator) break;
|
|
40
|
+
const runId = line.slice(markerStart, terminator.end) || undefined;
|
|
41
|
+
if (runId && pendingViewSpan && column >= pendingViewSpan.start && column < pendingViewSpan.end) return { kind: "view", runId };
|
|
42
|
+
pendingViewSpan = undefined;
|
|
43
|
+
index = terminator.end + terminator.length;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (line.startsWith(DELEGATE_SELECT_MARKER_PREFIX, index)) {
|
|
47
|
+
const markerStart = index + DELEGATE_SELECT_MARKER_PREFIX.length;
|
|
48
|
+
const terminator = findEscapeTerminator(line, markerStart);
|
|
49
|
+
if (!terminator) break;
|
|
50
|
+
const runId = line.slice(markerStart, terminator.end) || undefined;
|
|
51
|
+
if (runId && column >= 2 && column < visibleColumn) return { kind: "select", runId };
|
|
52
|
+
index = terminator.end + terminator.length;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (line.startsWith(DELEGATE_CLOSE_MARKER, index)) {
|
|
56
|
+
if (pendingCloseSpan && column >= pendingCloseSpan.start && column < pendingCloseSpan.end) return { kind: "close" };
|
|
57
|
+
pendingCloseSpan = undefined;
|
|
58
|
+
index += DELEGATE_CLOSE_MARKER.length;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (line[index] === "\x1b") {
|
|
62
|
+
index = skipAnsiEscape(line, index);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (line.startsWith(VIEW_LABEL, index)) {
|
|
66
|
+
const start = visibleColumn;
|
|
67
|
+
const width = visibleWidth(VIEW_LABEL);
|
|
68
|
+
pendingViewSpan = { start, end: start + width };
|
|
69
|
+
visibleText += VIEW_LABEL;
|
|
70
|
+
visibleColumn += width;
|
|
71
|
+
index += VIEW_LABEL.length;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (line.startsWith(CLOSE_LABEL, index)) {
|
|
75
|
+
const start = visibleColumn;
|
|
76
|
+
const width = visibleWidth(CLOSE_LABEL);
|
|
77
|
+
pendingCloseSpan = { start, end: start + width };
|
|
78
|
+
visibleText += CLOSE_LABEL;
|
|
79
|
+
visibleColumn += width;
|
|
80
|
+
index += CLOSE_LABEL.length;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const codePoint = line.codePointAt(index);
|
|
84
|
+
if (codePoint === undefined) break;
|
|
85
|
+
const char = String.fromCodePoint(codePoint);
|
|
86
|
+
visibleText += char;
|
|
87
|
+
visibleColumn += Math.max(visibleWidth(char), 0);
|
|
88
|
+
index += char.length;
|
|
89
|
+
}
|
|
90
|
+
const fallback = findVisibleRunBeforeView(visibleText);
|
|
91
|
+
if (fallback && pendingViewSpan && column >= pendingViewSpan.start && column < pendingViewSpan.end) return { kind: "view", ...fallback };
|
|
92
|
+
if (options.wholeRowFallback === true && fallback && visibleText.includes(VIEW_LABEL) && column >= 2 && column < visibleColumn) return { kind: "view", ...fallback };
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function findVisibleRunBeforeView(visibleText: string): { runId: string; agent?: string; status?: "queued" | "running" | "complete" | "failed" | "preflight_failed" | "aborted" } | undefined {
|
|
97
|
+
const viewIndex = visibleText.lastIndexOf(VIEW_LABEL);
|
|
98
|
+
const beforeView = viewIndex >= 0 ? visibleText.slice(0, viewIndex) : visibleText;
|
|
99
|
+
const matches = [...beforeView.matchAll(/\b((?:delegate|task)_[A-Za-z0-9_.:-]+)/g)];
|
|
100
|
+
const match = matches.at(-1);
|
|
101
|
+
const runId = match?.[1] ? sanitizeRunId(match[1]) : undefined;
|
|
102
|
+
if (!runId) return undefined;
|
|
103
|
+
const prefix = beforeView.slice(0, match?.index ?? 0).trimEnd();
|
|
104
|
+
const tokens = prefix.split(/\s+/).filter(Boolean);
|
|
105
|
+
const statusGlyph = [...tokens].reverse().find((token) => ["○", "●", "✓", "✗", "▲", "■"].includes(token));
|
|
106
|
+
const status = statusGlyph === "○" ? "queued" : statusGlyph === "●" ? "running" : statusGlyph === "✓" ? "complete" : statusGlyph === "✗" ? "failed" : statusGlyph === "▲" ? "preflight_failed" : statusGlyph === "■" ? "aborted" : undefined;
|
|
107
|
+
const agent = tokens.at(-1);
|
|
108
|
+
const safeAgent = agent && !["○", "●", "✓", "✗", "▲", "■"].includes(agent) && !agent.includes("─") ? sanitizeRunId(agent) : undefined;
|
|
109
|
+
return { runId, ...(safeAgent ? { agent: safeAgent } : {}), ...(status ? { status } : {}) };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function sanitizeRunId(runId: string): string {
|
|
113
|
+
return runId.replace(/[^A-Za-z0-9_.:-]/g, "");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function findEscapeTerminator(text: string, start: number): { end: number; length: number } | undefined {
|
|
117
|
+
const bel = text.indexOf("\x07", start);
|
|
118
|
+
const st = text.indexOf("\x1b\\", start);
|
|
119
|
+
if (bel === -1 && st === -1) return undefined;
|
|
120
|
+
if (bel !== -1 && (st === -1 || bel < st)) return { end: bel, length: 1 };
|
|
121
|
+
return { end: st, length: 2 };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function skipAnsiEscape(text: string, index: number): number {
|
|
125
|
+
if (text[index] !== "\x1b") return index + 1;
|
|
126
|
+
const next = text[index + 1];
|
|
127
|
+
if (next === "]" || next === "_") {
|
|
128
|
+
const terminator = findEscapeTerminator(text, index + 2);
|
|
129
|
+
return terminator ? terminator.end + terminator.length : text.length;
|
|
130
|
+
}
|
|
131
|
+
if (next === "[") {
|
|
132
|
+
let cursor = index + 2;
|
|
133
|
+
while (cursor < text.length) {
|
|
134
|
+
const code = text.charCodeAt(cursor);
|
|
135
|
+
cursor += 1;
|
|
136
|
+
if (code >= 0x40 && code <= 0x7e) break;
|
|
137
|
+
}
|
|
138
|
+
return cursor;
|
|
139
|
+
}
|
|
140
|
+
return Math.min(text.length, index + 2);
|
|
141
|
+
}
|