Files
fusion/packages/engine/src/executor/task-predicates.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

67 lines
2.7 KiB
TypeScript

/**
* FNXC:CodeOrganization 2026-08-03-13:10:
* Tiny pure TaskExecutor predicates peeled from executor.ts (U4).
* No instance state; re-exported from the facade for call-site stability.
*/
import type { Task } from "@fusion/core";
/** True when every step is done or skipped (and at least one step exists). */
export function isTaskWorkComplete(task: Task): boolean {
if (task.steps.length === 0) return false;
return task.steps.every((s) => s.status === "done" || s.status === "skipped");
}
/** Failed with "without calling fn_task_done" and zero step progress. */
export function isNoProgressNoTaskDoneFailure(task: Task): boolean {
return task.status === "failed" &&
task.error?.includes("without calling fn_task_done") === true &&
task.steps.every((step) => step.status === "pending");
}
export function createSeenSteeringIds(task: {
comments?: Array<{ id: string }>;
steeringComments?: Array<{ id: string }>;
}): Set<string> {
const seenSteeringIds = new Set<string>();
for (const comment of task.steeringComments ?? task.comments ?? []) {
seenSteeringIds.add(comment.id);
}
return seenSteeringIds;
}
export function createConfiguredCommandAbortError(taskId: string, command: string): Error {
const error = new Error(`Configured command aborted for ${taskId}: ${command}`);
error.name = "AbortError";
return error;
}
/** Composite key for graph-owned per-instance state: never share parallel foreach instances. */
export function graphActiveContextKey(taskId: string, instanceId: string): string {
return `${taskId}:${instanceId}`;
}
export function isRetryableMergePauseAbortStatus(status: string | null | undefined): boolean {
/*
FNXC:WorkflowMerge 2026-07-01-22:05:
FN-7335 surfaced a merge-node pause/resume abort while the row was legitimately `in-review` with status="reviewing" from the AI merge reviewer. That status is merge activity, not a pre-existing terminal failure; keep the retry classifier strict on real errors while allowing transient merge/review statuses to re-enter bounded merge retry.
*/
return status == null || status === "reviewing" || status === "merging" || status === "merging-pr";
}
export function isTerminalMergeGraphFailureValue(value: string | undefined): boolean {
if (!value) return false;
const normalized = value.toLowerCase();
return normalized.includes("conflict")
|| normalized.includes("contamination")
|| normalized.includes("foreign")
|| normalized.includes("retry-exhausted")
|| normalized.includes("retries exhausted")
|| normalized.includes("max retries");
}
export function isAwaitingGraphFailureValue(
value: string | undefined,
): value is "awaiting-user-input" | "awaiting-cli-approval" {
return value === "awaiting-user-input" || value === "awaiting-cli-approval";
}