@causyne/agent 1.20.124 → 1.20.127
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/package.json +4 -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 +83 -27
- package/src/agentLoop.ts +92 -26
- package/src/approvalPolicy.js +34 -10
- package/src/approvalPolicy.ts +42 -11
- package/src/browser/causyneBrowser.js +30 -3
- package/src/browser/causyneBrowser.ts +33 -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 +188 -32
- package/src/commands.ts +209 -32
- 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/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/providers/antigravity.js +62 -9
- package/src/providers/antigravity.ts +73 -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/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/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 +1096 -0
- package/src/tools/ptyTerminal.ts +1231 -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 +702 -0
- package/src/web/client/browserPanel.ts +663 -0
- package/src/web/client/chatStream.js +309 -0
- package/src/web/client/chatStream.ts +289 -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 +220 -0
- package/src/web/client/dom.ts +221 -0
- package/src/web/client/filesAndCanvas.js +231 -0
- package/src/web/client/filesAndCanvas.ts +238 -0
- package/src/web/client/gameLauncherUi.js +78 -0
- package/src/web/client/gameLauncherUi.ts +78 -0
- package/src/web/client/main.js +301 -0
- package/src/web/client/main.ts +368 -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 +191 -0
- package/src/web/client/settingsModal.ts +176 -0
- package/src/web/client/state.js +250 -0
- package/src/web/client/state.ts +233 -0
- package/src/web/client/streamSmoother.js +127 -0
- package/src/web/client/streamSmoother.ts +119 -0
- package/src/web/client/studioLayout.js +54 -0
- package/src/web/client/studioLayout.ts +60 -0
- package/src/web/client/studioShell.js +327 -0
- package/src/web/client/studioShell.ts +340 -0
- package/src/web/client/studioStart.js +77 -0
- package/src/web/client/studioStart.ts +89 -0
- package/src/web/client/terminalPanel.js +357 -0
- package/src/web/client/terminalPanel.ts +345 -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 +319 -0
- package/src/web/client/validators.js +106 -0
- package/src/web/client/validators.ts +96 -0
- package/src/web/server/activeRuns.js +152 -0
- package/src/web/server/activeRuns.ts +171 -0
- package/src/web/server/routesBrowser.js +355 -0
- package/src/web/server/routesBrowser.ts +386 -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/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 +80 -0
- package/src/web/server/staticAssets.ts +91 -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 +76 -2449
- package/src/web/skybridgeServer.ts +118 -2600
- package/src/web/skybridgeUi.js +16 -450
- package/src/web/skybridgeUi.ts +16 -454
- package/src/web/styles/agent.css +380 -0
- package/src/web/styles/composer.css +193 -0
- package/src/web/styles/overlays.css +436 -0
- package/src/web/styles/shell.css +387 -0
- package/src/web/styles/studio.css +723 -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 +139 -0
- package/src/web/ui/modalsTemplate.ts +139 -0
- package/src/web/ui/sidebarTemplate.js +63 -0
- package/src/web/ui/sidebarTemplate.ts +64 -0
- package/src/web/ui/studioTemplate.js +258 -0
- package/src/web/ui/studioTemplate.ts +258 -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,209 @@
|
|
|
1
|
+
import { dom } from './dom.js';
|
|
2
|
+
import { apiUrl, authHeaders, state, updateComposerMetrics } from './state.js';
|
|
3
|
+
import type { WorkspaceEntry } from './types.js';
|
|
4
|
+
|
|
5
|
+
export interface ComposerCallbacks {
|
|
6
|
+
submitPrompt(promptText: string, attachList: string[]): Promise<void>;
|
|
7
|
+
stopActiveRun(): Promise<void>;
|
|
8
|
+
runCliCommand(rawInput: string, target: 'studio' | 'chat'): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let callbacks: ComposerCallbacks = {
|
|
12
|
+
submitPrompt: async () => {},
|
|
13
|
+
stopActiveRun: async () => {},
|
|
14
|
+
runCliCommand: async () => {}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function configureComposerCallbacks(cbs: ComposerCallbacks): void {
|
|
18
|
+
callbacks = cbs;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function renderAttachmentChips(): void {
|
|
22
|
+
dom.composerChipsEl.textContent = '';
|
|
23
|
+
dom.composerChipsEl.classList.toggle('has-items', state.attachments.length > 0);
|
|
24
|
+
for (const rel of state.attachments) {
|
|
25
|
+
const chip = document.createElement('span');
|
|
26
|
+
chip.className = 'chip';
|
|
27
|
+
const label = document.createElement('span');
|
|
28
|
+
label.textContent = `@${rel}`;
|
|
29
|
+
const rm = document.createElement('button');
|
|
30
|
+
rm.type = 'button';
|
|
31
|
+
rm.textContent = 'x';
|
|
32
|
+
rm.setAttribute('aria-label', `Remove ${rel}`);
|
|
33
|
+
rm.addEventListener('click', () => {
|
|
34
|
+
state.attachments = state.attachments.filter((item) => item !== rel);
|
|
35
|
+
renderAttachmentChips();
|
|
36
|
+
});
|
|
37
|
+
chip.appendChild(label);
|
|
38
|
+
chip.appendChild(rm);
|
|
39
|
+
dom.composerChipsEl.appendChild(chip);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function attachWorkspaceFile(relPath: string): void {
|
|
44
|
+
if (!relPath || state.attachments.includes(relPath) || state.attachments.length >= 6) return;
|
|
45
|
+
state.attachments.push(relPath);
|
|
46
|
+
renderAttachmentChips();
|
|
47
|
+
dom.promptInput.focus();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function applySlashChoice(cmdName: string): void {
|
|
51
|
+
dom.promptInput.value = `/${cmdName} `;
|
|
52
|
+
state.mentionItems = [];
|
|
53
|
+
state.mentionStart = -1;
|
|
54
|
+
dom.mentionPopover.classList.remove('open');
|
|
55
|
+
updateComposerMetrics();
|
|
56
|
+
dom.promptInput.focus();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function applyMentionChoice(relPath: string): void {
|
|
60
|
+
const pos = dom.promptInput.selectionStart || dom.promptInput.value.length;
|
|
61
|
+
if (state.mentionStart >= 0 && pos >= state.mentionStart) {
|
|
62
|
+
dom.promptInput.value = dom.promptInput.value.slice(0, state.mentionStart) + dom.promptInput.value.slice(pos);
|
|
63
|
+
}
|
|
64
|
+
attachWorkspaceFile(relPath);
|
|
65
|
+
state.mentionItems = [];
|
|
66
|
+
state.mentionStart = -1;
|
|
67
|
+
dom.mentionPopover.classList.remove('open');
|
|
68
|
+
updateComposerMetrics();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function renderMentionList(): void {
|
|
72
|
+
dom.mentionPopover.textContent = '';
|
|
73
|
+
if (state.mentionItems.length === 0) {
|
|
74
|
+
dom.mentionPopover.classList.remove('open');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
dom.mentionPopover.classList.add('open');
|
|
78
|
+
state.mentionItems.forEach((item, idx) => {
|
|
79
|
+
const btn = document.createElement('button');
|
|
80
|
+
btn.type = 'button';
|
|
81
|
+
btn.className = `mention-item${idx === state.mentionIndex ? ' selected' : ''}`;
|
|
82
|
+
if (state.mentionMode === 'command') {
|
|
83
|
+
const cmdName = item.name || '';
|
|
84
|
+
btn.textContent = `/${cmdName}${item.description ? ` — ${item.description.slice(0, 62)}` : ''}`;
|
|
85
|
+
btn.addEventListener('click', () => applySlashChoice(cmdName));
|
|
86
|
+
} else {
|
|
87
|
+
const filePath = item.path || '';
|
|
88
|
+
btn.textContent = `@${filePath}`;
|
|
89
|
+
btn.addEventListener('click', () => applyMentionChoice(filePath));
|
|
90
|
+
}
|
|
91
|
+
dom.mentionPopover.appendChild(btn);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function checkAtMention(): Promise<void> {
|
|
96
|
+
const val = dom.promptInput.value || '';
|
|
97
|
+
const trimmedLeft = val.trimStart();
|
|
98
|
+
if (trimmedLeft.startsWith('/') && !trimmedLeft.includes(' ') && state.cliCommands.length > 0) {
|
|
99
|
+
const q = trimmedLeft.slice(1).toLowerCase();
|
|
100
|
+
state.mentionMode = 'command';
|
|
101
|
+
const prefixHits = state.cliCommands.filter((c) => c.name.toLowerCase().startsWith(q));
|
|
102
|
+
const nameHits = state.cliCommands.filter((c) => {
|
|
103
|
+
const n = c.name.toLowerCase();
|
|
104
|
+
return !n.startsWith(q) && n.includes(q);
|
|
105
|
+
});
|
|
106
|
+
const descHits = state.cliCommands.filter((c) => {
|
|
107
|
+
const n = c.name.toLowerCase();
|
|
108
|
+
return !n.includes(q) && (c.description || '').toLowerCase().includes(q);
|
|
109
|
+
});
|
|
110
|
+
state.mentionItems = prefixHits.concat(nameHits, descHits).slice(0, 10);
|
|
111
|
+
state.mentionIndex = 0;
|
|
112
|
+
renderMentionList();
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const pos = dom.promptInput.selectionStart || val.length;
|
|
116
|
+
const before = val.slice(0, pos);
|
|
117
|
+
const atIdx = before.lastIndexOf('@');
|
|
118
|
+
if (atIdx < 0 || (atIdx > 0 && !/\s/.test(before[atIdx - 1] || ''))) {
|
|
119
|
+
state.mentionItems = [];
|
|
120
|
+
state.mentionStart = -1;
|
|
121
|
+
dom.mentionPopover.classList.remove('open');
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const query = before.slice(atIdx + 1);
|
|
125
|
+
if (/\s/.test(query)) { dom.mentionPopover.classList.remove('open'); return; }
|
|
126
|
+
state.mentionMode = 'file';
|
|
127
|
+
state.mentionStart = atIdx;
|
|
128
|
+
const res = await fetch(apiUrl(`/api/files?q=${encodeURIComponent(query)}`), { headers: authHeaders() }).catch(() => null);
|
|
129
|
+
if (!res || !res.ok) return;
|
|
130
|
+
const data = await res.json() as { entries?: WorkspaceEntry[] };
|
|
131
|
+
state.mentionItems = (data.entries || []).filter((x) => x.type === 'file').slice(0, 8);
|
|
132
|
+
state.mentionIndex = 0;
|
|
133
|
+
renderMentionList();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function bindComposerEvents(): void {
|
|
137
|
+
dom.composerPill.addEventListener('click', (e) => {
|
|
138
|
+
if (e.target === dom.composerPill) dom.promptInput.focus();
|
|
139
|
+
});
|
|
140
|
+
dom.promptInput.addEventListener('compositionstart', () => { state.isComposing = true; });
|
|
141
|
+
dom.promptInput.addEventListener('compositionend', () => { state.isComposing = false; });
|
|
142
|
+
dom.promptInput.addEventListener('input', () => {
|
|
143
|
+
updateComposerMetrics();
|
|
144
|
+
void checkAtMention();
|
|
145
|
+
});
|
|
146
|
+
dom.promptInput.addEventListener('keydown', (e) => {
|
|
147
|
+
if (dom.mentionPopover.classList.contains('open') && state.mentionItems.length > 0) {
|
|
148
|
+
if (e.key === 'ArrowDown') {
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
state.mentionIndex = (state.mentionIndex + 1) % state.mentionItems.length;
|
|
151
|
+
renderMentionList();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (e.key === 'ArrowUp') {
|
|
155
|
+
e.preventDefault();
|
|
156
|
+
state.mentionIndex = (state.mentionIndex - 1 + state.mentionItems.length) % state.mentionItems.length;
|
|
157
|
+
renderMentionList();
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (e.key === 'Enter' || e.key === 'Tab') {
|
|
161
|
+
e.preventDefault();
|
|
162
|
+
const chosen = state.mentionItems[state.mentionIndex];
|
|
163
|
+
if (chosen) {
|
|
164
|
+
if (state.mentionMode === 'command' && chosen.name) applySlashChoice(chosen.name);
|
|
165
|
+
else if (chosen.path) applyMentionChoice(chosen.path);
|
|
166
|
+
}
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (e.key === 'Escape') {
|
|
170
|
+
e.preventDefault();
|
|
171
|
+
dom.mentionPopover.classList.remove('open');
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (e.key === 'Enter' && !e.shiftKey && !e.isComposing && !state.isComposing) {
|
|
176
|
+
e.preventDefault();
|
|
177
|
+
dom.chatForm.requestSubmit();
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
dom.chatForm.addEventListener('submit', (e) => {
|
|
182
|
+
e.preventDefault();
|
|
183
|
+
if (state.activeController) { void callbacks.stopActiveRun(); return; }
|
|
184
|
+
const text = (dom.promptInput.value || '').trim();
|
|
185
|
+
if (!text) return;
|
|
186
|
+
const toAttach = state.attachments.slice();
|
|
187
|
+
dom.promptInput.value = '';
|
|
188
|
+
state.attachments = [];
|
|
189
|
+
renderAttachmentChips();
|
|
190
|
+
updateComposerMetrics();
|
|
191
|
+
if (text.startsWith('/') && /^\/[a-z?][a-z0-9_-]*/i.test(text)) {
|
|
192
|
+
void callbacks.runCliCommand(text, 'chat');
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
void callbacks.submitPrompt(text, toAttach);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
dom.sendBtn.addEventListener('click', (e) => {
|
|
199
|
+
if (state.activeController) {
|
|
200
|
+
e.preventDefault();
|
|
201
|
+
void callbacks.stopActiveRun();
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
dom.heroHelpBtn.addEventListener('click', () => {
|
|
205
|
+
dom.promptInput.value = 'Inspect this local workspace and summarize its architecture and next steps.';
|
|
206
|
+
updateComposerMetrics();
|
|
207
|
+
dom.promptInput.focus();
|
|
208
|
+
});
|
|
209
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { dom } from './dom.js';
|
|
2
|
+
import { apiUrl, authHeaders, state } from './state.js';
|
|
3
|
+
let callbacks = {
|
|
4
|
+
openFile: async () => { },
|
|
5
|
+
saveCurrentSessionWorkspace: () => { }
|
|
6
|
+
};
|
|
7
|
+
export function configureDiffPanelCallbacks(cbs) {
|
|
8
|
+
callbacks = cbs;
|
|
9
|
+
}
|
|
10
|
+
export function syncDiffControlsUi() {
|
|
11
|
+
const isSessionScope = state.diffScope === 'session' && Boolean(state.sessionId);
|
|
12
|
+
if (dom.diffScopeSessionBtn) {
|
|
13
|
+
dom.diffScopeSessionBtn.classList.toggle('active', isSessionScope);
|
|
14
|
+
dom.diffScopeSessionBtn.disabled = !state.sessionId;
|
|
15
|
+
}
|
|
16
|
+
if (dom.diffScopeWorkspaceBtn) {
|
|
17
|
+
dom.diffScopeWorkspaceBtn.classList.toggle('active', !isSessionScope);
|
|
18
|
+
}
|
|
19
|
+
if (dom.diffStagedToggle) {
|
|
20
|
+
dom.diffStagedToggle.style.display = isSessionScope ? 'none' : 'inline-block';
|
|
21
|
+
dom.diffStagedToggle.textContent = state.diffStaged ? 'Staged' : 'Working';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export async function loadDiff() {
|
|
25
|
+
const seq = state.sessionSwitchSeq;
|
|
26
|
+
const scope = state.diffScope === 'session' && state.sessionId ? 'session' : 'workspace';
|
|
27
|
+
syncDiffControlsUi();
|
|
28
|
+
const params = new URLSearchParams();
|
|
29
|
+
params.set('scope', scope);
|
|
30
|
+
if (state.sessionId)
|
|
31
|
+
params.set('sessionId', state.sessionId);
|
|
32
|
+
if (scope === 'workspace' && state.diffStaged)
|
|
33
|
+
params.set('staged', '1');
|
|
34
|
+
const res = await fetch(apiUrl(`/api/diff?${params.toString()}`), { headers: authHeaders() }).catch(() => null);
|
|
35
|
+
if (!res || !res.ok || seq !== state.sessionSwitchSeq)
|
|
36
|
+
return;
|
|
37
|
+
const data = await res.json().catch(() => null);
|
|
38
|
+
if (!data || seq !== state.sessionSwitchSeq)
|
|
39
|
+
return;
|
|
40
|
+
dom.diffListEl.textContent = '';
|
|
41
|
+
const wsCount = Number(data.workspaceFileCount || 0);
|
|
42
|
+
const sessCount = Number(data.sessionFileCount || 0);
|
|
43
|
+
if (dom.diffScopeSessionBtn) {
|
|
44
|
+
dom.diffScopeSessionBtn.textContent = state.sessionId ? `This chat (${sessCount})` : 'This chat';
|
|
45
|
+
}
|
|
46
|
+
if (dom.diffScopeWorkspaceBtn) {
|
|
47
|
+
dom.diffScopeWorkspaceBtn.textContent = `Workspace (${wsCount})`;
|
|
48
|
+
}
|
|
49
|
+
if (!data.isGitRepo && scope === 'workspace') {
|
|
50
|
+
dom.diffSummaryEl.textContent = 'Not a Git repository.';
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const files = data.files || [];
|
|
54
|
+
const addTot = Number(data.totalAdditions || 0);
|
|
55
|
+
const delTot = Number(data.totalDeletions || 0);
|
|
56
|
+
dom.diffSummaryEl.textContent = (addTot || delTot)
|
|
57
|
+
? `+${addTot} / -${delTot}`
|
|
58
|
+
: (files.length > 0 ? `${files.length}${files.length === 1 ? ' file' : ' files'}` : '');
|
|
59
|
+
if (files.length === 0) {
|
|
60
|
+
const empty = document.createElement('div');
|
|
61
|
+
empty.className = 'diff-empty-box';
|
|
62
|
+
const activeSessObj = state.sessions.find((x) => x.id === state.sessionId);
|
|
63
|
+
const activeTitle = activeSessObj && activeSessObj.title
|
|
64
|
+
? `"${activeSessObj.title.slice(0, 48)}"`
|
|
65
|
+
: 'this conversation';
|
|
66
|
+
const msg = document.createElement('div');
|
|
67
|
+
msg.textContent = scope === 'session'
|
|
68
|
+
? `No file changes in ${activeTitle}.`
|
|
69
|
+
: (state.diffStaged ? 'No staged changes.' : 'Working tree clean.');
|
|
70
|
+
empty.appendChild(msg);
|
|
71
|
+
if (scope === 'session' && wsCount > 0) {
|
|
72
|
+
const switchBtn = document.createElement('button');
|
|
73
|
+
switchBtn.type = 'button';
|
|
74
|
+
switchBtn.className = 'btn-ghost';
|
|
75
|
+
switchBtn.textContent = `View workspace changes (${wsCount})`;
|
|
76
|
+
switchBtn.addEventListener('click', () => {
|
|
77
|
+
state.diffScope = 'workspace';
|
|
78
|
+
callbacks.saveCurrentSessionWorkspace();
|
|
79
|
+
syncDiffControlsUi();
|
|
80
|
+
void loadDiff();
|
|
81
|
+
});
|
|
82
|
+
empty.appendChild(switchBtn);
|
|
83
|
+
}
|
|
84
|
+
dom.diffListEl.appendChild(empty);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
for (const f of files) {
|
|
88
|
+
const card = document.createElement('details');
|
|
89
|
+
card.className = 'diff-file';
|
|
90
|
+
card.open = files.length <= 6;
|
|
91
|
+
const head = document.createElement('summary');
|
|
92
|
+
head.className = 'diff-file-head';
|
|
93
|
+
const p = document.createElement('span');
|
|
94
|
+
p.className = 'diff-file-path';
|
|
95
|
+
p.title = f.path;
|
|
96
|
+
const badgeChar = f.status && f.status[0] ? f.status[0].toUpperCase() : 'M';
|
|
97
|
+
p.textContent = `[${badgeChar}] ${f.path}`;
|
|
98
|
+
const right = document.createElement('span');
|
|
99
|
+
right.className = 'diff-file-right';
|
|
100
|
+
if (f.additions || f.deletions) {
|
|
101
|
+
const add = document.createElement('span');
|
|
102
|
+
add.className = 'diff-add';
|
|
103
|
+
add.textContent = `+${f.additions || 0}`;
|
|
104
|
+
const del = document.createElement('span');
|
|
105
|
+
del.className = 'diff-del';
|
|
106
|
+
del.textContent = `-${f.deletions || 0}`;
|
|
107
|
+
right.appendChild(add);
|
|
108
|
+
right.appendChild(del);
|
|
109
|
+
}
|
|
110
|
+
if (f.existsOnDisk !== false) {
|
|
111
|
+
const openBtn = document.createElement('button');
|
|
112
|
+
openBtn.type = 'button';
|
|
113
|
+
openBtn.className = 'diff-open-btn';
|
|
114
|
+
openBtn.textContent = 'Open';
|
|
115
|
+
openBtn.addEventListener('click', (e) => {
|
|
116
|
+
e.preventDefault();
|
|
117
|
+
e.stopPropagation();
|
|
118
|
+
void callbacks.openFile(f.path);
|
|
119
|
+
});
|
|
120
|
+
right.appendChild(openBtn);
|
|
121
|
+
}
|
|
122
|
+
head.appendChild(p);
|
|
123
|
+
head.appendChild(right);
|
|
124
|
+
card.appendChild(head);
|
|
125
|
+
if (Array.isArray(f.hunks) && f.hunks.length > 0) {
|
|
126
|
+
const pre = document.createElement('div');
|
|
127
|
+
pre.className = 'diff-lines';
|
|
128
|
+
for (const h of f.hunks) {
|
|
129
|
+
const hh = document.createElement('div');
|
|
130
|
+
hh.className = 'diff-line hunk';
|
|
131
|
+
hh.textContent = h.header;
|
|
132
|
+
pre.appendChild(hh);
|
|
133
|
+
for (const ln of h.lines || []) {
|
|
134
|
+
const row = document.createElement('div');
|
|
135
|
+
row.className = `diff-line${ln.startsWith('+') ? ' plus' : ln.startsWith('-') ? ' minus' : ''}`;
|
|
136
|
+
row.textContent = ln;
|
|
137
|
+
pre.appendChild(row);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
card.appendChild(pre);
|
|
141
|
+
}
|
|
142
|
+
else if (f.note) {
|
|
143
|
+
const note = document.createElement('div');
|
|
144
|
+
note.className = 'diff-note';
|
|
145
|
+
note.textContent = f.note;
|
|
146
|
+
card.appendChild(note);
|
|
147
|
+
}
|
|
148
|
+
dom.diffListEl.appendChild(card);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
export function bindDiffPanelEvents() {
|
|
152
|
+
if (dom.diffScopeSessionBtn) {
|
|
153
|
+
dom.diffScopeSessionBtn.addEventListener('click', () => {
|
|
154
|
+
if (!state.sessionId)
|
|
155
|
+
return;
|
|
156
|
+
state.diffScope = 'session';
|
|
157
|
+
callbacks.saveCurrentSessionWorkspace();
|
|
158
|
+
syncDiffControlsUi();
|
|
159
|
+
void loadDiff();
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
if (dom.diffScopeWorkspaceBtn) {
|
|
163
|
+
dom.diffScopeWorkspaceBtn.addEventListener('click', () => {
|
|
164
|
+
state.diffScope = 'workspace';
|
|
165
|
+
callbacks.saveCurrentSessionWorkspace();
|
|
166
|
+
syncDiffControlsUi();
|
|
167
|
+
void loadDiff();
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
dom.diffStagedToggle.addEventListener('click', () => {
|
|
171
|
+
state.diffStaged = !state.diffStaged;
|
|
172
|
+
syncDiffControlsUi();
|
|
173
|
+
void loadDiff();
|
|
174
|
+
});
|
|
175
|
+
dom.refreshDiffBtn.addEventListener('click', () => { void loadDiff(); });
|
|
176
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { dom } from './dom.js';
|
|
2
|
+
import { apiUrl, authHeaders, state } from './state.js';
|
|
3
|
+
|
|
4
|
+
interface DiffFilePayload {
|
|
5
|
+
path: string;
|
|
6
|
+
status?: string;
|
|
7
|
+
additions?: number;
|
|
8
|
+
deletions?: number;
|
|
9
|
+
existsOnDisk?: boolean;
|
|
10
|
+
note?: string;
|
|
11
|
+
hunks?: Array<{ header: string; lines?: string[] }>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface DiffResponsePayload {
|
|
15
|
+
isGitRepo?: boolean;
|
|
16
|
+
workspaceFileCount?: number;
|
|
17
|
+
sessionFileCount?: number;
|
|
18
|
+
totalAdditions?: number;
|
|
19
|
+
totalDeletions?: number;
|
|
20
|
+
files?: DiffFilePayload[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface DiffPanelCallbacks {
|
|
24
|
+
openFile(relPath: string): Promise<void>;
|
|
25
|
+
saveCurrentSessionWorkspace(): void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let callbacks: DiffPanelCallbacks = {
|
|
29
|
+
openFile: async () => {},
|
|
30
|
+
saveCurrentSessionWorkspace: () => {}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export function configureDiffPanelCallbacks(cbs: DiffPanelCallbacks): void {
|
|
34
|
+
callbacks = cbs;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function syncDiffControlsUi(): void {
|
|
38
|
+
const isSessionScope = state.diffScope === 'session' && Boolean(state.sessionId);
|
|
39
|
+
if (dom.diffScopeSessionBtn) {
|
|
40
|
+
dom.diffScopeSessionBtn.classList.toggle('active', isSessionScope);
|
|
41
|
+
dom.diffScopeSessionBtn.disabled = !state.sessionId;
|
|
42
|
+
}
|
|
43
|
+
if (dom.diffScopeWorkspaceBtn) {
|
|
44
|
+
dom.diffScopeWorkspaceBtn.classList.toggle('active', !isSessionScope);
|
|
45
|
+
}
|
|
46
|
+
if (dom.diffStagedToggle) {
|
|
47
|
+
dom.diffStagedToggle.style.display = isSessionScope ? 'none' : 'inline-block';
|
|
48
|
+
dom.diffStagedToggle.textContent = state.diffStaged ? 'Staged' : 'Working';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function loadDiff(): Promise<void> {
|
|
53
|
+
const seq = state.sessionSwitchSeq;
|
|
54
|
+
const scope: 'session' | 'workspace' = state.diffScope === 'session' && state.sessionId ? 'session' : 'workspace';
|
|
55
|
+
syncDiffControlsUi();
|
|
56
|
+
const params = new URLSearchParams();
|
|
57
|
+
params.set('scope', scope);
|
|
58
|
+
if (state.sessionId) params.set('sessionId', state.sessionId);
|
|
59
|
+
if (scope === 'workspace' && state.diffStaged) params.set('staged', '1');
|
|
60
|
+
const res = await fetch(apiUrl(`/api/diff?${params.toString()}`), { headers: authHeaders() }).catch(() => null);
|
|
61
|
+
if (!res || !res.ok || seq !== state.sessionSwitchSeq) return;
|
|
62
|
+
const data = await res.json().catch(() => null) as DiffResponsePayload | null;
|
|
63
|
+
if (!data || seq !== state.sessionSwitchSeq) return;
|
|
64
|
+
|
|
65
|
+
dom.diffListEl.textContent = '';
|
|
66
|
+
const wsCount = Number(data.workspaceFileCount || 0);
|
|
67
|
+
const sessCount = Number(data.sessionFileCount || 0);
|
|
68
|
+
if (dom.diffScopeSessionBtn) {
|
|
69
|
+
dom.diffScopeSessionBtn.textContent = state.sessionId ? `This chat (${sessCount})` : 'This chat';
|
|
70
|
+
}
|
|
71
|
+
if (dom.diffScopeWorkspaceBtn) {
|
|
72
|
+
dom.diffScopeWorkspaceBtn.textContent = `Workspace (${wsCount})`;
|
|
73
|
+
}
|
|
74
|
+
if (!data.isGitRepo && scope === 'workspace') {
|
|
75
|
+
dom.diffSummaryEl.textContent = 'Not a Git repository.';
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const files = data.files || [];
|
|
79
|
+
const addTot = Number(data.totalAdditions || 0);
|
|
80
|
+
const delTot = Number(data.totalDeletions || 0);
|
|
81
|
+
dom.diffSummaryEl.textContent = (addTot || delTot)
|
|
82
|
+
? `+${addTot} / -${delTot}`
|
|
83
|
+
: (files.length > 0 ? `${files.length}${files.length === 1 ? ' file' : ' files'}` : '');
|
|
84
|
+
|
|
85
|
+
if (files.length === 0) {
|
|
86
|
+
const empty = document.createElement('div');
|
|
87
|
+
empty.className = 'diff-empty-box';
|
|
88
|
+
const activeSessObj = state.sessions.find((x) => x.id === state.sessionId);
|
|
89
|
+
const activeTitle = activeSessObj && activeSessObj.title
|
|
90
|
+
? `"${activeSessObj.title.slice(0, 48)}"`
|
|
91
|
+
: 'this conversation';
|
|
92
|
+
const msg = document.createElement('div');
|
|
93
|
+
msg.textContent = scope === 'session'
|
|
94
|
+
? `No file changes in ${activeTitle}.`
|
|
95
|
+
: (state.diffStaged ? 'No staged changes.' : 'Working tree clean.');
|
|
96
|
+
empty.appendChild(msg);
|
|
97
|
+
if (scope === 'session' && wsCount > 0) {
|
|
98
|
+
const switchBtn = document.createElement('button');
|
|
99
|
+
switchBtn.type = 'button';
|
|
100
|
+
switchBtn.className = 'btn-ghost';
|
|
101
|
+
switchBtn.textContent = `View workspace changes (${wsCount})`;
|
|
102
|
+
switchBtn.addEventListener('click', () => {
|
|
103
|
+
state.diffScope = 'workspace';
|
|
104
|
+
callbacks.saveCurrentSessionWorkspace();
|
|
105
|
+
syncDiffControlsUi();
|
|
106
|
+
void loadDiff();
|
|
107
|
+
});
|
|
108
|
+
empty.appendChild(switchBtn);
|
|
109
|
+
}
|
|
110
|
+
dom.diffListEl.appendChild(empty);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
for (const f of files) {
|
|
115
|
+
const card = document.createElement('details');
|
|
116
|
+
card.className = 'diff-file';
|
|
117
|
+
card.open = files.length <= 6;
|
|
118
|
+
const head = document.createElement('summary');
|
|
119
|
+
head.className = 'diff-file-head';
|
|
120
|
+
const p = document.createElement('span');
|
|
121
|
+
p.className = 'diff-file-path';
|
|
122
|
+
p.title = f.path;
|
|
123
|
+
const badgeChar = f.status && f.status[0] ? f.status[0].toUpperCase() : 'M';
|
|
124
|
+
p.textContent = `[${badgeChar}] ${f.path}`;
|
|
125
|
+
const right = document.createElement('span');
|
|
126
|
+
right.className = 'diff-file-right';
|
|
127
|
+
if (f.additions || f.deletions) {
|
|
128
|
+
const add = document.createElement('span');
|
|
129
|
+
add.className = 'diff-add';
|
|
130
|
+
add.textContent = `+${f.additions || 0}`;
|
|
131
|
+
const del = document.createElement('span');
|
|
132
|
+
del.className = 'diff-del';
|
|
133
|
+
del.textContent = `-${f.deletions || 0}`;
|
|
134
|
+
right.appendChild(add);
|
|
135
|
+
right.appendChild(del);
|
|
136
|
+
}
|
|
137
|
+
if (f.existsOnDisk !== false) {
|
|
138
|
+
const openBtn = document.createElement('button');
|
|
139
|
+
openBtn.type = 'button';
|
|
140
|
+
openBtn.className = 'diff-open-btn';
|
|
141
|
+
openBtn.textContent = 'Open';
|
|
142
|
+
openBtn.addEventListener('click', (e) => {
|
|
143
|
+
e.preventDefault();
|
|
144
|
+
e.stopPropagation();
|
|
145
|
+
void callbacks.openFile(f.path);
|
|
146
|
+
});
|
|
147
|
+
right.appendChild(openBtn);
|
|
148
|
+
}
|
|
149
|
+
head.appendChild(p);
|
|
150
|
+
head.appendChild(right);
|
|
151
|
+
card.appendChild(head);
|
|
152
|
+
|
|
153
|
+
if (Array.isArray(f.hunks) && f.hunks.length > 0) {
|
|
154
|
+
const pre = document.createElement('div');
|
|
155
|
+
pre.className = 'diff-lines';
|
|
156
|
+
for (const h of f.hunks) {
|
|
157
|
+
const hh = document.createElement('div');
|
|
158
|
+
hh.className = 'diff-line hunk';
|
|
159
|
+
hh.textContent = h.header;
|
|
160
|
+
pre.appendChild(hh);
|
|
161
|
+
for (const ln of h.lines || []) {
|
|
162
|
+
const row = document.createElement('div');
|
|
163
|
+
row.className = `diff-line${ln.startsWith('+') ? ' plus' : ln.startsWith('-') ? ' minus' : ''}`;
|
|
164
|
+
row.textContent = ln;
|
|
165
|
+
pre.appendChild(row);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
card.appendChild(pre);
|
|
169
|
+
} else if (f.note) {
|
|
170
|
+
const note = document.createElement('div');
|
|
171
|
+
note.className = 'diff-note';
|
|
172
|
+
note.textContent = f.note;
|
|
173
|
+
card.appendChild(note);
|
|
174
|
+
}
|
|
175
|
+
dom.diffListEl.appendChild(card);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function bindDiffPanelEvents(): void {
|
|
180
|
+
if (dom.diffScopeSessionBtn) {
|
|
181
|
+
dom.diffScopeSessionBtn.addEventListener('click', () => {
|
|
182
|
+
if (!state.sessionId) return;
|
|
183
|
+
state.diffScope = 'session';
|
|
184
|
+
callbacks.saveCurrentSessionWorkspace();
|
|
185
|
+
syncDiffControlsUi();
|
|
186
|
+
void loadDiff();
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
if (dom.diffScopeWorkspaceBtn) {
|
|
190
|
+
dom.diffScopeWorkspaceBtn.addEventListener('click', () => {
|
|
191
|
+
state.diffScope = 'workspace';
|
|
192
|
+
callbacks.saveCurrentSessionWorkspace();
|
|
193
|
+
syncDiffControlsUi();
|
|
194
|
+
void loadDiff();
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
dom.diffStagedToggle.addEventListener('click', () => {
|
|
198
|
+
state.diffStaged = !state.diffStaged;
|
|
199
|
+
syncDiffControlsUi();
|
|
200
|
+
void loadDiff();
|
|
201
|
+
});
|
|
202
|
+
dom.refreshDiffBtn.addEventListener('click', () => { void loadDiff(); });
|
|
203
|
+
}
|