Skip to content

Commit d4014e6

Browse files
fix(mobile): project memory opens from the thread actions menu
The composer drew a bare "Project memory" text button above itself, so it floated over the last message in the feed. It now sits in the thread actions menu beside Conversation summaries, on threads and new-thread drafts alike, and the composer only hosts the sheet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 19ff7e1 commit d4014e6

8 files changed

Lines changed: 144 additions & 93 deletions

‎apps/mobile/src/components/ProjectKnowledgeEntry.test.tsx‎

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ vi.mock("../features/settings/appearance/AppearancePreferencesProvider", () => (
227227
}));
228228
vi.mock("../features/terminal/terminalTheme", () => ({ getMobileTerminalTheme: () => ({}) }));
229229
import { ComposerContextSheet } from "./ComposerContextSheet";
230-
import { ProjectKnowledgeEntry, requestRememberMessage } from "./ProjectKnowledgeEntry";
230+
import { ProjectKnowledgeEntry, requestProjectMemory } from "./ProjectKnowledgeEntry";
231231

232232
const scope = {
233233
environmentId: EnvironmentId.make("mobile-memory"),
@@ -330,6 +330,7 @@ function setup(entries = [scope]) {
330330
),
331331
),
332332
rerender: () => act(() => root.render(renderEntries())),
333+
openMemory: () => act(() => requestProjectMemory({ ...entries[0]!, message: null })),
333334
click: async (label: string) => {
334335
const button = [...container.querySelectorAll("button")].find(
335336
(item) => item.textContent === label || item.getAttribute("aria-label") === label,
@@ -400,7 +401,7 @@ it.each(["selection", "archive", "close", "unmount", "removal"] as const)(
400401
complete = resolve;
401402
}),
402403
);
403-
await screen.click("Project memory");
404+
screen.openMemory();
404405
if (change !== "removal") await screen.click("Select for draft");
405406
await screen.click("Attach to draft");
406407
if (change === "selection") await screen.click("Selected for draft");
@@ -410,7 +411,7 @@ it.each(["selection", "archive", "close", "unmount", "removal"] as const)(
410411
);
411412
if (change === "close") {
412413
await screen.click("Close");
413-
await screen.click("Project memory");
414+
screen.openMemory();
414415
}
415416
if (change === "unmount") screen.unmount();
416417
if (change === "removal") await screen.click("Remove from draft");
@@ -435,7 +436,7 @@ it("flags a fact whose citation is unavailable in the list", async () => {
435436
nextCursor: null,
436437
unavailableSources: [{ factId: fact.id, reason: "changed" }],
437438
};
438-
await screen.click("Project memory");
439+
screen.openMemory();
439440
expect(screen.container.textContent).toContain("Source changed");
440441
});
441442

@@ -457,7 +458,7 @@ it("saves a remembered feed message with a citation to that message", async () =
457458
archived: false,
458459
};
459460
act(() =>
460-
requestRememberMessage({
461+
requestProjectMemory({
461462
environmentId: scope.environmentId,
462463
projectId: scope.projectId,
463464
draftKey: scope.draftKey,
@@ -487,7 +488,7 @@ it("shows user origin once without treating the assertion as a citation", async
487488
sources: [{ kind: "user" }],
488489
};
489490
state.list = { facts: [asserted], nextCursor: null };
490-
await screen.click("Project memory");
491+
screen.openMemory();
491492
await screen.click("Inspect fact: " + asserted.content);
492493
expect(screen.container.textContent?.match(/User assertion/g)).toHaveLength(1);
493494
expect(screen.container.textContent).toContain("No cited source");
@@ -496,7 +497,7 @@ it("shows user origin once without treating the assertion as a citation", async
496497

497498
it("attaches the current selection", async () => {
498499
using screen = setup();
499-
await screen.click("Project memory");
500+
screen.openMemory();
500501
await screen.click("Select for draft");
501502
await screen.click("Attach to draft");
502503
expect(state.insert).toHaveBeenCalledWith(
@@ -513,7 +514,7 @@ it("attaches the current selection", async () => {
513514

514515
it("edits a citationless agent observation as an explicit user assertion", async () => {
515516
using screen = setup();
516-
await screen.click("Project memory");
517+
screen.openMemory();
517518
await screen.click(`Inspect fact: ${fact.content}`);
518519
await screen.click("Edit");
519520
await screen.click("Save");
@@ -558,7 +559,7 @@ it("pages both result streams without restarting the other stream", async () =>
558559
],
559560
},
560561
}));
561-
await screen.click("Project memory");
562+
screen.openMemory();
562563
const input = screen.container.querySelector(
563564
'[aria-label="Search project knowledge"]',
564565
) as HTMLInputElement;
@@ -620,7 +621,7 @@ it.each([
620621
] as const)("sends %s feedback against the fact's revision", async (label, helpful) => {
621622
using screen = setup();
622623
state.list = { facts: [{ ...fact, revision: 3 }], nextCursor: null };
623-
await screen.click("Project memory");
624+
screen.openMemory();
624625
await screen.click(`Inspect fact: ${fact.content}`);
625626
await screen.click(label);
626627
expect(state.mutate).toHaveBeenCalledWith({
@@ -638,7 +639,7 @@ it.each([
638639

639640
it("forgets a fact only after the permanent-erase warning is confirmed", async () => {
640641
using screen = setup();
641-
await screen.click("Project memory");
642+
screen.openMemory();
642643
await screen.click(`Inspect fact: ${fact.content}`);
643644

644645
await screen.click("Forget");
@@ -673,7 +674,7 @@ it("marks a superseded fact read-only and lists superseded facts on request", as
673674
facts: [{ ...fact, supersededBy: ProjectFactId.make("replacement") }],
674675
nextCursor: null,
675676
};
676-
await screen.click("Project memory");
677+
screen.openMemory();
677678
expect(screen.container.textContent).toContain("Superseded");
678679
await screen.click(`Inspect fact: ${fact.content}`);
679680
const labels = [...screen.container.querySelectorAll("button")].map((item) => item.textContent);
@@ -709,7 +710,7 @@ it("supersedes a fact with a new replacement and shows the returned conflict hin
709710
],
710711
},
711712
});
712-
await screen.click("Project memory");
713+
screen.openMemory();
713714
await screen.click(`Inspect fact: ${fact.content}`);
714715
await screen.click("Supersede");
715716
await screen.click("Save");
@@ -737,7 +738,7 @@ it("treats a changed message source as the same selection and shows it as change
737738
facts: { state: "available", matches: [], coverage: "complete", nextCursor: null },
738739
});
739740
state.search = match("a".repeat(64));
740-
await screen.click("Project memory");
741+
screen.openMemory();
741742
const input = screen.container.querySelector(
742743
'[aria-label="Search project knowledge"]',
743744
) as HTMLInputElement;
@@ -790,7 +791,7 @@ it("replaces a changed source with its current version on request", async () =>
790791
maxBytes: 48_000,
791792
});
792793
state.draft = { text: reference.text, context: { records: [reference.record] } };
793-
await screen.click("Project memory");
794+
screen.openMemory();
794795
const input = screen.container.querySelector(
795796
'[aria-label="Search project knowledge"]',
796797
) as HTMLInputElement;
@@ -818,7 +819,7 @@ it("removes the attached draft reference when the selection changes and says so"
818819
state.setText.mockImplementation((_key: string, text: string) => {
819820
state.draft = { text };
820821
});
821-
await screen.click("Project memory");
822+
screen.openMemory();
822823
expect(screen.container.textContent).toContain("is attached to this draft");
823824
await screen.click("Selected for draft");
824825
expect(state.setText).toHaveBeenCalledWith(scope.draftKey, "See");
@@ -836,7 +837,7 @@ it("drops a revised fact from the selection and the draft after saving", async (
836837
state.setText.mockImplementation((_key: string, text: string) => {
837838
state.draft = { text };
838839
});
839-
await screen.click("Project memory");
840+
screen.openMemory();
840841
await screen.click(`Inspect fact: ${fact.content}`);
841842
await screen.click("Confirm");
842843
expect(state.setText).toHaveBeenCalledWith(scope.draftKey, "");
@@ -862,7 +863,7 @@ it("opens only the destination composer for a remembered message from another th
862863
archived: false,
863864
};
864865
act(() =>
865-
requestRememberMessage({
866+
requestProjectMemory({
866867
environmentId: scope.environmentId,
867868
projectId: scope.projectId,
868869
draftKey: "other-thread-draft",
@@ -883,7 +884,7 @@ it("ignores remember requests while the destination entry is unfocused", () => {
883884
state.focused = false;
884885
screen.rerender();
885886
act(() =>
886-
requestRememberMessage({
887+
requestProjectMemory({
887888
environmentId: scope.environmentId,
888889
projectId: scope.projectId,
889890
draftKey: scope.draftKey,
@@ -901,7 +902,7 @@ it.each(["Hardware Back", "Header Back"])(
901902
async (back) => {
902903
using screen = setup();
903904
state.androidSheet = true;
904-
await screen.click("Project memory");
905+
screen.openMemory();
905906
await screen.click("Select for draft");
906907
await screen.click("Inspect fact: " + fact.content);
907908
await screen.click(back);
@@ -917,7 +918,7 @@ it.each(["Hardware Back", "Header Back"])(
917918
async (back) => {
918919
using screen = setup();
919920
state.androidSheet = true;
920-
await screen.click("Project memory");
921+
screen.openMemory();
921922
await screen.click(back);
922923
expect(screen.container.textContent).not.toContain("Search");
923924
},
@@ -928,7 +929,7 @@ it.each(["Hardware Back", "Header Back", "Back", "Cancel"])(
928929
async (back) => {
929930
using screen = setup();
930931
state.androidSheet = true;
931-
await screen.click("Project memory");
932+
screen.openMemory();
932933
await screen.click("Inspect fact: " + fact.content);
933934
await screen.click("Edit");
934935
const input = screen.container.querySelector('[aria-label="Fact content"]') as HTMLInputElement;

‎apps/mobile/src/components/ProjectKnowledgeEntry.tsx‎

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -79,26 +79,40 @@ type Page =
7979
| { readonly kind: "source"; readonly ref: SourceRef }
8080
| { readonly kind: "remember"; readonly ref: SourceRef }
8181
| { readonly kind: "editor"; readonly mode: FactEditorMode };
82-
type RememberRequest = {
82+
type OpenRequest = {
8383
readonly environmentId: EnvironmentId;
8484
readonly projectId: ProjectId;
8585
readonly draftKey: string;
86-
readonly message: MessageCitation;
86+
readonly message: MessageCitation | null;
8787
};
8888

89-
// The feed asks the composer's entry to open, since the sheet writes to that draft.
90-
const rememberListeners = new Set<(request: RememberRequest) => void>();
91-
export function requestRememberMessage(request: RememberRequest): void {
92-
for (const listener of rememberListeners) listener(request);
89+
// The header and feed ask the composer's entry to open, since the sheet writes to that draft.
90+
const openListeners = new Set<(request: OpenRequest) => void>();
91+
export function requestProjectMemory(request: OpenRequest): void {
92+
for (const listener of openListeners) listener(request);
93+
}
94+
95+
/** Opens project memory for a composer draft; undefined when the server has no project memory. */
96+
export function useOpenProjectMemory(
97+
environmentId: EnvironmentId,
98+
projectId: ProjectId | undefined,
99+
draftKey: string,
100+
) {
101+
const config = useAtomValue(serverEnvironment.configValueAtom(environmentId));
102+
const open = useCallback(() => {
103+
if (projectId) requestProjectMemory({ environmentId, projectId, draftKey, message: null });
104+
}, [environmentId, projectId, draftKey]);
105+
return config?.environment.capabilities.projectKnowledge === true && projectId ? open : undefined;
93106
}
94107

95108
export function ProjectKnowledgeEntry(props: Scope) {
96109
const isFocused = useIsFocused();
97110
const config = useAtomValue(serverEnvironment.configValueAtom(props.environmentId));
98111
const [open, setOpen] = useState<{ readonly seed: MessageCitation | null } | null>(null);
99112
const { environmentId, projectId, draftKey } = props;
113+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- registers this entry with the header and feed open requests while mounted
100114
useEffect(() => {
101-
const listener = (request: RememberRequest) => {
115+
const listener = (request: OpenRequest) => {
102116
if (
103117
isFocused &&
104118
request.environmentId === environmentId &&
@@ -107,33 +121,23 @@ export function ProjectKnowledgeEntry(props: Scope) {
107121
)
108122
setOpen({ seed: request.message });
109123
};
110-
rememberListeners.add(listener);
124+
openListeners.add(listener);
111125
return () => {
112-
rememberListeners.delete(listener);
126+
openListeners.delete(listener);
113127
};
114128
}, [environmentId, projectId, draftKey, isFocused]);
115-
if (config?.environment.capabilities.projectKnowledge !== true) return null;
129+
if (config?.environment.capabilities.projectKnowledge !== true || !open || !isFocused)
130+
return null;
116131
return (
117-
<>
118-
<Button
119-
label="Project memory"
120-
icon="brain"
121-
onPress={() => setOpen({ seed: null })}
122-
tone="text"
123-
accessibilityHint="Search and attach evidence from this project"
124-
/>
125-
{open && isFocused ? (
126-
<ProjectKnowledgeSheet
127-
key={`${props.environmentId}:${props.projectId}:${props.draftKey}:${open.seed?.messageId ?? ""}`}
128-
{...props}
129-
// Older servers lack readFact, status and supersede.
130-
history={config.environment.capabilities.projectKnowledgeHistory === true}
131-
assisted={config.environment.capabilities.projectKnowledgeAssistedLearning === true}
132-
seedMessage={open.seed}
133-
onClose={() => setOpen(null)}
134-
/>
135-
) : null}
136-
</>
132+
<ProjectKnowledgeSheet
133+
key={`${props.environmentId}:${props.projectId}:${props.draftKey}:${open.seed?.messageId ?? ""}`}
134+
{...props}
135+
// Older servers lack readFact, status and supersede.
136+
history={config.environment.capabilities.projectKnowledgeHistory === true}
137+
assisted={config.environment.capabilities.projectKnowledgeAssistedLearning === true}
138+
seedMessage={open.seed}
139+
onClose={() => setOpen(null)}
140+
/>
137141
);
138142
}
139143

@@ -175,6 +179,7 @@ function ProjectKnowledgeSheet(
175179
editorDirty.current = dirty;
176180
}, []);
177181
const selectionVersion = useRef(0);
182+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- invalidates in-flight selection work when the sheet unmounts
178183
useEffect(
179184
() => () => {
180185
selectionVersion.current += 1;

‎apps/mobile/src/components/useRememberMessage.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { EnvironmentId, MessageId, ThreadId } from "@t3tools/contracts";
55
import { projectKnowledge } from "../state/projectKnowledge";
66
import { serverEnvironment } from "../state/server";
77
import { environmentThreadShells } from "../state/threads";
8-
import { requestRememberMessage } from "./ProjectKnowledgeEntry";
8+
import { requestProjectMemory } from "./ProjectKnowledgeEntry";
99

1010
/** Returns a "Remember for this project" action, or null when this thread cannot save facts. */
1111
export function useRememberMessage(
@@ -22,5 +22,5 @@ export function useRememberMessage(
2222
if (config?.environment.capabilities.projectKnowledge !== true || !canMutate || !projectId)
2323
return null;
2424
return (message: { readonly threadId: ThreadId; readonly messageId: MessageId }) =>
25-
requestRememberMessage({ environmentId, projectId, draftKey, message });
25+
requestProjectMemory({ environmentId, projectId, draftKey, message });
2626
}

‎apps/mobile/src/features/threads/DraftThreadHeader.tsx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ import { useEnvironmentScope } from "../../state/session";
1515
import { useAtomCommand } from "../../state/use-atom-command";
1616
import { vcsActionManager, vcsEnvironment } from "../../state/vcs";
1717
import { useVcsActionState } from "../../state/use-vcs-action-state";
18+
import { scopedThreadKey } from "../../lib/scopedEntities";
19+
import { useOpenProjectMemory } from "../../components/ProjectKnowledgeEntry";
1820
import { ThreadHeader } from "./ThreadHeader";
1921

2022
export function DraftThreadHeader(props: {
2123
readonly thread: EnvironmentThreadShell;
2224
readonly project: EnvironmentProject;
2325
readonly cwd: string | null;
26+
readonly draftKey: string | null | undefined;
2427
}) {
2528
const navigation = useNavigation();
2629
const { themeVariables } = useAppearancePreferences();
@@ -44,6 +47,12 @@ export function DraftThreadHeader(props: {
4447
projectName: props.project.title,
4548
});
4649
};
50+
const openProjectMemory = useOpenProjectMemory(
51+
environmentId,
52+
props.project.id,
53+
// ThreadComposer falls back to the thread's own key the same way.
54+
props.draftKey ?? scopedThreadKey(environmentId, props.thread.id),
55+
);
4756
const requiresThread = () =>
4857
Dialog.alert("Available after the first message", "This action needs a saved thread.");
4958
return (
@@ -60,6 +69,7 @@ export function DraftThreadHeader(props: {
6069
onToggleInspector={openFiles}
6170
onOpenFilesInspector={openFiles}
6271
onOpenGitInspector={requiresThread}
72+
onOpenProjectMemory={openProjectMemory}
6373
gitControls={{
6474
environmentId,
6575
threadId: props.thread.id,

‎apps/mobile/src/features/threads/NewTaskDraftScreen.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,12 @@ export function NewTaskDraftScreen(props: {
893893
<ThreadScreenBinding
894894
environmentId={selectedProject.environmentId}
895895
header={
896-
<DraftThreadHeader thread={thread} project={selectedProject} cwd={composerWorkspaceCwd} />
896+
<DraftThreadHeader
897+
thread={thread}
898+
project={selectedProject}
899+
cwd={composerWorkspaceCwd}
900+
draftKey={flow.draftKey}
901+
/>
897902
}
898903
draftMode={{
899904
content: heroViewport,

0 commit comments

Comments
 (0)