crewx-pi-kit 0.1.2 → 0.1.4
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/README.md +1 -1
- package/extensions/crewx-tools.ts +158 -0
- package/package.json +12 -23
- package/skills/artifact-delivery/SKILL.md +13 -0
- package/skills/human-computer-handover/SKILL.md +18 -0
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { basename } from "node:path";
|
|
3
5
|
|
|
4
6
|
const API_PATH = "/api/agent/v1";
|
|
5
7
|
const MAX_RESULT_CHARS = 100_000;
|
|
@@ -48,6 +50,37 @@ async function crewxRequest(
|
|
|
48
50
|
return payload;
|
|
49
51
|
}
|
|
50
52
|
|
|
53
|
+
async function crewxUpload(
|
|
54
|
+
path: string,
|
|
55
|
+
caption: string | undefined,
|
|
56
|
+
signal?: AbortSignal,
|
|
57
|
+
): Promise<unknown> {
|
|
58
|
+
const { baseUrl, token } = connection();
|
|
59
|
+
const contents = await readFile(path);
|
|
60
|
+
const form = new FormData();
|
|
61
|
+
form.set("file", new Blob([contents]), basename(path));
|
|
62
|
+
if (caption?.trim()) form.set("caption", caption.trim());
|
|
63
|
+
const response = await fetch(`${baseUrl}${API_PATH}/files`, {
|
|
64
|
+
method: "POST",
|
|
65
|
+
headers: {
|
|
66
|
+
accept: "application/json",
|
|
67
|
+
authorization: `Bearer ${token}`,
|
|
68
|
+
},
|
|
69
|
+
body: form,
|
|
70
|
+
redirect: "error",
|
|
71
|
+
...(signal ? { signal } : {}),
|
|
72
|
+
});
|
|
73
|
+
const payload = (await response.json().catch(() => ({
|
|
74
|
+
message: `CrewX returned HTTP ${response.status}.`,
|
|
75
|
+
}))) as JsonRecord;
|
|
76
|
+
if (!response.ok) {
|
|
77
|
+
throw new Error(typeof payload.message === "string"
|
|
78
|
+
? payload.message
|
|
79
|
+
: `CrewX returned HTTP ${response.status}.`);
|
|
80
|
+
}
|
|
81
|
+
return payload;
|
|
82
|
+
}
|
|
83
|
+
|
|
51
84
|
function result(value: unknown) {
|
|
52
85
|
return {content: [{type: "text" as const, text: jsonText(value)}], details: {}};
|
|
53
86
|
}
|
|
@@ -60,7 +93,132 @@ function query(parameters: Record<string, string | number | boolean | undefined>
|
|
|
60
93
|
return search.size ? `?${search.toString()}` : "";
|
|
61
94
|
}
|
|
62
95
|
|
|
96
|
+
function wait(milliseconds: number, signal?: AbortSignal): Promise<void> {
|
|
97
|
+
return new Promise((resolve, reject) => {
|
|
98
|
+
if (signal?.aborted) {
|
|
99
|
+
reject(signal.reason ?? new Error("CrewX handover was cancelled."));
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const timer = setTimeout(resolve, milliseconds);
|
|
104
|
+
signal?.addEventListener("abort", () => {
|
|
105
|
+
clearTimeout(timer);
|
|
106
|
+
reject(signal.reason ?? new Error("CrewX handover was cancelled."));
|
|
107
|
+
}, {once: true});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
63
111
|
export default function crewxTools(pi: ExtensionAPI) {
|
|
112
|
+
pi.registerTool({
|
|
113
|
+
name: "crewx_request_handover",
|
|
114
|
+
label: "Request user computer handover",
|
|
115
|
+
description: "Pause the current browser task and ask a CrewX user to take control of this agent's computer. This tool waits until the user gives control back, then returns so work can resume.",
|
|
116
|
+
parameters: Type.Object({
|
|
117
|
+
reason: Type.String({
|
|
118
|
+
minLength: 1,
|
|
119
|
+
maxLength: 1000,
|
|
120
|
+
description: "A short, user-facing explanation of why human input is required.",
|
|
121
|
+
}),
|
|
122
|
+
kind: Type.Optional(Type.Union([
|
|
123
|
+
Type.Literal("authentication"),
|
|
124
|
+
Type.Literal("verification"),
|
|
125
|
+
Type.Literal("captcha"),
|
|
126
|
+
Type.Literal("payment"),
|
|
127
|
+
Type.Literal("approval"),
|
|
128
|
+
Type.Literal("other"),
|
|
129
|
+
])),
|
|
130
|
+
instructions: Type.Optional(Type.String({
|
|
131
|
+
maxLength: 2000,
|
|
132
|
+
description: "The exact action the user should complete before giving control back.",
|
|
133
|
+
})),
|
|
134
|
+
url: Type.Optional(Type.String({
|
|
135
|
+
maxLength: 2048,
|
|
136
|
+
description: "The current HTTP(S) page where the user is needed.",
|
|
137
|
+
})),
|
|
138
|
+
}),
|
|
139
|
+
promptSnippet: "Hand browser control to a CrewX user when a human-only step blocks progress.",
|
|
140
|
+
promptGuidelines: [
|
|
141
|
+
"Use crewx_request_handover for sign-in, 2FA, CAPTCHA, consent, payment, approval, or any other step that requires a person to interact with the live computer.",
|
|
142
|
+
"Before calling it, navigate to the exact blocked screen and explain the one action the user must complete.",
|
|
143
|
+
"Never ask for passwords, one-time codes, payment details, or other secrets in chat. Stop browser actions while this tool is waiting.",
|
|
144
|
+
"When the tool returns completed, verify the page state and continue the original task from the same point.",
|
|
145
|
+
],
|
|
146
|
+
async execute(_id, params, signal) {
|
|
147
|
+
const created = await crewxRequest("/handovers", {
|
|
148
|
+
method: "POST",
|
|
149
|
+
body: params,
|
|
150
|
+
signal,
|
|
151
|
+
}) as {handover?: {id?: unknown}};
|
|
152
|
+
const handoverId = created.handover?.id;
|
|
153
|
+
if (typeof handoverId !== "string" || handoverId.length === 0) {
|
|
154
|
+
throw new Error("CrewX created a handover without returning its ID.");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
while (true) {
|
|
158
|
+
await wait(2_000, signal);
|
|
159
|
+
const current = await crewxRequest(
|
|
160
|
+
`/handovers/${encodeURIComponent(handoverId)}`,
|
|
161
|
+
{signal},
|
|
162
|
+
) as {handover?: {status?: unknown}};
|
|
163
|
+
const status = current.handover?.status;
|
|
164
|
+
|
|
165
|
+
if (status === "ended") {
|
|
166
|
+
return result({
|
|
167
|
+
handover: {id: handoverId, status: "completed"},
|
|
168
|
+
instruction: "The user gave control back. Verify the current screen, then continue the original task.",
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
if (status === "expired") {
|
|
172
|
+
return result({
|
|
173
|
+
handover: {id: handoverId, status: "expired"},
|
|
174
|
+
instruction: "The user did not complete the handover before it expired. Explain the blocker and stop browser actions.",
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
if (status !== "requested" && status !== "active") {
|
|
178
|
+
return result({
|
|
179
|
+
handover: {id: handoverId, status},
|
|
180
|
+
instruction: "The handover ended without a completed return of control. Re-check the task before taking any browser action.",
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
pi.registerTool({
|
|
188
|
+
name: "crewx_attach_file",
|
|
189
|
+
label: "Attach CrewX file",
|
|
190
|
+
description: "Upload a durable file and attach it to the current CrewX reply.",
|
|
191
|
+
parameters: Type.Object({
|
|
192
|
+
path: Type.String({minLength: 1, maxLength: 4096}),
|
|
193
|
+
caption: Type.Optional(Type.String({maxLength: 1000})),
|
|
194
|
+
}),
|
|
195
|
+
promptSnippet: "Deliver generated files directly into the CrewX conversation.",
|
|
196
|
+
promptGuidelines: [
|
|
197
|
+
"Use crewx_attach_file for requested screenshots, reports, exports, and other deliverables instead of returning a local path.",
|
|
198
|
+
],
|
|
199
|
+
async execute(_id, params, signal) {
|
|
200
|
+
return result(await crewxUpload(params.path, params.caption, signal));
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
pi.registerTool({
|
|
205
|
+
name: "crewx_publish_preview",
|
|
206
|
+
label: "Publish CrewX preview",
|
|
207
|
+
description: "Publish a web service running on this CrewX Cloud Agent as a live preview.",
|
|
208
|
+
parameters: Type.Object({
|
|
209
|
+
port: Type.Integer({minimum: 1024, maximum: 65535}),
|
|
210
|
+
title: Type.Optional(Type.String({maxLength: 120})),
|
|
211
|
+
}),
|
|
212
|
+
promptSnippet: "Share interactive work as a managed CrewX live preview.",
|
|
213
|
+
promptGuidelines: [
|
|
214
|
+
"Bind the service to 0.0.0.0, verify it locally, then publish the port.",
|
|
215
|
+
"Do not reveal provider URLs, access tokens, or local file paths in the reply.",
|
|
216
|
+
],
|
|
217
|
+
async execute(_id, params, signal) {
|
|
218
|
+
return result(await crewxRequest("/previews", {method: "POST", body: params, signal}));
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
|
|
64
222
|
pi.registerTool({
|
|
65
223
|
name: "crewx_memory_search",
|
|
66
224
|
label: "Search CrewX memory",
|
package/package.json
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "crewx-pi-kit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Typed CrewX tools and operating skills for managed Pi agents.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"files": [
|
|
7
|
-
"extensions",
|
|
8
|
-
"skills"
|
|
9
|
-
],
|
|
6
|
+
"files": ["extensions", "skills"],
|
|
10
7
|
"pi": {
|
|
11
|
-
"extensions": [
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
"extensions": ["extensions"],
|
|
9
|
+
"skills": ["skills"]
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"types:check": "tsc --noEmit",
|
|
13
|
+
"test": "tsc --noEmit"
|
|
17
14
|
},
|
|
18
15
|
"peerDependencies": {
|
|
19
16
|
"@earendil-works/pi-coding-agent": "*",
|
|
@@ -25,15 +22,7 @@
|
|
|
25
22
|
"typebox": "^1.0.55",
|
|
26
23
|
"typescript": "^5.9.3"
|
|
27
24
|
},
|
|
28
|
-
"engines": {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"access": "public"
|
|
33
|
-
},
|
|
34
|
-
"license": "MIT",
|
|
35
|
-
"scripts": {
|
|
36
|
-
"types:check": "tsc --noEmit",
|
|
37
|
-
"test": "tsc --noEmit"
|
|
38
|
-
}
|
|
39
|
-
}
|
|
25
|
+
"engines": {"node": ">=22"},
|
|
26
|
+
"publishConfig": {"access": "public"},
|
|
27
|
+
"license": "MIT"
|
|
28
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: artifact-delivery
|
|
3
|
+
description: Deliver files and interactive previews back to the CrewX conversation. Use when an assignment produces screenshots, reports, exports, generated media, or a locally running web experience.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Artifact Delivery
|
|
7
|
+
|
|
8
|
+
1. Treat the final CrewX reply as the handoff, not the machine filesystem. Never ask a teammate to retrieve `/home`, `/tmp`, or another local path.
|
|
9
|
+
2. Use `crewx_attach_file` for durable outputs such as screenshots, documents, archives, data exports, and generated media. Add a short caption that explains what the file contains.
|
|
10
|
+
3. Use `crewx_publish_preview` only when interaction materially improves the handoff. Bind the service to `0.0.0.0`, verify the local port, then publish it.
|
|
11
|
+
4. A preview is a running service, not permanent storage. Also attach durable source or output files when the teammate may need them later.
|
|
12
|
+
5. Do not include provider URLs, preview tokens, credentials, or local paths in the response. CrewX presents the safe file and preview controls automatically.
|
|
13
|
+
6. Confirm that every requested deliverable was attached before sending the concise final response.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: human-computer-handover
|
|
3
|
+
description: Ask a CrewX user to take control of the managed computer when a website requires authentication, verification, approval, or another human-only action.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Human computer handover
|
|
7
|
+
|
|
8
|
+
Use `crewx_request_handover` when browser or desktop work reaches a step that a person must complete, including sign-in, two-factor authentication, CAPTCHA, consent, payment confirmation, or sensitive approval.
|
|
9
|
+
|
|
10
|
+
Before requesting handover:
|
|
11
|
+
|
|
12
|
+
1. Navigate to the exact screen where human input is required.
|
|
13
|
+
2. Explain the visible blocker and the single action the user should complete.
|
|
14
|
+
3. Never request credentials, one-time codes, payment details, cookies, or tokens in chat.
|
|
15
|
+
|
|
16
|
+
While the tool is waiting, stop all browser and desktop actions. The user has control of the same machine.
|
|
17
|
+
|
|
18
|
+
After the tool reports that control was returned, inspect the current screen, verify that the human-only step succeeded, and continue the original task from that state.
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 CrewX contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|