@capybara-hq/kernel 0.1.0-rc.113 → 0.1.0-rc.115
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 +7 -7
- package/dist/admin/admin.schemas.d.ts +1 -0
- 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 +21 -0
- package/dist/conversations/events.js +35 -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 +29 -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/identity/settings.d.ts +5 -0
- package/dist/identity/settings.js +4 -0
- package/dist/infra/outbox/registry.d.ts +14 -0
- package/dist/infra/outbox/registry.js +14 -0
- package/dist/models/purposes.js +5 -0
- package/dist/orgs/offboarding.js +5 -1
- package/dist/orgs/settings.service.d.ts +2 -0
- package/dist/platform/ops/org-settings.ops.js +1 -1
- package/dist/roles/worker.module.js +3 -0
- package/dist/runtime/compaction-model.d.ts +57 -0
- package/dist/runtime/compaction-model.js +87 -0
- package/dist/runtime/compaction.service.d.ts +23 -8
- package/dist/runtime/compaction.service.js +15 -10
- package/dist/runtime/context/compaction.d.ts +19 -2
- package/dist/runtime/context/compaction.js +23 -2
- package/dist/runtime/context/idle-compaction-rules.d.ts +17 -2
- package/dist/runtime/context/idle-compaction-rules.js +20 -5
- package/dist/runtime/idle-arm.d.ts +12 -2
- package/dist/runtime/idle-arm.js +66 -18
- package/dist/runtime/idle-compaction-jobs.d.ts +24 -3
- package/dist/runtime/idle-compaction.d.ts +11 -3
- package/dist/runtime/idle-compaction.js +61 -30
- package/dist/runtime/maintenance.d.ts +4 -2
- package/dist/runtime/maintenance.js +14 -4
- package/dist/runtime/model-call.d.ts +52 -16
- package/dist/runtime/model-call.js +71 -24
- package/dist/runtime/run-finish.d.ts +12 -3
- package/dist/runtime/run-finish.js +14 -7
- package/dist/runtime/run-queue.d.ts +5 -2
- package/dist/runtime/run-queue.js +7 -4
- package/dist/runtime/run-steps.d.ts +4 -1
- package/dist/runtime/run-steps.js +9 -2
- package/dist/runtime/run-worker.js +4 -2
- package/dist/runtime/runtime.module.js +3 -0
- 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
- package/src/migrations/0200_runs_idle_mode.sql +4 -0
|
@@ -4,6 +4,7 @@ import { NETWORK_ASK_MAX_HOSTS, NETWORK_HOST_MAX_CHARS } from "../conversations/
|
|
|
4
4
|
import { coversHost } from "../sandbox/modes.js";
|
|
5
5
|
import { ESCALATION_UNATTENDED_WHY } from "../sandbox/review/permission-candidate.js";
|
|
6
6
|
import { NETWORK_ASK_CANCELLED_NOTE, networkAskHosts, } from "./approvals.service.js";
|
|
7
|
+
import { settledLoopbackNotes } from "./loopback-asks.js";
|
|
7
8
|
/**
|
|
8
9
|
* Network asks in the tool pipeline (network ask-to-allow spec §6.2, §6.6–§6.9, §8.3): what a
|
|
9
10
|
* command's reported refusals turn into (an ask to the device owner, or notes written at once) and
|
|
@@ -359,18 +360,22 @@ const NO_OFFER_WHY = "the device's owner changes the device's network on its pag
|
|
|
359
360
|
* The note of a settled network ask (spec §6.6): one line per outcome. An approval allows
|
|
360
361
|
* `detail.grantedHosts` for the run (`once`) or added them to the device's own list (`always`,
|
|
361
362
|
* applying at `detail.appliesAt`) and declines the hosts left unchecked; `hours` is the ask's own
|
|
362
|
-
* wait (created to expiry). Null while it is pending.
|
|
363
|
+
* wait (created to expiry). Null while it is pending. A loopback port ask's notes are
|
|
364
|
+
* {@link settledLoopbackNotes}.
|
|
363
365
|
*/
|
|
364
366
|
export function settledNetworkNotes(a, hours) {
|
|
365
|
-
|
|
367
|
+
if (a.detail?.kind === "loopback")
|
|
368
|
+
return settledLoopbackNotes(a, hours);
|
|
369
|
+
const detail = a.detail;
|
|
370
|
+
const asked = detail === null ? [] : networkAskHosts(detail);
|
|
366
371
|
switch (a.status) {
|
|
367
372
|
case "approved": {
|
|
368
|
-
const granted =
|
|
373
|
+
const granted = detail?.grantedHosts ?? asked;
|
|
369
374
|
const rest = asked.filter((h) => !granted.includes(h));
|
|
370
375
|
const notes = [];
|
|
371
376
|
if (granted.length > 0) {
|
|
372
|
-
notes.push(a.scope === "always" &&
|
|
373
|
-
? addedToDeviceNote(granted,
|
|
377
|
+
notes.push(a.scope === "always" && detail !== null
|
|
378
|
+
? addedToDeviceNote(granted, detail.appliesAt)
|
|
374
379
|
: allowedOnceNote(granted));
|
|
375
380
|
}
|
|
376
381
|
if (rest.length > 0)
|
package/dist/tools/pipeline.d.ts
CHANGED
|
@@ -19,11 +19,13 @@ import { type SubagentParent, type WaitingFor } from "../runtime/loop.js";
|
|
|
19
19
|
import type { DispatchArgs, DispatchOutcome } from "../runtime/subagents/dispatch.js";
|
|
20
20
|
import { SubagentMessages } from "../runtime/subagents/messages.js";
|
|
21
21
|
import { SubagentsService } from "../runtime/subagents/subagents.service.js";
|
|
22
|
+
import { LoopbackGrants } from "../sandbox/loopback-grants.js";
|
|
22
23
|
import { type NetworkRunState } from "../sandbox/network-grants.js";
|
|
23
24
|
import { SandboxOperationAuthority } from "../sandbox/operation-authority.js";
|
|
24
25
|
import { PermissionAuthorityLock } from "../sandbox/permission-authority-lock.js";
|
|
25
26
|
import { PermissionAutoGrants } from "../sandbox/permission-auto-grants.js";
|
|
26
27
|
import { PermissionCallGrants } from "../sandbox/permission-call-grants.js";
|
|
28
|
+
import { PermissionFacts } from "../sandbox/permission-facts.js";
|
|
27
29
|
import { type CommandReview } from "../sandbox/review/index.js";
|
|
28
30
|
import { SandboxService } from "../sandbox/sandbox.service.js";
|
|
29
31
|
import { ApprovalsService, type NetworkAskDetail } from "./approvals.service.js";
|
|
@@ -243,7 +245,7 @@ interface PipelineDeps {
|
|
|
243
245
|
readonly breaker: Pick<Breaker, "check" | "failure" | "success">;
|
|
244
246
|
readonly outputs: Pick<ToolOutputs, "save" | "load">;
|
|
245
247
|
/** 策略为 `ask` 时建审批;续跑时读该调用的审批结果。 A refused network host: a network ask. */
|
|
246
|
-
readonly approvals: Pick<ApprovalsService, "request" | "forCall" | "networkForCall" | "requestNetwork" | "commandForCall" | "requestCommand" | "requestSecureInput" | "secureInputForCall">;
|
|
248
|
+
readonly approvals: Pick<ApprovalsService, "request" | "forCall" | "networkForCall" | "requestNetwork" | "requestLoopback" | "commandForCall" | "requestCommand" | "requestSecureInput" | "secureInputForCall">;
|
|
247
249
|
/** 处理函数返回 `input_required` 时建输入请求;续跑时读该调用的各轮输入请求。 */
|
|
248
250
|
readonly questions: Pick<QuestionsService, "ask" | "forCall">;
|
|
249
251
|
readonly log: Logger;
|
|
@@ -382,6 +384,16 @@ export interface ServiceBlocked {
|
|
|
382
384
|
hosts: ServiceBlockedHost[];
|
|
383
385
|
/** The page the refusals came from, when the service said. */
|
|
384
386
|
url: string | null;
|
|
387
|
+
/**
|
|
388
|
+
* The call's loopback refusal of an extension declaring `permissions.deviceAccess.loopbackPorts`
|
|
389
|
+
* (`CallScope.blocked.loopback`): the service (`<extension>.<name>`), the host and the port. Its
|
|
390
|
+
* host is in `hosts` too, as an address host. Absent: none.
|
|
391
|
+
*/
|
|
392
|
+
loopback?: {
|
|
393
|
+
serviceId: string;
|
|
394
|
+
host: string;
|
|
395
|
+
port: number;
|
|
396
|
+
};
|
|
385
397
|
}
|
|
386
398
|
export type ExecOutcome =
|
|
387
399
|
/** 工具返回了结果(可能是工具自己报告的错误,或畸形结果,由渲染阶段处理)。 */
|
|
@@ -586,13 +598,20 @@ export declare class ToolPipeline {
|
|
|
586
598
|
* result images design §2); absent (hand-built pipelines): images are named as not stored.
|
|
587
599
|
*/
|
|
588
600
|
private readonly resultImages?;
|
|
601
|
+
/**
|
|
602
|
+
* A device service's loopback port grants (browser loopback port grants); absent (hand-built
|
|
603
|
+
* pipelines): a loopback refusal keeps the address note.
|
|
604
|
+
*/
|
|
605
|
+
private readonly loopbackGrants?;
|
|
606
|
+
/** The device's sandbox and its provider's support a loopback grant is checked against. */
|
|
607
|
+
private readonly permissionFacts?;
|
|
589
608
|
private readonly decide;
|
|
590
609
|
private readonly deps;
|
|
591
610
|
constructor(kdb: KernelDb, eventLog: EventLog,
|
|
592
611
|
/** The `Agent` tool's sub-agent dispatch; absent (tests): `Agent` calls are refused. */
|
|
593
612
|
subagents: Pick<SubagentsService, "dispatch"> | undefined,
|
|
594
613
|
/** The message tools between agents; absent (tests): their calls are refused. */
|
|
595
|
-
messages: Pick<SubagentMessages, "toChild" | "toParent"> | undefined, registry: Pick<ToolRegistry, "forAgent" | "findConnector" | "handler" | "watcher">, credentials: Pick<Credentials, "injection" | "onUnauthorized">, breaker: Pick<Breaker, "check" | "failure" | "success">, outputs: Pick<ToolOutputs, "save" | "load">, approvals: Pick<ApprovalsService, "request" | "forCall" | "networkForCall" | "requestNetwork" | "commandForCall" | "requestCommand" | "requestSecureInput" | "secureInputForCall">, questions: Pick<QuestionsService, "ask" | "forCall">, config: Pick<KernelConfigService, "get">, log: Logger & Partial<Pick<KernelLogger, "debug">>,
|
|
614
|
+
messages: Pick<SubagentMessages, "toChild" | "toParent"> | undefined, registry: Pick<ToolRegistry, "forAgent" | "findConnector" | "handler" | "watcher">, credentials: Pick<Credentials, "injection" | "onUnauthorized">, breaker: Pick<Breaker, "check" | "failure" | "success">, outputs: Pick<ToolOutputs, "save" | "load">, approvals: Pick<ApprovalsService, "request" | "forCall" | "networkForCall" | "requestNetwork" | "requestLoopback" | "commandForCall" | "requestCommand" | "requestSecureInput" | "secureInputForCall">, questions: Pick<QuestionsService, "ask" | "forCall">, config: Pick<KernelConfigService, "get">, log: Logger & Partial<Pick<KernelLogger, "debug">>,
|
|
596
615
|
/** Plugin hooks and inline ui contributions; absent (tests): no hooks, cards dropped. */
|
|
597
616
|
host: Pick<ExtensionHost, "hooks" | "current"> | undefined, drift: Pick<ToolDrift, "onToolsChanged"> | undefined, effective: Pick<EffectiveConfigs, "get">, switches: Pick<OrgToolSwitches, "isToolOff">, txHost: TransactionHost, hooks?: ToolPipelineHooks, networkGrants?: {
|
|
598
617
|
runState(runId: string, deviceId?: string): Promise<NetworkRunState>;
|
|
@@ -616,7 +635,14 @@ export declare class ToolPipeline {
|
|
|
616
635
|
* Stores the images a tool result carries as `read` copies of the calling conversation (tool
|
|
617
636
|
* result images design §2); absent (hand-built pipelines): images are named as not stored.
|
|
618
637
|
*/
|
|
619
|
-
resultImages?: Pick<AttachmentsService, "storeRead"> | undefined
|
|
638
|
+
resultImages?: Pick<AttachmentsService, "storeRead"> | undefined,
|
|
639
|
+
/**
|
|
640
|
+
* A device service's loopback port grants (browser loopback port grants); absent (hand-built
|
|
641
|
+
* pipelines): a loopback refusal keeps the address note.
|
|
642
|
+
*/
|
|
643
|
+
loopbackGrants?: Pick<LoopbackGrants, "grantIn" | "forCall" | "liveForRoot"> | undefined,
|
|
644
|
+
/** The device's sandbox and its provider's support a loopback grant is checked against. */
|
|
645
|
+
permissionFacts?: Pick<PermissionFacts, "deviceSandboxFacts"> | undefined);
|
|
620
646
|
/**
|
|
621
647
|
* tools 节点:按顺序处理本步 assistant 消息里的全部 `tool_call`,每个调用都以一条 `tool_result` 结束
|
|
622
648
|
* (之后才回到 prepare 构建下一次请求,保持「已记录调用、未记录结果之间不构建请求」的不变式)。
|
|
@@ -712,6 +738,36 @@ export declare class ToolPipeline {
|
|
|
712
738
|
* settles (P-D2).
|
|
713
739
|
*/
|
|
714
740
|
private networkBlocked;
|
|
741
|
+
/** The call's live loopback port grant (null: none, ended, or no grants service). */
|
|
742
|
+
private loopbackGrantOf;
|
|
743
|
+
/**
|
|
744
|
+
* A device service's loopback refusal (browser loopback port grants): the port of the person's
|
|
745
|
+
* own device a service of an extension declaring `permissions.deviceAccess.loopbackPorts` was
|
|
746
|
+
* refused. Refused by the device's ceilings, its provider or an unattended run → a note
|
|
747
|
+
* (`write`). A live grant the service had not applied yet → the call runs again, once. Else the
|
|
748
|
+
* conversation's permission profile decides (`approverForCrossing`, crossing `loopback-port`):
|
|
749
|
+
* Full access grants it, the review model reviews it (allow grants, deny is a note, an unsure
|
|
750
|
+
* answer asks), the person is asked (the run waits, the result kept in the ask). A grant is
|
|
751
|
+
* written with its `permission_reviewed`, the call's display events and its `tool.called` in one
|
|
752
|
+
* transaction, naming this attempt: the call then runs again in the next one (`rerun`), also
|
|
753
|
+
* after a crash. `none`: not decidable here (no device of the call's account, a hand-built
|
|
754
|
+
* pipeline, no facts): the host stays an address host with its note.
|
|
755
|
+
*/
|
|
756
|
+
private loopbackBlocked;
|
|
757
|
+
/**
|
|
758
|
+
* A loopback port grant to this call's attempt and what goes with it, in one transaction: the
|
|
759
|
+
* grant first (it reads the root conversation `FOR SHARE`, before the conversation row the
|
|
760
|
+
* appends lock), then `permission_reviewed`, the call's display-only events and its
|
|
761
|
+
* `tool.called`. The call then runs again in the next attempt.
|
|
762
|
+
*/
|
|
763
|
+
private grantLoopbackIn;
|
|
764
|
+
/** A review model's loopback verdict that grants nothing (a deny, an unsure answer). */
|
|
765
|
+
private recordLoopbackReview;
|
|
766
|
+
/**
|
|
767
|
+
* A kept result's content within what an ask keeps: output under the spill threshold but over
|
|
768
|
+
* {@link NETWORK_ASK_KEPT_MAX_BYTES} is archived after all.
|
|
769
|
+
*/
|
|
770
|
+
private keptContent;
|
|
715
771
|
/**
|
|
716
772
|
* A device service's report (the call scope, browser use spec §7.1) on the device the call's
|
|
717
773
|
* conversation works in (the root conversation's for a sub-agent, as the sandbox tools resolve
|