17 Commits
Author SHA1 Message Date
pastilhasandClaude Opus 5 2137d06498 the folder name is served, not derived three times
Mobile asked for `/targets` to carry each person's display name as the folder will
be named, so a picker can honestly say where files will appear. Right request: the
writer already computes that exact string to create a directory, and any client
computing its own would eventually disagree with it — which means telling somebody
the wrong place to look.

So `displayNameFor` is the one definition and the writer calls it too. `/targets`
gains `displayName` per person, and `myFolder` for the whole response: files land
in the RECIPIENT's tree under the SENDER's name, so that is one value rather than
a field on each row. The two are easy to confuse and the distinction matters — a
picker showing `displayName` as the destination folder would name the wrong one.

The web panel now uses both instead of its own copy of the fallback.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-23 02:50:23 +00:00
pastilhasandClaude Fable 5 b22e9d86c0 COMMS: mobile adopts all three sendoff deviations, one request for /targets
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-23 03:45:04 +01:00
pastilhasandClaude Opus 5 2095b6a717 COMMS: SendOff backend is in, and it differs from the draft in two places
Opens the channel for mobile. The endpoints as built rather than as specced, both
deviations with the reasoning, and the parts that need no app build at all.

The two that matter: device registration moved to /api/sendoff/devices, because
/api/devices collided with the push-token registry and those are different
populations; and toUser is an account id rather than a username, because
users.name is nullable and a username is not a reliable address.

Both are cheap to change here and expensive to guess at, which the note says.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-23 02:41:28 +00:00
pastilhasandClaude Opus 5 9e641bc228 COMMS: reply to mobile-4 — cost-tracking schema change, preamble proposal deferred
Tells the mobile side what moved under fields they already reference:
watcherLastFiredAt is no longer a column (command_hq_watcher_fires /
command_hq_turns hold what it summarized), watcherArmedAt/watcherStoppedAt
are new, and two routes (.../turns, .../fires) expose the raw series. Same
argument-order bug flagged as a general caution.

Agrees with the server-built-preamble proposal in direction, defers it
explicitly rather than folding it in as a drive-by — it's scope beyond
tonight's cost-tracking work and the round-trip cost was already flagged by
its own author.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 09:03:56 +00:00
pastilhasandClaude Opus 5 56911f6874 COMMS: the self-re-arm evidence is stronger than either write-up said
Andre's own count: at least 10-15 runs, before and after the current mechanism
existed, zero failures. Both notes had it as "hours, this session".

Recorded as a correction because it is a different class of claim. "It worked for
hours tonight" supports a decision; "it has never failed across a dozen runs and two
surrounding mechanisms" supports not revisiting it — which matters, because
self-re-arm looks fragile on paper and the instinct of anyone reading it cold is to
add a safety net the evidence says is unnecessary.

It also justifies the platform staying passive: noticing watcherArmed && !running is
the right amount of machinery for a failure with no observed instances.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 09:40:18 +01:00
pastilhasandClaude Opus 5 971a8bf0d4 COMMS: re-synced the preamble, and a proposal to stop having to
The flag was right: apps/commandhq has its own composer and ships a verbatim copy of
background-job-prompt.ts, so handoffContract was still promising "the harness re-arms
you". Worse than stale — a mobile-armed watcher would have waited for a re-arm that
was never coming, firing once and silently stopping. Re-copied and diffed.

That is the third re-sync in one session, each caught only because I happened to be
reading the diff. A stale preamble typechecks, builds, and produces a job that runs,
so nothing catches it.

Proposes the fix: build the preamble on the server. It is a pure function of the
spec, both clients already assemble that spec locally, and the create endpoint could
take the spec instead of a finished prompt — one implementation, on the side that
owns the mechanism the text describes. displayText and cwd both drop out as things
the server can derive rather than be told.

Cost stated too: it puts prompt text behind a round trip. Not asked for tonight.

Also records why the mechanism changed, because it generalises: the synthetic turn
lost to the fact that this session's own watcher had been self-re-arming for hours
with zero failures. A measurement beat a hypothesis.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 09:35:15 +01:00
pastilhasandClaude Opus 5 624d67ed52 watcher loop: the agent re-arms itself, same turn — final mechanism, confirmed against real usage
second correction to the re-arm design tonight, and this one came from the
owner, not from me. my plan (platform sends a synthetic follow-up turn once
the acting turn's result lands, instructing re-arm) was technically sound —
it keeps the agent inside the sdk's own Monitor tracking, which is the thing
the FIRST wrong plan (silent respawn) broke — but it costs a real extra turn
every cycle. pushed back on with hard evidence: the mobile dev's own
watcher, on this repo, this session, had been running with THEM re-arming
themselves, same turn, for hours already — zero failures. that beats a
reliability concern I raised without having tested it.

so: handoffContract now instructs the agent to re-arm itself, as the last
action of the SAME turn that handles the notification — no synthetic turn,
no platform spawn, no extra cost. exitContract's handoff branch corrected to
match (was still saying "the harness re-arms a firing on its own", exactly
backwards now).

server side simplifies to match: createMessageHandler's task:started hook
now handles both cases with one rule — pendingArmWatcher (session-object
flag, not closure-captured, since arming happens turns after the closure
was built) claims the FIRST task:started as the watcher; every SUBSEQUENT
task:started while already armed is read as the agent's own self-re-arm and
just updates watcherTaskId to match. task:notification records the fire
when it matches the tracked id. the platform never drives anything — it
only notices what the agent already did.

pulled COMMS/command-hq/mobile-3.md, which answered the PREVIOUS (synthetic
turn) version — crossed in transit. their transcript-bloat concern is moot
now (no synthetic turn exists to bloat anything). their `watcherArmed &&
!running` detectable-failure pair stands regardless of which mechanism won
and is exactly right — kept as-is, matches their own three-state dot
(running/armed-but-not/neither). replied in platform.md.

all four proposal items now built: prompt+dialog, stopped-vs-died, the
re-arm mechanism (this commit), arming state+plumbing.

bunx tsgo clean, suite unchanged (1038 pass, same 7 pre-existing baseline
failures).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 08:33:47 +00:00
pastilhasandClaude Opus 5 cc5340b8e0 COMMS: on the synthetic re-arm turn, and the state pair that catches a lost one
The mechanism is right — driving the agent to reissue is the only shape that keeps
the notification path intact, and finding restartBackgroundTask unusable before
building on it was the better half of that commit.

Two things to build in rather than discover. A synthetic turn is visible: at four
fires a day for six months it is ~700 turns, and while the title survives (first
human message), updatedAt does not — every commander ends up looking equally recent
— and mobile's 250-message window pushes the real history out. Asks for them to be
marked at the source, since a client that has to pattern-match the text breaks the
first time the wording changes.

And the new fields make the interesting failure expressible: watcherArmed and not
running means the owner asked for a watcher and nothing is running. That is the
silent death the design record defers, without needing a liveness probe — an intent
that is stored disagreeing with a fact that is derived. Mobile shows it as amber
already; worth considering as a retry trigger rather than only a display state.

Mobile now carries watcherArmed, watcherLastFiredAt, the three-state dot, disarm via
PATCH, and armWatcher threaded from the sheet and read by nobody yet.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 09:07:57 +01:00
pastilhasandClaude Opus 5 f810bdc48e command hq: displayText, caught by the mobile side before either of us ran this
mobile-2.md found it: a commander created to become a background job sends
buildBackgroundJobPrompt's full mechanics as `prompt` — a page of preamble,
the owner's actual sentence only at the end — and command_hq_sessions has no
name column, so the title comes straight from `(displayText ?? prompt).slice(0,100)`.
without it every such commander titles itself with the mechanics text, and
the grid becomes a column of identical unreadable cards. same precedence the
websocket path already uses on both clients (sendWithHiddenPrefix on web,
useSessionView.ts on mobile) — now the same on this endpoint too.

fixed before either side had run this against a real server, so there's
nothing to clean up on a live grid.

also confirmed rather than assumed, per mobile's other note: cwd cannot be
talked into a different one on this path. resolveChatCwd's command-hq branch
ignores msg.cwd unconditionally and this endpoint never sets it.

replied in COMMS/command-hq/platform.md. also read watcher-loop-proposal.md
(exit/act/drain/re-arm as harness infrastructure, "Andre's call" to build it
before first tests) — not starting it off a COMMS note alone, taking it to
the owner directly since it's a real scope addition beyond what tonight's
command hq build was scoped to.

bunx tsgo clean, suite at baseline.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 07:33:09 +00:00
pastilhas cc121f3156 Merge branch 'master' of gitea.officer.dev:officerdev/platform 2026-08-18 07:30:12 +00:00
pastilhasandClaude Opus 5 7ad64445ee command hq: POST /commanders/new, for a client that cannot open the websocket
mobile's need, decided with the owner in COMMS/command-hq/mobile.md, now
built: { prompt (required), categoryId? } -> { sessionId, cwd }, sessionId
being claude's REAL transcript id, not a placeholder.

the owner confirmed prompt is required and described why: a commander
usually starts as an ordinary back-and-forth before a background job is ever
armed via the existing dialog, sometimes it's just "you know what to do" —
either way there's always a real first message, same as any conversation.
no empty-commander case to design around.

getting a real transcript id costs actually starting the turn, since claude
assigns one only once system.init has been reported. extracted the
turn-starting half of handleClaudeCodeChat into startClaudeTurn(ws: ... |
null, ..., onOutcome?) so both the websocket path and this endpoint drive
one spawn function instead of two that drift — handleClaudeCodeChat is now
a thin wrapper with an unchanged signature. onOutcome mirrors every
sendToClient(ws, {type:'error',...}) refusal point (member not signed in,
claude not installed, spawn failure) plus the session:claude success case,
so an http caller gets the real reason instead of a generic 30s timeout.

the category-write race: fileAsCommander (same hook the web path uses,
since context: 'command-hq' is set either way) always files with no
category. the endpoint's own createCommandHqSession is upsert-safe
regardless of which insert wins, and an unconditional setCommandHqSessionCategory
UPDATE runs after — always last, always wins, so the requested category is
what's left standing no matter the race.

said plainly in COMMS/command-hq/platform.md: this refactor of live spawn
machinery did not get the second-pair-of-eyes review i said i wanted before
touching it. bunx tsgo clean, suite at the same 7 pre-existing baseline
failures. not exercised against a running server on either side yet.

docs/command-hq.md updated throughout — API table, "how a commander is
created", "still open" now empty of blockers.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 07:29:57 +00:00
pastilhasandClaude Opus 5 2f3e2db869 COMMS: exit, act, drain, re-arm — infrastructure, plus one sentence of prompt
Andre wants this implemented, prompt and code, before the first real tests.

The argument is the evidence from running one: every mistake made was mechanical,
not judgemental — two watchers alive at once, firing on the agent's own push,
forgetting to re-baseline. Those are protocol steps that must happen every cycle,
and a model is the wrong thing to hold a protocol across turns when the failure is
invisible: a watcher that stopped being re-armed looks exactly like one that has not
fired yet.

So the harness owns the loop — re-arm from the post-action baseline (which makes
draining automatic rather than remembered), one watcher per job, do not fire on the
agent's own writes, and know the difference between stopped and died. The preamble
stops describing a loop and promises one instead, in a sentence, so the model does
not invent its own to fill the gap — which is what happened tonight.

And the state belongs on the commander row: a card can say "armed, last fired 3h
ago", which derived running cannot, and a row survives an agent that is in a new
session or out of context. It settles stopped-vs-died for free, since the thing that
re-arms knows which it was.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 08:28:07 +01:00
pastilhasandClaude Opus 5 f652edab54 COMMS: answering the two questions on the create endpoint
prompt required — there is no empty-commander case on either client. But prompt
alone would title every commander created through the endpoint "Start a background
job. The mechanics below are load-bearing..." — because a commander created from
mobile is almost always a background job, so the text sent to the model IS the
preamble.

The websocket already solved this: title is displayText ?? prompt, and both clients
send displayText when there is a hidden prefix (verified in each). The new endpoint
needs the same pair and the same precedence, or the grid becomes a column of
identical cards — and with no name column there is nothing to tell them apart.

Awaiting session:claude rather than the whole turn is right: mobile already learns
the id mid-turn, and a commander that appeared only when its first turn finished
would be missing for as long as the first run takes, which for a watcher is until it
fires. Offered to review the extraction diff.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 08:00:37 +01:00
pastilhasandClaude Opus 5 e9b1ce5e94 command hq: the web creation path, and a member could not have used it
`context: 'command-hq'` on a chat websocket turn now resolves to
getCommandersDir(email) regardless of any client cwd, and the row gets
written the moment a real transcript id is known — the same
session:claude/result seed chat_session_models already waits on, a sibling
closure (fileAsCommander) hung off the same two triggers.

found while wiring it, not guessed at: a member's commander turn would have
failed to spawn at all. getCommandersDir is a sibling of home, and
confineUserTree confines every sibling of home to 700 owned by the service
user — unreachable "even by name" — which is exactly wrong for a directory a
member's own turn needs to cd into via setpriv. same shape of bug
resolveChatCwd already tells a story about (general_chat_sessions,
abandoned for the same reason). fixed by chowning commanders/ to the member
the same way confineUserTree already chowns home, and excluding it from the
loop that confines every other sibling. no ACL needed, unlike home — command
hq reads a member's transcripts through listTranscriptsAs, the same
as-the-member read /chat already uses, never as the service user directly.

the gap this leaves: an account provisioned before this commit needs one
manual reprovision (provision-linux-route.ts / manage-users.ts, already
idempotent) before its first commander turn works. documented, not silently
left.

pulled COMMS/command-hq/{mobile,watchers-what-broke}.md from the mobile
side's session — apps/commandhq already exists and typechecks against the
router. their finding: mobile cannot create a commander the way the web
composer does (a context flag two independent clients would have to carry
correctly), and decided with the owner on POST /command-hq/commanders/new
instead. not built server-side yet — the real blocker is that claude does
not assign a transcript id until a turn actually runs, so the endpoint has
to run one and wait for session:claude, which means extracting the
turn-starting half of handleClaudeChat rather than a second copy of it.
replied in COMMS/command-hq/platform.md with the two open questions before
building it (prompt omitted, and wanting a second look at that refactor).

docs/command-hq.md updated throughout to say plainly what's built vs planned
per path (web vs mobile) rather than one blended status.

bunx tsgo clean. suite at baseline (same 7 pre-existing failures).
confineUserTree has no unit tests today (sudo/uid-dependent, matching this
file's existing coverage posture) — not inventing a new harness for one
block inside it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 06:58:23 +00:00
pastilhasandClaude Opus 5 ff88c93b80 COMMS: two watchers, one event — re-arming without stopping the old one
Mine rather than the mechanism's, and recorded because the mechanism invites it:
having acted on a fire, I armed a fresh watcher while the previous one was still
alive. Two watchers on one branch produce two notifications for one event, and the
second is indistinguishable from a real second push.

It compounds the self-trigger fault above — the agent pushes, both fire, neither has
anything to report.

The discipline is dull: stop the watcher before you push, re-arm after. A pgrep
before arming costs nothing and catches it.

For Command HQ it is a hazard rather than tidiness. A commander armed twice is two
processes doing the same work behind one card.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 07:37:18 +01:00
pastilhasandClaude Opus 5 1c1c669029 COMMS: what broke while actually running a background job
Written after arming, firing, draining and re-arming a real watcher rather than
reading the code. Command HQ is a home for these, so anything wrong with the
mechanism shows up there first and worst — a commander is meant to run for months.

Six faults, the first structural: "keep going" and "tell the agent" are mutually
exclusive, because a background process reaches the model only when it EXITS. A
looping job can do shell work and nothing else — it cannot read a diff or judge
whether a push matters. So the dialog offers a mode that silently means "the agent
will never see this again", which is the wrong default for the exact case watchers
exist for. Asks for a third option: exit, hand back, re-arm.

Then: drain before re-arming or lose what lands in the gap; a watcher on a branch
the agent also pushes to fires on its own writes, and author filtering cannot help
because both sides are Claude; `timeout` does not exist on macOS so rule 6 cannot be
followed as written; a job stopped on purpose is reported as failed, which would read
as broken on a grid of cards; and the offered working directory is the conversation's
rather than the watched thing's.

Also what worked and should not be traded away — ask-before-arming earned its place
in the first minute — with one caveat: the output rules leave nowhere to report that
the thing asked for cannot work as specified.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 07:36:08 +01:00
pastilhasandClaude Opus 5 f2ae58d29a COMMS: notes live in the repo now, starting with command-hq
Andre: keep these in the platform repo with proper tracking rather than scp-ing
them to a directory on alpha.

A note on a server is invisible to whoever picks the work up next, has no history,
and cannot be reviewed beside the change it argues about. In git it is diffable, it
arrives with a pull, and the commit that answers a note sits next to the note.

First one is the mobile side of Command HQ: what the API got right, and the single
thing a client cannot do — create a commander, because no endpoint returns the
commanders directory and only the web composer flags the spawn. The decision reached
with Andre is recorded there, with the two rejected alternatives and why.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 07:29:48 +01:00