@capybara-hq/kernel 0.1.0-rc.8 → 0.1.0-rc.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/dist/background/finish.js +2 -1
- package/dist/background/launch.d.ts +13 -7
- package/dist/background/launch.js +15 -8
- package/dist/background/poll.job.d.ts +1 -1
- package/dist/background/poll.job.js +8 -3
- package/dist/background/session.d.ts +2 -2
- package/dist/background/session.js +3 -2
- package/dist/background/status.d.ts +1 -1
- package/dist/background/status.js +1 -1
- package/dist/background/stop.js +4 -3
- package/dist/background/store.d.ts +6 -1
- package/dist/background/store.js +5 -1
- package/dist/background/tasks.service.d.ts +1 -1
- package/dist/background/tasks.service.js +4 -4
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/config/docs.js +2 -0
- package/dist/config/schema.d.ts +7 -0
- package/dist/config/schema.js +45 -0
- package/dist/conversations/event-log.d.ts +4 -3
- package/dist/conversations/event-log.js +4 -3
- package/dist/conversations/events.d.ts +9 -0
- package/dist/conversations/events.js +14 -0
- package/dist/db/kernel-schema.d.ts +26 -1
- package/dist/devices/device-auth.controller.d.ts +42 -0
- package/dist/devices/device-auth.controller.js +116 -0
- package/dist/devices/device-auth.d.ts +119 -0
- package/dist/devices/device-auth.js +403 -0
- package/dist/devices/device-auth.module.d.ts +7 -0
- package/dist/devices/device-auth.module.js +25 -0
- package/dist/devices/device-gateway.d.ts +128 -0
- package/dist/devices/device-gateway.js +530 -0
- package/dist/devices/device-provider.d.ts +89 -0
- package/dist/devices/device-provider.js +151 -0
- package/dist/devices/device-routes.d.ts +36 -0
- package/dist/devices/device-routes.js +90 -0
- package/dist/devices/devices.module.d.ts +16 -0
- package/dist/devices/devices.module.js +44 -0
- package/dist/devices/dto.d.ts +66 -0
- package/dist/devices/dto.js +44 -0
- package/dist/devices/keys.d.ts +25 -0
- package/dist/devices/keys.js +25 -0
- package/dist/devices/machines.d.ts +106 -0
- package/dist/devices/machines.js +301 -0
- package/dist/devices/relay.d.ts +100 -0
- package/dist/devices/relay.js +373 -0
- package/dist/devices/targets.d.ts +28 -0
- package/dist/devices/targets.js +73 -0
- package/dist/environments/access.d.ts +11 -6
- package/dist/environments/access.js +23 -8
- package/dist/environments/conversation-environments.d.ts +20 -6
- package/dist/environments/conversation-environments.js +70 -9
- package/dist/environments/environments.controller.d.ts +4 -1
- package/dist/environments/environments.controller.js +15 -1
- package/dist/environments/environments.module.js +3 -1
- package/dist/environments/environments.service.d.ts +54 -7
- package/dist/environments/environments.service.js +104 -20
- package/dist/environments/legacy-cleanup.job.d.ts +1 -1
- package/dist/environments/legacy-cleanup.job.js +4 -4
- package/dist/errors.d.ts +24 -0
- package/dist/errors.js +24 -0
- package/dist/evals/recorded-tools.d.ts +9 -0
- package/dist/evals/recorded-tools.js +27 -0
- package/dist/http/api.module.js +4 -0
- package/dist/http/gateway-routes.d.ts +7 -3
- package/dist/http/gateway-routes.js +6 -3
- package/dist/infra/config/kernel-config.service.js +2 -0
- package/dist/infra/throttler/named-throttlers.d.ts +5 -0
- package/dist/infra/throttler/named-throttlers.js +38 -0
- package/dist/kernel.module.js +3 -0
- package/dist/lifecycle/kernel-lifecycle.js +5 -0
- package/dist/platform/exclusions.js +33 -0
- package/dist/platform/ops/environments.ops.js +21 -3
- package/dist/roles/gateway-role.d.ts +14 -3
- package/dist/roles/gateway-role.js +25 -5
- package/dist/roles/gateway.module.d.ts +2 -1
- package/dist/roles/gateway.module.js +6 -3
- package/dist/runtime/context/build.d.ts +2 -0
- package/dist/runtime/context/build.js +14 -0
- package/dist/runtime/context/compaction.js +1 -0
- package/dist/runtime/context/environment-paths.d.ts +40 -0
- package/dist/runtime/context/environment-paths.js +48 -0
- package/dist/runtime/model-call.js +2 -0
- package/dist/sandbox/providers.d.ts +29 -7
- package/dist/sandbox/providers.js +43 -8
- package/dist/sandbox/sandbox.service.d.ts +70 -18
- package/dist/sandbox/sandbox.service.js +176 -59
- package/dist/tools/builtins/sandbox/bash.d.ts +2 -2
- package/dist/tools/builtins/sandbox/bash.js +39 -27
- package/dist/tools/builtins/sandbox/common.d.ts +60 -25
- package/dist/tools/builtins/sandbox/common.js +121 -30
- package/dist/tools/builtins/sandbox/deliver.js +9 -6
- package/dist/tools/builtins/sandbox/edit.js +40 -37
- package/dist/tools/builtins/sandbox/glob.js +13 -8
- package/dist/tools/builtins/sandbox/grep.js +10 -6
- package/dist/tools/builtins/sandbox/index.d.ts +6 -4
- package/dist/tools/builtins/sandbox/index.js +6 -4
- package/dist/tools/builtins/sandbox/read.js +9 -6
- package/dist/tools/builtins/sandbox/task-output.d.ts +7 -3
- package/dist/tools/builtins/sandbox/task-output.js +14 -10
- package/dist/tools/builtins/sandbox/task-stop.js +3 -3
- package/dist/tools/builtins/sandbox/write.js +33 -30
- package/dist/tools/builtins/skill-load.d.ts +8 -5
- package/dist/tools/builtins/skill-load.js +21 -15
- package/dist/tools/builtins/skill-write.js +2 -2
- package/dist/tools/pipeline.js +2 -0
- package/dist/tools/registry.d.ts +21 -4
- package/dist/tools/registry.js +10 -2
- package/package.json +5 -2
- package/src/migrations/0093_connected_environments.sql +37 -0
- package/src/migrations/0094_environment_paths_idx.sql +7 -0
package/dist/tools/registry.d.ts
CHANGED
|
@@ -12,6 +12,18 @@ import { BuiltinTools } from "./builtins/builtin-tools.js";
|
|
|
12
12
|
import { OrgToolSwitches } from "./org-tool-switches.js";
|
|
13
13
|
export { BUILTIN_TOOL_NAMES } from "./builtin-names.js";
|
|
14
14
|
export { canonicalJson } from "./canonical-json.js";
|
|
15
|
+
/**
|
|
16
|
+
* What a tool's `unavailable` is asked with: the org, and for a run's listing the root
|
|
17
|
+
* conversation (`conversationId`; the sandbox tools follow its environment, ruling R8), whether
|
|
18
|
+
* the run is an eval replay (`replay`: its tool calls are never executed), and a `memo` shared by
|
|
19
|
+
* the tools of one listing (one answer per question per listing).
|
|
20
|
+
*/
|
|
21
|
+
export interface ToolListingScope {
|
|
22
|
+
orgId: string;
|
|
23
|
+
conversationId?: string;
|
|
24
|
+
replay?: boolean;
|
|
25
|
+
memo?: Map<string, unknown>;
|
|
26
|
+
}
|
|
15
27
|
/** A problem of a saved definition's `disabledTools` (`path` is `disabledTools.<i>`). */
|
|
16
28
|
export interface ToolRefIssue {
|
|
17
29
|
path: string;
|
|
@@ -82,11 +94,9 @@ export interface BuiltinTool {
|
|
|
82
94
|
/**
|
|
83
95
|
* The factual reason this tool is unavailable for the org right now (English, actionable; it goes
|
|
84
96
|
* into the "tool unavailable" reminder), or null when it is available. May be async (e.g. a
|
|
85
|
-
* per-org extension-point default).
|
|
97
|
+
* per-org extension-point default). See {@link ToolListingScope} for what a listing passes.
|
|
86
98
|
*/
|
|
87
|
-
unavailable?: (ctx:
|
|
88
|
-
orgId: string;
|
|
89
|
-
}) => Promise<string | null> | string | null;
|
|
99
|
+
unavailable?: (ctx: ToolListingScope) => Promise<string | null> | string | null;
|
|
90
100
|
/**
|
|
91
101
|
* A policy key derived from the validated input (Platform tool spec §6.2), or null to use the
|
|
92
102
|
* tool key. With a key, agent and parent policies, grants and approvals are keyed by it (an
|
|
@@ -334,6 +344,13 @@ export declare class ToolRegistry {
|
|
|
334
344
|
* it reaches its parent with neither tool (`SendMessage` only to its own sub-agents).
|
|
335
345
|
*/
|
|
336
346
|
forkChild?: boolean;
|
|
347
|
+
/**
|
|
348
|
+
* The root conversation of the run (a sub-agent's tree root): tools whose availability
|
|
349
|
+
* depends on the conversation's environment (the sandbox tools) are listed by it.
|
|
350
|
+
*/
|
|
351
|
+
sandboxConversationId?: string;
|
|
352
|
+
/** An eval replay's listing: its calls are never executed (the sandbox tools are listed). */
|
|
353
|
+
replay?: boolean;
|
|
337
354
|
}): Promise<AgentTools>;
|
|
338
355
|
/** 是否启用 `ToolSearch`(见 {@link forAgent});先比阈值,超过才读组织设置。 */
|
|
339
356
|
private searchActive;
|
package/dist/tools/registry.js
CHANGED
|
@@ -348,6 +348,14 @@ let ToolRegistry = class ToolRegistry {
|
|
|
348
348
|
}
|
|
349
349
|
async resolve(orgId, def) {
|
|
350
350
|
const disabled = def.disabledTools ?? [];
|
|
351
|
+
const scope = {
|
|
352
|
+
orgId,
|
|
353
|
+
...(def.sandboxConversationId !== undefined && {
|
|
354
|
+
conversationId: def.sandboxConversationId,
|
|
355
|
+
}),
|
|
356
|
+
...(def.replay === true && { replay: true }),
|
|
357
|
+
memo: new Map(),
|
|
358
|
+
};
|
|
351
359
|
const tools = [];
|
|
352
360
|
const unavailable = [];
|
|
353
361
|
const hidden = [];
|
|
@@ -373,7 +381,7 @@ let ToolRegistry = class ToolRegistry {
|
|
|
373
381
|
const b = this.builtins.find((x) => x.spec.name === name);
|
|
374
382
|
if (!b)
|
|
375
383
|
continue;
|
|
376
|
-
const why = (await b.unavailable?.(
|
|
384
|
+
const why = (await b.unavailable?.(scope)) ?? null;
|
|
377
385
|
if (why !== null) {
|
|
378
386
|
hidden.push({ ref: name, reason: why });
|
|
379
387
|
continue;
|
|
@@ -392,7 +400,7 @@ let ToolRegistry = class ToolRegistry {
|
|
|
392
400
|
if (name === BUILTIN.Bash) {
|
|
393
401
|
for (const companion of BASH_COMPANION_TOOLS) {
|
|
394
402
|
const c = this.builtins.find((x) => x.spec.name === companion);
|
|
395
|
-
if (c && ((await c.unavailable?.(
|
|
403
|
+
if (c && ((await c.unavailable?.(scope)) ?? null) === null) {
|
|
396
404
|
add(builtinTool(c, c.spec));
|
|
397
405
|
}
|
|
398
406
|
}
|
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.9",
|
|
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": {
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@fastify/cookie": "^11.1.3",
|
|
34
34
|
"@fastify/static": "^9.3.0",
|
|
35
|
+
"@fastify/websocket": "^11.3.7",
|
|
35
36
|
"@langchain/core": "^1.2.18",
|
|
36
37
|
"@langchain/langgraph": "^1.5.1",
|
|
37
38
|
"@langchain/langgraph-checkpoint": "^1.2.0",
|
|
@@ -64,13 +65,15 @@
|
|
|
64
65
|
"yaml": "^2.9.1",
|
|
65
66
|
"yauzl": "3.4.0",
|
|
66
67
|
"zod": "^4.6.7",
|
|
67
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
68
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.6"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
|
70
71
|
"@langchain/langgraph-checkpoint-validation": "^1.2.0",
|
|
71
72
|
"@types/pg": "^8.23.1",
|
|
72
73
|
"@types/semver": "^7.8.0",
|
|
74
|
+
"@types/ws": "^8.18.2",
|
|
73
75
|
"@types/yauzl": "3.4.0",
|
|
76
|
+
"ws": "^8.22.0",
|
|
74
77
|
"@capybara-hq/testing": "0.1.0-rc.9"
|
|
75
78
|
},
|
|
76
79
|
"scripts": {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
-- Environments phase 2 (spec 2026-11-07-environments-design §6, §13): a person's own machine,
|
|
2
|
+
-- connected through the device program, becomes an environment with source 'device'. Expand-only:
|
|
3
|
+
-- the source CHECK list grows and a new table holds the connected machine.
|
|
4
|
+
|
|
5
|
+
-- 0088 left the CHECK unnamed, so Postgres named it environments_source_check; re-add it under
|
|
6
|
+
-- the same name with the longer list.
|
|
7
|
+
ALTER TABLE environments DROP CONSTRAINT IF EXISTS environments_source_check;
|
|
8
|
+
ALTER TABLE environments
|
|
9
|
+
ADD CONSTRAINT environments_source_check CHECK (source IN ('cloud', 'device'));
|
|
10
|
+
|
|
11
|
+
-- The machine connected to a device environment. credential_hash is a hash of the machine's
|
|
12
|
+
-- long-lived credential (cap_dev_...), never the credential itself; revoking a machine sets
|
|
13
|
+
-- revoked_at and keeps the row, so only one unrevoked machine exists per environment.
|
|
14
|
+
-- program_version, mode, roots and session_isolation are what the program reported on its last
|
|
15
|
+
-- connection; last_seen_at is the last time it connected or pinged.
|
|
16
|
+
CREATE TABLE IF NOT EXISTS environment_machines (
|
|
17
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
18
|
+
org_id text NOT NULL REFERENCES orgs(id) ON DELETE CASCADE,
|
|
19
|
+
environment_id text NOT NULL REFERENCES environments(id) ON DELETE CASCADE,
|
|
20
|
+
account_id text NOT NULL,
|
|
21
|
+
credential_hash text NOT NULL UNIQUE,
|
|
22
|
+
name text NOT NULL,
|
|
23
|
+
os text NOT NULL,
|
|
24
|
+
arch text NOT NULL,
|
|
25
|
+
program_version text,
|
|
26
|
+
mode text CHECK (mode IN ('os', 'docker')),
|
|
27
|
+
roots jsonb,
|
|
28
|
+
session_isolation boolean NOT NULL DEFAULT false,
|
|
29
|
+
last_seen_at timestamptz,
|
|
30
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
31
|
+
revoked_at timestamptz
|
|
32
|
+
);
|
|
33
|
+
CREATE UNIQUE INDEX IF NOT EXISTS environment_machines_active_uq
|
|
34
|
+
ON environment_machines (environment_id)
|
|
35
|
+
WHERE revoked_at IS NULL;
|
|
36
|
+
-- The org cascade delete looks rows up by org (as environment_instances_org_idx in 0088).
|
|
37
|
+
CREATE INDEX IF NOT EXISTS environment_machines_org_idx ON environment_machines (org_id);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
-- Environments phase 2 (spec 2026-11-07-environments-design §13.1, ruling R22): every sandbox tool
|
|
2
|
+
-- call reads the conversation's latest environment_paths event; a partial index answers it
|
|
3
|
+
-- without scanning the conversation's events backwards. Not CONCURRENTLY, like the other index
|
|
4
|
+
-- migrations (0025).
|
|
5
|
+
CREATE INDEX IF NOT EXISTS conversation_events_environment_paths_idx
|
|
6
|
+
ON conversation_events (conversation_id, seq)
|
|
7
|
+
WHERE type = 'environment_paths';
|