Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
d8bfa40
feat(server): anyone who can write to a shared thread answers its pro…
Jacksondr5 Oct 13, 2026
b5a6508
fix(server): an interrupted answer leaves no claim behind
Jacksondr5 Oct 13, 2026
302e5c5
fix(server): who answered is kept only for the command that settled t…
Jacksondr5 Oct 13, 2026
41b91bd
feat(server): the agent is told who answered its approval prompts, wi…
Jacksondr5 Oct 13, 2026
3e9a67a
feat(server): a person's reply from the inbox names them
Jacksondr5 Oct 13, 2026
8c0e3fc
fix(server): who answered a prompt is read from the event log upstrea…
Jacksondr5 Oct 13, 2026
cb2e3ac
fix(server): an approval answered before the first message is told in…
Jacksondr5 Oct 13, 2026
c2be998
fix(server): what the agent was told is read from the messages that t…
Jacksondr5 Oct 13, 2026
f06e300
fix(server): a guest's command goes on under an id of its own, and a …
Jacksondr5 Oct 13, 2026
08bd803
fix(server): a thread started in a shared project is a shared convers…
Jacksondr5 Oct 13, 2026
915c528
fix(server): a guest answers only a prompt that is waiting, and a run…
Jacksondr5 Oct 13, 2026
edd1aaf
docs(j5): the launch wrap is approved, and the definition's history s…
Jacksondr5 Oct 13, 2026
dbeafeb
feat(server): a guest's message carries composer context, and the age…
Jacksondr5 Oct 14, 2026
c4476b1
fix(server): a guest builds from a plan only on a thread it can write…
Jacksondr5 Oct 14, 2026
d57cb60
fix(server): a guest's client is told the server takes inline context
Jacksondr5 Oct 14, 2026
a1f88a4
feat(server): a member's slash command goes on as typed in a shared c…
Jacksondr5 Oct 14, 2026
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
4 changes: 2 additions & 2 deletions FORK.md

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion apps/server/src/j5/a2a/AgentCrewProposalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export interface CrewProposal {
readonly approvedSeats: ReadonlyArray<CrewProposalSeat> | null;
readonly createdAt: string;
readonly resolvedAt: string | null;
/** Who approved or declined it, named only when the Captain's thread is a shared conversation. */
readonly decidedBy?: string | null | undefined;
/** When the Captain received the launch report for an approval; null until it posts. */
readonly reportedAt: string | null;
/** The store always sets it; null when the proposal follows no playbook. */
Expand Down Expand Up @@ -142,6 +144,7 @@ export interface AgentCrewProposalServiceShape {
readonly decision: CrewProposalDecision;
readonly approvedSeats: ReadonlyArray<CrewProposalSeat> | null;
readonly resolvedAt: string;
readonly decidedBy?: string | null | undefined;
}) => Effect.Effect<CrewProposal | null, SqlError>;
/** Approved proposals whose launch report has not reached the Captain yet. */
readonly listUnreported: () => Effect.Effect<ReadonlyArray<CrewProposal>, SqlError>;
Expand Down Expand Up @@ -173,6 +176,7 @@ interface Row {
readonly created_at: string;
readonly resolved_at: string | null;
readonly reported_at: string | null;
readonly decided_by: string | null;
readonly playbook_name: string | null;
readonly playbook_definition_path: string | null;
}
Expand All @@ -192,6 +196,7 @@ const fromRow = (row: Row): CrewProposal => ({
createdAt: row.created_at,
resolvedAt: row.resolved_at,
reportedAt: row.reported_at,
decidedBy: row.decided_by,
playbook:
row.playbook_name === null || row.playbook_definition_path === null
? null
Expand Down Expand Up @@ -291,6 +296,7 @@ export const layer: Layer.Layer<AgentCrewProposalService, never, SqlClient.SqlCl
readonly decision: CrewProposalDecision;
readonly approvedSeats: ReadonlyArray<CrewProposalSeat> | null;
readonly resolvedAt: string;
readonly decidedBy?: string | null | undefined;
}) {
const approvedSeats =
input.decision === "approve" && input.approvedSeats !== null
Expand All @@ -300,7 +306,8 @@ export const layer: Layer.Layer<AgentCrewProposalService, never, SqlClient.SqlCl
UPDATE j5_agent_crew_proposal
SET status = ${finalStatus(input.decision)},
approved_seats = ${approvedSeats},
resolved_at = ${input.resolvedAt}
resolved_at = ${input.resolvedAt},
decided_by = ${input.decidedBy ?? null}
WHERE id = ${input.id} AND status = 'open'
RETURNING id
`;
Expand Down
9 changes: 6 additions & 3 deletions apps/server/src/j5/a2a/ClientActionsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ export class ClientActionsService extends Context.Service<
/** Resolve the runtime settings the roster card shows, and the token an approval must carry. */
readonly previewCrewProposal: (
input: CrewProposalPreviewRequest,
options?: { readonly forGuest?: boolean },
) => Effect.Effect<
CrewProposalPreviewResponse,
Failure<CrewProposalService["Service"]["preview"]>
>;
/** Approve (with the final seats) or decline one proposal; answers with it as the card reads it. */
readonly resolveCrewProposal: (
input: CrewProposalResolveRequest,
/** Who is answering, as the Captain is told; given only for a shared conversation. */
decidedBy?: string | null,
) => Effect.Effect<
typeof CrewProposalResolveResponse.Type,
Failure<CrewProposalService["Service"]["resolve"]>
Expand Down Expand Up @@ -115,9 +118,9 @@ const make = Effect.gen(function* () {
const projectProposal = projectCrewProposal(yield* PlaybookStore);

return ClientActionsService.of({
previewCrewProposal: (input) => proposals.preview(input),
resolveCrewProposal: (input) =>
proposals.resolve(input).pipe(
previewCrewProposal: (input, options) => proposals.preview(input, options),
resolveCrewProposal: (input, decidedBy) =>
proposals.resolve({ ...input, decidedBy }).pipe(
Effect.flatMap((result) =>
projectProposal(result.proposal).pipe(
Effect.map((proposal) => ({
Expand Down
17 changes: 17 additions & 0 deletions apps/server/src/j5/a2a/ClientReadsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ export interface ClientReadsShape {
typeof CrewProposalsResponse.Type,
Effect.Error<ReturnType<AgentCrewProposalService["Service"]["listOpen"]>>
>;
/** The rosters waiting for approval that the agent of one thread proposed, and no other proposal. */
readonly threadRosters: (
threadId: ThreadId,
) => Effect.Effect<
typeof CrewProposalsResponse.Type,
Effect.Error<ReturnType<AgentCrewProposalService["Service"]["listOpen"]>>
>;
/** The Inbox's Crew seat approvals: provider requests waiting on live Crew threads. */
readonly crewRuntimeRequests: Effect.Effect<
CrewRuntimeRequestsResponse,
Expand Down Expand Up @@ -336,6 +343,16 @@ export const layer: Layer.Layer<
Effect.flatMap((open) => Effect.forEach(open, projectProposal)),
Effect.map((listed) => ({ proposals: listed })),
),
threadRosters: (threadId) =>
proposals.listOpen().pipe(
Effect.map((open) =>
open.filter(
(proposal) => proposal.kind === "roster" && proposal.captainThreadId === threadId,
),
),
Effect.flatMap((open) => Effect.forEach(open, projectProposal)),
Effect.map((listed) => ({ proposals: listed })),
),
crewRuntimeRequests: runtimeRequests.list.pipe(Effect.map((requests) => ({ requests }))),
crewMemberships: yield* makeCrewMembershipsRead,
spawnedChildren: yield* makeSpawnedChildrenRead,
Expand Down
74 changes: 72 additions & 2 deletions apps/server/src/j5/a2a/CrewProposalService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ import {
CrewProposalService,
layer as crewProposalLayer,
type ResolveCrewProposalInput,
proposalForGuest,
withoutHostPaths,
} from "./CrewProposalService.ts";
import { A2ALedger, layer as ledgerLayer } from "./LedgerService.ts";
import { participantIdForThread } from "./HomeRegistrar.ts";
Expand Down Expand Up @@ -688,7 +690,20 @@ it.effect("gates every roster on the human and gates additions with the seat cap
});
assert.equal(custom.proposal.status, "open");
assert.isNull(custom.proposal.requestedSeats[0]?.agentId);
yield* gate.resolve({ proposalId: custom.proposal.id, decision: "decline" });
// In a shared conversation the Captain is told who answered, and the record keeps it.
const named = yield* gate.resolve({
proposalId: custom.proposal.id,
decision: "decline",
decidedBy: "Priya (guest)",
});
assert.equal(named.proposal.decidedBy, "Priya (guest)");
const namedNotice = (yield* Ref.get(notices)).at(-1);
if (namedNotice?.type === "message.dispatch") {
assert.include(
namedNotice.text,
"decision: declined\ndecided_by: Priya (guest)\ncrew_name:",
);
}

const declined = yield* gate.resolve({
proposalId: request.proposal.id,
Expand All @@ -697,7 +712,11 @@ it.effect("gates every roster on the human and gates additions with the seat cap
assert.equal(declined.proposal.status, "declined");
assert.isNull(declined.instance);
const last = (yield* Ref.get(notices)).at(-1);
if (last?.type === "message.dispatch") assert.include(last.text, "decision: declined");
// Anywhere else the notice is what it always was.
if (last?.type === "message.dispatch") {
assert.include(last.text, "decision: declined\ncrew_name:");
assert.notInclude(last.text, "decided_by");
}

const tooMany = yield* gate
.propose({
Expand Down Expand Up @@ -1246,6 +1265,57 @@ it.effect(
const first = yield* gate.preview({ proposalId: open.proposal.id });
// Every preview carries what the card offers: the Captain's branch, where it works, worktrees.
assert.deepStrictEqual(first.workspaceOptions, fakeWorkspaceOptions);
// A guest's connection is shown the same seats and the same approval token, with none
// of the host's folders and branches.
const forGuest = yield* gate.preview({ proposalId: open.proposal.id }, { forGuest: true });
assert.isFalse("workspaceOptions" in forGuest);
assert.strictEqual(forGuest.approvalToken, first.approvalToken);
assert.deepStrictEqual(
forGuest.seats.map((seat) => seat.seat),
first.seats.map((seat) => seat.seat),
);
assert.deepStrictEqual(
withoutHostPaths({
seat: "builder",
workspace: {
type: "existing_worktree",
worktreePath: "/home/owner/repo-wt",
branch: "fix",
},
}),
{
seat: "builder",
workspace: { type: "existing_worktree", worktreePath: "/", branch: "fix" },
},
);
// What a guest is handed back after answering is reduced the same way, and a problem
// reading the playbook is said without the reader's words, which can name a file.
const reduced = proposalForGuest({
...open.proposal,
requestedSeats: [
{
...open.proposal.requestedSeats[0]!,
workspace: {
type: "existing_worktree",
worktreePath: "/home/owner/repo-wt",
branch: "fix",
},
},
],
playbook: {
name: "review",
title: "review",
steps: [],
issue: "ENOENT: no such file, open '/home/owner/repo/.j5/playbooks/review.yaml'",
},
});
assert.deepStrictEqual(reduced.requestedSeats[0]?.workspace, {
type: "existing_worktree",
worktreePath: "/",
branch: "fix",
});
assert.isFalse(JSON.stringify(reduced).includes("/home/owner"));
assert.isTrue(reduced.playbook?.issue?.startsWith("This roster's playbook has a problem"));
assert.deepStrictEqual(first.seats[0]?.workspace, {
type: "worktree",
baseRef: "release",
Expand Down
62 changes: 56 additions & 6 deletions apps/server/src/j5/a2a/CrewProposalService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type {
CrewProposal as ClientCrewProposal,
CrewSeatWorkspace,
CrewPersonaSwap,
CrewProposalPreviewRequest,
CrewProposalPreviewResponse,
Expand Down Expand Up @@ -135,6 +137,8 @@ export interface ResolveCrewProposalInput {
readonly approvalToken?: string | undefined;
/** The human's final roster on approval; the requested seats when omitted. */
readonly seats?: ReadonlyArray<CrewProposalSeat> | undefined;
/** Who is answering, as the Captain is told; given only for a shared conversation. */
readonly decidedBy?: string | null | undefined;
}

/** What the Captain is told about a playbook proposal it just filed. */
Expand All @@ -152,9 +156,47 @@ export interface CrewProposalOutcome {
readonly playbook?: CrewProposalPlaybookOutcome | null | undefined;
}

/** Stands in for a folder on the host wherever a guest is shown a seat's workspace. */
const GUEST_PLACEHOLDER_PATH = "/";

/**
* A seat as a guest is shown it: the same seat, with a worktree's folder on the host replaced.
* Its branch, model and access are the roster's own and stay.
*/
export const withoutHostPaths = <S extends { readonly workspace?: CrewSeatWorkspace | undefined }>(
seat: S,
): S =>
seat.workspace?.type === "existing_worktree"
? { ...seat, workspace: { ...seat.workspace, worktreePath: GUEST_PLACEHOLDER_PATH } }
: seat;

/**
* A proposal as a guest is shown it: its seats without the host's folders, and a problem with
* its playbook said without the reader's own words, which can name a file on the host.
*/
export const proposalForGuest = (proposal: ClientCrewProposal): ClientCrewProposal => ({
...proposal,
requestedSeats: proposal.requestedSeats.map(withoutHostPaths),
approvedSeats: proposal.approvedSeats?.map(withoutHostPaths) ?? null,
...(proposal.playbook == null || proposal.playbook.issue == null
? {}
: {
playbook: {
...proposal.playbook,
issue: "This roster's playbook has a problem. A member can see what it is.",
},
}),
});

export interface CrewProposalServiceShape {
readonly preview: (
input: CrewProposalPreviewRequest,
/**
* For a guest's connection: the host's folders and branches are left out, and git is not
* asked for them. A guest approves a roster as proposed and has no use for where a seat
* could be moved to.
*/
options?: { readonly forGuest?: boolean },
) => Effect.Effect<CrewProposalPreviewResponse, CrewProposalError>;
readonly propose: (
input: ProposeCrewInput,
Expand Down Expand Up @@ -513,6 +555,7 @@ export const layer = Layer.effect(
decision: "approve",
approvedSeats: seats,
resolvedAt: DateTime.formatIso(yield* DateTime.now),
decidedBy: proposal.decidedBy,
})
.pipe(Effect.mapError(failed));
if (approved === null)
Expand Down Expand Up @@ -787,7 +830,8 @@ export const layer = Layer.effect(
});

const preview: CrewProposalServiceShape["preview"] = Effect.fn("j5.a2a.crewProposal.preview")(
function* (input) {
function* (input, options) {
const forGuest = options?.forGuest === true;
const proposal = yield* proposals
.read(input.proposalId)
.pipe(Effect.mapError(operationError("reading the proposal")));
Expand All @@ -804,7 +848,7 @@ export const layer = Layer.effect(
const resolved = yield* resolveRuntime(captain, seats);
return {
proposalId: proposal.id,
workspaceOptions: yield* launcher.workspaceOptions(captain),
...(forGuest ? {} : { workspaceOptions: yield* launcher.workspaceOptions(captain) }),
approvalToken: crewApprovalToken(
proposal,
captain,
Expand All @@ -813,7 +857,8 @@ export const layer = Layer.effect(
),
seats: resolved.map((entry) => {
const swaps = plan.swapsBySeat.get(entry.runtime.seat);
return swaps === undefined ? entry.runtime : { ...entry.runtime, personaSwaps: swaps };
const runtime = forGuest ? withoutHostPaths(entry.runtime) : entry.runtime;
return swaps === undefined ? runtime : { ...runtime, personaSwaps: swaps };
}),
...(plan.summary === null
? {}
Expand All @@ -826,9 +871,13 @@ export const layer = Layer.effect(
gates.withLock(
input.proposalId,
Effect.gen(function* () {
const proposal = yield* proposals
.read(input.proposalId)
.pipe(Effect.mapError(operationError("reading the proposal")));
// Who is answering rides on the proposal from here: both notices and the record read it.
const proposal = yield* proposals.read(input.proposalId).pipe(
Effect.mapError(operationError("reading the proposal")),
Effect.map((read) =>
read === null ? null : { ...read, decidedBy: input.decidedBy ?? null },
),
);
if (proposal === null)
return yield* new CrewProposalNotFoundError({ proposalId: input.proposalId });
if (proposal.status !== "open")
Expand All @@ -847,6 +896,7 @@ export const layer = Layer.effect(
decision: "decline",
approvedSeats: null,
resolvedAt: DateTime.formatIso(yield* DateTime.now),
decidedBy: proposal.decidedBy,
})
.pipe(Effect.mapError(operationError("recording the decline")));
if (declined === null)
Expand Down
38 changes: 38 additions & 0 deletions apps/server/src/j5/a2a/DeliveryTransport.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,44 @@ it.effect("attributes human-origin delivery to the user actor", () =>
),
[{ messageId: upstreamMessageId, mode: "queue", createdBy: "user" }],
);

// Once the server holds a name for the person, the header says it and keeps the id.
const sql = yield* SqlClient.SqlClient;
const at = "2026-10-13T00:00:00.000Z";
yield* sql`
INSERT INTO j5_a2a_human_person (person_id, is_local_operator, created_at, kind, display_name)
VALUES (${personId}, 0, ${at}, 'member', 'Jackson')
ON CONFLICT (person_id) DO UPDATE SET display_name = 'Jackson'
`;
const headerOf = Effect.fn("test.headerOf")(function* (key: string) {
const messageId = LedgerMessageId.make(`message:j5-a2a-delivery-human-${key}`);
yield* transport.deliverAgent({
...target.delivery,
messageId,
senderId: personId,
exchangeRole: "reply",
message,
});
const stored = (yield* threads.getThreadProjection(target.threadId)).messages.find(
(candidate) => candidate.id === deliveryMessageId(messageId),
);
return stored?.text.split("\n")[0];
});
assert.strictEqual(yield* headerOf("named"), `[Message from Jackson (${personId})]`);
// In a shared conversation it also says where the person stands, as a typed message does.
yield* sql`
INSERT INTO j5_a2a_human_person (person_id, is_local_operator, created_at, kind, display_name)
VALUES ('human:transport-guest', 0, ${at}, 'guest', 'Priya')
`;
yield* sql`
INSERT INTO j5_a2a_person_grant (
person_id, target_kind, target_id, level, created_at, updated_at
) VALUES ('human:transport-guest', 'thread', ${target.threadId}, 'collaborate', ${at}, ${at})
`;
assert.strictEqual(
yield* headerOf("shared"),
`[Message from Jackson (member) (${personId})]`,
);
}).pipe(Effect.provide(makeTestLayer(harness)));
}),
);
Expand Down
Loading
Loading