synabun 2.4.3 → 2.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +1 -1
- package/docs/browser-extension-bridge.md +61 -32
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +8 -1
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/services/identity.d.ts +2 -0
- package/mcp-server/dist/services/identity.d.ts.map +1 -1
- package/mcp-server/dist/services/identity.js +4 -0
- package/mcp-server/dist/services/identity.js.map +1 -1
- package/mcp-server/dist/services/memory-client.d.ts +5 -0
- package/mcp-server/dist/services/memory-client.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-client.js +21 -2
- package/mcp-server/dist/services/memory-client.js.map +1 -1
- package/mcp-server/dist/services/memory-writer.d.ts +3 -0
- package/mcp-server/dist/services/memory-writer.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-writer.js +7 -1
- package/mcp-server/dist/services/memory-writer.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +11 -1
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +67 -17
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/typesafe-config.d.ts +38 -2
- package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe-config.js +260 -8
- package/mcp-server/dist/services/typesafe-config.js.map +1 -1
- package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
- package/mcp-server/dist/tools/agents.d.ts +3 -1
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +11 -6
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/browser-observe.d.ts +11 -0
- package/mcp-server/dist/tools/browser-observe.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-observe.js +113 -27
- package/mcp-server/dist/tools/browser-observe.js.map +1 -1
- package/mcp-server/dist/tools/browser-readers.d.ts +6 -0
- package/mcp-server/dist/tools/browser-readers.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser-readers.js +17 -0
- package/mcp-server/dist/tools/browser-readers.js.map +1 -0
- package/mcp-server/dist/tools/remember.d.ts.map +1 -1
- package/mcp-server/dist/tools/remember.js +6 -2
- package/mcp-server/dist/tools/remember.js.map +1 -1
- package/mcp-server/dist/tools/youtube/analytics.d.ts +4 -0
- package/mcp-server/dist/tools/youtube/analytics.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/analytics.js +25 -20
- package/mcp-server/dist/tools/youtube/analytics.js.map +1 -1
- package/mcp-server/dist/tools/youtube/helpers.d.ts +5 -1
- package/mcp-server/dist/tools/youtube/helpers.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/helpers.js +7 -3
- package/mcp-server/dist/tools/youtube/helpers.js.map +1 -1
- package/mcp-server/dist/tools/youtube/navigate.d.ts +2 -0
- package/mcp-server/dist/tools/youtube/navigate.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/navigate.js +5 -3
- package/mcp-server/dist/tools/youtube/navigate.js.map +1 -1
- package/mcp-server/dist/tools/youtube/playlist.js +2 -2
- package/mcp-server/dist/tools/youtube/playlist.js.map +1 -1
- package/mcp-server/dist/tools/youtube/readers.d.ts +4 -0
- package/mcp-server/dist/tools/youtube/readers.d.ts.map +1 -0
- package/mcp-server/dist/tools/youtube/readers.js +15 -0
- package/mcp-server/dist/tools/youtube/readers.js.map +1 -0
- package/mcp-server/package-lock.json +2 -2
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +8 -1
- package/mcp-server/src/services/identity.ts +5 -0
- package/mcp-server/src/services/memory-client.ts +32 -12
- package/mcp-server/src/services/memory-writer.ts +5 -2
- package/mcp-server/src/services/neural-interface.ts +65 -18
- package/mcp-server/src/services/typesafe-config.ts +268 -7
- package/mcp-server/src/tools/agents.ts +12 -6
- package/mcp-server/src/tools/browser-observe.ts +117 -28
- package/mcp-server/src/tools/browser-readers.ts +19 -0
- package/mcp-server/src/tools/remember.ts +6 -1
- package/mcp-server/src/tools/youtube/analytics.ts +26 -28
- package/mcp-server/src/tools/youtube/helpers.ts +8 -2
- package/mcp-server/src/tools/youtube/navigate.ts +6 -7
- package/mcp-server/src/tools/youtube/playlist.ts +2 -2
- package/mcp-server/src/tools/youtube/readers.ts +15 -0
- package/neural-interface/i18n/en.json +139 -0
- package/neural-interface/i18n/pt-BR.json +139 -0
- package/neural-interface/lib/assistant-api.js +90 -0
- package/neural-interface/lib/assistant-brains/claude.js +10 -0
- package/neural-interface/lib/assistant-dispatch.js +276 -42
- package/neural-interface/lib/assistant-memory.js +3 -1
- package/neural-interface/lib/assistant-persona.js +6 -0
- package/neural-interface/lib/assistant-router.js +18 -8
- package/neural-interface/lib/assistant-runtime.js +87 -1
- package/neural-interface/lib/assistant-task-prompt.js +15 -2
- package/neural-interface/lib/browser-connection-state.js +20 -0
- package/neural-interface/lib/browser-extension-adapter.js +221 -15
- package/neural-interface/lib/browser-extension-bridge.js +40 -7
- package/neural-interface/lib/browser-extension-folder.js +50 -11
- package/neural-interface/lib/browser-extension-package.js +6 -5
- package/neural-interface/lib/browser-extension-pin.json +15 -13
- package/neural-interface/lib/browser-extension-protocol.js +111 -13
- package/neural-interface/lib/browser-extension-setup.js +7 -5
- package/neural-interface/lib/browser-extension-update.js +104 -0
- package/neural-interface/lib/browser-extraction.js +38 -14
- package/neural-interface/lib/claude-bg-tasks.js +183 -0
- package/neural-interface/lib/claude-history.js +12 -1
- package/neural-interface/lib/confined-fs.js +25 -0
- package/neural-interface/lib/coordination/operations.js +2 -0
- package/neural-interface/lib/db.js +39 -16
- package/neural-interface/lib/editor-completion-opencode.js +2 -2
- package/neural-interface/lib/git-bash/manager.js +28 -3
- package/neural-interface/lib/git-status-runner.js +31 -3
- package/neural-interface/lib/loop-inventory.js +162 -0
- package/neural-interface/lib/loop-stall.js +74 -4
- package/neural-interface/lib/memory-session-capture.js +157 -66
- package/neural-interface/lib/native-loop-providers.js +73 -13
- package/neural-interface/lib/native-loop-runtime.js +3 -0
- package/neural-interface/lib/opencode-protocol.js +4 -2
- package/neural-interface/lib/peer-identity.js +62 -16
- package/neural-interface/lib/session-cache-builder.js +66 -18
- package/neural-interface/lib/session-capture-gate.js +42 -0
- package/neural-interface/lib/session-indexer.js +28 -20
- package/neural-interface/lib/teams/scheduler.js +3 -2
- package/neural-interface/lib/ui-blob-api.js +14 -5
- package/neural-interface/lib/ui-blob-store.js +302 -39
- package/neural-interface/package-lock.json +2 -2
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/extension-setup.html +1 -0
- package/neural-interface/public/shared/assistant/asst-agents-dock.js +4 -0
- package/neural-interface/public/shared/assistant/asst-api.js +42 -0
- package/neural-interface/public/shared/assistant/asst-composer.js +85 -12
- package/neural-interface/public/shared/assistant/asst-panel.js +285 -10
- package/neural-interface/public/shared/assistant/asst-render.js +205 -4
- package/neural-interface/public/shared/assistant/asst-scenes.js +12 -0
- package/neural-interface/public/shared/assistant/asst-sidepanel.js +18 -1
- package/neural-interface/public/shared/assistant/asst-state.js +241 -2
- package/neural-interface/public/shared/assistant/asst-steer.js +294 -0
- package/neural-interface/public/shared/assistant/asst-styles.js +20 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-claude.js +147 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-model.js +527 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-panel.js +161 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-view.js +508 -0
- package/neural-interface/public/shared/browser-extension-updates.js +88 -0
- package/neural-interface/public/shared/cp/cp-bg-tasks.js +130 -0
- package/neural-interface/public/shared/extension-setup/es-page.js +18 -11
- package/neural-interface/public/shared/extension-update-view.js +34 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-logic.js +8 -4
- package/neural-interface/public/shared/settings/settings-browser-extension.js +10 -4
- package/neural-interface/public/shared/settings/settings-extension-update.js +114 -0
- package/neural-interface/public/shared/styles.css +4 -0
- package/neural-interface/public/shared/ui-claude-panel.js +110 -1
- package/neural-interface/public/shared/ui-notifications.js +23 -4
- package/neural-interface/public/shared/ui-settings-entry.js +6 -0
- package/neural-interface/public/shared/ui-tray-columns.js +9 -2
- package/neural-interface/public/shared/worker-end.js +18 -0
- package/neural-interface/scripts/patch-node-pty.mjs +151 -0
- package/neural-interface/scripts/rebuild-pty.js +10 -0
- package/neural-interface/server.js +483 -280
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -12,13 +12,101 @@
|
|
|
12
12
|
// HTML churn would bloat its WAL and backups for no benefit.
|
|
13
13
|
|
|
14
14
|
import { DatabaseSync } from 'node:sqlite';
|
|
15
|
+
import { Worker, isMainThread, parentPort, workerData } from 'node:worker_threads';
|
|
16
|
+
import { setTimeout, clearTimeout } from 'node:timers';
|
|
15
17
|
import { dirname } from 'path';
|
|
16
18
|
import { existsSync, mkdirSync } from 'fs';
|
|
17
19
|
|
|
20
|
+
const MAX_TRIM_ROWS = 128;
|
|
21
|
+
const DELETE_BATCH = 32;
|
|
22
|
+
const DEFAULT_BACKFILL_BATCH = 16;
|
|
23
|
+
const NAMESPACE_READ_PAGE = 25;
|
|
24
|
+
const WORKER_IDLE_MS = 5000;
|
|
25
|
+
|
|
18
26
|
let db = null;
|
|
19
27
|
let dbPath = null;
|
|
28
|
+
let backfillTimer = null;
|
|
29
|
+
let recountThrough = 0;
|
|
30
|
+
let readerState = null;
|
|
31
|
+
let readerJobSeq = 0;
|
|
32
|
+
|
|
33
|
+
function terminateReaderWorker(reason = 'ui-blob-store closed') {
|
|
34
|
+
const current = readerState;
|
|
35
|
+
if (!current) return;
|
|
36
|
+
readerState = null;
|
|
37
|
+
if (current.idleTimer) { clearTimeout(current.idleTimer); current.idleTimer = null; }
|
|
38
|
+
if (current.jobs.size) {
|
|
39
|
+
const err = new Error(reason);
|
|
40
|
+
for (const job of current.jobs.values()) job.reject(err);
|
|
41
|
+
current.jobs.clear();
|
|
42
|
+
}
|
|
43
|
+
try { void current.worker.terminate(); } catch {}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function ensureSchema(d) {
|
|
47
|
+
d.exec(`
|
|
48
|
+
CREATE TABLE IF NOT EXISTS ui_blobs (
|
|
49
|
+
ns TEXT NOT NULL, id TEXT NOT NULL, value TEXT NOT NULL,
|
|
50
|
+
value_chars INTEGER, updated_at INTEGER NOT NULL, PRIMARY KEY (ns, id)
|
|
51
|
+
);
|
|
52
|
+
CREATE TABLE IF NOT EXISTS ui_blob_meta (k TEXT PRIMARY KEY, v INTEGER NOT NULL);
|
|
53
|
+
`);
|
|
54
|
+
if (!d.prepare('PRAGMA table_info(ui_blobs)').all().some(col => col.name === 'value_chars')) {
|
|
55
|
+
d.exec('ALTER TABLE ui_blobs ADD COLUMN value_chars INTEGER');
|
|
56
|
+
}
|
|
57
|
+
d.exec(`
|
|
58
|
+
DROP TRIGGER IF EXISTS trg_ui_blobs_ai_chars;
|
|
59
|
+
DROP TRIGGER IF EXISTS trg_ui_blobs_au_chars;
|
|
60
|
+
DROP TRIGGER IF EXISTS trg_ui_blobs_au_rev;
|
|
61
|
+
DROP INDEX IF EXISTS idx_ui_blobs_ns_updated;
|
|
62
|
+
DROP INDEX IF EXISTS idx_ui_blobs_null_chars;
|
|
63
|
+
CREATE INDEX IF NOT EXISTS idx_ui_blobs_trim ON ui_blobs(ns, updated_at DESC, id DESC, value_chars);
|
|
64
|
+
INSERT OR IGNORE INTO ui_blob_meta (k, v)
|
|
65
|
+
SELECT 'recount_through', COALESCE(MAX(rowid), 0) FROM ui_blobs;
|
|
66
|
+
`);
|
|
67
|
+
return d.prepare("SELECT v FROM ui_blob_meta WHERE k = 'recount_through'").get().v;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Recount pre-upgrade rows (both NULL and old UTF-16 counts). The rowid keyset and
|
|
71
|
+
// its checkpoint commit together. New writes already use SQLite LENGTH().
|
|
72
|
+
export function backfillBlobValueCharsBatch(limit = DEFAULT_BACKFILL_BATCH) {
|
|
73
|
+
if (!db || !recountThrough) return 0;
|
|
74
|
+
const batch = Math.max(1, Math.min(DEFAULT_BACKFILL_BATCH, Math.trunc(limit) || DEFAULT_BACKFILL_BATCH));
|
|
75
|
+
const rows = db.prepare('SELECT rowid FROM ui_blobs WHERE rowid <= ? ORDER BY rowid DESC LIMIT ?')
|
|
76
|
+
.all(recountThrough, batch);
|
|
77
|
+
const next = rows.length === batch ? Math.max(0, rows.at(-1).rowid - 1) : 0;
|
|
78
|
+
db.exec('BEGIN');
|
|
79
|
+
try {
|
|
80
|
+
if (rows.length) {
|
|
81
|
+
db.prepare('UPDATE ui_blobs SET value_chars = LENGTH(value) WHERE rowid BETWEEN ? AND ?')
|
|
82
|
+
.run(rows.at(-1).rowid, rows[0].rowid);
|
|
83
|
+
}
|
|
84
|
+
db.prepare("UPDATE ui_blob_meta SET v = ? WHERE k = 'recount_through'").run(next);
|
|
85
|
+
db.exec('COMMIT');
|
|
86
|
+
recountThrough = next;
|
|
87
|
+
return rows.length;
|
|
88
|
+
} catch (err) {
|
|
89
|
+
db.exec('ROLLBACK');
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function scheduleBackfill() {
|
|
95
|
+
if (!recountThrough) return;
|
|
96
|
+
backfillTimer = setTimeout(() => {
|
|
97
|
+
try {
|
|
98
|
+
backfillBlobValueCharsBatch();
|
|
99
|
+
} catch (err) {
|
|
100
|
+
console.warn('[ui-blobs] Character recount paused until next open:', err.message);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
scheduleBackfill();
|
|
104
|
+
}, 25);
|
|
105
|
+
backfillTimer.unref();
|
|
106
|
+
}
|
|
20
107
|
|
|
21
108
|
export function initBlobStore(path) {
|
|
109
|
+
if (db && dbPath !== path) closeBlobStore();
|
|
22
110
|
dbPath = path;
|
|
23
111
|
return getBlobDb();
|
|
24
112
|
}
|
|
@@ -26,19 +114,24 @@ export function initBlobStore(path) {
|
|
|
26
114
|
function getBlobDb() {
|
|
27
115
|
if (!db) {
|
|
28
116
|
if (!dbPath) throw new Error('ui-blob-store: initBlobStore(path) not called');
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
)
|
|
117
|
+
if (dbPath !== ':memory:') {
|
|
118
|
+
const dir = dirname(dbPath);
|
|
119
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
120
|
+
}
|
|
121
|
+
const opened = new DatabaseSync(dbPath);
|
|
122
|
+
try {
|
|
123
|
+
if (dbPath !== ':memory:') opened.exec('PRAGMA journal_mode = WAL');
|
|
124
|
+
opened.exec('PRAGMA busy_timeout = 5000');
|
|
125
|
+
opened.exec('BEGIN');
|
|
126
|
+
recountThrough = ensureSchema(opened);
|
|
127
|
+
opened.exec('COMMIT');
|
|
128
|
+
} catch (err) {
|
|
129
|
+
try { opened.close(); } catch {}
|
|
130
|
+
throw err;
|
|
131
|
+
}
|
|
132
|
+
// Publish the connection only after PRAGMAs and ensureSchema() succeed.
|
|
133
|
+
db = opened;
|
|
134
|
+
scheduleBackfill();
|
|
42
135
|
}
|
|
43
136
|
return db;
|
|
44
137
|
}
|
|
@@ -53,6 +146,106 @@ export function blobGetNamespace(ns) {
|
|
|
53
146
|
return out;
|
|
54
147
|
}
|
|
55
148
|
|
|
149
|
+
function buildNamespaceJsonSync(d, ns, pageSize = NAMESPACE_READ_PAGE) {
|
|
150
|
+
const firstStmt = d.prepare('SELECT id, value FROM ui_blobs WHERE ns = ? ORDER BY id ASC LIMIT ?');
|
|
151
|
+
const nextStmt = d.prepare('SELECT id, value FROM ui_blobs WHERE ns = ? AND id > ? ORDER BY id ASC LIMIT ?');
|
|
152
|
+
let lastId = null;
|
|
153
|
+
const parts = ['{'];
|
|
154
|
+
let first = true;
|
|
155
|
+
for (;;) {
|
|
156
|
+
const rows = lastId === null ? firstStmt.all(ns, pageSize) : nextStmt.all(ns, lastId, pageSize);
|
|
157
|
+
if (!rows.length) break;
|
|
158
|
+
for (const row of rows) {
|
|
159
|
+
lastId = row.id;
|
|
160
|
+
try {
|
|
161
|
+
const parsed = JSON.parse(row.value);
|
|
162
|
+
const encoded = JSON.stringify(parsed);
|
|
163
|
+
if (encoded === undefined) continue;
|
|
164
|
+
parts.push(`${first ? '' : ','}${JSON.stringify(row.id)}:${encoded}`);
|
|
165
|
+
first = false;
|
|
166
|
+
} catch { /* skip corrupt row */ }
|
|
167
|
+
}
|
|
168
|
+
if (rows.length < pageSize) break;
|
|
169
|
+
}
|
|
170
|
+
parts.push('}');
|
|
171
|
+
return parts.join('');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function getOrCreateReaderWorker(targetPath) {
|
|
175
|
+
if (readerState && readerState.path !== targetPath) {
|
|
176
|
+
terminateReaderWorker('ui-blob-store path changed');
|
|
177
|
+
}
|
|
178
|
+
if (!readerState) {
|
|
179
|
+
const worker = new Worker(new URL(import.meta.url), {
|
|
180
|
+
workerData: { uiBlobReader: true },
|
|
181
|
+
execArgv: process.execArgv.filter((arg) => arg === '--experimental-sqlite'),
|
|
182
|
+
});
|
|
183
|
+
const state = { worker, path: targetPath, jobs: new Map(), idleTimer: null };
|
|
184
|
+
readerState = state;
|
|
185
|
+
worker.on('message', (msg) => {
|
|
186
|
+
const job = state.jobs.get(msg.id);
|
|
187
|
+
if (!job) return;
|
|
188
|
+
state.jobs.delete(msg.id);
|
|
189
|
+
if (state.jobs.size === 0 && readerState === state) {
|
|
190
|
+
worker.unref();
|
|
191
|
+
if (state.idleTimer) clearTimeout(state.idleTimer);
|
|
192
|
+
state.idleTimer = setTimeout(() => {
|
|
193
|
+
state.idleTimer = null;
|
|
194
|
+
if (readerState === state && state.jobs.size === 0) {
|
|
195
|
+
terminateReaderWorker('idle');
|
|
196
|
+
}
|
|
197
|
+
}, WORKER_IDLE_MS);
|
|
198
|
+
state.idleTimer.unref?.();
|
|
199
|
+
}
|
|
200
|
+
if (msg.error) job.reject(new Error(msg.error));
|
|
201
|
+
else job.resolve(Buffer.from(msg.bytes.buffer, msg.bytes.byteOffset, msg.bytes.byteLength));
|
|
202
|
+
});
|
|
203
|
+
const onWorkerEnd = (err) => {
|
|
204
|
+
if (state.idleTimer) { clearTimeout(state.idleTimer); state.idleTimer = null; }
|
|
205
|
+
if (readerState === state) readerState = null;
|
|
206
|
+
if (state.jobs.size) {
|
|
207
|
+
const error = err || new Error('ui-blob reader worker exited before replying');
|
|
208
|
+
for (const job of state.jobs.values()) job.reject(error);
|
|
209
|
+
state.jobs.clear();
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
worker.once('error', onWorkerEnd);
|
|
213
|
+
worker.once('exit', () => onWorkerEnd());
|
|
214
|
+
}
|
|
215
|
+
return readerState;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Read and serialize an entire namespace as a UTF-8 JSON Buffer off the event loop
|
|
220
|
+
* (in a short-lived worker thread for file-backed DBs).
|
|
221
|
+
* Preserves the exact `{ [id]: value }` response contract for GET /api/ui-blobs/:ns.
|
|
222
|
+
*/
|
|
223
|
+
export async function blobGetNamespaceJsonAsync(ns) {
|
|
224
|
+
const d = getBlobDb();
|
|
225
|
+
if (!dbPath || dbPath === ':memory:') {
|
|
226
|
+
return Buffer.from(buildNamespaceJsonSync(d, ns));
|
|
227
|
+
}
|
|
228
|
+
const targetPath = dbPath;
|
|
229
|
+
const state = getOrCreateReaderWorker(targetPath);
|
|
230
|
+
if (state.idleTimer) { clearTimeout(state.idleTimer); state.idleTimer = null; }
|
|
231
|
+
state.worker.ref();
|
|
232
|
+
const id = ++readerJobSeq;
|
|
233
|
+
return new Promise((resolve, reject) => {
|
|
234
|
+
state.jobs.set(id, { resolve, reject });
|
|
235
|
+
try {
|
|
236
|
+
state.worker.postMessage({ id, dbPath: targetPath, ns });
|
|
237
|
+
} catch (err) {
|
|
238
|
+
state.jobs.delete(id);
|
|
239
|
+
reject(err);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export async function blobGetNamespaceAsync(ns) {
|
|
245
|
+
const buf = await blobGetNamespaceJsonAsync(ns);
|
|
246
|
+
return JSON.parse(buf.toString('utf8'));
|
|
247
|
+
}
|
|
248
|
+
|
|
56
249
|
export function blobGet(ns, id) {
|
|
57
250
|
const d = getBlobDb();
|
|
58
251
|
const row = d.prepare('SELECT value FROM ui_blobs WHERE ns = ? AND id = ?').get(ns, id);
|
|
@@ -62,15 +255,20 @@ export function blobGet(ns, id) {
|
|
|
62
255
|
|
|
63
256
|
export function blobPut(ns, id, value) {
|
|
64
257
|
const d = getBlobDb();
|
|
258
|
+
const serialized = JSON.stringify(value);
|
|
259
|
+
// Keep the last write newest through millisecond ties and backwards clock steps.
|
|
65
260
|
d.prepare(`
|
|
66
|
-
INSERT INTO ui_blobs (ns, id, value, updated_at)
|
|
67
|
-
|
|
68
|
-
|
|
261
|
+
INSERT INTO ui_blobs (ns, id, value, value_chars, updated_at)
|
|
262
|
+
VALUES (?, ?, ?, LENGTH(?), MAX(?, COALESCE((
|
|
263
|
+
SELECT updated_at + 1 FROM ui_blobs WHERE ns = ? ORDER BY updated_at DESC LIMIT 1
|
|
264
|
+
), 0)))
|
|
265
|
+
ON CONFLICT(ns, id) DO UPDATE SET
|
|
266
|
+
value = excluded.value, value_chars = excluded.value_chars, updated_at = excluded.updated_at
|
|
267
|
+
`).run(ns, id, serialized, serialized, Date.now(), ns);
|
|
69
268
|
}
|
|
70
269
|
|
|
71
270
|
export function blobDelete(ns, id) {
|
|
72
|
-
|
|
73
|
-
d.prepare('DELETE FROM ui_blobs WHERE ns = ? AND id = ?').run(ns, id);
|
|
271
|
+
getBlobDb().prepare('DELETE FROM ui_blobs WHERE ns = ? AND id = ?').run(ns, id);
|
|
74
272
|
}
|
|
75
273
|
|
|
76
274
|
// ── Which of a page's requests for one entry is the newer ──
|
|
@@ -142,33 +340,98 @@ export function createBlobOrder({ now = Date.now, ttlMs = BLOB_ORDER_TTL_MS, max
|
|
|
142
340
|
}
|
|
143
341
|
|
|
144
342
|
export function blobClearNamespace(ns) {
|
|
145
|
-
|
|
146
|
-
const result = d.prepare('DELETE FROM ui_blobs WHERE ns = ?').run(ns);
|
|
147
|
-
return Number(result?.changes || 0);
|
|
343
|
+
return getBlobDb().prepare('DELETE FROM ui_blobs WHERE ns = ?').run(ns).changes;
|
|
148
344
|
}
|
|
149
345
|
|
|
150
|
-
//
|
|
151
|
-
// cumulative value length (newest kept). Returns the evicted ids.
|
|
346
|
+
// Keep the newest entry even if it alone exceeds the character budget.
|
|
152
347
|
export function blobPrune(ns, { maxEntries = 0, maxTotalChars = 0 } = {}) {
|
|
348
|
+
if (!(maxEntries > 0 || maxTotalChars > 0)) return [];
|
|
153
349
|
const d = getBlobDb();
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
350
|
+
let cutoff;
|
|
351
|
+
if (maxTotalChars > 0) {
|
|
352
|
+
// Only an uncounted legacy value needs a table lookup. Normal writes trim
|
|
353
|
+
// straight from the covering index and stop as soon as either cap is reached.
|
|
354
|
+
const rows = d.prepare(`
|
|
355
|
+
SELECT id, updated_at, CASE WHEN rowid <= ? OR value_chars IS NULL
|
|
356
|
+
THEN (SELECT LENGTH(legacy.value) FROM ui_blobs AS legacy WHERE legacy.rowid = b.rowid)
|
|
357
|
+
ELSE value_chars END AS chars
|
|
358
|
+
FROM ui_blobs AS b WHERE ns = ? ORDER BY updated_at DESC, id DESC LIMIT ?
|
|
359
|
+
`).iterate(recountThrough, ns, MAX_TRIM_ROWS);
|
|
360
|
+
let total = 0;
|
|
361
|
+
let count = 0;
|
|
362
|
+
for (const row of rows) {
|
|
363
|
+
total += row.chars;
|
|
364
|
+
if (count && total > maxTotalChars) break;
|
|
365
|
+
cutoff = row;
|
|
366
|
+
count++;
|
|
367
|
+
if (total >= maxTotalChars || count === maxEntries) break;
|
|
368
|
+
if (count === MAX_TRIM_ROWS) {
|
|
369
|
+
console.debug('[ui-blobs] Character trim reached the row budget for', ns);
|
|
370
|
+
// No character cutoff proven in this scan. A separate count cap still applies.
|
|
371
|
+
cutoff = null;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (!cutoff && maxEntries > 0) {
|
|
376
|
+
cutoff = d.prepare(`
|
|
377
|
+
SELECT updated_at, id FROM ui_blobs WHERE ns = ?
|
|
378
|
+
ORDER BY updated_at DESC, id DESC LIMIT 1 OFFSET ?
|
|
379
|
+
`).get(ns, Math.min(Number.MAX_SAFE_INTEGER, maxEntries) - 1);
|
|
380
|
+
}
|
|
381
|
+
if (!cutoff) return [];
|
|
382
|
+
const victims = d.prepare(`
|
|
383
|
+
SELECT id FROM ui_blobs WHERE ns = ? AND (updated_at, id) < (?, ?)
|
|
384
|
+
ORDER BY updated_at, id LIMIT ?
|
|
385
|
+
`).all(ns, cutoff.updated_at, cutoff.id, MAX_TRIM_ROWS + 1);
|
|
386
|
+
if (victims.length > MAX_TRIM_ROWS) {
|
|
387
|
+
victims.pop();
|
|
388
|
+
console.debug('[ui-blobs] Remaining evictions deferred to next write for', ns);
|
|
168
389
|
}
|
|
169
|
-
|
|
390
|
+
const ids = victims.map(row => row.id);
|
|
391
|
+
if (ids.length) {
|
|
392
|
+
d.exec('BEGIN');
|
|
393
|
+
try {
|
|
394
|
+
for (let i = 0; i < ids.length; i += DELETE_BATCH) {
|
|
395
|
+
const batch = ids.slice(i, i + DELETE_BATCH);
|
|
396
|
+
const params = batch.map(() => '?').join(',');
|
|
397
|
+
d.prepare(`DELETE FROM ui_blobs WHERE ns = ? AND id IN (${params})`).run(ns, ...batch);
|
|
398
|
+
}
|
|
399
|
+
d.exec('COMMIT');
|
|
400
|
+
} catch (err) {
|
|
401
|
+
d.exec('ROLLBACK');
|
|
402
|
+
throw err;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return ids;
|
|
170
406
|
}
|
|
171
407
|
|
|
172
408
|
export function closeBlobStore() {
|
|
173
|
-
|
|
409
|
+
clearTimeout(backfillTimer);
|
|
410
|
+
backfillTimer = null;
|
|
411
|
+
recountThrough = 0;
|
|
412
|
+
terminateReaderWorker('ui-blob-store closed');
|
|
413
|
+
if (db) { db.close(); db = null; }
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// ── Worker thread entrypoint for off-event-loop namespace reads ──
|
|
417
|
+
if (!isMainThread && workerData?.uiBlobReader && parentPort) {
|
|
418
|
+
const encoder = new TextEncoder();
|
|
419
|
+
parentPort.on('message', ({ id, dbPath: targetPath, ns }) => {
|
|
420
|
+
let reader = null;
|
|
421
|
+
try {
|
|
422
|
+
reader = new DatabaseSync(targetPath);
|
|
423
|
+
reader.exec('PRAGMA query_only = ON');
|
|
424
|
+
reader.exec('PRAGMA busy_timeout = 5000; BEGIN');
|
|
425
|
+
const json = buildNamespaceJsonSync(reader, ns, NAMESPACE_READ_PAGE);
|
|
426
|
+
reader.exec('COMMIT');
|
|
427
|
+
// Close before replying so an idle worker never pins the DB file (critical on Windows).
|
|
428
|
+
reader.close();
|
|
429
|
+
reader = null;
|
|
430
|
+
const bytes = encoder.encode(json);
|
|
431
|
+
parentPort.postMessage({ id, bytes }, [bytes.buffer]);
|
|
432
|
+
} catch (err) {
|
|
433
|
+
if (reader) { try { reader.close(); } catch {} }
|
|
434
|
+
parentPort.postMessage({ id, error: err?.message || String(err) });
|
|
435
|
+
}
|
|
436
|
+
});
|
|
174
437
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "neural-memory-interface",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.4",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "neural-memory-interface",
|
|
9
|
-
"version": "2.4.
|
|
9
|
+
"version": "2.4.4",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "Apache-2.0",
|
|
12
12
|
"dependencies": {
|
|
@@ -83,6 +83,7 @@
|
|
|
83
83
|
</section>
|
|
84
84
|
<p id="es-reload" class="es-note es-warn" hidden></p>
|
|
85
85
|
<div class="es-row es-actions" id="es-actions" hidden>
|
|
86
|
+
<a class="es-button es-button-primary" id="es-update-flow" href="/#browser-extension-update" hidden></a>
|
|
86
87
|
<a class="es-button es-button-primary" id="es-back" href="/" hidden></a>
|
|
87
88
|
<button type="button" class="es-button es-button-primary" id="es-restart" data-action="restart" hidden></button>
|
|
88
89
|
</div>
|
|
@@ -53,6 +53,7 @@ function esc(value) {
|
|
|
53
53
|
* createAgentsDock(hostEl, hooks)
|
|
54
54
|
* hooks: { t, sessionId, onFocus(runId), onStop(runId), onRead(runId), onEscalate(runId, target),
|
|
55
55
|
* onStopAll() (the second press of "Stop all"; stopAllConfirmMs / stopAllMinGapMs time it),
|
|
56
|
+
* onSteer(runId, text) → truthy when sent, onSteerInComposer(runId, text), locale() (asst-steer.js),
|
|
56
57
|
* onRemove(runId), onClearFinished(runIds), onReveal(runId), onRunChange(run),
|
|
57
58
|
* open, showAll, onToggle(open), onShowAllChange(showAll),
|
|
58
59
|
* onCountChange({ total, active, attention, answer, idle, working, waiting, visible }) }
|
|
@@ -172,6 +173,9 @@ export function createAgentsDock(hostEl, hooks = {}) {
|
|
|
172
173
|
onRead: hooks.onRead,
|
|
173
174
|
onEscalate: hooks.onEscalate,
|
|
174
175
|
onRemove: typeof hooks.onRemove === 'function' ? hooks.onRemove : null,
|
|
176
|
+
onSteer: hooks.onSteer,
|
|
177
|
+
onSteerInComposer: hooks.onSteerInComposer,
|
|
178
|
+
locale: hooks.locale,
|
|
175
179
|
};
|
|
176
180
|
}
|
|
177
181
|
|
|
@@ -65,6 +65,48 @@ export async function readAssistantShellOutput(sessionId, { shellId, cursor, tai
|
|
|
65
65
|
return { status: res.status, data };
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
// ── Background tasks of a Claude brain (the Background tasks view) ─
|
|
69
|
+
|
|
70
|
+
/** The brain's background shells and watches, rebuilt from its transcript, and its live set. Never throws: null. */
|
|
71
|
+
export async function listAssistantBackgroundTasks(sessionId) {
|
|
72
|
+
try {
|
|
73
|
+
const res = await fetch(`/api/assistant/sessions/${enc(sessionId)}/background-tasks`, { credentials: 'same-origin' });
|
|
74
|
+
const body = await res.json().catch(() => null);
|
|
75
|
+
// A server from before this view has no such route (its 404 names no code): its output waits for a restart.
|
|
76
|
+
if (res.status === 404 && !body?.code) return { unsupported: true };
|
|
77
|
+
return res.ok && body?.ok ? body : null;
|
|
78
|
+
} catch { return null; }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** One page of what a background task printed. → { status, data } or { ok: false, status, error }; never throws. */
|
|
82
|
+
export async function readAssistantBackgroundOutput(sessionId, { taskId, cursor, tail, limit } = {}) {
|
|
83
|
+
const query = new URLSearchParams();
|
|
84
|
+
if (Number.isSafeInteger(cursor) && cursor >= 0) query.set('cursor', String(cursor));
|
|
85
|
+
if (Number.isSafeInteger(tail) && tail > 0) query.set('tail', String(tail));
|
|
86
|
+
if (Number.isSafeInteger(limit) && limit > 0) query.set('limit', String(limit));
|
|
87
|
+
const search = query.toString();
|
|
88
|
+
let res;
|
|
89
|
+
try {
|
|
90
|
+
res = await fetch(`/api/assistant/sessions/${enc(sessionId)}/background-tasks/${enc(taskId)}/output${search ? `?${search}` : ''}`, { credentials: 'same-origin' });
|
|
91
|
+
} catch (error) {
|
|
92
|
+
return { ok: false, error: error?.message || 'The output could not be read.' };
|
|
93
|
+
}
|
|
94
|
+
let body = null;
|
|
95
|
+
try { body = await res.json(); } catch { /* not JSON */ }
|
|
96
|
+
if (!res.ok || !body?.ok) return { ok: false, status: res.status, error: body?.error || `HTTP ${res.status}` };
|
|
97
|
+
const { ok: _ok, ...data } = body;
|
|
98
|
+
return { status: res.status, data };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The owner's Stop of one background task (the SDK's stopTask). → { ok, error }; never throws. */
|
|
102
|
+
export async function stopAssistantBackgroundTask(sessionId, taskId) {
|
|
103
|
+
try {
|
|
104
|
+
const res = await fetch(`/api/assistant/sessions/${enc(sessionId)}/background-tasks/${enc(taskId)}/stop`, { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json', 'X-SynaBun-UI': '1' }, body: '{}' });
|
|
105
|
+
const body = await res.json().catch(() => null);
|
|
106
|
+
return res.ok && body?.ok ? { ok: true } : { ok: false, error: body?.error || `HTTP ${res.status}` };
|
|
107
|
+
} catch (error) { return { ok: false, error: error?.message || String(error) }; }
|
|
108
|
+
}
|
|
109
|
+
|
|
68
110
|
// ── Catalog ──────────────────────────────────
|
|
69
111
|
|
|
70
112
|
export function fetchAssistantCatalog({ force = false } = {}) {
|