pinokiod 8.3.7 → 8.3.10

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.
Files changed (36) hide show
  1. package/kernel/agent_instructions.js +56 -0
  2. package/kernel/app_log_sessions.js +1 -1
  3. package/kernel/bin/node.js +2 -2
  4. package/kernel/environment.js +6 -98
  5. package/kernel/managed_skills.js +2 -1
  6. package/kernel/prototype.js +7 -0
  7. package/kernel/request_file.js +53 -0
  8. package/package.json +1 -1
  9. package/prototype/system/SKILL_PINOKIO.md +5 -2
  10. package/server/index.js +12 -1
  11. package/server/lib/brain.js +305 -0
  12. package/server/public/agent-bar-app.css +359 -0
  13. package/server/public/agent-bar-app.js +837 -0
  14. package/server/public/agent-bar-attach.css +142 -0
  15. package/server/public/agent-bar-attach.js +299 -0
  16. package/server/public/agent-bar-panel.css +788 -0
  17. package/server/public/agent-bar-panel.js +1915 -0
  18. package/server/public/agent-bar-shell.css +128 -0
  19. package/server/public/agent-bar-shell.js +251 -0
  20. package/server/public/agent-bar.css +972 -0
  21. package/server/public/agent-bar.js +1513 -0
  22. package/server/public/common.js +65 -0
  23. package/server/public/layout.js +13 -1
  24. package/server/public/logs.js +22 -0
  25. package/server/routes/apps.js +6 -0
  26. package/server/socket.js +6 -2
  27. package/server/views/app.ejs +13 -0
  28. package/server/views/partials/main_sidebar.ejs +7 -0
  29. package/system/plugin/opencode/pinokio.js +8 -2
  30. package/system/plugin/opencode-auto/pinokio.js +4 -1
  31. package/test/agent-instructions.test.js +69 -0
  32. package/test/app-log-sessions.test.js +29 -0
  33. package/test/brain.test.js +301 -0
  34. package/test/managed-skills.test.js +6 -1
  35. package/test/node-bin.test.js +4 -4
  36. package/test/request-file.test.js +93 -0
@@ -3785,8 +3785,63 @@ document.addEventListener("DOMContentLoaded", () => {
3785
3785
  tools: null,
3786
3786
  toolsPromise: null
3787
3787
  };
3788
+ let agentBarLoad = null;
3788
3789
  initializeUniversalLauncherIntegration();
3789
3790
  initializeCreateLauncherIntegration();
3791
+ initializeAgentBar();
3792
+
3793
+ // Agent bar (top navbar prompt input). All of it lives in /agent-bar.js and
3794
+ // /agent-bar.css; this only loads them.
3795
+ // A Pinokio page is either the top window or a pane of the layout shell (the
3796
+ // page at "/", which shows every Pinokio page inside an iframe). Pages embedded
3797
+ // anywhere else (inside an app page, for instance) do not get the bar.
3798
+ function isAgentBarHostPage() {
3799
+ if (window.top === window) {
3800
+ return true;
3801
+ }
3802
+ try {
3803
+ return Boolean(window.parent && window.parent !== window && window.parent.PinokioLayout);
3804
+ } catch (_) {
3805
+ return false;
3806
+ }
3807
+ }
3808
+
3809
+ function initializeAgentBar() {
3810
+ if (!isAgentBarHostPage()) {
3811
+ return;
3812
+ }
3813
+ if (document.querySelector('script[data-agent-bar]')) {
3814
+ // the page already loaded it itself (early, from its own markup)
3815
+ agentBarLoad = Promise.resolve(true);
3816
+ return;
3817
+ }
3818
+ const target = document.head || document.documentElement;
3819
+ const link = document.createElement('link');
3820
+ link.rel = 'stylesheet';
3821
+ link.href = '/agent-bar.css';
3822
+ target.appendChild(link);
3823
+ const script = document.createElement('script');
3824
+ script.src = '/agent-bar.js';
3825
+ script.async = true;
3826
+ script.dataset.agentBar = 'true';
3827
+ agentBarLoad = new Promise((resolve) => {
3828
+ script.onload = () => resolve(true);
3829
+ script.onerror = () => resolve(false);
3830
+ });
3831
+ target.appendChild(script);
3832
+ }
3833
+
3834
+ // Resolves true when the agent bar took a launcher request (a Create / Ask /
3835
+ // Download button or a pre-filled ?universal link), false when the dialog should.
3836
+ function openInAgentBar(defaults) {
3837
+ if (!agentBarLoad) {
3838
+ return Promise.resolve(false);
3839
+ }
3840
+ return agentBarLoad
3841
+ .then(() => (window.PinokioAgentBar ? window.PinokioAgentBar.ready : null))
3842
+ .then(() => Boolean(window.PinokioAgentBar && window.PinokioAgentBar.open(defaults)))
3843
+ .catch(() => false);
3844
+ }
3790
3845
 
3791
3846
  function initializeUniversalLauncherIntegration() {
3792
3847
  const defaults = parseUniversalLauncherDefaults();
@@ -3991,6 +4046,16 @@ document.addEventListener("DOMContentLoaded", () => {
3991
4046
  }
3992
4047
 
3993
4048
  function guardUniversalLauncher(api, defaults = null) {
4049
+ // The agent bar takes the request when it is on screen (desktop). Otherwise
4050
+ // (phones, pages without the bar) the dialog opens exactly as before.
4051
+ openInAgentBar(defaults).then((handled) => {
4052
+ if (!handled) {
4053
+ showUniversalLauncherDialog(api, defaults);
4054
+ }
4055
+ });
4056
+ }
4057
+
4058
+ function showUniversalLauncherDialog(api, defaults = null) {
3994
4059
  if (!api || typeof api.showModal !== 'function') {
3995
4060
  createLauncherDebugLog('guardUniversalLauncher aborted: api unavailable');
3996
4061
  return;
@@ -923,8 +923,12 @@
923
923
  }
924
924
  }
925
925
 
926
+ // A browser allows six connections to one address, and this one never ends.
927
+ // So a tab holds it only while it is visible: a sixth Pinokio tab would
928
+ // otherwise never load. On return the stream opens with the current state.
926
929
  function connect() {
927
- if (typeof window.EventSource !== 'function') {
930
+ if (eventSource || document.hidden ||
931
+ typeof window.EventSource !== 'function') {
928
932
  return;
929
933
  }
930
934
  eventSource = new window.EventSource(
@@ -943,6 +947,14 @@
943
947
 
944
948
  if (typeof window.EventSource === 'function') {
945
949
  connect();
950
+ document.addEventListener('visibilitychange', () => {
951
+ if (!document.hidden) {
952
+ connect();
953
+ } else if (eventSource) {
954
+ eventSource.close();
955
+ eventSource = null;
956
+ }
957
+ });
946
958
  } else {
947
959
  loadState();
948
960
  }
@@ -1203,11 +1203,33 @@
1203
1203
  const index = launcher.selectedToolIndex
1204
1204
  return Number.isFinite(index) && index >= 0 ? this.askAiTools[index] || null : null
1205
1205
  }
1206
+ // The bar of the app page this report is shown in ("Ask Pinokio about
1207
+ // <app>", agent-bar-app.js), if there is one.
1208
+ appPageBar() {
1209
+ try {
1210
+ let frame = window
1211
+ while (frame.parent && frame.parent !== frame) {
1212
+ frame = frame.parent
1213
+ if (frame.PinokioAgentBarApp && typeof frame.PinokioAgentBarApp.ask === 'function') {
1214
+ return frame.PinokioAgentBarApp
1215
+ }
1216
+ }
1217
+ } catch (_) {}
1218
+ return null
1219
+ }
1206
1220
  async openAskAiModal() {
1207
1221
  if (!this.currentMarkdown && !this.reviewMarkdown) {
1208
1222
  this.updateDraftSizeReview()
1209
1223
  return
1210
1224
  }
1225
+ // On an app page the question goes out through the page's own bar, exactly
1226
+ // as if it had been typed there, and the session opens in the page's agent
1227
+ // window. The dialog below is what a Logs page without that bar still uses.
1228
+ const appBar = this.appPageBar()
1229
+ if (appBar) {
1230
+ appBar.ask(ASK_AI_DEFAULT_PROMPT)
1231
+ return
1232
+ }
1211
1233
  this.setAskAiBusy(true)
1212
1234
  let tools = []
1213
1235
  try {
@@ -7,6 +7,7 @@ const multer = require('multer')
7
7
  const FormData = require('form-data')
8
8
  const sanitize = require('sanitize-filename')
9
9
  const AppLogReportService = require('../lib/app_log_report')
10
+ const Brain = require('../lib/brain')
10
11
 
11
12
  const DEFAULT_PEER_PORT = 42000
12
13
  const DEFAULT_PEER_TIMEOUT_MS = 2500
@@ -822,6 +823,11 @@ module.exports = function registerAppRoutes(app, { registry, preferences, appSea
822
823
  limit,
823
824
  source: req.$source || null
824
825
  })
826
+ // where each app's saved skill is; not for another Pinokio asking, since the
827
+ // paths mean nothing on its machine
828
+ if (!req.get('x-pinokio-peer')) {
829
+ payload.apps = await Brain.addSkills(appSearch.kernel, payload.apps)
830
+ }
825
831
  const localSource = buildSource(currentPeerHost(), true)
826
832
  payload.apps = Array.isArray(payload.apps)
827
833
  ? payload.apps.map((appResult) => decorateSearchResult(appResult, localSource))
package/server/socket.js CHANGED
@@ -229,8 +229,12 @@ class Socket {
229
229
  if (req.response) {
230
230
  this.parent.kernel.api.respond(req)
231
231
  } else {
232
- // link git every time before processing
233
- await this.parent.kernel.api.init()
232
+ // link git every time before processing a request to run something.
233
+ // A key, text or resize sent to a running shell does not use it, and
234
+ // waiting for it here let two keys typed close together swap places.
235
+ if (req.uri || req.method) {
236
+ await this.parent.kernel.api.init()
237
+ }
234
238
  // look for repos that match
235
239
  if (req.uri) {
236
240
  if (req.mode === "open") {
@@ -8373,6 +8373,16 @@ body.dark .pinokio-custom-terminal-header {
8373
8373
  } catch (_) {}
8374
8374
  })()
8375
8375
  </script>
8376
+ <link rel="stylesheet" href="/agent-bar.css">
8377
+ <link rel="stylesheet" href="/agent-bar-app.css">
8378
+ <script src="/agent-bar.js" data-agent-bar="true"></script>
8379
+ <script src="/agent-bar-app.js" data-agent-bar-app="true"></script>
8380
+ <link rel="stylesheet" href="/agent-bar-panel.css">
8381
+ <script src="/agent-bar-panel.js" data-agent-bar-panel="true"></script>
8382
+ <link rel="stylesheet" href="/agent-bar-attach.css">
8383
+ <script src="/agent-bar-attach.js" data-agent-bar-attach="true"></script>
8384
+ <link rel="stylesheet" href="/agent-bar-shell.css">
8385
+ <script src="/agent-bar-shell.js" data-agent-bar-shell="true"></script>
8376
8386
  </head>
8377
8387
  <%
8378
8388
  const appInfoRemoteUrl = typeof launcher_remote_url === "string" ? launcher_remote_url : ""
@@ -8764,6 +8774,7 @@ body.dark .pinokio-custom-terminal-header {
8764
8774
  </div>
8765
8775
  </div>
8766
8776
  </aside>
8777
+ <script>window.PinokioAgentBarApp && window.PinokioAgentBarApp.mount({ mobileQuery: "(max-width: <%= appMobileBreakpointPx %>px)" })</script>
8767
8778
  <div class='appcanvas-resizer' id="appcanvas-resizer" role="separator" aria-orientation="vertical" aria-valuemin="140" aria-valuemax="560" aria-valuenow="150" tabindex="0" aria-label="Resize navigation sidebar"></div>
8768
8779
  <% } %>
8769
8780
  <% if (type === "run") { %>
@@ -18278,6 +18289,8 @@ document.addEventListener("DOMContentLoaded", () => {
18278
18289
  openWithAgent,
18279
18290
  openPicker,
18280
18291
  openWithUrl,
18292
+ openShellTool,
18293
+ redirectToPluginInstallIfNeeded,
18281
18294
  close: () => setOpen(false),
18282
18295
  isOpen: () => open
18283
18296
  }
@@ -1,6 +1,12 @@
1
1
  <%
2
2
  const sidebarSelected = (typeof selected !== "undefined" && selected) ? String(selected) : "";
3
3
  %>
4
+ <link rel="stylesheet" href="/agent-bar.css">
5
+ <script src="/agent-bar.js" data-agent-bar="true"></script>
6
+ <link rel="stylesheet" href="/agent-bar-panel.css">
7
+ <script src="/agent-bar-panel.js" data-agent-bar-panel="true"></script>
8
+ <link rel="stylesheet" href="/agent-bar-attach.css">
9
+ <script src="/agent-bar-attach.js" data-agent-bar-attach="true"></script>
4
10
  <button type="button" class="main-sidebar-mobile-toggle" data-main-sidebar-toggle aria-label="Open navigation" aria-expanded="false">
5
11
  <i class="fa-solid fa-bars" aria-hidden="true"></i>
6
12
  </button>
@@ -376,3 +382,4 @@
376
382
  sync();
377
383
  })();
378
384
  </script>
385
+ <script>window.PinokioAgentBar && window.PinokioAgentBar.mount()</script>
@@ -40,7 +40,10 @@ module.exports = {
40
40
  method: "shell.run",
41
41
  params: {
42
42
  shell: "bash",
43
- message: "opencode",
43
+ message: {
44
+ _: ["opencode"],
45
+ prompt: "{{args.prompt || undefined}}"
46
+ },
44
47
  path: "{{args.cwd}}",
45
48
  input: true
46
49
  }
@@ -49,7 +52,10 @@ module.exports = {
49
52
  id: "run",
50
53
  method: "shell.run",
51
54
  params: {
52
- message: "opencode",
55
+ message: {
56
+ _: ["opencode"],
57
+ prompt: "{{args.prompt || undefined}}"
58
+ },
53
59
  path: "{{args.cwd}}",
54
60
  input: true
55
61
  }
@@ -8,7 +8,10 @@ module.exports = {
8
8
  ...step,
9
9
  params: {
10
10
  ...step.params,
11
- message: "opencode --auto",
11
+ message: {
12
+ ...step.params.message,
13
+ auto: true,
14
+ },
12
15
  },
13
16
  })),
14
17
  }
@@ -0,0 +1,69 @@
1
+ const assert = require("node:assert/strict")
2
+ const fs = require("node:fs")
3
+ const os = require("node:os")
4
+ const path = require("node:path")
5
+ const test = require("node:test")
6
+
7
+ const AgentInstructions = require("../kernel/agent_instructions")
8
+
9
+ // spec/requirements/instruction-sync.md, section 3
10
+
11
+ const guide = "# Development Guide for Pinokio Projects\n\nthe guide for <%= app_root %>\n"
12
+ const newHome = () => {
13
+ const home = fs.mkdtempSync(path.join(os.tmpdir(), "pinokio-guide-"))
14
+ fs.mkdirSync(path.join(home, "prototype/system/structure"), { recursive: true })
15
+ fs.writeFileSync(path.join(home, "prototype/system/AGENTS.md"), guide)
16
+ fs.writeFileSync(path.join(home, "prototype/system/structure/clone"), "")
17
+ const kernel = {
18
+ homedir: home,
19
+ path: (...parts) => path.resolve(home, ...parts),
20
+ exists: async (target) => fs.existsSync(target),
21
+ renderFile: async (target, vars) => fs.readFileSync(target, "utf8").replace("<%= app_root %>", vars.app_root)
22
+ }
23
+ return { home, kernel }
24
+ }
25
+
26
+ test("the guide is the template with the folder filled in, and empty without a template", async () => {
27
+ const { home, kernel } = newHome()
28
+ try {
29
+ assert.equal(await AgentInstructions.render(kernel, "/some/app"), "# Development Guide for Pinokio Projects\n\nthe guide for /some/app\n")
30
+ fs.rmSync(path.join(home, "prototype/system/AGENTS.md"))
31
+ assert.equal(await AgentInstructions.render(kernel, "/some/app"), "")
32
+ } finally {
33
+ fs.rmSync(home, { recursive: true, force: true })
34
+ }
35
+ })
36
+
37
+ test("at the top of the home, only Pinokio's own copies of the guide are removed", async () => {
38
+ const { home, kernel } = newHome()
39
+ try {
40
+ const older = "# Development Guide for Pinokio Projects\n\nan older text\n\n## User Soul\n\nmine\n"
41
+ for (const name of AgentInstructions.FILES) {
42
+ fs.writeFileSync(path.join(home, name), older)
43
+ }
44
+ fs.writeFileSync(path.join(home, "CLAUDE.md"), "# My own instructions\n")
45
+ fs.writeFileSync(path.join(home, "GEMINI.md"), "")
46
+ fs.writeFileSync(path.join(home, "SOUL.md"), "mine\n")
47
+ fs.writeFileSync(path.join(home, "AGENTS.md.pinokio.backup"), "# Development Guide for Pinokio Projects\n")
48
+ fs.mkdirSync(path.join(home, ".cursorrules-keep"))
49
+
50
+ await AgentInstructions.removeOwn(home, await AgentInstructions.render(kernel, home))
51
+
52
+ const left = fs.readdirSync(home).sort()
53
+ assert.deepEqual(left, [".cursorrules-keep", "AGENTS.md.pinokio.backup", "CLAUDE.md", "GEMINI.md", "SOUL.md", "prototype"])
54
+ assert.equal(fs.readFileSync(path.join(home, "CLAUDE.md"), "utf8"), "# My own instructions\n")
55
+ assert.equal(fs.readFileSync(path.join(home, "GEMINI.md"), "utf8"), "")
56
+ assert.equal(fs.readFileSync(path.join(home, "SOUL.md"), "utf8"), "mine\n")
57
+
58
+ // a later template with another heading still clears the copies older versions wrote
59
+ fs.writeFileSync(path.join(home, "AGENTS.md"), older)
60
+ fs.writeFileSync(path.join(home, "QWEN.md"), "# A New Heading\n\nwritten from a newer template\n")
61
+ await AgentInstructions.removeOwn(home, "# A New Heading\n\nthe guide\n")
62
+ assert.equal(fs.existsSync(path.join(home, "AGENTS.md")), false)
63
+ assert.equal(fs.existsSync(path.join(home, "QWEN.md")), false)
64
+ assert.equal(fs.readFileSync(path.join(home, "CLAUDE.md"), "utf8"), "# My own instructions\n")
65
+ assert.equal(fs.existsSync(path.join(home, "GEMINI.md")), true, "an empty file is not Pinokio's")
66
+ } finally {
67
+ fs.rmSync(home, { recursive: true, force: true })
68
+ }
69
+ })
@@ -193,6 +193,35 @@ test('app log sessions attach child launches from the current backend execution
193
193
  })
194
194
  })
195
195
 
196
+ test('finishing an old log session preserves replacement mappings after an asynchronous load', async () => {
197
+ await withSessionFixture(async ({ sessions, scriptPath, readManifest }) => {
198
+ const request = { path: scriptPath('start.js'), id: `${scriptPath('start.js')}?cwd=fixture` }
199
+ const old = await sessions.startRun(request)
200
+ let release
201
+ let started
202
+ const barrier = new Promise(resolve => { release = resolve })
203
+ const loading = new Promise(resolve => { started = resolve })
204
+ const loadSession = sessions.loadSession.bind(sessions)
205
+ sessions.loadSession = async (appRoot, sessionId) => {
206
+ if (sessionId === old.session_id) {
207
+ started()
208
+ await barrier
209
+ }
210
+ return loadSession(appRoot, sessionId)
211
+ }
212
+ const finishing = sessions.finishRun(request, { internal_completion: true })
213
+ await loading
214
+ const replacement = await sessions.startRun(request)
215
+ release()
216
+ await finishing
217
+
218
+ assert.strictEqual(sessions.activeRun({ id: request.id }), replacement)
219
+ assert.strictEqual(sessions.activeRun({ path: request.path }), replacement)
220
+ assert.ok((await readManifest(old.session_id)).runs[0].ended_at)
221
+ assert.equal((await readManifest(replacement.session_id)).runs[0].ended_at, null)
222
+ })
223
+ })
224
+
196
225
  test('app log sessions keep same opaque session ids isolated by app root', async () => {
197
226
  await withSessionFixture(async ({ apiRoot, appRoot, kernel, scriptPath, readManifest }) => {
198
227
  const otherRoot = path.join(apiRoot, 'other')