Skip to content

feat: add batch-analysis skill for overnight headless execution - #73

Merged
etoyama merged 5 commits into
mainfrom
feat/batch-analysis-spec
Apr 3, 2026
Merged

feat: add batch-analysis skill for overnight headless execution#73
etoyama merged 5 commits into
mainfrom
feat/batch-analysis-spec

Conversation

@etoyama

@etoyama etoyama commented Apr 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • /batch-analysis スキルを追加: 夜間バッチで分析設計書をキューから取得し、marimo notebook を自動生成・実行・自己レビュー・journal 記録・summary 生成を行う
  • Skill レイヤーのみの実装(Python コード変更なし)。Extension Policy 準拠
  • 3コミット: spec 文書 → 実装 + team-review 修正 → Codex レビュー改善

主要成果物

ファイル 行数 内容
skills/batch-analysis/SKILL.md 384 スキル定義、8セルコントラクト、allowlist、セキュリティ前提
skills/batch-analysis/batch-prompt.md 902 headless オーケストレーション全体のプロンプト
tests/batch-analysis/fixtures/ 9ファイル テスト用設計書5種 + lib_dir + bad_notebook
.spec-workflow/specs/batch-analysis/ 5文書 requirements, design, test-design, tasks, investigation

設計判断 (investigation.md)

  • DD-1: セルコントラクト方式(構造固定、中身 AI 生成)
  • DD-2: marimo export session でバッチ実行
  • DD-3: next_action フィールド convention(モデル変更なし)
  • DD-4: Mid 裁量(journal 記録まで、terminal 遷移は人間)
  • DD-5: sonnet モデル(品質優先)
  • DD-6: 8セル固定 + lineage 拡張(Cell 4 にも tracked_pipe)
  • DD-7: verdict dict schema + 構造化 direction フィールド
  • DD-8: .insight/runs/YYYYMMDD_HHmmss/ ディレクトリ規約

レビュー対応

team-review (6 reviewers parallel):

  • [S-01] パッケージ allowlist 化(コマンドインジェクション対策)
  • [H-01] Self-Review ISSUE vs DOUBT 境界明確化
  • [H-02/H-03] Exit code 判定統一(session JSON cells 2,3,4,6 で判定)
  • [D-01~03] CLAUDE.md, README.md, CHANGELOG.md 更新
  • [T-02] summary.md インクリメンタル更新(budget 中断対策)
  • [S-03] プロンプトインジェクション対策(design フィールド = DATA)
  • [S-04] パス検証(プロジェクトルート外拒否)

Codex review (独立):

  • [C-1] ルールファイル凍結 → {RUN_DIR}/lessons.md に出力
  • [C-2] パッケージ allowlist(8パッケージ限定)
  • [C-3] Schema-first evidence 抽出(構造化 direction フィールド)
  • [C-4] Cell 4 lineage 拡張(session + tracked_pipe 追加)
  • [C-5] Deterministic direction 判定

Test plan

  • Integ-01~11: 全 PASS(キュー、生成、実行、journal、lib_dir、レビュー、ディレクトリ)
  • E2E-01: Exploratory 単件バッチ(8/8 検証 PASS)
  • E2E-02: Confirmatory PSM バッチ(3/3 検証 PASS)
  • E2E-03: エラースキップ(PASS)
  • E2E-04: Terminal ステータススキップ(PASS)
  • E2E-05: 混合 4 件バッチ + priority 順序(PASS)
  • E2E-06: Budget 安全終了(PASS)
  • 既存 pytest 810 tests PASS(リグレッションなし)

🤖 Generated with Claude Code

etoyama and others added 5 commits April 3, 2026 06:21
Overnight batch analysis skill specification for insight-blueprint.
Claude Code headless mode generates marimo notebooks from analysis
designs, executes them, records journal entries, and produces
morning review summaries.

Key design decisions (backed by V1-V6a investigation):
- Cell contract: 8-cell fixed structure for notebook generation
- Execution: marimo export session (JSON output)
- Queue: next_action field convention (no model changes)
- Self-review: 30min/design with graceful degradation
- Error repair: 3-attempt loop with context7 + rules update

Also adds scikit-learn and statsmodels as dev dependencies
(verified in V6a: PSM causal inference fits 8-cell contract).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Implements the batch-analysis skill (Skill-layer only, no Python code changes):
- SKILL.md (349 lines): cell contract, next_action convention, configuration
- batch-prompt.md (871 lines): full orchestration prompt for `claude -p`
- Test fixtures (9 files): design YAMLs, lib_dir utils, bad notebook

Review findings addressed:
- Package name validation (split by ` + `, regex check)
- Self-review ISSUE vs DOUBT boundary clarified
- Exit code check unified (session JSON cells 2,3,4,6 text/markdown)
- Incremental summary.md update for budget interruption resilience
- Prompt injection defense (design fields as DATA)
- Path validation for notebook_dir/lib_dir

Tested: Integ-01~11 PASS, E2E-01~06 PASS, 810 existing tests PASS.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5 improvements from independent Codex review:

C-1: Freeze runtime policy files — overnight batch writes lessons to
     {RUN_DIR}/lessons.md instead of .claude/rules/marimo-notebooks.md.
     Human promotes during morning review.

C-2: Package allowlist — methodology.package installs restricted to
     8 pre-approved packages (pandas, matplotlib, numpy, scipy, sklearn,
     statsmodels, seaborn, plotly). Blocks arbitrary uv add.

C-3: Schema-first evidence extraction — results dict now requires
     structured direction fields (hypothesis_direction, observed_direction,
     confidence_level, decision_reason). Eliminates free-text inference.

C-4: Cell 4 lineage extension — Cell 4 now receives session + tracked_pipe
     to record methodology-dependent transformations in lineage.

C-5: Deterministic direction logic — direction determined from structured
     results fields, not free-text comparison. Reduces journal noise.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codex PR review identified 3 REQUEST CHANGES:

1. Launch command: add mkdir -p before redirect to prevent
   "no such file" on first run

2. Cell 4 notebook template: update signature from
   (df_clean, pd, mo) to (df_clean, pd, session, tracked_pipe, mo)
   matching the cell contract definition

3. Spec-implementation alignment: update requirements.md, design.md,
   and test-design.md to match implementation reality:
   - next_action reset: null → {} (MCP limitation)
   - rules update: .claude/rules/ → {RUN_DIR}/lessons.md (policy freeze)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codex skill best-practices review findings:

- Frontmatter: move version to metadata map (agentskills.io spec)
- Description: add explicit trigger phrases (バッチ実行して, run overnight
  batch, etc.) to combat under-triggering
- Add argument-hint: [design_id | --all]
- Move batch-prompt.md to references/ (progressive disclosure Level 3)
- Add Key Files table to SKILL.md documenting references/ structure

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@etoyama
etoyama merged commit 40ad85b into main Apr 3, 2026
5 checks passed
@etoyama
etoyama deleted the feat/batch-analysis-spec branch April 3, 2026 02:37
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.

1 participant