@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
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
import { dom } from './dom.js';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
apiUrl,
|
|
4
|
+
applyAutoScrollPref,
|
|
5
|
+
applyDensity,
|
|
6
|
+
applyTheme,
|
|
7
|
+
authHeaders,
|
|
8
|
+
isAutoScrollEnabled
|
|
9
|
+
} from './state.js';
|
|
3
10
|
import { isSafeBillingUrl } from './validators.js';
|
|
4
11
|
|
|
12
|
+
export type SettingsSectionId =
|
|
13
|
+
| 'general'
|
|
14
|
+
| 'configuration'
|
|
15
|
+
| 'personalization'
|
|
16
|
+
| 'billing'
|
|
17
|
+
| 'vault'
|
|
18
|
+
| 'mcp'
|
|
19
|
+
| 'hooks'
|
|
20
|
+
| 'plugins'
|
|
21
|
+
| 'diagnostics';
|
|
22
|
+
|
|
23
|
+
type PersonalizationScope = 'project' | 'global';
|
|
24
|
+
|
|
5
25
|
interface LicenseStatusPayload {
|
|
6
26
|
entitlement?: string;
|
|
7
27
|
plan?: string;
|
|
@@ -13,20 +33,717 @@ interface LicenseStatusPayload {
|
|
|
13
33
|
error?: string;
|
|
14
34
|
}
|
|
15
35
|
|
|
36
|
+
interface PersonalizationDoc {
|
|
37
|
+
scope: PersonalizationScope;
|
|
38
|
+
path: string;
|
|
39
|
+
displayPath: string;
|
|
40
|
+
exists: boolean;
|
|
41
|
+
content: string;
|
|
42
|
+
bytes: number;
|
|
43
|
+
maxBytes: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface PersonalizationPayload {
|
|
47
|
+
workspaceRoot: string;
|
|
48
|
+
project: PersonalizationDoc;
|
|
49
|
+
global: PersonalizationDoc;
|
|
50
|
+
memory: {
|
|
51
|
+
enabled: boolean;
|
|
52
|
+
allowToolAssisted: boolean;
|
|
53
|
+
source: 'project' | 'global';
|
|
54
|
+
projectOverrides: { enabled?: boolean; allowToolAssisted?: boolean };
|
|
55
|
+
globalDefaults: { enabled: boolean; allowToolAssisted: boolean };
|
|
56
|
+
};
|
|
57
|
+
memoryStats: {
|
|
58
|
+
projectFacts: number;
|
|
59
|
+
totalFacts: number;
|
|
60
|
+
projectObservations: number;
|
|
61
|
+
totalObservations: number;
|
|
62
|
+
projectSummaries: number;
|
|
63
|
+
totalSummaries: number;
|
|
64
|
+
};
|
|
65
|
+
activeRules: Array<{
|
|
66
|
+
scope: string;
|
|
67
|
+
label: string;
|
|
68
|
+
bytes: number;
|
|
69
|
+
truncated?: boolean;
|
|
70
|
+
}>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface HookOverviewItem {
|
|
74
|
+
index: number;
|
|
75
|
+
name: string;
|
|
76
|
+
event: string;
|
|
77
|
+
tools: string[];
|
|
78
|
+
commandPreview: string;
|
|
79
|
+
timeoutMs: number;
|
|
80
|
+
enabled: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface PluginOverviewItem {
|
|
84
|
+
name: string;
|
|
85
|
+
version?: string;
|
|
86
|
+
description?: string;
|
|
87
|
+
enabled: boolean;
|
|
88
|
+
modified?: boolean;
|
|
89
|
+
invalid?: boolean;
|
|
90
|
+
error?: string;
|
|
91
|
+
capabilities?: string[];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
interface McpServerOverviewItem {
|
|
95
|
+
name: string;
|
|
96
|
+
transport: string;
|
|
97
|
+
target: string;
|
|
98
|
+
granted?: boolean;
|
|
99
|
+
connected?: boolean;
|
|
100
|
+
status?: string;
|
|
101
|
+
error?: string;
|
|
102
|
+
tools?: string[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface SettingsOverviewPayload {
|
|
106
|
+
ok?: boolean;
|
|
107
|
+
general?: {
|
|
108
|
+
workspaceRoot?: string;
|
|
109
|
+
workspaceName?: string;
|
|
110
|
+
version?: string;
|
|
111
|
+
platform?: string;
|
|
112
|
+
provider?: string;
|
|
113
|
+
model?: string;
|
|
114
|
+
};
|
|
115
|
+
configuration?: {
|
|
116
|
+
defaultPermissionPreset?: string;
|
|
117
|
+
reasoningEffort?: string;
|
|
118
|
+
osSandbox?: {
|
|
119
|
+
configuredMode?: string;
|
|
120
|
+
effectiveMode?: string;
|
|
121
|
+
strict?: boolean;
|
|
122
|
+
backend?: string;
|
|
123
|
+
available?: boolean;
|
|
124
|
+
reason?: string;
|
|
125
|
+
};
|
|
126
|
+
tokenBudget?: {
|
|
127
|
+
enabled?: boolean;
|
|
128
|
+
maxTokensPerTask?: number;
|
|
129
|
+
maxTokensPerDay?: number;
|
|
130
|
+
maxCostUsd?: number;
|
|
131
|
+
hardStop?: boolean;
|
|
132
|
+
};
|
|
133
|
+
autoCompact?: {
|
|
134
|
+
enabled?: boolean;
|
|
135
|
+
thresholdPercent?: number;
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
personalization?: PersonalizationPayload;
|
|
139
|
+
vault?: {
|
|
140
|
+
activeProvider?: string;
|
|
141
|
+
configuredProviders?: string[];
|
|
142
|
+
};
|
|
143
|
+
mcp?: {
|
|
144
|
+
servers?: McpServerOverviewItem[];
|
|
145
|
+
projectDiscovered?: McpServerOverviewItem[];
|
|
146
|
+
projectWarnings?: string[];
|
|
147
|
+
projectFile?: string | null;
|
|
148
|
+
};
|
|
149
|
+
hooks?: HookOverviewItem[];
|
|
150
|
+
plugins?: {
|
|
151
|
+
root?: string;
|
|
152
|
+
items?: PluginOverviewItem[];
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
16
156
|
export interface SettingsModalCallbacks {
|
|
17
157
|
loadHealth(): Promise<void>;
|
|
18
158
|
loadModels(mode?: string): Promise<void>;
|
|
19
159
|
}
|
|
20
160
|
|
|
161
|
+
const SECTION_LABELS: Record<SettingsSectionId, string> = {
|
|
162
|
+
general: 'General',
|
|
163
|
+
configuration: 'Configuration',
|
|
164
|
+
personalization: 'Personalization',
|
|
165
|
+
billing: 'Usage & billing',
|
|
166
|
+
vault: 'API keys',
|
|
167
|
+
mcp: 'MCP servers',
|
|
168
|
+
hooks: 'Hooks',
|
|
169
|
+
plugins: 'Plugins',
|
|
170
|
+
diagnostics: 'Diagnostics'
|
|
171
|
+
};
|
|
172
|
+
|
|
21
173
|
let callbacks: SettingsModalCallbacks = {
|
|
22
174
|
loadHealth: async () => {},
|
|
23
175
|
loadModels: async () => {}
|
|
24
176
|
};
|
|
25
177
|
|
|
178
|
+
let activeSection: SettingsSectionId = 'general';
|
|
179
|
+
let activeScope: PersonalizationScope = 'project';
|
|
180
|
+
let overviewData: SettingsOverviewPayload | null = null;
|
|
181
|
+
const savedInstructions: Record<PersonalizationScope, string> = { project: '', global: '' };
|
|
182
|
+
const draftInstructions: Record<PersonalizationScope, string> = { project: '', global: '' };
|
|
183
|
+
|
|
26
184
|
export function configureSettingsModalCallbacks(cbs: SettingsModalCallbacks): void {
|
|
27
185
|
callbacks = cbs;
|
|
28
186
|
}
|
|
29
187
|
|
|
188
|
+
function utf8ByteLength(text: string): number {
|
|
189
|
+
return new TextEncoder().encode(text).length;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function clearChildren(el: HTMLElement | null): void {
|
|
193
|
+
if (!el) return;
|
|
194
|
+
while (el.firstChild) el.removeChild(el.firstChild);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function makePill(text: string, variant?: 'ok' | 'warn'): HTMLSpanElement {
|
|
198
|
+
const span = document.createElement('span');
|
|
199
|
+
span.className = variant === 'ok'
|
|
200
|
+
? 'settings-pill is-ok'
|
|
201
|
+
: variant === 'warn'
|
|
202
|
+
? 'settings-pill is-warn'
|
|
203
|
+
: 'settings-pill';
|
|
204
|
+
span.textContent = text;
|
|
205
|
+
return span;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function makeEmptyBox(text: string): HTMLDivElement {
|
|
209
|
+
const div = document.createElement('div');
|
|
210
|
+
div.className = 'settings-empty-box';
|
|
211
|
+
div.textContent = text;
|
|
212
|
+
return div;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function makeSwitchControl(
|
|
216
|
+
checked: boolean,
|
|
217
|
+
ariaLabel: string,
|
|
218
|
+
onChange: (nextChecked: boolean, inputEl: HTMLInputElement) => void
|
|
219
|
+
): HTMLLabelElement {
|
|
220
|
+
const label = document.createElement('label');
|
|
221
|
+
label.className = 'c-switch';
|
|
222
|
+
const input = document.createElement('input');
|
|
223
|
+
input.type = 'checkbox';
|
|
224
|
+
input.checked = checked;
|
|
225
|
+
input.setAttribute('aria-label', ariaLabel);
|
|
226
|
+
input.addEventListener('change', () => onChange(input.checked, input));
|
|
227
|
+
const track = document.createElement('span');
|
|
228
|
+
track.className = 'c-switch-track';
|
|
229
|
+
label.appendChild(input);
|
|
230
|
+
label.appendChild(track);
|
|
231
|
+
return label;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function syncDeleteConfirmVisibility(confirming: boolean): void {
|
|
235
|
+
if (dom.personalizationMemoryDeleteBtn) dom.personalizationMemoryDeleteBtn.hidden = confirming;
|
|
236
|
+
if (dom.personalizationMemoryConfirmBtn) dom.personalizationMemoryConfirmBtn.hidden = !confirming;
|
|
237
|
+
if (dom.personalizationMemoryCancelBtn) dom.personalizationMemoryCancelBtn.hidden = !confirming;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function selectSettingsSection(section: SettingsSectionId): void {
|
|
241
|
+
activeSection = section;
|
|
242
|
+
const navButtons = dom.settingsModal.querySelectorAll<HTMLButtonElement>('[data-settings-section]');
|
|
243
|
+
navButtons.forEach((btn) => {
|
|
244
|
+
const isMatch = btn.dataset.settingsSection === section;
|
|
245
|
+
btn.classList.toggle('active', isMatch);
|
|
246
|
+
btn.setAttribute('aria-selected', isMatch ? 'true' : 'false');
|
|
247
|
+
});
|
|
248
|
+
const panes = dom.settingsModal.querySelectorAll<HTMLElement>('[data-settings-pane]');
|
|
249
|
+
panes.forEach((pane) => {
|
|
250
|
+
const isMatch = pane.dataset.settingsPane === section;
|
|
251
|
+
pane.classList.toggle('active', isMatch);
|
|
252
|
+
pane.hidden = !isMatch;
|
|
253
|
+
});
|
|
254
|
+
if (dom.settingsMobileTitle) {
|
|
255
|
+
dom.settingsMobileTitle.textContent = SECTION_LABELS[section] || 'Settings';
|
|
256
|
+
}
|
|
257
|
+
if (section === 'diagnostics') {
|
|
258
|
+
void loadDoctorReport();
|
|
259
|
+
} else if (section === 'billing') {
|
|
260
|
+
void loadLicenseStatus(false);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function updatePersonalizationSaveState(): void {
|
|
265
|
+
if (!dom.personalizationInstructionsInput || !dom.personalizationSaveBtn) return;
|
|
266
|
+
const current = dom.personalizationInstructionsInput.value;
|
|
267
|
+
draftInstructions[activeScope] = current;
|
|
268
|
+
const bytes = utf8ByteLength(current);
|
|
269
|
+
const maxBytes = overviewData?.personalization?.[activeScope]?.maxBytes ?? 16_384;
|
|
270
|
+
if (dom.personalizationByteCount) {
|
|
271
|
+
dom.personalizationByteCount.textContent = `${bytes.toLocaleString()} / ${maxBytes.toLocaleString()} bytes`;
|
|
272
|
+
dom.personalizationByteCount.style.color = bytes > maxBytes ? 'var(--err)' : '';
|
|
273
|
+
}
|
|
274
|
+
const dirty = current !== savedInstructions[activeScope];
|
|
275
|
+
dom.personalizationSaveBtn.disabled = !dirty || bytes > maxBytes;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function renderPersonalizationView(): void {
|
|
279
|
+
const p = overviewData?.personalization;
|
|
280
|
+
if (!p) return;
|
|
281
|
+
|
|
282
|
+
if (dom.settingsPersonalizationDot) {
|
|
283
|
+
dom.settingsPersonalizationDot.hidden = !(p.project.exists && p.project.content.trim().length > 0);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const isProject = activeScope === 'project';
|
|
287
|
+
dom.personalizationScopeProjectBtn?.classList.toggle('active', isProject);
|
|
288
|
+
dom.personalizationScopeGlobalBtn?.classList.toggle('active', !isProject);
|
|
289
|
+
|
|
290
|
+
const doc = isProject ? p.project : p.global;
|
|
291
|
+
if (dom.personalizationDocTitle) {
|
|
292
|
+
dom.personalizationDocTitle.textContent = isProject ? 'Project instructions' : 'Global instructions';
|
|
293
|
+
}
|
|
294
|
+
if (dom.personalizationDocDesc) {
|
|
295
|
+
dom.personalizationDocDesc.textContent = isProject
|
|
296
|
+
? 'Applies specifically to this project (.causyne/personalization.md) and is treated by Causyne Agent as a high-priority binding contract. Repository rules (CAUSYNE.md, AGENTS.md, .causyne/rules/) also apply.'
|
|
297
|
+
: 'Applies across all projects on this computer (~/.causyne/CAUSYNE.md). Project-specific personalization overrides global defaults when both are set.';
|
|
298
|
+
}
|
|
299
|
+
if (dom.personalizationFilePath) {
|
|
300
|
+
dom.personalizationFilePath.textContent = doc.displayPath;
|
|
301
|
+
}
|
|
302
|
+
if (dom.personalizationInstructionsInput) {
|
|
303
|
+
dom.personalizationInstructionsInput.value = draftInstructions[activeScope];
|
|
304
|
+
}
|
|
305
|
+
updatePersonalizationSaveState();
|
|
306
|
+
|
|
307
|
+
clearChildren(dom.personalizationActiveRules);
|
|
308
|
+
if (dom.personalizationActiveRules) {
|
|
309
|
+
if (p.activeRules.length === 0) {
|
|
310
|
+
dom.personalizationActiveRules.appendChild(makePill('No active project rule files yet'));
|
|
311
|
+
} else {
|
|
312
|
+
for (const rule of p.activeRules) {
|
|
313
|
+
const chip = makePill(
|
|
314
|
+
`${rule.scope}: ${rule.label} (${rule.bytes.toLocaleString()} B)`,
|
|
315
|
+
rule.scope === 'personalization' ? 'ok' : undefined
|
|
316
|
+
);
|
|
317
|
+
dom.personalizationActiveRules.appendChild(chip);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const memEnabled = isProject
|
|
323
|
+
? (typeof p.memory.projectOverrides.enabled === 'boolean' ? p.memory.projectOverrides.enabled : p.memory.globalDefaults.enabled)
|
|
324
|
+
: p.memory.globalDefaults.enabled;
|
|
325
|
+
const memToolAssisted = isProject
|
|
326
|
+
? (typeof p.memory.projectOverrides.allowToolAssisted === 'boolean' ? p.memory.projectOverrides.allowToolAssisted : p.memory.globalDefaults.allowToolAssisted)
|
|
327
|
+
: p.memory.globalDefaults.allowToolAssisted;
|
|
328
|
+
|
|
329
|
+
if (dom.personalizationMemoryEnabled) dom.personalizationMemoryEnabled.checked = memEnabled;
|
|
330
|
+
if (dom.personalizationMemoryToolAssisted) dom.personalizationMemoryToolAssisted.checked = memToolAssisted;
|
|
331
|
+
|
|
332
|
+
if (dom.personalizationMemoryDesc) {
|
|
333
|
+
if (isProject) {
|
|
334
|
+
dom.personalizationMemoryDesc.textContent = p.memory.source === 'project'
|
|
335
|
+
? 'Using project-specific memory settings for this workspace.'
|
|
336
|
+
: 'Inheriting global memory defaults for this workspace (toggling sets a project override).';
|
|
337
|
+
} else {
|
|
338
|
+
dom.personalizationMemoryDesc.textContent = 'Default Causyne memory behavior across all projects on this computer.';
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
if (dom.personalizationMemEnableDesc) {
|
|
342
|
+
dom.personalizationMemEnableDesc.textContent = isProject
|
|
343
|
+
? 'Create memories from chats in this project and use them to personalize future chats'
|
|
344
|
+
: 'Create memories from chats on this computer and use them to personalize future chats';
|
|
345
|
+
}
|
|
346
|
+
if (dom.personalizationMemDeleteDesc) {
|
|
347
|
+
dom.personalizationMemDeleteDesc.textContent = isProject
|
|
348
|
+
? 'Delete stored Causyne memories for this project'
|
|
349
|
+
: 'Delete all Causyne memories stored across every project on this computer';
|
|
350
|
+
}
|
|
351
|
+
if (dom.personalizationMemoryStats) {
|
|
352
|
+
const s = p.memoryStats;
|
|
353
|
+
dom.personalizationMemoryStats.textContent = isProject
|
|
354
|
+
? `${s.projectFacts} facts · ${s.projectObservations} observations`
|
|
355
|
+
: `${s.totalFacts} facts · ${s.totalObservations} observations`;
|
|
356
|
+
}
|
|
357
|
+
syncDeleteConfirmVisibility(false);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function renderConfigurationView(): void {
|
|
361
|
+
const cfg = overviewData?.configuration;
|
|
362
|
+
if (!cfg) return;
|
|
363
|
+
|
|
364
|
+
if (dom.settingsPermSelect && cfg.defaultPermissionPreset) {
|
|
365
|
+
dom.settingsPermSelect.value = cfg.defaultPermissionPreset;
|
|
366
|
+
}
|
|
367
|
+
if (dom.settingsOsSandboxSelect && cfg.osSandbox?.configuredMode) {
|
|
368
|
+
dom.settingsOsSandboxSelect.value = cfg.osSandbox.configuredMode;
|
|
369
|
+
}
|
|
370
|
+
if (dom.settingsSandboxBadge && cfg.osSandbox) {
|
|
371
|
+
const sb = cfg.osSandbox;
|
|
372
|
+
const label = sb.available
|
|
373
|
+
? `${sb.backend === 'seatbelt' ? 'Seatbelt' : sb.backend === 'bubblewrap' ? 'Bubblewrap' : sb.backend} ready`
|
|
374
|
+
: 'Unavailable';
|
|
375
|
+
dom.settingsSandboxBadge.textContent = label;
|
|
376
|
+
dom.settingsSandboxBadge.className = sb.available ? 'settings-pill is-ok' : 'settings-pill is-warn';
|
|
377
|
+
}
|
|
378
|
+
if (dom.settingsSandboxDesc && cfg.osSandbox?.reason) {
|
|
379
|
+
dom.settingsSandboxDesc.textContent = cfg.osSandbox.reason;
|
|
380
|
+
}
|
|
381
|
+
if (dom.settingsEffortSelect) {
|
|
382
|
+
dom.settingsEffortSelect.value = cfg.reasoningEffort || '';
|
|
383
|
+
}
|
|
384
|
+
if (cfg.tokenBudget) {
|
|
385
|
+
if (dom.settingsBudgetEnabled) dom.settingsBudgetEnabled.checked = cfg.tokenBudget.enabled === true;
|
|
386
|
+
if (dom.settingsBudgetHardstop) dom.settingsBudgetHardstop.checked = cfg.tokenBudget.hardStop === true;
|
|
387
|
+
if (dom.settingsBudgetTask) dom.settingsBudgetTask.value = String(cfg.tokenBudget.maxTokensPerTask ?? 150000);
|
|
388
|
+
if (dom.settingsBudgetDay) dom.settingsBudgetDay.value = String(cfg.tokenBudget.maxTokensPerDay ?? 1000000);
|
|
389
|
+
if (dom.settingsBudgetCost) dom.settingsBudgetCost.value = String(cfg.tokenBudget.maxCostUsd ?? 5);
|
|
390
|
+
}
|
|
391
|
+
if (cfg.autoCompact) {
|
|
392
|
+
if (dom.settingsAutoCompactEnabled) dom.settingsAutoCompactEnabled.checked = cfg.autoCompact.enabled !== false;
|
|
393
|
+
if (dom.settingsCompactPct) dom.settingsCompactPct.value = String(cfg.autoCompact.thresholdPercent ?? 78);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function renderVaultConfiguredChips(): void {
|
|
398
|
+
clearChildren(dom.vaultConfiguredList);
|
|
399
|
+
if (!dom.vaultConfiguredList) return;
|
|
400
|
+
const list = overviewData?.vault?.configuredProviders || [];
|
|
401
|
+
if (list.length === 0) {
|
|
402
|
+
dom.vaultConfiguredList.appendChild(makePill('No BYOK provider keys saved yet'));
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
for (const id of list) {
|
|
406
|
+
dom.vaultConfiguredList.appendChild(makePill(id, 'ok'));
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function renderMcpView(): void {
|
|
411
|
+
clearChildren(dom.settingsMcpList);
|
|
412
|
+
if (!dom.settingsMcpList) return;
|
|
413
|
+
const servers = overviewData?.mcp?.servers || [];
|
|
414
|
+
const discovered = overviewData?.mcp?.projectDiscovered || [];
|
|
415
|
+
|
|
416
|
+
if (servers.length === 0 && discovered.length === 0) {
|
|
417
|
+
dom.settingsMcpList.appendChild(
|
|
418
|
+
makeEmptyBox('No MCP servers configured yet. Add servers with `/mcp add` in the CLI or define a workspace `.mcp.json` file.')
|
|
419
|
+
);
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
for (const srv of servers) {
|
|
424
|
+
const card = document.createElement('div');
|
|
425
|
+
card.className = 'settings-entity-card';
|
|
426
|
+
const main = document.createElement('div');
|
|
427
|
+
main.className = 'settings-entity-main';
|
|
428
|
+
const nameRow = document.createElement('div');
|
|
429
|
+
nameRow.className = 'settings-entity-name';
|
|
430
|
+
nameRow.textContent = srv.name;
|
|
431
|
+
nameRow.appendChild(makePill(srv.transport || 'stdio'));
|
|
432
|
+
const statusText = srv.connected ? `connected · ${(srv.tools || []).length} tools` : (srv.status || 'disconnected');
|
|
433
|
+
nameRow.appendChild(makePill(statusText, srv.connected ? 'ok' : undefined));
|
|
434
|
+
const meta = document.createElement('div');
|
|
435
|
+
meta.className = 'settings-entity-meta';
|
|
436
|
+
meta.textContent = srv.error ? `${srv.target} — ${srv.error}` : (srv.target || 'Configured server');
|
|
437
|
+
main.appendChild(nameRow);
|
|
438
|
+
main.appendChild(meta);
|
|
439
|
+
card.appendChild(main);
|
|
440
|
+
dom.settingsMcpList.appendChild(card);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
for (const srv of discovered) {
|
|
444
|
+
if (servers.some((existing) => existing.name === srv.name)) continue;
|
|
445
|
+
const card = document.createElement('div');
|
|
446
|
+
card.className = 'settings-entity-card';
|
|
447
|
+
const main = document.createElement('div');
|
|
448
|
+
main.className = 'settings-entity-main';
|
|
449
|
+
const nameRow = document.createElement('div');
|
|
450
|
+
nameRow.className = 'settings-entity-name';
|
|
451
|
+
nameRow.textContent = srv.name;
|
|
452
|
+
nameRow.appendChild(makePill('workspace .mcp.json', 'warn'));
|
|
453
|
+
const meta = document.createElement('div');
|
|
454
|
+
meta.className = 'settings-entity-meta';
|
|
455
|
+
meta.textContent = srv.target || 'Requires trust grant before launch';
|
|
456
|
+
main.appendChild(nameRow);
|
|
457
|
+
main.appendChild(meta);
|
|
458
|
+
card.appendChild(main);
|
|
459
|
+
dom.settingsMcpList.appendChild(card);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
function renderHooksView(): void {
|
|
464
|
+
clearChildren(dom.settingsHooksList);
|
|
465
|
+
if (!dom.settingsHooksList) return;
|
|
466
|
+
const hooks = overviewData?.hooks || [];
|
|
467
|
+
if (hooks.length === 0) {
|
|
468
|
+
dom.settingsHooksList.appendChild(
|
|
469
|
+
makeEmptyBox('No lifecycle hooks configured. Add `hooks` entries (PreToolUse / PostToolUse) in `~/.causyne/config.json` to inspect or toggle them here.')
|
|
470
|
+
);
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
for (const hook of hooks) {
|
|
475
|
+
const card = document.createElement('div');
|
|
476
|
+
card.className = 'settings-entity-card';
|
|
477
|
+
const main = document.createElement('div');
|
|
478
|
+
main.className = 'settings-entity-main';
|
|
479
|
+
const nameRow = document.createElement('div');
|
|
480
|
+
nameRow.className = 'settings-entity-name';
|
|
481
|
+
nameRow.textContent = hook.name;
|
|
482
|
+
nameRow.appendChild(makePill(hook.event));
|
|
483
|
+
nameRow.appendChild(makePill(hook.tools.join(', ')));
|
|
484
|
+
const meta = document.createElement('div');
|
|
485
|
+
meta.className = 'settings-entity-meta';
|
|
486
|
+
meta.textContent = hook.commandPreview || `${hook.timeoutMs} ms timeout`;
|
|
487
|
+
main.appendChild(nameRow);
|
|
488
|
+
main.appendChild(meta);
|
|
489
|
+
card.appendChild(main);
|
|
490
|
+
card.appendChild(makeSwitchControl(hook.enabled, `Toggle hook ${hook.name}`, (nextEnabled, inputEl) => {
|
|
491
|
+
void toggleHookEnabled(hook.index, nextEnabled, inputEl);
|
|
492
|
+
}));
|
|
493
|
+
dom.settingsHooksList.appendChild(card);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function renderPluginsView(): void {
|
|
498
|
+
if (dom.settingsPluginsRoot && overviewData?.plugins?.root) {
|
|
499
|
+
dom.settingsPluginsRoot.textContent = `Plugin directory: ${overviewData.plugins.root}`;
|
|
500
|
+
}
|
|
501
|
+
clearChildren(dom.settingsPluginsList);
|
|
502
|
+
if (!dom.settingsPluginsList) return;
|
|
503
|
+
const items = overviewData?.plugins?.items || [];
|
|
504
|
+
if (items.length === 0) {
|
|
505
|
+
dom.settingsPluginsList.appendChild(
|
|
506
|
+
makeEmptyBox('No local plugins installed. Place a plugin directory with `plugin.json` in the plugin root and enable trust here or via `/plugins enable <name>`.')
|
|
507
|
+
);
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
for (const plugin of items) {
|
|
512
|
+
const card = document.createElement('div');
|
|
513
|
+
card.className = 'settings-entity-card';
|
|
514
|
+
const main = document.createElement('div');
|
|
515
|
+
main.className = 'settings-entity-main';
|
|
516
|
+
const nameRow = document.createElement('div');
|
|
517
|
+
nameRow.className = 'settings-entity-name';
|
|
518
|
+
nameRow.textContent = plugin.version ? `${plugin.name} v${plugin.version}` : plugin.name;
|
|
519
|
+
if (plugin.invalid) {
|
|
520
|
+
nameRow.appendChild(makePill('invalid', 'warn'));
|
|
521
|
+
} else if (plugin.modified) {
|
|
522
|
+
nameRow.appendChild(makePill('modified · trust revoked', 'warn'));
|
|
523
|
+
} else {
|
|
524
|
+
nameRow.appendChild(makePill(plugin.enabled ? 'enabled' : 'disabled', plugin.enabled ? 'ok' : undefined));
|
|
525
|
+
}
|
|
526
|
+
const meta = document.createElement('div');
|
|
527
|
+
meta.className = 'settings-entity-meta';
|
|
528
|
+
const caps = Array.isArray(plugin.capabilities) && plugin.capabilities.length > 0
|
|
529
|
+
? `Capabilities: ${plugin.capabilities.join(', ')}`
|
|
530
|
+
: 'No extra capabilities';
|
|
531
|
+
meta.textContent = plugin.error || plugin.description || caps;
|
|
532
|
+
main.appendChild(nameRow);
|
|
533
|
+
main.appendChild(meta);
|
|
534
|
+
card.appendChild(main);
|
|
535
|
+
|
|
536
|
+
if (!plugin.invalid) {
|
|
537
|
+
card.appendChild(makeSwitchControl(plugin.enabled && !plugin.modified, `Toggle plugin ${plugin.name}`, (nextEnabled, inputEl) => {
|
|
538
|
+
void togglePluginEnabled(plugin.name, nextEnabled, inputEl);
|
|
539
|
+
}));
|
|
540
|
+
}
|
|
541
|
+
dom.settingsPluginsList.appendChild(card);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
function renderGeneralMeta(): void {
|
|
546
|
+
const gen = overviewData?.general;
|
|
547
|
+
if (dom.settingsCompactToggle) {
|
|
548
|
+
dom.settingsCompactToggle.checked = document.documentElement.getAttribute('data-density') === 'compact';
|
|
549
|
+
}
|
|
550
|
+
if (dom.settingsAutoScrollToggle) {
|
|
551
|
+
dom.settingsAutoScrollToggle.checked = isAutoScrollEnabled();
|
|
552
|
+
}
|
|
553
|
+
if (!gen) return;
|
|
554
|
+
if (dom.settingsWsPath && gen.workspaceRoot) {
|
|
555
|
+
dom.settingsWsPath.textContent = gen.workspaceRoot;
|
|
556
|
+
}
|
|
557
|
+
if (dom.settingsRuntimeMeta) {
|
|
558
|
+
dom.settingsRuntimeMeta.textContent = `${gen.provider || 'unconfigured'} · ${gen.model || 'default'} · ${gen.platform || 'local'}`;
|
|
559
|
+
}
|
|
560
|
+
if (dom.settingsVersionPill && gen.version) {
|
|
561
|
+
dom.settingsVersionPill.textContent = `v${gen.version}`;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
export async function loadSettingsOverview(): Promise<void> {
|
|
566
|
+
const res = await fetch(apiUrl('/api/settings/overview'), { headers: authHeaders() }).catch(() => null);
|
|
567
|
+
if (!res || !res.ok) return;
|
|
568
|
+
const data = await res.json().catch(() => null) as SettingsOverviewPayload | null;
|
|
569
|
+
if (!data) return;
|
|
570
|
+
overviewData = data;
|
|
571
|
+
if (data.personalization) {
|
|
572
|
+
savedInstructions.project = data.personalization.project.content;
|
|
573
|
+
savedInstructions.global = data.personalization.global.content;
|
|
574
|
+
draftInstructions.project = data.personalization.project.content;
|
|
575
|
+
draftInstructions.global = data.personalization.global.content;
|
|
576
|
+
}
|
|
577
|
+
renderGeneralMeta();
|
|
578
|
+
renderConfigurationView();
|
|
579
|
+
renderPersonalizationView();
|
|
580
|
+
renderVaultConfiguredChips();
|
|
581
|
+
renderMcpView();
|
|
582
|
+
renderHooksView();
|
|
583
|
+
renderPluginsView();
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
async function saveConfigurationSettings(): Promise<void> {
|
|
587
|
+
if (dom.settingsConfigStatus) dom.settingsConfigStatus.textContent = 'Saving configuration...';
|
|
588
|
+
const payload = {
|
|
589
|
+
defaultPermissionPreset: dom.settingsPermSelect?.value,
|
|
590
|
+
osSandbox: dom.settingsOsSandboxSelect?.value,
|
|
591
|
+
reasoningEffort: dom.settingsEffortSelect?.value ?? '',
|
|
592
|
+
tokenBudget: {
|
|
593
|
+
enabled: Boolean(dom.settingsBudgetEnabled?.checked),
|
|
594
|
+
hardStop: Boolean(dom.settingsBudgetHardstop?.checked),
|
|
595
|
+
maxTokensPerTask: Number(dom.settingsBudgetTask?.value || 150000),
|
|
596
|
+
maxTokensPerDay: Number(dom.settingsBudgetDay?.value || 1000000),
|
|
597
|
+
maxCostUsd: Number(dom.settingsBudgetCost?.value || 5)
|
|
598
|
+
},
|
|
599
|
+
autoCompact: {
|
|
600
|
+
enabled: Boolean(dom.settingsAutoCompactEnabled?.checked),
|
|
601
|
+
thresholdPercent: Number(dom.settingsCompactPct?.value || 78)
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
const res = await fetch(apiUrl('/api/settings/configuration'), {
|
|
605
|
+
method: 'POST',
|
|
606
|
+
headers: authHeaders({ 'Content-Type': 'application/json' }),
|
|
607
|
+
body: JSON.stringify(payload)
|
|
608
|
+
}).catch(() => null);
|
|
609
|
+
if (!res || !res.ok) {
|
|
610
|
+
const err = await res?.json().catch(() => ({ error: 'Could not save configuration.' })) as { error?: string } | null;
|
|
611
|
+
if (dom.settingsConfigStatus) dom.settingsConfigStatus.textContent = err?.error || 'Could not save configuration.';
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
const updated = await res.json().catch(() => null) as SettingsOverviewPayload | null;
|
|
615
|
+
if (updated) {
|
|
616
|
+
overviewData = updated;
|
|
617
|
+
renderConfigurationView();
|
|
618
|
+
}
|
|
619
|
+
if (dom.settingsConfigStatus) dom.settingsConfigStatus.textContent = 'Configuration saved.';
|
|
620
|
+
void callbacks.loadHealth();
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
async function savePersonalizationText(): Promise<void> {
|
|
624
|
+
if (!dom.personalizationInstructionsInput) return;
|
|
625
|
+
const content = dom.personalizationInstructionsInput.value;
|
|
626
|
+
if (dom.personalizationStatusMsg) dom.personalizationStatusMsg.textContent = 'Saving...';
|
|
627
|
+
const res = await fetch(apiUrl('/api/settings/personalization'), {
|
|
628
|
+
method: 'POST',
|
|
629
|
+
headers: authHeaders({ 'Content-Type': 'application/json' }),
|
|
630
|
+
body: JSON.stringify({ scope: activeScope, instructions: content })
|
|
631
|
+
}).catch(() => null);
|
|
632
|
+
if (!res || !res.ok) {
|
|
633
|
+
const err = await res?.json().catch(() => ({ error: 'Could not save personalization.' })) as { error?: string } | null;
|
|
634
|
+
if (dom.personalizationStatusMsg) dom.personalizationStatusMsg.textContent = err?.error || 'Could not save personalization.';
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
const data = await res.json().catch(() => null) as { personalization?: PersonalizationPayload } | null;
|
|
638
|
+
if (data?.personalization && overviewData) {
|
|
639
|
+
overviewData.personalization = data.personalization;
|
|
640
|
+
savedInstructions[activeScope] = data.personalization[activeScope].content;
|
|
641
|
+
draftInstructions[activeScope] = data.personalization[activeScope].content;
|
|
642
|
+
renderPersonalizationView();
|
|
643
|
+
}
|
|
644
|
+
if (dom.personalizationStatusMsg) {
|
|
645
|
+
dom.personalizationStatusMsg.textContent = activeScope === 'project'
|
|
646
|
+
? 'Saved to .causyne/personalization.md — active immediately for this project.'
|
|
647
|
+
: 'Saved to ~/.causyne/CAUSYNE.md — active across all projects.';
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
async function saveMemoryTogglePatch(patch: { memoryEnabled?: boolean; allowToolAssisted?: boolean }): Promise<void> {
|
|
652
|
+
if (dom.personalizationMemoryStatus) dom.personalizationMemoryStatus.textContent = 'Updating memory preference...';
|
|
653
|
+
const res = await fetch(apiUrl('/api/settings/personalization'), {
|
|
654
|
+
method: 'POST',
|
|
655
|
+
headers: authHeaders({ 'Content-Type': 'application/json' }),
|
|
656
|
+
body: JSON.stringify({ scope: activeScope, ...patch })
|
|
657
|
+
}).catch(() => null);
|
|
658
|
+
if (!res || !res.ok) {
|
|
659
|
+
if (dom.personalizationMemoryStatus) dom.personalizationMemoryStatus.textContent = 'Could not update memory setting.';
|
|
660
|
+
void loadSettingsOverview();
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
const data = await res.json().catch(() => null) as { personalization?: PersonalizationPayload } | null;
|
|
664
|
+
if (data?.personalization && overviewData) {
|
|
665
|
+
overviewData.personalization = data.personalization;
|
|
666
|
+
renderPersonalizationView();
|
|
667
|
+
}
|
|
668
|
+
if (dom.personalizationMemoryStatus) {
|
|
669
|
+
dom.personalizationMemoryStatus.textContent = activeScope === 'project'
|
|
670
|
+
? 'Project memory settings updated.'
|
|
671
|
+
: 'Global memory defaults updated.';
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
async function confirmDeleteMemories(): Promise<void> {
|
|
676
|
+
const deleteScope = activeScope === 'global' ? 'all' : 'project';
|
|
677
|
+
if (dom.personalizationMemoryStatus) dom.personalizationMemoryStatus.textContent = 'Deleting memories...';
|
|
678
|
+
const res = await fetch(apiUrl('/api/settings/memories/delete'), {
|
|
679
|
+
method: 'POST',
|
|
680
|
+
headers: authHeaders({ 'Content-Type': 'application/json' }),
|
|
681
|
+
body: JSON.stringify({ scope: deleteScope })
|
|
682
|
+
}).catch(() => null);
|
|
683
|
+
syncDeleteConfirmVisibility(false);
|
|
684
|
+
if (!res || !res.ok) {
|
|
685
|
+
if (dom.personalizationMemoryStatus) dom.personalizationMemoryStatus.textContent = 'Could not delete memories.';
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
const data = await res.json().catch(() => null) as {
|
|
689
|
+
factsRemoved?: number;
|
|
690
|
+
observationsRemoved?: number;
|
|
691
|
+
summariesRemoved?: number;
|
|
692
|
+
personalization?: PersonalizationPayload;
|
|
693
|
+
} | null;
|
|
694
|
+
if (data?.personalization && overviewData) {
|
|
695
|
+
overviewData.personalization = data.personalization;
|
|
696
|
+
renderPersonalizationView();
|
|
697
|
+
}
|
|
698
|
+
if (dom.personalizationMemoryStatus) {
|
|
699
|
+
const f = data?.factsRemoved ?? 0;
|
|
700
|
+
const o = data?.observationsRemoved ?? 0;
|
|
701
|
+
const s = data?.summariesRemoved ?? 0;
|
|
702
|
+
dom.personalizationMemoryStatus.textContent =
|
|
703
|
+
`Deleted ${f} fact${f === 1 ? '' : 's'}, ${o} observation${o === 1 ? '' : 's'}, and ${s} summar${s === 1 ? 'y' : 'ies'}.`;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
async function toggleHookEnabled(index: number, enabled: boolean, inputEl: HTMLInputElement): Promise<void> {
|
|
708
|
+
if (dom.settingsHooksStatus) dom.settingsHooksStatus.textContent = 'Updating hook...';
|
|
709
|
+
const res = await fetch(apiUrl('/api/settings/hooks/toggle'), {
|
|
710
|
+
method: 'POST',
|
|
711
|
+
headers: authHeaders({ 'Content-Type': 'application/json' }),
|
|
712
|
+
body: JSON.stringify({ index, enabled })
|
|
713
|
+
}).catch(() => null);
|
|
714
|
+
if (!res || !res.ok) {
|
|
715
|
+
inputEl.checked = !enabled;
|
|
716
|
+
if (dom.settingsHooksStatus) dom.settingsHooksStatus.textContent = 'Could not update hook state.';
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
const data = await res.json().catch(() => null) as { hooks?: HookOverviewItem[] } | null;
|
|
720
|
+
if (data?.hooks && overviewData) {
|
|
721
|
+
overviewData.hooks = data.hooks;
|
|
722
|
+
renderHooksView();
|
|
723
|
+
}
|
|
724
|
+
if (dom.settingsHooksStatus) dom.settingsHooksStatus.textContent = enabled ? 'Hook enabled.' : 'Hook disabled.';
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
async function togglePluginEnabled(name: string, enabled: boolean, inputEl: HTMLInputElement): Promise<void> {
|
|
728
|
+
if (dom.settingsPluginsStatus) dom.settingsPluginsStatus.textContent = `${enabled ? 'Enabling' : 'Disabling'} ${name}...`;
|
|
729
|
+
const res = await fetch(apiUrl('/api/settings/plugins/toggle'), {
|
|
730
|
+
method: 'POST',
|
|
731
|
+
headers: authHeaders({ 'Content-Type': 'application/json' }),
|
|
732
|
+
body: JSON.stringify({ name, enabled })
|
|
733
|
+
}).catch(() => null);
|
|
734
|
+
if (!res || !res.ok) {
|
|
735
|
+
inputEl.checked = !enabled;
|
|
736
|
+
if (dom.settingsPluginsStatus) dom.settingsPluginsStatus.textContent = `Could not update plugin ${name}.`;
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
const data = await res.json().catch(() => null) as { plugins?: { root?: string; items?: PluginOverviewItem[] } } | null;
|
|
740
|
+
if (data?.plugins && overviewData) {
|
|
741
|
+
overviewData.plugins = data.plugins;
|
|
742
|
+
renderPluginsView();
|
|
743
|
+
}
|
|
744
|
+
if (dom.settingsPluginsStatus) dom.settingsPluginsStatus.textContent = enabled ? `Enabled ${name}.` : `Disabled ${name}.`;
|
|
745
|
+
}
|
|
746
|
+
|
|
30
747
|
export async function loadDoctorReport(): Promise<void> {
|
|
31
748
|
dom.doctorPre.textContent = 'Loading redacted diagnostics...';
|
|
32
749
|
const res = await fetch(apiUrl('/api/doctor/report'), { headers: authHeaders() });
|
|
@@ -81,7 +798,7 @@ export async function loadLicenseStatus(forceLive: boolean): Promise<void> {
|
|
|
81
798
|
async function startLicenseCheckout(): Promise<void> {
|
|
82
799
|
if (!dom.licensePlanSelect || !dom.licenseStatusMsg) return;
|
|
83
800
|
const plan = dom.licensePlanSelect.value || 'monthly';
|
|
84
|
-
dom.licenseStatusMsg.textContent = 'Opening secure
|
|
801
|
+
dom.licenseStatusMsg.textContent = 'Opening secure checkout...';
|
|
85
802
|
const res = await fetch(apiUrl('/api/license/checkout'), {
|
|
86
803
|
method: 'POST',
|
|
87
804
|
headers: authHeaders({ 'Content-Type': 'application/json' }),
|
|
@@ -94,7 +811,7 @@ async function startLicenseCheckout(): Promise<void> {
|
|
|
94
811
|
return;
|
|
95
812
|
}
|
|
96
813
|
window.open(data.url, '_blank', 'noopener,noreferrer');
|
|
97
|
-
dom.licenseStatusMsg.textContent = '
|
|
814
|
+
dom.licenseStatusMsg.textContent = 'Checkout opened in a new tab. Click Refresh after payment completes.';
|
|
98
815
|
}
|
|
99
816
|
|
|
100
817
|
async function claimLicenseRecovery(): Promise<void> {
|
|
@@ -117,7 +834,7 @@ async function claimLicenseRecovery(): Promise<void> {
|
|
|
117
834
|
|
|
118
835
|
async function openBillingPortal(): Promise<void> {
|
|
119
836
|
if (!dom.licenseStatusMsg) return;
|
|
120
|
-
dom.licenseStatusMsg.textContent = 'Opening
|
|
837
|
+
dom.licenseStatusMsg.textContent = 'Opening billing portal...';
|
|
121
838
|
const res = await fetch(apiUrl('/api/license/portal'), {
|
|
122
839
|
method: 'POST',
|
|
123
840
|
headers: authHeaders({ 'Content-Type': 'application/json' }),
|
|
@@ -130,7 +847,7 @@ async function openBillingPortal(): Promise<void> {
|
|
|
130
847
|
return;
|
|
131
848
|
}
|
|
132
849
|
window.open(data.url, '_blank', 'noopener,noreferrer');
|
|
133
|
-
dom.licenseStatusMsg.textContent = '
|
|
850
|
+
dom.licenseStatusMsg.textContent = 'Billing portal opened in a new tab.';
|
|
134
851
|
}
|
|
135
852
|
|
|
136
853
|
async function saveVaultApiKey(): Promise<void> {
|
|
@@ -149,24 +866,90 @@ async function saveVaultApiKey(): Promise<void> {
|
|
|
149
866
|
dom.vaultStatusEl.textContent = `Saved for ${data.provider || provider}.`;
|
|
150
867
|
void callbacks.loadHealth();
|
|
151
868
|
void callbacks.loadModels();
|
|
869
|
+
void loadSettingsOverview();
|
|
152
870
|
}
|
|
153
871
|
|
|
154
|
-
export function openSettingsModal(): void {
|
|
872
|
+
export function openSettingsModal(initialSection?: SettingsSectionId): void {
|
|
155
873
|
dom.settingsModal.classList.add('open');
|
|
874
|
+
if (initialSection) {
|
|
875
|
+
selectSettingsSection(initialSection);
|
|
876
|
+
} else {
|
|
877
|
+
selectSettingsSection(activeSection);
|
|
878
|
+
}
|
|
879
|
+
void loadSettingsOverview();
|
|
156
880
|
void loadLicenseStatus(false);
|
|
157
|
-
void loadDoctorReport();
|
|
158
881
|
}
|
|
159
882
|
|
|
160
883
|
export function bindSettingsModalEvents(): void {
|
|
161
|
-
dom.navSettingsBtn.addEventListener('click', openSettingsModal);
|
|
884
|
+
dom.navSettingsBtn.addEventListener('click', () => openSettingsModal());
|
|
162
885
|
dom.settingsCloseBtn.addEventListener('click', () => dom.settingsModal.classList.remove('open'));
|
|
163
886
|
dom.settingsModal.addEventListener('click', (e) => {
|
|
164
887
|
if (e.target === dom.settingsModal) dom.settingsModal.classList.remove('open');
|
|
165
888
|
});
|
|
889
|
+
|
|
890
|
+
const navButtons = dom.settingsModal.querySelectorAll<HTMLButtonElement>('[data-settings-section]');
|
|
891
|
+
navButtons.forEach((btn) => {
|
|
892
|
+
btn.addEventListener('click', () => {
|
|
893
|
+
const target = btn.dataset.settingsSection as SettingsSectionId | undefined;
|
|
894
|
+
if (target && Object.prototype.hasOwnProperty.call(SECTION_LABELS, target)) {
|
|
895
|
+
selectSettingsSection(target);
|
|
896
|
+
}
|
|
897
|
+
});
|
|
898
|
+
});
|
|
899
|
+
|
|
166
900
|
dom.themeToggleBtn.addEventListener('click', () => {
|
|
167
901
|
const cur = document.documentElement.getAttribute('data-theme') || 'dark';
|
|
168
902
|
applyTheme(cur === 'light' ? 'dark' : 'light');
|
|
169
903
|
});
|
|
904
|
+
dom.settingsCompactToggle?.addEventListener('change', () => {
|
|
905
|
+
applyDensity(dom.settingsCompactToggle?.checked ? 'compact' : 'comfortable');
|
|
906
|
+
});
|
|
907
|
+
dom.settingsAutoScrollToggle?.addEventListener('change', () => {
|
|
908
|
+
applyAutoScrollPref(Boolean(dom.settingsAutoScrollToggle?.checked));
|
|
909
|
+
});
|
|
910
|
+
|
|
911
|
+
dom.settingsConfigSaveBtn?.addEventListener('click', () => { void saveConfigurationSettings(); });
|
|
912
|
+
|
|
913
|
+
dom.personalizationScopeProjectBtn?.addEventListener('click', () => {
|
|
914
|
+
activeScope = 'project';
|
|
915
|
+
if (dom.personalizationStatusMsg) dom.personalizationStatusMsg.textContent = '';
|
|
916
|
+
if (dom.personalizationMemoryStatus) dom.personalizationMemoryStatus.textContent = '';
|
|
917
|
+
renderPersonalizationView();
|
|
918
|
+
});
|
|
919
|
+
dom.personalizationScopeGlobalBtn?.addEventListener('click', () => {
|
|
920
|
+
activeScope = 'global';
|
|
921
|
+
if (dom.personalizationStatusMsg) dom.personalizationStatusMsg.textContent = '';
|
|
922
|
+
if (dom.personalizationMemoryStatus) dom.personalizationMemoryStatus.textContent = '';
|
|
923
|
+
renderPersonalizationView();
|
|
924
|
+
});
|
|
925
|
+
dom.personalizationInstructionsInput?.addEventListener('input', () => {
|
|
926
|
+
updatePersonalizationSaveState();
|
|
927
|
+
});
|
|
928
|
+
dom.personalizationInstructionsInput?.addEventListener('keydown', (e) => {
|
|
929
|
+
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 's') {
|
|
930
|
+
e.preventDefault();
|
|
931
|
+
if (!dom.personalizationSaveBtn?.disabled) void savePersonalizationText();
|
|
932
|
+
}
|
|
933
|
+
});
|
|
934
|
+
dom.personalizationSaveBtn?.addEventListener('click', () => { void savePersonalizationText(); });
|
|
935
|
+
|
|
936
|
+
dom.personalizationMemoryEnabled?.addEventListener('change', () => {
|
|
937
|
+
void saveMemoryTogglePatch({ memoryEnabled: Boolean(dom.personalizationMemoryEnabled?.checked) });
|
|
938
|
+
});
|
|
939
|
+
dom.personalizationMemoryToolAssisted?.addEventListener('change', () => {
|
|
940
|
+
void saveMemoryTogglePatch({ allowToolAssisted: Boolean(dom.personalizationMemoryToolAssisted?.checked) });
|
|
941
|
+
});
|
|
942
|
+
dom.personalizationMemoryDeleteBtn?.addEventListener('click', () => {
|
|
943
|
+
syncDeleteConfirmVisibility(true);
|
|
944
|
+
});
|
|
945
|
+
dom.personalizationMemoryCancelBtn?.addEventListener('click', () => {
|
|
946
|
+
syncDeleteConfirmVisibility(false);
|
|
947
|
+
});
|
|
948
|
+
dom.personalizationMemoryConfirmBtn?.addEventListener('click', () => {
|
|
949
|
+
void confirmDeleteMemories();
|
|
950
|
+
});
|
|
951
|
+
|
|
952
|
+
dom.settingsMcpRefreshBtn?.addEventListener('click', () => { void loadSettingsOverview(); });
|
|
170
953
|
dom.doctorLoadBtn.addEventListener('click', () => { void loadDoctorReport(); });
|
|
171
954
|
dom.vaultSaveBtn.addEventListener('click', () => { void saveVaultApiKey(); });
|
|
172
955
|
if (dom.licenseUpgradeBtn) dom.licenseUpgradeBtn.addEventListener('click', () => { void startLicenseCheckout(); });
|