Skip to content

実装: unit taxonomy 型5種(Faction / UnitRole / CommandIntent / NpcBehaviorState / TargetingPolicy)を src/state に追加する #981

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "975"
goal_ref: "unit taxonomy 型5種(Faction / UnitRole / CommandIntent / NpcBehaviorState / TargetingPolicy)を src/state に追加し、後続 stage の型基盤を確立する"
change_kind: code
ssot_sections: ["§5", "§6"]
stage: 2
blocked_by: []
dedupe_key: "follow-up:squne121/loop-protocol:pr/978:stage2"

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

Parent Issue

#975

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

Parent Goal Ref

  • Goal: artifact §5 の Faction / UnitRole / CommandIntent / NpcBehaviorState / TargetingPolicy を型レベルで src/state に追加し、後続 stage(stage3〜stage8)の型基盤を確立する
  • Desired Destination: 5 enum union が src/state から export され、pnpm typecheck / pnpm test が緑で、ally collection / command buffer は追加されていない状態

Current Validated Scope

  • src/state/GameState.ts に Faction / UnitRole / CommandIntent / NpcBehaviorState / TargetingPolicy の型定義を追加する
  • src/state/index.ts は既存の export * from './GameState' で再 export が成立するため、通常変更不要。明示 export 方針に変更する場合のみ最小差分で編集する。
  • tests/state/unit-taxonomy-types.test.ts に型存在確認テストを追加してよい(任意)

Remaining Parent Gaps

  • stage3: command intent buffer と Z-equivalent mapping(本 Issue 完了後)
  • stage4: deterministic target scoring pure function(本 Issue 完了後)
  • 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 完了後)

Outcome

artifact §5 の Faction / UnitRole / CommandIntent / NpcBehaviorState / TargetingPolicy を型レベルで src/state に追加する。ally collection / command buffer / behavior runtime はまだ追加しない(型の export のみ)。

In Scope

  • src/state/GameState.ts への 5 enum union 型定義追加
  • src/state/index.ts からの export 追加(既存 export * from './GameState' で成立する場合は変更不要)
  • tests/state/unit-taxonomy-types.test.ts への型存在確認テスト追加(任意)。追加する場合は literal union の値集合が §5 と一致することを型レベル(tsc --noEmit / TypeScript 型代入テスト)で確認する。enum や const object は作らない(runtime value を必要としないため)。

Out of Scope

  • ally collection の実装(stage5 の責務)
  • command buffer の実装(stage3 の責務)
  • behavior runtime の実装(stage5/stage6 の責務)
  • targeting scoring の実装(stage4 の責務)
  • DOM affordance / Canvas cue の実装(stage7 の責務)

Acceptance Criteria

  • AC1: 5 enum union(Faction, UnitRole, CommandIntent, NpcBehaviorState, TargetingPolicy)が artifact §5 と逐語一致で src/state から export される
  • AC2: pnpm typecheck が緑
  • AC3: 既存テストが緑(runtime 挙動不変)
  • AC4: ally collection および command buffer が追加されていない(forbidden runtime fields が src/state に存在しない)

Stop Conditions

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

Required Skills

  • TypeScript / TSC strict
  • ECS(state / systems 分離)

Verification Commands

実装前は 5 型が未追加のため AC1 の rg は 0 件(baseline-expect: fail)。AC2/AC3 は型追加後に回帰しないことを確認する。AC4 は forbidden runtime fields が存在しないことを確認する(実装前後とも pass)。

# AC1
# baseline-expect: fail
$ rg -n "export type (Faction|UnitRole|CommandIntent|NpcBehaviorState|TargetingPolicy) =" src/state/GameState.ts
# AC2
$ pnpm typecheck
# AC3
$ pnpm test
# AC4
# trivially_pass: absence check - src/state に allies/commandBuffer が存在しないことは実装前後とも成立する
# preflight-scope: pr_review_only
$ rg -n "allies|commandBuffer" src/state
# Quality gate
$ pnpm lint
$ pnpm build
$ uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py

Allowed Paths

  • src/state/GameState.ts
  • src/state/index.ts(既存 export * from './GameState' で再 export が成立する場合、変更不要)
  • tests/state/unit-taxonomy-types.test.ts(型存在確認テストを追加する場合のみ)

Runtime Verification Applicability

  • decision: not_applicable
  • reason: 型 alias の追加のみで runtime 挙動・プロセス起動・通信・I/O を伴わない。検証は pnpm typecheck / pnpm lint / pnpm test / pnpm build と禁止語チェックで完結する。

Source

Activity

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

    @squne121
    OwnerAuthor

    判定

    REQUEST_CHANGES / Issue contract 修正後に着手可。
    #981 の実装意図自体は妥当です。docs/product/features/unit-operations-and-npc-behavior.md §5 の 5 型を src/state に追加し、ally runtime / command buffer / behavior runtime をまだ入れない分割は、8-stage 分解の stage2 として正しいです。§5 の型定義も、Faction / UnitRole / CommandIntent / NpcBehaviorState / TargetingPolicy の literal union として固定されています。

    ただし、このまま Claude Code / Codex に渡すと、検証が壊れます。 実装より Issue 本文の品質が問題です。

    Blocker 1: AC4 の rg 検証が逆向き

    #981 は AC4 で「ally collection / command buffer が追加されていない」ことを確認するために、次を VC にしています。

    rg "allies|commandBuffer" src/state
    

    これは 0件であることを確認するコマンドとして不適切です。grep 系コマンドは「一致あり」を成功、「一致なし」を非 0 として扱う慣習があり、GNU grep の manual でも exit status は「selected line あり = 0、なし = 1、error = 2」と説明されています。set -e 系の test-runner では、禁止語が存在しない正常状態で失敗扱いになり得ます。([GNU]1)

    修正案:

    # AC4: forbidden runtime fields are absent
    bash -lc 'set +e; rg -n "allies|commandBuffer" src/state; status=$?; test "$status" -eq 1'
    

    ! rg ... だけだと rg の実行エラーも成功扱いに反転し得るため、exit code 1 だけを「0件」として許容する形にしてください。

    Blocker 2: Runtime Verification Applicability が deferred になっているのは不正確

    #981 は型追加のみで、runtime 挙動、プロセス起動、通信、I/O を要求していません。プロジェクトの runtime verification policy では、静的検証だけで完結するものは not_applicable、プロセス起動・通信・I/O が必要なものが immediate、後続統合まで成立しないものが deferred です。

    さらに #981 の deferred_destination が #976 になっていますが、#976 は hook 境界ドキュメント系の PR/Issue 文脈であり、unit taxonomy stage2 の検証先として不整合です。#981 の検証条件は「型が存在し、typecheck/test が通ること」なので、本 Issue 内で静的に閉じられます。

    修正案:

    ## Runtime Verification Applicability
    
    - decision: not_applicable
    - reason: 型 alias の追加のみで runtime 挙動・プロセス起動・通信・I/O を伴わない。検証は `pnpm typecheck` / `pnpm lint` / `pnpm test` / `pnpm build` と禁止語チェックで完結する。
    

    Blocker 3: 必須品質ゲートが足りない

    #981 の Verification Commands は pnpm typecheck と pnpm test だけですが、プロジェクト憲法は原則として pnpm typecheck / pnpm lint / pnpm test / pnpm build / Gemini routing pytest を必須検証として定義しています。

    実装テンプレート側も標準 VC として pnpm typecheck / pnpm lint / pnpm test / pnpm build を初期値にしています。

    修正案:

    # AC1
    rg -n "export type (Faction|UnitRole|CommandIntent|NpcBehaviorState|TargetingPolicy) =" src/state/GameState.ts
    
    # AC2
    pnpm typecheck
    
    # AC3
    pnpm test
    
    # AC4
    bash -lc 'set +e; rg -n "allies|commandBuffer" src/state; status=$?; test "$status" -eq 1'
    
    # Quality gate
    pnpm lint
    pnpm build
    uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py
    

    Blocker 4: src/state/index.ts の編集要否が曖昧

    #981 は src/state/index.ts から 5 型を export するとしていますが、現状 src/state/index.ts はすでに export * from './GameState' を持っています。つまり GameState.ts 側で export type すれば、index からの再 export は既に成立します。

    ここを曖昧にすると、実装者が不要な差分を作る可能性があります。

    修正案:

    - `src/state/GameState.ts` に `export type` として 5 型を追加する。
    - `src/state/index.ts` は既存の `export * from './GameState'` で再 export が成立する場合、変更不要。
    - 明示 export 方針に変更する場合のみ `src/state/index.ts` を編集する。
    

    Blocker 5: 「型存在確認テスト」が runtime test として誤解されやすい

    TypeScript の type alias / export type は型検査用で、JavaScript 出力には残りません。TypeScript 3.8 の公式ドキュメントも import type / export type は型文脈専用で、完全に erase されると説明しています。(TypeScript)

    したがって、Vitest の runtime assertion で「型が存在する」ことを検証しようとすると、空テスト・無意味テスト・runtime object 化の誘惑が出ます。ここは literal union 型 + tsc --noEmit に寄せるべきです。TypeScript 公式 docs でも union type は複数型のいずれかを表す型、literal union は既知の値集合だけを受け付ける表現として説明されています。([TypeScript]3) (TypeScript)

    推奨実装:

    export type Faction = 'player' | 'ally' | 'enemy' | 'neutral'
    
    export type UnitRole =
      | 'ace_player'
      | 'ally_basic'
      | 'enemy_chaser'
      | 'objective'
      | 'neutral_obstacle'
    
    export type CommandIntent = 'none' | 'assist_player'
    
    export type NpcBehaviorState =
      | 'inactive'
      | 'acquire_target'
      | 'move_to_engage'
      | 'attack'
      | 'retreat'
      | 'destroyed'
    
    export type TargetingPolicy =
      | 'focus_player'
      | 'assist_player_threat'
      | 'nearest_hostile'
      | 'ignore'
    

    禁止: enum や const object を作ること。現 stage は runtime value を必要としていないため、JS 出力を増やす理由がありません。

    Major: Issue title が 3型しか書いていない

    タイトルは Faction / UnitRole / CommandIntent だけですが、AC1 と SSOT は NpcBehaviorState / TargetingPolicy も含む 5 型です。

    修正案:

    実装: unit taxonomy 型5種を src/state に追加する
    

    または:

    実装: Faction / UnitRole / CommandIntent / NpcBehaviorState / TargetingPolicy を src/state に追加する
    

    Major: tests/ が広すぎる

    Allowed Paths に tests/ 全体を許可していますが、後続 stage3 #982、stage4 #983 も tests/ を触ります。#982 は #981 に block され、#983 は #981/#982 に block されているので順序上は問題ありませんが、Scope Collision Preflight の観点では broad path は衝突を増やします。workflow は overlap がある場合に C1/C2/C3 判定と記録を要求しています。

    修正案:

    ## Allowed Paths
    
    - `src/state/GameState.ts`
    - `src/state/index.ts`(既存 `export *` で不足する場合のみ)
    - `tests/state/unit-taxonomy-types.test.ts`(追加する場合のみ)
    

    配布物・Evidence の扱い

    #981 は type-only stage なので、Pages preview、screenshot、artifact digest、retention-days などの配布証跡は不要です。PR #978 の spec は UI/playtest follow-up PR では commit SHA / Actions run ID / page_url or stable artifact / artifact names / retention-days / viewport / DPR / browser zoom 等を要求していますが、docs-only / type-only PR 自体には UI evidence を適用しない境界も明記しています。

    この Issue で配布物品質を上げるなら、Pages 証跡を足すのではなく、型追加が runtime に漏れていないこと、禁止 field が入っていないこと、標準品質ゲートが通ることに限定してください。

    修正版の実行プロンプト

    Issue #981 を実装してください。関連 Issue / PR / SSOT を確認した上で、1 Issue = 1 PR で完了させてください。
    
    必読:
    - Issue #981
    - parent research issue #975
    - merged PR #978
    - `docs/product/features/unit-operations-and-npc-behavior.md` §5, §6
    - `docs/dev/workflow.md`
    - `docs/dev/runtime-verification-policy.md`
    - `CLAUDE.md`
    - `.claude/rules/project-constitution.md`
    
    実装方針:
    - `src/state/GameState.ts` に以下 5 型を `export type` の literal union として追加する。
      - `Faction`
      - `UnitRole`
      - `CommandIntent`
      - `NpcBehaviorState`
      - `TargetingPolicy`
    - 値集合は `docs/product/features/unit-operations-and-npc-behavior.md` §5 と逐語一致させる。
    - `enum` / runtime const object は作らない。
    - ally collection、command buffer、behavior runtime、target scoring、DOM affordance、Canvas cue は実装しない。
    - `src/state/index.ts` は既存 `export * from './GameState'` で再 export が成立するなら変更しない。明示 export が必要な場合のみ最小差分で編集する。
    - test を追加する場合は type-level compile check に限定し、runtime object の存在確認テストを作らない。
    
    修正済み Verification Commands:
    ```bash
    rg -n "export type (Faction|UnitRole|CommandIntent|NpcBehaviorState|TargetingPolicy) =" src/state/GameState.ts
    pnpm typecheck
    pnpm lint
    pnpm test
    pnpm build
    bash -lc 'set +e; rg -n "allies|commandBuffer" src/state; status=$?; test "$status" -eq 1'
    uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py
    

    PR 作成時:

    • Closes #981 を入れる。
    • Allowed Paths 遵守 に、src/state/index.ts を変更したかどうかと理由を書く。
    • Runtime Verification Applicability は not_applicable として扱う。理由は type-only / static verification only。
    • Safety Claim Matrix は N/A。runtime、auth、transport、permission、deploy、secret、Pages artifact は触らない。

    停止条件:

    • Faction 等を runtime value として必要にする設計が必要になった場合
    • ally collection / command buffer / behavior runtime が必要になった場合
    • Allowed Paths 外の変更が必要になった場合
    • 標準品質ゲートの失敗が本 Issue 外の既存問題に見える場合
    • 外部サービス、secret、権限昇格、配布 pipeline 変更が必要になった場合
    
    ## 最終結論
    
    #981 は **stage2 として必要**です。ただし現状の Issue 本文は、実装内容ではなく **検証契約が弱い**。特に AC4 の bare `rg`、RVA の `deferred`、`#976` 参照、標準品質ゲート不足は修正必須です。ここを直せば、実装自体は `GameState.ts` への `export type` 追加だけで安全に閉じられます。
    
  3. changed the title [-]実装: unit taxonomy 型 Faction / UnitRole / CommandIntent を src/state に追加する[/-] [+]実装: unit taxonomy 型5種(Faction / UnitRole / CommandIntent / NpcBehaviorState / TargetingPolicy)を src/state に追加する[/+] on Jun 18, 2026
  4. squne121 commented on Jun 18, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  5. squne121 commented on Jun 18, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-06-18T13:07:43Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/981
      body_sha256: "sha256:5e2c82e291614d65ba9b1f900c9d722d6988c3a26ed3b4adb75ebb39151106a1"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: ensure_contract_snapshot_auto
  6. added a commit that references this issue on Jun 18, 2026
  7. squne121 commented on Jun 18, 2026

    @squne121
    OwnerAuthor

    post-merge-cleanup: 完了 (2026-06-18)

    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: post-merge-cleanup
      follow_up_issues: []
      note_only_observations:
        - summary: "後続 stage #982(stage3)〜#987(stage8) は既に起票済み・OPEN。追加起票不要。"
        - summary: "parent issue #975 は research phase として既クローズ済み。"
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