Skip to content

実装: repo-approved local temporary workspace を tmp/ へ一本化する - #2001

Merged
squne121 merged 5 commits into
mainfrom
worktree-issue-1995-tmp-canonicalization
Aug 6, 2026
Merged

squne121 merged 5 commits into
mainfrom
worktree-issue-1995-tmp-canonicalization

Conversation

@squne121

@squne121 squne121 commented Aug 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • eslint.config.mjs の ignores に '.claude/tmp/**' / '**/.claude/tmp/**' / 'tmp/**' を追加し、未追跡 session artifact が pnpm lint の regression gate を偽陽性で fail させる再発(Issue 実装: write-set-audit-helper に origin/storageKey 境界の記録を追加する #1993 実害)を防止する
  • docs/dev/repository-folder-policy.md / AGENTS.md / docs/dev/agent-skill-boundaries.md / docs/dev/hook-boundaries.md / .claude/skills/post-merge-cleanup-executor/SKILL.md を「tmp/ が canonical write destination、.claude/tmp/ は deprecated legacy root(構造・read/scan/report・never_delete safety rule は温存)」という一貫した記述に更新する
  • tests/eslint-ignore-policy.test.ts を ESLint Node.js API(ESLint#isPathIgnored() / ESLint#lintText())による in-process 検証へ全面書き換えし、.claude/tmp/ / tmp/(root 直下・nested 両方)が ignored 判定されること、通常 source path(negative control)は ignored でなく実際に lint エラーが検出されることを runtime に確認する(実ファイル fixture 書き込み・pnpm lint 子プロセス多重起動なし。OWNER 敵対的レビュー issuecomment-5203294136 を受けた改訂)
  • production writer(bootstrap-source-bound-readiness.mjs)・schema enum(repo_temp_folder_advice_v1.schema.json)・marker(temp_residue_marker.py)・classifier(temp_residue_classifier.py)の変更は本 PR のスコープ外(Issue 実装: repo-approved local temporary workspace を tmp/ へ一本化し .claude/tmp/ を非推奨化する #1995 の OWNER 敵対的レビューで narrow 化済み)

Checks

  • pnpm typecheck(型検証・成功)
  • pnpm lint(静的解析・成功)
  • pnpm test(全テスト・成功)
  • pnpm build(ビルド・成功)

Schema Change Applicability

  • decision: not_schema_change
  • reason: 本 PR は ESLint 設定・ドキュメント記述・テストのみを変更し、producer-consumer 境界をまたぐ machine-readable schema(schemas/*.json 等)は変更しない。

Schema Consumer Inventory

N/A(not_schema_change のため)

Compatibility Decision(互換性判定)

  • change_type: N/A
  • compatibility: N/A
  • migration_required: N/A
  • migration_or_followup: N/A
  • reason: schema 変更なし

Safety Claim Matrix

Claim Implemented? Not controlled Evidence Follow-up
.claude/tmp/** / tmp/** を ESLint scan 対象外にしても、通常 source path(src/** 等)の lint 検出力は維持される yes tests/eslint-ignore-policy.test.ts の negative control ケース(ESLint#isPathIgnored() が false を返し、ESLint#lintText() が実際に lint エラーを報告することを in-process で確認) 開かれた follow-up はない
.claude/tmp/ の never_delete / report_only safety boundary(TEMP_CLEANUP_SAFETY_RULES_V1)は本 PR で変更・削除されない yes .claude/skills/post-merge-cleanup-executor/SKILL.md の TEMP_CLEANUP_SAFETY_RULES_V1.never_delete に .claude/tmp/ が引き続き含まれることを diff で確認可能(AC13) 開かれた follow-up はない
hook(root_temporary_residue_policy.py)を新たな enforcement/検出境界にはしない yes 本 PR は scripts/agent-guards/root_temporary_residue_policy.py を一切変更しない(Allowed Paths 外) 開かれた follow-up はない
.claude/tmp/session-recording/ の production writer/consumer 契約(scripts/session-recording/bootstrap-source-bound-readiness.mjs / .claude/hooks/capture_scope_rollup_final_response.py)は本 PR の変更後も active に稼働し続ける no yes 本 PR は上記 writer/consumer/docs/dev/session-recording-policy.md を一切変更しない(Allowed Paths 外・Out of Scope)。.claude/tmp/session-recording/ は canonical/deprecated 区別の対象外の明示的な legacy exception として残る Issue #2004(#2004)で tmp/ への段階的移行を扱う

Notes

eslint.config.mjs の ignores に '.claude/tmp/**' / '**/.claude/tmp/**' / 'tmp/**' を追加し、
未追跡 session artifact が pnpm lint の regression gate を偽陽性で fail させる再発を防止する。
docs/dev/repository-folder-policy.md / AGENTS.md / docs/dev/agent-skill-boundaries.md /
docs/dev/hook-boundaries.md / .claude/skills/post-merge-cleanup-executor/SKILL.md を
「tmp/ が canonical、.claude/tmp/ は deprecated legacy root(構造・never_delete は温存)」
という一貫した記述に更新し、tests/eslint-ignore-policy.test.ts に runtime 検証テストを追加する。

production writer・schema enum・marker・classifier の変更は本 Issue のスコープ外。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Preview URL

✅ verified live assets: https://squne121.github.io/loop-protocol/pr-2001/

The preview will be removed when this PR is closed.

Canonical-heading exemption リストに未登録の見出しが
per-block 日本語比率 0.056(閾値 0.1)で PR Body Japanese Check
CI を fail させていたため、見出しに日本語 gloss を追加する。
@squne121

squne121 commented Aug 6, 2026

Copy link
Copy Markdown
Owner Author

敵対的レビュー結果

判定: REQUEST_CHANGES — 現 HEAD 78786430765cb2132cb2ca6eeacb3f8767de6659 はマージ非推奨です。

ESLint の ignore 追加自体は成立しています。一方で、正本文書の自己矛盾、未追跡の production writer、破壊的かつ並列非安全なテストという P1 ブロッカーが3件あります。PR は Draft・mergeable で CI も成功していますが、これらは単発の green CI では検出できない契約・副作用上の欠陥です。

P1 — folder-policy SSOT が同一文書内で相反している

docs/dev/repository-folder-policy.md の機械可読な REPOSITORY_FOLDER_POLICY_V1 では、現在も tmp/ と .claude/tmp/ の両方が次の同格定義です。

  • folder_class: repo_approved_temporary_workspace
  • guidance: repo-approved local temporary workspace

さらに既存の「運用ルール」も、両方を「使える」と明記しています。その直後に追加された節だけが「tmp/ は canonical」「.claude/tmp/ は deprecated で新規書き込み禁止」と述べています。つまり、正本の構造化定義・既存運用規則・追加説明の三者が不一致です。Issue #1995 が完了条件にした「一貫した記述」は満たしていません。

Issue の AC6・AC7 は単に deprecated と canonical の語が存在することしか検査しないため、旧契約を残したまま追記する今回の実装でも PASS します。これは受入条件側の偽陰性です。Issue #1995 の AC/VC も再修正が必要です。

必要な修正

REPOSITORY_FOLDER_POLICY_V1 本体と既存の運用ルールを更新してください。cleanup/classifier 互換性のため folder_class を直ちに削除する必要はありませんが、少なくとも guidance を次のように分離すべきです。

- path: "tmp/"
  folder_class: repo_approved_temporary_workspace
  guidance: canonical_write_destination

- path: ".claude/tmp/"
  folder_class: repo_approved_temporary_workspace
  guidance: deprecated_legacy_read_scan_report_only_use_tmp_for_new_writes

既存の「tmp/ と .claude/tmp/ は……使える」という文章も、「新規書き込みは tmp/ のみ。.claude/tmp/ は legacy residue の read/scan/report と登録済み例外のみ」に置換する必要があります。

P1 — 「一本化」を主張しているが、production runtime は現在も書き込み・推奨している

実装上の production writer は、既定で .claude/tmp/session-recording/scope-rollup-readiness.json に書き込みます。docs/dev/session-recording-policy.md も .claude/tmp/session-recording/ を固定 private location の authority として規定しています。これは単なる古い残置物ではなく、現在の契約に束縛された能動的 writer です。

加えて runtime advisory producer は、approved_temporary_roots に両方を列挙し、実際の日本語メッセージでも「tmp/ または .claude/tmp/ を使う」と案内したままです。docs/dev/hook-boundaries.md も advisory 自体は変更しないと明記しています。したがって、文書の一部だけが deprecated と言っても、実行系は引き続き legacy root を生成・推奨します。

Issue refinement の最終コメントでは、writer migration・schema v2・advisory 改修がすべて note_only_observations に置かれ、follow_up_issues: [] です。PR の Safety Claim Matrix にも、この能動的 legacy writer は Not controlled として記録されていません。Issue #1995 を Closes すると、残件の owner と完了条件が消失します。

次のどちらかが必要です。

  1. PR/Issue の名称と Outcome を「ESLint containment と新規書き込み先の優先指定」に狭め、.claude/tmp/session-recording/ を明示的な active legacy exception として記録し、移行 Issue を実際に起票する。
  2. writer、consumer、session-recording policy、advisory/schema を versioned migration として同時変更してから「一本化」を完了扱いにする。

現状の「一本化済みだが、実行系の移行は未起票」は不整合です。

P1 — 回帰テストが既存ファイルを上書き・削除できる

tests/eslint-ignore-policy.test.ts は、次の固定パスに直接書き込みます。

.claude/tmp/__eslint_ignore_policy_fixture__/
tmp/__eslint_ignore_policy_fixture__/
src/__eslint_ignore_policy_fixture__.ts

その後 afterEach で、固定ディレクトリを rmSync(..., { recursive: true, force: true }) しています。事前存在確認、排他的作成、ownership marker、作成時 inode の照合はありません。したがって、同名ファイルを事前に置くだけで、テストが内容を上書きし、終了時に削除します。別の pnpm test、別エージェント、前回異常終了時の fixture とも衝突します。

これはリポジトリ自身が Issue #1616/source PR #1544 で要求している「exact owned session directory」「削除直前の marker・Git state・identity 再検査」「root/glob deletion 禁止」という安全モデルより弱い削除です。production executor とテストでは脅威モデルが異なりますが、開発者の実 worktree を直接変更する以上、固定パスを無条件に再帰削除してよい理由にはなりません。

さらに Vitest は既定でテストファイルを並列実行します。このリポジトリには、同じ test suite 内で repo root を cwd として pnpm exec tsc を起動するテストがあります。新規テストが壊れた src/*.ts を置いている時間帯と重なると、スケジューリング依存の typecheck failure になります。Vitest 公式も、固定の writable temporary directory のような共有資源を使うテストは並列時に flake すると明示しています。 (Vitest)

なお、この危険な形は実装者独自の逸脱ではなく、Issue #1995 の AC3〜AC5 が「repo 内に fixture を生成して子プロセスで pnpm lint」を明示要求した結果です。したがって、PR だけを直すのではなく、Issue の AC3〜AC5 を先に改訂する必要があります。

P2 — pnpm test の中から全リポジトリ lint を3回起動している

3テストがそれぞれ execFileSync('pnpm', ['lint']) を実行するため、通常の pnpm test に全リポジトリ ESLint scan が3回追加されています。これはテスト対象の規模に比例して悪化する構造的な性能劣化です。

同一 runner image の exact base/head CI artifact を1回ずつ比較すると、pnpm_test は 35,675 ms → 62,841 ms、+27,166 ms、+76.15% でした。単発比較なので P50/P95 に基づく統計的回帰判定ではありませんが、3回の全体 lint 追加と整合する強いシグナルです。
[CI runtime 比較 JSON](sandbox:/mnt/data/pr2001-runtime-comparison.json)

また execFileSync はイベントループをブロックします。Vitest 側の 120_000 timeout は同期 child process の停止保証にはならず、execFileSync 自体にも timeout が設定されていません。Windows では .cmd ファイルを execFile 系で直接起動できないため、pnpm.cmd 解決でも移植性問題があります。([Node.js]2)

P2 — 追加した nested ignore pattern が未検証

設定には **/.claude/tmp/** も追加されていますが、回帰テストが検証するのは repo root の .claude/tmp/** と tmp/** だけです。nested pattern の誤記や将来の削除を検出できません。

推奨するテスト実装

ESLint は公式 Node.js API として ESLint#isPathIgnored() と ESLint#lintText() を提供しています。lintText() に ignored な filePath を渡すと空配列になるため、実ファイル生成も child process も不要です。([ESLint]3)

import { ESLint } from 'eslint'
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'

const REPO_ROOT = fileURLToPath(new URL('..', import.meta.url))
const eslint = new ESLint({ cwd: REPO_ROOT })
const INVALID_SOURCE = 'const x = {\n'

describe('eslint ignore policy', () => {
  it.each([
    ['.claude/tmp/__fixture__/invalid.js', true],
    ['nested/.claude/tmp/__fixture__/invalid.js', true],
    ['tmp/__fixture__/invalid.js', true],
    ['src/__fixture__.ts', false],
  ] as const)(
    'GIVEN %s THEN ignored=%s',
    async (relativePath, expectedIgnored) => {
      const filePath = resolve(REPO_ROOT, relativePath)

      expect(await eslint.isPathIgnored(filePath)).toBe(expectedIgnored)

      const results = await eslint.lintText(INVALID_SOURCE, {
        filePath,
        warnIgnored: false,
      })

      if (expectedIgnored) {
        expect(results).toEqual([])
      } else {
        expect(results).toHaveLength(1)
        expect(results[0]?.errorCount).toBeGreaterThan(0)
      }
    },
  )
})

これで次を同時に満たせます。

  • worktree mutation なし
  • cleanup 不要
  • 並列安全
  • root/nested pattern の両方を検証
  • 全リポジトリ lint の三重実行を除去
  • AC12 の独立した pnpm lint により CLI integration gate は維持

ESLint 設定については、現在の「ignores だけを持つ config object」は flat config の global ignore として有効なので、ここ自体はブロッカーではありません。ただし globalIgnores() と末尾 / の directory pattern を使うと意図が明確になり、ディレクトリ traversal も明示的に除外できます。(ESLint)

マージ前の最低条件

  1. Issue 実装: repo-approved local temporary workspace を tmp/ へ一本化し .claude/tmp/ を非推奨化する #1995 の AC3〜AC5 を ESLint Node API ベースへ改訂する。
  2. REPOSITORY_FOLDER_POLICY_V1 本体と既存運用ルールを canonical/deprecated の区別に合わせて修正する。
  3. active session-recording writer と advisory/schema migration の follow-up Issue を materialize し、PR の Safety Claim Matrix に Not controlled として記載する。起票しない場合は PR/Issue の「一本化」という主張を狭める。
  4. 固定パスへの書き込み・再帰削除・execFileSync('pnpm', ['lint']) をテストから除去し、nested .claude/tmp ケースを追加する。

ESLint ignore の追加は維持してよいですが、現状の正本契約と回帰テストはマージ可能な品質ではありません。

squne121 and others added 2 commits August 6, 2026 19:36
- tests/eslint-ignore-policy.test.ts を ESLint Node.js API
  (isPathIgnored/lintText) による in-process 検証へ全面書き換え。
  実ファイル fixture の固定パス書き込み・pnpm lint 子プロセス多重起動を廃止。
- docs/dev/repository-folder-policy.md の REPOSITORY_FOLDER_POLICY_V1
  構造化定義の guidance フィールドを tmp/=canonical, .claude/tmp/=deprecated
  legacy に変更し、運用ルールのプローズを新規書き込み tmp/ 単一の
  記述へ置換。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…lization' into worktree-issue-1995-tmp-canonicalization
@squne121
squne121 marked this pull request as ready for review August 6, 2026 10:55
@squne121
squne121 merged commit e00e5f4 into main Aug 6, 2026
26 checks passed
@squne121
squne121 deleted the worktree-issue-1995-tmp-canonicalization branch August 6, 2026 10:55
squne121 added a commit that referenced this pull request Aug 7, 2026
…sion-recording/ へ同時移行する (#2008)

* feat: move session-recording source-bound eligibility/readiness private location to tmp/ (#2004)

readiness producer (bootstrap-source-bound-readiness.mjs)、eligibility
producer/loader (check_session_recording_runtime_safety.py)、readiness
consumer (capture_scope_rollup_final_response.py) の固定 private location を
.claude/tmp/session-recording/ から tmp/session-recording/(#1995/#2001 の
repo-approved local temporary workspace)へ同時移行する。旧パスは dual-read
fallback せず消費しない。env override (SCOPE_ROLLUP_ELIGIBILITY_ARTIFACT_PATH /
SCOPE_ROLLUP_READINESS_ARTIFACT_PATH) は絶対パスをそのまま使い、相対パスは
producer/consumer で共通の repo-root 基準に正規化する。親ディレクトリ mode
0700 を umask に依存せず明示的に強制する。docs/dev/session-recording-policy.md
に新パスと digest 再生成順序(policy/secret-policy digest 変更→eligibility
再生成、producer digest 変更→readiness 再生成)を明記する。

tests/session-recording/test_fixed_location_cutover.py に AC1/AC3-AC7 の
runtime 検証テストを追加し、既存の regression テスト
(.claude/hooks/tests/test_scope_rollup_capture.py、
tests/agent_ops/test_temp_residue_classifier.py、
scripts/agent-guards/tests/test_root_temporary_residue_policy.py、
tests/codex/test_root_temporary_residue_advisory.py) が継続 pass することを
確認した。

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix_delta: register new session-recording test in python-test-plan.json + add scope-rollup round-trip negative controls

PR #2008 REQUEST_CHANGES fix_delta for Issue #2004:

1. tests/session-recording/test_fixed_location_cutover.py (hyphenated dir,
   uses node subprocess for the readiness bootstrap script) was not
   registered in any CI target, so it was never actually collected/executed
   by node-backed-hook-tests or python-test-core (uncovered_changed_test_files
   gate violation). Registered it as a python-test-plan.json target
   (python-test-core job; ubuntu-latest runners ship Node preinstalled, and
   the test only needs node + uv, both already available there).

   Scope Delta: .github/ci/python-test-plan.json is outside Issue #2004's
   Allowed Paths. This is a mechanical registration of an already-Allowed-Paths
   test file into the existing python-test-plan SSOT target list (no target
   set redesign, no workflow topology change) required to satisfy the
   Runtime Verification Applicability: immediate constraint (AC1/AC3-AC8
   cannot SKIP). Verified via python_test_plan.py --emit run-argv and
   verify_python_test_lane.py that the lane invariant/topology is
   unaffected.

2. Added the In-Scope-required tests to
   .claude/hooks/tests/test_scope_rollup_capture.py: a producer-consumer
   round trip against the real (non-overridden) new default
   tmp/session-recording/ location, plus three negative controls (old
   .claude/tmp/session-recording/ path only, readiness-only, eligibility-only)
   each asserting the fixed fail-closed missing reason code
   (eligibility_missing / readiness_missing), matching the Issue's In Scope
   bullet exactly (this file's existing tests only exercised the test-harness
   override paths, never the real default-path computation).

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix_delta: harden parent-dir/TOCTOU (P1-1), fix CI lane separation (P1-2), fix cross-language override parity (P1-3), sync PR body (P1-4), hermetic E2E (P2), non-fixed test clock (P3)

OWNER 敵対的レビュー (PR #2008 head 800116e) の REQUEST_CHANGES に対応する fix_delta。

P1-1: 親ディレクトリの symlink/owner 検証を追加(prepare_private_parent_dir /
validate_private_parent_dir_readonly、Python・Node 両方)。新規作成した親のみ
chmod する。artifact 読み取りは O_NOFOLLOW fd で open+fstat+read を単一 fd に
統一し stat-then-read の TOCTOU を解消。

P1-2: tests/session-recording/test_fixed_location_cutover.py のうち Node
subprocess を起動する 8 nodeid を python-test-plan.json の deselect へ移し、
node-backed-hook-tests job の専用ステップで実行するよう ci.yml を更新。

P1-3: override path 解決を Python/Node 双方で lexical-only 正規化に統一し
(symlink 非解決、".." 拒否)、cross-language parity test を追加。Node 側に
--print-resolved-override 診断用 CLI を追加。

P2: bootstrap-source-bound-readiness.mjs に --repo-root test seam を追加し、
live repo の canonical artifact を操作しない hermetic な
producer-consumer E2E テストへ置き換え。

P3: テスト内 eligibility expiry を real wall-clock 相対値に変更。

Scope Delta 追加: scripts/ci/tests/test_python_test_plan.py の serial-lane
argv snapshot を python-test-plan.json の deselect 追加に合わせて機械的に
更新(Issue #2004 Allowed Paths へ追加済み)。

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
Co-authored-by: Test User <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

実装: repo-approved local temporary workspace を tmp/ へ一本化し .claude/tmp/ を非推奨化する

1 participant