Skip to content

実装: sortie feature spec を作成する #485

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#483"
goal_ref: "M2: Combat MVP Gate — sortie lifecycle / 終了条件 / result object 仕様の正本を docs/product/features/sortie.md に作成する"
change_kind: docs
diff_rationale: "sortie lifecycle / FSM / timer authority / result invariants の新規定義(M2 初回 spec 作成)"
changed_requirement_id: "sortie_playable (M2)"
affected_sections:
  - "sortie lifecycle"
  - "FSM transition table"
  - "timer authority"
  - "result object invariants"

Parent Issue

#483

Parent Goal Ref

  • Goal: M2: Combat MVP Gate (v0.2.x) として 1 sortie を開始→操作→戦闘結果まで通す
  • Desired Destination: docs/product/features/sortie.md に sortie の lifecycle / 終了条件 / result object を置く

Current Validated Scope

  • docs/product/features/sortie.md が存在しない
  • docs/product/playable-roadmap.md の M2 spec_destination に sortie.md が列挙されている
  • docs/dev/ssot-registry.md に sortie エントリが存在しない

Remaining Parent Gaps

  • combat-core feature spec(並行 child issue)
  • enemy spawn / AI / collision / damage / sortie state machine の実装(別 child issues)
  • playtest 証跡(別 child issue)

Outcome

docs/product/features/sortie.md が作成され、sortie state machine(遷移表含む) / 終了条件 / timer authority / result object 不変条件が定義された状態で pnpm test && pnpm build が通っている。

In Scope

  • docs/product/features/sortie.md の新規作成(YAML frontmatter + 仕様本文)
  • docs/dev/ssot-registry.md への sortie エントリ追加

Out of Scope

  • src/ への実装変更
  • tests/ への変更
  • combat-core spec(別 Issue)
  • persistence / upgrade(M3/M4 スコープ)

Acceptance Criteria

  • AC1: docs/product/features/sortie.md が存在する
  • AC2: YAML frontmatter に doc_id, status, parent_issue, trace_links がある
  • AC3: trace_links に parent_issue: "#483", sibling_specs: ["#484"], implementation_consumers: ["#489"], upstream_implementation: ["#486","#487","#488"], validation: ["#490"] が含まれる
  • AC4: sortie state が有限状態(idle | running | victory | defeat | ended)として定義されている
  • AC5: victory と defeat は terminal result-latched states、ended は post-result acknowledgement state として定義されている(ended は result を変更しない)
  • AC6: normative transition table が定義されている(idle -START_SORTIE-> running、running -FIXED_TICK[playerHp<=0]-> defeat、running -FIXED_TICK[elapsedTicks>=targetTicks]-> victory、victory/defeat -ACK_RESULT-> ended、terminal state は result を再生成しない)
  • AC7: 120秒生存 victory と player HP 0 defeat が終了条件として定義されている
  • AC8: 同一 tick で player.hp <= 0 と elapsedTicks >= targetTicks が同時成立した場合、defeat が優先されることが明記されている
  • AC9: elapsedTicks は running 状態の fixed simulation steps 内でのみ加算されることが明記されている
  • AC10: 勝利判定が tick-based: targetTicks = ceil(120_000 / fixedDeltaMs)、elapsedTicks >= targetTicks で victory、durationMs = elapsedTicks * fixedDeltaMs が明記されている
  • AC11: wall-clock delta、rAF timestamp delta、Date.now()、performance.now() が sortie 時間計測に使用されないことが明記されている
  • AC12: SimulationLoop の panic/maxFrameSkip による破棄時間が sortie duration に含まれないことが明記されている
  • AC13: result object の最小 shape(outcome: "victory" | "defeat", durationMs: number, kills: number, shotsFired: number, playerHpRemaining: number)が定義されている
  • AC14: SortieResult の不変条件が定義されている(running→victory/defeat への初回遷移で一度だけ生成・immutable・kills は terminal tick 以前の敵から・shotsFired は terminal tick snapshot・playerHpRemaining は [0, maxHp] clamp・defeat 時は playerHpRemaining === 0・persistence/resources/upgrades/localStorage/campaign への書き込みなし)
  • AC15: result object は persistence / upgrade を直接実行しない transient output として定義されている
  • AC16: non-goals に persistence / upgrade / campaign / briefing UI が含まれる
  • AC17: planned_consumer_tests として 実装: sortie start-end state machine と result object を実装する #489 用テストケース(victory at target tick、defeat at HP zero、same-tick defeat-wins precedence、result generated once、timer authority ignores wall-clock/rAF pause、terminal state 後の combat mutation なし)が列挙されている
  • AC18: docs/dev/ssot-registry.md に sortie エントリが追加されている
  • AC19: pnpm typecheck && pnpm lint && pnpm test && pnpm build が通る

Verification Commands

# AC1
$ test -f docs/product/features/sortie.md

# AC2
# preflight-scope: pr_review_only
$ grep -n "doc_id\|status\|parent_issue\|trace_links" docs/product/features/sortie.md

# AC3
# preflight-scope: pr_review_only
$ grep -n "#483\|#484\|#489\|#486\|#487\|#488\|#490" docs/product/features/sortie.md

# AC4
# preflight-scope: pr_review_only
$ grep -n "idle\|running\|victory\|defeat\|ended" docs/product/features/sortie.md

# AC5
# preflight-scope: pr_review_only
$ grep -n "terminal\|result-latched\|acknowledgement\|MUST NOT alter" docs/product/features/sortie.md

# AC6
# preflight-scope: pr_review_only
$ grep -n "START_SORTIE\|FIXED_TICK\|ACK_RESULT" docs/product/features/sortie.md

# AC7
# preflight-scope: pr_review_only
$ grep -n "120\|victory\|defeat" docs/product/features/sortie.md

# AC8
# preflight-scope: pr_review_only
$ grep -n "defeat.*wins\|defeat.*priorit\|same.tick\|both.*true" docs/product/features/sortie.md

# AC9
# preflight-scope: pr_review_only
$ grep -n "elapsedTicks\|running.*fixed\|fixed.*running" docs/product/features/sortie.md

# AC10
# preflight-scope: pr_review_only
$ grep -n "targetTicks\|ceil\|120_000\|fixedDeltaMs" docs/product/features/sortie.md

# AC11
# preflight-scope: pr_review_only
$ grep -n "wall.clock\|rAF\|Date\.now\|performance\.now\|MUST NOT" docs/product/features/sortie.md

# AC12
# preflight-scope: pr_review_only
$ grep -n "panic\|maxFrameSkip\|discard" docs/product/features/sortie.md

# AC13
# preflight-scope: pr_review_only
$ grep -n "durationMs\|kills\|shotsFired\|playerHpRemaining" docs/product/features/sortie.md

# AC14
# preflight-scope: pr_review_only
$ grep -n "immutable\|generated once\|MUST be generated\|clamp\|playerHpRemaining\|defeat.*0" docs/product/features/sortie.md

# AC15
# preflight-scope: pr_review_only
$ grep -n "transient\|persistence\|upgrade" docs/product/features/sortie.md

# AC16
# preflight-scope: pr_review_only
$ grep -n "persistence\|upgrade\|campaign" docs/product/features/sortie.md

# AC17
# preflight-scope: pr_review_only
$ grep -n "planned_consumer_tests\|victory at\|defeat at\|same.tick\|result generated" docs/product/features/sortie.md

# AC18
$ grep -n "sortie\.md\|feature-sortie" docs/dev/ssot-registry.md

# AC19
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm build

Allowed Paths

  • docs/product/features/sortie.md
  • docs/dev/ssot-registry.md

Stop Conditions

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

Runtime Verification Applicability

decision: not_applicable
reason: "docs-only change. AC1-AC18 は grep/test コマンドで決定論的に検証可能。runtime 動作確認(actual play/UI)は #489 実装 Issue の責務。"

Required Skills

  • TypeScript / ECS(state/systems 分離モデルの理解)

Scope Delta(任意)

anchor_comment_feedback(#issuecomment-4580852938)に基づき AC/VC を強化:

  • FSM normative transition table と state role の明示を追加(AC5, AC6)
  • 同一 tick での defeat-wins 裁定を追加(AC8)
  • tick-based timer authority(targetTicks formula, wall-clock/panic clamp 禁止)を追加(AC9-AC12)
  • SortieResult 不変条件と算出元を追加(AC14)
  • related_tests → planned_consumer_tests に変更(AC17)
  • trace_links の必須リンク集合を明示(AC3)

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    on May 29, 2026
  2. added 2 commits that reference this issue on May 29, 2026
  3. squne121 commented on May 30, 2026

    @squne121
    OwnerAuthor

    結論

    #485 は docs-only の仕様作成 Issue として方向性は妥当ですが、このまま sortie.md を作ると #489 の実装で解釈分岐が出ます。特に 状態遷移、同一 tick の勝敗裁定、固定 timestep に基づく duration、result object の不変条件 が曖昧です。私は現状のままなら 実装着手前に修正要求 とします。

    確認範囲では、#485 自体には紐づく PR/branch がなく、GitHub 上の Development も “No branches or pull requests” です。#485 は親 #483 の子 Issue で、M2 Combat MVP Gate の sortie lifecycle / 終了条件 / result object の正本 docs/product/features/sortie.md を作る docs-only Issue です。(GitHub) 親 #483 は #484〜#490 を子 Issue として列挙しており、#485 は #489 の実装仕様入力になります。(GitHub)

    BLOCKER

    1. FSM が「状態名の列挙」止まりで、仕様として足りない

    #485 の AC は idle | running | victory | defeat | ended 等の有限状態を要求していますが、イベント、遷移表、guard、side effect、terminality が未定義です。(GitHub) #489 はこの仕様をもとに SortieSystem と GameState.sortie を実装するため、ここが曖昧だと実装者が ad hoc に boolean を増やす危険があります。(GitHub)

    最低限、sortie.md に以下を明記すべきです。

    type SortieState = "idle" | "running" | "victory" | "defeat" | "ended";
    type SortieOutcome = "victory" | "defeat";
    

    さらに、表で以下を固定してください。

    from | event | guard | to | side effect -- | -- | -- | -- | -- idle | START_SORTIE | none | running | elapsedTicks/result を初期化 running | FIXED_TICK | playerHp <= 0 | defeat | result を一度だけ生成 running | FIXED_TICK | elapsedTicks >= targetTicks | victory | result を一度だけ生成 victory/defeat | ACK_RESULT | none | ended | result は再生成しない ended | any tick | none | ended | no-op

    FSM は「状態名」だけでは不十分です。状態遷移モデルでは、イベントにより有効な transition が選ばれ、action が実行される、という契約まで定義する必要があります。(Stately)

    2. 同一 tick で勝利条件と敗北条件が同時成立した場合の裁定がない

    #485 は「120 秒生存で victory」「player HP 0 で defeat」を要求しています。(GitHub) #489 も同じ条件で実装する前提です。(GitHub) しかし、固定 tick の最後に敵接触ダメージで HP が 0 になり、同じ tick で 120 秒にも到達した場合、victory と defeat のどちらにするかが未定義です。

    これはテストの flake ではなく、ゲームルール上の仕様穴です。推奨は以下です。

    End-condition evaluation order: after movement/projectile/enemy AI/collision/combat resolution for the fixed tick, SortieSystem evaluates terminal conditions. If player.hp <= 0 and elapsedTicks >= targetTicks are both true in the same tick, defeat wins because the player did not survive the terminal tick.

    この裁定を入れないなら、少なくとも「victory 優先」と明記すべきです。無記載は不可です。

    3. timer authority が固定 timestep と panic clamp まで落ちていない

    #485 は timer authority を “simulation time / fixed timestep elapsed” としていますが、これだけでは弱いです。(GitHub) 既存の movement spec は 60Hz fixed timestep accumulator を前提にし、simulation time は「実行された tick」のみを権威としています。(GitHub) 実装済み SimulationLoop も fixedDeltaMs ごとに step を実行し、maxFrameSkip 超過時は panic discard を返す構造です。(GitHub)

    外部仕様上も、requestAnimationFrame は 60Hz 固定ではなく 75/120/144Hz などの表示環境で変化し、バックグラウンド tab では一時停止されることがあります。(MDN Web Docs) Page Visibility API の説明でも、ブラウザは hidden tab の requestAnimationFrame や timer を抑制・停止します。(MDN Web Docs)

    したがって sortie.md は次を明記すべきです。

    Sortie elapsed time MUST be accumulated only inside fixed simulation steps.
    Wall-clock delta, rAF timestamp delta, Date.now(), performance.now() MUST NOT directly determine victory.
    If SimulationLoop discards accumulated time due to panic/maxFrameSkip, discarded wall time MUST NOT count toward sortie duration.
    

    さらに 120 秒判定は floating ms ではなく tick ベースに寄せるべきです。

    targetTicks = Math.ceil(120_000 / fixedDeltaMs);
    victory when elapsedTicks >= targetTicks;
    durationMs = elapsedTicks * fixedDeltaMs;
    

    4. result object の shape はあるが、不変条件と算出元が足りない

    #485 は outcome, durationMs, kills, shotsFired, playerHpRemaining を要求しています。(GitHub) ただし、これだけでは kills の算出元、shotsFired の snapshot timing、playerHpRemaining の clamp、result の immutability が未定義です。

    #493 の combat-core spec 側では、EnemyState、defeatedAtTick、CollisionSystem と CombatSystem の責務分離、SortieSystem が defeatedAtTick !== null から kills を集約することがレビューコメント上で確認されています。(GitHub) #488 でも projectile-enemy collision、damage、defeat、同一 tick 順序、player HP clamp が実装対象になっています。(GitHub)

    sortie.md には最低限これを入れるべきです。

    interface SortieResult {
      outcome: "victory" | "defeat";
      durationMs: number;
      kills: number;
      shotsFired: number;
      playerHpRemaining: number;
    }
    

    不変条件:

    - result MUST be generated exactly once on the first transition from running to victory/defeat.
    - result MUST be immutable after generation.
    - kills MUST be derived from enemies defeated at or before the terminal tick.
    - shotsFired MUST be the player/projectile telemetry snapshot at the terminal tick.
    - playerHpRemaining MUST be clamped to [0, player.maxHp].
    - defeat result MUST have playerHpRemaining === 0.
    - result MUST NOT write persistence, resources, upgrades, localStorage, campaign state, or briefing UI.
    

    MAJOR

    5. victory | defeat | ended の関係が曖昧

    #485 は victory, defeat, ended を同列に置いています。(GitHub) これは危険です。victory/defeat が terminal state なのか、ended が terminal state なのか、あるいは victory/defeat が一瞬の intermediate state なのかが不明です。

    推奨はどちらかに統一です。

    案 A:

    phase: "idle" | "running" | "ended";
    result?: SortieResult; // outcome carries victory/defeat
    

    案 B:

    state: "idle" | "running" | "victory" | "defeat";
    

    #485 の文言を維持するなら案 C です。

    victory/defeat are terminal result-latched states.
    ended is only a post-result acknowledgement state and MUST NOT alter result.
    

    仕様書では案 C を採用するなら、ended への遷移条件を明示してください。

    6. #485 の docs-only scope と test 要求の書き方が噛み合っていない

    #485 は src/ や tests の変更を out of scope にしています。(GitHub) 一方で AC に related_tests として sortie-system test を要求しています。(GitHub) #489 が実際の SortieSystem とテストを作る Issue なので、#485 では related_tests よりも planned_consumer_tests または implementation_contract_tests として書く方が正確です。(GitHub)

    修正案:

    planned_consumer_tests:
      - src/systems/__tests__/sortie-system.test.ts
      - covers:
          - victory at target tick
          - defeat at hp zero
          - same-tick victory/defeat precedence
          - result generated once
          - timer authority ignores wall-clock/rAF pause
          - no combat mutation after terminal state
    

    7. trace_links の必須リンク集合が弱い

    #485 は frontmatter に trace_links を要求していますが、どのリンクが必須かを固定していません。(GitHub) 最低限、以下は必須にすべきです。

    trace_links:
      parent_issue: "#483"
      sibling_specs:
        - "#484"
      implementation_consumers:
        - "#489"
      upstream_implementation:
        - "#486"
        - "#487"
        - "#488"
      validation:
        - "#490"
      existing_specs:
        - docs/product/features/movement-projectile.md
        - docs/product/adr/0002-product-architecture-baseline.md
    

    playable-roadmap.md でも M2 の spec destination として combat-core.md と sortie.md が明記され、詳細仕様ができたら個別 feature spec が正本になる運用です。(GitHub) ssot-registry.md も canonical docs catalog として手動登録が必要な構造です。(GitHub)

    8. 配布物観点では「docs-only だから安全」が成立しない

    #485 は docs-only ですが、M2 全体では Vite build 可能な playable artifact に接続されます。親 #483 は one-screen playable sortie、system tests、build pass、DOM/Canvas 分離を close 条件にしています。(GitHub) Vite の production build は静的配布用 bundle を生成する工程なので、仕様が曖昧なままでも build は通ってしまいます。(vitejs)

    そのため #485 の docs は「build が通る」ではなく、後続 #489/#490 が検証可能な契約にする必要があります。#490 は WASD、enemy、collision、damage、victory、defeat の playtest evidence を要求するため、#485 側で observable acceptance を定義しておくべきです。(GitHub)

    #485 に入れるべき修正文案

    Issue 本文の Acceptance Criteria に以下を追加するのが最小修正です。

    - [ ] `docs/product/features/sortie.md` defines a normative transition table:
      - `idle -> running -> victory|defeat -> ended`
      - allowed events: `START_SORTIE`, `FIXED_TICK`, `ACK_RESULT`
      - terminal/result-latched states MUST NOT regenerate result.
    
    • End-condition evaluation order is explicit:

      • evaluated after movement/projectile/enemy AI/collision/combat resolution for the fixed tick.
      • if player.hp &lt;= 0 and elapsedTicks &gt;= targetTicks are both true in the same tick, defeat wins.
    • Timer authority is tick-based:

      • elapsedTicks increments only inside fixed simulation steps while state is running.
      • wall-clock deltas, rAF timestamp deltas, Date.now(), and performance.now() MUST NOT directly trigger victory.
      • time discarded by SimulationLoop panic/maxFrameSkip MUST NOT count toward durationMs.
    • Victory threshold is deterministic:

      • targetTicks = ceil(120_000 / fixedDeltaMs).
      • victory when elapsedTicks &gt;= targetTicks.
    • SortieResult invariants are defined:

      • generated exactly once.
      • immutable after generation.
      • kills derived from defeated enemies at or before terminal tick.
      • shotsFired snapshot at terminal tick.
      • playerHpRemaining clamped to [0, player.maxHp].
      • no persistence/resource/upgrade/localStorage/campaign mutation.
    • [ ] planned_consumer_tests lists required #489 tests:

      • victory at target tick.
      • defeat at HP zero.
      • same-tick victory/defeat precedence.
      • result generated once.
      • timer authority ignores wall-clock/rAF pause.
      • combat/projectile/enemy mutation does not continue after terminal state.

    最終判定

    現状: Request changes.

    #485 は「何を作るか」は合っています。しかし、#489 実装者に渡す契約としてはまだ粗いです。特に same tick precedence と fixed tick duration を明記しない限り、M2 の勝敗・result・playtest evidence が後から割れます。まず #485 の AC を上記レベルまで締めてから sortie.md 作成に進めるべきです。

    ## 結論

    #485 は docs-only の仕様作成 Issue として方向性は妥当ですが、このまま sortie.md を作ると #489 の実装で解釈分岐が出ます。特に 状態遷移、同一 tick の勝敗裁定、固定 timestep に基づく duration、result object の不変条件 が曖昧です。私は現状のままなら 実装着手前に修正要求 とします。

    確認範囲では、#485 自体には紐づく PR/branch がなく、GitHub 上の Development も “No branches or pull requests” です。#485 は親 #483 の子 Issue で、M2 Combat MVP Gate の sortie lifecycle / 終了条件 / result object の正本 docs/product/features/sortie.md を作る docs-only Issue です。([GitHub]1) 親 #483 は #484〜#490 を子 Issue として列挙しており、#485 は #489 の実装仕様入力になります。([GitHub]2)

    BLOCKER

    1. FSM が「状態名の列挙」止まりで、仕様として足りない

    #485 の AC は idle | running | victory | defeat | ended 等の有限状態を要求していますが、イベント、遷移表、guard、side effect、terminality が未定義です。([GitHub]1) #489 はこの仕様をもとに SortieSystem と GameState.sortie を実装するため、ここが曖昧だと実装者が ad hoc に boolean を増やす危険があります。([GitHub]3)

    最低限、sortie.md に以下を明記すべきです。

    type SortieState = "idle" | "running" | "victory" | "defeat" | "ended";
    type SortieOutcome = "victory" | "defeat";

    さらに、表で以下を固定してください。

    from event guard to side effect
    idle START_SORTIE none running elapsedTicks/result を初期化
    running FIXED_TICK playerHp <= 0 defeat result を一度だけ生成
    running FIXED_TICK elapsedTicks >= targetTicks victory result を一度だけ生成
    victory/defeat ACK_RESULT none ended result は再生成しない
    ended any tick none ended no-op

    FSM は「状態名」だけでは不十分です。状態遷移モデルでは、イベントにより有効な transition が選ばれ、action が実行される、という契約まで定義する必要があります。([Stately]4)

    2. 同一 tick で勝利条件と敗北条件が同時成立した場合の裁定がない

    #485 は「120 秒生存で victory」「player HP 0 で defeat」を要求しています。([GitHub]1) #489 も同じ条件で実装する前提です。([GitHub]3) しかし、固定 tick の最後に敵接触ダメージで HP が 0 になり、同じ tick で 120 秒にも到達した場合、victory と defeat のどちらにするかが未定義です。

    これはテストの flake ではなく、ゲームルール上の仕様穴です。推奨は以下です。

    End-condition evaluation order: after movement/projectile/enemy AI/collision/combat resolution for the fixed tick, SortieSystem evaluates terminal conditions. If player.hp <= 0 and elapsedTicks >= targetTicks are both true in the same tick, defeat wins because the player did not survive the terminal tick.

    この裁定を入れないなら、少なくとも「victory 優先」と明記すべきです。無記載は不可です。

    3. timer authority が固定 timestep と panic clamp まで落ちていない

    #485 は timer authority を “simulation time / fixed timestep elapsed” としていますが、これだけでは弱いです。([GitHub]1) 既存の movement spec は 60Hz fixed timestep accumulator を前提にし、simulation time は「実行された tick」のみを権威としています。([GitHub]5) 実装済み SimulationLoop も fixedDeltaMs ごとに step を実行し、maxFrameSkip 超過時は panic discard を返す構造です。([GitHub]6)

    外部仕様上も、requestAnimationFrame は 60Hz 固定ではなく 75/120/144Hz などの表示環境で変化し、バックグラウンド tab では一時停止されることがあります。([MDN Web Docs]7) Page Visibility API の説明でも、ブラウザは hidden tab の requestAnimationFrame や timer を抑制・停止します。([MDN Web Docs]8)

    したがって sortie.md は次を明記すべきです。

    Sortie elapsed time MUST be accumulated only inside fixed simulation steps.
    Wall-clock delta, rAF timestamp delta, Date.now(), performance.now() MUST NOT directly determine victory.
    If SimulationLoop discards accumulated time due to panic/maxFrameSkip, discarded wall time MUST NOT count toward sortie duration.
    

    さらに 120 秒判定は floating ms ではなく tick ベースに寄せるべきです。

    targetTicks = Math.ceil(120_000 / fixedDeltaMs);
    victory when elapsedTicks >= targetTicks;
    durationMs = elapsedTicks * fixedDeltaMs;

    4. result object の shape はあるが、不変条件と算出元が足りない

    #485 は outcome, durationMs, kills, shotsFired, playerHpRemaining を要求しています。([GitHub]1) ただし、これだけでは kills の算出元、shotsFired の snapshot timing、playerHpRemaining の clamp、result の immutability が未定義です。

    #493 の combat-core spec 側では、EnemyState、defeatedAtTick、CollisionSystem と CombatSystem の責務分離、SortieSystem が defeatedAtTick !== null から kills を集約することがレビューコメント上で確認されています。([GitHub]9) #488 でも projectile-enemy collision、damage、defeat、同一 tick 順序、player HP clamp が実装対象になっています。([GitHub]10)

    sortie.md には最低限これを入れるべきです。

    interface SortieResult {
      outcome: "victory" | "defeat";
      durationMs: number;
      kills: number;
      shotsFired: number;
      playerHpRemaining: number;
    }

    不変条件:

    - result MUST be generated exactly once on the first transition from running to victory/defeat.
    - result MUST be immutable after generation.
    - kills MUST be derived from enemies defeated at or before the terminal tick.
    - shotsFired MUST be the player/projectile telemetry snapshot at the terminal tick.
    - playerHpRemaining MUST be clamped to [0, player.maxHp].
    - defeat result MUST have playerHpRemaining === 0.
    - result MUST NOT write persistence, resources, upgrades, localStorage, campaign state, or briefing UI.
    

    MAJOR

    5. victory | defeat | ended の関係が曖昧

    #485 は victory, defeat, ended を同列に置いています。([GitHub]1) これは危険です。victory/defeat が terminal state なのか、ended が terminal state なのか、あるいは victory/defeat が一瞬の intermediate state なのかが不明です。

    推奨はどちらかに統一です。

    案 A:

    phase: "idle" | "running" | "ended";
    result?: SortieResult; // outcome carries victory/defeat

    案 B:

    state: "idle" | "running" | "victory" | "defeat";

    #485 の文言を維持するなら案 C です。

    victory/defeat are terminal result-latched states.
    ended is only a post-result acknowledgement state and MUST NOT alter result.
    

    仕様書では案 C を採用するなら、ended への遷移条件を明示してください。

    6. #485 の docs-only scope と test 要求の書き方が噛み合っていない

    #485 は src/ や tests の変更を out of scope にしています。([GitHub]1) 一方で AC に related_tests として sortie-system test を要求しています。([GitHub]1) #489 が実際の SortieSystem とテストを作る Issue なので、#485 では related_tests よりも planned_consumer_tests または implementation_contract_tests として書く方が正確です。([GitHub]3)

    修正案:

    planned_consumer_tests:
      - src/systems/__tests__/sortie-system.test.ts
      - covers:
          - victory at target tick
          - defeat at hp zero
          - same-tick victory/defeat precedence
          - result generated once
          - timer authority ignores wall-clock/rAF pause
          - no combat mutation after terminal state

    7. trace_links の必須リンク集合が弱い

    #485 は frontmatter に trace_links を要求していますが、どのリンクが必須かを固定していません。([GitHub]1) 最低限、以下は必須にすべきです。

    trace_links:
      parent_issue: "#483"
      sibling_specs:
        - "#484"
      implementation_consumers:
        - "#489"
      upstream_implementation:
        - "#486"
        - "#487"
        - "#488"
      validation:
        - "#490"
      existing_specs:
        - docs/product/features/movement-projectile.md
        - docs/product/adr/0002-product-architecture-baseline.md

    playable-roadmap.md でも M2 の spec destination として combat-core.md と sortie.md が明記され、詳細仕様ができたら個別 feature spec が正本になる運用です。([GitHub]11) ssot-registry.md も canonical docs catalog として手動登録が必要な構造です。([GitHub]12)

    8. 配布物観点では「docs-only だから安全」が成立しない

    #485 は docs-only ですが、M2 全体では Vite build 可能な playable artifact に接続されます。親 #483 は one-screen playable sortie、system tests、build pass、DOM/Canvas 分離を close 条件にしています。([GitHub]2) Vite の production build は静的配布用 bundle を生成する工程なので、仕様が曖昧なままでも build は通ってしまいます。([vitejs]13)

    そのため #485 の docs は「build が通る」ではなく、後続 #489/#490 が検証可能な契約にする必要があります。#490 は WASD、enemy、collision、damage、victory、defeat の playtest evidence を要求するため、#485 側で observable acceptance を定義しておくべきです。([GitHub]14)

    #485 に入れるべき修正文案

    Issue 本文の Acceptance Criteria に以下を追加するのが最小修正です。

    - [ ] `docs/product/features/sortie.md` defines a normative transition table:
      - `idle -> running -> victory|defeat -> ended`
      - allowed events: `START_SORTIE`, `FIXED_TICK`, `ACK_RESULT`
      - terminal/result-latched states MUST NOT regenerate result.
    
    - [ ] End-condition evaluation order is explicit:
      - evaluated after movement/projectile/enemy AI/collision/combat resolution for the fixed tick.
      - if `player.hp <= 0` and `elapsedTicks >= targetTicks` are both true in the same tick, `defeat` wins.
    
    - [ ] Timer authority is tick-based:
      - `elapsedTicks` increments only inside fixed simulation steps while state is `running`.
      - wall-clock deltas, rAF timestamp deltas, `Date.now()`, and `performance.now()` MUST NOT directly trigger victory.
      - time discarded by SimulationLoop panic/maxFrameSkip MUST NOT count toward `durationMs`.
    
    - [ ] Victory threshold is deterministic:
      - `targetTicks = ceil(120_000 / fixedDeltaMs)`.
      - victory when `elapsedTicks >= targetTicks`.
    
    - [ ] `SortieResult` invariants are defined:
      - generated exactly once.
      - immutable after generation.
      - `kills` derived from defeated enemies at or before terminal tick.
      - `shotsFired` snapshot at terminal tick.
      - `playerHpRemaining` clamped to `[0, player.maxHp]`.
      - no persistence/resource/upgrade/localStorage/campaign mutation.
    
    - [ ] `planned_consumer_tests` lists required #489 tests:
      - victory at target tick.
      - defeat at HP zero.
      - same-tick victory/defeat precedence.
      - result generated once.
      - timer authority ignores wall-clock/rAF pause.
      - combat/projectile/enemy mutation does not continue after terminal state.

    最終判定

    現状: Request changes.

    #485 は「何を作るか」は合っています。しかし、#489 実装者に渡す契約としてはまだ粗いです。特に same tick precedence と fixed tick duration を明記しない限り、M2 の勝敗・result・playtest evidence が後から割れます。まず #485 の AC を上記レベルまで締めてから sortie.md 作成に進めるべきです。

  4. squne121 commented on May 30, 2026

    @squne121
    OwnerAuthor

    NotebookLM草案

    Issue #485 の要件および「LOOP PROTOCOL」のアーキテクチャ方針に基づき、docs/product/features/sortie.md の草案および関連エントリ、レビュー指摘事項を作成しました。

    1. docs/product/features/sortie.md の完成ドラフト

    ---
    doc_id: feature-sortie
    status: draft
    parent_issue: #483
    trace_links:
      - #484 (combat-core spec)
      - #489 (SortieSystem implementation)
      - #490 (playtest traces)
    ---
    
    # Sortie Feature Specification
    
    ## Intent
    本ドキュメントは、M2: Combat MVP Gate における1回の戦闘単位(Sortie)のライフサイクル、終了条件、および出力結果(Result Object)の生成要件を定義する。ECSアーキテクチャの原則に従い、純粋な状態遷移とシミュレーション時間の管理のみを関心事とする。
    
    ## Scope
    - Sortieの進行状態(有限状態)の管理。
    - 固定タイムステップに基づくシミュレーション時間の計測とタイマー権威の保証。
    - M2 MVP要件に基づく勝利(Victory)および敗北(Defeat)条件の判定。
    - 終了時のTransientなResult Objectの生成。
    
    ## Terminology
    - **Sortie**: 開始から終了までの一連の戦闘セッション。
    - **Simulation Elapsed Time**: 固定タイムステップ(60Hz)のアキュムレータ更新に伴って加算される、ゲーム内での論理的な経過時間。
    - **Transient Result**: 永続化されず、直後のフェーズ(UI表示やM3での報酬計算など)に渡されるための一時的なリザルトデータ。
    
    ## State Machine
    Sortieは以下の有限状態(Finite State)を持つ。
    `idle | running | victory | defeat | ended`
    
    ## Transition Table
    | Current State | Event / Condition | Next State |
    | :--- | :--- | :--- |
    | `idle` | Sortie初期化コマンドを受信 | `running` |
    | `running` | Simulation Elapsed Time >= 120,000ms | `victory` |
    | `running` | Player HP <= 0 | `defeat` |
    | `victory` | Result Object 生成完了 | `ended` |
    | `defeat` | Result Object 生成完了 | `ended` |
    
    ## Timer Authority
    Sortie内の経過時間判定(120秒の計測など)の権威(Authority)は、すべて **Simulation Time(固定タイムステップの経過)** に依存しなければならない。
    ブラウザの `requestAnimationFrame` や `Date.now()`, `performance.now()`(Wall clock)に依存することは固く禁じられる。これにより、ブラウザのバックグラウンド移行時の停止や、144Hzモニター等の環境差異による状態のブレを防ぐ。
    
    ## End Conditions
    - **Victory Condition**: Simulation Elapsed Time が `120,000` ミリ秒(120秒)に到達すること。
    - **Defeat Condition**: PlayerのHPが `0` 以下になること。
    
    ## Result Object Schema
    Sortie終了時に生成されるオブジェクトは、後続のシステムが読み取るための以下の最小shapeを持たなければならない。
    ```typescript
    interface SortieResult {
      outcome: 'victory' | 'defeat';
      durationMs: number;
      kills: number;
      shotsFired: number;
      playerHpRemaining: number;
    }

    System Responsibility Boundaries

    • SortieSystem: タイマーの加算、Player HPの監視、勝敗の判定、状態遷移、Result Objectの生成のみを行う。
    • CombatCoreSystem (実装: combat-core feature spec を作成する #484): ダメージ計算、衝突判定、HPの減算を実行する(SortieSystemはこれらの数値を参照するのみ)。
    • 敵の撃破数(kills)や発射弾数(shotsFired)は、関連する集計コンポーネントまたはSystemから値を読み取ってマッピングする。

    Invariants (不変条件)

    • victory および defeat 判定は、running 状態からのみ遷移可能である。
    • Result Object は状態が victory または defeat になったフレームで一度だけ生成される。
    • ended 状態に遷移した後の状態変異(Mutation)は一切行われない。

    Non-Goals

    本仕様(M2スコープ)では以下を実行しない。

    • 戦闘結果の localStorage または IndexedDB への保存(永続化)。
    • リソースの付与、あるいは機体・武器のアップグレード処理。
    • キャンペーン(Campaign)進行やブリーフィングUIの描画。

    Open Questions

    • 120秒経過判定とPlayer HP 0判定が同一フレーム(同一tick)で発生した場合、どちらのOutcomeを優先するか(※現状はDefeat優先を推奨)。
    • M2において敵が120秒より前に全滅した場合、120秒到達まで待機するのか、あるいは即時勝利とするのか(M2の要件上は「120秒生存」であるため、待機が妥当か)。
    • kills や shotsFired の集計値を参照するための Component または Registry の厳密なパス(実装: sortie start-end state machine と result object を実装する #489 実装時に解決)。

    Related Tests

    • tests/sortie-system.test.ts (シミュレーション経過と状態遷移の決定論的テスト)

    Acceptance Criteria

    • Sortie状態が idle | running | victory | defeat | ended として適切に型定義されている。
    • Timer AuthorityがWall ClockではなくSimulation Timeに基づいている。
    • Result Object が仕様通りのShapeで生成されている。
    • 永続化やアップグレードのミューテーションがSortieSystem内に含まれていない。
    
    ---
    
    ### 2. `docs/dev/ssot-registry.md` に追加すべき sortie エントリ案
    
    `docs/dev/ssot-registry.md` の対象セクション(例: Features / Core Logic)に以下を追記してください。
    
    ```markdown
    - **Sortie Lifecycle & Combat End Conditions**
      - **Path**: `docs/product/features/sortie.md`
      - **Responsibility**: 戦闘(Sortie)の開始から終了(120秒生存 または 自機HP0)までの状態遷移、固定タイムステップタイマーの管理、および Transient Result Object の生成ルールの正本。永続化やUI表示に関する定義は持たない。
      - **Related Systems**: `src/systems/SortieSystem.ts`
    

    3. 実装者向けの短い注意点

    1. 時間の扱いに注意: accumulator の消費ループから提供される固定 delta を加算してタイマーを管理してください。performance.now() 等を条件分岐に混ぜると、タブがバックグラウンドに回った際の巨大なdelta(Spiral of Death)や可変フレームレート環境で状態が壊れます。
    2. 二重発火の防止: HPはダメージ処理順によっては複数回 <= 0 の判定を通る可能性があります。running 状態からの遷移ガードを確実に行い、Result Objectが毎フレーム生成されるバグを防いでください。
    3. 副作用の排除: Result Object を生成して ended に遷移する処理は純粋な状態遷移であるべきです。ここで直接UI描画関数をキックしたり、localStorage に書き込んだりしないでください。

    4. 仕様上の矛盾・不足・曖昧さの指摘(Open Questionsからの抽出)

    • 同時成立時の優先順位: 120,000ms到達 と Player HP <= 0 が全く同じtick内で真になった場合のハンドリングが要件上で未定義です。RTSやアクションの文脈では「死亡(敗北)優先」が一般的ですが、Issue #485の範囲外となるためOpen Questionとして分離しています。
    • 統計データのSSOT(集計元)の不在: kills や shotsFired の数値をResult Objectに含める要件がありますが、それらの「カウンター」をどこに保持するかの責務が明確ではありません。ECSでは PlayerStatsComponent のような集計用コンポーネントを別途設けるのがクリーンですが、この仕様は 実装: sortie start-end state machine と result object を実装する #489 または 実装: combat-core feature spec を作成する #484 で決定する必要があります。
    • 120秒前の敵全滅: 「120秒生存」が勝利条件ですが、プレイヤーが強すぎて100秒で敵(スポナー含む)を全滅させてしまった場合、残りの20秒を放置するのかが曖昧です。MVPでは敵スポーンは無限である前提で一旦仕様を閉じています。

    5. Issue #485 のAcceptance Criteria充足チェックリスト

    • Allowed Paths は docs/product/features/sortie.md と docs/dev/ssot-registry.md のみ。
    • src/ と tests/ は変更しない。
    • sortie state を有限状態として定義する (idle | running | victory | defeat | ended)。
    • victory 条件は 120秒生存。
    • defeat 条件は player HP 0。
    • result object の最小 shape は outcome, durationMs, kills, shotsFired, playerHpRemaining。
    • result object は persistence / upgrade を直接実行しない transient output である旨を記載。
    • sortie timer の authority は wall clock ではなく simulation time / fixed timestep elapsed。
    • non-goals に persistence / upgrade / campaign / briefing UI を含める。
    • related_tests に tests/sortie-system.test.ts を列挙。
    • pnpm typecheck && pnpm lint && pnpm test && pnpm build が通る前提のdocs-only変更にする(Markdownのみの草案として遵守)。
  5. squne121 commented on May 30, 2026

    @squne121
    OwnerAuthor

    Contract Review: BLOCKED (2026-05-30T00:40:32Z)

    CONTRACT_REVIEW_RESULT_V1:
      status: blocked
      generated_at: 2026-05-30T00:40:32Z
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/485
      checks:
        template_compliance: pass
        state_label: ok
        allowed_paths_present: pass
        vc_present: pass
        stop_conditions_complete: pass
        product_spec_check:
          applicability: applicable
          decision: fail
          triggers:
            docs_product_allowed_paths: true
            tasks_md_mentioned: false
            specify_artifact_mentioned: false
            generated_task_mentioned: false
            product_spec_context_present: false
          blocked_reasons:
            - rule_id: PS004
              source: issue_body
              excerpt: "docs/product/** 更新あり、diff_rationale / changed_requirement_id / affected_sections 欠落"
        vc_preflight:
          passed: null
          status: skipped_due_to_product_spec_block
        worktree_branch_collision: clear
      next_action: propose_refinement_loop
      blocked_reasons:
        - rule_id: PS004
          source: issue_body
          excerpt: "docs/product/** 更新あり(docs/product/features/sortie.md 新規作成)に対して diff_rationale / changed_requirement_id / affected_sections が Issue 本文に存在しない"

    Product Spec Preflight: BLOCKED

    判定理由

    Issue #485 は docs/product/features/sortie.md を新規作成する docs/product/** への変更を含んでいます。
    PS004 ルールにより、docs/product/** 更新を含む Issue には以下のいずれか 1 件以上が必要です:

    • diff_rationale(変更理由)
    • changed_requirement_id(変更された要件 ID)
    • affected_sections(影響セクション)

    該当ルール

    rule_id 説明
    PS004 product spec 更新に diff_rationale / changed_requirement_id / affected_sections が存在するか

    不足項目

    Issue 本文に以下のフィールドが存在しません:

    # 以下のいずれか 1 件以上を追加してください
    diff_rationale: "sortie lifecycle / FSM / timer authority / result invariants の新規定義(既存仕様の初回作成)"
    # または
    changed_requirement_id: "sortie_playable (M2)"
    # または
    affected_sections:
      - "sortie lifecycle"
      - "FSM transition table"
      - "result object invariants"

    推奨アクション

    issue-refinement-loop を起動して Issue 本文に PS004 準拠フィールドを追加してください。
    または Issue 本文の ## Scope Delta セクション(または ## Machine-Readable Contract の yaml block)に diff_rationale を直接追記することで解決できます。

  6. squne121 commented on May 30, 2026

    @squne121
    OwnerAuthor

    Contract Snapshot (2026-05-30T00:46:04Z)

    • Outcome: docs/product/features/sortie.md が作成され、sortie state machine(遷移表含む)/ 終了条件 / timer authority / result object 不変条件が定義された状態で pnpm test && pnpm build が通っている
    • Acceptance Criteria: AC1〜AC19(19 項目)
    • Verification Commands: AC1=test -f、AC2-AC17=grep(pr_review_only scope)、AC18=grep ssot-registry、AC19=pnpm typecheck/lint/test/build
    • Allowed Paths: docs/product/features/sortie.md, docs/dev/ssot-registry.md
    • Worktree: .claude/worktrees/issue-485-sortie-feature-spec
    • Branch: worktree-issue-485-sortie-feature-spec
    • VC preflight: baseline fail = 2, unexpected pass = 0, unrunnable = 0, skipped (pr_review_only) = 16, expected_pass = 4
    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: 2026-05-30T00:46:04Z
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/485
      checks:
        template_compliance: pass
        state_label: ok
        allowed_paths_present: pass
        vc_present: pass
        stop_conditions_complete: pass
        vc_preflight:
          passed: true
          vc_failed_as_expected: 2
          vc_passed_unexpectedly: 0
          vc_unrunnable: 0
          vc_expected_pass: 4
          vc_skipped: 16
          classifications:
            - ac: AC1
              command: "test -f docs/product/features/sortie.md"
              exit_code: 1
              category: file_not_found_expected
              scope_class: baseline_fail_expected
              confidence: high
              decision: go
            - ac: AC2
              command: "grep -n 'doc_id|status|parent_issue|trace_links' docs/product/features/sortie.md"
              exit_code: null
              category: pr_review_only
              scope_class: pr_review_only
              confidence: high
              decision: go
              classification: skipped
              verification_owner: pr-review-judge
              deferred_reason: file not created yet; content verified at PR review
              runtime_verification_required: false
            - ac: AC18
              command: "grep -n 'sortie\.md|feature-sortie' docs/dev/ssot-registry.md"
              exit_code: 1
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              decision: go
            - ac: AC19
              command: "pnpm typecheck / lint / test / build"
              exit_code: 0
              category: regression_gate
              scope_class: regression_gate
              confidence: low
              decision: go
        ac_verifiability: pass
        product_spec_check:
          applicability: applicable
          decision: pass
          triggers:
            docs_product_allowed_paths: true
            tasks_md_mentioned: false
            specify_artifact_mentioned: false
            generated_task_mentioned: false
            product_spec_context_present: false
          blocked_reasons: []
        worktree_branch_collision: clear
      next_action: implement_issue
      blocked_reasons: []
      warnings: []
  7. squne121 commented on May 30, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-05-30T00:49:38Z)

    • PR: docs(#485): add sortie feature spec #501
    • Worktree: .claude/worktrees/issue-485-sortie-feature-spec
    • Branch: worktree-issue-485-sortie-feature-spec
    • Verification: 4/4 PASS (typecheck / lint / test 179 passed / build)
    • 後続: PR レビュー(pr-review-judge)→ マージ → post-merge-cleanup
  8. added 2 commits that reference this issue on May 30, 2026
  9. added 2 commits that reference this issue on May 30, 2026
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/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions