Skip to content

実装: docs/product/game-logic.md を追加する — ゲームロジック仕様(C254-5) #287

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#254"
goal_ref: "SDD 駆動運用を採用しつつ、AI が実装前に必ず参照すべきプロダクト SSOT(game-logic)を追加する"
change_kind: docs
source_basis:
  game_thesis: accepted     # docs/product/game-thesis.md status
  game_design:
    status: draft
    reconciliation_required_before_normative_use: true
  fallback_used:
    - docs/product/requirements.md
    - docs/product/game-thesis.md
    - docs/adr/0001-architecture-baseline.md
    - docs/adr/0002-sdd-tool-adoption.md
    - docs/dev/product-spec-lifecycle.md

Parent Issue

#254

Parent Goal Ref

  • Goal: Spec Driven Development(SDD)駆動運用を採用しつつ、既存 docs/SSOT・Skill/SubAgent・Issue/PR 運用と整合させ、AI が実装前に必ず参照すべきプロダクト SSOT(game-thesis / game-design / game-logic / mvp-scope / playtest / lifecycle / release)を child Issue として段階起票する
  • Desired Destination: 不足 product SSOT 7 種が child Issue としてマージ済みとなり、docs/dev/ssot-registry.md に上記 SSOT が登録され、ssot-discovery skill 経由で検出可能な状態

Current Validated Scope

  • docs/product/game-logic.md の新規作成
    • YAML frontmatter: status: draft, issue: "#287", parent_issue: "#254", doc_id: game-logic, trace_links
    • 必須セクション(日本語/英語併記)
  • docs/dev/ssot-registry.md への game-logic エントリ追加

Remaining Parent Gaps

Outcome

docs/product/game-logic.md が main にマージされ、docs/dev/ssot-registry.md に game-logic エントリが登録されている。目的 / 正本階層 / 要求 / 状態遷移 / 入力 / 時間モデル / 衝突 / 勝敗 / 保存境界 / 非ゴール / 下流境界 / 未解決の問い / 検証が記述されており、src/state / src/systems / src/storage 実装の仕様根拠として参照可能な状態。

In Scope

  • docs/product/game-logic.md の新規作成
    • YAML frontmatter: status: draft, issue: "#287", parent_issue: "#254", doc_id: game-logic, trace_links
    • 必須セクション(日本語/英語併記):
      • ## 目的 / Intent
      • ## 正本階層 / Authority and Fallbacks(game-thesis.md accepted を上位、game-design.md draft を補助参照に明示)
      • ## 要求 / Requirements(EARS は AC レベルの 5〜9 個に限定)
      • ## 状態遷移 / State Transitions
      • ## 入力 / Input(DOM event を simulation に直接渡さず InputCommand に正規化)
      • ## 時間モデル / Time Model(60Hz 固定タイムステップ、accumulator、panic clamp、rAF=elapsed time のみ)
      • ## 衝突 / Collision(broad-phase + tick 内移動距離 > collider radius の高速 projectile のみ swept/CCD)
      • ## 勝敗 / Victory, Defeat, Draw(下記 Decision を反映)
      • ## 保存境界 / Persistence Boundary(src/storage 境界、MVP localStorage、安定点 snapshot、entity id ベース)
      • ## 非ゴール / Non-Goals
      • ## 下流境界 / Downstream Boundaries
      • ## 未解決の問い / Open Questions
      • ## 検証 / Verification Notes
    • compact spec 制約: 250 行以内
  • docs/dev/ssot-registry.md への game-logic エントリ追加
    • registry id は game-logic(spec-game-logic 等の prefix は禁止)
    • YAML-list 形式、既存 entry (game-thesis / game-design / requirements) と同じフォーマット

Victory/Defeat/Draw Decision (人間 Decision 反映)

  • 敗北条件: player-controlled entity の combat HP が 0 以下になった時点で defeat state へ遷移
  • 戦闘終了トリガ (OR、いずれか先に成立):
    • 120 秒の sortie timer 満了 → 戦闘終了(通常戦闘報酬)
    • 敵拠点破壊 → 戦闘終了(多量戦闘報酬)
    • 敵機殲滅 → 戦闘終了(勝利扱い)
  • Draw: MVP では定義しない(タイマー満了 = 通常終了として扱う)
  • 数値(具体的な報酬量・拠点 HP・敵機数)は Open Questions に退避

Product Spec Context

Out of Scope

  • 外部 physics engine の導入
  • .specify/**(derived workbench artifact)や tasks.md(staging artifact)を canonical source / 正本として扱うこと。docs/SSOT が優先。
  • 報酬量・拠点 HP・敵機数等の具体的な実装定数の固定(mvp-scope / 別 Issue で扱う)
  • src/ 実装の変更(仕様書のみ)
  • mvp-scope の定義(C254-6)
  • アセット制作

Acceptance Criteria

  • AC1: docs/product/game-logic.md が存在し、必須セクション(目的 / 正本階層 / 要求 / 状態遷移 / 入力 / 時間モデル / 衝突 / 勝敗 / 保存境界 / 非ゴール / 下流境界 / 未解決の問い / 検証)を含む
  • AC2: docs/product/game-logic.md がアーキテクチャ原則(src/state と src/render の完全分離・60Hz 固定タイムステップ・accumulator・rAF ≠ simulation dt)と整合している
  • AC3: docs/dev/ssot-registry.md に id: game-logic の entry が YAML-list 形式で追加されている(spec-game-logic 等の prefix を使わない)
  • AC4: docs/product/game-logic.md は compact spec 制約に準拠する
    • 250 行以内
    • YAML frontmatter に status, issue: "#287", parent_issue: "#254", doc_id: game-logic, trace_links を含む
    • Non-Goals, Open Questions, Verification Notes を含む
    • EARS は Requirements / Acceptance Criteria レベルに限定(5〜9 項目程度)
  • AC5: Source Hierarchy は accepted docs/product/game-thesis.md を上位、docs/product/game-design.md (status: draft) は補助参照として source_basis に明示する
  • AC6: 勝敗条件は人間 Decision を反映する(敗北: HP 0、戦闘終了 OR: 120秒満了/敵拠点破壊/敵機殲滅、報酬差分を明記)。具体的な数値(報酬量・拠点 HP・敵機数)は Open Questions に退避
  • AC7: stale / nonexistent reference を含まない
    • docs/adr/0001-architecture-core.md を参照しない(正しくは docs/adr/0001-architecture-baseline.md)
    • ssot-catalog.md を参照しない(削除済み)
  • AC8: docs/product/game-logic.md は src/ 実装変更、asset 制作、外部 physics engine 導入を要求しない(記述のみ、Allowed Paths 外への波及禁止)
  • AC9: pnpm typecheck && pnpm lint && pnpm test && pnpm build が PASS している
  • AC10: docs/dev/workflow.md の SSOT Routing Table に game-logic 行が追加されている(product-spec-lifecycle.md の「新規 SSOT 追加時の必須更新セット」遵守)

Verification Commands

# AC1: game-logic.md 存在と必須セクション
$ test -f docs/product/game-logic.md
$ rg -q "^## .*目的" docs/product/game-logic.md
$ rg -q "^## .*正本階層" docs/product/game-logic.md
$ rg -q "^## .*要求" docs/product/game-logic.md
$ rg -q "^## .*状態遷移" docs/product/game-logic.md
$ rg -q "^## .*入力" docs/product/game-logic.md
$ rg -q "^## .*時間モデル" docs/product/game-logic.md
$ rg -q "^## .*衝突" docs/product/game-logic.md
$ rg -q "^## .*勝敗" docs/product/game-logic.md
$ rg -q "^## .*保存境界" docs/product/game-logic.md
$ rg -q "^## .*非ゴール" docs/product/game-logic.md
$ rg -q "^## .*下流境界" docs/product/game-logic.md
$ rg -q "^## .*未解決の問い" docs/product/game-logic.md
$ rg -q "^## .*検証" docs/product/game-logic.md

# AC2: アーキテクチャ原則
$ rg -q "60Hz" docs/product/game-logic.md
$ rg -q "固定タイムステップ" docs/product/game-logic.md
$ rg -q "accumulator" docs/product/game-logic.md
$ rg -q "src/state" docs/product/game-logic.md
$ rg -q "src/render" docs/product/game-logic.md

# AC3: ssot-registry entry
$ rg -q "^- id: game-logic$" docs/dev/ssot-registry.md
$ rg -q "path: docs/product/game-logic.md" docs/dev/ssot-registry.md

# AC4: compact spec 制約
$ rg -q '^status:' docs/product/game-logic.md
$ rg -q '^issue: "#287"' docs/product/game-logic.md
$ rg -q '^parent_issue: "#254"' docs/product/game-logic.md
$ rg -q '^doc_id: game-logic$' docs/product/game-logic.md
$ rg -q '^trace_links:' docs/product/game-logic.md
$ awk 'END { exit (NR > 250) }' docs/product/game-logic.md

# AC5: Source Hierarchy / source_basis
$ rg -q "game-thesis" docs/product/game-logic.md
$ rg -q "source_basis|正本階層|Authority" docs/product/game-logic.md

# AC6: 勝敗条件 Decision
$ rg -q "120" docs/product/game-logic.md
$ rg -q "敵拠点|拠点破壊" docs/product/game-logic.md
$ rg -q "敵機殲滅|殲滅" docs/product/game-logic.md
$ rg -q "HP" docs/product/game-logic.md

# AC7: stale reference 不在(expected no match: exit 1 想定)
$ ! rg -n "docs/adr/0001-architecture-core.md" docs/product/game-logic.md
$ ! rg -n "ssot-catalog" docs/product/game-logic.md docs/dev/ssot-registry.md
$ ! rg -n "spec-game-logic" docs/dev/ssot-registry.md

# AC8: Allowed Paths 外の指示が混入していない(expected no match)
$ ! rg -n "^src/" docs/product/game-logic.md
$ ! rg -n "assets/" docs/product/game-logic.md

# AC10: workflow.md SSOT Routing Table 追加
$ rg -q "game-logic\.md" docs/dev/workflow.md
$ rg -q "^\| .*game-logic" docs/dev/workflow.md

# AC9: quality gate (atomic 実行)
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm build

Allowed Paths

  • docs/product/game-logic.md(新規)
  • docs/dev/ssot-registry.md(エントリ追加のみ)
  • docs/dev/workflow.md(SSOT Routing Table に game-logic 行を 1 件追加のみ。他セクション編集禁止)

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • docs/product/game-design.md(C254-4, 実装: docs/product/game-design.md を追加する — GDD v0.1(C254-4) #282)が未マージの状態で game-logic.md の記述に矛盾が生じた場合

Runtime Verification Applicability

  • decision: deferred
  • reason: docs/product/game-logic.md は仕様書であり、本 Issue の scope は仕様書作成のみ。VC(AC1〜AC9)は記述の正確性確認であって実装の動作検証ではない。状態遷移 / 衝突 / 入力 / 保存境界の実際の動作検証は、game-logic.md を参照する後続の実装 Issue(src/state / src/systems / src/storage 変更を含む)で impl-review-loop 経由で行う。
  • deferred_destination:
    • destination_type: implementation_issue
    • destination_ref: TBD(game-logic.md マージ後に src/state / src/systems / src/storage 実装 Issue が作成された時点で確定)
  • deferred_verification_condition: 以下いずれかが満たされた時点で動作検証可能。(1) src/state の状態遷移実装が game-logic.md の State Transitions セクションを満たす、(2) src/systems の collision 実装が game-logic.md の Collision セクションを満たす、(3) src/storage の persistence 実装が game-logic.md の Persistence Boundary セクションを満たす。

Required Skills

なし

Scope Delta(任意)

N/A

Delivery Rule

Source

Normative References

  • docs/adr/0001-architecture-baseline.md(60Hz / state-render 分離)
  • docs/adr/0002-sdd-tool-adoption.md(EARS 部分採用方針)
  • docs/dev/product-spec-lifecycle.md(compact spec / frontmatter / 250 行制約)
  • docs/product/requirements.md(MVP 境界)
  • docs/product/game-thesis.md(accepted、上位正本)
  • docs/product/game-design.md(draft、補助参照のみ)
  • docs/dev/ssot-registry.md(registry 命名規則)

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    triage-required
    on May 23, 2026
  2. squne121 commented on May 24, 2026

    @squne121
    OwnerAuthor

    NotebookLM に蓄積された資料に基づき、GitHub Issue #287「docs/product/game-logic.md を追加する — ゲームロジック仕様(C254-5)」の作成案を提示します。

    以下は、AI エージェント(Claude Code 等)が迷わず docs-only PR を作成できるように最適化された、設計案および作業指示の草案です。


    1. 根拠資料の優先順位

    game-logic.md を作成する上で、AI が参照すべき資料の優先順位と情報の確度は以下の通りです。

    【確定根拠】(最優先で遵守)

    1. ADR 0001 (アーキテクチャ定義): src/state と src/render の完全分離、60Hz固定タイムステップ(アキュムレータ方式)、Entity ID による参照。
    2. ADR 0002 / product-spec-lifecycle: compact spec 方針、YAML frontmatter、EARS notation の適用方針(与件定義に従う)。
    3. Issue 親: SDD 駆動運用方針の確定と不足 product SSOT の child 起票 #254 / 実装: docs/product/game-logic.md を追加する — ゲームロジック仕様(C254-5) #287: 本タスクの要件および Allowed Paths 制約。
    4. docs/product/requirements.md: MVPスコープ(1画面固定、WASD+マウス、Zキー指示)。

    【補助根拠】(ロジックの肉付けに利用)

    1. docs/product/game-design.md (Issue 実装: docs/product/game-design.md を追加する — GDD v0.1(C254-4) #282): ゲームのAestheticsやDynamicsの定義。
    2. 既存の src/ 構造: src/systems/, src/state/, src/input/ などの分離状況。

    【不明・要確認】(断定せず Open Questions または Fallback に退避)

    1. game-design.md のマージ状況: 未確定・未マージの場合は、推測でロジックを確定せず、「game-design.md 確定後に追記」とする。
    2. 勝敗条件の矛盾: 資料上、「敵拠点破壊で勝利」と「120秒生存で勝利」が混在している(Issue内で「120秒生存で勝利に修正する」との言及あり)。ここでは断定せず Draft 扱いとする。
    3. 具体的な実装定数: 武器のダメージ量、敵の出現数、キー割当の具体値などは Open Questions に逃がす。

    2. docs/product/game-logic.md の推奨アウトライン

    ---
    id: game-logic
    type: specification
    status: draft
    parent: docs/product/requirements.md
    trace_links:
      - docs/adr/0001-architecture-core.md
      - docs/product/game-design.md
    ---
    
    # Game Logic Specification
    
    ## Intent
    ## Source Hierarchy / Authority and Fallbacks
    ## Requirements (EARS)
    ## State Transitions
    ## Input
    ## Time Model
    ## Collision
    ## Victory / Defeat / Draw
    ## Persistence Boundary
    ## Non-Goals
    ## Downstream Boundaries
    ## Open Questions
    ## Verification Notes

    3. 各セクションの記述方針

    • Intent: このドキュメントが、ゲームのシミュレーションルール、入力の正規化、物理演算(衝突)、および状態永続化の境界を定義する「ロジックの SSOT」であることを簡潔に宣言します。
    • Source Hierarchy: game-design.md を体験設計の上位制約とし、技術的制約は ADR 0001 を正本とすることを明記します。game-design.md が未確定の場合は「Draft 状態の design を仮置きとする」とフォールバックを記述します。
    • Requirements: 後述の EARS 構文を用いて、アーキテクチャ要件を 5〜7 個程度に絞って記述します。
    • State Transitions: BattleState(戦闘中の状態)と CampaignState(戦闘外の状態)の遷移境界について記述します。
    • Input: DOM イベント(keydown / mousedown 等)を直接ロジックに渡さず、InputState から InputCommand へ正規化して System に渡す設計原則を明記します。具体的なキーバインドは Open Questions とします。
    • Time Model: requestAnimationFrame から分離された、60Hz の固定タイムステップ(アキュムレータ方式)について記述します。タブがバックグラウンドに回った際の「死の螺旋(Spiral of Death)」を防ぐパニック・クランプについても記載します。
    • Collision: 高速な弾(Projectile)のすり抜けを防ぐための「連続衝突判定(CCD)」と、計算量爆発を防ぐ「空間分割(均一グリッド等)」を明記します。ユニット・弾は「円」、施設や障害物は「AABB(矩形)」として扱う方針を書きます。
    • Victory / Defeat / Draw: 自機 HP 0 での敗北を明記します。勝利条件については資料の矛盾があるため、「敵拠点の破壊(あるいは 120秒生存)」と記載し、Open Questions に回します。
    • Persistence Boundary: IndexedDB(MVPでは localStorage)へ保存する際、JSON.stringify で同期スナップショットを取得し「Torn State(状態の引き裂かれ)」を防ぐこと、および Entity 参照はポインタではなく整数 ID を用いることを明記します。
    • Non-Goals: ネットワーク同期(ロックステップ等)、Z軸の物理演算、ヒットスキャン兵器の多用(一部レーザーを除く)を明確に除外します。
    • Downstream Boundaries: 描画(src/render)や、データ駆動用のパラメータ JSON への値の受け渡し境界について記述します。
    • Open Questions: 勝敗条件の厳密な仕様、武器のクールダウン秒数、画面上のエンティティ上限数など。
    • Verification Notes: ロジックの検証は Canvas に依存せず、Vitest による純粋な単体テスト(Mock の活用、シード固定)で行う方針を記述します。

    4. EARS requirements 案

    過剰な EARS 化を避け、Acceptance Criteria に直結するコア要件のみを定義します。

    • REQ-LOGIC-001 [Time Model]: While in the combat phase, the system shall update game logic using a fixed 60Hz time step (accumulator pattern), entirely independent of the render frame rate. (Ref: ADR 0001)
    • REQ-LOGIC-002 [Input]: When browser DOM events are fired, the Input System shall normalize them into pure InputCommand structures before passing them to the game simulation. (Ref: ADR 0001)
    • REQ-LOGIC-003 [Collision]: While calculating projectile collisions, the Collision System shall apply Continuous Collision Detection (CCD) to fast-moving entities to prevent tunneling. (Ref: ADR 0001)
    • REQ-LOGIC-004 [Persistence]: When the game state needs to be saved, the system shall capture a synchronous JSON snapshot of the GameState using integer Entity IDs instead of object references. (Ref: ADR 0001)
    • REQ-LOGIC-005 [Victory/Defeat] (Draft - 要確認): When the player's HP reaches zero, the system shall transition to the defeat state. When the 120-second sortie timer expires (or the enemy core is destroyed), the system shall transition to the victory state. (Ref: requirements.md, Issue #xxx for resolution)

    5. docs/dev/ssot-registry.md 追加エントリ案

    既存のレジストリフォーマットに準拠し、Markdown Table を使用せず YAML-list 形式でエントリを作成します。

    - id: spec-game-logic
      path: docs/product/game-logic.md
      title: Game Logic Specification
      keywords: [logic, ecs, simulation, 60hz, collision, input, persistence]
      description: Defines the core simulation rules, time model, input normalization, collision mechanics, and state persistence boundaries for the game.
      sections: [Intent, Time Model, Collision, State Transitions, Persistence Boundary, Input, Victory/Defeat]

    6. 敵対的レビュー観点

    実装 AI に指示を出す際、以下のリスクを回避できているかレビューする観点を持たせます。

    1. 実装: docs/product/game-logic.md を追加する — ゲームロジック仕様(C254-5) #287 AC 制約の違反リスク: src/ 配下の実装変更や、アセット制作の指示が game-logic.md に混入していないか(Allowed Paths 違反)。
    2. game-design.md との矛盾リスク: game-design.md (実装: docs/product/game-design.md を追加する — GDD v0.1(C254-4) #282) で定められる Aesthetics(エースとしての介入感など)を損なうようなロジック制約(例: 完全なオートバトラーへの改変)になっていないか。
    3. State/Render 分離違反リスク: ロジック仕様の中に「Canvas API を呼び出す」「DOM を操作する」といった描画に関わる記述が漏れ出していないか。
    4. 60Hz 固定タイムステップ違反リスク: delta time を直接ゲーム内座標の掛け合わせに使用するような(可変フレームレートを前提とした)仕様になっていないか。
    5. 保存境界のズレリスク: オブジェクト参照(ポインタ)を永続化しようとする(Torn Stateを引き起こす)記述がないか。
    6. 未確定実装定数の正本化リスク: 草案段階の「敵の数5体」「制限時間120秒」などを、game-logic.md 側で勝手にハードコードすべき「不変の仕様」として断定していないか(Open Questions に置かれているか)。

    7. 実装 AI へ渡す短い作業指示案

    このまま Claude Code などのエージェントにペーストできるプロンプト案です。

    # 目的
    Issue #287 の要件に従い、`docs/product/game-logic.md` の新規作成と、`docs/dev/ssot-registry.md` へのエントリ追加を行ってください。
    
    # 変更対象ファイル (Allowed Paths)
    - `docs/product/game-logic.md` (新規作成)
    - `docs/dev/ssot-registry.md` (追記)
    
    # 参照順序 (Authority)
    1. `docs/adr/0001-*.md` (ECS分離、60Hz固定タイムステップの技術制約)
    2. `docs/product/requirements.md` (MVPスコープ)
    3. `docs/product/game-design.md` (存在する場合のみ上位制約とする。存在しない、またはドラフトの場合は Open Questions にフォールバック条件を記載)
    
    # 禁止事項 (Stop Conditions)
    - これは **docs-only** の変更です。`src/` 配下のコード変更やアセット作成は絶対にしないでください。実装に触れそうになった場合は即座に作業を停止してください。
    - `game-design.md` が未確定な状態で、勝敗条件(120秒生存か拠点破壊か)や、具体的な武器パラメータ、キーバインドなどの「実装定数」を勝手に固定しないでください。未確定要素はすべて `Open Questions` セクションに退避してください。
    - EARS 構文を全文に適用せず、`Requirements` セクションの Acceptence Criteria レベルの 5〜7 項目のみに留めてください。
    - `ssot-registry.md` は Markdown Table ではなく YAML-list 形式で追記してください。
    
    # 完了条件
    `docs/product/game-logic.md` が指定のアウトライン(Intent, Source Hierarchy, Requirements, State Transitions, Input, Time Model, Collision, Victory/Defeat, Persistence Boundary, Non-Goals, Downstream Boundaries, Open Questions, Verification Notes)を含み、`ssot-registry.md` への追加が正しく完了していること。
    完了後、変更内容をサマリーとして報告してください。
  3. squne121 commented on May 24, 2026

    @squne121
    OwnerAuthor

    人間からの指摘です。
    120 秒生存 で戦闘を終了。戦闘報酬を獲得。敵拠点破壊で多量の戦闘報酬獲得。敵機殲滅で戦闘終了(勝利)はどうか?

  4. squne121 commented on May 24, 2026

    @squne121
    OwnerAuthor

    判定

    REQUEST_CHANGES。#287 は docs-only の方向性自体は正しいが、このまま実装エージェントへ渡すと game-logic.md が下流実装の誤った正本になり得る。 特に、#281/#282 の状態変化、product-spec-lifecycle.md の compact spec 要件、勝敗条件の未確定、検証コマンドの弱さを Issue 本文に反映してから着手すべきです。#287 自体は docs/product/game-logic.md 新規作成と docs/dev/ssot-registry.md 追記だけを Allowed Paths とする docs-only Issue で、AC も状態遷移・入力・時間・衝突・勝敗・保存境界、state/render 分離、60Hz 固定タイムステップ、registry 登録、pnpm quality gate を要求しています。

    主要ブロッカー

    B1. game-design.md の依存状態が古いまま

    #282 / PR #370 は merge 済みで game-design.md は main に存在しますが、現在の game-design.md は status: draft のままです。さらに本文には「game-thesis.md が accepted になったら、game-logic.md / mvp-scope.md の normative source として使う前に spec delta issue で reconcile せよ」という境界が残っています。

    一方で game-thesis.md は main 上で status: accepted になっており、後続の game-design.md / game-logic.md / mvp-scope.md の判断基準として参照される正本です。 したがって #287 は単に「Depends on #282」では不十分です。Issue 本文に以下を追加すべきです。

    source_basis:
      game_thesis: accepted
      game_design:
        status: draft
        reconciliation_required_before_normative_use: true
      fallback_used:
        - docs/product/requirements.md
        - docs/product/game-thesis.md
        - docs/adr/0001-architecture-baseline.md
        - docs/adr/0002-sdd-tool-adoption.md

    少なくとも PR 本文に source_basis を必須化し、game-design.md の stale fallback boundary を読んだうえで game-thesis.md を上位正本にする、という判断を明示させるべきです。

    B2. product-spec-lifecycle.md 準拠 AC が欠けている

    product-spec-lifecycle.md は docs/product/** 作成時に YAML frontmatter、compact spec、EARS は acceptance criteria レベル限定、non_goals、trace_links、registry 登録を要求し、compact spec は 250 行以内としています。 しかし #287 の AC は、必須セクション・architecture 整合・registry・quality gate だけで、frontmatter、250 行制約、trace_links、non-goals、open_questions、EARS 適用範囲を検証していません。

    追加すべき AC:

    - [ ] AC4: `docs/product/game-logic.md` は `docs/dev/product-spec-lifecycle.md` の compact spec 制約に準拠する
      - 250 行以内
      - YAML frontmatter に `status`, `issue: "#287"`, `parent_issue: "#254"`, `doc_id: game-logic`, `trace_links` を含む
      - `Non-Goals`, `Open Questions`, `Verification Notes` を含む
      - EARS notation は Requirements / Acceptance Criteria レベルに限定する

    B3. 勝敗条件を「120 秒生存 or 敵拠点破壊」と曖昧なまま EARS にしてはいけない

    添付草案 / Issue コメントは、勝敗条件について「敵拠点破壊」と「120 秒生存」が混在しているため Draft 扱いにする、としています。 これは正しい警戒ですが、草案の REQ-LOGIC-005 は “120-second sortie timer expires (or the enemy core is destroyed)” のように曖昧な OR を要求文に残しています。これは危険です。

    game-logic.md では次のどちらかに分けるべきです。

    - 敗北条件: player-controlled entity の combat HP が 0 以下になったら defeat state へ遷移する。
    - 勝利条件: 未確定。`mvp-scope.md` または spec delta issue で決定するまでは normative requirement にしない。

    または、勝利条件を #287 で決めるなら、docs/product/game-thesis.md の「局所介入」「短時間 sortie」「技術抽出ループ」と docs/product/requirements.md の MVP-003/MVP-004 へ明示的に trace し、Open Questions ではなく Decision として固定する必要があります。

    B4. registry entry の ID が草案だと既存形式とズレる

    NotebookLM 草案は id: spec-game-logic を提案していますが、既存 registry は game-thesis, game-design, requirements のように product SSOT 名そのものを ID にしています。 spec-game-logic は発見性と命名一貫性を壊すため、id: game-logic にするべきです。

    推奨 entry:

    - id: game-logic
      path: docs/product/game-logic.md
      title: Game Logic Specification
      keywords: [game-logic, state-transition, input, fixed-timestep, collision, ccd, persistence, snapshot, victory, defeat, deterministic-test]
      description: 状態遷移、入力正規化、60Hz 固定タイムステップ、衝突、勝敗、保存境界を定義するゲームロジック仕様の正本
      sections:
        - "## 目的 / Intent"
        - "## 正本階層 / Authority and Fallbacks"
        - "## 要求 / Requirements"
        - "## 状態遷移 / State Transitions"
        - "## 入力 / Input"
        - "## 時間モデル / Time Model"
        - "## 衝突 / Collision"
        - "## 勝敗 / Victory, Defeat, Draw"
        - "## 保存境界 / Persistence Boundary"
        - "## 非ゴール / Non-Goals"
        - "## 未解決の問い / Open Questions"
        - "## 検証 / Verification Notes"

    技術面の高品質化ポイント

    1. 時間モデル: rAF と 60Hz simulation を混同しない

    requestAnimationFrame() は一般に画面リフレッシュに同期しますが、60Hz だけでなく 75/120/144Hz も一般的で、バックグラウンドタブでは pause されることがあります。したがって game-logic.md は「rAF = 60Hz」と書いてはいけません。([MDNウェブドキュメント]1)

    ADR 0001 と requirements は、simulation は 60Hz 固定タイムステップ、render は Canvas 描画専用で状態更新禁止、と定義しています。 Gaffer の fixed timestep 記事でも、可変 delta time は挙動差や tunneling を招き得るため、accumulator で固定 dt を消費し、spiral of death 回避のため frameTime / max steps clamp を入れる設計が推奨されています。([Gaffer On Games]2)

    入れるべき文:

    REQ-LOGIC-TIME-001:
    While combat is active, the simulation shall advance only in fixed 1/60 second ticks.
    The render loop may supply elapsed wall-clock time, but systems shall consume it through an accumulator and shall not integrate arbitrary variable delta time.
    
    REQ-LOGIC-TIME-002:
    If accumulated wall-clock time exceeds the configured panic threshold, the game loop shall clamp catch-up steps to avoid spiral-of-death behavior.

    2. 保存境界: JSON.stringify だけで torn state を防ぐ、と言い切らない

    requirements は MVP では localStorage を最小保存手段として許容していますが、保存は src/storage の snapshot 境界で扱うとしています。 Web Storage の localStorage / sessionStorage は同期 API であり、大きなデータや高頻度操作では JavaScript 実行を block し得ます。MDN は、大きな構造化データや性能懸念がある場合は非同期の IndexedDB がより適切と説明しています。([MDNウェブドキュメント]3) IndexedDB は transaction を持つ object-oriented database で、structured clone 対象の object を保存でき、処理は非同期です。([MDNウェブドキュメント]4)

    したがって草案の「JSON.stringify で同期スナップショットを取得し Torn State を防ぐ」はやや強すぎます。より安全な仕様はこうです。

    - MVP では `localStorage` を小さな save snapshot の保存先として許容する。
    - 保存は combat tick 中ではなく、sortie end / debrief / explicit save point などの安定点で行う。
    - 永続化対象は object reference ではなく serializable snapshot と entity id で表現する。
    - snapshot には `schema_version`, `created_at_tick`, `campaign_state`, `unlocked_resources` を含める。
    - `localStorage` write failure / quota exceeded / parse failure は recoverable error として扱う。
    - 将来 IndexedDB へ移行する場合は transaction boundary を `src/storage` 内に閉じ込め、simulation system から直接呼ばない。

    3. 衝突: CCD を「全 projectile に必須」とせず、適用条件を定義する

    高速 projectile の tunneling 対策として CCD を検討するのは妥当です。Box2D のような 2D physics engine でも collision system は broad phase、continuous collision detection、solver の組み合わせで構成され、fast bodies の取りこぼしを避ける方向の設計が取られています。([ウィキペディア]5) ただし #287 は docs-only の仕様で、実装コストを固定しすぎると MVP を圧迫します。

    推奨は「高速 projectile / tick 内移動距離が collider 半径を超えるもののみ swept collision を要求」とすることです。

    REQ-LOGIC-COLLISION-001:
    The collision system shall use deterministic broad-phase filtering before narrow-phase checks.
    
    REQ-LOGIC-COLLISION-002:
    When a projectile can move farther than its collision radius during one simulation tick, the collision system shall use swept collision or an equivalent continuous check to avoid tunneling.
    
    REQ-LOGIC-COLLISION-003:
    If multiple collisions occur in the same tick, resolution order shall be deterministic.

    4. 入力: key binding と game command を分離する

    game-thesis.md は WASD + mouse 相当と Zキー相当 の軽量マクロ指示を想定プレイヤーの操作感として記述していますが、具体キー割り当てや時間制約は下流仕様へ委譲しています。 したがって game-logic.md では Z を直接正本化するより、まず command semantics を定義すべきです。

    Input binding:
    - `InputBinding` maps platform events to semantic commands.
    
    Input command:
    - `MoveIntent`
    - `AimIntent`
    - `FireIntent`
    - `IssueAllyCommandIntent`
    - `PauseIntent`
    
    Rule:
    - DOM KeyboardEvent / PointerEvent shall not be passed into simulation systems.
    - Systems consume only normalized input command snapshots for a fixed tick.

    これにより、将来キーボード配列や gamepad 対応をしてもロジック仕様を壊さずに済みます。

    5. EARS は要求だけに使い、設計散文を EARS 化しない

    EARS は少数のキーワードと規則で自然言語 requirement の曖昧さを減らす記法ですが、文書全体のフォーマット権威ではありません。([Jama Software]6) ADR 0002 でも EARS は docs/product/ で部分採用する notation であり、Spec Kit 等の生成物ではなく docs/ SSOT が正本です。

    #287 では EARS を 6〜9 個程度に絞り、本文の State Transitions / Input / Time Model / Collision / Persistence は説明と境界にするのが適切です。

    Issue #287 に入れるべき差分

    Acceptance Criteria 追加案

    - [ ] AC4: `docs/product/game-logic.md` は `docs/dev/product-spec-lifecycle.md` の compact spec 制約に準拠する
      - 250 行以内
      - YAML frontmatter: `status`, `issue: "#287"`, `parent_issue: "#254"`, `doc_id: game-logic`, `trace_links`
      - `Non-Goals`, `Open Questions`, `Verification Notes` を含む
    
    - [ ] AC5: `docs/product/game-logic.md` の Source Hierarchy は、accepted `docs/product/game-thesis.md` を `docs/product/game-design.md` より上位に置く。`game-design.md` が `status: draft` の場合は、その扱いを `source_basis` に明示する。
    
    - [ ] AC6: 勝利条件が未確定の場合、normative `REQ-LOGIC-*` として固定せず、`Open Questions` に置く。敗北条件など確定可能なものだけを requirement 化する。
    
    - [ ] AC7: stale / nonexistent reference を追加しない
      - `docs/adr/0001-architecture-core.md` を参照しない
      - `ssot-catalog.md` を参照しない
      - registry entry id は `game-logic` とする
    
    - [ ] AC8: `docs/product/game-logic.md` は `src/` 実装変更、asset 制作、外部 physics engine 導入を要求しない。実装可能性は記述してよいが、Allowed Paths 外の変更を発生させない。

    Verification Commands 改訂案

    #287 の現行 Verification Commands は for loop や && / || を含みます。#281/#282 では baseline preflight 互換のため、atomic command と post-implementation checks を分ける運用に修正されています。 #287 も同じ型に寄せるべきです。

    # AC1
    test -f docs/product/game-logic.md
    rg -q "^## .*状態遷移" docs/product/game-logic.md
    rg -q "^## .*入力" docs/product/game-logic.md
    rg -q "^## .*時間" docs/product/game-logic.md
    rg -q "^## .*衝突" docs/product/game-logic.md
    rg -q "^## .*勝敗" docs/product/game-logic.md
    rg -q "^## .*保存境界" docs/product/game-logic.md
    
    # AC2
    rg -q "60Hz\|固定タイムステップ" docs/product/game-logic.md
    rg -q "src/state\|state" docs/product/game-logic.md
    rg -q "src/render\|render" docs/product/game-logic.md
    rg -q "Canvas.*描画専用\|状態更新.*禁止" docs/product/game-logic.md
    
    # AC4
    rg -q '^issue: "#287"' docs/product/game-logic.md
    rg -q '^parent_issue: "#254"' docs/product/game-logic.md
    rg -q '^doc_id: game-logic$' docs/product/game-logic.md
    rg -q '^trace_links:' docs/product/game-logic.md
    awk 'END { exit (NR > 250) }' docs/product/game-logic.md
    
    # AC7 expected no-match checks
    rg -n "docs/adr/0001-architecture-core.md" docs/product/game-logic.md
    rg -n "ssot-catalog" docs/product/game-logic.md docs/dev/ssot-registry.md
    
    # AC3
    rg -q "^- id: game-logic$" docs/dev/ssot-registry.md
    rg -q "^  path: docs/product/game-logic.md$" docs/dev/ssot-registry.md
    
    # quality gate
    pnpm typecheck
    pnpm lint
    pnpm test
    pnpm build

    rg -n の no-match 系は exit 1 が期待値なので、Issue 本文では “expected no match” と明記してください。PR #370 でも rg -nE の誤用が non-blocker として指摘されているため、拡張正規表現を使う場合は rg -n -e 形式に寄せるのが安全です。

    実装エージェントへ渡す改訂プロンプト

    Issue #287 を対象に docs-only PR を作成してください。
    
    ## 目的
    `docs/product/game-logic.md` を新規作成し、`docs/dev/ssot-registry.md` に `game-logic` entry を追加する。
    本書は LOOP_PROTOCOL の状態遷移、入力正規化、60Hz 固定タイムステップ、衝突、勝敗、保存境界を定義する game logic SSOT とする。
    
    ## Allowed Paths
    - `docs/product/game-logic.md`
    - `docs/dev/ssot-registry.md`
    
    ## Source Hierarchy
    1. `docs/product/requirements.md`
    2. `docs/product/game-thesis.md`(accepted。product 判断基準)
    3. `docs/adr/0001-architecture-baseline.md`
    4. `docs/adr/0002-sdd-tool-adoption.md`
    5. `docs/dev/product-spec-lifecycle.md`
    6. `docs/product/game-design.md`(status: draft のため、上位正本ではなく補助参照。必要なら `source_basis` に明記)
    
    ## 必須構成
    - YAML frontmatter:
      - `status: draft`
      - `issue: "#287"`
      - `parent_issue: "#254"`
      - `doc_id: game-logic`
      - `trace_links`
    - 250 行以内
    - 見出しは日本語可読 + 英語併記:
      - `## 目的 / Intent`
      - `## 正本階層 / Authority and Fallbacks`
      - `## 要求 / Requirements`
      - `## 状態遷移 / State Transitions`
      - `## 入力 / Input`
      - `## 時間モデル / Time Model`
      - `## 衝突 / Collision`
      - `## 勝敗 / Victory, Defeat, Draw`
      - `## 保存境界 / Persistence Boundary`
      - `## 非ゴール / Non-Goals`
      - `## 下流境界 / Downstream Boundaries`
      - `## 未解決の問い / Open Questions`
      - `## 検証 / Verification Notes`
    
    ## 仕様上の注意
    - DOM / Canvas event を simulation systems に直接渡さない。`InputCommand` 相当の semantic command snapshot に正規化する。
    - simulation は固定 1/60 秒 tick。rAF は elapsed time source であり、simulation dt ではない。
    - accumulator + panic clamp / max catch-up steps を仕様化する。
    - projectile collision は、tick 内移動距離が collision radius を超える高速 projectile に限り swept / CCD 相当を要求する。
    - 保存は `src/storage` 境界。MVP では localStorage を許容するが、小さい snapshot を stable point で保存する。将来 IndexedDB に移行しても systems から直接 storage API を呼ばない。
    - 勝利条件が未確定なら `REQ-LOGIC-*` として固定せず Open Questions に置く。敗北条件など確定可能なものだけ requirement 化する。
    - `docs/adr/0001-architecture-core.md` は存在しないため参照しない。正しくは `docs/adr/0001-architecture-baseline.md`。
    - registry id は `game-logic` とする。`spec-game-logic` にしない。
    - `ssot-catalog.md` は参照しない。
    
    ## 禁止事項
    - `src/` の変更
    - asset 作成
    - external physics engine 導入
    - `.specify/**` や `tasks.md` を正本として扱うこと
    - game-design.md の stale fallback 文言をそのまま game-logic の正本階層に流用すること

    結論

    #287 は 「作るべき Issue」ではあるが、現契約のまま実装すると product SSOT として弱いです。最優先で直すべきは、game-thesis.md accepted 後の source hierarchy、game-design.md draft / reconciliation required の扱い、compact spec AC、勝敗条件の非正本化、registry ID、atomic verification です。これを直せば、game-logic.md は後続の src/state / src/systems / src/storage 実装の参照正本としてかなり安定します。

  5. squne121 commented on May 24, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop: 完了 (2026-05-24T11:55:00Z)

    改善履歴

    • iter1: anchor comment (B1〜B4) と人間 Decision (勝敗条件) を反映
      • Machine-Readable Contract に source_basis 追加(game_thesis: accepted / game_design: draft+reconciliation_required / fallback_used 列挙)
      • In Scope を必須セクション 13 個 + YAML frontmatter (status / issue / parent_issue / doc_id: game-logic / trace_links) + 250 行 compact spec 制約に詳細化
      • Victory/Defeat/Draw Decision 反映: 敗北=HP≤0、戦闘終了 OR=120秒満了/敵拠点破壊/敵機殲滅、報酬差分。具体数値は Open Questions に退避
      • AC を AC1〜AC9 に再構成(AC4: compact spec、AC5: source hierarchy、AC6: 勝敗 Decision、AC7: stale ref 不在、AC8: Allowed Paths 厳守)
      • Verification Commands を atomic 形式に書き換え(for / && / || チェーン撤去)
      • Normative References に product-spec-lifecycle.md / game-thesis.md 追加、docs/adr/0001-architecture-baseline.md を正しい path に修正
    • iter2: review-issue 構造チェック対応
      • VC bash block の全実行コマンド行に \$ prefix 付与(C4)
      • ## Runtime Verification Applicability セクション新規追加(C9)
    • iter3: schema 準拠
      • applicability: → decision: deferred にフィールド名修正、deferred_destination を nested 形式に統一

    fact-check 結果(iter1 codebase-investigator)

    • C1 PASS: docs/product/game-design.md 存在 / status: draft
    • C2 PASS: docs/product/game-thesis.md 存在 / status: accepted
    • C3 PASS: ssot-registry id は SSOT 名そのもの(prefix なし)
    • C4 PARTIAL: lifecycle template は doc_id / trace_links を frontmatter として明文化していないが、既存 game-design.md / game-thesis.md は de-facto convention として採用済み
    • C5 PASS: docs/adr/0001-architecture-baseline.md(-core.md は存在しない誤参照)
    • C6 PASS: requirements.md MVP-003/004 は sortie timer / 勝敗条件未定義(game-logic.md で定義)
    • C8 PASS: ssot-catalog.md は削除済み(PR feat(#297): ssot-catalog.md を削除し、registry を唯一の正本とする #302)

    次アクション

    • issue-contract-review skill で go/no-go preflight
    • 承認後 implement-issue skill または impl-review-loop skill で着手

    Runtime Verification Applicability

    decision: deferred。本 Issue は仕様書作成スコープであり、状態遷移 / 衝突 / 入力 / 保存境界の動作検証は後続の src/state / src/systems / src/storage 実装 Issue で impl-review-loop 経由で実施する。

  6. squne121 commented on May 24, 2026

    @squne121
    OwnerAuthor

    Contract Snapshot (2026-05-24T12:05:00Z)

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-05-24T12:05:00Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/287
      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: 3
          vc_passed_unexpectedly: 4
          vc_unrunnable: 35
          override_note: |
            docs-only new-file 作成 Issue のため classifier 制約に該当:
            - 30 件 unknown/human_judgment: `rg -q "pattern" docs/product/game-logic.md` の exit 2 ("No such file or directory")。新規作成前 baseline では正常な不在状態。
            - 5 件 blocked (unexpected_pass): AC7 stale-ref 不在チェック (`! rg -n "stale-ref"`) の否定形が exit 0 を返すのを誤分類。
            - VC 自体は実装後に PASS する設計として妥当。
            - 人間事前承認 (no-human-approval) に基づき judgment override で go。
        ac_verifiability: pass
        product_spec_check:
          applicability: applicable
          decision: pass
          triggers:
            docs_product_allowed_paths: true
            tasks_md_mentioned: true
            specify_artifact_mentioned: true
            generated_task_mentioned: false
            product_spec_context_present: true
          conditions:
            docs_product_requires_spec_evidence: { status: pass }
            tasks_md_not_direct_source: { status: pass }
            specify_not_canonical: { status: pass }
            diff_first_rationale_present: { status: pass }
            generated_task_trace_present: { status: pass }
            task_dependencies_materialized: { status: pass }
          blocked_reasons: []
        worktree_branch_collision: clear
      next_action: implement_issue
      blocked_reasons: []
      warnings:
        - "VC preflight classifier limitation for docs-only new-file Issues; override authorized by user pre-approval"

    Contract Summary

    • Outcome: docs/product/game-logic.md を新規作成し docs/dev/ssot-registry.md に id: game-logic エントリを追加。状態遷移 / 入力 / 時間モデル / 衝突 / 勝敗 / 保存境界を 13 セクション・250 行以内・YAML frontmatter (status: draft, issue: "#287", parent_issue: "#254", doc_id: game-logic, trace_links) で記述。
    • Acceptance Criteria: AC1〜AC9(必須セクション / アーキテクチャ整合 / registry entry / compact spec / Source Hierarchy / 勝敗 Decision 反映 / stale-ref 不在 / Allowed Paths 厳守 / quality gate)
    • Allowed Paths: docs/product/game-logic.md(新規), docs/dev/ssot-registry.md(追記のみ)
    • Worktree: .claude/worktrees/issue-287-docs-product-game-logic-md-を追加する-ゲームロジ
    • Branch: worktree-issue-287-docs-product-game-logic-md-を追加する-ゲームロジ
    • Runtime Verification Applicability: decision: deferred (仕様書作成スコープ、動作検証は後続実装 Issue へ)

    Next Action

    implement-issue skill で着手可能。

  7. squne121 commented on May 24, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-05-24T12:08:28Z)

    Summary

    docs/product/game-logic.md を新規作成し、docs/dev/ssot-registry.md に game-logic エントリを追加。13 必須セクション・compact spec(209 行)・YAML frontmatter を完備。

    Results

    Verification Summary

    Command Status Details
    pnpm typecheck ✓ PASS TypeScript 型エラーなし
    pnpm lint ✓ PASS ESLint エラーなし
    pnpm test ✓ PASS 5 files, 25 tests PASS
    pnpm build ✓ PASS dist/ 生成完了

    Acceptance Criteria

    • AC1: 必須 13 セクション完備
    • AC2: アーキテクチャ原則(60Hz / accumulator / state-render 分離)を明記
    • AC3: ssot-registry に id: game-logic エントリ追加(prefix なし)
    • AC4: compact spec(209 行 / 250 行以下)・YAML frontmatter 完備
    • AC5: source hierarchy(game-thesis 上位・game-design 補助参照)を明示
    • AC6: 勝敗条件(敗北 HP0 / 終了 OR 120s/敵拠点/敵機)・数値は Open Questions 退避
    • AC7: stale reference なし(architecture-core / ssot-catalog 不在)
    • AC8: Allowed Paths 厳守(src/ / assets/ 指示なし)
    • AC9: 品質ゲート全件成功

    Next Steps

    PR レビュー(pr-review-judge)→ マージ → post-merge-cleanup


    Generated by implement-issue skill

  8. squne121 commented on May 24, 2026

    @squne121
    OwnerAuthor

    Contract Patch (2026-05-24T13:00:00Z)

    PR #376 reviewer feedback (#376 (comment)) の Blocker 2 (Product Spec Lifecycle / Workflow: 新規 SSOT 追加時の必須更新セット) に対応するため、Issue 本文を patch しました。

    変更

    • Allowed Paths: docs/dev/workflow.md を追加(SSOT Routing Table に game-logic 行を 1 件追加のみ、他編集禁止)
    • AC10: workflow.md の SSOT Routing Table に game-logic 行が追加されていることを追加
    • VC: AC10 用の検証コマンドを追加

    これにより docs/dev/product-spec-lifecycle.md / docs/dev/workflow.md の「新規 SSOT 追加時の必須更新セット」(workflow Routing Table + ssot-registry + ssot-discovery skill 説明) のうち、Routing Table と registry を同 PR で更新する状態になります。ssot-discovery skill 説明の更新は必要に応じて follow-up。

    PR #376 に対する fix_delta は impl-review-loop iteration 2 で適用します。

  9. added 2 commits that reference this issue on May 24, 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/implementationtriage-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions