pinokiod 8.3.6 → 8.3.9
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/git.js +1 -1
- package/kernel/bin/node.js +2 -2
- package/kernel/environment.js +6 -98
- package/kernel/managed_skills.js +2 -1
- package/package.json +1 -1
- package/prototype/system/SKILL_PINOKIO.md +5 -2
- package/server/index.js +7 -0
- package/server/lib/brain.js +279 -0
- package/server/public/agent-bar-app.css +359 -0
- package/server/public/agent-bar-app.js +821 -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 +1912 -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/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 +257 -0
- package/test/managed-skills.test.js +6 -1
- package/test/node-bin.test.js +4 -4
package/server/public/common.js
CHANGED
|
@@ -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;
|
package/server/public/layout.js
CHANGED
|
@@ -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 (
|
|
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
|
}
|
package/server/routes/apps.js
CHANGED
|
@@ -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
|
-
|
|
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") {
|
package/server/views/app.ejs
CHANGED
|
@@ -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:
|
|
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:
|
|
55
|
+
message: {
|
|
56
|
+
_: ["opencode"],
|
|
57
|
+
prompt: "{{args.prompt || undefined}}"
|
|
58
|
+
},
|
|
53
59
|
path: "{{args.cwd}}",
|
|
54
60
|
input: true
|
|
55
61
|
}
|
|
@@ -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')
|
|
@@ -0,0 +1,257 @@
|
|
|
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
|
+
const seen = async (kernel, name) => (await Brain.addSkills(kernel, [{ app_id: name }]))[0]
|
|
52
|
+
const logLines = (dir) => fs.readFileSync(path.join(dir, "me", "log.md"), "utf8").trim().split("\n")
|
|
53
|
+
const tree = (dir) => fs.readdirSync(dir).sort().join(" ")
|
|
54
|
+
const quietly = async (run) => {
|
|
55
|
+
const warn = console.warn
|
|
56
|
+
const said = []
|
|
57
|
+
console.warn = (...args) => said.push(args.join(" "))
|
|
58
|
+
try {
|
|
59
|
+
return { result: await run(), said }
|
|
60
|
+
} finally {
|
|
61
|
+
console.warn = warn
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
test("a top-bar Ask starts in the brain with the request and a log line", async () => {
|
|
66
|
+
await withHome({}, async (t) => {
|
|
67
|
+
const a = await ask(t.brain, { prompt: " say hello " })
|
|
68
|
+
const id = query(a).get("session")
|
|
69
|
+
assert.deepEqual(Object.keys(a).sort(), ["code", "cwd", "ok", "url"])
|
|
70
|
+
assert.equal(a.cwd, t.dir)
|
|
71
|
+
assert.equal(query(a).get("cwd"), t.dir)
|
|
72
|
+
assert.equal(query(a).get("chrome"), "full")
|
|
73
|
+
assert.match(id, /^\d{8}-[a-f0-9]{8}$/)
|
|
74
|
+
assert.equal(query(a).get("prompt"), `say hello\n\nOutput folder: me/files/${id}/`)
|
|
75
|
+
assert.equal(tree(t.dir), "AGENTS.md CLAUDE.md GEMINI.md me")
|
|
76
|
+
assert.equal(tree(path.join(t.dir, "me")), "files log.md")
|
|
77
|
+
assert.equal(fs.existsSync(path.join(t.dir, "me", "files", id)), false, "the output folder is named, not created")
|
|
78
|
+
assert.match(logLines(t.dir)[0], new RegExp(`^- \\d{4}-\\d\\d-\\d\\d \\d\\d:\\d\\d \\| ${id} \\| claude \\| say hello$`))
|
|
79
|
+
|
|
80
|
+
const empty = await ask(t.brain, { prompt: "" })
|
|
81
|
+
assert.equal(query(empty).get("prompt"), null)
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test("attached files are copied into the Ask's folder and named in the request", async () => {
|
|
86
|
+
await withHome({ copyUploads: async (token, dir) => { fs.writeFileSync(path.join(dir, "a.jpg"), "x"); return ["a.jpg"] } }, async (t) => {
|
|
87
|
+
const a = await ask(t.brain, { prompt: "crop", uploadToken: "a".repeat(32) })
|
|
88
|
+
const id = query(a).get("session")
|
|
89
|
+
assert.equal(query(a).get("prompt"), `crop\n\nAttached files:\n- me/files/${id}/a.jpg\n\nOutput folder: me/files/${id}/`)
|
|
90
|
+
assert.equal(fs.existsSync(path.join(t.dir, "me", "files", id, "a.jpg")), true)
|
|
91
|
+
})
|
|
92
|
+
await withHome({}, async (t) => {
|
|
93
|
+
const a = await ask(t.brain, { prompt: "nothing copied", uploadToken: "a".repeat(32) })
|
|
94
|
+
assert.equal(fs.existsSync(path.join(t.dir, "me", "files", query(a).get("session"))), false)
|
|
95
|
+
assert.equal(query(a).get("prompt").includes("Attached files"), false)
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
test("only an unknown tool, the brain folder or a failed copy can stop a top-bar Ask", async () => {
|
|
100
|
+
await withHome({ pluginHref: () => { throw Object.assign(new Error("No such plugin."), { status: 400 }) } }, async (t) => {
|
|
101
|
+
const a = await ask(t.brain)
|
|
102
|
+
assert.deepEqual([a.code, a.ok, a.error], [400, false, "No such plugin."])
|
|
103
|
+
assert.equal(fs.existsSync(t.dir), false, "nothing is written")
|
|
104
|
+
})
|
|
105
|
+
await withHome({ copyUploads: async () => { throw Object.assign(new Error("Upload expired."), { status: 400 }) } }, async (t) => {
|
|
106
|
+
const a = await ask(t.brain, { uploadToken: "a".repeat(32) })
|
|
107
|
+
assert.deepEqual([a.code, a.ok], [400, false])
|
|
108
|
+
assert.equal(fs.readdirSync(path.join(t.dir, "me", "files")).length, 0)
|
|
109
|
+
})
|
|
110
|
+
await withHome({}, async (t) => {
|
|
111
|
+
fs.mkdirSync(t.dir, { recursive: true })
|
|
112
|
+
fs.writeFileSync(path.join(t.dir, "me"), "not a folder")
|
|
113
|
+
const { result, said } = await quietly(() => ask(t.brain))
|
|
114
|
+
assert.equal(result.ok, true)
|
|
115
|
+
assert.ok(said.some((line) => line.includes("folders failed")))
|
|
116
|
+
assert.ok(said.some((line) => line.includes("log failed")))
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
test("the instruction files are fixed text", async () => {
|
|
121
|
+
await withHome({}, async (t) => {
|
|
122
|
+
await ask(t.brain, { prompt: "first" })
|
|
123
|
+
const file = path.join(t.dir, "AGENTS.md")
|
|
124
|
+
const first = fs.readFileSync(file, "utf8")
|
|
125
|
+
const own = first.includes("\n## Pinokio\n") ? first.slice(0, first.indexOf("\n## Pinokio\n")) : first
|
|
126
|
+
assert.ok(first.startsWith("# Pinokio Brain\n"))
|
|
127
|
+
assert.ok(own.includes("## Which app to use"))
|
|
128
|
+
assert.ok(own.includes("read `me/preferences.md` if it exists"))
|
|
129
|
+
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."))
|
|
130
|
+
assert.equal(/apps\/|Apps with/i.test(own), false, "no list of apps")
|
|
131
|
+
assert.equal(fs.readFileSync(path.join(t.dir, "CLAUDE.md"), "utf8"), first)
|
|
132
|
+
assert.equal(fs.readFileSync(path.join(t.dir, "GEMINI.md"), "utf8"), first)
|
|
133
|
+
|
|
134
|
+
const stamp = fs.statSync(file).mtimeMs
|
|
135
|
+
const app = path.join(t.api, "Speech")
|
|
136
|
+
skill(app, await commit(app, "pinokio.js", "1"))
|
|
137
|
+
write(path.join(t.dir, "me", "preferences.md"), "- speak text aloud: `Speech`\n")
|
|
138
|
+
await new Promise((resolve) => setTimeout(resolve, 20))
|
|
139
|
+
await ask(t.brain, { prompt: "something else entirely" })
|
|
140
|
+
assert.equal(fs.readFileSync(file, "utf8"), first)
|
|
141
|
+
assert.equal(fs.statSync(file).mtimeMs, stamp, "not rewritten")
|
|
142
|
+
assert.equal(fs.readFileSync(path.join(t.dir, "me", "preferences.md"), "utf8"), "- speak text aloud: `Speech`\n", "Pinokio never writes the preferences")
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
test("Pinokio only writes an instruction file that is missing or its own", async () => {
|
|
147
|
+
await withHome({}, async (t) => {
|
|
148
|
+
write(path.join(t.dir, "AGENTS.md"), "")
|
|
149
|
+
write(path.join(t.dir, "CLAUDE.md"), "# Pinokio Brain\r\nan older copy with Windows line ends\r\n")
|
|
150
|
+
write(path.join(t.dir, "GEMINI.md"), "# Pinokio Brainstorm\nmy own notes\n")
|
|
151
|
+
await ask(t.brain)
|
|
152
|
+
assert.equal(fs.readFileSync(path.join(t.dir, "AGENTS.md"), "utf8"), "", "an empty file that is not Pinokio's")
|
|
153
|
+
assert.ok(fs.readFileSync(path.join(t.dir, "CLAUDE.md"), "utf8").includes("## Which app to use"), "its own older copy is put back")
|
|
154
|
+
assert.equal(fs.readFileSync(path.join(t.dir, "GEMINI.md"), "utf8"), "# Pinokio Brainstorm\nmy own notes\n")
|
|
155
|
+
assert.equal(fs.existsSync(path.join(t.dir, ".git")), false, "the brain is never a git repository")
|
|
156
|
+
})
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
test("the log puts a request on one line and cuts it at 200 characters", async () => {
|
|
160
|
+
await withHome({}, async (t) => {
|
|
161
|
+
await ask(t.brain, { prompt: `line one\n line two ${"x".repeat(300)}`, tool: "some agent" })
|
|
162
|
+
const words = logLines(t.dir)[0].split(" | ").slice(3).join(" | ")
|
|
163
|
+
assert.equal(logLines(t.dir).length, 1)
|
|
164
|
+
assert.ok(words.startsWith("line one line two x"))
|
|
165
|
+
assert.equal(words.length, 201)
|
|
166
|
+
assert.ok(words.endsWith("…"))
|
|
167
|
+
const many = await Promise.all(Array.from({ length: 20 }, (_, i) => ask(t.brain, { prompt: `parallel ${i}` })))
|
|
168
|
+
assert.equal(new Set(many.map((a) => query(a).get("session"))).size, 20)
|
|
169
|
+
assert.equal(logLines(t.dir).length, 21)
|
|
170
|
+
})
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
test("an app's skill lives in the app's own folder and hides itself from git", async () => {
|
|
174
|
+
await withHome({}, async (t) => {
|
|
175
|
+
const app = path.join(t.api, "Plain")
|
|
176
|
+
const first = await commit(app, "pinokio.js", "1")
|
|
177
|
+
let s = await seen(t.kernel, "Plain")
|
|
178
|
+
assert.deepEqual(s, { app_id: "Plain", skill_dir: path.join(app, ".pinokio-skill"), skill_state: "none", app_version: first })
|
|
179
|
+
assert.equal(tree(app), ".git pinokio.js", "an app with no skill is not touched")
|
|
180
|
+
|
|
181
|
+
skill(app, first)
|
|
182
|
+
s = await seen(t.kernel, "Plain")
|
|
183
|
+
assert.equal(s.skill_state, "current")
|
|
184
|
+
assert.equal(fs.readFileSync(path.join(app, ".pinokio-skill", ".gitignore"), "utf8"), "*\n")
|
|
185
|
+
const visible = (await git.statusMatrix({ fs, dir: app })).filter((row) => row[0].startsWith(".pinokio-skill"))
|
|
186
|
+
assert.deepEqual(visible, [], "git no longer sees the folder")
|
|
187
|
+
assert.equal(fs.existsSync(path.join(app, ".git", "info", "exclude")) && /pinokio-skill/.test(fs.readFileSync(path.join(app, ".git", "info", "exclude"), "utf8")), false)
|
|
188
|
+
|
|
189
|
+
fs.writeFileSync(path.join(app, ".pinokio-skill", ".gitignore"), "mine\n")
|
|
190
|
+
await seen(t.kernel, "Plain")
|
|
191
|
+
assert.equal(fs.readFileSync(path.join(app, ".pinokio-skill", ".gitignore"), "utf8"), "mine\n", "never replaced")
|
|
192
|
+
|
|
193
|
+
const copy = path.join(t.api, "Plain-copy")
|
|
194
|
+
await commit(copy, "pinokio.js", "1")
|
|
195
|
+
assert.equal((await seen(t.kernel, "Plain-copy")).skill_state, "none", "another copy has its own skill")
|
|
196
|
+
assert.equal((await seen(t.kernel, "Plain-copy")).skill_dir, path.join(copy, ".pinokio-skill"))
|
|
197
|
+
|
|
198
|
+
write(path.join(app, ".pinokio-skill", "SKILL.md"), "")
|
|
199
|
+
assert.equal((await seen(t.kernel, "Plain")).skill_state, "none", "an empty SKILL.md")
|
|
200
|
+
assert.equal((await seen(t.kernel, "not-installed")).skill_state, "none")
|
|
201
|
+
assert.equal(fs.existsSync(path.join(t.api, "not-installed")), false)
|
|
202
|
+
})
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
test("the version covers the app's folder and the code repositories it keeps", async () => {
|
|
206
|
+
await withHome({}, async (t) => {
|
|
207
|
+
const app = path.join(t.api, "Both")
|
|
208
|
+
const launcher = await commit(app, "pinokio.js", "1")
|
|
209
|
+
assert.equal((await seen(t.kernel, "Both")).app_version, launcher)
|
|
210
|
+
|
|
211
|
+
const code = await commit(path.join(app, "app"), "main.py", "1")
|
|
212
|
+
assert.equal((await seen(t.kernel, "Both")).app_version, `${launcher}+${code}`)
|
|
213
|
+
skill(app, `${launcher}+${code}`)
|
|
214
|
+
assert.equal((await seen(t.kernel, "Both")).skill_state, "current")
|
|
215
|
+
|
|
216
|
+
const updated = await commit(path.join(app, "app"), "main.py", "2")
|
|
217
|
+
let s = await seen(t.kernel, "Both")
|
|
218
|
+
assert.deepEqual([s.skill_state, s.app_version], ["check", `${launcher}+${updated}`], "the code was updated, the launcher was not")
|
|
219
|
+
|
|
220
|
+
const other = await commit(path.join(app, "tool"), "main.py", "3")
|
|
221
|
+
const nested = await commit(path.join(app, "app", "comfyui"), "main.py", "4")
|
|
222
|
+
await commit(path.join(app, "app", "comfyui", "custom_nodes", "deep"), "main.py", "5")
|
|
223
|
+
s = await seen(t.kernel, "Both")
|
|
224
|
+
assert.equal(s.app_version, `${launcher}+${updated}+${other}+${nested}`, "one level inside the folder and inside app, no deeper")
|
|
225
|
+
|
|
226
|
+
const bare = path.join(t.api, "Bare")
|
|
227
|
+
skill(bare, "abc1234")
|
|
228
|
+
s = await seen(t.kernel, "Bare")
|
|
229
|
+
assert.deepEqual([s.skill_state, s.app_version], ["current", ""], "an app with no git history is never check")
|
|
230
|
+
})
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
test("an app-page Ask gets back only what the page adds to the request", async () => {
|
|
234
|
+
await withHome({}, async (t) => {
|
|
235
|
+
const app = path.join(t.api, "Plain")
|
|
236
|
+
const version = await commit(app, "pinokio.js", "1")
|
|
237
|
+
skill(app, "older")
|
|
238
|
+
const a = await ask(t.brain, { app: "Plain", prompt: "say hi" })
|
|
239
|
+
const id = logLines(t.dir)[0].split(" | ")[1]
|
|
240
|
+
assert.deepEqual(Object.keys(a).sort(), ["append", "code", "ok"])
|
|
241
|
+
assert.equal(a.append, `Pinokio brain:\n- This app's skill (skill_dir): ${path.join(app, ".pinokio-skill")} (skill_state: check, app_version: ${version})\n- Output folder: ${path.join(t.dir, "me", "files", id)}`)
|
|
242
|
+
assert.match(logLines(t.dir)[0], new RegExp(`\\| ${id} \\| claude in Plain \\| say hi$`))
|
|
243
|
+
assert.equal(tree(t.dir), "me", "the instruction files are not written")
|
|
244
|
+
|
|
245
|
+
fs.mkdirSync(path.join(t.api, "NoGit"))
|
|
246
|
+
const plain = await ask(t.brain, { app: "NoGit", prompt: "x" })
|
|
247
|
+
assert.ok(plain.append.includes("(skill_state: none)\n"), "no version, so none is named")
|
|
248
|
+
})
|
|
249
|
+
await withHome({}, async (t) => {
|
|
250
|
+
fs.mkdirSync(path.join(t.api, "Thing"), { recursive: true })
|
|
251
|
+
for (const bad of ["../Thing", "..", ".", "a/b", "a\\b", "C:", "nope"]) {
|
|
252
|
+
const a = await ask(t.brain, { app: bad })
|
|
253
|
+
assert.deepEqual([bad, a.code, a.ok], [bad, 404, false])
|
|
254
|
+
}
|
|
255
|
+
assert.equal(fs.existsSync(t.dir), false, "nothing is written for a refused name")
|
|
256
|
+
})
|
|
257
|
+
})
|
|
@@ -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)
|