feat(cognition,#1375): check_redundancy PR-1 — pure types + prompt + parser#1377
Merged
Merged
Conversation
…parser Oxidizer for AIDecisionService.checkRedundancy (TS, see src/system/ai/server/AIDecisionService.ts:165-308). Mirrors the should_respond.rs gating arm + rate_proposals PR-1 shape (#1290). ## What this ships (PR-1 scope — pure, atomic) - `RedundancyCheckRequest` (ts-rs) — { context: AIDecisionContext, draftText: string, model?: string } - `RedundancyDecision` (ts-rs) — { isRedundant, reason, model, timestamp } - `ParsedRedundancyResponse` — internal parser output (no model / timestamp; caller in PR-2 will stamp those) - `RedundancyParseError` — typed: NoJsonObject, NotAnObject, MissingIsRedundant - `build_redundancy_prompt(&AIDecisionContext, draft_text) -> String` — pure. Embeds last N=10 conversation messages in `[HH:MM] speaker: content` shape, then draft, then JSON schema. - `parse_redundancy_response(&str) -> Result<...>` — pure. Extracts first balanced JSON object, decodes, validates isRedundant boolean. ## NOT in this PR - **PR-2**: `cognition/check-redundancy` IPC handler — composes prompt → AI provider call (existing Groq router) → parse → RedundancyDecision with model + timestamp stamped. - **PR-3**: TS `AIDecisionService.checkRedundancy` shim — replaces inline prompt + AIProviderDaemon.generateText with the IPC call. - **PR-4**: Delete dead TS code (the inline prompt template + JSON parsing from AIDecisionService.ts) — same pattern as rate_proposals PR-3 (#1293). ## Discipline - No silent default-on-error. Parser returns typed Result, never panics. - Caller decides fail-open vs fail-closed — module never invents a default. - Pure prompt builder uses UTC (removes hidden TZ dependency that the TS version's local-time prefix had). - Snippet bounding on error variants caps upstream garbage in error messages. - ConversationTurn types reused from gating stack (no new shapes invented for shared concepts). ## Tests (18, all passing) prompt: - embeds draft + conversation lines with [HH:MM] prefix - falls back to role when name missing - omits time prefix when timestamp missing - uses only last 10 messages in chronological order - handles empty conversation - includes unescaped JSON schema example parser: - bare JSON object (happy path) - extracts JSON from surrounding prose (markdown-wrapped output) - uses default reason "No reason provided" when reason field missing - typed err for no-JSON - typed err for unbalanced braces - typed err for top-level array (degrades through NoJsonObject) - typed err for missing isRedundant field - typed err for non-boolean isRedundant ("true" string) - extracts first balanced object when nested bounds: - snippet truncates long input (200-byte prefix + 3-byte UTF-8 ellipsis) - 2 ts-rs export bindings Full cognition regression: 292/292 pass. Ref: #1375 oxidizer card, #1248 umbrella (TS-side AI logic violates 'TS is thin glue' directive). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 17, 2026
Closed
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.
Summary
Oxidizer for
AIDecisionService.checkRedundancy(TS, seesrc/system/ai/server/AIDecisionService.ts:165-308). Mirrors theshould_respond.rsgating arm +rate_proposalsPR-1 shape (#1290).What this ships (PR-1 scope — pure, atomic)
RedundancyCheckRequest(ts-rs) —{ context: AIDecisionContext, draftText, model? }RedundancyDecision(ts-rs) —{ isRedundant, reason, model, timestamp }ParsedRedundancyResponse— internal parser output (caller in PR-2 stamps model + timestamp)RedundancyParseError— typed:NoJsonObject,NotAnObject,MissingIsRedundantbuild_redundancy_prompt(&AIDecisionContext, draft_text) -> String— pure. Embeds last N=10 conversation messages in[HH:MM] speaker: contentshape, then draft, then JSON schema.parse_redundancy_response(&str) -> Result<...>— pure. Extracts first balanced JSON object, decodes, validatesisRedundantboolean.NOT in this PR
cognition/check-redundancyIPC handler — composes prompt → AI provider call (existing Groq router) → parse →RedundancyDecisionwith model + timestamp stamped.AIDecisionService.checkRedundancyshim — replaces inline prompt +AIProviderDaemon.generateTextwith the IPC call.rate_proposalsPR-3 (refactor(cognition,#1289): rate_proposals PR-3 — delete dead TS adapter (no production callers) #1293).Discipline
Result, never panics.Tests (18, all passing)
Prompt (6 tests): draft + conversation embed, role fallback, time-prefix omission, last-N window + chronological order, empty conversation, unescaped JSON schema example.
Parser (9 tests): bare JSON, JSON-in-prose, default reason, all error variants, nested object extraction.
Bounds (1 test): snippet bounding (200-byte ASCII prefix + 3-byte UTF-8 ellipsis).
ts-rs (2 tests): export bindings.
Full cognition regression: 292/292 pass.
Refs
rate_proposalsstack refactor(cognition,#1289): rate_proposals PR-1 — Rust types+prompt+parser slice #1290/refactor(cognition,#1289): rate_proposals PR-2 — IPC handler + orchestrator #1291/refactor(cognition,#1289): rate_proposals PR-3 — delete dead TS adapter (no production callers) #1293 (MERGED)should_respond.rs(already oxidized —evaluateGatingarm)Test plan
cargo test --package continuum-core --lib --features metal,accelerate cognition::check_redundancy::— 18/18 passcargo test --package continuum-core --lib --features metal,accelerate cognition::— 292/292 pass (no regressions)🤖 Generated with Claude Code