Skip to content

実装: agent_session_manifest producer output の schema validation gate (pnpm manifest:check) を追加する #378

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#242"
goal_ref: "既存 scripts/lib/agent-session-manifest-validation.mjs semantic validator と scripts/extract-agent-session-manifest-from-comment.mjs extractor を再利用した pnpm manifest:check entrypoint と CI gate を追加し、main にマージされる manifest の品質を保証する"
change_kind: code

Parent Issue

#242

Parent Goal Ref

  • Goal: agent_session_manifest producer (Issue A) の出力を schema 検証し、GitHub に載る manifest の品質を保証する
  • Desired Destination: CI pipeline に pnpm manifest:check を組み込み、invalid manifest を reject する gate

Current Validated Scope

  • pnpm manifest:check script の新規追加
  • scripts/check-agent-session-manifests.mjs の新規追加(既存 scripts/lib/agent-session-manifest-validation.mjs と scripts/extract-agent-session-manifest-from-comment.mjs を import する thin wrapper)
  • .github/workflows/ci.yml の test job への pnpm manifest:check 統合
  • marker 付き GitHub comment fixture からの extractor → validator roundtrip テスト

Remaining Parent Gaps

  • producer 本体実装 (Issue A)
  • no-push / private checkpoint verifier (Issue C)
  • Kill Switch runtime smoke (Issue D)

Outcome

既存 shared validation module (scripts/lib/agent-session-manifest-validation.mjs) と extractor (scripts/extract-agent-session-manifest-from-comment.mjs) を thin wrapper から呼ぶ pnpm manifest:check entrypoint を追加し、.github/workflows/ci.yml の test job に統合することで、main にマージされる manifest の品質を CI で保証する状態。

visibility: public_github_comment での source_kind: transcript / local_file 拒否に加え、redaction / raw transcript / local absolute path / secret-like metadata の semantic violation も fail-close する。明示 target 指定で対象 0 件のときは fail(空検査 green を禁止)。

#426 が生成する session-manifest artifact が存在する場合は validate 対象とし、無い場合も docs/schemas/examples と tests/fixtures の static 検査で常時 green を担保する。

In Scope

  • package.json への "manifest:check" script 追加
  • scripts/check-agent-session-manifests.mjs の新規追加(既存 scripts/lib/agent-session-manifest-validation.mjs と scripts/extract-agent-session-manifest-from-comment.mjs を import し、JSON manifest と marker 付き GitHub comment fixture の双方を validate する thin wrapper)
  • 既定 target: docs/schemas/examples/**/*.json, tests/fixtures/**/agent-session-manifest*.{json,md}、環境変数 or option 指定があれば追加 glob
  • 明示 target 指定時に対象 0 件なら exit 1
  • .github/workflows/ci.yml の test job 内に pnpm manifest:check を追加
  • tests/** に manifest:check entrypoint の positive/negative fixture テスト追加(marker 付き comment fixture からの extractor → validator roundtrip を含む)

Out of Scope

Acceptance Criteria

  • AC1: pnpm manifest:check が package.json に登録されている
  • AC2: scripts/check-agent-session-manifests.mjs が存在し、scripts/lib/agent-session-manifest-validation.mjs と scripts/extract-agent-session-manifest-from-comment.mjs を import している(新規 validator は実装しない)
  • AC3: valid JSON manifest fixture を渡すと exit 0
  • AC4: invalid JSON manifest fixture(必須フィールド欠落 / schema 違反)で exit 1
  • AC5: GitHub Issue / PR comment fixture(<!-- agent_session_manifest:v1 start --> / <!-- agent_session_manifest:v1 end --> marker と dynamic fence で囲まれた manifest)を extractor で抽出 → validator で validate できる。複数 marker / 欠落 marker / fence mismatch / malformed JSON は exit 1
  • AC6: visibility: public_github_comment で evidence.source_kind: transcript または local_file を含む manifest で exit 1
  • AC7: redaction.raw_transcript_included: true / visibility: public_github_comment かつ redaction.local_paths_included: true で exit 1
  • AC8: producer.command / producer.source_ref / evidence.source_ref に絶対パス(/home/, /Users/, C:\)や secret/token/api[_-]?key 様の値が混入したら exit 1
  • AC9: token_usage.availability: unavailable のとき token count フィールドが 0 ではなく null であることを要求(違反で exit 1)
  • AC10: verification.skipped_count > 0 かつ verification.overall: pass の組合せで exit 1
  • AC11: 明示 target glob 指定で対象 0 件のとき exit 1
  • AC12: validation failure 時に field / expected / actual を含む detailed error message を stderr に出力
  • AC13: .github/workflows/ci.yml の test job 内で pnpm manifest:check が呼ばれる
  • AC14: pnpm typecheck が pass する
  • AC15: pnpm lint が pass する
  • AC16: pnpm test が pass する
  • AC17: pnpm build が pass する

Verification Commands

# AC1: pnpm manifest:check が登録
$ rg -n '"manifest:check"' package.json

# AC2: thin wrapper が存在する(既存 validator/extractor module の import は PR review で確認)
$ test -f scripts/check-agent-session-manifests.mjs

# AC3: valid JSON manifest fixture が exit 0 で pass する test case が manifest:check entrypoint に存在する
$ rg -n "manifest:check.*valid fixture|valid fixture.*manifest:check" tests/

# AC4: invalid JSON manifest fixture が exit 1+ で fail する test case が manifest:check entrypoint に存在する
$ rg -n "manifest:check.*invalid schema|invalid schema.*manifest:check" tests/

# AC5: comment marker roundtrip (extractor→validator) の test case が manifest:check entrypoint に存在する
$ rg -n "manifest:check.*marker roundtrip|marker roundtrip.*manifest:check" tests/

# AC6: public_github_comment + transcript/local_file 拒否の test case が manifest:check entrypoint に存在する
$ rg -n "manifest:check.*public_github_comment|public_github_comment.*manifest:check" tests/

# AC7: redaction.raw_transcript_included / local_paths_included 違反拒否の test case が manifest:check entrypoint に存在する
$ rg -n "manifest:check.*redaction violation|redaction violation.*manifest:check" tests/

# AC8: secret / local absolute path leakage 検出の test case が manifest:check entrypoint に存在する
$ rg -n "manifest:check.*leakage|leakage.*manifest:check" tests/

# AC9: token_usage.availability=unavailable と token count null 要求の test case が manifest:check entrypoint に存在する
$ rg -n "manifest:check.*token_usage availability|token_usage availability.*manifest:check" tests/

# AC10: verification.skipped_count vs overall=pass の組合せ拒否 test case が manifest:check entrypoint に存在する
$ rg -n "manifest:check.*skipped vs pass|skipped vs pass.*manifest:check" tests/

# AC11: explicit target glob 0 件で exit 1 の test case が manifest:check entrypoint に存在する
$ rg -n "manifest:check.*empty target|empty target.*manifest:check" tests/

# AC12: detailed error message (field / expected / actual) の test case が manifest:check entrypoint に存在する
$ rg -n "manifest:check.*detailed error|detailed error.*manifest:check" tests/

# AC13: ci.yml の test job 内で manifest:check が呼ばれる
$ rg -n "manifest:check" .github/workflows/ci.yml

# AC14: typecheck (regression_gate)
$ pnpm typecheck

# AC15: lint (regression_gate)
$ pnpm lint

# AC16: test (regression_gate)
$ pnpm test

# AC17: build (regression_gate)
$ pnpm build

Allowed Paths

  • scripts/check-agent-session-manifests.mjs(新規)
  • package.json(manifest:check script 追加のみ)
  • .github/workflows/ci.yml(manifest:check 追加のみ)
  • tests/agent-session-manifest-check.test.ts(新規)
  • tests/fixtures/agent-session-manifest/**(新規 fixture)
  • scripts/validate-agent-session-manifest.mjs, scripts/extract-agent-session-manifest-from-comment.mjs, scripts/lib/agent-session-manifest-validation.mjs, docs/schemas/agent-session-manifest.schema.json(参照のみ。変更禁止)

Stop Conditions

  • Allowed Paths 外への変更が必要と判明
  • In Scope の固定契約の変更が必要
  • new Issue 起票が必要と判明
  • nested SubAgent delegation が必要
  • 外部サービス利用・権限昇格が必要
  • pnpm typecheck/lint/test/build のいずれかが fail した場合
  • 既存 validator / extractor / shared module の semantic rule を変更する必要が判明したら停止し、別 Issue へ
  • agent-session-manifest.schema.json の変更が必要と判明したら停止
  • .github/workflows/ci.yml の test job 以外(typecheck/lint/build)の job 変更が必要なら停止

Runtime Verification Applicability

decision: not_applicable
rationale: 全 AC が決定論的 script verification (rg / test -f / pnpm typecheck/lint/test/build) で成立し、外部 CLI / auth / network / fallback semantics を伴わない。意味論検証は新規 vitest テストケース内で実行され、pnpm test (AC16) regression gate に包含される。SKIP exit 77 / _*_fallback: true 経路は本 Issue のスコープに存在しない。

Related

Source

source: refinement_loop_rewrite_from_followup
origin_issue: "#326"
anchor_comment_url: "https://github.com/squne121/loop-protocol/issues/326#issuecomment-4528499380"
dedupe_key: "326-followup-B"

Required Skills

  • なし(implementation issue)

Activity

  1. added
    kind/implementation
    area/security
    area/ai-ops
    on May 24, 2026
  2. squne121 commented on May 27, 2026

    @squne121
    OwnerAuthor

    結論

    Issue #378 はそのまま実装開始すると高確率で二重実装・誤ったCI接続・偽陽性のgreen checkを作る。現状のままなら BLOCK / 要Issue再整形 が妥当です。

    #378 は「pnpm manifest:check を追加し、validator/parser を新規実装し、CIに統合する」Issueですが、関連Issue/PRの後続状態を見ると、validator・extractor・Ajv 2020-12 設定・producer semantic validation は既に #377 / PR #404 / PR #409 でかなり実装済みです。したがって #378 の実体は「新規validator実装」ではなく、既存 validator/extractor を使った manifest:check entrypoint と CI enforcement の追加に縮退させるべきです。([GitHub]1)

    BLOCKER 1: Issue本文が現在のmainとズレている

    #378 は scripts/validate-agent-session-manifest.mjs と GitHub comment parser を「新規実装」としていますが、PR #404 は既に scripts/validate-agent-session-manifest.mjs、scripts/extract-agent-session-manifest-from-comment.mjs、tests/agent-session-manifest-producer.test.ts を追加したと記録しており、mainにも validator が存在します。validator は Ajv 2020-12 と semantic validation を行うと明記されています。([GitHub]1)

    一方で、現在の package.json には dev/test/typecheck/lint/build/preview/policy:* はあるが、manifest:check はまだありません。つまり #378 の残件は **「validatorを書く」ではなく「既存validatorを包む manifest:check を定義し、CIで実行する」**です。([GitHub]2)

    BLOCKER 2: Verification Command が Vitest とCI実体に合っていない

    #378 の AC5 は pnpm test -- --testPathPattern="manifest.*comment" を指定していますが、これは Jest 由来の発想です。Vitest の公式ガイドは、ファイル名で絞る場合は filename pattern をCLI引数として渡し、テスト名で絞る場合は -t / --testNamePattern を使うと説明しています。--testPathPattern 前提のVCは不正確です。([GitHub]1)

    修正案:

    pnpm test -- tests/agent-session-manifest-producer.test.ts
    # または
    pnpm vitest run tests/agent-session-manifest-producer.test.ts -t "Fenced markdown roundtrip"

    また、#378 は .github/workflows/test.yml / .github/workflows/python-test.yml をgrep対象にしていますが、現在のworkflowは .github/workflows/ci.yml で、Node系の test job と Python系の python-test job が同一ファイル内にあります。VCは .github/workflows/ci.yml を検査対象にすべきです。([GitHub]1)

    BLOCKER 3: #402 / PR #426 と責務が衝突する

    #402 は producer を .claude/settings.json hooks と GitHub Actions artifact workflow から自動起動するIssueで、manifestを private artifact に出す設計です。PR #426 は draft 状態で、.github/workflows/session-manifest.yml、upload-artifact、stdout/comment禁止などを追加する内容です。([GitHub]3)

    #378 が独立にCIへ manifest:check を入れるだけだと、以下のどちらかになります。

    1. 生成対象がないのにpassする空検査
    2. feat(#402): wire agent_session_manifest/v1 producer to hooks and CI #426 の artifact 生成と接続せず、実運用で検証されない別物のfixture検査

    したがって #378 は #402/#426 の後続として、少なくとも以下を明記すべきです。

    - #426 の session-manifest artifact が存在する場合は全件 validate
    - 明示 glob 指定時に対象0件なら fail
    - docs/schemas/examples と tests/fixtures は常に validate
    - GitHub comment markdown fixture は extractor → validator の roundtrip で validate
    

    HIGH: schema validation だけでは security gate として弱い

    agent_session_manifest/v1 の schema docs は、visibility: public_github_comment の場合に source_kind: transcript / local_file を禁止するとしています。これは JSON Schema の if/then で機械検証される設計です。([GitHub]4)

    ただし #378 の目的は security label 付きの gate なので、JSON Schema だけでは足りません。既存 validator は producer がある場合に actor/evidence subset、producer.kind と evidence.source_kind の対応、verification semantic rule なども検査しています。#378 はこの既存 semantic validator を必ず使うべきで、単純な Ajv CLI ラッパーに戻してはいけません。([GitHub]5)

    最低限、manifest:check は次を fail-close で見るべきです。

    - public_github_comment + transcript/local_file の禁止
    - redaction.raw_transcript_included === false
    - public出力時の redaction.local_paths_included === false
    - producer.command / producer.source_ref / evidence.source_ref に token, private key, expanded env assignment, local absolute path が混入しない
    - token_usage.availability=unavailable のとき token count が 0 ではなく null
    - verification.skipped_count > 0 なのに overall=pass を禁止
    

    HIGH: comment parser の仕様は「fenced code block」ではなく marker付きcontractに寄せるべき

    #378 は「markdown fenced code block 内の manifest」を抽出するとだけ書いていますが、既存 extractor は <!-- agent_session_manifest:v1 start --> / end marker と、最低4バッククォート以上の動的fence長を前提にしています。これは単なる「最初の ```json を拾う」実装より安全です。([GitHub]6)

    #378 のAC5は次のように書き換えるべきです。

    AC5: GitHub Issue / PR comment fixture から
    <!-- agent_session_manifest:v1 start -->
    ...
    <!-- agent_session_manifest:v1 end -->
    に囲まれた manifest を extractor で一意に抽出し、validator で validate できる。
    複数 marker、欠落 marker、fence mismatch、malformed JSON は exit 1+。
    

    既存テストにも fenced markdown roundtrip はあります。#378 ではこのテストを再実装するのではなく、manifest:check entrypoint 経由で同じ保証が効くことを追加テストするべきです。([GitHub]7)

    修正後のIssueスコープ案

    #378 はこう縮めるのが安全です。

    Goal:
    既存 agent_session_manifest validator/extractor を用いて、
    pnpm manifest:check を追加し、CIで manifest contract drift / malformed public comment / unsafe manifest を reject する。
    
    In Scope:
    - package.json に "manifest:check" 追加
    - scripts/check-agent-session-manifests.mjs 追加
      - JSON manifest file validate
      - GitHub comment markdown fixture extract -> validate
      - glob scan
      - explicit target 0件は fail
      - default target: docs/schemas/examples/**, tests/fixtures/**, generated manifest artifacts if present
    - 既存 scripts/validate-agent-session-manifest.mjs と shared validation module を再利用
    - .github/workflows/ci.yml の test job に pnpm manifest:check を追加
    - tests/** に manifest:check entrypoint の positive/negative fixture test を追加
    
    Out of Scope:
    - validator/extractor の再実装
    - schema変更
    - hook wiring / artifact generation
    - required check 昇格
    - GitHub comment 投稿
    

    GitHubコメント案

    BLOCK: #378 は現在の main / 関連PR状態とズレています。
    
    #378 は validator と GitHub comment parser の新規実装をScopeにしていますが、#377 / PR #404 で `scripts/validate-agent-session-manifest.mjs` と `scripts/extract-agent-session-manifest-from-comment.mjs` は既に実装済みです。さらに #401 / PR #409 で `producer` provenance と semantic validation も入っています。
    
    このIssueでやるべきことは「validator再実装」ではなく、既存 validator/extractor を使った `pnpm manifest:check` entrypoint と CI gate 追加に限定すべきです。
    
    修正要求:
    - Scopeから `scripts/validate-agent-session-manifest.mjs` 新規実装を削除
    - `manifest:check` は既存 shared validation module を利用
    - `.github/workflows/test.yml` / `python-test.yml` ではなく、現行 `.github/workflows/ci.yml` の `test` job に統合
    - `pnpm test -- --testPathPattern=...` はVitest向けに不適切なので、`pnpm test -- tests/agent-session-manifest-producer.test.ts` 等へ修正
    - #402 / PR #426 の artifact-only producer wiring と衝突しないよう、#378 は「生成」ではなく「既存/生成済みmanifestの検証」に限定
    - explicit target/glob が0件の場合は fail させ、空検査greenを禁止
    - public_github_comment の `source_kind` 禁止だけでなく、redaction/raw transcript/local path/secret-like metadata の semantic validation も必須
    
    このままだと、二重実装・stale VC・CI上の偽greenが発生するため、Issue本文の再整形後に着手すべきです。

    最終判定: 要再整形。実装開始不可。

  3. squne121 commented on May 27, 2026

    @squne121
    OwnerAuthor

    Contract Snapshot (2026-05-27T20:59:00Z)

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: 2026-05-27T20:59:00Z
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/378
      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: 13
          vc_passed_unexpectedly: 0
          vc_unrunnable: 0
          vc_expected_pass: 4
          vc_skipped: 0
        ac_verifiability: pass
        product_spec_check:
          applicability: not_applicable
          decision: pass
          triggers:
            docs_product_allowed_paths: false
            tasks_md_mentioned: false
            specify_artifact_mentioned: false
            generated_task_mentioned: false
            product_spec_context_present: false
        worktree_branch_collision: clear
      next_action: implement_issue
      blocked_reasons: []
      warnings: []
    • Outcome: 既存 validator/extractor を thin wrapper から呼ぶ pnpm manifest:check entrypoint と CI test job 統合を追加し、main にマージされる manifest 品質を CI で保証する
    • Acceptance Criteria: AC1-AC17(pnpm script 登録 / thin wrapper 存在 / 10 種の semantic 拒否 test case / ci.yml 統合 / 4 regression gates)
    • Verification Commands: 13 baseline-fail (deterministic rg / test -f) + 4 regression_gate (pnpm typecheck/lint/test/build)
    • Allowed Paths: scripts/check-agent-session-manifests.mjs / package.json / .github/workflows/ci.yml / tests/agent-session-manifest-check.test.ts / tests/fixtures/agent-session-manifest/**
    • Worktree: .claude/worktrees/issue-378-agent-session-manifest-producer-output
    • Branch: worktree-issue-378-agent-session-manifest-producer-output
    • VC preflight: baseline fail = 13, 想定外 pass = 0, 実行不可 = 0, regression_gate pass = 4
  4. squne121 commented on May 27, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-05-27T21:12:16Z)

    • PR: feat: pnpm manifest:check entrypoint と CI gate を追加する (#378) #431
    • Worktree: .claude/worktrees/issue-378-agent-session-manifest-producer-output
    • Branch: worktree-issue-378-agent-session-manifest-producer-output
    • Verification: 17/17 PASS (13 baseline-fail VCs pass 化 + 4 regression gates)
    • 後続: PR レビュー(pr-review-judge)→ マージ → post-merge-cleanup
  5. squne121 commented on May 27, 2026

    @squne121
    OwnerAuthor

    implement-issue iter2: 修正完了 (2026-05-28T06:36:30Z)

    対応内容

    B1 (blocker): explicit target に unsupported ファイル(.txt 等)が含まれる場合 exit 1 で fail-closed。supported file が 0 件の場合も "no supported manifest files were validated" で exit 1。regression tests 2 件追加。

    B2 (blocker): PR 本文を scope-down("producer output の CI gate" → "schema/examples/fixtures の CI validation gate (pre-gate)")。follow-up Issue #434 を起票し PR 本文の Related follow-ups セクションに記載。

    NB1: --help 以外の未知 -- option を exit 2 で reject。テスト 1 件追加。

    NB3: execFileSync の maxBuffer を 10MB に明示。

    NB5: Safety Claim Matrix を canonical 5-column 形式(Claim ID / Claim / Threat Model / Mitigation / Evidence)へ書き換え。

    NB2: Out of Scope として PR 本文に Note を記載(別 Issue 化)。

    検証結果

    • pnpm typecheck: PASS
    • pnpm lint: PASS
    • pnpm test: 75/75 PASS(既存 72 + 新規 3)
    • pnpm build: PASS

    follow-up Issue

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

    area/ai-opsarea/securitykind/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions