pinokiod 8.3.9 → 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/prototype.js +7 -0
- package/kernel/request_file.js +53 -0
- package/package.json +1 -1
- package/server/index.js +5 -1
- package/server/lib/brain.js +40 -14
- package/server/public/agent-bar-app.js +33 -17
- package/server/public/agent-bar-panel.js +6 -3
- package/server/public/logs.js +22 -0
- package/test/brain.test.js +54 -10
- package/test/request-file.test.js +93 -0
package/kernel/prototype.js
CHANGED
|
@@ -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
package/server/index.js
CHANGED
|
@@ -85,6 +85,7 @@ 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
87
|
const { createBrain } = require("./lib/brain")
|
|
88
|
+
const RequestFile = require("../kernel/request_file")
|
|
88
89
|
const { createTerminalGitResetHandler } = require("./lib/terminal_git_reset")
|
|
89
90
|
const { createDesktopEventRouter } = require("./lib/desktop_event_router")
|
|
90
91
|
const { deletePluginFolder } = require("./lib/plugin_delete")
|
|
@@ -9606,7 +9607,10 @@ class Server {
|
|
|
9606
9607
|
params.set("cwd", targetPath)
|
|
9607
9608
|
params.set("chrome", "full")
|
|
9608
9609
|
if (prompt) {
|
|
9609
|
-
|
|
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)
|
|
9610
9614
|
}
|
|
9611
9615
|
|
|
9612
9616
|
return {
|
package/server/lib/brain.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// me/preferences.md which app the user wants for which kind of task
|
|
8
8
|
// me/log.md one line per Ask
|
|
9
9
|
// me/files/<id>/ the files given to, or made by, one Ask
|
|
10
|
+
// .pinokio-temp/requests/<id>.md one Ask's request (kernel/request_file.js)
|
|
10
11
|
//
|
|
11
12
|
// What agents learn about an app is not kept here but in the app's own folder:
|
|
12
13
|
//
|
|
@@ -17,13 +18,15 @@
|
|
|
17
18
|
// app's skill is, writes the instruction files and adds a log line. It only
|
|
18
19
|
// rewrites instruction files it wrote itself, and none of this bookkeeping can
|
|
19
20
|
// stop an Ask. An Ask from an app's page runs in the app's own folder, so there
|
|
20
|
-
// the place of the app's skill and the output folder are added to the request
|
|
21
|
+
// the place of the app's skill and the output folder are added to the request,
|
|
22
|
+
// which is written into that folder's .pinokio-temp/requests.
|
|
21
23
|
|
|
22
24
|
const fs = require("fs")
|
|
23
25
|
const path = require("path")
|
|
24
26
|
const crypto = require("crypto")
|
|
25
27
|
const git = require("isomorphic-git")
|
|
26
28
|
const ManagedSkills = require("../../kernel/managed_skills")
|
|
29
|
+
const RequestFile = require("../../kernel/request_file")
|
|
27
30
|
|
|
28
31
|
const LOG_PROMPT_LENGTH = 200
|
|
29
32
|
const BRAIN_HEADING = "# Pinokio Brain"
|
|
@@ -202,8 +205,12 @@ const createBrain = ({ kernel, copyUploads, pluginHref }) => {
|
|
|
202
205
|
request.push(`Attached files:\n${copied.map((name) => `- me/files/${id}/${name}`).join("\n")}`)
|
|
203
206
|
}
|
|
204
207
|
}
|
|
208
|
+
// The agent is started with one line that points to the request, which is
|
|
209
|
+
// in a file in this folder (spec/requirements/request-files.md).
|
|
210
|
+
let requestLine = ""
|
|
205
211
|
if (request.length > 0) {
|
|
206
212
|
request.push(`Output folder: me/files/${id}/`)
|
|
213
|
+
requestLine = await RequestFile.save(dir, id, request.join("\n\n"))
|
|
207
214
|
}
|
|
208
215
|
|
|
209
216
|
await attempt("instructions", () => writeInstructions(dir))
|
|
@@ -213,8 +220,8 @@ const createBrain = ({ kernel, copyUploads, pluginHref }) => {
|
|
|
213
220
|
params.set("cwd", dir)
|
|
214
221
|
params.set("chrome", "full")
|
|
215
222
|
params.set("session", id)
|
|
216
|
-
if (
|
|
217
|
-
params.set("prompt",
|
|
223
|
+
if (requestLine) {
|
|
224
|
+
params.set("prompt", requestLine)
|
|
218
225
|
}
|
|
219
226
|
return {
|
|
220
227
|
ok: true,
|
|
@@ -224,30 +231,48 @@ const createBrain = ({ kernel, copyUploads, pluginHref }) => {
|
|
|
224
231
|
}
|
|
225
232
|
|
|
226
233
|
// An Ask from an app's page. The agent runs in the app's folder, which the
|
|
227
|
-
// page starts itself; this
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
234
|
+
// page starts itself; this writes the request into that folder and hands back
|
|
235
|
+
// the line the page starts the agent with (spec/requirements/request-files.md).
|
|
236
|
+
const prepareForApp = async ({ app, prompt, tool, files }) => {
|
|
237
|
+
const appDir = /^[^/\\:]+$/.test(app) && app !== "." && app !== ".." ? kernel.path("api", app) : ""
|
|
238
|
+
const appStat = appDir ? await fs.promises.stat(appDir).catch(() => null) : null
|
|
232
239
|
if (!appStat || !appStat.isDirectory()) {
|
|
233
240
|
const error = new Error("App not found.")
|
|
234
241
|
error.status = 404
|
|
235
242
|
throw error
|
|
236
243
|
}
|
|
244
|
+
// only files the page uploaded for this app
|
|
245
|
+
const uploads = path.resolve(appDir, ".pinokio-temp", "uploads")
|
|
246
|
+
const attached = files.map((file) => (typeof file === "string" ? path.resolve(file) : ""))
|
|
247
|
+
const outside = attached.some((file) => {
|
|
248
|
+
const inside = file ? path.relative(uploads, file) : ""
|
|
249
|
+
return !inside || inside.startsWith("..") || path.isAbsolute(inside)
|
|
250
|
+
})
|
|
251
|
+
if (outside || (!prompt && attached.length === 0)) {
|
|
252
|
+
const error = new Error(outside ? "Attached files must be this app's uploads." : "The request is empty.")
|
|
253
|
+
error.status = 400
|
|
254
|
+
throw error
|
|
255
|
+
}
|
|
237
256
|
const dir = brainRoot(kernel)
|
|
238
257
|
const now = new Date()
|
|
239
258
|
const id = newId(now)
|
|
240
259
|
await makeFolders(dir)
|
|
241
260
|
|
|
242
261
|
const { skill_dir, skill_state, app_version } = await describeApp(kernel, app)
|
|
262
|
+
const request = prompt ? [prompt] : []
|
|
263
|
+
if (attached.length > 0) {
|
|
264
|
+
request.push(`Attached files:\n${attached.map((file) => `- ${file}`).join("\n")}`)
|
|
265
|
+
}
|
|
266
|
+
request.push([
|
|
267
|
+
"Pinokio brain:",
|
|
268
|
+
`- This app's skill (skill_dir): ${skill_dir} (skill_state: ${skill_state}${app_version ? `, app_version: ${app_version}` : ""})`,
|
|
269
|
+
`- Output folder: ${path.resolve(dir, "me", "files", id)}`
|
|
270
|
+
].join("\n"))
|
|
271
|
+
const requestLine = await RequestFile.save(appDir, id, request.join("\n\n"))
|
|
243
272
|
await attempt("log", () => appendLog(dir, { id, now, tool, app, prompt }))
|
|
244
273
|
return {
|
|
245
274
|
ok: true,
|
|
246
|
-
|
|
247
|
-
"Pinokio brain:",
|
|
248
|
-
`- This app's skill (skill_dir): ${skill_dir} (skill_state: ${skill_state}${app_version ? `, app_version: ${app_version}` : ""})`,
|
|
249
|
-
`- Output folder: ${path.resolve(dir, "me", "files", id)}`
|
|
250
|
-
].join("\n")
|
|
275
|
+
prompt: requestLine
|
|
251
276
|
}
|
|
252
277
|
}
|
|
253
278
|
|
|
@@ -258,7 +283,8 @@ const createBrain = ({ kernel, copyUploads, pluginHref }) => {
|
|
|
258
283
|
prompt: typeof body.prompt === "string" ? body.prompt.trim() : "",
|
|
259
284
|
tool: typeof body.tool === "string" ? body.tool : "",
|
|
260
285
|
uploadToken: typeof body.uploadToken === "string" ? body.uploadToken.trim() : "",
|
|
261
|
-
app: typeof body.app === "string" ? body.app : ""
|
|
286
|
+
app: typeof body.app === "string" ? body.app : "",
|
|
287
|
+
files: Array.isArray(body.files) ? body.files : []
|
|
262
288
|
}
|
|
263
289
|
res.json(await (ask.app ? prepareForApp(ask) : prepare(ask)))
|
|
264
290
|
} catch (error) {
|
|
@@ -677,7 +677,11 @@
|
|
|
677
677
|
// One send at a time: a second Enter while the agents are still being read
|
|
678
678
|
// must not start a second agent.
|
|
679
679
|
let sending = false;
|
|
680
|
-
|
|
680
|
+
// `given` is text another part of the page sends for the user (Get Help's
|
|
681
|
+
// Ask AI). It goes out exactly as if it had been typed here; what is in the
|
|
682
|
+
// box, and any files attached to it, are left as they are.
|
|
683
|
+
async function submit(given) {
|
|
684
|
+
const asked = typeof given === 'string' ? given.trim() : null;
|
|
681
685
|
if (state.busy || sending) return;
|
|
682
686
|
sending = true;
|
|
683
687
|
state.menu = null;
|
|
@@ -695,7 +699,7 @@
|
|
|
695
699
|
return;
|
|
696
700
|
}
|
|
697
701
|
setMsg('');
|
|
698
|
-
const prompt = input.value.trim();
|
|
702
|
+
const prompt = asked === null ? input.value.trim() : asked;
|
|
699
703
|
state.busy = true;
|
|
700
704
|
render();
|
|
701
705
|
try {
|
|
@@ -706,30 +710,39 @@
|
|
|
706
710
|
return;
|
|
707
711
|
}
|
|
708
712
|
// Attached files go into the app's own temp folder first (see
|
|
709
|
-
// agent-bar-attach.js)
|
|
710
|
-
const attached = await shared.attachments.paths(appId);
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
//
|
|
715
|
-
// (
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
713
|
+
// agent-bar-attach.js).
|
|
714
|
+
const attached = asked === null ? await shared.attachments.paths(appId) : [];
|
|
715
|
+
// Pinokio writes the request into a file in the app's folder: the words,
|
|
716
|
+
// where the attached files are, where this app's skill is and where to
|
|
717
|
+
// save output (server/lib/brain.js). The agent is started with the one
|
|
718
|
+
// line that points to that file, never with the request itself
|
|
719
|
+
// (spec/requirements/request-files.md). Nothing is sent if that fails.
|
|
720
|
+
let text = '';
|
|
721
|
+
if (prompt || attached.length) {
|
|
722
|
+
if (!appId) throw new Error('This page does not know which app it is on.');
|
|
723
|
+
const response = await fetch('/brain/ask', {
|
|
724
|
+
method: 'POST',
|
|
725
|
+
headers: { 'Content-Type': 'application/json' },
|
|
726
|
+
body: JSON.stringify({ app: appId, prompt, tool: tool.value, files: attached }),
|
|
727
|
+
});
|
|
728
|
+
const brain = await response.json().catch(() => null);
|
|
729
|
+
if (!response.ok || !brain || typeof brain.prompt !== 'string' || !brain.prompt) {
|
|
730
|
+
throw new Error(brain && typeof brain.error === 'string' && brain.error ? brain.error : 'Failed to prepare the Ask.');
|
|
731
|
+
}
|
|
732
|
+
text = brain.prompt;
|
|
733
|
+
}
|
|
722
734
|
if (drawer) {
|
|
723
735
|
// its own session, so a session that is already running is left alone
|
|
724
736
|
const opened = drawer.openWithAgent({
|
|
725
737
|
agentHref: withParam(tool.href, 'session', newSession()),
|
|
726
738
|
prompt: text,
|
|
739
|
+
said: prompt, // what the dock lists the session by: the user's words
|
|
727
740
|
workspaceCwd,
|
|
728
741
|
});
|
|
729
742
|
if (opened === false) throw new Error('Could not launch this plugin.');
|
|
730
|
-
shared.attachments.clear();
|
|
743
|
+
if (asked === null) shared.attachments.clear();
|
|
731
744
|
state.busy = false;
|
|
732
|
-
input.value = '';
|
|
745
|
+
if (asked === null) input.value = '';
|
|
733
746
|
leave();
|
|
734
747
|
render();
|
|
735
748
|
window.setTimeout(loadSessions, 1500);
|
|
@@ -749,6 +762,9 @@
|
|
|
749
762
|
}
|
|
750
763
|
}
|
|
751
764
|
|
|
765
|
+
// Get Help's Ask AI (logs.js, in a frame of this page) sends its question here.
|
|
766
|
+
window.PinokioAgentBarApp.ask = (text) => submit(String(text == null ? '' : text));
|
|
767
|
+
|
|
752
768
|
running.addEventListener('click', () => toggleMenu('running'));
|
|
753
769
|
agentButton.addEventListener('click', () => toggleMenu('agent'));
|
|
754
770
|
input.addEventListener('focus', engage);
|
|
@@ -1231,8 +1231,11 @@
|
|
|
1231
1231
|
const session = url ? sessionAt(url, settings.label) : null;
|
|
1232
1232
|
if (!session) return false;
|
|
1233
1233
|
const address = `${url.pathname}${url.search}`;
|
|
1234
|
-
|
|
1235
|
-
|
|
1234
|
+
// What the session is listed by is the user's words (`said`), not the line
|
|
1235
|
+
// the agent is started with (spec/requirements/request-files.md).
|
|
1236
|
+
const said = typeof settings.said === 'string' ? settings.said.trim() : prompt;
|
|
1237
|
+
if (said) {
|
|
1238
|
+
asked[session.key] = said;
|
|
1236
1239
|
write(STORE_ASKED, asked);
|
|
1237
1240
|
}
|
|
1238
1241
|
if (settings.launch) {
|
|
@@ -1253,7 +1256,7 @@
|
|
|
1253
1256
|
// a send: starts the agent with the prompt
|
|
1254
1257
|
openWithAgent: (payload) => {
|
|
1255
1258
|
if (!payload || typeof payload.agentHref !== 'string' || !payload.agentHref) return false;
|
|
1256
|
-
return openFromUrl(payload.agentHref, { prompt: payload.prompt || '', launch: true });
|
|
1259
|
+
return openFromUrl(payload.agentHref, { prompt: payload.prompt || '', said: payload.said, launch: true });
|
|
1257
1260
|
},
|
|
1258
1261
|
// a new shell, with a session of its own
|
|
1259
1262
|
openShellTool: (shell) => {
|
package/server/public/logs.js
CHANGED
|
@@ -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 {
|
package/test/brain.test.js
CHANGED
|
@@ -48,6 +48,10 @@ const ask = (brain, body = {}) => new Promise((resolve) => {
|
|
|
48
48
|
brain.handleAsk({ body: { prompt: "p", tool: "claude", ...body } }, res)
|
|
49
49
|
})
|
|
50
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")
|
|
51
55
|
const seen = async (kernel, name) => (await Brain.addSkills(kernel, [{ app_id: name }]))[0]
|
|
52
56
|
const logLines = (dir) => fs.readFileSync(path.join(dir, "me", "log.md"), "utf8").trim().split("\n")
|
|
53
57
|
const tree = (dir) => fs.readdirSync(dir).sort().join(" ")
|
|
@@ -71,14 +75,16 @@ test("a top-bar Ask starts in the brain with the request and a log line", async
|
|
|
71
75
|
assert.equal(query(a).get("cwd"), t.dir)
|
|
72
76
|
assert.equal(query(a).get("chrome"), "full")
|
|
73
77
|
assert.match(id, /^\d{8}-[a-f0-9]{8}$/)
|
|
74
|
-
assert.equal(query(a).get("prompt"),
|
|
75
|
-
assert.equal(
|
|
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")
|
|
76
81
|
assert.equal(tree(path.join(t.dir, "me")), "files log.md")
|
|
77
82
|
assert.equal(fs.existsSync(path.join(t.dir, "me", "files", id)), false, "the output folder is named, not created")
|
|
78
83
|
assert.match(logLines(t.dir)[0], new RegExp(`^- \\d{4}-\\d\\d-\\d\\d \\d\\d:\\d\\d \\| ${id} \\| claude \\| say hello$`))
|
|
79
84
|
|
|
80
85
|
const empty = await ask(t.brain, { prompt: "" })
|
|
81
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")
|
|
82
88
|
})
|
|
83
89
|
})
|
|
84
90
|
|
|
@@ -86,17 +92,34 @@ test("attached files are copied into the Ask's folder and named in the request",
|
|
|
86
92
|
await withHome({ copyUploads: async (token, dir) => { fs.writeFileSync(path.join(dir, "a.jpg"), "x"); return ["a.jpg"] } }, async (t) => {
|
|
87
93
|
const a = await ask(t.brain, { prompt: "crop", uploadToken: "a".repeat(32) })
|
|
88
94
|
const id = query(a).get("session")
|
|
89
|
-
assert.equal(query(a).get("prompt"),
|
|
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`)
|
|
90
97
|
assert.equal(fs.existsSync(path.join(t.dir, "me", "files", id, "a.jpg")), true)
|
|
91
98
|
})
|
|
92
99
|
await withHome({}, async (t) => {
|
|
93
100
|
const a = await ask(t.brain, { prompt: "nothing copied", uploadToken: "a".repeat(32) })
|
|
94
101
|
assert.equal(fs.existsSync(path.join(t.dir, "me", "files", query(a).get("session"))), false)
|
|
95
|
-
assert.equal(query(a).get("
|
|
102
|
+
assert.equal(requestIn(t.dir, query(a).get("session")).includes("Attached files"), false)
|
|
96
103
|
})
|
|
97
104
|
})
|
|
98
105
|
|
|
99
|
-
test("
|
|
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 () => {
|
|
100
123
|
await withHome({ pluginHref: () => { throw Object.assign(new Error("No such plugin."), { status: 400 }) } }, async (t) => {
|
|
101
124
|
const a = await ask(t.brain)
|
|
102
125
|
assert.deepEqual([a.code, a.ok, a.error], [400, false, "No such plugin."])
|
|
@@ -230,21 +253,42 @@ test("the version covers the app's folder and the code repositories it keeps", a
|
|
|
230
253
|
})
|
|
231
254
|
})
|
|
232
255
|
|
|
233
|
-
test("an app-page Ask
|
|
256
|
+
test("an app-page Ask writes the request into the app's folder and gets back the request line", async () => {
|
|
234
257
|
await withHome({}, async (t) => {
|
|
235
258
|
const app = path.join(t.api, "Plain")
|
|
236
259
|
const version = await commit(app, "pinokio.js", "1")
|
|
237
260
|
skill(app, "older")
|
|
238
261
|
const a = await ask(t.brain, { app: "Plain", prompt: "say hi" })
|
|
239
262
|
const id = logLines(t.dir)[0].split(" | ")[1]
|
|
240
|
-
|
|
241
|
-
assert.
|
|
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`)
|
|
242
267
|
assert.match(logLines(t.dir)[0], new RegExp(`\\| ${id} \\| claude in Plain \\| say hi$`))
|
|
243
268
|
assert.equal(tree(t.dir), "me", "the instruction files are not written")
|
|
244
269
|
|
|
245
270
|
fs.mkdirSync(path.join(t.api, "NoGit"))
|
|
246
|
-
const
|
|
247
|
-
|
|
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)
|
|
248
292
|
})
|
|
249
293
|
await withHome({}, async (t) => {
|
|
250
294
|
fs.mkdirSync(path.join(t.api, "Thing"), { recursive: true })
|
|
@@ -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
|
+
})
|