Skip to content

実装: allies collection と ally_basic semi-autonomous behavior を追加する #984

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "975"
goal_ref: "allies collection と 1 種 ally_basic role を追加し、NpcBehaviorState 機械で semi-autonomous に行動する ally を runEnemyAISystem 後 / runCombatSystem 前へ統合する"
change_kind: code
ssot_sections: ["§4", "§5", "§7.2", "§8", "§9"]
stage: 5
blocked_by: []
dedupe_key: "follow-up:squne121/loop-protocol:pr/978:stage5"

この stage の詳細契約は docs/product/features/unit-operations-and-npc-behavior.md §4, §5, §7.2, §8, §9 が SSOT である。本文の AC/Allowed Paths/VC はそれと矛盾しない。

Parent Issue

#975

関連 PR: #978(docs(#975): define unit operations and NPC behavior SSOT, merged 確認済み)

Parent Goal Ref

  • Goal: allies collection と 1 種 ally_basic role を追加し、NpcBehaviorState 機械で semi-autonomous に行動(直接命令しない)し、ally behavior/movement を runEnemyAISystem 後 / runCombatSystem 前へ統合する
  • Desired Destination: allies: AllyState[] が GameState に存在し、CommandIntent.none でも ally が deterministic に基礎行動し、直接移動命令/編隊/個別選択/ally projectile・damage 実装を持ち込まない状態

Current Validated Scope

  • src/state/GameState.ts に AllyState、allies: AllyState[]、nextAllyId を追加する
  • src/systems/SortieSystem.ts を含む src/systems/ に ally behavior/movement 統合と reset 処理を追加する
  • src/systems/TargetingSystem.ts または同階層 helper に TargetEntityId 変換の集中化を追加する
  • tests/ に ally_basic behavior / stale target / reset / no projectile-no damage の検証を追加する

Remaining Parent Gaps

  • stage6: existing enemy_chaser を new taxonomy へ非破壊移行する(本 Issue と並行可だが別責務)
  • stage7: assist_player DOM command affordance と Canvas visual cue を追加する(本 Issue 完了後)
  • stage8: assist_player playtest self-explanation test と evidence policy を追加する(stage7 完了後)

Blocked by

なし(前提 issue #981 / #983 は 2026-06-21 時点で CLOSED 確認済み)

Outcome

allies: AllyState[] と nextAllyId を持つ ally runtime が追加され、ally_basic が CommandIntent.none でも deterministic に target を選んで移動し、runEnemyAISystem 後 / runCombatSystem 前でのみ振る舞い、ally projectile・damage・直接命令を実装しない状態。

In Scope

  • GameState への AllyState / allies / nextAllyId 追加
  • ally_basic を top-level field ではなく role: 'ally_basic' を持つ collection element として表現する
  • resetCombatRuntime / startSortie における ally runtime と commandIntentRuntime の reset
  • TargetEntityId 変換の集中化
  • ally target selection / state transition / movement の deterministic 実装
  • stale target clear と再選択または inactive 遷移
  • ally projectile / damage を発生させないことのテスト固定
  • runEnemyAISystem 後 / runCombatSystem 前への ally behavior/movement 統合

Out of Scope

  • 直接移動命令の実装
  • 編隊・個別選択・命令キュー
  • ally projectile、enemy/player への ally damage、ally collision/damage resolution
  • existing enemy_chaser taxonomy 移行
  • DOM affordance / Canvas visual cue
  • pathfinding / navmesh / full behavior tree / GOAP

Acceptance Criteria

  • AC1: GameState に AllyState、allies: AllyState[]、nextAllyId が追加されている
  • AC2: ally_basic は top-level field ではなく AllyState.role === 'ally_basic' と AllyState.faction === 'ally' で表現される
  • AC3: resetCombatRuntime / startSortie は allies、nextAllyId、commandIntentRuntime を初期化する
  • AC4: EnemyState.id / player entity を TargetEntityId へ橋渡しする変換が集中化され、ally targeting から一貫して利用される
  • AC5: ally behavior/movement は runEnemyAISystem の後、runCombatSystem の前に実行される
  • AC6: CommandIntent.none かつ alive enemy がいる場合、ally_basic は deterministic に target を取得して移動し、その挙動を専用テストで検証する
  • AC7: stale / defeated target は clear され、valid target の再選択または inactive への遷移が deterministic に専用テストで検証される
  • AC8: 本 Issue では ally projectile を発生させず、enemy/player HP に ally 由来の damage を適用しないことを専用テストで検証する
  • AC9: pnpm typecheck が PASS する
  • AC10: pnpm test が PASS する
  • AC11: pnpm build が PASS する

Verification Commands

実装前 baseline では AC1-AC8 の該当 rg / test は fail を期待する。AC9-AC11 は hygiene / global gate として最終確認に使う。

# AC1
# baseline-expect: fail
$ rg -n "interface AllyState" src/state/GameState.ts
# AC2
# baseline-expect: fail
$ rg -n "faction: 'ally'" src/state/GameState.ts
# AC3
# baseline-expect: fail
$ rg -n "resetCommandIntentRuntime" src/systems/SortieSystem.ts
# AC4
# baseline-expect: fail
$ rg -n "enemyTargetEntityId" src/systems/TargetingSystem.ts
# AC5
# baseline-expect: fail
$ rg -n "runAlly.*System" src/systems/SortieSystem.ts
# AC6
# baseline-expect: fail
$ rg -n "CommandIntent.none acquires target deterministically" tests
# AC7
# baseline-expect: fail
$ rg -n "stale target is cleared deterministically" tests
# AC8
# baseline-expect: fail
$ rg -n "ally emits no projectile and no damage" tests
# AC9
$ pnpm typecheck
# AC10
$ pnpm test
# AC11
# preflight-scope: pr_review_only
$ pnpm build

Allowed Paths

  • src/state/GameState.ts
  • src/systems/
  • tests/

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • ally_basic に projectile / damage / collision resolution まで持ち込まないと AC を満たせないと判明した場合

Required Skills

  • TypeScript / TSC strict
  • ECS(state / systems 分離)
  • deterministic targeting / pure function 設計
  • NPC behavior 設計(semi-autonomous)

Scope Delta(任意)

N/A

Runtime Verification Applicability

  • decision: not_applicable
  • reason: 本 Issue の受け入れは state/systems と automated test の deterministic 契約で完結し、human-facing DOM/Canvas affordance は out of scope であるため manual runtime verification を要求しない

Source

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    triage-required
    on Jun 18, 2026
  2. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    結論

    #984 は方向性は正しいですが、このまま実装に入ると 「動くが、次の stage6/7 で壊れる ally_basic」 になりやすいです。最大の問題は、ally_basic の状態形状、target id、tick 挿入位置、CommandIntent の寿命、reset 仕様が AC に落ちていないことです。

    #984 自体は open・コメント 0 件で、親は #975、前提は #981 / #983、Allowed Paths は src/state/GameState.ts・src/systems/・tests/ に限定されています。
    また、#984 本文は関連 PR #978 を「merged」と書いていますが、公開 Web 表示では #978 は Open と読めるため、この依存状態は実装前に確認が必要です。(GitHub)

    敵対的レビュー

    Blocker 1: resetCombatRuntime が CommandIntent をリセットしていない

    現在の GameState.ts には resetCommandIntentRuntime() があり、コメントでも resetCombatRuntime / startSortie で呼ぶべきと書かれています。
    しかし SortieSystem.ts の resetCombatRuntime() は tick、player、projectiles、enemies、nextEnemyId をリセットするだけで、commandIntentRuntime を初期化していません。

    #984 の ally は CommandIntent.none でも基礎行動し、将来 assist_player も使う前提です。ここが未修正だと、前 sortie の assist_player buffer が次 sortie の ally 行動へ漏れる可能性があります。これは #984 の実装前または同時に潰すべきです。

    要求修正:
    startSortie/resetCombatRuntime で resetCommandIntentRuntime(state.commandIntentRuntime) を必ず呼ぶ。加えて allies / nextAllyId も同じ箇所で初期化する。


    Blocker 2: ally_basic の GameState 形状が未定義

    #984 は「ally collection と ally_basic フィールドを追加」と書いていますが、これは危険な表現です。現在の GameState は player, projectiles, enemies, commandIntentRuntime を持ちますが、allies はまだありません。

    ally_basic を top-level field にすると、将来 ally_sniper や ally_guard が増えた時に state shape が破綻します。正しくは、role を持つ collection にすべきです。

    推奨形:

    export interface AllyState {
      id: EntityId | string
      role: Extract<UnitRole, 'ally_basic'>
      faction: 'ally'
      behaviorState: NpcBehaviorState
      targetingPolicy: Extract<TargetingPolicy, 'nearest_hostile' | 'assist_player_threat'>
      targetEntityId: TargetEntityId | null
      x: number
      y: number
      radius: number
      speedPxPerSec: number
    }
    
    allies: AllyState[]
    nextAllyId: number
    

    ally_basic は field 名ではなく role: 'ally_basic' として表現する方がよいです。


    Blocker 3: target id の型がすでにズレている

    現在の EnemyState.id は number、PlayerState.id は EntityId です。
    一方、TargetingSystem は TargetEntityId = string を前提にしています。

    #984 で ally が TargetingSystem を使うなら、enemy id をどう TargetEntityId に変換するかを固定しないと、後で targetId: 1 / '1' / 'enemy-1' が混在します。

    要求修正:
    EnemyState.id をそのまま使うのではなく、変換関数を固定する。

    function enemyTargetEntityId(enemy: EnemyState): TargetEntityId {
      return `enemy:${enemy.id}`
    }
    

    同様に player は player:${state.player.id} または既存の 'player-alpha' をそのまま使うのかを明記するべきです。


    Blocker 4: tick step6 が現在の実装順序に対応していない

    現在の runSortieSimulationStep は次の順です。

    1. player movement

    2. enemy spawn

    3. enemy AI

    4. combat

    5. projectile

    6. collision

    7. combat collision resolve

    8. sortie terminal check

    9. tick increment

    該当コードは runMovementSystem → runEnemySpawnSystem → runEnemyAISystem → runCombatSystem → runProjectileSystem → runCollisionSystem → resolveCombatCollisions → runSortieSystem です。

    #984 は「tick step6 に ally movement」と書きますが、現在のコードには step 番号がありません。ここを曖昧にすると、ally の移動が projectile/collision の前か後かで結果が変わります。

    推奨:
    #984 の AC に以下を追加する。

    Ally behavior/movement is executed after runEnemyAISystem and before runCombatSystem.
    Ally movement participates in no collision/damage resolution in this issue.
    Ally attack state may be assigned, but ally projectile/damage emission is out of scope.
    

    または、ally collision を入れるなら CollisionPair の discriminated union に ally-enemy などを足す必要がありますが、それは #984 の Allowed Paths と scope を超えます。


    Major 1: CommandIntent.none の「基礎行動」がテスト不能

    #984 の AC2 は「CommandIntent.none でも基礎行動する」とだけあります。これは曖昧です。

    最低限、次を固定してください。

    状況 | 期待 -- | -- enemy あり、ally が target なし | acquire_target へ遷移し target を保持 enemy あり、target が alive | target 方向へ移動 enemy が defeated | stale target を clear し再選択または inactive enemy なし | inactive または acquire_target で位置不変 CommandIntent.none | 上記が成立する assist_player active | assist_player_threat scoring を使うが、直接移動命令にはならない

    現在の TargetingSystem は assist_player_threat、nearest_hostile、focus_player、ignore を扱い、tie-break も targetEntityId ASC で安定化しています。
    テスト側でも、同点時の deterministic selection、candidate 順序反転時の安定性、immutability が検証されています。

    #984 はこの scoring を使うだけでなく、「selected target を ally behavior にどう反映するか」までテストすべきです。


    Major 2: state machine は小さく保つべきだが、今の AC だと膨らむ余地がある

    TypeScript では discriminated union と exhaustive checking を使うと、状態ごとの不正な組み合わせを抑えやすいです。公式 docs でも discriminated union は message/state mutation のような用途に適しており、never による exhaustive checking が紹介されています。(TypeScript) (TypeScript)

    一方、ゲーム AI の FSM は状態が増えると組み合わせ爆発しやすいです。Game Programming Patterns も、FSM は少数の明確な状態には向くが、複数の独立状態を 1 つに詰めると爆発すると説明しています。(ゲームプログラミングパターン)

    #984 では NpcBehaviorState を増やさず、まずは以下だけで十分です。

    inactive → acquire_target → move_to_engage
    move_to_engage → attack は「range 内で移動停止」程度に留める
    retreat は未使用なら導入しない、または未到達をテストで明示
    destroyed は ally hp/damage を実装しないなら使わない
    

    retreat や attack projectile まで入れると #984 の scope を超えます。


    Major 3: movement は steering/locomotion と decision を分けるべき

    Craig Reynolds の steering behavior 論文は、autonomous character の行動を goal/action selection、steering、locomotion に分けています。steering は locomotion と独立させられ、単純な vehicle model では position/velocity/max speed で更新できます。(Red3D) (Red3D)

    #984 でも同じ分離が必要です。

    悪い実装:

    runAllySystem(state) {
      // target selection, state transition, movement, attack side effect, telemetry を全部やる
    }
    

    良い実装:

    decideAllyBasicBehavior(...)
    moveAllyTowardTarget(...)
    runAllyBehaviorSystem(...)
    

    selectTarget() はすでに pure function なので、ally system も pure に寄せるべきです。Date.now, performance.now, Math.random は使わない。tick と fixedDeltaMs のみで更新してください。


    追加すべきテスト

    #984 の rg "directMove|formation|individualSelect" は弱いです。文字列が無いことは「直接命令を実装していない」証明になりません。

    最低限、以下を追加してください。

    GIVEN CommandIntent.none and one alive enemy
    WHEN runAllyBehaviorSystem executes
    THEN ally_basic acquires that enemy and moves toward it deterministically
    
    GIVEN two equal-score enemies
    WHEN candidates are provided in reversed order
    THEN selected targetEntityId is stable
    
    GIVEN previous ally target is defeated
    WHEN ally behavior runs
    THEN stale target is cleared and a valid target is selected or ally becomes inactive
    
    GIVEN no enemies
    WHEN ally behavior runs
    THEN ally position remains unchanged and behaviorState is inactive/acquire_target as specified
    
    GIVEN a new sortie starts after assist_player was buffered
    WHEN startSortie/resetCombatRuntime runs
    THEN commandIntentRuntime.activeIntent is none and bufferedIntent is null
    
    GIVEN ally_basic behavior runs
    THEN no new projectile is emitted and no enemy/player HP changes in #984
    

    最後のテストが重要です。#984 は movement/behavior の issue であって、ally 攻撃・damage・projectile まで入れる issue ではありません。


    配布物・検証の高品質化

    package.json には pnpm test, pnpm typecheck, pnpm build, test:e2e が用意されています。
    #984 の AC4 は pnpm typecheck / pnpm test だけですが、runtime code を入れるなら最低でも pnpm build も必須にした方がよいです。

    推奨 VC:

    pnpm typecheck
    pnpm test
    pnpm build
    

    UI 変更は stage7 なので、E2E は必須にしなくてよいです。ただし #984 で runSortieSimulationStep の順序を変えるため、既存 sortie 系テストが緑であることは必須です。


    #984 に追記すべき AC 案

    - [ ] AC5: GameState has `allies: AllyState[]` and `nextAllyId`, not a top-level role-specific `ally_basic` collection.
    - [ ] AC6: `AllyState.role` is exactly `'ally_basic'`; `AllyState.faction` is exactly `'ally'`.
    - [ ] AC7: `startSortie/resetCombatRuntime` resets allies, nextAllyId, and CommandIntent runtime.
    - [ ] AC8: `CommandIntent.none` with an alive enemy causes ally_basic to acquire a target and move toward it deterministically.
    - [ ] AC9: stale/defeated target ids are cleared.
    - [ ] AC10: ally_basic emits no projectile and applies no damage in this issue.
    - [ ] AC11: ally behavior runs after `runEnemyAISystem` and before `runCombatSystem`.
    - [ ] AC12: target id conversion between EnemyState.id and TargetingSystem.TargetEntityId is centralized and tested.
    - [ ] AC13: deterministic tie-break is stable when enemy candidate order is reversed.
    - [ ] AC14: `pnpm typecheck`, `pnpm test`, and `pnpm build` pass.
    

    実装方針

    #984 は実装してよいですが、条件付きです。

    1. まず docs(#975): define unit operations and NPC behavior SSOT #978 の状態不整合を確認する。実装: allies collection と ally_basic semi-autonomous behavior を追加する #984 本文は merged と書いているが、Web では Open に見える。

    2. GameState.ts には top-level ally_basic ではなく allies: AllyState[] を入れる。

    3. TargetingSystem の TargetEntityId = string と EnemyState.id = number の橋渡しを必ず関数化する。

    4. resetCombatRuntime に resetCommandIntentRuntime と ally reset を入れる。

    5. ally は「選ぶ」「状態遷移する」「動く」まで。撃つ・当たる・ダメージ・Canvas cue は入れない。

    6. tick 挿入位置は runEnemyAISystem の後、runCombatSystem の前に固定する。

    この修正を入れれば、#984 は後続の enemy taxonomy 移行 stage6 と UI cue stage7 に耐える実装になります。

    ## 結論

    #984 は方向性は正しいですが、このまま実装に入ると 「動くが、次の stage6/7 で壊れる ally_basic」 になりやすいです。最大の問題は、ally_basic の状態形状、target id、tick 挿入位置、CommandIntent の寿命、reset 仕様が AC に落ちていないことです。

    #984 自体は open・コメント 0 件で、親は #975、前提は #981 / #983、Allowed Paths は src/state/GameState.ts・src/systems/・tests/ に限定されています。
    また、#984 本文は関連 PR #978 を「merged」と書いていますが、公開 Web 表示では #978 は Open と読めるため、この依存状態は実装前に確認が必要です。([GitHub]1)

    敵対的レビュー

    Blocker 1: resetCombatRuntime が CommandIntent をリセットしていない

    現在の GameState.ts には resetCommandIntentRuntime() があり、コメントでも resetCombatRuntime / startSortie で呼ぶべきと書かれています。
    しかし SortieSystem.ts の resetCombatRuntime() は tick、player、projectiles、enemies、nextEnemyId をリセットするだけで、commandIntentRuntime を初期化していません。

    #984 の ally は CommandIntent.none でも基礎行動し、将来 assist_player も使う前提です。ここが未修正だと、前 sortie の assist_player buffer が次 sortie の ally 行動へ漏れる可能性があります。これは #984 の実装前または同時に潰すべきです。

    要求修正:
    startSortie/resetCombatRuntime で resetCommandIntentRuntime(state.commandIntentRuntime) を必ず呼ぶ。加えて allies / nextAllyId も同じ箇所で初期化する。


    Blocker 2: ally_basic の GameState 形状が未定義

    #984 は「ally collection と ally_basic フィールドを追加」と書いていますが、これは危険な表現です。現在の GameState は player, projectiles, enemies, commandIntentRuntime を持ちますが、allies はまだありません。

    ally_basic を top-level field にすると、将来 ally_sniper や ally_guard が増えた時に state shape が破綻します。正しくは、role を持つ collection にすべきです。

    推奨形:

    export interface AllyState {
      id: EntityId | string
      role: Extract<UnitRole, 'ally_basic'>
      faction: 'ally'
      behaviorState: NpcBehaviorState
      targetingPolicy: Extract<TargetingPolicy, 'nearest_hostile' | 'assist_player_threat'>
      targetEntityId: TargetEntityId | null
      x: number
      y: number
      radius: number
      speedPxPerSec: number
    }
    allies: AllyState[]
    nextAllyId: number

    ally_basic は field 名ではなく role: 'ally_basic' として表現する方がよいです。


    Blocker 3: target id の型がすでにズレている

    現在の EnemyState.id は number、PlayerState.id は EntityId です。
    一方、TargetingSystem は TargetEntityId = string を前提にしています。

    #984 で ally が TargetingSystem を使うなら、enemy id をどう TargetEntityId に変換するかを固定しないと、後で targetId: 1 / '1' / 'enemy-1' が混在します。

    要求修正:
    EnemyState.id をそのまま使うのではなく、変換関数を固定する。

    function enemyTargetEntityId(enemy: EnemyState): TargetEntityId {
      return `enemy:${enemy.id}`
    }

    同様に player は player:${state.player.id} または既存の 'player-alpha' をそのまま使うのかを明記するべきです。


    Blocker 4: tick step6 が現在の実装順序に対応していない

    現在の runSortieSimulationStep は次の順です。

    1. player movement
    2. enemy spawn
    3. enemy AI
    4. combat
    5. projectile
    6. collision
    7. combat collision resolve
    8. sortie terminal check
    9. tick increment

    該当コードは runMovementSystem → runEnemySpawnSystem → runEnemyAISystem → runCombatSystem → runProjectileSystem → runCollisionSystem → resolveCombatCollisions → runSortieSystem です。

    #984 は「tick step6 に ally movement」と書きますが、現在のコードには step 番号がありません。ここを曖昧にすると、ally の移動が projectile/collision の前か後かで結果が変わります。

    推奨:
    #984 の AC に以下を追加する。

    Ally behavior/movement is executed after runEnemyAISystem and before runCombatSystem.
    Ally movement participates in no collision/damage resolution in this issue.
    Ally attack state may be assigned, but ally projectile/damage emission is out of scope.
    

    または、ally collision を入れるなら CollisionPair の discriminated union に ally-enemy などを足す必要がありますが、それは #984 の Allowed Paths と scope を超えます。


    Major 1: CommandIntent.none の「基礎行動」がテスト不能

    #984 の AC2 は「CommandIntent.none でも基礎行動する」とだけあります。これは曖昧です。

    最低限、次を固定してください。

    状況 期待
    enemy あり、ally が target なし acquire_target へ遷移し target を保持
    enemy あり、target が alive target 方向へ移動
    enemy が defeated stale target を clear し再選択または inactive
    enemy なし inactive または acquire_target で位置不変
    CommandIntent.none 上記が成立する
    assist_player active assist_player_threat scoring を使うが、直接移動命令にはならない

    現在の TargetingSystem は assist_player_threat、nearest_hostile、focus_player、ignore を扱い、tie-break も targetEntityId ASC で安定化しています。
    テスト側でも、同点時の deterministic selection、candidate 順序反転時の安定性、immutability が検証されています。

    #984 はこの scoring を使うだけでなく、「selected target を ally behavior にどう反映するか」までテストすべきです。


    Major 2: state machine は小さく保つべきだが、今の AC だと膨らむ余地がある

    TypeScript では discriminated union と exhaustive checking を使うと、状態ごとの不正な組み合わせを抑えやすいです。公式 docs でも discriminated union は message/state mutation のような用途に適しており、never による exhaustive checking が紹介されています。([TypeScript]2) (TypeScript)

    一方、ゲーム AI の FSM は状態が増えると組み合わせ爆発しやすいです。Game Programming Patterns も、FSM は少数の明確な状態には向くが、複数の独立状態を 1 つに詰めると爆発すると説明しています。([ゲームプログラミングパターン]3)

    #984 では NpcBehaviorState を増やさず、まずは以下だけで十分です。

    inactive → acquire_target → move_to_engage
    move_to_engage → attack は「range 内で移動停止」程度に留める
    retreat は未使用なら導入しない、または未到達をテストで明示
    destroyed は ally hp/damage を実装しないなら使わない
    

    retreat や attack projectile まで入れると #984 の scope を超えます。


    Major 3: movement は steering/locomotion と decision を分けるべき

    Craig Reynolds の steering behavior 論文は、autonomous character の行動を goal/action selection、steering、locomotion に分けています。steering は locomotion と独立させられ、単純な vehicle model では position/velocity/max speed で更新できます。([Red3D]4) ([Red3D]4)

    #984 でも同じ分離が必要です。

    悪い実装:

    runAllySystem(state) {
      // target selection, state transition, movement, attack side effect, telemetry を全部やる
    }

    良い実装:

    decideAllyBasicBehavior(...)
    moveAllyTowardTarget(...)
    runAllyBehaviorSystem(...)

    selectTarget() はすでに pure function なので、ally system も pure に寄せるべきです。Date.now, performance.now, Math.random は使わない。tick と fixedDeltaMs のみで更新してください。


    追加すべきテスト

    #984 の rg "directMove|formation|individualSelect" は弱いです。文字列が無いことは「直接命令を実装していない」証明になりません。

    最低限、以下を追加してください。

    GIVEN CommandIntent.none and one alive enemy
    WHEN runAllyBehaviorSystem executes
    THEN ally_basic acquires that enemy and moves toward it deterministically
    
    GIVEN two equal-score enemies
    WHEN candidates are provided in reversed order
    THEN selected targetEntityId is stable
    
    GIVEN previous ally target is defeated
    WHEN ally behavior runs
    THEN stale target is cleared and a valid target is selected or ally becomes inactive
    
    GIVEN no enemies
    WHEN ally behavior runs
    THEN ally position remains unchanged and behaviorState is inactive/acquire_target as specified
    
    GIVEN a new sortie starts after assist_player was buffered
    WHEN startSortie/resetCombatRuntime runs
    THEN commandIntentRuntime.activeIntent is none and bufferedIntent is null
    
    GIVEN ally_basic behavior runs
    THEN no new projectile is emitted and no enemy/player HP changes in #984
    

    最後のテストが重要です。#984 は movement/behavior の issue であって、ally 攻撃・damage・projectile まで入れる issue ではありません。


    配布物・検証の高品質化

    package.json には pnpm test, pnpm typecheck, pnpm build, test:e2e が用意されています。
    #984 の AC4 は pnpm typecheck / pnpm test だけですが、runtime code を入れるなら最低でも pnpm build も必須にした方がよいです。

    推奨 VC:

    pnpm typecheck
    pnpm test
    pnpm build

    UI 変更は stage7 なので、E2E は必須にしなくてよいです。ただし #984 で runSortieSimulationStep の順序を変えるため、既存 sortie 系テストが緑であることは必須です。


    #984 に追記すべき AC 案

    - [ ] AC5: GameState has `allies: AllyState[]` and `nextAllyId`, not a top-level role-specific `ally_basic` collection.
    - [ ] AC6: `AllyState.role` is exactly `'ally_basic'`; `AllyState.faction` is exactly `'ally'`.
    - [ ] AC7: `startSortie/resetCombatRuntime` resets allies, nextAllyId, and CommandIntent runtime.
    - [ ] AC8: `CommandIntent.none` with an alive enemy causes ally_basic to acquire a target and move toward it deterministically.
    - [ ] AC9: stale/defeated target ids are cleared.
    - [ ] AC10: ally_basic emits no projectile and applies no damage in this issue.
    - [ ] AC11: ally behavior runs after `runEnemyAISystem` and before `runCombatSystem`.
    - [ ] AC12: target id conversion between EnemyState.id and TargetingSystem.TargetEntityId is centralized and tested.
    - [ ] AC13: deterministic tie-break is stable when enemy candidate order is reversed.
    - [ ] AC14: `pnpm typecheck`, `pnpm test`, and `pnpm build` pass.

    実装方針

    #984 は実装してよいですが、条件付きです。

    1. まず docs(#975): define unit operations and NPC behavior SSOT #978 の状態不整合を確認する。実装: allies collection と ally_basic semi-autonomous behavior を追加する #984 本文は merged と書いているが、Web では Open に見える。
    2. GameState.ts には top-level ally_basic ではなく allies: AllyState[] を入れる。
    3. TargetingSystem の TargetEntityId = string と EnemyState.id = number の橋渡しを必ず関数化する。
    4. resetCombatRuntime に resetCommandIntentRuntime と ally reset を入れる。
    5. ally は「選ぶ」「状態遷移する」「動く」まで。撃つ・当たる・ダメージ・Canvas cue は入れない。
    6. tick 挿入位置は runEnemyAISystem の後、runCombatSystem の前に固定する。

    この修正を入れれば、#984 は後続の enemy taxonomy 移行 stage6 と UI cue stage7 に耐える実装になります。

  3. changed the title [-]実装: ally_basic NPC state(1種) と semi-autonomous behavior を追加する[/-] [+]実装: allies collection と ally_basic semi-autonomous behavior を追加する[/+] on Jun 20, 2026
  4. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    anchor comment を反映して #984 の contract を更新しました。

    ローカルでは更新案に対して以下を確認済みです。

    • guard-issue-body.py: pass
    • contract_readiness_check.py --mode preflight-static: status: go
    • check_issue_contract.py: verdict: approve
  5. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    edit-issue: success

    • status: ok
    • changed: AC11 の pnpm build ブロックに # preflight-scope: pr_review_only を追加
    • reason: baseline preflight では defer、PR review/worktree verification では実行対象である意図を明示
    • guard: template_guard=pass, outcome_quality_guard=pass, diff_threshold=pass, ac_vc_alignment=pass
    • readiness: status=go
  6. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-06-20T19:57:03Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/984
      body_sha256: "sha256:a582339702dce6a6f5041f911085880e042e3ab45c5e2c0195efcfb446ed001c"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: ensure_contract_snapshot_auto
  7. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-06-21T05:12:00Z)

    • PR: feat: add ally basic behavior (#984) #1070
    • Worktree: .claude/worktrees/issue-984-allies-ally-basic
    • Branch: worktree-issue-984-allies-ally-basic
    • Verification:
      • pnpm typecheck: PASS
      • pnpm test: PASS
      • pnpm build: PASS
      • pnpm lint: PASS
    • 備考: PR body validator と日本語比率 checker を通過する本文へ調整済み
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementationtriage-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions