clideck 1.26.0 → 1.26.3

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.
@@ -0,0 +1,84 @@
1
+ // Autopilot client — toggle state, notifications, token display
2
+
3
+ let api = null;
4
+ const activeProjects = new Set();
5
+
6
+ export function init(pluginApi) {
7
+ api = pluginApi;
8
+
9
+ api.onMessage('started', (msg) => {
10
+ activeProjects.add(msg.projectId);
11
+ updateToggle(msg.projectId, true);
12
+ api.toast('Autopilot started');
13
+ });
14
+
15
+ api.onMessage('stopped', (msg) => {
16
+ activeProjects.delete(msg.projectId);
17
+ updateToggle(msg.projectId, false);
18
+ api.toast('Autopilot stopped');
19
+ });
20
+
21
+ api.onMessage('error', (msg) => api.toast(msg.msg || 'Autopilot error', { type: 'error' }));
22
+ api.onMessage('routed', (msg) => api.toast(`→ ${msg.to}`, { type: 'info' }));
23
+ api.onMessage('notify', (msg) => api.toast(msg.reason, { type: 'warn', duration: 0, markdown: true, title: `Autopilot \u2014 ${msg.projectName || 'Project'}` }));
24
+ api.onMessage('paused', (msg) => api.toast(`Autopilot: ${msg.question}`, { type: 'warn' }));
25
+ api.onMessage('resumed', () => api.toast('Autopilot resumed'));
26
+
27
+ api.onMessage('tokens', (msg) => {
28
+ const btn = toggleBtn(msg.projectId);
29
+ if (btn && activeProjects.has(msg.projectId)) {
30
+ const total = (msg.input || 0) + (msg.output || 0);
31
+ btn.title = `Autopilot ON — ${total.toLocaleString()} tokens`;
32
+ }
33
+ });
34
+
35
+ api.onMessage('status', (msg) => {
36
+ if (msg.active) activeProjects.add(msg.projectId);
37
+ else activeProjects.delete(msg.projectId);
38
+ updateToggle(msg.projectId, msg.active);
39
+ });
40
+
41
+ // Re-apply toggle state when sidebar re-renders
42
+ const list = document.getElementById('session-list');
43
+ if (list) {
44
+ new MutationObserver(() => {
45
+ for (const pid of activeProjects) updateToggle(pid, true);
46
+ }).observe(list, { childList: true, subtree: true });
47
+ }
48
+
49
+ activeProjects.clear();
50
+ api.send('sync');
51
+ }
52
+
53
+ function toggleBtn(pid) {
54
+ return document.querySelector(`.project-plugin-action[data-action-id="autopilot-toggle"][data-project-id="${pid}"]`);
55
+ }
56
+
57
+ function updateToggle(pid, active) {
58
+ const btn = toggleBtn(pid);
59
+ if (!btn) return;
60
+ btn.classList.toggle('autopilot-active', active);
61
+ btn.title = active ? 'Autopilot ON — click to stop' : 'Autopilot — click to start';
62
+ }
63
+
64
+ const style = document.createElement('style');
65
+ style.textContent = `
66
+ @keyframes autopilot-pulse {
67
+ 0%, 100% { opacity: 1; filter: drop-shadow(0 0 2px #818cf8); }
68
+ 50% { opacity: 0.6; filter: drop-shadow(0 0 6px #818cf8); }
69
+ }
70
+ @keyframes clock-spin {
71
+ from { transform: rotate(0deg); }
72
+ to { transform: rotate(360deg); }
73
+ }
74
+ .autopilot-active {
75
+ color: #818cf8 !important;
76
+ opacity: 1 !important;
77
+ animation: autopilot-pulse 2s ease-in-out infinite;
78
+ }
79
+ .autopilot-active svg path {
80
+ transform-origin: 12px 12px;
81
+ animation: clock-spin 2s linear infinite;
82
+ }
83
+ `;
84
+ document.head.appendChild(style);