pinokiod 8.4.0 → 8.4.1

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,146 @@
1
+ // A plugin is started with the user's request as one line (`args.prompt`), and
2
+ // its author decides whether the tool's command carries it. When the command
3
+ // leaves it out, the tool opens empty and the request would be lost without a
4
+ // word. This page then says so in a strip above the terminal, with a button
5
+ // that sends the request line to the tool: the line goes into the tool's input
6
+ // and Enter follows. The user presses it when they see the tool is ready.
7
+ //
8
+ // How the page knows: Pinokio tells it every step it starts, with the step's
9
+ // values filled in. A step that takes typing (`shell.run` with `input: true`)
10
+ // whose values do not hold the request line, after no earlier step that did,
11
+ // is a tool started without the request. Nothing is read from the screen and
12
+ // nothing is timed.
13
+ //
14
+ // The line goes in through the terminal itself, as a paste and then the Enter
15
+ // key, so it reaches the tool the way the user's own paste and key do. Enter
16
+ // comes a moment after the paste: a tool takes keys that arrive with a paste as
17
+ // part of the pasted text, and Enter would then be a new line in the box, not
18
+ // "send".
19
+ (function () {
20
+ const query = new URLSearchParams(window.location.search);
21
+ const line = (query.get('prompt') || '').trim();
22
+ // one answer per session: pasted or dismissed, the strip stays away; still
23
+ // showing, it comes back when the page is loaded again
24
+ const key = `pinokio:request-strip:${query.get('session') || window.location.pathname + window.location.search}`;
25
+ const recall = () => {
26
+ try {
27
+ return window.sessionStorage.getItem(key);
28
+ } catch (_) {
29
+ return null;
30
+ }
31
+ };
32
+ const remember = (value) => {
33
+ try {
34
+ window.sessionStorage.setItem(key, value);
35
+ } catch (_) {}
36
+ };
37
+
38
+ let passed = false;
39
+ let strip = null;
40
+ let term = null;
41
+
42
+ // The step's values hold the request line, as it is or the way JSON writes it.
43
+ function carries(step) {
44
+ if (!line) return false;
45
+ let values = '';
46
+ try {
47
+ values = JSON.stringify(step.params || null);
48
+ } catch (_) {
49
+ return false;
50
+ }
51
+ return values.includes(line) || values.includes(JSON.stringify(line).slice(1, -1));
52
+ }
53
+
54
+ function addStyle() {
55
+ if (document.getElementById('request-strip-style')) return;
56
+ const style = document.createElement('style');
57
+ style.id = 'request-strip-style';
58
+ style.textContent = `
59
+ .request-strip ~ #terminal { flex: 1 1 0; min-height: 0; height: auto; }
60
+ .request-strip { flex: none; display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 12px; font: 12px/16px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: #fdf3d7; color: #5c4200; border-bottom: 1px solid #ecd9a0; }
61
+ body.dark .request-strip { background: #33290f; color: #f1dca2; border-bottom-color: #4d3f17; }
62
+ .request-strip__text { flex: 1; min-width: 0; }
63
+ .request-strip__title { font-weight: 600; }
64
+ .request-strip__send { flex: none; height: 26px; padding: 0 11px; border: 0; border-radius: 7px; font: inherit; font-weight: 600; cursor: pointer; background: #5c4200; color: #fdf3d7; white-space: nowrap; }
65
+ body.dark .request-strip__send { background: #f1dca2; color: #33290f; }
66
+ .request-strip__close { flex: none; width: 26px; height: 26px; border: 0; border-radius: 7px; background: transparent; color: inherit; cursor: pointer; opacity: 0.75; }
67
+ .request-strip__close:hover { opacity: 1; }`;
68
+ document.head.appendChild(style);
69
+ }
70
+
71
+ function hide(answer) {
72
+ if (answer) remember(answer);
73
+ if (!strip) return;
74
+ strip.remove();
75
+ strip = null;
76
+ }
77
+
78
+ const ENTER_AFTER = 300;
79
+
80
+ function send() {
81
+ const terminal = term;
82
+ hide('done');
83
+ terminal.paste(line);
84
+ terminal.focus();
85
+ window.setTimeout(() => terminal.input('\r'), ENTER_AFTER);
86
+ }
87
+
88
+ // While the strip is there the terminal takes the room that is left (see the
89
+ // styles), and the page measures the terminal again because its box changed.
90
+ function show() {
91
+ const terminal = document.getElementById('terminal');
92
+ if (strip || !term || !terminal || !terminal.parentNode) return;
93
+ addStyle();
94
+ strip = document.createElement('div');
95
+ strip.className = 'request-strip';
96
+ strip.setAttribute('role', 'status');
97
+ const text = document.createElement('div');
98
+ text.className = 'request-strip__text';
99
+ const title = document.createElement('div');
100
+ title.className = 'request-strip__title';
101
+ title.textContent = 'This tool started without your message';
102
+ const sub = document.createElement('div');
103
+ sub.textContent = 'Send it when the tool is ready.';
104
+ text.append(title, sub);
105
+ const button = document.createElement('button');
106
+ button.type = 'button';
107
+ button.className = 'request-strip__send';
108
+ button.textContent = 'Send message';
109
+ button.addEventListener('click', send);
110
+ const close = document.createElement('button');
111
+ close.type = 'button';
112
+ close.className = 'request-strip__close';
113
+ close.setAttribute('aria-label', 'Dismiss');
114
+ close.title = 'Dismiss';
115
+ close.textContent = '✕';
116
+ close.addEventListener('click', () => hide('done'));
117
+ strip.append(text, button, close);
118
+ terminal.parentNode.insertBefore(strip, terminal);
119
+ remember('shown');
120
+ }
121
+
122
+ // Told every packet the running script sends this page. Nothing here may stop
123
+ // the page from handling the packet.
124
+ function step(packet) {
125
+ try {
126
+ if (!line || !packet || packet.type !== 'start') return;
127
+ const started = packet.data;
128
+ if (!started || typeof started.method !== 'string') return;
129
+ if (carries(started)) {
130
+ passed = true;
131
+ return;
132
+ }
133
+ if (passed || recall() === 'done') return;
134
+ if (started.method === 'shell.run' && started.params && started.params.input === true) show();
135
+ } catch (_) {}
136
+ }
137
+
138
+ // Given the page's terminal once it is there. A page loaded again while the
139
+ // strip was showing is the same session, so the strip is shown again.
140
+ function attach(terminal) {
141
+ term = terminal;
142
+ if (line && recall() === 'shown') show();
143
+ }
144
+
145
+ window.PinokioRequestStrip = { attach, step };
146
+ })();
@@ -8392,6 +8392,8 @@ body.dark .pinokio-custom-terminal-header {
8392
8392
  <script src="/agent-bar-compose.js" data-agent-bar-compose="true"></script>
8393
8393
  <link rel="stylesheet" href="/agent-bar-shell.css">
8394
8394
  <script src="/agent-bar-shell.js" data-agent-bar-shell="true"></script>
8395
+ <link rel="stylesheet" href="/agent-bar-shortcut.css">
8396
+ <script src="/agent-bar-shortcut.js" data-agent-bar-shortcut="true"></script>
8395
8397
  </head>
8396
8398
  <%
8397
8399
  const appInfoRemoteUrl = typeof launcher_remote_url === "string" ? launcher_remote_url : ""
@@ -21,6 +21,10 @@
21
21
  <script src="/agent-bar-modes.js" data-agent-bar-modes="true"></script>
22
22
  <link rel="stylesheet" href="/agent-bar-about.css">
23
23
  <script src="/agent-bar-about.js" data-agent-bar-about="true"></script>
24
+ <link rel="stylesheet" href="/agent-bar-search.css">
25
+ <script src="/agent-bar-search.js" data-agent-bar-search="true"></script>
26
+ <link rel="stylesheet" href="/agent-bar-shortcut.css">
27
+ <script src="/agent-bar-shortcut.js" data-agent-bar-shortcut="true"></script>
24
28
  <button type="button" class="main-sidebar-mobile-toggle" data-main-sidebar-toggle aria-label="Open navigation" aria-expanded="false">
25
29
  <i class="fa-solid fa-bars" aria-hidden="true"></i>
26
30
  </button>
@@ -36,6 +36,7 @@
36
36
  <script src="/simplemodal.js"></script>
37
37
  <script src="/waitmodal.js"></script>
38
38
  <script src="/notifyinput.js"></script>
39
+ <script src="/request-strip.js"></script>
39
40
  <script src="/report.js"></script>
40
41
  <script src="/mark.min.js"></script>
41
42
  <script src="/dropzone-min.js"></script>
@@ -1918,6 +1919,7 @@ document.addEventListener("DOMContentLoaded", async () => {
1918
1919
  this.socket.run(payload, async (packet) => {
1919
1920
  // what a page showing this one in a frame cannot see otherwise (agent-bar-launch.js)
1920
1921
  if (packet.type === "error" || packet.type === "notify" || packet.type === "process.wait.start") refreshParent({ type: "pinokio:session-step", step: packet.type, data: packet.data })
1922
+ if (window.PinokioRequestStrip) window.PinokioRequestStrip.step(packet)
1921
1923
  if (packet.type === 'start') {
1922
1924
  refreshParent(packet)
1923
1925
  reloadMemory()
@@ -3222,6 +3224,7 @@ document.addEventListener("DOMContentLoaded", async () => {
3222
3224
  })
3223
3225
  // input the terminal library does not send by itself (see terminal-input.js)
3224
3226
  window.PinokioTerminalInput.attach(term, () => this.socket, () => shell_id)
3227
+ if (window.PinokioRequestStrip) window.PinokioRequestStrip.attach(term)
3225
3228
 
3226
3229
  const fitAddon = new FitAddon.FitAddon();
3227
3230
  // const searchAddon = new SearchAddon.SearchAddon();
@@ -3250,6 +3253,8 @@ document.addEventListener("DOMContentLoaded", async () => {
3250
3253
  this.resizeSync.sendResize(this.term.cols, this.term.rows)
3251
3254
  });
3252
3255
  this.observer.observe(document.body)
3256
+ // the terminal's own box changes when something is shown above it (request-strip.js)
3257
+ if (document.querySelector("#terminal")) this.observer.observe(document.querySelector("#terminal"))
3253
3258
  }
3254
3259
  }
3255
3260
  <% if (!install_required) { %>
@@ -11,6 +11,17 @@ module.exports = {
11
11
  message: "cursor .",
12
12
  path: "{{args.cwd}}"
13
13
  }
14
+ }, {
15
+ // Cursor's own link for a prompt: it puts the request in the chat box, and
16
+ // the user sends it. Cursor never runs a prompt from a link by itself.
17
+ when: "{{which('cursor') && args.prompt}}",
18
+ method: "uri.open",
19
+ params: {
20
+ uri: "cursor://anysphere.cursor-deeplink/prompt",
21
+ params: {
22
+ text: "{{args.prompt}}"
23
+ }
24
+ }
14
25
  }, {
15
26
  when: "{{!which('cursor')}}",
16
27
  method: "notify",
@@ -1,16 +1,72 @@
1
- module.exports = {
2
- title: "VS Code",
3
- link: "https://code.visualstudio.com/",
4
- icon: "vscode.png",
5
- description: "The AI Code Editor",
6
- run: [{
7
- when: "{{which('code')}}",
8
- method: "exec",
9
- params: {
10
- message: "code .",
11
- path: "{{args.cwd}}",
1
+ // VS Code is opened by its own `code` command: `code chat <request>` opens the
2
+ // folder's window with a chat that holds the request, and `code .` opens the
3
+ // folder when there is no request.
4
+ //
5
+ // VS Code does not put `code` on the PATH by itself (on a Mac the user has to
6
+ // run "Install 'code' command in PATH"), so the command is also looked for where
7
+ // VS Code installs it. When it is nowhere, VS Code's own links are opened
8
+ // instead: the system finds the app for them, and Pinokio says so when no app
9
+ // takes the link.
10
+ //
11
+ // The command is given as a list of words, which Pinokio quotes for the shell it
12
+ // runs in, so nothing in the request is read by the shell as a command.
13
+ const fs = require("fs")
14
+ const os = require("os")
15
+ const path = require("path")
16
+ const { pathToFileURL } = require("url")
17
+
18
+ function installPlaces(platform) {
19
+ if (platform === "darwin") {
20
+ const inApp = "Visual Studio Code.app/Contents/Resources/app/bin/code"
21
+ return [path.join("/Applications", inApp), path.join(os.homedir(), "Applications", inApp)]
22
+ }
23
+ if (platform === "win32") {
24
+ return [process.env.LOCALAPPDATA && path.join(process.env.LOCALAPPDATA, "Programs", "Microsoft VS Code", "bin", "code.cmd"),
25
+ process.env.ProgramFiles && path.join(process.env.ProgramFiles, "Microsoft VS Code", "bin", "code.cmd")].filter(Boolean)
26
+ }
27
+ return ["/usr/bin/code", "/usr/share/code/bin/code", "/snap/bin/code"]
28
+ }
29
+
30
+ function codeCommand(kernel) {
31
+ let found = null
32
+ try {
33
+ found = kernel.which("code")
34
+ } catch (_) {}
35
+ return found || installPlaces(kernel.platform).find((place) => fs.existsSync(place)) || null
36
+ }
37
+
38
+ function runSteps(kernel, info, context) {
39
+ const args = context && context.args ? context.args : {}
40
+ const cwd = args.cwd
41
+ const request = typeof args.prompt === "string" ? args.prompt : ""
42
+ const code = codeCommand(kernel)
43
+
44
+ let open
45
+ if (code) {
46
+ open = {
47
+ method: "shell.run",
48
+ params: {
49
+ conda: { skip: true },
50
+ message: { _: request ? [code, "chat", request] : [code, "."] },
51
+ path: cwd
52
+ }
12
53
  }
13
- }, {
54
+ } else if (request) {
55
+ open = {
56
+ method: "uri.open",
57
+ params: {
58
+ uri: "vscode://agents/new",
59
+ params: { prompt: request, workspace: pathToFileURL(cwd).href }
60
+ }
61
+ }
62
+ } else {
63
+ open = {
64
+ method: "uri.open",
65
+ params: { uri: `vscode://file${pathToFileURL(cwd).pathname}` }
66
+ }
67
+ }
68
+
69
+ return [open, {
14
70
  method: "process.wait",
15
71
  params: {
16
72
  title: "Launched",
@@ -18,3 +74,13 @@ module.exports = {
18
74
  }
19
75
  }]
20
76
  }
77
+
78
+ module.exports = {
79
+ title: "VS Code",
80
+ link: "https://code.visualstudio.com/",
81
+ icon: "vscode.png",
82
+ description: "The AI Code Editor",
83
+ // said outright: Pinokio reads a plugin's kind from its steps only when they are a list
84
+ launch_type: "desktop",
85
+ run: runSteps,
86
+ }
@@ -373,3 +373,50 @@ test('the dock: a launch the card hands back opens in a window', { timeout: 5000
373
373
  assert.ok(frame, 'the session\'s page is in a dock window')
374
374
  assert.equal(new URL(frame.src).pathname, '/pinokio/run/plugin/codex-desktop/pinokio.js')
375
375
  })
376
+
377
+ // ---- a launch with a request ----
378
+ const LINE = 'My message is in .pinokio-sessions/s1/request.md. Read it and respond as if I had typed it here.'
379
+ const withRequest = (address) => `${address}&prompt=${encodeURIComponent(LINE)}`
380
+
381
+ test('a desktop app opened with a request: the card stays, with the request to copy, whatever the plugin did with it', { timeout: 5000 }, async (t) => {
382
+ // a plugin that hands the request to the app, and one that leaves it out
383
+ const launches = [
384
+ [DESKTOP, 'Codex Desktop', { method: 'uri.open', params: { uri: 'codex://new', params: { prompt: LINE } } }],
385
+ ['/pinokio/run/plugin/cursor/pinokio.js?cwd=%2Fhome%2Fapi%2Fdemo', 'Cursor', { method: 'exec', params: { message: 'cursor .' } }],
386
+ ]
387
+ for (const [address, name, step] of launches) {
388
+ const p = await page(t)
389
+ const copied = []
390
+ Object.defineProperty(p.window.navigator, 'clipboard', { configurable: true, value: { writeText: async (text) => { copied.push(text) } } })
391
+ p.launch.take(Object.assign({}, p.session, { key: name }), withRequest(address), p.dock)
392
+ await p.loaded()
393
+ p.tell({ type: 'start', data: step })
394
+ p.tell({ type: 'disconnect' })
395
+ assert.equal(p.text('.agent-launch__title'), `Opened in ${name}`)
396
+ assert.equal(p.text('.agent-launch__sub'), 'If your message isn\'t in the chat, copy it and paste it.')
397
+ assert.deepEqual(p.buttons(), ['Copy message'])
398
+ assert.equal(p.card().querySelector('.agent-launch__close').hidden, false)
399
+ assert.equal(p.card().querySelector('.agent-launch__timer').hidden, true)
400
+ // it does not close by itself
401
+ await pause(p.window, 450)
402
+ assert.equal(p.card().dataset.open, 'true')
403
+
404
+ p.press('Copy message')
405
+ await pause(p.window, 10)
406
+ assert.deepEqual(copied, [LINE])
407
+ assert.deepEqual(p.buttons(), ['Copied'])
408
+
409
+ p.card().querySelector('.agent-launch__close').click()
410
+ assert.equal(p.card().dataset.open, 'false')
411
+ }
412
+ })
413
+
414
+ test('a launch without a request is not asked to copy anything', { timeout: 5000 }, async (t) => {
415
+ const p = await page(t)
416
+ p.launch.take(Object.assign({}, p.session, { key: 'cursor' }), '/pinokio/run/plugin/cursor/pinokio.js?cwd=%2Fhome%2Fapi%2Fdemo', p.dock)
417
+ await p.loaded()
418
+ p.tell({ type: 'start', data: { method: 'exec', params: { message: 'cursor .' } } })
419
+ p.tell({ type: 'disconnect' })
420
+ assert.equal(p.text('.agent-launch__sub'), 'Carry on there.')
421
+ assert.deepEqual(p.buttons(), [])
422
+ })