Commit Graph
32 Commits
Author SHA1 Message Date
BFlat e698aa01df Merge pull request #2613 from dotCooCoo/feat/control-protocol-new-token
craft-control-protocol: generate session tokens that valid_token accepts
2026-11-28 11:47:50 +07:00
BFlat cb73a0aadf Merge pull request #3965 from dotCooCoo/fix/control-server-test-clock
craft-control: the server tests wait on its signals and a clock they move instead of on time
2026-11-28 11:35:18 +07:00
BFlat 794d2a1c1d Merge pull request #3956 from dotCooCoo/fix/control-client-tests-handshakes
craft-control: the client tests hold the app's answer on a gate instead of sleeping
2026-11-28 11:34:57 +07:00
dotCooCoo f62b70ed4f craft-control: the restart test waits for the stopped listener to free its port
`Stop::stop` returns after at most two seconds whether or not the
listener has closed. On a loaded machine the listener can still hold the
port then, and `hold` bound it once and failed with AddrInUse. `hold` now
retries the bind for up to two seconds, as the earlier `serve` helper did.
The new test `holding_a_port_waits_for_the_listener_on_it_to_close` binds
a port while a listener holds it and fails without the retry.
2026-11-27 19:46:45 -08:00
dotCooCoo 7b29a321a5 control: the launch tests run on a test clock and wait on the calls instead of on time
LiveConfig takes the clock and the sleep its launch wait uses (Instant::now
and std::thread::sleep unless a test changes them), and a hook that each
resolve calls once it has noted how many starts have finished, before it
waits for the lookup. All three are hidden from the docs.

The four launch tests in tests/agents.rs no longer depend on how fast the
machine runs:

- A launch that never finishes advances the test clock by each poll, and
  the test checks that the wait polled until the 40 ms timeout passed.
- Concurrent calls: the app accepts agents only after all four calls have
  queued and the start has begun, instead of 60 ms after the start.
- Calls behind a failed start: the start returns once all four calls have
  queued, instead of after a 5 s poll and a 250 ms sleep, and the 150 ms
  timeout passes on the test clock.
- A huge timeout or poll: the test records each sleep, checks that the
  poll is cut to 1 s, and checks that an app that never accepts agents
  gives up after 600 polls with "within 600 s", instead of checking that
  the call took less than 5 s.

The file's wait_for helper, which polled for up to 5 s, has no caller left
and is removed.
2026-11-27 17:44:57 -08:00
dotCooCoo b353e7c314 craft-control: the server tests cover the events thread's seat and fail without the leave signal
- A new test runs the events thread on a socket that takes no more
  writes while another share of the seat stays held, publishes once,
  and waits for the thread to end. It checks that the failed write
  alone ended the thread and that the watch counts nobody.
- wait_until_nothing_runs fails when a wait runs out its ten seconds,
  so the cancel and timed-out tests fail when Listing::drop does not
  notify. Before, the wait rechecked the list after the timeout and
  passed once the request had left without telling it.
2026-11-27 17:32:19 -08:00
dotCooCoo d1c8f31ec9 craft-control: the server tests wait on its signals and a clock they move instead of on time
Six tests in crates/control/src/server.rs decided their results on the
wall clock: a 500 ms token limit with a 50 ms drip and a lower bound on
the elapsed time, a 100 ms request wait with control.pending polled
every 10 ms, watch seats polled after a 200 ms sleep, and a stopped
listener checked against a 3 s bound with a 2 s rebind loop.

- The token deadline reads a Clock (Hub::with_clock, Instant::now by
  default). The token test moves a clock of its own past the limit and
  past three limits of idling. A silent connection still closes on the
  socket's read timeout, with no bound on how long that takes.
- Running notifies a Condvar when a request leaves the list, which
  happens once its reply is with control.pending. The cancel and
  timed-out tests wait on that instead of polling. Only the two requests
  the test window holds take the short wait, which is zero, so they time
  out at once and every other request waits for its reply.
- The watch tests wait for the connection's own thread to end, then
  check the seat is gone.
- Stop::stop waits for the listener to close its port once its wake-up
  connection was made. Before, it returned after 2 s even when the
  listener had not closed the port yet. It still waits at most 2 s when
  that connection cannot be made. The listener test binds the port once
  after stop() returns. Its connection shows the token first, so only the
  stop can end it, and the elapsed-time bound is removed.
2026-11-27 17:07:16 -08:00
dotCooCoo 178bae9175 craft-control: the client tests hold the app's answer on a gate instead of sleeping
The client tests' app answered each request after a sleep, and the server
reported a request as still running after a short real wait, so the two
still-running tests passed only when the 400 ms sleep outlasted the 20 or
50 ms waits. The app now holds each answer on a channel the test opens:
the server reports the request as still running at once, the pending test
opens the gate from the client's progress report and checks that the
report came, and the past-the-wait test opens it after the call returns.

The serve helper took a port and retried the bind for up to 2 s with
10 ms sleeps. It now takes a listener. The test that stops the app and
starts it again holds the port bound, without listening, from the stop
until the app is back, and then listens on that same socket, so the port
is bound once and no other listener can take it meanwhile.
2026-11-27 16:52:08 -08:00
dotCooCoo f7d6305ee8 control: the agents switch tests drive its polls instead of waiting on time
AgentSwitch::watch_with takes a tick function in place of the poll
interval: the watch thread calls it before each poll and ends when it
returns false. AgentSwitch::watch passes one that sleeps POLL, so the
app polls as before.

The tests the_switch_wakes_once_per_change in craft-control and
craft-automation polled every 5 ms, waited up to five seconds for each
step and slept 20 to 100 ms to check that the watch had ended. They now
run each poll through a channel and wait for the thread to finish it,
so they count probes and wakes exactly: one probe per poll, one wake
per change, and no poll after the last switch is dropped.
2026-11-27 15:41:55 -08:00
aiongg 4190dfde1a Merge remote-tracking branch 'upstream/main' into next-into-main-2 2026-11-26 11:03:37 +00:00
FredApps caf0433554 Merge branch 'main' into codex/control-client-not-running-fixture-2223 2026-11-26 10:19:25 +01:00
aiongg ecdc221f4a Merge next into main 2026-11-26 05:38:41 +00:00
dotCooCoo 4a41cbc244 control: re-export control-protocol's new_token instead of a second copy
craft_control::server::new_token is now a re-export of
craft_control_protocol::new_token, so the crate keeps one session-token
generator. The signature and path are unchanged. craft-control no longer
depends on getrandom directly.
2026-11-25 19:37:22 -08:00
BFlat e1c27c729f Merge pull request #2643 from dotCooCoo/fix/control-shared-line-reader
craft-control: the server reads request lines with craft-control-protocol's bounded reader
2026-11-26 10:27:26 +07:00
BFlat 7e92cb2f6d Merge pull request #3120 from dotCooCoo/fix/control-line-reader-behavior
craft-control: the server's line reader frames request lines as craft-control-protocol's does
2026-11-26 10:26:22 +07:00
dotCooCoo 1418db7abe control: a token file create that owner_only timed out takes the timed-out path
owner_only now ends a whoami or PowerShell run after 10 seconds and
returns ErrorKind::TimedOut. create_within treats that error, when it
arrives before its own 10-second wait ends, the same as a create it
stopped waiting for: a CONTROL_DIR folder gets no token and the default
folder gets the file with that folder's access list. Before, the
default folder returned the error and got no token file.
2026-11-24 15:26:47 -08:00
dotCooCoo 1798f485a2 control: the token file is private from the moment it is created
On Windows, write_token_file_with created the control token file with
create_new, so the file started with its folder's access list, and only
then ran icacls to restrict it to the user. Another local account that
the folder lets read new files could open a handle in between, and that
handle keeps its read access after the list changes, so it could read
the token once it was written.

On Windows the file is now created with
craft_platform::owner_only::create_private_file under a name of its own
beside the token file: the user and SYSTEM are the only entries from the
call that creates it, and the token is written through that handle. The
finished file then takes the token file's name through a hard link, so
a token file another launch wrote meanwhile is kept and this write
fails, as create_new did. The discovery file (current.port) is renamed
into place instead, so the latest launch replaces it.

The create runs on its own thread and is waited for at most 10 seconds,
as icacls was waited for 5. When it does not finish in time, a folder
named by the app's CONTROL_DIR gets no token, the default folder gets
the file with its own access list, as before, and the late file is
removed when the create finishes. While such a create is still running,
later writes start no create of their own and take the timed-out path
at once. Unix keeps mode 0600 at create.
2026-11-24 11:04:30 -08:00
dotCooCoo 21f4e14f3b Merge fix/control-line-reader-behavior into fix/control-shared-line-reader
The behavior changes to craft-control's line reader and the \r\n fix in
craft-control-protocol now come from that branch. With it merged, this
branch only replaces the server's reader and client::outcome with
craft-control-protocol's, and the reader tests stay as they are.
2026-11-22 15:51:51 -08:00
dotCooCoo 960d2508ed craft-control: the server's line reader refuses a line past the cap in the read that ends it
craft-control's server reads request lines with its own reader. It now
frames lines as craft_control_protocol::read_bounded_line does:

- A line longer than max_line is refused even when its newline arrives
  in the same read. Before, the limit was checked only between reads,
  so such a line was accepted. A last line past the limit with no
  newline is refused too.
- A \r before the newline is dropped from the line and does not count
  toward the limit.
- A read interrupted by a signal is retried instead of closing the
  connection.
- A read that would block reports TimedOut.
- The refusal names the limit: "request line longer than N bytes;
  closing the connection" instead of "request too large".
2026-11-22 15:51:15 -08:00
dotCooCoo 8a13f644db craft-control-protocol: the line cap does not count the line's \r\n
read_bounded_line read at most max + 1 bytes, so a line of exactly max
bytes followed by \r\n stopped after the \r and was refused, while the
same line followed by \n was read. It now reads up to max + 2 bytes,
strips the \n and a \r before it, and then checks the line against max.
A line of max + 1 bytes is still refused with either ending.
2026-11-20 14:46:45 -08:00
yoriswind d7b37a2f11 Apply repository import ordering to control fixture 2026-11-20 12:08:23 -08:00
dotCooCoo 17ba68ff57 craft-control: read request lines with craft-control-protocol's bounded reader
The server's private line reader is replaced by
craft_control_protocol::read_bounded_line, and client::outcome now
returns craft_control_protocol::reply_result. craft-control and
craft-control-protocol read the same request framing with one reader.

Behavior changes in the server's reader:
- A line longer than the server's max_line is refused even when its
  newline arrives in the same read. Before, the limit was checked only
  between reads, so such a line was accepted and up to one buffer past
  the limit was allocated.
- A read interrupted by a signal is retried instead of closing the
  connection.
- A \r before the newline is dropped from the line.
- The refusal names the limit: "request line longer than N bytes;
  closing the connection" instead of "request too large".
2026-11-20 11:29:47 -08:00
yoriswind 1baedb164b test(control): disambiguate the socket protocol type 2026-11-20 09:30:16 -08:00
yoriswind b175f61fda test(control): hold a non-listening port reservation 2026-11-20 09:26:00 -08:00
yoriswind fdd3e35b6a test(control): retry ports taken by a competing listener 2026-11-20 09:18:28 -08:00
David MannandClaude Opus 5.5 1929e79ebb Merge storytold main into next (20 Nov, second sync)
Merges main at 8f92ed1334 (#2550 and the rest of main since the 20 Nov sync).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 16:38:55 +01:00
David MannandClaude Opus 5.5 f9ebae49c0 craft-control agents: default agent folder in Documents and the agent_folders tool (#2548)
An empty agent folder setting meant no file access, so an agent reached
through the launcher's MCP entry could neither open nor save a file, and
nothing told it where to put files.

- default_folder(app): Documents/ArtCraft/Agents/<App> (dirs::document_dir,
  else ~/Documents), only for plain app names.
- AgentSettings::folders / folders_with: the person's own folders win; an
  empty setting falls back to the default, created on first use.
- The live client's headless sessions use it (LiveConfig::default_folder).
- FOLDERS_TOOL, folders_tool, folders_answer: the tool each app offers so an
  agent learns the folders it may use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:00:40 +01:00
David MannandClaude Opus 5.5 6195b126d2 craft-automation: re-export the agents code from craft-control (#2390)
craft_automation::agents kept its own copy of the agent settings, the
launcher's switch and the connection file beside craft_control::agents.
It now re-exports craft-control's (and with it the CLI's live client)
and keeps only the egui link host. The Agents page is unchanged.

Callers see two API changes: AgentSwitch::watch takes a closure
instead of craft_host::Wake, and the connection functions return
std::io::Error. AgentSettings is #[non_exhaustive] in another crate
now, so the trials set fields on a default instead of using struct
update syntax.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 15:14:26 +01:00
David Mann 6b16ec2b41 craft-control agents: second review round (#2141)
- The token is passed on as the app wrote it (trimmed): craft-control's
  server compares exactly and accepts any CONTROL_TOKEN of 32+ chars.
  The token file is checked as a regular file before it is opened (a
  FIFO would block the open).
- Allow Agent Control off counts as not allowed on the CLI's side too.
- A window route is dropped once no app accepts agents.
- A headless session with the app's agent folders ends when the person
  stops letting agents in.
- The launch timeout is capped and the deadline computed without
  overflow; the poll interval is kept between 1 ms and 1 s.
- The connect error names the app's window; the guide says to remove
  the connection file on quit and that one process per settings folder
  accepts agents; the AppImage mount is compared after resolving links.
- Tests for each, and a wider margin in the queued-start test.
2026-11-18 03:19:07 +01:00
David Mann aa0f72303c craft-control agents: review fixes (#2141)
- Calls queued behind a start that failed get its error instead of
  starting the app again; a later call retries.
- The started process is reaped on a thread of its own.
- APPIMAGE counts only when the CLI runs from that image's mount.
- The guide names allow_agent_control as part of the listen condition.
- A watcher thread that can't start leaves agents off.
- The watcher test waits for the thread to end instead of a fixed sleep.
2026-11-18 02:53:47 +01:00
David Mann b837aa22dc craft-control: agents in the open window for apps on main (#2141)
The ArtCraft Launcher's switch (AgentSwitch, mcp_flag, launcher_allows),
the agent settings, the connection file (agent-connection.json) and the
<id>-cli mcp side that finds the open window (Live: window while the app
accepts agents, otherwise headless or the closed-app choice; launcher
starts the app beside the CLI), behind the new feature agents. No UI
toolkit and no async runtime. Same formats as craft_automation::agents
on next, which can re-export these once the branches meet.
2026-11-18 02:35:58 +01:00
Dylan M. Taylor 472956a8d7 feat: add craft-control (control channel protocol) (#1879)
* feat: add craft-control (control channel protocol)

Port from solidcraft: the control channel any app may share, no UI toolkit.
- Per-launch token files (32 random bytes, user-only permissions)
- Loopback server with token-based authentication
- Client that talks to the loopback server
- Request/response types (ControlRequest, ControlResponse)
- Document watch for subscribed connections waiting on changes
- Effect type for requests still running when they finish

Desktop-only (wasm32 excluded): uses getrandom for token generation.
No external dependencies beyond serde and serde_json.

* fix: update test directory names from solidcraft-control to craft-control

* Record control crate dependencies in workspace lockfile

* re-trigger CI

* chore(lock): keep the wasm-bindgen family at the version main's runners install
2026-11-16 09:55:33 -05:00