@causyne/agent 1.20.127 → 1.20.128
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/docs/THIRD_PARTY_NOTICES.md +36 -2
- package/package.json +3 -1
- package/src/agentLoop.js +59 -26
- package/src/agentLoop.ts +59 -24
- package/src/browser/causyneBrowser.js +31 -0
- package/src/browser/causyneBrowser.ts +32 -0
- package/src/commands.js +177 -13
- package/src/commands.ts +194 -13
- package/src/memory/episodicStore.js +40 -0
- package/src/memory/episodicStore.ts +46 -0
- package/src/memory.js +67 -0
- package/src/memory.ts +65 -0
- package/src/personalization.js +365 -0
- package/src/personalization.ts +471 -0
- package/src/projectInstructions.js +30 -10
- package/src/projectInstructions.ts +31 -12
- package/src/providers/acp.js +3 -2
- package/src/providers/acp.ts +3 -2
- package/src/providers/antigravity.js +2 -0
- package/src/providers/antigravity.ts +2 -0
- package/src/tools/memoryWrite.js +15 -1
- package/src/tools/memoryWrite.ts +16 -1
- package/src/tools/osSandbox.js +1 -1
- package/src/tools/osSandbox.ts +1 -1
- package/src/tools/ptyTerminal.js +17 -5
- package/src/tools/ptyTerminal.ts +19 -5
- package/src/web/client/browserPanel.js +234 -31
- package/src/web/client/browserPanel.ts +240 -31
- package/src/web/client/chatStream.js +19 -7
- package/src/web/client/chatStream.ts +17 -9
- package/src/web/client/cliPanel.js +3 -3
- package/src/web/client/cliPanel.ts +3 -3
- package/src/web/client/dom.js +53 -2
- package/src/web/client/dom.ts +54 -3
- package/src/web/client/filesAndCanvas.js +3 -1
- package/src/web/client/filesAndCanvas.ts +3 -1
- package/src/web/client/main.js +28 -13
- package/src/web/client/main.ts +35 -12
- package/src/web/client/settingsModal.js +641 -8
- package/src/web/client/settingsModal.ts +791 -8
- package/src/web/client/state.js +31 -1
- package/src/web/client/state.ts +27 -1
- package/src/web/client/studioLayout.js +39 -4
- package/src/web/client/studioLayout.ts +47 -4
- package/src/web/client/studioShell.js +370 -37
- package/src/web/client/studioShell.ts +368 -36
- package/src/web/client/terminalPanel.js +378 -129
- package/src/web/client/terminalPanel.ts +394 -107
- package/src/web/client/terminalTheme.js +249 -0
- package/src/web/client/terminalTheme.ts +258 -0
- package/src/web/client/types.ts +3 -0
- package/src/web/client/validators.js +51 -10
- package/src/web/client/validators.ts +54 -10
- package/src/web/server/routesBrowser.js +64 -10
- package/src/web/server/routesBrowser.ts +62 -13
- package/src/web/server/routesSettings.js +344 -0
- package/src/web/server/routesSettings.ts +397 -0
- package/src/web/server/staticAssets.js +24 -0
- package/src/web/server/staticAssets.ts +25 -0
- package/src/web/skybridgeServer.js +3 -0
- package/src/web/skybridgeServer.ts +2 -0
- package/src/web/skybridgeUi.js +5 -1
- package/src/web/skybridgeUi.ts +8 -1
- package/src/web/styles/overlays.css +499 -0
- package/src/web/styles/studio.css +274 -46
- package/src/web/ui/modalsTemplate.js +320 -71
- package/src/web/ui/modalsTemplate.ts +320 -71
- package/src/web/ui/studioTemplate.js +19 -21
- package/src/web/ui/studioTemplate.ts +19 -21
|
@@ -201,13 +201,30 @@ export async function handleBrowserRoutes(req, res, parsedUrl, ctx) {
|
|
|
201
201
|
}
|
|
202
202
|
if (action === 'start') {
|
|
203
203
|
ctx.setBrowserControlOwner('human');
|
|
204
|
-
|
|
204
|
+
let frame = await browser.captureLiveFrame({ ensureStarted: true });
|
|
205
|
+
const reqW = Number(body.width);
|
|
206
|
+
const reqH = Number(body.height);
|
|
207
|
+
if (frame.active && Number.isFinite(reqW) && Number.isFinite(reqH) && reqW >= 320 && reqH >= 240) {
|
|
208
|
+
const width = Math.max(320, Math.min(2560, Math.round(reqW)));
|
|
209
|
+
const height = Math.max(240, Math.min(1440, Math.round(reqH)));
|
|
210
|
+
try {
|
|
211
|
+
await browser.run([{ type: 'viewport', width, height }], { workspace: workspaceRoot });
|
|
212
|
+
frame = await browser.captureLiveFrame({ ensureStarted: false });
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
// Keep started frame if viewport resize raced with close.
|
|
216
|
+
}
|
|
217
|
+
}
|
|
205
218
|
sendJson(res, 200, { ok: true, controlOwner: ctx.getBrowserControlOwner(), ...frame });
|
|
206
219
|
return true;
|
|
207
220
|
}
|
|
208
221
|
if (action === 'close') {
|
|
209
|
-
await browser.
|
|
210
|
-
|
|
222
|
+
const frame = await browser.closeLiveSession();
|
|
223
|
+
ctx.broadcastBrowserNotice({
|
|
224
|
+
type: 'closed',
|
|
225
|
+
controlOwner: ctx.getBrowserControlOwner(),
|
|
226
|
+
...frame
|
|
227
|
+
});
|
|
211
228
|
sendJson(res, 200, { ok: true, controlOwner: ctx.getBrowserControlOwner(), ...frame });
|
|
212
229
|
return true;
|
|
213
230
|
}
|
|
@@ -230,7 +247,21 @@ export async function handleBrowserRoutes(req, res, parsedUrl, ctx) {
|
|
|
230
247
|
? `https://${rawUrl}`
|
|
231
248
|
: (expandSearchMacro('@duckduckgo_search', rawUrl) || `https://duckduckgo.com/?q=${encodeURIComponent(rawUrl)}`);
|
|
232
249
|
}
|
|
233
|
-
|
|
250
|
+
const actions = [
|
|
251
|
+
action === 'newTab'
|
|
252
|
+
? { type: 'newTab', ...(rawUrl ? { url: rawUrl } : {}) }
|
|
253
|
+
: { type: 'goto', url: rawUrl || 'about:blank' }
|
|
254
|
+
];
|
|
255
|
+
const reqW = Number(body.width);
|
|
256
|
+
const reqH = Number(body.height);
|
|
257
|
+
if (Number.isFinite(reqW) && Number.isFinite(reqH) && reqW >= 320 && reqH >= 240) {
|
|
258
|
+
actions.push({
|
|
259
|
+
type: 'viewport',
|
|
260
|
+
width: Math.max(320, Math.min(2560, Math.round(reqW))),
|
|
261
|
+
height: Math.max(240, Math.min(1440, Math.round(reqH)))
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
await browser.run(actions, { workspace: workspaceRoot });
|
|
234
265
|
const frame = await browser.captureLiveFrame({ ensureStarted: true });
|
|
235
266
|
sendJson(res, 200, { ok: true, controlOwner: ctx.getBrowserControlOwner(), ...frame });
|
|
236
267
|
return true;
|
|
@@ -242,18 +273,41 @@ export async function handleBrowserRoutes(req, res, parsedUrl, ctx) {
|
|
|
242
273
|
sendJson(res, 200, { ok: true, controlOwner: ctx.getBrowserControlOwner(), ...frame });
|
|
243
274
|
return true;
|
|
244
275
|
}
|
|
245
|
-
if (
|
|
276
|
+
if (action === 'switchTab' && typeof body.tabId === 'string' && body.tabId.trim()) {
|
|
246
277
|
ctx.setBrowserControlOwner('human');
|
|
247
|
-
await browser.run([{ type:
|
|
278
|
+
await browser.run([{ type: 'switchTab', tabId: body.tabId.trim() }], { workspace: workspaceRoot });
|
|
248
279
|
const frame = await browser.captureLiveFrame({ ensureStarted: true });
|
|
249
280
|
sendJson(res, 200, { ok: true, controlOwner: ctx.getBrowserControlOwner(), ...frame });
|
|
250
281
|
return true;
|
|
251
282
|
}
|
|
283
|
+
if (action === 'closeTab' && typeof body.tabId === 'string' && body.tabId.trim()) {
|
|
284
|
+
ctx.setBrowserControlOwner('human');
|
|
285
|
+
const frame = await browser.closeLiveTab(body.tabId.trim());
|
|
286
|
+
if (!frame.active) {
|
|
287
|
+
ctx.broadcastBrowserNotice({
|
|
288
|
+
type: 'closed',
|
|
289
|
+
controlOwner: ctx.getBrowserControlOwner(),
|
|
290
|
+
...frame
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
sendJson(res, 200, { ok: true, controlOwner: ctx.getBrowserControlOwner(), ...frame });
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
252
296
|
if (action === 'viewport') {
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
297
|
+
const pre = await browser.captureLiveFrame({ ensureStarted: false });
|
|
298
|
+
if (!pre.active) {
|
|
299
|
+
sendJson(res, 200, { ok: true, controlOwner: ctx.getBrowserControlOwner(), ...pre });
|
|
300
|
+
return true;
|
|
301
|
+
}
|
|
302
|
+
const width = Math.max(320, Math.min(2560, Math.round(Number(body.width) || 1280)));
|
|
303
|
+
const height = Math.max(240, Math.min(1440, Math.round(Number(body.height) || 800)));
|
|
304
|
+
try {
|
|
305
|
+
await browser.run([{ type: 'viewport', width, height }], { workspace: workspaceRoot });
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
308
|
+
// Browser closed concurrently during resize; return current closed state cleanly.
|
|
309
|
+
}
|
|
310
|
+
const frame = await browser.captureLiveFrame({ ensureStarted: false });
|
|
257
311
|
sendJson(res, 200, { ok: true, controlOwner: ctx.getBrowserControlOwner(), ...frame });
|
|
258
312
|
return true;
|
|
259
313
|
}
|
|
@@ -226,13 +226,29 @@ export async function handleBrowserRoutes(
|
|
|
226
226
|
}
|
|
227
227
|
if (action === 'start') {
|
|
228
228
|
ctx.setBrowserControlOwner('human');
|
|
229
|
-
|
|
229
|
+
let frame = await browser.captureLiveFrame({ ensureStarted: true });
|
|
230
|
+
const reqW = Number(body.width);
|
|
231
|
+
const reqH = Number(body.height);
|
|
232
|
+
if (frame.active && Number.isFinite(reqW) && Number.isFinite(reqH) && reqW >= 320 && reqH >= 240) {
|
|
233
|
+
const width = Math.max(320, Math.min(2560, Math.round(reqW)));
|
|
234
|
+
const height = Math.max(240, Math.min(1440, Math.round(reqH)));
|
|
235
|
+
try {
|
|
236
|
+
await browser.run([{ type: 'viewport', width, height }], { workspace: workspaceRoot });
|
|
237
|
+
frame = await browser.captureLiveFrame({ ensureStarted: false });
|
|
238
|
+
} catch {
|
|
239
|
+
// Keep started frame if viewport resize raced with close.
|
|
240
|
+
}
|
|
241
|
+
}
|
|
230
242
|
sendJson(res, 200, { ok: true, controlOwner: ctx.getBrowserControlOwner(), ...frame });
|
|
231
243
|
return true;
|
|
232
244
|
}
|
|
233
245
|
if (action === 'close') {
|
|
234
|
-
await browser.
|
|
235
|
-
|
|
246
|
+
const frame = await browser.closeLiveSession();
|
|
247
|
+
ctx.broadcastBrowserNotice({
|
|
248
|
+
type: 'closed',
|
|
249
|
+
controlOwner: ctx.getBrowserControlOwner(),
|
|
250
|
+
...frame
|
|
251
|
+
});
|
|
236
252
|
sendJson(res, 200, { ok: true, controlOwner: ctx.getBrowserControlOwner(), ...frame });
|
|
237
253
|
return true;
|
|
238
254
|
}
|
|
@@ -254,10 +270,21 @@ export async function handleBrowserRoutes(
|
|
|
254
270
|
? `https://${rawUrl}`
|
|
255
271
|
: (expandSearchMacro('@duckduckgo_search', rawUrl) || `https://duckduckgo.com/?q=${encodeURIComponent(rawUrl)}`);
|
|
256
272
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
273
|
+
const actions: Array<{ type: 'viewport'; width: number; height: number } | { type: 'newTab'; url?: string } | { type: 'goto'; url: string }> = [
|
|
274
|
+
action === 'newTab'
|
|
275
|
+
? { type: 'newTab', ...(rawUrl ? { url: rawUrl } : {}) }
|
|
276
|
+
: { type: 'goto', url: rawUrl || 'about:blank' }
|
|
277
|
+
];
|
|
278
|
+
const reqW = Number(body.width);
|
|
279
|
+
const reqH = Number(body.height);
|
|
280
|
+
if (Number.isFinite(reqW) && Number.isFinite(reqH) && reqW >= 320 && reqH >= 240) {
|
|
281
|
+
actions.push({
|
|
282
|
+
type: 'viewport',
|
|
283
|
+
width: Math.max(320, Math.min(2560, Math.round(reqW))),
|
|
284
|
+
height: Math.max(240, Math.min(1440, Math.round(reqH)))
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
await browser.run(actions, { workspace: workspaceRoot });
|
|
261
288
|
const frame = await browser.captureLiveFrame({ ensureStarted: true });
|
|
262
289
|
sendJson(res, 200, { ok: true, controlOwner: ctx.getBrowserControlOwner(), ...frame });
|
|
263
290
|
return true;
|
|
@@ -269,18 +296,40 @@ export async function handleBrowserRoutes(
|
|
|
269
296
|
sendJson(res, 200, { ok: true, controlOwner: ctx.getBrowserControlOwner(), ...frame });
|
|
270
297
|
return true;
|
|
271
298
|
}
|
|
272
|
-
if (
|
|
299
|
+
if (action === 'switchTab' && typeof body.tabId === 'string' && body.tabId.trim()) {
|
|
273
300
|
ctx.setBrowserControlOwner('human');
|
|
274
|
-
await browser.run([{ type:
|
|
301
|
+
await browser.run([{ type: 'switchTab', tabId: body.tabId.trim() }], { workspace: workspaceRoot });
|
|
275
302
|
const frame = await browser.captureLiveFrame({ ensureStarted: true });
|
|
276
303
|
sendJson(res, 200, { ok: true, controlOwner: ctx.getBrowserControlOwner(), ...frame });
|
|
277
304
|
return true;
|
|
278
305
|
}
|
|
306
|
+
if (action === 'closeTab' && typeof body.tabId === 'string' && body.tabId.trim()) {
|
|
307
|
+
ctx.setBrowserControlOwner('human');
|
|
308
|
+
const frame = await browser.closeLiveTab(body.tabId.trim());
|
|
309
|
+
if (!frame.active) {
|
|
310
|
+
ctx.broadcastBrowserNotice({
|
|
311
|
+
type: 'closed',
|
|
312
|
+
controlOwner: ctx.getBrowserControlOwner(),
|
|
313
|
+
...frame
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
sendJson(res, 200, { ok: true, controlOwner: ctx.getBrowserControlOwner(), ...frame });
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
279
319
|
if (action === 'viewport') {
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
320
|
+
const pre = await browser.captureLiveFrame({ ensureStarted: false });
|
|
321
|
+
if (!pre.active) {
|
|
322
|
+
sendJson(res, 200, { ok: true, controlOwner: ctx.getBrowserControlOwner(), ...pre });
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
const width = Math.max(320, Math.min(2560, Math.round(Number(body.width) || 1280)));
|
|
326
|
+
const height = Math.max(240, Math.min(1440, Math.round(Number(body.height) || 800)));
|
|
327
|
+
try {
|
|
328
|
+
await browser.run([{ type: 'viewport', width, height }], { workspace: workspaceRoot });
|
|
329
|
+
} catch {
|
|
330
|
+
// Browser closed concurrently during resize; return current closed state cleanly.
|
|
331
|
+
}
|
|
332
|
+
const frame = await browser.captureLiveFrame({ ensureStarted: false });
|
|
284
333
|
sendJson(res, 200, { ok: true, controlOwner: ctx.getBrowserControlOwner(), ...frame });
|
|
285
334
|
return true;
|
|
286
335
|
}
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { loadConfig, resolveProviderApiKey, saveConfig } from '../../config.js';
|
|
3
|
+
import { DEFAULT_MODEL_BY_PROVIDER } from '../../modelCatalogue.js';
|
|
4
|
+
import { getDefaultPermissionPreset, normalizePermissionPreset, setDefaultPermissionPreset } from '../../permissionPresets.js';
|
|
5
|
+
import { probeOsSandbox, resolveOsSandboxMode } from '../../tools/osSandbox.js';
|
|
6
|
+
import { deleteCausyneMemories, readPersonalizationOverview, saveMemoryPreferences, savePersonalizationInstructions } from '../../personalization.js';
|
|
7
|
+
import { discoverProjectMcpServers, serverStatus } from '../../mcp/mcpRegistry.js';
|
|
8
|
+
import { disablePlugin, enablePlugin, listPlugins, PLUGIN_ROOT } from '../../plugins/pluginManager.js';
|
|
9
|
+
import { auditLog } from '../../auditLog.js';
|
|
10
|
+
import { readJsonBody, sendJson } from './security.js';
|
|
11
|
+
const VAULT_PROVIDER_IDS = [
|
|
12
|
+
'deepseek',
|
|
13
|
+
'qwen',
|
|
14
|
+
'dashscope-byok',
|
|
15
|
+
'anthropic',
|
|
16
|
+
'openai',
|
|
17
|
+
'gemini',
|
|
18
|
+
'moonshot',
|
|
19
|
+
'xai',
|
|
20
|
+
'openrouter',
|
|
21
|
+
'groq',
|
|
22
|
+
'cerebras',
|
|
23
|
+
'mistral'
|
|
24
|
+
];
|
|
25
|
+
const ALLOWED_OS_SANDBOX_MODES = new Set([
|
|
26
|
+
'off',
|
|
27
|
+
'workspace-write',
|
|
28
|
+
'strict',
|
|
29
|
+
'read-only',
|
|
30
|
+
'read-only-strict'
|
|
31
|
+
]);
|
|
32
|
+
const ALLOWED_EFFORT_LEVELS = new Set(['', 'off', 'low', 'medium', 'high', 'max']);
|
|
33
|
+
function buildHooksOverview(config) {
|
|
34
|
+
const rawHooks = Array.isArray(config.hooks) ? config.hooks : [];
|
|
35
|
+
const items = [];
|
|
36
|
+
for (let i = 0; i < rawHooks.length && i < 64; i++) {
|
|
37
|
+
const entry = rawHooks[i];
|
|
38
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry))
|
|
39
|
+
continue;
|
|
40
|
+
const rec = entry;
|
|
41
|
+
const event = typeof rec.event === 'string' && rec.event.trim() ? rec.event.trim() : 'PreToolUse';
|
|
42
|
+
const tools = Array.isArray(rec.tools)
|
|
43
|
+
? rec.tools.filter((t) => typeof t === 'string' && t.trim().length > 0)
|
|
44
|
+
: [typeof rec.tool === 'string' && rec.tool.trim() ? rec.tool.trim() : '*'];
|
|
45
|
+
const command = Array.isArray(rec.command)
|
|
46
|
+
? rec.command.map((c) => String(c)).join(' ')
|
|
47
|
+
: '';
|
|
48
|
+
const name = typeof rec.name === 'string' && rec.name.trim()
|
|
49
|
+
? rec.name.trim().slice(0, 120)
|
|
50
|
+
: `${event}:${tools[0] || '*'}`;
|
|
51
|
+
const timeoutMs = typeof rec.timeoutMs === 'number' && Number.isFinite(rec.timeoutMs)
|
|
52
|
+
? Math.max(100, Math.min(10_000, Math.round(rec.timeoutMs)))
|
|
53
|
+
: 5_000;
|
|
54
|
+
items.push({
|
|
55
|
+
index: i,
|
|
56
|
+
name,
|
|
57
|
+
event,
|
|
58
|
+
tools,
|
|
59
|
+
commandPreview: command.slice(0, 180),
|
|
60
|
+
timeoutMs,
|
|
61
|
+
enabled: rec.enabled !== false
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return items;
|
|
65
|
+
}
|
|
66
|
+
function buildSettingsOverviewPayload(ctx) {
|
|
67
|
+
const config = loadConfig();
|
|
68
|
+
const osSandboxCap = probeOsSandbox();
|
|
69
|
+
const osSandboxResolved = resolveOsSandboxMode(process.env, config.osSandbox);
|
|
70
|
+
const configuredOsSandbox = typeof config.osSandbox === 'string' && ALLOWED_OS_SANDBOX_MODES.has(config.osSandbox.trim().toLowerCase())
|
|
71
|
+
? config.osSandbox.trim().toLowerCase()
|
|
72
|
+
: 'workspace-write';
|
|
73
|
+
const rawBudget = config.tokenBudget && typeof config.tokenBudget === 'object' && !Array.isArray(config.tokenBudget)
|
|
74
|
+
? config.tokenBudget
|
|
75
|
+
: {};
|
|
76
|
+
const tokenBudget = {
|
|
77
|
+
enabled: rawBudget.enabled === true,
|
|
78
|
+
maxTokensPerTask: typeof rawBudget.maxTokensPerTask === 'number' && Number.isFinite(rawBudget.maxTokensPerTask)
|
|
79
|
+
? Math.max(1000, Math.round(rawBudget.maxTokensPerTask))
|
|
80
|
+
: 150000,
|
|
81
|
+
maxTokensPerDay: typeof rawBudget.maxTokensPerDay === 'number' && Number.isFinite(rawBudget.maxTokensPerDay)
|
|
82
|
+
? Math.max(1000, Math.round(rawBudget.maxTokensPerDay))
|
|
83
|
+
: 1000000,
|
|
84
|
+
maxCostUsd: typeof rawBudget.maxCostUsd === 'number' && Number.isFinite(rawBudget.maxCostUsd)
|
|
85
|
+
? Math.max(0.1, Number(rawBudget.maxCostUsd))
|
|
86
|
+
: 5,
|
|
87
|
+
hardStop: rawBudget.hardStop === true
|
|
88
|
+
};
|
|
89
|
+
const rawCompact = config.contextCompaction && typeof config.contextCompaction === 'object' && !Array.isArray(config.contextCompaction)
|
|
90
|
+
? config.contextCompaction
|
|
91
|
+
: {};
|
|
92
|
+
const autoCompact = {
|
|
93
|
+
enabled: rawCompact.enabled !== false,
|
|
94
|
+
thresholdPercent: typeof rawCompact.thresholdPercent === 'number' && Number.isFinite(rawCompact.thresholdPercent)
|
|
95
|
+
? Math.max(40, Math.min(95, Math.round(rawCompact.thresholdPercent)))
|
|
96
|
+
: 78
|
|
97
|
+
};
|
|
98
|
+
const configuredProviders = VAULT_PROVIDER_IDS.filter((id) => Boolean(resolveProviderApiKey(config, id)));
|
|
99
|
+
const projectMcp = discoverProjectMcpServers(ctx.workspaceRoot);
|
|
100
|
+
let pluginItems = [];
|
|
101
|
+
try {
|
|
102
|
+
pluginItems = listPlugins();
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
pluginItems = [];
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
ok: true,
|
|
109
|
+
general: {
|
|
110
|
+
workspaceRoot: ctx.workspaceRoot,
|
|
111
|
+
workspaceName: path.basename(ctx.workspaceRoot),
|
|
112
|
+
version: ctx.version,
|
|
113
|
+
platform: process.platform,
|
|
114
|
+
provider: config.provider || 'unconfigured',
|
|
115
|
+
model: config.model || DEFAULT_MODEL_BY_PROVIDER[String(config.provider || '')] || 'default'
|
|
116
|
+
},
|
|
117
|
+
configuration: {
|
|
118
|
+
defaultPermissionPreset: getDefaultPermissionPreset(),
|
|
119
|
+
reasoningEffort: typeof config.reasoningEffort === 'string' ? config.reasoningEffort.trim().toLowerCase() : '',
|
|
120
|
+
osSandbox: {
|
|
121
|
+
configuredMode: configuredOsSandbox,
|
|
122
|
+
effectiveMode: osSandboxResolved.mode,
|
|
123
|
+
strict: osSandboxResolved.strict,
|
|
124
|
+
allowNetwork: osSandboxResolved.allowNetwork,
|
|
125
|
+
backend: osSandboxCap.backend,
|
|
126
|
+
available: osSandboxCap.available,
|
|
127
|
+
reason: osSandboxCap.reason
|
|
128
|
+
},
|
|
129
|
+
tokenBudget,
|
|
130
|
+
autoCompact
|
|
131
|
+
},
|
|
132
|
+
personalization: readPersonalizationOverview(ctx.workspaceRoot),
|
|
133
|
+
vault: {
|
|
134
|
+
activeProvider: config.provider || '',
|
|
135
|
+
configuredProviders
|
|
136
|
+
},
|
|
137
|
+
mcp: {
|
|
138
|
+
servers: serverStatus(),
|
|
139
|
+
projectDiscovered: projectMcp.servers.map((srv) => ({
|
|
140
|
+
name: srv.name,
|
|
141
|
+
transport: srv.url ? 'http' : 'stdio',
|
|
142
|
+
target: srv.url ?? [srv.command, ...(srv.args ?? [])].filter(Boolean).join(' ')
|
|
143
|
+
})),
|
|
144
|
+
projectWarnings: projectMcp.warnings,
|
|
145
|
+
projectFile: projectMcp.filePath
|
|
146
|
+
},
|
|
147
|
+
hooks: buildHooksOverview(config),
|
|
148
|
+
plugins: {
|
|
149
|
+
root: PLUGIN_ROOT,
|
|
150
|
+
items: pluginItems
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function invalidateActiveLoopStaticContexts(ctx) {
|
|
155
|
+
for (const run of ctx.activeRuns.values()) {
|
|
156
|
+
const loopObj = run.loop;
|
|
157
|
+
if (loopObj && typeof loopObj === 'object' && 'staticContext' in loopObj) {
|
|
158
|
+
loopObj.staticContext = null;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
export async function handleSettingsRoutes(req, res, parsedUrl, ctx) {
|
|
163
|
+
const pathname = parsedUrl.pathname;
|
|
164
|
+
if (req.method === 'GET' && pathname === '/api/settings/overview') {
|
|
165
|
+
sendJson(res, 200, buildSettingsOverviewPayload(ctx));
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
if (req.method === 'POST' && pathname === '/api/settings/configuration') {
|
|
169
|
+
const body = await readJsonBody(req);
|
|
170
|
+
const config = loadConfig();
|
|
171
|
+
if (body.defaultPermissionPreset !== undefined) {
|
|
172
|
+
const preset = normalizePermissionPreset(body.defaultPermissionPreset);
|
|
173
|
+
if (!preset) {
|
|
174
|
+
sendJson(res, 400, { error: 'Invalid defaultPermissionPreset value.' });
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
setDefaultPermissionPreset(preset);
|
|
178
|
+
config.defaultPermissionPreset = preset;
|
|
179
|
+
}
|
|
180
|
+
if (typeof body.osSandbox === 'string') {
|
|
181
|
+
const mode = body.osSandbox.trim().toLowerCase();
|
|
182
|
+
if (!ALLOWED_OS_SANDBOX_MODES.has(mode)) {
|
|
183
|
+
sendJson(res, 400, { error: 'Invalid osSandbox mode.' });
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
config.osSandbox = mode;
|
|
187
|
+
}
|
|
188
|
+
if (typeof body.reasoningEffort === 'string') {
|
|
189
|
+
const effort = body.reasoningEffort.trim().toLowerCase();
|
|
190
|
+
if (!ALLOWED_EFFORT_LEVELS.has(effort)) {
|
|
191
|
+
sendJson(res, 400, { error: 'Invalid reasoningEffort level.' });
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
if (!effort)
|
|
195
|
+
delete config.reasoningEffort;
|
|
196
|
+
else
|
|
197
|
+
config.reasoningEffort = effort;
|
|
198
|
+
}
|
|
199
|
+
if (body.tokenBudget && typeof body.tokenBudget === 'object' && !Array.isArray(body.tokenBudget)) {
|
|
200
|
+
const raw = body.tokenBudget;
|
|
201
|
+
const prev = config.tokenBudget && typeof config.tokenBudget === 'object'
|
|
202
|
+
? config.tokenBudget
|
|
203
|
+
: {};
|
|
204
|
+
const nextBudget = { ...prev };
|
|
205
|
+
if (typeof raw.enabled === 'boolean')
|
|
206
|
+
nextBudget.enabled = raw.enabled;
|
|
207
|
+
if (typeof raw.hardStop === 'boolean')
|
|
208
|
+
nextBudget.hardStop = raw.hardStop;
|
|
209
|
+
if (typeof raw.maxTokensPerTask === 'number' && Number.isFinite(raw.maxTokensPerTask)) {
|
|
210
|
+
nextBudget.maxTokensPerTask = Math.max(1000, Math.min(100_000_000, Math.round(raw.maxTokensPerTask)));
|
|
211
|
+
}
|
|
212
|
+
if (typeof raw.maxTokensPerDay === 'number' && Number.isFinite(raw.maxTokensPerDay)) {
|
|
213
|
+
nextBudget.maxTokensPerDay = Math.max(1000, Math.min(1_000_000_000, Math.round(raw.maxTokensPerDay)));
|
|
214
|
+
}
|
|
215
|
+
if (typeof raw.maxCostUsd === 'number' && Number.isFinite(raw.maxCostUsd)) {
|
|
216
|
+
nextBudget.maxCostUsd = Math.max(0.1, Math.min(10_000, Number(raw.maxCostUsd.toFixed(2))));
|
|
217
|
+
}
|
|
218
|
+
config.tokenBudget = nextBudget;
|
|
219
|
+
}
|
|
220
|
+
if (body.autoCompact && typeof body.autoCompact === 'object' && !Array.isArray(body.autoCompact)) {
|
|
221
|
+
const raw = body.autoCompact;
|
|
222
|
+
const prev = config.contextCompaction && typeof config.contextCompaction === 'object'
|
|
223
|
+
? config.contextCompaction
|
|
224
|
+
: {};
|
|
225
|
+
const nextCompact = { ...prev };
|
|
226
|
+
if (typeof raw.enabled === 'boolean')
|
|
227
|
+
nextCompact.enabled = raw.enabled;
|
|
228
|
+
if (typeof raw.thresholdPercent === 'number' && Number.isFinite(raw.thresholdPercent)) {
|
|
229
|
+
nextCompact.thresholdPercent = Math.max(40, Math.min(95, Math.round(raw.thresholdPercent)));
|
|
230
|
+
}
|
|
231
|
+
config.contextCompaction = nextCompact;
|
|
232
|
+
}
|
|
233
|
+
saveConfig(config);
|
|
234
|
+
auditLog.log({ event: 'skybridge_configuration_updated' });
|
|
235
|
+
sendJson(res, 200, buildSettingsOverviewPayload(ctx));
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
if (req.method === 'POST' && pathname === '/api/settings/personalization') {
|
|
239
|
+
const body = await readJsonBody(req);
|
|
240
|
+
const scope = body.scope === 'global' ? 'global' : 'project';
|
|
241
|
+
try {
|
|
242
|
+
if (typeof body.instructions === 'string') {
|
|
243
|
+
savePersonalizationInstructions(ctx.workspaceRoot, scope, body.instructions);
|
|
244
|
+
}
|
|
245
|
+
const memPatch = {};
|
|
246
|
+
if (typeof body.memoryEnabled === 'boolean' || body.memoryEnabled === null) {
|
|
247
|
+
memPatch.enabled = body.memoryEnabled;
|
|
248
|
+
}
|
|
249
|
+
if (typeof body.allowToolAssisted === 'boolean' || body.allowToolAssisted === null) {
|
|
250
|
+
memPatch.allowToolAssisted = body.allowToolAssisted;
|
|
251
|
+
}
|
|
252
|
+
if (memPatch.enabled !== undefined || memPatch.allowToolAssisted !== undefined) {
|
|
253
|
+
saveMemoryPreferences(ctx.workspaceRoot, scope, memPatch);
|
|
254
|
+
}
|
|
255
|
+
invalidateActiveLoopStaticContexts(ctx);
|
|
256
|
+
auditLog.log({
|
|
257
|
+
event: 'skybridge_personalization_updated',
|
|
258
|
+
scope,
|
|
259
|
+
updatedInstructions: typeof body.instructions === 'string',
|
|
260
|
+
updatedMemory: memPatch.enabled !== undefined || memPatch.allowToolAssisted !== undefined
|
|
261
|
+
});
|
|
262
|
+
sendJson(res, 200, {
|
|
263
|
+
ok: true,
|
|
264
|
+
scope,
|
|
265
|
+
personalization: readPersonalizationOverview(ctx.workspaceRoot)
|
|
266
|
+
});
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
catch (err) {
|
|
270
|
+
const rawMsg = err instanceof Error ? err.message : '';
|
|
271
|
+
const safeMsg = rawMsg.includes('exceed maximum size')
|
|
272
|
+
? 'Personalization instructions exceed the 16 KB limit.'
|
|
273
|
+
: rawMsg.includes('symlink')
|
|
274
|
+
? 'Refusing to write personalization through a symbolic link.'
|
|
275
|
+
: 'Could not save personalization settings.';
|
|
276
|
+
sendJson(res, 400, { error: safeMsg });
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (req.method === 'POST' && pathname === '/api/settings/memories/delete') {
|
|
281
|
+
const body = await readJsonBody(req);
|
|
282
|
+
const scope = body.scope === 'all' ? 'all' : 'project';
|
|
283
|
+
const result = deleteCausyneMemories(ctx.workspaceRoot, scope);
|
|
284
|
+
invalidateActiveLoopStaticContexts(ctx);
|
|
285
|
+
auditLog.log({
|
|
286
|
+
event: 'skybridge_memories_deleted',
|
|
287
|
+
scope,
|
|
288
|
+
factsRemoved: result.factsRemoved,
|
|
289
|
+
observationsRemoved: result.observationsRemoved,
|
|
290
|
+
summariesRemoved: result.summariesRemoved
|
|
291
|
+
});
|
|
292
|
+
sendJson(res, 200, {
|
|
293
|
+
ok: true,
|
|
294
|
+
...result,
|
|
295
|
+
personalization: readPersonalizationOverview(ctx.workspaceRoot)
|
|
296
|
+
});
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
if (req.method === 'POST' && pathname === '/api/settings/hooks/toggle') {
|
|
300
|
+
const body = await readJsonBody(req);
|
|
301
|
+
const index = typeof body.index === 'number' && Number.isInteger(body.index) ? body.index : -1;
|
|
302
|
+
const enabled = typeof body.enabled === 'boolean' ? body.enabled : null;
|
|
303
|
+
if (index < 0 || enabled === null) {
|
|
304
|
+
sendJson(res, 400, { error: 'Valid hook index and boolean enabled flag are required.' });
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
const config = loadConfig();
|
|
308
|
+
if (!Array.isArray(config.hooks) || index >= config.hooks.length) {
|
|
309
|
+
sendJson(res, 404, { error: 'Configured hook entry not found.' });
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
const target = config.hooks[index];
|
|
313
|
+
if (!target || typeof target !== 'object' || Array.isArray(target)) {
|
|
314
|
+
sendJson(res, 400, { error: 'Hook entry is malformed.' });
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
target.enabled = enabled;
|
|
318
|
+
saveConfig(config);
|
|
319
|
+
auditLog.log({ event: 'skybridge_hook_toggled', index, enabled });
|
|
320
|
+
sendJson(res, 200, { ok: true, hooks: buildHooksOverview(config) });
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
if (req.method === 'POST' && pathname === '/api/settings/plugins/toggle') {
|
|
324
|
+
const body = await readJsonBody(req);
|
|
325
|
+
const name = typeof body.name === 'string' ? body.name.trim() : '';
|
|
326
|
+
const enabled = typeof body.enabled === 'boolean' ? body.enabled : null;
|
|
327
|
+
if (!name || enabled === null) {
|
|
328
|
+
sendJson(res, 400, { error: 'Valid plugin name and boolean enabled flag are required.' });
|
|
329
|
+
return true;
|
|
330
|
+
}
|
|
331
|
+
const outcome = enabled ? enablePlugin(name) : disablePlugin(name);
|
|
332
|
+
if (!outcome.ok) {
|
|
333
|
+
sendJson(res, 400, { error: 'Could not update plugin trust state.' });
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
auditLog.log({ event: 'skybridge_plugin_toggled', name, enabled });
|
|
337
|
+
sendJson(res, 200, {
|
|
338
|
+
ok: true,
|
|
339
|
+
plugins: { root: PLUGIN_ROOT, items: listPlugins() }
|
|
340
|
+
});
|
|
341
|
+
return true;
|
|
342
|
+
}
|
|
343
|
+
return false;
|
|
344
|
+
}
|