pinokiod 8.3.34 → 8.3.35
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/kernel/api/uri/index.js +6 -0
- package/package.json +1 -1
- package/server/public/agent-bar-agents.css +154 -0
- package/server/public/agent-bar-agents.js +346 -0
- package/server/public/agent-bar-launch.css +274 -0
- package/server/public/agent-bar-launch.js +333 -0
- package/server/public/agent-bar-panel.js +2 -0
- package/server/public/agent-bar.js +1 -0
- package/server/views/app.ejs +4 -0
- package/server/views/partials/main_sidebar.ejs +4 -0
- package/server/views/terminal.ejs +2 -0
- package/test/agent-bar-agents.test.js +297 -0
- package/test/agent-bar-launch.test.js +375 -0
- package/test/uri-api.test.js +23 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
// The agent menu (server/public/agent-bar-agents.js): a search box, and two tabs
|
|
2
|
+
// (Terminal, Desktop) when both kinds of agent are installed.
|
|
3
|
+
//
|
|
4
|
+
// The real agent-bar.js (and agent-bar-app.js for the app page's bar) run here in
|
|
5
|
+
// a page that has only a top bar. This page lays nothing out, so nothing here is
|
|
6
|
+
// about sizes or scrolling.
|
|
7
|
+
const assert = require('node:assert/strict')
|
|
8
|
+
const fs = require('node:fs')
|
|
9
|
+
const path = require('node:path')
|
|
10
|
+
const test = require('node:test')
|
|
11
|
+
const { JSDOM } = require('jsdom')
|
|
12
|
+
|
|
13
|
+
const publicDir = path.resolve(__dirname, '../server/public')
|
|
14
|
+
const read = (name) => fs.readFileSync(path.join(publicDir, name), 'utf8')
|
|
15
|
+
const barScript = read('agent-bar.js')
|
|
16
|
+
const appScript = read('agent-bar-app.js')
|
|
17
|
+
const agentsScript = read('agent-bar-agents.js')
|
|
18
|
+
|
|
19
|
+
const TOOL_KEY = 'pinokio.universalLauncher.tool'
|
|
20
|
+
const HOME_PAGE = '<!doctype html><body><header class="navheader"><h1><div class="flexible"></div></h1></header><main id="page"></main></body>'
|
|
21
|
+
const APP_PAGE = '<!doctype html><body class="app-page"><header class="navheader"><h1>'
|
|
22
|
+
+ '<div class="app-header-identity"><span class="app-header-identity-title">Demo App</span></div>'
|
|
23
|
+
+ '<button id="ask-ai-tab" data-workspace-cwd="/home/api/demo"></button><div class="flexible"></div></h1></header>'
|
|
24
|
+
+ '<div class="appcanvas"><aside id="app-sidebar"><div class="menu-scroller"></div></aside><main id="page"></main>'
|
|
25
|
+
+ '<div class="mobile-bottom-nav"><div class="mobile-bottom-nav__identity"></div></div></div></body>'
|
|
26
|
+
|
|
27
|
+
const MENU = [
|
|
28
|
+
{ href: '/run/plugin/opencode/pinokio.js', title: 'Opencode' },
|
|
29
|
+
{ href: '/run/plugin/claude/pinokio.js', title: 'Claude Code', default: true },
|
|
30
|
+
{ href: '/run/plugin/claude-auto/pinokio.js', title: 'Claude Code Auto' },
|
|
31
|
+
{ href: '/run/plugin/Devin/pinokio.js', title: 'Devin CLI' },
|
|
32
|
+
{ href: '/run/plugin/Devin.git/pinokio.js', title: 'Devin CLI' },
|
|
33
|
+
{ href: '/run/plugin/vscode/pinokio.js', title: 'VS Code', category: 'ide' },
|
|
34
|
+
{ href: '/run/plugin/claude-desktop/pinokio.js', title: 'Claude Desktop', category: 'ide' },
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
async function settle(window) {
|
|
38
|
+
for (let i = 0; i < 4; i += 1) await new Promise((resolve) => window.setTimeout(resolve, 0))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function page(t, options = {}) {
|
|
42
|
+
const media = new Set(options.media || [])
|
|
43
|
+
const dom = new JSDOM(options.app ? APP_PAGE : HOME_PAGE, {
|
|
44
|
+
url: `http://127.0.0.1:42000/${options.app ? 'p/demo' : 'home'}`,
|
|
45
|
+
runScripts: 'outside-only',
|
|
46
|
+
pretendToBeVisual: true,
|
|
47
|
+
beforeParse(window) {
|
|
48
|
+
window.matchMedia = (query) => ({ matches: media.has(query), addEventListener() {}, removeEventListener() {} })
|
|
49
|
+
window.fetch = async (url) => {
|
|
50
|
+
if (String(url) === '/info/shells') return { ok: true, json: async () => [] }
|
|
51
|
+
if (String(url).split('?')[0] === '/api/plugin/menu') {
|
|
52
|
+
return { ok: true, json: async () => ({ menu: options.menu || MENU }) }
|
|
53
|
+
}
|
|
54
|
+
return { ok: false, json: async () => ({ ok: false, error: 'not sent in this test' }) }
|
|
55
|
+
}
|
|
56
|
+
if (options.stored) window.localStorage.setItem(TOOL_KEY, options.stored)
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
t.after(() => dom.window.close())
|
|
60
|
+
const { window } = dom
|
|
61
|
+
const { document } = window
|
|
62
|
+
window.eval(barScript)
|
|
63
|
+
if (options.app) window.eval(appScript)
|
|
64
|
+
window.eval(agentsScript)
|
|
65
|
+
await window.PinokioAgentBar.ready
|
|
66
|
+
await settle(window)
|
|
67
|
+
const root = document.querySelector('.agent-bar')
|
|
68
|
+
const menu = root.querySelector('.agent-bar__menu')
|
|
69
|
+
const search = () => menu.querySelector('.agent-menu__input')
|
|
70
|
+
const p = {
|
|
71
|
+
window,
|
|
72
|
+
document,
|
|
73
|
+
root,
|
|
74
|
+
menu,
|
|
75
|
+
search,
|
|
76
|
+
tabs: () => menu.querySelector('.agent-menu__tabs'),
|
|
77
|
+
tab: (key) => menu.querySelector(`.agent-menu__tab[data-tab="${key}"]`),
|
|
78
|
+
selectedTab: () => menu.querySelector('.agent-menu__tab[aria-selected="true"]').dataset.tab,
|
|
79
|
+
count: (key) => p.tab(key).querySelector('.agent-menu__count').textContent,
|
|
80
|
+
labels: () => Array.from(menu.querySelectorAll('.agent-menu__list .agent-bar__row-label')).map((node) => node.textContent),
|
|
81
|
+
notes: () => Array.from(menu.querySelectorAll('.agent-menu__list .agent-bar__row'))
|
|
82
|
+
.map((row) => (row.querySelector('.agent-bar__row-note') || {}).textContent || ''),
|
|
83
|
+
titles: () => Array.from(menu.querySelectorAll('.agent-menu__list .agent-bar__menu-title')).map((node) => node.textContent),
|
|
84
|
+
lit: () => {
|
|
85
|
+
const row = menu.querySelector('.agent-menu__list .agent-bar__row.is-active')
|
|
86
|
+
return row ? row.querySelector('.agent-bar__row-label').textContent : null
|
|
87
|
+
},
|
|
88
|
+
checked: () => Array.from(menu.querySelectorAll('.agent-menu__list .agent-bar__row'))
|
|
89
|
+
.filter((row) => row.querySelector('.agent-bar__row-check'))
|
|
90
|
+
.map((row) => row.querySelector('.agent-bar__row-label').textContent),
|
|
91
|
+
async open() {
|
|
92
|
+
root.querySelector('.agent-bar__agent').click()
|
|
93
|
+
await settle(window)
|
|
94
|
+
},
|
|
95
|
+
async type(text) {
|
|
96
|
+
search().value = text
|
|
97
|
+
search().dispatchEvent(new window.Event('input', { bubbles: true }))
|
|
98
|
+
await settle(window)
|
|
99
|
+
},
|
|
100
|
+
async key(key) {
|
|
101
|
+
const event = new window.KeyboardEvent('keydown', { key, bubbles: true, cancelable: true })
|
|
102
|
+
document.activeElement.dispatchEvent(event)
|
|
103
|
+
await settle(window)
|
|
104
|
+
},
|
|
105
|
+
}
|
|
106
|
+
return p
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
test('the menu has a search box and two tabs with counts, and opens on Terminal', async (t) => {
|
|
110
|
+
const p = await page(t)
|
|
111
|
+
await p.open()
|
|
112
|
+
assert.equal(p.menu.hidden, false)
|
|
113
|
+
assert.equal(p.menu.dataset.menu, 'agent')
|
|
114
|
+
assert.ok(p.search(), 'there is a search box')
|
|
115
|
+
assert.equal(p.tabs().hidden, false)
|
|
116
|
+
assert.equal(p.count('terminal'), '5')
|
|
117
|
+
assert.equal(p.count('desktop'), '2')
|
|
118
|
+
assert.equal(p.selectedTab(), 'terminal')
|
|
119
|
+
assert.deepEqual(p.labels(), ['Claude Code', 'Claude Code Auto', 'Devin CLI', 'Devin CLI', 'Opencode'])
|
|
120
|
+
assert.deepEqual(p.checked(), ['Claude Code'], 'the default agent is marked')
|
|
121
|
+
assert.equal(p.document.activeElement, p.search(), 'the search box takes the cursor')
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
test('a tab shows its own agents', async (t) => {
|
|
125
|
+
const p = await page(t)
|
|
126
|
+
await p.open()
|
|
127
|
+
p.tab('desktop').click()
|
|
128
|
+
await settle(p.window)
|
|
129
|
+
assert.equal(p.selectedTab(), 'desktop')
|
|
130
|
+
assert.deepEqual(p.labels(), ['Claude Desktop', 'VS Code'])
|
|
131
|
+
assert.equal(p.menu.hidden, false, 'the menu stays open')
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
test('the menu opens on the tab that holds the chosen agent', async (t) => {
|
|
135
|
+
const p = await page(t, { stored: 'vscode' })
|
|
136
|
+
await p.open()
|
|
137
|
+
assert.equal(p.selectedTab(), 'desktop')
|
|
138
|
+
assert.deepEqual(p.checked(), ['VS Code'])
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test('agents with the same name show their folder names', async (t) => {
|
|
142
|
+
const p = await page(t)
|
|
143
|
+
await p.open()
|
|
144
|
+
assert.deepEqual(p.notes(), ['', '', 'Devin', 'Devin.git', ''])
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test('typing searches both tabs, by name and by folder name', async (t) => {
|
|
148
|
+
const p = await page(t)
|
|
149
|
+
await p.open()
|
|
150
|
+
await p.type('claude')
|
|
151
|
+
assert.equal(p.tabs().hidden, true, 'the tabs step aside')
|
|
152
|
+
assert.deepEqual(p.titles(), ['Terminal', 'Desktop'])
|
|
153
|
+
assert.deepEqual(p.labels(), ['Claude Code', 'Claude Code Auto', 'Claude Desktop'])
|
|
154
|
+
assert.equal(p.lit(), 'Claude Code', 'the first match is lit')
|
|
155
|
+
|
|
156
|
+
await p.type('devin.git')
|
|
157
|
+
assert.deepEqual(p.labels(), ['Devin CLI'])
|
|
158
|
+
assert.deepEqual(p.notes(), ['Devin.git'])
|
|
159
|
+
|
|
160
|
+
await p.type('code auto')
|
|
161
|
+
assert.deepEqual(p.labels(), ['Claude Code Auto'], 'every word has to match')
|
|
162
|
+
|
|
163
|
+
await p.type('zzz')
|
|
164
|
+
assert.deepEqual(p.labels(), [])
|
|
165
|
+
assert.match(p.menu.querySelector('.agent-menu__list').textContent, /No agents match “zzz”/)
|
|
166
|
+
|
|
167
|
+
await p.type('')
|
|
168
|
+
assert.equal(p.tabs().hidden, false, 'the tabs come back')
|
|
169
|
+
assert.equal(p.lit(), null)
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
test('Up and Down move the lit row and Enter picks it', async (t) => {
|
|
173
|
+
const p = await page(t)
|
|
174
|
+
await p.open()
|
|
175
|
+
await p.type('claude')
|
|
176
|
+
await p.key('ArrowDown')
|
|
177
|
+
assert.equal(p.lit(), 'Claude Code Auto')
|
|
178
|
+
await p.key('ArrowDown')
|
|
179
|
+
await p.key('ArrowDown')
|
|
180
|
+
assert.equal(p.lit(), 'Claude Desktop', 'it stops at the last row')
|
|
181
|
+
await p.key('ArrowUp')
|
|
182
|
+
assert.equal(p.lit(), 'Claude Code Auto')
|
|
183
|
+
await p.key('Enter')
|
|
184
|
+
assert.equal(p.menu.hidden, true, 'the menu closes')
|
|
185
|
+
assert.equal(p.window.localStorage.getItem(TOOL_KEY), 'claude-auto', 'the pick is remembered')
|
|
186
|
+
assert.equal(p.root.querySelector('.agent-bar__agent').title, 'Runs with Claude Code Auto')
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
test('a click on a row picks it', async (t) => {
|
|
190
|
+
const p = await page(t)
|
|
191
|
+
await p.open()
|
|
192
|
+
p.tab('desktop').click()
|
|
193
|
+
await settle(p.window)
|
|
194
|
+
p.menu.querySelectorAll('.agent-menu__list .agent-bar__row')[1].click()
|
|
195
|
+
await settle(p.window)
|
|
196
|
+
assert.equal(p.menu.hidden, true)
|
|
197
|
+
assert.equal(p.window.localStorage.getItem(TOOL_KEY), 'vscode')
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
test('Escape clears the text first, then closes the menu', async (t) => {
|
|
201
|
+
const p = await page(t)
|
|
202
|
+
await p.open()
|
|
203
|
+
await p.type('open')
|
|
204
|
+
await p.key('Escape')
|
|
205
|
+
assert.equal(p.menu.hidden, false, 'the menu stays')
|
|
206
|
+
assert.equal(p.search().value, '')
|
|
207
|
+
assert.equal(p.tabs().hidden, false)
|
|
208
|
+
await p.key('Escape')
|
|
209
|
+
assert.equal(p.menu.hidden, true)
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
test('a redraw of the bar keeps what was typed, the tab and the cursor', async (t) => {
|
|
213
|
+
const p = await page(t)
|
|
214
|
+
await p.open()
|
|
215
|
+
p.tab('desktop').click()
|
|
216
|
+
await settle(p.window)
|
|
217
|
+
p.search().focus()
|
|
218
|
+
p.window.PinokioAgentBar.refresh()
|
|
219
|
+
await settle(p.window)
|
|
220
|
+
assert.equal(p.selectedTab(), 'desktop')
|
|
221
|
+
assert.equal(p.document.activeElement, p.search())
|
|
222
|
+
|
|
223
|
+
await p.type('vs')
|
|
224
|
+
p.search().setSelectionRange(1, 1)
|
|
225
|
+
p.search().dispatchEvent(new p.window.KeyboardEvent('keyup', { key: 'ArrowLeft', bubbles: true }))
|
|
226
|
+
p.window.PinokioAgentBar.refresh()
|
|
227
|
+
p.window.PinokioAgentBar.refresh()
|
|
228
|
+
await settle(p.window)
|
|
229
|
+
assert.equal(p.search().value, 'vs')
|
|
230
|
+
assert.deepEqual(p.labels(), ['VS Code'])
|
|
231
|
+
assert.equal(p.document.activeElement, p.search())
|
|
232
|
+
assert.equal(p.search().selectionStart, 1, 'the cursor is where it was')
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
test('each opening starts over', async (t) => {
|
|
236
|
+
const p = await page(t)
|
|
237
|
+
await p.open()
|
|
238
|
+
p.tab('desktop').click()
|
|
239
|
+
await settle(p.window)
|
|
240
|
+
await p.type('vs')
|
|
241
|
+
await p.open()
|
|
242
|
+
assert.equal(p.menu.hidden, true)
|
|
243
|
+
await p.open()
|
|
244
|
+
assert.equal(p.search().value, '')
|
|
245
|
+
assert.equal(p.selectedTab(), 'terminal')
|
|
246
|
+
assert.equal(p.tabs().hidden, false)
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
test('the bar\'s other menus, which use the same box, keep their own look', async (t) => {
|
|
250
|
+
const p = await page(t)
|
|
251
|
+
await p.open()
|
|
252
|
+
assert.ok(p.menu.classList.contains('agent-menu'))
|
|
253
|
+
p.root.querySelector('.agent-bar__scope').click()
|
|
254
|
+
await settle(p.window)
|
|
255
|
+
assert.equal(p.menu.dataset.menu, 'mode')
|
|
256
|
+
assert.equal(p.menu.classList.contains('agent-menu'), false)
|
|
257
|
+
assert.equal(p.menu.querySelector('.agent-menu__head'), null)
|
|
258
|
+
assert.equal(p.menu.querySelectorAll('.agent-bar__row').length, 4, 'the four modes')
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
test('with only one kind of agent there are no tabs', async (t) => {
|
|
262
|
+
const p = await page(t, { menu: MENU.filter((plugin) => plugin.category !== 'ide') })
|
|
263
|
+
await p.open()
|
|
264
|
+
assert.equal(p.tabs().hidden, true)
|
|
265
|
+
assert.equal(p.labels().length, 5)
|
|
266
|
+
await p.type('code')
|
|
267
|
+
assert.deepEqual(p.titles(), [], 'no headings either')
|
|
268
|
+
assert.deepEqual(p.labels(), ['Claude Code', 'Claude Code Auto', 'Opencode'])
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
test('on a touch screen the search box does not take the cursor', async (t) => {
|
|
272
|
+
const p = await page(t, { media: ['(hover: none)'] })
|
|
273
|
+
await p.open()
|
|
274
|
+
assert.equal(p.menu.hidden, false)
|
|
275
|
+
assert.notEqual(p.document.activeElement, p.search())
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
test('a press on a tab leaves the cursor where it is', async (t) => {
|
|
279
|
+
const p = await page(t)
|
|
280
|
+
await p.open()
|
|
281
|
+
const press = new p.window.MouseEvent('pointerdown', { bubbles: true, cancelable: true })
|
|
282
|
+
p.tab('desktop').dispatchEvent(press)
|
|
283
|
+
assert.equal(press.defaultPrevented, true)
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
test('the app page\'s bar has the same menu', async (t) => {
|
|
287
|
+
const p = await page(t, { app: true })
|
|
288
|
+
await p.open()
|
|
289
|
+
assert.equal(p.menu.hidden, false)
|
|
290
|
+
assert.equal(p.tabs().hidden, false)
|
|
291
|
+
assert.equal(p.count('terminal'), '5')
|
|
292
|
+
await p.type('desktop')
|
|
293
|
+
assert.deepEqual(p.labels(), ['Claude Desktop'])
|
|
294
|
+
await p.key('Enter')
|
|
295
|
+
assert.equal(p.menu.hidden, true)
|
|
296
|
+
assert.equal(p.window.localStorage.getItem(TOOL_KEY), 'claude-desktop')
|
|
297
|
+
})
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
// The card for a plugin that opens a desktop app (server/public/agent-bar-launch.js).
|
|
2
|
+
//
|
|
3
|
+
// The real script runs here with the bar's real helpers. The plugin's page is a
|
|
4
|
+
// stand-in that has only what the card looks for (the page's Stop, the folder
|
|
5
|
+
// question), and what that page would tell its parent is sent by the test.
|
|
6
|
+
// Layout and the look of the card are not covered: this page lays nothing out.
|
|
7
|
+
const assert = require('node:assert/strict')
|
|
8
|
+
const fs = require('node:fs')
|
|
9
|
+
const path = require('node:path')
|
|
10
|
+
const test = require('node:test')
|
|
11
|
+
const { JSDOM, ResourceLoader } = require('jsdom')
|
|
12
|
+
|
|
13
|
+
const script = (name) => fs.readFileSync(path.resolve(__dirname, '../server/public', name), 'utf8')
|
|
14
|
+
|
|
15
|
+
class PluginPage extends ResourceLoader {
|
|
16
|
+
fetch() {
|
|
17
|
+
const page = Promise.resolve(Buffer.from('<!doctype html><div class="run"><button class="stop"></button></div><div id="terminal"></div>'))
|
|
18
|
+
// a page still on its way when the test's window closes
|
|
19
|
+
page.abort = () => {}
|
|
20
|
+
return page
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const MENU = {
|
|
25
|
+
menu: [
|
|
26
|
+
{ href: '/pinokio/run/plugin/codex/pinokio.js', title: 'Codex', category: 'cli', default: true },
|
|
27
|
+
{ href: '/pinokio/run/plugin/codex-desktop/pinokio.js', title: 'Codex Desktop', category: 'ide', link: 'https://openai.com/codex', image: '/codex.png' },
|
|
28
|
+
{ href: '/pinokio/run/plugin/cursor/pinokio.js', title: 'Cursor', category: 'ide', link: 'https://cursor.com' },
|
|
29
|
+
],
|
|
30
|
+
}
|
|
31
|
+
const DESKTOP = '/pinokio/run/plugin/codex-desktop/pinokio.js?cwd=%2Fhome%2Fapi%2Fdemo&session=s1&ask_ai=1'
|
|
32
|
+
const pause = (window, ms) => new Promise((resolve) => window.setTimeout(resolve, ms))
|
|
33
|
+
|
|
34
|
+
async function page(t, options = {}) {
|
|
35
|
+
const dom = new JSDOM('<!doctype html><body class="main-sidebar-page"><header class="navheader"><h1><div class="flexible"></div></h1></header></body>', {
|
|
36
|
+
url: 'http://127.0.0.1:42000/home',
|
|
37
|
+
resources: new PluginPage(),
|
|
38
|
+
runScripts: 'outside-only',
|
|
39
|
+
pretendToBeVisual: true,
|
|
40
|
+
})
|
|
41
|
+
t.after(() => dom.window.close())
|
|
42
|
+
const { window } = dom
|
|
43
|
+
const { document } = window
|
|
44
|
+
window.innerWidth = 1760
|
|
45
|
+
window.matchMedia = () => ({ matches: false, addEventListener() {}, removeEventListener() {} })
|
|
46
|
+
window.Element.prototype.getBoundingClientRect = () => ({ left: 300, top: 8, right: 900, bottom: 40, width: 600, height: 32 })
|
|
47
|
+
window.fetch = async (url) => {
|
|
48
|
+
if (url === '/info/shells') return { ok: true, json: async () => [] }
|
|
49
|
+
return { ok: true, json: async () => MENU }
|
|
50
|
+
}
|
|
51
|
+
const visited = []
|
|
52
|
+
window.open = (...args) => { visited.push(args) }
|
|
53
|
+
const names = ['agent-bar.js', 'agent-bar-launch.js'].concat(options.dock ? ['agent-bar-panel.js'] : [])
|
|
54
|
+
for (const name of names) window.eval(script(name))
|
|
55
|
+
await window.PinokioAgentBar.ready
|
|
56
|
+
const launch = window.PinokioAgentBarLaunch
|
|
57
|
+
Object.assign(launch.times, { close: 60, start: 400, run: 400, answer: 80, poll: 10 }, options.times)
|
|
58
|
+
|
|
59
|
+
const H = window.PinokioAgentBar.helpers
|
|
60
|
+
const tools = MENU.menu.map((plugin) => Object.assign(H.mapPluginMenuToTools([plugin])[0], { href: plugin.href }))
|
|
61
|
+
const calls = []
|
|
62
|
+
const dock = {
|
|
63
|
+
tools,
|
|
64
|
+
open: (session, settings) => calls.push(['open', session.key, settings]),
|
|
65
|
+
show: (session) => calls.push(['show', session.key]),
|
|
66
|
+
}
|
|
67
|
+
const session = { key: '/plugin/codex-desktop/pinokio.js|/home/api/demo|s1', kind: 'agent', label: 'Codex Desktop', placeName: 'demo' }
|
|
68
|
+
const card = () => document.querySelector('.agent-launch__card')
|
|
69
|
+
const frame = () => document.querySelector('.agent-launch__frame')
|
|
70
|
+
// the plugin's page, once it is there, with its Stop presses counted
|
|
71
|
+
const loaded = async () => {
|
|
72
|
+
const target = frame()
|
|
73
|
+
for (let i = 0; i < 100 && !(target.contentDocument && target.contentDocument.querySelector('.stop')); i += 1) await pause(window, 10)
|
|
74
|
+
const doc = target.contentDocument
|
|
75
|
+
const pressed = { stop: 0 }
|
|
76
|
+
doc.querySelector('.stop').addEventListener('click', () => { pressed.stop += 1 })
|
|
77
|
+
return { doc, pressed }
|
|
78
|
+
}
|
|
79
|
+
// what the plugin's page tells the page it is shown in
|
|
80
|
+
const tell = (data, source) => window.dispatchEvent(new window.MessageEvent('message', { data, source: source || frame().contentWindow }))
|
|
81
|
+
const step = (name, data) => tell({ type: 'pinokio:session-step', step: name, data })
|
|
82
|
+
const text = (selector) => {
|
|
83
|
+
const node = card() && card().querySelector(selector)
|
|
84
|
+
return node && !node.hidden ? node.textContent : ''
|
|
85
|
+
}
|
|
86
|
+
const buttons = () => Array.from(card().querySelectorAll('.agent-launch__actions button')).map((button) => button.textContent)
|
|
87
|
+
const press = (label) => Array.from(card().querySelectorAll('.agent-launch__actions button')).find((button) => button.textContent === label).click()
|
|
88
|
+
return { window, document, launch, dock, calls, session, card, frame, loaded, tell, step, text, buttons, press, visited }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
test('a plugin that runs in a terminal is left to the dock', { timeout: 5000 }, async (t) => {
|
|
92
|
+
const p = await page(t)
|
|
93
|
+
const taken = p.launch.take({ key: 'k', kind: 'agent' }, '/pinokio/run/plugin/codex/pinokio.js?cwd=%2Fhome%2Fapi%2Fdemo', p.dock)
|
|
94
|
+
assert.equal(taken, false)
|
|
95
|
+
assert.equal(p.card(), null)
|
|
96
|
+
// so is a shell, and a plugin the list does not know
|
|
97
|
+
assert.equal(p.launch.take({ key: 's', kind: 'shell' }, DESKTOP, p.dock), false)
|
|
98
|
+
assert.equal(p.launch.take({ key: 'u', kind: 'agent' }, '/pinokio/run/plugin/unknown/pinokio.js', p.dock), false)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('a desktop app: opening, then opened, then the card closes by itself', { timeout: 5000 }, async (t) => {
|
|
102
|
+
const p = await page(t)
|
|
103
|
+
assert.equal(p.launch.take(p.session, DESKTOP, p.dock), true)
|
|
104
|
+
assert.equal(p.card().dataset.open, 'true')
|
|
105
|
+
assert.equal(p.text('.agent-launch__title'), 'Opening Codex Desktop…')
|
|
106
|
+
assert.equal(p.text('.agent-launch__sub'), 'demo')
|
|
107
|
+
assert.ok(p.card().querySelector('.agent-launch__spinner'))
|
|
108
|
+
assert.equal(p.card().querySelector('.agent-launch__close').hidden, true)
|
|
109
|
+
// the plugin is started by loading its own page, with what was asked
|
|
110
|
+
assert.equal(new URL(p.frame().src).pathname + new URL(p.frame().src).search, DESKTOP)
|
|
111
|
+
assert.ok(p.frame().hasAttribute('data-skip-startup-focus'))
|
|
112
|
+
|
|
113
|
+
const { pressed } = await p.loaded()
|
|
114
|
+
p.tell({ type: 'start', data: { current: 0, total: 2 } })
|
|
115
|
+
assert.equal(p.text('.agent-launch__title'), 'Opening Codex Desktop…')
|
|
116
|
+
// the plugin has reached its step that waits for Stop: the app is open
|
|
117
|
+
p.step('process.wait.start', { title: 'Launched', description: 'Click the stop button to stop watching file changes' })
|
|
118
|
+
assert.equal(p.text('.agent-launch__title'), 'Opened in Codex Desktop')
|
|
119
|
+
assert.ok(p.card().querySelector('.agent-launch__check'))
|
|
120
|
+
assert.equal(pressed.stop, 1, 'the page\'s own Stop ends the waiting plugin')
|
|
121
|
+
assert.equal(p.card().querySelector('.agent-launch__timer').hidden, false)
|
|
122
|
+
|
|
123
|
+
await pause(p.window, 150)
|
|
124
|
+
assert.equal(p.card().dataset.open, 'false')
|
|
125
|
+
await pause(p.window, 300)
|
|
126
|
+
assert.equal(p.card(), null, 'the card, and the page in it, are gone')
|
|
127
|
+
assert.deepEqual(p.calls, [], 'the dock is asked for no window')
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
test('pointing at the card holds it open', { timeout: 5000 }, async (t) => {
|
|
131
|
+
const p = await page(t)
|
|
132
|
+
p.launch.take(p.session, DESKTOP, p.dock)
|
|
133
|
+
await p.loaded()
|
|
134
|
+
p.tell({ type: 'start' })
|
|
135
|
+
p.step('process.wait.start', {})
|
|
136
|
+
p.card().dispatchEvent(new p.window.MouseEvent('mouseenter'))
|
|
137
|
+
await pause(p.window, 200)
|
|
138
|
+
assert.equal(p.card().dataset.open, 'true')
|
|
139
|
+
p.card().dispatchEvent(new p.window.MouseEvent('mouseleave'))
|
|
140
|
+
await pause(p.window, 150)
|
|
141
|
+
assert.equal(p.card().dataset.open, 'false')
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
test('a plugin whose steps simply end has opened the app too, and nothing is stopped', { timeout: 5000 }, async (t) => {
|
|
145
|
+
const p = await page(t)
|
|
146
|
+
p.launch.take(Object.assign({}, p.session, { key: 'cursor' }), '/pinokio/run/plugin/cursor/pinokio.js?cwd=%2Fhome%2Fapi%2Fdemo', p.dock)
|
|
147
|
+
const { pressed } = await p.loaded()
|
|
148
|
+
// an end before any start is not this plugin's end
|
|
149
|
+
p.tell({ type: 'disconnect' })
|
|
150
|
+
assert.equal(p.text('.agent-launch__title'), 'Opening Cursor…')
|
|
151
|
+
p.tell({ type: 'start' })
|
|
152
|
+
p.tell({ type: 'disconnect' })
|
|
153
|
+
assert.equal(p.text('.agent-launch__title'), 'Opened in Cursor')
|
|
154
|
+
assert.equal(pressed.stop, 0)
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
test('a step that waits for something else is not "opened"', { timeout: 5000 }, async (t) => {
|
|
158
|
+
const p = await page(t)
|
|
159
|
+
p.launch.take(p.session, DESKTOP, p.dock)
|
|
160
|
+
await p.loaded()
|
|
161
|
+
p.tell({ type: 'start' })
|
|
162
|
+
p.step('process.wait.start', { title: 'Warming up', sec: 5 })
|
|
163
|
+
p.step('process.wait.start', { title: 'Waiting for the server', url: 'http://localhost:1234' })
|
|
164
|
+
assert.equal(p.text('.agent-launch__title'), 'Opening Codex Desktop…')
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
test('an error keeps the card, with the reason, the plugin\'s homepage and a way to try again', { timeout: 5000 }, async (t) => {
|
|
168
|
+
const p = await page(t)
|
|
169
|
+
p.launch.take(p.session, DESKTOP, p.dock)
|
|
170
|
+
await p.loaded()
|
|
171
|
+
const first = p.frame()
|
|
172
|
+
p.tell({ type: 'start' })
|
|
173
|
+
p.step('error', 'Error: Nothing on this computer could open the codex: link. The app for it may not be installed.\nopen exited with code 1\n at URI.open (/kernel/api/uri/index.js:50:13)')
|
|
174
|
+
// the end that follows an error changes nothing
|
|
175
|
+
p.tell({ type: 'disconnect' })
|
|
176
|
+
await pause(p.window, 20)
|
|
177
|
+
assert.equal(p.text('.agent-launch__title'), 'Couldn\'t open Codex Desktop')
|
|
178
|
+
assert.equal(p.text('.agent-launch__sub'), 'Nothing on this computer could open the codex: link. The app for it may not be installed.')
|
|
179
|
+
assert.ok(p.card().querySelector('.agent-launch__warn'))
|
|
180
|
+
assert.deepEqual(p.buttons(), ['Get Codex Desktop', 'Try again', 'Show details'])
|
|
181
|
+
assert.equal(p.card().querySelector('.agent-launch__close').hidden, false)
|
|
182
|
+
|
|
183
|
+
const details = p.card().querySelector('.agent-launch__details')
|
|
184
|
+
assert.equal(details.hidden, true)
|
|
185
|
+
p.press('Show details')
|
|
186
|
+
assert.equal(details.hidden, false)
|
|
187
|
+
assert.equal(details.textContent, 'Nothing on this computer could open the codex: link. The app for it may not be installed.\nopen exited with code 1')
|
|
188
|
+
assert.deepEqual(p.buttons(), ['Get Codex Desktop', 'Try again', 'Hide details'])
|
|
189
|
+
|
|
190
|
+
p.press('Get Codex Desktop')
|
|
191
|
+
assert.deepEqual(p.visited, [['https://openai.com/codex', '_blank', 'noopener']])
|
|
192
|
+
|
|
193
|
+
// it stays until it is dismissed
|
|
194
|
+
await pause(p.window, 500)
|
|
195
|
+
assert.equal(p.card().dataset.open, 'true')
|
|
196
|
+
assert.deepEqual(p.calls, [])
|
|
197
|
+
|
|
198
|
+
p.press('Try again')
|
|
199
|
+
assert.equal(p.text('.agent-launch__title'), 'Opening Codex Desktop…')
|
|
200
|
+
assert.notEqual(p.frame(), first, 'the plugin\'s page is loaded again')
|
|
201
|
+
assert.equal(p.document.querySelectorAll('.agent-launch__frame').length, 1)
|
|
202
|
+
assert.deepEqual(p.buttons(), [])
|
|
203
|
+
|
|
204
|
+
p.tell({ type: 'start' })
|
|
205
|
+
p.step('error', 'Error: again')
|
|
206
|
+
await pause(p.window, 20)
|
|
207
|
+
// one line of error: nothing more to show
|
|
208
|
+
assert.deepEqual(p.buttons(), ['Get Codex Desktop', 'Try again'])
|
|
209
|
+
p.card().querySelector('.agent-launch__close').click()
|
|
210
|
+
assert.equal(p.card().dataset.open, 'false')
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
test('a plugin that says something instead keeps the card, with its words and its link', { timeout: 5000 }, async (t) => {
|
|
214
|
+
const p = await page(t)
|
|
215
|
+
p.launch.take(Object.assign({}, p.session, { key: 'cursor' }), '/pinokio/run/plugin/cursor/pinokio.js?cwd=%2Fhome%2Fapi%2Fdemo', p.dock)
|
|
216
|
+
await p.loaded()
|
|
217
|
+
p.tell({ type: 'start' })
|
|
218
|
+
p.step('notify', { html: 'Cursor is <b>not installed</b>. Click to visit the Cursor homepage to download', href: 'https://www.cursor.com', target: '_blank' })
|
|
219
|
+
p.tell({ type: 'disconnect' })
|
|
220
|
+
assert.equal(p.text('.agent-launch__title'), 'Cursor')
|
|
221
|
+
assert.equal(p.text('.agent-launch__sub'), 'Cursor is not installed. Click to visit the Cursor homepage to download')
|
|
222
|
+
assert.deepEqual(p.buttons(), ['Open cursor.com', 'Try again'])
|
|
223
|
+
p.press('Open cursor.com')
|
|
224
|
+
assert.deepEqual(p.visited, [['https://www.cursor.com/', '_blank', 'noopener']])
|
|
225
|
+
await pause(p.window, 500)
|
|
226
|
+
assert.equal(p.card().dataset.open, 'true')
|
|
227
|
+
|
|
228
|
+
// a link that is not a web address gets no button
|
|
229
|
+
p.press('Try again')
|
|
230
|
+
p.tell({ type: 'start' })
|
|
231
|
+
p.step('notify', { html: 'Hello', href: 'javascript:alert(1)' })
|
|
232
|
+
assert.deepEqual(p.buttons(), ['Try again'])
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
test('Pinokio\'s question about the folder is shown in the card', { timeout: 5000 }, async (t) => {
|
|
236
|
+
const p = await page(t, { times: { start: 150 } })
|
|
237
|
+
p.launch.take(p.session, DESKTOP, p.dock)
|
|
238
|
+
const { doc } = await p.loaded()
|
|
239
|
+
assert.equal(p.card().dataset.stage, 'false')
|
|
240
|
+
const question = doc.createElement('div')
|
|
241
|
+
question.className = 'ai-consent-overlay is-visible'
|
|
242
|
+
doc.body.appendChild(question)
|
|
243
|
+
await pause(p.window, 40)
|
|
244
|
+
assert.equal(p.card().dataset.stage, 'true')
|
|
245
|
+
assert.equal(p.text('.agent-launch__title'), 'Codex Desktop needs your OK')
|
|
246
|
+
assert.equal(p.card().querySelector('.agent-launch__close').hidden, false)
|
|
247
|
+
// however long the answer takes, the card waits
|
|
248
|
+
await pause(p.window, 300)
|
|
249
|
+
assert.equal(p.card().dataset.open, 'true')
|
|
250
|
+
assert.deepEqual(p.calls, [])
|
|
251
|
+
|
|
252
|
+
// allowed: the plugin starts and the card carries on
|
|
253
|
+
question.remove()
|
|
254
|
+
await pause(p.window, 40)
|
|
255
|
+
assert.equal(p.card().dataset.stage, 'false')
|
|
256
|
+
assert.equal(p.text('.agent-launch__title'), 'Opening Codex Desktop…')
|
|
257
|
+
p.tell({ type: 'start' })
|
|
258
|
+
p.step('process.wait.start', {})
|
|
259
|
+
assert.equal(p.text('.agent-launch__title'), 'Opened in Codex Desktop')
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
test('the folder question answered and the plugin started before the card looked again: the page is put away', { timeout: 5000 }, async (t) => {
|
|
263
|
+
// the card looks for the question less often than the plugin takes to start
|
|
264
|
+
const p = await page(t, { times: { poll: 60 } })
|
|
265
|
+
p.launch.take(p.session, DESKTOP, p.dock)
|
|
266
|
+
const { doc } = await p.loaded()
|
|
267
|
+
const question = doc.createElement('div')
|
|
268
|
+
question.className = 'ai-consent-overlay is-visible'
|
|
269
|
+
doc.body.appendChild(question)
|
|
270
|
+
await pause(p.window, 120)
|
|
271
|
+
assert.equal(p.card().dataset.stage, 'true')
|
|
272
|
+
question.remove()
|
|
273
|
+
p.tell({ type: 'start' })
|
|
274
|
+
assert.equal(p.card().dataset.stage, 'false')
|
|
275
|
+
assert.equal(p.text('.agent-launch__title'), 'Opening Codex Desktop…')
|
|
276
|
+
p.step('process.wait.start', {})
|
|
277
|
+
assert.equal(p.card().dataset.stage, 'false')
|
|
278
|
+
assert.equal(p.text('.agent-launch__title'), 'Opened in Codex Desktop')
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
test('the folder question cancelled: nothing starts and the card goes', { timeout: 5000 }, async (t) => {
|
|
282
|
+
const p = await page(t)
|
|
283
|
+
p.launch.take(p.session, DESKTOP, p.dock)
|
|
284
|
+
const { doc } = await p.loaded()
|
|
285
|
+
const question = doc.createElement('div')
|
|
286
|
+
question.className = 'ai-consent-overlay is-visible'
|
|
287
|
+
doc.body.appendChild(question)
|
|
288
|
+
await pause(p.window, 40)
|
|
289
|
+
question.remove()
|
|
290
|
+
await pause(p.window, 200)
|
|
291
|
+
assert.equal(p.card().dataset.open, 'false')
|
|
292
|
+
assert.deepEqual(p.calls, [])
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
test('a page that never starts the plugin is handed to the dock, to load in a window', { timeout: 5000 }, async (t) => {
|
|
296
|
+
const p = await page(t, { times: { start: 80 } })
|
|
297
|
+
p.launch.take(p.session, DESKTOP, p.dock)
|
|
298
|
+
await pause(p.window, 200)
|
|
299
|
+
assert.equal(p.card(), null)
|
|
300
|
+
// (the settings object is made in the page, so it is compared as text)
|
|
301
|
+
assert.equal(JSON.stringify(p.calls), JSON.stringify([['open', p.session.key, { launchUrl: DESKTOP, window: true }]]))
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
test('a plugin that starts and gets nowhere is handed to the dock, to show if it still runs', { timeout: 5000 }, async (t) => {
|
|
305
|
+
const p = await page(t, { times: { run: 80 } })
|
|
306
|
+
p.launch.take(p.session, DESKTOP, p.dock)
|
|
307
|
+
await p.loaded()
|
|
308
|
+
p.tell({ type: 'start' })
|
|
309
|
+
// every step says it starts; only the first one counts
|
|
310
|
+
await pause(p.window, 50)
|
|
311
|
+
p.tell({ type: 'start' })
|
|
312
|
+
await pause(p.window, 60)
|
|
313
|
+
assert.equal(p.card(), null)
|
|
314
|
+
assert.deepEqual(p.calls, [['show', p.session.key]])
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
test('only the card\'s own page is listened to', { timeout: 5000 }, async (t) => {
|
|
318
|
+
const p = await page(t)
|
|
319
|
+
p.launch.take(p.session, DESKTOP, p.dock)
|
|
320
|
+
await p.loaded()
|
|
321
|
+
p.tell({ type: 'start' }, p.window)
|
|
322
|
+
p.tell({ type: 'pinokio:session-step', step: 'error', data: 'Error: from another page' }, p.window)
|
|
323
|
+
p.tell({ type: 'disconnect' }, null)
|
|
324
|
+
assert.equal(p.text('.agent-launch__title'), 'Opening Codex Desktop…')
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
test('the same launch sent again replaces its card', { timeout: 5000 }, async (t) => {
|
|
328
|
+
const p = await page(t)
|
|
329
|
+
p.launch.take(p.session, DESKTOP, p.dock)
|
|
330
|
+
p.launch.take(p.session, DESKTOP, p.dock)
|
|
331
|
+
assert.equal(p.document.querySelectorAll('.agent-launch__card').length, 1)
|
|
332
|
+
p.launch.take(Object.assign({}, p.session, { key: 'other' }), DESKTOP, p.dock)
|
|
333
|
+
assert.equal(p.document.querySelectorAll('.agent-launch__card').length, 2)
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
test('the dock: a desktop app gets the card and no window or tab; a terminal agent gets its window', { timeout: 5000 }, async (t) => {
|
|
337
|
+
const p = await page(t, { dock: true })
|
|
338
|
+
const { document, window } = p
|
|
339
|
+
for (let i = 0; i < 50 && typeof window.PinokioAgentBar.deliver !== 'function'; i += 1) await pause(window, 10)
|
|
340
|
+
// the dock knows the plugins before a send
|
|
341
|
+
await pause(window, 50)
|
|
342
|
+
|
|
343
|
+
assert.equal(window.PinokioAgentBar.deliver({
|
|
344
|
+
type: 'ask', cwd: '/home/api/demo', prompt: 'hello', tool: { label: 'Codex Desktop' },
|
|
345
|
+
url: '/pinokio/run/plugin/codex-desktop/pinokio.js?cwd=%2Fhome%2Fapi%2Fdemo&session=s1&ask_ai=1&prompt=hello',
|
|
346
|
+
}), true)
|
|
347
|
+
assert.equal(document.querySelectorAll('.agent-launch__card').length, 1)
|
|
348
|
+
assert.equal(document.querySelectorAll('.agent-bar-panel').length, 0)
|
|
349
|
+
assert.equal(document.querySelectorAll('.agent-dock__tab').length, 0)
|
|
350
|
+
assert.equal(new URL(p.frame().src).searchParams.get('prompt'), 'hello')
|
|
351
|
+
|
|
352
|
+
assert.equal(window.PinokioAgentBar.deliver({
|
|
353
|
+
type: 'ask', cwd: '/home/api/demo', prompt: 'hello', tool: { label: 'Codex' },
|
|
354
|
+
url: '/pinokio/run/plugin/codex/pinokio.js?cwd=%2Fhome%2Fapi%2Fdemo&session=s2&ask_ai=1&prompt=hello',
|
|
355
|
+
}), true)
|
|
356
|
+
assert.equal(document.querySelectorAll('.agent-launch__card').length, 1)
|
|
357
|
+
assert.equal(document.querySelectorAll('.agent-bar-panel').length, 1)
|
|
358
|
+
})
|
|
359
|
+
|
|
360
|
+
test('the dock: a launch the card hands back opens in a window', { timeout: 5000 }, async (t) => {
|
|
361
|
+
const p = await page(t, { dock: true, times: { start: 60 } })
|
|
362
|
+
const { document, window } = p
|
|
363
|
+
for (let i = 0; i < 50 && typeof window.PinokioAgentBar.deliver !== 'function'; i += 1) await pause(window, 10)
|
|
364
|
+
await pause(window, 50)
|
|
365
|
+
window.PinokioAgentBar.deliver({
|
|
366
|
+
type: 'ask', cwd: '/home/api/demo', tool: { label: 'Codex Desktop' },
|
|
367
|
+
url: '/pinokio/run/plugin/codex-desktop/pinokio.js?cwd=%2Fhome%2Fapi%2Fdemo&session=s1&ask_ai=1',
|
|
368
|
+
})
|
|
369
|
+
assert.equal(document.querySelectorAll('.agent-bar-panel').length, 0)
|
|
370
|
+
await pause(window, 150)
|
|
371
|
+
assert.equal(document.querySelectorAll('.agent-launch__card').length, 0)
|
|
372
|
+
const frame = document.querySelector('.agent-bar-panel .agent-bar-panel__frame')
|
|
373
|
+
assert.ok(frame, 'the session\'s page is in a dock window')
|
|
374
|
+
assert.equal(new URL(frame.src).pathname, '/pinokio/run/plugin/codex-desktop/pinokio.js')
|
|
375
|
+
})
|