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
5 changes: 4 additions & 1 deletion .github/workflows/closura-arc-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ jobs:
apps/server/src/scheduledTasks/webhookRoute.test.ts \
apps/server/src/persistence/Migrations.test.ts \
apps/server/src/persistence/Migrations/102_ScheduledTaskOccurrences.test.ts \
apps/server/src/orchestration-v2/HumanNote.test.ts \
packages/contracts/src/environment.test.ts \
scripts/feature-map.test.ts

Expand Down Expand Up @@ -356,7 +357,9 @@ jobs:
apps/web/src/components/chat/draftPlacement.test.ts \
apps/web/src/components/chat/draftAttachmentUploads.test.ts \
apps/web/src/components/chat/draftUploadReconcile.test.ts \
apps/web/src/lib/attachmentUploadQueue.test.ts
apps/web/src/lib/attachmentUploadQueue.test.ts \
apps/web/src/composer-logic.test.ts \
packages/client-runtime/src/operations/commands.test.ts

- name: Build founder inbox and voice settings web client
shell: bash
Expand Down
13 changes: 12 additions & 1 deletion apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ import {
import { AsyncResult } from "effect/reactivity";
import { isElectron } from "../env";
import { useActiveThreadRef } from "../hooks/useActiveThreadRef";
import { composerRequiresModifier } from "../composer-logic";
import { composerRequiresModifier, serverSupportsHumanNote } from "../composer-logic";
import {
derivePhase,
deriveActiveWorkStartedAt,
Expand Down Expand Up @@ -3207,6 +3207,15 @@ export default function ChatView(props: ChatViewProps) {
)
? gt("Available once the thread's worktree is set up.")
: null;
// `/note` is refused with this reason; a note never reaches a server that would start a turn.
const noteDisabledReason =
serverConfig === null
? gt("Notes are not ready yet. Try again in a moment.")
: !serverSupportsHumanNote(serverConfig)
? gt(
"Update this environment's T3 Code server to use /note. It would send the note to the bot.",
)
: null;
const openSideChatStable = useStableCallback(() => void sideChat.open());
const openSurfaceInMainView = useOpenSurfaceInMainView(activeThreadRef);
const sendSideChatStable = useStableCallback(sideChat.open);
Expand Down Expand Up @@ -3355,6 +3364,7 @@ export default function ChatView(props: ChatViewProps) {
acknowledgeActiveThreadWoke,
onSideChat: sideChat.available ? sendSideChatStable : undefined,
sideChatDisabledReason,
noteDisabledReason,
handleNewThreadInActiveProject,
persistThreadSettingsForNextTurn,
linkCheckoutPullRequest,
Expand Down Expand Up @@ -4117,6 +4127,7 @@ export default function ChatView(props: ChatViewProps) {
onToggleKeepFullHistory={toggleKeepFullHistoryStable}
sideChatAvailable={sideChat.available}
sideChatDisabledReason={sideChatDisabledReason}
noteDisabledReason={noteDisabledReason}
onFreshSession={
freshSessionCommandAvailable ? armFreshSessionStable : undefined
}
Expand Down
11 changes: 11 additions & 0 deletions apps/web/src/components/chat/ChatComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ export interface ChatComposerProps {
onUsageLimitsCommand?: (() => void) | undefined;
sideChatAvailable?: boolean;
sideChatDisabledReason?: string | null;
/** Refuses `/note` with this reason, for example when the server would drop the note flag. */
noteDisabledReason?: string | null;
/** Arms a fresh session for the next message; absent where `/clear` is unavailable. */
onFreshSession?: (() => void) | undefined;
environmentUnavailable: {
Expand Down Expand Up @@ -1239,6 +1241,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
sideChatAvailable: props.sideChatAvailable === true,
sideChatDisabledReason: props.sideChatDisabledReason ?? null,
noteAvailable: activeThread?.source.inbox?.audience === "shared",
noteDisabledReason: props.noteDisabledReason ?? null,
freshSessionAvailable: props.onFreshSession !== undefined,
compactSlashCommandAvailable,
selectedProvider,
Expand Down Expand Up @@ -2117,6 +2120,14 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
}
if (item.command === "side" || item.command === "btw" || item.command === "note") {
if (item.command !== "note" && props.sideChatDisabledReason) return;
if (item.command === "note" && props.noteDisabledReason) {
toastManager.add({
type: "warning",
title: gt("/note is unavailable"),
description: props.noteDisabledReason,
});
return;
}
const applied = applyPromptReplacement(
trigger.rangeStart,
trigger.rangeEnd,
Expand Down
6 changes: 5 additions & 1 deletion apps/web/src/components/chat/useComposerMenuItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export function useComposerMenuItems({
sideChatAvailable,
sideChatDisabledReason,
noteAvailable,
noteDisabledReason,
freshSessionAvailable,
compactSlashCommandAvailable,
selectedProvider,
Expand All @@ -96,6 +97,7 @@ export function useComposerMenuItems({
readonly sideChatAvailable: boolean;
readonly sideChatDisabledReason: string | null;
readonly noteAvailable: boolean;
readonly noteDisabledReason: string | null;
readonly freshSessionAvailable: boolean;
readonly compactSlashCommandAvailable: boolean;
readonly selectedProvider: ProviderDriverKind;
Expand Down Expand Up @@ -289,7 +291,9 @@ export function useComposerMenuItems({
type: "slash-command",
command: "note",
label: "/note",
description: gt("Leave a note for the other founder. It does not wake the bot."),
description:
noteDisabledReason ??
gt("Leave a note for the other founder. It does not wake the bot."),
},
] as const)
: []),
Expand Down
13 changes: 13 additions & 0 deletions apps/web/src/components/chat/useComposerSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ interface ComposerSendInput {
readonly onSideChat?: ((message: SideChatMessage | undefined) => Promise<boolean>) | undefined;
/** Refuses `/side` with this reason and keeps the draft. */
readonly sideChatDisabledReason: string | null;
/** Refuses `/note` with this reason and keeps the draft; nothing is sent. */
readonly noteDisabledReason: string | null;
readonly handleNewThreadInActiveProject: () => void;
readonly persistThreadSettingsForNextTurn: (input: {
threadId: ThreadId;
Expand Down Expand Up @@ -399,6 +401,7 @@ export function useComposerSend(input: ComposerSendInput) {
acknowledgeActiveThreadWoke,
onSideChat,
sideChatDisabledReason,
noteDisabledReason,
handleNewThreadInActiveProject,
persistThreadSettingsForNextTurn,
linkCheckoutPullRequest,
Expand Down Expand Up @@ -786,6 +789,16 @@ export function useComposerSend(input: ComposerSendInput) {
);
return;
}
if (noteDisabledReason !== null) {
toastManager.add(
stackedThreadToast({
type: "warning",
title: m(msg("Note not sent")),
description: noteDisabledReason,
}),
);
return;
}
if (activeThread.source.inbox?.audience !== "shared") {
toastManager.add(
stackedThreadToast({
Expand Down
15 changes: 15 additions & 0 deletions apps/web/src/composer-logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
formatAssistantCitationForComposer,
isPathSuggestionCurrent,
replaceTextRange,
serverSupportsHumanNote,
} from "./composer-logic";
import { slashCommandItemsForPromptPosition } from "./components/chat/composerSlashCommandSearch";
import { carryDisplacedCustomAnswerIntoPrompt } from "./pendingUserInput";
Expand Down Expand Up @@ -607,3 +608,17 @@ describe("side chat slash commands", () => {
]);
});
});

describe("serverSupportsHumanNote", () => {
it("offers /note only to a server that advertises the private-note flag", () => {
const config = (humanNote?: boolean) => ({
environment: { capabilities: humanNote === undefined ? {} : { humanNote } },
});
expect(serverSupportsHumanNote(config(true))).toBe(true);
// A server built before the flag (fleet t3code 3ad1bfdd) sends no key at all.
expect(serverSupportsHumanNote(config())).toBe(false);
expect(serverSupportsHumanNote(config(false))).toBe(false);
expect(serverSupportsHumanNote(null)).toBe(false);
expect(serverSupportsHumanNote(undefined)).toBe(false);
});
});
14 changes: 14 additions & 0 deletions apps/web/src/composer-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ export type ComposerTriggerKind = "path" | "pull-request" | "slash-command" | "s
export type ComposerSlashCommand = "model" | "side" | "btw" | "clear" | "note";
export type ComposerSubmissionIntent = "foreground" | "background" | "alternate";

/**
* Closura (CLO-1105): an older server drops the unknown `humanNote` flag but keeps
* `start_immediately`, so a private note would run as a provider turn. Offer `/note`
* only when the connected server says it honours the flag; an unknown config fails closed.
*/
export function serverSupportsHumanNote(
serverConfig:
| { readonly environment: { readonly capabilities: { readonly humanNote?: boolean } } }
| null
| undefined,
): boolean {
return serverConfig?.environment.capabilities.humanNote === true;
}

export interface ComposerTrigger {
kind: ComposerTriggerKind;
query: string;
Expand Down
90 changes: 89 additions & 1 deletion packages/client-runtime/src/operations/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {
MessageId,
NodeId,
ORCHESTRATION_V2_WS_METHODS,
OrchestrationV2Command,
ProjectId,
ProviderInstanceId,
ProviderDriverKind,
RunId,
ThreadId,
TurnItemId,
WS_METHODS,
type OrchestrationV2Command,
type OrchestrationV2ThreadLaunchInput,
type OrchestrationV2ThreadProjection,
type ProjectMutation,
Expand Down Expand Up @@ -383,6 +383,94 @@ describe("V2 environment commands", () => {
}).pipe(Effect.provide(layerTestRandom)),
);

/** message.dispatch as a server built before `humanNote` decodes it: the same fields minus the flag. */
const preHumanNoteDispatchCommand = (() => {
const member = OrchestrationV2Command.members.find(
(candidate) => candidate.fields.type.literal === "message.dispatch",
);
if (member === undefined) throw new Error("message.dispatch command schema not found");
const { humanNote: _dropped, ...preNoteFields } = member.fields as Schema.Struct.Fields;
// The fields are the dispatch command's own, so decoding needs no services.
return Schema.Struct(preNoteFields) as unknown as Schema.Codec<
Record<string, unknown>,
unknown
>;
})();

// CLO-1105: a server built before `humanNote` (fleet t3code 3ad1bfdd) decodes message.dispatch
// without the field, so the flag is dropped and `start_immediately` would start a provider turn.
it.effect.each([
["an old server that lacks the capability", false],
["a server that advertises the capability", true],
] as const)("a /note sent to %s never reaches the server as a startable turn", ([, advertised]) =>
Effect.gen(function* () {
const decodeOnServer = Schema.decodeUnknownEffect(
advertised ? OrchestrationV2Command : preHumanNoteDispatchCommand,
);
const rawNote = {
type: "message.dispatch",
commandId: "command-old-server-note",
createdBy: "user",
creationSource: "web",
threadId: v2ThreadId,
messageId: "message-old-server-note",
text: "Synthetic private note",
attachments: [],
humanNote: true,
dispatchMode: { type: "start_immediately" },
};
if (!advertised) {
// The hazard this guards: the old decoder keeps the start and loses the note flag.
const stripped = (yield* decodeOnServer(rawNote)) as Record<string, unknown>;
expect(stripped.humanNote).toBeUndefined();
expect(stripped.dispatchMode).toEqual({ type: "start_immediately" });
}

const commands: OrchestrationV2Command[] = [];
const supervisor = yield* makeSupervisor({
commands,
projects: [],
...(advertised ? { advertiseHumanNote: true } : {}),
});
const exit = yield* startThreadTurn({
commandId: CommandId.make("command-old-server-note"),
threadId: v2ThreadId,
message: {
messageId: MessageId.make("message-old-server-note"),
role: "user",
text: "Synthetic private note",
attachments: [],
humanNote: true,
},
runtimeMode: "full-access",
interactionMode: "default",
dispatchMode: "start",
}).pipe(
Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor),
Effect.exit,
);

const received: Array<Record<string, unknown>> = [];
for (const command of commands) {
received.push((yield* decodeOnServer(command)) as Record<string, unknown>);
}
const startableTurns = received.filter(
(command) => command.type === "message.dispatch" && command.humanNote !== true,
);
expect(startableTurns).toEqual([]);
if (advertised) {
expect(Exit.isSuccess(exit)).toBe(true);
expect(commands).toMatchObject([{ type: "message.dispatch", humanNote: true }]);
} else {
expect(commands).toEqual([]);
expect(Exit.isFailure(exit)).toBe(true);
if (Exit.isFailure(exit)) {
expect(String(Cause.squash(exit.cause))).toContain("Update the server to use /note");
}
}
}).pipe(Effect.provide(layerTestRandom)),
);

it.effect(
"sends fallback text only on empty manual continuations for servers without native resume",
() =>
Expand Down
Loading