Skip to content

Issue #1773: plug-in host — import hooks that copy and convert, queued work, program.run, convert.toDng, library.import - #1859

Merged
emmertex merged 21 commits into
stagingfrom
plugin-host/step2-import
Dec 3, 2026
Merged

emmertex merged 21 commits into
stagingfrom
plugin-host/step2-import

Conversation

@emmertex

@emmertex emmertex commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

Fixes #1773
Part of #1771

Stacked on #1858 (plugin-host/step1-files); this PR's own commits are plugin-host/step1-files..plugin-host/step2-import.

Problem

Import hooks can neither copy nor convert a real raw: beforeImport has no scratch folder, only the first plug-in is asked, Auto Import never builds the hook, and long work would run on the session thread.

Change

  • importFiles: beforeImport gets tmpDir (per-import scratch, removed after) and attended; replies may be {replace, temporary: true}; every declaring plug-in is asked in install order, each seeing the previous answer; Auto Import builds the hook too. A replacement that fails to import falls back to the original (import warning + replacementFailed); sidecars and the companion JPEG are taken from beside the original. afterImport photos carry import {from, replacedFrom?, sidecars, companion}, files lent read-only.
  • jobSpawn: hooks queue work for the plug-in's job handler on the plug-in job thread, with an activity row and cancel; per-plug-in serial queue.
  • programRun: synchronous program.run, allowed in hooks only for programs marked hooks: true (the grant prompt says so).
  • convert: convert.toDng through the built-in DNG writer under the memory gate.
  • libraryImport: library.import {paths, mode, album?} without a from photo.
  • Plain (non-\\?\) paths handed to plug-ins on Windows; error texts keep their cause.
  • SDK example sdk/examples/convert-tools.

Not in this PR: A plug-in can't yet ask for no fallback ("fallback": false). Queued work holds catalog writes only from step 4 on (#1775's PR).

How it was checked

  • cargo xtask ci --quick on this branch, up to date with staging (merged in, not rebased): fmt, brand, docs,
    notes, i18n, windows, clippy, heif, stamp, parity, layers, assets and the wasm check pass. The test step
    fails on three lcc-ui-egui tests that are not touched by this stack and fail the same way on step 1 after
    merging staging:
    tests_pixel_shift::a_cancelled_pixel_shift_merge_leaves_no_file_and_no_photo (a sourceColour
    "Reading source colours" activity row from staging's own colour work is still open when the test looks),
    tests_pixel_shift::a_series_of_another_mode_is_refused_by_name_and_never_merged_as_16_shots, and
    tests_chart_profile::the_dialog_reads_the_chart_photo_and_suggests_a_name (passes when run alone).
    Every lcc-plugins test passes, and the full lcc-engine lib suite passes (3097 tests on step 2).
  • Tests that fail without the change, including hostile-input cases in crates/plugins/tests/{abi,robust}.rs
    for every new call (bad paths, huge lengths, bad handles, NaN/negative numbers).
  • App smoke over the control channel (Windows, debug build, scratch config and library) with the two first
    consumers installed: chromaforge-archive-copy and
    chromaforge-convert-on-import. Archive copy,
    hash mismatch, unwritable archive, retry, DNG conversion (built-in and an external stand-in), sidecars kept,
    fallback to the original and scratch clean-up all checked. Folder choices and grants were written into the
    scratch config (they can only be made by the user, by design), so the Choose…/Allow clicks were not driven.
  • Not run here: the #[cfg(unix)] link-swap and odd-name tests (Windows machine); the first unix CI run covers them.

Each step went through three independent reviews (crash safety, security/permissions, completeness against the
plan); every finding was fixed or answered.

Merging

Checklist

  • No new panic path in non-test code
  • New text on screen goes through tr() and has its key in every locale
  • LRC-SHELL-PLUGINS row and gap 19 updated in the same commits
  • Manual updated in the same commits (pages: automate/plugins.mdx, library/import.mdx)
  • New code has a caller (SDK example + tests; the two plug-ins above)
  • No new assets

🤖 Generated with Claude Code

emmertex and others added 21 commits December 1, 2026 23:51
…me, chunked writes, fs.copy)

Plug-ins that list "fsFiles" in `requires` get fs.stat, fs.read {path,
offset, length} (8 MiB a call), fs.freeSpace, fs.mkdir, fs.rename and
chunked atomic writes (fs.writeBegin / fs.writeChunk / fs.writeEnd: temp
file beside the target, synced and renamed at the end; open writes are
dropped with their temp files when the call ends). fs.copy {from, to,
expectHash?, overwrite} is a host-side verified copy with no size cap:
import_move::copy_verified (now with a watched variant counting bytes and
honouring a cancel flag) run as an io_sched job, never overwriting unless
asked. Time inside fs.copy is paused against the 120 s wall budget; in a
job it reports bytes to the activity row and stops on cancel.

Lent files are split into read/write and read-only lists; the
beforeImport hook now lends its file read-only (as the docs said).

SDK wrappers: host::list, stat, read, free_space, mkdir, rename,
write_begin/write_chunk/write_end, write_large, copy. Hostile-input
tests in tests/abi.rs and a fuzz case in tests/robust.rs.

Manual: none (docs/plugins.md updated; manual page, example, notes in the
step's docs pass)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Host features folderSettings and secrets. Manifest settings gain three
types, for settings only, never prepared, with no default and set only by
the user on the plug-in's Settings tab:

- folder {write?}: the chosen folder is granted as an fs root while chosen
  (stored as {path, write}; write no more than the field asks for now),
  checked like a manifest root (absolute, no "..", never a folder holding
  the app's settings or plug-ins); settings.get gives its path.
- host: the chosen host (a plain DNS name) is granted as a network host.
- secret: kept in the session's secret store under
  Key("plugin:<id>", key), never in settings/<id>.json, never shown, left
  out of settings.get; plugin.settings says only whether one is stored.

Chosen folders and hosts are listed with the plug-in's requests
(setting: <key>) and on the Permissions tab ("chosen in Settings",
Revoke clears the choice; plugin.revoke does too). settings.set and
plugin.setSettings may only clear them and refuse secrets; the control
channel's clicks on the new buttons change nothing.

New permission group secrets and host calls secrets.get / secrets.set /
secrets.delete (the plug-in's own secrets only; 16 KiB cap; set/delete
are writes), served by SessionHost, relayed from workers (Relayed::Secret,
not tied to the open library), jobs and program.end hooks. A locked or
missing store fails with what to do. Every secret value a plug-in read,
kept or had typed for it is redacted as [secret] in its log and call
errors for the session. Removing a plug-in with its data deletes its
secret settings' secrets.

UI: Settings tab rows for the three types (Choose.../Clear, Allow/Clear,
a password field with Save/Remove), localized in every language. SDK:
host::secret, secret_set, secret_delete, chosen_folder, chosen_host.
Docs: docs/plugins.md (Folder, host and secret settings; Secrets;
permission and SDK tables; feature names). Tests: abi (secrets, redaction,
grant, hostile requests, chosen folder grants, hostile choices, manifest
checks), compat (features, secrets group), robust (fuzzed secrets and
settings calls), engine (session store, relay, uninstall), ui (drawing).

Manual: none (docs/plugins.md updated; manual page, example, notes in the
step's docs pass)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tings and secrets

- docs/plugins.md: the copy hash is photo.inspect's `content_hash`; Engine commands
  say how plugin.settings / setSettings / revoke / uninstall treat the new setting
  kinds and secrets; the Permissions tab lists chosen folders and hosts; the
  settings file never holds a secret; "Not done yet" no longer claims hosts are
  fixed in the manifest, notes that a secret kept under the plug-in's own name
  outlives removal and that a job's fs.copy stops at once; ten examples.
- New SDK example sdk/examples/archive-tools (fsFiles, folderSettings, secrets):
  Copy to Archive (free space, mkdir, stat, verified fs.copy against the photo's
  hash, rename, chunked writes), Verify Archive (ranged reads), Server Status /
  Forget Session (chosen host, secrets get/set/delete, log redaction); driven
  end to end in crates/plugins/tests/example.rs.
- permissions.rs: every fsFiles call and secrets.* fail ungranted and work once
  allowed; a chunked write not ended is dropped.
- What's New and changelog entries; parity row LRC-SHELL-PLUGINS, gap 19,
  ROADMAP log and target-app-parity line updated (status unchanged).

Manual: automate/plugins, platforms/settings-and-privacy

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- fs.copy opens its source with open_checked and copies and verifies from
  that open file; the file it creates (or the temp file renamed over the
  target) must be in the target's own folder before any write and again
  before the rename, so a link swapped in after the check never reads,
  creates or replaces anything outside the roots (no after-the-fact
  remove_file any more).
- fs.copy's time is outside the wall budget only in a job; outside a job
  the copy stops when the call's deadline passes (CallContext::deadline).
- Secrets: the names a plug-in sets are listed in the store under a name no
  plug-in can use; uninstall (by id or file) deletes all of them; a locked
  store keeps a pending list, wiped before the id's next store use.
- Host settings are stored as {host}, so a value kept for a setting of
  another kind is never taken for the user's choice.
- plugins.chooseFolder takes a path only with the random token given to the
  picker it opened; the folder row and picker title say what is granted.
- group_label names secrets and libraryRemove, unknown groups by name.
- Parity change table back in date order.

Manual: automate/plugins

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The row added by #1732 (merged from staging) was painted in English in every
language; the i18n sweep failed after merging staging.

Manual: none, no user-visible change beyond the translation

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
beforeImport (host feature importFiles): every enabled plug-in with the
hook is asked in turn, each about the file the one before left, with
`mode`, `original` and `previous`; `tmpDir`, a per-import scratch folder
(a private run folder, one sub-folder per plug-in) lent read/write below
it and removed when the import ends. A reply may say `temporary: true`:
in a copying import the host deletes the replacement once its copy is
catalogued and the afterImport hooks have run (only for a file in tmpDir
or a folder the plug-in may write; refused when the import adds files
where they are). A replacement gone before the import reads it imports
the original. The app's Auto Import and camera-roll imports now build
the hook too (unattended: no program.start), as the docs said.

afterImport: each photo carries import {from, replacedFrom?, sidecars,
companion}; the photos' files and those are lent for reading. Neither
hook runs for a plug-in's own import (pluginHooks: false), so a hook
never re-enters the manager from library.add / library.import.

library.import {paths, mode?, album?} (permission and host feature
libraryImport): paths the plug-in may read (to move: write), checked and
resolved before anything is imported; no plug-in's import hooks; one
undo step; selection kept. Refused in prepare steps and jobs.

SDK: Request::original/import_mode/previous, imported_from,
replace_with, host::library_import. docs/plugins.md: Import hooks,
permission and SDK tables, feature names.

Manual: none

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Queued work (host feature jobSpawn): any call but a prepare step may
queue an item for the plug-in's job handler (hooks.job) with
job.spawn {label, state?} -> {job, queued}. Each item gets its activity
row when queued (kind pluginJob, cancel drops a waiting one); a
plug-in's items run in turn on a plugin-job worker of their own, as
jobs ({"hook": "job", "label", "state"}). Each {continue: state} reply
ends a slice: the call goes back to the manager before the next begins
(Manager::begin_spawned), and a hook arriving meanwhile (beforeImport,
afterImport, program.end, export hooks) waits for the slice boundary
and goes first instead of failing Busy (begin_hook; on the session's
thread it answers the slice's relayed requests while it waits). At
most 256 items per plug-in.

program.run (host feature programRun): program.start's checks, folder
and start, then it waits for the exit on the calling thread -> {code,
tmpDir}, the run folder lent for reading until the call ends. From a
command any granted program; from hooks and jobs only a program whose
entry says hooks: true, a standing grant (part of the grant: an entry
that adds hooks is no longer covered; the Plug-in Manager row says it
runs during imports and background jobs without asking), which also
loosens HOOK_NO_START for that program. In a job the wait is outside
the budget and cancel stops it; elsewhere the budget does. A stopped
wait leaves the program its folder and claim until it exits.

convert.toDng {path, out} (host feature convert): the app's DNG writer
(cmd::convert::write_dng_to) under the memory work gate; path readable,
out a new .dng where the plug-in may write; the raw read from the file
opened at its checked path, out's folder checked again; never over a
file, nothing left on failure.

Hostile-input tests: abi (labels, states, handler, program.run args and
files, convert paths), robust fuzz of the three calls, compat (features,
old grants without hooks), engine (queued work in slices with a hook
getting in, items in turn, hook program policy, a stopped wait,
to_dng on bad and cut-short raws). SDK: job::spawn, host::program_run,
host::convert_to_dng, Request::label. docs/plugins.md: Queued work,
program.run and hooks, Converting to DNG, tables, feature names.

Manual: none (plug-in author docs only; the manual page follows in the
step's docs pass)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ogram.run, convert.toDng and library.import

- docs/plugins.md: the `hooks` manifest field lists `job`; the examples
  table gains convert-tools (eleven examples); "Not done yet" says queued
  work is lost at quit, a waiting hook holds up its caller and gives up
  after ten minutes, convert.toDng can't be stopped, and outside a job
  program.run stops at the budget; a job's program.run wait stops at
  once on cancel.
- New SDK example sdk/examples/convert-tools (importFiles, convert,
  programRun, jobSpawn, libraryImport): beforeImport converts listed
  raws into the import's tmpDir with convert.toDng or a `hooks: true`
  program run to its end (result copied out with fs.copy) and replies
  with a temporary replacement, keeping the original in add mode and on
  failure; afterImport queues the converted photos (imported_from) for
  its job handler, which records each original in slices of ten; Import
  Inbox... runs library.import on a chosen folder. Driven end to end in
  crates/plugins/tests/example.rs.
- permissions.rs: program.run needs the program's grant and convert.toDng
  the folder's, like the calls they follow; job.spawn needs a handler,
  not a permission.
- Fork catalogs re-sorted (cargo xtask i18n --sort): the step's new keys
  were out of order and failed the i18n check.
- What's New and changelog entries; parity row LRC-SHELL-PLUGINS, gap 19,
  ROADMAP log and target-app-parity line updated (status unchanged).

Manual: automate/plugins

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nvert.toDng

- Queued work (job.spawn) runs with JobHost: relayed catalog, pixel and secret
  reads fail at once in a session nobody answers for and wait at most 60 s
  otherwise, so a headless slice can't hang and keep its plug-in busy.
- beforeImport replies: a replacement must be a file the plug-in may read; a
  moving import takes only one it may write (or in tmpDir); the file asked
  about or the original is never a temporary replacement, and neither the
  original nor the file imported is deleted as a dropped temporary.
- Temporary replacements the import doesn't catalogue (duplicates, failures,
  a failed commit, an error after commit) are deleted when the import ends.
- Hooks wait only for a running slice, and on the session's thread at most
  15 s per import or export; convert.toDng there waits at most 3 s for the
  memory work gate.
- A plug-in-job worker that unwinds takes its queue with it.
- program.run from any hook needs `hooks: true`; `attended` (new
  ImportOptions field, off for the library.import command) governs
  program.start only.
- beforeImport plug-ins are asked in install order (kept in plugins.json; an
  update keeps its place); `previous` of a failed plug-in is
  `{plugin, failed: true}`, the error text stays in the app's log.
- Plug-in Manager lists the libraryImport and libraryRemove permissions with
  their own labels.
- Fuzzing covers library.import; a table-driven no-panic test of
  beforeImport replies.

Manual: automate/plugins

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Manual: none, no user-visible change

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ack for replacements

- Windows: the run and scratch folders lent to plug-ins (tmpDir, program.* run folders) are
  plain paths, never verbatim \?\ ones where '/' is no separator (beforeImport replacements at
  {tmpDir}/name failed with os error 123). New lcc_plugins::paths: plain (dunce-style, only when
  the plain form names the same file), shown, from_plugin (a verbatim path sent back with '/'
  read as meant) and plain_in_text. Checks stay canonical internally; convert.toDng's path,
  library.import's paths, program.end's tmpDir and error messages are plain.
- Errors: fs errors put the cause first; host-call errors and activity reasons show plain paths;
  a long activity reason is cut in the middle so its cause stays.
- beforeImport carries "attended" (false for Auto Import, watched folders, tethering, camera
  roll, sync and library.import by agents or plug-ins); SDK Request::attended().
- A replaced file's XMP sidecar and companion JPEG are looked for beside the original (sidecar
  read, companion paired and taken along, afterImport import.sidecars reported from there).
- A replacement that passed the checks but fails to import falls back to the original (logged,
  no replacedFrom, a temporary replacement still deleted), in library.import and the app's
  streamed import alike.
- wasm: copy_verified_open and the open-file copy source are cfg-gated (no unused warning).
- ci --quick failures seen earlier on this branch, not caused by it (it touches neither):
  tests_color::one_field_wb_preset_gives_the_same_result_in_command_preview_and_import fails
  3 of 5 runs when run with its sibling one_field_wb_preset_apply_keeps_the_other_field_on_its_scale
  (which empties the process-wide DCP registries via NoInstalledProfiles) and 6 of 6 pass alone:
  it lacks that guard. headless::tests::adjustment_pixel_bounds_stay_fixed_across_texture_sizes_and_output_modes
  passes 4 of 4 alone and with its whole module; load-dependent. Both passed in this ci --quick.

Manual: automate/plugins (imports: fallback, sidecars, unattended); docs/plugins.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lain paths

- beforeImport replies: containment in tmpDir and identity checks compare canonical
  paths (a long name inside tmpDir keeps its verbatim form on Windows while the folder
  is plain); only the returned path is made plain.
- A replacement may not be another file the import found (FoundFiles, by name, whole
  import where known), nor stand in for two files (per batch in the hook, across
  batches in the job).
- Fallback: a replacement that fails to import gives back the companion JPEG it
  claimed and its pairing goes to the original (ImportJob::fell_back), so a Move
  carries the original raw and its JPEG together. Each fallback is an import warning
  (ReplacementFailed, own group in Import Warnings) and the afterImport origin names
  the replacement (replacementFailed; SDK ImportOrigin::replacement_failed).
- paths.rs: device names with superscript digits counted in characters; \?\C: stays
  verbatim (the volume); plain_in_text drops a prefix only when every place the path
  may end gives the same file (runs to a character no path holds, cut points judged).
- Test-only Fault::FailWriteMarked fails the copy of one marked file.

Manual: automate/plugins, library/import

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…import

Held job writes (#1811) and log sources (#1813) meet this branch's job.spawn,
library.import, secrets and fs work: command jobs' Holding host forwards fs.copy,
secrets, job.spawn, program.run, convert.toDng and library.import to the job's host;
library.import stays refused in a job; queued work (job.spawn) holds nothing yet and
says so; secret redaction applies to LogLine text.

Manual: automate/plugins (both sides' lines kept)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… order)

Manual: none, no user-visible change

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…om an earlier test

Staging's held-write tests call answer_requests, which marks the whole process as
answered; the queued-work test then waited a minute for a read nobody answers.

Manual: none, no user-visible change

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…un_presets' wasm warning

Manual: none, no user-visible change

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plug-in host step 2: import hooks, job.spawn, program.run, convert.toDng, library.import

1 participant