@capybara-hq/kernel 0.1.0-rc.72 → 0.1.0-rc.74

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.
Files changed (81) hide show
  1. package/bootstrap.json +5 -5
  2. package/dist/catalog/admin-catalog.schemas.d.ts +3 -1
  3. package/dist/catalog/admin-catalog.schemas.js +6 -2
  4. package/dist/catalog/marketplaces.service.d.ts +1 -1
  5. package/dist/catalog/org-catalog.schemas.d.ts +3 -1
  6. package/dist/catalog/org-catalog.schemas.js +3 -1
  7. package/dist/catalog/plugin-package.js +7 -5
  8. package/dist/catalog/reserved-names.js +3 -9
  9. package/dist/channels/actions.js +4 -0
  10. package/dist/channels/cards.d.ts +10 -7
  11. package/dist/channels/cards.js +23 -12
  12. package/dist/channels/phrases.d.ts +24 -2
  13. package/dist/channels/phrases.js +12 -2
  14. package/dist/ctx/secrets.d.ts +4 -2
  15. package/dist/ctx/secrets.js +19 -5
  16. package/dist/db/kernel-schema.d.ts +14 -0
  17. package/dist/devices/conversation-devices.d.ts +3 -2
  18. package/dist/devices/conversation-devices.js +9 -4
  19. package/dist/devices/device-projects.service.d.ts +22 -27
  20. package/dist/devices/device-projects.service.js +36 -41
  21. package/dist/devices/devices.controller.d.ts +3 -5
  22. package/dist/devices/devices.controller.js +4 -17
  23. package/dist/devices/devices.schemas.d.ts +1 -1
  24. package/dist/devices/devices.schemas.js +1 -1
  25. package/dist/devices/devices.service.d.ts +72 -52
  26. package/dist/devices/devices.service.js +158 -93
  27. package/dist/devices/project-rules.d.ts +6 -8
  28. package/dist/devices/project-rules.js +5 -11
  29. package/dist/dial-in/auth.controller.d.ts +1 -1
  30. package/dist/dial-in/auth.controller.js +1 -1
  31. package/dist/dial-in/auth.service.d.ts +4 -0
  32. package/dist/dial-in/auth.service.js +16 -2
  33. package/dist/dial-in/machines.d.ts +5 -4
  34. package/dist/dial-in/machines.js +5 -4
  35. package/dist/errors.d.ts +8 -3
  36. package/dist/errors.js +8 -3
  37. package/dist/extensions/admin-ops.js +2 -1
  38. package/dist/extensions/bootstrap-extra.d.ts +11 -1
  39. package/dist/extensions/bootstrap-extra.js +21 -1
  40. package/dist/extensions/bootstrap-manifest.d.ts +14 -0
  41. package/dist/extensions/bootstrap-manifest.js +23 -0
  42. package/dist/extensions/bootstrap-packages.d.ts +87 -0
  43. package/dist/extensions/bootstrap-packages.js +263 -0
  44. package/dist/extensions/bootstrap.d.ts +27 -71
  45. package/dist/extensions/bootstrap.js +85 -329
  46. package/dist/extensions/guide-places.d.ts +9 -0
  47. package/dist/extensions/guide-places.js +32 -22
  48. package/dist/extensions/permission-set.d.ts +1 -1
  49. package/dist/extensions/permission-set.js +1 -1
  50. package/dist/extensions/plugin-guides.d.ts +20 -2
  51. package/dist/extensions/plugin-guides.js +39 -14
  52. package/dist/identity/sso-paths.d.ts +7 -0
  53. package/dist/identity/sso-paths.js +13 -0
  54. package/dist/identity/sso.js +3 -2
  55. package/dist/index.d.ts +3 -1
  56. package/dist/index.js +3 -1
  57. package/dist/lifecycle/kernel-lifecycle.js +2 -2
  58. package/dist/platform/exclusions.js +2 -7
  59. package/dist/platform/ops/devices.ops.js +11 -7
  60. package/dist/platform/ops/setup.ops.js +1 -1
  61. package/dist/runtime/project/knowledge.service.js +6 -5
  62. package/dist/sandbox/device-sandbox.d.ts +11 -0
  63. package/dist/sandbox/device-sandbox.js +29 -0
  64. package/dist/sandbox/modes.d.ts +16 -4
  65. package/dist/sandbox/modes.js +12 -0
  66. package/dist/sandbox/permission-facts.d.ts +12 -2
  67. package/dist/sandbox/permission-facts.js +14 -4
  68. package/dist/sandbox/sandbox.service.d.ts +18 -11
  69. package/dist/sandbox/sandbox.service.js +51 -24
  70. package/dist/setup/setup-guides.service.d.ts +2 -2
  71. package/dist/setup/setup-guides.service.js +1 -1
  72. package/dist/tools/approvals.service.d.ts +31 -11
  73. package/dist/tools/approvals.service.js +55 -19
  74. package/dist/tools/builtins/sandbox/common.d.ts +2 -2
  75. package/dist/tools/builtins/sandbox/common.js +2 -2
  76. package/dist/tools/network-asks.d.ts +103 -20
  77. package/dist/tools/network-asks.js +133 -18
  78. package/dist/tools/pipeline.d.ts +5 -0
  79. package/dist/tools/pipeline.js +15 -8
  80. package/package.json +3 -3
  81. package/src/migrations/0178_bootstrap_run_extra.sql +17 -0
@@ -283,8 +283,8 @@ export declare const SCOPE_DENIED_TOOL_TEXT = "This operation reaches outside th
283
283
  export declare const ESCALATION_GRANT_MISSING_TEXT = "This Bash call was approved to run outside the sandbox, but the approval no longer matches: the device, its outside-sandbox setting or this conversation's permission scope changed since it was approved, so it did not run. Call Bash again with sandbox: \"escalated\" and a justification to ask again, or call it without sandbox to run it inside the sandbox.";
284
284
  /** {@link ESCALATION_GRANT_MISSING_TEXT} as the reason of a refused background start. */
285
285
  export declare const ESCALATION_GRANT_MISSING_LAUNCH_WHY = "its approval to run outside the sandbox no longer matches (the device, its outside-sandbox setting or the permission scope changed since it was approved); call Bash again with sandbox: \"escalated\" and a justification to ask again";
286
- /** A staged request the machine never got: it reconnected before the request was sent. */
287
- export declare const DEVICE_REQUEST_NOT_SENT_TOOL_TEXT = "The device's machine reconnected before this operation was sent, so nothing ran. Retry the tool call.";
286
+ /** A request the machine never got: it reconnected, or its instance was gone, before it was sent. */
287
+ export declare const DEVICE_REQUEST_NOT_SENT_TOOL_TEXT = "The device's machine reconnected or changed before this operation was sent, so nothing ran. Retry the tool call.";
288
288
  /** The device itself refused: it cannot enforce its sandbox (`SandboxPermissionUnsupportedError`). */
289
289
  export declare const PERMISSION_UNSUPPORTED_TOOL_TEXT = "This device refused to run the operation because it cannot enforce its sandbox limits, so nothing ran. Ask the device's owner to update its device program (or a super admin to update its device plugin), or continue without the device.";
290
290
  /** Earlier work on the device blocks a new operation (`SandboxWorkUnsettledError`). */
@@ -314,8 +314,8 @@ export const SCOPE_DENIED_TOOL_TEXT = "This operation reaches outside the scope
314
314
  export const ESCALATION_GRANT_MISSING_TEXT = 'This Bash call was approved to run outside the sandbox, but the approval no longer matches: the device, its outside-sandbox setting or this conversation\'s permission scope changed since it was approved, so it did not run. Call Bash again with sandbox: "escalated" and a justification to ask again, or call it without sandbox to run it inside the sandbox.';
315
315
  /** {@link ESCALATION_GRANT_MISSING_TEXT} as the reason of a refused background start. */
316
316
  export const ESCALATION_GRANT_MISSING_LAUNCH_WHY = 'its approval to run outside the sandbox no longer matches (the device, its outside-sandbox setting or the permission scope changed since it was approved); call Bash again with sandbox: "escalated" and a justification to ask again';
317
- /** A staged request the machine never got: it reconnected before the request was sent. */
318
- export const DEVICE_REQUEST_NOT_SENT_TOOL_TEXT = "The device's machine reconnected before this operation was sent, so nothing ran. Retry the tool call.";
317
+ /** A request the machine never got: it reconnected, or its instance was gone, before it was sent. */
318
+ export const DEVICE_REQUEST_NOT_SENT_TOOL_TEXT = "The device's machine reconnected or changed before this operation was sent, so nothing ran. Retry the tool call.";
319
319
  /** The device itself refused: it cannot enforce its sandbox (`SandboxPermissionUnsupportedError`). */
320
320
  export const PERMISSION_UNSUPPORTED_TOOL_TEXT = "This device refused to run the operation because it cannot enforce its sandbox limits, so nothing ran. Ask the device's owner to update its device program (or a super admin to update its device plugin), or continue without the device.";
321
321
  /** Earlier work on the device blocks a new operation (`SandboxWorkUnsettledError`). */
@@ -1,7 +1,7 @@
1
1
  import { type NetworkBlockedHost } from "@capybara-hq/plugin-sdk";
2
2
  import type { NetworkRunState } from "../sandbox/network-grants.js";
3
3
  import { type UnattendedRun } from "../schedules/unattended.js";
4
- import { type ApprovalRecord } from "./approvals.service.js";
4
+ import { type ApprovalRecord, type NetworkAppliesAt } from "./approvals.service.js";
5
5
  /**
6
6
  * Network asks in the tool pipeline (network ask-to-allow spec §6.2, §6.6–§6.9, §8.3): what a
7
7
  * command's reported refusals turn into (an ask to the device owner, or notes written at once) and
@@ -16,10 +16,74 @@ export declare const NETWORK_ASK_CLIPPED_NOTE = "[Output clipped to its first 16
16
16
  /** The idempotency key of a call's `network_blocked` event. */
17
17
  export declare const networkBlockedIdemKey: (runId: string, callId: string) => string;
18
18
  /**
19
- * Asked, allowed this time (a run grant, the only offer: an ask never adds a host to the device's
20
- * own network list, only its owner's network setting does).
19
+ * What a network ask offers (device-provider spec §6.3): only what the device's provider enforces.
20
+ * `once` (a run grant) needs per-operation hosts; `always` adds the hosts to the device's own
21
+ * network list, which takes effect at `appliesAt`.
21
22
  */
23
+ export interface NetworkAskOffer {
24
+ scopes: ("once" | "always")[];
25
+ appliesAt: NetworkAppliesAt;
26
+ }
27
+ /**
28
+ * The offer of a network ask on a device (device-provider spec §6.3): with per-operation hosts
29
+ * (`support.perOperationHosts`, an operation boundary) `once`, plus `always` when every asked host
30
+ * may join the device's own list (`listAddable`), applying from the next command; otherwise
31
+ * `always` only, applying the next time the device is used, or after the files are rebuilt when
32
+ * its provider fixes limits at its file system (`limitsApplyAt: "fileSystem"`). Null: nothing to
33
+ * offer (no per-operation hosts and not addable), so the host is never asked about.
34
+ */
35
+ export declare function networkAskOffer(support: {
36
+ perOperationHosts: boolean;
37
+ }, limitsApplyAt: "instance" | "fileSystem" | undefined, listAddable: boolean): NetworkAskOffer | null;
38
+ /** What a device's sandbox says about what a network ask may offer (`SandboxService.hostRefusal`). */
39
+ export interface DeviceAskFacts {
40
+ /** Why a per-call grant for a host is unavailable (`hostGrantRefusal`), or null. */
41
+ refusal: (host: string) => string | null;
42
+ /** Why a host cannot join the device's own network list (`deviceListAddRefusal`), or null. */
43
+ listAddRefusal: (host: string) => string | null;
44
+ /**
45
+ * `perCallHosts`: the provider gives each operation its own hosts (an operation boundary);
46
+ * `hosts`: the device's effective allowlist (its own list within the org's hosts, else the org's
47
+ * hosts), what the device should allow.
48
+ */
49
+ box: {
50
+ perCallHosts: boolean;
51
+ hosts: readonly string[];
52
+ };
53
+ /** The device's network is an allowlist with a host list of its own. */
54
+ ownList: boolean;
55
+ /** That list's hosts (entries may be `*.` patterns). */
56
+ ownHosts: readonly string[];
57
+ limitsApplyAt: "instance" | "fileSystem" | undefined;
58
+ }
59
+ /**
60
+ * The plan's `refusal` and `offer` on a device (device-provider spec §6.3). With per-operation
61
+ * hosts a host is offered unless a per-call grant is unavailable; without, unless it cannot join
62
+ * the device's own list (so a host outside the org's effective hosts is never offered). `always`
63
+ * is offered only when the device has a list of its own and every asked host may join it (what
64
+ * `addNetworkHostsIn` accepts), so an offered decision does not fail for that.
65
+ */
66
+ export declare function deviceAskTerms(f: DeviceAskFacts): Required<Pick<NetworkPlanContext, "refusal" | "offer" | "onList" | "deviceBlocks">>;
67
+ /** Asked, allowed this time (a run grant: "once"). */
22
68
  export declare const allowedOnceNote: (hosts: readonly string[]) => string;
69
+ /**
70
+ * Asked, added to the device's own network list ("always", device-provider spec §6.3): the hosts
71
+ * apply at `appliesAt`, never to the command that asked, which is not run again.
72
+ */
73
+ export declare const addedToDeviceNote: (hosts: readonly string[], appliesAt: NetworkAppliesAt) => string;
74
+ /**
75
+ * Not asked: the device's network settings already allow the host (its own list, added by an
76
+ * earlier answer or on the device page, or the org's hosts it follows), but its sandbox has not
77
+ * applied them yet; they apply at `appliesAt`, not to this command (device-provider spec §6.3).
78
+ */
79
+ export declare const onListNote: (hosts: readonly string[], appliesAt: NetworkAppliesAt) => string;
80
+ /**
81
+ * Not asked: on a device whose operations each carry its own host list, the list allows the host
82
+ * and it went out with the command, so the refusal comes from the device itself (such as
83
+ * its owner's local policy on the machine, device-provider spec §7.3); nothing in the
84
+ * conversation changes it.
85
+ */
86
+ export declare const deviceOwnBlockNote: (hosts: readonly string[]) => string;
23
87
  /** Asked and declined (also the unchecked hosts of a partial decision, and a host refused earlier in the run). */
24
88
  export declare const deniedNote: (hosts: readonly string[], reason?: string | null) => string;
25
89
  /** Asked, no answer within the approval timeout. */
@@ -72,10 +136,11 @@ export declare const unattendedNetworkNote: (hosts: readonly string[]) => string
72
136
  /** What the pipeline knows when a command reported refused hosts. */
73
137
  export interface NetworkPlanContext {
74
138
  /**
75
- * The device's provider enforces a sandbox allowlist (its permission support): only then is a
76
- * device-layer host asked about (absent: never).
139
+ * What an ask about `hosts` would offer on the device ({@link networkAskOffer}); null: nothing,
140
+ * so those hosts get an unavailable note. Absent (no device sandbox known): a device-layer host
141
+ * is never asked about.
77
142
  */
78
- allowlist?: boolean;
143
+ offer?: (hosts: string[]) => NetworkAskOffer | null;
79
144
  /** The scheduled task run the run serves (null / undefined: attended). */
80
145
  unattended: UnattendedRun | null | undefined;
81
146
  /**
@@ -84,10 +149,23 @@ export interface NetworkPlanContext {
84
149
  */
85
150
  outsideCeiling?: (host: string) => boolean;
86
151
  /**
87
- * Why a per-call grant for a host is unavailable on the device (`hostGrantRefusal`), or null when
88
- * one may be granted: an unavailable host is never asked about, its note names who adds it.
152
+ * Why a host cannot be offered on the device, or null when it may: with per-operation hosts why
153
+ * a per-call grant is unavailable (`hostGrantRefusal`), else why it cannot join the device's own
154
+ * list (`deviceListAddRefusal`). An unavailable host is never asked about; its note names who
155
+ * adds it.
89
156
  */
90
157
  refusal?: (host: string) => string | null;
158
+ /**
159
+ * When a host the device's network settings already allow (its own list, or its org's hosts when
160
+ * it follows them) applies there, or null when they do not allow it: such a host is not asked
161
+ * again, its note says when it applies.
162
+ */
163
+ onList?: (host: string) => NetworkAppliesAt | null;
164
+ /**
165
+ * Whether a device-layer refusal of a host comes from the device itself (its own list allows the
166
+ * host and every operation carries it): never asked, {@link deviceOwnBlockNote}.
167
+ */
168
+ deviceBlocks?: (host: string) => boolean;
91
169
  /**
92
170
  * {@link addressEscalationHint}: a private-address block of an attended run answers with the
93
171
  * escalation hint.
@@ -101,14 +179,13 @@ export interface NetworkPlanContext {
101
179
  }
102
180
  /** What to do with a command's refused hosts. */
103
181
  export interface NetworkPlan {
104
- /**
105
- * The device-layer hosts to ask the device owner about (empty: no ask). The ask offers a run
106
- * grant only; the owner adds a host to the device's own list on its page.
107
- */
182
+ /** The device-layer hosts to ask the device owner about (empty: no ask). */
108
183
  ask: {
109
184
  host: string;
110
185
  port: number;
111
186
  }[];
187
+ /** What the ask offers (present exactly when `ask` is not empty). */
188
+ offer?: NetworkAskOffer;
112
189
  /** Notes written now, after the command output (one line per outcome). */
113
190
  notes: string[];
114
191
  /** `missing_grants` keys of an unattended run (`network:<host>`). */
@@ -124,22 +201,28 @@ export declare function blockedEventHosts(blocked: readonly NetworkBlockedHost[]
124
201
  * an `address` host under the open network on a device that allows running outside the sandbox
125
202
  * gets the escalation hint; an `org` host whose grant is unavailable names who adds it;
126
203
  * `unknown`: nothing (the device's trailer explains);
127
- * - a `device` host whose per-call grant is unavailable (`ctx.refusal`: a provider without
128
- * per-operation hosts, or beyond the org's or platform's allowlist ceiling): a note naming who
129
- * adds it, never an ask;
130
- * - `device` layer on a provider that enforces no allowlist: nothing (no ask);
204
+ * - a `device` host that cannot be offered (`ctx.refusal`: beyond the org's or platform's
205
+ * allowlist ceiling, or on a device without per-operation hosts one its own list cannot take):
206
+ * a note naming who adds it, never an ask;
207
+ * - `device` layer with no device sandbox known (no `ctx.offer`): nothing (no ask);
208
+ * - a `device` host the device itself refused although its own list allows it and the operation
209
+ * carried that list (`ctx.deviceBlocks`): a note saying so, never asked;
210
+ * - a `device` host the device's settings already allow (`ctx.onList`: not yet applied to the
211
+ * instance): a note saying when it applies, never asked again;
131
212
  * - approved by the scheduled task the run serves (`run.taskGranted`) yet refused: a note that
132
213
  * the device ignores the task's grants (never asked, never a missing grant);
133
214
  * - refused earlier in the run tree: the denied note; an unattended run in `fail` mode: its note
134
215
  * and a missing grant;
135
- * - the rest is asked, unless another ask of the run tree is pending or the run made
136
- * {@link MAX_NETWORK_ASKS_PER_RUN} asks (a note each).
216
+ * - the rest is asked with `ctx.offer`'s offer (none: an unavailable note each), unless another
217
+ * ask of the run tree is pending or the run made {@link MAX_NETWORK_ASKS_PER_RUN} asks (a note
218
+ * each).
137
219
  */
138
220
  export declare function planNetworkAsk(blocked: readonly NetworkBlockedHost[], run: NetworkRunState | null, ctx: NetworkPlanContext): NetworkPlan;
139
221
  /**
140
222
  * The note of a settled network ask (spec §6.6): one line per outcome. An approval allows
141
- * `detail.grantedHosts` for the run and declines the hosts
142
- * left unchecked; `hours` is the ask's own wait (created to expiry). Null while it is pending.
223
+ * `detail.grantedHosts` for the run (`once`) or added them to the device's own list (`always`,
224
+ * applying at `detail.appliesAt`) and declines the hosts left unchecked; `hours` is the ask's own
225
+ * wait (created to expiry). Null while it is pending.
143
226
  */
144
227
  export declare function settledNetworkNotes(a: ApprovalRecord, hours: number): string[] | null;
145
228
  /** `text` followed by `notes` after a blank line (unchanged without notes). */
@@ -1,8 +1,9 @@
1
1
  import { validateAllowHost } from "@capybara-hq/plugin-sdk";
2
2
  import { NETWORK_ASK_MAX_HOSTS, NETWORK_HOST_MAX_CHARS } from "../conversations/events.js";
3
+ import { coversHost } from "../sandbox/modes.js";
3
4
  import { ESCALATION_UNATTENDED_WHY } from "../sandbox/review/permission-candidate.js";
4
5
  import { networkGrantKey, unattendedFails, unattendedRules, } from "../schedules/unattended.js";
5
- import { NETWORK_ASK_CANCELLED_NOTE } from "./approvals.service.js";
6
+ import { NETWORK_ASK_CANCELLED_NOTE, } from "./approvals.service.js";
6
7
  /**
7
8
  * Network asks in the tool pipeline (network ask-to-allow spec §6.2, §6.6–§6.9, §8.3): what a
8
9
  * command's reported refusals turn into (an ask to the device owner, or notes written at once) and
@@ -22,10 +23,93 @@ const pron = (hosts) => (one(hosts) ? "it" : "them");
22
23
  /** "x was blocked by this device's network policy." (the lead of every device-layer note). */
23
24
  const blockedLead = (hosts) => `[network] ${list(hosts)} ${one(hosts) ? "was" : "were"} blocked by this device's network policy.`;
24
25
  /**
25
- * Asked, allowed this time (a run grant, the only offer: an ask never adds a host to the device's
26
- * own network list, only its owner's network setting does).
26
+ * The offer of a network ask on a device (device-provider spec §6.3): with per-operation hosts
27
+ * (`support.perOperationHosts`, an operation boundary) `once`, plus `always` when every asked host
28
+ * may join the device's own list (`listAddable`), applying from the next command; otherwise
29
+ * `always` only, applying the next time the device is used, or after the files are rebuilt when
30
+ * its provider fixes limits at its file system (`limitsApplyAt: "fileSystem"`). Null: nothing to
31
+ * offer (no per-operation hosts and not addable), so the host is never asked about.
27
32
  */
33
+ export function networkAskOffer(support, limitsApplyAt, listAddable) {
34
+ if (support.perOperationHosts)
35
+ return { scopes: listAddable ? ["once", "always"] : ["once"], appliesAt: "next-command" };
36
+ if (!listAddable)
37
+ return null;
38
+ return {
39
+ scopes: ["always"],
40
+ appliesAt: limitsApplyAt === "fileSystem" ? "files-reset" : "next-use",
41
+ };
42
+ }
43
+ /**
44
+ * The plan's `refusal` and `offer` on a device (device-provider spec §6.3). With per-operation
45
+ * hosts a host is offered unless a per-call grant is unavailable; without, unless it cannot join
46
+ * the device's own list (so a host outside the org's effective hosts is never offered). `always`
47
+ * is offered only when the device has a list of its own and every asked host may join it (what
48
+ * `addNetworkHostsIn` accepts), so an offered decision does not fail for that.
49
+ */
50
+ export function deviceAskTerms(f) {
51
+ const perOperationHosts = f.box.perCallHosts;
52
+ const appliesAt = perOperationHosts
53
+ ? "next-command"
54
+ : f.limitsApplyAt === "fileSystem"
55
+ ? "files-reset"
56
+ : "next-use";
57
+ return {
58
+ refusal: perOperationHosts ? f.refusal : f.listAddRefusal,
59
+ // a host the device's network settings already allow (its own list, else the org's hosts it
60
+ // follows), refused because the instance does not have it yet: it applies when a network
61
+ // change applies, so it is not asked again. Only a host the list can carry (the org's hosts
62
+ // still cover it): an entry the org dropped since is in effect nowhere and never applies.
63
+ // With per-operation hosts every operation carries the list, so there is nothing pending
64
+ onList: (host) => {
65
+ if (perOperationHosts)
66
+ return null;
67
+ const h = host.toLowerCase();
68
+ const allowed = f.ownList ? f.ownHosts : f.box.hosts;
69
+ if (!allowed.some((p) => coversHost(p.toLowerCase(), h)))
70
+ return null;
71
+ if (f.listAddRefusal(h) !== null)
72
+ return null;
73
+ return appliesAt;
74
+ },
75
+ // with per-operation hosts, a host the device's own list carries (within the org's hosts, its
76
+ // effective allowlist) went out with the operation: a device-layer refusal of it comes from the
77
+ // device itself
78
+ deviceBlocks: (host) => {
79
+ if (!perOperationHosts || !f.ownList)
80
+ return false;
81
+ const h = host.toLowerCase();
82
+ return f.box.hosts.some((p) => coversHost(p.toLowerCase(), h));
83
+ },
84
+ offer: (hosts) => networkAskOffer({ perOperationHosts }, f.limitsApplyAt, f.ownList && hosts.length > 0 && hosts.every((h) => f.listAddRefusal(h) === null)),
85
+ };
86
+ }
87
+ /** When a host added to the device's list applies, as the model reads it. */
88
+ const APPLIES_TEXT = {
89
+ "next-command": "from the next command",
90
+ "next-use": "the next time the device is used",
91
+ "files-reset": "after the files are rebuilt",
92
+ };
93
+ /** Asked, allowed this time (a run grant: "once"). */
28
94
  export const allowedOnceNote = (hosts) => `${blockedLead(hosts)} The user allowed ${pron(hosts)} for the rest of this task. Run the command again.`;
95
+ /**
96
+ * Asked, added to the device's own network list ("always", device-provider spec §6.3): the hosts
97
+ * apply at `appliesAt`, never to the command that asked, which is not run again.
98
+ */
99
+ export const addedToDeviceNote = (hosts, appliesAt) => `${blockedLead(hosts)} The person added ${list(hosts)} to this device's network list; it applies ${APPLIES_TEXT[appliesAt]}. This command is not run again.`;
100
+ /**
101
+ * Not asked: the device's network settings already allow the host (its own list, added by an
102
+ * earlier answer or on the device page, or the org's hosts it follows), but its sandbox has not
103
+ * applied them yet; they apply at `appliesAt`, not to this command (device-provider spec §6.3).
104
+ */
105
+ export const onListNote = (hosts, appliesAt) => `${blockedLead(hosts)} This device's network settings already allow ${pron(hosts)}, but its sandbox has not applied them yet; they apply ${APPLIES_TEXT[appliesAt]}. Continue without ${pron(hosts)} until then or tell the user.`;
106
+ /**
107
+ * Not asked: on a device whose operations each carry its own host list, the list allows the host
108
+ * and it went out with the command, so the refusal comes from the device itself (such as
109
+ * its owner's local policy on the machine, device-provider spec §7.3); nothing in the
110
+ * conversation changes it.
111
+ */
112
+ export const deviceOwnBlockNote = (hosts) => `${blockedLead(hosts)} This device's network settings allow ${pron(hosts)} and every command carries them, so the block comes from the device itself (such as its owner's local network policy on the machine); it cannot be allowed from this conversation. Continue without ${pron(hosts)} or tell the user.`;
29
113
  /** Asked and declined (also the unchecked hosts of a partial decision, and a host refused earlier in the run). */
30
114
  export const deniedNote = (hosts, reason) => `${blockedLead(hosts)} The user declined access to ${list(hosts)}. Do not try to reach ${pron(hosts)} another way; continue without ${pron(hosts)} or ask the user.` +
31
115
  (reason != null && reason !== "" ? ` Reason: ${reason}` : "");
@@ -113,16 +197,21 @@ export function blockedEventHosts(blocked) {
113
197
  * an `address` host under the open network on a device that allows running outside the sandbox
114
198
  * gets the escalation hint; an `org` host whose grant is unavailable names who adds it;
115
199
  * `unknown`: nothing (the device's trailer explains);
116
- * - a `device` host whose per-call grant is unavailable (`ctx.refusal`: a provider without
117
- * per-operation hosts, or beyond the org's or platform's allowlist ceiling): a note naming who
118
- * adds it, never an ask;
119
- * - `device` layer on a provider that enforces no allowlist: nothing (no ask);
200
+ * - a `device` host that cannot be offered (`ctx.refusal`: beyond the org's or platform's
201
+ * allowlist ceiling, or on a device without per-operation hosts one its own list cannot take):
202
+ * a note naming who adds it, never an ask;
203
+ * - `device` layer with no device sandbox known (no `ctx.offer`): nothing (no ask);
204
+ * - a `device` host the device itself refused although its own list allows it and the operation
205
+ * carried that list (`ctx.deviceBlocks`): a note saying so, never asked;
206
+ * - a `device` host the device's settings already allow (`ctx.onList`: not yet applied to the
207
+ * instance): a note saying when it applies, never asked again;
120
208
  * - approved by the scheduled task the run serves (`run.taskGranted`) yet refused: a note that
121
209
  * the device ignores the task's grants (never asked, never a missing grant);
122
210
  * - refused earlier in the run tree: the denied note; an unattended run in `fail` mode: its note
123
211
  * and a missing grant;
124
- * - the rest is asked, unless another ask of the run tree is pending or the run made
125
- * {@link MAX_NETWORK_ASKS_PER_RUN} asks (a note each).
212
+ * - the rest is asked with `ctx.offer`'s offer (none: an unavailable note each), unless another
213
+ * ask of the run tree is pending or the run made {@link MAX_NETWORK_ASKS_PER_RUN} asks (a note
214
+ * each).
126
215
  */
127
216
  export function planNetworkAsk(blocked, run, ctx) {
128
217
  const address = [];
@@ -134,8 +223,8 @@ export function planNetworkAsk(blocked, run, ctx) {
134
223
  const candidates = [];
135
224
  const missingGrants = [];
136
225
  const unavailable = [];
137
- // only a provider that enforces an allowlist blocks a host at the device layer
138
- const canAsk = ctx.allowlist === true;
226
+ const onList = [];
227
+ const deviceOwn = [];
139
228
  for (const b of hostsOf(blocked)) {
140
229
  if (b.layer === "address")
141
230
  address.push(b.host);
@@ -151,15 +240,20 @@ export function planNetworkAsk(blocked, run, ctx) {
151
240
  missingGrants.push(networkGrantKey(b.host));
152
241
  }
153
242
  else if (b.layer === "device") {
154
- if (!canAsk)
243
+ if (ctx.offer === undefined)
155
244
  continue;
156
245
  const why = ctx.refusal?.(b.host) ?? null;
157
246
  // relayer already made an invalid name an address; a wildcard is never asked
247
+ const listed = ctx.onList?.(b.host) ?? null;
158
248
  if (b.host.startsWith("*.") || validateAllowHost(b.host).length > 0) {
159
249
  address.push(b.host);
160
250
  }
161
251
  else if (why !== null)
162
252
  unavailable.push(unavailableHostNote(b.host, why));
253
+ else if (ctx.deviceBlocks?.(b.host) === true)
254
+ deviceOwn.push(b.host);
255
+ else if (listed !== null)
256
+ onList.push({ host: b.host, appliesAt: listed });
163
257
  else if (run?.taskGranted?.has(b.host))
164
258
  taskIgnored.push(b.host);
165
259
  else if (run?.refused.has(b.host))
@@ -179,15 +273,28 @@ export function planNetworkAsk(blocked, run, ctx) {
179
273
  notes.push(taskGrantIgnoredNote(taskIgnored));
180
274
  if (unattended.length > 0)
181
275
  notes.push(unattendedNetworkNote(unattended));
276
+ for (const at of ["next-command", "next-use", "files-reset"]) {
277
+ const hosts = onList.filter((o) => o.appliesAt === at).map((o) => o.host);
278
+ if (hosts.length > 0)
279
+ notes.push(onListNote(hosts, at));
280
+ }
281
+ if (deviceOwn.length > 0)
282
+ notes.push(deviceOwnBlockNote(deviceOwn));
182
283
  let ask = [];
284
+ let offer = null;
183
285
  if (candidates.length > 0) {
286
+ const asked = candidates.slice(0, NETWORK_ASK_MAX_HOSTS);
184
287
  const names = candidates.map((c) => c.host);
185
- if (run?.pending === true)
288
+ offer = ctx.offer?.(asked.map((c) => c.host)) ?? null;
289
+ if (offer === null)
290
+ for (const h of names)
291
+ unavailable.push(unavailableHostNote(h, NO_OFFER_WHY));
292
+ else if (run?.pending === true)
186
293
  notes.push(otherAskPendingNote(names));
187
294
  else if ((run?.asks ?? 0) >= MAX_NETWORK_ASKS_PER_RUN)
188
295
  notes.push(tooManyNote(names));
189
296
  else
190
- ask = candidates.slice(0, NETWORK_ASK_MAX_HOSTS);
297
+ ask = asked;
191
298
  }
192
299
  notes.push(...unavailable);
193
300
  if (org.length > 0)
@@ -198,12 +305,18 @@ export function planNetworkAsk(blocked, run, ctx) {
198
305
  notes.push(ctx.escalation === true && ctx.unattended == null
199
306
  ? addressEscalationNote(address)
200
307
  : addressLayerNote(address, ctx.unattended != null ? ESCALATION_UNATTENDED_WHY : ctx.escalationRefusal));
201
- return { ask, notes, missingGrants };
308
+ return { ask, ...(ask.length > 0 && offer !== null && { offer }), notes, missingGrants };
202
309
  }
310
+ /**
311
+ * Why a host is not asked about where nothing can be offered (a device with no own list whose
312
+ * settings do not allow the host).
313
+ */
314
+ const NO_OFFER_WHY = "the device's owner changes the device's network on its page";
203
315
  /**
204
316
  * The note of a settled network ask (spec §6.6): one line per outcome. An approval allows
205
- * `detail.grantedHosts` for the run and declines the hosts
206
- * left unchecked; `hours` is the ask's own wait (created to expiry). Null while it is pending.
317
+ * `detail.grantedHosts` for the run (`once`) or added them to the device's own list (`always`,
318
+ * applying at `detail.appliesAt`) and declines the hosts left unchecked; `hours` is the ask's own
319
+ * wait (created to expiry). Null while it is pending.
207
320
  */
208
321
  export function settledNetworkNotes(a, hours) {
209
322
  const asked = (a.detail?.hosts ?? []).map((h) => h.host);
@@ -213,7 +326,9 @@ export function settledNetworkNotes(a, hours) {
213
326
  const rest = asked.filter((h) => !granted.includes(h));
214
327
  const notes = [];
215
328
  if (granted.length > 0) {
216
- notes.push(allowedOnceNote(granted));
329
+ notes.push(a.scope === "always" && a.detail !== null
330
+ ? addedToDeviceNote(granted, a.detail.appliesAt)
331
+ : allowedOnceNote(granted));
217
332
  }
218
333
  if (rest.length > 0)
219
334
  notes.push(deniedNote(rest));
@@ -372,6 +372,11 @@ export type ExecOutcome =
372
372
  export declare const PERMISSION_SUPPORT_UNVERIFIED_TEXT = "This call needs access outside the working directory, but this device's permission support is not verified yet, so only paths inside the working directory work now. Keep the call inside the working directory, or retry once the device is ready.";
373
373
  /** What the model gets when the permission check of its call refused (fail closed). */
374
374
  export declare const permissionCheckFailedText: (why: string) => string;
375
+ /**
376
+ * `ToolCallContext.idempotencyKey`: one logical call's key (a call id is unique only within its
377
+ * run), the same for every `InputRequired` round of the call.
378
+ */
379
+ export declare const toolIdempotencyKey: (conversationId: string, runId: string, callId: string) => string;
375
380
  /**
376
381
  * 工具执行管线(spec 5.4 / 6.2):每个阶段是独立函数——
377
382
  * `resolveOutputRefs` → `validateInput` → `decidePolicy` → `execute`(超时、熔断)→ `renderResult` / `spillIfLarge`
@@ -66,7 +66,7 @@ import { canonicalJson } from "./canonical-json.js";
66
66
  import { CredentialMissing, Credentials } from "./credentials.js";
67
67
  import { ToolDrift } from "./drift.js";
68
68
  import { ElicitationSession } from "./elicitation.js";
69
- import { addressEscalationHint, blockedEventHosts, clipKept, NETWORK_ASK_KEPT_MAX_BYTES, networkBlockedIdemKey, planNetworkAsk, settledNetworkNotes, withNetworkNotes, } from "./network-asks.js";
69
+ import { addressEscalationHint, blockedEventHosts, clipKept, deviceAskTerms, NETWORK_ASK_KEPT_MAX_BYTES, networkBlockedIdemKey, planNetworkAsk, settledNetworkNotes, withNetworkNotes, } from "./network-asks.js";
70
70
  import { OrgToolSwitches, toolTurnedOffReason } from "./org-tool-switches.js";
71
71
  import { renderResult, resolveOutputRefs, spillIfLarge, ToolOutputs } from "./outputs.js";
72
72
  import { createDecidePolicy } from "./policy.js";
@@ -360,6 +360,11 @@ const idem = {
360
360
  connection: (runId, callId) => `connection_required:${runId}:${callId}`,
361
361
  hookDenied: (runId, callId) => `hook_denied:${runId}:${callId}`,
362
362
  };
363
+ /**
364
+ * `ToolCallContext.idempotencyKey`: one logical call's key (a call id is unique only within its
365
+ * run), the same for every `InputRequired` round of the call.
366
+ */
367
+ export const toolIdempotencyKey = (conversationId, runId, callId) => sha256Hex(`capybara:tool-call:${conversationId}:${runId}:${callId}`);
363
368
  /** 同一调用最多连续请求用户输入的次数。 */
364
369
  const MAX_INPUT_ROUNDS = 3;
365
370
  /** 输入请求 state 的上限(JSON 序列化后的字节数)。 */
@@ -2040,9 +2045,9 @@ let ToolPipeline = class ToolPipeline {
2040
2045
  ? await network.grants.runState(ctx.runId, report.deviceId)
2041
2046
  : null;
2042
2047
  const limits = this.config.get().sandbox.limits;
2043
- // the per-call host ceiling decides what is worth asking: a host a per-call grant cannot
2044
- // reach on this device (its provider, the org's or the platform's allowlist ceiling) is
2045
- // unavailable, never asked about
2048
+ // the ask offers what the device's provider enforces (device-provider spec §6.3): a run grant
2049
+ // only with per-operation hosts, "add to this device's list" only for hosts its own list can
2050
+ // take; a host neither reaches is unavailable, never asked about
2046
2051
  const sandbox = await network.sandbox?.hostRefusal({
2047
2052
  orgId: ctx.orgId,
2048
2053
  deviceId: report.deviceId,
@@ -2051,8 +2056,7 @@ let ToolPipeline = class ToolPipeline {
2051
2056
  unattended: ctx.unattended,
2052
2057
  outsideCeiling: (h) => orgHostOutsideCeiling(limits, h),
2053
2058
  ...(sandbox !== undefined && {
2054
- allowlist: sandbox.allowlist,
2055
- refusal: sandbox.refusal,
2059
+ ...deviceAskTerms(sandbox),
2056
2060
  // the hint follows admission's verdict for this call (never a recomputation), and only
2057
2061
  // the open network makes a private address the one thing escalation adds
2058
2062
  escalation: addressEscalationHint(escalation, sandbox.box.networkMode),
@@ -2064,7 +2068,8 @@ let ToolPipeline = class ToolPipeline {
2064
2068
  await appendMissingGrant(this.deps.db, ctx.unattended.taskRunId, key);
2065
2069
  }
2066
2070
  }
2067
- if (plan.ask.length === 0)
2071
+ const offer = plan.offer;
2072
+ if (plan.ask.length === 0 || offer === undefined)
2068
2073
  return { kind: "write", event, notes: plan.notes };
2069
2074
  // the device's owner is the only person who may decide (spec §5.2)
2070
2075
  const owner = await this.deps.db
@@ -2111,9 +2116,10 @@ let ToolPipeline = class ToolPipeline {
2111
2116
  hosts: plan.ask,
2112
2117
  command: typeof given.command === "string" ? clipText(given.command, 2000) : "",
2113
2118
  description: typeof given.description === "string" ? given.description : null,
2119
+ appliesAt: offer.appliesAt,
2114
2120
  result: kept,
2115
2121
  },
2116
- scopes: ["once"],
2122
+ scopes: offer.scopes,
2117
2123
  });
2118
2124
  return { kind: "wait", wait: approvalWait(ask), content: kept.content };
2119
2125
  }
@@ -2299,6 +2305,7 @@ let ToolPipeline = class ToolPipeline {
2299
2305
  agentId: ctx.agentId,
2300
2306
  conversationId: ctx.conversationId,
2301
2307
  callId,
2308
+ idempotencyKey: toolIdempotencyKey(ctx.conversationId, ctx.runId, callId),
2302
2309
  ...(resume !== undefined && { resume }),
2303
2310
  // who and where (memory plugin spec §6.2): `accountId` stays the trigger account
2304
2311
  source: ctx.source,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.72",
3
+ "version": "0.1.0-rc.74",
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.56"
69
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.59"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@langchain/langgraph-checkpoint-validation": "^1.2.0",
@@ -75,7 +75,7 @@
75
75
  "@types/ws": "^8.18.2",
76
76
  "@types/yauzl": "3.4.0",
77
77
  "ws": "^8.22.0",
78
- "@capybara-hq/testing": "0.1.0-rc.35"
78
+ "@capybara-hq/testing": "0.1.0-rc.37"
79
79
  },
80
80
  "scripts": {
81
81
  "build": "tsc -b"
@@ -0,0 +1,17 @@
1
+ -- Bootstrap extra manifest follow-ups (spec 2026-11-20-bootstrap-extra-manifest, "As built" R18, R19).
2
+ -- - bootstrap_runs.extra_sha256: sha256 of what the extra manifest contributed to the run (NULL
3
+ -- without one, and in rows written before this column). A recorded run counts as done only while
4
+ -- the latest completed run has the same extra part, so re-adding an extra manifest after its
5
+ -- removal runs it again (R18).
6
+ -- - bootstrap_run_started: at most one row, the run that has written but not completed yet, with
7
+ -- the names of its extra entries. A process without an extra manifest reads it as a trace before
8
+ -- the first run with that manifest completes (R19); completing a run deletes it.
9
+ ALTER TABLE bootstrap_runs ADD COLUMN IF NOT EXISTS extra_sha256 text
10
+ CHECK (extra_sha256 ~ '^[0-9a-f]{64}$');
11
+
12
+ CREATE TABLE IF NOT EXISTS bootstrap_run_started (
13
+ singleton boolean PRIMARY KEY DEFAULT true CHECK (singleton),
14
+ manifest_sha256 text NOT NULL CHECK (manifest_sha256 ~ '^[0-9a-f]{64}$'),
15
+ extra_plugins jsonb NOT NULL,
16
+ started_at timestamptz NOT NULL
17
+ );