Repository navigation
Closed
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#483"
goal_ref: "M2: Combat MVP Gate — SortieSystem で sortie state machine / result object を実装する"
change_kind: codeParent Issue
Parent Goal Ref
- Goal: M2: Combat MVP Gate (v0.2.x) として 1 sortie を開始→操作→戦闘結果まで通す
- Desired Destination:
src/systems/SortieSystem.tsに sortie start-end state machine を実装し、victory / defeat 時に result object を生成する
Precondition
- 実装: hitbox / collision / damage / defeat を実装する #488/feat(#488): add hitbox collision detection, damage, and defeat system #515 が main に merge 済みであること(確認済み: 2026-05-30T14:39:36Z マージ)
- 実装: enemy approach AI を fixed timestep system として実装する #487 が main に merge 済みであること(確認済み: CLOSED)
- main の
stepSimulationがrunCollisionSystem → resolveCombatCollisionsの wiring を含むこと(確認済み)
Current Validated Scope
src/systems/SortieSystem.tsが存在しないsrc/state/GameState.tsに sortie state が存在しないsrc/main.tsのstepSimulationにソーティゲート・EnemySpawnSystem/EnemyAISystem 呼び出しが未接続- hitbox / collision / damage は 実装: hitbox / collision / damage / defeat を実装する #488 で実装済み(merge 済み)
- sortie.md spec は
docs/product/features/sortie.mdに定義済み
Remaining Parent Gaps
- playtest 証跡(別 child issue)
- M3: Result Persistence(sortie result の永続化)— 別 milestone
Outcome
SortieSystem が sortie state machine を管理し、120秒経過で victory result、player HP 0 で defeat result を生成する状態で、src/main.ts の stepSimulation に SortieSystem・EnemySpawnSystem・EnemyAISystem が接続され、tests/sortie-system.test.ts が PASS し pnpm typecheck && pnpm lint && pnpm test && pnpm build が通っている。
In Scope
src/state/GameState.tsへの sortie state(SortieState型)追加src/systems/SortieSystem.ts新規作成src/systems/SimulationLoop.tsへの SortieSystem 組み込み(変更が必要な場合のみ)src/systems/index.tsへの export 追加tests/sortie-system.test.ts新規作成src/main.ts—stepSimulationへの SortieSystem ゲート・runEnemySpawnSystem・runEnemyAISystem接続、terminal 後 mutation 停止ゲート追加
Out of Scope
- result persistence(M3 スコープ)
- upgrade screen / campaign progression
- score balancing
- briefing UI
Acceptance Criteria
- AC1:
GameStateに sortie state(idle | running | victory | defeat | ended等)が追加されている - AC2: sortie timer は simulation elapsed(fixed timestep の
elapsedTicks)に基づく - AC3: 120秒到達で victory result が生成される
- AC4: player HP 0 で defeat result が生成される
- AC5: result object は
outcome,durationMs,kills,shotsFired,playerHpRemainingを含む最小 shape を持つ - AC6: result object 生成は一度だけ行われる(二重 result 防止)
- AC7: victory / defeat 後に combat systems が不要な追加 mutation を行わない
- AC8: persistence / upgrade / resource 消費は実装しない
- AC9:
tests/sortie-system.test.tsで victory・defeat・二重 result 防止・timer authority・bootstrap・defeat precedence・terminal gate・kills boundary を検証している - AC10:
pnpm typecheck && pnpm lint && pnpm test && pnpm buildが通る - AC11: victory 判定は
state.sortie.elapsedTicksのみを authority とし、state.elapsedMsを勝敗判定・SortieResult.durationMs算出に使わない - AC12: M2 bootstrap —
createInitialGameState()はsortie.status = 'idle'、src/main.ts初期化後にstartSortie(state, fixedDeltaMs)を一度だけ呼ぶ - AC13:
stepSimulationの先頭でsortie.status !== 'running'の場合、全 combat/projectile/enemy/collision 処理を skip して return する - AC14: 同一 tick で player.hp <= 0 と elapsedTicks >= targetTicks が同時に起きた場合 outcome = defeat(defeat 優先)
Required Test Cases
tests/sortie-system.test.ts に以下を含めること。
bootstrap:createInitialGameState()後にstartSortieするとstatus=running,elapsedTicks=0,result=nullno-start: idle のままrunSortieSystemしてもelapsedTicksは増えず result も生成されないvictory: 120秒相当の ticks 後にoutcome=victoryの result が生成されるdefeat:player.hp <= 0でoutcome=defeatの result が生成されるdouble-result: victory/defeat 後にrunSortieSystemを複数回呼んでも result は同一オブジェクトのままtimer-authority:SortieResult.durationMsはelapsedTicks * fixedDeltaMsと等しいdefeat-precedence: 同一 tick でplayer.hp <= 0とelapsedTicks >= targetTicksが同時ならoutcome=defeatterminal-gate: victory/defeat 後にstepSimulationを複数回呼んでもprojectiles,enemies,player,shotsFired,resultが変化しないkills-boundary:defeatedAtTick <= terminalTickの enemy のみ kills に含まれる
Verification Commands
# AC1
$ test -f src/systems/SortieSystem.ts
# AC1
$ grep -n "SortieState\|sortie" src/state/GameState.ts
# AC2
# AC3
# AC4
# AC11
# preflight-scope: pr_review_only
$ grep -n "victory\|defeat\|targetTicks\|elapsedTicks" src/systems/SortieSystem.ts
# AC5
# preflight-scope: pr_review_only
$ grep -n "outcome\|durationMs\|kills\|shotsFired\|playerHpRemaining" src/systems/SortieSystem.ts
# AC8
# preflight-scope: pr_review_only
$ grep -rn "persist\|localStorage\|upgrade" src/systems/SortieSystem.ts
# AC9
$ test -f tests/sortie-system.test.ts
# AC12
# AC13
$ grep -n "startSortie\|runSortieSystem\|runEnemySpawnSystem\|runEnemyAISystem" src/main.ts
# AC6
# AC7
# AC14
$ pnpm test
# AC10
$ pnpm typecheck
# AC10
$ pnpm lint
# AC10
$ pnpm buildAllowed Paths
src/state/GameState.tssrc/systems/SortieSystem.tssrc/systems/SimulationLoop.tssrc/systems/index.tstests/sortie-system.test.tssrc/main.ts
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Runtime Verification Applicability
runtime_verification_applicability: not_applicable
decision: not_applicable
reason: SortieSystem は純粋な状態遷移関数。Vitest ユニットテストで AC9 を決定論的に検証可能Required Skills
- TypeScript / ECS(state/systems 分離)
- Vitest BDD
- finite state machine 設計(discriminated union 推奨)
Scope Delta
src/main.tsを Allowed Paths / In Scope に追加(anchor comment blocker#1/Claude Code ガードレールを .claude に実装する #5 対応)- AC11〜AC14 を追加(timer authority・bootstrap・terminal gate・defeat precedence 明記)
- Required Test Cases セクション追加
- Precondition セクション追加(実装: hitbox / collision / damage / defeat を実装する #488/実装: enemy approach AI を fixed timestep system として実装する #487 確認済み記録)
- VC を個別コマンドに分割(compound command 除去)
- Runtime Verification Applicability セクション追加
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Activity
docs(#485): add sortie feature spec (#501)
squne121 commentedon May 30, 2026
結論: REQUEST CHANGES
#489 はそのまま実装に入ると、state machine だけは作れるが、playable sortie には接続されない可能性が高いです。主因は
src/main.tsが Allowed Paths に入っていないことです。#487 は EnemyAISystem の runtime wiring を #489/#490 側へ送っている一方、#489 の In Scope はSimulationLoop.ts変更を示すだけで、実際にstepSimulationを持っているsrc/main.tsを許可していません。([GitHub]1) ([GitHub]2)Blocking comments
1.
src/main.tsが Allowed Paths にないため、実行時に SortieSystem を接続できない現行
src/main.tsのstepSimulationはrunMovementSystem → runCombatSystem → runProjectileSystem → runCollisionSystem → tick/elapsedMs加算の流れを直接持っており、SimulationLoop.tsは accumulator を進める純関数です。つまり sortie gate、enemy spawn/AI、collision resolution、terminal 後の mutation 停止を入れる場所は実質main.ts側です。([GitHub]3)#489 の Allowed Paths は
GameState.ts,SortieSystem.ts,SimulationLoop.ts,systems/index.ts,tests/sortie-system.test.tsのみで、src/main.tsがありません。([GitHub]2)これは Stop Condition に抵触します。実装者が契約を守ると runtime wiring できず、契約を破ると Allowed Paths 違反になります。
修正要求: #489 の Allowed Paths / In Scope に以下を追加。
* src/main.ts — stepSimulation に SortieSystem / EnemySpawnSystem / EnemyAISystem / collision resolution gating を接続するまたは
stepSimulationをsrc/systems/SimulationLoop.ts配下の純関数へ移す設計変更 Issue を先に切るべきです。2. #489 は #488 完了前提だが、公開ページ上は #488/#515 がまだ Open 表示
#489 は「hitbox / collision / damage は別 child issue で実装される前提」とし、parent #483 でも #489 は #488 に依存すると定義されています。([GitHub]2) ([GitHub]4)
一方、#488 と #515 は公開ページ上では Open 表示です。#515 は damage / defeat / player contact damage / pipeline 接続を含む PR とされていますが、Open のままです。([GitHub]5) ([GitHub]6)
修正要求: #489 の着手条件に明示してください。
これが満たされない場合、#489 は
player.hp <= 0を観測するだけで、実際の damage pipeline が未接続の可能性があります。3.
GameState.elapsedMsとsortie.elapsedTicksの二重 authority が曖昧sortie.md は
elapsedTicksを唯一の timer authority とし、durationMs = elapsedTicks * fixedDeltaMsと定義しています。wall-clock、rAF、Date.now()、performance.now()は SortieResult duration や勝敗判定に使わない方針です。([GitHub]7)この方針は妥当です。固定 timestep は simulation/render 分離と決定論性のために有効で、Gaffer も fixed delta と accumulator 型 loop を推奨しています。([Gaffer On Games]8) MDN でも
requestAnimationFrameは display refresh rate に依存し、background tab では pause され得るため、勝敗 authority に使うべきではありません。([MDNウェブドキュメント]9)ただし現行
GameStateには既にelapsedMsがあり、main.tsは毎 fixed step 後にstate.elapsedMs += deltaMsしています。([GitHub]3)#489 が
sortie.elapsedTicksを追加するなら、state.elapsedMsは gameplay authority ではなく telemetry/debug であることを明記しないと、実装者がelapsedMs >= 120_000で victory 判定する余地が残ります。修正要求: AC に追加。
4.
idle → runningの起動契約が不足している#489 は state と result の生成を要求していますが、誰がいつ
START_SORTIEするのかが曖昧です。sortie.md はidle -START_SORTIE-> runningを定義していますが、UI/briefing は Out of Scope、現行 app は起動後すぐ battle loop が回る構造です。([GitHub]7) ([GitHub]3)このままだと実装者は次のどちらかを勝手に選びます。
createInitialGameState()でsortie.status = "running"にするSortieSystem.startSortie(state)をmain.ts初期化時に呼ぶidleのままにして何も進まない修正要求: #489 に M2 用の暫定起動契約を入れる。
または、M2 では初期状態を
runningにすると明記してください。曖昧なままは不可です。5. terminal 後 mutation 停止の実装責務が SortieSystem 単体では満たせない
#489 AC は「victory / defeat 後に combat systems が不要な追加 mutation を行わない」としています。([GitHub]2)
しかし SortieSystem を新規作成するだけでは、
runMovementSystem,runCombatSystem,runProjectileSystem,runEnemyAISystem,runCollisionSystem,resolveCombatCollisionsの呼び出し自体は止まりません。止めるにはstepSimulation側でsortie.status === "running"を gate する必要があります。修正要求: 実装契約に擬似コードを固定してください。
ただし tick 加算順は要注意です。#488 は
defeatedAtTick = state.tickを tick increment 前と定義しています。([GitHub]6) #489 側でも terminalTick の定義をstate.tickベースで揃える必要があります。実装品質を上げる推奨型
TypeScript では discriminated union と exhaustiveness check を使うと、存在しない状態・result 未生成状態・result 二重生成を型で潰しやすいです。TypeScript Handbook も discriminated union は state management の mutation 表現に有効で、
neverによる網羅性チェックが可能と説明しています。([TypeScript]10)推奨:
最低限、
result !== nullはvictory | defeat | endedのみ、runningではresult === nullをテストで固定すべきです。追加すべきテスト
#489 の既存 AC に加えて、以下を追加してください。
GitHub に貼る短縮レビュー
現時点の #489 は、仕様としての方向性は正しいが、実装境界が足りないという評価です。特に
src/main.tsを許可しない限り、AC の「terminal 後 mutation なし」と parent goal の「playable sortie」は満たしにくいです。squne121 commentedon May 30, 2026
Contract Snapshot (2026-05-30T15:49:00Z)
SortieSystemが sortie state machine を管理し、120秒経過で victory result、player HP 0 で defeat result を生成する状態で、src/main.tsのstepSimulationに SortieSystem・EnemySpawnSystem・EnemyAISystem が接続され、tests/sortie-system.test.tsが PASS しpnpm typecheck && pnpm lint && pnpm test && pnpm buildが通っている。src/state/GameState.ts,src/systems/SortieSystem.ts,src/systems/SimulationLoop.ts,src/systems/index.ts,tests/sortie-system.test.ts,src/main.ts.claude/worktrees/issue-489-sortie-start-end-state-machine-result-obworktree-issue-489-sortie-start-end-state-machine-result-obsqune121 commentedon May 30, 2026
implement-issue: 実装完了 (2026-05-30T15:55:36Z)
.claude/worktrees/issue-489-sortie-start-end-state-machine-result-obworktree-issue-489-sortie-start-end-state-machine-result-obfix(#489): apply fix_delta iteration 1 — clamp, freeze, kills guard, …
feat(#489): implement SortieSystem and sortie state machine (#530)