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:
committed by
GitHub
parent
7611076436
commit
34e8a24b20
@@ -20,6 +20,7 @@ import { opencodeClient } from "@/lib/opencode/client"
|
||||
import { runtimeFetch } from "@/lib/runtime-fetch"
|
||||
import { useConfigStore } from "@/stores/useConfigStore"
|
||||
import { useProjectsStore } from "@/stores/useProjectsStore"
|
||||
import { fetchSessionKnowledge, reportSessionKnowledgeDelivered } from "@/lib/sessionKnowledgeApi"
|
||||
import { useGlobalSessionsStore, resolveGlobalSessionDirectory } from "@/stores/useGlobalSessionsStore"
|
||||
import { useDirectoryStore } from "@/stores/useDirectoryStore"
|
||||
import { useSessionFoldersStore } from "@/stores/useSessionFoldersStore"
|
||||
@@ -1383,9 +1384,22 @@ export const useSessionUIStore = create<SessionUIState>()((set, get) => ({
|
||||
}, options?.draftSnapshot)
|
||||
if (!createdDraftSession) throw new Error("Failed to create session")
|
||||
|
||||
const mergedAdditionalParts = createdDraftSession.syntheticParts?.length
|
||||
const draftParts = createdDraftSession.syntheticParts?.length
|
||||
? [...(additionalParts || []), ...createdDraftSession.syntheticParts]
|
||||
: additionalParts
|
||||
// The server decides what this session still owes and assembles it; the
|
||||
// client only carries it and reports it delivered.
|
||||
const draftKnowledge = await fetchSessionKnowledge(
|
||||
createdDraftSession.directory,
|
||||
createdDraftSession.sessionId,
|
||||
)
|
||||
const draftPrefixParts: Array<{ text: string; attachments?: AttachedFile[]; synthetic?: boolean }> =
|
||||
draftKnowledge.text ? [{ text: draftKnowledge.text, synthetic: true }] : []
|
||||
// Left undefined when nothing was added, as before: an empty array is not
|
||||
// the same as no additional parts to everything downstream.
|
||||
const mergedAdditionalParts = draftPrefixParts.length > 0
|
||||
? [...draftPrefixParts, ...(draftParts || [])]
|
||||
: draftParts
|
||||
|
||||
notifyMessageSent(createdDraftSession.sessionId)
|
||||
|
||||
@@ -1422,6 +1436,15 @@ export const useSessionUIStore = create<SessionUIState>()((set, get) => ({
|
||||
})),
|
||||
})),
|
||||
})
|
||||
// Recorded only after the send resolves: a failed send must carry the
|
||||
// pinned context again rather than assume the agent already saw it.
|
||||
if (draftKnowledge.text) {
|
||||
void reportSessionKnowledgeDelivered(
|
||||
createdDraftSession.directory,
|
||||
createdDraftSession.sessionId,
|
||||
draftKnowledge.signature,
|
||||
)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1481,6 +1504,17 @@ export const useSessionUIStore = create<SessionUIState>()((set, get) => ({
|
||||
if (targetSessionId) {
|
||||
await applyArmedGoal(targetSessionId, currentSessionDirectory)
|
||||
}
|
||||
|
||||
// Standing project context — pinned notes and plans, and the memory index.
|
||||
// Prepended so it reads as background before the message it accompanies,
|
||||
// and empty unless the session is actually missing it.
|
||||
const knowledge = await fetchSessionKnowledge(currentSessionDirectory, targetSessionId || "")
|
||||
const prefixParts: Array<{ text: string; attachments?: AttachedFile[]; synthetic?: boolean }> =
|
||||
knowledge.text ? [{ text: knowledge.text, synthetic: true }] : []
|
||||
const partsWithPinnedContext = prefixParts.length > 0
|
||||
? [...prefixParts, ...(additionalParts || [])]
|
||||
: additionalParts
|
||||
|
||||
await routeMessage({
|
||||
runtimeKey: capturedTarget?.runtimeKey,
|
||||
sessionId: targetSessionId || "",
|
||||
@@ -1494,7 +1528,7 @@ export const useSessionUIStore = create<SessionUIState>()((set, get) => ({
|
||||
inputMode,
|
||||
files,
|
||||
delivery: options?.delivery,
|
||||
additionalParts: additionalParts?.map((p) => ({
|
||||
additionalParts: partsWithPinnedContext?.map((p) => ({
|
||||
text: p.text,
|
||||
synthetic: p.synthetic,
|
||||
files: p.attachments?.map((a) => ({
|
||||
@@ -1505,6 +1539,9 @@ export const useSessionUIStore = create<SessionUIState>()((set, get) => ({
|
||||
})),
|
||||
})),
|
||||
})
|
||||
if (knowledge.text) {
|
||||
void reportSessionKnowledgeDelivered(currentSessionDirectory, targetSessionId || "", knowledge.signature)
|
||||
}
|
||||
},
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -1540,9 +1577,20 @@ export const useSessionUIStore = create<SessionUIState>()((set, get) => ({
|
||||
// ---------------------------------------------------------------------------
|
||||
// deleteSession — calls SDK, SSE event updates child store
|
||||
// ---------------------------------------------------------------------------
|
||||
deleteSession: (id, options) => deleteSessionAction(id, options),
|
||||
deleteSession: async (id, options) => {
|
||||
const deleted = await deleteSessionAction(id, options)
|
||||
if (deleted) {
|
||||
// Nothing to forget here any more: what a session was told lives in its
|
||||
// own metadata and goes with it.
|
||||
}
|
||||
return deleted
|
||||
},
|
||||
|
||||
deleteSessions: (ids, options) => deleteSessionsAction(ids, options),
|
||||
deleteSessions: async (ids, options) => {
|
||||
const result = await deleteSessionsAction(ids, options)
|
||||
|
||||
return result
|
||||
},
|
||||
|
||||
archiveSession: (id) => archiveSessionAction(id),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user