@capybara-hq/kernel 0.1.0-rc.62 → 0.1.0-rc.64
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 +3 -3
- package/dist/app.d.ts +2 -0
- package/dist/catalog/catalog.service.d.ts +13 -0
- package/dist/catalog/catalog.service.js +17 -8
- package/dist/catalog/git-source.d.ts +8 -0
- package/dist/catalog/git-source.js +14 -6
- package/dist/catalog/marketplaces.controller.d.ts +3 -2
- package/dist/catalog/marketplaces.controller.js +5 -2
- package/dist/catalog/marketplaces.schemas.d.ts +7 -0
- package/dist/catalog/marketplaces.schemas.js +13 -0
- package/dist/catalog/marketplaces.service.d.ts +65 -11
- package/dist/catalog/marketplaces.service.js +208 -30
- package/dist/catalog/org-catalog.schemas.d.ts +1 -1
- package/dist/catalog/org-catalog.schemas.js +1 -1
- package/dist/channels/actions.d.ts +2 -5
- package/dist/channels/actions.js +20 -8
- package/dist/channels/cards.d.ts +4 -3
- package/dist/channels/cards.js +6 -4
- package/dist/channels/outbound.js +3 -2
- package/dist/config/schema.d.ts +2 -0
- package/dist/config/schema.js +22 -2
- package/dist/conversations/approval-profile.d.ts +30 -0
- package/dist/conversations/approval-profile.js +62 -0
- package/dist/conversations/conversations.service.js +0 -2
- package/dist/conversations/events.d.ts +43 -0
- package/dist/conversations/events.js +52 -0
- package/dist/conversations/permission-profiles.controller.d.ts +3 -2
- package/dist/conversations/permission-profiles.service.d.ts +3 -2
- package/dist/conversations/permission-profiles.service.js +12 -8
- package/dist/db/kernel-schema.d.ts +8 -2
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +7 -0
- package/dist/extensions/bootstrap-defaults.d.ts +24 -0
- package/dist/extensions/bootstrap-defaults.js +78 -0
- package/dist/extensions/bootstrap-extra.d.ts +74 -0
- package/dist/extensions/bootstrap-extra.js +131 -0
- package/dist/extensions/bootstrap.d.ts +77 -13
- package/dist/extensions/bootstrap.js +282 -48
- package/dist/identity/initial-passwords.controller.d.ts +8 -6
- package/dist/identity/initial-passwords.controller.js +13 -7
- package/dist/identity/initial-passwords.d.ts +22 -13
- package/dist/identity/initial-passwords.js +25 -29
- package/dist/identity/settings.d.ts +10 -0
- package/dist/identity/settings.js +46 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/kernel.module.js +3 -0
- package/dist/lifecycle/kernel-lifecycle.d.ts +7 -1
- package/dist/lifecycle/kernel-lifecycle.js +69 -16
- package/dist/local-devices/relay.js +3 -1
- package/dist/models/images.js +5 -4
- package/dist/platform/connector-person-fields.js +2 -2
- package/dist/platform/exclusions.js +4 -4
- package/dist/platform/method.js +1 -1
- package/dist/platform/operation.d.ts +9 -7
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/accounts.ops.d.ts +1 -1
- package/dist/platform/ops/accounts.ops.js +3 -3
- package/dist/platform/ops/channels.ops.d.ts +1 -1
- package/dist/platform/ops/channels.ops.js +2 -2
- package/dist/platform/ops/connectors.ops.d.ts +2 -2
- package/dist/platform/ops/connectors.ops.js +8 -8
- package/dist/platform/ops/extensions-admin.ops.d.ts +1 -1
- package/dist/platform/ops/extensions-admin.ops.js +3 -3
- package/dist/platform/ops/extensions.ops.d.ts +1 -1
- package/dist/platform/ops/extensions.ops.js +4 -4
- package/dist/platform/ops/marketplaces.ops.js +27 -4
- package/dist/platform/ops/org-plugins.ops.js +2 -2
- package/dist/platform/ops/orgs.ops.d.ts +1 -1
- package/dist/platform/ops/orgs.ops.js +3 -3
- package/dist/platform/ops/plugins.ops.d.ts +1 -1
- package/dist/platform/ops/plugins.ops.js +2 -2
- package/dist/platform/person-fields.d.ts +4 -3
- package/dist/platform/person-fields.js +6 -5
- package/dist/platform/sealed-inputs.d.ts +2 -2
- package/dist/platform/sealed-inputs.js +2 -2
- package/dist/platform/sealed-reveals.controller.d.ts +5 -8
- package/dist/platform/sealed-reveals.controller.js +8 -8
- package/dist/platform/sealed-reveals.d.ts +19 -17
- package/dist/platform/sealed-reveals.js +30 -33
- package/dist/runtime/context/build.js +3 -0
- package/dist/runtime/context/compaction.js +2 -0
- package/dist/runtime/waits.js +3 -2
- package/dist/sandbox/operation-authority.js +16 -15
- package/dist/sandbox/operation-intents.js +2 -2
- package/dist/sandbox/permission-availability.d.ts +49 -3
- package/dist/sandbox/permission-availability.js +61 -6
- package/dist/sandbox/permission-call-types.d.ts +3 -0
- package/dist/sandbox/permission-facts.d.ts +29 -1
- package/dist/sandbox/permission-facts.js +29 -6
- package/dist/sandbox/review/classifier.d.ts +72 -2
- package/dist/sandbox/review/classifier.js +113 -38
- package/dist/sandbox/review/index.d.ts +2 -2
- package/dist/sandbox/review/index.js +1 -1
- package/dist/sandbox/review/review.service.d.ts +1 -4
- package/dist/sandbox/review/review.service.js +4 -33
- package/dist/setup/setup-guides.service.js +1 -1
- package/dist/tools/approvals.service.d.ts +71 -16
- package/dist/tools/approvals.service.js +139 -13
- package/dist/tools/builtins/builtin-tools.d.ts +1 -1
- package/dist/tools/builtins/builtin-tools.js +12 -6
- package/dist/tools/builtins/platform.d.ts +15 -11
- package/dist/tools/builtins/platform.js +49 -39
- package/dist/tools/builtins/sandbox/bash.d.ts +1 -1
- package/dist/tools/builtins/sandbox/bash.js +32 -14
- package/dist/tools/builtins/sandbox/common.d.ts +12 -3
- package/dist/tools/builtins/sandbox/common.js +29 -5
- package/dist/tools/connectors.schemas.d.ts +1 -1
- package/dist/tools/connectors.schemas.js +1 -1
- package/dist/tools/pipeline.d.ts +70 -10
- package/dist/tools/pipeline.js +356 -48
- package/dist/tools/policy.d.ts +4 -3
- package/dist/tools/policy.js +6 -6
- package/dist/tools/registry.d.ts +25 -9
- package/dist/tools/tool-review.d.ts +113 -0
- package/dist/tools/tool-review.js +303 -0
- package/dist/tools/tools.module.js +6 -0
- package/package.json +4 -4
- package/src/migrations/0174_marketplace_managed_username.sql +4 -0
- package/src/migrations/0175_secure_input_kind.sql +8 -0
|
@@ -13,7 +13,7 @@ import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
|
13
13
|
import { sql } from "kysely";
|
|
14
14
|
import { normalizeStoredDefinition } from "../agents/definition.js";
|
|
15
15
|
import { EventLog } from "../conversations/event-log.js";
|
|
16
|
-
import { COMMAND_ASK_TEXT_MAX_CHARS, GIT_ASK_MAX_REFS, GIT_REF_MAX_CHARS, NETWORK_ASK_MAX_HOSTS, NETWORK_HOST_MAX_CHARS, } from "../conversations/events.js";
|
|
16
|
+
import { COMMAND_ASK_TEXT_MAX_CHARS, GIT_ASK_MAX_REFS, GIT_REF_MAX_CHARS, NETWORK_ASK_MAX_HOSTS, NETWORK_HOST_MAX_CHARS, SECURE_INPUT_MAX_FIELDS, } from "../conversations/events.js";
|
|
17
17
|
import { ConversationLeakCheck } from "../conversations/leak-check.js";
|
|
18
18
|
import { conversationSourceOf } from "../conversations/source.js";
|
|
19
19
|
import { ApiError } from "../errors.js";
|
|
@@ -54,7 +54,10 @@ export const APPROVALS_LIST_MAX = 100;
|
|
|
54
54
|
export const NETWORK_ASK_CANCELLED_NOTE = "[network] The run was stopped before the user answered; access stays blocked.";
|
|
55
55
|
/** The model-visible note after a git ask's kept result when its run is stopped before the answer. */
|
|
56
56
|
export const GIT_ASK_CANCELLED_NOTE = "[git] The run was stopped before the user answered; the push was not made.";
|
|
57
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* The record without an ask's kept command result (what routes and cards may show). A secure
|
|
59
|
+
* input request shows its fields and target, never the call's input it binds.
|
|
60
|
+
*/
|
|
58
61
|
export function publicRecord(r) {
|
|
59
62
|
const strip = (d) => {
|
|
60
63
|
if (d === null)
|
|
@@ -71,8 +74,17 @@ export function publicRecord(r) {
|
|
|
71
74
|
: r.scopes,
|
|
72
75
|
detail: strip(r.detail),
|
|
73
76
|
git: strip(r.git),
|
|
77
|
+
...(r.kind === "secure_input" && { input: null }),
|
|
74
78
|
};
|
|
75
79
|
}
|
|
80
|
+
/** Whether a tool ask's stored `detail` says the review model could not decide it. */
|
|
81
|
+
function reviewUnsureOf(detail) {
|
|
82
|
+
return typeof detail === "object" &&
|
|
83
|
+
detail !== null &&
|
|
84
|
+
detail.reviewUnsure === true
|
|
85
|
+
? { reviewUnsure: true }
|
|
86
|
+
: null;
|
|
87
|
+
}
|
|
76
88
|
/** A tool ask's file from its stored `detail` (none: the call takes no file). */
|
|
77
89
|
function fileOf(detail) {
|
|
78
90
|
if (typeof detail !== "object" || detail === null)
|
|
@@ -82,7 +94,7 @@ function fileOf(detail) {
|
|
|
82
94
|
return null;
|
|
83
95
|
return { file: f };
|
|
84
96
|
}
|
|
85
|
-
/**
|
|
97
|
+
/** The person fields of a secure input request from its stored `detail`. */
|
|
86
98
|
function personFieldsOf(detail) {
|
|
87
99
|
if (typeof detail !== "object" || detail === null)
|
|
88
100
|
return null;
|
|
@@ -140,8 +152,9 @@ function toRecord(r) {
|
|
|
140
152
|
detail: r.kind === "network" ? (r.detail ?? null) : null,
|
|
141
153
|
git: r.kind === "git" ? (r.detail ?? null) : null,
|
|
142
154
|
command: r.kind === "command" ? (r.detail ?? null) : null,
|
|
143
|
-
...(r.kind === "
|
|
155
|
+
...(r.kind === "secure_input" && personFieldsOf(r.detail)),
|
|
144
156
|
...(r.kind === "tool" && fileOf(r.detail)),
|
|
157
|
+
...(r.kind === "tool" && reviewUnsureOf(r.detail)),
|
|
145
158
|
toolKey: r.tool_key,
|
|
146
159
|
specHash: r.spec_hash,
|
|
147
160
|
connectorId: r.connector_id,
|
|
@@ -166,8 +179,11 @@ function toRecord(r) {
|
|
|
166
179
|
* - 指定了 `requested_for` → 只有那个人;
|
|
167
180
|
* - 按角色升级(`approver_role`)→ 当前角色不低于它、且不是该运行发起人的成员(发起人不能批准按角色升级到别人的请求)。
|
|
168
181
|
* agent / 服务令牌不能处理任何审批(路由动作 `approvals.decide` 仅限用户主体)。
|
|
182
|
+
* A secure input request is only ever its `requested_for` person's, never a role's.
|
|
169
183
|
*/
|
|
170
184
|
function canHandle(a, initiator, accountId, role) {
|
|
185
|
+
if (a.kind === "secure_input")
|
|
186
|
+
return a.requestedFor !== null && a.requestedFor === accountId;
|
|
171
187
|
if (a.requestedFor !== null)
|
|
172
188
|
return a.requestedFor === accountId;
|
|
173
189
|
return (a.approverRole !== null &&
|
|
@@ -304,6 +320,96 @@ let ApprovalsService = class ApprovalsService {
|
|
|
304
320
|
]);
|
|
305
321
|
return { record: rec, toSeq: Math.max(...written.map((e) => e.seq)) };
|
|
306
322
|
}
|
|
323
|
+
/**
|
|
324
|
+
* A secure input request (profiles govern every approval, R4): a pending approval of kind
|
|
325
|
+
* `secure_input` asking `requestedFor` for the call's secret fields, expiring like a tool
|
|
326
|
+
* approval, and its `approval_requested` (the display-only `secureInput`: the target and the
|
|
327
|
+
* field paths), in one transaction. It carries no consent: scopes `["once"]`, and Submit is a
|
|
328
|
+
* decision `approve` with the values, Cancel a `deny`. The raw call input is stored for binding
|
|
329
|
+
* only and shown nowhere. Idempotent per (run, call, attempt); an attempt already held by
|
|
330
|
+
* another kind is refused.
|
|
331
|
+
*/
|
|
332
|
+
async requestSecureInput(input) {
|
|
333
|
+
const n = input.personFields.length;
|
|
334
|
+
if (n === 0 || n > SECURE_INPUT_MAX_FIELDS) {
|
|
335
|
+
throw new Error(`a secure input asks for 1 to ${SECURE_INPUT_MAX_FIELDS} fields`);
|
|
336
|
+
}
|
|
337
|
+
if (input.requestedFor.length === 0)
|
|
338
|
+
throw new Error("a secure input names its person");
|
|
339
|
+
const { record, toSeq } = await this.requestSecureInputIn(input);
|
|
340
|
+
if (toSeq !== null)
|
|
341
|
+
await this.eventLog.notify(record.conversationId, toSeq);
|
|
342
|
+
return record;
|
|
343
|
+
}
|
|
344
|
+
async requestSecureInputIn(input) {
|
|
345
|
+
const hours = this.config.get().tools.approvalTimeoutHours;
|
|
346
|
+
const t = this.db.db;
|
|
347
|
+
// the conversation row first (the append's lock), as `requestIn`
|
|
348
|
+
await t
|
|
349
|
+
.selectFrom("conversations")
|
|
350
|
+
.select("id")
|
|
351
|
+
.where("id", "=", input.conversationId)
|
|
352
|
+
.forUpdate()
|
|
353
|
+
.execute();
|
|
354
|
+
const detail = { personFields: input.personFields, target: input.target };
|
|
355
|
+
const inserted = await t
|
|
356
|
+
.insertInto("approvals")
|
|
357
|
+
.values({
|
|
358
|
+
id: randomUUID(),
|
|
359
|
+
org_id: input.orgId,
|
|
360
|
+
conversation_id: input.conversationId,
|
|
361
|
+
run_id: input.runId,
|
|
362
|
+
call_id: input.callId,
|
|
363
|
+
attempt: input.attempt,
|
|
364
|
+
kind: "secure_input",
|
|
365
|
+
detail: JSON.stringify(detail),
|
|
366
|
+
tool_key: input.toolKey,
|
|
367
|
+
spec_hash: input.specHash,
|
|
368
|
+
connector_id: input.connectorId,
|
|
369
|
+
input: JSON.stringify(input.input ?? {}),
|
|
370
|
+
requested_for: input.requestedFor,
|
|
371
|
+
approver_role: null,
|
|
372
|
+
scopes: ["once"],
|
|
373
|
+
scope: null,
|
|
374
|
+
decided_by: null,
|
|
375
|
+
expires_at: sql `now() + ${hours}::integer * interval '1 hour'`,
|
|
376
|
+
})
|
|
377
|
+
.onConflict((oc) => oc.columns(["run_id", "call_id", "attempt"]).doNothing())
|
|
378
|
+
.returningAll()
|
|
379
|
+
.executeTakeFirst();
|
|
380
|
+
if (inserted === undefined) {
|
|
381
|
+
const row = await t
|
|
382
|
+
.selectFrom("approvals")
|
|
383
|
+
.selectAll()
|
|
384
|
+
.where("run_id", "=", input.runId)
|
|
385
|
+
.where("call_id", "=", input.callId)
|
|
386
|
+
.where("attempt", "=", input.attempt)
|
|
387
|
+
.executeTakeFirstOrThrow();
|
|
388
|
+
if (row.kind !== "secure_input") {
|
|
389
|
+
throw new Error(`attempt ${input.attempt} of call ${input.callId} is an approval of kind ${row.kind}`);
|
|
390
|
+
}
|
|
391
|
+
return { record: toRecord(row), toSeq: null };
|
|
392
|
+
}
|
|
393
|
+
const rec = toRecord(inserted);
|
|
394
|
+
const written = await this.eventLog.appendIn(rec.conversationId, [
|
|
395
|
+
{
|
|
396
|
+
type: "approval_requested",
|
|
397
|
+
runId: rec.runId,
|
|
398
|
+
idemKey: `approval_requested:${rec.id}`,
|
|
399
|
+
payload: {
|
|
400
|
+
step: input.step,
|
|
401
|
+
callId: rec.callId,
|
|
402
|
+
approvalId: rec.id,
|
|
403
|
+
toolKey: rec.toolKey,
|
|
404
|
+
expiresAt: rec.expiresAt,
|
|
405
|
+
secureInput: { target: input.target, fields: input.personFields.map((f) => f.path) },
|
|
406
|
+
requestedFor: rec.requestedFor,
|
|
407
|
+
approverRole: null,
|
|
408
|
+
},
|
|
409
|
+
},
|
|
410
|
+
]);
|
|
411
|
+
return { record: rec, toSeq: Math.max(...written.map((e) => e.seq)) };
|
|
412
|
+
}
|
|
307
413
|
/**
|
|
308
414
|
* A network ask (network ask-to-allow spec §6.2): a pending approval of kind `network` for the
|
|
309
415
|
* device owner, expiring like a tool approval (`tools.approvalTimeoutHours`), and its
|
|
@@ -964,16 +1070,18 @@ let ApprovalsService = class ApprovalsService {
|
|
|
964
1070
|
// decision committed, even when a caller has a transaction open
|
|
965
1071
|
decideIn(orgId, id, accountId, body, actorTokenId, network, git, command) {
|
|
966
1072
|
return this.decideTx(orgId, id, accountId, body, actorTokenId, network, git, command).then((o) => {
|
|
967
|
-
// only a
|
|
968
|
-
if ("leaked" in o)
|
|
969
|
-
throw new Error(`approval ${id}: a leak outcome outside a
|
|
1073
|
+
// only a secure input takes inputs (refused for every other kind before)
|
|
1074
|
+
if ("leaked" in o) {
|
|
1075
|
+
throw new Error(`approval ${id}: a leak outcome outside a secure input request`);
|
|
1076
|
+
}
|
|
970
1077
|
return o;
|
|
971
1078
|
});
|
|
972
1079
|
}
|
|
973
1080
|
/**
|
|
974
|
-
* A tool ask's decision in its own transaction.
|
|
975
|
-
* leaked paths in `detail.leakedFields` and returns them (the caller refuses
|
|
976
|
-
* the
|
|
1081
|
+
* A tool ask's or a secure input's decision in its own transaction. For a secure input, a leak
|
|
1082
|
+
* refusal commits the leaked paths in `detail.leakedFields` and returns them (the caller refuses
|
|
1083
|
+
* after the commit, the request still pending); the same transaction cannot both keep that write
|
|
1084
|
+
* and throw.
|
|
977
1085
|
*/
|
|
978
1086
|
decideToolIn(orgId, id, accountId, body, actorTokenId, via) {
|
|
979
1087
|
return this.decideTx(orgId, id, accountId, body, actorTokenId, undefined, undefined, undefined, via);
|
|
@@ -1030,12 +1138,13 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1030
1138
|
await this.permissionGrants.assertCurrent(before.command.permissionCandidate.binding);
|
|
1031
1139
|
}
|
|
1032
1140
|
const approved = body.decision === "approve";
|
|
1033
|
-
|
|
1141
|
+
// only a secure input request takes values
|
|
1142
|
+
const person = before.kind === "secure_input" ? before.personFields : undefined;
|
|
1034
1143
|
if (body.inputs !== undefined && (person === undefined || !approved)) {
|
|
1035
1144
|
throw inputsNotExpected();
|
|
1036
1145
|
}
|
|
1037
|
-
//
|
|
1038
|
-
// its person, in a web session, with every asked value, valid and never seen in the
|
|
1146
|
+
// a secure input (platform web parity spec §4.2, §4.3, R5; profiles govern every approval R4):
|
|
1147
|
+
// submitted only by its person, in a web session, with every asked value, valid and never seen in the
|
|
1039
1148
|
// conversation; the values are sealed before the status changes. A deny takes no values.
|
|
1040
1149
|
let inputsProvided;
|
|
1041
1150
|
if (person !== undefined && approved) {
|
|
@@ -1288,6 +1397,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1288
1397
|
action: "approval.decided",
|
|
1289
1398
|
target: id,
|
|
1290
1399
|
detail: {
|
|
1400
|
+
...(before.kind === "secure_input" && { kind: "secure_input" }),
|
|
1291
1401
|
...(git !== undefined &&
|
|
1292
1402
|
before.git !== null && {
|
|
1293
1403
|
kind: "git",
|
|
@@ -1491,6 +1601,19 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1491
1601
|
.executeTakeFirst();
|
|
1492
1602
|
return row ? toRecord(row) : null;
|
|
1493
1603
|
}
|
|
1604
|
+
/** The latest secure input request of a tool call (highest attempt); null when it has none. */
|
|
1605
|
+
async secureInputForCall(runId, callId) {
|
|
1606
|
+
const row = await this.db
|
|
1607
|
+
.selectFrom("approvals")
|
|
1608
|
+
.selectAll()
|
|
1609
|
+
.where("run_id", "=", runId)
|
|
1610
|
+
.where("call_id", "=", callId)
|
|
1611
|
+
.where("kind", "=", "secure_input")
|
|
1612
|
+
.orderBy("attempt", "desc")
|
|
1613
|
+
.limit(1)
|
|
1614
|
+
.executeTakeFirst();
|
|
1615
|
+
return row ? toRecord(row) : null;
|
|
1616
|
+
}
|
|
1494
1617
|
/** The network ask of a tool call (at most one per call); null when it has none. */
|
|
1495
1618
|
async networkForCall(runId, callId) {
|
|
1496
1619
|
const row = await this.db
|
|
@@ -1923,6 +2046,9 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1923
2046
|
__decorate([
|
|
1924
2047
|
Transactional()
|
|
1925
2048
|
], ApprovalsService.prototype, "requestIn", null);
|
|
2049
|
+
__decorate([
|
|
2050
|
+
Transactional()
|
|
2051
|
+
], ApprovalsService.prototype, "requestSecureInputIn", null);
|
|
1926
2052
|
__decorate([
|
|
1927
2053
|
Transactional()
|
|
1928
2054
|
], ApprovalsService.prototype, "requestNetworkIn", null);
|
|
@@ -40,7 +40,7 @@ export declare class BuiltinTools {
|
|
|
40
40
|
purposes: ModelPurposesService, host: {
|
|
41
41
|
readonly hooks?: HookRunner;
|
|
42
42
|
} | undefined, stepLog: StepLog, log: Logger, background: BackgroundTaskStore, finisher: BackgroundTaskFinisher, stopper: BackgroundTaskStopper, platformOps: PlatformOperations, platformActor: PlatformActor, agentDocs: AgentDocs,
|
|
43
|
-
/** The person's sealed
|
|
43
|
+
/** The person's sealed secure input values a Platform write with person fields reads. */
|
|
44
44
|
sealedInputs: SealedInputs,
|
|
45
45
|
/** A Platform write's file reference: a conversation file (spec §5). */
|
|
46
46
|
fileRefs: FileRefs,
|
|
@@ -63,7 +63,7 @@ let BuiltinTools = class BuiltinTools {
|
|
|
63
63
|
constructor(db, config, outputs, storage, attachments, eventLog, sandbox, devices, points, webPages,
|
|
64
64
|
/** The WebFetch extraction call: the `web_fetch` purpose, its hooks, usage and denials. */
|
|
65
65
|
purposes, host, stepLog, log, background, finisher, stopper, platformOps, platformActor, agentDocs,
|
|
66
|
-
/** The person's sealed
|
|
66
|
+
/** The person's sealed secure input values a Platform write with person fields reads. */
|
|
67
67
|
sealedInputs,
|
|
68
68
|
/** A Platform write's file reference: a conversation file (spec §5). */
|
|
69
69
|
fileRefs,
|
|
@@ -172,30 +172,36 @@ let BuiltinTools = class BuiltinTools {
|
|
|
172
172
|
setting: async (orgId) => (await readOrgSettings(db.db, orgId)).platformTool,
|
|
173
173
|
log,
|
|
174
174
|
sealed: sealedInputs,
|
|
175
|
-
|
|
176
|
-
// only this call's own
|
|
175
|
+
secureInputPaths: async (secureInputId, call) => {
|
|
176
|
+
// only this call's own submitted secure input in this org (anything else: none, fails
|
|
177
|
+
// closed)
|
|
177
178
|
const row = await db.db
|
|
178
179
|
.selectFrom("approvals")
|
|
179
180
|
.select(["kind", "detail"])
|
|
180
|
-
.where("id", "=",
|
|
181
|
+
.where("id", "=", secureInputId)
|
|
181
182
|
.where("org_id", "=", call.orgId)
|
|
182
183
|
.where("run_id", "=", call.runId)
|
|
183
184
|
.where("call_id", "=", call.callId)
|
|
185
|
+
.where("kind", "=", "secure_input")
|
|
184
186
|
.where("status", "=", "approved")
|
|
185
187
|
.executeTakeFirst();
|
|
186
188
|
const fields = row?.detail
|
|
187
189
|
?.personFields;
|
|
188
|
-
if (row?.kind !== "
|
|
190
|
+
if (row?.kind !== "secure_input" || !Array.isArray(fields) || fields.length === 0) {
|
|
189
191
|
return null;
|
|
192
|
+
}
|
|
190
193
|
return fields.map((f) => String(f.path));
|
|
191
194
|
},
|
|
192
195
|
files: fileRefs,
|
|
196
|
+
// a call no approval governs binds its file to the automatic decision instead (R7)
|
|
193
197
|
approvalFileSha256: async (approvalId, call) => {
|
|
194
|
-
// only this call's own approved approval in this org (anything else: none, fails
|
|
198
|
+
// only this call's own approved tool approval in this org (anything else: none, fails
|
|
199
|
+
// closed)
|
|
195
200
|
const row = await db.db
|
|
196
201
|
.selectFrom("approvals")
|
|
197
202
|
.select(["kind", "detail"])
|
|
198
203
|
.where("id", "=", approvalId)
|
|
204
|
+
.where("kind", "=", "tool")
|
|
199
205
|
.where("org_id", "=", call.orgId)
|
|
200
206
|
.where("run_id", "=", call.runId)
|
|
201
207
|
.where("call_id", "=", call.callId)
|
|
@@ -21,14 +21,18 @@ import type { BuiltinTool, CallPolicyContext } from "../registry.js";
|
|
|
21
21
|
* - An `ApiError` gets the next step the operation declares for its code and the actor's role.
|
|
22
22
|
* - The actor, the agent and the conversation come from the runtime context, never from input.
|
|
23
23
|
* - A write with person fields (platform web parity spec §4: `op.personFields`) is planned at the
|
|
24
|
-
* policy step: a secret in `values` is denied before
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
24
|
+
* policy step: a secret in `values` is denied before any card, and the asked fields go to the
|
|
25
|
+
* pipeline through {@link CallPolicy.personFields}, which asks for them in a secure input request
|
|
26
|
+
* after the consent (profiles govern every approval, R4). The call reads the person's sealed
|
|
27
|
+
* values by that request (`BuiltinCallContext.secureInputId`) through `personInputs`, and its
|
|
28
|
+
* result names the request and each entered path, never a value.
|
|
28
29
|
* - A write that takes a file in place of an upload (spec §5: `op.fileRef`) resolves it at the
|
|
29
30
|
* policy step: a file over the limit or of another type is denied before the card; the card
|
|
30
|
-
* shows it (`CallPolicy.file`, never remembered) and the approval binds its sha256
|
|
31
|
-
* `op.run` the file is read again, and
|
|
31
|
+
* shows it (`CallPolicy.file`, never remembered) and the approval binds its sha256, or, with no
|
|
32
|
+
* approval, the automatic decision does (R7). Right before `op.run` the file is read again, and
|
|
33
|
+
* bytes with another sha256 are refused.
|
|
34
|
+
* - A write whose result is shown once to the run's person (`op.revealsOnce`) carries the
|
|
35
|
+
* reveal view, which the web reads by the call (R6).
|
|
32
36
|
* - Results are JSON text; a list an operation returns is capped at {@link LIST_MAX} entries.
|
|
33
37
|
*/
|
|
34
38
|
/** The most entries of a list in one result (operations that page return `next`). */
|
|
@@ -49,14 +53,14 @@ export interface PlatformToolDeps {
|
|
|
49
53
|
precheckTimeoutMs?: number;
|
|
50
54
|
/** A precheck that throws is logged (warn) and one that times out (debug), with the op id. */
|
|
51
55
|
log?: Pick<KernelLogger, "warn"> & Partial<Pick<KernelLogger, "debug">>;
|
|
52
|
-
/** The person's sealed
|
|
56
|
+
/** The person's sealed values (`personInputs`); absent: no write has person fields. */
|
|
53
57
|
sealed?: Pick<SealedInputs, "consume">;
|
|
54
58
|
/**
|
|
55
|
-
* The person field paths
|
|
56
|
-
* when it
|
|
57
|
-
*
|
|
59
|
+
* The person field paths a secure input request asked for (its stored `detail.personFields`), or
|
|
60
|
+
* null when it is not this call's submitted secure input in the org: what the call's values are
|
|
61
|
+
* bound to.
|
|
58
62
|
*/
|
|
59
|
-
|
|
63
|
+
secureInputPaths?(secureInputId: string, call: {
|
|
60
64
|
orgId: string;
|
|
61
65
|
runId: string;
|
|
62
66
|
callId: string;
|
|
@@ -23,14 +23,18 @@ import { BUILTIN } from "../builtin-names.js";
|
|
|
23
23
|
* - An `ApiError` gets the next step the operation declares for its code and the actor's role.
|
|
24
24
|
* - The actor, the agent and the conversation come from the runtime context, never from input.
|
|
25
25
|
* - A write with person fields (platform web parity spec §4: `op.personFields`) is planned at the
|
|
26
|
-
* policy step: a secret in `values` is denied before
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
26
|
+
* policy step: a secret in `values` is denied before any card, and the asked fields go to the
|
|
27
|
+
* pipeline through {@link CallPolicy.personFields}, which asks for them in a secure input request
|
|
28
|
+
* after the consent (profiles govern every approval, R4). The call reads the person's sealed
|
|
29
|
+
* values by that request (`BuiltinCallContext.secureInputId`) through `personInputs`, and its
|
|
30
|
+
* result names the request and each entered path, never a value.
|
|
30
31
|
* - A write that takes a file in place of an upload (spec §5: `op.fileRef`) resolves it at the
|
|
31
32
|
* policy step: a file over the limit or of another type is denied before the card; the card
|
|
32
|
-
* shows it (`CallPolicy.file`, never remembered) and the approval binds its sha256
|
|
33
|
-
* `op.run` the file is read again, and
|
|
33
|
+
* shows it (`CallPolicy.file`, never remembered) and the approval binds its sha256, or, with no
|
|
34
|
+
* approval, the automatic decision does (R7). Right before `op.run` the file is read again, and
|
|
35
|
+
* bytes with another sha256 are refused.
|
|
36
|
+
* - A write whose result is shown once to the run's person (`op.revealsOnce`) carries the
|
|
37
|
+
* reveal view, which the web reads by the call (R6).
|
|
34
38
|
* - Results are JSON text; a list an operation returns is capped at {@link LIST_MAX} entries.
|
|
35
39
|
*/
|
|
36
40
|
/** The most entries of a list in one result (operations that page return `next`). */
|
|
@@ -231,11 +235,11 @@ const missingText = (action, field, what) => `Action ${action} needs "${field}":
|
|
|
231
235
|
const invalidParamsText = (id, problems) => `Invalid params for ${id}: ${problems}. Call describe with operation "${id}" for its input schema and an example, then call again.`;
|
|
232
236
|
const unavailableOpText = (id, reason) => `Operation ${id} is unavailable, so do not call it again as is: ${reason}`;
|
|
233
237
|
const precheckText = (id, code, message, next) => `Operation ${id} cannot run now: ${code}: ${sentence(message)} ${next ?? OPERATION_ERROR_NEXT}`;
|
|
234
|
-
const secretRecordText = (id, path, target) => `Operation ${id} cannot run now: platform.secret_record_web_only: \`${path}\` is a secret record, which
|
|
238
|
+
const secretRecordText = (id, path, target) => `Operation ${id} cannot run now: platform.secret_record_web_only: \`${path}\` is a secret record, which a secure input request cannot ask for. Tell the person to enter it on the web page of ${target}.`;
|
|
235
239
|
/** Model-visible: the person's values expired before the approved call ran (spec §4.3). */
|
|
236
240
|
export const PERSON_INPUTS_EXPIRED_TEXT = "The values the person entered expired before they were applied; call the operation again.";
|
|
237
241
|
/** Model-visible: an approved call with person fields that has no approval to read them by. */
|
|
238
|
-
const personInputsMissingText = (id) => `Operation ${id} needs values the person enters
|
|
242
|
+
const personInputsMissingText = (id) => `Operation ${id} needs values the person enters in a secure input request, and this call ran without one; call the operation again.`;
|
|
239
243
|
/**
|
|
240
244
|
* Model-visible: the person-field plan refused an approved call when it resumed (the target's
|
|
241
245
|
* secret fields changed while the card waited); `message` is the plan's English refusal.
|
|
@@ -248,6 +252,8 @@ const personRefusedText = (id, message) => `Operation ${id} cannot run as approv
|
|
|
248
252
|
const PERSON_FIELDS_CHANGED_TEXT = "The target changed after the person confirmed (the fields to enter differ); call the operation again.";
|
|
249
253
|
/** Model-visible result line: the approved call's operation never applied the person's values. */
|
|
250
254
|
const unusedValuesText = (id) => `The values the person entered were not used by ${id}.`;
|
|
255
|
+
/** The result line naming the submitted secure input request (never a value). */
|
|
256
|
+
const submittedLine = (id) => `Secure input ${id}: submitted.`;
|
|
251
257
|
/** The result line of one field the person entered (never its value). */
|
|
252
258
|
const enteredLine = (path) => `\`${path}\`: entered by the person`;
|
|
253
259
|
/** Model-visible: an operation takes a file, and this kernel has no resolver wired (a bug). */
|
|
@@ -391,15 +397,14 @@ export function platformTool(deps) {
|
|
|
391
397
|
return {
|
|
392
398
|
key,
|
|
393
399
|
policy: "ask",
|
|
394
|
-
// org / platform writes are confirmed every time (spec §6.2); so is
|
|
395
|
-
//
|
|
396
|
-
|
|
397
|
-
remember: personFields === null && card === null && cls === "personal" && op.rememberable !== false,
|
|
400
|
+
// org / platform writes are confirmed every time (spec §6.2); so is one whose card shows a
|
|
401
|
+
// file (§5: the person confirms these bytes). Person fields do not decide the consent (R5)
|
|
402
|
+
remember: card === null && cls === "personal" && op.rememberable !== false,
|
|
398
403
|
summary,
|
|
399
404
|
...(personFields !== null && { personFields }),
|
|
400
405
|
...(card !== null && { file: card }),
|
|
401
|
-
// its result is shown once to the
|
|
402
|
-
...(op.
|
|
406
|
+
// its result is shown once to the run's person: only they may consent to it
|
|
407
|
+
...(op.revealsOnce !== undefined && { personOnly: true }),
|
|
403
408
|
};
|
|
404
409
|
}
|
|
405
410
|
async function run(raw, ctx) {
|
|
@@ -499,30 +504,31 @@ export function platformTool(deps) {
|
|
|
499
504
|
// the file is read again, and must be the bytes the person confirmed (Review Focus 5)
|
|
500
505
|
const file = await fileOf(op, params, deps, octx, ctx.signal);
|
|
501
506
|
if (file !== null) {
|
|
502
|
-
// fails closed: bytes run only under this call's approval whose card showed them
|
|
503
|
-
// approval,
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
deps.approvalFileSha256 === undefined
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
507
|
+
// fails closed: bytes run only under this call's approval whose card showed them or,
|
|
508
|
+
// with no approval, the automatic decision that was bound to them (R7); a grant, an
|
|
509
|
+
// approval whose card showed no file or another one does not cover these bytes
|
|
510
|
+
const bound = ctx.approvalId !== undefined
|
|
511
|
+
? ctx.runId === undefined || deps.approvalFileSha256 === undefined
|
|
512
|
+
? null
|
|
513
|
+
: await deps.approvalFileSha256(ctx.approvalId, {
|
|
514
|
+
orgId: ctx.orgId,
|
|
515
|
+
runId: ctx.runId,
|
|
516
|
+
callId: ctx.callId,
|
|
517
|
+
})
|
|
518
|
+
: (ctx.decision?.fileSha256 ?? null);
|
|
513
519
|
if (bound === null || bound !== file.sha256)
|
|
514
520
|
throw new ToolError(FILE_CHANGED_TEXT);
|
|
515
521
|
octx.file = file;
|
|
516
522
|
}
|
|
517
523
|
const person = await personFieldsOf(op, params, octx);
|
|
518
|
-
// what the
|
|
519
|
-
//
|
|
520
|
-
const
|
|
521
|
-
const shown =
|
|
522
|
-
deps.
|
|
524
|
+
// what the secure input asked (its stored specs) binds what runs: the run-time plan must
|
|
525
|
+
// ask exactly those fields, and the sealed values must carry exactly them
|
|
526
|
+
const secureInputId = ctx.secureInputId;
|
|
527
|
+
const shown = secureInputId === undefined ||
|
|
528
|
+
deps.secureInputPaths === undefined ||
|
|
523
529
|
ctx.runId === undefined
|
|
524
530
|
? null
|
|
525
|
-
: await deps.
|
|
531
|
+
: await deps.secureInputPaths(secureInputId, {
|
|
526
532
|
orgId: ctx.orgId,
|
|
527
533
|
runId: ctx.runId,
|
|
528
534
|
callId: ctx.callId,
|
|
@@ -531,10 +537,10 @@ export function platformTool(deps) {
|
|
|
531
537
|
throw new PersonFieldsChanged();
|
|
532
538
|
if (person !== null) {
|
|
533
539
|
const sealed = deps.sealed;
|
|
534
|
-
if (
|
|
540
|
+
if (secureInputId === undefined || sealed === undefined) {
|
|
535
541
|
throw new ToolError(personInputsMissingText(op.id));
|
|
536
542
|
}
|
|
537
|
-
//
|
|
543
|
+
// a request that is not this call's submitted one, or asked before the target changed
|
|
538
544
|
if (shown === null)
|
|
539
545
|
throw new PersonFieldsChanged();
|
|
540
546
|
const asked = person.fields.map((p) => p.path);
|
|
@@ -546,9 +552,9 @@ export function platformTool(deps) {
|
|
|
546
552
|
if (applied)
|
|
547
553
|
throw new Error("personInputs.apply called twice");
|
|
548
554
|
applied = true;
|
|
549
|
-
// the person who typed the values is the run's trigger account, the
|
|
550
|
-
// `requested_for` (a role escalation is refused before
|
|
551
|
-
return sealed.consume(
|
|
555
|
+
// the person who typed the values is the run's trigger account, the secure input's
|
|
556
|
+
// `requested_for` (a role escalation is refused before any card, R5)
|
|
557
|
+
return sealed.consume(secureInputId, ctx.accountId, async (values) => {
|
|
552
558
|
// a throw here rolls the row's delete back: nothing is applied
|
|
553
559
|
if (!sameSet(Object.keys(values), shown) || !sameSet(asked, shown)) {
|
|
554
560
|
throw new PersonFieldsChanged();
|
|
@@ -574,14 +580,18 @@ export function platformTool(deps) {
|
|
|
574
580
|
throw toToolError(e, (code) => nextStepFor(op.errors, code, role));
|
|
575
581
|
}
|
|
576
582
|
const summary = { zh: `调用平台操作 ${op.id}`, en: `Called ${op.id}` };
|
|
577
|
-
const lines =
|
|
583
|
+
const lines = octx.personInputs !== undefined && ctx.secureInputId !== undefined
|
|
584
|
+
? [submittedLine(ctx.secureInputId), ...entered.map(enteredLine)]
|
|
585
|
+
: entered.map(enteredLine);
|
|
578
586
|
if (octx.personInputs !== undefined && !applied) {
|
|
579
587
|
// an operation bug: the person typed values the write never used (they expire unread)
|
|
580
588
|
deps.log?.warn("platform operation did not use the person's values", { operation: op.id });
|
|
581
589
|
lines.push(unusedValuesText(op.id));
|
|
582
590
|
}
|
|
583
|
-
const
|
|
584
|
-
const out = withReviewUrl(asResult(withoutPersonAvatars(result)),
|
|
591
|
+
const handoff = handoffOf(op, params, result, octx, deps.log);
|
|
592
|
+
const out = withReviewUrl(asResult(withoutPersonAvatars(result)), handoff);
|
|
593
|
+
// a result shown once to the run's person: the web reads it by this call (R6)
|
|
594
|
+
const view = op.revealsOnce !== undefined ? { kind: "reveal", reveal: op.revealsOnce } : handoff;
|
|
585
595
|
return {
|
|
586
596
|
content: [
|
|
587
597
|
{ type: "text", text: JSON.stringify(out) },
|
|
@@ -60,7 +60,7 @@ export declare function sandboxDenialHint(r: ExecResult, escalation: {
|
|
|
60
60
|
* {@link SCOPE_DENIED_TOOL_TEXT} followed by {@link ESCALATION_RETRY_HINT}, written out as a literal
|
|
61
61
|
* for the tool design check (a unit test keeps the two copies equal).
|
|
62
62
|
*/
|
|
63
|
-
export declare const SCOPE_DENIED_ESCALATION_TEXT = "This operation reaches outside
|
|
63
|
+
export declare const SCOPE_DENIED_ESCALATION_TEXT = "This operation reaches outside the scope this conversation has on the device (a path outside the directories it may read or write, or a host it may not reach), so it did not run. Keep the call inside the working directory and the directories already granted, or ask the user to grant the directory, then retry. If this command must reach outside the sandbox, retry the same Bash call with sandbox: \"escalated\" and justification: one sentence saying why; this conversation's permission profile decides whether it may run outside the sandbox for this call only (the user, the review model, or Full access within this device's limits).";
|
|
64
64
|
/** 内置工具 `Bash`:在本对话的沙箱里执行命令。 */
|
|
65
65
|
export declare function sandboxBashTool(deps: SandboxToolDeps): BuiltinTool;
|
|
66
66
|
export {};
|