Repository navigation
Closed
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasetriage-requiredNeeds owner triage for priority decision
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "975"
goal_ref: "deterministic target scoring pure function を追加し、candidate filter・tie-break・score tuple を unit test で固定する"
change_kind: code
ssot_sections: ["§8", "§8.5"]
stage: 4
blocked_by: [981, 982]
dedupe_key: "follow-up:squne121/loop-protocol:pr/978:stage4"この stage の詳細契約は docs/product/features/unit-operations-and-npc-behavior.md §8(候補フィルタ/tie-break/score tuple), §8.5 が SSOT である。本文の AC/Allowed Paths/VC はそれと矛盾しない。
Parent Issue
関連 PR: #978(docs(#975): define unit operations and NPC behavior SSOT, merged)
Parent Goal Ref
- Goal: §8 の candidate filter・tie-break(entityId ASC)・assist_player/enemy_chaser score tuple を pure function として実装し unit test を付ける
- Desired Destination: targeting scoring pure function が
src/systems/に存在し、同一入力で同一出力が unit test で証明された状態
Current Validated Scope
src/systems/に新規 targeting モジュールを追加する(ファイル名は実装者に委ねる)tests/に targeting unit test を追加する
Remaining Parent Gaps
- stage5: ally_basic NPC state と semi-autonomous behavior(本 Issue 完了後)
- stage6: existing enemy_chaser を new taxonomy へ非破壊移行(本 Issue 完了後)
- stage7: assist_player DOM command affordance と Canvas visual cue(stage3/5 完了後)
- stage8: assist_player playtest self-explanation test と evidence policy(stage7 完了後)
Blocked by
stage2(#981)— CommandIntent/Faction/TargetingPolicy 型が src/state に存在することを前提とする
stage3(#982)— CommandIntent buffer が存在することを前提とする
Outcome
§8 の candidate filter・tie-break(entityId ASC)・assist_player/enemy_chaser score tuple を pure function として実装し unit test を付ける。randomness/wall-clock/render/DOM/frame-rate 依存なし。
In Scope
src/systems/への targeting モジュール追加- candidate filter(defeated/同faction/arena外/stale 除外)
- tie-break(entityId ASC)
- §8.3/§8.4 の score tuple
threatToPlayerは §8.5 の 3 案から 1 つ選び式を明記tests/への unit test 追加
Out of Scope
- ally collection・behavior runtime の実装(stage5 の責務)
- enemy_chaser の taxonomy 移行(stage6 の責務)
- DOM affordance / Canvas cue(stage7 の責務)
- randomness・wall-clock・render・DOM・frame-rate への依存
Acceptance Criteria
- AC1: defeated/同faction/arena外/stale な candidate を除外する
- AC2: 最終 tie-break が entityId ASC である
- AC3: §8.3/§8.4 の score tuple 順に従う
- AC4:
threatToPlayerは §8.5 の 3 案から 1 つ選び式を明記し、randomness/wall-clock/render/DOM/frame-rate 依存なし - AC5: 同一入力で同一出力を確認する deterministic unit test が通る
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
- TypeScript / TSC strict
- ECS(state / systems 分離)
- deterministic pure function 設計
Verification Commands
実装前は targeting モジュールが未作成のため AC1〜AC5 の rg/test は baseline-fail する。
# AC1
# baseline-expect: fail
$ pnpm test# AC2
# baseline-expect: fail
$ rg -e entityId src/systems
$ rg -e threatToPlayer src/systems
$ rg -e commandIntentMatch src/systems# AC3
$ rg -e entityId src/systems
$ rg -e threatToPlayer src/systems
$ rg -e commandIntentMatch src/systems# AC4
# baseline-expect: pass
$ rg "Date\.now" src/systems
# baseline-expect: pass
$ rg "performance\.now" src/systems
# baseline-expect: fail
$ rg "Math\.random" src/systems# AC5
$ pnpm typecheckAllowed Paths
src/systems/(新規 targeting モジュール)tests/
Runtime Verification Applicability
- decision: deferred
- reason: targeting モジュールは実装後に pnpm test で検証する。実装前は test file が存在しないため baseline-fail。
- deferred_destination:
- destination_type: issue
- destination_ref: "実装: unit taxonomy 型5種(Faction / UnitRole / CommandIntent / NpcBehaviorState / TargetingPolicy)を src/state に追加する #981"(stage2 完了後・本 Issue 実装完了時)
- deferred_verification_condition: src/systems/ に targeting モジュールが存在し、同一入力同一出力を確認する unit test が PASS すること
Source
- dedupe_key:
follow-up:squne121/loop-protocol:pr/978:stage4 - artifact SSOT:
docs/product/features/unit-operations-and-npc-behavior.md§8, §8.5 - merged PR: docs(#975): define unit operations and NPC behavior SSOT #978
- research issue: 調査: 味方機体・敵機体の運用モデルと NPC 行動契約を正本化する #975
- blocked by: 実装: unit taxonomy 型5種(Faction / UnitRole / CommandIntent / NpcBehaviorState / TargetingPolicy)を src/state に追加する #981(stage2), 実装: binding-agnostic command intent buffer と Z-equivalent mapping を追加する #982(stage3)
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasetriage-requiredNeeds owner triage for priority decision
Activity
squne121 commentedon Jun 20, 2026
判定
REQUEST_CHANGES / Issue contract 修正後に着手可。
#983 の方向性自体は妥当です。#978 で作られた SSOT の §8 / §8.5 を stage4 として実装し、target scoring を pure function として固定するのは、後続の #984 ally_basic と #985 enemy_chaser migration の前提として必要です。#983 は open、コメントは空です。
ただし、現状の #983 をそのまま Claude Code / Codex に渡すと、曖昧なスコア関数だけ作って終わる可能性が高いです。特に、
entityId ASCの型、stale target の出力契約、threatToPlayerの式、入力 snapshot、sort mutation、#982 との接続境界が弱いです。主要ブロッカー
1.
blocked_byと RVA が古い#983 はまだ
blocked_by: [981, 982]としていますが、#981 は closed/completed で、PR #988 により 5 型がsrc/state/GameState.tsに追加済みです。#982 も closed/completed で、CommandIntent buffer / KeyZ mapping / TTL contract が実装済み扱いになっています。
修正案:
また、#983 の Runtime Verification Applicability は
deferred_destination: "#981"になっていますが、これは明らかに不整合です。stage4 は pure function + unit test で閉じるため、runtime verification: not_applicableまたは少なくともdeferred_destination: 本 Issue 実装完了時に直すべきです。2. pure function の公開 API が未定義
SSOT は targeting を pure function とし、同一入力で同一結果を要求しています。
しかし #983 は「
src/systems/に新規 targeting モジュール」としか書いておらず、関数名、入力 snapshot、戻り値、stale target の扱いが未定義です。推奨 contract:
重要なのは、
GameStateを直接読まないことです。stage4 は後続 stage5/6 のための scoring kernel であり、ally runtime や enemy migration に結合しすぎると分割が崩れます。3.
entityId ASCが曖昧SSOT は最終 tie-break を
entityId ASCとしています。ただし現行
EnemyState.idは number、PlayerState.idはEntityIdで、初期値はplayer-alphaです。このままだと、
1と'player-alpha'の比較、敵 ID と player ID の比較、将来 ally ID の比較で実装が割れます。修正要求:
これを入れないと、「entityId ASC」は見た目だけ deterministic で、実装者ごとに別の ordering になります。
4.
threatToPlayerは実装者に選ばせない方がよいSSOT §8.5 は
threatToPlayerを 3 案から 1 つ選ぶ、としています。候補は inverse distance、projected time-to-contact、binary hostile-near-player です。#983 では binary hostile-near-player flag を固定するのが最も安全です。
理由は単純です。inverse distance は距離 0 の扱いに epsilon が必要で、projected time-to-contact は速度・進行方向が入力に必要です。現行
EnemyStateは速度を持ちますが、ally / generic target snapshot にはまだ速度契約がありません。stage4 では binary の方が後続の #984 / #985 に安全に渡せます。
5. stale target の扱いが出力契約になっていない
SSOT は「stale target IDs cleared before scoring」と書いています。
しかし #983 の AC は「stale を除外」程度で、呼び出し元が stale を検知できる戻り値になっていません。
修正要求:
previousTargetIdが candidates に存在しない場合、clearedStaleTargetIdにその ID を返す。これで stage5/6 が「前ターゲットが消えたので再取得した」と判断できます。6. JS sort の罠を Issue に明記すべき
target scoring は sort/comparator 実装になりがちです。
Array.prototype.sort()は in-place mutation で、元配列を変更します。非破壊にするにはtoSorted()または shallow copy が必要です。また comparator は pure / reflexive / anti-symmetric / transitive な well-formed comparator である必要があり、壊れた comparator の挙動は engine 間で一致しません。ECMAScript 2019 以降 sort は stable ですが、#983 は最終 tie-break を持つべきなので、stable sort の入力順に依存してはいけません。([MDN Web Docs]1)修正要求:
#982 との接続上の注意
#982 の型・helper は存在します。
BufferedCommandIntent/CommandIntentRuntimeState、isBufferedCommandIntentActive、sampleAssistPlayerIntent、tickCommandIntentRuntimeはGameState.tsにあります。ただし、私が確認した
runSortieSimulationStepの範囲では、sample_assist_playerをsampleAssistPlayerIntentに接続する処理やtickCommandIntentRuntimeの呼び出しは見えていません。現行順序は movement → spawn → enemy AI → combat → projectile → collision → sortie → tick increment です。したがって #983 では、
state.commandIntentRuntimeを直接読みに行くのではなく、commandIntentとcommandIntentActiveを snapshot input として受け取る pure functionにしてください。これなら #982 の統合状態に依存せず、stage5/6 が安全に使えます。必須テスト
最低限、以下がないと merge しない方がよいです。
Verification Commands 修正版
#983 の現行 VC は弱いです。特に禁止語
rgは、裸で実行すると「見つかったら成功」になるため逆です。#981 のレビューでも同じ問題が指摘されています。推奨:
Allowed Paths 修正版
現行の
tests/は広すぎます。stage5/6 と衝突しやすいので絞るべきです。Evidence / 配布物
#983 は pure system + unit test の stage なので、Pages preview、スクリーンショット、viewport / DPR / browser zoom 証跡は不要です。SSOT の Evidence / Distribution Policy は UI / playtest follow-up PR に必須であり、docs-only や pure-system PR には境界があります。
ただし PR body には通常の証跡として、commit SHA、GitHub Actions run ID、実行した gate の結果は残すべきです。
GitHub に貼るレビューコメント案
Required tests:
pnpm typecheck,pnpm lint,pnpm test,pnpm build, Gemini routing pytestsqune121 commentedon Jun 20, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jun 20, 2026
Contract Review Result