Files
openchamber/packages/web/server/lib/openchamber-control/action-resolution.test.js
T
Bohdan Triapitsyn 34e8a24b20 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.
2026-08-18 02:59:04 +03:00

66 lines
2.7 KiB
JavaScript

import { describe, expect, test } from 'bun:test';
import { resolveAgentToolAction } from './actions.js';
/**
* Both cases here are from one real conversation: the model called `read` and
* then `get` on `openchamber_memory`, having dropped the namespace its own tool
* name appeared to supply, and gave up after the second bare "unsupported".
*/
describe('a namespace the tool name already implies', () => {
test('resolves a bare action inside the calling tool', () => {
expect(resolveAgentToolAction('read', 'openchamber_memory')).toEqual({ action: 'memory.read' });
expect(resolveAgentToolAction('save', 'openchamber_memory')).toEqual({ action: 'memory.save' });
});
test('resolves a bare name that is ambiguous only across tools', () => {
// `delete` belongs to schedule and to memory; inside one tool it is plain.
expect(resolveAgentToolAction('delete', 'openchamber_memory')).toEqual({ action: 'memory.delete' });
expect(resolveAgentToolAction('delete', 'openchamber')).toEqual({ action: 'schedule.delete' });
});
test('keeps a fully qualified action as it is', () => {
expect(resolveAgentToolAction('memory.read', 'openchamber_memory')).toEqual({ action: 'memory.read' });
});
test('does not reach outside the tool that asked', () => {
// The memory tool asking for `open` must fail, not drive the browser.
expect(resolveAgentToolAction('open', 'openchamber_memory').action).toBeUndefined();
});
});
describe('an unidentified caller', () => {
test('still resolves a bare name that means one thing everywhere', () => {
expect(resolveAgentToolAction('snapshot', null)).toEqual({ action: 'browser.snapshot' });
});
test('refuses a bare name that several actions share', () => {
expect(resolveAgentToolAction('list', null).action).toBeUndefined();
});
});
describe('what an unresolvable action reports', () => {
test('names the actions the calling tool actually has', () => {
const { error } = resolveAgentToolAction('get', 'openchamber_memory');
expect(error).toContain('memory.read');
expect(error).toContain('memory.save');
// Listing every action of every tool would bury the four that apply.
expect(error).not.toContain('browser.open');
});
test('reports a missing action rather than resolving to something', () => {
const { error, action } = resolveAgentToolAction('', 'openchamber_memory');
expect(action).toBeUndefined();
expect(error).toContain('missing');
});
test('an unknown tool falls back to the full action list', () => {
const { error } = resolveAgentToolAction('nonsense', 'openchamber_future');
expect(error).toContain('memory.read');
expect(error).toContain('browser.open');
});
});