feat(knowledge): rebuild the project notes panel as Project knowledge (#2973)

The panel stored notes, todos and plans inside one shared JSON file that
six unrelated domains also wrote to, synchronised itself through window
CustomEvents, and could only read plans. It is now Project knowledge:
server-owned storage with explicit routes, a store with rollback, a
section sidebar, plans that open and edit in place, and search across
all of it.

Notes and plans the user pins travel with every message sent in that
project. Pinning is project state, not an attachment to one message, so
it holds until unpinned and the work status panel names what is riding
along and can detach it.

Agent memory is added alongside, in two scopes: what is true about the
user, and what is true about this codebase. The split is not cosmetic —
a wrong project fact costs one project and is noticed, while a wrong
global fact quietly shapes every session everywhere and the user has no
code to check it against. It stays separate from notes so an agent
mistake cannot land in what the user wrote. Sessions receive an index of
titles only; bodies are read on demand, because an index carrying full
text grows until it crowds out the conversation.

Deciding what a session must be told, and whether it has been told, now
lives on the server. The client owned it before, which meant sessions
started without a UI — scheduled tasks, sessions the agent dispatches —
received nothing at all, and a tab's record of what it had sent outlived
the conversation: after compaction the agent no longer held the block
while the tab went on believing it did. What was delivered is recorded
in the session's own metadata, and compaction restores it through the
runtime that already restores pinned messages, in the same turn.

Agent memory ships dark behind OPENCHAMBER_MEMORY_ENABLE: unset, there
is no tool, no routes, no session index, no settings row and no panel
tab. Absent rather than switched off, so nothing invites turning on a
feature that has not been announced. Pinned notes and plans are
unaffected and ship as normal.
This commit is contained in:
Bohdan Triapitsyn
2026-08-18 02:59:04 +03:00
committed by GitHub
parent 7611076436
commit 34e8a24b20
102 changed files with 10640 additions and 1630 deletions
+61 -9
View File
@@ -38,7 +38,8 @@ import { useEffectiveDirectory } from '@/hooks/useEffectiveDirectory';
import { EditorView } from '@codemirror/view';
import { copyTextToClipboard } from '@/lib/clipboard';
import { generateBranchName } from '@/lib/git/branchNameGenerator';
import { parseProjectPlanMarkdown } from '@/lib/openchamberConfig';
import { fetchProjectPlan, parsePlanMarkdown } from '@/lib/projectContextApi';
import { useProjectContextStore } from '@/stores/useProjectContextStore';
import { createWorktreeSessionForNewBranch } from '@/lib/worktreeSessionCreator';
import { TodoSendDialog, type TodoSendExecution } from '@/components/session/TodoSendDialog';
import { Icon } from "@/components/icon/Icon";
@@ -48,6 +49,9 @@ import { useI18n } from '@/lib/i18n';
type PlanViewProps = {
targetPath?: string | null;
/** Saved project plan to open. Project plans are server-owned and addressed
by id; they never carry a client-visible filesystem path. */
projectPlanId?: string | null;
/** Called after a send action routes the user to the chat — hosts that show
PlanView in an overlay (mobile fullscreen surface) close it here. */
onNavigatedToChat?: () => void;
@@ -150,7 +154,7 @@ type SelectedLineRange = {
end: number;
};
export const PlanView: React.FC<PlanViewProps> = ({ targetPath = null, onNavigatedToChat }) => {
export const PlanView: React.FC<PlanViewProps> = ({ targetPath = null, projectPlanId = null, onNavigatedToChat }) => {
const { t } = useI18n();
const currentSessionId = useSessionUIStore((state) => state.currentSessionId);
const createSession = useSessionUIStore((state) => state.createSession);
@@ -195,6 +199,12 @@ export const PlanView: React.FC<PlanViewProps> = ({ targetPath = null, onNavigat
const [isPlanSendSubmitting, setIsPlanSendSubmitting] = React.useState(false);
const [resolvedPath, setResolvedPath] = React.useState<string | null>(null);
// Set once a saved project plan has actually loaded. Kept separate from
// `resolvedPath` so nothing downstream can mistake a project plan for a file
// the user could open, edit, or be shown a path for.
const [loadedProjectPlanId, setLoadedProjectPlanId] = React.useState<string | null>(null);
const savePlan = useProjectContextStore((state) => state.savePlan);
const hasDocument = Boolean(resolvedPath) || Boolean(loadedProjectPlanId);
const displayPath = React.useMemo(() => {
if (!resolvedPath || !sessionDirectory || !homeDirectory) {
return resolvedPath;
@@ -212,7 +222,7 @@ export const PlanView: React.FC<PlanViewProps> = ({ targetPath = null, onNavigat
if (!content.trim()) {
return t('planView.title.default');
}
return parseProjectPlanMarkdown(content).title || t('planView.title.default');
return parsePlanMarkdown(content, t('planView.title.default')).title;
}, [content, t]);
const sendPromptTitle = React.useMemo(() => parsedTitle.trim() || t('planView.title.default'), [parsedTitle, t]);
const [loading, setLoading] = React.useState(false);
@@ -374,8 +384,9 @@ export const PlanView: React.FC<PlanViewProps> = ({ targetPath = null, onNavigat
React.useEffect(() => {
// Saved project plans opened via context panel should work even when session plan mode is off.
if (!planModeEnabled && !targetPath) {
if (!planModeEnabled && !targetPath && !projectPlanId) {
setResolvedPath(null);
setLoadedProjectPlanId(null);
setContent('');
setLoading(false);
return;
@@ -407,9 +418,36 @@ export const PlanView: React.FC<PlanViewProps> = ({ targetPath = null, onNavigat
const run = async () => {
setResolvedPath(null);
setLoadedProjectPlanId(null);
setContent('');
setSaveError(null);
if (projectPlanId) {
if (!currentProjectRef) {
return;
}
setLoading(true);
try {
const plan = await fetchProjectPlan(currentProjectRef, projectPlanId);
if (cancelled) return;
if (!plan) {
// The plan or its markdown is gone. Leave the view empty and
// unsaveable rather than presenting an editor that would recreate
// a document the user deleted.
setSaveError(t('planView.error.loadFailed'));
return;
}
setContent(plan.raw);
setLoadedProjectPlanId(projectPlanId);
} catch (error) {
if (cancelled) return;
setSaveError(error instanceof Error ? error.message : t('planView.error.loadFailed'));
} finally {
if (!cancelled) setLoading(false);
}
return;
}
if (targetPath) {
setLoading(true);
try {
@@ -482,17 +520,31 @@ export const PlanView: React.FC<PlanViewProps> = ({ targetPath = null, onNavigat
return () => {
cancelled = true;
};
}, [homeDirectory, planModeEnabled, runtimeApis.files, sessionDirectory, session?.slug, session?.time?.created, targetPath]);
}, [currentProjectRef, homeDirectory, planModeEnabled, projectPlanId, runtimeApis.files, sessionDirectory, session?.slug, session?.time?.created, t, targetPath]);
React.useEffect(() => {
if (!resolvedPath) {
setSaveError(null);
if (!resolvedPath && !loadedProjectPlanId) {
return;
}
const controller = window.setTimeout(async () => {
setSaveError(null);
try {
if (loadedProjectPlanId) {
if (!currentProjectRef) {
throw new Error(t('planView.error.writeFailed'));
}
const saved = await savePlan(currentProjectRef, loadedProjectPlanId, content);
if (!saved) {
throw new Error(t('planView.error.writeFailed'));
}
return;
}
if (!resolvedPath) {
return;
}
if (runtimeApis.files?.writeFile) {
const result = await runtimeApis.files.writeFile(resolvedPath, content);
if (!result?.success) {
@@ -516,7 +568,7 @@ export const PlanView: React.FC<PlanViewProps> = ({ targetPath = null, onNavigat
return () => {
window.clearTimeout(controller);
};
}, [content, resolvedPath, runtimeApis.files, t]);
}, [content, currentProjectRef, loadedProjectPlanId, resolvedPath, runtimeApis.files, savePlan, t]);
React.useEffect(() => {
return () => {
@@ -672,7 +724,7 @@ export const PlanView: React.FC<PlanViewProps> = ({ targetPath = null, onNavigat
</div>
) : null}
</div>
{resolvedPath ? (
{hasDocument ? (
<div className="flex items-center gap-1">
<DropdownMenu>
<Tooltip>