Skip to content

refactor(agents): key Herdr ownership by terminal_id - #272

Merged
furedea merged 3 commits into
mainfrom
refactor/herdr-ownership-by-terminal
Oct 21, 2026
Merged

furedea merged 3 commits into
mainfrom
refactor/herdr-ownership-by-terminal

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

概要

Herdr の所有モデルを,名前ベースの lane と terminal_id ベースの primary の二本立てから,terminal_id をキーにした単一のモデルへ統一する.あわせて skill の文章を短くする.

背景

名前ベースのモデルには次の 2 つの穴があった.

  1. agent start が失敗した場合や agent が終了した場合でも名前が記録されたまま残り,同じ名前で起動した別セッションが,prompt の自動承認と workspace の close/remove の自動承認を受けてしまう.
  2. ユーザーの既存 workspace の空きペインで lane を起動すると,その workspace の全 agent が「自分のもの」になり,workspace(とユーザーのシェルペイン)の close が自動承認されてしまう.

変更内容

  • セッションが所有するのは,自身の成功した単一・単純・直接の herdr 呼び出し(workspace create,worktree create,agent start)が作ったものだけとし,terminal_id で識別する.記録は PostToolUse で結果 JSON から行い,実行前には保存しない(実行前の「同名の生きた agent がいれば拒否」は維持).
  • PreToolUse の判定:
    • agent prompt: 記録された名前かつ,生きた agent の terminal_id と agent session が記録と一致する場合のみ許可.
    • workspace close と worktree remove --workspace: 記録済みで,id・label・path が一致し,記録済みルート terminal が存在し,その中の全 agent が記録済みの場合のみ許可.それ以外は ask.
  • レビュー指摘への対応:
    • 記録の失効は,実行前ではなく close/remove の成功結果(PostToolUse)で行う.workspace close と worktree remove の PostToolUse フックを登録した.
    • worktree remove は --workspace <ID> のみの形で,リンクされた worktree に限り自動承認する.
    • グローバルオプションはすべて server override として扱い,ask にする.
    • 結果の type が想定どおり(close は実際の ok)の場合のみ記録・失効し,worktree remove は結果の workspace_id で失効させる.
    • 記録の更新はセッションのロックを取って行う(並行テスト付き).
  • 名前ベースの分岐と primary 専用の特殊処理,およびそれらだけを検証していたテストを削除した.
  • agents/hooks.json に worktree create,agent start,workspace close,worktree remove の PostToolUse フックを追加した.
  • branches.md と herdr-delegation/SKILL.md の文章を短縮した.gh api の引用符の項目は,単一呼び出しのルールの直後に置いた.
  • テストが 500 行の上限を超えたため,test_herdr_ownership_workspaces.py と共有ヘルパー herdr_runtime.py に分割した.

確認

  • uv run --frozen pytest tests/agents: 1958 passed
  • lefthook(pre-commit,commit-msg,pre-push): 通過

Closes #270

🤖 Generated with Claude Code

furedea and others added 3 commits October 21, 2026 22:58
Record workspaces and agents from the result of one simple direct
herdr call (workspace create, worktree create, agent start) instead of
claiming agent names before the command runs. Prompt and close are
allowed only when the live terminal matches the recorded terminal_id,
which closes the stale-name and shared-workspace holes. Trim the
matching skill text and split the ownership tests to stay within the
file-length budget.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Expire records from the successful close or remove result instead of
before the command runs, match agents by terminal and agent session,
limit worktree remove to a bare --workspace on a linked worktree, and
treat any global option as a server override. Register the PostToolUse
hooks for workspace close and worktree remove, and restore the gh api
quoting rule next to the single-call rule.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Hold the session lock while a create, start, close, or remove result
updates the record, accept the real `ok` response type for workspace
close, and expire a removed worktree by the workspace_id in its
result. Simplify the worktree path handling and the agent match.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea
furedea merged commit dabf958 into main Oct 21, 2026
11 checks passed
@furedea
furedea deleted the refactor/herdr-ownership-by-terminal branch October 21, 2026 16:19
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.

Herdr の所有権を terminal_id の記録に一本化し,skill の記述を手順だけに削る

1 participant