Skip to content

feat(session): add /goal that keeps working until the condition is met - #75

Open
yukihamada wants to merge 1 commit into
headless-model-fallbackfrom
sente-goal
Open

yukihamada wants to merge 1 commit into
headless-model-fallbackfrom
sente-goal

Conversation

@yukihamada

Copy link
Copy Markdown
Owner

概要

/goal <完了条件> を追加しました。ターンが終わるたびに小さい判定モデルが完了条件を照合し、未達なら短いリマインダーを付けて自動で次のターンを続けます(Claude Code / Codex / Grok の /goal と同じ使い方。本家 OpenCode anomalyco#59437 / anomalyco#65788 の設計を Sente の従来経路 packages/sente/src/session/* に移植)。

使い方

  • /goal <完了条件> 設定して開始 / /goal 現在のゴールと進捗 / /goal clear 解除 / /goal resume 停止中のゴールを再開
  • sente run --goal "<条件>" [--goal-max-rounds N] 非対話でも同じループ。終了時に「ゴール達成: …」「ゴール停止: …」を表示(--format json では goal イベント)

設計

  • 状態: セッション metadata の goal(id / 条件 / status / rounds / maxRounds / reason / repeats)。TUI・run・SDK のどれからでも同じ状態を見て解除できる。fork には引き継がない
  • 判定: hidden の goal エージェント(既定は small_model → 無ければ会話のモデル)に、ゴール開始以降の作業ログ(発話・ツール入出力を切り詰め、最新24k字まで)と未完了 todo を渡し、VERDICT / REASON / NEXT の行形式で回答させる(小さいモデルで JSON が壊れやすいため。JSON 回答も受理)。使えない回答は1回だけ再試行
  • 継続: 未達なら「ゴール: … / 未達の点: … / 次の一手: …(自動継続 n/上限)」を synthetic な user メッセージとして追加して次のターンへ
  • キャッシュ: 圧縮で開始メッセージが消えた時だけ、保存しないリマインダーを先頭メッセージ直後に挿入(本家 fix(core): keep the goal reminder out of the cache tail anomalyco/opencode#65788 と同じく末尾=キャッシュ点を動かさない)
  • 停止条件: ①done ②blocked(利用者の対応が必要)③継続上限(既定20、SENTE_GOAL_MAX_ROUNDS / --goal-max-rounds、上限到達時は判定を呼ばず停止)④利用者の入力・中断(esc)⑤同じ未達理由が3回連続(表記ゆれは bigram 類似度 0.85 で同一扱い)⑥エラー・承認拒否でターンが途中終了
  • 費用上限: 継続は通常のターンなので、既存の依頼ごと費用上限(/cost、既定 $1)の承認ゲートをそのまま通る。拒否されるとループが終わり、ゴールは停止扱い。判定呼び出しは title/summary と同じ内部補助扱い(承認ゲートの対象外、小モデル1回分)
  • todo-followup との関係: ゴール進行中は todo の追い込みを出さず、判定に未完了 todo を渡す(二重にターンが増えない)
  • 既存の利用者独自 goal コマンド(~/.config/sente/command/goal.md 等)がある場合: その本文を追加指示としてキックオフに添える。SENTE_GOAL_LOOP=0 でループを無効化して従来のテンプレートコマンドに戻せる
  • TUI: 入力欄下の右側に ゴール 3/20(英語 goal 3/20)。/goal と /goal clear は手元で処理。達成・停止時に理由付きトースト

テスト

  • packages/sente: bun run typecheck 通過
  • bun test test/session/goal.test.ts 14 pass(解析・上限・同一理由3回・判定行解析・割り込み判定・リマインダー位置・作業ログ)
  • bun test test/session/prompt.test.ts -t goal 9 pass(完了で停止 / 未達で継続 / 上限で停止 / 同一理由3回で停止 / 中断で停止 / 利用者入力で停止 / todo-followup と二重にならない / blocked・表示・clear / 利用者独自 goal コマンド)
  • packages/tui: bun run typecheck 通過、bun test 464 pass(新規 test/util/goal.test.ts 5件)
  • 既存失敗(base headless-model-fallback でも同じ失敗を確認): prompt.test.ts の7件(static loop consumes queued replies / loop defers compaction… / loop compacts and continues tool results… / loop sets status to busy then idle / cancel interrupts loop… / prompt submitted during an active run… / assertNotBusy…)、llm.test.ts の3件(openai-compatible / Anthropic Compatible / Gemini payload)、server/plugin の3件(openai.ws / workflow.js P0-1 / session HttpApi v2 unavailable)
  • CLI ヘルプのスナップショットは run --goal 追加分を更新。base で既に古かった stats --completion 分も同時に更新されています

実機確認(teai/cheap、費用上限 $0.3)

  • sente run --goal "count.txt に1〜3を書いて cat で確認" → 1ターンで「ゴール達成」
  • sente run --goal-max-rounds 2 --goal "plan.txt を書き、別のターンで result.txt…" → 判定が「未達の点: result.txt 未作成」→ 自動継続1回 → 「ゴール達成」(rounds=1)
  • TUI(tmux)で /goal note.txt に hi と書いて cat で確認 → 実行中フッターに ゴール 0/20、完了後に消える。/goal で状態トースト、/goal clear で metadata から削除を確認

既知の制限

  • サーバー再起動で実行中のループが切れた場合、ゴールは active のまま残る(次の利用者入力で停止扱いになる)。本家の boot ID 方式は未導入
  • 判定呼び出しの費用は title と同様にメッセージの費用集計に入らない(小モデル1回/ターン)
  • 判定は切り詰めた作業ログだけを見るため、長い出力の途中にしか証拠が無い場合は「未達」寄りになる

🤖 Generated with Claude Code

…he condition is met

`/goal <condition>` stores the goal in session metadata and starts the work.
After each finished turn a small reviewer model (hidden `goal` agent, small
model by default) reads a clipped log of the work and answers done /
continue / blocked. On continue, a short synthetic reminder ("goal / not met
yet / next step") starts another turn.

Stops on: done, blocked, the round limit (default 20, SENTE_GOAL_MAX_ROUNDS),
the same missing point three times in a row, the user typing or interrupting,
and any turn that ends early (error, refused cost approval). Continuations
are ordinary turns, so the existing request cost limit (/cost) still asks.
While a goal is active it replaces the todo follow-up, so the two never both
add a turn. The re-statement after compaction goes after the first message,
not at the cached tail.

TUI: `ゴール n/max` next to the usage line, `/goal` and `/goal clear` handled
locally, a toast when the goal is met or stops. `sente run --goal "<cond>"`
(and --goal-max-rounds) runs the same loop and prints the outcome. A user's
own `goal` command keeps working: its text joins the kickoff.
SENTE_GOAL_LOOP=0 turns the loop off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

This branch has not been deployed

No deployments
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