Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: re-export the handoff predicate to the client instead of mirroring it

[._.]/ Adam Eivyca8ae92e7bd3
diff --git a/client/src/lib/README.md b/client/src/lib/README.md
index da1614c7f8..26ddbc75aa 100644
--- a/client/src/lib/README.md
+++ b/client/src/lib/README.md
@@ -119,7 +119,7 @@ grep -i "what you want to do" client/src/lib/README.md
| Module | Purpose |
|---|---|
| `a11yKeyboard.js` | `clickableProps(handler, { role?, disabled? })` → `{ role, tabIndex, onKeyDown }` and `onActivateKeyDown(handler)` — make a non-`<button>` element with an `onClick` keyboard-accessible (Enter/Space activation, focusable, `role="button"`). Spread `clickableProps` next to the existing `onClick`. Use instead of hand-rolling `role`/`tabIndex`/`onKeyDown` on clickable `<div>`/`<span>`/`<li>`. Also the shared predicate every app-global key handler consults: `shouldIgnoreGlobalKey(event, { enabledInDialog?, ignoreRepeat?, allowChords? })` — the single "must this handler stand down?" answer (editable target, native Space button activation, ⌘/Ctrl/Alt chord, OS auto-repeat, open `aria-modal` dialog), used by `useKeyboardShortcuts`, `useKeyCapture` AND the voice widget's push-to-talk hotkey so their guard lists can't drift. Add a new guard there, not at one caller. Its parts are exported too: `isEditableTarget(el)`, `isButtonActivation(event)` (true when Space would natively activate the focused button) and `isPressKey(event)` (Enter or Space by either `key` or `code`). Also `isFocusEscapeKey(event)` — the shared "leave this widget" gesture (Shift+Tab backtab) that a key-capturing widget must release to the browser; the Shell terminal's `attachCustomKeyEventHandler` consults it so focus can escape the xterm trap. Plus `noPointerFocusSurfaceProps` — spread on the ROOT of a surface that owns a key globally (a Space-scored drill, the Morse keyer, RapidReader, the OpenWorld HUD); one capture-phase handler stops a mouse click anywhere inside from parking focus on a button and taking that key over via native activation, covering controls added later too. |
-| `agentOutcome.js` | Mirror of `server/lib/agentOutcome.js` (pinned by its `agentOutcome.parity.test.js`): `isAgentHandoff(agent)` — `result.resumed === true` — tells a record retired to hand its task to a continuation, a Resume or a provider Relaunch, from one that reached a verdict. Cards reading `result.success` alone rendered a red "Failed" run for a swap the user made deliberately, and the needs-feedback filter asked them to rate it. Adds `agentHandoffReason(agent)` (client-only): `metadata.pauseReason` before `result.error`, because on a Relaunch the pause reason names what the USER changed while `result.error` holds the resume summary, which says where the TASK went. Mirrored rather than imported so the browser bundle never pulls the server closure in for one predicate. |
+| `agentOutcome.js` | Re-export of `server/lib/agentOutcome.js`: `isAgentHandoff(agent)` — `result.resumed === true` — tells a record retired to hand its task to a continuation, a Resume or a provider Relaunch, from one that reached a verdict, and `agentHandoffReason(agent)` gives the line such a card should show. Cards reading `result.success` alone rendered a red "Failed" run for a swap the user made deliberately, and the needs-feedback filter asked them to rate it. Imported rather than copied so the run card and the daily report cannot disagree about whether a swap was a failure. |
| `agentResumeOutcome.js` | `agentResumeMessage(result, messages, fallback)` — the toast wording for a CoS agent resume/relaunch result. The server answers with a `mode` (what it did to the task) plus `spawned`/`spawnHold` (whether it also STARTED it — a resumed task is force-spawned when a slot is free, and `spawnHold` names the refusal when it isn't). `messages` is keyed by mode as `{ queued, running? }`; a mode with no `running` variant is one that deliberately queues nothing, so it can never be reported as started. Shared by the Resume dialog (`cos/tabs/AgentsTab.jsx`) and `cos/tabs/RelaunchAgentModal.jsx` so neither can say "queued" for a run that already started, or omit the reason it didn't. |
| `appIdentity.js` | `PORTOS_APP_ID` — stable id of the baseline PortOS app. Re-exported from `server/lib/appIdentity.js`; dependency-free so a module reachable from a server test can import it. |
| `applyManuscriptEdits.js` | `applyEditsToContent(content, edits, anchorQuote)` — PREVIEW-ONLY client mirror of the server's accept splice (`server/services/pipeline/manuscriptFix.js`): locate each `find` (nearest the anchor when recurring), drop overlaps, replace bottom-up. Powers the Manuscript editor's whole-manuscript impact preview. |
diff --git a/client/src/lib/agentOutcome.js b/client/src/lib/agentOutcome.js
index 9dc176d3c4..4ffbc117c0 100644
--- a/client/src/lib/agentOutcome.js
+++ b/client/src/lib/agentOutcome.js
@@ -1,49 +1,9 @@
/**
* Is a completed agent record an OUTCOME, or a handoff to its own continuation?
*
- * Client mirror of `server/lib/agentOutcome.js` — same contract, same key, and
- * pinned to it by `server/lib/agentOutcome.parity.test.js`. Read that file for
- * why the rule exists; the short version is that Relaunch (and Resume) retire the
- * old record with `success: false` and requeue the SAME task, usually because the
- * user swapped providers after a CLI hit a usage limit. Surfaces that render
- * `result.success` alone therefore showed a red "Failed" run for a swap the user
- * made deliberately, and the feedback prompt asked them to rate it.
- *
- * Mirrored rather than imported: `client/src/lib` must not reach into the server
- * tree (a client-side import of a server module pulls its whole closure into the
- * browser bundle and into every suite that renders one of these cards).
- */
-
-/**
- * True when this record was retired to hand its task to a continuation run
- * (Resume / Relaunch) rather than because the run reached a verdict.
- *
- * STRICT equality on purpose — see the server copy for why.
- */
-export function isAgentHandoff(agent) {
- return agent?.result?.resumed === true;
-}
-
-/**
- * The one line a handoff card should show: WHAT THE USER CHANGED.
- *
- * When a continuation was actually queued (`resumedTaskId`), `metadata.pauseReason`
- * wins: on a Relaunch that is the sentence the user is looking for ("Relaunched by
- * user on codex / gpt-5"), while `result.error` holds `resumeAgent`'s summary,
- * which says where the TASK went rather than why this run stopped.
- *
- * With no continuation the order flips. `retireStrandedPausedAgents` also stamps
- * `resumed: true` — on a pause whose task was deleted or moved on — and there the
- * pause reason is the ORIGINAL one ("Paused by user"), which would read as a
- * deliberate provider swap for a run that was simply abandoned. `result.error`
- * ("Pause retired — its task … no longer exists") is the honest line.
- *
- * Client-only: nothing server-side renders it, and keeping it out of the mirrored
- * half is what keeps the parity test a one-line contract.
+ * Re-export of `server/lib/agentOutcome.js` — the one definition of the rule,
+ * imported rather than copied so the run card, the daily report and the weekly
+ * digest cannot drift on whether a provider swap was a failure. The file stays so
+ * every `lib/agentOutcome` import path in the client is unchanged.
*/
-export function agentHandoffReason(agent) {
- const error = agent?.result?.error;
- const pauseReason = agent?.metadata?.pauseReason;
- const handedOn = !!agent?.result?.resumedTaskId;
- return (handedOn ? pauseReason || error : error || pauseReason) || 'Handed off to a new run';
-}
+export { isAgentHandoff, agentHandoffReason } from '../../../server/lib/agentOutcome.js';
diff --git a/server/lib/README.md b/server/lib/README.md
index e8a2ca23cc..35e445979a 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -51,7 +51,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `spriteChromaKey.js` | Chroma-key selection color math (`CHROMA_KEYS`, `CHROMA_KEY_HEXES`, `DEFAULT_CHROMA_KEY`, hue-distance picking). Pure color math, no image I/O — that lives in `services/sprites/normalize.js`. |
| `spriteAnimationTracks.js` | The animation-track registry (`ANIMATION_TRACKS`, `WALK_TRACK`, `TRACK_BOUND_TRIPLES`, `AUTHORED_TRACK_FIELDS`) — a zero-import table of per-track frame/fps bounds. |
| `spriteAnimationTrackStore.js` | The EFFECTIVE track table — compiled built-ins plus the user-defined store read from one small JSON config, so sprite schemas stay module-load constants rather than lazily-built. |
-| `agentOutcome.js` | Is a completed CoS agent record an OUTCOME, or a HANDOFF to its own continuation? `isAgentHandoff(agent)` — `result.resumed === true`, what `resumeAgent`/`relaunchAgent` stamps when it retires a record and requeues the SAME task, typically because the user swapped providers after a usage limit. Every consumer that read `result.success` as the verdict booked a phantom failure per swap — a red history card, a failed task in the daily report and weekly digest, a dented success rate, a quota-burn denial recorded against "Relaunched by user", a feature agent flipped to `error` — so the rule task-learning already applied lives here once. Reads only `result`, so `completeAgent`'s stats writer can ask it before the record exists. Keyed on a field `resumeAgent` has always written, so archived relaunches reclassify retroactively with no migration. Mirrored at `client/src/lib/agentOutcome.js`, pinned by `agentOutcome.parity.test.js`. |
+| `agentOutcome.js` | Is a completed CoS agent record an OUTCOME, or a HANDOFF to its own continuation? `isAgentHandoff(agent)` — `result.resumed === true`, what `resumeAgent`/`relaunchAgent` stamps when it retires a record and requeues the SAME task, typically because the user swapped providers after a usage limit. Every consumer that read `result.success` as the verdict booked a phantom failure per swap — a red history card, a failed task in the daily report and weekly digest, a dented success rate, a quota-burn denial recorded against "Relaunched by user", a feature agent flipped to `error` — so the rule task-learning already applied lives here once. Reads only `result`, so `completeAgent`'s stats writer can ask it before the record exists. Keyed on a field `resumeAgent` has always written, so archived relaunches reclassify retroactively with no migration. Also carries `agentHandoffReason(agent)` — `metadata.pauseReason` when a continuation was queued, else `result.error`, so an abandoned run is not captioned as a deliberate provider swap. `client/src/lib/agentOutcome.js` re-exports this file rather than copying it. |
| `agentOutputMarkers.js` | Status lines PortOS itself appends to an agent's output buffer: `SENTINEL_COMPLETION_MARKER` (the line `ingestDoneSentinel` writes just before the agent's `.agent-done` summary) plus `isAgentLifecycleLine(line)`/`stripLifecycleLines(lines)`, which match PortOS's telemetry on its actual message shapes rather than on a leading emoji (an agent's own summary may well start a line with `✅`). Pure — shared by the emitter (`services/agentTuiSpawning.js`) and by readers that must show only the agent's own words (notably the generated PR description). |
| `agentRunEvents.js` | CoS run lifecycle-event envelope (#4540) — pure half of the append-only ledger in `services/agentRunEventLog.js`. `AGENT_RUN_EVENT_KINDS` (closed vocabulary: spawned, handoff, output, reconnected, paused, resumed, interrupted, pr-verified, orphan-recovered, runner-recovered, finalized), `agentRunEventSchema` (Zod, `.strict()`), `buildRunEvent()` which redacts then mints a CONTENT-derived `eventId` (sha256 of the canonicalized envelope) so a redelivered lifecycle transition dedupes instead of double-counting, `redactRunEventData()` (drops prompt/description/output/result-class keys to a `{ redacted, chars }` stub, scrubs the home-dir prefix out of every remaining string via `scrubHomePath`, runs `redactOutput`, and caps string/array/key/depth per `RUN_EVENT_LIMITS`), and `projectRunStates()` — the clock-free fold that derives current run status from the ordered stream, so replay-after-restart and read-current-status are one code path. Unknown kinds fold as no-ops so a newer install's ledger replays on an older one. |
| `agentRunReconcile.js` | CoS run reconciliation (#4540) — pure diff between a ledger projection (`projectRunStates`) and the durable run record. Closed finding vocabulary `RUN_RECONCILE_FINDINGS` (`record-open`, `record-missing`, `verdict-mismatch`, `ledger-open`), `diffRunRecord()`, `reconcileRunRecords()` with a zero-filled per-kind summary, and `planRunRecordRepair()` — the metadata patch that closes a record the ledger proves is finished. Repairs are one-directional (ledger → record) by design: a record closed while the ledger missed the close is reported, never back-filled, so the stream stays an audit of the record rather than a copy of it. I/O half: `services/agentRunReconciler.js`. |
diff --git a/server/lib/agentOutcome.js b/server/lib/agentOutcome.js
index a9eefc0d94..c6c5769151 100644
--- a/server/lib/agentOutcome.js
+++ b/server/lib/agentOutcome.js
@@ -41,3 +41,28 @@
export function isAgentHandoff(agent) {
return agent?.result?.resumed === true;
}
+
+/**
+ * The one line a handoff card should show: WHAT THE USER CHANGED.
+ *
+ * When a continuation was actually queued (`resumedTaskId`), `metadata.pauseReason`
+ * wins: on a Relaunch that is the sentence the user is looking for ("Relaunched by
+ * user on codex / gpt-5"), while `result.error` holds `resumeAgent`'s summary,
+ * which says where the TASK went rather than why this run stopped.
+ *
+ * With no continuation the order flips. `retireStrandedPausedAgents` also stamps
+ * `resumed: true` — on a pause whose task was deleted or moved on — and there the
+ * pause reason is the ORIGINAL one ("Paused by user"), which would read as a
+ * deliberate provider swap for a run that was simply abandoned. `result.error`
+ * ("Pause retired — its task … no longer exists") is the honest line.
+ *
+ * Lives here beside the predicate even though only the client renders it: this is
+ * the file the client re-exports, and splitting the pair would put half the
+ * contract back in a copy.
+ */
+export function agentHandoffReason(agent) {
+ const error = agent?.result?.error;
+ const pauseReason = agent?.metadata?.pauseReason;
+ const handedOn = !!agent?.result?.resumedTaskId;
+ return (handedOn ? pauseReason || error : error || pauseReason) || 'Handed off to a new run';
+}
diff --git a/server/lib/agentOutcome.parity.test.js b/server/lib/agentOutcome.test.js
similarity index 76%
rename from server/lib/agentOutcome.parity.test.js
rename to server/lib/agentOutcome.test.js
index 9c79ef00e7..b7e4cc4060 100644
--- a/server/lib/agentOutcome.parity.test.js
+++ b/server/lib/agentOutcome.test.js
@@ -1,21 +1,15 @@
/**
- * The handoff predicate, and cross-package parity for its client mirror.
+ * The handoff predicate and the line a handoff card shows.
*
- * `server/lib/agentOutcome.js` is the source of truth; `client/src/lib/agentOutcome.js`
- * is a hand-maintained copy, because the client must not import out of the server
- * tree. Both are pure, so ONE table runs against BOTH and a copy that drifts fails
- * here instead of quietly letting the run card disagree with the daily report about
- * whether a provider swap was a failure.
- *
- * It lives server-side, like the repo's other parity suites, because the server
- * runner can load the pure client module but not the reverse.
+ * No parity suite: `client/src/lib/agentOutcome.js` re-exports this module rather
+ * than copying it (the one-way client→`server/lib` edge the repo allows for a pure
+ * leaf), so there is only ever one implementation to test. A server test may not
+ * import client source — `scripts/server-imports-no-client.test.js` freezes the
+ * legacy cross-imports and refuses new ones.
*/
import { describe, it, expect } from 'vitest';
-import { isAgentHandoff as serverIsAgentHandoff } from './agentOutcome.js';
-import { isAgentHandoff as clientIsAgentHandoff, agentHandoffReason } from '../../client/src/lib/agentOutcome.js';
-
-const IMPLEMENTATIONS = [['server', serverIsAgentHandoff], ['client', clientIsAgentHandoff]];
+import { isAgentHandoff, agentHandoffReason } from './agentOutcome.js';
// The record `resumeAgent` retires when Relaunch swaps providers mid-run: it
// carries `success: false` and a summary in `error`, because the pause/requeue
@@ -47,13 +41,13 @@ const CASES = [
['undefined', undefined, false],
];
-describe.each(IMPLEMENTATIONS)('isAgentHandoff (%s)', (_side, isAgentHandoff) => {
+describe('isAgentHandoff', () => {
it.each(CASES)('reads %s as %s', (_label, record, expected) => {
expect(isAgentHandoff(record)).toBe(expected);
});
});
-describe('agentHandoffReason (client-only)', () => {
+describe('agentHandoffReason', () => {
it('prefers the pause reason when a continuation was actually queued', () => {
// `result.error` there is `resumeAgent`'s summary — "task … requeued on
// <branch>" — which answers a question nobody asked while looking at the run