Skip to content

extract: --source-id/--date/--tag — 昇格 runbook 規約の焼き込み(#466 S1, ADR 0017) - #513

Merged
t0k0sh1 merged 4 commits into
mainfrom
466-extract-runbook-flags
Aug 9, 2026
Merged

extract: --source-id/--date/--tag — 昇格 runbook 規約の焼き込み(#466 S1, ADR 0017)#513
t0k0sh1 merged 4 commits into
mainfrom
466-extract-runbook-flags

Conversation

@t0k0sh1

@t0k0sh1 t0k0sh1 commented Aug 8, 2026

Copy link
Copy Markdown
Owner

概要

#466 S1(再評価コメントの推奨分割 1)。リハーサルで「純粋に機械的で束ねる価値が最も高い」と記録した作業 — 生成バッチの sourcesession:{agent}:{id} へ手で書き換え、datetags を手で足す — を 3 つのフラグにする。これで extract は昇格用の import-ready バッチを直接出力し、runbook step 2 の手編集が消える。

設計(ADR 0017)

  • --source-id ID: バッチヘッダの source を差し替え。単一文書は verbatim、複数文書は runbook の /{doc} 規約どおり ID/{file stem} を自動付与。stem 衝突は 2 件目をモデル呼び出し前にエラー(import の retract-then-apply は source id 単位 — 黙って畳まれる事故を先に止める)
  • --date WHEN: YYYY-MM-DD(UTC 0時)または正の epoch 秒。実在しない日付(2026-02-30)は描画方向との roundtrip 不一致で拒否。--tag TAG(繰り返し・重複畳み込み・バイト/本数 cap は早期 usage error)
  • date/tags は wire format どおり passage 行に載るため、--no-passage との併用は usage error(associations-only source はメタデータを持てない — runbook 自身の警告をそのまま強制)
  • fingerprint 非対称: 3 つとも manifest の計算入力(emitted file に焼き込まれる以上、変更は skip でなく再書き込み。serde(default) で旧 manifest は default run に一致し続ける)。ただしプロンプトに届かないので checkpoint には入れない — メタデータ変更時の書き直しは checkpoint 済みチャンク答案を再利用し、モデル呼び出しゼロ
  • env 対応なし(セッション固有値でありデプロイ設定ではない — --context/--description と同じ姿勢)

Pre-PR Mutation Gate

diff スコープ 119 mutants で CI 予算(60)超過。else 分岐の module sweep は新規モジュール想定で、本 diff は既存 6 ファイルへの分散編集のため whole-file sweep は無関係な既存 mutants を大量に含む — 規定の意図(missed をローカルで解決してから PR)に沿い、diff スコープちょうどをローカル実行した:

  • 初回: 119 → 99 caught / 3 unviable / 17 missed
  • 17 件をテスト追加で対応: tag のバイト/本数 cap と source id の name cap の境界(ちょうど= pass / 1 超過= fail、/{stem} 付与時のみ踏める run 側 cap 含む)、--date 重複、空 --tagdays_from_civil の負年 era 分岐、文言でしか区別できない usage error の統合アサーション
  • 再検証 40 件(missed 17 + 同型既 caught 23)→ 39 caught / 1 生存: parse_date の第2 ||&& は優先順位により a || (b && c) となり、範囲違反はすべて roundtrip 検査に救済されるため機能的等価と判明 → 範囲チェックを独立 early-return 3 本に分解して変異面を除去(可読性も向上)
  • 最終検証(parse_date 13 mutants)→ 13/13 caught、missed ゼロ

テスト

  • unit: フラグのパースと矛盾(6 本相当のケース)、境界値一式、parse_date の両表記と拒否形状、render の passage 行(フラグなしはバイト同一)、manifest の書き換え条件と旧エントリ後方互換、days_from_civil 逆変換
  • 統合: 焼き込み(複数文書 ID/{stem}・date/tags)、同フラグ skip、date 変更で再抽出、単一文書 verbatim、stem 衝突、suffix 付き name cap 境界、usage error の文言
  • cargo fmt / cargo clippy クリーン、全 3179 テスト通過

残り(#466)

  • S2: MCP promote tool(graph 経路、LLM なし)/ S3(必要なら): CLI text 経路プリセット — issue の再評価コメント参照

https://claude.ai/code/session_01UPjzCLVuXQmxhGkr6phPb9

Summary by CodeRabbit

  • 新機能
    • taguru extract--source-id--date、繰り返し指定可能な --tag を追加しました。
    • 指定したメタデータを出力バッチのヘッダーや passage に反映します。
    • 複数文書では文書名を付加した source ID を生成し、重複を検出します。
  • 改善
    • メタデータの変更を検知してバッチを再生成し、既存の回答を再利用します。
    • 旧形式のマニフェストとの互換性を維持しました。
  • ドキュメント
    • CLIリファレンスとメモリ昇格手順を更新しました。

t0k0sh1 added 3 commits August 9, 2026 00:14
…he batch

#466 S1 (ADR 0017): the promotion rehearsal's most mechanical step —
rewriting each emitted batch's source to session:{agent}:{id} and
hand-adding date/tags — becomes three flags. --source-id replaces the
header source (verbatim for one document, ID/{stem} across several,
collisions refused before any model call); --date (YYYY-MM-DD or epoch
seconds) and --tag ride the passage line, so --no-passage alongside
them is a usage error. All three are manifest computation inputs but
deliberately not checkpoint inputs: a metadata change rewrites the
batch while reusing every cached chunk answer, since none of them
reaches the prompt.

Claude-Session: https://claude.ai/code/session_01UPjzCLVuXQmxhGkr6phPb9
The local diff-scoped sweep (119 mutants — over CI's 60 budget, so
this run is the coverage) left 17 missed: boundary values for the tag
byte/count caps and the source-id name cap (exact-cap passes, one-over
fails, including the /{stem}-suffixed check only extract time can
trip), a duplicate --date, an empty --tag, parse_date's
malformed-shape guards, days_from_civil's negative-year era branch,
and the --source-id usage errors distinguishable only by wording.

Claude-Session: https://claude.ai/code/session_01UPjzCLVuXQmxhGkr6phPb9
…ndtrip-equivalent

The chained condition's second || survived mutation to && because
operator precedence turns the chain into a || (b && c), and every
input that distinguishes it is rescued by the round-trip guard —
an out-of-range month or day always renders as a different date.
Separate early returns leave nothing for an operator mutant to bind
to, and read better anyway.

Claude-Session: https://claude.ai/code/session_01UPjzCLVuXQmxhGkr6phPb9
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: df826f5c-cd57-4b89-8b4e-39854dc33a62

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

taguru extract--source-id--date--tag を追加しました。指定値を batch と passage に反映し、manifest の再利用判定に含めます。旧 manifest には既定値を適用します。複数文書の source ID 衝突を検証します。

Changes

extract 実行時メタデータ

Layer / File(s) Summary
CLI 引数と日付検証
src/clock.rs, src/extract/args.rs, src/extract.rs, docs/extract.html, src/extract/tests.rs
--source-id--date--tag を解析します。値の長さ、個数、重複、日付形式を検証します。--no-passage との併用を拒否します。
バッチメタデータ生成
src/extract/run.rs, src/extract/render.rs, tests/http_api/extract.rs, adr/0017-runbook-metadata-at-extract-time.md, docs/promotion.html, CHANGELOG.md
実効 source ID を生成します。複数文書ではファイル stem を付加し、衝突を拒否します。batch header と passage に source ID、日付、タグを反映します。関連する ADR、手順、変更履歴を追加します。
manifest 照合と互換性
src/extract/manifest.rs, src/extract/tests.rs
manifest の一致判定と記録に source ID、日付、タグを追加します。旧形式の manifest では既定値を使用します。メタデータ変更時の再抽出を検証します。

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI as extract CLI
  participant Run as Run
  participant Renderer as render_batch
  participant Manifest as Manifest
  CLI->>Run: source_id、date、tags
  Run->>Run: 実効 source ID を生成して衝突を検証
  Run->>Renderer: 実効 source ID、date、tags
  Renderer-->>Run: メタデータ付き batch
  Run->>Manifest: source_id、date、tags を記録
Loading

Possibly related PRs

  • t0k0sh1/taguru#468: docs/promotion.html のメモリ昇格用抽出手順を変更しており、本 PR の手順変更と直接関連します。
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed タイトルは、extract に3つのオプションを追加し、昇格用 runbook 規約を組み込む主な変更を明確に示しています。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 466-extract-runbook-flags

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/extract/args.rs`:
- Around line 519-537: Update parse_date before the days_from_civil call to
validate year against the supported YYYY-MM-DD range, such as 1..=9999, and
return None when it falls outside that range. Preserve the existing month/day
validation and civil-date conversion for valid years.

In `@src/extract/tests.rs`:
- Around line 3814-3840: In the legacy manifest test around Manifest
serialization and deserialization, validate that each of the three replace
operations for source_id, date, and tags actually removed its field before
calling serde_json::from_str. Add assertions on the transformed JSON so the test
fails when any expected legacy-field removal no longer matches, while preserving
the existing reloaded.matches validation.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5acbf3b4-1b05-4075-85d6-a66591d85938

📥 Commits

Reviewing files that changed from the base of the PR and between fb929b4 and da3a58f.

📒 Files selected for processing (12)
  • CHANGELOG.md
  • adr/0017-runbook-metadata-at-extract-time.md
  • docs/extract.html
  • docs/promotion.html
  • src/clock.rs
  • src/extract.rs
  • src/extract/args.rs
  • src/extract/manifest.rs
  • src/extract/render.rs
  • src/extract/run.rs
  • src/extract/tests.rs
  • tests/http_api/extract.rs

Comment thread src/extract/args.rs
Comment thread src/extract/tests.rs
…y-manifest strip

An i64-scale year overflowed era * 146097 inside days_from_civil
before the round-trip could refuse it — a panic on external input.
1..=9999 is the YYYY-MM-DD contract and keeps the arithmetic
in-domain. The legacy-manifest test now asserts its string replaces
actually removed the three fields, so a future field-order or serde
change cannot silently turn it into a test of nothing.

Claude-Session: https://claude.ai/code/session_01UPjzCLVuXQmxhGkr6phPb9
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