Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion FORK.md
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ migrations after upstream migrations.

113. Metro doesn't watch a worktree's `.j5code` folder ([#964](https://github.com/Jacksondr5/j5code/issues/964)). `apps/mobile/metro.config.js` watches the whole workspace and blocks only upstream's `.t3` state folder. J5's dev and test homes live in `.j5code`, so every server write there reached Metro's watcher and showed React Native's "Refreshing…" banner. One more `blockList` entry, beside upstream's, blocks it. Release bundles also go through Metro, but nothing the app imports lives in `.j5code`, so the entry only changes what the dev watcher reacts to. On a pin advance: if upstream moves or renames its `.t3` entry, keep `.j5code` beside it.

114. Mobile roster review for a Captain's Crew proposal ([#836](https://github.com/Jacksondr5/j5code/issues/836), Jackson's decisions 1 and 2 of 2026-11-07/08: a phone approves, declines and removes seats, showing each seat's access; other edits stay on web). `apps/mobile/src/features/threads/ThreadDetailScreen.tsx` mounts J5-owned `J5ComposerControls` (`apps/mobile/src/j5/composer/`) beside case 49's `PlaybookComposerControl`, under the same conditions; every J5 row above the composer joins there, not as another seam. Its first row, `CrewRosterStrip` (`apps/mobile/src/j5/crew/`), shows one row per open, human-approved proposal for the thread and opens the `ThreadCrewProposal` screen, which case 98's `j5ThreadRoutes` spread registers. The gate filter, seat lines, playbook notes and preview binding live in `packages/client-runtime/src/j5/crewProposals.ts` (a new `./j5/crew-proposals` export in `packages/client-runtime/package.json`), shared with web's card; approval sends only the token from a complete preview of the seats on screen.
114. Mobile roster review for a Captain's Crew proposal ([#836](https://github.com/Jacksondr5/j5code/issues/836), Jackson's decisions 1 and 2 of 2026-11-07/08: a phone approves, declines and removes seats, showing each seat's access; other edits stay on web). `apps/mobile/src/features/threads/ThreadDetailScreen.tsx` mounts J5-owned `J5ComposerControls` (`apps/mobile/src/j5/composer/`) beside case 49's `PlaybookComposerControl`, under the same conditions; every J5 row above the composer joins there, not as another seam. Its first row, `CrewRosterStrip` (`apps/mobile/src/j5/crew/`), shows one row per open, human-approved proposal for the thread and opens the `ThreadCrewProposal` screen, which case 98's `j5ThreadRoutes` spread registers. The gate filter, seat lines, playbook notes and preview binding live in `packages/client-runtime/src/j5/crewProposals.ts` (a new `./j5/crew-proposals` export in `packages/client-runtime/package.json`), shared with web's card; approval sends only the token from a complete preview of the seats on screen. Its second row, `AdjudicationDock` (`apps/mobile/src/j5/a2a/`), pins a Captain's open asks to the person, as web's dock does (#836 piece 6): the Inbox's own asks from this thread, answered through the Inbox's `useInboxAnswers`, shown only when `useCrewMembership` (`apps/mobile/src/j5/crew/crewMemberships.ts`, over case 115's `threadReadConnectionsAtom`, re-read whenever the server's Crew revision moves) says the thread commands a Crew. It has no attachments and no owner's clear action, since the mobile Inbox has neither. The dock's logic is `packages/client-runtime/src/j5/adjudicationDock.ts` and the membership replace is `crewMemberships.ts`, both shared with web and reached through the `./j5/adjudication-dock` and `./j5/crew-memberships` exports this case appends to upstream-owned `packages/client-runtime/package.json`.

115. Mobile lists a spawner's agents under its row (register D22, the mobile half of case 23; [#836](https://github.com/Jacksondr5/j5code/issues/836) decisions 3 and 4). `apps/mobile/src/features/threads/useThreadListV2.ts` passes its threads through J5-owned `useCrewListedThreads` (`apps/mobile/src/j5/crew/spawnedChildren.ts`), which keeps the spawned-children read (`j5.fleet.listSpawnedChildren`) current for every listed thread and drops the threads an agent spawned unless they are pinned, so every list, shelf and reorder computed after it sees the same rows. Mobile has no Fleet roster to bound re-reads by, so a moved `crew` or `fleet` revision re-reads that server's listed rows in one batched read. `apps/mobile/src/features/threads/thread-list-v2-items.tsx` mounts J5-owned `CaptainSeatsToggle` (`apps/mobile/src/j5/crew/CaptainSeats.tsx`) inside the card row's bottom line, before the pull request badge, and inside the slim row before its time, so a collapsed spawner is no taller; and it mounts `CaptainSeats` after the row's swipeable, outside its long-press menu, handing it upstream's own `STATUS_LABEL_BY_STATUS` so seat rows read as rows do. The expanded seats show each Crew's summary, Stop crew while a seat is running, "Not started", and "Replaced by". The grouping, the membership rule and the Crew state labels moved from web to `packages/client-runtime/src/j5/spawnedChildren.ts` and `crewState.ts`, reached through the `./j5/spawned-children` and `./j5/crew-state` exports this case adds to `packages/client-runtime/package.json`. Its test mocks the hook as a passthrough, since the hook reads server connections. On a pin advance: keep the one wrap at the top of `useThreadListV2`, the toggle inside both row layouts, and the seats outside the swipeable.

Expand Down
222 changes: 222 additions & 0 deletions apps/mobile/src/j5/a2a/AdjudicationDock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
import { useAtomValue } from "@effect/atom-react";
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
import {
adjudicationAsks,
commandsACrew,
pickShownAsk,
} from "@t3tools/client-runtime/j5/adjudication-dock";
import { closedLine, mergeHumanInboxSources } from "@t3tools/client-runtime/j5/inbox";
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
import { useState } from "react";
import { Pressable, ScrollView, View } from "react-native";

import { SymbolView } from "../../components/ui/AppSymbol";
import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/AppText";
import { Button } from "../../components/ui/Button";
import { useMarkdownPreviewStyles } from "../../features/files/FileMarkdownPreview";
import { relativeTime } from "../../lib/time";
import { SelectableMarkdownText } from "../../native/SelectableMarkdownText";
import { useCrewMembership } from "../crew/crewMemberships";
import { useInboxAnswers } from "../inbox/inboxAnswers";
import { answeredInboxSourcesAtom, openInboxSourcesAtom } from "../inbox/inboxSources";
import { j5Sharing } from "../sharing/guestAccess";
import { j5Environment } from "../state";

/** About three lines of the question while the dock is opened but not in full. */
const EXCERPT_HEIGHT = 72;

const URGENCY = {
blocking: { label: "Blocking", className: "text-danger-foreground" },
soon: { label: "Soon", className: "text-warning-foreground" },
fyi: { label: "FYI", className: "text-foreground-muted" },
} as const;

/**
* A Captain's open asks to the person, pinned above its composer as web's dock is. They are the
* Inbox's own asks, answered through the same command, so answering here or there closes the one
* Exchange (Crews: adjudication request). Only a Captain's asks are pinned; others stay in the Inbox.
*/
export function AdjudicationDock(props: {
readonly environmentId: EnvironmentId;
readonly threadId: ThreadId;
}) {
const membership = useCrewMembership(scopeThreadRef(props.environmentId, props.threadId));
// The Inbox is read only for a Captain's thread.
return commandsACrew(membership) ? <CaptainAsks {...props} /> : null;
}

function CaptainAsks(props: {
readonly environmentId: EnvironmentId;
readonly threadId: ThreadId;
}) {
const { environmentId, threadId } = props;
const openSources = useAtomValue(openInboxSourcesAtom);
const answeredSources = useAtomValue(answeredInboxSourcesAtom);
const ofThisEnvironment = (items: ReturnType<typeof mergeHumanInboxSources>) =>
items.filter((item) => item.environmentId === environmentId);
const answers = useInboxAnswers({
openSources,
items: ofThisEnvironment(mergeHumanInboxSources(openSources)),
answeredSources,
answered: ofThisEnvironment(mergeHumanInboxSources(answeredSources)),
});
const mayAnswer = useAtomValue(j5Environment.answerHumanExchange.permissionAtom(environmentId));
const access = useAtomValue(j5Sharing.connectionAccess(environmentId));
const styles = useMarkdownPreviewStyles();
const [open, setOpen] = useState(false);
const [full, setFull] = useState(false);
const [picked, setPicked] = useState<string | null>(null);
// The ask whose question runs past the excerpt's height.
const [overflowing, setOverflowing] = useState<string | null>(null);

// An ask that closed while the person had typed into it stays, with who answered (Inbox AC17).
const asks = adjudicationAsks({
items: answers.shownItems,
refused: [],
threadId,
hasWords: () => true,
});
const view = pickShownAsk(asks, picked);
if (!mayAnswer || view === null) return null;
const { shown, others, next: nextAsk } = view;
const urgency = URGENCY[shown.urgency];
const closed = answers.closedOf(shown);
const closedText =
closed === undefined
? null
: closedLine({ ...closed, ownName: access?.kind === "person" ? access.name : null });
const text = answers.answerText(shown);
const delivering = answers.pendingKey !== null;
const error = answers.errorFor(shown);
// Measured, not counted: a few short lines can still wrap past the excerpt on a phone.
const longer = full || overflowing === shown.exchangeId;
const markdown = (value: string) => (
<SelectableMarkdownText markdown={value} textStyle={styles.nativeTextStyle} />
);

return (
<View className="px-4 pb-2" testID="adjudication-dock">
<View className="rounded-[20px] border-continuous bg-card px-3 py-1">
<Pressable
accessibilityRole="button"
accessibilityState={{ expanded: open }}
accessibilityLabel={`Question for you, ${urgency.label}: ${shown.intent}`}
onPress={() => setOpen((value) => !value)}
className="min-h-11 flex-row items-center gap-2"
>
<SymbolView name="questionmark.bubble" size={14} tintColorClassName="accent-icon-muted" />
<View className="min-w-0 flex-1">
<Text numberOfLines={1} className="text-xs text-foreground-muted">
Question for you · open {relativeTime(shown.openedAt)}
</Text>
<Text
numberOfLines={open ? undefined : 1}
className="text-xs font-t3-medium text-foreground"
>
{shown.intent}
</Text>
</View>
<Text className={`text-2xs font-t3-semibold uppercase ${urgency.className}`}>
{urgency.label}
</Text>
<SymbolView
name={open ? "chevron.down" : "chevron.right"}
size={12}
tintColorClassName="accent-icon-muted"
/>
</Pressable>
{open ? (
<View className="gap-2 pb-2">
<ScrollView
// Remounted per ask, so each reports its own content size.
key={shown.exchangeId}
style={{ maxHeight: full ? 280 : EXCERPT_HEIGHT }}
scrollEnabled={full}
nestedScrollEnabled
onContentSizeChange={(_width, height) =>
setOverflowing(height > EXCERPT_HEIGHT ? shown.exchangeId : null)
}
>
<View className="gap-2">
{markdown(shown.message)}
{[shown.escalation?.summary, shown.personaDraft?.summary].map((record) =>
record === undefined ? null : (
// J5's own record, apart from the agent's words; plain text, so they can't alter it.
<View key={record} className="gap-1 rounded-lg bg-subtle px-3 py-2">
<Text className="text-xs font-t3-medium text-foreground-muted">
Recorded by J5
</Text>
<Text className="text-sm">{record}</Text>
</View>
),
)}
{shown.followUps?.map((followUp) => (
<View className="gap-1" key={followUp.messageId}>
<Text className="text-xs font-t3-medium text-foreground-muted">Follow-up</Text>
{markdown(followUp.message)}
</View>
))}
</View>
</ScrollView>
{longer ? (
<Pressable
accessibilityRole="button"
hitSlop={6}
onPress={() => setFull((value) => !value)}
>
<Text className="text-xs font-t3-medium text-foreground-secondary">
{full ? "Show less" : "Show full question"}
</Text>
</Pressable>
) : null}
<TextInput
accessibilityLabel={`Answer ${shown.intent}`}
multiline
placeholder="Type the answer exactly as it should be delivered"
value={text}
onChangeText={(value) => answers.setAnswerText(shown, value)}
style={{ minHeight: 44, maxHeight: 120, textAlignVertical: "top" }}
/>
{error === null ? null : (
<Text accessibilityRole="alert" className="text-sm text-danger-foreground">
{error}
</Text>
)}
<View className="flex-row items-center justify-end gap-2">
{closedText !== null ? (
<Text className="text-sm text-foreground-muted">{closedText}</Text>
) : (
<Button
label={delivering ? "Delivering…" : "Answer"}
tone="primary"
size="compact"
loading={delivering}
disabled={!shown.sourceReady || delivering || text.length === 0}
onPress={() => void answers.answer(shown)}
/>
)}
</View>
</View>
) : null}
{nextAsk !== null ? (
<Pressable
accessibilityRole="button"
onPress={() => {
setPicked(nextAsk.exchangeId);
setFull(false);
}}
className="min-h-9 flex-row items-center gap-1 border-t border-border-subtle"
>
<Text className="shrink-0 text-xs text-foreground">
{others.length} more {others.length === 1 ? "question" : "questions"}
</Text>
<Text numberOfLines={1} className="min-w-0 flex-1 text-xs text-foreground-muted">
· {nextAsk.intent}
</Text>
<SymbolView name="chevron.right" size={12} tintColorClassName="accent-icon-muted" />
</Pressable>
) : null}
</View>
</View>
);
}
8 changes: 7 additions & 1 deletion apps/mobile/src/j5/composer/J5ComposerControls.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";

import { AdjudicationDock } from "../a2a/AdjudicationDock";
import { CrewRosterStrip } from "../crew/CrewRosterStrip";

/**
* J5's rows above a thread's composer, mounted once beside upstream's playbook bar, so each
* J5 control (a Crew's roster review, the adjudication dock) joins here without another seam.
*/
export function J5ComposerControls(props: { environmentId: EnvironmentId; threadId: ThreadId }) {
return <CrewRosterStrip environmentId={props.environmentId} threadId={props.threadId} />;
return (
<>
<CrewRosterStrip environmentId={props.environmentId} threadId={props.threadId} />
<AdjudicationDock environmentId={props.environmentId} threadId={props.threadId} />
</>
);
}
54 changes: 54 additions & 0 deletions apps/mobile/src/j5/crew/crewMemberships.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { useAtomValue } from "@effect/atom-react";
import { scopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime/environment";
import { replaceCrewMemberships } from "@t3tools/client-runtime/j5/crew-memberships";
import { createScopedThreadReadStore } from "@t3tools/client-runtime/j5/scopedThreadReadStore";
import type { ScopedThreadRef } from "@t3tools/contracts";
import type { CrewMembershipEntry, ThreadCrewMembership } from "@t3tools/contracts/j5";
import * as Cause from "effect/Cause";
import { Atom } from "effect/reactivity";
import { useEffect, useSyncExternalStore } from "react";

import { appAtomRegistry } from "../../state/atom-registry";
import { j5Environment } from "../state";
import { threadReadConnectionsAtom } from "./spawnedChildren";

const store = createScopedThreadReadStore<ThreadCrewMembership, CrewMembershipEntry>({
load: async (environmentId, threadIds) => {
const result = await j5Environment.listCrewMemberships.run(appAtomRegistry, {
environmentId,
input: { threadIds },
});
if (result._tag === "Failure") throw Cause.squash(result.cause);
return result.value.entries;
},
replace: replaceCrewMemberships,
});

const NO_REVISION = Atom.make<string | null>(null).pipe(
Atom.withLabel("mobile-j5:no-crew-revision"),
);

/**
* One thread's Crew membership, read when it is first shown and again whenever its server says
* a Crew changed, so a thread that becomes a Captain while open learns it. Undefined until read,
* and for a thread in no Crew.
*/
export function useCrewMembership(
ref: ScopedThreadRef | undefined,
): ThreadCrewMembership | undefined {
const connections = useAtomValue(threadReadConnectionsAtom);
const environmentId = ref?.environmentId;
const threadId = ref?.threadId;
const crewRevision = useAtomValue(
environmentId === undefined ? NO_REVISION : j5Environment.rereadOn("crew")({ environmentId }),
);
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- asks the server for this thread's Crew membership, and again when its Crew revision moves.
useEffect(() => {
store.setConnections(connections);
if (environmentId !== undefined && threadId !== undefined)
store.request([scopeThreadRef(environmentId, threadId)], true);
// oxlint-disable-next-line react/exhaustive-effect-dependencies -- a moved Crew revision re-reads the membership.
}, [connections, crewRevision, environmentId, threadId]);
const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
return ref === undefined ? undefined : snapshot.get(scopedThreadKey(ref));
}
4 changes: 2 additions & 2 deletions apps/mobile/src/j5/crew/spawnedChildren.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const store = createScopedThreadReadStore<SpawnedChildrenRow, SpawnedChildrenRow
* Each catalogued environment's prepared connection, or null while it is not connected or the
* person reaches less than the whole server, which refuses these reads (web's `useThreadRowReads`).
*/
const threadReadConnectionsAtom = Atom.make((get) => {
export const threadReadConnectionsAtom = Atom.make((get) => {
const connections = new Map<EnvironmentId, PreparedConnection | null>();
for (const id of get(environmentCatalog.catalogValueAtom).entries.keys()) {
const state = Option.getOrNull(AsyncResult.value(get(environmentCatalog.stateAtom(id))));
Expand All @@ -47,7 +47,7 @@ const threadReadConnectionsAtom = Atom.make((get) => {
connections.set(id, readable ? Option.getOrNull(prepared) : null);
}
return connections;
}).pipe(Atom.withLabel("mobile-j5:spawned-children-connections"));
}).pipe(Atom.withLabel("mobile-j5:thread-read-connections"));

/** Each environment's Crew and Fleet revisions; a moved pair means placements may have changed. */
const placementRevisionsAtom = Atom.make((get) => {
Expand Down
Loading
Loading