mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-27 07:58:01 +01:00
* Stage clipboard-preserving capture insertion for Paste Last on Mac * Update Rune and its Nix source hash for the picker work * Select the latest ready paste by owner identity and revalidate it * Exercise a held mixed paste picker with real bundles and a private Mac pasteboard * Publish ready Annotate identity and queue owner-specific paste requests * Wire the existing Mac paste shortcut and controls to the opt-in mixed picker * Recheck the selected field and cover Paste Last with a disposable Mac receiver * Refresh the Rune revision for the unified History pane * Unify Mac History and keep only spoken words after a deliberate dictation cancel * History and Paste Last call a Hex capture an annotation (t1612) A finished Hex capture is an Annotation in History, its details and the Paste Last picker, and the type filter is Annotations. The Captures pane no longer rewrites its own label when the unified History is on, and the search index drops the old synonym. Scrawl stays only as Scrawl.app and the on-disk .scrawl format; a Hex-owned format is separate file and engine work. * Gate the unified History behind a Labs toggle and give it one row shape (t1612) Labs › Paste Last picker (labs.paste_last_picker; macOS, Dev audience, off by default) replaces HEX_EXPERIMENTAL_PASTE_LAST and is read where the work starts: the picker and its gesture, History's unified list, and the cancel path's word writer. Off, Paste Last and History behave exactly as before. History's rows now share one shape for dictations, annotations, screenshots and recordings; a capture's detail card carries its picture, words, facts and actions; a search or the type filter never leaves a stale card open; an empty History has one empty state; and the type filter shows only when there is more than one kind to filter. The picker's rows sit on its title's left edge. * Show the Paste Last picker card on macOS only (t1612) * Refresh the Labs goldens for the Paste Last picker card (t1612) * Keep the unified History's capture helpers to macOS builds (t1612) * Keep the unified History's fixture pictures behind the Mac capture gate (t1612) * Point the docs at the Paste Last picker lab (t1612)
176 lines
6.6 KiB
Rust
176 lines
6.6 KiB
Rust
//! One selection rule for an immediate paste and the open picker. Only the
|
||
//! stable ID crosses the selection boundary, never a payload or a row index.
|
||
|
||
#[cfg(test)]
|
||
use crate::capture_host::paste_source as captures;
|
||
use crate::capture_host::paste_source::Scope;
|
||
use crate::history::History;
|
||
use scrawl_capture::model::ScrawlBundle;
|
||
use std::path::PathBuf;
|
||
|
||
pub(crate) use crate::history::timeline::{PasteId as Id, Row, latest, snapshot};
|
||
|
||
pub(crate) enum Output {
|
||
Text(String),
|
||
Capture(PathBuf, Box<ScrawlBundle>),
|
||
}
|
||
|
||
pub(crate) fn resolve(
|
||
history: &History,
|
||
captures: Option<&Scope<'_>>,
|
||
id: &Id,
|
||
now: u64,
|
||
) -> Option<Output> {
|
||
match id {
|
||
Id::Dictation(id) => history.resolve_paste(*id, now).map(Output::Text),
|
||
Id::Capture(id) => captures?
|
||
.resolve(id, now)
|
||
.map(|(dir, bundle)| Output::Capture(dir, Box::new(bundle))),
|
||
}
|
||
}
|
||
|
||
/// Only constructed from the gesture/menu's frontmost application, never
|
||
/// from the caller of a control request. Runs on the ordered output worker.
|
||
pub(crate) struct Request {
|
||
pub id: Option<Id>,
|
||
pub target: Target,
|
||
}
|
||
|
||
pub(crate) struct Target {
|
||
pid: i32,
|
||
focus: crate::accessibility::PasteFocus,
|
||
}
|
||
impl Target {
|
||
pub(crate) fn capture() -> Option<Self> {
|
||
let pid = crate::dictation::context::frontmost_pid()?;
|
||
Some(Self {
|
||
pid,
|
||
focus: crate::accessibility::PasteFocus::capture(pid)?,
|
||
})
|
||
}
|
||
pub(crate) fn in_front(&self) -> bool {
|
||
crate::dictation::context::frontmost_pid() == Some(self.pid)
|
||
}
|
||
pub(crate) fn unchanged(&self) -> bool {
|
||
self.in_front() && self.focus.unchanged()
|
||
}
|
||
}
|
||
|
||
/// Labs › Paste Last picker (macOS): the picker, unified History, and the
|
||
/// words a deliberate cancel keeps. Off, every one of those is exactly as it
|
||
/// was before the lab.
|
||
pub(crate) fn enabled() -> bool {
|
||
crate::labs::paste_last_picker()
|
||
}
|
||
|
||
pub(crate) fn current_rows(history: &History) -> Vec<Row> {
|
||
let settings = crate::app_settings::capture_settings();
|
||
let root = settings.enabled.then(|| settings.captures_dir());
|
||
let scope = root.as_ref().map(|p| Scope::new(p, settings.bundle_days));
|
||
snapshot(history, scope.as_ref(), 8, crate::history::now_ms())
|
||
}
|
||
|
||
impl Request {
|
||
pub(crate) fn insert(
|
||
self,
|
||
paster: &mut super::Paster,
|
||
history: Option<&History>,
|
||
) -> color_eyre::Result<String> {
|
||
use color_eyre::eyre::eyre;
|
||
let history = history.ok_or_else(|| eyre!("paste history is unavailable"))?;
|
||
let settings = crate::app_settings::capture_settings();
|
||
let root = settings.enabled.then(|| settings.captures_dir());
|
||
let scope = root.as_ref().map(|p| Scope::new(p, settings.bundle_days));
|
||
let now = crate::history::now_ms();
|
||
let id = self
|
||
.id
|
||
.or_else(|| latest(history, scope.as_ref(), now))
|
||
.ok_or_else(|| eyre!("nothing to paste"))?;
|
||
let output = resolve(history, scope.as_ref(), &id, crate::history::now_ms())
|
||
.ok_or_else(|| eyre!("that item is no longer available"))?;
|
||
if !self.target.unchanged() {
|
||
return Err(eyre!("paste target changed"));
|
||
}
|
||
match output {
|
||
Output::Text(text) => {
|
||
paster.insert_recent_text(&text, &self.target)?;
|
||
Ok(text)
|
||
}
|
||
Output::Capture(dir, bundle) => {
|
||
let payload = super::capture::Payload::prepare(
|
||
&dir,
|
||
&bundle,
|
||
scrawl_capture::capture::is_frontmost_terminal(),
|
||
scrawl_capture::handoff::experiment(scrawl_capture::handoff::AGENT_CONTEXT),
|
||
)?;
|
||
paster.paste_capture(&payload, &self.target)?;
|
||
Ok(String::new())
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
#[cfg(test)]
|
||
mod tests {
|
||
use super::*;
|
||
use crate::history::{HistoryDraft, HistoryKind, HistoryRetention, HistoryStore};
|
||
use std::fs;
|
||
|
||
#[test]
|
||
fn mixed_tap_and_picker_revalidate_the_same_ready_item_without_promoting_it() {
|
||
let root = std::env::temp_dir().join(format!("hex-paste-model-{}", std::process::id()));
|
||
fs::create_dir(&root).unwrap();
|
||
let mut history = HistoryStore::open(root.join("history.json"), HistoryRetention::Day, 10);
|
||
history
|
||
.record(
|
||
HistoryDraft {
|
||
kind: HistoryKind::Raw,
|
||
raw_text: "first".into(),
|
||
final_text: "first".into(),
|
||
application: None,
|
||
processing: None,
|
||
audio_ms: 0,
|
||
inference_ms: 0,
|
||
total_ms: 0,
|
||
recording: None,
|
||
model: None,
|
||
},
|
||
11,
|
||
)
|
||
.unwrap();
|
||
let history = History::new(history);
|
||
let capture = root.join("12.scrawl");
|
||
fs::create_dir(&capture).unwrap();
|
||
let manifest = r#"{"version":1,"id":"12","createdAtMs":12,"durationMs":1800,"target":{"mode":"display","displayId":1,"frame":{"x":0,"y":0,"width":40,"height":30,"scale":1}},"transcript":{"source":"hex","text":"move it down","segments":[],"words":[]},"strokes":[],"marks":[],"events":[],"keyframes":[],"contactSheet":"contact-sheet.png"}"#;
|
||
fs::write(capture.join("scrawl.json"), manifest).unwrap();
|
||
let scope = Scope::new(&root, Some(7));
|
||
// A readable manifest, even with Hex as its speech source, is not
|
||
// proof it came from Hex Annotate (standalone Scrawl shares the root).
|
||
assert_eq!(snapshot(&history, Some(&scope), 8, 20).len(), 1);
|
||
captures::mark_ready(&capture, 13).unwrap();
|
||
let failed = root.join("14.scrawl");
|
||
fs::create_dir(&failed).unwrap();
|
||
fs::write(failed.join("scrawl.json"), "unfinished").unwrap();
|
||
let picker = snapshot(&history, Some(&scope), 8, 20);
|
||
assert_eq!(picker.len(), 2);
|
||
assert_eq!(picker[0].preview, "move it down");
|
||
assert_eq!(
|
||
latest(&history, Some(&scope), 20),
|
||
Some(picker[0].id.clone())
|
||
);
|
||
assert!(
|
||
matches!(resolve(&history, Some(&scope), &picker[1].id, 20), Some(Output::Text(text)) if text == "first")
|
||
);
|
||
assert_eq!(
|
||
latest(&history, Some(&scope), 20),
|
||
Some(picker[0].id.clone())
|
||
);
|
||
fs::remove_dir_all(&capture).unwrap();
|
||
assert!(resolve(&history, Some(&scope), &picker[0].id, 20).is_none());
|
||
assert_eq!(
|
||
latest(&history, Some(&scope), 20),
|
||
Some(picker[1].id.clone())
|
||
);
|
||
fs::remove_dir_all(root).unwrap();
|
||
}
|
||
}
|