refactor(core): kiro decode into core, stores and companions host-side (phase 8, stateful tier) - #841
Merged
Merged
Conversation
…e (phase 8, stateful tier) Move all five kiro parse arms (legacy .chat, v1 modern execution, workspace-session, CLI .jsonl, v2 IDE event log) into @codeburn/core/providers/kiro as pure decode. The host keeps discovery, every file read, the companion-file reads (CLI .json, v2 session.json), the workspace-session mtime stat, project attribution, model display names, and all pricing. Behaviour is byte-identical to the pre-move provider; the four dedup-key namespaces (kiro:, kiro:ws-session:, kiro-cli:, kiro-v2:) and the five per-arm ParsedProviderCall key sets are unchanged. Preserved verbatim, with tests that discriminate against plausible refactors: - A4's asymmetric turnIndex: a zero-output turn does NOT consume a user_turn_metadatas slot, while the dedup-hit and bad-timestamp skip arms DO. Every later turn's timestamp and metered credits depend on this. All three arms are mutation-tested. - A1's toolSequence key stays present-with-undefined for single-entry sequences, gated by an Object.keys() assertion (toEqual cannot see it). - A1's input tokens still derive from the already-truncated 500-char prompt, unlike every other arm. - A5's dedup fallback stays `execId || String(calls.length)`, evaluated at flush time. - The three-way workspace-session prepare/finish split keeps the mtime stat behind both content gates rather than hoisting it. Credits seam: core emits `credits: number` and never prices. The host multiplies by USD_PER_KIRO_CREDIT and builds costUSD/costBasis, matching the codebuff precedent. Validator fixes on top of the migration: - A1's dedup key regained the raw `data.executionId` field; a fallback to basename(path) had been introduced, changing keys for chat files with a missing, empty, or non-string executionId. - The content-smuggling non-vacuousness guard was vacuous per vector (an aggregate re-decode compared against itself); it now asserts per-vector call counts, verified by breaking two fixtures. - Restored a mangled comment on the load-bearing v2-root derivation and several explanatory comments dropped during the move. - Added goldens G1b (raw executionId), G4b (exact credit products) and G6b (turnIndex advances across a bad-timestamp turn), plus a core test for the same; all reproduce against the pre-move provider. PROVIDER_PARSE_VERSIONS['kiro'] and CACHE_VERSION are unchanged. The companion-file fingerprint blind spot (session-cache.ts) and the dead project parameter on the old parseChatFile are left as-is. This completes the Phase 8 tail.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 8 stateful tier (tracking #809), last of three — this completes the Phase 8 tail: 35/35 provider identities migrated. Kiro's five parse arms (chat / modern / ws-session / cli / v2, four dedup namespaces) move their pure decode into
@codeburn/core; companion-file reads,stat(), env/fs, and the credits→USD conversion (USD_PER_KIRO_CREDIT) stay host-side. Core emitscredits; no state type, no cache or parse-version changes.Checkpointed flow (Opus spec → Kimi M1 goldens+core / M2 CLI conversion → Opus validation). Validation found and fixed 2 real defects plus a coverage hole:
|| fallbackExecutionIdthe original never had — files with missing/emptyexecutionIdproduced different keys. Caught by a 60-fixture differential harness against the restored original (5 divergences, all this arm); pinned by new golden G1b.Preserved verbatim and pinned: the asymmetric turnIndex semantics (zero-output turns don't advance; dedup-hit and bad-timestamp do), the A1 truncated-500-char inputTokens quirk (pinned at exact values), the three-way ws-session prepare/finish split with
stat()behind both content gates,toolSequence's present-with-undefined key (key-set gated, mutation-proven). Deterministic fractional-credit pricing pinned exactly (G4b); estimated-basis assertions deliberately not pinned to vendored snapshot data.Oracle: 16 goldens + 59 kiro.test.ts cases + 3 cache-invalidation cases pass identically against the restored pre-migration original and the migrated code, before and after merge-up (74741a8, shared files add-only unions).
Gates: core 497/497; root
npm test2456 passed, 5 skipped; kiro.test.ts byte-identical;tsc --noEmitclean both packages.