@capybara-hq/kernel 0.1.0-rc.98 → 0.1.0-rc.99
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/bootstrap.json +17 -17
- package/dist/catalog/git-source.d.ts +5 -0
- package/dist/catalog/git-source.js +9 -5
- package/dist/catalog/marketplace-fetch.d.ts +9 -0
- package/dist/catalog/marketplace-fetch.js +9 -5
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/conversations/events.d.ts +1 -0
- package/dist/conversations/events.js +3 -1
- package/dist/net/safe-fetch.d.ts +22 -4
- package/dist/net/safe-fetch.js +74 -0
- package/dist/platform/file-ref.d.ts +2 -0
- package/dist/platform/file-ref.js +1 -3
- package/dist/tools/builtins/platform.js +4 -3
- package/dist/tools/builtins/sandbox/bash.d.ts +3 -1
- package/dist/tools/builtins/sandbox/bash.js +22 -11
- package/dist/tools/builtins/sandbox/common.d.ts +4 -1
- package/dist/tools/builtins/sandbox/common.js +5 -2
- package/dist/tools/builtins/sandbox/glob.js +2 -1
- package/dist/tools/builtins/sandbox/grep.js +2 -1
- package/dist/tools/builtins/sandbox/search-command.d.ts +4 -3
- package/dist/tools/builtins/sandbox/search-command.js +11 -3
- package/dist/tools/network-asks.d.ts +23 -0
- package/dist/tools/network-asks.js +24 -5
- package/dist/tools/pipeline.d.ts +1 -1
- package/dist/tools/pipeline.js +41 -11
- package/dist/tools/registry.d.ts +6 -6
- package/package.json +2 -2
package/bootstrap.json
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
"schemaVersion": 1,
|
|
4
4
|
"marketplace": {
|
|
5
5
|
"url": "https://github.com/capybara-hq/plugins.git",
|
|
6
|
-
"commit": "
|
|
6
|
+
"commit": "1f142e1cebba0b54d94ba69b97004609d9c03cc4"
|
|
7
7
|
},
|
|
8
8
|
"plugins": [
|
|
9
9
|
{
|
|
10
10
|
"name": "openai-compatible",
|
|
11
11
|
"source": "npm",
|
|
12
12
|
"npm": "@capybara-hq/plugin-openai-compatible",
|
|
13
|
-
"version": "0.1.0-rc.
|
|
14
|
-
"integrity": "sha512-
|
|
13
|
+
"version": "0.1.0-rc.13",
|
|
14
|
+
"integrity": "sha512-IXdGfR9nhUXFWcF+3Bpmemn6M2e/EgC7x1jhKg84H23vKANviVcGvyTugyAjyd7K3vd0DD8aYAW1CMnTksUpJg==",
|
|
15
15
|
"required": false
|
|
16
16
|
},
|
|
17
17
|
{
|
|
@@ -26,40 +26,40 @@
|
|
|
26
26
|
"name": "anthropic",
|
|
27
27
|
"source": "npm",
|
|
28
28
|
"npm": "@capybara-hq/plugin-anthropic",
|
|
29
|
-
"version": "0.1.0-rc.
|
|
30
|
-
"integrity": "sha512-
|
|
29
|
+
"version": "0.1.0-rc.11",
|
|
30
|
+
"integrity": "sha512-du0wCj2z3asIZk1mpDOBAtlZSmqB1WQTr8doHb8uPSKGCqfkcCgSVrJWP8dbqW//BHO8un0uWLs74TBvk+f9ug==",
|
|
31
31
|
"required": false
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
34
|
"name": "openai",
|
|
35
35
|
"source": "npm",
|
|
36
36
|
"npm": "@capybara-hq/plugin-openai",
|
|
37
|
-
"version": "0.1.0-rc.
|
|
38
|
-
"integrity": "sha512-
|
|
37
|
+
"version": "0.1.0-rc.13",
|
|
38
|
+
"integrity": "sha512-96cLlSSDPNlAjeFjHYYVfupqUDYYmePMThmB1nhwDoNO15F3OXEUECRGUR8PbUSjjthZTQ7gmb+HfCx9CqBweg==",
|
|
39
39
|
"required": false
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
42
|
"name": "deepseek",
|
|
43
43
|
"source": "npm",
|
|
44
44
|
"npm": "@capybara-hq/plugin-deepseek",
|
|
45
|
-
"version": "0.1.0-rc.
|
|
46
|
-
"integrity": "sha512-
|
|
45
|
+
"version": "0.1.0-rc.12",
|
|
46
|
+
"integrity": "sha512-bDl3SWO/SO23PaY7Jc9km79kctaGYKqjWOTaXcb+olJNHCNwP4lEXuAY7jylBMaDxL3WttWdHDS6c/QjHFbUeA==",
|
|
47
47
|
"required": false
|
|
48
48
|
},
|
|
49
49
|
{
|
|
50
50
|
"name": "bailian",
|
|
51
51
|
"source": "npm",
|
|
52
52
|
"npm": "@capybara-hq/plugin-bailian",
|
|
53
|
-
"version": "0.1.0-rc.
|
|
54
|
-
"integrity": "sha512-
|
|
53
|
+
"version": "0.1.0-rc.12",
|
|
54
|
+
"integrity": "sha512-bEO6UTSlFJq5F+4ht/FQtgM2pOhRzaVY2+URWegR7lZ7utd9AhkTEoRAFnECUq3e7kI7/pJMoNyNX6KTMd9Xpw==",
|
|
55
55
|
"required": false
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
58
|
"name": "ark",
|
|
59
59
|
"source": "npm",
|
|
60
60
|
"npm": "@capybara-hq/plugin-ark",
|
|
61
|
-
"version": "0.1.0-rc.
|
|
62
|
-
"integrity": "sha512-
|
|
61
|
+
"version": "0.1.0-rc.13",
|
|
62
|
+
"integrity": "sha512-dmS7jJcPGTsWBzRC8rIe5T/GUrqfNNzlQeS5iIfoZdXGNPJqNrylHLp12eRZspaTPkZzpGgowV0MOhiQvwDzMA==",
|
|
63
63
|
"required": false
|
|
64
64
|
},
|
|
65
65
|
{
|
|
@@ -90,8 +90,8 @@
|
|
|
90
90
|
"name": "device-docker",
|
|
91
91
|
"source": "npm",
|
|
92
92
|
"npm": "@capybara-hq/plugin-device-docker",
|
|
93
|
-
"version": "0.1.0-rc.
|
|
94
|
-
"integrity": "sha512-
|
|
93
|
+
"version": "0.1.0-rc.34",
|
|
94
|
+
"integrity": "sha512-FOYFio9VPBzGic0RqpFDN6qMmyuWEA2PHl2ZsIknHfvHYqMQsv6NCoESbWo2SAVGzmt6c3YRC1u8C02m3SDAEg==",
|
|
95
95
|
"required": false
|
|
96
96
|
},
|
|
97
97
|
{
|
|
@@ -107,8 +107,8 @@
|
|
|
107
107
|
"name": "todo",
|
|
108
108
|
"source": "npm",
|
|
109
109
|
"npm": "@capybara-hq/plugin-todo",
|
|
110
|
-
"version": "0.1.0-rc.
|
|
111
|
-
"integrity": "sha512-
|
|
110
|
+
"version": "0.1.0-rc.14",
|
|
111
|
+
"integrity": "sha512-HtGVlONC/l11Pw0lctdOMQc29ccUaVuU86LYx6cIq/plvfGKUXzSO9K/fAM3ED64eHNPSAUUYGRutloQY6HsfA==",
|
|
112
112
|
"required": false
|
|
113
113
|
},
|
|
114
114
|
{
|
|
@@ -57,6 +57,11 @@ export type GitOptions = {
|
|
|
57
57
|
maxBytes: number;
|
|
58
58
|
/** Where the temp object store is created (default the OS temp dir); tests only. */
|
|
59
59
|
tempRoot?: string;
|
|
60
|
+
/** Retry of transient failures (connection errors, HTTP 502 / 503 / 504); tests shorten it. */
|
|
61
|
+
retry?: {
|
|
62
|
+
attempts?: number;
|
|
63
|
+
backoffMs?: number;
|
|
64
|
+
};
|
|
60
65
|
};
|
|
61
66
|
export type GitSourceErrorCode = "marketplace.git_failed" | "marketplace.git_too_large" | "marketplace.git_unsupported_entry";
|
|
62
67
|
/**
|
|
@@ -6,7 +6,7 @@ import { inflateSync } from "node:zlib";
|
|
|
6
6
|
import { GIT_MARKETPLACE_USERNAME_DEFAULT, GIT_USERNAME_RE } from "@capybara-hq/plugin-sdk";
|
|
7
7
|
import git, {} from "isomorphic-git";
|
|
8
8
|
import { NetDeniedError } from "../net/public-address.js";
|
|
9
|
-
import { NetBodyTooLargeError, safeFetch } from "../net/safe-fetch.js";
|
|
9
|
+
import { describeFetchError, NetBodyTooLargeError, safeFetch } from "../net/safe-fetch.js";
|
|
10
10
|
import { marketplaceNetCode, marketplaceUrlProblem, } from "./marketplace-fetch.js";
|
|
11
11
|
/**
|
|
12
12
|
* Reading plugins from git (spec §5.1, §5.2; Decision 2): isomorphic-git (pure JS, any smart-HTTP
|
|
@@ -138,7 +138,9 @@ function startOp(loc, o) {
|
|
|
138
138
|
headers.authorization = auth;
|
|
139
139
|
const method = req.method ?? "GET";
|
|
140
140
|
const body = req.body === undefined ? undefined : await collect(req.body);
|
|
141
|
-
const res = await safeFetch(target.href, { method, headers, ...(body !== undefined && { body }), signal }, o.net,
|
|
141
|
+
const res = await safeFetch(target.href, { method, headers, ...(body !== undefined && { body }), signal }, o.net,
|
|
142
|
+
// both git requests only read (`info/refs`, `git-upload-pack`) and the body is a Buffer
|
|
143
|
+
{ maxBytes: o.maxBytes, retry: o.retry ?? {} });
|
|
142
144
|
const stream = res.body;
|
|
143
145
|
async function* chunks() {
|
|
144
146
|
if (stream === null)
|
|
@@ -191,9 +193,11 @@ function mapError(e, op, o, what) {
|
|
|
191
193
|
if (cause instanceof NetDeniedError)
|
|
192
194
|
return mapError(cause, op, o, what);
|
|
193
195
|
const status = e?.data?.statusCode;
|
|
194
|
-
if (typeof status === "number")
|
|
195
|
-
|
|
196
|
-
|
|
196
|
+
if (typeof status === "number") {
|
|
197
|
+
const text = e.data?.statusMessage;
|
|
198
|
+
return failed(`${what}: the git server answered ${status}${typeof text === "string" && text !== "" ? ` ${text}` : ""}`, e);
|
|
199
|
+
}
|
|
200
|
+
return failed(`${what}: ${describeFetchError(e)}`, e);
|
|
197
201
|
}
|
|
198
202
|
/**
|
|
199
203
|
* The commit to read (40 lower-case hex): `commit` when given (it wins over `ref`), otherwise the
|
|
@@ -60,6 +60,11 @@ export interface MarketplaceFetchOptions {
|
|
|
60
60
|
net: NetPolicy;
|
|
61
61
|
/** Tests only: replaces the DNS lookup. */
|
|
62
62
|
lookup?: LookupFn;
|
|
63
|
+
/** Retry of transient failures (connection errors, HTTP 502 / 503 / 504); tests shorten it. */
|
|
64
|
+
retry?: {
|
|
65
|
+
attempts?: number;
|
|
66
|
+
backoffMs?: number;
|
|
67
|
+
};
|
|
63
68
|
signal: AbortSignal;
|
|
64
69
|
}
|
|
65
70
|
export type MarketplaceFetchResult = {
|
|
@@ -95,6 +100,10 @@ export declare function fetchMarketplaceArchive(archive: {
|
|
|
95
100
|
timeoutMs: number;
|
|
96
101
|
net: NetPolicy;
|
|
97
102
|
lookup?: LookupFn;
|
|
103
|
+
retry?: {
|
|
104
|
+
attempts?: number;
|
|
105
|
+
backoffMs?: number;
|
|
106
|
+
};
|
|
98
107
|
signal?: AbortSignal;
|
|
99
108
|
}): Promise<{
|
|
100
109
|
bytes: Uint8Array;
|
|
@@ -2,7 +2,7 @@ import { createHash, timingSafeEqual } from "node:crypto";
|
|
|
2
2
|
import { parseMarketplaceManifest } from "@capybara-hq/plugin-sdk";
|
|
3
3
|
import { ApiError } from "../errors.js";
|
|
4
4
|
import { NetDeniedError } from "../net/public-address.js";
|
|
5
|
-
import { safeFetch } from "../net/safe-fetch.js";
|
|
5
|
+
import { describeFetchError, safeFetch } from "../net/safe-fetch.js";
|
|
6
6
|
import { isLoopback, readCapped } from "../packages/npm.js";
|
|
7
7
|
/**
|
|
8
8
|
* The API error for a refused download, or undefined when the refusal is not one of the two
|
|
@@ -96,6 +96,7 @@ export async function fetchMarketplaceManifest(url, o) {
|
|
|
96
96
|
try {
|
|
97
97
|
res = await safeFetch(target.href, { headers, signal }, o.net, {
|
|
98
98
|
...(o.lookup !== undefined && { lookup: o.lookup }),
|
|
99
|
+
retry: o.retry ?? {},
|
|
99
100
|
});
|
|
100
101
|
}
|
|
101
102
|
catch (e) {
|
|
@@ -106,7 +107,9 @@ export async function fetchMarketplaceManifest(url, o) {
|
|
|
106
107
|
...(code !== undefined && { code, host: e.host }),
|
|
107
108
|
});
|
|
108
109
|
}
|
|
109
|
-
throw new MarketplaceFetchError(`cannot fetch the marketplace: ${
|
|
110
|
+
throw new MarketplaceFetchError(`cannot fetch the marketplace: ${describeFetchError(e)}`, {
|
|
111
|
+
cause: e,
|
|
112
|
+
});
|
|
110
113
|
}
|
|
111
114
|
if (res.status === 304) {
|
|
112
115
|
await res.body?.cancel().catch(() => { });
|
|
@@ -114,7 +117,7 @@ export async function fetchMarketplaceManifest(url, o) {
|
|
|
114
117
|
}
|
|
115
118
|
if (!res.ok) {
|
|
116
119
|
await res.body?.cancel().catch(() => { });
|
|
117
|
-
throw new MarketplaceFetchError(`the marketplace responded with HTTP ${res.status}`);
|
|
120
|
+
throw new MarketplaceFetchError(`the marketplace responded with HTTP ${res.status}${res.statusText !== "" ? ` ${res.statusText}` : ""}${res.status >= 500 ? " (the upstream host failed; try again later)" : ""}`);
|
|
118
121
|
}
|
|
119
122
|
let raw;
|
|
120
123
|
try {
|
|
@@ -171,6 +174,7 @@ export async function fetchMarketplaceArchive(archive, o) {
|
|
|
171
174
|
try {
|
|
172
175
|
res = await safeFetch(new URL(archive.url).href, { signal }, o.net, {
|
|
173
176
|
...(o.lookup !== undefined && { lookup: o.lookup }),
|
|
177
|
+
retry: o.retry ?? {},
|
|
174
178
|
});
|
|
175
179
|
}
|
|
176
180
|
catch (e) {
|
|
@@ -180,11 +184,11 @@ export async function fetchMarketplaceArchive(archive, o) {
|
|
|
180
184
|
throw new ApiError(code, `Archive download refused: ${e.message}`, [{ host: e.host }]);
|
|
181
185
|
}
|
|
182
186
|
}
|
|
183
|
-
throw failed(`cannot fetch the archive: ${
|
|
187
|
+
throw failed(`cannot fetch the archive ${archive.url}: ${describeFetchError(e)}`);
|
|
184
188
|
}
|
|
185
189
|
if (!res.ok) {
|
|
186
190
|
await res.body?.cancel().catch(() => { });
|
|
187
|
-
throw failed(`the archive URL responded with HTTP ${res.status}`);
|
|
191
|
+
throw failed(`the archive URL ${archive.url} responded with HTTP ${res.status}`);
|
|
188
192
|
}
|
|
189
193
|
const tooLarge = new ApiError("extension.package_too_large", `the package is larger than ${o.maxBytes} bytes`);
|
|
190
194
|
let bytes;
|
|
@@ -208,7 +208,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
|
|
|
208
208
|
/** The host versions (an entry's `minKernel` is judged against them). */
|
|
209
209
|
export declare const HOST_VERSIONS: {
|
|
210
210
|
readonly kernel: string;
|
|
211
|
-
readonly sdk: "0.1.0-rc.
|
|
211
|
+
readonly sdk: "0.1.0-rc.82";
|
|
212
212
|
};
|
|
213
213
|
/** Whether this deployment satisfies the entry's `minKernel`. */
|
|
214
214
|
export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
|
|
@@ -1493,6 +1493,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
|
|
|
1493
1493
|
process: "process";
|
|
1494
1494
|
}>>;
|
|
1495
1495
|
text: z.ZodOptional<z.ZodString>;
|
|
1496
|
+
badge: z.ZodOptional<z.ZodString>;
|
|
1496
1497
|
}, z.core.$strip>>;
|
|
1497
1498
|
media: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1498
1499
|
attachmentId: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { posix } from "node:path";
|
|
2
|
-
import { CARD_TEXT_MAX, CONTEXT_LIMITS, DOCUMENT_MEDIA_TYPES, hasControlChars, IMAGE_MEDIA_TYPES, isAttachmentId, isSkillName, MEDIA_NAME_MAX_CHARS, validateAllowHost, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { CARD_BADGE_MAX, CARD_TEXT_MAX, CONTEXT_LIMITS, DOCUMENT_MEDIA_TYPES, hasControlChars, IMAGE_MEDIA_TYPES, isAttachmentId, isSkillName, MEDIA_NAME_MAX_CHARS, validateAllowHost, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { AgentDefinitionSchema, DisabledSkillRef, DisabledToolRef, ModelRef, } from "../agents/definition.js";
|
|
5
5
|
import { ORG_ROLES } from "../orgs/roles.js";
|
|
@@ -1304,6 +1304,8 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
1304
1304
|
placement: z.enum(["pinned", "process"]).optional(),
|
|
1305
1305
|
/** Only with `placement: "pinned"`; at most `CARD_TEXT_MAX` characters. */
|
|
1306
1306
|
text: z.string().min(1).max(CARD_TEXT_MAX).optional(),
|
|
1307
|
+
/** Only with `placement: "pinned"`: its view's badge, at most `CARD_BADGE_MAX`. */
|
|
1308
|
+
badge: z.string().min(1).max(CARD_BADGE_MAX).optional(),
|
|
1307
1309
|
})
|
|
1308
1310
|
.optional(),
|
|
1309
1311
|
/**
|
package/dist/net/safe-fetch.d.ts
CHANGED
|
@@ -28,9 +28,7 @@ export declare class NetBodyTooLargeError extends Error {
|
|
|
28
28
|
export declare function pinnedAgent(ips: string[], tls?: {
|
|
29
29
|
ca?: string | string[];
|
|
30
30
|
}): Agent;
|
|
31
|
-
export
|
|
32
|
-
signal: AbortSignal;
|
|
33
|
-
}, policy: NetPolicy, opts?: {
|
|
31
|
+
export type SafeFetchOptions = {
|
|
34
32
|
lookup?: LookupFn;
|
|
35
33
|
maxBytes?: number;
|
|
36
34
|
/** A 3xx response (other than 304): `refuse` (default) rejects with `net.redirect`, `return` returns it. */
|
|
@@ -39,4 +37,24 @@ export declare function safeFetch(url: string, init: RequestInit & {
|
|
|
39
37
|
dispatcherFor?: (ips: string[]) => Agent;
|
|
40
38
|
/** Tests only: builds the proxy dispatcher (defaults to {@link proxyAgent}). */
|
|
41
39
|
proxyDispatcherFor?: (proxyUrl: string) => Agent;
|
|
42
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Retry transient failures of an idempotent request (a GET, or a POST that only reads, with a
|
|
42
|
+
* replayable body): a connection error or HTTP 502 / 503 / 504, up to `attempts` tries in all
|
|
43
|
+
* (default 3) with exponential backoff from `backoffMs` (default 500 ms), cut short by the
|
|
44
|
+
* request's signal. Network refusals (`NetDeniedError`), an oversized body and an abort are
|
|
45
|
+
* never retried. After the last try a 5xx response is returned as is.
|
|
46
|
+
*/
|
|
47
|
+
retry?: {
|
|
48
|
+
attempts?: number;
|
|
49
|
+
backoffMs?: number;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Why a fetch failed, with undici's hidden cause ("fetch failed" -> ETIMEDOUT, ECONNRESET, ...).
|
|
54
|
+
* A connection-level failure names the egress proxy setting: the kernel connects directly unless
|
|
55
|
+
* `net.httpsProxy` is set, and never reads HTTPS_PROXY.
|
|
56
|
+
*/
|
|
57
|
+
export declare function describeFetchError(e: unknown): string;
|
|
58
|
+
export declare function safeFetch(url: string, init: RequestInit & {
|
|
59
|
+
signal: AbortSignal;
|
|
60
|
+
}, policy: NetPolicy, opts?: SafeFetchOptions): Promise<Response>;
|
package/dist/net/safe-fetch.js
CHANGED
|
@@ -71,7 +71,81 @@ function capBody(body, maxBytes) {
|
|
|
71
71
|
},
|
|
72
72
|
}));
|
|
73
73
|
}
|
|
74
|
+
const RETRY_ATTEMPTS = 3;
|
|
75
|
+
const RETRY_BACKOFF_MS = 500;
|
|
76
|
+
const RETRY_STATUSES = new Set([502, 503, 504]);
|
|
77
|
+
function retryDelay(ms, signal) {
|
|
78
|
+
signal.throwIfAborted();
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
const onAbort = () => {
|
|
81
|
+
clearTimeout(timer);
|
|
82
|
+
reject(signal.reason);
|
|
83
|
+
};
|
|
84
|
+
const timer = setTimeout(() => {
|
|
85
|
+
signal.removeEventListener("abort", onAbort);
|
|
86
|
+
resolve();
|
|
87
|
+
}, ms);
|
|
88
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const CONNECTION_CODES = new Set([
|
|
92
|
+
"ETIMEDOUT",
|
|
93
|
+
"ECONNRESET",
|
|
94
|
+
"ECONNREFUSED",
|
|
95
|
+
"EHOSTUNREACH",
|
|
96
|
+
"ENETUNREACH",
|
|
97
|
+
"EAI_AGAIN",
|
|
98
|
+
"UND_ERR_CONNECT_TIMEOUT",
|
|
99
|
+
"UND_ERR_SOCKET",
|
|
100
|
+
]);
|
|
101
|
+
/**
|
|
102
|
+
* Why a fetch failed, with undici's hidden cause ("fetch failed" -> ETIMEDOUT, ECONNRESET, ...).
|
|
103
|
+
* A connection-level failure names the egress proxy setting: the kernel connects directly unless
|
|
104
|
+
* `net.httpsProxy` is set, and never reads HTTPS_PROXY.
|
|
105
|
+
*/
|
|
106
|
+
export function describeFetchError(e) {
|
|
107
|
+
if (!(e instanceof Error))
|
|
108
|
+
return String(e);
|
|
109
|
+
const cause = e.cause;
|
|
110
|
+
if (!(cause instanceof Error) || cause.message === "" || cause.message === e.message) {
|
|
111
|
+
return e.message;
|
|
112
|
+
}
|
|
113
|
+
const code = cause.code;
|
|
114
|
+
const text = `${e.message} (${typeof code === "string" ? `${code}: ` : ""}${cause.message})`;
|
|
115
|
+
return typeof code === "string" && CONNECTION_CODES.has(code)
|
|
116
|
+
? `${text}. If this deployment reaches the internet through a proxy, set net.httpsProxy (CAPYBARA_NET__HTTPSPROXY); HTTPS_PROXY is not read`
|
|
117
|
+
: text;
|
|
118
|
+
}
|
|
74
119
|
export async function safeFetch(url, init, policy, opts = {}) {
|
|
120
|
+
const retry = opts.retry;
|
|
121
|
+
if (retry === undefined)
|
|
122
|
+
return safeFetchOnce(url, init, policy, opts);
|
|
123
|
+
const attempts = Math.max(1, retry.attempts ?? RETRY_ATTEMPTS);
|
|
124
|
+
const base = retry.backoffMs ?? RETRY_BACKOFF_MS;
|
|
125
|
+
for (let attempt = 1;; attempt++) {
|
|
126
|
+
let res;
|
|
127
|
+
let failure;
|
|
128
|
+
try {
|
|
129
|
+
res = await safeFetchOnce(url, init, policy, opts);
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
failure = e;
|
|
133
|
+
}
|
|
134
|
+
const transient = res !== undefined
|
|
135
|
+
? RETRY_STATUSES.has(res.status)
|
|
136
|
+
: !init.signal.aborted &&
|
|
137
|
+
!(failure instanceof NetDeniedError) &&
|
|
138
|
+
!(failure instanceof NetBodyTooLargeError);
|
|
139
|
+
if (!transient || attempt >= attempts) {
|
|
140
|
+
if (res !== undefined)
|
|
141
|
+
return res;
|
|
142
|
+
throw failure;
|
|
143
|
+
}
|
|
144
|
+
await res?.body?.cancel().catch(() => { });
|
|
145
|
+
await retryDelay(base * 2 ** (attempt - 1), init.signal);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async function safeFetchOnce(url, init, policy, opts) {
|
|
75
149
|
let target;
|
|
76
150
|
try {
|
|
77
151
|
target = new URL(url);
|
|
@@ -46,6 +46,8 @@ export interface FileCardDetail {
|
|
|
46
46
|
export interface FileRefContext {
|
|
47
47
|
orgId: string;
|
|
48
48
|
conversationId: string;
|
|
49
|
+
/** The root of the conversation tree, from the call's context. */
|
|
50
|
+
rootConversationId: string;
|
|
49
51
|
signal: AbortSignal;
|
|
50
52
|
}
|
|
51
53
|
/** Ruling R9: the thumbnail's longest edge, quality and the most the data URL may take. */
|
|
@@ -14,7 +14,6 @@ import sharp from "sharp";
|
|
|
14
14
|
import { z } from "zod";
|
|
15
15
|
import { AttachmentsService, normalizeContentType, sniffMatches, } from "../conversations/attachments.service.js";
|
|
16
16
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
17
|
-
import { rootConversationOf } from "../runtime/subagents/child.js";
|
|
18
17
|
import { StorageService } from "../storage/storage.service.js";
|
|
19
18
|
import { findConversationFile } from "../tools/builtins/conversation-files.js";
|
|
20
19
|
/** Model-visible: a device path where a file reference is expected. */
|
|
@@ -120,11 +119,10 @@ let FileRefs = class FileRefs {
|
|
|
120
119
|
}
|
|
121
120
|
async conversationFile(id, limits, ctx) {
|
|
122
121
|
const db = this.db.db;
|
|
123
|
-
const rootConversationId = await rootConversationOf(db, ctx.conversationId);
|
|
124
122
|
const file = await findConversationFile({ db, attachments: this.attachments, storage: this.storage }, {
|
|
125
123
|
orgId: ctx.orgId,
|
|
126
124
|
conversationId: ctx.conversationId,
|
|
127
|
-
rootConversationId,
|
|
125
|
+
rootConversationId: ctx.rootConversationId,
|
|
128
126
|
id,
|
|
129
127
|
// one byte past the limit tells a file that grew from one that fits
|
|
130
128
|
maxBytes: limits.maxBytes + 1,
|
|
@@ -382,7 +382,7 @@ export function platformTool(deps) {
|
|
|
382
382
|
let file;
|
|
383
383
|
let card = null;
|
|
384
384
|
try {
|
|
385
|
-
file = await fileOf(op, params, deps, octx, ctx.signal);
|
|
385
|
+
file = await fileOf(op, params, deps, octx, ctx.rootConversationId ?? ctx.conversationId, ctx.signal);
|
|
386
386
|
if (file !== null)
|
|
387
387
|
card = await fileCardDetail(file);
|
|
388
388
|
}
|
|
@@ -510,7 +510,7 @@ export function platformTool(deps) {
|
|
|
510
510
|
let result;
|
|
511
511
|
try {
|
|
512
512
|
// the file is read again, and must be the bytes the person confirmed (Review Focus 5)
|
|
513
|
-
const file = await fileOf(op, params, deps, octx, ctx.signal);
|
|
513
|
+
const file = await fileOf(op, params, deps, octx, ctx.rootConversationId, ctx.signal);
|
|
514
514
|
if (file !== null) {
|
|
515
515
|
// fails closed: bytes run only under this call's approval whose card showed them or,
|
|
516
516
|
// with no approval, the automatic decision that was bound to them (R7); a grant, an
|
|
@@ -637,7 +637,7 @@ export function platformTool(deps) {
|
|
|
637
637
|
* against its limits; null when the operation takes none for this input. Refusals are
|
|
638
638
|
* model-visible `ToolError`s; other errors propagate.
|
|
639
639
|
*/
|
|
640
|
-
async function fileOf(op, params, deps, ctx, signal) {
|
|
640
|
+
async function fileOf(op, params, deps, ctx, rootConversationId, signal) {
|
|
641
641
|
const wanted = op.fileRef?.(params) ?? null;
|
|
642
642
|
if (wanted === null)
|
|
643
643
|
return null;
|
|
@@ -646,6 +646,7 @@ async function fileOf(op, params, deps, ctx, signal) {
|
|
|
646
646
|
return deps.files.resolve(wanted.ref, wanted.limits, {
|
|
647
647
|
orgId: ctx.orgId,
|
|
648
648
|
conversationId: ctx.conversationId,
|
|
649
|
+
rootConversationId,
|
|
649
650
|
signal: signal ?? ctx.signal,
|
|
650
651
|
});
|
|
651
652
|
}
|
|
@@ -51,11 +51,13 @@ export declare const sandboxDenied: (r: ExecResult) => boolean;
|
|
|
51
51
|
* sandbox closes, then either the invitation to retry escalated (this device and org allow running
|
|
52
52
|
* outside the sandbox) or why that is not possible here and who can change it (the per-layer
|
|
53
53
|
* escalation refusal). Empty for an escalated call, a call without escalation facts, or no signal.
|
|
54
|
+
* `afterAddressNote`: the line follows a network note that already says private and local
|
|
55
|
+
* addresses are closed inside the sandbox, so a network denial's lead is left out.
|
|
54
56
|
*/
|
|
55
57
|
export declare function sandboxDenialHint(r: ExecResult, escalation: {
|
|
56
58
|
escalation?: "available" | "escalated";
|
|
57
59
|
refusal?: string;
|
|
58
|
-
}): string;
|
|
60
|
+
}, afterAddressNote?: boolean): string;
|
|
59
61
|
/**
|
|
60
62
|
* {@link SCOPE_DENIED_TOOL_TEXT} followed by {@link ESCALATION_RETRY_HINT}, written out as a literal
|
|
61
63
|
* for the tool design check (a unit test keeps the two copies equal).
|
|
@@ -419,15 +419,19 @@ export const sandboxDenied = (r) => sandboxDenial(r) !== null;
|
|
|
419
419
|
* sandbox closes, then either the invitation to retry escalated (this device and org allow running
|
|
420
420
|
* outside the sandbox) or why that is not possible here and who can change it (the per-layer
|
|
421
421
|
* escalation refusal). Empty for an escalated call, a call without escalation facts, or no signal.
|
|
422
|
+
* `afterAddressNote`: the line follows a network note that already says private and local
|
|
423
|
+
* addresses are closed inside the sandbox, so a network denial's lead is left out.
|
|
422
424
|
*/
|
|
423
|
-
export function sandboxDenialHint(r, escalation) {
|
|
425
|
+
export function sandboxDenialHint(r, escalation, afterAddressNote = false) {
|
|
424
426
|
if (escalation.escalation !== "available" && escalation.refusal === undefined)
|
|
425
427
|
return "";
|
|
426
428
|
const kind = sandboxDenial(r);
|
|
427
429
|
if (kind === null)
|
|
428
430
|
return "";
|
|
429
431
|
const lead = kind === "network"
|
|
430
|
-
?
|
|
432
|
+
? afterAddressNote
|
|
433
|
+
? "\n[sandbox]"
|
|
434
|
+
: "\n[sandbox] The OS sandbox may have blocked this command's connection: private and local addresses are closed inside the sandbox, and so is any host the sandbox network does not allow."
|
|
431
435
|
: "\n[sandbox] The OS sandbox may have blocked this command.";
|
|
432
436
|
return escalation.escalation === "available"
|
|
433
437
|
? `${lead}${ESCALATION_RETRY_HINT}`
|
|
@@ -511,14 +515,21 @@ export function sandboxBashTool(deps) {
|
|
|
511
515
|
const lowered = requested !== undefined && requested > maxMs
|
|
512
516
|
? `\n[timeout ${requested} ms is over the deployment maximum; it was lowered to ${maxMs} ms.]`
|
|
513
517
|
: "";
|
|
514
|
-
const
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
518
|
+
const facts = {
|
|
519
|
+
...(ctx.sandboxEscalation !== undefined && { escalation: ctx.sandboxEscalation }),
|
|
520
|
+
...(ctx.sandboxEscalationRefusal !== undefined && {
|
|
521
|
+
refusal: ctx.sandboxEscalationRefusal,
|
|
522
|
+
}),
|
|
523
|
+
};
|
|
524
|
+
// refused hosts become network notes in the pipeline, which picks the denial line that goes
|
|
525
|
+
// with them (`denialHintFor`): none after an address note that says how to run outside the
|
|
526
|
+
// sandbox, so the result carries one instruction about it
|
|
527
|
+
const reported = blocked.length > 0 && deviceId !== "";
|
|
528
|
+
const denialHint = {
|
|
529
|
+
full: sandboxDenialHint(r, facts),
|
|
530
|
+
afterAddressFact: sandboxDenialHint(r, facts, true),
|
|
531
|
+
};
|
|
532
|
+
const text = formatExec(r, seconds, clamped, workspace) + lowered + (reported ? "" : denialHint.full);
|
|
522
533
|
return {
|
|
523
534
|
content: [{ type: "text", text: withNotices(notices, text) }],
|
|
524
535
|
isError: r.timedOut || r.exitCode === null,
|
|
@@ -535,7 +546,7 @@ export function sandboxBashTool(deps) {
|
|
|
535
546
|
? display(`命令被中止:${shown}`, `Command stopped: ${shown}`)
|
|
536
547
|
: display(`运行命令(退出码 ${r.exitCode}):${shown}`, `Ran command (exit ${r.exitCode}): ${shown}`),
|
|
537
548
|
// kernel-internal: the pipeline asks the device owner or writes notes (spec §6.2)
|
|
538
|
-
...(
|
|
549
|
+
...(reported && { networkReport: { deviceId, blocked, denialHint } }),
|
|
539
550
|
// kernel-internal: the pipeline writes the display-only `device_code` event (auto mode §6)
|
|
540
551
|
...(loginCode !== null && { loginCode }),
|
|
541
552
|
};
|
|
@@ -330,7 +330,10 @@ export declare function inSandboxPreparation<T>(deps: SandboxToolDeps, ctx: Buil
|
|
|
330
330
|
export declare function recordManagedDevicePaths(deps: {
|
|
331
331
|
managedDeviceContext: ManagedDeviceContextPort;
|
|
332
332
|
}, ctx: BuiltinCallContext, held: Readonly<HeldDeviceContextEvidence>, signal: AbortSignal): Promise<void>;
|
|
333
|
-
/**
|
|
333
|
+
/**
|
|
334
|
+
* The conversation whose device a call uses (sub-agents spec §10.1, agent map spec §6): the tree
|
|
335
|
+
* root for a sub-agent's call at any depth, the conversation itself otherwise.
|
|
336
|
+
*/
|
|
334
337
|
export declare const sandboxConversationOf: (ctx: BuiltinCallContext) => string;
|
|
335
338
|
/**
|
|
336
339
|
* Runs `fn` under the per-path lease of `path` in the session's device (spec §10.4: the
|
|
@@ -593,8 +593,11 @@ export async function recordManagedDevicePaths(deps, ctx, held, signal) {
|
|
|
593
593
|
accountId: ctx.accountId,
|
|
594
594
|
}, held, signal);
|
|
595
595
|
}
|
|
596
|
-
/**
|
|
597
|
-
|
|
596
|
+
/**
|
|
597
|
+
* The conversation whose device a call uses (sub-agents spec §10.1, agent map spec §6): the tree
|
|
598
|
+
* root for a sub-agent's call at any depth, the conversation itself otherwise.
|
|
599
|
+
*/
|
|
600
|
+
export const sandboxConversationOf = (ctx) => ctx.rootConversationId;
|
|
598
601
|
/**
|
|
599
602
|
* Runs `fn` under the per-path lease of `path` in the session's device (spec §10.4: the
|
|
600
603
|
* kernel's own read-modify-write of one file never loses another holder's update, from any
|
|
@@ -14,7 +14,8 @@ const SPEC = {
|
|
|
14
14
|
'locate files by name, e.g. pattern "**/*.py" for all Python files. The pattern is matched ' +
|
|
15
15
|
"against paths relative to path (default: the workspace directory): * matches within one directory, ** " +
|
|
16
16
|
"matches across directories, ? matches one character, {a,b} matches either. Returns absolute " +
|
|
17
|
-
"paths sorted by name, up to 1000. Skips .git
|
|
17
|
+
"paths sorted by name, up to 1000. Skips version control (.git, .hg, .svn, .jj), " +
|
|
18
|
+
"node_modules and .cache directories and, where the " +
|
|
18
19
|
"device supports it, files ignored by .gitignore, .ignore or .rgignore files; to list files " +
|
|
19
20
|
"inside a skipped directory, pass that directory as path. To search file contents, use Grep. " +
|
|
20
21
|
"In auto mode paths may be anywhere on the machine.",
|
|
@@ -18,7 +18,8 @@ const SPEC = {
|
|
|
18
18
|
'syntax as in grep -E, e.g. "log.*Error" or "def (load|save)"; no backreferences or ' +
|
|
19
19
|
"look-around). Use it to find where something is defined or mentioned. Searches path (a " +
|
|
20
20
|
"file, or a directory recursively; default: the workspace directory). A directory search " +
|
|
21
|
-
"skips binary files, .git
|
|
21
|
+
"skips binary files, version control (.git, .hg, .svn, .jj), node_modules and .cache " +
|
|
22
|
+
"directories and, where the device supports it, " +
|
|
22
23
|
"files ignored by .gitignore, .ignore or .rgignore files; to search inside a skipped " +
|
|
23
24
|
"directory, pass that directory or a file in it as path. glob limits " +
|
|
24
25
|
'the files searched by name, e.g. "*.py". output_mode picks what comes back: ' +
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Directories `Grep` and `Glob` never walk into, whatever the ignore files say: version control
|
|
3
|
-
* metadata
|
|
4
|
-
*
|
|
3
|
+
* metadata, installed packages and tool caches (`.cache`: a docker device's HOME is the workspace,
|
|
4
|
+
* so a search of the workspace outside a repository would walk its caches). A path given
|
|
5
|
+
* explicitly is still searched (only directories met while walking are skipped).
|
|
5
6
|
*/
|
|
6
|
-
export declare const ALWAYS_SKIPPED_DIRS: readonly [".git", ".hg", ".svn", ".jj", "node_modules"];
|
|
7
|
+
export declare const ALWAYS_SKIPPED_DIRS: readonly [".git", ".hg", ".svn", ".jj", "node_modules", ".cache"];
|
|
7
8
|
export type GrepMode = "content" | "files_with_matches" | "count";
|
|
8
9
|
export interface GrepCommandOptions {
|
|
9
10
|
mode: GrepMode;
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { shellQuote } from "./common.js";
|
|
2
2
|
/**
|
|
3
3
|
* Directories `Grep` and `Glob` never walk into, whatever the ignore files say: version control
|
|
4
|
-
* metadata
|
|
5
|
-
*
|
|
4
|
+
* metadata, installed packages and tool caches (`.cache`: a docker device's HOME is the workspace,
|
|
5
|
+
* so a search of the workspace outside a repository would walk its caches). A path given
|
|
6
|
+
* explicitly is still searched (only directories met while walking are skipped).
|
|
6
7
|
*/
|
|
7
|
-
export const ALWAYS_SKIPPED_DIRS = [
|
|
8
|
+
export const ALWAYS_SKIPPED_DIRS = [
|
|
9
|
+
".git",
|
|
10
|
+
".hg",
|
|
11
|
+
".svn",
|
|
12
|
+
".jj",
|
|
13
|
+
"node_modules",
|
|
14
|
+
".cache",
|
|
15
|
+
];
|
|
8
16
|
/**
|
|
9
17
|
* Runs `rg` when the device has it, else `fallback`, in one shell command (no extra round trip
|
|
10
18
|
* to find out). Both branches print the same format, so the caller parses either the same way.
|
|
@@ -203,7 +203,30 @@ export interface NetworkPlan {
|
|
|
203
203
|
notes: string[];
|
|
204
204
|
/** `missing_grants` keys of an unattended run (`network:<host>`). */
|
|
205
205
|
missingGrants: string[];
|
|
206
|
+
/**
|
|
207
|
+
* Whether `notes` hold a private-address note ({@link addressEscalationNote} or
|
|
208
|
+
* {@link addressLayerNote}) and what it says about running outside the sandbox: `remedy` when it
|
|
209
|
+
* also says how (retry escalated) or why that is not possible here, `fact` when it only says
|
|
210
|
+
* that a command run outside the sandbox reaches the address. Absent: no address note.
|
|
211
|
+
*/
|
|
212
|
+
addressNote?: "remedy" | "fact";
|
|
206
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* The two forms of the `Bash` tool's sandbox denial line for a command whose refused hosts become
|
|
216
|
+
* network notes (kernel-internal, `BuiltinResult.networkReport.denialHint`): `full` when no note
|
|
217
|
+
* covers a private address, `afterAddressFact` (without the closed-address lead the note already
|
|
218
|
+
* states) after an address note of kind `fact`.
|
|
219
|
+
*/
|
|
220
|
+
export interface DenialHint {
|
|
221
|
+
full: string;
|
|
222
|
+
afterAddressFact: string;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* The sandbox denial line a command result keeps beside its network notes: one instruction about
|
|
226
|
+
* running outside the sandbox, never two. An address note that says how (or why not) replaces the
|
|
227
|
+
* line; one that states only the fact keeps the line's retry part; without one the line is whole.
|
|
228
|
+
*/
|
|
229
|
+
export declare function denialHintFor(hint: DenialHint | undefined, addressNote: NetworkPlan["addressNote"]): string;
|
|
207
230
|
/** The hosts of a `network_blocked` event: valid, deduplicated, at most {@link NETWORK_ASK_MAX_HOSTS}. */
|
|
208
231
|
export declare function blockedEventHosts(blocked: readonly NetworkBlockedHost[]): NetworkBlockedHost[];
|
|
209
232
|
/**
|
|
@@ -194,6 +194,16 @@ export const unavailableHostNote = (host, why) => `[network] ${host} was blocked
|
|
|
194
194
|
export const taskGrantIgnoredNote = (hosts) => `${blockedLead(hosts)} The scheduled task approves ${pron(hosts)}, but this device did not apply the task's network grant. The device owner can add ${pron(hosts)} to the device's network list on its page. Continue without ${pron(hosts)}.`;
|
|
195
195
|
/** An unattended run in `fail` mode (spec §8.3): no ask, the creator can add a task grant. */
|
|
196
196
|
export const unattendedNetworkNote = (hosts) => `[network] ${list(hosts)} ${one(hosts) ? "is" : "are"} blocked on this device and this scheduled run cannot ask for network access. The task's owner can add ${pron(hosts)} to the task's approved domains. Continue without ${pron(hosts)}.`;
|
|
197
|
+
/**
|
|
198
|
+
* The sandbox denial line a command result keeps beside its network notes: one instruction about
|
|
199
|
+
* running outside the sandbox, never two. An address note that says how (or why not) replaces the
|
|
200
|
+
* line; one that states only the fact keeps the line's retry part; without one the line is whole.
|
|
201
|
+
*/
|
|
202
|
+
export function denialHintFor(hint, addressNote) {
|
|
203
|
+
if (hint === undefined || addressNote === "remedy")
|
|
204
|
+
return "";
|
|
205
|
+
return addressNote === "fact" ? hint.afterAddressFact : hint.full;
|
|
206
|
+
}
|
|
197
207
|
/** Hosts in first-seen order, deduplicated, lower-cased, trailing dot dropped. */
|
|
198
208
|
function hostsOf(blocked) {
|
|
199
209
|
const seen = new Set();
|
|
@@ -325,11 +335,20 @@ export function planNetworkAsk(blocked, run, ctx) {
|
|
|
325
335
|
notes.push(orgLayerNote(org));
|
|
326
336
|
if (platform.length > 0)
|
|
327
337
|
notes.push(platformCeilingNote(platform));
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
338
|
+
let addressNote;
|
|
339
|
+
if (address.length > 0) {
|
|
340
|
+
const why = ctx.unattended != null ? ESCALATION_UNATTENDED_WHY : ctx.escalationRefusal;
|
|
341
|
+
const escalate = ctx.escalation === true && ctx.unattended == null;
|
|
342
|
+
notes.push(escalate ? addressEscalationNote(address) : addressLayerNote(address, why));
|
|
343
|
+
addressNote = escalate || why !== undefined ? "remedy" : "fact";
|
|
344
|
+
}
|
|
345
|
+
return {
|
|
346
|
+
ask,
|
|
347
|
+
...(ask.length > 0 && offer !== null && { offer }),
|
|
348
|
+
notes,
|
|
349
|
+
missingGrants,
|
|
350
|
+
...(addressNote !== undefined && { addressNote }),
|
|
351
|
+
};
|
|
333
352
|
}
|
|
334
353
|
/**
|
|
335
354
|
* Why a host is not asked about where nothing can be offered (a device with no own list whose
|
package/dist/tools/pipeline.d.ts
CHANGED
|
@@ -720,7 +720,7 @@ export declare class ToolPipeline {
|
|
|
720
720
|
* be an `inline` ui contribution of the same extension and `key` at most 200 characters; anything
|
|
721
721
|
* else is dropped with a warning and the result is written as usual. `placement` is kept when
|
|
722
722
|
* `pinned` or `process` (an unknown value means `output`); `text` only with `pinned`, 1 to
|
|
723
|
-
* {@link CARD_TEXT_MAX} characters.
|
|
723
|
+
* {@link CARD_TEXT_MAX} characters; `badge` only with `pinned`, 1 to {@link CARD_BADGE_MAX}.
|
|
724
724
|
*/
|
|
725
725
|
private cardOf;
|
|
726
726
|
/**
|
package/dist/tools/pipeline.js
CHANGED
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
|
-
import { CARD_TEXT_MAX, DeviceAccessError, ToolError, validateInputForm, validateToolDisplay, } from "@capybara-hq/plugin-sdk";
|
|
10
|
+
import { CARD_BADGE_MAX, CARD_TEXT_MAX, DeviceAccessError, ToolError, validateInputForm, validateToolDisplay, } from "@capybara-hq/plugin-sdk";
|
|
11
11
|
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
13
|
import { backgroundMaxSeconds } from "../background/launch.js";
|
|
@@ -67,7 +67,7 @@ import { canonicalJson } from "./canonical-json.js";
|
|
|
67
67
|
import { CredentialMissing, Credentials } from "./credentials.js";
|
|
68
68
|
import { ToolDrift } from "./drift.js";
|
|
69
69
|
import { ElicitationSession } from "./elicitation.js";
|
|
70
|
-
import { addressEscalationHint, blockedEventHosts, clipKept, deviceAskTerms, NETWORK_ASK_KEPT_MAX_BYTES, networkBlockedIdemKey, planNetworkAsk, serviceAskedNote, serviceAskTerms, settledNetworkNotes, withNetworkNotes, } from "./network-asks.js";
|
|
70
|
+
import { addressEscalationHint, blockedEventHosts, clipKept, denialHintFor, deviceAskTerms, NETWORK_ASK_KEPT_MAX_BYTES, networkBlockedIdemKey, planNetworkAsk, serviceAskedNote, serviceAskTerms, settledNetworkNotes, withNetworkNotes, } from "./network-asks.js";
|
|
71
71
|
import { OrgToolSwitches, toolTurnedOffReason } from "./org-tool-switches.js";
|
|
72
72
|
import { renderResult, resolveOutputRefs, spillIfLarge, ToolOutputs } from "./outputs.js";
|
|
73
73
|
import { createDecidePolicy } from "./policy.js";
|
|
@@ -531,6 +531,15 @@ function networkReportOf(result) {
|
|
|
531
531
|
["device", "org", "address", "unknown"].includes(b.layer));
|
|
532
532
|
return blocked.length === 0 ? undefined : { deviceId: r.deviceId, blocked };
|
|
533
533
|
}
|
|
534
|
+
/** A builtin result's kernel-internal sandbox denial line (`BuiltinResult.networkReport.denialHint`). */
|
|
535
|
+
function denialHintOf(result) {
|
|
536
|
+
const h = result?.networkReport
|
|
537
|
+
?.denialHint;
|
|
538
|
+
if (h === undefined || typeof h.full !== "string" || typeof h.afterAddressFact !== "string") {
|
|
539
|
+
return undefined;
|
|
540
|
+
}
|
|
541
|
+
return { full: h.full, afterAddressFact: h.afterAddressFact };
|
|
542
|
+
}
|
|
534
543
|
/**
|
|
535
544
|
* A kernel-internal device code (see `BuiltinResult.loginCode` and `KeptToolResult.loginCode`):
|
|
536
545
|
* the shape is checked again here so a malformed value never reaches the log (the event schema
|
|
@@ -925,6 +934,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
925
934
|
accountId: ctx.accountId,
|
|
926
935
|
agentId: ctx.agentId,
|
|
927
936
|
conversationId: ctx.conversationId,
|
|
937
|
+
rootConversationId: ctx.parent?.rootConversationId ?? ctx.conversationId,
|
|
928
938
|
runId: ctx.runId,
|
|
929
939
|
callId: call.id,
|
|
930
940
|
rawInput: call.input,
|
|
@@ -1384,6 +1394,11 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1384
1394
|
const commandReport = outcome.kind === "result" && tool.source.kind === "builtin"
|
|
1385
1395
|
? networkReportOf(outcome.result)
|
|
1386
1396
|
: undefined;
|
|
1397
|
+
// the denial line `Bash` left out of its content: appended here in the form that goes with
|
|
1398
|
+
// the network notes (`denialHintFor`), after the output (and its truncation line)
|
|
1399
|
+
const denialHint = outcome.kind === "result" && tool.source.kind === "builtin"
|
|
1400
|
+
? denialHintOf(outcome.result)
|
|
1401
|
+
: undefined;
|
|
1387
1402
|
// a device service's refusals reported in the call scope (browser use spec §7.1), any source:
|
|
1388
1403
|
// asked as "always" only, the call runs again once approved
|
|
1389
1404
|
// a report about another device than the conversation's is ignored: only the device the call
|
|
@@ -1417,6 +1432,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1417
1432
|
// carried into the kept result so a resumed run writes the event too (it was written
|
|
1418
1433
|
// with `network_blocked` below when the ask was created)
|
|
1419
1434
|
...(loginCode !== undefined && { loginCode }),
|
|
1435
|
+
...(denialHint !== undefined && { denialHint }),
|
|
1420
1436
|
}, reviewedRoots.escalation, reviewedRoots.escalationRefusal, scoped === undefined
|
|
1421
1437
|
? undefined
|
|
1422
1438
|
: {
|
|
@@ -1432,8 +1448,10 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1432
1448
|
}
|
|
1433
1449
|
if (handled.event !== null)
|
|
1434
1450
|
pre.push(handled.event);
|
|
1435
|
-
content = withNetworkNotes(content, handled.notes);
|
|
1451
|
+
content = withNetworkNotes(content + denialHintFor(denialHint, handled.addressNote), handled.notes);
|
|
1436
1452
|
}
|
|
1453
|
+
else
|
|
1454
|
+
content += denialHintFor(denialHint, undefined);
|
|
1437
1455
|
await this.writeResult(ctx, call.id, outKey, {
|
|
1438
1456
|
content,
|
|
1439
1457
|
isError: rendered.isError,
|
|
@@ -2279,8 +2297,9 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2279
2297
|
}
|
|
2280
2298
|
}
|
|
2281
2299
|
const offer = plan.offer;
|
|
2300
|
+
const addressNote = plan.addressNote;
|
|
2282
2301
|
if (plan.ask.length === 0 || offer === undefined)
|
|
2283
|
-
return { kind: "write", event, notes: plan.notes };
|
|
2302
|
+
return { kind: "write", event, notes: plan.notes, addressNote };
|
|
2284
2303
|
// one ask per call: a service call that ran again after its ask is not asked again; only a
|
|
2285
2304
|
// would-be ask is replaced, the plan's other notes (a host on the list, not yet applied) stay
|
|
2286
2305
|
if (service !== undefined &&
|
|
@@ -2289,6 +2308,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2289
2308
|
kind: "write",
|
|
2290
2309
|
event,
|
|
2291
2310
|
notes: [...plan.notes, serviceAskedNote(plan.ask.map((h) => h.host))],
|
|
2311
|
+
addressNote,
|
|
2292
2312
|
};
|
|
2293
2313
|
}
|
|
2294
2314
|
// the device's owner is the only person who may decide (spec §5.2)
|
|
@@ -2300,7 +2320,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2300
2320
|
.where("deleted_at", "is", null)
|
|
2301
2321
|
.executeTakeFirst();
|
|
2302
2322
|
if (owner === undefined)
|
|
2303
|
-
return { kind: "write", event, notes: plan.notes };
|
|
2323
|
+
return { kind: "write", event, notes: plan.notes, addressNote };
|
|
2304
2324
|
let { content, outputId } = result;
|
|
2305
2325
|
if (Buffer.byteLength(content, "utf8") > NETWORK_ASK_KEPT_MAX_BYTES && outputId === undefined) {
|
|
2306
2326
|
// output under the spill threshold but over what an ask keeps: archive it after all
|
|
@@ -2313,10 +2333,10 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2313
2333
|
content = spilled.content;
|
|
2314
2334
|
outputId = spilled.outputId;
|
|
2315
2335
|
}
|
|
2316
|
-
const { text: _text, ...rest } = result;
|
|
2336
|
+
const { text: _text, denialHint, ...rest } = result;
|
|
2317
2337
|
const kept = {
|
|
2318
2338
|
...rest,
|
|
2319
|
-
content: withNetworkNotes(clipKept(content), plan.notes),
|
|
2339
|
+
content: withNetworkNotes(clipKept(content) + denialHintFor(denialHint, addressNote), plan.notes),
|
|
2320
2340
|
...(outputId !== undefined && { outputId }),
|
|
2321
2341
|
};
|
|
2322
2342
|
// the command ran: the call's display-only events (a `device_code`) and network_blocked with
|
|
@@ -2615,9 +2635,6 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2615
2635
|
reviewed?.escalationRefusal !== undefined && {
|
|
2616
2636
|
sandboxEscalationRefusal: reviewed.escalationRefusal,
|
|
2617
2637
|
}),
|
|
2618
|
-
// a sub-agent works in its root conversation's sandbox (spec §10.1, at every depth)
|
|
2619
|
-
...(tool.source.kind === "builtin" &&
|
|
2620
|
-
ctx.parent !== undefined && { sandboxConversationId: ctx.parent.rootConversationId }),
|
|
2621
2638
|
...(tool.source.kind === "builtin" &&
|
|
2622
2639
|
ctx.parent !== undefined && { parentRunId: ctx.parent.runId }),
|
|
2623
2640
|
...(tool.source.kind === "builtin" &&
|
|
@@ -2990,7 +3007,7 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2990
3007
|
* be an `inline` ui contribution of the same extension and `key` at most 200 characters; anything
|
|
2991
3008
|
* else is dropped with a warning and the result is written as usual. `placement` is kept when
|
|
2992
3009
|
* `pinned` or `process` (an unknown value means `output`); `text` only with `pinned`, 1 to
|
|
2993
|
-
* {@link CARD_TEXT_MAX} characters.
|
|
3010
|
+
* {@link CARD_TEXT_MAX} characters; `badge` only with `pinned`, 1 to {@link CARD_BADGE_MAX}.
|
|
2994
3011
|
*/
|
|
2995
3012
|
cardOf(result, plugin, toolKey) {
|
|
2996
3013
|
const c = result?.card;
|
|
@@ -3032,12 +3049,25 @@ let ToolPipeline = class ToolPipeline {
|
|
|
3032
3049
|
else
|
|
3033
3050
|
text = x.text;
|
|
3034
3051
|
}
|
|
3052
|
+
// badge: only a pinned card carries it, at most CARD_BADGE_MAX characters
|
|
3053
|
+
let badge;
|
|
3054
|
+
if (x.badge !== undefined) {
|
|
3055
|
+
if (placement !== "pinned") {
|
|
3056
|
+
this.deps.log.warn("tool returned an inline card badge without a pinned placement; badge dropped", { toolKey });
|
|
3057
|
+
}
|
|
3058
|
+
else if (typeof x.badge !== "string" || x.badge === "" || x.badge.length > CARD_BADGE_MAX) {
|
|
3059
|
+
this.deps.log.warn("tool returned an inline card badge that is empty or too long; badge dropped", { toolKey });
|
|
3060
|
+
}
|
|
3061
|
+
else
|
|
3062
|
+
badge = x.badge;
|
|
3063
|
+
}
|
|
3035
3064
|
return {
|
|
3036
3065
|
plugin,
|
|
3037
3066
|
view: x.view,
|
|
3038
3067
|
...(x.key !== undefined && { key: x.key }),
|
|
3039
3068
|
...(placement !== undefined && { placement }),
|
|
3040
3069
|
...(text !== undefined && { text }),
|
|
3070
|
+
...(badge !== undefined && { badge }),
|
|
3041
3071
|
};
|
|
3042
3072
|
}
|
|
3043
3073
|
/**
|
package/dist/tools/registry.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type { ConversationKindForHooks } from "../runtime/hook-calls.js";
|
|
|
13
13
|
import type { ExecutionClaim } from "../runtime/run-execution.js";
|
|
14
14
|
import { BuiltinTools } from "./builtins/builtin-tools.js";
|
|
15
15
|
import { Credentials } from "./credentials.js";
|
|
16
|
+
import type { DenialHint } from "./network-asks.js";
|
|
16
17
|
import { OrgToolSwitches } from "./org-tool-switches.js";
|
|
17
18
|
export { BUILTIN_TOOL_NAMES } from "./builtin-names.js";
|
|
18
19
|
export { canonicalJson } from "./canonical-json.js";
|
|
@@ -50,12 +51,6 @@ export interface BuiltinCallContext extends ToolCallContext {
|
|
|
50
51
|
* only by `sandbox.limits.maxCommandSeconds` and the tool timeouts.
|
|
51
52
|
*/
|
|
52
53
|
runDeadline?: number;
|
|
53
|
-
/**
|
|
54
|
-
* The conversation whose sandbox this call uses (sub-agents spec §10.1, agent map spec §6): the
|
|
55
|
-
* root conversation for a sub-agent's call at any depth, the conversation itself otherwise (the
|
|
56
|
-
* default when absent).
|
|
57
|
-
*/
|
|
58
|
-
sandboxConversationId?: string;
|
|
59
54
|
/**
|
|
60
55
|
* The working root the command review judged this call against (project root spec §4.3): a
|
|
61
56
|
* sandbox tool runs there instead of reading the working root again, so it executes exactly what
|
|
@@ -141,10 +136,13 @@ export type BuiltinResult = (ToolResult & {
|
|
|
141
136
|
* Kernel-internal (never written to the log or sent to the model): the network hosts a
|
|
142
137
|
* foreground command on a device was refused (`Bash`; network ask-to-allow spec §6.2). The
|
|
143
138
|
* pipeline turns it into `network_blocked`, an ask to the device owner or notes.
|
|
139
|
+
* `denialHint`: the sandbox denial line, left out of the content; the pipeline appends the
|
|
140
|
+
* form that goes with its notes (`denialHintFor`).
|
|
144
141
|
*/
|
|
145
142
|
networkReport?: {
|
|
146
143
|
deviceId: string;
|
|
147
144
|
blocked: NetworkBlockedHost[];
|
|
145
|
+
denialHint?: DenialHint;
|
|
148
146
|
};
|
|
149
147
|
/**
|
|
150
148
|
* Kernel-internal (never written to the log or sent to the model): `gh auth login --web`'s
|
|
@@ -197,6 +195,8 @@ export interface CallPolicyContext {
|
|
|
197
195
|
accountId: string;
|
|
198
196
|
agentId: string;
|
|
199
197
|
conversationId: string;
|
|
198
|
+
/** The root of the conversation tree; absent outside the pipeline (then the conversation itself). */
|
|
199
|
+
rootConversationId?: string;
|
|
200
200
|
/** Null outside a run (a builtin called directly). */
|
|
201
201
|
runId: string | null;
|
|
202
202
|
/** The tool call being decided (a call id is unique within its run). Absent outside the pipeline. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/kernel",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.99",
|
|
4
4
|
"description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"yaml": "^2.9.1",
|
|
67
67
|
"yauzl": "3.4.0",
|
|
68
68
|
"zod": "^4.6.7",
|
|
69
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
69
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.82"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
72
|
"@langchain/langgraph-checkpoint-validation": "^1.2.0",
|