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
@@ -0,0 +1,56 @@
1
+ const fs = require("fs")
2
+ const path = require("path")
3
+
4
+ // The launcher guide: the template from the proto repository with this
5
+ // machine's paths filled in. It is written into an app folder that has none,
6
+ // and it is the `gepeto` managed skill. It is not kept at the top of the home
7
+ // folder, because that folder is above every folder an agent starts in, so an
8
+ // agent that also reads the folders above its own would load it twice.
9
+ // spec/requirements/instruction-sync.md
10
+
11
+ const FILES = [
12
+ "AGENTS.md",
13
+ "CLAUDE.md",
14
+ "GEMINI.md",
15
+ "QWEN.md",
16
+ ".windsurfrules",
17
+ ".cursorrules",
18
+ ".clinerules"
19
+ ]
20
+
21
+ const render = async (kernel, root) => {
22
+ const template = kernel.path("prototype/system/AGENTS.md")
23
+ if (!(await kernel.exists(template))) {
24
+ return ""
25
+ }
26
+ const structure = await fs.promises.readFile(kernel.path("prototype/system/structure/clone"), "utf-8")
27
+ return kernel.renderFile(template, {
28
+ structure,
29
+ examples: kernel.path("prototype/system/examples"),
30
+ browser_logs: kernel.path("logs/browser.log"),
31
+ PINOKIO_DOCUMENTATION: kernel.path("prototype/PINOKIO.md"),
32
+ PTERM_DOCUMENTATION: kernel.path("prototype/PTERM.md"),
33
+ app_root: root,
34
+ proto_path: kernel.path("prototype"),
35
+ home_path: kernel.homedir
36
+ })
37
+ }
38
+
39
+ // Earlier versions wrote the guide at the top of the home folder on every
40
+ // start. Those copies are removed. Every copy Pinokio ever wrote there starts
41
+ // with GUIDE_HEADING; the guide's current first line is checked as well, in
42
+ // case the template's heading changes. A file that starts with neither is the
43
+ // user's own and is left alone.
44
+ const GUIDE_HEADING = "# Development Guide for Pinokio Projects"
45
+ const removeOwn = async (root, guide) => {
46
+ const headings = [GUIDE_HEADING, guide.split(/\r?\n/, 1)[0]].filter(Boolean)
47
+ for (const filename of FILES) {
48
+ const filepath = path.resolve(root, filename)
49
+ const text = await fs.promises.readFile(filepath, "utf8").catch(() => null)
50
+ if (text !== null && headings.includes(text.split(/\r?\n/, 1)[0])) {
51
+ await fs.promises.rm(filepath, { force: true }).catch(() => {})
52
+ }
53
+ }
54
+ }
55
+
56
+ module.exports = { FILES, render, removeOwn }
@@ -378,7 +378,7 @@ class AppLogSessions {
378
378
  run.ended_at = endedAt
379
379
  session.updated_at = endedAt
380
380
  for (const key of this.requestKeys({ ...requestOrRun, path: run.scriptPath })) {
381
- this.activeRunsByKey.delete(key)
381
+ if (this.activeRunsByKey.get(key) === run) this.activeRunsByKey.delete(key)
382
382
  }
383
383
  await this.persistSession(session)
384
384
 
@@ -2,8 +2,8 @@ const fs = require('fs')
2
2
  const fetch = require('cross-fetch')
3
3
  const { rimraf } = require('rimraf')
4
4
  const decompress = require('decompress');
5
- const NODE_VERSION = "24.22.1"
6
- const PNPM_VERSION = "11.9.0"
5
+ const NODE_VERSION = "24.22.3"
6
+ const PNPM_VERSION = "11.24.0"
7
7
 
8
8
  const normalizeVersion = (version) => {
9
9
  const match = String(version || "").match(/^\d+\.\d+\.\d+/)
@@ -3,6 +3,7 @@ const portfinder = require('portfinder-cp')
3
3
  const fs = require('fs')
4
4
  const Util = require('./util')
5
5
  const ManagedSkills = require('./managed_skills')
6
+ const AgentInstructions = require('./agent_instructions')
6
7
  const { pipConfigDisabledPath } = require('./pip_env')
7
8
  const TEMP_ENV_KEYS = ["TMP", "TEMP", "TMPDIR", "PIP_TMPDIR"]
8
9
  const CACHE_ENV_KEYS = ["UV_CACHE_DIR", "PIP_CACHE_DIR"]
@@ -803,45 +804,6 @@ const init = async (options, kernel) => {
803
804
  }
804
805
  const homeRoot = path.resolve(kernel.homedir)
805
806
  const isHomeRoot = path.resolve(root) === homeRoot
806
- const writeFileIfChanged = async (targetPath, content) => {
807
- let shouldWrite = true
808
- try {
809
- const existingContent = await fs.promises.readFile(targetPath, "utf8")
810
- shouldWrite = existingContent !== content
811
- } catch (error) {
812
- if (!(error && error.code === "ENOENT")) {
813
- throw error
814
- }
815
- }
816
-
817
- if (shouldWrite) {
818
- await fs.promises.writeFile(targetPath, content, "utf8")
819
- }
820
- }
821
- const backupFileIfChanged = async (targetPath, desiredContent) => {
822
- let existingContent
823
- try {
824
- existingContent = await fs.promises.readFile(targetPath, "utf8")
825
- } catch (error) {
826
- if (error && error.code === "ENOENT") {
827
- return
828
- }
829
- throw error
830
- }
831
- if (existingContent === desiredContent) {
832
- return
833
- }
834
- const backupPath = `${targetPath}.pinokio.backup`
835
- try {
836
- await fs.promises.access(backupPath, fs.constants.F_OK)
837
- return
838
- } catch (error) {
839
- if (!(error && error.code === "ENOENT")) {
840
- throw error
841
- }
842
- }
843
- await fs.promises.copyFile(targetPath, backupPath)
844
- }
845
807
  let current = path.resolve(root, "ENVIRONMENT")
846
808
  let exists = await kernel.exists(current)
847
809
  if (exists) {
@@ -875,67 +837,13 @@ const init = async (options, kernel) => {
875
837
  }
876
838
  }
877
839
 
878
- const agentTemplatePath = kernel.path("prototype/system/AGENTS.md")
879
- const agentTemplateExists = await kernel.exists(agentTemplatePath)
880
- if (agentTemplateExists) {
881
- const agentFiles = [
882
- "AGENTS.md",
883
- "CLAUDE.md",
884
- "GEMINI.md",
885
- "QWEN.md",
886
- ".windsurfrules",
887
- ".cursorrules",
888
- ".clinerules"
889
- ]
890
- const structure_path = kernel.path("prototype/system/structure/clone")
891
- const structure_content = await fs.promises.readFile(structure_path, "utf-8")
892
- const proto_path = kernel.path("prototype")
893
- const home_path = kernel.homedir
894
- const rendered_recipe = await kernel.renderFile(agentTemplatePath, {
895
- structure: structure_content,
896
- examples: kernel.path("prototype/system/examples"),
897
- browser_logs: kernel.path("logs/browser.log"),
898
- PINOKIO_DOCUMENTATION: kernel.path("prototype/PINOKIO.md"),
899
- PTERM_DOCUMENTATION: kernel.path("prototype/PTERM.md"),
900
- app_root: root,
901
- proto_path,
902
- home_path,
903
- })
840
+ const rendered_recipe = await AgentInstructions.render(kernel, root)
841
+ if (rendered_recipe) {
904
842
  if (isHomeRoot) {
905
- const soulPath = path.resolve(root, "SOUL.md")
906
- let soulExists = await kernel.exists(soulPath)
907
- if (!soulExists) {
908
- for (const filename of agentFiles) {
909
- const destination = path.resolve(root, filename)
910
- await backupFileIfChanged(destination, rendered_recipe)
911
- }
912
- await fs.promises.writeFile(soulPath, "", "utf8")
913
- soulExists = true
914
- }
915
- let renderedOutput = rendered_recipe
916
- if (soulExists) {
917
- const soulContent = await fs.promises.readFile(soulPath, "utf8")
918
- const soulBody = soulContent.trim()
919
- if (soulBody.length > 0) {
920
- const soulWrapper = [
921
- "## User Soul",
922
- "",
923
- "The following instructions come from `SOUL.md`.",
924
- "",
925
- "If this section conflicts with the general Pinokio defaults earlier in this document, follow this section.",
926
- "",
927
- "If there is no conflict, follow both.",
928
- ].join("\n")
929
- const separator = rendered_recipe.endsWith("\n") ? "\n" : "\n\n"
930
- renderedOutput = `${rendered_recipe}${separator}${soulWrapper}\n\n${soulBody}\n`
931
- }
932
- }
933
- for (const filename of agentFiles) {
934
- const destination = path.resolve(root, filename)
935
- await writeFileIfChanged(destination, renderedOutput)
936
- }
843
+ // not kept at the top of the home folder: spec/requirements/instruction-sync.md
844
+ await AgentInstructions.removeOwn(root, rendered_recipe)
937
845
  } else {
938
- for (const filename of agentFiles) {
846
+ for (const filename of AgentInstructions.FILES) {
939
847
  const destination = path.resolve(root, filename)
940
848
  const destinationExists = await kernel.exists(destination)
941
849
  if (!destinationExists) {
@@ -1,6 +1,7 @@
1
1
  const fs = require("fs")
2
2
  const os = require("os")
3
3
  const path = require("path")
4
+ const AgentInstructions = require("./agent_instructions")
4
5
 
5
6
  const INDEX_FILENAME = "index.json"
6
7
  const INDEX_VERSION = 1
@@ -306,7 +307,7 @@ const composeBuiltinSkillContent = async (kernel, id) => {
306
307
  return readSkillContent(path.resolve(__dirname, "../prototype/system/SKILL_PINOKIO.md"))
307
308
  }
308
309
  if (id === "gepeto") {
309
- const agentsContent = await readSkillContent(path.resolve(kernel.homedir, "AGENTS.md"))
310
+ const agentsContent = await AgentInstructions.render(kernel, kernel.homedir).catch(() => "")
310
311
  if (!agentsContent.trim()) {
311
312
  return ""
312
313
  }
@@ -3,6 +3,7 @@ const path = require('path')
3
3
  const { glob, sync, hasMagic } = require('glob-gitignore')
4
4
  const marked = require('marked')
5
5
  const matter = require('gray-matter');
6
+ const RequestFile = require('./request_file')
6
7
  class Proto {
7
8
  constructor(kernel) {
8
9
  this.kernel = kernel
@@ -124,6 +125,12 @@ class Proto {
124
125
  let mod_path = this.kernel.path("prototype/system", projectType, startType)
125
126
  let mod = await this.kernel.require(mod_path)
126
127
  let response = await mod(payload, ondata, this.kernel)
128
+ // A new app whose agent is started with the user's words: the words are in
129
+ // SPEC.md, and the address carries the line that points to it instead
130
+ // (kernel/request_file.js, spec/requirements/request-files.md).
131
+ if (response && typeof response.success === "string") {
132
+ response.success = await RequestFile.pointAddressToSpec(response.success, payload.cwd)
133
+ }
127
134
 
128
135
  if (projectType === 'dns') {
129
136
  try {
@@ -0,0 +1,53 @@
1
+ "use strict"
2
+
3
+ // How the text of a request reaches an agent: the request is in a file inside
4
+ // the folder the agent starts in, and the plugin is started with one line that
5
+ // points to the file. spec/requirements/request-files.md
6
+
7
+ const fs = require("fs")
8
+ const path = require("path")
9
+
10
+ const FOLDER = [".pinokio-temp", "requests"]
11
+ const SPEC = "SPEC.md"
12
+
13
+ // The request line. `file` is relative to the folder the agent starts in, with
14
+ // `/` on every system.
15
+ const line = (file) => `My message is in ${file}. Read it and respond as if I had typed it here.`
16
+
17
+ // An Ask: writes the request into `cwd` and gives back the request line.
18
+ const save = async (cwd, id, text) => {
19
+ const dir = path.resolve(cwd, ...FOLDER)
20
+ await fs.promises.mkdir(dir, { recursive: true })
21
+ await fs.promises.writeFile(path.resolve(dir, `${id}.md`), `${text}\n`, "utf8")
22
+ return line([...FOLDER, `${id}.md`].join("/"))
23
+ }
24
+
25
+ // Create app and Create plugin: the new folder already holds the user's words as
26
+ // SPEC.md. Gives back the request line for it, or null when SPEC.md is not there
27
+ // or holds something else.
28
+ const forSpec = async (cwd, words) => {
29
+ const asked = typeof words === "string" ? words.trim() : ""
30
+ if (!asked) return null
31
+ const saved = await fs.promises.readFile(path.resolve(cwd, SPEC), "utf8").catch(() => null)
32
+ return saved !== null && saved.trim() === asked ? line(SPEC) : null
33
+ }
34
+
35
+ // The same for a start address that carries the words as `prompt`
36
+ // (`/p/<app>/dev?plugin=...&prompt=...`): the address with the request line in
37
+ // their place. An address without words, or without a matching SPEC.md, is
38
+ // given back as it is.
39
+ const pointAddressToSpec = async (address, cwd) => {
40
+ if (typeof address !== "string" || !address) return address
41
+ let url
42
+ try {
43
+ url = new URL(address, "http://localhost")
44
+ } catch (_) {
45
+ return address
46
+ }
47
+ const requestLine = await forSpec(cwd, url.searchParams.get("prompt"))
48
+ if (!requestLine) return address
49
+ url.searchParams.set("prompt", requestLine)
50
+ return `${url.pathname}${url.search}${url.hash}`
51
+ }
52
+
53
+ module.exports = { line, save, forSpec, pointAddressToSpec }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "8.3.7",
3
+ "version": "8.3.10",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -196,15 +196,17 @@ Follow these sections in order:
196
196
 
197
197
  ### 4. Using Apps
198
198
  - Create or reuse one app-specific skill folder for the selected app:
199
- - `<current_working_directory>/pinokio_agent/skills/<scope>/<app_id>/`
199
+ - if a `skill_dir` is given for the app, in its search result or in the request, that folder is the app-specific skill folder; use it exactly as given
200
+ - otherwise `<current_working_directory>/pinokio_agent/skills/<scope>/<app_id>/`
200
201
  - App-specific skill folder structure:
201
202
  - `SKILL.md`: persistent, shareable across machines, not tied to a specific host, filesystem, or path, app-specific delta relative to the workspace/root Pinokio instructions
202
203
  - include frontmatter with only:
203
204
  - `name`: short stable app-specific skill name using lowercase letters, digits, and hyphens only; derive it from a normalized app identity such as `<scope>-<app_id>` and keep it under 64 characters
204
205
  - `description`: one clear sentence describing what this app-specific skill does and when it should be used
206
+ - `version`: the `app_version` given with the `skill_dir`, when there is one
205
207
  - optional `clients/`: reusable local client files
206
208
  - optional `references/`: saved API artifacts such as OpenAPI specs, Gradio config, or concise notes
207
- - outputs: `<app_skill_folder>/output/<target_host>/...`
209
+ - outputs: the output folder named in the request when there is one, otherwise `<app_skill_folder>/output/<target_host>/...`
208
210
 
209
211
  - Saved app-specific `SKILL.md` policy:
210
212
  - treat it as a persistent, shareable delta relative to the workspace/root Pinokio instructions
@@ -235,6 +237,7 @@ Follow these sections in order:
235
237
  - do not add sections such as `Launch command`, `Poll status`, or `Base URL` unless the app has a genuine app-specific exception that is not already covered by the workspace/root Pinokio instructions
236
238
 
237
239
  - Reuse an existing app-specific skill when possible:
240
+ - if a `skill_state` comes with the `skill_dir`: `none` means nothing is saved yet, `current` means the saved skill can be used as it is, and `check` means it was written for a different or unknown version of the app, so verify it against the running app before relying on it and then set its `version` to the current `app_version`
238
241
  - if `<app_skill_folder>/SKILL.md` exists and still describes the app's current API correctly and still follows this policy, read it first and follow it
239
242
  - if the folder already contains a reusable client for the needed operation and it still works against the current app API and does not hardcode per-run values, reuse that client
240
243
  - if the folder has no `SKILL.md`, or the saved instructions or saved client no longer match the current API or this policy, rediscover the app interface and rewrite the app-specific skill folder
package/server/index.js CHANGED
@@ -84,6 +84,8 @@ const WorkspaceStatusManager = require("../kernel/workspace_status")
84
84
  const Setup = require("../kernel/bin/setup")
85
85
  const { createTerminalSessionHelpers } = require("./lib/terminal_session_helpers")
86
86
  const { createLauncherInstructionBootstrap } = require("./lib/launcher_instruction_bootstrap")
87
+ const { createBrain } = require("./lib/brain")
88
+ const RequestFile = require("../kernel/request_file")
87
89
  const { createTerminalGitResetHandler } = require("./lib/terminal_git_reset")
88
90
  const { createDesktopEventRouter } = require("./lib/desktop_event_router")
89
91
  const { deletePluginFolder } = require("./lib/plugin_delete")
@@ -9605,7 +9607,10 @@ class Server {
9605
9607
  params.set("cwd", targetPath)
9606
9608
  params.set("chrome", "full")
9607
9609
  if (prompt) {
9608
- params.set("prompt", prompt)
9610
+ // Create plugin: the words are in SPEC.md, and the agent is started with
9611
+ // the line that points to it (spec/requirements/request-files.md).
9612
+ const requestLine = normalizedType === "create_plugin" ? await RequestFile.forSpec(targetPath, prompt) : null
9613
+ params.set("prompt", requestLine || prompt)
9609
9614
  }
9610
9615
 
9611
9616
  return {
@@ -11890,6 +11895,12 @@ class Server {
11890
11895
  })
11891
11896
  }
11892
11897
  }))
11898
+ const brain = createBrain({
11899
+ kernel: this.kernel,
11900
+ copyUploads: copyLauncherUploadsToDir,
11901
+ pluginHref: resolveUniversalLauncherPluginHref
11902
+ })
11903
+ this.app.post("/brain/ask", ex(brain.handleAsk))
11893
11904
  this.app.post("/launcher/prepare", ex(async (req, res) => {
11894
11905
  try {
11895
11906
  const body = req.body && typeof req.body === "object" ? req.body : {}