Skip to content

feat(cognition,#1375): check_redundancy PR-1 — pure types + prompt + parser#1377

Merged
joelteply merged 1 commit into
canaryfrom
feat/oxidizer-redundancy-pr1-pure-types
May 17, 2026
Merged

feat(cognition,#1375): check_redundancy PR-1 — pure types + prompt + parser#1377
joelteply merged 1 commit into
canaryfrom
feat/oxidizer-redundancy-pr1-pure-types

Conversation

@joelteply
Copy link
Copy Markdown
Contributor

Summary

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, model? }
  • RedundancyDecision (ts-rs) — { isRedundant, reason, model, timestamp }
  • ParsedRedundancyResponse — internal parser output (caller in PR-2 stamps model + timestamp)
  • 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

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 the TS version's local-time prefix had).
  • Snippet bounding on error variants caps upstream garbage in error messages.
  • Conversation types reused from gating stack (no new shapes invented for shared concepts).

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

Test plan

  • cargo test --package continuum-core --lib --features metal,accelerate cognition::check_redundancy:: — 18/18 pass
  • cargo test --package continuum-core --lib --features metal,accelerate cognition:: — 292/292 pass (no regressions)
  • Pre-push TS clean, ESLint baseline held, Rust compile clean
  • CI green
  • PR-2 IPC handler stack on top (separate PR)

🤖 Generated with Claude Code

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant