A share is a folder the hub serves on phux-share/1. Share keys and full-join satellites both dial that ALPN. The hub reads the live registry on every request. The owner socket also edits, moves, and searches that folder.
phux host ticket --share-only notes/docs --access rw
phux host join --share-only -
phux share pull notes/docs ./docs
phux share push ./docs notes/docs
pull and push dial the share uplink’s certificate on phux-share/1.
They do not open the owner socket and they do not send Command::Share.
A grant on a covers a itself and a/.... It does not cover A, ab,
or ab/x. An empty prefix covers the whole folder. That is
SharePath::covers: the prefix itself is inside the grant.
pull checks every name the hub returns before joining it onto the
destination. ../x and an absolute name are refused on the client. A push
that finds a newer revision writes name (conflict <time> <host>).ext
beside the file instead of replacing it.
read, write, edit, grep, and changes over the share channel check
the grant first. The folder store, edit/grep, and the changes feed are not
in this build: an authorized call returns not_yet_available (S04, S05, and
S06). It does not report success. A path outside the grant, or a write on a
read-only grant, is forbidden.
A [share] table lists the folders. enabled defaults to on;
enabled = false refuses the share channel and lists nothing. excludes
is re-read from that file on each share command and each scan tick, so an
edit applies without a restart. Each
[[share.entries]] folder needs a name and a path, and is read-write
for every machine whose satellite entry says link = "full", unless
joined or exclude says otherwise. That is not owner access. A share
key implies nothing else.
[[share.entries]] is the table of folders. [[share]] is deprecated in favour of [share] plus [[share.entries]]
with a required path. A v0.174.0 file still loads: each old entry keeps
joined and exclude, gets an empty path, and phux config check
warns. Rune 0.1.71 through 0.1.74 refuse settings edits once a config has
a [share] table, so update Rune after this release.
Owner-socket store
Local phux share create, ls, read, write, rm, and changes use
an owner-socket store. phux share create notes --path ~/phux-shares/notes
creates the directory and prints the entry to add; it does not edit
config.toml. A root cannot be the home directory or one of its parents,
a system directory, or inside .git. Empty legacy paths do not open a store.
These commands are distinct from pull and push on the share channel.
Paths
A path in a command is relative to that share’s folder. a//b, a/./b,
a trailing /, .., a leading /, NUL, and other control characters are
refused. So are the names the store uses itself, after ASCII case folding
and the characters HFS+ ignores: .phux-share and anything starting with
.phux-tmp-. .PHUX-SHARE is the same name on APFS.
A grant is compared one component at a time, as exact bytes, not as a
string prefix and not after case folding. A grant on a covers a/b and
does not cover A/b or ab/x. Case folding is only for the refusals
above. mv checks the source and the destination the same way.
The server opens the folder from / with openat(O_NOFOLLOW) on each
component, and holds that directory descriptor. A symlink swapped in for a
component does not redirect the read or the write.
Read and write
phux share ls notes lists the top of the share. Until a scan finishes,
it warns that the share is not baselined. phux share ls notes --prefix dir lists that directory. phux share read notes note writes
the bytes to stdout, repeating the read from the next offset until the
file’s size is covered. Revision, size, and hash are taken from the first
chunk. A later chunk that disagrees, a short or empty chunk before that
size, or a byte count that does not match it, is an error and writes
nothing. phux share write notes note reads stdin, and
--from FILE reads a file. --if-absent refuses when the name already
exists. phux share edit notes note --old OLD --new NEW replaces the one
occurrence of OLD. Zero occurrences, or more than one, are refused and
the file is left as it was. phux share mv notes from to moves a file.
phux share rm notes note removes a file, not a directory.
phux share restore notes note puts back the newest copy still in
.phux-share/trash. A removed file stays there for trash-ttl-secs
(one hour when the key is omitted). phux share grep notes PATTERN
searches file text. A write past write-rate-bytes in one
write-rate-window-secs is too_large and names that limit. A staged
upload older than an hour is dropped, and one caller can have at most
eight live stages. The share quota counts live files, those stages, and
trash once each.
A write creates a temporary file in the destination’s parent directory,
fsyncs the file, and renameats it onto the name in that same directory.
The directory is fsynced after the rename. A crash before the rename
leaves the old bytes in place. The temporary file is not in one shared
directory, so the rename does not cross devices.
--if-absent publishes with renameat2(RENAME_NOREPLACE) on Linux and
renameatx_np(RENAME_EXCL) on macOS. On any other Unix there is no
exclusive rename; the share’s lock is what keeps two writers apart. A file
with more than one name (nlink > 1), a symlink, or a fifo is not
replaced.
A path component . is invalid_path. src/. is not rewritten to src.
One request carries at most 64 KiB. A file is at most 8 MiB, which is also
max-file-bytes when that key is omitted. Raising it further waits on
append-only staging, because a staged upload rewrites one SQLite blob per
chunk. A write with
end: false stages bytes and does not publish them. The next write
continues at offset. All chunks of a multipart write must carry the same
upload_id; the CLI generates a fresh one per upload. Stages are separate
for each caller, share, and path. Each chunk is written at the end of that
upload’s temporary file. The bytes already there are not read back or copied.
An offset-zero write with end: true (the default) needs no upload ID.
Each published file has a revision. The share has one sequence number in
<state>/share/<name>.db, increased on each publish and each removal.
The database tables are files (path, revision, sha256, size, mtime,
inode), meta (the sequence), changes (the journal below), plus
staged_uploads and write_receipts. A repeated write with the same
--idempotency-key by the same caller to the same share and path returns
the first published answer without appending another journal row. The
idempotency key is independent of the upload ID.
Revisions
Each published file has a revision, starting at 1. A missing file is
revision 0. The share has one sequence number in
<state>/share/<name>.db. The sequence bump and the file-row change
commit in one transaction, on each publish, edit, removal, move, and
external change. The server holds one directory descriptor and one
database connection per share; a command does not open the folder again.
The tables are files (path, revision, sha256, size, mtime, mtime
nanoseconds, inode, and write or external), meta (the sequence),
and idem (credential, share, key, request hash, answer).
--base-rev N publishes, edits, or removes only when the file’s revision
is N. --if-absent publishes only when the file is absent. A mismatch
answers stale_revision with current_rev and current_sha, and the
file is unchanged. mv checks the source when --from-rev is set. The
destination must be absent unless --to-rev is its current revision. A
mismatch leaves both paths unchanged.
--idempotency-key is stored with the caller’s credential and the path.
phux share write sends the key on the publishing chunk. The same key
returns the first answer and does not publish a second revision, including
when a retry uses another upload id.
On access the server compares the file’s size, modification time, and
inode with the stored row. When any of them differ, it hashes the file
again and increases the revision. That revision is an external change, so
a later --base-rev sees it.
Grep
phux share grep notes PATTERN searches from the top of the share.
--prefix starts at that directory, or at that file. --fixed matches
the pattern as text. --context N keeps N lines before and after a
matching line. The answer holds at most 10,000 matching lines and 1 MiB
of path and line text. truncated is true when a cap stops the walk.
Names .git (every spelling the path check uses), node_modules,
target, .venv, and .env are skipped. A file larger than 8 MiB is
skipped unless --all. The walk reads each directory through the
descriptor of its parent and does not follow a symlink.
Change feed
phux share changes notes --after 0 --wait 60 returns journal rows whose
sequence is greater than --after. It answers as soon as one exists, or
with an empty list when --wait elapses. --wait is at most 60 seconds.
--limit is at most 1000 rows; the default is 100. --json prints the
answer. The next call passes the answer’s cursor as --after. That
cursor moves past rows the feed withheld.
A row is seq, path, op, rev, sha256, size, actor_credential,
and ts. ts is Unix time in milliseconds. op is create (the path
was not tracked yet), write (a publish replaced a tracked file), rm
(a removal through phux), or external (the scanner noticed a change).
edit and mv are reserved and this version does not emit them.
actor_credential is the caller’s credential id. It is empty for the
owner on the local socket, and empty for a row the scanner appended. A
credential with a share grant sees only paths that grant covers. A read
grant and a read-write grant both see those rows. A grant on another
folder, or on a prefix that does not cover the path, sees nothing, and
another caller’s credential id is blank.
The server keeps a row for 7 days or among the newest 100,000 rows,
whichever set is smaller. A cursor older than that is
cursor_expired, with oldest set to the smallest sequence still held
(or the share’s current sequence when the journal is empty). A cursor
ahead of the share’s sequence is the same answer. List the share again,
then resume with --after set to oldest - 1 so the oldest row is
included. The JSON field cursor is the sequence to pass as --after
next, including rows the feed withheld.
When at least one share is configured, the server walks it every 30
seconds and compares each file with the table. No shares means that timer
does not start. One pass journals its rows together. A tracked file whose
bytes changed, a file that appears after
the first walk, and a tracked file that disappeared are external. The
first complete walk records files phux did not write and does not journal
them. The walk does not follow a symlink. .git and .phux-share are
not reported. A path in the feed is a share-relative path; a row that is
not one is dropped. A credential that cannot call SHARE gets no rows. The owner principal
on the local socket is the only reader that sees every path and every
credential id. Any other principal, including a missing or unknown one,
sees only paths its grant covers, and nothing when it has no grant.
Dropping the connection abandons a wait. The wait does not remove rows.
MCP
phux mcp serves phux_share_ls, phux_share_read, phux_share_write,
phux_share_rm, phux_share_edit, phux_share_grep, and
phux_share_changes. They call the same client as phux share. While
[share] enabled is false, each tool returns share disabled.
phux_share_write with if_absent true creates a file. A base_rev on
write or edit reads the current revision and, when it differs, returns
stale_revision and current_rev. Applying that write waits on S05: a
matching revision returns not yet available and does not change the file.
Grep waits on S05. The change feed waits on S06.
A sandboxed agent is started with PHUX_SHARE_KEY set to a non-empty UTF-8
value. That process exposes the share tools only. An empty, blank, or
non-UTF-8 value refuses to start and does not fall open to the owner
catalog. PHUX_SHARE_KEY today only limits which tools are exposed. It
does not scope access until S07. Share-key mode currently sends
Command::Share over the owner Unix socket, with no credential check, and
it rejects a caller-supplied socket. The hand-off with mail and claims
is in agents.
Older builds
Config, UplinkConfigEntry, and the workload registry’s RegistryRecord
refuse unknown fields. An older phux that reads a config.toml containing
[share], or an uplink entry or registry record with a field it does not
know, rejects the whole file. It does not load the uplink client key or
any registry credential from that file. Share state stays in its own table
and its own database so a share write does not add a field to those
records. Adding [share] to a config file still means an older binary
will not start from that file until the lines are removed.