refactor(chunk): 9개 동일 code AST chunker → CodeAstV1Chunker 통합 #220

Merged
altair823 merged 2 commits from refactor/code-ast-chunker-consolidation into main 2026-06-27 00:22:08 +00:00
Owner

요약

code_{c,cpp,go,java,js,kotlin,python,rust,ts}_ast_v1.rs 9개는 struct 이름 + const VERSION_LABEL 문자열만 다른 byte-identical 복붙이었다 (chunker 는 tree-sitter 를 쓰지 않고, lang 은 struct 가 아니라 SourceSpan::Code { lang } 데이터에서 흘러나온다 — #[cfg(test)] 앞 production 본문이 언어 토큰 정규화 후 diff 완전 비어있음). 단일 CodeAstV1Chunker 로 통합한다.

ponytail-audit 의 최대 단일 절단(net −3030줄, 무손실). 코어 청킹 동작은 byte-identical — chunk_id 까지 변하지 않아 재인덱싱·임베딩 드리프트 0.

변경

  • 신규 CodeAstV1Chunker { version_label: &'static str } + for_lang(lang) 생성자. 9개 lang → 기존 VERSION_LABELverbatim 매핑 (rust→code-rust-ast-v1, typescript→code-ts-ast-v1, javascript→code-js-ast-v1, c→code-c-ast-v1 …). chunker_version() 이 라벨을 그대로 반환 → id_for_chunk(...) 의 입력 불변 → chunk_id byte-identical.
  • chunk/policy_hash/make_chunk/split_oversizecode_rust_ast_v1.rs 에서 verbatim 이식. 인라인 유닛 테스트 1세트 + 9-lang 라벨 매핑 테스트 + for_lang panic 테스트 추가.
  • 9개 src 파일 삭제, lib.rs 의 9 mod+9 pub use → 1.
  • ingest.rs 의 두 디스패치(chunker_version 스탬프 ~2700 + .chunk() ~3298)에서 9개 AST arm 을 단일 arm 으로 collapse, for_lang(code_lang) 사용.

비범위 / 가드레일

  • 비-AST chunker 무손상: K8sManifestResourceV1Chunker/DockerfileFileV1Chunker/ManifestFileV1Chunker/CodeTextParagraphV1Chunker 는 같은 arm·같은 .context() 문자열로 그대로. other => anyhow::bail! 가드도 유지.
  • chunker_version 문자열 보존이 하드 게이트 — 한 글자라도 틀리면 해당 언어 코퍼스가 조용히 재인덱싱됨. 9개 라벨 old==new 를 git history 와 대조 확인.

검증

  • byte-identical 증명: 9개 골든 스냅샷 tests/code_*_ast_snapshot.rsassertion/expected chunk text/expected chunk_id/fixture 수정 0으로 통과 — construction/import 줄만 바뀜. (스냅샷이 기대 JSON 을 fixture 에서 로드해 새 chunker 출력과 byte 대조하므로, 무수정 통과 = 출력 무드리프트.)
  • 적대적 검증 워크플로 3렌즈: byte-identical-proof(9 스냅샷 diff = construction-only) + version-string-integrity(9 라벨 old==new, typescript→code-ts-ast-v1 등 약어 케이스 포함) + completeness(9 src 삭제·비-AST 무손상·잔존 참조 0) 통과.
  • cargo test -p kebab-chunk -p kebab-app 녹색, cargo clippy -D warnings 클린. net −3030줄 (20파일 +143/−3173).

시험 항목 (Test Plan)

  • 기존 code KB 재인덱싱 시 chunk 수·chunk_id 불변 (force-reingest 로 확인).
  • 9개 언어 각각 kebab search 결과 동일.
  • kebab ingest 가 rust/python/ts/js/go/java/kotlin/c/cpp 소스를 이전과 동일하게 청킹.

Assisted-by: Claude Code

## 요약 `code_{c,cpp,go,java,js,kotlin,python,rust,ts}_ast_v1.rs` 9개는 **struct 이름 + `const VERSION_LABEL` 문자열만 다른 byte-identical 복붙**이었다 (chunker 는 tree-sitter 를 쓰지 않고, `lang` 은 struct 가 아니라 `SourceSpan::Code { lang }` 데이터에서 흘러나온다 — `#[cfg(test)]` 앞 production 본문이 언어 토큰 정규화 후 diff 완전 비어있음). 단일 `CodeAstV1Chunker` 로 통합한다. ponytail-audit 의 최대 단일 절단(net **−3030줄**, 무손실). 코어 청킹 동작은 **byte-identical** — chunk_id 까지 변하지 않아 재인덱싱·임베딩 드리프트 0. ## 변경 - 신규 `CodeAstV1Chunker { version_label: &'static str }` + `for_lang(lang)` 생성자. 9개 lang → 기존 `VERSION_LABEL` 을 **verbatim** 매핑 (`rust→code-rust-ast-v1`, `typescript→code-ts-ast-v1`, `javascript→code-js-ast-v1`, `c→code-c-ast-v1` …). `chunker_version()` 이 라벨을 그대로 반환 → `id_for_chunk(...)` 의 입력 불변 → **chunk_id byte-identical**. - `chunk`/`policy_hash`/`make_chunk`/`split_oversize` 는 `code_rust_ast_v1.rs` 에서 verbatim 이식. 인라인 유닛 테스트 1세트 + 9-lang 라벨 매핑 테스트 + `for_lang` panic 테스트 추가. - 9개 src 파일 삭제, `lib.rs` 의 9 `mod`+9 `pub use` → 1. - `ingest.rs` 의 두 디스패치(`chunker_version` 스탬프 ~2700 + `.chunk()` ~3298)에서 9개 AST arm 을 단일 arm 으로 collapse, `for_lang(code_lang)` 사용. ## 비범위 / 가드레일 - **비-AST chunker 무손상**: `K8sManifestResourceV1Chunker`/`DockerfileFileV1Chunker`/`ManifestFileV1Chunker`/`CodeTextParagraphV1Chunker` 는 같은 arm·같은 `.context()` 문자열로 그대로. `other => anyhow::bail!` 가드도 유지. - **chunker_version 문자열 보존이 하드 게이트** — 한 글자라도 틀리면 해당 언어 코퍼스가 조용히 재인덱싱됨. 9개 라벨 old==new 를 git history 와 대조 확인. ## 검증 - **byte-identical 증명**: 9개 골든 스냅샷 `tests/code_*_ast_snapshot.rs` 가 **assertion/expected chunk text/expected chunk_id/fixture 수정 0**으로 통과 — construction/import 줄만 바뀜. (스냅샷이 기대 JSON 을 fixture 에서 로드해 새 chunker 출력과 byte 대조하므로, 무수정 통과 = 출력 무드리프트.) - 적대적 검증 워크플로 3렌즈: **byte-identical-proof**(9 스냅샷 diff = construction-only) + **version-string-integrity**(9 라벨 old==new, `typescript→code-ts-ast-v1` 등 약어 케이스 포함) + **completeness**(9 src 삭제·비-AST 무손상·잔존 참조 0) 통과. - `cargo test -p kebab-chunk -p kebab-app` 녹색, `cargo clippy -D warnings` 클린. net −3030줄 (20파일 +143/−3173). ## 시험 항목 (Test Plan) - [ ] 기존 code KB 재인덱싱 시 chunk 수·chunk_id 불변 (force-reingest 로 확인). - [ ] 9개 언어 각각 `kebab search` 결과 동일. - [ ] `kebab ingest` 가 rust/python/ts/js/go/java/kotlin/c/cpp 소스를 이전과 동일하게 청킹. Assisted-by: Claude Code
altair823 added 1 commit 2026-06-26 23:59:54 +00:00
code_{c,cpp,go,java,js,kotlin,python,rust,ts}_ast_v1.rs 9개는 struct 이름과
const VERSION_LABEL 문자열만 다른 byte-identical 복붙이었다 (chunker 는
tree-sitter 를 안 쓰고 lang 은 SourceSpan::Code 데이터에서 흘러나옴). 하나로
통합:

- 신규 CodeAstV1Chunker { version_label: &'static str } + for_lang(lang) 생성자.
  9개 lang → 기존 VERSION_LABEL 문자열을 verbatim 매핑 (rust→code-rust-ast-v1,
  typescript→code-ts-ast-v1, javascript→code-js-ast-v1, ...). chunker_version()
  이 라벨을 그대로 반환 → chunk_id (id_for_chunk) byte-identical → 재인덱싱·
  버전 캐스케이드 0.
- chunk/policy_hash/make_chunk/split_oversize 는 code_rust_ast_v1.rs 에서 verbatim
  이식. 인라인 유닛 테스트 1세트 + 9-lang 라벨 매핑 테스트 추가.
- 9개 src 파일 삭제, lib.rs 9 mod+pub use → 1.
- ingest.rs 의 두 디스패치(chunker_version 스탬프 ~2700 + .chunk() ~3298)에서
  9개 AST arm 을 단일 arm 으로 collapse, for_lang(code_lang) 사용. 비-AST
  chunker(K8s/Dockerfile/Manifest/TextParagraph) arm 은 무손상.

byte-identical 증명: 9개 골든 스냅샷 테스트(tests/code_*_ast_snapshot.rs)가
assertion/expected-data 수정 0으로 통과 — construction/import 줄만 변경.
net −3030줄 (20파일 +143/−3173). 적대적 검증 3렌즈(byte-identical-proof +
version-string-integrity[9 라벨 old==new] + completeness) 통과, clippy -D warnings 클린.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Mc6W1fgsrbFKTsqA6P8La
altair823 added 1 commit 2026-06-27 00:05:24 +00:00
리뷰 nit: collapsed AST chunk arm 의 .context(format!(...)) 는 성공 경로에서도
String 을 매번 할당. .with_context(|| format!(...)) 로 에러 경로에만 alloc.
(나머지 nit — 일반화된 error-text "CodeAstV1Chunker" — 은 리뷰어가 no-action:
테스트가 새 substring 으로 맞춰져 있고 7개 arm 과 .context prefix 통일됨.)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Mc6W1fgsrbFKTsqA6P8La
claude-reviewer-01 approved these changes 2026-06-27 00:05:39 +00:00
claude-reviewer-01 left a comment
Member

회차 2 — 회차 1 의 actionable nit(.context(format!) → .with_context(|| format!), 성공 경로 alloc 회피) 반영 확인. 다른 nit(일반화된 error-text)은 의도된 통일이라 no-action.

하드 게이트 경험적 충족: 9개 골든 스냅샷이 커밋된 baseline JSON(옛 per-lang chunker 생성본)과 byte 대조해 통과(UPDATE_SNAPSHOTS 미설정 → drift 시 panic). chunker_version 라벨 9개 old==new(typescript→code-ts-ast-v1 등 약어 케이스 포함) → chunk_id 불변 → 재인덱싱 0. 비-AST chunker 무손상, panic 경로 unreachable.

clippy -D warnings 클린. 머지 동의합니다.

회차 2 — 회차 1 의 actionable nit(.context(format!) → .with_context(|| format!), 성공 경로 alloc 회피) 반영 확인. 다른 nit(일반화된 error-text)은 의도된 통일이라 no-action. 하드 게이트 경험적 충족: 9개 골든 스냅샷이 커밋된 baseline JSON(옛 per-lang chunker 생성본)과 byte 대조해 통과(UPDATE_SNAPSHOTS 미설정 → drift 시 panic). chunker_version 라벨 9개 old==new(typescript→code-ts-ast-v1 등 약어 케이스 포함) → chunk_id 불변 → 재인덱싱 0. 비-AST chunker 무손상, panic 경로 unreachable. clippy -D warnings 클린. 머지 동의합니다.
altair823 merged commit 9dc7e14434 into main 2026-06-27 00:22:08 +00:00
altair823 deleted branch refactor/code-ast-chunker-consolidation 2026-06-27 00:22:09 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: altair823-org/kebab#220