Skip to content

feat: migrate enemy chaser taxonomy (#985) - #1122

Merged
squne121 merged 5 commits into
mainfrom
worktree-issue-985-enemy-taxonomy
Jun 21, 2026
Merged

squne121 merged 5 commits into
mainfrom
worktree-issue-985-enemy-taxonomy

Conversation

@squne121

@squne121 squne121 commented Jun 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • 既存 enemy_chaser を新 taxonomy の required schema へ移行し、EnemyState に faction / role / behaviorState / targetingPolicy / targetEntityId を追加しました。
  • spawnEnemy() で taxonomy field を必ず初期化し、runEnemyAISystem では behaviorState / targetEntityId を更新しながら既存 chaser の移動 trace は維持しました。
  • no-ally fixture 前提の compatibility test を 2 本追加し、pure enemy AI の golden trace と sortie における CommandIntent.none / sample_assist_player lane 分離を固定しました。

受け入れ条件の達成状況

  • AC1: src/state/GameState.ts の EnemyState に required taxonomy fields を追加しました。根拠: faction: 'enemy'、role: 'enemy_chaser'、behaviorState、targetingPolicy: 'focus_player'、targetEntityId を runtime schema に固定しました。
  • AC2: src/systems/EnemySpawnSystem.ts の spawn literal を taxonomy-complete に更新しました。根拠: spawned enemy 生成時に required taxonomy fields を必ず初期化しています。
  • AC3: tests/systems/enemy-ai-taxonomy-compatibility.test.ts を追加し、one enemy / multiple enemies / defeated / invalid fixedDeltaMs / overshoot clamp / epsilon の golden trace contract を固定しました。
  • AC4: tests/systems/sortie-enemy-taxonomy-compatibility.test.ts を追加し、CommandIntent.none + no allies と sample_assist_player + no allies を分離し、fixture 冒頭で no-ally 前提を固定しました。
  • AC5: src/systems/EnemyAISystem.ts / src/systems/EnemySpawnSystem.ts に Date.now / performance.now / Math.random / window. / document. / CanvasRenderingContext2D 依存を追加していません。
  • AC6: canonical static gates と Python 補助テストが通過しました。

検証コマンド結果

  • rtk pnpm typecheck で型検査に成功しました。
  • rtk pnpm lint で lint に成功しました。
  • rtk pnpm test で全件テストに成功しました。
  • rtk pnpm build で build に成功しました。
  • uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py で Python 補助テストに成功しました。
  • rtk vitest run tests/systems/enemy-ai-taxonomy-compatibility.test.ts で targeted enemy AI compatibility test に成功しました。
  • rtk vitest run tests/systems/sortie-enemy-taxonomy-compatibility.test.ts で targeted sortie compatibility test に成功しました。

Allowed Paths 遵守

  • 変更ファイルは issue 実装: existing enemy_chaser を new taxonomy へ非破壊移行する #985 の Allowed Paths 内に限定しました。
  • PR diff の変更対象: src/state/GameState.ts、src/systems/EnemyAISystem.ts、src/systems/EnemySpawnSystem.ts、tests/systems/enemy-ai-taxonomy-compatibility.test.ts、tests/systems/sortie-enemy-taxonomy-compatibility.test.ts
  • .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py は verification-only read path として参照しました。

Checks

  • 型検査: rtk pnpm typecheck
  • Lint: rtk pnpm lint
  • 全件テスト: rtk pnpm test
  • build: rtk pnpm build
  • Python 補助テスト: uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py
  • targeted enemy AI compatibility: rtk vitest run tests/systems/enemy-ai-taxonomy-compatibility.test.ts
  • targeted sortie compatibility: rtk vitest run tests/systems/sortie-enemy-taxonomy-compatibility.test.ts

Schema Change Applicability

  • decision: schema_change
  • reason: EnemyState の runtime schema に required taxonomy fields を追加し、spawn / AI / compatibility tests の consumer を同期したためです。

Schema Consumer Inventory

変更対象 schema: EnemyState runtime taxonomy schema

before/after 差分:

# before
- EnemyState は combat / movement の基本 field のみを持ち、enemy taxonomy の runtime field を持たない
- spawnEnemy() は taxonomy field を埋めない
- enemy AI compatibility は legacy chaser movement trace のみを見ていた

# after
- EnemyState は faction / role / behaviorState / targetingPolicy / targetEntityId を required として持つ
- spawnEnemy() は required taxonomy fields を必ず初期化する
- EnemyAISystem は target/player 追尾 trace を変えずに behaviorState / targetEntityId を更新する
- compatibility tests は no-ally fixture と command intent lane 分離を固定し、golden trace を追加する

Consumer 列挙(rg コマンド例と結果):

rg -l EnemyState src tests
src/systems/EnemySpawnSystem.ts
src/state/GameState.ts

rg -l targetEntityId src/state/GameState.ts src/systems/EnemyAISystem.ts tests/systems
src/state/GameState.ts
tests/systems/ally-behavior-system.test.ts
tests/systems/targeting-system.test.ts

gh pr view 1122 --json files --jq '.files[].path'
src/state/GameState.ts
src/systems/EnemyAISystem.ts
src/systems/EnemySpawnSystem.ts
tests/systems/enemy-ai-taxonomy-compatibility.test.ts
tests/systems/sortie-enemy-taxonomy-compatibility.test.ts

Consumer 更新状況:

Consumer ファイル 更新有無 備考
src/state/GameState.ts yes EnemyState に required taxonomy fields と EnemyTaxonomyBehaviorState を追加
src/systems/EnemySpawnSystem.ts yes spawned enemy の taxonomy fields を初期化
src/systems/EnemyAISystem.ts yes behaviorState / targetEntityId を更新しつつ movement trace は維持
tests/systems/enemy-ai-taxonomy-compatibility.test.ts yes one enemy / multiple / defeated / invalid delta / overshoot / epsilon の golden trace を固定
tests/systems/sortie-enemy-taxonomy-compatibility.test.ts yes no-ally fixture と CommandIntent.none / sample_assist_player lane 分離を固定

互換性判定 (Compatibility Decision)

  • change_type: additive
  • compatibility: backward_compatible
  • migration_required: no
  • migration_or_followup: N/A
  • reason: required taxonomy fields を runtime object に追加しましたが、spawn / AI / compatibility tests を同一 PR 内で同期し、enemy movement trace と sortie compatibility gate は維持しています。

Safety Claim Matrix

N/A reason: この PR は safety-sensitive path を変更しておらず、追加した変更は enemy taxonomy と deterministic compatibility test の範囲に閉じています。

Notes

@github-actions

github-actions Bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #1122 closed).

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOOP_VERDICT_V2

verdict: REQUEST_CHANGES
reviewed_head_sha: "7d37827276c7723d7b821e06cde7146818c7bf83"
merge_ready: false
mergeability:
mergeable: "MERGEABLE"
merge_state_status: "BEHIND"
blockers:

  • "CI_CHECK_RUN_SCOPED is not green for reviewed head SHA 7d37827: ci_verdict_summary.py returned pending_or_queued at 2026-06-21T14:16:22Z, with python-test still in_progress."
    required_auto_actions:
  • kind: update_pr_body_hygiene
    executor: implementation-worker
    skill: open-pr.update_pr
    blocking_merge_ready: true
    mechanical: true
  • kind: update_branch
    executor: implementation-worker
    skill: implement-issue.update_branch
    blocking_merge_ready: true
    mechanical: true
    expected_head_sha: "7d37827276c7723d7b821e06cde7146818c7bf83"
    auto_fix_applied: []
    follow_up_issue_requests: []
    allowed_paths_gate:
    status: ok
    allowed_paths_gate_source: review_subagent

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOOP_VERDICT_V2

verdict: APPROVE
reviewed_head_sha: "d0373226077ceb74066f2822e3f004806a926a4a"
merge_ready: false
mergeability:
mergeable: "MERGEABLE"
merge_state_status: "BEHIND"
blockers: []
required_auto_actions:

  • kind: update_pr_body_hygiene
    executor: implementation-worker
    skill: open-pr.update_pr
    blocking_merge_ready: true
    mechanical: true
  • kind: update_branch
    executor: implementation-worker
    skill: implement-issue.update_branch
    blocking_merge_ready: true
    mechanical: true
    expected_head_sha: "d0373226077ceb74066f2822e3f004806a926a4a"
    auto_fix_applied: []
    follow_up_issue_requests: []
    allowed_paths_gate:
    status: ok
    allowed_paths_gate_source: review_subagent

@squne121

Copy link
Copy Markdown
Owner Author

判定

REQUEST_CHANGES 寄り。
実装の本筋、つまり EnemyState への required taxonomy field 追加、spawnEnemy() での初期化、既存 chaser movement trace の維持は概ね通っています。ただし、PR証跡のSHA不整合と、terminal tick / no-op command compatibility の検証が「新実装同士の比較」に寄っている点は、#985 の contract から見るとマージ前に直すべきです。

レビュー投稿はしていません。

良い点

#985 は stage 6 の “enemy policy migration” で、既存 enemy_chaser に faction / role / behaviorState / targetingPolicy / targetEntityId を required runtime field として追加しつつ、no-ally + CommandIntent.none で既存 runEnemyAISystem と tick-by-tick の位置・collision ordering・terminal tick を維持する契約です。PR #1122 はこの契約に対して、変更ファイルを GameState.ts、EnemyAISystem.ts、EnemySpawnSystem.ts、2本の compatibility test に限定しており、Allowed Paths の範囲は妥当です。

EnemyState は faction: 'enemy'、role: 'enemy_chaser'、behaviorState、targetingPolicy: 'focus_player'、targetEntityId を required field として持つようになっています。spawnEnemy() も同じ field を literal で埋めているので、TypeScript の型だけ足して runtime object に値が入らない、という典型的な失敗は避けられています。TypeScript 公式は import type / export type が runtime 出力から erase されると明記しているため、この PR が spawn path まで実データを埋めた点は正しいです。 ([TypeScript]1)

CI については、現在取得できた head SHA cc9278d1f05d94a4f7b21934b87241c44656de8a に対して ci、deploy-pages、agent-session-manifest、Check Japanese Content、check-hook-integrity は成功しています。CI run 27907744698 の job も python-test、lint、build、test、e2e、actionlint、typecheck、ci-verdict-summary が成功しています。

Blocker 1: PR body / review 証跡の head SHA が stale

PR 本文には Reviewed head SHA: 1ec03183f1448d9698d9fc65db0e160bd201dd52 とありますが、現在の PR head は cc9278d1f05d94a4f7b21934b87241c44656de8a です。さらに既存レビューコメントでは、7d378272... では CI pending、d037322... では APPROVE だが merge_ready: false、かつ update_pr_body_hygiene と update_branch が required auto action とされています。

これはコード品質の問題というより、監査証跡として危険です。現 head の CI は緑ですが、PR body が別 SHA の検証結果を主張しているため、後続の review loop / merge gate が「何を検証したのか」を取り違えます。

修正要求:

Reviewed head SHA: cc9278d1f05d94a4f7b21934b87241c44656de8a
GitHub Actions CI run: 27907744698
Result: ci / typecheck / lint / test / build / e2e / python-test / ci-verdict-summary all success

また、古い 1ec031...、7d378...、d037322... は historical note に落とすか削除してください。

Blocker 2: terminal tick 検証がまだ “new implementation vs new implementation” に寄っている

SSOT §14.1 は、no allies + CommandIntent.none で current runEnemyAISystem と同じ tick-by-tick enemy positions、既存 sortie terminal timing、collision pair ordering、no-op command intent path の golden test を要求しています。

追加された enemy-ai-taxonomy-compatibility.test.ts は [339, 338, 280] の precomputed golden positions を持っているため、enemy movement の主要 regression guard としては良いです。

一方、sortie-enemy-taxonomy-compatibility.test.ts の terminal 検証は、none lane と sample_assist_player lane の elapsedTicks / tick / endReason が等しいことを確認するだけです。つまり「両 lane が同じ新実装上で同じ結果になる」ことは証明していますが、「legacy / precomputed terminal tick と同じ」ことは固定していません。

修正要求:

runTerminalLane('none') に対して、legacy 由来の literal expectation を追加してください。例:

expect(noneLane.sortie.status).toBe('defeat')
expect(noneLane.tick).toBe(/* legacy expected tick */)
expect(noneLane.sortie.elapsedTicks).toBe(/* legacy expected elapsedTicks */)
expect(noneLane.sortie.result?.durationMs).toBe(/* legacy expected durationMs */)

そのうえで sample_assist_player lane が同じ値になることを比較してください。可能なら §14.1 の文面どおり、defeat だけでなく victory / timeout の terminal tick も precomputed golden にした方が堅いです。

Blocker 3: behaviorState: 'attack' の意味が実際の攻撃・接触とズレている

runEnemyAISystem() は、敵中心とプレイヤー中心の距離が ENEMY_AI_EPSILON_PX = 0.5 以下になったときだけ behaviorState = 'attack' にしています。敵の radius やプレイヤーの radius、接触ダメージ範囲は見ていません。

これは互換性維持だけを目的にするなら許容できます。ただし taxonomy としては危険です。SSOT 上の NpcBehaviorState は move_to_engage → attack のような行動状態として説明されており、downstream の debug panel / UI / ally targeting が attack を「攻撃中」や「接触中」と解釈すると、実態とズレます。

修正方針は2択です。

  1. 実装: existing enemy_chaser を new taxonomy へ非破壊移行する #985 では attack を「中心点が epsilon 内に入った互換 placeholder」と明記し、後続 issue で contact/range based state に改修する。
  2. 今回の PR で distance <= player.radius + enemy.radius などの collision/contact semantic に合わせる。ただしこれは挙動・状態 semantics の変更なので、実装: existing enemy_chaser を new taxonomy へ非破壊移行する #985 の「挙動は変えない」契約からは外れやすいです。

この PR では 1 を推奨します。PR body と test 名に “compatibility placeholder” を明記してください。

P1: invalid tick / invalid player 座標時に taxonomy invariant が更新されない

runEnemyAISystem() は fixedDeltaMs が invalid の場合、または player 座標が non-finite の場合、enemy loop に入る前に return します。そのため、既存 enemy が stale な targetEntityId や stale な behaviorState を持っていても正規化されません。

現テストは invalid fixedDeltaMs で位置が動かないことと、初期値 targetEntityId: 'player-alpha' が残ることだけを確認しています。これは「壊れない」テストではありますが、「required taxonomy field の runtime invariant を保つ」テストではありません。

追加テスト案:

it('GIVEN invalid fixedDeltaMs and stale targetEntityId WHEN AI runs THEN taxonomy normalization policy is explicit', () => {
  const state = createInitialGameState()
  state.enemies = [
    makeEnemy({ targetEntityId: 'enemy:stale', behaviorState: 'attack' }),
  ]

  runEnemyAISystem(state, Number.NaN)

  // どちらかに固定する:
  // A. invalid tick では完全 no-op:
  expect(state.enemies[0].targetEntityId).toBe('enemy:stale')

  // B. taxonomy invariant は normalize する:
  // expect(state.enemies[0].targetEntityId).toBe(state.player.id)
})

現状の実装なら A です。A を採るなら、PR body に「invalid fixedDeltaMs / invalid player position では taxonomy field も no-op」と明記すべきです。

P1: no-ally fixture は contract 通りだが、production state と乖離している

startSortie() は resetCombatRuntime() 経由で state.allies = [createDefaultAllyState(1)] と nextAllyId = 2 をセットします。今回の test fixture はその後に state.allies = []、nextAllyId = 1、command intent 初期化、allies.length === 0 assert を入れており、#985 の no-ally fixture contract には合っています。

ただしこれは production の sortie 初期状態ではなく、compatibility 専用の人工 state です。今のままでもよいですが、後続の agent がこの fixture を通常仕様と誤読しないよう、createNoAllySortieState() にコメントを足した方が安全です。

// Compatibility-only fixture for #985 / SSOT §14.1.
// startSortie() intentionally creates one default ally in production;
// this test clears allies to freeze the legacy no-ally enemy_chaser contract.

P2: PR preview URL を acceptance evidence と混同しないこと

Bot は PR preview URL を投稿していますが、SSOT の Evidence / Distribution Policy は、UI / playtest follow-up PR で PR preview URL だけを証跡にすることを禁止し、commit SHA、GitHub Actions run ID、artifact URL / name / digest / retention-days、viewport / DPR / zoom / userAgent / timezone、screenshot/video path などを要求しています。

GitHub の deploy-pages は page_url を output しますが、PR preview input は alpha で public 利用不可とされています。upload-artifact は artifact-url、artifact-digest、retention-days などの証跡を出せます。したがって、この PR では preview は参考情報に留め、acceptance evidence は current head SHA と CI run ID に寄せるべきです。(GitHub) (GitHub)

外部実装調査からの補強

TargetingSystem 側は .slice().sort(...) を使っており、入力配列を直接 mutate しない形になっています。MDN は Array.prototype.sort() が in-place mutation で同じ配列参照を返すと説明しているため、今後 enemy 側で targeting policy を接続する場合も、現行の .slice().sort 方針を維持すべきです。 ([MDN Web Docs]4)

Canvas については、今回の PR は runtime taxonomy / compatibility test なので直接の UI 実装対象ではありません。ただし後続 stage 7 で command affordance を Canvas に寄せる場合、MDN は <canvas> 単体が bitmap であり、描画オブジェクトが semantic HTML として accessibility tools に露出しないと説明しています。SSOT が DOM/focusable control を authoritative surface としている判断は妥当です。([MDN Web Docs]5)

マージ前チェックリスト

最低限、以下を直せば merge-ready に近づきます。

  1. PR body の Reviewed head SHA を cc9278d1f05d94a4f7b21934b87241c44656de8a に更新し、CI run 27907744698 を明記する。
  2. terminal tick test を none lane vs assist lane だけでなく、legacy / precomputed literal expectation に固定する。
  3. behaviorState: 'attack' が現時点では epsilon co-location placeholder であり、contact/range semantic ではないことを PR body または test comment に明記する。
  4. invalid fixedDeltaMs / invalid player position 時の taxonomy normalization policy をテストで明示する。
  5. PR preview URL を acceptance evidence として扱わず、current SHA + CI run + targeted tests を evidence の中心にする。

結論として、コード差分の方向性は妥当。ただし #985 の “compatibility gate” と監査証跡の厳密性にはまだ穴があります。

@squne121
squne121 marked this pull request as ready for review June 21, 2026 15:11

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE

Mergeability

  • mergeable=MERGEABLE, merge_state_status=CLEAN

Evidence Check

  • AC coverage: issue #985 の AC1-AC6 が PR 本文の達成状況と diff で対応しており、EnemyState required taxonomy fields、spawn 初期化、EnemyAISystem の trace 維持、2 本の compatibility test 追加を確認しました。
  • Allowed Paths: git diff --name-only f749960e89ed4723feb8c9616c7a910106ae08fd...399833e74810828c436b17690dd968f99d92f8f8 の変更ファイル 5 件は issue #985 の Allowed Paths 内でした。
  • CI Verification: ci_verdict_summary.py で expected_head_sha=399833e74810828c436b17690dd968f99d92f8f8 と一致する all_pass を確認しました。
  • 検証コマンド結果: PR 本文に canonical static gates と targeted compatibility tests の完了記録があり、live checks も success です。
  • Schema Gate: schema_change と Schema Consumer Inventory が diff と整合し、compatibility decision は backward_compatible でした。

Blockers

  • なし

Non-blockers

  • なし

LOOP_VERDICT_V2

verdict: APPROVE
reviewed_head_sha: "399833e74810828c436b17690dd968f99d92f8f8"
merge_ready: true
mergeability:
  mergeable: MERGEABLE
  merge_state_status: CLEAN
blockers: []
required_auto_actions: []
auto_fix_applied: []
follow_up_issue_requests: []
allowed_paths_gate:
  status: ok
allowed_paths_gate_source: review_subagent

@squne121
squne121 merged commit 3917a09 into main Jun 21, 2026
25 checks passed
@squne121
squne121 deleted the worktree-issue-985-enemy-taxonomy branch June 21, 2026 23:15
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.

実装: existing enemy_chaser を new taxonomy へ非破壊移行する

1 participant