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.
57 lines
1.9 KiB
JavaScript
57 lines
1.9 KiB
JavaScript
/**
|
|
* Which project's memory a session directory belongs to.
|
|
*
|
|
* A session often runs in a worktree, whose path is not the project's path.
|
|
* Keying memory by the session directory filed a worktree's memories under a
|
|
* project the panel never reads, so the agent stored them and the user never
|
|
* saw them. Every worktree of a repository shares one project memory, which is
|
|
* also what the user means by "this project".
|
|
*
|
|
* A directory that is itself a configured project is taken as-is; anything else
|
|
* resolves to its primary worktree. The configured check comes first because a
|
|
* user may register a worktree as a project in its own right, and that choice
|
|
* has to win over the git topology.
|
|
*/
|
|
|
|
import path from 'node:path';
|
|
|
|
import { createProjectIdFromPath } from '../projects/project-id.js';
|
|
|
|
const normalize = (value) => {
|
|
if (typeof value !== 'string') return '';
|
|
const trimmed = value.trim();
|
|
return trimmed ? path.resolve(trimmed) : '';
|
|
};
|
|
|
|
export const createMemoryProjectResolver = (dependencies) => {
|
|
const { listProjectPaths, resolvePrimaryWorktreeRoot } = dependencies;
|
|
|
|
return async (directory) => {
|
|
const resolved = normalize(directory);
|
|
if (!resolved) {
|
|
return '';
|
|
}
|
|
|
|
let configured = [];
|
|
try {
|
|
configured = ((await listProjectPaths()) || []).map(normalize).filter(Boolean);
|
|
} catch {
|
|
// An unreadable project list must not lose the memory: the git-derived
|
|
// root below still converges every worktree of the repository on one
|
|
// store rather than scattering one per checkout.
|
|
}
|
|
if (configured.includes(resolved)) {
|
|
return createProjectIdFromPath(resolved);
|
|
}
|
|
|
|
let primaryRoot = '';
|
|
try {
|
|
primaryRoot = normalize((await resolvePrimaryWorktreeRoot(resolved))?.root);
|
|
} catch {
|
|
// Not a git checkout, or git is unavailable.
|
|
}
|
|
|
|
return createProjectIdFromPath(primaryRoot || resolved);
|
|
};
|
|
};
|