@capybara-hq/kernel 0.1.0-rc.73 → 0.1.0-rc.75
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 +5 -5
- package/dist/catalog/admin-catalog.schemas.d.ts +3 -1
- package/dist/catalog/admin-catalog.schemas.js +6 -2
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.schemas.d.ts +3 -1
- package/dist/catalog/org-catalog.schemas.js +3 -1
- package/dist/catalog/plugin-package.js +7 -5
- package/dist/catalog/reserved-names.js +3 -9
- package/dist/channels/actions.js +4 -0
- package/dist/channels/cards.d.ts +10 -7
- package/dist/channels/cards.js +23 -12
- package/dist/channels/phrases.d.ts +24 -2
- package/dist/channels/phrases.js +12 -2
- package/dist/ctx/secrets.d.ts +4 -2
- package/dist/ctx/secrets.js +19 -5
- package/dist/db/kernel-schema.d.ts +14 -0
- package/dist/devices/conversation-devices.d.ts +3 -2
- package/dist/devices/conversation-devices.js +9 -4
- package/dist/devices/device-projects.service.d.ts +22 -27
- package/dist/devices/device-projects.service.js +39 -44
- package/dist/devices/devices.controller.d.ts +3 -5
- package/dist/devices/devices.controller.js +4 -17
- package/dist/devices/devices.schemas.d.ts +1 -1
- package/dist/devices/devices.schemas.js +1 -1
- package/dist/devices/devices.service.d.ts +75 -52
- package/dist/devices/devices.service.js +166 -95
- package/dist/devices/project-rules.d.ts +6 -8
- package/dist/devices/project-rules.js +5 -11
- package/dist/dial-in/auth.service.js +1 -1
- package/dist/dial-in/machines.d.ts +4 -15
- package/dist/dial-in/machines.js +4 -59
- package/dist/errors.d.ts +8 -3
- package/dist/errors.js +8 -3
- package/dist/extensions/admin-ops.js +2 -1
- package/dist/extensions/bootstrap-extra.d.ts +11 -1
- package/dist/extensions/bootstrap-extra.js +21 -1
- package/dist/extensions/bootstrap-manifest.d.ts +14 -0
- package/dist/extensions/bootstrap-manifest.js +23 -0
- package/dist/extensions/bootstrap-packages.d.ts +87 -0
- package/dist/extensions/bootstrap-packages.js +263 -0
- package/dist/extensions/bootstrap.d.ts +27 -71
- package/dist/extensions/bootstrap.js +85 -329
- package/dist/extensions/guide-places.d.ts +9 -0
- package/dist/extensions/guide-places.js +32 -22
- package/dist/extensions/plugin-guides.d.ts +20 -2
- package/dist/extensions/plugin-guides.js +39 -14
- package/dist/http/meta.controller.d.ts +0 -1
- package/dist/http/meta.controller.js +2 -6
- package/dist/identity/sso-paths.d.ts +7 -0
- package/dist/identity/sso-paths.js +13 -0
- package/dist/identity/sso.js +3 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +2 -2
- package/dist/platform/exclusions.js +2 -7
- package/dist/platform/ops/devices.ops.js +11 -7
- package/dist/platform/ops/setup.ops.js +1 -1
- package/dist/runtime/project/knowledge.service.js +6 -5
- package/dist/sandbox/device-sandbox.d.ts +27 -2
- package/dist/sandbox/device-sandbox.js +42 -5
- package/dist/sandbox/modes.d.ts +16 -4
- package/dist/sandbox/modes.js +12 -0
- package/dist/sandbox/operation-authority.js +3 -1
- package/dist/sandbox/permission-authority-lock.d.ts +6 -0
- package/dist/sandbox/permission-authority-lock.js +14 -0
- package/dist/sandbox/permission-facts.d.ts +16 -2
- package/dist/sandbox/permission-facts.js +20 -5
- package/dist/sandbox/review/permission-candidate.d.ts +12 -7
- package/dist/sandbox/review/permission-candidate.js +28 -7
- package/dist/sandbox/sandbox.service.d.ts +18 -11
- package/dist/sandbox/sandbox.service.js +51 -24
- package/dist/setup/setup-guides.service.d.ts +3 -4
- package/dist/setup/setup-guides.service.js +2 -5
- package/dist/shares/sweep.job.d.ts +2 -0
- package/dist/shares/sweep.job.js +3 -1
- package/dist/tools/approvals.service.d.ts +31 -11
- package/dist/tools/approvals.service.js +55 -19
- package/dist/tools/builtins/sandbox/common.d.ts +2 -2
- package/dist/tools/builtins/sandbox/common.js +2 -2
- package/dist/tools/network-asks.d.ts +103 -20
- package/dist/tools/network-asks.js +133 -18
- package/dist/tools/pipeline.d.ts +5 -0
- package/dist/tools/pipeline.js +15 -8
- package/package.json +3 -3
- package/src/migrations/0178_bootstrap_run_extra.sql +17 -0
|
@@ -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
|
-
*
|
|
26
|
-
*
|
|
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
|
|
117
|
-
*
|
|
118
|
-
* adds it, never an ask;
|
|
119
|
-
* - `device` layer
|
|
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
|
|
125
|
-
* {@link MAX_NETWORK_ASKS_PER_RUN} asks (a note
|
|
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
|
-
|
|
138
|
-
const
|
|
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 (
|
|
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
|
-
|
|
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 =
|
|
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
|
|
206
|
-
* left unchecked; `hours` is the ask's own
|
|
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(
|
|
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));
|
package/dist/tools/pipeline.d.ts
CHANGED
|
@@ -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`
|
package/dist/tools/pipeline.js
CHANGED
|
@@ -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
|
|
2044
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
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.
|
|
3
|
+
"version": "0.1.0-rc.75",
|
|
4
4
|
"description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"yaml": "^2.9.1",
|
|
67
67
|
"yauzl": "3.4.0",
|
|
68
68
|
"zod": "^4.6.7",
|
|
69
|
-
"@capybara-hq/plugin-sdk": "^0.1.0-rc.
|
|
69
|
+
"@capybara-hq/plugin-sdk": "^0.1.0-rc.60"
|
|
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.
|
|
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
|
+
);
|