Repository navigation
Superseded By #357 — Do Not Merge - #353
jaywedgeworth22 wants to merge 12 commits into
Conversation
…r controls, and SMS
This comment has been minimized.
This comment has been minimized.
|
@kody start-review 35761ac fixes all three initial findings, the CI compiler-expression failure, and the exact gitleaks false positive. It also preserves PR #352's long Kimi OAuth token fix and restricts shared-config fallback to explicitly identified Kimi coding providers. Provider parsing/cancellation tests passed 33/33; Muse plugin tests 16/16; Twilio tests 8/8. Additional explicit Z.ai key setup is being integrated after first-party source confirmed its OAuth token is not the coding-plan quota credential. |
Code Review Completed! 🔥The code review was successfully completed based on your current configurations. Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
|
Superseded by #357, which contains the same fixed implementation reconciled with current main and #354. All 106 changed blobs were verified against native-tested source 2da7e69 (1,597 Swift tests, 10 skipped, zero failures; 101 Node contracts passed). The cumulative-segment, persistence-coupling, SMS-encoding, and CRLF-parser findings were fixed with evidence in their original threads; no finding is being abandoned. #357 now has a clean merge base and active CI/review. Runtime installation and scoped credential binding remain tracked under CC-205. |
| climbed = reading >= last + ResetAlarmPolicy.earlyResetRiseMargin | ||
| } | ||
| if jump > required || (jump > ResetAlarmPolicy.resetDriftTolerance && climbed) { | ||
| let rose = reading.flatMap { current in | ||
| window.lastRemaining.map { current > $0 + ResetAlarmPolicy.riseEpsilon } | ||
| } ?? false | ||
| let resetHasQuotaEvidence = rose || (hasPassed && reading == nil) | ||
| if (jump > required && resetHasQuotaEvidence) | ||
| || (jump > ResetAlarmPolicy.resetDriftTolerance && climbed) { | ||
| isReset = true | ||
| // When the window had *not* reached its own scheduled end, | ||
| // any reset is an early / mid-cycle vendor restore rather than |
There was a problem hiding this comment.
Bug: Scheduled quota rollovers fail to trigger isReset when the remaining quota was idle or unchanged across the period boundary.
Severity: MEDIUM
Suggested Fix
Only require resetHasQuotaEvidence when !hasPassed, allowing jump > required to indicate a reset once hasPassed is true even if the reading has not risen.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: Sources/QuotaCore/ResetAlarmTracker.swift#L496-L512
Potential issue: In `ResetAlarmTracker.advance`, the reset detection condition requires
`resetHasQuotaEvidence` for scheduled jumps (`jump > required`). Because
`resetHasQuotaEvidence` requires `rose` (`reading > lastRemaining + 1`) or `hasPassed &&
reading == nil`, an idle quota window sitting at 100% remaining will not trigger
`isReset` when its period passes and the reset timestamp advances. The subsequent branch
updates `periodResetAt`, causing the scheduled rollover to be permanently missed for
flat or near-flat windows.
| let total = number(usage["totalTokens"]), total >= 0 else { return nil } | ||
| let range = usage["sourceRange"] as? [String: Any] | ||
| return MuseCodeTokenSegment( | ||
| sessionId: sessionId, | ||
| modelId: modelId, | ||
| totalTokens: Int(total.rounded()), | ||
| promptTokens: number(usage["promptTokens"]).map { Int($0.rounded()) }, |
There was a problem hiding this comment.
Bug: Converting unbounded floating-point numbers to Int in MuseCodeSessionReader can trigger a runtime trap on large numeric values.
Severity: LOW
Suggested Fix
Enforce maximum and minimum bounds or clamp token values before casting them to Int, or use safe conversion methods that handle overflow without trapping.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: Sources/QuotaCore/MuseCodeSessionReader.swift#L335-L341
Potential issue: `MuseCodeSessionReader.number()` accepts any finite `NSNumber`, but
callers in `segment()` convert these values via `Int(total.rounded())` and
`Int($0.rounded())`. Converting floating-point values larger than `Double(Int.max)`
traps at runtime in Swift. An excessively large or corrupted token count in a local
session snapshot file will crash the application during `refreshMuseCodePlugin` and
repeatedly on subsequent launches within the activity window.
Fixes CC-205
This pull request fixes reset-alert false positives and adds Muse monitoring, optional provider controls, and opt-in SMS delivery. It also updates quit behavior, provider artwork, and Mac version planning.
Resets: the tracker rebaselines when a reused window ID changes cadence and requires a quota rise before treating a pre-end timestamp correction as a reset. Scheduled rollovers and demonstrated restores keep their existing alert rules. Quit now offers Close Window And Keep Running, Quit CodeCaps, and Cancel. The keep-running choice preserves menu-bar access for quota checks and alerts, including Dock-only mode, while confirmed quit retains the snapshot-write drain. System shutdown, restart, logout, quit-all, and an active automatic Sparkle install bypass the prompt.
Providers and plugins: Kimi and Z.ai / ZCode become optional local readers behind a typed
LocalQuotaReaderRegistryextension point with per-device preferences. Sources & Fleet adds separate quota-check switches; disabling a provider skips reader construction and credential access, removes its cached rows, and invalidates in-flight refreshes. New code adds a Plugins section with deterministic Mac-local Muse session monitoring, including 60/90-minute burn totals, contributor share display, per-model split, tunable 90-minute burn threshold, bridge controls, and centralized alert fan-out. The burn rule fires only above threshold with a currently observed standard-model session, and standard-session detection fires once on first sight or contributor-to-standard switch, re-arms on return to contributor, ignores missing models, and persists across relaunch. An optional Usage Monitor bridge posts only positive per-session deltas with replay-safe event IDs and checkpointed baselines.SMS: Alerts & Alarms adds independent SMS for Muse Standard Sessions, Muse Burn, and Quota Exhaustion. SMS ships off for every kind, requires the alert kind to stay enabled, and remains available when notification and popup are off. Setup uses a build-scoped Keychain record plus UserDefaults configuration, saves no message on save, preserves a matching saved secret on blank entry, and exposes explicit re-authorize and forget actions. Delivery reserves a persistent hashed event ID before submission to avoid duplicate paid messages, uses a fixed Twilio endpoint with redirects rejected and no automatic retry, and reports acceptance without claiming handset delivery.
Operational and packaging: adds Keychain services for Muse ingest and Twilio SMS, new UserDefaults preferences and checkpoint state, new Kimi and Z.ai marks with companion and widget mappings, and Mac version planning based on Chicago merge-timestamp shared builds with fail-closed release behavior. No live SMS sending is represented in the changes, and unverified runtime behavior remains unverified.
Tests added: reset-plan and tracker correction cases, quit-confirmation policy cases, registry non-invocation and merge-order cases, Muse reader aggregation and filesystem cases, burn gating and status cases, standard-session detector transition and persistence cases, bridge safety and replay cases, plugin alert-routing cases, SMS coordinator deduplication and capacity cases, SMS controller routing and cancellation cases, Twilio client encoding and receipt cases, credential-store isolation cases, logo and companion-catalog coverage, and Mac version-planner contract tests. The rollout note instructs running
swift buildandswift teston macOS. No run results, approvals, or deployment verification are included in the changes.Open review findings, not resolved here: critical — Sources/QuotaCore/TwilioSMSClient.swift:154, SMS form encoding force-unwrap can crash delivery. High — Sources/CodeCaps/MonitorModel.swift:3240, burn persistence failure skips standard-session alerts.
Summary
This pull request fixes Muse alert persistence and refines quota and notification handling. It keeps burn cooldowns and session-detector state retryable when persistence fails rather than consuming them, and it adjusts Muse usage aggregation, Kimi credential selection, cancellation handling, and SMS encoding. Runtime verification status is unverified.
Functional Changes
MonitorModel: saves burn timestamps and detector state through a guarded helper that restores the previous defaults value when synchronize fails. Failed burn persistence no longer blocks the standard session alert or consumes the burn cooldown, and failed detector persistence leaves the standard event eligible on a later poll. Adds a test hook for synchronize behavior.MuseCodeSessionReader: changes segment identity to exact source range and model, with total treated as high-water rather than identity when both boundaries exist. Aggregation keeps only the high-water total per segment and uses deterministic ordering, so repeated cumulative snapshots do not sum and stale snapshots do not replace newer high-water values.User-Visible / Operational Impact
Tests Added
New automated tests were added in the diff; no run results were provided so outcomes are unverified. Added tests cover failed burn persistence not blocking standard alerts, failed detector persistence remaining eligible without repeating burn, persistence failure not consuming contributor-to-standard rearm across recreation, long and oversized OAuth credential handling, TOML and JSON provider selection and rejection including unapproved bases and unscoped keys, numeric-string counters and guards, cancellation without fallback for Kimi and Z-Code, high-water aggregation and distinct-range summation for Muse sessions, Unicode SMS form encoding, and Kimi logo color preservation with revised pixel scanning.
Unresolved Risks
Sources/QuotaCore/KimiQuotaReader.swift:341— CRLFconfig.tomlhandling may reject a valid Kimi key as missing credential. Behavior for affected configurations is unverified.