@capybara-hq/kernel 0.1.0-rc.113 → 0.1.0-rc.114
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/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/actions.js +2 -0
- package/dist/channels/cards.d.ts +4 -3
- package/dist/channels/cards.js +18 -3
- package/dist/channels/phrases.d.ts +15 -0
- package/dist/channels/phrases.js +9 -0
- package/dist/conversations/conversations.service.js +7 -0
- package/dist/conversations/events.d.ts +13 -0
- package/dist/conversations/events.js +24 -3
- package/dist/ctx/create-ctx.d.ts +1 -1
- package/dist/ctx/create-ctx.js +6 -1
- package/dist/db/kernel-schema.d.ts +26 -0
- package/dist/device-access/device-access.service.d.ts +74 -3
- package/dist/device-access/device-access.service.js +221 -7
- package/dist/devices/devices.service.js +3 -0
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +6 -0
- package/dist/extensions/permission-set.d.ts +11 -1
- package/dist/extensions/permission-set.js +15 -1
- package/dist/extensions/permission-view.d.ts +3 -2
- package/dist/extensions/permission-view.js +15 -2
- package/dist/infra/outbox/registry.d.ts +14 -0
- package/dist/infra/outbox/registry.js +14 -0
- package/dist/orgs/offboarding.js +5 -1
- package/dist/roles/worker.module.js +3 -0
- package/dist/runtime/maintenance.d.ts +4 -2
- package/dist/runtime/maintenance.js +14 -4
- package/dist/sandbox/device-sandbox.d.ts +12 -0
- package/dist/sandbox/device-sandbox.js +2 -0
- package/dist/sandbox/device-services.d.ts +42 -2
- package/dist/sandbox/device-services.js +74 -14
- package/dist/sandbox/loopback-expiry.job.d.ts +21 -0
- package/dist/sandbox/loopback-expiry.job.js +50 -0
- package/dist/sandbox/loopback-grant-records.d.ts +143 -0
- package/dist/sandbox/loopback-grant-records.js +239 -0
- package/dist/sandbox/loopback-grants.d.ts +119 -0
- package/dist/sandbox/loopback-grants.js +454 -0
- package/dist/sandbox/loopback-live-ports.d.ts +12 -0
- package/dist/sandbox/loopback-live-ports.js +43 -0
- package/dist/sandbox/permission-call-types.d.ts +3 -2
- package/dist/sandbox/permission-ceiling-writes.js +13 -1
- package/dist/sandbox/permission-facts.d.ts +4 -0
- package/dist/sandbox/permission-facts.js +4 -0
- package/dist/sandbox/review/classifier.d.ts +26 -4
- package/dist/sandbox/review/classifier.js +31 -4
- package/dist/sandbox/review/index.d.ts +3 -3
- package/dist/sandbox/review/index.js +2 -2
- package/dist/sandbox/review/permission-candidate.d.ts +5 -4
- package/dist/sandbox/review/permission-candidate.js +6 -5
- package/dist/sandbox/review/review.service.d.ts +69 -0
- package/dist/sandbox/review/review.service.js +117 -0
- package/dist/sandbox/sandbox.module.d.ts +1 -1
- package/dist/sandbox/sandbox.module.js +13 -2
- package/dist/tools/approvals.service.d.ts +82 -6
- package/dist/tools/approvals.service.js +233 -11
- package/dist/tools/call-scope.d.ts +9 -1
- package/dist/tools/loopback-asks.d.ts +52 -0
- package/dist/tools/loopback-asks.js +70 -0
- package/dist/tools/network-asks.d.ts +2 -1
- package/dist/tools/network-asks.js +10 -5
- package/dist/tools/pipeline.d.ts +59 -3
- package/dist/tools/pipeline.js +403 -40
- package/dist/tools/tools.module.js +3 -0
- package/package.json +2 -2
- package/src/migrations/0199_device_loopback_grants.sql +59 -0
|
@@ -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.90";
|
|
212
212
|
};
|
|
213
213
|
/** Whether this deployment satisfies the entry's `minKernel`. */
|
|
214
214
|
export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
|
package/dist/channels/actions.js
CHANGED
|
@@ -20,6 +20,8 @@ const REPLY_FOR = {
|
|
|
20
20
|
"question.already_answered": "alreadyHandled",
|
|
21
21
|
validation_failed: "invalidAction",
|
|
22
22
|
"approval.scope_not_allowed": "invalidAction",
|
|
23
|
+
// a loopback port the device can no longer open (the ask stays pending; the web says why)
|
|
24
|
+
"approval.loopback_unavailable": "invalidAction",
|
|
23
25
|
// a network ask clicked by someone other than the device's owner
|
|
24
26
|
"approval.not_yours": "cannotHandle",
|
|
25
27
|
// an approval with person fields is approved only on the web (platform web parity spec R5)
|
package/dist/channels/cards.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type ChannelCard, type FormAnswer, type InputForm, type OutboundMessage
|
|
|
2
2
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
3
3
|
import type { FileCardDetail } from "../platform/file-ref.js";
|
|
4
4
|
import type { PermissionEscalation } from "../sandbox/permission-call-types.js";
|
|
5
|
-
import { type ApprovalsService, type ApprovalView, type CommandAskDetail, type CommandNetworkAskDetail, type GitAskView, type ServiceNetworkAskDetail } from "../tools/approvals.service.js";
|
|
5
|
+
import { type ApprovalsService, type ApprovalView, type CommandAskDetail, type CommandNetworkAskDetail, type GitAskView, type LoopbackAskDetail, type ServiceNetworkAskDetail } from "../tools/approvals.service.js";
|
|
6
6
|
import { type ToolInfo } from "../tools/info.js";
|
|
7
7
|
import type { ToolRegistry } from "../tools/registry.js";
|
|
8
8
|
import { type ChannelLocale } from "./phrases.js";
|
|
@@ -66,9 +66,10 @@ export interface NetworkCardText {
|
|
|
66
66
|
scopeLabels: Partial<Record<"once" | "session" | "always", string>>;
|
|
67
67
|
}
|
|
68
68
|
/** What a network ask's card reads: a command's or a device service's view, its `appliesAt` optional. */
|
|
69
|
-
type NetworkCardDetail = (Pick<CommandNetworkAskDetail, "kind" | "hosts" | "command"> & Partial<Pick<CommandNetworkAskDetail, "appliesAt">>) | (Pick<ServiceNetworkAskDetail, "kind" | "hosts" | "url"> & Partial<Pick<ServiceNetworkAskDetail, "appliesAt">>)
|
|
69
|
+
type NetworkCardDetail = (Pick<CommandNetworkAskDetail, "kind" | "hosts" | "command"> & Partial<Pick<CommandNetworkAskDetail, "appliesAt">>) | (Pick<ServiceNetworkAskDetail, "kind" | "hosts" | "url"> & Partial<Pick<ServiceNetworkAskDetail, "appliesAt">>) | Pick<LoopbackAskDetail, "kind" | "port" | "url" | "database">;
|
|
70
70
|
/**
|
|
71
|
-
* A network ask's card text (a
|
|
71
|
+
* A network ask's card text (a loopback port ask's: its port and the session choice; a device
|
|
72
|
+
* service's: browser use spec §7.1, its own title and a note
|
|
72
73
|
* that open network mode stops the asks): the title names the host (or the number of hosts); the preview lists
|
|
73
74
|
* the hosts, then the command clipped to {@link CARD_SUMMARY_MAX}, for several hosts that the
|
|
74
75
|
* decision applies to all of them (an IM card has no per-host choice) and, when `scopes` offers
|
package/dist/channels/cards.js
CHANGED
|
@@ -197,7 +197,8 @@ async function displayName(db, accountId) {
|
|
|
197
197
|
return r?.display_name || undefined;
|
|
198
198
|
}
|
|
199
199
|
/**
|
|
200
|
-
* A network ask's card text (a
|
|
200
|
+
* A network ask's card text (a loopback port ask's: its port and the session choice; a device
|
|
201
|
+
* service's: browser use spec §7.1, its own title and a note
|
|
201
202
|
* that open network mode stops the asks): the title names the host (or the number of hosts); the preview lists
|
|
202
203
|
* the hosts, then the command clipped to {@link CARD_SUMMARY_MAX}, for several hosts that the
|
|
203
204
|
* decision applies to all of them (an IM card has no per-host choice) and, when `scopes` offers
|
|
@@ -206,6 +207,18 @@ async function displayName(db, accountId) {
|
|
|
206
207
|
* web.
|
|
207
208
|
*/
|
|
208
209
|
export function networkCardText(detail, locale, redact = (s) => s, scopes = []) {
|
|
210
|
+
// a loopback port ask: the port, then what it holds (a database port) or the page, and one
|
|
211
|
+
// choice, for this conversation (browser loopback port grants)
|
|
212
|
+
if (detail.kind === "loopback") {
|
|
213
|
+
const preview = detail.database
|
|
214
|
+
? phrase("loopbackDatabase", locale)
|
|
215
|
+
: cut(redact((detail.url ?? "").trim()), CARD_SUMMARY_MAX);
|
|
216
|
+
return {
|
|
217
|
+
title: phrase("loopbackTitle", locale).replace("{port}", String(detail.port)),
|
|
218
|
+
inputPreview: preview,
|
|
219
|
+
scopeLabels: { session: phrase("loopbackAllow", locale) },
|
|
220
|
+
};
|
|
221
|
+
}
|
|
209
222
|
const service = detail.kind === "service";
|
|
210
223
|
const hosts = [...new Set(networkAskHosts(detail).map(redact))];
|
|
211
224
|
const title = hosts.length === 1
|
|
@@ -354,6 +367,7 @@ export async function approvalCard(d, approvalId, base, locale, redact) {
|
|
|
354
367
|
? commandCardText(v.command, v.scopes, locale, redact)
|
|
355
368
|
: null;
|
|
356
369
|
const special = network ?? command;
|
|
370
|
+
const serviceAsk = v.kind === "network" && (v.detail?.kind === "service" || v.detail?.kind === "loopback");
|
|
357
371
|
const display = v.summary === null && special === null
|
|
358
372
|
? (await toolInfo({ db: d.db, registry: d.registry }, v.orgId, [v.toolKey]))[0]
|
|
359
373
|
: undefined;
|
|
@@ -362,8 +376,9 @@ export async function approvalCard(d, approvalId, base, locale, redact) {
|
|
|
362
376
|
id: v.id,
|
|
363
377
|
title: network?.title ?? command?.title ?? phrase("approvalTitle", locale),
|
|
364
378
|
// the label carries the source, so no separate appName (renderers would repeat it); a
|
|
365
|
-
// network
|
|
366
|
-
|
|
379
|
+
// command's network ask and a command ask ran in Bash, a device service's ask (network or
|
|
380
|
+
// loopback port) names the extension's tool that asked
|
|
381
|
+
toolName: special !== null && !serviceAsk ? "Bash" : approvalToolName(v, locale),
|
|
367
382
|
agentName: v.agent.name || "Agent",
|
|
368
383
|
// the field keeps its contract name; it carries the call line (a network ask's hosts and
|
|
369
384
|
// command, a command ask's reason and command), never the raw input
|
|
@@ -107,6 +107,21 @@ export declare const CHANNEL_PHRASES: {
|
|
|
107
107
|
readonly zh: "智能体的浏览器想访问 {host}";
|
|
108
108
|
readonly en: "The agent's browser wants to reach {host}";
|
|
109
109
|
};
|
|
110
|
+
/** A loopback port ask's card title (`{port}`; browser loopback port grants). */
|
|
111
|
+
readonly loopbackTitle: {
|
|
112
|
+
readonly zh: "允许浏览器访问本机端口 {port}?";
|
|
113
|
+
readonly en: "Allow the browser to reach port {port} on this device?";
|
|
114
|
+
};
|
|
115
|
+
/** Under a loopback port ask's title: the port is a well-known database port. */
|
|
116
|
+
readonly loopbackDatabase: {
|
|
117
|
+
readonly zh: "这是一个本地数据库端口。";
|
|
118
|
+
readonly en: "This is a local database port.";
|
|
119
|
+
};
|
|
120
|
+
/** A loopback port ask's one button: the grant for this conversation. */
|
|
121
|
+
readonly loopbackAllow: {
|
|
122
|
+
readonly zh: "允许本会话访问";
|
|
123
|
+
readonly en: "Allow for this conversation";
|
|
124
|
+
};
|
|
110
125
|
/** Under a device service's network ask: open network mode stops the asks. */
|
|
111
126
|
readonly networkServiceNote: {
|
|
112
127
|
readonly zh: "开放网络模式下不会再询问";
|
package/dist/channels/phrases.js
CHANGED
|
@@ -93,6 +93,15 @@ export const CHANNEL_PHRASES = {
|
|
|
93
93
|
zh: "智能体的浏览器想访问 {host}",
|
|
94
94
|
en: "The agent's browser wants to reach {host}",
|
|
95
95
|
},
|
|
96
|
+
/** A loopback port ask's card title (`{port}`; browser loopback port grants). */
|
|
97
|
+
loopbackTitle: {
|
|
98
|
+
zh: "允许浏览器访问本机端口 {port}?",
|
|
99
|
+
en: "Allow the browser to reach port {port} on this device?",
|
|
100
|
+
},
|
|
101
|
+
/** Under a loopback port ask's title: the port is a well-known database port. */
|
|
102
|
+
loopbackDatabase: { zh: "这是一个本地数据库端口。", en: "This is a local database port." },
|
|
103
|
+
/** A loopback port ask's one button: the grant for this conversation. */
|
|
104
|
+
loopbackAllow: { zh: "允许本会话访问", en: "Allow for this conversation" },
|
|
96
105
|
/** Under a device service's network ask: open network mode stops the asks. */
|
|
97
106
|
networkServiceNote: {
|
|
98
107
|
zh: "开放网络模式下不会再询问",
|
|
@@ -33,6 +33,7 @@ import { ProviderRegistry } from "../runtime/providers.js";
|
|
|
33
33
|
import { RunControl as RunControlService } from "../runtime/run-control.js";
|
|
34
34
|
import { RunDeletion } from "../runtime/run-deletion.js";
|
|
35
35
|
import { rootConversationOf } from "../runtime/subagents/child.js";
|
|
36
|
+
import { revokeLoopbackGrantsOfConversation } from "../sandbox/loopback-grant-records.js";
|
|
36
37
|
import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
|
|
37
38
|
import { permissionScopeHash } from "../sandbox/permission-facts.js";
|
|
38
39
|
import { revokeSharesIn } from "../shares/revoke.js";
|
|
@@ -609,6 +610,12 @@ let ConversationsService = class ConversationsService {
|
|
|
609
610
|
deviceId: subject.deviceId,
|
|
610
611
|
conversationId,
|
|
611
612
|
});
|
|
613
|
+
// a root's loopback port grants end with it and its services are refreshed without them (a
|
|
614
|
+
// sub-agent's conversation holds none)
|
|
615
|
+
await revokeLoopbackGrantsOfConversation(this.db.db, this.outbox, {
|
|
616
|
+
orgId,
|
|
617
|
+
rootConversationId: conversationId,
|
|
618
|
+
});
|
|
612
619
|
}
|
|
613
620
|
/** 读会话:非所有者、或 agent 已对所有者不可用 → `conversation.not_found`。 */
|
|
614
621
|
async get(orgId, conversationId, viewerAccountId) {
|
|
@@ -364,6 +364,7 @@ export declare const ReviewRecordSchema: z.ZodObject<{
|
|
|
364
364
|
crossing: z.ZodOptional<z.ZodEnum<{
|
|
365
365
|
directory: "directory";
|
|
366
366
|
host: "host";
|
|
367
|
+
"loopback-port": "loopback-port";
|
|
367
368
|
"outside-sandbox": "outside-sandbox";
|
|
368
369
|
sensitive: "sensitive";
|
|
369
370
|
}>>;
|
|
@@ -840,6 +841,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
|
|
|
840
841
|
targetPath: z.ZodOptional<z.ZodString>;
|
|
841
842
|
scopeKind: z.ZodEnum<{
|
|
842
843
|
"directories-and-hosts": "directories-and-hosts";
|
|
844
|
+
"loopback-port": "loopback-port";
|
|
843
845
|
"sandbox-escalation": "sandbox-escalation";
|
|
844
846
|
}>;
|
|
845
847
|
escalation: z.ZodOptional<z.ZodObject<{
|
|
@@ -862,9 +864,14 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
|
|
|
862
864
|
crossing: z.ZodOptional<z.ZodEnum<{
|
|
863
865
|
directory: "directory";
|
|
864
866
|
host: "host";
|
|
867
|
+
"loopback-port": "loopback-port";
|
|
865
868
|
"outside-sandbox": "outside-sandbox";
|
|
866
869
|
}>>;
|
|
867
870
|
sensitive: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
871
|
+
loopback: z.ZodOptional<z.ZodObject<{
|
|
872
|
+
service: z.ZodString;
|
|
873
|
+
port: z.ZodNumber;
|
|
874
|
+
}, z.core.$strip>>;
|
|
868
875
|
}, z.core.$strip>;
|
|
869
876
|
}, z.core.$strip>, z.ZodObject<{
|
|
870
877
|
type: z.ZodLiteral<"permission_profile_changed">;
|
|
@@ -1477,6 +1484,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
|
|
|
1477
1484
|
crossing: z.ZodOptional<z.ZodEnum<{
|
|
1478
1485
|
directory: "directory";
|
|
1479
1486
|
host: "host";
|
|
1487
|
+
"loopback-port": "loopback-port";
|
|
1480
1488
|
"outside-sandbox": "outside-sandbox";
|
|
1481
1489
|
sensitive: "sensitive";
|
|
1482
1490
|
}>>;
|
|
@@ -1648,6 +1656,11 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
|
|
|
1648
1656
|
sandbox: "sandbox";
|
|
1649
1657
|
}>;
|
|
1650
1658
|
}, z.core.$strict>>;
|
|
1659
|
+
loopback: z.ZodOptional<z.ZodObject<{
|
|
1660
|
+
service: z.ZodString;
|
|
1661
|
+
port: z.ZodNumber;
|
|
1662
|
+
database: z.ZodBoolean;
|
|
1663
|
+
}, z.core.$strip>>;
|
|
1651
1664
|
secureInput: z.ZodOptional<z.ZodObject<{
|
|
1652
1665
|
target: z.ZodObject<{
|
|
1653
1666
|
zh: z.ZodString;
|
|
@@ -455,7 +455,9 @@ export const ReviewRecordSchema = z
|
|
|
455
455
|
* scope, a host outside the allowlist, running outside the sandbox, or a sensitive command.
|
|
456
456
|
* Not model-visible, so it needs no DriftReason.
|
|
457
457
|
*/
|
|
458
|
-
crossing: z
|
|
458
|
+
crossing: z
|
|
459
|
+
.enum(["directory", "host", "outside-sandbox", "sensitive", "loopback-port"])
|
|
460
|
+
.optional(),
|
|
459
461
|
})
|
|
460
462
|
.strict();
|
|
461
463
|
/** The display-only `approval_requested.command` facts of a `command` ask (auto mode spec §5.4). */
|
|
@@ -848,7 +850,7 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
848
850
|
binding: PermissionCallBindingSchema,
|
|
849
851
|
permissionScope: PermissionExpansionSchema,
|
|
850
852
|
targetPath: z.string().max(4096).optional(),
|
|
851
|
-
scopeKind: z.enum(["directories-and-hosts", "sandbox-escalation"]),
|
|
853
|
+
scopeKind: z.enum(["directories-and-hosts", "sandbox-escalation", "loopback-port"]),
|
|
852
854
|
/** A per-call sandbox escalation: the model's justification (its scope is empty). */
|
|
853
855
|
escalation: PermissionEscalationSchema.optional(),
|
|
854
856
|
candidateHash: z.string(),
|
|
@@ -860,9 +862,16 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
860
862
|
*/
|
|
861
863
|
decisionSource: z.enum(["review-model", "rule", "full-access"]),
|
|
862
864
|
/** The crossing reviewed (approval-only profiles design); not model-visible. */
|
|
863
|
-
crossing: z.enum(["directory", "host", "outside-sandbox"]).optional(),
|
|
865
|
+
crossing: z.enum(["directory", "host", "outside-sandbox", "loopback-port"]).optional(),
|
|
864
866
|
/** The sensitive-command consents (rule ids) a Full access auto-grant skipped; not model-visible. */
|
|
865
867
|
sensitive: z.array(z.string()).optional(),
|
|
868
|
+
/**
|
|
869
|
+
* A loopback port grant's review (`scopeKind: "loopback-port"`): the device service and the
|
|
870
|
+
* port it asked to reach on the person's own device. Not model-visible.
|
|
871
|
+
*/
|
|
872
|
+
loopback: z
|
|
873
|
+
.object({ service: z.string(), port: z.number().int().min(1).max(65535) })
|
|
874
|
+
.optional(),
|
|
866
875
|
})),
|
|
867
876
|
ev("permission_profile_changed", z.object({
|
|
868
877
|
oldProfile: z.enum(["request-approval", "approve-for-me", "full-access"]),
|
|
@@ -1486,6 +1495,18 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
1486
1495
|
* model-visible, as `network` and `git`; the model sees the call's `tool_result` only.
|
|
1487
1496
|
*/
|
|
1488
1497
|
command: CommandAskSchema.optional(),
|
|
1498
|
+
/**
|
|
1499
|
+
* A loopback port ask (browser loopback port grants): the device service, the port it asks
|
|
1500
|
+
* to reach on the person's own device and whether it is a well-known database port. Display
|
|
1501
|
+
* only, never model-visible, as `network`.
|
|
1502
|
+
*/
|
|
1503
|
+
loopback: z
|
|
1504
|
+
.object({
|
|
1505
|
+
service: z.string(),
|
|
1506
|
+
port: z.number().int().min(1).max(65535),
|
|
1507
|
+
database: z.boolean(),
|
|
1508
|
+
})
|
|
1509
|
+
.optional(),
|
|
1489
1510
|
/**
|
|
1490
1511
|
* A secure input request (`kind = 'secure_input'`; profiles govern every approval): what the
|
|
1491
1512
|
* values are for and the field paths the person enters. Display only, never a value and
|
package/dist/ctx/create-ctx.d.ts
CHANGED
|
@@ -103,7 +103,7 @@ export interface KernelDeps {
|
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
105
|
/** What `ctx.deviceAccess` calls through (`DeviceAccessService`). */
|
|
106
|
-
export type DeviceAccessBackend = Pick<DeviceAccessService, "ensureService" | "request" | "reportBlockedHosts" | "streamTicket" | "addNetworkHosts" | "answerHandoff">;
|
|
106
|
+
export type DeviceAccessBackend = Pick<DeviceAccessService, "ensureService" | "request" | "reportBlockedHosts" | "streamTicket" | "addNetworkHosts" | "answerHandoff" | "grantLoopbackPort" | "revokeLoopbackPort" | "loopbackPorts">;
|
|
107
107
|
/** What `ctx.triggers` calls through (`TriggerEventsService`). */
|
|
108
108
|
export type TriggersBackend = Pick<TriggerEventsService, "emit" | "causeOf">;
|
|
109
109
|
/** What `ctx.inbox` calls through (`InboxItemsService`). */
|
package/dist/ctx/create-ctx.js
CHANGED
|
@@ -418,6 +418,8 @@ identity = { sha256: null }) {
|
|
|
418
418
|
sha256: identity.sha256,
|
|
419
419
|
// a draining instance (its successor is loaded) never rolls a service back to its files
|
|
420
420
|
superseded: () => disposing || lifecycle.signal.aborted,
|
|
421
|
+
// read from the approved manifest: an upgrade adding it waits for approval again
|
|
422
|
+
loopbackPorts: perms.deviceAccess?.loopbackPorts === true,
|
|
421
423
|
};
|
|
422
424
|
const backend = () => {
|
|
423
425
|
const b = deps.deviceAccess?.();
|
|
@@ -428,10 +430,13 @@ identity = { sha256: null }) {
|
|
|
428
430
|
return {
|
|
429
431
|
ensureService: async (call, spec) => backend().ensureService(caller, call, spec),
|
|
430
432
|
request: async (call, req) => backend().request(caller, call, req),
|
|
431
|
-
reportBlockedHosts: (call, hosts, opts) => backend().reportBlockedHosts(call, hosts, opts),
|
|
433
|
+
reportBlockedHosts: (call, hosts, opts) => backend().reportBlockedHosts(caller, call, hosts, opts),
|
|
432
434
|
streamTicket: async (scope) => backend().streamTicket(caller, scope),
|
|
433
435
|
addNetworkHosts: async (scope) => backend().addNetworkHosts(caller, scope),
|
|
434
436
|
answerHandoff: async (scope) => backend().answerHandoff(caller, scope),
|
|
437
|
+
grantLoopbackPort: async (scope) => backend().grantLoopbackPort(caller, scope),
|
|
438
|
+
revokeLoopbackPort: async (scope) => backend().revokeLoopbackPort(caller, scope),
|
|
439
|
+
loopbackPorts: async (scope) => backend().loopbackPorts(caller, scope),
|
|
435
440
|
};
|
|
436
441
|
})()
|
|
437
442
|
: undefined;
|
|
@@ -1291,6 +1291,31 @@ export interface DeviceConversationNoticesTable {
|
|
|
1291
1291
|
acked_services: ColumnType<string[], string[] | undefined, string[]>;
|
|
1292
1292
|
last_failure: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1293
1293
|
}
|
|
1294
|
+
/**
|
|
1295
|
+
* 0199: a grant letting one extension service of a person's own device reach one loopback port for
|
|
1296
|
+
* one conversation tree (browser loopback port grants design §6). At most one live row (null
|
|
1297
|
+
* `revoked_at`) per (device, service, conversation, port).
|
|
1298
|
+
*/
|
|
1299
|
+
export interface DeviceLoopbackGrantsTable {
|
|
1300
|
+
id: string;
|
|
1301
|
+
org_id: string;
|
|
1302
|
+
device_id: string;
|
|
1303
|
+
/** The service id (`<extension>.<name>`). */
|
|
1304
|
+
service_id: string;
|
|
1305
|
+
/** The root conversation. */
|
|
1306
|
+
conversation_id: string;
|
|
1307
|
+
port: number;
|
|
1308
|
+
source: "human" | "review-model" | "full-access" | "owner-panel";
|
|
1309
|
+
approval_id: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1310
|
+
/** The call that asked (`run_id`, `call_id`, `attempt`); null for the owner's panel. */
|
|
1311
|
+
run_id: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1312
|
+
call_id: ColumnType<string | null, string | null | undefined, string | null>;
|
|
1313
|
+
attempt: ColumnType<number | null, number | null | undefined, number | null>;
|
|
1314
|
+
created_at: Ts;
|
|
1315
|
+
expires_at: ColumnType<Date, Date | string, Date | string>;
|
|
1316
|
+
revoked_at: TsNullable;
|
|
1317
|
+
revoke_reason: Generated<"revoked" | "expired" | "conversation-deleted" | "outside-sandbox-off" | null>;
|
|
1318
|
+
}
|
|
1294
1319
|
/** 0088_environments.sql, renamed in 0105: the device a member's new conversations use by default. */
|
|
1295
1320
|
export interface DeviceDefaultsTable {
|
|
1296
1321
|
org_id: string;
|
|
@@ -2022,6 +2047,7 @@ export interface KernelDatabase {
|
|
|
2022
2047
|
device_machines: DeviceMachinesTable;
|
|
2023
2048
|
device_projects: DeviceProjectsTable;
|
|
2024
2049
|
device_conversation_notices: DeviceConversationNoticesTable;
|
|
2050
|
+
device_loopback_grants: DeviceLoopbackGrantsTable;
|
|
2025
2051
|
background_tasks: BackgroundTasksTable;
|
|
2026
2052
|
automations: AutomationsTable;
|
|
2027
2053
|
automation_runs: AutomationRunsTable;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type DeviceAccessScope, type DeviceServiceSpec, type DeviceServiceStatus, type Logger, type ServiceBlockedHost, type ToolCallContext } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import { type DeviceAccessScope, type DeviceServiceSpec, type DeviceServiceStatus, type Logger, type LoopbackGrantView, type ServiceBlockedHost, type ToolCallContext } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { Redis } from "ioredis";
|
|
3
3
|
import { DeviceAccess } from "../devices/access.js";
|
|
4
4
|
import { ConversationDevices } from "../devices/conversation-devices.js";
|
|
@@ -6,9 +6,12 @@ import { DevicesService } from "../devices/devices.service.js";
|
|
|
6
6
|
import { ExtensionRegistry } from "../extensions/registry.js";
|
|
7
7
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
8
8
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
9
|
+
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
9
10
|
import { DeviceServices } from "../sandbox/device-services.js";
|
|
11
|
+
import { LoopbackGrants } from "../sandbox/loopback-grants.js";
|
|
10
12
|
import { DeviceProviders } from "../sandbox/providers.js";
|
|
11
13
|
import { CommandReviewService } from "../sandbox/review/review.service.js";
|
|
14
|
+
import { ApprovalsService } from "../tools/approvals.service.js";
|
|
12
15
|
import { QuestionsService } from "../tools/questions.service.js";
|
|
13
16
|
/** What every `ctx.deviceAccess` call refuses a run another member triggered with. */
|
|
14
17
|
export declare const DEVICE_ACCESS_NOT_OWNER_TEXT = "Browser tools only run for the conversation's owner on their own device.";
|
|
@@ -39,6 +42,11 @@ export interface DeviceAccessCaller {
|
|
|
39
42
|
sha256?: string | null;
|
|
40
43
|
/** True once the calling instance is being replaced or unloaded (it drains its calls). */
|
|
41
44
|
superseded?: () => boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The approved manifest declares `permissions.deviceAccess.loopbackPorts: true`: its services may
|
|
47
|
+
* be granted local ports of the device (browser loopback port grants design).
|
|
48
|
+
*/
|
|
49
|
+
loopbackPorts: boolean;
|
|
42
50
|
}
|
|
43
51
|
/**
|
|
44
52
|
* `ctx.deviceAccess` (browser use spec §7): an extension's device services in the conversation's
|
|
@@ -64,7 +72,13 @@ export declare class DeviceAccessService {
|
|
|
64
72
|
private readonly providers;
|
|
65
73
|
private readonly log;
|
|
66
74
|
private readonly registry;
|
|
67
|
-
|
|
75
|
+
readonly txHost: TransactionHost;
|
|
76
|
+
private readonly loopback;
|
|
77
|
+
/** A panel grant settles the agent's pending ask for the same port. */
|
|
78
|
+
private readonly approvals;
|
|
79
|
+
constructor(kdb: KernelDb, redis: Redis, config: Pick<KernelConfigService, "get">, services: DeviceServices, review: Pick<CommandReviewService, "review">, devices: Pick<ConversationDevices, "forTool" | "reviewFacts">, access: Pick<DeviceAccess, "usable">, deviceWrites: Pick<DevicesService, "addNetworkHostsIn">, questions: Pick<QuestionsService, "answer">, providers: Pick<DeviceProviders, "forDevice">, log: Logger, registry: Pick<ExtensionRegistry, "current">, txHost: TransactionHost, loopback: Pick<LoopbackGrants, "grantIn" | "revoke" | "liveForRoot" | "refusalNow">,
|
|
80
|
+
/** A panel grant settles the agent's pending ask for the same port. */
|
|
81
|
+
approvals: Pick<ApprovalsService, "settleLoopbackAsks">);
|
|
68
82
|
private get db();
|
|
69
83
|
/**
|
|
70
84
|
* Starts the service in the call's device, or finds it running. An `ifRunning` ensure first
|
|
@@ -109,10 +123,67 @@ export declare class DeviceAccessService {
|
|
|
109
123
|
* once the handler returns) on the device this call's own `ctx.deviceAccess` calls resolved, if
|
|
110
124
|
* any. A malformed entry (not a non-empty host with a known layer) is dropped; a host reported
|
|
111
125
|
* again keeps its most restrictive layer, so a later report never makes it grantable.
|
|
126
|
+
*
|
|
127
|
+
* A loopback refusal (layer `address`, class `loopback`, a loopback grant host, an integer port
|
|
128
|
+
* in 1–65535) of an extension declaring `permissions.deviceAccess.loopbackPorts` also lands as
|
|
129
|
+
* the scope's `loopback` entry (the first such entry of the call wins), naming the service it
|
|
130
|
+
* came from: `opts.service` when declared, else the extension's only declared service; with no
|
|
131
|
+
* such service it does not. Every other port and class is dropped: the entry is an address host
|
|
132
|
+
* like any other.
|
|
112
133
|
*/
|
|
113
|
-
reportBlockedHosts(call: ToolCallContext, hosts: ServiceBlockedHost[], opts?: {
|
|
134
|
+
reportBlockedHosts(caller: DeviceAccessCaller, call: ToolCallContext, hosts: ServiceBlockedHost[], opts?: {
|
|
114
135
|
url?: string;
|
|
136
|
+
service?: string;
|
|
115
137
|
}): void;
|
|
138
|
+
/**
|
|
139
|
+
* Grants the scope conversation's root a local port of its device for one service (the owner's
|
|
140
|
+
* click in the panel, source `owner-panel`): owner only, refused with `loopback_unavailable`
|
|
141
|
+
* when the device's outside-sandbox ceilings or its provider do not allow it now
|
|
142
|
+
* (`loopbackRefusal`). The record is written in its own transaction
|
|
143
|
+
* (`LoopbackGrants.grantIn`, which owes the refresh); the running service then gets the live set
|
|
144
|
+
* at once, best effort (the owed refresh job is the backstop).
|
|
145
|
+
*/
|
|
146
|
+
grantLoopbackPort(caller: DeviceAccessCaller, scope: DeviceAccessScope & {
|
|
147
|
+
service: string;
|
|
148
|
+
port: number;
|
|
149
|
+
}): Promise<LoopbackGrantView>;
|
|
150
|
+
/**
|
|
151
|
+
* Revokes the scope conversation root's grant of the port to the service (owner only); nothing
|
|
152
|
+
* to revoke succeeds. The running service then gets the live set at once, best effort (the
|
|
153
|
+
* owed refresh job is the backstop).
|
|
154
|
+
*/
|
|
155
|
+
revokeLoopbackPort(caller: DeviceAccessCaller, scope: DeviceAccessScope & {
|
|
156
|
+
service: string;
|
|
157
|
+
port: number;
|
|
158
|
+
}): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* The live grants of the service held by the scope conversation's root (owner only), by port.
|
|
161
|
+
* None while the tree is unattended ({@link unattendedTree}): a grant the person made is never an
|
|
162
|
+
* unattended run's, so the browser's per-tab check refuses that tab (the grants stay live).
|
|
163
|
+
*/
|
|
164
|
+
loopbackPorts(caller: DeviceAccessCaller, scope: DeviceAccessScope & {
|
|
165
|
+
service: string;
|
|
166
|
+
}): Promise<LoopbackGrantView[]>;
|
|
167
|
+
/**
|
|
168
|
+
* The checks every loopback call makes (the extension declares loopback ports and the service,
|
|
169
|
+
* the port is one, the account owns the conversation and its personal device) and the grant key
|
|
170
|
+
* under the conversation's root (`port` 0 for a listing).
|
|
171
|
+
*/
|
|
172
|
+
private loopbackKey;
|
|
173
|
+
/**
|
|
174
|
+
* Whether the scope's tree is unattended now, by the kernel's own records: its root is an
|
|
175
|
+
* automation's conversation (`automation_id`), or a run of the scope conversation or its root
|
|
176
|
+
* that has not ended serves an automation run with no person joined (`unattendedRunOf`; a trial
|
|
177
|
+
* run is attended).
|
|
178
|
+
*/
|
|
179
|
+
private unattendedTree;
|
|
180
|
+
/**
|
|
181
|
+
* The grant in a transaction of its own. `grantIn` locks the root conversation first, so nothing
|
|
182
|
+
* here locks rows the conversation deletion path locks after the conversation.
|
|
183
|
+
*/
|
|
184
|
+
private grantInTx;
|
|
185
|
+
/** Sends the service's live set now when it runs (best effort, logged on failure). */
|
|
186
|
+
private refreshLoopback;
|
|
116
187
|
/** A single-use viewer ticket for the service (the person's panel opens `url`). */
|
|
117
188
|
streamTicket(caller: DeviceAccessCaller, scope: DeviceAccessScope & {
|
|
118
189
|
service: string;
|