@hassangameryt/freeflow 0.7.3 → 0.9.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/.agents/plugins/marketplace.json +2 -2
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +2 -2
- package/.codex-plugin/plugin.json +3 -3
- package/.cursor-plugin/plugin.json +1 -1
- package/NOTICE +14 -0
- package/README.md +101 -159
- package/capabilities/cognitive-routing/SKILL.md +47 -210
- package/capabilities/cognitive-routing/references/coordinator.md +163 -0
- package/capabilities/cognitive-routing/references/worker.md +38 -0
- package/capabilities/compaction/SKILL.md +49 -0
- package/capabilities/compaction/references/summary-format.md +250 -0
- package/capabilities/messaging/SKILL.md +49 -0
- package/capabilities/task-memory/SKILL.md +87 -0
- package/command-surface.json +8 -52
- package/gemini-extension.json +1 -1
- package/hooks/claude/hooks.json +13 -3
- package/hooks/codex/hooks.json +2 -1
- package/hooks/shared/runtime-context.mjs +73 -83
- package/licenses/Apache-2.0.txt +55 -0
- package/package.json +42 -12
- package/pi-extension/README.md +41 -0
- package/pi-extension/dist/ask-user/ask.js +108 -0
- package/pi-extension/dist/ask-user/form.js +250 -0
- package/pi-extension/dist/ask-user/questions.js +66 -0
- package/pi-extension/dist/ask-user/tool.js +124 -0
- package/pi-extension/dist/cognitive-routing/assembler.js +417 -0
- package/pi-extension/dist/cognitive-routing/bootstrap.js +90 -0
- package/pi-extension/dist/{cognitive-routing-v2 → cognitive-routing}/config.js +8 -6
- package/pi-extension/dist/cognitive-routing/economics.js +45 -0
- package/pi-extension/dist/cognitive-routing/event-schema.js +388 -0
- package/pi-extension/dist/{session-sources/events.js → cognitive-routing/event-store.js} +107 -41
- package/pi-extension/dist/cognitive-routing/gate.js +256 -0
- package/pi-extension/dist/cognitive-routing/handlers.js +901 -0
- package/pi-extension/dist/cognitive-routing/handoffs.js +350 -0
- package/pi-extension/dist/cognitive-routing/model-control.js +476 -0
- package/pi-extension/dist/cognitive-routing/projection.js +520 -0
- package/pi-extension/dist/cognitive-routing/provenance.js +83 -0
- package/pi-extension/dist/{cognitive-routing-v2 → cognitive-routing}/render.js +15 -15
- package/pi-extension/dist/cognitive-routing/runtime.js +398 -0
- package/pi-extension/dist/{cognitive-routing-v2 → cognitive-routing}/schemas.js +47 -11
- package/pi-extension/dist/cognitive-routing/session.js +223 -0
- package/pi-extension/dist/{session-sources → cognitive-routing}/sources.js +126 -87
- package/pi-extension/dist/{cognitive-routing-v2 → cognitive-routing}/state.js +55 -386
- package/pi-extension/dist/cognitive-routing/status.js +81 -0
- package/pi-extension/dist/cognitive-routing/tools.js +74 -0
- package/pi-extension/dist/{cognitive-routing-v2 → cognitive-routing}/types.js +14 -11
- package/pi-extension/dist/compaction/carry.js +205 -0
- package/pi-extension/dist/compaction/config.js +24 -0
- package/pi-extension/dist/compaction/controller.js +494 -0
- package/pi-extension/dist/compaction/harness.js +93 -0
- package/pi-extension/dist/compaction/results.js +159 -0
- package/pi-extension/dist/compaction/thresholds.js +35 -0
- package/pi-extension/dist/compaction/tool.js +57 -0
- package/pi-extension/dist/host/branch.js +13 -0
- package/pi-extension/dist/host/canonical.js +12 -0
- package/pi-extension/dist/host/catalog.js +62 -0
- package/pi-extension/dist/host/config-validation.js +233 -0
- package/pi-extension/dist/host/config.js +361 -0
- package/pi-extension/dist/host/inbound.js +142 -0
- package/pi-extension/dist/host/projection-tags.js +60 -0
- package/pi-extension/dist/host/prompts.js +93 -0
- package/pi-extension/dist/{session-sources → host}/read-only-session.js +117 -1
- package/pi-extension/dist/{runtime → host}/request-history.js +125 -39
- package/pi-extension/dist/host/rows.js +25 -0
- package/pi-extension/dist/host/runtime-state.js +204 -0
- package/pi-extension/dist/host/section-keeper.js +85 -0
- package/pi-extension/dist/host/settings/freeflow-command.js +2323 -0
- package/pi-extension/dist/{settings/settings-tui.js → host/settings/settings-view.js} +205 -73
- package/pi-extension/dist/host/staging.js +28 -0
- package/pi-extension/dist/host/status.js +115 -0
- package/pi-extension/dist/index.js +1004 -188
- package/pi-extension/dist/messaging/config.js +27 -0
- package/pi-extension/dist/messaging/messaging.js +398 -0
- package/pi-extension/dist/messaging/registry.js +57 -0
- package/pi-extension/dist/messaging/render.js +90 -0
- package/pi-extension/dist/messaging/tools.js +109 -0
- package/pi-extension/dist/messaging/transport.js +101 -0
- package/pi-extension/dist/provider-support/cache/anchor.js +21 -0
- package/pi-extension/dist/provider-support/cache/anthropic.js +102 -0
- package/pi-extension/dist/provider-support/cache/health.js +73 -0
- package/pi-extension/dist/provider-support/cache/index.js +58 -0
- package/pi-extension/dist/provider-support/cache/keepalive.js +222 -0
- package/pi-extension/dist/provider-support/cache/monitor.js +17 -0
- package/pi-extension/dist/provider-support/cache/openai-responses.js +48 -0
- package/pi-extension/dist/provider-support/effort.js +13 -0
- package/pi-extension/dist/provider-support/index.js +44 -3
- package/pi-extension/dist/provider-support/{astra → openai}/adapter.js +46 -29
- package/pi-extension/dist/provider-support/{astra → openai}/history.js +10 -8
- package/pi-extension/dist/provider-support/{astra → openai}/index.js +8 -4
- package/pi-extension/dist/provider-support/{astra → openai}/session-state.js +29 -38
- package/pi-extension/dist/provider-support/routes.js +17 -0
- package/pi-extension/dist/task-memory/config.js +49 -0
- package/pi-extension/dist/task-memory/registry.js +119 -0
- package/pi-extension/dist/task-memory/render.js +107 -0
- package/pi-extension/dist/task-memory/runtime.js +994 -0
- package/pi-extension/dist/task-memory/tool.js +233 -0
- package/pi-extension/dist/tool-execution/apply-patch/grammar.js +23 -0
- package/pi-extension/dist/tool-execution/apply-patch/match.js +38 -0
- package/pi-extension/dist/tool-execution/apply-patch/parser.js +177 -0
- package/pi-extension/dist/tool-execution/apply-patch/plan.js +201 -0
- package/pi-extension/dist/tool-execution/apply-patch/tool.js +84 -0
- package/pi-extension/dist/tool-execution/background.js +430 -0
- package/pi-extension/dist/tool-execution/bash-guard.js +23 -0
- package/pi-extension/dist/tool-execution/config.js +33 -0
- package/pi-extension/dist/tool-execution/edit-messages.js +120 -0
- package/pi-extension/dist/tool-execution/file-state.js +138 -0
- package/pi-extension/dist/tool-execution/file-tracking.js +163 -0
- package/pi-extension/dist/tool-execution/guidance-notices.js +124 -0
- package/pi-extension/dist/tool-execution/prompt.js +54 -0
- package/pi-extension/dist/tool-execution/skill-reads.js +143 -0
- package/pi-extension/dist/tool-execution/tools.js +16 -0
- package/pi-extension/freeflow/README.md +9 -0
- package/runtime/prompts/cognitive-routing.md +4 -4
- package/runtime/prompts/core.md +29 -72
- package/runtime/prompts/interaction-contract.md +18 -8
- package/runtime/prompts/tool-execution.md +25 -0
- package/runtime/prompts/working-method.md +25 -0
- package/skills/deliver-work/SKILL.md +76 -0
- package/skills/deliver-work/references/branch-closeout.md +134 -0
- package/skills/deliver-work/references/commit.md +83 -0
- package/skills/deliver-work/references/launch.md +94 -0
- package/skills/deliver-work/references/release.md +85 -0
- package/skills/deliver-work/scripts/commit-state.mjs +139 -0
- package/skills/deliver-work/scripts/delivery-state.mjs +107 -0
- package/skills/deliver-work/scripts/lib/git-state.mjs +178 -0
- package/skills/deliver-work/scripts/push-route.mjs +122 -0
- package/skills/deliver-work/scripts/release-preflight.mjs +177 -0
- package/skills/discuss-work/SKILL.md +148 -0
- package/skills/{discuss → discuss-work}/references/discussion-continuity.md +13 -50
- package/skills/discuss-work/references/learning-action.md +36 -0
- package/skills/discuss-work/scripts/choices.mjs +101 -0
- package/skills/discuss-work/scripts/lib/choices.mjs +159 -0
- package/skills/evaluate-behavior/SKILL.md +107 -0
- package/skills/evaluate-behavior/references/authoring.md +381 -0
- package/skills/evaluate-behavior/references/coding-tasks.md +145 -0
- package/skills/evaluate-behavior/references/conversations-pipelines-judges.md +177 -0
- package/skills/evaluate-behavior/references/design-and-measurement.md +273 -0
- package/skills/evaluate-behavior/references/running-and-evidence.md +245 -0
- package/skills/evaluate-behavior/scripts/claude-guard.mjs +76 -0
- package/skills/evaluate-behavior/scripts/guard-rules.mjs +309 -0
- package/skills/evaluate-behavior/scripts/lib/agreement.mjs +90 -0
- package/skills/evaluate-behavior/scripts/lib/arms.mjs +55 -0
- package/skills/evaluate-behavior/scripts/lib/budget.mjs +87 -0
- package/skills/evaluate-behavior/scripts/lib/build-source.mjs +287 -0
- package/skills/evaluate-behavior/scripts/lib/clear.mjs +74 -0
- package/skills/evaluate-behavior/scripts/lib/container.mjs +395 -0
- package/skills/evaluate-behavior/scripts/lib/decision.mjs +418 -0
- package/skills/evaluate-behavior/scripts/lib/definitions.mjs +1072 -0
- package/skills/evaluate-behavior/scripts/lib/freeflow.mjs +103 -0
- package/skills/evaluate-behavior/scripts/lib/grade-command.mjs +591 -0
- package/skills/evaluate-behavior/scripts/lib/grade-comparison.mjs +90 -0
- package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/grade-interaction.mjs +19 -18
- package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/grade-support.mjs +32 -5
- package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/grade-workspace.mjs +28 -12
- package/skills/evaluate-behavior/scripts/lib/grade.mjs +101 -0
- package/skills/evaluate-behavior/scripts/lib/hooks.mjs +98 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/confinement.mjs +196 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/constraints.mjs +111 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/index.mjs +48 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/isolation.mjs +74 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/launch.mjs +123 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/model-call.mjs +73 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/recorder.mjs +178 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/session.mjs +494 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/claude-code/skills.mjs +81 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/index.mjs +31 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/names.mjs +3 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/pi/confinement.mjs +173 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/pi/host.mjs +148 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/pi/index.mjs +70 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/pi/isolation.mjs +81 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/pi/model-call.mjs +79 -0
- package/skills/evaluate-behavior/scripts/lib/hosts/pi/process.mjs +241 -0
- package/skills/{evaluate-skill/scripts/lib → evaluate-behavior/scripts/lib/hosts/pi}/rpc.mjs +144 -26
- package/skills/evaluate-behavior/scripts/lib/identity.mjs +82 -0
- package/skills/evaluate-behavior/scripts/lib/judge.mjs +688 -0
- package/skills/evaluate-behavior/scripts/lib/metrics.mjs +332 -0
- package/skills/evaluate-behavior/scripts/lib/model-call.mjs +17 -0
- package/skills/evaluate-behavior/scripts/lib/participants.mjs +616 -0
- package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/process.mjs +22 -0
- package/skills/evaluate-behavior/scripts/lib/queue.mjs +54 -0
- package/skills/evaluate-behavior/scripts/lib/reference.mjs +343 -0
- package/skills/evaluate-behavior/scripts/lib/reuse.mjs +277 -0
- package/skills/evaluate-behavior/scripts/lib/review.mjs +933 -0
- package/skills/evaluate-behavior/scripts/lib/runner.mjs +732 -0
- package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/sandbox.mjs +121 -14
- package/skills/evaluate-behavior/scripts/lib/scan-shell.mjs +457 -0
- package/skills/evaluate-behavior/scripts/lib/scan.mjs +479 -0
- package/skills/evaluate-behavior/scripts/lib/seal.mjs +91 -0
- package/skills/evaluate-behavior/scripts/lib/shell.mjs +560 -0
- package/skills/evaluate-behavior/scripts/lib/source-override.mjs +64 -0
- package/skills/evaluate-behavior/scripts/lib/subject-file.mjs +88 -0
- package/skills/{evaluate-skill/scripts/lib/pi.mjs → evaluate-behavior/scripts/lib/subject.mjs} +239 -262
- package/skills/evaluate-behavior/scripts/lib/task-copy.mjs +124 -0
- package/skills/evaluate-behavior/scripts/lib/trials.mjs +524 -0
- package/skills/evaluate-behavior/scripts/lib/validity.mjs +68 -0
- package/skills/evaluate-behavior/scripts/lib/view-html.mjs +454 -0
- package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/view.mjs +218 -11
- package/skills/evaluate-behavior/scripts/pi-command-tool.mjs +159 -0
- package/skills/evaluate-behavior/scripts/pi-container-route.mjs +23 -0
- package/skills/evaluate-behavior/scripts/pi-guard.mjs +77 -0
- package/skills/evaluate-behavior/scripts/pi-login-refresh.mjs +31 -0
- package/skills/evaluate-behavior/scripts/skill-eval.mjs +586 -0
- package/skills/execute-work/SKILL.md +96 -72
- package/skills/execute-work/references/code-practices.md +27 -49
- package/skills/execute-work/references/design.md +271 -0
- package/skills/execute-work/references/diagnose.md +117 -0
- package/skills/execute-work/references/migration.md +108 -0
- package/skills/execute-work/references/simplify.md +65 -0
- package/skills/execute-work/scripts/self-review.mjs +422 -0
- package/skills/execute-work/scripts/touch-map.mjs +290 -0
- package/skills/review-work/SKILL.md +94 -64
- package/skills/review-work/references/adjudication.md +94 -0
- package/skills/review-work/references/artifact.md +198 -0
- package/skills/review-work/references/evals-and-judges.md +66 -0
- package/skills/review-work/references/work.md +177 -0
- package/skills/review-work/scripts/check-brief.mjs +128 -0
- package/skills/review-work/scripts/review-packet.mjs +233 -0
- package/skills/setup-freeflow/SKILL.md +69 -16
- package/skills/track-work/SKILL.md +135 -151
- package/skills/track-work/references/handoff.md +190 -0
- package/skills/track-work/references/projects.md +51 -0
- package/skills/track-work/references/working-record-format.md +201 -344
- package/skills/track-work/scripts/lib/document.mjs +79 -19
- package/skills/track-work/scripts/lib/format.mjs +18 -1
- package/skills/track-work/scripts/lib/recover.mjs +254 -0
- package/skills/track-work/scripts/lib/registry.mjs +656 -0
- package/skills/track-work/scripts/lib/search.mjs +40 -0
- package/skills/track-work/scripts/lib/store.mjs +53 -21
- package/skills/track-work/scripts/lib/transitions.mjs +79 -4
- package/skills/track-work/scripts/lib/views.mjs +50 -1
- package/skills/track-work/scripts/working-record.mjs +263 -22
- package/skills/verify-work/SKILL.md +64 -47
- package/skills/verify-work/references/feature-map.md +120 -0
- package/skills/verify-work/references/runtime-evidence.md +203 -0
- package/skills/verify-work/references/test-design.md +27 -6
- package/skills/verify-work/scripts/test-changes.mjs +246 -0
- package/skills/write-docs/SKILL.md +171 -0
- package/skills/write-docs/references/documentation-shapes.md +184 -0
- package/skills/write-docs/references/spec-and-plan-shapes.md +308 -0
- package/skills/write-docs/scripts/artifact-check.mjs +148 -0
- package/skills/write-docs/scripts/docs-check.mjs +229 -0
- package/skills/write-docs/scripts/plan-lint.mjs +123 -0
- package/skills/write-skill/SKILL.md +165 -165
- package/skills/write-skill/references/activation-and-wording.md +143 -0
- package/skills/write-skill/references/placement-and-dependencies.md +154 -0
- package/skills/write-skill/scripts/lib/compare.mjs +701 -0
- package/skills/write-skill/scripts/lib/similarity.mjs +56 -0
- package/skills/write-skill/scripts/lib/skill-author.mjs +197 -3
- package/skills/write-skill/scripts/skill-author.mjs +67 -8
- package/capabilities/context-virtualization/SKILL.md +0 -103
- package/capabilities/conversation-history/SKILL.md +0 -53
- package/hooks/tests/check-host-adapters.test.mjs +0 -82
- package/hooks/tests/check-runtime-context-hook.sh +0 -212
- package/pi-extension/dist/cognitive-routing-v2/projection.js +0 -330
- package/pi-extension/dist/cognitive-routing-v2/runtime.js +0 -2181
- package/pi-extension/dist/cognitive-routing-v2/tools.js +0 -60
- package/pi-extension/dist/context-virtualization/commands.js +0 -89
- package/pi-extension/dist/context-virtualization/projector.js +0 -42
- package/pi-extension/dist/context-virtualization/runtime.js +0 -378
- package/pi-extension/dist/context-virtualization/state.js +0 -57
- package/pi-extension/dist/context-virtualization/types.js +0 -10
- package/pi-extension/dist/conversation-history/passages.js +0 -66
- package/pi-extension/dist/conversation-history/ranking.js +0 -105
- package/pi-extension/dist/conversation-history/runtime.js +0 -226
- package/pi-extension/dist/conversation-history/search.js +0 -56
- package/pi-extension/dist/conversation-history/types.js +0 -1
- package/pi-extension/dist/freeflow-context/resolver.js +0 -120
- package/pi-extension/dist/freeflow-context/runtime.js +0 -80
- package/pi-extension/dist/freeflow-context/source-projector.js +0 -95
- package/pi-extension/dist/freeflow-context/tool.js +0 -314
- package/pi-extension/dist/freeflow-context/types.js +0 -12
- package/pi-extension/dist/freeflow-context/visibility.js +0 -28
- package/pi-extension/dist/integrations/mcp-config.js +0 -29
- package/pi-extension/dist/runtime/runtime-context.js +0 -754
- package/pi-extension/dist/runtime/runtime-identity.js +0 -5
- package/pi-extension/dist/session-sources/provenance.js +0 -32
- package/pi-extension/dist/settings/settings-ui.js +0 -1360
- package/pi-extension/dist/ui/text-component.js +0 -57
- package/pi-extension/src/cognitive-routing-v2/budget.ts +0 -42
- package/pi-extension/src/cognitive-routing-v2/config.ts +0 -173
- package/pi-extension/src/cognitive-routing-v2/projection.ts +0 -375
- package/pi-extension/src/cognitive-routing-v2/render.ts +0 -277
- package/pi-extension/src/cognitive-routing-v2/runtime.ts +0 -2241
- package/pi-extension/src/cognitive-routing-v2/schemas.ts +0 -180
- package/pi-extension/src/cognitive-routing-v2/state.ts +0 -839
- package/pi-extension/src/cognitive-routing-v2/tools.ts +0 -62
- package/pi-extension/src/cognitive-routing-v2/types.ts +0 -254
- package/pi-extension/src/context-virtualization/commands.ts +0 -111
- package/pi-extension/src/context-virtualization/projector.ts +0 -62
- package/pi-extension/src/context-virtualization/runtime.ts +0 -428
- package/pi-extension/src/context-virtualization/state.ts +0 -79
- package/pi-extension/src/context-virtualization/types.ts +0 -92
- package/pi-extension/src/conversation-history/passages.ts +0 -81
- package/pi-extension/src/conversation-history/ranking.ts +0 -155
- package/pi-extension/src/conversation-history/runtime.ts +0 -250
- package/pi-extension/src/conversation-history/search.ts +0 -79
- package/pi-extension/src/conversation-history/types.ts +0 -31
- package/pi-extension/src/freeflow-context/resolver.ts +0 -139
- package/pi-extension/src/freeflow-context/runtime.ts +0 -100
- package/pi-extension/src/freeflow-context/source-projector.ts +0 -106
- package/pi-extension/src/freeflow-context/tool.ts +0 -366
- package/pi-extension/src/freeflow-context/types.ts +0 -70
- package/pi-extension/src/freeflow-context/visibility.ts +0 -53
- package/pi-extension/src/index.ts +0 -390
- package/pi-extension/src/integrations/mcp-config.ts +0 -32
- package/pi-extension/src/provider-support/astra/adapter.ts +0 -108
- package/pi-extension/src/provider-support/astra/history.ts +0 -145
- package/pi-extension/src/provider-support/astra/index.ts +0 -12
- package/pi-extension/src/provider-support/astra/session-state.ts +0 -113
- package/pi-extension/src/provider-support/index.ts +0 -5
- package/pi-extension/src/runtime/request-history.ts +0 -243
- package/pi-extension/src/runtime/runtime-context.ts +0 -860
- package/pi-extension/src/runtime/runtime-identity.ts +0 -8
- package/pi-extension/src/session-sources/events.ts +0 -230
- package/pi-extension/src/session-sources/provenance.ts +0 -39
- package/pi-extension/src/session-sources/read-only-session.ts +0 -170
- package/pi-extension/src/session-sources/sources.ts +0 -334
- package/pi-extension/src/settings/settings-tui.ts +0 -501
- package/pi-extension/src/settings/settings-ui.ts +0 -1652
- package/pi-extension/src/ui/text-component.ts +0 -66
- package/pi-extension/tests/cache-reuse/history.test.js +0 -117
- package/pi-extension/tests/cache-reuse/native.test.js +0 -91
- package/pi-extension/tests/cache-reuse/settings.test.js +0 -211
- package/pi-extension/tests/cognitive-routing-v2/communication.test.js +0 -577
- package/pi-extension/tests/cognitive-routing-v2/compaction-input.test.js +0 -183
- package/pi-extension/tests/cognitive-routing-v2/delegation.test.js +0 -557
- package/pi-extension/tests/cognitive-routing-v2/native.test.js +0 -474
- package/pi-extension/tests/cognitive-routing-v2/performance.test.js +0 -87
- package/pi-extension/tests/cognitive-routing-v2/persistence.test.js +0 -300
- package/pi-extension/tests/cognitive-routing-v2/projection.test.js +0 -241
- package/pi-extension/tests/cognitive-routing-v2/recovery.test.js +0 -1034
- package/pi-extension/tests/cognitive-routing-v2/render.test.js +0 -244
- package/pi-extension/tests/cognitive-routing-v2/runtime.test.js +0 -423
- package/pi-extension/tests/cognitive-routing-v2/stabilization.test.js +0 -521
- package/pi-extension/tests/cognitive-routing-v2/state.test.js +0 -586
- package/pi-extension/tests/context-virtualization/extension.test.js +0 -775
- package/pi-extension/tests/context-virtualization/projector.test.js +0 -110
- package/pi-extension/tests/context-virtualization/runtime.test.js +0 -230
- package/pi-extension/tests/conversation-history/runtime.test.js +0 -98
- package/pi-extension/tests/conversation-history/search.test.js +0 -97
- package/pi-extension/tests/fixtures/pi-host.js +0 -4
- package/pi-extension/tests/fixtures/routing-native.js +0 -191
- package/pi-extension/tests/integration/mode-free-core.test.js +0 -220
- package/pi-extension/tests/integration/pi-extension.test.js +0 -1447
- package/pi-extension/tests/integration/prompt-architecture.test.js +0 -447
- package/pi-extension/tests/integration/unaffected-regressions.test.js +0 -478
- package/pi-extension/tests/provider-support/astra-boundaries.test.js +0 -75
- package/pi-extension/tests/provider-support/astra.test.js +0 -306
- package/pi-extension/tests/provider-support/cli.test.js +0 -92
- package/pi-extension/tests/provider-support/native.test.js +0 -183
- package/pi-extension/tests/settings/settings-tui.test.js +0 -243
- package/pi-extension/tsconfig.json +0 -16
- package/plugin.json +0 -33
- package/runtime/prompts/context-virtualization.md +0 -3
- package/runtime/prompts/conversation-history.md +0 -3
- package/skills/action-selection/SKILL.md +0 -100
- package/skills/action-selection/references/trajectory-stalls.md +0 -71
- package/skills/bypass/SKILL.md +0 -153
- package/skills/commit-work/SKILL.md +0 -145
- package/skills/commit-work/references/git-state-edges.md +0 -94
- package/skills/commit-work/references/simple-push.md +0 -92
- package/skills/commit-work/references/staging-decisions.md +0 -106
- package/skills/decision-gate/SKILL.md +0 -106
- package/skills/design-for-depth/SKILL.md +0 -117
- package/skills/design-for-depth/references/design-pressure-signals.md +0 -182
- package/skills/design-for-depth/references/implementation-decisions.md +0 -76
- package/skills/design-for-depth/references/interface-design-loop.md +0 -136
- package/skills/design-for-depth/references/module-and-dependency-design.md +0 -147
- package/skills/design-for-depth/references/software-design-philosophy.md +0 -202
- package/skills/design-for-depth/references/state-and-failure-boundaries.md +0 -136
- package/skills/diagnose-failure/SKILL.md +0 -125
- package/skills/diagnose-failure/references/diagnostic-loop-catalog.md +0 -48
- package/skills/diagnose-failure/references/flaky-and-performance-diagnosis.md +0 -51
- package/skills/discuss/SKILL.md +0 -116
- package/skills/evaluate-skill/SKILL.md +0 -219
- package/skills/evaluate-skill/references/evaluation-definition-schema.md +0 -385
- package/skills/evaluate-skill/references/evaluation-design.md +0 -112
- package/skills/evaluate-skill/references/execution-and-evidence.md +0 -90
- package/skills/evaluate-skill/references/review-and-revision.md +0 -92
- package/skills/evaluate-skill/scripts/lib/definitions.mjs +0 -407
- package/skills/evaluate-skill/scripts/lib/grade-comparison.mjs +0 -60
- package/skills/evaluate-skill/scripts/lib/grade.mjs +0 -64
- package/skills/evaluate-skill/scripts/lib/runner.mjs +0 -368
- package/skills/evaluate-skill/scripts/pi-guard.mjs +0 -164
- package/skills/evaluate-skill/scripts/skill-eval.mjs +0 -102
- package/skills/execute-work/references/execute-work-edges.md +0 -68
- package/skills/finish-branch/SKILL.md +0 -117
- package/skills/finish-branch/references/integration-options.md +0 -80
- package/skills/handoff/SKILL.md +0 -82
- package/skills/handoff/references/handoff-templates.md +0 -150
- package/skills/launch-work/SKILL.md +0 -116
- package/skills/launch-work/references/launch-readiness.md +0 -85
- package/skills/migration-work/SKILL.md +0 -115
- package/skills/migration-work/references/migration-lifecycle.md +0 -82
- package/skills/release-work/SKILL.md +0 -118
- package/skills/release-work/references/release-evidence.md +0 -78
- package/skills/review-artifact/SKILL.md +0 -142
- package/skills/review-artifact/references/adjudicate-artifact-review.md +0 -101
- package/skills/review-artifact/references/independent-artifact-reviewer-contract.md +0 -159
- package/skills/review-work/references/adjudicate-work-review.md +0 -97
- package/skills/review-work/references/independent-work-reviewer-contract.md +0 -139
- package/skills/review-work/references/security-risk-lens.md +0 -69
- package/skills/setup-freeflow/references/activation-contract.md +0 -109
- package/skills/setup-freeflow/references/host-setup.md +0 -67
- package/skills/simplify-code/SKILL.md +0 -85
- package/skills/simplify-code/references/simplification-patterns.md +0 -70
- package/skills/verify-work/references/browser-runtime-evidence.md +0 -55
- package/skills/verify-work/references/integration-evidence.md +0 -47
- package/skills/verify-work/references/performance-evidence.md +0 -57
- package/skills/workflow/SKILL.md +0 -127
- package/skills/workflow/references/domain-skill-composition.md +0 -43
- package/skills/write-plan/SKILL.md +0 -92
- package/skills/write-plan/references/plan-shapes.md +0 -156
- package/skills/write-skill/references/activation-boundaries.md +0 -104
- package/skills/write-skill/references/agent-first-instructions.md +0 -121
- package/skills/write-skill/references/progressive-disclosure.md +0 -127
- package/skills/write-skill/references/skill-dependency-graphs.md +0 -190
- package/skills/write-spec/SKILL.md +0 -92
- package/skills/write-spec/references/artifact-standards.md +0 -86
- package/skills/write-spec/references/decision-records.md +0 -78
- package/skills/write-spec/references/spec-shapes.md +0 -143
- /package/pi-extension/dist/{cognitive-routing-v2 → cognitive-routing}/budget.js +0 -0
- /package/skills/{evaluate-skill → evaluate-behavior}/scripts/lib/evidence.mjs +0 -0
- /package/skills/{evaluate-skill → evaluate-behavior}/scripts/pi-observer.mjs +0 -0
|
@@ -1,373 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
EFFORTS,
|
|
3
2
|
PROFILES,
|
|
4
3
|
ROUTING_ENTRY,
|
|
5
4
|
canonical,
|
|
6
5
|
eventKey,
|
|
7
6
|
eventValue,
|
|
8
|
-
isObject,
|
|
9
7
|
isWorkerProfile,
|
|
10
8
|
requireCondition as check,
|
|
11
9
|
} from "./types.js";
|
|
12
|
-
|
|
13
|
-
const identity = (x) => text(x, 512);
|
|
14
|
-
const nullableId = (x) => x === null || identity(x);
|
|
15
|
-
const shape = (x, keys) => isObject(x) && Object.keys(x).every((k) => keys.includes(k));
|
|
16
|
-
const uniqueStrings = (x) => Array.isArray(x) && x.every(identity) && new Set(x).size === x.length;
|
|
17
|
-
const pair = (x) =>
|
|
18
|
-
shape(x, ["provider", "modelId", "thinking"]) &&
|
|
19
|
-
identity(x.provider) &&
|
|
20
|
-
identity(x.modelId) &&
|
|
21
|
-
EFFORTS.includes(x.thinking);
|
|
22
|
-
const profileOverrides = (x) =>
|
|
23
|
-
isObject(x) &&
|
|
24
|
-
Object.keys(x).length > 0 &&
|
|
25
|
-
Object.keys(x).every((key) => PROFILES.includes(key)) &&
|
|
26
|
-
Object.values(x).every((value) => value === null || pair(value));
|
|
27
|
-
const problemList = (xs) =>
|
|
28
|
-
Array.isArray(xs) &&
|
|
29
|
-
xs.every(
|
|
30
|
-
(x) =>
|
|
31
|
-
shape(x, ["ref", "code", "detail"]) && typeof x.ref === "string" && text(x.code, 256) && text(x.detail, 4096),
|
|
32
|
-
);
|
|
33
|
-
const reservation = (r) =>
|
|
34
|
-
shape(r, [
|
|
35
|
-
"id",
|
|
36
|
-
"selectionRevision",
|
|
37
|
-
"receiver",
|
|
38
|
-
"target",
|
|
39
|
-
"qualification",
|
|
40
|
-
"sources",
|
|
41
|
-
"maximumInputTokens",
|
|
42
|
-
"outputReserve",
|
|
43
|
-
"estimateMethod",
|
|
44
|
-
]) &&
|
|
45
|
-
identity(r.id) &&
|
|
46
|
-
Number.isSafeInteger(r.selectionRevision) &&
|
|
47
|
-
r.selectionRevision >= 0 &&
|
|
48
|
-
PROFILES.includes(r.receiver) &&
|
|
49
|
-
pair(r.target) &&
|
|
50
|
-
text(r.qualification) &&
|
|
51
|
-
Array.isArray(r.sources) &&
|
|
52
|
-
r.sources.every((s) => shape(s, ["ref", "bodyHash"]) && identity(s.ref) && /^[a-f0-9]{64}$/.test(s.bodyHash)) &&
|
|
53
|
-
new Set(r.sources.map((s) => s.ref)).size === r.sources.length &&
|
|
54
|
-
Number.isFinite(r.maximumInputTokens) &&
|
|
55
|
-
r.maximumInputTokens > 0 &&
|
|
56
|
-
Number.isFinite(r.outputReserve) &&
|
|
57
|
-
r.outputReserve >= 0 &&
|
|
58
|
-
text(r.estimateMethod);
|
|
59
|
-
const recovery = (r) =>
|
|
60
|
-
shape(r, [
|
|
61
|
-
"id",
|
|
62
|
-
"assignmentId",
|
|
63
|
-
"assessmentHandoffId",
|
|
64
|
-
"baseReportRevision",
|
|
65
|
-
"request",
|
|
66
|
-
"requestedPaths",
|
|
67
|
-
"paths",
|
|
68
|
-
"state",
|
|
69
|
-
"requestHandoffId",
|
|
70
|
-
"supplementHandoffId",
|
|
71
|
-
"supplementRevision",
|
|
72
|
-
"cancellationReason",
|
|
73
|
-
]) &&
|
|
74
|
-
identity(r.id) &&
|
|
75
|
-
identity(r.assignmentId) &&
|
|
76
|
-
identity(r.assessmentHandoffId) &&
|
|
77
|
-
Number.isSafeInteger(r.baseReportRevision) &&
|
|
78
|
-
r.baseReportRevision > 0 &&
|
|
79
|
-
text(r.request) &&
|
|
80
|
-
Array.isArray(r.requestedPaths) &&
|
|
81
|
-
r.requestedPaths.length <= 32 &&
|
|
82
|
-
r.requestedPaths.every((path) => text(path, 4096)) &&
|
|
83
|
-
new Set(r.requestedPaths).size === r.requestedPaths.length &&
|
|
84
|
-
Array.isArray(r.paths) &&
|
|
85
|
-
r.paths.length <= 32 &&
|
|
86
|
-
r.paths.every((path) => text(path, 4096)) &&
|
|
87
|
-
new Set(r.paths).size === r.paths.length &&
|
|
88
|
-
["requested", "reading", "returning", "completed", "cancelled"].includes(r.state) &&
|
|
89
|
-
identity(r.requestHandoffId) &&
|
|
90
|
-
(r.supplementHandoffId === undefined || identity(r.supplementHandoffId)) &&
|
|
91
|
-
Number.isSafeInteger(r.supplementRevision) &&
|
|
92
|
-
r.supplementRevision >= 0 &&
|
|
93
|
-
(r.cancellationReason === undefined || text(r.cancellationReason, 2048));
|
|
94
|
-
const handoff = (h) =>
|
|
95
|
-
shape(h, [
|
|
96
|
-
"id",
|
|
97
|
-
"kind",
|
|
98
|
-
"assignmentId",
|
|
99
|
-
"text",
|
|
100
|
-
"from",
|
|
101
|
-
"to",
|
|
102
|
-
"executionId",
|
|
103
|
-
"toolCallId",
|
|
104
|
-
"basisUserEntryId",
|
|
105
|
-
"state",
|
|
106
|
-
"reportRevision",
|
|
107
|
-
"outcome",
|
|
108
|
-
"limitations",
|
|
109
|
-
"reason",
|
|
110
|
-
]) &&
|
|
111
|
-
identity(h.id) &&
|
|
112
|
-
identity(h.assignmentId) &&
|
|
113
|
-
text(h.text) &&
|
|
114
|
-
identity(h.executionId) &&
|
|
115
|
-
identity(h.toolCallId) &&
|
|
116
|
-
nullableId(h.basisUserEntryId) &&
|
|
117
|
-
["delegate", "return", "recovery-request", "recovery-return"].includes(h.kind) &&
|
|
118
|
-
PROFILES.includes(h.from) &&
|
|
119
|
-
PROFILES.includes(h.to) &&
|
|
120
|
-
h.from !== h.to &&
|
|
121
|
-
["pending", "configured", "blocked", "superseded"].includes(h.state) &&
|
|
122
|
-
Number.isSafeInteger(h.reportRevision) &&
|
|
123
|
-
h.reportRevision >= 0 &&
|
|
124
|
-
Array.isArray(h.limitations) &&
|
|
125
|
-
h.limitations.length <= 32 &&
|
|
126
|
-
h.limitations.every((x) => text(x, 2048)) &&
|
|
127
|
-
(h.reason === undefined || text(h.reason, 4096)) &&
|
|
128
|
-
(h.outcome === undefined || ["completed", "partial", "blocked"].includes(h.outcome)) &&
|
|
129
|
-
(["delegate", "recovery-request"].includes(h.kind)
|
|
130
|
-
? h.outcome === undefined && h.reportRevision === 0
|
|
131
|
-
: ["completed", "partial", "blocked"].includes(h.outcome) && h.reportRevision > 0);
|
|
132
|
-
const fields = {
|
|
133
|
-
"execution-interrupted": ["executionId", "reason"],
|
|
134
|
-
"assignment-resumed": ["assignmentId", "basisUserEntryId"],
|
|
135
|
-
control: ["control", "profile", "reason"],
|
|
136
|
-
"profile-overrides": ["overrides", "reason"],
|
|
137
|
-
"execution-opened": ["execution"],
|
|
138
|
-
"execution-bound": ["executionId", "assistantEntryId", "resultEntryIds", "outcome"],
|
|
139
|
-
"delegate-accepted": ["unit", "assignment", "handoff", "replacement"],
|
|
140
|
-
"return-accepted": ["handoff"],
|
|
141
|
-
"recovery-request-accepted": ["recovery", "handoff"],
|
|
142
|
-
"recovery-supplement-accepted": ["recoveryId", "handoff"],
|
|
143
|
-
"recovery-cancelled": ["recoveryId", "reason"],
|
|
144
|
-
"handoff-retry-requested": [
|
|
145
|
-
"handoffId",
|
|
146
|
-
"attemptId",
|
|
147
|
-
"executionId",
|
|
148
|
-
"toolCallId",
|
|
149
|
-
"reportRevision",
|
|
150
|
-
"selectionRevision",
|
|
151
|
-
],
|
|
152
|
-
"handoff-prepared": ["handoffId", "reservation"],
|
|
153
|
-
"handoff-state": ["handoffId", "state", "reason", "observedPair"],
|
|
154
|
-
"selection-changed": ["assignmentId", "selection"],
|
|
155
|
-
"assessment-suspended": ["handoffId", "reason", "basisUserEntryId", "problems"],
|
|
156
|
-
"assessment-resumed": ["handoffId", "basisUserEntryId", "reservation"],
|
|
157
|
-
"unit-closed": ["unitId", "outcome", "assessment", "supersededAssignmentId"],
|
|
158
|
-
"sources-exposed": ["executionId", "view", "sources"],
|
|
159
|
-
"request-observed": ["executionId", "profile", "boundary", "manifestHash", "handoffId", "selectionRevision"],
|
|
160
|
-
};
|
|
161
|
-
export function parseRoutingEvent(raw) {
|
|
162
|
-
check(
|
|
163
|
-
isObject(raw) &&
|
|
164
|
-
raw.version === 2 &&
|
|
165
|
-
identity(raw.eventId) &&
|
|
166
|
-
identity(raw.operationId) &&
|
|
167
|
-
identity(raw.stepId) &&
|
|
168
|
-
identity(raw.recordedSessionId) &&
|
|
169
|
-
isObject(raw.data),
|
|
170
|
-
"invalid_event",
|
|
171
|
-
);
|
|
172
|
-
check(
|
|
173
|
-
Object.keys(raw).every((k) =>
|
|
174
|
-
["version", "eventId", "operationId", "stepId", "recordedSessionId", "data"].includes(k),
|
|
175
|
-
),
|
|
176
|
-
"invalid_event_field",
|
|
177
|
-
);
|
|
178
|
-
const d = raw.data;
|
|
179
|
-
check(
|
|
180
|
-
typeof d.type === "string" &&
|
|
181
|
-
Object.hasOwn(fields, d.type) &&
|
|
182
|
-
Object.keys(d).every((k) => k === "type" || fields[d.type].includes(k)),
|
|
183
|
-
"invalid_event_type",
|
|
184
|
-
);
|
|
185
|
-
check(Buffer.byteLength(JSON.stringify(raw)) <= 512 * 1024, "event_too_large");
|
|
186
|
-
if (d.handoffId !== undefined) check(identity(d.handoffId), "invalid_handoff_id");
|
|
187
|
-
switch (d.type) {
|
|
188
|
-
case "execution-interrupted":
|
|
189
|
-
check(identity(d.executionId) && text(d.reason, 4096), "invalid_interruption");
|
|
190
|
-
break;
|
|
191
|
-
case "assignment-resumed":
|
|
192
|
-
check(identity(d.assignmentId) && nullableId(d.basisUserEntryId), "invalid_resume");
|
|
193
|
-
break;
|
|
194
|
-
case "control":
|
|
195
|
-
check(
|
|
196
|
-
["automatic", "manual", "inactive"].includes(d.control) &&
|
|
197
|
-
text(d.reason, 4096) &&
|
|
198
|
-
(d.profile === undefined || PROFILES.includes(d.profile)) &&
|
|
199
|
-
(d.control === "inactive" || PROFILES.includes(d.profile)),
|
|
200
|
-
"invalid_control",
|
|
201
|
-
);
|
|
202
|
-
break;
|
|
203
|
-
case "profile-overrides":
|
|
204
|
-
check(profileOverrides(d.overrides) && text(d.reason, 4096), "invalid_profile_overrides");
|
|
205
|
-
break;
|
|
206
|
-
case "execution-opened": {
|
|
207
|
-
const e = d.execution;
|
|
208
|
-
check(
|
|
209
|
-
shape(e, ["id", "profile", "assignmentId", "recoveryId", "basisUserEntryId", "pair", "resultEntryIds"]) &&
|
|
210
|
-
identity(e.id) &&
|
|
211
|
-
["solo", ...PROFILES].includes(e.profile) &&
|
|
212
|
-
nullableId(e.basisUserEntryId) &&
|
|
213
|
-
pair(e.pair) &&
|
|
214
|
-
uniqueStrings(e.resultEntryIds) &&
|
|
215
|
-
e.resultEntryIds.length === 0 &&
|
|
216
|
-
(e.assignmentId === undefined || identity(e.assignmentId)) &&
|
|
217
|
-
(e.recoveryId === undefined || identity(e.recoveryId)),
|
|
218
|
-
"invalid_execution",
|
|
219
|
-
);
|
|
220
|
-
break;
|
|
221
|
-
}
|
|
222
|
-
case "execution-bound":
|
|
223
|
-
check(
|
|
224
|
-
identity(d.executionId) &&
|
|
225
|
-
identity(d.assistantEntryId) &&
|
|
226
|
-
uniqueStrings(d.resultEntryIds) &&
|
|
227
|
-
["completed", "failed", "aborted"].includes(d.outcome),
|
|
228
|
-
"invalid_binding",
|
|
229
|
-
);
|
|
230
|
-
break;
|
|
231
|
-
case "delegate-accepted": {
|
|
232
|
-
const u = d.unit,
|
|
233
|
-
a = d.assignment,
|
|
234
|
-
r = d.replacement;
|
|
235
|
-
check(
|
|
236
|
-
shape(u, ["id", "objective", "state", "assignmentIds"]) &&
|
|
237
|
-
identity(u.id) &&
|
|
238
|
-
text(u.objective) &&
|
|
239
|
-
u.state === "open" &&
|
|
240
|
-
uniqueStrings(u.assignmentIds),
|
|
241
|
-
"invalid_unit",
|
|
242
|
-
);
|
|
243
|
-
check(
|
|
244
|
-
shape(a, ["id", "unitId", "contract", "basisUserEntryId", "state", "delegateHandoffId"]) &&
|
|
245
|
-
identity(a.id) &&
|
|
246
|
-
identity(a.unitId) &&
|
|
247
|
-
text(a.contract) &&
|
|
248
|
-
nullableId(a.basisUserEntryId) &&
|
|
249
|
-
a.state === "outstanding" &&
|
|
250
|
-
identity(a.delegateHandoffId) &&
|
|
251
|
-
handoff(d.handoff),
|
|
252
|
-
"invalid_assignment",
|
|
253
|
-
);
|
|
254
|
-
check(
|
|
255
|
-
r === undefined ||
|
|
256
|
-
(shape(r, ["assignmentId", "supersededHandoffId", "reason"]) &&
|
|
257
|
-
identity(r.assignmentId) &&
|
|
258
|
-
text(r.reason, 2048) &&
|
|
259
|
-
(r.supersededHandoffId === undefined || identity(r.supersededHandoffId))),
|
|
260
|
-
"invalid_replacement",
|
|
261
|
-
);
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
case "return-accepted":
|
|
265
|
-
check(handoff(d.handoff) && d.handoff.kind === "return", "invalid_return");
|
|
266
|
-
break;
|
|
267
|
-
case "recovery-request-accepted":
|
|
268
|
-
check(
|
|
269
|
-
recovery(d.recovery) &&
|
|
270
|
-
handoff(d.handoff) &&
|
|
271
|
-
d.handoff.kind === "recovery-request" &&
|
|
272
|
-
d.recovery.requestHandoffId === d.handoff.id &&
|
|
273
|
-
d.recovery.assignmentId === d.handoff.assignmentId &&
|
|
274
|
-
d.recovery.request === d.handoff.text,
|
|
275
|
-
"invalid_recovery_request",
|
|
276
|
-
);
|
|
277
|
-
break;
|
|
278
|
-
case "recovery-supplement-accepted":
|
|
279
|
-
check(
|
|
280
|
-
identity(d.recoveryId) && handoff(d.handoff) && d.handoff.kind === "recovery-return",
|
|
281
|
-
"invalid_recovery_supplement",
|
|
282
|
-
);
|
|
283
|
-
break;
|
|
284
|
-
case "recovery-cancelled":
|
|
285
|
-
check(identity(d.recoveryId) && text(d.reason, 2048), "invalid_recovery_cancellation");
|
|
286
|
-
break;
|
|
287
|
-
case "handoff-retry-requested":
|
|
288
|
-
check(
|
|
289
|
-
identity(d.attemptId) &&
|
|
290
|
-
identity(d.executionId) &&
|
|
291
|
-
identity(d.toolCallId) &&
|
|
292
|
-
Number.isSafeInteger(d.reportRevision) &&
|
|
293
|
-
d.reportRevision > 0 &&
|
|
294
|
-
Number.isSafeInteger(d.selectionRevision) &&
|
|
295
|
-
d.selectionRevision >= 0,
|
|
296
|
-
"invalid_retry",
|
|
297
|
-
);
|
|
298
|
-
break;
|
|
299
|
-
case "handoff-prepared":
|
|
300
|
-
check(reservation(d.reservation), "invalid_reservation");
|
|
301
|
-
break;
|
|
302
|
-
case "handoff-state":
|
|
303
|
-
check(
|
|
304
|
-
["configured", "blocked", "superseded"].includes(d.state) &&
|
|
305
|
-
(d.reason === undefined || text(d.reason, 4096)) &&
|
|
306
|
-
(d.observedPair === undefined || pair(d.observedPair)),
|
|
307
|
-
"invalid_delivery",
|
|
308
|
-
);
|
|
309
|
-
break;
|
|
310
|
-
case "selection-changed": {
|
|
311
|
-
const s = d.selection;
|
|
312
|
-
check(
|
|
313
|
-
identity(d.assignmentId) &&
|
|
314
|
-
shape(s, ["revision", "selected", "unresolved", "withdrawals"]) &&
|
|
315
|
-
Number.isSafeInteger(s.revision) &&
|
|
316
|
-
s.revision > 0 &&
|
|
317
|
-
uniqueStrings(s.selected) &&
|
|
318
|
-
problemList(s.unresolved) &&
|
|
319
|
-
Array.isArray(s.withdrawals) &&
|
|
320
|
-
s.withdrawals.every((w) => shape(w, ["ref", "reason"]) && identity(w.ref) && text(w.reason, 2048)),
|
|
321
|
-
"invalid_selection",
|
|
322
|
-
);
|
|
323
|
-
break;
|
|
324
|
-
}
|
|
325
|
-
case "assessment-suspended":
|
|
326
|
-
check(
|
|
327
|
-
["user-attention", "delivery-gap"].includes(d.reason) &&
|
|
328
|
-
nullableId(d.basisUserEntryId) &&
|
|
329
|
-
problemList(d.problems),
|
|
330
|
-
"invalid_suspension",
|
|
331
|
-
);
|
|
332
|
-
break;
|
|
333
|
-
case "assessment-resumed":
|
|
334
|
-
check(
|
|
335
|
-
nullableId(d.basisUserEntryId) && (d.reservation === undefined || reservation(d.reservation)),
|
|
336
|
-
"invalid_resumption",
|
|
337
|
-
);
|
|
338
|
-
break;
|
|
339
|
-
case "unit-closed":
|
|
340
|
-
check(
|
|
341
|
-
identity(d.unitId) &&
|
|
342
|
-
["accepted", "cancelled", "deferred"].includes(d.outcome) &&
|
|
343
|
-
text(d.assessment) &&
|
|
344
|
-
(d.supersededAssignmentId === undefined || identity(d.supersededAssignmentId)),
|
|
345
|
-
"invalid_closure",
|
|
346
|
-
);
|
|
347
|
-
break;
|
|
348
|
-
case "request-observed":
|
|
349
|
-
check(
|
|
350
|
-
identity(d.executionId) &&
|
|
351
|
-
["solo", ...PROFILES].includes(d.profile) &&
|
|
352
|
-
["assembled", "payload-hook"].includes(d.boundary) &&
|
|
353
|
-
/^[a-f0-9]{64}$/.test(d.manifestHash) &&
|
|
354
|
-
(d.selectionRevision === undefined ||
|
|
355
|
-
(Number.isSafeInteger(d.selectionRevision) && d.selectionRevision >= 0)),
|
|
356
|
-
"invalid_request_observation",
|
|
357
|
-
);
|
|
358
|
-
break;
|
|
359
|
-
case "sources-exposed":
|
|
360
|
-
check(
|
|
361
|
-
identity(d.executionId) &&
|
|
362
|
-
["solo", ...PROFILES].includes(d.view) &&
|
|
363
|
-
Array.isArray(d.sources) &&
|
|
364
|
-
d.sources.every((s) => shape(s, ["ref", "bodyHash"]) && identity(s.ref) && /^[a-f0-9]{64}$/.test(s.bodyHash)),
|
|
365
|
-
"invalid_exposure",
|
|
366
|
-
);
|
|
367
|
-
break;
|
|
368
|
-
}
|
|
369
|
-
return structuredClone(raw);
|
|
370
|
-
}
|
|
10
|
+
import { parseRoutingEvent } from "./event-schema.js";
|
|
371
11
|
export function initialState() {
|
|
372
12
|
return {
|
|
373
13
|
control: "inactive",
|
|
@@ -405,7 +45,17 @@ function applyEvent(state, event, owned = false) {
|
|
|
405
45
|
units: new Map([...state.units].map(([k, v]) => [k, { ...v }])),
|
|
406
46
|
assignments: new Map([...state.assignments].map(([k, v]) => [k, { ...v }])),
|
|
407
47
|
handoffs: new Map([...state.handoffs].map(([k, v]) => [k, { ...v }])),
|
|
408
|
-
recoveries: new Map(
|
|
48
|
+
recoveries: new Map(
|
|
49
|
+
[...state.recoveries].map(([k, v]) => [
|
|
50
|
+
k,
|
|
51
|
+
{
|
|
52
|
+
...v,
|
|
53
|
+
paths: [...v.paths],
|
|
54
|
+
requestedResults: [...(v.requestedResults ?? [])],
|
|
55
|
+
results: (v.results ?? []).map((grant) => ({ ...grant })),
|
|
56
|
+
},
|
|
57
|
+
]),
|
|
58
|
+
),
|
|
409
59
|
executions: new Map([...state.executions].map(([k, v]) => [k, { ...v }])),
|
|
410
60
|
selections: new Map(state.selections),
|
|
411
61
|
reservations: new Map(state.reservations),
|
|
@@ -426,6 +76,11 @@ function applyEvent(state, event, owned = false) {
|
|
|
426
76
|
check(h?.kind === "delegate" && h.assignmentId === a?.id && isWorkerProfile(h.to), "assignment_worker_missing");
|
|
427
77
|
return h.to;
|
|
428
78
|
};
|
|
79
|
+
// A worker response that started but was neither bound nor retired may still be producing effects.
|
|
80
|
+
const workerRunning = (belongs) =>
|
|
81
|
+
[...s.executions.values()].some(
|
|
82
|
+
(x) => belongs(x) && isWorkerProfile(x.profile) && !x.assistantEntryId && !x.interrupted,
|
|
83
|
+
);
|
|
429
84
|
const pending = () => (s.pendingId ? s.handoffs.get(s.pendingId) : undefined);
|
|
430
85
|
const isPending = () => pending() && ["pending", "blocked"].includes(pending().state);
|
|
431
86
|
const currentReturn = (id) => {
|
|
@@ -460,10 +115,13 @@ function applyEvent(state, event, owned = false) {
|
|
|
460
115
|
for (const profile of PROFILES) {
|
|
461
116
|
if (!Object.hasOwn(d.overrides, profile)) continue;
|
|
462
117
|
const override = d.overrides[profile];
|
|
463
|
-
if (override === null) s.profileOverrides.delete(profile);
|
|
118
|
+
if (override === null || override === undefined) s.profileOverrides.delete(profile);
|
|
464
119
|
else s.profileOverrides.set(profile, override);
|
|
465
120
|
}
|
|
466
121
|
break;
|
|
122
|
+
case "delegation-override":
|
|
123
|
+
s.delegationOverride = d.delegation ?? undefined;
|
|
124
|
+
break;
|
|
467
125
|
case "execution-opened":
|
|
468
126
|
check(!s.executions.has(d.execution.id), "duplicate_execution");
|
|
469
127
|
s.executions.set(d.execution.id, d.execution);
|
|
@@ -513,19 +171,17 @@ function applyEvent(state, event, owned = false) {
|
|
|
513
171
|
);
|
|
514
172
|
if (d.replacement) {
|
|
515
173
|
check(a?.state === "outstanding" && a.id === d.replacement.assignmentId && u, "no_replaceable_assignment");
|
|
516
|
-
check(
|
|
517
|
-
![...s.executions.values()].some(
|
|
518
|
-
(x) => x.assignmentId === a.id && isWorkerProfile(x.profile) && !x.assistantEntryId && !x.interrupted,
|
|
519
|
-
),
|
|
520
|
-
"unresolved_worker_execution",
|
|
521
|
-
);
|
|
174
|
+
check(!workerRunning((x) => x.assignmentId === a.id), "unresolved_worker_execution");
|
|
522
175
|
check(
|
|
523
176
|
!isPending() || (pending().kind === "delegate" && d.replacement.supersededHandoffId === pending().id),
|
|
524
177
|
"handoff_pending",
|
|
525
178
|
);
|
|
526
179
|
a.state = "superseded";
|
|
527
180
|
s.handoffs.get(a.delegateHandoffId).state = "superseded";
|
|
528
|
-
} else
|
|
181
|
+
} else {
|
|
182
|
+
check(a?.state !== "outstanding" && !isPending(), "assignment_outstanding");
|
|
183
|
+
check(!s.recoveryId, "recovery_outstanding");
|
|
184
|
+
}
|
|
529
185
|
s.units.set(d.unit.id, d.unit);
|
|
530
186
|
s.unitId = d.unit.id;
|
|
531
187
|
s.assignments.set(d.assignment.id, d.assignment);
|
|
@@ -586,8 +242,8 @@ function applyEvent(state, event, owned = false) {
|
|
|
586
242
|
d.recovery.supplementRevision === 0 &&
|
|
587
243
|
d.recovery.supplementHandoffId === undefined &&
|
|
588
244
|
d.recovery.cancellationReason === undefined &&
|
|
589
|
-
s.assessment?.handoffId === base?.id &&
|
|
590
245
|
base?.kind === "return" &&
|
|
246
|
+
s.assessment?.handoffId === base.id &&
|
|
591
247
|
a.returnHandoffId === base.id &&
|
|
592
248
|
base.state === "configured" &&
|
|
593
249
|
base.reportRevision === d.recovery.baseReportRevision &&
|
|
@@ -602,14 +258,22 @@ function applyEvent(state, event, owned = false) {
|
|
|
602
258
|
!s.recoveries.has(d.recovery.id),
|
|
603
259
|
"recovery_not_available",
|
|
604
260
|
);
|
|
605
|
-
s.recoveries.set(d.recovery.id,
|
|
261
|
+
s.recoveries.set(d.recovery.id, {
|
|
262
|
+
...d.recovery,
|
|
263
|
+
requestedResults: [...(d.recovery.requestedResults ?? [])],
|
|
264
|
+
results: (d.recovery.results ?? []).map((grant) => ({ ...grant })),
|
|
265
|
+
});
|
|
606
266
|
s.recoveryId = d.recovery.id;
|
|
607
267
|
s.handoffs.set(h.id, h);
|
|
608
268
|
s.pendingId = h.id;
|
|
609
269
|
s.assessment.view = "suspended";
|
|
610
|
-
s
|
|
611
|
-
|
|
612
|
-
s.assessment.
|
|
270
|
+
// A recovery answers the Coordinator's evidence question, not new user input: an assessment already waiting
|
|
271
|
+
// for that attention keeps waiting for it after the recovery, instead of resuming when the supplement arrives.
|
|
272
|
+
if (s.assessment.suspensionReason !== "user-attention") {
|
|
273
|
+
s.assessment.suspensionReason = "recovery";
|
|
274
|
+
s.assessment.basisUserEntryId = h.basisUserEntryId;
|
|
275
|
+
s.assessment.problems = [];
|
|
276
|
+
}
|
|
613
277
|
break;
|
|
614
278
|
}
|
|
615
279
|
case "recovery-supplement-accepted": {
|
|
@@ -621,7 +285,8 @@ function applyEvent(state, event, owned = false) {
|
|
|
621
285
|
s.control === "automatic" &&
|
|
622
286
|
s.profile === assignmentWorker() &&
|
|
623
287
|
a?.state === "returned" &&
|
|
624
|
-
r
|
|
288
|
+
r !== undefined &&
|
|
289
|
+
r.id === s.recoveryId &&
|
|
625
290
|
r.assignmentId === a.id &&
|
|
626
291
|
s.assessment?.handoffId === r.assessmentHandoffId &&
|
|
627
292
|
s.handoffs.get(r.assessmentHandoffId)?.reportRevision === r.baseReportRevision &&
|
|
@@ -648,10 +313,12 @@ function applyEvent(state, event, owned = false) {
|
|
|
648
313
|
check(
|
|
649
314
|
s.control === "automatic" &&
|
|
650
315
|
s.profile === "coordinator" &&
|
|
651
|
-
r
|
|
316
|
+
r !== undefined &&
|
|
317
|
+
r.id === s.recoveryId &&
|
|
652
318
|
["requested", "reading", "returning"].includes(r.state),
|
|
653
319
|
"recovery_not_cancellable",
|
|
654
320
|
);
|
|
321
|
+
check(!workerRunning((x) => x.recoveryId === r.id), "unresolved_worker_execution");
|
|
655
322
|
const p = pending();
|
|
656
323
|
if (p) {
|
|
657
324
|
check([r.requestHandoffId, r.supplementHandoffId].includes(p.id), "handoff_pending");
|
|
@@ -737,14 +404,10 @@ function applyEvent(state, event, owned = false) {
|
|
|
737
404
|
break;
|
|
738
405
|
}
|
|
739
406
|
case "assessment-resumed": {
|
|
740
|
-
check(
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
s.assessment?.handoffId === d.handoffId &&
|
|
745
|
-
s.assessment.view === "suspended",
|
|
746
|
-
s.recoveryId ? "recovery_outstanding" : "assessment_not_suspended",
|
|
747
|
-
);
|
|
407
|
+
check(s.control === "automatic" && s.profile === "coordinator", "wrong_control");
|
|
408
|
+
check(!s.recoveryId, "recovery_outstanding");
|
|
409
|
+
check(s.assessment?.handoffId === d.handoffId, "assessment_missing");
|
|
410
|
+
check(s.assessment.view === "suspended", "assessment_not_suspended");
|
|
748
411
|
if (d.reservation)
|
|
749
412
|
check(
|
|
750
413
|
d.reservation.selectionRevision === (s.selections.get(s.assessment.assignmentId)?.revision ?? 0),
|
|
@@ -764,7 +427,11 @@ function applyEvent(state, event, owned = false) {
|
|
|
764
427
|
const u = s.units.get(d.unitId),
|
|
765
428
|
a = assignment();
|
|
766
429
|
check(
|
|
767
|
-
s.control === "automatic" &&
|
|
430
|
+
s.control === "automatic" &&
|
|
431
|
+
s.profile === "coordinator" &&
|
|
432
|
+
u !== undefined &&
|
|
433
|
+
u.id === s.unitId &&
|
|
434
|
+
u.state === "open",
|
|
768
435
|
"unit_not_open",
|
|
769
436
|
);
|
|
770
437
|
if (d.outcome === "accepted")
|
|
@@ -775,6 +442,7 @@ function applyEvent(state, event, owned = false) {
|
|
|
775
442
|
d.outcome !== "accepted" && ["requested", "reading", "returning"].includes(recovery.state),
|
|
776
443
|
"unfinished_work",
|
|
777
444
|
);
|
|
445
|
+
check(!workerRunning((x) => x.recoveryId === recovery.id), "unresolved_worker_execution");
|
|
778
446
|
const transfer = pending();
|
|
779
447
|
if (transfer) {
|
|
780
448
|
check([recovery.requestHandoffId, recovery.supplementHandoffId].includes(transfer.id), "handoff_pending");
|
|
@@ -787,6 +455,7 @@ function applyEvent(state, event, owned = false) {
|
|
|
787
455
|
}
|
|
788
456
|
if (a?.state === "outstanding") {
|
|
789
457
|
check(d.supersededAssignmentId === a.id && d.outcome !== "accepted", "supersession_required");
|
|
458
|
+
check(!workerRunning((x) => x.assignmentId === a.id), "unresolved_worker_execution");
|
|
790
459
|
a.state = "superseded";
|
|
791
460
|
}
|
|
792
461
|
if (pending()) pending().state = "superseded";
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { initialState } from "./state.js";
|
|
2
|
+
/**
|
|
3
|
+
* What routing reports about itself: the summary behind Freeflow's status line and the Runtime State sent with each
|
|
4
|
+
* request (whether routing is active or blocked and why, the running profile, control mode, a switch waiting for the
|
|
5
|
+
* next prompt, preset warnings), and the detailed view with unit, assignment, handoff, recovery, and recent events
|
|
6
|
+
* used by unit status and diagnostics.
|
|
7
|
+
*/
|
|
8
|
+
export class RoutingStatus {
|
|
9
|
+
session;
|
|
10
|
+
models;
|
|
11
|
+
constructor(session, models) {
|
|
12
|
+
this.session = session;
|
|
13
|
+
this.models = models;
|
|
14
|
+
}
|
|
15
|
+
state() {
|
|
16
|
+
let state;
|
|
17
|
+
try {
|
|
18
|
+
state = this.session.stateData();
|
|
19
|
+
} catch {
|
|
20
|
+
state = initialState();
|
|
21
|
+
}
|
|
22
|
+
// A model or effort named on Pi's command line holds routing at startup (`startup_selection`). Its store is not
|
|
23
|
+
// reconciled then, so the store's own reason would hide why (Task 008 S-005).
|
|
24
|
+
const blocked = this.session.error ?? (this.session.suppressed ? "startup_selection" : this.session.store?.blocked);
|
|
25
|
+
return {
|
|
26
|
+
effective: this.session.supported() && state.control !== "inactive" && !blocked,
|
|
27
|
+
activeProfile: state.profile,
|
|
28
|
+
delegation: this.session.delegation(state),
|
|
29
|
+
controlMode: state.control === "manual" ? `manual-${state.profile}` : state.control,
|
|
30
|
+
runtimeStatus: blocked
|
|
31
|
+
? "blocked"
|
|
32
|
+
: this.session.supported() && state.control !== "inactive"
|
|
33
|
+
? "active"
|
|
34
|
+
: "inactive",
|
|
35
|
+
runtimeReason: blocked ?? this.session.capability?.blockingReason.message,
|
|
36
|
+
projectionFailure: this.session.projectionError,
|
|
37
|
+
...((pending) => (pending ? { pendingPair: `${pending.modelId}/${pending.thinking}` } : {}))(
|
|
38
|
+
this.models.pending(),
|
|
39
|
+
),
|
|
40
|
+
...(this.models.heldMismatch(state) ? { pairMismatch: true } : {}),
|
|
41
|
+
...((warnings) => (warnings.length ? { presetWarnings: warnings } : {}))(this.models.presetWarnings(state)),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
detail(limit = 0) {
|
|
45
|
+
const state = this.session.stateData();
|
|
46
|
+
const unit = state.unitId ? state.units.get(state.unitId) : undefined;
|
|
47
|
+
const a = state.assignmentId ? state.assignments.get(state.assignmentId) : undefined;
|
|
48
|
+
return {
|
|
49
|
+
...this.state(),
|
|
50
|
+
unit: unit ? { id: unit.id, state: unit.state, assignments: unit.assignmentIds.length } : null,
|
|
51
|
+
assignment: a ? { id: a.id, state: a.state, worker: this.session.assignedWorker(state, a.id) } : null,
|
|
52
|
+
pendingHandoff: state.pendingId ?? null,
|
|
53
|
+
recovery: state.recoveryId
|
|
54
|
+
? (() => {
|
|
55
|
+
const recovery = state.recoveries.get(state.recoveryId);
|
|
56
|
+
return recovery
|
|
57
|
+
? {
|
|
58
|
+
id: recovery.id,
|
|
59
|
+
state: recovery.state,
|
|
60
|
+
assignmentId: recovery.assignmentId,
|
|
61
|
+
assessmentHandoffId: recovery.assessmentHandoffId,
|
|
62
|
+
paths: recovery.paths,
|
|
63
|
+
results: recovery.results ?? [],
|
|
64
|
+
supplementRevision: recovery.supplementRevision,
|
|
65
|
+
}
|
|
66
|
+
: null;
|
|
67
|
+
})()
|
|
68
|
+
: null,
|
|
69
|
+
assessment: state.assessment
|
|
70
|
+
? { handoffId: state.assessment.handoffId, view: state.assessment.view, problems: state.assessment.problems }
|
|
71
|
+
: null,
|
|
72
|
+
...(limit
|
|
73
|
+
? {
|
|
74
|
+
history: [...state.events.values()]
|
|
75
|
+
.slice(-Math.min(100, Math.max(1, limit)))
|
|
76
|
+
.map((e) => ({ event: e.eventId, type: e.data.type, operation: e.operationId })),
|
|
77
|
+
}
|
|
78
|
+
: {}),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|