Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,40 @@ Implemented capabilities include:
- Custom dictionaries, app rules, blocklists, and allowlists.
- App-level undo and secure-field blocking.

**Word-count correction** is optional and defaults to every 10 completed words.
Under **Triggers**, enable or disable it and configure the threshold. A word is
completed by whitespace; an unfinished word does not trigger correction. Only
the current executable context counts. At the threshold, AutoFix freezes that
segment and runs correction on its worker while new typing starts a fresh
executable context. App rules and secure-field blocks apply before execution
and again before replacement. Completion requires the same session and control,
an exact live pre-caret range, and no input conflict during validation or mutation.
New typing and text after the caret are preserved.

High-confidence results apply silently by default. Medium confidence follows
the saved policy; automatic suggestion behavior currently skips because suggestion
acceptance is planned. Low confidence never applies. A verified no-change or
confidence-suppressed word-count result commits the original as informative
context and clears its pending segment without an undo entry. Changed segments
record app-level undo. Failed, timed-out, stale or unsafe work returns to executable
context for a later trigger. Logs contain metadata only.

**Character correction** is optional and defaults to `.`. Under **Triggers**,
configure the character list (for example `.`, `?`, `!`, or `。`). Configured
sequences can span keystrokes. Typing a configured boundary at the end of the
active executable context freezes that completed segment for asynchronous
correction; subsequent typing starts a new executable context. Earlier skipped
boundaries remain in the active segment so unchecked text is preserved.

Character results use the same conservative live validation, app rules, security
blocks and confidence settings as word-count results. High confidence applies
silently by default; medium confidence follows settings and low confidence never
applies. A verified no-change or confidence skip commits the original. Corrected
or unchanged text becomes informative context, which shrinks to its configured
budget without editing the document. Failed or unsafe results stay executable.
New typing and text after the caret remain untouched; changed text supports
app-level undo, and logs contain metadata only.

Local ML correction, suggestion acceptance, IME composition, and direct text API
or UI Automation mutation remain planned. App-level undo restores only recorded
corrections whose exact span and caret can still be verified.
Expand Down
14 changes: 12 additions & 2 deletions app-core-rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,13 @@ executable text. Validated no-change results from manual, word-count, character,
and final-fix requests commit the original segment without replacement or an
undo entry. Each accepted result logs one metadata-only event and writes a
`correction_metadata` row with trigger, engine, confidence, reason, latency, and
replacement method `none`; no context text enters these logs. Failed, stale,
timed-out, unsupported-language, and confidence-suppressed results stay executable.
replacement method `none`; no context text enters these logs. Completed frozen
word-count and character results suppressed by the admitted confidence policy
also commit the verified original, with reason `confidence_below_configured_behavior`,
no native replacement and no undo entry. They require the same target, security and exact
live range checks as changed results. Medium automatic suggestions resolve to
skip; low confidence always skips. Other confidence-suppressed results and
failed, stale, timed-out or unsupported-language results stay executable.
Exceeding `context.executable_context_max_words` (default 80) also commits the
current segment, including after caret movement resolves and after a limit update.
This size-limit commit logs only session and word-count metadata. New typing
Expand Down Expand Up @@ -269,6 +274,11 @@ one active executable context and a bounded pending correction queue.
includes running work. Automatic triggers freeze the current executable context
before processing subsequent typing, including keys in the same input batch.
New typing starts a fresh executable context while correction runs asynchronously.
The character trigger is optional, defaults to `.`, and reads its configurable
list from `triggers.characters`. Matching uses the active pre-caret text, allowing
Unicode boundaries and configured sequences entered over multiple key events.
The whole completed active segment is frozen, including earlier skipped
boundaries; informative text and already frozen text never become editable.
`context.pending_queue_full_behavior` defaults to `skip_new`, which skips the
new automatic trigger and retains current typing. `cancel_oldest` cancels the
oldest pending request and its dependent newer requests, restores their unchecked
Expand Down
30 changes: 26 additions & 4 deletions app-core-rust/src/background/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,24 @@ impl CorrectionPipeline {
let no_change_reason = match output.no_change_reason {
Some(NoChangeReason::NoCorrectionNeeded) => Some("no_correction_needed"),
Some(NoChangeReason::AllCandidatesProtected) => Some("all_candidates_protected"),
// A completed automatic check may deliberately keep the original.
// Retire it only after the same live range proof as an applied edit,
// and only when the admitted policy really suppresses this tier.
Some(NoChangeReason::ConfidenceBelowConfiguredBehavior)
if matches!(
active.request.trigger,
TriggerKind::WordCount | TriggerKind::Character
) && segment_id.is_some()
&& output.behavior == ConfidenceBehavior::DoNothing
&& output.changes.as_ref().is_some_and(Vec::is_empty)
&& active.request.confidence_behavior.behavior_for(
output.confidence,
active.trigger_type,
active.suggestion_ui_available,
) == ConfidenceBehavior::DoNothing =>
{
Some("confidence_below_configured_behavior")
}
_ => None,
};
if output.changes_needed {
Expand Down Expand Up @@ -668,10 +686,14 @@ impl CorrectionPipeline {
);
} else if completed {
self.feedback_event = Some((
Event::Skipped(if no_change_reason == Some("all_candidates_protected") {
"AutoFix: matching terms are protected."
} else {
"AutoFix: no correction needed."
Event::Skipped(match no_change_reason {
Some("all_candidates_protected") => {
"AutoFix: matching terms are protected."
}
Some("confidence_below_configured_behavior") => {
"AutoFix: confidence policy skipped this correction."
}
_ => "AutoFix: no correction needed.",
}),
manual,
));
Expand Down
110 changes: 80 additions & 30 deletions app-core-rust/src/background/pipeline/tests.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,58 @@
use super::*;
use crate::background::{
context_capture::SelectionCapture,
security,
target::FocusedElementId,
triggers,
typing::{MovementSignal, TypedInput},
InputProcessor, PendingTrigger,
};
use std::{cell::Cell, sync::mpsc, time::Instant};

mod character;
mod manual;
mod word_count;

/// Build the runtime input owner for automatic-trigger flow tests.
fn processor(config: AppConfig, pipeline: CorrectionPipeline) -> InputProcessor {
let mut processor = InputProcessor {
feedback: crate::background::feedback::Feedback::default(),
learner: crate::dictionary::Learner::default(),
pipeline,
processed_input_sequence: STAMP.sequence,
session_manager: SessionManager::new(config.context.clone()),
config,
database: crate::storage::Database::open_memory().unwrap(),
};
processor.session_manager.focus(&target());
processor
}

/// Send translated keys individually, preserving the real trigger boundary.
fn type_text(processor: &mut InputProcessor, text: &str) -> Vec<PendingTrigger> {
let mut pending = Vec::new();
for character in text.chars() {
processor.track_input(TypedInput::Text(character.to_string()), &mut pending);
}
pending
}

/// Dispatch with real app rules and a deterministic focused target.
fn dispatch(processor: &mut InputProcessor, request: CorrectionRequest) -> bool {
processor.dispatch_trigger_with(
request,
STAMP,
|| STAMP,
|trigger, config, database| {
security::check_detection(
trigger,
config,
&database.app_rules().list().unwrap(),
crate::background::target::TargetDetection::Available(target()),
)
},
)
}

const STAMP: InputStamp = InputStamp {
position: 7,
Expand Down Expand Up @@ -767,7 +812,7 @@ fn cancel_oldest_suppresses_late_transport_and_runs_new_segment() {
#[test]
fn frozen_failures_release_capacity_without_committing_engine_output() {
let config = AppConfig::default();
for failure in 0..9 {
for failure in 0..8 {
let mut manager = manager(&config, "teh");
let mut pipeline = CorrectionPipeline::new().unwrap();
submit_frozen(&mut pipeline, &mut manager, &config);
Expand All @@ -794,14 +839,6 @@ fn frozen_failures_release_capacity_without_committing_engine_output() {
}
6 => output.behavior = ConfidenceBehavior::DoNothing,
7 => {
*output = CorrectionOutput::unchanged(
"teh".into(),
ConfidenceTier::Medium,
NoChangeReason::ConfidenceBelowConfiguredBehavior,
0,
)
}
8 => {
*output = CorrectionOutput::unchanged(
"teh".into(),
ConfidenceTier::Low,
Expand Down Expand Up @@ -964,10 +1001,12 @@ fn unchanged_commit_policy_preserves_skips_for_all_triggers() {
reason.clone(),
17,
);
let accepted = matches!(
reason,
NoChangeReason::NoCorrectionNeeded | NoChangeReason::AllCandidatesProtected
);
let accepted =
matches!(
reason,
NoChangeReason::NoCorrectionNeeded | NoChangeReason::AllCandidatesProtected
) || (matches!(trigger, TriggerKind::WordCount | TriggerKind::Character)
&& reason == NoChangeReason::ConfidenceBelowConfiguredBehavior);
let calls = Cell::new(0);
assert_eq!(
finish(&mut pipeline, &mut manager, &config, STAMP, &calls, false),
Expand Down Expand Up @@ -1002,10 +1041,12 @@ fn unchanged_commit_policy_preserves_skips_for_all_triggers() {
trigger.as_str().into(),
"low".into(),
"none".into(),
if reason == NoChangeReason::NoCorrectionNeeded {
"no_correction_needed"
} else {
"all_candidates_protected"
match reason {
NoChangeReason::NoCorrectionNeeded => "no_correction_needed",
NoChangeReason::ConfidenceBelowConfiguredBehavior => {
"confidence_below_configured_behavior"
}
_ => "all_candidates_protected",
}
.into(),
17
Expand Down Expand Up @@ -1470,14 +1511,10 @@ fn medium_previews_are_manual_opt_in_and_never_mutate_or_commit() {
}
wait_completion(&pipeline);
let calls = Cell::new(0);
assert!(!finish(
&mut pipeline,
&mut manager,
&config,
STAMP,
&calls,
true
));
assert_eq!(
finish(&mut pipeline, &mut manager, &config, STAMP, &calls, true),
automatic
);
assert_eq!(calls.get(), 0);
let preview = pipeline.take_suggestion();
if let Some(preview) = &preview {
Expand All @@ -1496,8 +1533,14 @@ fn medium_previews_are_manual_opt_in_and_never_mutate_or_commit() {
}
);
assert!(pipeline.take_suggestion().is_none());
assert_eq!(manager.active().unwrap().editable_context(), "teh");
assert!(manager.active().unwrap().informative_context().is_empty());
assert_eq!(
manager.active().unwrap().editable_context(),
if automatic { "" } else { "teh" }
);
assert_eq!(
manager.active().unwrap().informative_context(),
if automatic { "teh" } else { "" }
);
assert!(manager.active().unwrap().undo_target().is_none());
}
}
Expand Down Expand Up @@ -1593,21 +1636,28 @@ fn medium_local_results_skip_preview_or_apply_without_losing_typed_text() {
wait_completion(&pipeline);
let calls = Cell::new(0);
let silent = configured == ConfidenceBehavior::Silent;
let committed = silent || automatic;
assert_eq!(
finish(&mut pipeline, &mut manager, &config, STAMP, &calls, true,),
silent
committed
);
assert_eq!(calls.get(), usize::from(silent));
assert!(pipeline.take_suggestion().is_none());
let session = manager.active().unwrap();
assert_eq!(session.undo_target().is_some(), silent);
assert_eq!(
session.informative_context(),
if silent { "accommodate" } else { "" }
if silent {
"accommodate"
} else if automatic {
"accomodate"
} else {
""
}
);
assert_eq!(
session.editable_context(),
if silent { "" } else { "accomodate" }
if committed { "" } else { "accomodate" }
);
}
}
Expand Down
Loading
Loading