pinokiod 8.3.7 → 8.3.9

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,128 @@
1
+ /* Shell button on app pages (see agent-bar-shell.js): a terminal icon in the top
2
+ bar, left of the Home Server button, with a small menu of the app's shells.
3
+ The button is the same size and has the same hover as the Home Server button;
4
+ the menu's rows match the agent menu's rows. */
5
+ .agent-bar-shell {
6
+ --agent-bar-shell-text: #111827;
7
+ --agent-bar-shell-muted: rgba(55, 65, 81, 0.78);
8
+ --agent-bar-shell-border: rgba(15, 23, 42, 0.16);
9
+ --agent-bar-shell-surface: #ffffff;
10
+ --agent-bar-shell-hover: rgba(15, 23, 42, 0.06);
11
+ --agent-bar-shell-shadow: 0 12px 24px rgba(15, 23, 42, 0.14), 0 2px 8px rgba(15, 23, 42, 0.08);
12
+ position: relative;
13
+ display: inline-flex;
14
+ align-items: center;
15
+ justify-content: center;
16
+ -webkit-app-region: no-drag;
17
+ }
18
+ body.dark .agent-bar-shell {
19
+ --agent-bar-shell-text: rgba(250, 250, 250, 0.96);
20
+ --agent-bar-shell-muted: rgba(161, 161, 170, 0.92);
21
+ --agent-bar-shell-border: rgba(255, 255, 255, 0.16);
22
+ --agent-bar-shell-surface: #323334;
23
+ --agent-bar-shell-hover: rgba(255, 255, 255, 0.08);
24
+ --agent-bar-shell-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
25
+ }
26
+ .agent-bar-shell [hidden] {
27
+ display: none !important;
28
+ }
29
+ .agent-bar-shell__trigger {
30
+ width: 40px;
31
+ height: 30px;
32
+ min-width: 40px;
33
+ min-height: 30px;
34
+ padding: 0;
35
+ border-radius: 9px;
36
+ box-sizing: border-box;
37
+ }
38
+ .agent-bar-shell__trigger:hover,
39
+ .agent-bar-shell__trigger:focus-visible,
40
+ .agent-bar-shell[data-open="true"] .agent-bar-shell__trigger {
41
+ background: rgba(15, 23, 42, 0.055);
42
+ }
43
+ body.dark .agent-bar-shell__trigger:hover,
44
+ body.dark .agent-bar-shell__trigger:focus-visible,
45
+ body.dark .agent-bar-shell[data-open="true"] .agent-bar-shell__trigger {
46
+ background: rgba(255, 255, 255, 0.08);
47
+ }
48
+
49
+ /* The menu hangs below the top bar, over the page. While it is open the top bar
50
+ is raised, so page content stacked above the top bar cannot cover it. */
51
+ header.navheader.agent-bar-shell-raised {
52
+ z-index: 100000;
53
+ }
54
+ .agent-bar-shell__menu {
55
+ position: absolute;
56
+ top: calc(100% + 6px);
57
+ right: 0;
58
+ z-index: 10003;
59
+ box-sizing: border-box;
60
+ width: 270px;
61
+ max-width: calc(100vw - 24px);
62
+ max-height: min(70vh, 520px);
63
+ overflow-y: auto;
64
+ padding: 6px;
65
+ border: 1px solid var(--agent-bar-shell-border);
66
+ border-radius: 12px;
67
+ background: var(--agent-bar-shell-surface);
68
+ box-shadow: var(--agent-bar-shell-shadow);
69
+ font: 400 13px system-ui, -apple-system, "Segoe UI", sans-serif;
70
+ letter-spacing: 0;
71
+ color: var(--agent-bar-shell-text);
72
+ text-align: left;
73
+ }
74
+ .agent-bar-shell__title {
75
+ padding: 7px 8px 4px;
76
+ font-size: 11px;
77
+ font-weight: 600;
78
+ letter-spacing: 0.04em;
79
+ text-transform: uppercase;
80
+ color: var(--agent-bar-shell-muted);
81
+ }
82
+ .agent-bar-shell__empty {
83
+ padding: 6px 8px;
84
+ font-size: 12px;
85
+ color: var(--agent-bar-shell-muted);
86
+ }
87
+ .agent-bar-shell__row {
88
+ width: 100%;
89
+ height: 32px;
90
+ display: flex;
91
+ align-items: center;
92
+ gap: 9px;
93
+ padding: 0 8px;
94
+ border: 0;
95
+ border-radius: 7px;
96
+ background: transparent;
97
+ font: inherit;
98
+ color: inherit;
99
+ text-align: left;
100
+ cursor: pointer;
101
+ }
102
+ .agent-bar-shell__row:hover,
103
+ .agent-bar-shell__row:focus-visible {
104
+ background: var(--agent-bar-shell-hover);
105
+ }
106
+ .agent-bar-shell__row-icon {
107
+ flex: none;
108
+ width: 18px;
109
+ text-align: center;
110
+ font-size: 12px;
111
+ color: var(--agent-bar-shell-muted);
112
+ }
113
+ .agent-bar-shell__row-label {
114
+ flex: 1 1 auto;
115
+ min-width: 0;
116
+ white-space: nowrap;
117
+ overflow: hidden;
118
+ text-overflow: ellipsis;
119
+ }
120
+ .agent-bar-shell__row-note {
121
+ flex: none;
122
+ max-width: 55%;
123
+ white-space: nowrap;
124
+ overflow: hidden;
125
+ text-overflow: ellipsis;
126
+ font-size: 12px;
127
+ color: var(--agent-bar-shell-muted);
128
+ }
@@ -0,0 +1,251 @@
1
+ // Shell button on app pages (Run and Dev): a terminal icon in the top bar,
2
+ // immediately left of the Home Server button. Loaded by app.ejs.
3
+ //
4
+ // A shell is not an agent: it takes no prompt and opens the moment it is picked.
5
+ // So it has its own button instead of rows at the end of the agent menu (those
6
+ // rows are still built in agent-bar-app.js, only not shown while this is here).
7
+ //
8
+ // click -> a small menu of this app's shells, read from the same
9
+ // request the agent menu used:
10
+ // GET /api/plugin/menu?workspace=<app folder> -> projectShell.items
11
+ // pick one (Run) -> the page's own way of opening a shell in the docked
12
+ // window: PinokioAgentDock.openShellTool (or the page's
13
+ // own Ask AI panel when the dock is not there)
14
+ // pick one (Dev) -> the same message the Plugins page sends when a
15
+ // "Project Shell" row is clicked: { launch: { name, href, label } }
16
+ //
17
+ // Nothing else on the page is changed.
18
+ (function (window, document) {
19
+ 'use strict';
20
+
21
+ if (window.PinokioShellButton) return;
22
+
23
+ function el(tag, className, text) {
24
+ const node = document.createElement(tag);
25
+ if (className) node.className = className;
26
+ if (text) node.textContent = text;
27
+ return node;
28
+ }
29
+
30
+ // The app's folder: the Ask AI button carries it in Run mode; the app card's
31
+ // disk figure carries it in both modes.
32
+ function appFolder() {
33
+ const source = document.getElementById('ask-ai-tab') || document.querySelector('[data-workspace-cwd]');
34
+ if (source && source.dataset.workspaceCwd) return source.dataset.workspaceCwd.trim();
35
+ const disk = document.querySelector('.disk-usage[data-filepath]');
36
+ return disk && disk.dataset.filepath ? disk.dataset.filepath.trim() : '';
37
+ }
38
+
39
+ function newSession() {
40
+ if (window.crypto && typeof window.crypto.randomUUID === 'function') return window.crypto.randomUUID();
41
+ return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
42
+ }
43
+
44
+ function withSession(value, session) {
45
+ if (!value || value.includes('session=')) return value;
46
+ return `${value}${value.includes('?') ? '&' : '?'}session=${session}`;
47
+ }
48
+
49
+ // While a shell of one kind is running, the server hands out that kind's link
50
+ // with the running shell's own session on it, and a link that already names a
51
+ // session opens that session again. Every pick here is a new shell, so the
52
+ // link is used without it. The rest of the link is left exactly as it came.
53
+ function withoutSession(value) {
54
+ const at = value.indexOf('?');
55
+ if (at < 0) return value;
56
+ const kept = value.slice(at + 1).split('&')
57
+ .filter((part) => part && !part.startsWith('session=') && !part.startsWith('terminal_id='));
58
+ return kept.length ? `${value.slice(0, at)}?${kept.join('&')}` : value.slice(0, at);
59
+ }
60
+
61
+ function readShells(payload) {
62
+ const items = payload && payload.projectShell && Array.isArray(payload.projectShell.items)
63
+ ? payload.projectShell.items
64
+ : [];
65
+ return items.map((item) => {
66
+ const href = withoutSession(item && typeof item.href === 'string' ? item.href.trim() : '');
67
+ if (!href || !href.startsWith('/shell/')) return null;
68
+ return {
69
+ label: (typeof item.title === 'string' && item.title.trim())
70
+ || (typeof item.text === 'string' && item.text.trim())
71
+ || 'Shell',
72
+ href,
73
+ target: typeof item.target === 'string' && item.target.trim() ? withoutSession(item.target.trim()) : `@${href}`,
74
+ iconClass: typeof item.icon === 'string' && item.icon.trim() ? item.icon.trim() : 'fa-solid fa-terminal',
75
+ description: typeof item.subtitle === 'string' ? item.subtitle.trim() : '',
76
+ kind: 'shell',
77
+ };
78
+ }).filter(Boolean);
79
+ }
80
+
81
+ function build(anchor) {
82
+ const root = el('div', 'agent-bar-shell');
83
+ const button = el('button', 'btn2 agent-bar-shell__trigger');
84
+ button.type = 'button';
85
+ button.title = 'Open a shell';
86
+ button.setAttribute('aria-label', 'Open a shell');
87
+ button.setAttribute('aria-haspopup', 'menu');
88
+ button.setAttribute('aria-expanded', 'false');
89
+ button.setAttribute('data-tippy-content', 'Open a shell');
90
+ const icon = el('i', 'fa-solid fa-terminal');
91
+ icon.setAttribute('aria-hidden', 'true');
92
+ button.appendChild(icon);
93
+ const menu = el('div', 'agent-bar-shell__menu');
94
+ menu.setAttribute('role', 'menu');
95
+ menu.hidden = true;
96
+ root.append(button, menu);
97
+ anchor.parentNode.insertBefore(root, anchor);
98
+
99
+ const state = { open: false, shells: null, failed: false };
100
+
101
+ // The menu hangs below the top bar, over the page. The top bar is raised
102
+ // while it is open, the same way the agent bar raises it for its menus.
103
+ function raise(on) {
104
+ const header = root.closest('header');
105
+ if (header) header.classList.toggle('agent-bar-shell-raised', on);
106
+ }
107
+
108
+ function render() {
109
+ root.dataset.open = state.open ? 'true' : 'false';
110
+ button.setAttribute('aria-expanded', state.open ? 'true' : 'false');
111
+ menu.hidden = !state.open;
112
+ raise(state.open);
113
+ menu.textContent = '';
114
+ if (!state.open) return;
115
+ menu.appendChild(el('div', 'agent-bar-shell__title', 'Open a shell'));
116
+ if (state.failed) {
117
+ menu.appendChild(el('div', 'agent-bar-shell__empty', "Couldn't read this app's shells."));
118
+ } else if (!state.shells) {
119
+ menu.appendChild(el('div', 'agent-bar-shell__empty', 'Loading…'));
120
+ } else if (!state.shells.length) {
121
+ menu.appendChild(el('div', 'agent-bar-shell__empty', 'This app has no shells.'));
122
+ } else {
123
+ state.shells.forEach((shell) => {
124
+ const row = el('button', 'agent-bar-shell__row');
125
+ row.type = 'button';
126
+ row.setAttribute('role', 'menuitem');
127
+ const rowIcon = el('i', `${shell.iconClass} agent-bar-shell__row-icon`);
128
+ rowIcon.setAttribute('aria-hidden', 'true');
129
+ row.append(rowIcon, el('span', 'agent-bar-shell__row-label', shell.label));
130
+ if (shell.description) row.appendChild(el('span', 'agent-bar-shell__row-note', shell.description));
131
+ row.addEventListener('click', () => open(shell));
132
+ menu.appendChild(row);
133
+ });
134
+ }
135
+ }
136
+
137
+ // Read once per page, like the agent menu. A failed read is tried again
138
+ // the next time the menu opens.
139
+ let loading = null;
140
+ function load() {
141
+ if (loading) return loading;
142
+ const folder = appFolder();
143
+ if (!folder) {
144
+ state.failed = true;
145
+ render();
146
+ return Promise.resolve();
147
+ }
148
+ state.failed = false;
149
+ loading = fetch(`/api/plugin/menu?workspace=${encodeURIComponent(folder)}`)
150
+ .then((res) => {
151
+ if (!res.ok) throw new Error('Failed to load shells.');
152
+ return res.json();
153
+ })
154
+ .then((payload) => {
155
+ state.shells = readShells(payload);
156
+ render();
157
+ })
158
+ .catch(() => {
159
+ loading = null;
160
+ state.failed = true;
161
+ render();
162
+ });
163
+ return loading;
164
+ }
165
+
166
+ function close() {
167
+ if (!state.open) return;
168
+ state.open = false;
169
+ render();
170
+ }
171
+
172
+ function open(shell) {
173
+ close();
174
+ const isRun = Boolean(document.getElementById('ask-ai-tab') || document.getElementById('ask-ai-drawer'));
175
+ const drawer = isRun ? (window.PinokioAgentDock || window.PinokioAskAiDrawer || null) : null;
176
+ if (drawer && typeof drawer.openShellTool === 'function') {
177
+ // Run: the docked window, with a session of its own
178
+ Promise.resolve(drawer.openShellTool(shell)).then(() => {
179
+ // the agent bar's "N running" count reads the running list again
180
+ window.dispatchEvent(new CustomEvent('pinokio:shell-opened'));
181
+ });
182
+ return;
183
+ }
184
+ // Dev: what the Plugins page sends for a "Project Shell" row
185
+ const session = newSession();
186
+ window.postMessage({
187
+ launch: {
188
+ name: withSession(shell.target, session),
189
+ href: withSession(shell.href, session),
190
+ label: shell.label,
191
+ },
192
+ }, window.location.origin);
193
+ }
194
+
195
+ button.addEventListener('click', (event) => {
196
+ event.preventDefault();
197
+ event.stopPropagation();
198
+ state.open = !state.open;
199
+ render();
200
+ if (state.open) load();
201
+ });
202
+ // read the list on the way to the button, so the menu opens already filled
203
+ button.addEventListener('pointerenter', load);
204
+ root.addEventListener('keydown', (event) => {
205
+ if (event.key !== 'Escape' || !state.open) return;
206
+ event.stopPropagation();
207
+ close();
208
+ button.focus();
209
+ });
210
+ document.addEventListener('pointerdown', (event) => {
211
+ if (!root.contains(event.target)) close();
212
+ }, true);
213
+ // A click inside one of the page's frames never reaches this document. What
214
+ // does happen is that this window loses focus and the frame becomes the
215
+ // active element (the agent bar closes its menus the same way). Any other
216
+ // loss of focus leaves the menu as it is.
217
+ window.addEventListener('blur', () => {
218
+ window.setTimeout(() => {
219
+ const active = document.activeElement;
220
+ if (active && active.tagName === 'IFRAME') close();
221
+ }, 0);
222
+ });
223
+
224
+ return root;
225
+ }
226
+
227
+ // The Home Server button is in the top bar's markup; the button is put in as
228
+ // soon as that markup exists, so the top bar is drawn with it the first time.
229
+ function mount() {
230
+ if (document.querySelector('.agent-bar-shell')) return true;
231
+ const anchor = document.querySelector('header .home-server-popover') || document.querySelector('.home-server-popover');
232
+ if (!anchor || !anchor.parentNode) return false;
233
+ build(anchor);
234
+ return true;
235
+ }
236
+
237
+ window.PinokioShellButton = { mount };
238
+
239
+ if (!mount()) {
240
+ const watcher = new MutationObserver(() => {
241
+ if (mount()) watcher.disconnect();
242
+ });
243
+ watcher.observe(document.documentElement, { childList: true, subtree: true });
244
+ const stop = () => {
245
+ mount();
246
+ watcher.disconnect();
247
+ };
248
+ if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', stop, { once: true });
249
+ else stop();
250
+ }
251
+ })(window, document);