Skip to content

実装: src/data/weapons.ts と src/data/units.ts を実体化して armament catalog を bootstrap する #1175

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "src/data/weapons.ts と src/data/units.ts の空 catalog を実体化し、後続 consumer Issue が参照可能な最小 armament seed を追加する"
change_kind: data

Parent Issue

none(単独改善)

Parent Goal Ref

  • Goal: src/data/weapons.ts と src/data/units.ts を空配列のまま放置せず、後続 consumer が参照可能な最小 catalog seed を追加する
  • Desired Destination: N/A(単独改善 Issue のため)

Current Validated Scope

  • src/data/weapons.ts の schema を id ではなく readonly definitionId に統一し、player_weapon_basic を最小 1 件追加する
  • src/data/units.ts の schema を id ではなく readonly definitionId に統一し、ally_basic を最小 1 件追加する
  • 両 catalog は src/data/enemies.ts と同じ as const satisfies readonly ...[] パターンに揃える
  • src/data/CLAUDE.md の不変条件に従い、純粋データ列挙のみとし、helper 関数や制御フローを持ち込まない
  • units.ts の ally_basic は既存 createDefaultAllyState(1) と矛盾しない archetype 値に限定する
  • weapons.ts は docs/product/features/upgrade.md と衝突しない最小 schema に留め、damage の authority を progress.weaponPower から奪わない

Remaining Parent Gaps

なし(単独改善 Issue のため)

Outcome

src/data/weapons.ts と src/data/units.ts が空 catalog ではなくなり、definitionId ベースの readonly catalog seed として後続 consumer Issue が参照可能な最小データが追加され、pnpm typecheck / pnpm lint / pnpm test / pnpm build が PASS した PR がマージされた状態。

In Scope

  • src/data/weapons.ts で WeaponDefinition を readonly definitionId ベースへ更新し、player_weapon_basic を追加する
  • src/data/units.ts で UnitDefinition を readonly definitionId ベースへ更新し、ally_basic を追加する
  • weaponDefinitions / unitDefinitions を as const satisfies readonly ...[] に変更する
  • ally_basic の radius / speed / behavior に相当する catalog 値を、既存 createDefaultAllyState(1) と矛盾しない範囲に揃える
  • WeaponDefinition は progress.weaponPower と authority conflict を起こさない最小 field に限定する

Out of Scope

  • weaponDefinitions / unitDefinitions を runtime で参照する system 側の実装
  • GameState.ts / SortieSystem.ts など Allowed Paths 外の runtime hardcode の置換
  • docs/product/features/upgrade.md の仕様変更、および upgrade apply / resource debit / persistence 連携の実装
  • progress.weaponPower と別 authority になる固定 damage schema の導入
  • バランス調整、および src/data/enemies.ts の変更

Acceptance Criteria

  • AC1: src/data/weapons.ts の WeaponDefinition が readonly definitionId: string を持つ
  • AC2: src/data/weapons.ts に definitionId: 'player_weapon_basic' を持つ readonly catalog entry があり、as const satisfies readonly WeaponDefinition[] を使っている
  • AC3: src/data/units.ts の UnitDefinition が readonly definitionId: string を持つ
  • AC4: src/data/units.ts に definitionId: 'ally_basic' を持つ readonly catalog entry があり、as const satisfies readonly UnitDefinition[] を使っている
  • AC5: ally_basic の catalog 値は既存 createDefaultAllyState(1) と矛盾しない archetype 範囲(faction: 'ally'、role: 'ally_basic'、radius: 12、speedPxPerSec: 140、initialBehaviorState: 'inactive'、defaultTargetingPolicy: 'nearest_hostile')に限定されている
  • AC6: src/data/weapons.ts の catalog schema は ownerFaction / fireCooldownMs / projectileRadius / projectileSpeedPxPerSec / projectileLifetimeMs を含む最小 readonly data shape である
  • AC7: pnpm typecheck が PASS する
  • AC8: pnpm lint が PASS する
  • AC9: pnpm test が PASS する
  • AC10: pnpm build が PASS する

Verification Commands

# AC1
$ rg -n "readonly definitionId: string" src/data/weapons.ts

# AC2
$ rg -n "definitionId: 'player_weapon_basic'" src/data/weapons.ts

# AC3
$ rg -n "readonly definitionId: string" src/data/units.ts

# AC4
$ rg -n "definitionId: 'ally_basic'" src/data/units.ts

# AC5
$ rg -F -n "faction: 'ally'" src/data/units.ts

$ rg -F -n "role: 'ally_basic'" src/data/units.ts

$ rg -F -n "radius: 12" src/data/units.ts

$ rg -F -n "speedPxPerSec: 140" src/data/units.ts

$ rg -F -n "initialBehaviorState: 'inactive'" src/data/units.ts

$ rg -F -n "defaultTargetingPolicy: 'nearest_hostile'" src/data/units.ts

# AC6
$ rg -F -n "ownerFaction: 'player'" src/data/weapons.ts

$ rg -F -n "fireCooldownMs:" src/data/weapons.ts

$ rg -F -n "projectileRadius:" src/data/weapons.ts

$ rg -F -n "projectileSpeedPxPerSec:" src/data/weapons.ts

$ rg -F -n "projectileLifetimeMs:" src/data/weapons.ts

# AC7
$ pnpm typecheck

# AC8
$ pnpm lint

# AC9
$ pnpm test

# AC10
$ pnpm build

Allowed Paths

  • src/data/weapons.ts
  • src/data/units.ts

Runtime Verification Applicability

  • decision: not_applicable
  • reason: 本 Issue は src/data 配下の静的 catalog seed 追加に限定され、runtime consumer 接続・playtest・preview 配布の動作検証は別 Issue の責務である

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • ally_basic を既存 createDefaultAllyState(1) と異なる runtime authority にしたいと判明した場合
  • WeaponDefinition に固定 damage field など progress.weaponPower と衝突する authority を導入する必要があると判明した場合

Notes for Reviewer

src/data/enemies.ts の readonly catalog pattern を参照パターンとする。ただし weapons.ts は docs/product/features/upgrade.md の target: progress.weaponPower と衝突しない最小 schema に留め、固定 damage field を導入しない。units.ts は runtime spawn schedule ではなく archetype catalog として扱い、createDefaultAllyState(1) の既存値と矛盾しない最小 seed を置く。

Required Skills

  • TypeScript

Scope Delta(任意)

N/A

Activity

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

    @squne121
    OwnerAuthor

    判定

    REQUEST_CHANGES 相当。 #1175 の目的自体は妥当です。src/data/weapons.ts と src/data/units.ts は現状 id: string だけの interface と空配列で、Issue が指摘する「catalog が実体化されていない」状態は事実です。#1175 自体にコメントはありません。

    ただし、この Issue contract は そのまま実装投入すると false green になりやすいです。特に、現在の AC は definitionId の grep だけで配列が空でも通り得ること、id と definitionId の schema 不一致、既存 runtime が weaponDefinitions / unitDefinitions を一切参照していないこと、そして #1170 / #1237 により upgrade.md が既に存在しているため #1175 の Out of Scope が古くなっていることが問題です。#1175 は weapons.ts / units.ts に最低 1 件追加し、enemies.ts の as const satisfies readonly EnemyDefinition[] パターンに倣うことを要求していますが、現在の enemies.ts は readonly definitionId と数値 field を持つ readonly catalog です。

    P0: 実装前に Issue contract を修正すべき点

    1. upgrade.md が未作成 という前提が古い

    #1175 の Out of Scope は「upgrade spec との連携(docs/product/features/upgrade.md が未作成のため)」としていますが、現在は docs/product/features/upgrade.md が存在し、doc_id: feature-upgrade、related_issue: "#1170"、parent_issue: "#1176" を持っています。さらに UpgradeDefinition schema として currency: resources / cost / target: progress.weaponPower を固定しています。

    修正案は、「upgrade spec が未作成だから連携しない」ではなく、次のようにすべきです。

    - upgrade apply pipeline / resource debit / persistence との runtime 連携は Out of Scope。
    - ただし `docs/product/features/upgrade.md` と衝突する WeaponDefinition を導入してはならない。
    - `damage` を固定値として二重定義する場合は、`progress.weaponPower` との authority conflict を明示して別 Issue 化する。

    特に ProjectileState.damage は「fire 時点の state.progress.weaponPower snapshot」として定義済みなので、#1175 で安易に WeaponDefinition.damage を追加すると、damage の正本が progress.weaponPower と weapons.ts に分裂します。

    2. id と definitionId の schema 不一致を放置している

    現状の weapons.ts / units.ts は id: string です。一方、#1175 の verification は definitionId を grep し、参照パターンである enemies.ts も readonly definitionId を使っています。

    ここは実装者判断にせず、Issue 側で明示すべきです。

    readonly definitionId: string

    さらに、export const weaponDefinitions: WeaponDefinition[] = [] のような widening する配列型指定ではなく、repo 既存 pattern と TypeScript の as const satisfies を使うべきです。TypeScript 公式 docs でも、satisfies は式の具体的な型情報を保ちながら target type への適合を検証する目的の機能です。また as const は literal widening を抑え、object property を readonly、array literal を readonly tuple にします。([typescriptlang.org]1) ([typescriptlang.org]2)

    3. AC が false green を許す

    現在の AC1 / AC2 は rg -n "definitionId" src/data/weapons.ts と src/data/units.ts です。これは interface に definitionId を追加しただけで、catalog 配列が空のままでも通ります。Issue の Outcome は「空配列でなくなること」なので、AC は literal entry を直接検証すべきです。

    最低限、以下に差し替えるべきです。

    # weapon catalog is materialized
    rg -n "definitionId: 'player_weapon_basic'" src/data/weapons.ts
    rg -n "as const satisfies readonly WeaponDefinition\\[\\]" src/data/weapons.ts
    
    # unit catalog is materialized
    rg -n "definitionId: 'ally_basic'" src/data/units.ts
    rg -n "as const satisfies readonly UnitDefinition\\[\\]" src/data/units.ts
    
    # stale `id` schema is not left behind
    ! rg -n "^\\s*readonly id:|^\\s*id:" src/data/weapons.ts src/data/units.ts
    
    # src/data invariant: no logic
    ! rg -n "\\b(if|while|for|switch)\\b|=>" src/data/weapons.ts src/data/units.ts
    
    pnpm typecheck
    pnpm lint
    pnpm test
    pnpm build

    src/data/CLAUDE.md は src/data を「ロジック禁止・純粋データ列挙のみ」「1 ファイル 1 ドメイン」と定めています。Issue の VC にこの不変条件を入れないと、後続実装で helper function や derivation logic が混入しても検出できません。

    4. 「data-driven armament を参照できる」は現状では過大表現

    検索上、weaponDefinitions は src/data/weapons.ts 以外に参照がありません。unitDefinitions も src/data/units.ts 以外に参照がありません。つまり #1175 だけでは runtime が data-driven になるわけではなく、単に future consumer 向けの catalog seed を作るだけです。

    一方、enemy 側は EnemySpawnSystem が enemyDefinitions を import し、definitionId で検索して EnemyState へ値をコピーしています。これが「data-driven catalog を runtime が消費している」実例です。weapons / units にはこの consumer がまだありません。

    したがって Outcome はこう直すべきです。

    weaponDefinitions / unitDefinitions が空配列でなくなり、後続 consumer Issue が参照可能な最小 catalog seed が存在する状態。
    runtime 参照・spawn/apply 接続は別 Issue の責務。

    5. unitDefinitions は既存 hardcoded ally と二重 SSOT になり得る

    GameState.ts には既に createDefaultAllyState(1) があり、ally_basic の role / faction / behavior / targeting / radius / speed / spawn position を hardcode しています。SortieSystem.resetCombatRuntime() は sortie 開始時に state.allies = [createDefaultAllyState(1)] を直接設定します。

    #1175 で ally_basic を別値で定義すると、即座に GameState.ts と src/data/units.ts が矛盾します。Allowed Paths が src/data/weapons.ts / src/data/units.ts のみなので、runtime 側を直すこともテストを追加することもできません。したがって #1175 では、少なくとも既存 hardcoded defaults と同じ値を catalog に写すべきです。異なる値にするなら、#1175 の Stop Condition に該当します。

    6. WeaponDefinition の damage は特に危険

    #1175 の Notes は damage / speed / radius 等の field 設計に触れていますが、damage は軽く扱うべきではありません。現在の upgrade spec は progress.weaponPower を M4 最小 target とし、purchase は validate → debit → apply → snapshot、保存成功後のみ commit、次 sortie 反映、既存 projectile への retroactive 適用なしと定義しています。

    したがって、#1175 で damage: 1 のような固定値を WeaponDefinition に入れると、後続の upgrade apply pipeline が「weapon catalog の damage を変更するのか」「progress.weaponPower を参照するのか」で割れます。

    安全な選択肢はどちらかです。

    // A: #1175 では damage を持たせない
    readonly fireCooldownMs: number
    readonly projectileRadius: number
    readonly projectileSpeedPxPerSec: number
    readonly projectileLifetimeMs: number

    または、

    // B: damage の正本が progress.weaponPower であることを data 上に明示する
    readonly damageSource: 'progress.weaponPower'

    A の方がより保守的です。B は future consumer に意図を伝えますが、data catalog に progression path string を入れる設計なので、採用するなら Issue に明記すべきです。

    推奨する最小 schema 方針

    src/data/weapons.ts

    damage を固定値にしない。fireCooldownMs は既存 player.weaponIntervalMs = 280 と整合させる。projectile speed / lifetime / radius は既存 runtime 定数があるならそれを写し、なければ #1175 で勝手に balance 決定しない。movement-projectile.md では fire_cooldown_ms は既存 weaponIntervalMs = 280 を暫定採用していますが、projectile speed / lifetime は当初 TBD とされていました。

    推奨形は次です。

    export interface WeaponDefinition {
      readonly definitionId: string
      readonly ownerFaction: 'player'
      readonly fireCooldownMs: number
      readonly projectileRadius: number
      readonly projectileSpeedPxPerSec: number
      readonly projectileLifetimeMs: number
    }
    
    export const weaponDefinitions = [
      {
        definitionId: 'player_weapon_basic',
        ownerFaction: 'player',
        fireCooldownMs: 280,
        projectileRadius: /* existing runtime value only */,
        projectileSpeedPxPerSec: /* existing runtime value only */,
        projectileLifetimeMs: /* existing runtime value only */,
      },
    ] as const satisfies readonly WeaponDefinition[]

    未確認値を新規に決める必要があるなら、それは #1175 の「バランス調整は別 Issue」に反します。

    src/data/units.ts

    units.ts は spawn schedule ではなく unit archetype catalog として扱うべきです。x / y を入れると「unit 定義」と「sortie 初期配置」が混ざります。既存 createDefaultAllyState() との互換を保つなら、spawn-independent な archetype field に限定するのが安全です。

    export interface UnitDefinition {
      readonly definitionId: string
      readonly faction: 'ally'
      readonly role: 'ally_basic'
      readonly initialBehaviorState: 'inactive'
      readonly defaultTargetingPolicy: 'nearest_hostile'
      readonly radius: number
      readonly speedPxPerSec: number
    }
    
    export const unitDefinitions = [
      {
        definitionId: 'ally_basic',
        faction: 'ally',
        role: 'ally_basic',
        initialBehaviorState: 'inactive',
        defaultTargetingPolicy: 'nearest_hostile',
        radius: 12,
        speedPxPerSec: 140,
      },
    ] as const satisfies readonly UnitDefinition[]

    これは GameState.ts の既存 createDefaultAllyState() と矛盾しません。

    配布物・Web 実装観点での注意

    #1175 単体は localStorage や preview 配布を触りません。ただし M4 の upgrade loop に接続されると、保存・preview・E2E key 分離が関係します。persistence.md は HTTP origin 前提、file:// 非保証、production / PR preview / E2E の storage key matrix、production key を preview / E2E で clear しない方針を定義済みです。

    この方針は外部仕様とも整合します。MDN は localStorage を origin ごとの保存と説明し、file: の挙動は保証されないとしています。WHATWG HTML は Web Storage について、複数 agent 間の locking は想定できず、setItem() は保存不能時に QuotaExceededError を投げ得るとしています。([MDNウェブドキュメント]3) ([html.spec.whatwg.org]4)

    また、Vite の import.meta.env は build 時に静的置換され、client に露出する env は VITE_ prefix 付きです。Vite 公式 docs は VITE_* に secret を入れないよう明記しています。#1175 で env は触らないとしても、後続の PR preview / upgrade persistence 実装で catalog ID や storage namespace を混同しないよう、VITE_LOOP_STORAGE_NAMESPACE は非秘密の build-time namespace として扱うべきです。([vitejs]5)

    UI 露出も同様です。unit / weapon catalog の definitionId を normal UI にそのまま出すべきではありません。unit-operations SSOT は DOM HUD を authoritative / focusable surface とし、Canvas は non-authoritative visual cue、raw enum / raw state は debug 限定としています。MDN も canvas 単体では描画物の semantic information を accessibility tools に露出しないため、canvas のみへ依存しない設計を求めています。 ([MDNウェブドキュメント]6)

    GitHub に貼るレビュー案

    ## Adversarial review: #1175 is valid, but not implementation-ready
    
    REQUEST_CHANGES 相当です。目的は妥当です。`src/data/weapons.ts` / `src/data/units.ts` は現状空 catalog であり、最小 seed を置く価値はあります。
    
    ただし、この Issue contract はそのまま実装投入すると false green になります。
    
    ### Blockers
    
    1. Out of Scope が stale です。
       `docs/product/features/upgrade.md` は #1170 / PR #1237 で既に作成済みです。  
       「upgrade spec 未作成のため連携しない」ではなく、「upgrade apply / resource debit / persistence 連携は Out of Scope。ただし `upgrade.md` と衝突する WeaponDefinition は導入しない」に修正してください。
    
    2. `id` と `definitionId` が矛盾しています。
       現在の `weapons.ts` / `units.ts` は `id: string` ですが、VC は `definitionId` を grep し、`enemies.ts` も `readonly definitionId` です。  
       `WeaponDefinition` / `UnitDefinition` は `readonly definitionId: string` に固定してください。
    
    3. AC1 / AC2 が弱すぎます。
       `rg "definitionId"` は interface に field を追加しただけで通ります。配列が空でも green になります。  
       `player_weapon_basic` / `ally_basic` の literal entry と `as const satisfies readonly ...[]` を検証してください。
    
    4. Runtime data-driven 化を過大主張しています。
       現状 `weaponDefinitions` / `unitDefinitions` の consumer はありません。#1175 は catalog seed を作る Issue であり、runtime 参照は別 Issue です。Outcome を修正してください。
    
    5. `ally_basic` は既存 `createDefaultAllyState()` と矛盾させないでください。
       Allowed Paths が `src/data/weapons.ts` / `src/data/units.ts` のみなので、runtime default と異なる値を入れると二重 SSOT になります。値を変えるなら Stop Condition です。
    
    6. `WeaponDefinition.damage` は安易に追加しないでください。
       現行 `ProjectileState.damage` は `state.progress.weaponPower` の fire-time snapshot であり、`upgrade.md` も `target: progress.weaponPower` を正本化しています。固定 `damage` field を追加すると damage authority が割れます。
    
    ### Required AC changes
    
    ```bash
    rg -n "definitionId: 'player_weapon_basic'" src/data/weapons.ts
    rg -n "as const satisfies readonly WeaponDefinition\\[\\]" src/data/weapons.ts
    rg -n "definitionId: 'ally_basic'" src/data/units.ts
    rg -n "as const satisfies readonly UnitDefinition\\[\\]" src/data/units.ts
    ! rg -n "^\\s*readonly id:|^\\s*id:" src/data/weapons.ts src/data/units.ts
    ! rg -n "\\b(if|while|for|switch)\\b|=>" src/data/weapons.ts src/data/units.ts
    
    pnpm typecheck
    pnpm lint
    pnpm test
    pnpm build

    Recommended direction

    • Use as const satisfies readonly ...[], matching enemies.ts.
    • Keep src/data pure data only.
    • Treat units.ts as unit archetype catalog, not spawn schedule.
    • Do not claim runtime data-driven behavior until consumer systems are implemented.
    • Keep damage authority with progress.weaponPower unless a separate schema issue explicitly changes that.
    
    ## 結論
    
    #1175 は **目的は正しいが、contract を修正してから実装すべき Issue** です。最小修正は、`definitionId` への schema 統一、`as const satisfies readonly ...[]` の強制、AC の false-green 排除、`upgrade.md` 存在後の Out of Scope 更新、そして runtime 接続を Outcome から外すことです。これを入れれば、`src/data` の catalog bootstrap としては安全に進められます。
    
  3. squne121 commented on Jul 1, 2026

    @squne121
    OwnerAuthor

    Contract Review

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_by: issue-contract-review
      generated_at: 2026-07-01T11:36:23Z
      issue_url: https://github.com/squne121/loop-protocol/issues/1175
      body_sha256: "sha256:fb0b57f41d535495c033076d05928e5a0c6563e5432cda78ec5fc1f193f781df"
      checks:
        template_compliance: pass
        state_label: pass
        allowed_paths_present: pass
        vc_present: pass
        stop_conditions_complete: pass
        vc_preflight: pass
        ac_verifiability: pass
        product_spec_check: pass
        worktree_branch_collision: pass
        next_action: implement_issue
        blocked_reasons: []
      next_action: implement_issue
      blocked_reasons: []
      warnings: []
  4. squne121 commented on Jul 1, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    Issue #1175 の anchor comment #issuecomment-4853952978 を一次ソースとして contract を更新し、deterministic review と contract review の両方で go / approve を確認しました。

    LOOP_HANDOFF_RESULT_V1:
      status: impl_ready
      routing_action: run_impl_review_loop
      contract_review:
        status: go
        gate_result: fresh_go
        latest_comment_url: https://github.com/squne121/loop-protocol/issues/1175#issuecomment-4854059231
        generated_at: 2026-07-01T11:36:23Z
        body_sha256: "sha256:fb0b57f41d535495c033076d05928e5a0c6563e5432cda78ec5fc1f193f781df"
      metadata:
        title_prefix_ready: true
        phase_label_ready: true
      auto_fixes:
        result: auto_fixed
        required:
          - kind: contract_snapshot_materialization
            executor: implementation-worker
            result: applied
            evidence:
              before: https://github.com/squne121/loop-protocol/issues/1175#issuecomment-4853952978
              after: https://github.com/squne121/loop-protocol/issues/1175
              comment_url: https://github.com/squne121/loop-protocol/issues/1175#issuecomment-4854059231
        skipped: []
      blockers: []
      permissions:
        unavailable: []
      generated_at: 2026-07-01T11:36:23Z
      checked_body_sha256: "sha256:fb0b57f41d535495c033076d05928e5a0c6563e5432cda78ec5fc1f193f781df"
      checker_exit_code: 0
      missing_sections: []
      missing_contract_keys: []
    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: issue-refinement-loop
      follow_up_issues: []
      note_only_observations: []
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions