mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +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)
161 lines
5.1 KiB
Rust
161 lines
5.1 KiB
Rust
//! Only an Annotate writer can publish a ready result. Never adopt old
|
|
//! folders from the shared Scrawl library by name, transcript source or age.
|
|
|
|
use std::fs;
|
|
use std::io::{self, Read, Write};
|
|
use std::os::unix::fs::OpenOptionsExt;
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use scrawl_capture::model::ScrawlBundle;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
const READY: &str = ".hex-annotate-v1";
|
|
const DAY_MS: u64 = 86_400_000;
|
|
|
|
#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
|
|
struct Stamp {
|
|
ready_at: u64,
|
|
generation: [u8; 16],
|
|
}
|
|
|
|
/// Relative to the *current* configured folder; includes its root so a
|
|
/// settings change cannot retarget a selected row. No path is accepted from
|
|
/// a client. Copying a folder creates a different identity.
|
|
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
|
pub(crate) struct Id {
|
|
dir: PathBuf,
|
|
stamp: Stamp,
|
|
}
|
|
|
|
impl Id {
|
|
pub(crate) fn bundle(&self) -> &Path {
|
|
&self.dir
|
|
}
|
|
}
|
|
|
|
/// A receipt belongs to the bundle (so deletion needs no index cleanup).
|
|
/// It contains identity and time only. Never rewrite an existing receipt.
|
|
pub(crate) fn mark_ready(dir: &Path, ready_at: u64) -> io::Result<()> {
|
|
let mut generation = [0; 16];
|
|
getrandom::fill(&mut generation).map_err(|e| io::Error::other(e.to_string()))?;
|
|
let stamp = serde_json::to_vec(&Stamp {
|
|
ready_at,
|
|
generation,
|
|
})?;
|
|
fs::OpenOptions::new()
|
|
.write(true)
|
|
.create_new(true)
|
|
.mode(0o600)
|
|
.open(dir.join(READY))?
|
|
.write_all(&stamp)
|
|
}
|
|
|
|
pub(crate) fn read_regular(path: &Path, max: u64) -> Option<Vec<u8>> {
|
|
// Refuse links and devices. O_NONBLOCK also refuses to hang on a FIFO
|
|
// substituted between discovery and open.
|
|
let file = fs::OpenOptions::new()
|
|
.read(true)
|
|
.custom_flags(libc::O_NOFOLLOW | libc::O_NONBLOCK)
|
|
.open(path)
|
|
.ok()?;
|
|
let metadata = file.metadata().ok()?;
|
|
if !metadata.is_file() || metadata.len() > max {
|
|
return None;
|
|
}
|
|
let mut bytes = Vec::new();
|
|
file.take(max + 1).read_to_end(&mut bytes).ok()?;
|
|
(bytes.len() as u64 <= max).then_some(bytes)
|
|
}
|
|
|
|
pub(crate) struct Scope<'a> {
|
|
root: &'a Path,
|
|
days: Option<u32>,
|
|
}
|
|
|
|
impl<'a> Scope<'a> {
|
|
pub(crate) fn new(root: &'a Path, days: Option<u32>) -> Self {
|
|
Self { root, days }
|
|
}
|
|
|
|
fn identity(&self, dir: &Path, now: u64) -> Option<Id> {
|
|
if dir.parent() != Some(self.root)
|
|
|| dir.extension()? != "scrawl"
|
|
|| !fs::symlink_metadata(dir).ok()?.is_dir()
|
|
{
|
|
return None;
|
|
}
|
|
let stamp: Stamp = serde_json::from_slice(&read_regular(&dir.join(READY), 256)?).ok()?;
|
|
if self
|
|
.days
|
|
.is_some_and(|d| now.saturating_sub(stamp.ready_at) >= u64::from(d.max(1)) * DAY_MS)
|
|
{
|
|
return None;
|
|
}
|
|
Some(Id {
|
|
dir: dir.to_owned(),
|
|
stamp,
|
|
})
|
|
}
|
|
|
|
pub(crate) fn rows(&self, limit: usize, now: u64) -> Vec<(Id, u64, String)> {
|
|
let Ok(entries) = self.root.read_dir() else {
|
|
return vec![];
|
|
};
|
|
let mut ids: Vec<_> = entries
|
|
.flatten()
|
|
.filter_map(|e| self.identity(&e.path(), now))
|
|
.collect();
|
|
ids.sort_unstable_by(|a, b| {
|
|
b.stamp
|
|
.ready_at
|
|
.cmp(&a.stamp.ready_at)
|
|
.then_with(|| b.cmp(a))
|
|
});
|
|
ids.into_iter()
|
|
.filter_map(|id| {
|
|
let (_, manifest) = self.resolve(&id, now)?;
|
|
let preview = [
|
|
Some(manifest.transcript.text.as_str()),
|
|
manifest.note.as_deref(),
|
|
manifest.target.app.as_deref(),
|
|
]
|
|
.into_iter()
|
|
.flatten()
|
|
.map(str::trim)
|
|
.find(|s| !s.is_empty())
|
|
.unwrap_or("Annotate")
|
|
.chars()
|
|
.take(100)
|
|
.collect();
|
|
let ready_at = id.stamp.ready_at;
|
|
Some((id, ready_at, preview))
|
|
})
|
|
.take(limit)
|
|
.collect()
|
|
}
|
|
|
|
pub(crate) fn resolve(&self, id: &Id, now: u64) -> Option<(PathBuf, ScrawlBundle)> {
|
|
if &self.identity(&id.dir, now)? != id {
|
|
return None;
|
|
}
|
|
let bundle: ScrawlBundle =
|
|
serde_json::from_slice(&read_regular(&id.dir.join("scrawl.json"), 16 << 20)?).ok()?;
|
|
if !bundle.keyframes.is_empty() {
|
|
// The Annotate writer emits this name; never follow paths supplied
|
|
// by an edited manifest outside the bundle.
|
|
if bundle.contact_sheet != "contact-sheet.png"
|
|
|| !fs::symlink_metadata(id.dir.join(&bundle.contact_sheet))
|
|
.ok()?
|
|
.is_file()
|
|
{
|
|
return None;
|
|
}
|
|
} else if bundle.transcript.text.trim().is_empty()
|
|
&& bundle.note.as_deref().is_none_or(|n| n.trim().is_empty())
|
|
&& bundle.marks.is_empty()
|
|
{
|
|
return None;
|
|
}
|
|
Some((id.dir.clone(), bundle))
|
|
}
|
|
}
|