fix: [ENG-3025] address review findings on response-file flag PR
Four cleanups from PR review (one per finding):
1. Defer --response-file unlink until after daemon dispatch returns.
Previously the unlink fired between local validation and dispatch, so
a transport error (daemon down, malformed payload, daemon-side throw)
destroyed the envelope file the agent had paid an LLM call to author.
Now the unlink only fires on a non-throw dispatch (success OR
validation-failed); a daemon-error throw skips it and the file
survives for retry. Unlink failure post-success appends a warning to
the dispatch envelope instead of aborting.
2. Replace `as Error & {kind?: string}` cast on the parse-error catch
with `instanceof InvalidResponseFormatError`. Required exporting the
class from curate-session.ts. Matches the existing pattern for
InvalidResponseFileError and respects the no-`as`-Type convention.
3. Pre-check whitespace-only payload in the command and emit the
transient `empty-response` envelope directly instead of letting
JSON.parse(' ') throw and collapse it into the terminal
`invalid-response-format` kind. Preserves the documented contract
where `empty-response` keeps the session alive for retry.
4. Replace the one-line buildUnknownSessionEnvelope wrapper with a
direct export of the internal unknownSessionEnvelope. Same shape,
one fewer indirection.
Interactive verification: file preserved on whitespace-only payload
(both inline and file), happy-path file deleted post-dispatch, real
envelope still curates clean. 8877 tests pass (1 new for the
parseCurateResponse-throws-InvalidResponseFormatError contract). N
Nguyễn Thuận Phát committed
abd82bafe64bcd7e9ad6095e794e52b8eca14ba0
Parent: 7c2d6f8