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.
- package/kernel/agent_instructions.js +56 -0
- package/kernel/app_log_sessions.js +1 -1
- package/kernel/bin/node.js +2 -2
- package/kernel/environment.js +6 -98
- package/kernel/managed_skills.js +2 -1
- package/kernel/prototype.js +7 -0
- package/kernel/request_file.js +53 -0
- package/package.json +1 -1
- package/prototype/system/SKILL_PINOKIO.md +5 -2
- package/server/index.js +12 -1
- package/server/lib/brain.js +305 -0
- package/server/public/agent-bar-app.css +359 -0
- package/server/public/agent-bar-app.js +837 -0
- package/server/public/agent-bar-attach.css +142 -0
- package/server/public/agent-bar-attach.js +299 -0
- package/server/public/agent-bar-panel.css +788 -0
- package/server/public/agent-bar-panel.js +1915 -0
- package/server/public/agent-bar-shell.css +128 -0
- package/server/public/agent-bar-shell.js +251 -0
- package/server/public/agent-bar.css +972 -0
- package/server/public/agent-bar.js +1513 -0
- package/server/public/common.js +65 -0
- package/server/public/layout.js +13 -1
- package/server/public/logs.js +22 -0
- package/server/routes/apps.js +6 -0
- package/server/socket.js +6 -2
- package/server/views/app.ejs +13 -0
- package/server/views/partials/main_sidebar.ejs +7 -0
- package/system/plugin/opencode/pinokio.js +8 -2
- package/system/plugin/opencode-auto/pinokio.js +4 -1
- package/test/agent-instructions.test.js +69 -0
- package/test/app-log-sessions.test.js +29 -0
- package/test/brain.test.js +301 -0
- package/test/managed-skills.test.js +6 -1
- package/test/node-bin.test.js +4 -4
- package/test/request-file.test.js +93 -0
|
@@ -0,0 +1,301 @@
|
|
|
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
|
+
const git = require("isomorphic-git")
|
|
7
|
+
|
|
8
|
+
const Brain = require("../server/lib/brain")
|
|
9
|
+
|
|
10
|
+
// spec/requirements/brain.md
|
|
11
|
+
|
|
12
|
+
const author = { name: "t", email: "t@t" }
|
|
13
|
+
const newHome = (options = {}) => {
|
|
14
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), "pinokio-brain-"))
|
|
15
|
+
const kernel = { homedir: home, path: (...parts) => path.resolve(home, ...parts) }
|
|
16
|
+
const brain = Brain.createBrain({
|
|
17
|
+
kernel,
|
|
18
|
+
copyUploads: options.copyUploads || (async () => []),
|
|
19
|
+
pluginHref: options.pluginHref || ((tool) => `/run/plugin/${tool}/pinokio.js`)
|
|
20
|
+
})
|
|
21
|
+
return { home, kernel, brain, dir: path.join(home, "brain"), api: path.join(home, "api") }
|
|
22
|
+
}
|
|
23
|
+
const withHome = async (options, run) => {
|
|
24
|
+
const t = newHome(options)
|
|
25
|
+
try {
|
|
26
|
+
await run(t)
|
|
27
|
+
} finally {
|
|
28
|
+
fs.rmSync(t.home, { recursive: true, force: true })
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const write = (file, text) => {
|
|
32
|
+
fs.mkdirSync(path.dirname(file), { recursive: true })
|
|
33
|
+
fs.writeFileSync(file, text)
|
|
34
|
+
}
|
|
35
|
+
const commit = async (dir, file, text) => {
|
|
36
|
+
fs.mkdirSync(dir, { recursive: true })
|
|
37
|
+
if (!fs.existsSync(path.join(dir, ".git"))) {
|
|
38
|
+
await git.init({ fs, dir, defaultBranch: "main" })
|
|
39
|
+
}
|
|
40
|
+
fs.writeFileSync(path.join(dir, file), text)
|
|
41
|
+
await git.add({ fs, dir, filepath: file })
|
|
42
|
+
return (await git.commit({ fs, dir, message: "c", author })).slice(0, 7)
|
|
43
|
+
}
|
|
44
|
+
const skill = (appDir, version) => write(path.join(appDir, ".pinokio-skill", "SKILL.md"), `---\nname: s\ndescription: d\nversion: ${version}\n---\n`)
|
|
45
|
+
// through the same door the browser uses
|
|
46
|
+
const ask = (brain, body = {}) => new Promise((resolve) => {
|
|
47
|
+
const res = { code: 200, status(code) { this.code = code; return this }, json(value) { resolve({ code: this.code, ...value }) } }
|
|
48
|
+
brain.handleAsk({ body: { prompt: "p", tool: "claude", ...body } }, res)
|
|
49
|
+
})
|
|
50
|
+
const query = (answer) => new URL(answer.url, "http://x").searchParams
|
|
51
|
+
// spec/requirements/request-files.md: the agent gets this line, the request is in the file
|
|
52
|
+
const requestPath = (id) => `.pinokio-temp/requests/${id}.md`
|
|
53
|
+
const requestLine = (id) => `My message is in ${requestPath(id)}. Read it and respond as if I had typed it here.`
|
|
54
|
+
const requestIn = (dir, id) => fs.readFileSync(path.join(dir, ".pinokio-temp", "requests", `${id}.md`), "utf8")
|
|
55
|
+
const seen = async (kernel, name) => (await Brain.addSkills(kernel, [{ app_id: name }]))[0]
|
|
56
|
+
const logLines = (dir) => fs.readFileSync(path.join(dir, "me", "log.md"), "utf8").trim().split("\n")
|
|
57
|
+
const tree = (dir) => fs.readdirSync(dir).sort().join(" ")
|
|
58
|
+
const quietly = async (run) => {
|
|
59
|
+
const warn = console.warn
|
|
60
|
+
const said = []
|
|
61
|
+
console.warn = (...args) => said.push(args.join(" "))
|
|
62
|
+
try {
|
|
63
|
+
return { result: await run(), said }
|
|
64
|
+
} finally {
|
|
65
|
+
console.warn = warn
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
test("a top-bar Ask starts in the brain with the request and a log line", async () => {
|
|
70
|
+
await withHome({}, async (t) => {
|
|
71
|
+
const a = await ask(t.brain, { prompt: " say hello " })
|
|
72
|
+
const id = query(a).get("session")
|
|
73
|
+
assert.deepEqual(Object.keys(a).sort(), ["code", "cwd", "ok", "url"])
|
|
74
|
+
assert.equal(a.cwd, t.dir)
|
|
75
|
+
assert.equal(query(a).get("cwd"), t.dir)
|
|
76
|
+
assert.equal(query(a).get("chrome"), "full")
|
|
77
|
+
assert.match(id, /^\d{8}-[a-f0-9]{8}$/)
|
|
78
|
+
assert.equal(query(a).get("prompt"), requestLine(id), "the agent is started with the request line, not the request")
|
|
79
|
+
assert.equal(requestIn(t.dir, id), `say hello\n\nOutput folder: me/files/${id}/\n`)
|
|
80
|
+
assert.equal(tree(t.dir), ".pinokio-temp AGENTS.md CLAUDE.md GEMINI.md me")
|
|
81
|
+
assert.equal(tree(path.join(t.dir, "me")), "files log.md")
|
|
82
|
+
assert.equal(fs.existsSync(path.join(t.dir, "me", "files", id)), false, "the output folder is named, not created")
|
|
83
|
+
assert.match(logLines(t.dir)[0], new RegExp(`^- \\d{4}-\\d\\d-\\d\\d \\d\\d:\\d\\d \\| ${id} \\| claude \\| say hello$`))
|
|
84
|
+
|
|
85
|
+
const empty = await ask(t.brain, { prompt: "" })
|
|
86
|
+
assert.equal(query(empty).get("prompt"), null)
|
|
87
|
+
assert.equal(tree(path.join(t.dir, ".pinokio-temp", "requests")), `${id}.md`, "an empty request has no file")
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test("attached files are copied into the Ask's folder and named in the request", async () => {
|
|
92
|
+
await withHome({ copyUploads: async (token, dir) => { fs.writeFileSync(path.join(dir, "a.jpg"), "x"); return ["a.jpg"] } }, async (t) => {
|
|
93
|
+
const a = await ask(t.brain, { prompt: "crop", uploadToken: "a".repeat(32) })
|
|
94
|
+
const id = query(a).get("session")
|
|
95
|
+
assert.equal(query(a).get("prompt"), requestLine(id))
|
|
96
|
+
assert.equal(requestIn(t.dir, id), `crop\n\nAttached files:\n- me/files/${id}/a.jpg\n\nOutput folder: me/files/${id}/\n`)
|
|
97
|
+
assert.equal(fs.existsSync(path.join(t.dir, "me", "files", id, "a.jpg")), true)
|
|
98
|
+
})
|
|
99
|
+
await withHome({}, async (t) => {
|
|
100
|
+
const a = await ask(t.brain, { prompt: "nothing copied", uploadToken: "a".repeat(32) })
|
|
101
|
+
assert.equal(fs.existsSync(path.join(t.dir, "me", "files", query(a).get("session"))), false)
|
|
102
|
+
assert.equal(requestIn(t.dir, query(a).get("session")).includes("Attached files"), false)
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
test("an Ask whose request file cannot be written is not sent", async () => {
|
|
107
|
+
await withHome({}, async (t) => {
|
|
108
|
+
fs.mkdirSync(t.dir, { recursive: true })
|
|
109
|
+
fs.writeFileSync(path.join(t.dir, ".pinokio-temp"), "not a folder")
|
|
110
|
+
const a = await ask(t.brain)
|
|
111
|
+
assert.deepEqual([a.code, a.ok, "url" in a], [500, false, false])
|
|
112
|
+
|
|
113
|
+
const app = path.join(t.api, "Thing")
|
|
114
|
+
fs.mkdirSync(app, { recursive: true })
|
|
115
|
+
fs.writeFileSync(path.join(app, ".pinokio-temp"), "not a folder")
|
|
116
|
+
const b = await ask(t.brain, { app: "Thing" })
|
|
117
|
+
assert.deepEqual([b.code, b.ok, "prompt" in b], [500, false, false])
|
|
118
|
+
assert.equal(fs.existsSync(path.join(t.dir, "me", "log.md")), false, "an Ask that was not sent is not logged")
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
test("only an unknown tool, the brain folder, a failed copy or the request file can stop a top-bar Ask", async () => {
|
|
123
|
+
await withHome({ pluginHref: () => { throw Object.assign(new Error("No such plugin."), { status: 400 }) } }, async (t) => {
|
|
124
|
+
const a = await ask(t.brain)
|
|
125
|
+
assert.deepEqual([a.code, a.ok, a.error], [400, false, "No such plugin."])
|
|
126
|
+
assert.equal(fs.existsSync(t.dir), false, "nothing is written")
|
|
127
|
+
})
|
|
128
|
+
await withHome({ copyUploads: async () => { throw Object.assign(new Error("Upload expired."), { status: 400 }) } }, async (t) => {
|
|
129
|
+
const a = await ask(t.brain, { uploadToken: "a".repeat(32) })
|
|
130
|
+
assert.deepEqual([a.code, a.ok], [400, false])
|
|
131
|
+
assert.equal(fs.readdirSync(path.join(t.dir, "me", "files")).length, 0)
|
|
132
|
+
})
|
|
133
|
+
await withHome({}, async (t) => {
|
|
134
|
+
fs.mkdirSync(t.dir, { recursive: true })
|
|
135
|
+
fs.writeFileSync(path.join(t.dir, "me"), "not a folder")
|
|
136
|
+
const { result, said } = await quietly(() => ask(t.brain))
|
|
137
|
+
assert.equal(result.ok, true)
|
|
138
|
+
assert.ok(said.some((line) => line.includes("folders failed")))
|
|
139
|
+
assert.ok(said.some((line) => line.includes("log failed")))
|
|
140
|
+
})
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
test("the instruction files are fixed text", async () => {
|
|
144
|
+
await withHome({}, async (t) => {
|
|
145
|
+
await ask(t.brain, { prompt: "first" })
|
|
146
|
+
const file = path.join(t.dir, "AGENTS.md")
|
|
147
|
+
const first = fs.readFileSync(file, "utf8")
|
|
148
|
+
const own = first.includes("\n## Pinokio\n") ? first.slice(0, first.indexOf("\n## Pinokio\n")) : first
|
|
149
|
+
assert.ok(first.startsWith("# Pinokio Brain\n"))
|
|
150
|
+
assert.ok(own.includes("## Which app to use"))
|
|
151
|
+
assert.ok(own.includes("read `me/preferences.md` if it exists"))
|
|
152
|
+
assert.ok(own.includes("ask the user once, in one line, whether to use that app for this kind of task from now on. Write the line only if they say yes."))
|
|
153
|
+
assert.equal(/apps\/|Apps with/i.test(own), false, "no list of apps")
|
|
154
|
+
assert.equal(fs.readFileSync(path.join(t.dir, "CLAUDE.md"), "utf8"), first)
|
|
155
|
+
assert.equal(fs.readFileSync(path.join(t.dir, "GEMINI.md"), "utf8"), first)
|
|
156
|
+
|
|
157
|
+
const stamp = fs.statSync(file).mtimeMs
|
|
158
|
+
const app = path.join(t.api, "Speech")
|
|
159
|
+
skill(app, await commit(app, "pinokio.js", "1"))
|
|
160
|
+
write(path.join(t.dir, "me", "preferences.md"), "- speak text aloud: `Speech`\n")
|
|
161
|
+
await new Promise((resolve) => setTimeout(resolve, 20))
|
|
162
|
+
await ask(t.brain, { prompt: "something else entirely" })
|
|
163
|
+
assert.equal(fs.readFileSync(file, "utf8"), first)
|
|
164
|
+
assert.equal(fs.statSync(file).mtimeMs, stamp, "not rewritten")
|
|
165
|
+
assert.equal(fs.readFileSync(path.join(t.dir, "me", "preferences.md"), "utf8"), "- speak text aloud: `Speech`\n", "Pinokio never writes the preferences")
|
|
166
|
+
})
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
test("Pinokio only writes an instruction file that is missing or its own", async () => {
|
|
170
|
+
await withHome({}, async (t) => {
|
|
171
|
+
write(path.join(t.dir, "AGENTS.md"), "")
|
|
172
|
+
write(path.join(t.dir, "CLAUDE.md"), "# Pinokio Brain\r\nan older copy with Windows line ends\r\n")
|
|
173
|
+
write(path.join(t.dir, "GEMINI.md"), "# Pinokio Brainstorm\nmy own notes\n")
|
|
174
|
+
await ask(t.brain)
|
|
175
|
+
assert.equal(fs.readFileSync(path.join(t.dir, "AGENTS.md"), "utf8"), "", "an empty file that is not Pinokio's")
|
|
176
|
+
assert.ok(fs.readFileSync(path.join(t.dir, "CLAUDE.md"), "utf8").includes("## Which app to use"), "its own older copy is put back")
|
|
177
|
+
assert.equal(fs.readFileSync(path.join(t.dir, "GEMINI.md"), "utf8"), "# Pinokio Brainstorm\nmy own notes\n")
|
|
178
|
+
assert.equal(fs.existsSync(path.join(t.dir, ".git")), false, "the brain is never a git repository")
|
|
179
|
+
})
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
test("the log puts a request on one line and cuts it at 200 characters", async () => {
|
|
183
|
+
await withHome({}, async (t) => {
|
|
184
|
+
await ask(t.brain, { prompt: `line one\n line two ${"x".repeat(300)}`, tool: "some agent" })
|
|
185
|
+
const words = logLines(t.dir)[0].split(" | ").slice(3).join(" | ")
|
|
186
|
+
assert.equal(logLines(t.dir).length, 1)
|
|
187
|
+
assert.ok(words.startsWith("line one line two x"))
|
|
188
|
+
assert.equal(words.length, 201)
|
|
189
|
+
assert.ok(words.endsWith("…"))
|
|
190
|
+
const many = await Promise.all(Array.from({ length: 20 }, (_, i) => ask(t.brain, { prompt: `parallel ${i}` })))
|
|
191
|
+
assert.equal(new Set(many.map((a) => query(a).get("session"))).size, 20)
|
|
192
|
+
assert.equal(logLines(t.dir).length, 21)
|
|
193
|
+
})
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
test("an app's skill lives in the app's own folder and hides itself from git", async () => {
|
|
197
|
+
await withHome({}, async (t) => {
|
|
198
|
+
const app = path.join(t.api, "Plain")
|
|
199
|
+
const first = await commit(app, "pinokio.js", "1")
|
|
200
|
+
let s = await seen(t.kernel, "Plain")
|
|
201
|
+
assert.deepEqual(s, { app_id: "Plain", skill_dir: path.join(app, ".pinokio-skill"), skill_state: "none", app_version: first })
|
|
202
|
+
assert.equal(tree(app), ".git pinokio.js", "an app with no skill is not touched")
|
|
203
|
+
|
|
204
|
+
skill(app, first)
|
|
205
|
+
s = await seen(t.kernel, "Plain")
|
|
206
|
+
assert.equal(s.skill_state, "current")
|
|
207
|
+
assert.equal(fs.readFileSync(path.join(app, ".pinokio-skill", ".gitignore"), "utf8"), "*\n")
|
|
208
|
+
const visible = (await git.statusMatrix({ fs, dir: app })).filter((row) => row[0].startsWith(".pinokio-skill"))
|
|
209
|
+
assert.deepEqual(visible, [], "git no longer sees the folder")
|
|
210
|
+
assert.equal(fs.existsSync(path.join(app, ".git", "info", "exclude")) && /pinokio-skill/.test(fs.readFileSync(path.join(app, ".git", "info", "exclude"), "utf8")), false)
|
|
211
|
+
|
|
212
|
+
fs.writeFileSync(path.join(app, ".pinokio-skill", ".gitignore"), "mine\n")
|
|
213
|
+
await seen(t.kernel, "Plain")
|
|
214
|
+
assert.equal(fs.readFileSync(path.join(app, ".pinokio-skill", ".gitignore"), "utf8"), "mine\n", "never replaced")
|
|
215
|
+
|
|
216
|
+
const copy = path.join(t.api, "Plain-copy")
|
|
217
|
+
await commit(copy, "pinokio.js", "1")
|
|
218
|
+
assert.equal((await seen(t.kernel, "Plain-copy")).skill_state, "none", "another copy has its own skill")
|
|
219
|
+
assert.equal((await seen(t.kernel, "Plain-copy")).skill_dir, path.join(copy, ".pinokio-skill"))
|
|
220
|
+
|
|
221
|
+
write(path.join(app, ".pinokio-skill", "SKILL.md"), "")
|
|
222
|
+
assert.equal((await seen(t.kernel, "Plain")).skill_state, "none", "an empty SKILL.md")
|
|
223
|
+
assert.equal((await seen(t.kernel, "not-installed")).skill_state, "none")
|
|
224
|
+
assert.equal(fs.existsSync(path.join(t.api, "not-installed")), false)
|
|
225
|
+
})
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
test("the version covers the app's folder and the code repositories it keeps", async () => {
|
|
229
|
+
await withHome({}, async (t) => {
|
|
230
|
+
const app = path.join(t.api, "Both")
|
|
231
|
+
const launcher = await commit(app, "pinokio.js", "1")
|
|
232
|
+
assert.equal((await seen(t.kernel, "Both")).app_version, launcher)
|
|
233
|
+
|
|
234
|
+
const code = await commit(path.join(app, "app"), "main.py", "1")
|
|
235
|
+
assert.equal((await seen(t.kernel, "Both")).app_version, `${launcher}+${code}`)
|
|
236
|
+
skill(app, `${launcher}+${code}`)
|
|
237
|
+
assert.equal((await seen(t.kernel, "Both")).skill_state, "current")
|
|
238
|
+
|
|
239
|
+
const updated = await commit(path.join(app, "app"), "main.py", "2")
|
|
240
|
+
let s = await seen(t.kernel, "Both")
|
|
241
|
+
assert.deepEqual([s.skill_state, s.app_version], ["check", `${launcher}+${updated}`], "the code was updated, the launcher was not")
|
|
242
|
+
|
|
243
|
+
const other = await commit(path.join(app, "tool"), "main.py", "3")
|
|
244
|
+
const nested = await commit(path.join(app, "app", "comfyui"), "main.py", "4")
|
|
245
|
+
await commit(path.join(app, "app", "comfyui", "custom_nodes", "deep"), "main.py", "5")
|
|
246
|
+
s = await seen(t.kernel, "Both")
|
|
247
|
+
assert.equal(s.app_version, `${launcher}+${updated}+${other}+${nested}`, "one level inside the folder and inside app, no deeper")
|
|
248
|
+
|
|
249
|
+
const bare = path.join(t.api, "Bare")
|
|
250
|
+
skill(bare, "abc1234")
|
|
251
|
+
s = await seen(t.kernel, "Bare")
|
|
252
|
+
assert.deepEqual([s.skill_state, s.app_version], ["current", ""], "an app with no git history is never check")
|
|
253
|
+
})
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
test("an app-page Ask writes the request into the app's folder and gets back the request line", async () => {
|
|
257
|
+
await withHome({}, async (t) => {
|
|
258
|
+
const app = path.join(t.api, "Plain")
|
|
259
|
+
const version = await commit(app, "pinokio.js", "1")
|
|
260
|
+
skill(app, "older")
|
|
261
|
+
const a = await ask(t.brain, { app: "Plain", prompt: "say hi" })
|
|
262
|
+
const id = logLines(t.dir)[0].split(" | ")[1]
|
|
263
|
+
const brainLines = (appDir, state, outputId) => `Pinokio brain:\n- This app's skill (skill_dir): ${path.join(appDir, ".pinokio-skill")} (skill_state: ${state})\n- Output folder: ${path.join(t.dir, "me", "files", outputId)}`
|
|
264
|
+
assert.deepEqual(Object.keys(a).sort(), ["code", "ok", "prompt"])
|
|
265
|
+
assert.equal(a.prompt, requestLine(id))
|
|
266
|
+
assert.equal(requestIn(app, id), `say hi\n\n${brainLines(app, `check, app_version: ${version}`, id)}\n`)
|
|
267
|
+
assert.match(logLines(t.dir)[0], new RegExp(`\\| ${id} \\| claude in Plain \\| say hi$`))
|
|
268
|
+
assert.equal(tree(t.dir), "me", "the instruction files are not written")
|
|
269
|
+
|
|
270
|
+
fs.mkdirSync(path.join(t.api, "NoGit"))
|
|
271
|
+
const noGit = path.join(t.api, "NoGit")
|
|
272
|
+
await ask(t.brain, { app: "NoGit", prompt: "x" })
|
|
273
|
+
const plainId = logLines(t.dir)[1].split(" | ")[1]
|
|
274
|
+
assert.ok(requestIn(noGit, plainId).includes("(skill_state: none)\n"), "no version, so none is named")
|
|
275
|
+
|
|
276
|
+
// files the page uploaded for this app are named in the request; with no words they are still a request
|
|
277
|
+
const upload = path.join(noGit, ".pinokio-temp", "uploads", "t", "a.png")
|
|
278
|
+
await ask(t.brain, { app: "NoGit", prompt: "", files: [upload] })
|
|
279
|
+
const fileId = logLines(t.dir)[2].split(" | ")[1]
|
|
280
|
+
assert.equal(requestIn(noGit, fileId), `Attached files:\n- ${upload}\n\n${brainLines(noGit, "none", fileId)}\n`)
|
|
281
|
+
|
|
282
|
+
// anything else is refused and nothing is written
|
|
283
|
+
const before = tree(path.join(noGit, ".pinokio-temp", "requests"))
|
|
284
|
+
for (const files of [[path.join(noGit, "pinokio.js")], [path.join(noGit, ".pinokio-temp", "uploads")], [path.join(noGit, ".pinokio-temp", "uploads", "..", "..", "x")], [path.join(t.api, "Plain", ".pinokio-temp", "uploads", "t", "a.png")], [7]]) {
|
|
285
|
+
const refused = await ask(t.brain, { app: "NoGit", prompt: "x", files })
|
|
286
|
+
assert.deepEqual([refused.code, refused.ok], [400, false], JSON.stringify(files))
|
|
287
|
+
}
|
|
288
|
+
const emptyAsk = await ask(t.brain, { app: "NoGit", prompt: "", files: [] })
|
|
289
|
+
assert.deepEqual([emptyAsk.code, emptyAsk.ok], [400, false], "an empty request is not an Ask")
|
|
290
|
+
assert.equal(tree(path.join(noGit, ".pinokio-temp", "requests")), before)
|
|
291
|
+
assert.equal(logLines(t.dir).length, 3)
|
|
292
|
+
})
|
|
293
|
+
await withHome({}, async (t) => {
|
|
294
|
+
fs.mkdirSync(path.join(t.api, "Thing"), { recursive: true })
|
|
295
|
+
for (const bad of ["../Thing", "..", ".", "a/b", "a\\b", "C:", "nope"]) {
|
|
296
|
+
const a = await ask(t.brain, { app: bad })
|
|
297
|
+
assert.deepEqual([bad, a.code, a.ok], [bad, 404, false])
|
|
298
|
+
}
|
|
299
|
+
assert.equal(fs.existsSync(t.dir), false, "nothing is written for a refused name")
|
|
300
|
+
})
|
|
301
|
+
})
|
|
@@ -13,7 +13,10 @@ async function withTempHome(fn) {
|
|
|
13
13
|
await fs.mkdir(homedir, { recursive: true })
|
|
14
14
|
await fs.mkdir(userhome, { recursive: true })
|
|
15
15
|
try {
|
|
16
|
-
|
|
16
|
+
// the launcher guide's template, which the gepeto skill is made from
|
|
17
|
+
await fs.mkdir(path.resolve(homedir, "prototype/system/structure"), { recursive: true })
|
|
18
|
+
await fs.writeFile(path.resolve(homedir, "prototype/system/AGENTS.md"), "# Home instructions\n\nUse Pinokio carefully.\n")
|
|
19
|
+
await fs.writeFile(path.resolve(homedir, "prototype/system/structure/clone"), "")
|
|
17
20
|
await fn({
|
|
18
21
|
root,
|
|
19
22
|
homedir,
|
|
@@ -21,6 +24,8 @@ async function withTempHome(fn) {
|
|
|
21
24
|
kernel: {
|
|
22
25
|
homedir,
|
|
23
26
|
path: (...parts) => path.resolve(homedir, ...parts),
|
|
27
|
+
exists: (target) => fs.access(target).then(() => true, () => false),
|
|
28
|
+
renderFile: (target) => fs.readFile(target, "utf8"),
|
|
24
29
|
exec: async () => {}
|
|
25
30
|
},
|
|
26
31
|
publishRoots: ManagedSkills.publishRoots(userhome)
|
package/test/node-bin.test.js
CHANGED
|
@@ -3,7 +3,7 @@ const test = require('node:test')
|
|
|
3
3
|
|
|
4
4
|
const Node = require('../kernel/bin/node')
|
|
5
5
|
|
|
6
|
-
function createNode({ nodeVersion = '24.22.
|
|
6
|
+
function createNode({ nodeVersion = '24.22.3', pnpmVersion = '11.24.0', hasNode = true, hasPnpm = true } = {}) {
|
|
7
7
|
const node = new Node()
|
|
8
8
|
const conda = new Set()
|
|
9
9
|
if (hasNode) conda.add('nodejs')
|
|
@@ -23,13 +23,13 @@ function createNode({ nodeVersion = '24.22.1', pnpmVersion = '11.9.0', hasNode =
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
test('Node bin pins Node.js 24 LTS and matching pnpm', () => {
|
|
26
|
-
assert.equal(createNode().cmd(), 'nodejs=24.22.
|
|
26
|
+
assert.equal(createNode().cmd(), 'nodejs=24.22.3 pnpm=11.24.0')
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
test('Node.installed accepts exactly the pinned Node.js and pnpm versions', async () => {
|
|
30
30
|
assert.equal(await createNode().installed(), true)
|
|
31
|
-
assert.equal(await createNode({ nodeVersion: '24.22.
|
|
32
|
-
assert.equal(await createNode({ pnpmVersion: '11.
|
|
31
|
+
assert.equal(await createNode({ nodeVersion: '24.22.3-h654b19f_0' }).installed(), true)
|
|
32
|
+
assert.equal(await createNode({ pnpmVersion: '11.24.0-h7c87c79_0' }).installed(), true)
|
|
33
33
|
assert.equal(await createNode({ nodeVersion: '22.21.1' }).installed(), false)
|
|
34
34
|
assert.equal(await createNode({ nodeVersion: '26.4.0' }).installed(), false)
|
|
35
35
|
assert.equal(await createNode({ pnpmVersion: '10.29.3' }).installed(), false)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
// spec/requirements/request-files.md
|
|
4
|
+
const test = require("node:test")
|
|
5
|
+
const assert = require("node:assert/strict")
|
|
6
|
+
const fs = require("fs")
|
|
7
|
+
const os = require("os")
|
|
8
|
+
const path = require("path")
|
|
9
|
+
const RequestFile = require("../kernel/request_file")
|
|
10
|
+
|
|
11
|
+
const withFolder = async (run) => {
|
|
12
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "pinokio-request-file-"))
|
|
13
|
+
try {
|
|
14
|
+
await run(dir)
|
|
15
|
+
} finally {
|
|
16
|
+
fs.rmSync(dir, { recursive: true, force: true })
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const LINE = (file) => `My message is in ${file}. Read it and respond as if I had typed it here.`
|
|
20
|
+
|
|
21
|
+
test("the request line is one line that names the file", () => {
|
|
22
|
+
assert.equal(RequestFile.line("SPEC.md"), LINE("SPEC.md"))
|
|
23
|
+
assert.equal(/[\r\n]/.test(RequestFile.line(".pinokio-temp/requests/20261117-aaaaaaaa.md")), false)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test("an Ask's request is saved in the folder the agent starts in, lines intact", async () => {
|
|
27
|
+
await withFolder(async (dir) => {
|
|
28
|
+
const line = await RequestFile.save(dir, "20261117-aaaaaaaa", "one\n\ntwo\n- three")
|
|
29
|
+
assert.equal(line, LINE(".pinokio-temp/requests/20261117-aaaaaaaa.md"), "the path uses / on every system")
|
|
30
|
+
assert.equal(fs.readFileSync(path.join(dir, ".pinokio-temp", "requests", "20261117-aaaaaaaa.md"), "utf8"), "one\n\ntwo\n- three\n")
|
|
31
|
+
await RequestFile.save(dir, "20261117-bbbbbbbb", "another")
|
|
32
|
+
assert.equal(fs.readdirSync(path.join(dir, ".pinokio-temp", "requests")).length, 2, "an earlier request is kept")
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test("a new folder's request line points to the SPEC.md that holds the words", async () => {
|
|
37
|
+
await withFolder(async (dir) => {
|
|
38
|
+
assert.equal(await RequestFile.forSpec(dir, "build a thing"), null, "no SPEC.md")
|
|
39
|
+
fs.writeFileSync(path.join(dir, "SPEC.md"), "build a thing\nwith two lines\n")
|
|
40
|
+
assert.equal(await RequestFile.forSpec(dir, " build a thing\nwith two lines "), LINE("SPEC.md"))
|
|
41
|
+
assert.equal(await RequestFile.forSpec(dir, "something else"), null, "SPEC.md holds other words")
|
|
42
|
+
assert.equal(await RequestFile.forSpec(dir, ""), null, "no words")
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test("a start address carries the request line in place of the words", async () => {
|
|
47
|
+
await withFolder(async (dir) => {
|
|
48
|
+
const words = "make a radio\n\nwith a queue & a 100% volume knob"
|
|
49
|
+
const address = `/p/radio/dev?plugin=/plugin/codex/pinokio.js&prompt=${encodeURIComponent(words)}`
|
|
50
|
+
assert.equal(await RequestFile.pointAddressToSpec(address, dir), address, "left alone without SPEC.md")
|
|
51
|
+
fs.writeFileSync(path.join(dir, "SPEC.md"), `${words}\n`)
|
|
52
|
+
const pointed = new URL(await RequestFile.pointAddressToSpec(address, dir), "http://x")
|
|
53
|
+
assert.equal(pointed.pathname, "/p/radio/dev")
|
|
54
|
+
assert.equal(pointed.searchParams.get("plugin"), "/plugin/codex/pinokio.js")
|
|
55
|
+
assert.equal(pointed.searchParams.get("prompt"), LINE("SPEC.md"))
|
|
56
|
+
for (const same of ["/p/radio/dev", "/p/radio/dev?plugin=/plugin/codex/pinokio.js&prompt=", undefined, ""]) {
|
|
57
|
+
assert.equal(await RequestFile.pointAddressToSpec(same, dir), same)
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
test("creating an app hands back an address that carries the request line", async () => {
|
|
63
|
+
const Proto = require("../kernel/prototype")
|
|
64
|
+
await withFolder(async (home) => {
|
|
65
|
+
// a creation script that does what the real ones do with the words:
|
|
66
|
+
// save them as SPEC.md and put them in the address
|
|
67
|
+
const script = path.join(home, "prototype", "system", "default", "new", "index.js")
|
|
68
|
+
fs.mkdirSync(path.dirname(script), { recursive: true })
|
|
69
|
+
fs.writeFileSync(script, `
|
|
70
|
+
const fs = require("fs"), path = require("path")
|
|
71
|
+
module.exports = async (req) => {
|
|
72
|
+
fs.mkdirSync(req.cwd, { recursive: true })
|
|
73
|
+
if (req.input.aiPrompt) fs.writeFileSync(path.resolve(req.cwd, "SPEC.md"), req.input.aiPrompt + "\\n")
|
|
74
|
+
return { success: "/p/" + req.input.name + "/dev?plugin=/plugin/" + req.input.tool + "/pinokio.js&prompt=" + encodeURIComponent(req.input.aiPrompt) }
|
|
75
|
+
}`)
|
|
76
|
+
const kernel = { path: (...parts) => path.resolve(home, ...parts), require: async (file) => require(file) }
|
|
77
|
+
const log = console.log
|
|
78
|
+
console.log = () => {}
|
|
79
|
+
let made
|
|
80
|
+
let bare
|
|
81
|
+
try {
|
|
82
|
+
made = await new Proto(kernel).create({ cwd: path.join(home, "api"), params: { name: "radio", projectType: "default", startType: "new", aiPrompt: "make a radio\nwith a queue", tool: "codex" } }, () => {})
|
|
83
|
+
bare = await new Proto(kernel).create({ cwd: path.join(home, "api"), params: { name: "empty", projectType: "default", startType: "new", aiPrompt: "", tool: "codex" } }, () => {})
|
|
84
|
+
} finally {
|
|
85
|
+
console.log = log
|
|
86
|
+
}
|
|
87
|
+
const address = new URL(made.success, "http://x")
|
|
88
|
+
assert.equal(address.pathname, "/p/radio/dev")
|
|
89
|
+
assert.equal(address.searchParams.get("prompt"), LINE("SPEC.md"))
|
|
90
|
+
assert.equal(fs.readFileSync(path.join(home, "api", "radio", "SPEC.md"), "utf8"), "make a radio\nwith a queue\n")
|
|
91
|
+
assert.equal(new URL(bare.success, "http://x").searchParams.get("prompt"), "", "no words, nothing to point to")
|
|
92
|
+
})
|
|
93
|
+
})
|