Skip to content

refactor(server): move five agents' prompt helpers into their own modules - #1755

Merged
devswha merged 1 commit into
mainfrom
refactor/prompt-helper-modules
Oct 23, 2026
Merged

devswha merged 1 commit into
mainfrom
refactor/prompt-helper-modules

Conversation

@devswha

@devswha devswha commented Oct 23, 2026

Copy link
Copy Markdown
Owner

The first wave of the per-agent module split. The plan is .omo/plans/agent-modules-split.md in the maintainer's workspace, wave P1a, and plan-reviewer approved it.

This wave moves self-contained helpers for five agents out of server/prompt.ts into new leaf modules. prompt.ts keeps every per-pane map, the reader dispatch and the HTTP route. It re-exports each moved name it exported before, so no importer changes.

What changes

All declarations move verbatim with their doc comments, into five new files:

  • server/claude-input.ts: the Claude input-box, suggestion and held-message readers, from SUGGESTION_READ_MS to claudeHeldIsGrey. restoredOnLiveScreen stays in prompt.ts, because it reads the chatSent map.
  • server/hermes-input.ts: plainRow, hermesInputRow and hermesInputDraft.
  • server/opencode-prompt.ts: the OpenCodePromptState class. Its one instance, defaultOpenCodeState, stays in prompt.ts.
  • server/omo-questions.ts: omoAskOf, openOmoAsks, pendingOmoAsk, OMO_FORM_RE, omoAskReader and omoAsksFor. omoAskReader is module state with one user, omoAsksFor, and the two move together, so the state keeps a single owner.
  • server/codex-queue.ts: the head of the Codex queue: CODEX_QUEUE_COUNT_RE, queuedQuestionCount, QueueFront, queuedPrompt and codexQueuedPrompt. The queue drivers stay in prompt.ts, because they need parsePrompt.

Four names gain an export, because prompt.ts still calls them: SUGGESTION_READ_MS, queuedQuestionCount, OMO_FORM_RE and omoAsksFor.

Some things stay in prompt.ts on purpose:

  • prepareCommandSend and noteSubmitted stay declared there, because tests spy on them.
  • The fixed sleep in sendStep, keyed in scripts/fixed-sleeps.json, stays in place.

Checks

  • --color-moved: git diff --color-moved=plain --color-moved-ws=allow-indentation-change origin/main...HEAD -- server shows 1,127 lines as moved. The other 43 lines are the new modules' imports, prompt.ts's narrowed imports and re-exports, and the four export keywords.

  • No import cycle: for each new module, bun <plan>/no-path.ts <module> server/prompt.ts server/conversation.ts exits 0. It follows value imports through every file, so no new module reaches prompt.ts or conversation.ts, directly or transitively.

  • Typecheck: bun run typecheck passes.

  • Unit tests: 540 pass, 0 fail, from:

    HERDR_TEST_MODE=unit bun test server/prompt.test.ts server/opencode-state.test.ts server/outcome-opencode.test.ts server/opencode-answer.test.ts server/dialogs/claude.test.ts server/core/claude-rewind-send.test.ts server/core/omo-pane-send.test.ts server/core/outcome-delivery.test.ts server/outcome.test.ts

  • bun run check fast: passes (unit 6244 pass, 0 fail, 13 skip in 442 files, 8 at a time, 57.4s)

  • Integration lane: CI runs pending-input.contract, prompt.contract, opencode-prompt.contract and claude-session.contract.

Outside PRs that touch the same files

No other maintainer PR touches these files. Three outside contributors' PRs touch server/prompt.ts. I checked each against this branch with git merge-tree:

Move-only: moved declarations plus imports, re-exports and four export keywords. No changelog fragment: users see no change.

…ules

Claude input/held, Hermes input, OpenCode prompt state, OmO questions and the
Codex queue head move verbatim into leaf modules that import nothing back from
prompt.ts or conversation.ts.
prompt.ts imports what it still uses and re-exports what it exported before,
so no importer changes.
Plan .omo/plans/agent-modules-split.md P1a.
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between d7c3f82 and 72a9391.

📒 Files selected for processing: 6
  • server/claude-input.ts
  • server/codex-queue.ts
  • server/hermes-input.ts
  • server/omo-questions.ts
  • server/opencode-prompt.ts
  • server/prompt.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

📝 Summary

Summary by CodeRabbit

  • New Features
    • Improved recognition of draft text, suggestions, and restored input across supported AI tools, helping preserve and display prompt content more reliably.
    • Added support for detecting queued questions and open interactive questions, so pending prompts can be surfaced more accurately.
    • Improved tracking of in-progress OpenCode prompts across sessions.
  • Bug Fixes
    • Reduced the chance that placeholder text, hidden input, or stale screen content is mistaken for a draft or pending question.

The change adds Claude and Hermes input detection, Codex queue prompt construction, OmO open-question lookup, and OpenCode prompt state. It moves these implementations into dedicated modules and updates server/prompt.ts to import and re-export them.

Changes: Prompt handling

Layer / File(s) Summary
Claude input parsing
server/claude-input.ts, server/prompt.ts
New helpers parse suggestions and input-box content, detect and match drafts, verify viewport reads, and check held-message text.
Hermes draft detection
server/hermes-input.ts
New helpers locate the prompt row and use viewport text and ANSI styling to distinguish typed input from placeholders and cursor chips.
Codex collapsed queue prompts
server/codex-queue.ts, server/prompt.ts
New helpers detect collapsed question counts and construct queued prompts from unanswered questions, with optional matching against the front question.
OmO open-question lookup
server/omo-questions.ts, server/prompt.ts
New helpers validate question calls, track open questions in JSONL records, and look up questions from pane transcripts.
OpenCode prompt state
server/opencode-prompt.ts, server/prompt.ts
The new state class checkpoints and reconciles entries, orders asynchronous snapshots, prunes old entries, and supports entry lifecycle operations.
Prompt module exports and relocation
server/prompt.ts
The module imports and re-exports helpers from the dedicated modules. Inline implementations are removed, while the Codex rollout-path cache remains.

Priority: ⬇️ Low

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Refactor

Possibly related PRs

  • devswha/ovis#1714: Changes Pi question handling in server/prompt.ts and OmO form state and settling logic, which connect to the OmO helpers moved in this change.
Merge Risk: ⚪ Minimal · up to 72a93

No merge-blocking issue is established; the change is ready for normal merge checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: moving five agents' prompt helpers into separate server modules.
Description check Passed The description explains the refactor, resulting behavior, retained responsibilities, validation results, integration coverage, and merge considerations. It provides the required Change and Validation…
Docstring Coverage Passed Docstring coverage is 93.55% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 31 functions across 6 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the refactor, resulting behavior, retained responsibilities, validation results, integration coverage, and merge considerations. It provides the required Change and Validation information under equivalent headings.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 23, 2026

Copy link
Copy Markdown
Owner Author

Merge pass: move-only PR, merged on its checks without waiting for a CodeRabbit review, as AGENTS.md allows.

  • Pure move. A comparison of removed and added lines differs only in:

    • imports;
    • the re-exports in prompt.ts;
    • four export keywords (SUGGESTION_READ_MS, queuedQuestionCount, OMO_FORM_RE, omoAsksFor).
  • Checks. bun run typecheck passes, and the seven-file server suite gives 509 pass, 0 fail. The suite covers prompt, opencode-state, outcome-opencode, opencode-answer, dialogs/claude, omo-pane-send and outcome.

  • Gate review. A gate reviewer on a different model than the author's found that the move preserves:

    • every export;
    • the spy targets: prepareCommandSend and noteSubmitted are still declared and called in prompt.ts;
    • single ownership of module state, including omoAskReader;
    • initialization order.

    All 45 convention tests pass, including the fixed-sleeps key.

  • Outside contributors. fix(prompt): support GJC custom answers with guarded delivery #1669, fix(chat): recognize Pi's thinking selector #1670 and fix(prompt): support Pi rpiv question cards and safe navigation #1714 also touch server/prompt.ts. At most they need a rebase.

All required checks are green and no review thread is open.

@devswha
devswha merged commit 8bd6480 into main Oct 23, 2026
17 checks passed
@devswha
devswha deleted the refactor/prompt-helper-modules branch October 23, 2026 12:18
devswha added a commit that referenced this pull request Oct 23, 2026
…le (#1760)

Wave C1 of the per-agent module split. The plan is
`.omo/plans/agent-modules-split.md` in the maintainer's workspace, and
plan-reviewer approved it. It follows P1a (#1755).

This wave moves the Claude transcript parser out of
`server/conversation.ts` into a new leaf module,
`server/claude-transcript.ts`. `conversation.ts` keeps:
- every cache and both `forget*` functions;
- the paging core and the transcript resolvers;
- the three functions tests spy on (`paneTranscript`,
`readCommandTranscript`, `paneProcessRoots`).

It re-exports the parser's public names, so no importer changes.

## What changes

- **Moved verbatim, with their doc comments:** about 420 lines. That
covers `isCommandEntry` through `parseClaudeTranscript`:
- the local-command and notice helpers, `stripTerminalControls` and
`unwrapPastes`;
  - `TranscriptEntry`, `claudeResultText`, `IMAGE_TYPES`;
- the parser state, `createClaudeTranscriptParser`,
`claudeTranscriptParser` and `parseClaudeTranscript`.
- **New `export` keywords:** four names gain one, because
`conversation.ts` still uses them: `isCommandEntry`, `claudeResultText`,
`IMAGE_TYPES` and the type `TranscriptEntry`.
- **Re-exports:** `conversation.ts` re-exports `parseClaudeTranscript`,
`createClaudeTranscriptParser` and `unwrapPastes`. Its other imports
narrow to what it still uses.
- **Not moved:** the parser holds no module state (its state lives in
closures), so no cache changes owner.

## Checks

- **`--color-moved`:** `git diff --color-moved=plain
--color-moved-ws=allow-indentation-change origin/main...HEAD -- server`
shows 831 lines as moved. The other 19 lines are the new module's
imports, `conversation.ts`'s narrowed imports, the re-export, and the
four `export` keywords.
- **No import cycle:** `bun <plan>/no-path.ts
server/claude-transcript.ts server/conversation.ts server/prompt.ts`
exits 0. It follows value imports through every file, and the new module
never reaches `conversation.ts` or `prompt.ts`.
- **Spied names stay put:** `paneTranscript`, `readCommandTranscript`
and `paneProcessRoots` are still declared in `conversation.ts`.
- **No new herdr call:** `server/claude-transcript.ts` has no `herdrRpc`
call (`server/conventions.test.ts` forbids new ones).
- **Typecheck:** `bun run typecheck` passes.
- **Unit tests:** **212 pass, 0 fail**, from:

`HERDR_TEST_MODE=unit bun test server/chat-history.test.ts
server/claude-incremental.test.ts server/claude-turn-boundaries.test.ts
server/skill-activity.test.ts server/conversation.test.ts
server/native-incremental.test.ts server/large-history-agents.test.ts
server/outcome-transcript*.test.ts`
- `bun run check fast`: passes (unit 6251 pass, 0 fail, 13 skip in 443
files, 8 at a time, 73.4s)
- **Integration lane:** CI runs `claude-session.contract` and
`conversation-push.contract`.

## Outside PRs that touch the same files

No other maintainer PR touches these files. Three outside contributors'
PRs touch `server/conversation.ts`. I checked each against this branch
with `git merge-tree`:
- **#1706** still merges cleanly.
- **#1652** conflicts only in two import blocks at the top of
`conversation.ts`: the `../shared/protocol.ts` type import, and the line
after `./tool-output.ts` where it adds its Copilot imports. Its code
changes do not touch the moved parser.
- **#1442** already conflicts with main in `conversation.ts`, and needs
a rebase either way.

Move-only: moved declarations plus imports, re-exports and four `export`
keywords. No changelog fragment: users see no change.
devswha added a commit that referenced this pull request Oct 23, 2026
…s/live.ts (#1761)

Wave P1b of the per-agent module split. The plan is
`.omo/plans/agent-modules-split.md` in the maintainer's workspace, and
plan-reviewer approved it. It follows P1a (#1755) and C1 (#1760).

This wave moves the live-screen tail checks out of `server/prompt.ts`
into a new leaf module, `server/dialogs/live.ts`. These are the
per-agent checks that say whether a dialog parsed from the screen is
still drawn at its bottom. `prompt.ts` keeps every per-pane map, the
queue drivers and every route.

## What changes

- **Moved verbatim, with their doc comments:**
- the omo task and spinner patterns (`OMO_TASK_ROW_RE` through
`OMO_EMPTY_BOX_RE`);
- `CLAUDE_SUBMIT_TAIL_RE`, `omoFooterIsActive` and `promptTailIsActive`;
- the pi and Command Code footer helpers (`PI_MENU_HINT_AT_END_RE`,
`PI_INPUT_HINT_AT_END_RE`, `CMD_HINT_RE`, `CMD_FOOTER_WORDS`,
`cmdFooterEnds`, `PI_MODEL_HINT_AT_END_RE`, `PI_FOOTER_LINES`);
  - `hintAtEnd`, `parsePrompt` and `liveScreen`.
- **New `export` keywords:** `parsePrompt`, `promptTailIsActive` and
`liveScreen`. `prompt.ts` imports these three back.
- **No re-exports:** nothing else imported these names from `prompt.ts`.
- **Imports:** `prompt.ts`'s imports from `./dialogs/*` narrow to what
it still uses. `live.ts` imports the same names from the same dialogs
modules, plus `paneRead` from `../herdr/client.ts`.
- **State:** none. Nothing that moves holds module state, and no
`herdrRpc` call moves (`liveScreen` uses the typed `paneRead` wrapper).

`server/prompt.ts` goes from 1,530 to 1,334 lines.

## Checks

- **`--color-moved`:** `git diff --color-moved=plain
--color-moved-ws=allow-indentation-change origin/main...HEAD` shows 382
lines as moved. The other 30 lines are:
  - `live.ts`'s eleven import lines;
  - `prompt.ts`'s narrowed and new import lines;
- the three declarations whose only change is the added `export`, each
shown as removed and added.
- **No import cycle:** `bun <plan>/no-path.ts server/dialogs/live.ts
server/prompt.ts server/conversation.ts` prints "no path to
server/prompt.ts, server/conversation.ts". The new module never reaches
either file through value imports.
- **Typecheck:** `bun run typecheck` passes.
- **Unit tests:** **589 pass, 0 fail across 20 files**, from:

`HERDR_TEST_MODE=unit bun test server/prompt.test.ts server/dialogs/
server/hermes-prompt.test.ts server/cmd.test.ts server/core/`

  Every `parseInteractivePrompt` path runs through `parsePrompt`.
- `bun run check fast`: passes (unit 6253 pass, 0 fail, 13 skip in 443
files, 8 at a time, 73.5s)
- **Integration lane:** CI runs pending-input, prompt, opencode-prompt
and claude-session contracts.

## Outside PRs that touch the same files

No other maintainer PR touches these files. Three outside contributors'
PRs touch `server/prompt.ts`. Each has a small change inside a function
that now lives in `server/dialogs/live.ts`, so its rebase carries that
change into the new file. I checked each with `git merge-tree`:
- **#1670** merges cleanly with main, and conflicts with this branch in
`server/prompt.ts`.
- **#1714** already conflicts with main in `server/prompt.ts`, and needs
a rebase either way.
- **#1669** already conflicts with main in `server/prompt.ts`, and needs
a rebase either way.

Move-only: moved declarations plus imports and three `export` keywords.
No changelog fragment: users see no change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant