Files
fusion/packages/engine/src/executor/facade-methods.ts
gsxdsm 1cf86baa1c refactor: package code organization wave 18 (executor pure peels) (#3317)
## Summary

Wave 18 continues the package code-organization program after wave 17
domain folders (U4 Slice A from
`docs/plans/2026-07-14-001-refactor-package-code-organization-plan.md`).

### What changed
Peel **pure, behavior-preserving** helpers out of
`packages/engine/src/executor.ts` into domain modules under
`packages/engine/src/executor/`, with **stable re-exports** from
`executor.ts` so deep imports and `vi.mock("../executor.js")` keep
working.

| New module | Symbols |
|------------|---------|
| `executor/task-done-refusal.ts` | `evaluateTaskDoneRefusal`,
`determineRevisionResetStart`, skip-bypass refusal helper |
| `executor/workflow-feedback-paths.ts` |
`extractReferencedPathsFromWorkflowFeedback`,
`isAlwaysAllowedScopeLeakPath`, `workflowPathMatchesDeclaredScope` |
| `executor/workflow-step-verdict.ts` |
`FUSION_WORKFLOW_STEP_CONVENTIONS_PREAMBLE`, `parseWorkflowStepVerdict`
/ `parseWorkflowStepOutput`, step outcome types |
| `executor/await-input-parse.ts` | `parseAwaitInputSentinel`,
`parseAwaitInputQuestionToolCall` |
| `executor/no-commit-eligibility.ts` | `getNoCommitEligibilityReason`
(+ prompt heuristics) |

`executor.ts` live LOC ~**22817 → ~22427** (first pure-peel batch; more
peels needed to approach the 2k cap).

### Shims
- `old path` `executor.ts` public exports → `new path` `executor/*.ts` →
delete-when consumer deep-imports are re-pointed (not this PR)

### Test plan
- [x] `@fusion/engine` typecheck
- [x] Oracle: task-done refusal, skip-bypass, workflow malformed
verdict, scope-leak allowlist, executor-step-session, executor-prompt
- [x] `vitest --project=engine-core` (merge-gate curated suite)
- [ ] CI merge gate

**Stack:** wave17 (merged) → **this PR**

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Improved recognition of workflow outcomes from structured and
conversational responses.
* Added support for extracting questions from await-input responses and
tool calls.
* Improved workflow feedback handling for referenced files and declared
scope patterns.
* Added clearer guidance for task execution, approvals, verification,
and available tools.

* **Bug Fixes**
* Prevented completion when required review approvals are missing or
revisions remain pending.
* Improved handling of workflows that legitimately require no code
changes.
  * Added clearer refusal messages and more reliable revision restarts.
  * Sanitized repository paths in Git remediation instructions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-08-09 15:46:09 -10:00

55 lines
2.7 KiB
TypeScript

/**
* FNXC:CodeOrganization 2026-08-03-21:25:
* Compact TaskExecutor facade deps wiring (U4).
*
* Large free-function peels take many host methods as deps callbacks. Writing each as
* `(...args) => (this as any).name(...args)` bloats the facade. This helper builds the
* same bound bag from a name list so facades stay thin without changing call semantics.
*
* FNXC:CodeOrganization 2026-08-03-21:40:
* Returns `any` deliberately so spread into typed deps bags does not force `as any` at
* every call site (eslint no-explicit-any would fire on each cast). The host methods are
* private TaskExecutor members; the free-fn deps types are the real contract.
*
* FNXC:CodeOrganization 2026-08-04-04:15:
* FacadeRestArgs strips the leading deps bag from a free-fn signature so multi-arg
* TaskExecutor facades can forward with `...args` instead of re-declaring long parameter
* lists (defaults remain on the free function).
*/
/** Args after the deps bag for a free function of shape `(deps, ...args) => R`. */
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- free-fn deps bag is always first
export type FacadeRestArgs<F> = F extends (deps: any, ...args: infer A) => any ? A : never;
/** Args after the first positional arg (store / rootDir / worktreePath) for free peels. */
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- first positional is host-owned
export type FacadeAfterFirst<F> = F extends (first: any, ...args: infer A) => any ? A : never;
/** Args after two fixed host positionals (rootDir, store). */
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- first two positionals are host-owned
export type FacadeAfterSecond<F> = F extends (a: any, b: any, ...args: infer A) => any ? A : never;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- see FNXC above
export function facadeMethods(host: object, names: readonly string[]): any {
const out: Record<string, (...args: unknown[]) => unknown> = {};
for (const name of names) {
out[name] = (...args: unknown[]) =>
(host as Record<string, (...a: unknown[]) => unknown>)[name](...args);
}
return out;
}
/*
FNXC:CodeOrganization 2026-08-03-22:15:
Pick host fields by name for free-fn deps bags. Complements facadeMethods for
the field-heavy executeWorkflowGraph / handleGraphFailure / runImplementation facades.
Returns any for the same spread-into-typed-deps reason as facadeMethods.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- see FNXC above
export function facadeFields(host: object, names: readonly string[]): any {
const out: Record<string, unknown> = {};
for (const name of names) {
out[name] = (host as Record<string, unknown>)[name];
}
return out;
}