@causyne/agent 1.20.124 → 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/bin/causyne.js +1 -1
- package/docs/THIRD_PARTY_NOTICES.md +36 -2
- package/package.json +6 -4
- package/src/acp/protocol.ts +19 -1
- package/src/acp/server.js +282 -8
- package/src/acp/server.ts +284 -8
- package/src/agent/abortableDelay.js +2 -2
- package/src/agent/abortableDelay.ts +2 -2
- package/src/agent/errorClassifier.js +9 -1
- package/src/agent/errorClassifier.ts +8 -1
- package/src/agentLoop.js +142 -53
- package/src/agentLoop.ts +151 -50
- package/src/approvalPolicy.js +34 -10
- package/src/approvalPolicy.ts +42 -11
- package/src/browser/causyneBrowser.js +61 -3
- package/src/browser/causyneBrowser.ts +65 -3
- package/src/browser/urlPolicy.js +14 -1
- package/src/browser/urlPolicy.ts +12 -1
- package/src/cliMode.js +21 -9
- package/src/cliMode.ts +20 -8
- package/src/commands.js +365 -45
- package/src/commands.ts +403 -45
- package/src/config.js +19 -4
- package/src/config.ts +18 -4
- package/src/core/contextCompactor.js +54 -7
- package/src/core/contextCompactor.ts +63 -7
- package/src/core/goalLoop.js +257 -0
- package/src/core/goalLoop.ts +310 -0
- package/src/entrypoint.js +135 -3
- package/src/entrypoint.ts +136 -3
- package/src/game/causyneCoreBridge.js +686 -0
- package/src/game/causyneCoreBridge.ts +702 -0
- package/src/game/gameLauncher.js +287 -0
- package/src/game/gameLauncher.ts +352 -0
- package/src/game/gameProvisioner.js +425 -0
- package/src/game/gameProvisioner.ts +488 -0
- package/src/headlessCli.js +19 -12
- package/src/headlessCli.ts +22 -8
- package/src/infra/atomicWriter.js +40 -4
- package/src/infra/atomicWriter.ts +36 -4
- package/src/launchIntent.js +73 -3
- package/src/launchIntent.ts +76 -3
- package/src/lsp/lspClient.js +83 -12
- package/src/lsp/lspClient.ts +75 -12
- package/src/mcp/mcpRegistry.js +75 -8
- package/src/mcp/mcpRegistry.ts +70 -7
- package/src/memory/contextBudget.js +2 -0
- package/src/memory/contextBudget.ts +1 -0
- 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/modelVariants.js +45 -0
- package/src/modelVariants.ts +54 -0
- package/src/outputRecovery.js +3 -2
- package/src/outputRecovery.ts +4 -2
- package/src/permissionPresets.js +327 -0
- package/src/permissionPresets.ts +361 -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 +64 -9
- package/src/providers/antigravity.ts +75 -9
- package/src/providers/byokHttp.js +7 -1
- package/src/providers/byokHttp.ts +6 -1
- package/src/providers/byokStream.js +21 -8
- package/src/providers/byokStream.ts +17 -7
- package/src/providers/dashscope-byok.js +21 -5
- package/src/providers/dashscope-byok.ts +29 -11
- package/src/providers/moonshot.js +26 -7
- package/src/providers/moonshot.ts +34 -13
- package/src/providers/muse.js +6 -0
- package/src/providers/muse.ts +8 -0
- package/src/providers/ollama.js +39 -7
- package/src/providers/ollama.ts +36 -7
- package/src/providers/openai-compatible.js +16 -3
- package/src/providers/openai-compatible.ts +13 -3
- package/src/providers/openai.js +62 -4
- package/src/providers/openai.ts +50 -4
- package/src/providers/openrouter.js +19 -4
- package/src/providers/openrouter.ts +21 -4
- package/src/providers/qwen-byok.js +21 -5
- package/src/providers/qwen-byok.ts +29 -11
- package/src/providers/xai.js +26 -10
- package/src/providers/xai.ts +34 -16
- package/src/reporting.js +4 -2
- package/src/reporting.ts +4 -2
- package/src/sandbox.js +34 -0
- package/src/sandbox.ts +43 -0
- package/src/scheduler/scheduler.js +372 -0
- package/src/scheduler/scheduler.ts +433 -0
- package/src/sessionSearchIndex.js +267 -0
- package/src/sessionSearchIndex.ts +311 -0
- package/src/skillsManager.js +2 -3
- package/src/skillsManager.ts +2 -3
- package/src/toolPacks.js +6 -0
- package/src/toolPacks.ts +6 -0
- package/src/tools/applyPatch.js +1 -1
- package/src/tools/applyPatch.ts +1 -1
- package/src/tools/generateMediaViaApi.js +4 -3
- package/src/tools/generateMediaViaApi.ts +4 -3
- package/src/tools/memoryWrite.js +15 -1
- package/src/tools/memoryWrite.ts +16 -1
- package/src/tools/nativeEngine.js +2 -2
- package/src/tools/nativeEngine.ts +2 -2
- package/src/tools/openSourceToolProvisioner.js +2 -2
- package/src/tools/openSourceToolProvisioner.ts +2 -2
- package/src/tools/osSandbox.js +1 -1
- package/src/tools/osSandbox.ts +1 -1
- package/src/tools/payloadSanitizer.js +0 -1
- package/src/tools/payloadSanitizer.ts +0 -1
- package/src/tools/pdfReader.js +122 -20
- package/src/tools/pdfReader.ts +111 -20
- package/src/tools/presentDeliverable.js +103 -0
- package/src/tools/presentDeliverable.ts +127 -0
- package/src/tools/ptcRuntime.js +444 -0
- package/src/tools/ptcRuntime.ts +490 -0
- package/src/tools/ptyTerminal.js +1108 -0
- package/src/tools/ptyTerminal.ts +1245 -0
- package/src/tools/registry.js +21 -12
- package/src/tools/registry.ts +21 -12
- package/src/tools/toolOutputStore.js +26 -4
- package/src/tools/toolOutputStore.ts +22 -4
- package/src/tools/webFetch.js +158 -11
- package/src/tools/webFetch.ts +145 -11
- package/src/tools/webSearch.js +123 -36
- package/src/tools/webSearch.ts +124 -33
- package/src/tui/banner.js +5 -1
- package/src/tui/banner.ts +6 -1
- package/src/tui/chatRenderer.js +1 -2
- package/src/tui/chatRenderer.ts +1 -2
- package/src/tui/completion.js +1 -0
- package/src/tui/completion.ts +1 -0
- package/src/tui/composerControls.js +111 -27
- package/src/tui/composerControls.ts +124 -28
- package/src/tui/dialogs.js +3 -16
- package/src/tui/dialogs.ts +3 -16
- package/src/tui/home.js +1 -0
- package/src/tui/home.ts +1 -0
- package/src/tui/invocation.js +1 -2
- package/src/tui/invocation.ts +1 -2
- package/src/tui/modelPicker.js +22 -12
- package/src/tui/modelPicker.ts +22 -12
- package/src/tui/overlay.js +2 -5
- package/src/tui/overlay.ts +2 -5
- package/src/tui/prompt.js +6 -4
- package/src/tui/prompt.ts +6 -4
- package/src/tui/selectList.js +4 -12
- package/src/tui/selectList.ts +4 -12
- package/src/tui/setup.js +22 -9
- package/src/tui/setup.ts +26 -9
- package/src/tui/statusLine.ts +2 -0
- package/src/web/client/browserPanel.js +905 -0
- package/src/web/client/browserPanel.ts +872 -0
- package/src/web/client/chatStream.js +321 -0
- package/src/web/client/chatStream.ts +297 -0
- package/src/web/client/cliPanel.js +165 -0
- package/src/web/client/cliPanel.ts +171 -0
- package/src/web/client/composer.js +204 -0
- package/src/web/client/composer.ts +209 -0
- package/src/web/client/diffPanel.js +176 -0
- package/src/web/client/diffPanel.ts +203 -0
- package/src/web/client/dom.js +271 -0
- package/src/web/client/dom.ts +272 -0
- package/src/web/client/filesAndCanvas.js +233 -0
- package/src/web/client/filesAndCanvas.ts +240 -0
- package/src/web/client/gameLauncherUi.js +78 -0
- package/src/web/client/gameLauncherUi.ts +78 -0
- package/src/web/client/main.js +316 -0
- package/src/web/client/main.ts +391 -0
- package/src/web/client/markdown.js +364 -0
- package/src/web/client/markdown.ts +373 -0
- package/src/web/client/modelPicker.js +455 -0
- package/src/web/client/modelPicker.ts +451 -0
- package/src/web/client/permissionPresetsUi.js +307 -0
- package/src/web/client/permissionPresetsUi.ts +333 -0
- package/src/web/client/sessions.js +353 -0
- package/src/web/client/sessions.ts +372 -0
- package/src/web/client/settingsModal.js +824 -0
- package/src/web/client/settingsModal.ts +959 -0
- package/src/web/client/state.js +280 -0
- package/src/web/client/state.ts +259 -0
- package/src/web/client/streamSmoother.js +127 -0
- package/src/web/client/streamSmoother.ts +119 -0
- package/src/web/client/studioLayout.js +89 -0
- package/src/web/client/studioLayout.ts +103 -0
- package/src/web/client/studioShell.js +660 -0
- package/src/web/client/studioShell.ts +672 -0
- package/src/web/client/studioStart.js +77 -0
- package/src/web/client/studioStart.ts +89 -0
- package/src/web/client/terminalPanel.js +606 -0
- package/src/web/client/terminalPanel.ts +632 -0
- package/src/web/client/terminalTheme.js +249 -0
- package/src/web/client/terminalTheme.ts +258 -0
- package/src/web/client/turnView.js +934 -0
- package/src/web/client/turnView.ts +981 -0
- package/src/web/client/types.js +1 -0
- package/src/web/client/types.ts +322 -0
- package/src/web/client/validators.js +147 -0
- package/src/web/client/validators.ts +140 -0
- package/src/web/server/activeRuns.js +152 -0
- package/src/web/server/activeRuns.ts +171 -0
- package/src/web/server/routesBrowser.js +409 -0
- package/src/web/server/routesBrowser.ts +435 -0
- package/src/web/server/routesChat.js +304 -0
- package/src/web/server/routesChat.ts +347 -0
- package/src/web/server/routesCore.js +472 -0
- package/src/web/server/routesCore.ts +522 -0
- package/src/web/server/routesSettings.js +344 -0
- package/src/web/server/routesSettings.ts +397 -0
- package/src/web/server/routesTerminal.js +162 -0
- package/src/web/server/routesTerminal.ts +182 -0
- package/src/web/server/routesWorkspace.js +510 -0
- package/src/web/server/routesWorkspace.ts +546 -0
- package/src/web/server/security.js +98 -0
- package/src/web/server/security.ts +108 -0
- package/src/web/server/sessionTranscript.js +586 -0
- package/src/web/server/sessionTranscript.ts +566 -0
- package/src/web/server/staticAssets.js +104 -0
- package/src/web/server/staticAssets.ts +116 -0
- package/src/web/server/types.js +1 -0
- package/src/web/server/types.ts +135 -0
- package/src/web/server/workspaceFiles.js +368 -0
- package/src/web/server/workspaceFiles.ts +363 -0
- package/src/web/skybridgeServer.js +78 -2448
- package/src/web/skybridgeServer.ts +120 -2600
- package/src/web/skybridgeUi.js +20 -450
- package/src/web/skybridgeUi.ts +24 -455
- package/src/web/styles/agent.css +380 -0
- package/src/web/styles/composer.css +193 -0
- package/src/web/styles/overlays.css +935 -0
- package/src/web/styles/shell.css +387 -0
- package/src/web/styles/studio.css +951 -0
- package/src/web/styles/thread.css +221 -0
- package/src/web/styles/tokens.css +94 -0
- package/src/web/ui/brandMark.js +73 -0
- package/src/web/ui/brandMark.ts +82 -0
- package/src/web/ui/modalsTemplate.js +388 -0
- package/src/web/ui/modalsTemplate.ts +388 -0
- package/src/web/ui/sidebarTemplate.js +63 -0
- package/src/web/ui/sidebarTemplate.ts +64 -0
- package/src/web/ui/studioTemplate.js +256 -0
- package/src/web/ui/studioTemplate.ts +256 -0
- package/src/web/ui/workspaceTemplate.js +72 -0
- package/src/web/ui/workspaceTemplate.ts +73 -0
- package/src/worktreeManager.js +16 -1
- package/src/worktreeManager.ts +22 -1
- package/src/web/skybridgeClientScript.js +0 -3951
- package/src/web/skybridgeClientScript.ts +0 -3952
- package/src/web/skybridgeStyles.js +0 -827
- package/src/web/skybridgeStyles.ts +0 -828
|
@@ -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
|
+
}
|