feat: сохранять настройки и сессии супервизора в Pi 1.4

This commit is contained in:
Suslov-MD
2026-10-25 15:53:47 +03:00
parent ced355b0ee
commit a73e09d5a1
21 changed files with 1134 additions and 142 deletions
@@ -1,3 +1,6 @@
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import test from 'node:test';
import assert from 'node:assert/strict';
import { setImmediate as tick } from 'node:timers/promises';
@@ -5,6 +8,13 @@ import supervisorExtension, { isLocalEndpoint } from '../src/index.ts';
import { captureSession, parseReport } from '../src/evidence.ts';
import { SupervisorObserver } from '../src/observer.ts';
const temporaryRoots = [];
test.after(() => {
for (const root of temporaryRoots) {
fs.rmSync(root, { recursive: true, force: true });
}
});
const event = (id, text = id) => ({ id, type: 'message', role: 'user', content: text });
const snapshot = (...events) => ({ sourceId: 'synthetic-session', events });
const note = (id, summary = 'Проверка результата пропущена') => ({
@@ -290,6 +300,8 @@ test('clear begins at a new boundary, reports skipped work honestly and rejects
});
function harness(complete = async () => reply()) {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'supervisor-test-'));
temporaryRoots.push(root);
const handlers = new Map();
const commands = new Map();
const notices = [];
@@ -308,9 +320,14 @@ function harness(complete = async () => reply()) {
};
const ctx = {
hasUI: true,
cwd: path.join(root, 'project'),
model,
getSystemPrompt: () => 'Synthetic instructions',
sessionManager: { getSessionId: () => 'synthetic-session', getBranch: () => state.entries },
sessionManager: {
getSessionId: () => 'synthetic-session',
getBranch: () => state.entries,
getSessionFile: () => undefined,
},
modelRegistry: {
find: (provider, id) => (provider === 'local' ? { ...model, id } : undefined),
getApiKeyAndHeaders: async () => ({ ok: true }),
@@ -326,13 +343,26 @@ function harness(complete = async () => reply()) {
},
};
const pi = {
on: (name, handler) => handlers.set(name, handler),
getActiveTools: () => ['read', 'bash'],
setActiveTools: () => {},
on: (name, handler) => {
const previous = handlers.get(name);
handlers.set(
name,
previous
? (...args) => {
previous(...args);
return handler(...args);
}
: handler,
);
},
registerCommand: (name, command) => commands.set(name, command),
sendMessage: () => assert.fail('Observer must not add to the main transcript'),
sendUserMessage: () => assert.fail('Observer must not start a main-agent turn'),
appendEntry: () => assert.fail('Observer must not persist raw data or reports'),
};
supervisorExtension(pi);
supervisorExtension(pi, root);
return {
handlers,
notices,