feat(chat): preserve pinned messages across compaction

Add pin and unpin actions for user and assistant text messages, with clear compaction-survival labels, localized tooltips, status-info active styling, and VS Code gating where the server runtime is unavailable.

Persist pinned message IDs, creation timestamps, and roles under the OpenChamber session metadata namespace using fresh-read merge updates so goal, review, and other metadata remain intact.

Introduce a server runtime that reacts to OpenCode's dedicated session.compacted event, fetches pinned messages by ID, extracts and chronologically orders their text parts, and injects them as hidden synthetic context through prompt_async. The restoration prompt tells the agent to use the context silently while work remains and limits idle summaries to one short paragraph.

Track the last handled compaction summary to avoid replay duplication, tolerate individually missing pinned messages, integrate runtime shutdown, document ownership and limitations, and cover metadata round trips plus compaction injection behavior with focused tests.
This commit is contained in:
Bohdan Triapitsyn
2026-07-17 10:30:45 +03:00
parent 53d2dde87a
commit bd68e303d4
20 changed files with 457 additions and 2 deletions
+7
View File
@@ -74,6 +74,7 @@ import { createSessionRuntime } from './lib/opencode/session-runtime.js';
import { createOpenCodeWatcherRuntime } from './lib/opencode/watcher.js';
import { createSessionAssistRuntime } from './lib/session-assist/runtime.js';
import { createSessionGoalRuntime } from './lib/session-goal/runtime.js';
import { createContextObligatoryRuntime } from './lib/context-obligatory/runtime.js';
import { createScheduledTasksRuntime } from './lib/scheduled-tasks/runtime.js';
import { createServerStartupRuntime } from './lib/opencode/server-startup-runtime.js';
import { createTunnelWiringRuntime } from './lib/opencode/tunnel-wiring-runtime.js';
@@ -768,6 +769,10 @@ const sessionGoalRuntime = createSessionGoalRuntime({
});
},
});
const contextObligatoryRuntime = createContextObligatoryRuntime({
buildOpenCodeUrl,
getOpenCodeAuthHeaders,
});
const globalMessageStreamHub = createGlobalMessageStreamHub({
buildOpenCodeUrl,
@@ -813,6 +818,7 @@ globalMessageStreamHub.subscribeEvent((event) => {
: '';
sessionAssistRuntime.processPayload(payload, directory);
sessionGoalRuntime.processPayload(payload, directory);
contextObligatoryRuntime.processPayload(payload, directory);
});
const processForwardedEventPayload = (payload, emitSyntheticEvent) => {
@@ -1130,6 +1136,7 @@ const gracefulShutdownRuntime = createGracefulShutdownRuntime({
openCodeWatcherRuntime,
sessionAssistRuntime,
sessionGoalRuntime,
contextObligatoryRuntime,
sessionRuntime,
getHealthCheckInterval: () => healthCheckInterval,
clearHealthCheckInterval: (value) => clearInterval(value),