AI/Tasks/OrchestratorUpgrades/Orchestrator_Phase03_RepairAndAcceptancePrompt.txt

PHASE 03 REPAIR AND ACCEPTANCE PROMPT - RESOLVE POLICY HARDENING REGRESSIONS AND COMPLETE THE TEST GATE
 
Goal:
Fix the remaining Phase 03 regression failures while preserving the new centralized tool-policy and authorization hardening. The implementation added the registry, fail-closed mutation checks, path validation, and postcondition guardrails, but the targeted suite still fails on write-file/replace-in-file parsing and compact read-file fallback behavior.
 
Inputs:
- AI/Tasks/OrchestratorUpgrades/Orchestrator_Phase03_ToolPolicyAuthorization_Implementation.txt
- AI/Tasks/OrchestratorUpgrades/Orchestrator_Phase03_ToolPolicyAuthorization_Strict.txt
- LogsAndExports/Logs/TechAgentMarkdown/TechAgent_20260905_223414_36688.md
 
Problem statement:
- The policy and authorization foundation is in place and the build passes.
- The targeted validation still fails with 16 regressions, primarily in write-file decision parsing, replace-in-file flows, compact read-file fallback, and tool-result handling.
- The failure report explicitly states that after one repair cycle the task must stop with the exact failing assertions rather than broadening the refactor.
- This prompt is the bounded repair needed to resolve the exact remaining incompatibilities without expanding the scope beyond Phase 03 policy enforcement.
 
Required code work:
- Repair the compatibility regressions introduced by the new policy/authorization seam without weakening fail-closed mutation enforcement.
- Restore correct write-file and replace-in-file decision parsing so the orchestrator still recognizes valid mutation workflows and file updates.
- Restore the compact read-file fallback behavior expected by the existing orchestration tests.
- Correct the tool-result handling so policy decisions and execution results remain compatible with current orchestrator behavior.
- Keep the registry and authorization seam central and fail-closed for unknown or unauthorized mutation tools.
- Preserve the path checks, argument validation, redacted diagnostics, and postcondition verification introduced in the policy model.
- Do not relax safety guarantees or allow unauthorized mutation.
 
Implementation constraints:
- Keep the fix bounded to the Phase 03 compatibility regressions and directly associated test coverage.
- Do not broaden into unrelated orchestrator or validation logic.
- Do not weaken authorization, confirmation, or sandboxing behavior.
- Do not reintroduce unsafe or unvalidated mutation paths.
- Keep the patch deterministic and minimal.
 
Minimum tests to add/update:
- Focused tests covering the exact failing assertions:
  - `RunAsync_InferWriteFilePath_WhenMissingAndPromptRequiresExactOutputPath`
  - `RunAsync_AllowsReplaceInFile_ToSatisfyRequiredFileUpdate`
  - `RunAsync_ReplaceInFilePreflight_AllowsEquivalentLineEndingVariants`
- Additional policy/authorization regression tests for write-file, replace-in-file, and compact read-file compatibility.
- Preserve and pass the existing targeted suite filter:
  - `Orchestrator|Tool|Policy|Authorization|Safety|Strict`
 
Validation commands:
- dotnet build src/TechToolbox.Agent/TechToolbox.Agent.csproj -c Release
- dotnet test src/TechToolbox.Agent/Tests/TechToolbox.Agent.Tests.csproj -c Release --filter "Orchestrator|Tool|Policy|Authorization|Safety|Strict"
 
Deliverable:
Return changed files, the exact compatibility fix, whether the registry/authorization seam remains fail-closed, and proof that the targeted Phase 03 tests pass.
 
Step budget (hard limits):
1) Discovery: <= 6 read/search tool calls.
2) Edits: <= 8 file edits total.
3) Validation: 1 build + 1 targeted test run; allow exactly 1 repair cycle if failures are phase-related.
4) Stop once acceptance criteria pass.
 
Loop guards:
- If the fix expands beyond the compatibility regressions and policy guardrails, stop and keep it bounded.
- If write-file or replace-in-file parsing is still incompatible with existing orchestrator behavior, stop and repair the compatibility layer.
- If compact read-file fallback is still broken, stop and restore the expected fallback behavior.
- If policy enforcement is relaxed to satisfy the tests, stop and restore fail-closed authorization.
 
Fallback behavior:
- Fallback A: repair the compatibility boundary between orchestrator decision parsing and the new policy registry while preserving fail-closed checks.
- Fallback B: if the issue is in the argument normalization or tool execution seam, repair that seam only and do not redesign the policy model.
- Fallback C: after one failed repair cycle, emit FAILED_VALIDATION with the exact failing assertions and the incompatible behavior.
 
Acceptance criteria:
- The targeted Phase 03 validation suite passes.
- The write-file and replace-in-file parsing regressions are fixed.
- Compact read-file fallback behavior is restored to expected orchestrator behavior.
- Policy enforcement remains fail-closed for unauthorized or unregistered mutation tools.
- Safety, authorization, and postcondition verification remain intact.
 
Output results in markdown using this structure:
1) Summary
2) Files changed
3) Policy and authorization compatibility notes
4) Tests added/updated
5) Validation results
6) Step-budget report (planned vs actual counts)