@capybara-hq/plugin-sdk 0.1.0-rc.76 → 0.1.0-rc.78
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/agent-docs/extension-points/identity-source.md +2 -0
- package/dist/ctx.d.ts +11 -6
- package/dist/device-provider.d.ts +29 -0
- package/dist/device-provider.js +46 -0
- package/dist/device-service.d.ts +21 -0
- package/dist/device-service.js +37 -0
- package/dist/identity.d.ts +32 -0
- package/dist/identity.js +25 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/native-failure.d.ts +13 -0
- package/dist/native-failure.js +31 -0
- package/dist/skill-invocation.d.ts +5 -0
- package/dist/skill-invocation.js +4 -3
- package/package.json +1 -1
|
@@ -12,4 +12,6 @@ Contract: IdentitySource (`identity.ts`)
|
|
|
12
12
|
|
|
13
13
|
Provide SSO login through an external provider. The kernel owns state, nonce and PKCE checks; identities are keyed `<plugin>:<tenant>`.
|
|
14
14
|
|
|
15
|
+
Declare `tenant` so the admin console can label and check trusted tenants; list tenants that must never be trusted in `neverTrusted` (`validateTenantId` applies the same rule). A super admin turns the source on, orders the login page and sets its trusted tenants in the admin console (the login section of the extension's page, or the `login-sources.*` Platform operations); there is no startup config for it.
|
|
16
|
+
|
|
15
17
|
See `extensions` for the rules every extension follows.
|
package/dist/ctx.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Kysely } from "kysely";
|
|
2
|
-
import type { DeviceServiceSpec, DeviceServiceStatus } from "./device-provider.js";
|
|
2
|
+
import type { DeviceServiceSpec, DeviceServiceStatus, ServiceBlockedHost } from "./device-provider.js";
|
|
3
3
|
import type { DevicesCtx, DialInChannel } from "./dial-in.js";
|
|
4
4
|
import type { ExtensionPointRef } from "./extension-point.js";
|
|
5
5
|
import type { AvailableHook, HookHandler, HookOptions } from "./hooks.js";
|
|
@@ -202,12 +202,17 @@ export interface DeviceAccessCtx {
|
|
|
202
202
|
timeoutMs: number;
|
|
203
203
|
}): Promise<Uint8Array>;
|
|
204
204
|
/**
|
|
205
|
-
* The service saw requests to `hosts` refused by the device's network
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
205
|
+
* The service saw requests to `hosts` refused by the device's network during this call, each
|
|
206
|
+
* with the layer that refused it (`sandboxProxyRefusalLayer` reads it from the device's
|
|
207
|
+
* proxy): once the handler returns, the kernel raises the network ask in the call's
|
|
208
|
+
* conversation for `device` hosts it can offer (and runs the call again once the person
|
|
209
|
+
* approves), and writes a note for the others (an `address` host: a private or local address,
|
|
210
|
+
* which no host grant reaches). Only an ask: a layer never widens access, and the kernel's own
|
|
211
|
+
* planning still applies (a host the device list cannot take is never asked about; an IP
|
|
212
|
+
* literal is always `address`). A host reported twice keeps its most restrictive layer.
|
|
213
|
+
* `opts.url` is the page the refusals came from, shown with the ask.
|
|
209
214
|
*/
|
|
210
|
-
reportBlockedHosts(call: ToolCallContext, hosts:
|
|
215
|
+
reportBlockedHosts(call: ToolCallContext, hosts: ServiceBlockedHost[], opts?: {
|
|
211
216
|
url?: string;
|
|
212
217
|
}): void;
|
|
213
218
|
/**
|
|
@@ -71,6 +71,26 @@ export interface SandboxActor {
|
|
|
71
71
|
* points to a private or local address; never grantable), `unknown`.
|
|
72
72
|
*/
|
|
73
73
|
export type NetworkBlockLayer = "device" | "org" | "address" | "unknown";
|
|
74
|
+
/**
|
|
75
|
+
* A host a device service saw refused, with the layer that refused it
|
|
76
|
+
* (`ctx.deviceAccess.reportBlockedHosts`). The service reports host names only (no port).
|
|
77
|
+
*/
|
|
78
|
+
export interface ServiceBlockedHost {
|
|
79
|
+
host: string;
|
|
80
|
+
layer: NetworkBlockLayer;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The layer of a refusal by a device's sandbox proxy, read from the reason the proxy gives: the
|
|
84
|
+
* status phrase of its 403 answer to a CONNECT, or the reason in its violation line
|
|
85
|
+
* (`deny network-outbound <host>:<port> (<reason>)`).
|
|
86
|
+
*
|
|
87
|
+
* - `address`: the destination's address is closed (an IP literal in a closed class, or a name
|
|
88
|
+
* resolving to a private or local address: "address is …", "resolved to …"), or the host is
|
|
89
|
+
* malformed. No host grant reaches it, only a command run outside the sandbox.
|
|
90
|
+
* - `device`: the host is not on the operation's allowlist ("host is not on the allow list").
|
|
91
|
+
* - `unknown`: any other reason (a proxy that names none, a failed fake-IP lookup).
|
|
92
|
+
*/
|
|
93
|
+
export declare function sandboxProxyRefusalLayer(reason: string): NetworkBlockLayer;
|
|
74
94
|
/** A host a command was refused, as the provider reports it. */
|
|
75
95
|
export interface NetworkBlockedHost {
|
|
76
96
|
/** The host as the proxy saw it (IPv6 literals bracketed). */
|
|
@@ -329,6 +349,15 @@ export interface DeviceServiceStatus {
|
|
|
329
349
|
* may send it to a machine instead of the files.
|
|
330
350
|
*/
|
|
331
351
|
export declare function deviceServiceFilesDigest(files: Record<string, Uint8Array>): string;
|
|
352
|
+
/**
|
|
353
|
+
* A fixed input and its {@link deviceServiceFilesDigest}, for the tests of every implementation
|
|
354
|
+
* of the digest (the SDK's, capybara-device's, a provider's own): one that disagrees would restart
|
|
355
|
+
* every running service at every ensure.
|
|
356
|
+
*/
|
|
357
|
+
export declare const DEVICE_SERVICE_FILES_DIGEST_VECTOR: {
|
|
358
|
+
readonly files: Readonly<Record<string, string>>;
|
|
359
|
+
readonly digest: string;
|
|
360
|
+
};
|
|
332
361
|
/**
|
|
333
362
|
* A message stream to a device service ({@link DeviceProvider.openStream},
|
|
334
363
|
* `DialInChannel.openStream`): whole messages both ways, flow-controlled by credit.
|
package/dist/device-provider.js
CHANGED
|
@@ -24,6 +24,25 @@ export const DEFAULT_SANDBOX_ROOTS = Object.freeze({
|
|
|
24
24
|
export function rootsOf(h) {
|
|
25
25
|
return h.roots ?? DEFAULT_SANDBOX_ROOTS;
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* The layer of a refusal by a device's sandbox proxy, read from the reason the proxy gives: the
|
|
29
|
+
* status phrase of its 403 answer to a CONNECT, or the reason in its violation line
|
|
30
|
+
* (`deny network-outbound <host>:<port> (<reason>)`).
|
|
31
|
+
*
|
|
32
|
+
* - `address`: the destination's address is closed (an IP literal in a closed class, or a name
|
|
33
|
+
* resolving to a private or local address: "address is …", "resolved to …"), or the host is
|
|
34
|
+
* malformed. No host grant reaches it, only a command run outside the sandbox.
|
|
35
|
+
* - `device`: the host is not on the operation's allowlist ("host is not on the allow list").
|
|
36
|
+
* - `unknown`: any other reason (a proxy that names none, a failed fake-IP lookup).
|
|
37
|
+
*/
|
|
38
|
+
export function sandboxProxyRefusalLayer(reason) {
|
|
39
|
+
const r = reason.trim().toLowerCase();
|
|
40
|
+
if (r.startsWith("address is ") || r.startsWith("resolved to ") || r === "malformed host")
|
|
41
|
+
return "address";
|
|
42
|
+
if (r === "host is not on the allow list")
|
|
43
|
+
return "device";
|
|
44
|
+
return "unknown";
|
|
45
|
+
}
|
|
27
46
|
/**
|
|
28
47
|
* The instance is definitely gone on the provider's side (container removed, E2B sandbox expired).
|
|
29
48
|
* `exec` / `readFile` / `writeFile` / `stat` must throw it (not a plain Error) when they find the
|
|
@@ -221,6 +240,33 @@ export function deviceServiceId(extension, name) {
|
|
|
221
240
|
* may send it to a machine instead of the files.
|
|
222
241
|
*/
|
|
223
242
|
export function deviceServiceFilesDigest(files) {
|
|
243
|
+
const cached = digests.get(files);
|
|
244
|
+
if (cached !== undefined)
|
|
245
|
+
return cached;
|
|
246
|
+
const digest = digestOf(files);
|
|
247
|
+
digests.set(files, digest);
|
|
248
|
+
return digest;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Digests already computed, by files object: a plugin passes the same `files` object on every
|
|
252
|
+
* call (its service files are read once), and a browser's are megabytes. Callers never mutate a
|
|
253
|
+
* spec's files after building it.
|
|
254
|
+
*/
|
|
255
|
+
const digests = new WeakMap();
|
|
256
|
+
/**
|
|
257
|
+
* A fixed input and its {@link deviceServiceFilesDigest}, for the tests of every implementation
|
|
258
|
+
* of the digest (the SDK's, capybara-device's, a provider's own): one that disagrees would restart
|
|
259
|
+
* every running service at every ensure.
|
|
260
|
+
*/
|
|
261
|
+
export const DEVICE_SERVICE_FILES_DIGEST_VECTOR = Object.freeze({
|
|
262
|
+
files: Object.freeze({
|
|
263
|
+
"main.js": "console.log(1)\n",
|
|
264
|
+
"lib/a.js": "export const a = 1;\n",
|
|
265
|
+
empty: "",
|
|
266
|
+
}),
|
|
267
|
+
digest: "sha256:7b3959ff2e10237b9f1a255bbecb5dacebd31422fe734b2867403e42913432a5",
|
|
268
|
+
});
|
|
269
|
+
function digestOf(files) {
|
|
224
270
|
const h = createHash("sha256");
|
|
225
271
|
for (const path of Object.keys(files).sort()) {
|
|
226
272
|
const data = files[path];
|
package/dist/device-service.d.ts
CHANGED
|
@@ -26,6 +26,27 @@
|
|
|
26
26
|
* never context. Providers and the device program pass the viewer context through like any
|
|
27
27
|
* stream message.
|
|
28
28
|
*/
|
|
29
|
+
/**
|
|
30
|
+
* The request body the kernel sends a running service before restarting it on new files (an
|
|
31
|
+
* upgraded extension, {@link DeviceServiceRollCheck}). A service that answers
|
|
32
|
+
* `{"busy":true,"reason":"…"}` is kept running (a person is using it); the kernel asks again at a
|
|
33
|
+
* later ensure. Any other answer, an error or no answer within a few seconds lets the restart go
|
|
34
|
+
* ahead, so a service that does not know the check is restarted as before. Every service gets
|
|
35
|
+
* this body on its request connection, so a service must ignore a request body it does not know
|
|
36
|
+
* (answer an error, act on nothing), never treat an arbitrary body as a command.
|
|
37
|
+
*/
|
|
38
|
+
export declare const DEVICE_SERVICE_ROLL_CHECK = "{\"capybara\":\"roll-check\"}";
|
|
39
|
+
/** A service's answer to {@link DEVICE_SERVICE_ROLL_CHECK}. */
|
|
40
|
+
export interface DeviceServiceRollCheck {
|
|
41
|
+
/** True while restarting now would lose something a person is doing (a takeover, a handoff). */
|
|
42
|
+
busy: boolean;
|
|
43
|
+
/** What keeps it busy, for the kernel's log. */
|
|
44
|
+
reason?: string;
|
|
45
|
+
}
|
|
46
|
+
/** Whether `body` is the kernel's {@link DEVICE_SERVICE_ROLL_CHECK} request. */
|
|
47
|
+
export declare function isRollCheck(body: Uint8Array | string): boolean;
|
|
48
|
+
/** Reads a service's answer to the roll check: busy only for `{"busy":true}` (never throws). */
|
|
49
|
+
export declare function parseRollCheck(body: Uint8Array | string): DeviceServiceRollCheck;
|
|
29
50
|
/** Names the unix socket path the service listens on. */
|
|
30
51
|
export declare const DEVICE_SERVICE_SOCKET_ENV = "CAPYBARA_SERVICE_SOCKET";
|
|
31
52
|
/** Names the service's state directory (its own data, its write root; not where its code is). */
|
package/dist/device-service.js
CHANGED
|
@@ -26,6 +26,43 @@
|
|
|
26
26
|
* never context. Providers and the device program pass the viewer context through like any
|
|
27
27
|
* stream message.
|
|
28
28
|
*/
|
|
29
|
+
/**
|
|
30
|
+
* The request body the kernel sends a running service before restarting it on new files (an
|
|
31
|
+
* upgraded extension, {@link DeviceServiceRollCheck}). A service that answers
|
|
32
|
+
* `{"busy":true,"reason":"…"}` is kept running (a person is using it); the kernel asks again at a
|
|
33
|
+
* later ensure. Any other answer, an error or no answer within a few seconds lets the restart go
|
|
34
|
+
* ahead, so a service that does not know the check is restarted as before. Every service gets
|
|
35
|
+
* this body on its request connection, so a service must ignore a request body it does not know
|
|
36
|
+
* (answer an error, act on nothing), never treat an arbitrary body as a command.
|
|
37
|
+
*/
|
|
38
|
+
export const DEVICE_SERVICE_ROLL_CHECK = '{"capybara":"roll-check"}';
|
|
39
|
+
/** Whether `body` is the kernel's {@link DEVICE_SERVICE_ROLL_CHECK} request. */
|
|
40
|
+
export function isRollCheck(body) {
|
|
41
|
+
const text = typeof body === "string" ? body : new TextDecoder().decode(body);
|
|
42
|
+
try {
|
|
43
|
+
const v = JSON.parse(text);
|
|
44
|
+
return (typeof v === "object" && v !== null && v.capybara === "roll-check");
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** Reads a service's answer to the roll check: busy only for `{"busy":true}` (never throws). */
|
|
51
|
+
export function parseRollCheck(body) {
|
|
52
|
+
const text = typeof body === "string" ? body : new TextDecoder().decode(body);
|
|
53
|
+
try {
|
|
54
|
+
const v = JSON.parse(text);
|
|
55
|
+
if (typeof v === "object" && v !== null && v.busy === true)
|
|
56
|
+
return {
|
|
57
|
+
busy: true,
|
|
58
|
+
...(typeof v.reason === "string" && { reason: v.reason.slice(0, 200) }),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// not JSON: not busy
|
|
63
|
+
}
|
|
64
|
+
return { busy: false };
|
|
65
|
+
}
|
|
29
66
|
/** Names the unix socket path the service listens on. */
|
|
30
67
|
export const DEVICE_SERVICE_SOCKET_ENV = "CAPYBARA_SERVICE_SOCKET";
|
|
31
68
|
/** Names the service's state directory (its own data, its write root; not where its code is). */
|
package/dist/identity.d.ts
CHANGED
|
@@ -16,6 +16,32 @@ export interface ExternalIdentity {
|
|
|
16
16
|
displayName: string;
|
|
17
17
|
avatarUrl?: string;
|
|
18
18
|
}
|
|
19
|
+
/** How an identity source describes its tenants to the admin console. */
|
|
20
|
+
export interface IdentitySourceTenant {
|
|
21
|
+
/** The field label in Chinese and English, e.g. the Slack workspace ID. */
|
|
22
|
+
label: {
|
|
23
|
+
zh: string;
|
|
24
|
+
en: string;
|
|
25
|
+
};
|
|
26
|
+
/** Where to find the tenant id. */
|
|
27
|
+
help?: {
|
|
28
|
+
zh: string;
|
|
29
|
+
en: string;
|
|
30
|
+
};
|
|
31
|
+
/** A regular expression (JavaScript syntax) a tenant id must match, e.g. `^T[A-Z0-9]+$`. */
|
|
32
|
+
pattern?: string;
|
|
33
|
+
/** An example tenant id shown as the placeholder. */
|
|
34
|
+
placeholder?: string;
|
|
35
|
+
/** Tenant ids that may never be trusted for email merge (Google: `consumer`). */
|
|
36
|
+
neverTrusted?: string[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Checks a tenant id against a source's tenant declaration: `"empty"` for a blank id, `"pattern"`
|
|
40
|
+
* when it does not match the declared pattern (an invalid pattern counts as none),
|
|
41
|
+
* `"never_trusted"` when the source lists it in `neverTrusted`, else `"ok"`. The id is trimmed
|
|
42
|
+
* first. The kernel uses it before storing trusted tenants.
|
|
43
|
+
*/
|
|
44
|
+
export declare function validateTenantId(decl: IdentitySourceTenant | undefined, id: string): "ok" | "pattern" | "never_trusted" | "empty";
|
|
19
45
|
/**
|
|
20
46
|
* Third-party login (`identity-source@1`). State, nonce and PKCE are all generated by the kernel
|
|
21
47
|
* and kept server-side:
|
|
@@ -29,6 +55,12 @@ export interface IdentitySource {
|
|
|
29
55
|
zh: string;
|
|
30
56
|
en: string;
|
|
31
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* What a tenant is on this platform, so the admin console can label and check the trusted
|
|
60
|
+
* tenants of this source (a tenant id is the `<tenant>` of the source key `<plugin>:<tenant>`).
|
|
61
|
+
* Without it the console shows a plain tenant id field.
|
|
62
|
+
*/
|
|
63
|
+
tenant?: IdentitySourceTenant;
|
|
32
64
|
authorizeUrl(args: {
|
|
33
65
|
config: unknown;
|
|
34
66
|
redirectUri: string;
|
package/dist/identity.js
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks a tenant id against a source's tenant declaration: `"empty"` for a blank id, `"pattern"`
|
|
3
|
+
* when it does not match the declared pattern (an invalid pattern counts as none),
|
|
4
|
+
* `"never_trusted"` when the source lists it in `neverTrusted`, else `"ok"`. The id is trimmed
|
|
5
|
+
* first. The kernel uses it before storing trusted tenants.
|
|
6
|
+
*/
|
|
7
|
+
export function validateTenantId(decl, id) {
|
|
8
|
+
const value = id.trim();
|
|
9
|
+
if (value === "")
|
|
10
|
+
return "empty";
|
|
11
|
+
if (decl?.pattern) {
|
|
12
|
+
let re;
|
|
13
|
+
try {
|
|
14
|
+
re = new RegExp(decl.pattern);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
re = undefined;
|
|
18
|
+
}
|
|
19
|
+
if (re && !re.test(value))
|
|
20
|
+
return "pattern";
|
|
21
|
+
}
|
|
22
|
+
if (decl?.neverTrusted?.includes(value))
|
|
23
|
+
return "never_trusted";
|
|
24
|
+
return "ok";
|
|
25
|
+
}
|
|
1
26
|
/**
|
|
2
27
|
* Thrown by an identity source's `callback` when it refuses the account on purpose (a hosted domain
|
|
3
28
|
* or tenant the platform does not allow, a consumer account where only organization accounts are
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.1.0-rc.
|
|
1
|
+
export declare const SDK_VERSION = "0.1.0-rc.78";
|
|
2
2
|
export * from "./agent-template.js";
|
|
3
3
|
export * from "./avatar-presets.js";
|
|
4
4
|
export * from "./bootstrap.js";
|
|
@@ -28,6 +28,7 @@ export * from "./identity.js";
|
|
|
28
28
|
export * from "./marketplace.js";
|
|
29
29
|
export * from "./model.js";
|
|
30
30
|
export * from "./model-params.js";
|
|
31
|
+
export * from "./native-failure.js";
|
|
31
32
|
export * from "./net.js";
|
|
32
33
|
export * from "./network-classes.js";
|
|
33
34
|
export * from "./permissions.js";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.1.0-rc.
|
|
1
|
+
export const SDK_VERSION = "0.1.0-rc.78";
|
|
2
2
|
export * from "./agent-template.js";
|
|
3
3
|
export * from "./avatar-presets.js";
|
|
4
4
|
export * from "./bootstrap.js";
|
|
@@ -28,6 +28,7 @@ export * from "./identity.js";
|
|
|
28
28
|
export * from "./marketplace.js";
|
|
29
29
|
export * from "./model.js";
|
|
30
30
|
export * from "./model-params.js";
|
|
31
|
+
export * from "./native-failure.js";
|
|
31
32
|
export * from "./net.js";
|
|
32
33
|
export * from "./network-classes.js";
|
|
33
34
|
export * from "./permissions.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model-facing text of a failed native file operation (#907), one mapping for every native
|
|
3
|
+
* helper and provider (capybara-device, device-docker, device-e2b). A native helper answers
|
|
4
|
+
* `{ error: { code } }` with an errno name (`ENOENT`, …), `SCOPE_DENIED`, `NOT_REGULAR_FILE` or
|
|
5
|
+
* `INVALID_NATIVE_REQUEST`; its own exception text never reaches the model (it may carry paths or
|
|
6
|
+
* other details), only the kernel-defined text for the code.
|
|
7
|
+
*/
|
|
8
|
+
/** The code a native helper answers when a read or write names something other than a regular file. */
|
|
9
|
+
export declare const NATIVE_NOT_REGULAR_FILE = "NOT_REGULAR_FILE";
|
|
10
|
+
/** The text for a code this mapping does not know. */
|
|
11
|
+
export declare const NATIVE_FAILURE_GENERIC = "Native operation failed; check the path, scope and filesystem access";
|
|
12
|
+
/** The model-facing text for a native helper's error code. */
|
|
13
|
+
export declare function nativeFailureText(code: string | undefined): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model-facing text of a failed native file operation (#907), one mapping for every native
|
|
3
|
+
* helper and provider (capybara-device, device-docker, device-e2b). A native helper answers
|
|
4
|
+
* `{ error: { code } }` with an errno name (`ENOENT`, …), `SCOPE_DENIED`, `NOT_REGULAR_FILE` or
|
|
5
|
+
* `INVALID_NATIVE_REQUEST`; its own exception text never reaches the model (it may carry paths or
|
|
6
|
+
* other details), only the kernel-defined text for the code.
|
|
7
|
+
*/
|
|
8
|
+
/** The code a native helper answers when a read or write names something other than a regular file. */
|
|
9
|
+
export const NATIVE_NOT_REGULAR_FILE = "NOT_REGULAR_FILE";
|
|
10
|
+
/** The text for a code this mapping does not know. */
|
|
11
|
+
export const NATIVE_FAILURE_GENERIC = "Native operation failed; check the path, scope and filesystem access";
|
|
12
|
+
const TEXTS = {
|
|
13
|
+
[NATIVE_NOT_REGULAR_FILE]: "The path is not a regular file (it is a directory, a device or another special file); only regular files can be read or written",
|
|
14
|
+
ENOENT: "The path, or one of its parent directories, does not exist; check the path",
|
|
15
|
+
ENOTDIR: "A component of the path is not a directory; check the path",
|
|
16
|
+
EISDIR: "The path is a directory, not a file",
|
|
17
|
+
EEXIST: "The path already exists",
|
|
18
|
+
ENAMETOOLONG: "The path is too long",
|
|
19
|
+
ENOSPC: "The device's disk is full; free some space, then retry",
|
|
20
|
+
EDQUOT: "The device's disk quota is exhausted; free some space, then retry",
|
|
21
|
+
EROFS: "The path is on a read-only file system",
|
|
22
|
+
EFBIG: "The file is too large for the device's file system",
|
|
23
|
+
EBUSY: "The file is busy; retry the call",
|
|
24
|
+
ESTALE: "The file changed while it was being used; retry the call",
|
|
25
|
+
EIO: "The device's disk reported an input/output error",
|
|
26
|
+
};
|
|
27
|
+
/** The model-facing text for a native helper's error code. */
|
|
28
|
+
export function nativeFailureText(code) {
|
|
29
|
+
return ((code !== undefined && Object.hasOwn(TEXTS, code) ? TEXTS[code] : undefined) ??
|
|
30
|
+
NATIVE_FAILURE_GENERIC);
|
|
31
|
+
}
|
|
@@ -64,6 +64,11 @@ export interface RenderSkillInvocationInput {
|
|
|
64
64
|
};
|
|
65
65
|
/** false: leave out the lead sentence (a forked skill's task for the sub-agent). Default true. */
|
|
66
66
|
lead?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* The skills root of the conversation's device (`SandboxRoots.skills`, e.g. a connected
|
|
69
|
+
* machine's real path), used for `${CLAUDE_SKILL_DIR}` and the files line. Default `/skills`.
|
|
70
|
+
*/
|
|
71
|
+
skillsRoot?: string;
|
|
67
72
|
}
|
|
68
73
|
/**
|
|
69
74
|
* Both `skill_invocation` wrapper tags made inert (`<\/skill_invocation`, `<\skill_invocation`, any
|
package/dist/skill-invocation.js
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* The argument rules follow Claude Code (re-checked 2026-10-27): `$ARGUMENTS` is the whole argument
|
|
7
7
|
* string, `$ARGUMENTS[N]` / `$N` are 0-based positional values (a missing one stays as written),
|
|
8
8
|
* `$name` takes its value from frontmatter `arguments` (a missing one becomes empty), `\$` is a
|
|
9
|
-
* literal `$`, `${CLAUDE_SKILL_DIR}` is
|
|
9
|
+
* literal `$`, `${CLAUDE_SKILL_DIR}` is `<skills root>/<name>@<digest>` (the device's skills root,
|
|
10
|
+
* default `/skills`) and every other `${…}` stays as written.
|
|
10
11
|
* When the body has no argument placeholder and the arguments are not empty, they are appended as
|
|
11
12
|
* `ARGUMENTS: <args>`. Substituted text is never scanned again. Nothing is executed: shell
|
|
12
13
|
* injections (`` !`cmd` ``) stay text, and the model is told how to run them.
|
|
@@ -183,14 +184,14 @@ const escapeAttr = (s) => s.replace(/&/g, "&").replace(/"/g, """).repla
|
|
|
183
184
|
*/
|
|
184
185
|
export function renderSkillInvocation(i) {
|
|
185
186
|
const args = trimmedArgs(i.args);
|
|
186
|
-
const body = renderSkillBody(i.body, i.invocation, args, i.skillName, i.digest).replace(CLOSE_TAG_RE, "<\\/$1");
|
|
187
|
+
const body = renderSkillBody(i.body, i.invocation, args, i.skillName, i.digest, i.skillsRoot).replace(CLOSE_TAG_RE, "<\\/$1");
|
|
187
188
|
const parts = [];
|
|
188
189
|
if (i.lead !== false) {
|
|
189
190
|
parts.push(escapeTags(`The user invoked the skill "${i.name}" with /${i.name}${args === "" ? "" : ` ${args}`}. Follow its instructions for this request.`));
|
|
190
191
|
}
|
|
191
192
|
parts.push(`<skill_invocation name="${escapeAttr(i.name)}" version="${i.version}">\n${body}\n</skill_invocation>`);
|
|
192
193
|
if (i.lines.files === "load") {
|
|
193
|
-
parts.push(`Its files are not in the sandbox yet: call Skill with "${i.name}" to copy them to ${skillSandboxDir(i.skillName, i.digest)}/ before running its scripts.`);
|
|
194
|
+
parts.push(`Its files are not in the sandbox yet: call Skill with "${i.name}" to copy them to ${skillSandboxDir(i.skillName, i.digest, i.skillsRoot)}/ before running its scripts.`);
|
|
194
195
|
}
|
|
195
196
|
else if (i.lines.files === "unavailable") {
|
|
196
197
|
parts.push("Its other files are not available in this conversation.");
|