@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,165 @@
|
|
|
1
|
+
import { copyText, dom } from './dom.js';
|
|
2
|
+
import { apiUrl, authHeaders, scrollToBottom, setStageMode, state } from './state.js';
|
|
3
|
+
import { openStudio } from './studioShell.js';
|
|
4
|
+
import { openInCanvas } from './filesAndCanvas.js';
|
|
5
|
+
const QUICK_CLI_COMMANDS = [
|
|
6
|
+
'/status', '/doctor', '/map', '/rules', '/checkpoints', '/undo',
|
|
7
|
+
'/worktree list', '/pr', '/tasks', '/mcp', '/skills', '/peers',
|
|
8
|
+
'/plugins', '/slop', '/policy', '/audit', '/eval'
|
|
9
|
+
];
|
|
10
|
+
let callbacks = {
|
|
11
|
+
startFreshChat: async () => { },
|
|
12
|
+
appendUserTurn: () => { },
|
|
13
|
+
loadHealth: async () => { }
|
|
14
|
+
};
|
|
15
|
+
export function configureCliPanelCallbacks(cbs) {
|
|
16
|
+
callbacks = cbs;
|
|
17
|
+
}
|
|
18
|
+
export function renderCliQuickGrid() {
|
|
19
|
+
dom.cliQuickGrid.textContent = '';
|
|
20
|
+
for (const cmd of QUICK_CLI_COMMANDS) {
|
|
21
|
+
const btn = document.createElement('button');
|
|
22
|
+
btn.type = 'button';
|
|
23
|
+
btn.className = 'cli-chip';
|
|
24
|
+
btn.textContent = cmd;
|
|
25
|
+
btn.addEventListener('click', () => { void runCliCommand(cmd, 'studio'); });
|
|
26
|
+
dom.cliQuickGrid.appendChild(btn);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export async function loadCliCommands() {
|
|
30
|
+
const res = await fetch(apiUrl('/api/commands'), { headers: authHeaders() }).catch(() => null);
|
|
31
|
+
if (!res || !res.ok)
|
|
32
|
+
return;
|
|
33
|
+
const data = await res.json();
|
|
34
|
+
state.cliCommands = data.commands || [];
|
|
35
|
+
}
|
|
36
|
+
export async function loadCliOverview() {
|
|
37
|
+
const res = await fetch(apiUrl('/api/cli/overview'), { headers: authHeaders() }).catch(() => null);
|
|
38
|
+
if (!res || !res.ok)
|
|
39
|
+
return;
|
|
40
|
+
const d = await res.json();
|
|
41
|
+
const parts = [
|
|
42
|
+
`${d.commandsCount || 0} commands`,
|
|
43
|
+
`${d.skillsCount || 0} skills`
|
|
44
|
+
];
|
|
45
|
+
const cps = (d.checkpoints || []).length;
|
|
46
|
+
if (cps > 0)
|
|
47
|
+
parts.push(`${cps} checkpoints`);
|
|
48
|
+
const mcps = (d.mcpServers || []).length;
|
|
49
|
+
if (mcps > 0)
|
|
50
|
+
parts.push(`${mcps} MCP`);
|
|
51
|
+
const tasks = (d.tasks || []).length;
|
|
52
|
+
if (tasks > 0)
|
|
53
|
+
parts.push(`${tasks} running`);
|
|
54
|
+
dom.cliStatsEl.textContent = parts.join(' · ');
|
|
55
|
+
}
|
|
56
|
+
function appendCliTurnCard(cmdLine, title, output, ok) {
|
|
57
|
+
setStageMode(true);
|
|
58
|
+
const turn = document.createElement('div');
|
|
59
|
+
turn.className = 'turn assistant';
|
|
60
|
+
const card = document.createElement('div');
|
|
61
|
+
card.className = 'cli-turn-card';
|
|
62
|
+
const head = document.createElement('div');
|
|
63
|
+
head.className = 'cli-turn-head';
|
|
64
|
+
const left = document.createElement('span');
|
|
65
|
+
left.textContent = (title || cmdLine) + (ok ? '' : ' (failed)');
|
|
66
|
+
if (!ok)
|
|
67
|
+
left.style.color = 'var(--err)';
|
|
68
|
+
const right = document.createElement('div');
|
|
69
|
+
right.style.display = 'inline-flex';
|
|
70
|
+
right.style.gap = '6px';
|
|
71
|
+
const copyBtn = document.createElement('button');
|
|
72
|
+
copyBtn.type = 'button';
|
|
73
|
+
copyBtn.className = 'code-btn';
|
|
74
|
+
copyBtn.textContent = 'Copy';
|
|
75
|
+
copyBtn.addEventListener('click', () => copyText(output || '', copyBtn));
|
|
76
|
+
const canvasBtn = document.createElement('button');
|
|
77
|
+
canvasBtn.type = 'button';
|
|
78
|
+
canvasBtn.className = 'code-btn';
|
|
79
|
+
canvasBtn.textContent = 'Canvas';
|
|
80
|
+
canvasBtn.addEventListener('click', () => openInCanvas('cli-output.md', output || '', false));
|
|
81
|
+
right.appendChild(copyBtn);
|
|
82
|
+
right.appendChild(canvasBtn);
|
|
83
|
+
head.appendChild(left);
|
|
84
|
+
head.appendChild(right);
|
|
85
|
+
const pre = document.createElement('pre');
|
|
86
|
+
pre.className = 'cli-turn-body';
|
|
87
|
+
pre.textContent = output || '(no output)';
|
|
88
|
+
card.appendChild(head);
|
|
89
|
+
card.appendChild(pre);
|
|
90
|
+
turn.appendChild(card);
|
|
91
|
+
dom.threadEl.appendChild(turn);
|
|
92
|
+
scrollToBottom(true);
|
|
93
|
+
}
|
|
94
|
+
export async function runCliCommand(rawInput, target) {
|
|
95
|
+
const trimmed = String(rawInput || '').trim();
|
|
96
|
+
if (!trimmed)
|
|
97
|
+
return;
|
|
98
|
+
if (trimmed === '/new' || trimmed === '/clear') {
|
|
99
|
+
await callbacks.startFreshChat();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (trimmed === '/browser') {
|
|
103
|
+
openStudio('browser');
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (trimmed === '/diff') {
|
|
107
|
+
openStudio('diff');
|
|
108
|
+
}
|
|
109
|
+
if (target === 'studio') {
|
|
110
|
+
dom.cliStatusEl.textContent = `Running ${trimmed}...`;
|
|
111
|
+
dom.cliConsoleEl.textContent = `Executing ${trimmed}...`;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
callbacks.appendUserTurn(trimmed, []);
|
|
115
|
+
}
|
|
116
|
+
const res = await fetch(apiUrl('/api/command'), {
|
|
117
|
+
method: 'POST',
|
|
118
|
+
headers: authHeaders({ 'Content-Type': 'application/json' }),
|
|
119
|
+
body: JSON.stringify({ input: trimmed })
|
|
120
|
+
}).catch(() => null);
|
|
121
|
+
if (!res) {
|
|
122
|
+
if (target === 'studio')
|
|
123
|
+
dom.cliConsoleEl.textContent = 'Command request failed.';
|
|
124
|
+
else
|
|
125
|
+
appendCliTurnCard(trimmed, trimmed, 'Command request failed.', false);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const data = await res.json().catch(() => ({ ok: false, output: `HTTP ${res.status}` }));
|
|
129
|
+
const outText = data.output || data.error || '(done)';
|
|
130
|
+
if (target === 'studio') {
|
|
131
|
+
dom.cliConsoleEl.textContent = outText;
|
|
132
|
+
dom.cliStatusEl.textContent = (data.ok ? 'OK · ' : 'Failed · ') + trimmed;
|
|
133
|
+
void loadCliOverview();
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
appendCliTurnCard(trimmed, data.title || trimmed, outText, Boolean(data.ok));
|
|
137
|
+
}
|
|
138
|
+
void callbacks.loadHealth();
|
|
139
|
+
}
|
|
140
|
+
export async function runZeroSpendProbe() {
|
|
141
|
+
dom.cliStatusEl.textContent = 'Testing connections...';
|
|
142
|
+
dom.cliConsoleEl.textContent = 'Checking local Ollama and configured providers...';
|
|
143
|
+
const res = await fetch(apiUrl('/api/doctor/probe'), { method: 'POST', headers: authHeaders() }).catch(() => null);
|
|
144
|
+
if (!res || !res.ok) {
|
|
145
|
+
dom.cliConsoleEl.textContent = 'Connection test failed.';
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const data = await res.json();
|
|
149
|
+
dom.cliConsoleEl.textContent = data.report || 'Completed.';
|
|
150
|
+
dom.cliStatusEl.textContent = `${data.summary?.passedCount || 0} connected`;
|
|
151
|
+
}
|
|
152
|
+
export function bindCliPanelEvents() {
|
|
153
|
+
dom.cliRunBtn.addEventListener('click', () => {
|
|
154
|
+
void runCliCommand(dom.cliCmdInput.value, 'studio');
|
|
155
|
+
dom.cliCmdInput.value = '';
|
|
156
|
+
});
|
|
157
|
+
dom.cliCmdInput.addEventListener('keydown', (e) => {
|
|
158
|
+
if (e.key === 'Enter') {
|
|
159
|
+
e.preventDefault();
|
|
160
|
+
void runCliCommand(dom.cliCmdInput.value, 'studio');
|
|
161
|
+
dom.cliCmdInput.value = '';
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
dom.cliProbeBtn.addEventListener('click', () => { void runZeroSpendProbe(); });
|
|
165
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { copyText, dom } from './dom.js';
|
|
2
|
+
import { apiUrl, authHeaders, scrollToBottom, setStageMode, state } from './state.js';
|
|
3
|
+
import { openStudio } from './studioShell.js';
|
|
4
|
+
import { openInCanvas } from './filesAndCanvas.js';
|
|
5
|
+
import type { CliCommandEntry } from './types.js';
|
|
6
|
+
|
|
7
|
+
const QUICK_CLI_COMMANDS: readonly string[] = [
|
|
8
|
+
'/status', '/doctor', '/map', '/rules', '/checkpoints', '/undo',
|
|
9
|
+
'/worktree list', '/pr', '/tasks', '/mcp', '/skills', '/peers',
|
|
10
|
+
'/plugins', '/slop', '/policy', '/audit', '/eval'
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
export interface CliPanelCallbacks {
|
|
14
|
+
startFreshChat(): Promise<void>;
|
|
15
|
+
appendUserTurn(prompt: string, attachments: string[], animate?: boolean): void;
|
|
16
|
+
loadHealth(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let callbacks: CliPanelCallbacks = {
|
|
20
|
+
startFreshChat: async () => {},
|
|
21
|
+
appendUserTurn: () => {},
|
|
22
|
+
loadHealth: async () => {}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function configureCliPanelCallbacks(cbs: CliPanelCallbacks): void {
|
|
26
|
+
callbacks = cbs;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function renderCliQuickGrid(): void {
|
|
30
|
+
dom.cliQuickGrid.textContent = '';
|
|
31
|
+
for (const cmd of QUICK_CLI_COMMANDS) {
|
|
32
|
+
const btn = document.createElement('button');
|
|
33
|
+
btn.type = 'button';
|
|
34
|
+
btn.className = 'cli-chip';
|
|
35
|
+
btn.textContent = cmd;
|
|
36
|
+
btn.addEventListener('click', () => { void runCliCommand(cmd, 'studio'); });
|
|
37
|
+
dom.cliQuickGrid.appendChild(btn);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function loadCliCommands(): Promise<void> {
|
|
42
|
+
const res = await fetch(apiUrl('/api/commands'), { headers: authHeaders() }).catch(() => null);
|
|
43
|
+
if (!res || !res.ok) return;
|
|
44
|
+
const data = await res.json() as { commands?: CliCommandEntry[] };
|
|
45
|
+
state.cliCommands = data.commands || [];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function loadCliOverview(): Promise<void> {
|
|
49
|
+
const res = await fetch(apiUrl('/api/cli/overview'), { headers: authHeaders() }).catch(() => null);
|
|
50
|
+
if (!res || !res.ok) return;
|
|
51
|
+
const d = await res.json() as {
|
|
52
|
+
commandsCount?: number;
|
|
53
|
+
skillsCount?: number;
|
|
54
|
+
checkpoints?: unknown[];
|
|
55
|
+
mcpServers?: unknown[];
|
|
56
|
+
tasks?: unknown[];
|
|
57
|
+
};
|
|
58
|
+
const parts = [
|
|
59
|
+
`${d.commandsCount || 0} commands`,
|
|
60
|
+
`${d.skillsCount || 0} skills`
|
|
61
|
+
];
|
|
62
|
+
const cps = (d.checkpoints || []).length;
|
|
63
|
+
if (cps > 0) parts.push(`${cps} checkpoints`);
|
|
64
|
+
const mcps = (d.mcpServers || []).length;
|
|
65
|
+
if (mcps > 0) parts.push(`${mcps} MCP`);
|
|
66
|
+
const tasks = (d.tasks || []).length;
|
|
67
|
+
if (tasks > 0) parts.push(`${tasks} running`);
|
|
68
|
+
dom.cliStatsEl.textContent = parts.join(' · ');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function appendCliTurnCard(cmdLine: string, title: string, output: string, ok: boolean): void {
|
|
72
|
+
setStageMode(true);
|
|
73
|
+
const turn = document.createElement('div');
|
|
74
|
+
turn.className = 'turn assistant';
|
|
75
|
+
const card = document.createElement('div');
|
|
76
|
+
card.className = 'cli-turn-card';
|
|
77
|
+
const head = document.createElement('div');
|
|
78
|
+
head.className = 'cli-turn-head';
|
|
79
|
+
const left = document.createElement('span');
|
|
80
|
+
left.textContent = (title || cmdLine) + (ok ? '' : ' (failed)');
|
|
81
|
+
if (!ok) left.style.color = 'var(--err)';
|
|
82
|
+
const right = document.createElement('div');
|
|
83
|
+
right.style.display = 'inline-flex';
|
|
84
|
+
right.style.gap = '6px';
|
|
85
|
+
const copyBtn = document.createElement('button');
|
|
86
|
+
copyBtn.type = 'button';
|
|
87
|
+
copyBtn.className = 'code-btn';
|
|
88
|
+
copyBtn.textContent = 'Copy';
|
|
89
|
+
copyBtn.addEventListener('click', () => copyText(output || '', copyBtn));
|
|
90
|
+
const canvasBtn = document.createElement('button');
|
|
91
|
+
canvasBtn.type = 'button';
|
|
92
|
+
canvasBtn.className = 'code-btn';
|
|
93
|
+
canvasBtn.textContent = 'Canvas';
|
|
94
|
+
canvasBtn.addEventListener('click', () => openInCanvas('cli-output.md', output || '', false));
|
|
95
|
+
right.appendChild(copyBtn);
|
|
96
|
+
right.appendChild(canvasBtn);
|
|
97
|
+
head.appendChild(left);
|
|
98
|
+
head.appendChild(right);
|
|
99
|
+
const pre = document.createElement('pre');
|
|
100
|
+
pre.className = 'cli-turn-body';
|
|
101
|
+
pre.textContent = output || '(no output)';
|
|
102
|
+
card.appendChild(head);
|
|
103
|
+
card.appendChild(pre);
|
|
104
|
+
turn.appendChild(card);
|
|
105
|
+
dom.threadEl.appendChild(turn);
|
|
106
|
+
scrollToBottom(true);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export async function runCliCommand(rawInput: string, target: 'studio' | 'chat'): Promise<void> {
|
|
110
|
+
const trimmed = String(rawInput || '').trim();
|
|
111
|
+
if (!trimmed) return;
|
|
112
|
+
if (trimmed === '/new' || trimmed === '/clear') { await callbacks.startFreshChat(); return; }
|
|
113
|
+
if (trimmed === '/browser') { openStudio('browser'); return; }
|
|
114
|
+
if (trimmed === '/diff') { openStudio('diff'); }
|
|
115
|
+
if (target === 'studio') {
|
|
116
|
+
dom.cliStatusEl.textContent = `Running ${trimmed}...`;
|
|
117
|
+
dom.cliConsoleEl.textContent = `Executing ${trimmed}...`;
|
|
118
|
+
} else {
|
|
119
|
+
callbacks.appendUserTurn(trimmed, []);
|
|
120
|
+
}
|
|
121
|
+
const res = await fetch(apiUrl('/api/command'), {
|
|
122
|
+
method: 'POST',
|
|
123
|
+
headers: authHeaders({ 'Content-Type': 'application/json' }),
|
|
124
|
+
body: JSON.stringify({ input: trimmed })
|
|
125
|
+
}).catch(() => null);
|
|
126
|
+
if (!res) {
|
|
127
|
+
if (target === 'studio') dom.cliConsoleEl.textContent = 'Command request failed.';
|
|
128
|
+
else appendCliTurnCard(trimmed, trimmed, 'Command request failed.', false);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const data = await res.json().catch(() => ({ ok: false, output: `HTTP ${res.status}` })) as {
|
|
132
|
+
ok?: boolean;
|
|
133
|
+
title?: string;
|
|
134
|
+
output?: string;
|
|
135
|
+
error?: string;
|
|
136
|
+
};
|
|
137
|
+
const outText = data.output || data.error || '(done)';
|
|
138
|
+
if (target === 'studio') {
|
|
139
|
+
dom.cliConsoleEl.textContent = outText;
|
|
140
|
+
dom.cliStatusEl.textContent = (data.ok ? 'OK · ' : 'Failed · ') + trimmed;
|
|
141
|
+
void loadCliOverview();
|
|
142
|
+
} else {
|
|
143
|
+
appendCliTurnCard(trimmed, data.title || trimmed, outText, Boolean(data.ok));
|
|
144
|
+
}
|
|
145
|
+
void callbacks.loadHealth();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export async function runZeroSpendProbe(): Promise<void> {
|
|
149
|
+
dom.cliStatusEl.textContent = 'Testing connections...';
|
|
150
|
+
dom.cliConsoleEl.textContent = 'Checking local Ollama and configured providers...';
|
|
151
|
+
const res = await fetch(apiUrl('/api/doctor/probe'), { method: 'POST', headers: authHeaders() }).catch(() => null);
|
|
152
|
+
if (!res || !res.ok) { dom.cliConsoleEl.textContent = 'Connection test failed.'; return; }
|
|
153
|
+
const data = await res.json() as { report?: string; summary?: { passedCount?: number } };
|
|
154
|
+
dom.cliConsoleEl.textContent = data.report || 'Completed.';
|
|
155
|
+
dom.cliStatusEl.textContent = `${data.summary?.passedCount || 0} connected`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function bindCliPanelEvents(): void {
|
|
159
|
+
dom.cliRunBtn.addEventListener('click', () => {
|
|
160
|
+
void runCliCommand(dom.cliCmdInput.value, 'studio');
|
|
161
|
+
dom.cliCmdInput.value = '';
|
|
162
|
+
});
|
|
163
|
+
dom.cliCmdInput.addEventListener('keydown', (e) => {
|
|
164
|
+
if (e.key === 'Enter') {
|
|
165
|
+
e.preventDefault();
|
|
166
|
+
void runCliCommand(dom.cliCmdInput.value, 'studio');
|
|
167
|
+
dom.cliCmdInput.value = '';
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
dom.cliProbeBtn.addEventListener('click', () => { void runZeroSpendProbe(); });
|
|
171
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { dom } from './dom.js';
|
|
2
|
+
import { apiUrl, authHeaders, state, updateComposerMetrics } from './state.js';
|
|
3
|
+
let callbacks = {
|
|
4
|
+
submitPrompt: async () => { },
|
|
5
|
+
stopActiveRun: async () => { },
|
|
6
|
+
runCliCommand: async () => { }
|
|
7
|
+
};
|
|
8
|
+
export function configureComposerCallbacks(cbs) {
|
|
9
|
+
callbacks = cbs;
|
|
10
|
+
}
|
|
11
|
+
export function renderAttachmentChips() {
|
|
12
|
+
dom.composerChipsEl.textContent = '';
|
|
13
|
+
dom.composerChipsEl.classList.toggle('has-items', state.attachments.length > 0);
|
|
14
|
+
for (const rel of state.attachments) {
|
|
15
|
+
const chip = document.createElement('span');
|
|
16
|
+
chip.className = 'chip';
|
|
17
|
+
const label = document.createElement('span');
|
|
18
|
+
label.textContent = `@${rel}`;
|
|
19
|
+
const rm = document.createElement('button');
|
|
20
|
+
rm.type = 'button';
|
|
21
|
+
rm.textContent = 'x';
|
|
22
|
+
rm.setAttribute('aria-label', `Remove ${rel}`);
|
|
23
|
+
rm.addEventListener('click', () => {
|
|
24
|
+
state.attachments = state.attachments.filter((item) => item !== rel);
|
|
25
|
+
renderAttachmentChips();
|
|
26
|
+
});
|
|
27
|
+
chip.appendChild(label);
|
|
28
|
+
chip.appendChild(rm);
|
|
29
|
+
dom.composerChipsEl.appendChild(chip);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function attachWorkspaceFile(relPath) {
|
|
33
|
+
if (!relPath || state.attachments.includes(relPath) || state.attachments.length >= 6)
|
|
34
|
+
return;
|
|
35
|
+
state.attachments.push(relPath);
|
|
36
|
+
renderAttachmentChips();
|
|
37
|
+
dom.promptInput.focus();
|
|
38
|
+
}
|
|
39
|
+
function applySlashChoice(cmdName) {
|
|
40
|
+
dom.promptInput.value = `/${cmdName} `;
|
|
41
|
+
state.mentionItems = [];
|
|
42
|
+
state.mentionStart = -1;
|
|
43
|
+
dom.mentionPopover.classList.remove('open');
|
|
44
|
+
updateComposerMetrics();
|
|
45
|
+
dom.promptInput.focus();
|
|
46
|
+
}
|
|
47
|
+
function applyMentionChoice(relPath) {
|
|
48
|
+
const pos = dom.promptInput.selectionStart || dom.promptInput.value.length;
|
|
49
|
+
if (state.mentionStart >= 0 && pos >= state.mentionStart) {
|
|
50
|
+
dom.promptInput.value = dom.promptInput.value.slice(0, state.mentionStart) + dom.promptInput.value.slice(pos);
|
|
51
|
+
}
|
|
52
|
+
attachWorkspaceFile(relPath);
|
|
53
|
+
state.mentionItems = [];
|
|
54
|
+
state.mentionStart = -1;
|
|
55
|
+
dom.mentionPopover.classList.remove('open');
|
|
56
|
+
updateComposerMetrics();
|
|
57
|
+
}
|
|
58
|
+
function renderMentionList() {
|
|
59
|
+
dom.mentionPopover.textContent = '';
|
|
60
|
+
if (state.mentionItems.length === 0) {
|
|
61
|
+
dom.mentionPopover.classList.remove('open');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
dom.mentionPopover.classList.add('open');
|
|
65
|
+
state.mentionItems.forEach((item, idx) => {
|
|
66
|
+
const btn = document.createElement('button');
|
|
67
|
+
btn.type = 'button';
|
|
68
|
+
btn.className = `mention-item${idx === state.mentionIndex ? ' selected' : ''}`;
|
|
69
|
+
if (state.mentionMode === 'command') {
|
|
70
|
+
const cmdName = item.name || '';
|
|
71
|
+
btn.textContent = `/${cmdName}${item.description ? ` — ${item.description.slice(0, 62)}` : ''}`;
|
|
72
|
+
btn.addEventListener('click', () => applySlashChoice(cmdName));
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const filePath = item.path || '';
|
|
76
|
+
btn.textContent = `@${filePath}`;
|
|
77
|
+
btn.addEventListener('click', () => applyMentionChoice(filePath));
|
|
78
|
+
}
|
|
79
|
+
dom.mentionPopover.appendChild(btn);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async function checkAtMention() {
|
|
83
|
+
const val = dom.promptInput.value || '';
|
|
84
|
+
const trimmedLeft = val.trimStart();
|
|
85
|
+
if (trimmedLeft.startsWith('/') && !trimmedLeft.includes(' ') && state.cliCommands.length > 0) {
|
|
86
|
+
const q = trimmedLeft.slice(1).toLowerCase();
|
|
87
|
+
state.mentionMode = 'command';
|
|
88
|
+
const prefixHits = state.cliCommands.filter((c) => c.name.toLowerCase().startsWith(q));
|
|
89
|
+
const nameHits = state.cliCommands.filter((c) => {
|
|
90
|
+
const n = c.name.toLowerCase();
|
|
91
|
+
return !n.startsWith(q) && n.includes(q);
|
|
92
|
+
});
|
|
93
|
+
const descHits = state.cliCommands.filter((c) => {
|
|
94
|
+
const n = c.name.toLowerCase();
|
|
95
|
+
return !n.includes(q) && (c.description || '').toLowerCase().includes(q);
|
|
96
|
+
});
|
|
97
|
+
state.mentionItems = prefixHits.concat(nameHits, descHits).slice(0, 10);
|
|
98
|
+
state.mentionIndex = 0;
|
|
99
|
+
renderMentionList();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const pos = dom.promptInput.selectionStart || val.length;
|
|
103
|
+
const before = val.slice(0, pos);
|
|
104
|
+
const atIdx = before.lastIndexOf('@');
|
|
105
|
+
if (atIdx < 0 || (atIdx > 0 && !/\s/.test(before[atIdx - 1] || ''))) {
|
|
106
|
+
state.mentionItems = [];
|
|
107
|
+
state.mentionStart = -1;
|
|
108
|
+
dom.mentionPopover.classList.remove('open');
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const query = before.slice(atIdx + 1);
|
|
112
|
+
if (/\s/.test(query)) {
|
|
113
|
+
dom.mentionPopover.classList.remove('open');
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
state.mentionMode = 'file';
|
|
117
|
+
state.mentionStart = atIdx;
|
|
118
|
+
const res = await fetch(apiUrl(`/api/files?q=${encodeURIComponent(query)}`), { headers: authHeaders() }).catch(() => null);
|
|
119
|
+
if (!res || !res.ok)
|
|
120
|
+
return;
|
|
121
|
+
const data = await res.json();
|
|
122
|
+
state.mentionItems = (data.entries || []).filter((x) => x.type === 'file').slice(0, 8);
|
|
123
|
+
state.mentionIndex = 0;
|
|
124
|
+
renderMentionList();
|
|
125
|
+
}
|
|
126
|
+
export function bindComposerEvents() {
|
|
127
|
+
dom.composerPill.addEventListener('click', (e) => {
|
|
128
|
+
if (e.target === dom.composerPill)
|
|
129
|
+
dom.promptInput.focus();
|
|
130
|
+
});
|
|
131
|
+
dom.promptInput.addEventListener('compositionstart', () => { state.isComposing = true; });
|
|
132
|
+
dom.promptInput.addEventListener('compositionend', () => { state.isComposing = false; });
|
|
133
|
+
dom.promptInput.addEventListener('input', () => {
|
|
134
|
+
updateComposerMetrics();
|
|
135
|
+
void checkAtMention();
|
|
136
|
+
});
|
|
137
|
+
dom.promptInput.addEventListener('keydown', (e) => {
|
|
138
|
+
if (dom.mentionPopover.classList.contains('open') && state.mentionItems.length > 0) {
|
|
139
|
+
if (e.key === 'ArrowDown') {
|
|
140
|
+
e.preventDefault();
|
|
141
|
+
state.mentionIndex = (state.mentionIndex + 1) % state.mentionItems.length;
|
|
142
|
+
renderMentionList();
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (e.key === 'ArrowUp') {
|
|
146
|
+
e.preventDefault();
|
|
147
|
+
state.mentionIndex = (state.mentionIndex - 1 + state.mentionItems.length) % state.mentionItems.length;
|
|
148
|
+
renderMentionList();
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (e.key === 'Enter' || e.key === 'Tab') {
|
|
152
|
+
e.preventDefault();
|
|
153
|
+
const chosen = state.mentionItems[state.mentionIndex];
|
|
154
|
+
if (chosen) {
|
|
155
|
+
if (state.mentionMode === 'command' && chosen.name)
|
|
156
|
+
applySlashChoice(chosen.name);
|
|
157
|
+
else if (chosen.path)
|
|
158
|
+
applyMentionChoice(chosen.path);
|
|
159
|
+
}
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (e.key === 'Escape') {
|
|
163
|
+
e.preventDefault();
|
|
164
|
+
dom.mentionPopover.classList.remove('open');
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (e.key === 'Enter' && !e.shiftKey && !e.isComposing && !state.isComposing) {
|
|
169
|
+
e.preventDefault();
|
|
170
|
+
dom.chatForm.requestSubmit();
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
dom.chatForm.addEventListener('submit', (e) => {
|
|
174
|
+
e.preventDefault();
|
|
175
|
+
if (state.activeController) {
|
|
176
|
+
void callbacks.stopActiveRun();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const text = (dom.promptInput.value || '').trim();
|
|
180
|
+
if (!text)
|
|
181
|
+
return;
|
|
182
|
+
const toAttach = state.attachments.slice();
|
|
183
|
+
dom.promptInput.value = '';
|
|
184
|
+
state.attachments = [];
|
|
185
|
+
renderAttachmentChips();
|
|
186
|
+
updateComposerMetrics();
|
|
187
|
+
if (text.startsWith('/') && /^\/[a-z?][a-z0-9_-]*/i.test(text)) {
|
|
188
|
+
void callbacks.runCliCommand(text, 'chat');
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
void callbacks.submitPrompt(text, toAttach);
|
|
192
|
+
});
|
|
193
|
+
dom.sendBtn.addEventListener('click', (e) => {
|
|
194
|
+
if (state.activeController) {
|
|
195
|
+
e.preventDefault();
|
|
196
|
+
void callbacks.stopActiveRun();
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
dom.heroHelpBtn.addEventListener('click', () => {
|
|
200
|
+
dom.promptInput.value = 'Inspect this local workspace and summarize its architecture and next steps.';
|
|
201
|
+
updateComposerMetrics();
|
|
202
|
+
dom.promptInput.focus();
|
|
203
|
+
});
|
|
204
|
+
}
|