@hassangameryt/freeflow 0.1.0 → 0.3.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 +1 -1
- package/.claude-plugin/marketplace.json +2 -2
- package/{plugins/freeflow/.claude-plugin → .claude-plugin}/plugin.json +1 -1
- package/{plugins/freeflow/.codex-plugin → .codex-plugin}/plugin.json +1 -1
- package/README.md +25 -16
- package/assets/freeflow-plugin-icon.png +0 -0
- package/{plugins/freeflow/command-surface.json → command-surface.json} +10 -10
- package/evals/README.md +32 -0
- package/evals/fixtures/copy-conventions.md +31 -0
- package/evals/fixtures/output-router/README.md +12 -0
- package/evals/fixtures/output-router/failed-command-output.txt +9 -0
- package/evals/fixtures/output-router/large-router-manual.md +63 -0
- package/evals/fixtures/output-router/native-large-output.txt +40 -0
- package/evals/fixtures/output-router/noisy-test-output.txt +30 -0
- package/evals/fixtures/output-router/verification-output.txt +8 -0
- package/evals/fixtures/tiny-artifact-review-app/README.md +5 -0
- package/evals/fixtures/tiny-artifact-review-app/docs/billing-policy.md +10 -0
- package/evals/fixtures/tiny-artifact-review-app/docs/specs/billing-webhook-api-draft.md +21 -0
- package/evals/fixtures/tiny-artifact-review-app/docs/specs/failed-payment-grace-period.md +24 -0
- package/evals/fixtures/tiny-artifact-review-app/docs/specs/immediate-downgrade.md +17 -0
- package/evals/fixtures/tiny-artifact-review-app/tests/billing.test.md +8 -0
- package/evals/fixtures/tiny-commit-ambiguous-app/.freeflow-eval-setup.sh +15 -0
- package/evals/fixtures/tiny-commit-ambiguous-app/README.md +3 -0
- package/evals/fixtures/tiny-commit-ambiguous-app/src/billing.ts +5 -0
- package/evals/fixtures/tiny-commit-ambiguous-app/src/settings-page.ts +1 -0
- package/evals/fixtures/tiny-commit-ambiguous-app/tests/settings.test.md +5 -0
- package/evals/fixtures/tiny-commit-app/.freeflow-eval-setup.sh +14 -0
- package/evals/fixtures/tiny-commit-app/README.md +3 -0
- package/evals/fixtures/tiny-commit-app/docs/specs/settings-title.md +5 -0
- package/evals/fixtures/tiny-commit-app/src/billing.ts +5 -0
- package/evals/fixtures/tiny-commit-app/src/settings-page.ts +1 -0
- package/evals/fixtures/tiny-commit-app/tests/settings.test.md +5 -0
- package/evals/fixtures/tiny-commit-everything-app/.freeflow-eval-setup.sh +15 -0
- package/evals/fixtures/tiny-commit-everything-app/README.md +3 -0
- package/evals/fixtures/tiny-commit-everything-app/docs/specs/settings-title.md +5 -0
- package/evals/fixtures/tiny-commit-everything-app/src/billing.ts +5 -0
- package/evals/fixtures/tiny-commit-everything-app/src/settings-page.ts +1 -0
- package/evals/fixtures/tiny-commit-everything-app/tests/settings.test.md +5 -0
- package/evals/fixtures/tiny-commit-staged-app/.freeflow-eval-setup.sh +15 -0
- package/evals/fixtures/tiny-commit-staged-app/README.md +3 -0
- package/evals/fixtures/tiny-commit-staged-app/docs/specs/settings-title.md +5 -0
- package/evals/fixtures/tiny-commit-staged-app/src/billing.ts +5 -0
- package/evals/fixtures/tiny-commit-staged-app/src/settings-page.ts +1 -0
- package/evals/fixtures/tiny-commit-staged-app/tests/settings.test.md +5 -0
- package/evals/fixtures/tiny-commit-staged-mixed-app/.freeflow-eval-setup.sh +15 -0
- package/evals/fixtures/tiny-commit-staged-mixed-app/README.md +3 -0
- package/evals/fixtures/tiny-commit-staged-mixed-app/docs/billing-policy.md +3 -0
- package/evals/fixtures/tiny-commit-staged-mixed-app/docs/release-notes.md +3 -0
- package/evals/fixtures/tiny-commit-staged-mixed-app/src/billing.ts +5 -0
- package/evals/fixtures/tiny-dashboard-stale-app/README.md +11 -0
- package/evals/fixtures/tiny-dashboard-stale-app/src/api-client.ts +13 -0
- package/evals/fixtures/tiny-dashboard-stale-app/src/dashboard-data.ts +19 -0
- package/evals/fixtures/tiny-dashboard-stale-app/tests/dashboard-data.test.md +9 -0
- package/evals/fixtures/tiny-decision-destination-app/README.md +6 -0
- package/evals/fixtures/tiny-decision-destination-app/src/risk.ts +8 -0
- package/evals/fixtures/tiny-decision-destination-app/tests/risk.test.md +4 -0
- package/evals/fixtures/tiny-design-depth-app/README.md +15 -0
- package/evals/fixtures/tiny-design-depth-app/src/routes.ts +25 -0
- package/evals/fixtures/tiny-design-depth-app/src/sendEmail.ts +3 -0
- package/evals/fixtures/tiny-design-depth-app/src/sendSms.ts +3 -0
- package/evals/fixtures/tiny-design-depth-app/src/telemetry.ts +3 -0
- package/evals/fixtures/tiny-design-depth-app/tests/routes.test.md +12 -0
- package/evals/fixtures/tiny-eval-method-app/README.md +8 -0
- package/evals/fixtures/tiny-eval-method-app/evals/reports/review-pr-eval-result.md +5 -0
- package/evals/fixtures/tiny-eval-method-app/evals/reports/triage-question-failure.md +17 -0
- package/evals/fixtures/tiny-eval-method-app/evals/runs/review-pr-with-skill-output.diff +11 -0
- package/evals/fixtures/tiny-eval-method-app/evals/runs/review-pr-with-skill-output.md +3 -0
- package/evals/fixtures/tiny-eval-method-app/skills/review-pr/SKILL.md +10 -0
- package/evals/fixtures/tiny-eval-method-app/skills/triage-question/SKILL.md +10 -0
- package/evals/fixtures/tiny-execute-plan-app/README.md +5 -0
- package/evals/fixtures/tiny-execute-plan-app/checks/settings-and-billing-check.sh +5 -0
- package/evals/fixtures/tiny-execute-plan-app/docs/billing-policy.md +10 -0
- package/evals/fixtures/tiny-execute-plan-app/docs/plans/immediate-downgrade-plan.md +11 -0
- package/evals/fixtures/tiny-execute-plan-app/docs/plans/settings-title-plan.md +12 -0
- package/evals/fixtures/tiny-execute-plan-app/docs/plans/settings-title-with-bad-check.md +15 -0
- package/evals/fixtures/tiny-execute-plan-app/docs/plans/unverified-billing-plan.md +9 -0
- package/evals/fixtures/tiny-execute-plan-app/docs/specs/failed-payment-grace-period.md +9 -0
- package/evals/fixtures/tiny-execute-plan-app/docs/specs/settings-title.md +9 -0
- package/evals/fixtures/tiny-execute-plan-app/src/billing.ts +7 -0
- package/evals/fixtures/tiny-execute-plan-app/src/settings-page.ts +1 -0
- package/evals/fixtures/tiny-execute-plan-app/tests/billing.test.md +7 -0
- package/evals/fixtures/tiny-execute-plan-app/tests/settings.test.md +5 -0
- package/evals/fixtures/tiny-execute-review-loop-app/README.md +5 -0
- package/evals/fixtures/tiny-execute-review-loop-app/docs/billing-policy.md +9 -0
- package/evals/fixtures/tiny-execute-review-loop-app/docs/plans/settings-title-plan.md +12 -0
- package/evals/fixtures/tiny-execute-review-loop-app/docs/review/previous-agent-summary.md +15 -0
- package/evals/fixtures/tiny-execute-review-loop-app/docs/review/review-pass-1-non-pass.md +11 -0
- package/evals/fixtures/tiny-execute-review-loop-app/docs/specs/settings-title.md +9 -0
- package/evals/fixtures/tiny-execute-review-loop-app/src/billing.ts +7 -0
- package/evals/fixtures/tiny-execute-review-loop-app/src/settings-page.ts +1 -0
- package/evals/fixtures/tiny-execute-review-loop-app/tests/billing.test.md +7 -0
- package/evals/fixtures/tiny-execute-review-loop-app/tests/settings.test.md +5 -0
- package/evals/fixtures/tiny-flaky-session-app/README.md +10 -0
- package/evals/fixtures/tiny-flaky-session-app/src/session-timeout.ts +13 -0
- package/evals/fixtures/tiny-flaky-session-app/tests/session-timeout.test.md +8 -0
- package/evals/fixtures/tiny-handoff-app/README.md +5 -0
- package/evals/fixtures/tiny-handoff-app/docs/billing-policy.md +10 -0
- package/evals/fixtures/tiny-handoff-app/docs/handoffs/old-agent-handoff.md +8 -0
- package/evals/fixtures/tiny-handoff-app/docs/plans/billing-retry-plan.md +11 -0
- package/evals/fixtures/tiny-handoff-app/src/billing.ts +7 -0
- package/evals/fixtures/tiny-handoff-report-app/README.md +3 -0
- package/evals/fixtures/tiny-handoff-report-app/evals/runs/handoff-3/hof-003/with-skill-output.diff +1 -0
- package/evals/fixtures/tiny-handoff-report-app/evals/runs/handoff-3/hof-003/with-skill-output.md +1 -0
- package/evals/fixtures/tiny-handoff-report-app/evals/scores/hof-003-score.txt +4 -0
- package/evals/fixtures/tiny-plan-app/README.md +5 -0
- package/evals/fixtures/tiny-plan-app/docs/billing-policy.md +10 -0
- package/evals/fixtures/tiny-plan-app/docs/specs/failed-payment-grace-period.md +25 -0
- package/evals/fixtures/tiny-plan-app/src/billing.ts +17 -0
- package/evals/fixtures/tiny-plan-app/src/settings-page.ts +1 -0
- package/evals/fixtures/tiny-plan-app/tests/billing.test.md +8 -0
- package/evals/fixtures/tiny-plan-app/tests/settings.test.md +5 -0
- package/evals/fixtures/tiny-plan-strict-api-app/README.md +3 -0
- package/evals/fixtures/tiny-plan-strict-api-app/docs/billing-policy.md +5 -0
- package/evals/fixtures/tiny-plan-strict-api-app/docs/specs/billing-webhook-api.md +25 -0
- package/evals/fixtures/tiny-plan-strict-api-app/src/billing.ts +5 -0
- package/evals/fixtures/tiny-plan-strict-api-app/src/webhooks.ts +3 -0
- package/evals/fixtures/tiny-plan-strict-api-app/tests/billing-webhook.test.md +8 -0
- package/evals/fixtures/tiny-post-setup-invalid-config-app/.freeflow/config.json +3 -0
- package/evals/fixtures/tiny-post-setup-invalid-config-app/AGENTS.md +15 -0
- package/evals/fixtures/tiny-post-setup-invalid-config-app/README.md +16 -0
- package/evals/fixtures/tiny-post-setup-invalid-config-app/docs/auth-review.md +15 -0
- package/evals/fixtures/tiny-post-setup-invalid-config-app/docs/billing-policy.md +10 -0
- package/evals/fixtures/tiny-post-setup-invalid-config-app/docs/copy-conventions.md +15 -0
- package/evals/fixtures/tiny-post-setup-invalid-config-app/src/auth-middleware.ts +12 -0
- package/evals/fixtures/tiny-post-setup-invalid-config-app/src/billing.ts +20 -0
- package/evals/fixtures/tiny-post-setup-invalid-config-app/src/login-copy.ts +1 -0
- package/evals/fixtures/tiny-post-setup-invalid-config-app/src/settings-page.ts +1 -0
- package/evals/fixtures/tiny-post-setup-invalid-config-app/tests/auth-middleware.test.md +8 -0
- package/evals/fixtures/tiny-post-setup-invalid-config-app/tests/billing.test.md +8 -0
- package/evals/fixtures/tiny-post-setup-invalid-config-app/tests/copy.test.md +7 -0
- package/evals/fixtures/tiny-post-setup-missing-config-app/AGENTS.md +15 -0
- package/evals/fixtures/tiny-post-setup-missing-config-app/README.md +16 -0
- package/evals/fixtures/tiny-post-setup-missing-config-app/docs/auth-review.md +15 -0
- package/evals/fixtures/tiny-post-setup-missing-config-app/docs/billing-policy.md +10 -0
- package/evals/fixtures/tiny-post-setup-missing-config-app/docs/copy-conventions.md +15 -0
- package/evals/fixtures/tiny-post-setup-missing-config-app/src/auth-middleware.ts +12 -0
- package/evals/fixtures/tiny-post-setup-missing-config-app/src/billing.ts +20 -0
- package/evals/fixtures/tiny-post-setup-missing-config-app/src/login-copy.ts +1 -0
- package/evals/fixtures/tiny-post-setup-missing-config-app/src/settings-page.ts +1 -0
- package/evals/fixtures/tiny-post-setup-missing-config-app/tests/auth-middleware.test.md +8 -0
- package/evals/fixtures/tiny-post-setup-missing-config-app/tests/billing.test.md +8 -0
- package/evals/fixtures/tiny-post-setup-missing-config-app/tests/copy.test.md +7 -0
- package/evals/fixtures/tiny-post-setup-source-conflict-app/.freeflow/config.json +3 -0
- package/evals/fixtures/tiny-post-setup-source-conflict-app/AGENTS.md +15 -0
- package/evals/fixtures/tiny-post-setup-source-conflict-app/README.md +16 -0
- package/evals/fixtures/tiny-post-setup-source-conflict-app/docs/auth-review.md +15 -0
- package/evals/fixtures/tiny-post-setup-source-conflict-app/docs/billing-policy.md +10 -0
- package/evals/fixtures/tiny-post-setup-source-conflict-app/docs/copy-conventions.md +15 -0
- package/evals/fixtures/tiny-post-setup-source-conflict-app/src/auth-middleware.ts +12 -0
- package/evals/fixtures/tiny-post-setup-source-conflict-app/src/billing.ts +20 -0
- package/evals/fixtures/tiny-post-setup-source-conflict-app/src/login-copy.ts +1 -0
- package/evals/fixtures/tiny-post-setup-source-conflict-app/src/settings-page.ts +1 -0
- package/evals/fixtures/tiny-post-setup-source-conflict-app/tests/auth-middleware.test.md +8 -0
- package/evals/fixtures/tiny-post-setup-source-conflict-app/tests/billing.test.md +8 -0
- package/evals/fixtures/tiny-post-setup-source-conflict-app/tests/copy.test.md +7 -0
- package/evals/fixtures/tiny-report-performance-app/README.md +11 -0
- package/evals/fixtures/tiny-report-performance-app/docs/performance.md +10 -0
- package/evals/fixtures/tiny-report-performance-app/src/report-summary.ts +29 -0
- package/evals/fixtures/tiny-report-performance-app/tests/report-performance.test.md +8 -0
- package/evals/fixtures/tiny-review-request-app/README.md +3 -0
- package/evals/fixtures/tiny-review-request-app/docs/billing-policy.md +5 -0
- package/evals/fixtures/tiny-review-request-app/docs/plans/billing-webhook-api.md +19 -0
- package/evals/fixtures/tiny-review-request-app/docs/review/previous-agent-summary.md +20 -0
- package/evals/fixtures/tiny-review-request-app/docs/specs/billing-webhook-api.md +25 -0
- package/evals/fixtures/tiny-review-request-app/src/billing.ts +11 -0
- package/evals/fixtures/tiny-review-request-app/src/webhooks.ts +19 -0
- package/evals/fixtures/tiny-review-request-app/tests/billing-webhook.test.md +8 -0
- package/evals/fixtures/tiny-review-work-app/README.md +5 -0
- package/evals/fixtures/tiny-review-work-app/docs/billing-policy.md +9 -0
- package/evals/fixtures/tiny-review-work-app/docs/plans/settings-title-plan.md +12 -0
- package/evals/fixtures/tiny-review-work-app/docs/review/previous-agent-summary.md +15 -0
- package/evals/fixtures/tiny-review-work-app/docs/specs/settings-title.md +9 -0
- package/evals/fixtures/tiny-review-work-app/src/billing.ts +7 -0
- package/evals/fixtures/tiny-review-work-app/src/settings-page.ts +1 -0
- package/evals/fixtures/tiny-review-work-app/tests/billing.test.md +7 -0
- package/evals/fixtures/tiny-review-work-app/tests/settings.test.md +5 -0
- package/evals/fixtures/tiny-saas-app/README.md +16 -0
- package/evals/fixtures/tiny-saas-app/docs/auth-review.md +15 -0
- package/evals/fixtures/tiny-saas-app/docs/billing-policy.md +10 -0
- package/evals/fixtures/tiny-saas-app/docs/copy-conventions.md +15 -0
- package/evals/fixtures/tiny-saas-app/docs/specs/settings-title.md +13 -0
- package/evals/fixtures/tiny-saas-app/src/auth-middleware.ts +12 -0
- package/evals/fixtures/tiny-saas-app/src/billing.ts +20 -0
- package/evals/fixtures/tiny-saas-app/src/login-copy.ts +1 -0
- package/evals/fixtures/tiny-saas-app/src/settings-page.ts +1 -0
- package/evals/fixtures/tiny-saas-app/tests/auth-middleware.test.md +8 -0
- package/evals/fixtures/tiny-saas-app/tests/billing.test.md +8 -0
- package/evals/fixtures/tiny-saas-app/tests/copy.test.md +7 -0
- package/evals/fixtures/tiny-setup-agents-app/AGENTS.md +6 -0
- package/evals/fixtures/tiny-setup-both-app/AGENTS.md +5 -0
- package/evals/fixtures/tiny-setup-both-app/CLAUDE.md +5 -0
- package/evals/fixtures/tiny-setup-claude-app/CLAUDE.md +6 -0
- package/evals/fixtures/tiny-setup-codex-rules-app/.codex/rules/shell.rules +5 -0
- package/evals/fixtures/tiny-setup-codex-rules-app/AGENTS.md +6 -0
- package/evals/fixtures/tiny-setup-conflict-app/AGENTS.md +6 -0
- package/evals/fixtures/tiny-setup-existing-block-app/AGENTS.md +14 -0
- package/evals/fixtures/tiny-setup-four-rules-app/CLAUDE.md +6 -0
- package/evals/fixtures/tiny-skill-dev-app/README.md +10 -0
- package/evals/fixtures/tiny-skill-dev-app/evals/prompts/review-pr-001.txt +8 -0
- package/evals/fixtures/tiny-skill-dev-app/evals/reports/review-pr-failure.md +17 -0
- package/evals/fixtures/tiny-skill-dev-app/skills/review-pr/SKILL.md +13 -0
- package/evals/fixtures/tiny-team-app/README.md +5 -0
- package/evals/fixtures/tiny-team-app/docs/product.md +6 -0
- package/evals/fixtures/tiny-team-app/src/teams.ts +9 -0
- package/evals/fixtures/tiny-team-app/src/users.ts +5 -0
- package/evals/fixtures/tiny-team-app/tests/teams.test.md +7 -0
- package/evals/fixtures/tiny-verify-app/README.md +5 -0
- package/evals/fixtures/tiny-verify-app/src/settings-nav.ts +1 -0
- package/evals/fixtures/tiny-verify-app/src/settings-page.ts +1 -0
- package/evals/fixtures/tiny-verify-app/tests/settings.test.md +7 -0
- package/evals/prompts/aon-001.txt +2 -0
- package/evals/prompts/byp-001.txt +2 -0
- package/evals/prompts/byp-002.txt +2 -0
- package/evals/prompts/cap-001.txt +3 -0
- package/evals/prompts/cap-002.txt +3 -0
- package/evals/prompts/cmd-001.txt +3 -0
- package/evals/prompts/cmd-002.txt +3 -0
- package/evals/prompts/cmd-003.txt +6 -0
- package/evals/prompts/cmd-004.txt +5 -0
- package/evals/prompts/cmd-005.txt +5 -0
- package/evals/prompts/cmd-006.txt +5 -0
- package/evals/prompts/cmd-007.txt +5 -0
- package/evals/prompts/cmd-008.txt +5 -0
- package/evals/prompts/cmd-009.txt +8 -0
- package/evals/prompts/cmd-010.txt +5 -0
- package/evals/prompts/cmd-011.txt +5 -0
- package/evals/prompts/cmd-012.txt +5 -0
- package/evals/prompts/cmd-013.txt +5 -0
- package/evals/prompts/cmd-014.txt +7 -0
- package/evals/prompts/cmd-015.txt +7 -0
- package/evals/prompts/cmd-016.txt +5 -0
- package/evals/prompts/cmt-001.txt +1 -0
- package/evals/prompts/cmt-002.txt +1 -0
- package/evals/prompts/cmt-003.txt +1 -0
- package/evals/prompts/cmt-004.txt +1 -0
- package/evals/prompts/cmt-005.txt +1 -0
- package/evals/prompts/dfd-001.txt +3 -0
- package/evals/prompts/dia-001.txt +3 -0
- package/evals/prompts/dia-002.txt +3 -0
- package/evals/prompts/dia-003.txt +3 -0
- package/evals/prompts/dis-001.txt +5 -0
- package/evals/prompts/dis-002.txt +5 -0
- package/evals/prompts/esk-001.txt +5 -0
- package/evals/prompts/esk-002.txt +5 -0
- package/evals/prompts/esk-003.txt +5 -0
- package/evals/prompts/grc-001.txt +3 -0
- package/evals/prompts/hof-001.txt +3 -0
- package/evals/prompts/hof-002.txt +1 -0
- package/evals/prompts/hof-003.txt +1 -0
- package/evals/prompts/hof-004.txt +1 -0
- package/evals/prompts/hof-005.txt +1 -0
- package/evals/prompts/ivg-001.txt +1 -0
- package/evals/prompts/ivg-002.txt +11 -0
- package/evals/prompts/ivg-003.txt +1 -0
- package/evals/prompts/ivg-004.txt +1 -0
- package/evals/prompts/mode-001.txt +3 -0
- package/evals/prompts/mode-002.txt +1 -0
- package/evals/prompts/mode-003.txt +3 -0
- package/evals/prompts/mode-004.txt +3 -0
- package/evals/prompts/mode-005.txt +3 -0
- package/evals/prompts/mode-006.txt +3 -0
- package/evals/prompts/mode-007.txt +3 -0
- package/evals/prompts/otr-001.txt +3 -0
- package/evals/prompts/otr-002.txt +3 -0
- package/evals/prompts/rar-001.txt +5 -0
- package/evals/prompts/rar-002.txt +3 -0
- package/evals/prompts/rar-003.txt +6 -0
- package/evals/prompts/rar-004.txt +15 -0
- package/evals/prompts/rar-005.txt +10 -0
- package/evals/prompts/rbr-001.txt +3 -0
- package/evals/prompts/rbr-002.txt +3 -0
- package/evals/prompts/rbr-003.txt +7 -0
- package/evals/prompts/rev-001.txt +3 -0
- package/evals/prompts/rev-002.txt +5 -0
- package/evals/prompts/rev-003.txt +6 -0
- package/evals/prompts/rev-004.txt +1 -0
- package/evals/prompts/rev-005.txt +15 -0
- package/evals/prompts/rev-006.txt +5 -0
- package/evals/prompts/stp-001.txt +1 -0
- package/evals/prompts/stp-002.txt +1 -0
- package/evals/prompts/stp-003.txt +1 -0
- package/evals/prompts/stp-004.txt +1 -0
- package/evals/prompts/stp-005.txt +1 -0
- package/evals/prompts/stp-006.txt +1 -0
- package/evals/prompts/stp-007.txt +1 -0
- package/evals/prompts/stp-008.txt +1 -0
- package/evals/prompts/stp-009.txt +1 -0
- package/evals/prompts/stp-010.txt +1 -0
- package/evals/prompts/stp-011.txt +1 -0
- package/evals/prompts/vfy-003.txt +1 -0
- package/evals/prompts/wpl-001.txt +3 -0
- package/evals/prompts/wpl-002.txt +5 -0
- package/evals/prompts/wpl-003.txt +3 -0
- package/evals/prompts/wpl-004.txt +5 -0
- package/evals/prompts/wpl-005.txt +1 -0
- package/evals/prompts/wrc-001.txt +10 -0
- package/evals/prompts/wrc-002.txt +3 -0
- package/evals/prompts/wsk-001.txt +6 -0
- package/evals/prompts/wsp-001.txt +5 -0
- package/evals/prompts/wsp-002.txt +15 -0
- package/evals/prompts/wsp-003.txt +3 -0
- package/evals/prompts/wsp-004.txt +15 -0
- package/evals/prompts/wsp-005.txt +5 -0
- package/evals/prompts/wsp-006.txt +12 -0
- package/evals/prompts/wsp-007.txt +9 -0
- package/evals/prompts/wsp-008.txt +13 -0
- package/evals/prompts/xpl-001.txt +1 -0
- package/evals/prompts/xpl-002.txt +3 -0
- package/evals/prompts/xpl-003.txt +3 -0
- package/evals/prompts/xpl-004.txt +3 -0
- package/evals/prompts/xpl-005.txt +5 -0
- package/evals/prompts/xpl-006.txt +3 -0
- package/evals/registries/adversarial-evals.json +39 -0
- package/evals/registries/fixture-evals.json +2513 -0
- package/evals/registries/handoff-evals.json +74 -0
- package/evals/registries/legacy-evals.json +147 -0
- package/evals/registries/skill-evidence.json +193 -0
- package/evals/registries/verify-work-evals.json +46 -0
- package/evals/reports/acceptance/v0.1-acceptance-report.md +130 -0
- package/evals/reports/by-command-surface/command-surface-1-report.md +45 -0
- package/evals/reports/by-command-surface/command-surface-10-report.md +76 -0
- package/evals/reports/by-command-surface/command-surface-11-report.md +77 -0
- package/evals/reports/by-command-surface/command-surface-12-report.md +91 -0
- package/evals/reports/by-command-surface/command-surface-13-report.md +64 -0
- package/evals/reports/by-command-surface/command-surface-14-report.md +66 -0
- package/evals/reports/by-command-surface/command-surface-15-report.md +124 -0
- package/evals/reports/by-command-surface/command-surface-16-report.md +39 -0
- package/evals/reports/by-command-surface/command-surface-2-report.md +80 -0
- package/evals/reports/by-command-surface/command-surface-3-report.md +86 -0
- package/evals/reports/by-command-surface/command-surface-4-report.md +76 -0
- package/evals/reports/by-command-surface/command-surface-5-report.md +80 -0
- package/evals/reports/by-command-surface/command-surface-6-report.md +74 -0
- package/evals/reports/by-command-surface/command-surface-7-report.md +84 -0
- package/evals/reports/by-command-surface/command-surface-8-report.md +79 -0
- package/evals/reports/by-command-surface/command-surface-9-report.md +79 -0
- package/evals/reports/by-command-surface/command-surface-matrix.md +91 -0
- package/evals/reports/by-skill/bypass-1-report.md +124 -0
- package/evals/reports/by-skill/capture-decisions-1-report.md +99 -0
- package/evals/reports/by-skill/capture-decisions-2-report.md +102 -0
- package/evals/reports/by-skill/commit-work-1-report.md +165 -0
- package/evals/reports/by-skill/commit-work-2-report.md +109 -0
- package/evals/reports/by-skill/design-for-depth-1-report.md +95 -0
- package/evals/reports/by-skill/diagnose-failure-1-report.md +91 -0
- package/evals/reports/by-skill/diagnose-failure-2-report.md +94 -0
- package/evals/reports/by-skill/discover-1-report.md +118 -0
- package/evals/reports/by-skill/evaluate-skill-2-report.md +71 -0
- package/evals/reports/by-skill/execute-plan-1-report.md +103 -0
- package/evals/reports/by-skill/execute-plan-2-report.md +112 -0
- package/evals/reports/by-skill/execute-plan-3-report.md +87 -0
- package/evals/reports/by-skill/grill-context-1-report.md +103 -0
- package/evals/reports/by-skill/handoff-1-report.md +123 -0
- package/evals/reports/by-skill/handoff-2-report.md +105 -0
- package/evals/reports/by-skill/handoff-3-report.md +100 -0
- package/evals/reports/by-skill/handoff-7-report.md +77 -0
- package/evals/reports/by-skill/interview-gate-1-report.md +63 -0
- package/evals/reports/by-skill/interview-gate-2-report.md +105 -0
- package/evals/reports/by-skill/mode-contract-1-report.md +74 -0
- package/evals/reports/by-skill/mode-contract-2-report.md +87 -0
- package/evals/reports/by-skill/mode-contract-3-report.md +65 -0
- package/evals/reports/by-skill/mode-contract-4-report.md +71 -0
- package/evals/reports/by-skill/mode-contract-5-report.md +70 -0
- package/evals/reports/by-skill/output-router-1-report.md +76 -0
- package/evals/reports/by-skill/output-router-2-report.md +65 -0
- package/evals/reports/by-skill/research-1-report.md +144 -0
- package/evals/reports/by-skill/research-brief-1-report.md +94 -0
- package/evals/reports/by-skill/research-brief-2-report.md +75 -0
- package/evals/reports/by-skill/review-artifact-1-report.md +91 -0
- package/evals/reports/by-skill/review-artifact-2-report.md +79 -0
- package/evals/reports/by-skill/review-artifact-3-report.md +120 -0
- package/evals/reports/by-skill/review-artifact-4-report.md +89 -0
- package/evals/reports/by-skill/review-artifact-5-report.md +66 -0
- package/evals/reports/by-skill/review-work-1-report.md +85 -0
- package/evals/reports/by-skill/review-work-2-report.md +87 -0
- package/evals/reports/by-skill/review-work-3-report.md +104 -0
- package/evals/reports/by-skill/review-work-4-report.md +108 -0
- package/evals/reports/by-skill/review-work-5-report.md +73 -0
- package/evals/reports/by-skill/review-work-6-report.md +66 -0
- package/evals/reports/by-skill/setup-freeflow-1-report.md +199 -0
- package/evals/reports/by-skill/setup-freeflow-2-report.md +105 -0
- package/evals/reports/by-skill/setup-freeflow-3-report.md +105 -0
- package/evals/reports/by-skill/setup-freeflow-4-report.md +88 -0
- package/evals/reports/by-skill/setup-freeflow-5-report.md +115 -0
- package/evals/reports/by-skill/skill-authoring-1-report.md +81 -0
- package/evals/reports/by-skill/verify-work-1-report.md +111 -0
- package/evals/reports/by-skill/verify-work-2-report.md +120 -0
- package/evals/reports/by-skill/workflow-1-report.md +65 -0
- package/evals/reports/by-skill/write-plan-1-report.md +123 -0
- package/evals/reports/by-skill/write-plan-2-report.md +98 -0
- package/evals/reports/by-skill/write-plan-3-report.md +110 -0
- package/evals/reports/by-skill/write-spec-1-report.md +88 -0
- package/evals/reports/by-skill/write-spec-2-report.md +89 -0
- package/evals/reports/by-skill/write-spec-3-report.md +90 -0
- package/evals/reports/by-skill/write-spec-4-report.md +167 -0
- package/evals/reports/harness/claude-harness-1-report.md +103 -0
- package/evals/reports/harness/eval-harness-1-report.md +91 -0
- package/evals/reports/iterations/iteration-1-report.md +71 -0
- package/evals/reports/iterations/iteration-2-report.md +78 -0
- package/evals/reports/iterations/iteration-3-report.md +118 -0
- package/evals/reports/iterations/iteration-4-report.md +131 -0
- package/evals/reports/iterations/iteration-5-report.md +149 -0
- package/evals/reports/iterations/iteration-6-report.md +136 -0
- package/evals/reports/runtime/always-on-runtime-1-report.md +107 -0
- package/evals/reports/runtime/context-mode-normalized-benchmark-1-report.md +52 -0
- package/evals/reports/runtime/context-mode-real-deep-baseline-1-report.md +410 -0
- package/evals/reports/runtime/context-mode-real-deep-final-slice-11-report.md +203 -0
- package/evals/reports/runtime/context-mode-real-deep-final-slice-11-review.md +51 -0
- package/evals/reports/runtime/context-saving-native-tools-baseline-1-report.md +99 -0
- package/evals/reports/runtime/eryx-python-compatibility-reprobe-1-report.md +166 -0
- package/evals/reports/runtime/eryx-python-proof-spike-1-report.md +96 -0
- package/evals/reports/runtime/eryx-python-proof-spike-2-report.md +151 -0
- package/evals/reports/runtime/eryx-python-script-derive-execution-1-report.md +233 -0
- package/evals/reports/runtime/jq-script-derive-execution-1-report.md +215 -0
- package/evals/reports/runtime/jq-wasm-proof-spike-1-report.md +67 -0
- package/evals/reports/runtime/output-router-benchmark-1-report.md +81 -0
- package/evals/reports/runtime/output-router-capture-derive-provider-eval-1-report.md +35 -0
- package/evals/reports/runtime/output-router-codex-large-index-sqlite-adhoc-report.md +150 -0
- package/evals/reports/runtime/output-router-codex-qa-benchmark-1-report.md +46 -0
- package/evals/reports/runtime/output-router-command-benchmark-1-report.md +62 -0
- package/evals/reports/runtime/output-router-index-benchmark-1-report.md +64 -0
- package/evals/reports/runtime/output-router-regression-1-report.md +81 -0
- package/evals/reports/runtime/output-router-transform-eval-1-report.md +28 -0
- package/evals/reports/runtime/pi-observed-routing-eval-1-report.md +44 -0
- package/evals/reports/runtime/quickjs-script-derive-execution-1-report.md +159 -0
- package/evals/reports/runtime/quickjs-wasi-proof-spike-1-report.md +55 -0
- package/evals/reports/runtime/render-format-row-protocol-1-report.md +58 -0
- package/evals/reports/runtime/script-sandbox-adapter-selection-review-1-report.md +84 -0
- package/evals/reports/runtime/script-sandbox-probe-resource-hardening-1-report.md +51 -0
- package/evals/reports/runtime/storage-policy-benchmark-1-report.md +176 -0
- package/evals/reports/runtime/vault-index-storage-spike-1-report.md +39 -0
- package/evals/reports/runtime/workflow-context-hook-1-report.md +82 -0
- package/evals/runbooks/adversarial-eval-runbook.md +28 -0
- package/evals/runbooks/fixture-eval-runbook.md +137 -0
- package/evals/runbooks/handoff-eval-runbook.md +22 -0
- package/evals/runbooks/verify-work-eval-runbook.md +27 -0
- package/evals/scripts/audit-command-surface.sh +160 -0
- package/evals/scripts/check-activation-contract.sh +121 -0
- package/evals/scripts/check-runtime-context-hook.sh +183 -0
- package/evals/scripts/grade-fixture-eval.sh +446 -0
- package/evals/scripts/run-claude-fixture-eval.sh +26 -0
- package/evals/scripts/run-codex-fixture-eval.sh +26 -0
- package/evals/scripts/run-eryx-python-proof-spike.js +559 -0
- package/evals/scripts/run-fixture-eval-by-id.sh +23 -0
- package/evals/scripts/run-fixture-eval.sh +464 -0
- package/evals/scripts/run-jq-wasm-proof-spike.js +299 -0
- package/evals/scripts/run-output-router-transform-eval.js +115 -0
- package/evals/scripts/run-pi-observed-routing-eval.js +478 -0
- package/evals/scripts/run-quickjs-wasi-proof-spike.js +339 -0
- package/evals/scripts/skill-evidence.sh +316 -0
- package/evals/scripts/validate-release-metadata.sh +486 -0
- package/evals/suites/v0.1-acceptance-suite.md +131 -0
- package/{plugins/freeflow/hooks → hooks}/freeflow-runtime-context.mjs +65 -14
- package/package.json +46 -13
- package/pi-extension/dist/host-producer-identification.js +186 -0
- package/pi-extension/dist/index.js +85 -0
- package/pi-extension/dist/mcp-config.js +30 -0
- package/pi-extension/dist/native-safety-net.js +209 -0
- package/pi-extension/dist/observed-tool-routing.js +114 -0
- package/pi-extension/dist/renderers.js +835 -0
- package/pi-extension/dist/router-tools.js +438 -0
- package/pi-extension/dist/runtime-context.js +288 -0
- package/pi-extension/dist/schemas.js +254 -0
- package/pi-extension/dist/status.js +449 -0
- package/pi-extension/dist/utils.js +467 -0
- package/pi-extension/src/host-producer-identification.ts +226 -0
- package/pi-extension/src/index.ts +121 -0
- package/pi-extension/src/mcp-config.ts +32 -0
- package/pi-extension/src/native-safety-net.ts +252 -0
- package/pi-extension/src/observed-tool-routing.ts +126 -0
- package/pi-extension/src/renderers.ts +917 -0
- package/pi-extension/src/router-tools.ts +478 -0
- package/pi-extension/src/runtime-context.ts +347 -0
- package/pi-extension/src/schemas.ts +259 -0
- package/pi-extension/src/status.ts +505 -0
- package/pi-extension/src/utils.ts +492 -0
- package/pi-extension/tsconfig.json +16 -0
- package/plugin-docs/README.md +40 -0
- package/plugin-docs/adr/0002-evals-before-hooks.md +17 -0
- package/{plugins/freeflow/docs → plugin-docs}/adr/0003-release-boundary.md +2 -2
- package/plugin-docs/adr/0004-discover-replaces-shallow-discovery-skills.md +26 -0
- package/plugin-docs/adr/README.md +10 -0
- package/plugin-docs/architecture.md +89 -0
- package/plugin-docs/output-router.md +396 -0
- package/plugin-docs/release-evidence.md +77 -0
- package/{plugins/freeflow/docs → plugin-docs}/skills.md +7 -7
- package/{plugins/freeflow/docs → plugin-docs}/workflow.md +4 -4
- package/router/dist/benchmarks/benchmark-harness.d.ts +32 -0
- package/router/dist/benchmarks/benchmark-harness.js +92 -0
- package/router/dist/benchmarks/benchmarks.d.ts +102 -0
- package/router/dist/benchmarks/benchmarks.js +880 -0
- package/router/dist/benchmarks/codex-qa-benchmarks.d.ts +91 -0
- package/router/dist/benchmarks/codex-qa-benchmarks.js +461 -0
- package/router/dist/benchmarks/command-benchmarks.d.ts +128 -0
- package/router/dist/benchmarks/command-benchmarks.js +653 -0
- package/router/dist/benchmarks/context-mode-normalized-benchmarks.d.ts +74 -0
- package/router/dist/benchmarks/context-mode-normalized-benchmarks.js +707 -0
- package/router/dist/benchmarks/context-mode-real-deep-benchmark.d.ts +124 -0
- package/router/dist/benchmarks/context-mode-real-deep-benchmark.js +1295 -0
- package/router/dist/benchmarks/context-saving-baseline.d.ts +54 -0
- package/router/dist/benchmarks/context-saving-baseline.js +439 -0
- package/router/dist/benchmarks/index-benchmarks.d.ts +98 -0
- package/router/dist/benchmarks/index-benchmarks.js +762 -0
- package/router/dist/benchmarks/storage-policy-benchmarks.d.ts +90 -0
- package/router/dist/benchmarks/storage-policy-benchmarks.js +538 -0
- package/router/dist/benchmarks/vault-index-benchmarks.d.ts +47 -0
- package/router/dist/benchmarks/vault-index-benchmarks.js +257 -0
- package/router/dist/config/config.d.ts +96 -0
- package/router/dist/config/config.js +453 -0
- package/router/dist/config/router-contract.d.ts +10 -0
- package/router/dist/config/router-contract.js +54 -0
- package/router/dist/config/schema.d.ts +18 -0
- package/router/dist/config/schema.js +600 -0
- package/router/dist/config/types.d.ts +521 -0
- package/router/dist/config/types.js +30 -0
- package/router/dist/evidence/bounded-evidence.d.ts +40 -0
- package/router/dist/evidence/bounded-evidence.js +310 -0
- package/router/dist/evidence/evidence-range-selector.d.ts +22 -0
- package/router/dist/evidence/evidence-range-selector.js +231 -0
- package/router/dist/evidence/evidence-search.d.ts +25 -0
- package/router/dist/evidence/evidence-search.js +466 -0
- package/router/dist/evidence/evidence.d.ts +38 -0
- package/router/dist/evidence/evidence.js +196 -0
- package/router/dist/evidence/failure-contracts.d.ts +27 -0
- package/router/dist/evidence/failure-contracts.js +160 -0
- package/router/dist/evidence/line-ranges.d.ts +22 -0
- package/router/dist/evidence/line-ranges.js +22 -0
- package/router/dist/experiments/local-index.d.ts +58 -0
- package/router/dist/experiments/local-index.js +562 -0
- package/router/dist/index.d.ts +30 -0
- package/router/dist/index.js +32 -0
- package/router/dist/processing/engine.d.ts +108 -0
- package/router/dist/processing/engine.js +435 -0
- package/router/dist/processing/reducers.d.ts +266 -0
- package/router/dist/processing/reducers.js +1495 -0
- package/router/dist/processing/renderers.d.ts +25 -0
- package/router/dist/processing/renderers.js +186 -0
- package/router/dist/processing/scripts.d.ts +78 -0
- package/router/dist/processing/scripts.js +333 -0
- package/router/dist/repo/repo-traversal.d.ts +18 -0
- package/router/dist/repo/repo-traversal.js +242 -0
- package/router/dist/routing/observed-reducers.d.ts +35 -0
- package/router/dist/routing/observed-reducers.js +647 -0
- package/router/dist/routing/observed-routing.d.ts +17 -0
- package/router/dist/routing/observed-routing.js +377 -0
- package/router/dist/routing/parsers.d.ts +16 -0
- package/router/dist/routing/parsers.js +473 -0
- package/router/dist/routing/run-filters.d.ts +56 -0
- package/router/dist/routing/run-filters.js +230 -0
- package/router/dist/routing/run-reducers.d.ts +30 -0
- package/router/dist/routing/run-reducers.js +110 -0
- package/router/dist/sandbox/adapter-roots.d.ts +38 -0
- package/router/dist/sandbox/adapter-roots.js +64 -0
- package/router/dist/sandbox/eryx-python-adapter.d.ts +9 -0
- package/router/dist/sandbox/eryx-python-adapter.js +797 -0
- package/router/dist/sandbox/jq-wasm-adapter.d.ts +9 -0
- package/router/dist/sandbox/jq-wasm-adapter.js +421 -0
- package/router/dist/sandbox/quickjs-wasi-adapter.d.ts +9 -0
- package/router/dist/sandbox/quickjs-wasi-adapter.js +381 -0
- package/router/dist/sandbox/script-sandbox.d.ts +113 -0
- package/router/dist/sandbox/script-sandbox.js +303 -0
- package/router/dist/setup/script-transform-adapters.d.ts +28 -0
- package/router/dist/setup/script-transform-adapters.js +259 -0
- package/router/dist/tools/batch.d.ts +22 -0
- package/router/dist/tools/batch.js +509 -0
- package/router/dist/tools/run.d.ts +50 -0
- package/router/dist/tools/run.js +1219 -0
- package/router/dist/tools/search.d.ts +44 -0
- package/router/dist/tools/search.js +1205 -0
- package/router/dist/transform/engine.d.ts +143 -0
- package/router/dist/transform/engine.js +1955 -0
- package/router/dist/vault/vault-index.d.ts +106 -0
- package/router/dist/vault/vault-index.js +411 -0
- package/router/dist/vault/vault.d.ts +103 -0
- package/router/dist/vault/vault.js +635 -0
- package/{plugins/freeflow/skills → skills}/commit-work/SKILL.md +17 -16
- package/{plugins/freeflow/skills → skills}/commit-work/references/staging-decisions.md +3 -3
- package/skills/design-for-depth/SKILL.md +90 -0
- package/skills/design-for-depth/references/design-pressure-signals.md +265 -0
- package/skills/design-for-depth/references/software-design-philosophy.md +219 -0
- package/{plugins/freeflow/skills → skills}/diagnose-failure/SKILL.md +6 -1
- package/skills/discover/ARTIFACT-DESTINATIONS.md +58 -0
- package/skills/discover/CHECKPOINTS.md +74 -0
- package/skills/discover/SKILL.md +173 -0
- package/skills/execute-plan/SKILL.md +133 -0
- package/skills/execute-plan/references/execution-map.md +122 -0
- package/{plugins/freeflow/skills → skills}/mode-contract/SKILL.md +10 -5
- package/skills/output-router/SKILL.md +202 -0
- package/skills/output-router/references/safety-policy.md +40 -0
- package/{plugins/freeflow/skills → skills}/review-artifact/SKILL.md +37 -1
- package/{plugins/freeflow/skills → skills}/review-artifact/references/reviewer-prompt.md +14 -2
- package/skills/review-work/SKILL.md +101 -0
- package/{plugins/freeflow/skills → skills}/review-work/references/reviewer-prompt.md +8 -0
- package/skills/setup-freeflow/SKILL.md +106 -0
- package/{plugins/freeflow/skills → skills}/setup-freeflow/references/activation-contract.md +14 -8
- package/{plugins/freeflow/skills → skills}/setup-freeflow/references/host-setup.md +5 -3
- package/skills/setup-freeflow/references/output-router-setup.md +102 -0
- package/{plugins/freeflow/skills → skills}/verify-work/SKILL.md +3 -1
- package/{plugins/freeflow/skills → skills}/workflow/SKILL.md +23 -13
- package/{plugins/freeflow/skills → skills}/workflow/references/workflow-map.md +21 -20
- package/{plugins/freeflow/skills → skills}/write-plan/SKILL.md +9 -1
- package/{plugins/freeflow/skills → skills}/write-skill/SKILL.md +1 -1
- package/{plugins/freeflow/skills → skills}/write-spec/SKILL.md +9 -6
- package/plugins/freeflow/docs/README.md +0 -39
- package/plugins/freeflow/docs/adr/0002-evals-before-hooks.md +0 -17
- package/plugins/freeflow/docs/adr/README.md +0 -7
- package/plugins/freeflow/docs/architecture.md +0 -86
- package/plugins/freeflow/docs/release-evidence.md +0 -49
- package/plugins/freeflow/pi-extension/index.js +0 -250
- package/plugins/freeflow/skills/capture-decisions/SKILL.md +0 -95
- package/plugins/freeflow/skills/capture-decisions/references/destination-guide.md +0 -65
- package/plugins/freeflow/skills/execute-plan/SKILL.md +0 -67
- package/plugins/freeflow/skills/grill-context/SKILL.md +0 -79
- package/plugins/freeflow/skills/grill-context/references/approach-framing.md +0 -52
- package/plugins/freeflow/skills/research-brief/SKILL.md +0 -69
- package/plugins/freeflow/skills/review-work/SKILL.md +0 -73
- package/plugins/freeflow/skills/setup-freeflow/SKILL.md +0 -84
- /package/{plugins/freeflow/assets → assets}/freeflow-plugin-icon-transparent.png +0 -0
- /package/{plugins/freeflow/hooks → hooks}/hooks.json +0 -0
- /package/{plugins/freeflow/docs → plugin-docs}/adr/0001-three-modes.md +0 -0
- /package/{plugins/freeflow/skills → skills}/bypass/SKILL.md +0 -0
- /package/{plugins/freeflow/skills → skills}/diagnose-failure/references/feedback-loop-catalog.md +0 -0
- /package/{plugins/freeflow/skills → skills}/diagnose-failure/references/flaky-and-performance.md +0 -0
- /package/{plugins/freeflow/skills → skills}/evaluate-skill/SKILL.md +0 -0
- /package/{plugins/freeflow/skills → skills}/evaluate-skill/references/eval-patterns.md +0 -0
- /package/{plugins/freeflow/skills → skills}/evaluate-skill/references/grading-priority.md +0 -0
- /package/{plugins/freeflow/skills → skills}/handoff/SKILL.md +0 -0
- /package/{plugins/freeflow/skills → skills}/handoff/references/templates.md +0 -0
- /package/{plugins/freeflow/skills → skills}/interview-gate/SKILL.md +0 -0
- /package/{plugins/freeflow/skills → skills}/write-plan/references/plan-shapes.md +0 -0
- /package/{plugins/freeflow/skills → skills}/write-spec/references/artifact-standards.md +0 -0
- /package/{plugins/freeflow/skills → skills}/write-spec/references/spec-shapes.md +0 -0
|
@@ -0,0 +1,1219 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { commandOutputFingerprints, createVault, findExactDuplicateCommandOutput, storeCommandOutput, storeMetadataOutput, storeTextOutput, } from "../vault/vault.js";
|
|
3
|
+
import { DEFAULT_ROUTER_THRESHOLDS, DEFAULT_STORAGE_POLICY } from "../config/config.js";
|
|
4
|
+
import { executeSandboxedScriptOperation, freeflowTransform, validateTransformInput } from "../transform/engine.js";
|
|
5
|
+
import { assembleTextEvidence, byteLength, countLines } from "../evidence/evidence.js";
|
|
6
|
+
import { parseCommandOutput } from "../routing/parsers.js";
|
|
7
|
+
import { applyRunOutputFilters, hasRunOutputFilters, normalizeRunOutputFilters, } from "../routing/run-filters.js";
|
|
8
|
+
import { parserWithReducer, reducerImportantLines, selectRunReducerRoute, } from "../routing/run-reducers.js";
|
|
9
|
+
export async function freeflowRun(options, runner) {
|
|
10
|
+
const preserve = options.preserve ?? "important";
|
|
11
|
+
const producerValidation = normalizeRunProducer(options);
|
|
12
|
+
if (!producerValidation.ok) {
|
|
13
|
+
return runProducerValidationFailureResult({
|
|
14
|
+
preserve,
|
|
15
|
+
message: producerValidation.message,
|
|
16
|
+
path: producerValidation.path,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const runProducer = producerValidation.producer;
|
|
20
|
+
const command = runProducer.command;
|
|
21
|
+
const validationProducer = runProducer.kind === "script" ? { kind: "script", name: `script:${runProducer.script.language}` } : runProducer.producer;
|
|
22
|
+
const filterValidation = normalizeRunOutputFilters(options.filters);
|
|
23
|
+
if (!filterValidation.ok) {
|
|
24
|
+
return commandFilterValidationFailureResult({
|
|
25
|
+
command,
|
|
26
|
+
producer: validationProducer,
|
|
27
|
+
preserve,
|
|
28
|
+
message: filterValidation.message,
|
|
29
|
+
path: filterValidation.path,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const scriptFilterValidation = normalizeRunScriptFilter(options.scriptFilter);
|
|
33
|
+
if (!scriptFilterValidation.ok) {
|
|
34
|
+
return commandScriptFilterValidationFailureResult({
|
|
35
|
+
command,
|
|
36
|
+
producer: validationProducer,
|
|
37
|
+
preserve,
|
|
38
|
+
message: scriptFilterValidation.message,
|
|
39
|
+
path: scriptFilterValidation.path,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const filters = hasRunOutputFilters(filterValidation.filters) ? filterValidation.filters : undefined;
|
|
43
|
+
const scriptFilter = scriptFilterValidation.scriptFilter;
|
|
44
|
+
const thresholds = { ...DEFAULT_ROUTER_THRESHOLDS, ...options.thresholds };
|
|
45
|
+
const vaultOptions = {};
|
|
46
|
+
if (options.vaultRoot !== undefined) {
|
|
47
|
+
vaultOptions.root = options.vaultRoot;
|
|
48
|
+
}
|
|
49
|
+
if (options.vaultRetention !== undefined) {
|
|
50
|
+
vaultOptions.retention = options.vaultRetention;
|
|
51
|
+
}
|
|
52
|
+
const vault = createVault(vaultOptions);
|
|
53
|
+
let runResult;
|
|
54
|
+
let producer = runProducer.kind === "command" ? runProducer.producer : { kind: "script", name: `script:${runProducer.script.language}` };
|
|
55
|
+
let scriptProducer;
|
|
56
|
+
if (runProducer.kind === "command") {
|
|
57
|
+
try {
|
|
58
|
+
const runRequest = { command: runProducer.command };
|
|
59
|
+
if (options.cwd !== undefined) {
|
|
60
|
+
runRequest.cwd = options.cwd;
|
|
61
|
+
}
|
|
62
|
+
if (options.timeoutMs !== undefined) {
|
|
63
|
+
runRequest.timeoutMs = options.timeoutMs;
|
|
64
|
+
}
|
|
65
|
+
runResult = await runner.run(runRequest);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
69
|
+
return {
|
|
70
|
+
toolStatus: "error",
|
|
71
|
+
decisionId: decisionId("run-error", commandText(command), message),
|
|
72
|
+
preserve,
|
|
73
|
+
outputId: "",
|
|
74
|
+
execution: { status: "failed", exitCode: null },
|
|
75
|
+
producer,
|
|
76
|
+
persistence: { status: "not_persisted", recoverability: "none" },
|
|
77
|
+
routing: {
|
|
78
|
+
status: "failed",
|
|
79
|
+
route: "run",
|
|
80
|
+
reason: `Adapter-provided runner failed before command output could be captured: ${message}`,
|
|
81
|
+
},
|
|
82
|
+
recovery: {
|
|
83
|
+
how: "No command output was captured. Retry through the host-approved runner or use the host-native shell tool if direct raw behavior is required.",
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
const scriptExecutionOptions = {
|
|
90
|
+
operation: runScriptProducerOperation(runProducer.script),
|
|
91
|
+
scriptSandboxAdapters: options.scriptSandboxAdapters ?? [],
|
|
92
|
+
};
|
|
93
|
+
const limits = scriptProducerLimits(runProducer.script, options.timeoutMs);
|
|
94
|
+
if (limits !== undefined) {
|
|
95
|
+
Object.assign(scriptExecutionOptions, { limits });
|
|
96
|
+
}
|
|
97
|
+
if (options.scriptTransform !== undefined) {
|
|
98
|
+
Object.assign(scriptExecutionOptions, { scriptTransform: options.scriptTransform });
|
|
99
|
+
}
|
|
100
|
+
const scriptExecution = await executeSandboxedScriptOperation(scriptExecutionOptions);
|
|
101
|
+
scriptProducer = runScriptProducerMetadata(runProducer.script, scriptExecution);
|
|
102
|
+
producer = scriptProducerDescriptor(runProducer.script, scriptExecution);
|
|
103
|
+
if (!scriptExecution.ok) {
|
|
104
|
+
return scriptProducerExecutionFailureResult({
|
|
105
|
+
command,
|
|
106
|
+
preserve,
|
|
107
|
+
producer,
|
|
108
|
+
scriptProducer,
|
|
109
|
+
execution: scriptExecution,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
runResult = scriptExecutionResult(scriptExecution);
|
|
113
|
+
}
|
|
114
|
+
const combined = runResult.combined ?? combineOutputSections(runResult.stdout, runResult.stderr);
|
|
115
|
+
let record;
|
|
116
|
+
let duplicate;
|
|
117
|
+
const fingerprints = commandOutputFingerprints({
|
|
118
|
+
command,
|
|
119
|
+
stdout: runResult.stdout,
|
|
120
|
+
stderr: runResult.stderr,
|
|
121
|
+
combined,
|
|
122
|
+
executionStatus: runResult.executionStatus,
|
|
123
|
+
exitCode: runResult.exitCode,
|
|
124
|
+
...(options.cwd !== undefined ? { cwd: options.cwd } : {}),
|
|
125
|
+
});
|
|
126
|
+
try {
|
|
127
|
+
duplicate = await findExactDuplicateCommandOutput(vault, {
|
|
128
|
+
sessionId: options.sessionId,
|
|
129
|
+
fingerprints,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
duplicate = undefined;
|
|
134
|
+
}
|
|
135
|
+
const storagePolicy = options.storagePolicy ?? DEFAULT_STORAGE_POLICY;
|
|
136
|
+
const storageParser = parseCommandOutput({
|
|
137
|
+
command,
|
|
138
|
+
executionStatus: runResult.executionStatus,
|
|
139
|
+
exitCode: runResult.exitCode,
|
|
140
|
+
stdout: runResult.stdout,
|
|
141
|
+
stderr: runResult.stderr,
|
|
142
|
+
combined,
|
|
143
|
+
...(options.goal !== undefined ? { goal: options.goal } : {}),
|
|
144
|
+
});
|
|
145
|
+
const reducerRoute = selectRunReducerRoute({
|
|
146
|
+
command,
|
|
147
|
+
...(options.goal !== undefined ? { goal: options.goal } : {}),
|
|
148
|
+
executionStatus: runResult.executionStatus,
|
|
149
|
+
stdout: runResult.stdout,
|
|
150
|
+
stderr: runResult.stderr,
|
|
151
|
+
combined,
|
|
152
|
+
preserve,
|
|
153
|
+
thresholds,
|
|
154
|
+
hasFilters: filters !== undefined,
|
|
155
|
+
hasScriptFilter: scriptFilter !== undefined,
|
|
156
|
+
});
|
|
157
|
+
const storageInput = {
|
|
158
|
+
policy: storagePolicy,
|
|
159
|
+
command,
|
|
160
|
+
producerKind: runProducer.kind,
|
|
161
|
+
preserve,
|
|
162
|
+
executionStatus: runResult.executionStatus,
|
|
163
|
+
outputBytes: byteLength(combined),
|
|
164
|
+
outputLines: countLines(combined),
|
|
165
|
+
thresholds,
|
|
166
|
+
parserName: storageParser.parser.name,
|
|
167
|
+
hasFilters: filters !== undefined,
|
|
168
|
+
hasScriptFilter: scriptFilter !== undefined,
|
|
169
|
+
hasReducer: reducerRoute.status === "selected",
|
|
170
|
+
};
|
|
171
|
+
if (options.goal !== undefined) {
|
|
172
|
+
Object.assign(storageInput, { goal: options.goal });
|
|
173
|
+
}
|
|
174
|
+
if (duplicate !== undefined) {
|
|
175
|
+
Object.assign(storageInput, { duplicate });
|
|
176
|
+
}
|
|
177
|
+
const storageDecision = decideCommandStorage(storageInput);
|
|
178
|
+
const execution = {
|
|
179
|
+
status: runResult.executionStatus,
|
|
180
|
+
exitCode: runResult.exitCode,
|
|
181
|
+
};
|
|
182
|
+
if (runResult.durationMs !== undefined) {
|
|
183
|
+
Object.assign(execution, { durationMs: runResult.durationMs });
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
const storeOptions = {
|
|
187
|
+
sessionId: options.sessionId,
|
|
188
|
+
command,
|
|
189
|
+
stdout: runResult.stdout,
|
|
190
|
+
stderr: runResult.stderr,
|
|
191
|
+
combined,
|
|
192
|
+
executionStatus: runResult.executionStatus,
|
|
193
|
+
exitCode: runResult.exitCode,
|
|
194
|
+
decisionIds: [decisionId("run", commandText(command), options.sessionId)],
|
|
195
|
+
producer,
|
|
196
|
+
};
|
|
197
|
+
if (options.cwd !== undefined) {
|
|
198
|
+
Object.assign(storeOptions, { cwd: options.cwd });
|
|
199
|
+
}
|
|
200
|
+
if (runResult.durationMs !== undefined) {
|
|
201
|
+
Object.assign(storeOptions, { durationMs: runResult.durationMs });
|
|
202
|
+
}
|
|
203
|
+
const metadataStoreOptions = {
|
|
204
|
+
vault,
|
|
205
|
+
sessionId: options.sessionId,
|
|
206
|
+
command,
|
|
207
|
+
runResult,
|
|
208
|
+
combined,
|
|
209
|
+
fingerprints,
|
|
210
|
+
storageDecision,
|
|
211
|
+
parserName: storageParser.parser.name,
|
|
212
|
+
producer,
|
|
213
|
+
};
|
|
214
|
+
if (options.cwd !== undefined) {
|
|
215
|
+
Object.assign(metadataStoreOptions, { cwd: options.cwd });
|
|
216
|
+
}
|
|
217
|
+
record = storageDecision.mode === "exact"
|
|
218
|
+
? await storeCommandOutput(vault, storeOptions)
|
|
219
|
+
: await storeCommandMetadataOutput(metadataStoreOptions);
|
|
220
|
+
const routeOptions = {
|
|
221
|
+
outputId: record.outputId,
|
|
222
|
+
command,
|
|
223
|
+
executionStatus: runResult.executionStatus,
|
|
224
|
+
exitCode: runResult.exitCode,
|
|
225
|
+
stdout: runResult.stdout,
|
|
226
|
+
stderr: runResult.stderr,
|
|
227
|
+
combined,
|
|
228
|
+
preserve,
|
|
229
|
+
thresholds,
|
|
230
|
+
storage: storageDecision,
|
|
231
|
+
};
|
|
232
|
+
if (filters !== undefined) {
|
|
233
|
+
routeOptions.filters = filters;
|
|
234
|
+
}
|
|
235
|
+
if (options.goal !== undefined) {
|
|
236
|
+
routeOptions.goal = options.goal;
|
|
237
|
+
}
|
|
238
|
+
if (reducerRoute.status === "selected") {
|
|
239
|
+
routeOptions.reducer = reducerRoute;
|
|
240
|
+
}
|
|
241
|
+
let routing;
|
|
242
|
+
const duplicateForRouting = duplicate && preserve !== "full" && filters === undefined && scriptFilter === undefined ? duplicate : undefined;
|
|
243
|
+
if (duplicateForRouting) {
|
|
244
|
+
routing = routeDuplicateCommandOutput({
|
|
245
|
+
outputId: record.outputId,
|
|
246
|
+
duplicate: duplicateForRouting,
|
|
247
|
+
storage: storageDecision,
|
|
248
|
+
command,
|
|
249
|
+
executionStatus: runResult.executionStatus,
|
|
250
|
+
exitCode: runResult.exitCode,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
else if (scriptFilter) {
|
|
254
|
+
const scriptRouteOptions = {
|
|
255
|
+
routeOptions,
|
|
256
|
+
rawRecord: record,
|
|
257
|
+
sessionId: options.sessionId,
|
|
258
|
+
scriptFilter,
|
|
259
|
+
scriptSandboxAdapters: options.scriptSandboxAdapters ?? [],
|
|
260
|
+
};
|
|
261
|
+
if (options.vaultRoot !== undefined) {
|
|
262
|
+
Object.assign(scriptRouteOptions, { vaultRoot: options.vaultRoot });
|
|
263
|
+
}
|
|
264
|
+
if (options.vaultRetention !== undefined) {
|
|
265
|
+
Object.assign(scriptRouteOptions, { vaultRetention: options.vaultRetention });
|
|
266
|
+
}
|
|
267
|
+
if (options.scriptTransform !== undefined) {
|
|
268
|
+
Object.assign(scriptRouteOptions, { scriptTransform: options.scriptTransform });
|
|
269
|
+
}
|
|
270
|
+
routing = await routeScriptFilteredOutput(scriptRouteOptions);
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
if (routeOptions.reducer?.status === "selected" && record.kind === "command" && storageDecision.mode === "exact") {
|
|
274
|
+
routeOptions.reducerRecord = await storeReducerOutput({
|
|
275
|
+
vault,
|
|
276
|
+
sessionId: options.sessionId,
|
|
277
|
+
rawRecord: record,
|
|
278
|
+
reducer: routeOptions.reducer,
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
routing = routeCommandOutput(routeOptions);
|
|
282
|
+
}
|
|
283
|
+
return {
|
|
284
|
+
toolStatus: "ok",
|
|
285
|
+
decisionId: routing.decisionId,
|
|
286
|
+
outputId: record.outputId,
|
|
287
|
+
recordId: record.recordId,
|
|
288
|
+
preserve,
|
|
289
|
+
execution,
|
|
290
|
+
producer: record.producer,
|
|
291
|
+
persistence: record.persistence,
|
|
292
|
+
...(routing.lineage !== undefined ? { lineage: routing.lineage } : record.lineage !== undefined ? { lineage: record.lineage } : {}),
|
|
293
|
+
...(routing.failure !== undefined ? { failure: routing.failure } : {}),
|
|
294
|
+
...(routing.transformExecution !== undefined ? { transformExecution: routing.transformExecution } : {}),
|
|
295
|
+
...(routing.evidence !== undefined ? { evidence: routing.evidence } : {}),
|
|
296
|
+
routing: {
|
|
297
|
+
status: routing.routingStatus,
|
|
298
|
+
route: "run",
|
|
299
|
+
reason: routing.reason,
|
|
300
|
+
},
|
|
301
|
+
summary: routing.summary,
|
|
302
|
+
importantLines: routing.importantLines,
|
|
303
|
+
parser: routing.parser,
|
|
304
|
+
...(routing.filters !== undefined ? { filters: routing.filters } : {}),
|
|
305
|
+
...(scriptProducer !== undefined ? { scriptProducer } : {}),
|
|
306
|
+
...(routing.scriptFilter !== undefined ? { scriptFilter: routing.scriptFilter } : {}),
|
|
307
|
+
...(routing.reducer !== undefined ? { reducer: routing.reducer } : {}),
|
|
308
|
+
recovery: routing.recovery ?? commandRecoveryHint(record.outputId, storageDecision),
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
313
|
+
return commandRoutingFailureResult({
|
|
314
|
+
command,
|
|
315
|
+
outputId: record?.outputId ?? "",
|
|
316
|
+
record,
|
|
317
|
+
preserve,
|
|
318
|
+
execution,
|
|
319
|
+
stdout: runResult.stdout,
|
|
320
|
+
stderr: runResult.stderr,
|
|
321
|
+
combined,
|
|
322
|
+
errorMessage: message,
|
|
323
|
+
storage: storageDecision,
|
|
324
|
+
producer,
|
|
325
|
+
...(scriptProducer !== undefined ? { scriptProducer } : {}),
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function routeDuplicateCommandOutput(options) {
|
|
330
|
+
const currentVaultText = options.storage.mode === "duplicate-metadata"
|
|
331
|
+
? `Current run stored metadata-only as outputId=${options.outputId}; exact raw output remains recoverable from prior outputId=${options.duplicate.outputId}.`
|
|
332
|
+
: options.outputId === options.duplicate.outputId
|
|
333
|
+
? `Current run resolved to the same outputId=${options.outputId}.`
|
|
334
|
+
: `Current raw output was vaulted as outputId=${options.outputId}.`;
|
|
335
|
+
const statusText = `executionStatus=${options.executionStatus} exitCode=${options.exitCode}`;
|
|
336
|
+
return {
|
|
337
|
+
decisionId: decisionId("run-route", options.outputId, "exact-duplicate", options.duplicate.outputId),
|
|
338
|
+
routingStatus: "partial",
|
|
339
|
+
reason: `Exact duplicate run output matched previous outputId=${options.duplicate.outputId} by exact output hash and producer/cwd/status fingerprint (${statusText}); returning a compact duplicate note instead of re-injecting repeated output. ${currentVaultText}`,
|
|
340
|
+
summary: `Run output is an exact duplicate of previous outputId=${options.duplicate.outputId}. ${currentVaultText}`,
|
|
341
|
+
importantLines: [],
|
|
342
|
+
parser: {
|
|
343
|
+
name: "duplicate-output",
|
|
344
|
+
confidence: 1,
|
|
345
|
+
fidelity: "exact",
|
|
346
|
+
compressed: true,
|
|
347
|
+
counts: { duplicateOutputs: 1 },
|
|
348
|
+
},
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
function commandRecoveryHint(outputId, storage) {
|
|
352
|
+
if (storage.mode === "exact") {
|
|
353
|
+
return {
|
|
354
|
+
how: `Use freeflow_search with source.kind=vault and outputId=${outputId} to recover exact run output.`,
|
|
355
|
+
outputId,
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
if (storage.mode === "duplicate-metadata" && storage.exactRecoveryOutputId) {
|
|
359
|
+
return {
|
|
360
|
+
how: `Current run record is metadata-only outputId=${outputId}; exact duplicate raw output is recoverable with freeflow_search source.kind=vault outputId=${storage.exactRecoveryOutputId}.`,
|
|
361
|
+
outputId: storage.exactRecoveryOutputId,
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
return {
|
|
365
|
+
how: `Current run record is metadata-only outputId=${outputId}; exact raw output was not vaulted by storagePolicy=${storage.policy}. Rerun with preserve=full or a verification/diagnosis goal if exact recovery is required.`,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
function commandStorageReason(storage) {
|
|
369
|
+
if (!storage || storage.mode === "exact") {
|
|
370
|
+
return "raw output was vaulted";
|
|
371
|
+
}
|
|
372
|
+
if (storage.mode === "duplicate-metadata" && storage.exactRecoveryOutputId) {
|
|
373
|
+
return `current output was stored as metadata-only with exact duplicate recovery from outputId=${storage.exactRecoveryOutputId}`;
|
|
374
|
+
}
|
|
375
|
+
return `current output was stored as metadata-only by storagePolicy=${storage.policy}; exact raw output was not vaulted`;
|
|
376
|
+
}
|
|
377
|
+
function decideCommandStorage(options) {
|
|
378
|
+
const exactnessSensitive = commandOutputIsExactnessSensitive(options);
|
|
379
|
+
if (options.policy === "store-everything") {
|
|
380
|
+
return { policy: options.policy, mode: "exact", exactnessSensitive, reason: "storagePolicy=store-everything stores every run output exactly." };
|
|
381
|
+
}
|
|
382
|
+
if (!exactnessSensitive) {
|
|
383
|
+
return {
|
|
384
|
+
policy: options.policy,
|
|
385
|
+
mode: "metadata-only",
|
|
386
|
+
exactnessSensitive,
|
|
387
|
+
reason: "Small non-sensitive successful run output is stored metadata-only by storagePolicy=hybrid-dedupe.",
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
if (options.duplicate?.outputId && !options.hasScriptFilter) {
|
|
391
|
+
return {
|
|
392
|
+
policy: options.policy,
|
|
393
|
+
mode: "duplicate-metadata",
|
|
394
|
+
exactnessSensitive,
|
|
395
|
+
exactRecoveryOutputId: options.duplicate.outputId,
|
|
396
|
+
reason: `Exactness-sensitive run output duplicates prior exact outputId=${options.duplicate.outputId}; current record stores metadata only.`,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
return {
|
|
400
|
+
policy: options.policy,
|
|
401
|
+
mode: "exact",
|
|
402
|
+
exactnessSensitive,
|
|
403
|
+
reason: "Run output is exactness-sensitive or large/noisy; storagePolicy=hybrid-dedupe stores it exactly.",
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
function commandOutputIsExactnessSensitive(options) {
|
|
407
|
+
if (options.preserve === "full" || options.executionStatus !== "success" || options.hasFilters || options.hasScriptFilter || options.hasReducer) {
|
|
408
|
+
return true;
|
|
409
|
+
}
|
|
410
|
+
if (options.producerKind === "script") {
|
|
411
|
+
return true;
|
|
412
|
+
}
|
|
413
|
+
if (options.outputBytes > options.thresholds.largeOutputBytes || options.outputLines > options.thresholds.largeOutputLines) {
|
|
414
|
+
return true;
|
|
415
|
+
}
|
|
416
|
+
const goalText = `${options.goal ?? ""} ${commandText(options.command)}`.toLowerCase();
|
|
417
|
+
if (/\b(verify|verification|test|tests|lint|typecheck|type-check|diagnos|debug|build|ci)\b/.test(goalText)) {
|
|
418
|
+
return true;
|
|
419
|
+
}
|
|
420
|
+
return options.parserName !== "generic";
|
|
421
|
+
}
|
|
422
|
+
async function storeCommandMetadataOutput(options) {
|
|
423
|
+
const metadata = {
|
|
424
|
+
storagePolicy: options.storageDecision.policy,
|
|
425
|
+
storageDecision: options.storageDecision.mode,
|
|
426
|
+
storageReason: options.storageDecision.reason,
|
|
427
|
+
command: options.command,
|
|
428
|
+
executionStatus: options.runResult.executionStatus,
|
|
429
|
+
exitCode: options.runResult.exitCode,
|
|
430
|
+
parserName: options.parserName,
|
|
431
|
+
exactnessSensitive: options.storageDecision.exactnessSensitive,
|
|
432
|
+
byteCounts: {
|
|
433
|
+
stdout: byteLength(options.runResult.stdout),
|
|
434
|
+
stderr: byteLength(options.runResult.stderr),
|
|
435
|
+
combined: byteLength(options.combined),
|
|
436
|
+
},
|
|
437
|
+
lineCounts: {
|
|
438
|
+
stdout: countLines(options.runResult.stdout),
|
|
439
|
+
stderr: countLines(options.runResult.stderr),
|
|
440
|
+
combined: countLines(options.combined),
|
|
441
|
+
},
|
|
442
|
+
fingerprints: options.fingerprints,
|
|
443
|
+
};
|
|
444
|
+
if (options.cwd !== undefined) {
|
|
445
|
+
metadata.cwd = options.cwd;
|
|
446
|
+
}
|
|
447
|
+
if (options.runResult.durationMs !== undefined) {
|
|
448
|
+
metadata.durationMs = options.runResult.durationMs;
|
|
449
|
+
}
|
|
450
|
+
if (options.storageDecision.exactRecoveryOutputId !== undefined) {
|
|
451
|
+
metadata.exactRecoveryOutputId = options.storageDecision.exactRecoveryOutputId;
|
|
452
|
+
}
|
|
453
|
+
return storeMetadataOutput(options.vault, {
|
|
454
|
+
sessionId: options.sessionId,
|
|
455
|
+
sourceKind: options.producer.kind === "script" ? "script" : "other",
|
|
456
|
+
rawLineCount: countLines(options.combined),
|
|
457
|
+
rawByteCount: byteLength(options.combined),
|
|
458
|
+
rawSha256: hash(options.combined),
|
|
459
|
+
decisionIds: [decisionId("run-metadata", commandText(options.command), options.sessionId, options.storageDecision.mode)],
|
|
460
|
+
producer: options.producer,
|
|
461
|
+
metadata,
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
function normalizeRunProducer(options) {
|
|
465
|
+
const hasCommand = options.command !== undefined && options.command !== null;
|
|
466
|
+
const hasScript = options.script !== undefined && options.script !== null;
|
|
467
|
+
if (hasCommand === hasScript) {
|
|
468
|
+
return {
|
|
469
|
+
ok: false,
|
|
470
|
+
path: "$",
|
|
471
|
+
message: hasCommand
|
|
472
|
+
? "freeflow_run accepts either command or script, not both."
|
|
473
|
+
: "freeflow_run requires either command or script.",
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
if (hasCommand) {
|
|
477
|
+
const command = options.command;
|
|
478
|
+
if (typeof command === "string") {
|
|
479
|
+
if (command.trim().length === 0) {
|
|
480
|
+
return { ok: false, path: "$.command", message: "Expected non-empty shell command string." };
|
|
481
|
+
}
|
|
482
|
+
return { ok: true, producer: { kind: "command", command, producer: { kind: "command" } } };
|
|
483
|
+
}
|
|
484
|
+
if (Array.isArray(command) && command.length > 0 && command.every((part) => typeof part === "string" && part.length > 0)) {
|
|
485
|
+
return { ok: true, producer: { kind: "command", command, producer: { kind: "command" } } };
|
|
486
|
+
}
|
|
487
|
+
return { ok: false, path: "$.command", message: "Expected non-empty shell command string or command argument array." };
|
|
488
|
+
}
|
|
489
|
+
const scriptValidation = normalizeRunScriptProducer(options.script);
|
|
490
|
+
if (!scriptValidation.ok) {
|
|
491
|
+
return scriptValidation;
|
|
492
|
+
}
|
|
493
|
+
return {
|
|
494
|
+
ok: true,
|
|
495
|
+
producer: {
|
|
496
|
+
kind: "script",
|
|
497
|
+
command: scriptCommandDescriptor(scriptValidation.script),
|
|
498
|
+
script: scriptValidation.script,
|
|
499
|
+
},
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
function normalizeRunScriptProducer(input) {
|
|
503
|
+
if (!isRecord(input)) {
|
|
504
|
+
return { ok: false, path: "$.script", message: "freeflow_run script must be an object." };
|
|
505
|
+
}
|
|
506
|
+
const operation = { kind: "script" };
|
|
507
|
+
if (input.language !== undefined) {
|
|
508
|
+
operation.language = input.language;
|
|
509
|
+
}
|
|
510
|
+
if (input.code !== undefined) {
|
|
511
|
+
operation.code = input.code;
|
|
512
|
+
}
|
|
513
|
+
if (input.label !== undefined) {
|
|
514
|
+
operation.label = input.label;
|
|
515
|
+
}
|
|
516
|
+
const candidate = {
|
|
517
|
+
sources: runScriptFilterSources("ffout_run_script_producer_validation"),
|
|
518
|
+
operation,
|
|
519
|
+
};
|
|
520
|
+
if (input.limits !== undefined) {
|
|
521
|
+
candidate.limits = input.limits;
|
|
522
|
+
}
|
|
523
|
+
const validation = validateTransformInput(candidate);
|
|
524
|
+
if (!validation.ok) {
|
|
525
|
+
const issue = validation.issues[0] ?? { path: "$.script", message: "Invalid script producer." };
|
|
526
|
+
return {
|
|
527
|
+
ok: false,
|
|
528
|
+
path: issue.path.replace(/^\$\.operation/, "$.script").replace(/^\$\.limits/, "$.script.limits"),
|
|
529
|
+
message: issue.message,
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
const script = {
|
|
533
|
+
language: input.language,
|
|
534
|
+
code: input.code,
|
|
535
|
+
};
|
|
536
|
+
if (input.label !== undefined) {
|
|
537
|
+
script.label = input.label;
|
|
538
|
+
}
|
|
539
|
+
if (input.limits !== undefined) {
|
|
540
|
+
script.limits = input.limits;
|
|
541
|
+
}
|
|
542
|
+
return { ok: true, script };
|
|
543
|
+
}
|
|
544
|
+
function runScriptProducerOperation(script) {
|
|
545
|
+
const operation = {
|
|
546
|
+
kind: "script",
|
|
547
|
+
language: script.language,
|
|
548
|
+
code: script.code,
|
|
549
|
+
};
|
|
550
|
+
if (script.label !== undefined) {
|
|
551
|
+
operation.label = script.label;
|
|
552
|
+
}
|
|
553
|
+
return operation;
|
|
554
|
+
}
|
|
555
|
+
function scriptProducerLimits(script, timeoutMs) {
|
|
556
|
+
if (timeoutMs === undefined || script.limits?.timeoutMs !== undefined) {
|
|
557
|
+
return script.limits;
|
|
558
|
+
}
|
|
559
|
+
return { ...(script.limits ?? {}), timeoutMs };
|
|
560
|
+
}
|
|
561
|
+
function scriptExecutionResult(execution) {
|
|
562
|
+
const result = execution.result;
|
|
563
|
+
return {
|
|
564
|
+
stdout: result.stdout ?? "",
|
|
565
|
+
stderr: result.stderr ?? "",
|
|
566
|
+
executionStatus: scriptExecutionStatus(result.status),
|
|
567
|
+
exitCode: result.exitCode ?? (result.status === "success" ? 0 : null),
|
|
568
|
+
combined: combineOutputSections(result.stdout ?? "", result.stderr ?? ""),
|
|
569
|
+
...(result.durationMs !== undefined ? { durationMs: result.durationMs } : {}),
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
function scriptExecutionStatus(status) {
|
|
573
|
+
if (status === "success") {
|
|
574
|
+
return "success";
|
|
575
|
+
}
|
|
576
|
+
if (status === "timed_out") {
|
|
577
|
+
return "timed_out";
|
|
578
|
+
}
|
|
579
|
+
return "failed";
|
|
580
|
+
}
|
|
581
|
+
function runScriptProducerMetadata(script, execution) {
|
|
582
|
+
const metadata = {
|
|
583
|
+
status: execution.ok ? execution.result.status : execution.executionStatus === "unavailable" ? "unavailable" : "failed",
|
|
584
|
+
language: script.language,
|
|
585
|
+
policy: "sandboxed",
|
|
586
|
+
rawScriptPersistence: "disabled",
|
|
587
|
+
codeSha256: scriptCodeSha256(script),
|
|
588
|
+
limits: execution.limits,
|
|
589
|
+
operation: execution.operation,
|
|
590
|
+
};
|
|
591
|
+
if (script.label !== undefined) {
|
|
592
|
+
metadata.label = script.label;
|
|
593
|
+
}
|
|
594
|
+
if (execution.ok) {
|
|
595
|
+
metadata.adapterId = execution.adapterId;
|
|
596
|
+
metadata.adapterVersion = execution.adapterVersion;
|
|
597
|
+
if (execution.runtime !== undefined) {
|
|
598
|
+
metadata.runtime = execution.runtime;
|
|
599
|
+
}
|
|
600
|
+
metadata.stdoutBytes = byteLength(execution.result.stdout ?? "");
|
|
601
|
+
metadata.stderrBytes = byteLength(execution.result.stderr ?? "");
|
|
602
|
+
if (execution.result.exitCode !== undefined) {
|
|
603
|
+
metadata.exitCode = execution.result.exitCode;
|
|
604
|
+
}
|
|
605
|
+
if (execution.result.durationMs !== undefined) {
|
|
606
|
+
metadata.durationMs = execution.result.durationMs;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
else {
|
|
610
|
+
if (execution.adapterId !== undefined) {
|
|
611
|
+
metadata.adapterId = execution.adapterId;
|
|
612
|
+
}
|
|
613
|
+
if (execution.adapterVersion !== undefined) {
|
|
614
|
+
metadata.adapterVersion = execution.adapterVersion;
|
|
615
|
+
}
|
|
616
|
+
metadata.failure = { kind: execution.failureKind, message: execution.message };
|
|
617
|
+
metadata.transformExecution = {
|
|
618
|
+
status: execution.executionStatus,
|
|
619
|
+
failureKind: execution.failureKind,
|
|
620
|
+
message: execution.message,
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
return metadata;
|
|
624
|
+
}
|
|
625
|
+
function scriptProducerDescriptor(script, execution) {
|
|
626
|
+
const descriptor = {
|
|
627
|
+
kind: "script",
|
|
628
|
+
name: script.label ?? `script:${script.language}`,
|
|
629
|
+
};
|
|
630
|
+
if (execution.ok) {
|
|
631
|
+
descriptor.adapter = execution.adapterId;
|
|
632
|
+
}
|
|
633
|
+
else if (execution.adapterId !== undefined) {
|
|
634
|
+
descriptor.adapter = execution.adapterId;
|
|
635
|
+
}
|
|
636
|
+
return descriptor;
|
|
637
|
+
}
|
|
638
|
+
function scriptCommandDescriptor(script) {
|
|
639
|
+
const label = script.label ? ` label=${JSON.stringify(script.label)}` : "";
|
|
640
|
+
return `script:${script.language} code=${scriptCodeSha256(script)}${label}`;
|
|
641
|
+
}
|
|
642
|
+
function scriptCodeSha256(script) {
|
|
643
|
+
return `sha256_${hash(script.code)}`;
|
|
644
|
+
}
|
|
645
|
+
function runProducerValidationFailureResult(options) {
|
|
646
|
+
return {
|
|
647
|
+
toolStatus: "error",
|
|
648
|
+
decisionId: decisionId("run-producer-validation", options.path, options.message),
|
|
649
|
+
outputId: "",
|
|
650
|
+
preserve: options.preserve,
|
|
651
|
+
execution: { status: "failed", exitCode: null },
|
|
652
|
+
producer: { kind: "other", name: "freeflow_run" },
|
|
653
|
+
persistence: { status: "not_persisted", recoverability: "none" },
|
|
654
|
+
routing: {
|
|
655
|
+
status: "failed",
|
|
656
|
+
route: "run",
|
|
657
|
+
reason: `Invalid freeflow_run producer at ${options.path}: ${options.message}`,
|
|
658
|
+
},
|
|
659
|
+
summary: "Run producer was not executed because freeflow_run input was invalid.",
|
|
660
|
+
recovery: {
|
|
661
|
+
how: "No command or script output was captured. Fix the freeflow_run producer input and rerun.",
|
|
662
|
+
},
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
function scriptProducerExecutionFailureResult(options) {
|
|
666
|
+
return {
|
|
667
|
+
toolStatus: "error",
|
|
668
|
+
decisionId: decisionId("run-script-producer", commandText(options.command), options.execution.failureKind, options.execution.message),
|
|
669
|
+
outputId: "",
|
|
670
|
+
preserve: options.preserve,
|
|
671
|
+
execution: { status: "failed", exitCode: null },
|
|
672
|
+
producer: options.producer,
|
|
673
|
+
scriptProducer: options.scriptProducer,
|
|
674
|
+
failure: {
|
|
675
|
+
kind: options.execution.failureKind,
|
|
676
|
+
message: options.execution.message,
|
|
677
|
+
},
|
|
678
|
+
transformExecution: {
|
|
679
|
+
status: options.execution.executionStatus,
|
|
680
|
+
failureKind: options.execution.failureKind,
|
|
681
|
+
message: options.execution.message,
|
|
682
|
+
},
|
|
683
|
+
persistence: { status: "not_persisted", recoverability: "none" },
|
|
684
|
+
routing: {
|
|
685
|
+
status: "failed",
|
|
686
|
+
route: "run",
|
|
687
|
+
reason: `Sandboxed script producer could not execute: ${options.execution.message}`,
|
|
688
|
+
},
|
|
689
|
+
summary: "Script producer was not executed; no stdout/stderr was captured.",
|
|
690
|
+
recovery: {
|
|
691
|
+
how: "No script output was captured. Enable scriptTransform with a proof-backed sandbox adapter, fix the script producer input, or use a shell command when host execution is intentionally required.",
|
|
692
|
+
},
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
function commandFilterValidationFailureResult(options) {
|
|
696
|
+
return {
|
|
697
|
+
toolStatus: "error",
|
|
698
|
+
decisionId: decisionId("run-filter-validation", commandText(options.command), options.path, options.message),
|
|
699
|
+
outputId: "",
|
|
700
|
+
preserve: options.preserve,
|
|
701
|
+
execution: { status: "failed", exitCode: null },
|
|
702
|
+
producer: options.producer,
|
|
703
|
+
persistence: { status: "not_persisted", recoverability: "none" },
|
|
704
|
+
routing: {
|
|
705
|
+
status: "failed",
|
|
706
|
+
route: "run",
|
|
707
|
+
reason: `Invalid freeflow_run filters at ${options.path}: ${options.message}`,
|
|
708
|
+
},
|
|
709
|
+
summary: "Run producer was not executed because freeflow_run filters were invalid.",
|
|
710
|
+
recovery: {
|
|
711
|
+
how: "No command or script output was captured. Fix the declarative filter and rerun through freeflow_run.",
|
|
712
|
+
},
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
function commandScriptFilterValidationFailureResult(options) {
|
|
716
|
+
return {
|
|
717
|
+
toolStatus: "error",
|
|
718
|
+
decisionId: decisionId("run-script-filter-validation", commandText(options.command), options.path, options.message),
|
|
719
|
+
outputId: "",
|
|
720
|
+
preserve: options.preserve,
|
|
721
|
+
execution: { status: "failed", exitCode: null },
|
|
722
|
+
producer: options.producer,
|
|
723
|
+
persistence: { status: "not_persisted", recoverability: "none" },
|
|
724
|
+
routing: {
|
|
725
|
+
status: "failed",
|
|
726
|
+
route: "run",
|
|
727
|
+
reason: `Invalid freeflow_run scriptFilter at ${options.path}: ${options.message}`,
|
|
728
|
+
},
|
|
729
|
+
summary: "Run producer was not executed because freeflow_run scriptFilter was invalid.",
|
|
730
|
+
recovery: {
|
|
731
|
+
how: "No command or script output was captured. Fix the sandboxed script filter and rerun through freeflow_run.",
|
|
732
|
+
},
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
function commandRoutingFailureResult(options) {
|
|
736
|
+
const { stream, text } = routedCommandText({
|
|
737
|
+
outputId: options.outputId,
|
|
738
|
+
command: options.command,
|
|
739
|
+
executionStatus: options.execution.status,
|
|
740
|
+
exitCode: options.execution.exitCode,
|
|
741
|
+
stdout: options.stdout,
|
|
742
|
+
stderr: options.stderr,
|
|
743
|
+
combined: options.combined,
|
|
744
|
+
preserve: options.preserve,
|
|
745
|
+
thresholds: DEFAULT_ROUTER_THRESHOLDS,
|
|
746
|
+
});
|
|
747
|
+
const fallback = assembleTextEvidence({ stream, text });
|
|
748
|
+
const parser = {
|
|
749
|
+
name: "router-fallback",
|
|
750
|
+
confidence: 0,
|
|
751
|
+
fidelity: fallback.fidelity,
|
|
752
|
+
compressed: fallback.compressed,
|
|
753
|
+
};
|
|
754
|
+
const recovery = options.outputId
|
|
755
|
+
? options.storage !== undefined
|
|
756
|
+
? commandRecoveryHint(options.outputId, options.storage)
|
|
757
|
+
: {
|
|
758
|
+
how: `Routing failed after vault capture; use freeflow_search with source.kind=vault and outputId=${options.outputId} to recover exact run output.`,
|
|
759
|
+
outputId: options.outputId,
|
|
760
|
+
}
|
|
761
|
+
: {
|
|
762
|
+
how: "Run output could not be vaulted. A bounded in-memory preview was returned; rerun through the appropriate producer if exact recovery is required.",
|
|
763
|
+
};
|
|
764
|
+
return {
|
|
765
|
+
toolStatus: "error",
|
|
766
|
+
decisionId: decisionId("run-route-error", commandText(options.command), options.errorMessage),
|
|
767
|
+
outputId: options.outputId,
|
|
768
|
+
...(options.record !== undefined ? { recordId: options.record.recordId } : {}),
|
|
769
|
+
preserve: options.preserve,
|
|
770
|
+
execution: options.execution,
|
|
771
|
+
producer: options.record?.producer ?? options.producer,
|
|
772
|
+
persistence: options.record?.persistence ?? { status: "not_persisted", recoverability: "none" },
|
|
773
|
+
...(options.record?.lineage !== undefined ? { lineage: options.record.lineage } : {}),
|
|
774
|
+
...(options.scriptProducer !== undefined ? { scriptProducer: options.scriptProducer } : {}),
|
|
775
|
+
routing: {
|
|
776
|
+
status: "failed",
|
|
777
|
+
route: "run",
|
|
778
|
+
reason: `Run producer executed, but Freeflow routing failed after execution: ${options.errorMessage}`,
|
|
779
|
+
},
|
|
780
|
+
summary: "Run producer executed, but Freeflow routing failed after execution.",
|
|
781
|
+
importantLines: fallback.importantLines,
|
|
782
|
+
parser,
|
|
783
|
+
recovery,
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
// Keep exactness-sensitive command routing aligned with
|
|
787
|
+
// skills/output-router/references/safety-policy.md.
|
|
788
|
+
function routeCommandOutput(options) {
|
|
789
|
+
const outputBytes = byteLength(options.combined);
|
|
790
|
+
const outputLines = countLines(options.combined);
|
|
791
|
+
const isLarge = outputBytes > options.thresholds.largeOutputBytes || outputLines > options.thresholds.largeOutputLines;
|
|
792
|
+
const parseInput = {
|
|
793
|
+
command: options.command,
|
|
794
|
+
executionStatus: options.executionStatus,
|
|
795
|
+
exitCode: options.exitCode,
|
|
796
|
+
stdout: options.stdout,
|
|
797
|
+
stderr: options.stderr,
|
|
798
|
+
combined: options.combined,
|
|
799
|
+
};
|
|
800
|
+
if (options.goal !== undefined) {
|
|
801
|
+
Object.assign(parseInput, { goal: options.goal });
|
|
802
|
+
}
|
|
803
|
+
const parsed = parseCommandOutput(parseInput);
|
|
804
|
+
const parser = parsed.parser;
|
|
805
|
+
const statusText = `executionStatus=${options.executionStatus} exitCode=${options.exitCode}`;
|
|
806
|
+
const parserText = parserTextFor(parser);
|
|
807
|
+
if (options.filters) {
|
|
808
|
+
return routeFilteredOutput({ ...options, filters: options.filters }, parsed, statusText);
|
|
809
|
+
}
|
|
810
|
+
if (options.preserve === "full") {
|
|
811
|
+
return routeFullOutput(options, parsed, outputBytes, outputLines, statusText);
|
|
812
|
+
}
|
|
813
|
+
if (options.executionStatus !== "success") {
|
|
814
|
+
return {
|
|
815
|
+
decisionId: decisionId("run-route", options.outputId, options.executionStatus, "failed", parser.name),
|
|
816
|
+
routingStatus: "routed",
|
|
817
|
+
reason: `Command failed or did not complete (${statusText}); selected failure evidence was returned and ${commandStorageReason(options.storage)} before routing (${parserText}).`,
|
|
818
|
+
summary: parsed.summary ?? `Command ${options.executionStatus} with exitCode=${options.exitCode}.`,
|
|
819
|
+
importantLines: parsed.importantLines,
|
|
820
|
+
parser,
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
if (options.reducer) {
|
|
824
|
+
return routeReducedCommandOutput({ ...options, reducer: options.reducer }, parsed, statusText);
|
|
825
|
+
}
|
|
826
|
+
if (isLarge) {
|
|
827
|
+
return {
|
|
828
|
+
decisionId: decisionId("run-route", options.outputId, "large-success", parser.name),
|
|
829
|
+
routingStatus: "partial",
|
|
830
|
+
reason: `Large successful run output (${outputBytes} bytes, ${outputLines} lines): ${commandStorageReason(options.storage)}; bounded important lines were returned instead of full output (${parserText}).`,
|
|
831
|
+
summary: parsed.summary ?? `Command succeeded with ${outputLines} output lines and ${outputBytes} bytes.`,
|
|
832
|
+
importantLines: parsed.importantLines,
|
|
833
|
+
parser,
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
const nearRaw = selectNearRawSuccessfulLines(options);
|
|
837
|
+
const nearRawParser = parserWithEvidence(parser, nearRaw);
|
|
838
|
+
return {
|
|
839
|
+
decisionId: decisionId("run-route", options.outputId, "small-success", parser.name, nearRaw.fidelity),
|
|
840
|
+
routingStatus: nearRaw.fidelity === "exact" ? "routed" : "partial",
|
|
841
|
+
reason: `Small successful run output: ${commandStorageReason(options.storage)}; routed evidence was returned near-raw from the captured execution (${parserTextFor(nearRawParser)}).`,
|
|
842
|
+
summary: parsed.summary ?? `Command success with exitCode=${options.exitCode}.`,
|
|
843
|
+
importantLines: nearRaw.importantLines,
|
|
844
|
+
parser: nearRawParser,
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
function routeReducedCommandOutput(options, parsed, statusText) {
|
|
848
|
+
const importantLines = reducerImportantLines(options.reducer);
|
|
849
|
+
const parser = parserWithReducer(parsed.parser, options.reducer);
|
|
850
|
+
return {
|
|
851
|
+
decisionId: decisionId("run-route", options.outputId, "reducer", options.reducer.result.name, options.reducer.result.version),
|
|
852
|
+
routingStatus: "partial",
|
|
853
|
+
reason: `Reducer ${options.reducer.result.name}@${options.reducer.result.version} selected for successful run output (${statusText}); raw output was vaulted before deterministic reduction (${parserTextFor(parser)}).`,
|
|
854
|
+
summary: options.reducer.result.visibleText,
|
|
855
|
+
importantLines,
|
|
856
|
+
parser,
|
|
857
|
+
reducer: runReducerMetadata(options.outputId, options.reducer, options.reducerRecord),
|
|
858
|
+
...(options.reducerRecord?.lineage !== undefined ? { lineage: options.reducerRecord.lineage } : {}),
|
|
859
|
+
recovery: commandReducerRecoveryHint(options.outputId, options.reducerRecord?.outputId),
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
function routeFilteredOutput(options, parsed, statusText) {
|
|
863
|
+
const defaultText = routedCommandText(options);
|
|
864
|
+
const filtered = applyRunOutputFilters({
|
|
865
|
+
filters: options.filters,
|
|
866
|
+
defaultStream: defaultText.stream,
|
|
867
|
+
stdout: options.stdout,
|
|
868
|
+
stderr: options.stderr,
|
|
869
|
+
combined: options.combined,
|
|
870
|
+
fallbackImportantLines: parsed.importantLines,
|
|
871
|
+
preserveFallbackFailureEvidence: options.executionStatus !== "success",
|
|
872
|
+
caps: {
|
|
873
|
+
maxLines: options.thresholds.largeOutputLines,
|
|
874
|
+
maxExcerptBytes: options.thresholds.largeOutputBytes,
|
|
875
|
+
maxLineBytes: options.thresholds.largeOutputBytes,
|
|
876
|
+
},
|
|
877
|
+
});
|
|
878
|
+
const parser = parserWithEvidence(parsed.parser, filtered.evidence);
|
|
879
|
+
const fallbackText = filtered.metadata.fallbackPreservedFailureEvidence
|
|
880
|
+
? " No filtered lines matched, so parsed failure evidence was preserved instead of hiding the failure."
|
|
881
|
+
: "";
|
|
882
|
+
const selectedText = `${filtered.metadata.selectedLines}/${filtered.metadata.sourceLines} line(s) selected`;
|
|
883
|
+
return {
|
|
884
|
+
decisionId: decisionId("run-route", options.outputId, "filtered", filtered.description, parser.name),
|
|
885
|
+
routingStatus: filtered.evidence.compressed ? "partial" : "routed",
|
|
886
|
+
reason: `Run output was vaulted before declarative filters were applied (${statusText}; filters: ${filtered.description}; ${parserTextFor(parser)}).${fallbackText}`,
|
|
887
|
+
summary: `${parsed.summary ?? `Command ${options.executionStatus} with exitCode=${options.exitCode}.`} Filtered routed evidence: ${selectedText} from ${filtered.stream}.`,
|
|
888
|
+
importantLines: filtered.evidence.importantLines,
|
|
889
|
+
parser: {
|
|
890
|
+
...parser,
|
|
891
|
+
counts: {
|
|
892
|
+
...(parser.counts ?? {}),
|
|
893
|
+
filterSourceLines: filtered.metadata.sourceLines,
|
|
894
|
+
filterSelectedLines: filtered.metadata.selectedLines,
|
|
895
|
+
},
|
|
896
|
+
},
|
|
897
|
+
filters: filtered.metadata,
|
|
898
|
+
};
|
|
899
|
+
}
|
|
900
|
+
async function routeScriptFilteredOutput(options) {
|
|
901
|
+
const { routeOptions, rawRecord, scriptFilter } = options;
|
|
902
|
+
const baseRouting = routeCommandOutput(routeOptions);
|
|
903
|
+
const operation = {
|
|
904
|
+
kind: "script",
|
|
905
|
+
language: scriptFilter.language,
|
|
906
|
+
code: scriptFilter.code,
|
|
907
|
+
};
|
|
908
|
+
if (scriptFilter.label !== undefined) {
|
|
909
|
+
operation.label = scriptFilter.label;
|
|
910
|
+
}
|
|
911
|
+
const transformOptions = {
|
|
912
|
+
sessionId: options.sessionId,
|
|
913
|
+
sources: runScriptFilterSources(rawRecord.outputId),
|
|
914
|
+
operation,
|
|
915
|
+
preserve: routeOptions.preserve,
|
|
916
|
+
thresholds: routeOptions.thresholds,
|
|
917
|
+
scriptSandboxAdapters: options.scriptSandboxAdapters,
|
|
918
|
+
};
|
|
919
|
+
if (options.scriptTransform !== undefined) {
|
|
920
|
+
Object.assign(transformOptions, { scriptTransform: options.scriptTransform });
|
|
921
|
+
}
|
|
922
|
+
if (options.vaultRoot !== undefined) {
|
|
923
|
+
Object.assign(transformOptions, { vaultRoot: options.vaultRoot });
|
|
924
|
+
}
|
|
925
|
+
if (options.vaultRetention !== undefined) {
|
|
926
|
+
Object.assign(transformOptions, { vaultRetention: options.vaultRetention });
|
|
927
|
+
}
|
|
928
|
+
if (scriptFilter.limits !== undefined) {
|
|
929
|
+
Object.assign(transformOptions, { limits: scriptFilter.limits });
|
|
930
|
+
}
|
|
931
|
+
const scriptResult = await freeflowTransform(transformOptions);
|
|
932
|
+
const metadata = runScriptFilterMetadata(scriptFilter, scriptResult, rawRecord.outputId);
|
|
933
|
+
if (isSuccessfulScriptFilterResult(scriptResult)) {
|
|
934
|
+
const importantLines = evidencePacketsAsImportantLines(scriptResult.evidence);
|
|
935
|
+
const parser = {
|
|
936
|
+
name: `script-filter:${scriptFilter.language}`,
|
|
937
|
+
confidence: 1,
|
|
938
|
+
fidelity: "exact",
|
|
939
|
+
compressed: scriptResult.routing.status === "partial",
|
|
940
|
+
counts: {
|
|
941
|
+
scriptEvidencePackets: scriptResult.evidence?.length ?? 0,
|
|
942
|
+
},
|
|
943
|
+
};
|
|
944
|
+
return {
|
|
945
|
+
decisionId: decisionId("run-route", rawRecord.outputId, "script-filter", scriptResult.outputId, scriptFilter.language),
|
|
946
|
+
routingStatus: scriptResult.routing.status,
|
|
947
|
+
reason: `Run output was vaulted as outputId=${rawRecord.outputId} before a sandboxed ${scriptFilter.language} script filter ran over captured stdout/stderr/combined. ${scriptResult.routing.reason}`,
|
|
948
|
+
summary: `${baseRouting.summary} Script filter completed; transformed outputId=${scriptResult.outputId}.`,
|
|
949
|
+
importantLines,
|
|
950
|
+
parser,
|
|
951
|
+
...(baseRouting.filters !== undefined ? { filters: baseRouting.filters } : {}),
|
|
952
|
+
scriptFilter: metadata,
|
|
953
|
+
...(scriptResult.lineage !== undefined ? { lineage: scriptResult.lineage } : {}),
|
|
954
|
+
...(scriptResult.evidence !== undefined ? { evidence: scriptResult.evidence } : {}),
|
|
955
|
+
recovery: commandScriptFilterRecoveryHint(rawRecord.outputId, scriptResult.outputId),
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
const failureMessage = scriptResult.failure?.message ?? scriptResult.routing.reason;
|
|
959
|
+
return {
|
|
960
|
+
...baseRouting,
|
|
961
|
+
decisionId: decisionId("run-route", rawRecord.outputId, "script-filter-failed", scriptFilter.language, failureMessage),
|
|
962
|
+
routingStatus: baseRouting.routingStatus === "failed" ? "failed" : "partial",
|
|
963
|
+
reason: `Run producer executed and raw output was vaulted as outputId=${rawRecord.outputId}, but the sandboxed ${scriptFilter.language} script filter did not produce transformed output: ${failureMessage} Base run evidence was returned instead.`,
|
|
964
|
+
summary: `${baseRouting.summary} Script filter did not produce transformed output: ${failureMessage}`,
|
|
965
|
+
parser: {
|
|
966
|
+
...baseRouting.parser,
|
|
967
|
+
counts: {
|
|
968
|
+
...(baseRouting.parser.counts ?? {}),
|
|
969
|
+
scriptFilterFailures: 1,
|
|
970
|
+
},
|
|
971
|
+
},
|
|
972
|
+
scriptFilter: metadata,
|
|
973
|
+
...(scriptResult.failure !== undefined ? { failure: scriptResult.failure } : {}),
|
|
974
|
+
...(scriptResult.transformExecution !== undefined ? { transformExecution: scriptResult.transformExecution } : {}),
|
|
975
|
+
...(scriptResult.lineage !== undefined ? { lineage: scriptResult.lineage } : {}),
|
|
976
|
+
recovery: commandScriptFilterRecoveryHint(rawRecord.outputId),
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
function routeFullOutput(options, parsed, outputBytes, outputLines, statusText) {
|
|
980
|
+
const full = selectFullOutputLines(options);
|
|
981
|
+
const parser = parserWithEvidence(parsed.parser, full);
|
|
982
|
+
const routedStatus = full.fidelity === "exact" ? "routed" : "partial";
|
|
983
|
+
const capText = `${options.thresholds.largeOutputBytes} byte full-context cap`;
|
|
984
|
+
const reason = full.fidelity === "exact"
|
|
985
|
+
? `preserve=full returned exact run output within the ${capText} after ${commandStorageReason(options.storage)} (${statusText}; ${parserTextFor(parser)}).`
|
|
986
|
+
: `preserve=full output exceeded the bounded context policy (${outputBytes} bytes, ${outputLines} lines); a bounded preview was returned with raw vault recovery (${statusText}; ${parserTextFor(parser)}).`;
|
|
987
|
+
return {
|
|
988
|
+
decisionId: decisionId("run-route", options.outputId, "preserve-full", full.fidelity, parsed.parser.name),
|
|
989
|
+
routingStatus: routedStatus,
|
|
990
|
+
reason,
|
|
991
|
+
summary: parsed.summary ?? `Command ${options.executionStatus} with exitCode=${options.exitCode}.`,
|
|
992
|
+
importantLines: full.importantLines,
|
|
993
|
+
parser,
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
function selectNearRawSuccessfulLines(options) {
|
|
997
|
+
const { stream, text } = routedCommandText(options);
|
|
998
|
+
return assembleTextEvidence({
|
|
999
|
+
stream,
|
|
1000
|
+
text,
|
|
1001
|
+
caps: {
|
|
1002
|
+
maxLines: options.thresholds.largeOutputLines,
|
|
1003
|
+
maxExcerptBytes: options.thresholds.largeOutputBytes,
|
|
1004
|
+
maxLineBytes: options.thresholds.largeOutputBytes,
|
|
1005
|
+
},
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
function selectFullOutputLines(options) {
|
|
1009
|
+
const { stream, text } = routedCommandText(options);
|
|
1010
|
+
return assembleTextEvidence({
|
|
1011
|
+
stream,
|
|
1012
|
+
text,
|
|
1013
|
+
caps: {
|
|
1014
|
+
maxLines: Number.MAX_SAFE_INTEGER,
|
|
1015
|
+
maxExcerptBytes: options.thresholds.largeOutputBytes,
|
|
1016
|
+
maxLineBytes: options.thresholds.largeOutputBytes,
|
|
1017
|
+
},
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
function routedCommandText(options) {
|
|
1021
|
+
if (options.stdout.length > 0 && options.stderr.length === 0) {
|
|
1022
|
+
return { stream: "stdout", text: options.stdout };
|
|
1023
|
+
}
|
|
1024
|
+
if (options.stderr.length > 0 && options.stdout.length === 0) {
|
|
1025
|
+
return { stream: "stderr", text: options.stderr };
|
|
1026
|
+
}
|
|
1027
|
+
return { stream: "combined", text: options.combined };
|
|
1028
|
+
}
|
|
1029
|
+
function runScriptFilterSources(outputId) {
|
|
1030
|
+
return [
|
|
1031
|
+
{ kind: "vault", outputId, stream: "stdout", alias: "stdout" },
|
|
1032
|
+
{ kind: "vault", outputId, stream: "stderr", alias: "stderr" },
|
|
1033
|
+
{ kind: "vault", outputId, stream: "combined", alias: "combined" },
|
|
1034
|
+
];
|
|
1035
|
+
}
|
|
1036
|
+
function isSuccessfulScriptFilterResult(result) {
|
|
1037
|
+
return result.toolStatus === "ok" && result.failure === undefined && typeof result.outputId === "string" && result.outputId.length > 0;
|
|
1038
|
+
}
|
|
1039
|
+
function runScriptFilterMetadata(input, result, rawOutputId) {
|
|
1040
|
+
const metadata = {
|
|
1041
|
+
status: isSuccessfulScriptFilterResult(result) ? "success" : result.transformExecution?.status ?? "failed",
|
|
1042
|
+
language: input.language,
|
|
1043
|
+
sourceAliases: ["stdout", "stderr", "combined"],
|
|
1044
|
+
rawOutputId,
|
|
1045
|
+
};
|
|
1046
|
+
if (input.label !== undefined) {
|
|
1047
|
+
metadata.label = input.label;
|
|
1048
|
+
}
|
|
1049
|
+
if ("operation" in result && result.operation !== undefined) {
|
|
1050
|
+
metadata.operation = result.operation;
|
|
1051
|
+
}
|
|
1052
|
+
if (result.outputId !== undefined) {
|
|
1053
|
+
metadata.outputId = result.outputId;
|
|
1054
|
+
}
|
|
1055
|
+
if (result.recordId !== undefined) {
|
|
1056
|
+
metadata.recordId = result.recordId;
|
|
1057
|
+
}
|
|
1058
|
+
if (result.persistence !== undefined) {
|
|
1059
|
+
metadata.persistence = result.persistence;
|
|
1060
|
+
}
|
|
1061
|
+
if (result.lineage !== undefined) {
|
|
1062
|
+
metadata.lineage = result.lineage;
|
|
1063
|
+
}
|
|
1064
|
+
if (result.failure !== undefined) {
|
|
1065
|
+
metadata.failure = result.failure;
|
|
1066
|
+
}
|
|
1067
|
+
if (result.transformExecution !== undefined) {
|
|
1068
|
+
metadata.transformExecution = result.transformExecution;
|
|
1069
|
+
}
|
|
1070
|
+
if ("summary" in result && result.summary !== undefined) {
|
|
1071
|
+
metadata.summary = result.summary;
|
|
1072
|
+
}
|
|
1073
|
+
return metadata;
|
|
1074
|
+
}
|
|
1075
|
+
function evidencePacketsAsImportantLines(evidence) {
|
|
1076
|
+
if (!Array.isArray(evidence)) {
|
|
1077
|
+
return [];
|
|
1078
|
+
}
|
|
1079
|
+
return evidence
|
|
1080
|
+
.filter((packet) => typeof packet.excerpt === "string" && typeof packet.lines === "string")
|
|
1081
|
+
.map((packet) => ({
|
|
1082
|
+
stream: "combined",
|
|
1083
|
+
lines: packet.lines,
|
|
1084
|
+
excerpt: packet.excerpt,
|
|
1085
|
+
}));
|
|
1086
|
+
}
|
|
1087
|
+
function storeReducerOutput(options) {
|
|
1088
|
+
const operation = `run-reducer:${options.reducer.result.name}@${options.reducer.result.version}`;
|
|
1089
|
+
return storeTextOutput(options.vault, {
|
|
1090
|
+
sessionId: options.sessionId,
|
|
1091
|
+
raw: options.reducer.result.visibleText,
|
|
1092
|
+
sourceKind: "transform",
|
|
1093
|
+
decisionIds: [decisionId("run-reducer", options.rawRecord.outputId, options.reducer.result.name, options.reducer.result.version)],
|
|
1094
|
+
producer: { kind: "transform", name: "freeflow_run reducer" },
|
|
1095
|
+
lineage: {
|
|
1096
|
+
sourceRecordIds: [options.rawRecord.recordId],
|
|
1097
|
+
sourceOutputIds: [options.rawRecord.outputId],
|
|
1098
|
+
operation,
|
|
1099
|
+
operationHash: hash(JSON.stringify({ operation, sourceOutputId: options.rawRecord.outputId, facts: options.reducer.result.facts })),
|
|
1100
|
+
},
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
function runReducerMetadata(rawOutputId, reducer, reducerRecord) {
|
|
1104
|
+
return {
|
|
1105
|
+
status: reducerRecord === undefined ? "selected" : "success",
|
|
1106
|
+
name: reducer.result.name,
|
|
1107
|
+
version: reducer.result.version,
|
|
1108
|
+
confidence: reducer.result.confidence,
|
|
1109
|
+
rawOutputId,
|
|
1110
|
+
summary: reducer.result.visibleText,
|
|
1111
|
+
facts: reducer.result.facts,
|
|
1112
|
+
...(reducerRecord !== undefined ? {
|
|
1113
|
+
outputId: reducerRecord.outputId,
|
|
1114
|
+
recordId: reducerRecord.recordId,
|
|
1115
|
+
persistence: reducerRecord.persistence,
|
|
1116
|
+
lineage: reducerRecord.lineage,
|
|
1117
|
+
} : {}),
|
|
1118
|
+
};
|
|
1119
|
+
}
|
|
1120
|
+
function commandReducerRecoveryHint(rawOutputId, transformedOutputId) {
|
|
1121
|
+
if (transformedOutputId) {
|
|
1122
|
+
return {
|
|
1123
|
+
how: `Raw run output: use freeflow_search with source.kind=vault and outputId=${rawOutputId}. Reducer-transformed output: use freeflow_search with source.kind=vault, outputId=${transformedOutputId}, stream=raw, and an exact lineRange.`,
|
|
1124
|
+
outputId: rawOutputId,
|
|
1125
|
+
};
|
|
1126
|
+
}
|
|
1127
|
+
return {
|
|
1128
|
+
how: `Reducer output was returned in the structured run result. Raw run output remains recoverable with freeflow_search source.kind=vault outputId=${rawOutputId}.`,
|
|
1129
|
+
outputId: rawOutputId,
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
function commandScriptFilterRecoveryHint(rawOutputId, transformedOutputId) {
|
|
1133
|
+
if (transformedOutputId) {
|
|
1134
|
+
return {
|
|
1135
|
+
how: `Raw run output: use freeflow_search with source.kind=vault and outputId=${rawOutputId}. Script-filtered transformed output: use freeflow_search with source.kind=vault, outputId=${transformedOutputId}, stream=raw, and an exact lineRange.`,
|
|
1136
|
+
outputId: rawOutputId,
|
|
1137
|
+
};
|
|
1138
|
+
}
|
|
1139
|
+
return {
|
|
1140
|
+
how: `Script filter did not produce transformed output. Raw run output remains recoverable with freeflow_search source.kind=vault outputId=${rawOutputId}.`,
|
|
1141
|
+
outputId: rawOutputId,
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
function normalizeRunScriptFilter(input) {
|
|
1145
|
+
if (input === undefined || input === null) {
|
|
1146
|
+
return { ok: true };
|
|
1147
|
+
}
|
|
1148
|
+
if (!isRecord(input)) {
|
|
1149
|
+
return { ok: false, path: "$.scriptFilter", message: "freeflow_run scriptFilter must be an object." };
|
|
1150
|
+
}
|
|
1151
|
+
const operation = { kind: "script" };
|
|
1152
|
+
if (input.language !== undefined) {
|
|
1153
|
+
operation.language = input.language;
|
|
1154
|
+
}
|
|
1155
|
+
if (input.code !== undefined) {
|
|
1156
|
+
operation.code = input.code;
|
|
1157
|
+
}
|
|
1158
|
+
if (input.label !== undefined) {
|
|
1159
|
+
operation.label = input.label;
|
|
1160
|
+
}
|
|
1161
|
+
const candidate = {
|
|
1162
|
+
sources: runScriptFilterSources("ffout_run_script_filter_validation"),
|
|
1163
|
+
operation,
|
|
1164
|
+
};
|
|
1165
|
+
if (input.limits !== undefined) {
|
|
1166
|
+
candidate.limits = input.limits;
|
|
1167
|
+
}
|
|
1168
|
+
const validation = validateTransformInput(candidate);
|
|
1169
|
+
if (!validation.ok) {
|
|
1170
|
+
const issue = validation.issues[0] ?? { path: "$.scriptFilter", message: "Invalid script filter." };
|
|
1171
|
+
return {
|
|
1172
|
+
ok: false,
|
|
1173
|
+
path: issue.path.replace(/^\$\.operation/, "$.scriptFilter").replace(/^\$\.limits/, "$.scriptFilter.limits"),
|
|
1174
|
+
message: issue.message,
|
|
1175
|
+
};
|
|
1176
|
+
}
|
|
1177
|
+
const scriptFilter = {
|
|
1178
|
+
language: input.language,
|
|
1179
|
+
code: input.code,
|
|
1180
|
+
};
|
|
1181
|
+
if (input.label !== undefined) {
|
|
1182
|
+
scriptFilter.label = input.label;
|
|
1183
|
+
}
|
|
1184
|
+
if (input.limits !== undefined) {
|
|
1185
|
+
scriptFilter.limits = input.limits;
|
|
1186
|
+
}
|
|
1187
|
+
return { ok: true, scriptFilter };
|
|
1188
|
+
}
|
|
1189
|
+
function isRecord(value) {
|
|
1190
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1191
|
+
}
|
|
1192
|
+
function parserWithEvidence(parser, evidence) {
|
|
1193
|
+
return {
|
|
1194
|
+
...parser,
|
|
1195
|
+
fidelity: parser.fidelity === "lossy" || evidence.fidelity === "lossy" ? "lossy" : "exact",
|
|
1196
|
+
compressed: evidence.compressed,
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1199
|
+
function parserTextFor(parser) {
|
|
1200
|
+
return `parser=${parser.name} confidence=${parser.confidence.toFixed(2)} fidelity=${parser.fidelity}`;
|
|
1201
|
+
}
|
|
1202
|
+
function combineOutputSections(stdout, stderr) {
|
|
1203
|
+
if (stdout.length === 0) {
|
|
1204
|
+
return stderr;
|
|
1205
|
+
}
|
|
1206
|
+
if (stderr.length === 0) {
|
|
1207
|
+
return stdout;
|
|
1208
|
+
}
|
|
1209
|
+
return `[stdout]\n${stdout}\n[stderr]\n${stderr}`;
|
|
1210
|
+
}
|
|
1211
|
+
function commandText(command) {
|
|
1212
|
+
return typeof command === "string" ? command : command.join(" ");
|
|
1213
|
+
}
|
|
1214
|
+
function decisionId(...parts) {
|
|
1215
|
+
return `ffdec_${hash(parts.join("\0")).slice(0, 16)}`;
|
|
1216
|
+
}
|
|
1217
|
+
function hash(value) {
|
|
1218
|
+
return createHash("sha256").update(value).digest("hex");
|
|
1219
|
+
}
|