Skip to content

実装: generate-session-manifest.mjs に secret_policy フィールド出力を追加する #500

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#242"
goal_ref: "session recording policy — producer が schema contract の secret_policy フィールドを実際に出力する"
change_kind: code

Parent Issue

#242

Parent Goal Ref

Current Validated Scope

  • scripts/generate-session-manifest.mjs に secret_policy フィールドの出力を追加する

Remaining Parent Gaps

Outcome

scripts/generate-session-manifest.mjs が生成する manifest JSON に secret_policy フィールド(value_exposed: false / boundary_enforced: true / mode: "presence_only")が含まれるよう実装され、pnpm test が PASS した状態でコミットが存在する。

boundary_enforced: true は static producer contract(「このスクリプトが生成する manifest は secret boundary 前提の contract に従う」という宣言)であり、runtime attestation(hook が実際にこのプロセス中に実行されたという証拠)ではない。

Background

PR #495(Issue #412)で docs/schemas/agent-session-manifest.schema.json に secret_policy フィールドを追加し、schema contract test で代替された。しかし producer である scripts/generate-session-manifest.mjs は #412 の Allowed Paths 外のため実際の出力には含まれていない。本 Issue はその follow-up として producer 側の実装を行う。

origin PR: #495

source: post_merge_cleanup
origin_pr: "https://github.com/squne121/loop-protocol/pull/495"
dedupe_key: "follow-up:squne121/loop-protocol:pr/495:secret-policy-producer-output"

注意: docs/schemas/agent-session-manifest.schema.json の top-level required 配列には secret_policy が含まれていない(optional フィールド)。そのため schema validation だけでは producer が secret_policy を必ず出力することを保証できない。保証は producer regression test(tests/agent-session-manifest-producer.test.ts)の明示 assertion で行う。

In Scope

  • scripts/generate-session-manifest.mjs に secret_policy フィールドの出力を追加する(固定値: value_exposed: false / boundary_enforced: true / mode: "presence_only")
    • boundary_enforced: true は static producer contract として追加する。runtime attestation ではないため、コード中にコメントで明示すること
  • tests/agent-session-manifest-producer.test.ts に secret_policy フィールドの deep-equal assertion を追加する(schema validation ではなく producer 出力 JSON の構造を直接検証する)

Out of Scope

  • docs/schemas/agent-session-manifest.schema.json の変更(feat(#412): secret boundary guard — fail-closed PreToolUse hook + deny entries + tests #495 で実施済み)
  • secret_policy フィールドの値をランタイム引数から受け取る動的化
  • 他の producer / consumer スクリプトへの同フィールド追加
  • schema の top-level required への secret_policy 追加(別 follow-up で扱う)
  • scripts/lib/agent-session-manifest-validation.mjs の修正

Acceptance Criteria

  • AC1: scripts/generate-session-manifest.mjs が出力する manifest JSON に secret_policy.value_exposed キーが存在する
  • AC2: secret_policy.value_exposed の値が false である
  • AC3: secret_policy.boundary_enforced の値が true である(static producer contract として実装されること)
  • AC4: secret_policy.mode の値が "presence_only" である
  • AC5: tests/agent-session-manifest-producer.test.ts に secret_policy の deep-equal assertion が追加されている
  • AC6: pnpm test が全件 PASS する(新規の secret_policy deep-equal assertion を含む)
  • AC7: pnpm typecheck がエラーなしで完了する

Verification Commands

# AC1
$ rg -c "secret_policy" scripts/generate-session-manifest.mjs
# AC2
$ rg -n "value_exposed" scripts/generate-session-manifest.mjs
# AC3
$ rg -n "boundary_enforced" scripts/generate-session-manifest.mjs
# AC4
$ rg -n "presence_only" scripts/generate-session-manifest.mjs
# AC5
$ rg -n "secret_policy" tests/agent-session-manifest-producer.test.ts
# AC6
$ pnpm test
# AC7
$ pnpm typecheck

Runtime Verification Applicability

decision: not_applicable
reason: "全 VC コマンド(rg / pnpm test / pnpm typecheck)は CI で実行可能。runtime-only 環境は不要。"

Allowed Paths

  • scripts/generate-session-manifest.mjs
  • tests/agent-session-manifest-producer.test.ts

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • boundary_enforced: true が「secret_boundary_guard hook が実際にこのプロセス中に実行された」ことの runtime proof として意味する必要があると判明した場合 → この Issue を停止し、hook/wrapper/CI attestation の follow-up Issue を別途起票する

Required Skills

  • Node.js / ESM (.mjs)
  • JSON Schema (agent-session-manifest.schema.json)

Scope Delta(任意)

N/A

Delivery Rule

1 Issue = 1 PR。Draft PR で開始し、AC が全件 PASS したらレビュー依頼する。

Activity

  1. added
    follow-up
    kind/implementation
    area/security
    area/ai-ops
    on May 30, 2026
  2. squne121 commented on May 31, 2026

    @squne121
    OwnerAuthor

    判定

    REQUEST_CHANGES 寄り。
    Issue #500 の問題設定自体は妥当です。現在の generate-session-manifest.mjs は manifest 本体に producer と redaction を出している一方、secret_policy を出していません。Issue #500 は、PR #495 / Issue #412 で schema 側に追加された secret_policy を producer 出力にも反映するための follow-up と整理されています。([GitHub]1)

    ただし、このまま実装すると「セキュリティ境界が実際に効いていた」という未検証の自己申告フィールドを成果物に混ぜる危険があります。 特に boundary_enforced: true は、schema 上「secret_boundary_guard PreToolUse hook がこの session 中に active だったか」を意味する説明になっていますが、単体 producer は hook 実行状態を観測していません。([GitHub]2)


    主要な敵対的レビュー

    1. boundary_enforced: true は producer 単体では実証不能

    #500 は固定値として以下を要求しています。

    {
      "secret_policy": {
        "value_exposed": false,
        "boundary_enforced": true,
        "mode": "presence_only"
      }
    }

    しかし、boundary_enforced が「実際に guard が走った」ことを表すなら、scripts/generate-session-manifest.mjs に固定値で true を入れるのは危険です。Claude Code hook は PreToolUse で exit code 2 を返すと tool call を block できますが、それは hook 実行系の事実であって、JSON producer が単独で知れる事実ではありません。([Claude Code]3)

    修正要求: #500 の contract を次のどちらかに明確化すべきです。

    • boundary_enforced: true は「この producer contract は secret boundary 前提で生成される」という静的 contract 表示であり、runtime attestation ではない。
    • runtime attestation にするなら、wrapper / hook / CI 側から「guard 実行済み」の証跡を渡す設計に変更する。ただしこれは 実装: generate-session-manifest.mjs に secret_policy フィールド出力を追加する #500 の Allowed Paths を超えるため、別 Issue 化が必要。

    現状のままでは、単に node scripts/generate-session-manifest.mjs を手元実行しても boundary_enforced: true が出るため、監査ログとしては過大主張になります。


    2. schema は secret_policy の存在を強制していない

    #500 は schema 変更を out-of-scope にしていますが、現行 schema の top-level required には secret_policy が含まれていません。また JSON Schema / Ajv では、properties に定義しただけではその property は必須にならず、必須化には required が必要です。([GitHub]2)

    さらに、secret_policy オブジェクト内にも value_exposed / boundary_enforced / mode の required が見当たりません。つまり schema contract test だけでは「producer が必ず完全な secret_policy を出す」ことを保証できません。([GitHub]2)

    修正要求: #500 の AC に、schema validation ではなく producer 出力 JSON の deep-equal regression test を明示してください。schema を強くするのは別 follow-up でもよいですが、その場合は #500 の完了条件に「schema は必須化しないため producer test で担保する」と明記すべきです。


    3. Verification が rg 中心で弱すぎる

    #500 の検証コマンドは rg "secret_policy|value_exposed|boundary_enforced|presence_only" と pnpm typecheck/test が中心です。これは「文字列がリポジトリ内に存在する」ことしか証明せず、「manifest 出力に正しい JSON として入る」ことを証明しません。([GitHub]4)

    最低限、以下のような executable verification が必要です。

    node scripts/generate-session-manifest.mjs \
      --repository squne121/loop-protocol \
      --actor test-actor \
      --phase test \
      --manifest-id asm-test \
      --recorded-at 2026-05-31T00:00:00.000Z \
      --format json \
      --validate \
    | jq -e '.secret_policy == {
      "value_exposed": false,
      "boundary_enforced": true,
      "mode": "presence_only"
    }'

    加えて、github-comment 形式を producer がサポートしているなら、コードフェンス内 JSON にも同一 field が出ることを確認すべきです。artifact-only / no public comment という #402 の安全境界と衝突しない範囲で、出力形式ごとの regression test を置くのが妥当です。([GitHub]5)


    4. 既存の semantic validator が secret_policy を見ていない

    現状、scripts/lib/agent-session-manifest-validation.mjs には secret_policy の参照が見つかりませんでした。([GitHub]6)
    #500 の Allowed Paths は scripts/generate-session-manifest.mjs と generate 関連 tests に絞られているため、validator 側で「欠落を fail する」修正はこの Issue の範囲外に見えます。([GitHub]4)

    修正要求: #500 では validator をいじらず、tests/agent-session-manifest-producer.test.ts に producer 出力の明示 assertion を足すのが安全です。tests tree には当該 producer test が存在するため、そこが最短の受け皿です。([GitHub]7)


    5. value_exposed: false は必要条件であって十分条件ではない

    Issue #412 / PR #495 は、secret value を manifest/log/artifact に出さないため、PreToolUse guard、workflow の secrets. 非参照、sentinel test、構造 assertion を要求していました。([GitHub]8)
    GitHub Actions 側でも、secret の自動 redaction は万能ではなく、変換・エンコード済み secret や stdout/stderr 経由の露出に注意が必要です。([GitHub Docs]9)

    修正要求: secret_policy.value_exposed: false を追加しても、既存の fail-closed secret detection / sentinel test / no-log 方針を弱めてはいけません。特に producer test では、secret_policy 追加により既存の redaction や secret detection の挙動が変わっていないことを確認すべきです。


    推奨する実装形

    manifest 組み立ての近くに定数を置き、typo と accidental mutation を避ける形がよいです。

    const DEFAULT_SECRET_POLICY = Object.freeze({
      value_exposed: false,
      boundary_enforced: true,
      mode: 'presence_only',
    });

    manifest には redaction の直前あたりに追加。

    secret_policy: { ...DEFAULT_SECRET_POLICY },
    redaction: {
      ...
    }

    ただし、コメントで以下を明示してください。

    // Static producer contract. This does not attest that the hook ran in this process.

    このコメントがないと、将来の reviewer が boundary_enforced を runtime evidence と誤読します。


    #500 の Issue 本文に入れるべき修正

    AC を次のように強化してください。

    1. --format json の producer 出力に secret_policy が deep-equal で存在する。
    2. --validate 付き実行で schema validation が通る。
    3. 既存 producer regression test に secret_policy assertion を追加する。
    4. github-comment 形式が JSON manifest を含むなら、その JSON にも同一 field がある。
    5. secret_policy 追加後も secret sentinel / redaction 系 test は pass する。
    6. boundary_enforced は runtime attestation ではなく static producer contract である、と Issue に明記する。

    Stop Conditions も追加すべきです。

    If boundary_enforced is required to mean runtime proof that secret_boundary_guard executed, stop this issue and split a hook/wrapper/CI attestation follow-up.


    最終評価

    #500 は「schema にある field を producer が出していない」という実装ギャップを閉じる Issue としては正しいです。
    ただし、現在の文面は 固定 JSON 追加だけで security boundary が実証されたように見える ため、そのまま merge すると監査上の意味が濁ります。

    結論としては、実装は小さいが contract の文言と test が弱い。
    PR 化するなら、boundary_enforced の意味を static contract に限定し、rg ではなく producer 出力の deep-equal test で完了判定するべきです。

  3. squne121 commented on May 31, 2026

    @squne121
    OwnerAuthor

    Contract Snapshot (2026-05-31T03:28:00Z)

    • Outcome: scripts/generate-session-manifest.mjs が生成する manifest JSON に secret_policy フィールド(value_exposed: false / boundary_enforced: true / mode: "presence_only")が含まれ、pnpm test が PASS した状態でコミットが存在する
    • Acceptance Criteria: AC1〜AC7(secret_policy フィールド存在・各値・deep-equal assertion・pnpm test PASS・pnpm typecheck PASS)
    • Verification Commands: AC1〜AC7(rg × 5 + pnpm test + pnpm typecheck)
    • Allowed Paths: scripts/generate-session-manifest.mjs, tests/agent-session-manifest-producer.test.ts
    • Worktree: .claude/worktrees/issue-500-generate-session-manifest-mjs-secret-pol
    • Branch: worktree-issue-500-generate-session-manifest-mjs-secret-pol
    • VC preflight: baseline fail expected = 5, unexpected pass = 0, blocked = 0, regression gate pass = 2, skipped = 0
    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-05-31T03:28:00Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/500
      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: 5
          vc_passed_unexpectedly: 0
          vc_unrunnable: 0
          vc_expected_pass: 2
          vc_skipped: 0
          classifications:
            - ac: AC1
              command: "rg -c \"secret_policy\" scripts/generate-session-manifest.mjs"
              exit_code: 1
              classification: expected_fail
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              evidence:
                stdout_excerpt: ""
                stderr_excerpt: ""
              decision: go
            - ac: AC2
              command: "rg -n \"value_exposed\" scripts/generate-session-manifest.mjs"
              exit_code: 1
              classification: expected_fail
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              evidence:
                stdout_excerpt: ""
                stderr_excerpt: ""
              decision: go
            - ac: AC3
              command: "rg -n \"boundary_enforced\" scripts/generate-session-manifest.mjs"
              exit_code: 1
              classification: expected_fail
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              evidence:
                stdout_excerpt: ""
                stderr_excerpt: ""
              decision: go
            - ac: AC4
              command: "rg -n \"presence_only\" scripts/generate-session-manifest.mjs"
              exit_code: 1
              classification: expected_fail
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              evidence:
                stdout_excerpt: ""
                stderr_excerpt: ""
              decision: go
            - ac: AC5
              command: "rg -n \"secret_policy\" tests/agent-session-manifest-producer.test.ts"
              exit_code: 1
              classification: expected_fail
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              evidence:
                stdout_excerpt: ""
                stderr_excerpt: ""
              decision: go
            - ac: AC6
              command: "pnpm test"
              exit_code: 0
              classification: expected_pass
              category: regression_gate
              scope_class: regression_gate
              confidence: low
              evidence:
                stdout_excerpt: "Test Files  15 passed (15), Tests  266 passed (266)"
                stderr_excerpt: ""
              decision: go
            - ac: AC7
              command: "pnpm typecheck"
              exit_code: 0
              classification: expected_pass
              category: regression_gate
              scope_class: regression_gate
              confidence: low
              evidence:
                stdout_excerpt: ""
                stderr_excerpt: ""
              decision: go
        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
          blocked_reasons: []
        worktree_branch_collision: clear
      next_action: implement_issue
      blocked_reasons: []
      warnings: []
  4. squne121 commented on May 31, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-05-31T12:32:00Z)

    IMPLEMENT_RESULT_V1:
      status: ok
      generated_at: "2026-05-31T12:32:00Z"
      generated_by: implement-issue
      issue_url: https://github.com/squne121/loop-protocol/issues/500
      pr_url: https://github.com/squne121/loop-protocol/pull/532
      worktree: .claude/worktrees/issue-500-generate-session-manifest-mjs-secret-pol
      branch: worktree-issue-500-generate-session-manifest-mjs-secret-pol
      verification:
        typecheck: pass
        lint: skip
        test:
          passed: 268
          failed: 0
          files: 15
        build: skip
      allowed_paths_compliance: true
      warnings: []
      errors: []
  5. squne121 commented on May 31, 2026

    @squne121
    OwnerAuthor

    Stop Condition 発動

    boundary_enforced: true が schema 上 "secret_boundary_guard PreToolUse hook was active during this session" という runtime attestation に読める状態のまま、static producer contract として固定値 true を出す実装をマージすることは、security telemetry の意味論的 greenwashing になるため、本 Issue を停止します。

    発動 Stop Condition

    boundary_enforced: true が「secret_boundary_guard hook が実際にこのプロセス中に実行された」ことの runtime proof として意味する必要があると判明した場合 → この Issue を停止し、hook/wrapper/CI attestation の follow-up Issue を別途起票する

    状況

    次アクション

    1. PR feat(#500): replace boundary_enforced with producer_contract + runtime_boundary in secret_policy #532 は Draft のまま維持(as-is merge しない)
    2. follow-up Issue: secret_policy.boundary_enforced の意味論再設計(runtime と static の分離)
    3. follow-up 確定後、PR feat(#500): replace boundary_enforced with producer_contract + runtime_boundary in secret_policy #532 を close または新 schema に合わせて差し替える
  6. added a commit that references this issue on May 31, 2026
  7. squne121 commented on May 31, 2026

    @squne121
    OwnerAuthor

    implement-issue: 再実装完了 (2026-05-31 — producer_contract + runtime_boundary 対応)

    前回の Stop Condition(boundary_enforced の意味論衝突)を解消。
    PR #537(#536)でスキーマが producer_contract + runtime_boundary 構造に分割されたため、worktree を main にマージして producer 出力を新スキーマに合わせた。

    IMPLEMENT_RESULT_V1:
      status: ok
      generated_at: "2026-05-31T18:24:00Z"
      generated_by: implement-issue
      issue_url: https://github.com/squne121/loop-protocol/issues/500
      pr_url: https://github.com/squne121/loop-protocol/pull/532
      worktree: .claude/worktrees/issue-500-generate-session-manifest-mjs-secret-pol
      branch: worktree-issue-500-generate-session-manifest-mjs-secret-pol
      verification:
        typecheck: pass
        lint: skip
        test:
          passed: 277
          failed: 0
          files: 15
        build: skip
      allowed_paths_compliance: true
      changes:
        - path: scripts/generate-session-manifest.mjs
          description: "Replace boundary_enforced:true with producer_contract + runtime_boundary structure"
        - path: tests/agent-session-manifest-producer.test.ts
          description: "Update AC5 deep-equal assertions to match new schema structure"
      warnings: []
      errors: []
  8. added a commit that references this issue on May 31, 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

    area/ai-opsarea/securityfollow-upkind/implementationphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions