Skip to content

Issue #1776: plug-in host — background watches and timers - #1862

Merged
emmertex merged 45 commits into
stagingfrom
plugin-host/step5-background
Dec 3, 2026
Merged

emmertex merged 45 commits into
stagingfrom
plugin-host/step5-background

Conversation

@emmertex

@emmertex emmertex commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

Fixes #1776
Part of #1771

Stacked on #1861 (plugin-host/step4-publish); this PR's own commits are plugin-host/step4-publish..plugin-host/step5-background.

Problem

Nothing lets a plug-in run in the background: a hot folder or a periodic job needs the user to start a command each time.

Change

  • watch, timers: an engine-owned service beside folder_notify.rs (OS watch + interval fallback + the size-unchanged-across-two-scans rule); watch.start/stop/list, timer.start/stop; hooks watch (files lent) and timer, delivered like program.end, each with an activity row.
  • Started from a user command, persisted in plugins.json, resumed at start while the plug-in stays enabled and granted; listed with Stop in the Plug-in Manager.
  • SDK example sdk/examples/watch-tools.

Not in this PR: A lent file swapped for a link during a hook call is still readable for that call. watch_call resolves up to 1000 paths under the manager lock.

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)
  • New code has a caller (SDK example + tests; the two plug-ins above)
  • No new assets

🤖 Generated with Claude Code

emmertex and others added 30 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>
Request::body_reader(content_type, reader, len) sends a body of any size
read while sending (a file), with progress and the cancel flag, its
Content-Length promised: a reader shorter or longer than announced fails
the request. Like a multipart body it is never resent to a redirect.

Manual: none, no user-visible change.

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

Host feature httpFiles: http.request gains bodyFile (a readable or lent
file streamed by the host), multipart forms (text, base64 and file
parts, crates/net multipart), saveTo + overwrite (a 2xx answer streamed
to a file through a temp file, never half-written), responseBase64, the
response headers and a per-request timeout. Everything is checked before
anything is sent or written; a request with saveTo counts as a write.

A server certificate no public authority vouches for is reached once the
user trusts it: the new `certificate` permission group, "<host>
<fingerprint>", asked about like any permission from a command the user
started (Allow trusts it per plug-in and host through
Trust::with_pinned, Deny is remembered), listed on the Permissions tab
with Revoke and in plugin.list requests; never in a manifest, never
added by a command's grant.

In a job a transfer's time is outside the call's wall-clock budget, its
bytes show on the row and a cancel stops it; elsewhere the budget stops
it. SDK: host::http_request -> HttpResponse, http_send_file,
http_download, http_get_bytes, http_form with form_text/form_file/
form_bytes. docs/plugins.md: Network section, permission and SDK rows.

Manual: none yet (the step's docs pass updates automate/plugins).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lcc_webgallery::sftp::Session is one logged-in connection used from a
plain thread (it keeps its own single-threaded runtime), so a caller can
hold it across many operations: stat, list, mkdir, rename, remove_file,
remove_dir, write, and path-streamed upload (from any reader, through a
temporary name renamed into place, never over a file unless asked;
cancel removes the temporary file) and download (into any writer), each
with a progress callback that can stop it. connect_pinned takes any
number of pinned host keys; an unknown or changed key is a typed
ConnectError naming the fingerprint, and nothing is sent. The site
upload, check and remove helpers now run on it, unchanged for callers;
a build without the feature answers every call with "SFTP is not part
of this build".

sftp_testserver: an in-memory SFTP server on localhost (password and
key logins, files, folders, listings, renames) for this crate's, the
engine's and the plug-in host's tests.

Manual: none, no user-visible change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Host feature sftp: a plug-in with `sftp: [hosts]` in its permissions
(named as network hosts are, each allowed on its own) gets sftp.hostKey,
sftp.stat, sftp.list, sftp.mkdir (parents), sftp.rename, sftp.remove,
sftp.upload and sftp.download (files of any size streamed by the host,
never half-written, replaced only with overwrite). `server` is an upload
server the user saved with web.saveServer (its login, folder and pinned
key stay the app's) or {host, port?, user, path?, passwordSecret? |
keyFile?, passphraseSecret?}, the login one of the plug-in's secrets or
a key file it may read. Everything a call names is checked, and a file
to send opened, before connecting; one connection per server and login
is kept for the rest of the plug-in call (at most 4).

A host key must be trusted before anything is sent: pinned for the
saved server, or trusted by the user for the plug-in through the new
`hostKey` permission group ("<host>:<port> SHA256:..."), asked about
like any permission from a command the user started, listed on the
Permissions tab with Revoke and in plugin.list requests, never in a
manifest or a command's grant. An unknown or changed key fails naming
its fingerprint. In a job, connecting and transferring are outside the
call's budget, bytes show on the row and a cancel stops a transfer.
Without the engine's sftp cargo feature every call is an error.

Engine: plugin_sftp on lcc_webgallery::sftp::Session for every host
(SessionHost, RelayHost, HookSession, JobHost, HookHost; saved servers
relayed to the session's thread). SDK: the sftp module (Server, host_key,
stat, list, mkdir, rename, remove, upload, download). docs/plugins.md:
SFTP section, permission, feature and SDK rows.

Manual: none yet (the step's docs pass updates automate/plugins).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Host feature print: a plug-in with the `print` permission gets
print.printers (a CUPS server's printers), print.info (formats, paper
sizes and margins, the printer's own options), print.send (a ready-made
PDF or JPEG it may read, at most 256 MiB, checked to be what it says,
with copies 1-999, a job name and mediaType/mediaSource/printQuality/
sides) and print.status (a job's state), over the Print module's IPP
client. A printer is reached when it is on the local network
(localhost, .local/.home.arpa/.lan or dotless names, loopback, private
and link-local addresses) or on one of the plug-in's network hosts, so
`print` alone can't send files anywhere. Everything is checked and the
file read before anything is sent; print.send counts as a write and is
noted in the plug-in's log.

An ipps:// printer's certificate is trusted by the app's list (the Print
module's trusted certificates and trust-on-first-use) or by the user for
the plug-in through the `certificate` permission group, now also allowed
for local printers of a plug-in with `print`; untrusted, the call fails
naming the fingerprint and the user is asked from a command they
started. The plug-in's own trust is used for its requests only, never
added to the app's list. In a job the printer's time is outside the
call's budget.

lcc-print: printer_info_pinned / print_job_pinned (JobTicket) /
job_state_pinned / send_pinned take per-request certificate pins;
send::submit_document sends a ready-made document after asking the
printer for its formats and options; the virtual test printer answers
CUPS-Get-Printers. Engine: plugin_print for every host (SessionHost,
RelayHost, HookSession, JobHost, HookHost), tested on the virtual
printer. Plug-in Manager: the print permission row, in every fork
locale. SDK: the print module (printers, info, send, status).
docs/plugins.md: Printing section, permission, feature and SDK rows.

Manual: none yet (the step's docs pass updates automate/plugins).

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

- New SDK example sdk/examples/transfer-tools (httpFiles, sftp, print, with
  fsFiles, folderSettings, secrets, jobs): sends originals to a server as a
  form or a PUT (streamed, Location header read), fetches a file with saveTo
  (an error answer reported, nothing saved), reads a status as bytes with a
  timeout; checks an SFTP server's host key so the user is asked from a
  command, backs up over SFTP as a job (mkdir with parents, skip same size,
  upload, list) and restores a file; lists a CUPS server's printers and
  prints the selected JPEGs with copies and quality. Driven end to end in
  crates/plugins/tests/example.rs against an in-process HTTP server and
  fake SFTP and printer hosts.
- permissions.rs: http.request's new parameters, sftp.hostKey and the
  print.* calls fail ungranted and work once allowed; bodyFile, saveTo and
  multipart files need their folder besides the host; sftp and print are
  revoked like any group; host keys and certificates are trusted only by
  the user, never by a command's grant.
- docs/plugins.md: twelve examples (transfer-tools row), the missing comma
  in the feature names, the Permissions tab lists trusted certificates and
  host keys.
- Manual: uploads and downloads, server certificates, SFTP and printing on
  automate/plugins, trusted keys on the Permissions tab, twelve examples;
  settings-and-privacy and PRIVACY.md name printers on the local network.
- What's New and changelog entries; parity row LRC-SHELL-PLUGINS (paths,
  twelve examples), 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>
- SFTP replace never loses a file: Session::replace uses posix-rename@openssh.com
  when offered, otherwise moves the old file aside and restores it on failure;
  an upload that can't be put in place is kept at its .part name, named in the
  error. sftp.rename gains `overwrite` (a file at `to` is refused without it).
- sftp.list reads READDIR batches on a second raw channel, stops at the cap or
  after 4096 batches, and gives up after 60 s (a server that never says EOF).
- Saved upload servers are lent to a plug-in by name (new `savedServer`
  permission, asked about from a command, revoked on the Permissions tab); the
  lookup reads no credentials until a call logs in (never for sftp.hostKey), a
  host outside `sftp` is refused without naming it, paths stay inside the saved
  folder, and only the app's own pin is used (a changed key points to Trust
  Upload Server Host Key, no per-plug-in prompt).
- sftp_testserver is compiled only for tests (feature `test-support`, enabled
  from lcc-engine's dev-dependencies).
- print: dotless names and inet_aton numeric hosts (0x7f000001) are not local;
  with `print` alone only the IPP port 631 is reached; the printer host part
  stops at `/` and allows only host characters, the scheme is lower-cased, and
  the engine checks IppUri's host equals the checked one before sending.
  IPv6 printer certificates can be trusted per plug-in (cert_value normalizes
  IPv6 literals).

Manual: automate/plugins
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…transfer

# Conflicts:
#	crates/engine/src/cmd/plugins.rs
The test (from staging) uses the SONY ILCE-7M3 as a Kelvin camera and failed
when the whole lcc-engine lib suite ran in one process after another test had
installed the bundled calibrations; it now holds NoInstalledProfiles like the
other WB tests.

Manual: none, no user-visible change
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PublishService gains default begin(&RunInfo) and finish(&RunSummary).
Plan::execute calls begin once after the service opens (a failure fails
every photo of the run, removals included, and nothing is sent) and
finish once at the end, after a cancel too; finish follows only a begin
that succeeded. finish may answer a URL (returned as `url` by
publish.run); a finish error is a warning, the photos stay published.

Plug-in services declared with `publish.batch: true` (host feature
publishBatch) hear `publish.begin {service, account, collection,
counts: {new, update, remove}}` -> `{context?}` and `publish.end
{results: [{photo, remoteId?, removed?, error?}], cancelled}` ->
`{url?}`; the context goes with every publish.upload, publish.delete and
publish.end of the run. Replies are checked (context <= 64 KiB, url
1-2048 bytes without control characters); results are capped at 10,000,
each error at 1 KiB.

SDK: Request::context/run_counts/run_results/cancelled, RunCounts,
RunResult, publish_begun, publish_ended. sdk/examples/publish-folder
writes its index once per run in publish.end.

Tests: engine begin/finish order, cancel path, begin failure, finish
failure, plug-in batch service end to end; abi (requests carry counts,
results, context), compat (feature), robust (hostile begin/end replies),
unit tests for the reply checks, SDK accessors, example.

Manual: none, no user-visible change in the app (plug-in API only; docs/plugins.md updated)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- sdk/examples/publish-folder (requires settings, fsFiles, folderSettings,
  publishBatch): publishes into a gallery folder the user chooses on its
  Settings tab instead of a fixed /tmp root, copies renders with fs.copy (no
  8 MiB cap); publish.begin fails the run with "Choose the gallery
  folder..." when none is chosen and puts the folder in the run's context;
  uploads, removals and publish.end use it; publish.end folds the notes into
  index.json once per run and answers a file:/// address. The example test
  in crates/plugins/tests/example.rs now runs on every platform (was
  unix-only): begin failure, one index write, a context that grants nothing
  once the folder is no longer chosen, a cancelled run with a removal.
- permissions.rs: publish.begin / publish.end calls need their groups like
  any hook's (with nobody to ask they fail and say where to allow), and a
  context naming a folder grants nothing.
- docs/plugins.md: feature list comma, failed begin leaves removals queued,
  where a failed end's warning shows, each hook its own call, the context
  grants nothing and isn't kept, no publish.end after a quit or crash,
  the publish-folder row and paragraph.
- Manual: Publishing in one go on automate/plugins; plug-in services on
  output/publish-services.
- What's New and changelog entries; parity rows LRC-SHELL-PLUGINS and
  LRC-LIB-PUBLISH plus a history row, gap 19, ROADMAP log and
  target-app-parity line updated (status unchanged).

Manual: automate/plugins, output/publish-services

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Plug-in publish calls (upload, delete, comments, begin, end) run against a
  host that copies (`fs.copy` through plugin_fs::copy_file) instead of NoHost,
  so the publish-folder example's upload works in the app; an engine test runs
  publish.run through a plug-in that copies its lent render.
- Publish Now shows the run's warnings (a failed publish.end) in red and the
  address the service gave for the collection.
- SDK: Request::truncated for publish.end.

Manual: automate/plugins

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

#1775: merge staging (#1811 held job writes, #1813 log sources) into the
plug-in host work. Jobs refuse library.import along with the other unheld
writes; Holding passes every newer host call (fs.copy, secrets, job.spawn,
program.run, convert.toDng, SFTP, printing) to the job's own host; queued
work (job.spawn) holds its writes like a job and applies them when the item
ends; log lines keep their source and are still redacted of secrets.

Manual: automate/plugins (Remove and Log tab bullets merged)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Host features `watch` and `timers`: `hooks.watch` / `hooks.timer` in the
manifest and the host calls `watch.start {id, path, recursive?, patterns?}`,
`watch.stop`, `watch.list`, `timer.start {id, everySeconds}` (raised to at
least 5 s, at most a week) and `timer.stop`. Starting is for a command's
call only; the path must be a folder below a readable root. What a plug-in
runs is kept with its plugins.json entry (read leniently, checked on load)
and resumed at start while it is enabled and, for a watch, the folder is
still granted (Manager::background_plan); plugin.list shows it with its
state, and plugin.stopBackground stops one.

An engine-owned service (crates/engine/src/plugin_background.rs, its own
thread, attached by the session that answers relayed requests) runs the
plan: OsWatch (now recursive on request) says when to look, polling covers
folders without notifications, and a file is handed over once two looks
agree on its size and time. `{"hook": "watch", "watch", "path", "files"}`
(files lent for reading, up to 1000 a call) and `{"hook": "timer"}` run on
a worker with a `pluginBackground` activity row, catalog requests relayed
as for program.end.

Tests: abi (calls checked, command-only start, persistence, plan, lent
files, requests), compat (features), robust (hostile calls and
plugins.json), unit tests (patterns, settling, timers, hostile folders),
engine end-to-end (watch delivered, timer row, revoke).

Manual: none, no user-visible change in this commit (the Plug-in Manager part follows)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The plug-in's page lists the folders it watches and the timers it runs
under "In the background", running or why paused, each with Stop
(plugin.stopBackground). Strings and the activity labels translated in
every language. SDK: background::{watch, stop_watch, timer, stop_timer,
list}, Request::{watch_id, watched_files, timer_id}, WatchedFile.
docs/plugins.md: Background work section, tables, engine command.

Manual: automate/plugins

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- sdk/examples/watch-tools (requires settings, fsFiles, folderSettings,
  watch, timers): Watch Inbox watches the inbox chosen on its Settings tab
  with the patterns and subfolder setting; its watch hook reads each lent
  file's first bytes (fs.read) to tell raw, JPEG and HEIF apart and notes it
  in inbox-pending.tsv; Start Inbox Report runs a timer whose hook folds the
  notes into inbox-report.txt; Background Status lists, Stop Watching stops
  both. Wired into crates/plugins/tests/example.rs: nothing chosen, start,
  plan, resume from plugins.json, an empty turn, two watch calls and two
  reports, stop.
- permissions.rs: watch and timers ask for no permission of their own;
  watch.start needs its folder readable (asks for the manifest root, refuses
  outside every root, a chosen folder setting counts while chosen); a revoked
  or no longer chosen folder pauses the watch, kept.
- docs/plugins.md: pattern limits (1-128 characters, no / or \), the 10,000
  files a watch holds for its hook, the watch-tools row and paragraph.
- Manual: automate/plugins (when a file is handed over, what is left alone,
  window-only; thirteen examples).
- What's New and changelog entries; parity row LRC-SHELL-PLUGINS (evidence,
  notes, history row), 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>
- watch_call: refused unless the plug-in may still read the folder where
  it leads now; lends only regular files (not links) whose real place is
  inside it, UTF-8 names only, by that real place; no json! on a PathBuf
  (a non-UTF-8 name panicked the hook worker under the manager lock).
- list_files: leaves out non-UTF-8 names; refuses a watched folder that
  now leads elsewhere (swapped for a link); says when a look was cut off.
  A cut-off look reports nothing and forgets nothing, so old files in a
  huge folder are never handed over as new.
- Each look runs on a thread of its own (taken within SCAN_WAIT or at a
  later tick): a hung share holds up no other watch or timer.
- The plan is taken under the manager lock and its folders checked after
  it is released; plugin.list shows the state without a filesystem look.
- A watch whose folder is away for now (a card out, an unreachable share;
  Windows' verbatim prefix) stays planned and is retried, not dropped.
- Relayed requests and background hooks wake the window (set_waker), so an
  idle window answers a background hook's catalog requests.

Manual: automate/plugins (a watched folder away for a while keeps its watch)

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

# Conflicts:
#	docs/parity-checklist.md
emmertex and others added 15 commits December 2, 2026 17:36
…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>
Brings step2's review fixes and its staging merge up: held job writes and LogLine
logs meet this step's http, sftp and print calls (a command job's Holding host
forwards sftp.* and print.*; tests read LogLine text).

Manual: none beyond step2's

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Step2's review fixes come up. This branch's own staging merge already holds queued
work's writes like a job's and has the forget_answered test helper, so those parts
keep this branch's versions; docs and the parity rows keep both sides (newer staging
rows, publish run hooks, attended and replacementFailed).

Manual: none beyond step2's

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

Step2's review fixes come up through step3 and step4; the docs keep this branch's
watch and timer rows with attended and replacementFailed added, and the parity row
takes the newer staging wording.

Manual: none beyond step2's

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 5: background watches and timers

1 participant