Skip to content

[feat] Hint the user to start a new session after N conversation turns #227

Description

@jeff-r2026

Problem

Long-running AI coding sessions accumulate large context windows, which degrades response quality and increases cost. There is currently no signal nudging the user to start a fresh session once a conversation has gone on for many turns.

Proposed Solution

Add a new prompt-submit (UserPromptSubmit) hook handler that counts human conversation turns per session and injects a gentle, one-time reminder when the count crosses a threshold.

  • Threshold: default 20 turns, overridable via TEAMAI_TURN_LIMIT.
  • Frequency: hint once per session (fires on the first crossing, then stays quiet).
  • Kill switch: TEAMAI_TURN_HINT_DISABLED=1, independent from TEAMAI_RECALL_DISABLED.

Why this fits cleanly

  • The hook dispatcher already fires on prompt-submit for every user message (trackSlashHandler is already wired there), so one user turn == one prompt-submit.
  • Handler return values are injected back into the session by the host (hookSpecificOutput.additionalContext).
  • Per-session counting + 24h TTL dedup is an established pattern (todowrite-hint.ts).

Net change: one new handler + one small module. No dispatcher changes, no new command.

Implementation sketch

  1. src/turn-limit-hint.ts — count store at ~/.teamai/sessions/<sid>-turn-count.json (24h TTL), resolveTurnLimit(), recordTurnAndShouldHint(), buildTurnLimitHintMessage().
  2. Register turnLimitHintHandler on prompt-submit in hook-handlers.ts.
  3. Unit tests (threshold, once-only, TTL reset, env override, disable switch).
  4. End-to-end verification with the real CLI via hook-dispatch prompt-submit.
  5. Sync docs (README + README.zh-CN + usage-guide both languages).

Alternatives Considered

  • Count on stop instead of prompt-submit: rejected — stop fires per assistant turn including tool loops, so it doesn't map to "human turns".
  • Hard-block via continue:false: rejected — too disruptive; a soft additionalContext nudge lets the model relay it at a natural moment.
  • Reuse TEAMAI_RECALL_DISABLED as the switch: rejected — coupling unrelated features; a dedicated switch is clearer.

Additional Context

Turn semantics: counts UserPromptSubmit events only; subagent round-trips and tool calls do not count, matching the "human conversation" intent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions