Skip to content

refactor(adapters): split kiro.ts into cohesive leaf modules - #4493

Merged
lidge-jun merged 9 commits into
devfrom
codex/260913-split-kiro
Sep 13, 2026
Merged

lidge-jun merged 9 commits into
devfrom
codex/260913-split-kiro

Conversation

@lidge-jun

Copy link
Copy Markdown
Owner

Summary

src/adapters/kiro.ts was 2319 lines mixing wire identity, token estimation, reasoning and thinking control, conversation-state validation, payload assembly, and the streaming event parser. This splits it into seven leaves under src/adapters/kiro/ and leaves the original path as an 8-line facade re-exporting all seven previously exported names, so no consumer and no test is edited.

The file has no module-level mutable state, so there is nothing to fork: every Map and Set in it is function-local and moved with its enclosing function. The leaf graph is acyclic — wire and reasoning are sinks, feeding usage and conversation, then payload and stream, then adapter.

stream.ts is 1153 lines, above the size the rest of the split targets. parseKiroAttemptEvents alone is roughly 730 lines of one stateful eventstream loop sharing about twenty closure locals; splitting it would mean parameterizing that state, which is a rewrite rather than a move, so it stays whole.

Third and final PR of the stack, on top of the service.ts split. This is the stack tip, so CI runs here and its tree contains all three splits.

Verification

  • Local product suite, typecheck, and build were NOT RUN by operator instruction. Hosted CI on this head is the proof for the whole stack.
  • Export parity checked mechanically: 7 exported by the original including the parseKiroStream generator, 7 re-exported by the facade, none missing and none added.
  • All 65 baseline top-level declarations resolve to exactly one leaf; comment-normalized body comparison shows zero differing bodies.
  • No duplicate declaration across the leaf set, no leaf imports the facade, no src/lab/ import, no relative specifier left unresolvable.
  • Adversarial static review of this lane returned no BLOCKER and no RISK findings.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Pure-move split of src/storage/cleanup.ts (3141 lines) into src/storage/cleanup/ leaves: types, paths, db, satellite, pending, reconcile, staging, preview, execute, restore. The original file remains a facade re-exporting every public name. No behavior change; no consumer edits.
Pure-move split of src/service.ts (5558 lines) into src/service/ leaves: state (paths/install-state), guards (ownership/auth/manager-command), health (port resolution + serving checks), launchd, systemd, windows-scheduler (schtasks + elevation finalize), windows-taskxml (task XML build/verify), windows-ops (Windows install/stop/uninstall + stage tracking), repair, orchestration (install/uninstall/stop dispatch), diagnostics, cli (arg parsing/dispatch). src/service.ts is now a facade re-exporting every original export. One semantic-preserving adjustment: import.meta.dir at the old file depth is carried by serviceSourceDir in state.ts.
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner September 13, 2026 07:56
@github-actions github-actions Bot added the chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature). label Sep 13, 2026
@coderabbitai

coderabbitai Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (2)
  • ^dev$
  • ^preview$

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: ASSERTIVE

Plan: Advanced

Run ID: a63ba6df-9741-4b88-9e55-d7486386d24d

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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions github-actions Bot added the intake: hygiene-blocked Deterministic PR hygiene checks failed label Sep 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Deterministic hygiene checks failed.

  • missing_regression_test — Behavior changed under src/ or gui/src/ without a test change. Add focused coverage or obtain test-exception-approved.

@github-actions

github-actions Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ READY

  • all PR quality gates passed.

Hygiene

✅ Deterministic PR hygiene checks passed.

@lidge-jun

Copy link
Copy Markdown
Owner Author

test-exception-approved applied — rationale

This PR is a pure-move refactor with zero behavior change: the original file stays as a facade re-exporting every name it exported before, so no consumer and no test is edited. The hygiene gate counts any non-comment change under src/ as a behavior change, which is correct as a default and does not fit a relocation.

Adding a new focused test here would be the wrong artifact. The oracle for a pure move is the existing suite for the moved subsystem, unchanged, which is exactly what proves the relocation preserved behavior. Those suites run on the stack tip (#4493).

Fidelity was verified statically instead, and the checks found real defects rather than rubber-stamping: every baseline top-level declaration resolves to exactly one leaf with a comment-normalized identical body, the facade's export set matches the baseline exactly, every module-level mutable binding and test hook has a single declaration site, and every relative import specifier resolves. Local product suite, typecheck, and build were NOT RUN by operator instruction.

@lidge-jun lidge-jun added the test-exception-approved Maintainer approved a non-automated regression-test exception label Sep 13, 2026
@lidge-jun

Copy link
Copy Markdown
Owner Author

리뷰 · 우선순위 62 / 80

설명
이 PR은 god-file round 1의 마지막 장이고, 스택 tip입니다. 지금 dev의 src/adapters/kiro.ts는 약 2319줄에 와이어 식별, 토큰 추정, reasoning/thinking 제어, conversation-state 검증, payload 조립, 스트리밍 이벤트 파서가 섞여 있습니다. 이 변경은 src/adapters/kiro/ 아래 일곱 leaf(wire, reasoning, usage, conversation, payload, stream, adapter)로 옮기고, 원래 src/adapters/kiro.ts는 예전에 내보내던 일곱 이름을 그대로 다시보내는 facade(약 8줄)로 남깁니다.

모듈 수준 mutable 상태가 없어서 싱글톤 포크 위험이 cleanup/service보다 낮습니다. Map/Set은 함수 안 지역 값이라 함수와 함께 이동합니다. leaf 그래프도 한 방향(wire/reasoning → usage/conversation → payload/stream → adapter)입니다. stream.ts는 약 1153줄로 여전히 큽니다. parseKiroAttemptEvents 하나가 대략 730줄짜리 상태 루프라서, 지금 더 쪼개면 "이동"이 아니라 "상태 매개변수화 리라이트"가 됩니다. round 1 계약(순수 이동)을 지키려면 여기까지가 맞습니다.

이 브랜치는 #4492(codex/260913-split-service) 위에 쌓여 있고, tip이라서 호스트 CI가 여기서 돕니다. 트리에는 cleanup+service+kiro 세 분할이 모두 들어 있습니다. 로컬 스위트/typecheck/build는 운영자 지시로 안 돌렸고, hygiene은 스택 공통으로 missing_regression_test(intake: hygiene-blocked)입니다. structure 쪽은 adapters 영역이 이미 문서화되어 있어서 cleanup처럼 새 top-level 문서는 필요 없다고 본문에 적혀 있습니다.

우선순위 62는 tip으로서 CI 증명 역할은 크지만, 내용 자체는 세 장 중 가장 기계적이고 사용자 버그 수정이 아니기 때문입니다. 다만 Kiro 어댑터는 트래픽이 있는 경로라, facade 재수출이 빠지거나 stream leaf import가 깨지면 로그인 다음 단계에서 바로 터집니다. package 2.53.0, types/config 분할과 무관합니다. 참고로 같은 시각의 Kiro 계정 붕괴 수정 #4482는 oauth 쪽(src/oauth/kiro.ts)이라 이 어댑터 분할과 파일이 겹치지 않습니다.

src/adapters/kiro.ts facade - 일곱 공개 이름 재수출. 소비자 경로 유지.

src/adapters/kiro/stream.ts - 1153줄. round 1에서는 의도적 미분할. 다음 round 후보.

src/adapters/kiro/adapter.ts / payload.ts - createKiroAdapter·buildKiroPayload 경로. import 깊이 오류 시 런타임 실패.

심볼 스택 tip CI - 세 분할이 한 트리에서 같이 검증되는지 여기가 게이트.

심볼 hygiene missing_regression_test - #4491/#4492와 동일. tip에서만 풀어도 스택 전체가 막힐 수 있음.

메인테이너의 판단이 필요한 지점

  • stream.ts 1153줄을 round 1 종료 조건으로 받아들일지, tip 머지 전에 추가 분할을 요구할지.
  • tip CI 초록 후 머지 순서(4491→4492→4493, 매 단계 rebase)를 그대로 갈지.
  • hygiene을 tip에만 테스트 추가로 풀지, 세 PR 모두에 같은 스모크를 넣을지.

너의 추천
tip CI가 초록이면 4491→4492→4493 순으로 머지하세요. stream.ts는 round 1에서 남기고, 다음 god-file round 메모에만 적어두세요. hygiene은 세 PR에 공통인 작은 export-parity 스모크로 푸는 편이 덜 아픕니다.

이 댓글은 grok-bot이 작성했습니다

@github-actions
github-actions Bot marked this pull request as ready for review September 13, 2026 07:59
@github-actions github-actions Bot removed the intake: hygiene-blocked Deterministic PR hygiene checks failed label Sep 13, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 56bc78ada5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/adapters/kiro.ts
},
};
}
// Thin facade over the cohesive leaf modules under ./kiro/. Every name this file exported

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update the architecture map for the new Kiro directory

This split moves the Kiro implementation into src/adapters/kiro/, but structure/runtime.md:168 still describes src/adapters/kiro.ts and the pre-existing kiro-*.ts helpers as the implementation owners, leaving the maintained source map inaccurate. Update that entry to include the facade and new leaf directory and describe their responsibilities; adapter changes are required to update their mapped structure documentation in the same change.

AGENTS.md reference: src/AGENTS.md:L11-L11

Useful? React with 👍 / 👎.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-13T08:01:13.225309Z 56bc78a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…eaves [skip ci]

Hosted CI on the stack tip went red because source-contract tests still
read the 30-line facade at src/service.ts. Point each assertion at the
owning leaf so the existing oracles keep their original strings, slices,
and negative matches. Import-specifier depth is the only assertion text
that changed, because the leaves sit one directory lower.
@lidge-jun
lidge-jun force-pushed the codex/260913-split-kiro branch from 56bc78a to 60b21c0 Compare September 13, 2026 08:32
@github-actions github-actions Bot added intake: hygiene-blocked Deterministic PR hygiene checks failed and removed test-exception-approved Maintainer approved a non-automated regression-test exception labels Sep 13, 2026
@github-actions
github-actions Bot marked this pull request as draft September 13, 2026 08:33
@lidge-jun lidge-jun added the test-exception-approved Maintainer approved a non-automated regression-test exception label Sep 13, 2026
@github-actions github-actions Bot removed the intake: hygiene-blocked Deterministic PR hygiene checks failed label Sep 13, 2026
@github-actions
github-actions Bot marked this pull request as ready for review September 13, 2026 08:34
… [skip ci]

Hosted CI shard 2/4 still read src/service.ts from launchd-repair.test.ts.
Point each slice at the owning leaf and keep the original assertion strings.
Pure-move split of the 2319-line kiro.ts god file into src/adapters/kiro/ leaves: wire.ts (wire identity/constants + message shapes), usage.ts (token estimation + message-text walkers), reasoning.ts (reasoning mode + thinking-tag injection), conversation.ts (capability + conversation-state validation), payload.ts (buildKiroPayload assembly), stream.ts (eventstream parsing + bounded fallback), adapter.ts (createKiroAdapter). kiro.ts is now a thin facade re-exporting the same public surface. Zero behavior change; no consumer edits.
The Kiro implementation now lives under src/adapters/kiro/, with
src/adapters/kiro.ts as the facade. Keep the structure map aligned so
structure:check still names a path inside the owned area.
@lidge-jun
lidge-jun force-pushed the codex/260913-split-kiro branch from 60b21c0 to 3176ac8 Compare September 13, 2026 08:43
@github-actions github-actions Bot added intake: hygiene-blocked Deterministic PR hygiene checks failed and removed test-exception-approved Maintainer approved a non-automated regression-test exception labels Sep 13, 2026
@github-actions
github-actions Bot marked this pull request as draft September 13, 2026 08:44
@lidge-jun lidge-jun added the test-exception-approved Maintainer approved a non-automated regression-test exception label Sep 13, 2026
@github-actions github-actions Bot removed the intake: hygiene-blocked Deterministic PR hygiene checks failed label Sep 13, 2026
@github-actions
github-actions Bot marked this pull request as ready for review September 13, 2026 08:49
dev landed #4425 on the old src/service.ts after this stack branched.
Carry the LogonTrigger UserId and the matching source-contract tests
into src/service/windows-taskxml.ts so a non-elevated install still
registers without asking for UAC.
Keep the service facade. The Windows logon-trigger fix from #4425 is
already in src/service/windows-taskxml.ts.
@lidge-jun
lidge-jun changed the base branch from codex/260913-split-service to dev September 13, 2026 08:53
@lidge-jun
lidge-jun merged commit 0d3cd53 into dev Sep 13, 2026
27 of 29 checks passed
@lidge-jun
lidge-jun deleted the codex/260913-split-kiro branch September 13, 2026 09:02
agentHits pushed a commit to agentHits/opencodex that referenced this pull request Sep 17, 2026
…un#4493)

Merge the god-file round 1 stack: storage/cleanup, service, and kiro facades.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature). test-exception-approved Maintainer approved a non-automated regression-test exception

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant