@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
package/dist/tools/pipeline.js
CHANGED
|
@@ -9,7 +9,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
9
9
|
};
|
|
10
10
|
import { ToolError, validateInputForm, validateToolDisplay, } from "@capybara-hq/plugin-sdk";
|
|
11
11
|
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
12
|
+
import { sql } from "kysely";
|
|
12
13
|
import { backgroundMaxSeconds } from "../background/launch.js";
|
|
14
|
+
import { ConversationApprovalProfile } from "../conversations/approval-profile.js";
|
|
13
15
|
import { EventLog } from "../conversations/event-log.js";
|
|
14
16
|
import { COMMAND_ASK_MAX_CHARS, COMMAND_ASK_TEXT_MAX_CHARS, ToolViewSchema, } from "../conversations/events.js";
|
|
15
17
|
import { ConversationDevices } from "../devices/conversation-devices.js";
|
|
@@ -56,6 +58,7 @@ import { BUILTIN, SEND_MESSAGE, SUBAGENT_HANDBACK, TOOL_SEARCH } from "./builtin
|
|
|
56
58
|
import { AGENT_TOOL, AgentToolInput } from "./builtins/agent.js";
|
|
57
59
|
import { HandbackInput } from "./builtins/handback.js";
|
|
58
60
|
import { generateImagePaths } from "./builtins/image/paths.js";
|
|
61
|
+
import { admissionUnavailableText } from "./builtins/sandbox/common.js";
|
|
59
62
|
import { DEVICE_CODE_PATTERN, deviceCodeIdemKey, GITHUB_DEVICE_LOGIN_URL, } from "./builtins/sandbox/device-code.js";
|
|
60
63
|
import { DEVICE_OF_ANOTHER_ACCOUNT_TEXT } from "./builtins/sandbox/device-owner.js";
|
|
61
64
|
import { SendMessageInput } from "./builtins/send-message.js";
|
|
@@ -72,6 +75,7 @@ import { QuestionsService } from "./questions.service.js";
|
|
|
72
75
|
import { redactDeep, redactorFor } from "./redact.js";
|
|
73
76
|
import { ToolRegistry, } from "./registry.js";
|
|
74
77
|
import { runResourceTool } from "./resources.js";
|
|
78
|
+
import { ToolAskReview } from "./tool-review.js";
|
|
75
79
|
import { validateInput } from "./validate.js";
|
|
76
80
|
// ---- 模型可见文案(英文) ----
|
|
77
81
|
/** 审批被拒绝。 */
|
|
@@ -149,11 +153,22 @@ export const PERSON_FIELDS_UNATTENDED_TEXT = "This write needs the person to ent
|
|
|
149
153
|
export const PERSON_FIELDS_ROLE_TEXT = "This write needs the person you work for to enter values; they lack the role. Ask an admin to do it on the web.";
|
|
150
154
|
/**
|
|
151
155
|
* A call only the person may confirm (`CallPolicy.personOnly`: its result is shown once to the
|
|
152
|
-
*
|
|
156
|
+
* run's person) in an unattended run: nobody is there to read it.
|
|
153
157
|
*/
|
|
154
|
-
export const PERSON_ONLY_UNATTENDED_TEXT = "This write shows its result once, on the web, to the person
|
|
158
|
+
export const PERSON_ONLY_UNATTENDED_TEXT = "This write shows its result once, on the web, to the person you work for, and no one is there to read it; it cannot run unattended.";
|
|
155
159
|
/** A call only the person may confirm whose ask would go to a role instead of the person. */
|
|
156
|
-
export const PERSON_ONLY_ROLE_TEXT = "This write shows its result once to the person you work for,
|
|
160
|
+
export const PERSON_ONLY_ROLE_TEXT = "This write shows its result once to the person you work for, so it runs only for them, and they lack the role. Ask an admin to do it on the web.";
|
|
161
|
+
/**
|
|
162
|
+
* The review model declined, under Approve for me, a call whose approval would have gone to the
|
|
163
|
+
* person (profiles govern every approval, R3): nothing ran.
|
|
164
|
+
*/
|
|
165
|
+
export const toolReviewDeniedText = (reason) => `The review model declined this call for the person (Approve for me): ${reason} Nothing ran. Tell the person what you wanted to do and why; they can do it themselves, or switch this conversation to Request approval and approve it when you call again.`;
|
|
166
|
+
/** The reason recorded when Auto runs an approval addressed to the person (R2). */
|
|
167
|
+
export const TOOL_AUTO_REASON = "Auto runs approvals addressed to the person without asking.";
|
|
168
|
+
/** The person cancelled the secure input request of a call with person fields (R4): nothing ran. */
|
|
169
|
+
export const secureInputCancelledText = (id) => `The person cancelled secure input ${id}, so nothing ran. Never ask for the value in the conversation; call the operation again only if the person asks for it.`;
|
|
170
|
+
/** A secure input request expired unanswered (R4): nothing ran. */
|
|
171
|
+
export const secureInputExpiredText = (id, hours) => `Secure input ${id} expired after ${hours} h without the person submitting it, so nothing ran. Call the operation again if it is still needed.`;
|
|
157
172
|
/** 调用执行中 run 被中止 / 到达截止时间。 */
|
|
158
173
|
export const RUN_STOPPED_DURING_TEXT = "The run was stopped while this tool call was running; its outcome is unknown. Verify before retrying.";
|
|
159
174
|
/** The fixed result of a call whose input request was skipped by a message (spec §7.1). */
|
|
@@ -310,6 +325,26 @@ const textField = (input, field) => {
|
|
|
310
325
|
const v = input?.[field];
|
|
311
326
|
return typeof v === "string" ? v : "";
|
|
312
327
|
};
|
|
328
|
+
/**
|
|
329
|
+
* The binding of an automatic decision (R2): the first 16 hex chars of the sha256 of the policy
|
|
330
|
+
* key, the definition and the raw input, as an approval binds them.
|
|
331
|
+
*/
|
|
332
|
+
const askBindingHash = (policyKey, specHash, rawInput) => sha256Hex(canonicalJson([policyKey, specHash, rawInput ?? {}])).slice(0, 16);
|
|
333
|
+
/** The profile step's outcome from a recorded automatic decision. */
|
|
334
|
+
const askDecisionOf = (event) => {
|
|
335
|
+
const p = event.payload;
|
|
336
|
+
return p.outcome === "deny"
|
|
337
|
+
? { kind: "deny", reason: p.reason }
|
|
338
|
+
: {
|
|
339
|
+
kind: "allow",
|
|
340
|
+
decision: {
|
|
341
|
+
source: p.decisionSource,
|
|
342
|
+
revision: p.profileRevision,
|
|
343
|
+
seq: event.seq,
|
|
344
|
+
...(p.fileSha256 !== undefined && { fileSha256: p.fileSha256 }),
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
};
|
|
313
348
|
const approvalAuthorization = (a) => ({
|
|
314
349
|
approvalId: a.id,
|
|
315
350
|
approvedByAccountId: a.decidedBy,
|
|
@@ -443,6 +478,8 @@ let ToolPipeline = class ToolPipeline {
|
|
|
443
478
|
autoGrants;
|
|
444
479
|
permissionLocks;
|
|
445
480
|
sandboxes;
|
|
481
|
+
approvalProfile;
|
|
482
|
+
toolReview;
|
|
446
483
|
decide;
|
|
447
484
|
deps;
|
|
448
485
|
constructor(kdb, eventLog,
|
|
@@ -461,7 +498,14 @@ let ToolPipeline = class ToolPipeline {
|
|
|
461
498
|
/** The paired activation gate: on, the managed builtins take the permission review. */
|
|
462
499
|
activation,
|
|
463
500
|
/** Starts a cloud device before its first managed call is reviewed (absent: never). */
|
|
464
|
-
sandboxes
|
|
501
|
+
sandboxes,
|
|
502
|
+
/**
|
|
503
|
+
* The profile of an ask addressed to the conversation's person (profiles govern every
|
|
504
|
+
* approval, R1); absent with {@link toolReview} (hand-built pipelines): every ask asks.
|
|
505
|
+
*/
|
|
506
|
+
approvalProfile,
|
|
507
|
+
/** The review model's judgment of an ask under Approve for me (R3); absent: every ask asks. */
|
|
508
|
+
toolReview) {
|
|
465
509
|
this.config = config;
|
|
466
510
|
this.txHost = txHost;
|
|
467
511
|
this.permissionAuthority = permissionAuthority;
|
|
@@ -469,6 +513,8 @@ let ToolPipeline = class ToolPipeline {
|
|
|
469
513
|
this.autoGrants = autoGrants;
|
|
470
514
|
this.permissionLocks = permissionLocks;
|
|
471
515
|
this.sandboxes = sandboxes;
|
|
516
|
+
this.approvalProfile = approvalProfile;
|
|
517
|
+
this.toolReview = toolReview;
|
|
472
518
|
this.deps = {
|
|
473
519
|
// the builtins that enter a device on the managed operation route once activated (common.ts
|
|
474
520
|
// `inToolSandbox`, `inSandboxPreparation`): their review is the permission review, whose
|
|
@@ -742,12 +788,13 @@ let ToolPipeline = class ToolPipeline {
|
|
|
742
788
|
return fail(callPolicy.denyReason, outKey);
|
|
743
789
|
}
|
|
744
790
|
const policyKey = callPolicy?.key ?? tool.key;
|
|
745
|
-
// person fields (platform web parity spec §4.2
|
|
746
|
-
//
|
|
791
|
+
// person fields (platform web parity spec §4.2; profiles govern every approval R4, R5): the
|
|
792
|
+
// person types the values in a secure input request, so an unattended run (a trial run has its
|
|
793
|
+
// creator there) cannot make the call at all
|
|
747
794
|
const personFields = callPolicy?.personFields;
|
|
748
|
-
// a call whose result is shown once to
|
|
749
|
-
const personOnly =
|
|
750
|
-
if (personOnly && unattendedRules(ctx.unattended)) {
|
|
795
|
+
// a call whose result is shown once to the run's person is refused there the same way
|
|
796
|
+
const personOnly = callPolicy?.personOnly === true;
|
|
797
|
+
if ((personFields !== undefined || personOnly) && unattendedRules(ctx.unattended)) {
|
|
751
798
|
return fail(personFields !== undefined ? PERSON_FIELDS_UNATTENDED_TEXT : PERSON_ONLY_UNATTENDED_TEXT, outKey);
|
|
752
799
|
}
|
|
753
800
|
let decision = await this.decide(tool, ctx.agent, {
|
|
@@ -775,10 +822,11 @@ let ToolPipeline = class ToolPipeline {
|
|
|
775
822
|
if (typeof decision === "object" && "unavailable" in decision) {
|
|
776
823
|
return fail(unavailableText(tool.key, decision.unavailable), outKey);
|
|
777
824
|
}
|
|
778
|
-
if (personOnly) {
|
|
779
|
-
// R6:
|
|
780
|
-
// asks for them; this holds for any decision)
|
|
781
|
-
|
|
825
|
+
if (personOnly || personFields !== undefined) {
|
|
826
|
+
// R6: a call only the person may confirm is always their own ask, never a grant or an
|
|
827
|
+
// `allow` (the default policy already asks for them; this holds for any decision). Person
|
|
828
|
+
// fields no longer force the consent (R5): it follows the call's policy, grants and profile
|
|
829
|
+
if (personOnly && (decision === "allow" || "grant" in decision)) {
|
|
782
830
|
decision = {
|
|
783
831
|
ask: {
|
|
784
832
|
toolKey: policyKey,
|
|
@@ -790,8 +838,9 @@ let ToolPipeline = class ToolPipeline {
|
|
|
790
838
|
},
|
|
791
839
|
};
|
|
792
840
|
}
|
|
793
|
-
// R5: only the person the run works for types the values
|
|
794
|
-
|
|
841
|
+
// R5: only the person the run works for types the values or reads the result; a role
|
|
842
|
+
// escalation cannot ask them
|
|
843
|
+
if (typeof decision === "object" && "ask" in decision && decision.ask.requestedFor === null) {
|
|
795
844
|
return fail(personFields !== undefined ? PERSON_FIELDS_ROLE_TEXT : PERSON_ONLY_ROLE_TEXT, outKey);
|
|
796
845
|
}
|
|
797
846
|
}
|
|
@@ -805,9 +854,26 @@ let ToolPipeline = class ToolPipeline {
|
|
|
805
854
|
approval.specHash === tool.specHash &&
|
|
806
855
|
canonicalJson(approval.input) === canonicalJson(call.input ?? {});
|
|
807
856
|
const stale = approval?.status === "approved" && !approvedHere;
|
|
857
|
+
// the profile step (profiles govern every approval, R1-R3): an ask addressed to the person
|
|
858
|
+
// with no approval governing the call yet is decided by the conversation's profile
|
|
859
|
+
let auto;
|
|
860
|
+
let reviewUnsure = false;
|
|
808
861
|
if ((!approval || stale) && typeof decision === "object" && "ask" in decision) {
|
|
862
|
+
const step = await this.profileStep(ctx, call, tool, input, decision.ask, callPolicy);
|
|
863
|
+
if (step.kind === "deny")
|
|
864
|
+
return fail(toolReviewDeniedText(step.reason), outKey);
|
|
865
|
+
if (step.kind === "allow")
|
|
866
|
+
auto = step.decision;
|
|
867
|
+
else
|
|
868
|
+
reviewUnsure = step.unsure;
|
|
869
|
+
}
|
|
870
|
+
if ((!approval || stale) &&
|
|
871
|
+
auto === undefined &&
|
|
872
|
+
typeof decision === "object" &&
|
|
873
|
+
"ask" in decision) {
|
|
809
874
|
approval = await this.deps.approvals.request({
|
|
810
|
-
|
|
875
|
+
// after every earlier request of the call, whatever its kind (attempts share one key)
|
|
876
|
+
attempt: (await this.lastAttempt(ctx.runId, call.id)) + 1,
|
|
811
877
|
orgId: ctx.orgId,
|
|
812
878
|
conversationId: ctx.conversationId,
|
|
813
879
|
runId: ctx.runId,
|
|
@@ -821,18 +887,12 @@ let ToolPipeline = class ToolPipeline {
|
|
|
821
887
|
approverRole: decision.ask.approverRole,
|
|
822
888
|
policy: decision.ask.policy,
|
|
823
889
|
...(callPolicy?.summary !== undefined && { summary: callPolicy.summary }),
|
|
824
|
-
...(
|
|
825
|
-
scopes: ["once"],
|
|
826
|
-
}),
|
|
827
|
-
// the specs of the asked fields, never a value (the card draws its inputs from them), and
|
|
890
|
+
...(callPolicy !== null && !callPolicy.remember && { scopes: ["once"] }),
|
|
828
891
|
// the referenced file the approval binds by its sha256
|
|
829
|
-
...((
|
|
892
|
+
...((callPolicy?.file !== undefined || reviewUnsure) && {
|
|
830
893
|
detail: {
|
|
831
|
-
...(personFields !== undefined && {
|
|
832
|
-
personFields: personFields.fields,
|
|
833
|
-
target: personFields.target,
|
|
834
|
-
}),
|
|
835
894
|
...(callPolicy?.file !== undefined && { file: callPolicy.file }),
|
|
895
|
+
...(reviewUnsure && { reviewUnsure: true }),
|
|
836
896
|
},
|
|
837
897
|
}),
|
|
838
898
|
});
|
|
@@ -844,9 +904,23 @@ let ToolPipeline = class ToolPipeline {
|
|
|
844
904
|
// 走到这里即放行:在(与当前定义一致的)审批下执行,否则是授权或策略放行
|
|
845
905
|
let authorization = approval?.status === "approved" && approvedHere
|
|
846
906
|
? approvalAuthorization(approval)
|
|
847
|
-
:
|
|
848
|
-
? {
|
|
849
|
-
:
|
|
907
|
+
: auto !== undefined
|
|
908
|
+
? { decisionSource: auto.source, profileRevision: auto.revision, decisionSeq: auto.seq }
|
|
909
|
+
: typeof decision === "object" && "grant" in decision
|
|
910
|
+
? { grant: decision.grant }
|
|
911
|
+
: { policy: "allow" };
|
|
912
|
+
// the secure input (profiles govern every approval, R4): once the call's consent is settled
|
|
913
|
+
// (approved here, a grant, an allow or the profile's decision), the person enters the call's
|
|
914
|
+
// secret fields under every profile, before the command review
|
|
915
|
+
let secureInputId;
|
|
916
|
+
if (personFields !== undefined) {
|
|
917
|
+
const secured = await this.secureInput(ctx, call, tool, policyKey, personFields);
|
|
918
|
+
if (secured.kind === "wait")
|
|
919
|
+
return secured.wait;
|
|
920
|
+
if (secured.kind === "refused")
|
|
921
|
+
return fail(secured.text, outKey);
|
|
922
|
+
secureInputId = secured.id;
|
|
923
|
+
}
|
|
850
924
|
// Auto mode spec §5.1: the command review, after argument validation and the tool policy (and
|
|
851
925
|
// its approval), before the plugin hooks and `tool_call_started`. A deny ends the call here; an
|
|
852
926
|
// ask parks the run on the command approval (attended) or is a deny at once (unattended). An
|
|
@@ -1019,7 +1093,16 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1019
1093
|
const t0 = Date.now();
|
|
1020
1094
|
let outcome = await this.execute(tool, input, ctx, call.id, resume, resolved.tools, reviewedRoots,
|
|
1021
1095
|
// the approval the call runs under (a Platform write reads the person's values by it)
|
|
1022
|
-
approval?.status === "approved" && approvedHere ? approval.id : undefined
|
|
1096
|
+
approval?.status === "approved" && approvedHere ? approval.id : undefined,
|
|
1097
|
+
// or the automatic decision and the file bytes it was bound to (R7)
|
|
1098
|
+
auto === undefined
|
|
1099
|
+
? undefined
|
|
1100
|
+
: {
|
|
1101
|
+
source: auto.source,
|
|
1102
|
+
...(auto.fileSha256 !== undefined && { fileSha256: auto.fileSha256 }),
|
|
1103
|
+
},
|
|
1104
|
+
// and the submitted secure input holding the person's values
|
|
1105
|
+
secureInputId);
|
|
1023
1106
|
const durationMs = Date.now() - t0;
|
|
1024
1107
|
await this.deps.hooks?.afterExecute?.(ctx.runId, call.id);
|
|
1025
1108
|
// the record says a call ran outside the sandbox only when admission gave it that scope
|
|
@@ -1171,6 +1254,151 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1171
1254
|
}
|
|
1172
1255
|
return undefined;
|
|
1173
1256
|
}
|
|
1257
|
+
/**
|
|
1258
|
+
* The profile step (profiles govern every approval, R1-R3) of an ask `decide` returned for a call
|
|
1259
|
+
* no approval governs yet. It applies only to an ask addressed to the person (no role, the root
|
|
1260
|
+
* conversation's own owner), in an attended interactive chat, and for a tool that does not
|
|
1261
|
+
* itself require the person's interaction (D3); a call's secret fields are asked afterwards in a
|
|
1262
|
+
* secure input request whatever it decides (R4). Request approval asks; Auto allows; Approve for
|
|
1263
|
+
* me asks the review model, whose unsure answer asks the person. An `allow` or `deny` is recorded
|
|
1264
|
+
* once (`tool_ask_decided` and its audit row); a resumed call reads that record before the profile
|
|
1265
|
+
* and never calls the review model again. Anything that cannot be read asks the person (fail closed).
|
|
1266
|
+
*/
|
|
1267
|
+
async profileStep(ctx, call, tool, input, ask, callPolicy) {
|
|
1268
|
+
const asks = { kind: "ask", unsure: false };
|
|
1269
|
+
const profiles = this.approvalProfile;
|
|
1270
|
+
const reviewer = this.toolReview;
|
|
1271
|
+
if (profiles === undefined || reviewer === undefined)
|
|
1272
|
+
return asks;
|
|
1273
|
+
if (ask.approverRole !== null || ask.requestedFor === null)
|
|
1274
|
+
return asks;
|
|
1275
|
+
if (ctx.unattended != null)
|
|
1276
|
+
return asks;
|
|
1277
|
+
if (tool.spec.annotations?.requiresUserInteraction === true)
|
|
1278
|
+
return asks;
|
|
1279
|
+
// a decision already recorded for this call governs it whatever the profile reads now (R2: a
|
|
1280
|
+
// resumed call reuses it; a profile change never revokes started work)
|
|
1281
|
+
const bindingHash = askBindingHash(ask.toolKey, ask.specHash, call.input);
|
|
1282
|
+
const idemKey = `tool_ask_decided:${ctx.runId}:${call.id}:${bindingHash}`;
|
|
1283
|
+
const recorded = await this.deps.eventLog.findByIdem(ctx.conversationId, idemKey);
|
|
1284
|
+
if (recorded?.type === "tool_ask_decided")
|
|
1285
|
+
return askDecisionOf(recorded);
|
|
1286
|
+
const rootConversationId = ctx.parent?.rootConversationId ?? ctx.conversationId;
|
|
1287
|
+
let resolved;
|
|
1288
|
+
try {
|
|
1289
|
+
resolved = await profiles.resolve({
|
|
1290
|
+
orgId: ctx.orgId,
|
|
1291
|
+
rootConversationId,
|
|
1292
|
+
requestedFor: ask.requestedFor,
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
catch (err) {
|
|
1296
|
+
this.deps.log.warn("cannot read the conversation's permission profile; asking the person", {
|
|
1297
|
+
conversationId: ctx.conversationId,
|
|
1298
|
+
callId: call.id,
|
|
1299
|
+
err,
|
|
1300
|
+
});
|
|
1301
|
+
return asks;
|
|
1302
|
+
}
|
|
1303
|
+
if (resolved === null || resolved.profile === "request-approval")
|
|
1304
|
+
return asks;
|
|
1305
|
+
let decision;
|
|
1306
|
+
if (resolved.profile === "full-access") {
|
|
1307
|
+
decision = { outcome: "allow", reason: TOOL_AUTO_REASON, source: "full-access" };
|
|
1308
|
+
}
|
|
1309
|
+
else {
|
|
1310
|
+
const parent = ctx.parent;
|
|
1311
|
+
const verdict = await reviewer.review({
|
|
1312
|
+
orgId: ctx.orgId,
|
|
1313
|
+
rootConversationId,
|
|
1314
|
+
conversationId: ctx.conversationId,
|
|
1315
|
+
runId: ctx.runId,
|
|
1316
|
+
step: ctx.step,
|
|
1317
|
+
callId: call.id,
|
|
1318
|
+
accountId: ctx.accountId,
|
|
1319
|
+
signal: ctx.signal,
|
|
1320
|
+
toolKey: ask.toolKey,
|
|
1321
|
+
title: tool.spec.title ?? null,
|
|
1322
|
+
summary: callPolicy?.summary ?? null,
|
|
1323
|
+
input,
|
|
1324
|
+
inputSchema: tool.spec.inputSchema,
|
|
1325
|
+
// a sub-agent's review counts on its parent run, as the command review's does
|
|
1326
|
+
...(parent !== undefined && {
|
|
1327
|
+
parentRunId: parent.runId,
|
|
1328
|
+
...(parent.budgetRunId !== undefined && { budgetRunId: parent.budgetRunId }),
|
|
1329
|
+
}),
|
|
1330
|
+
hookFacts: {
|
|
1331
|
+
accountId: ctx.accountId,
|
|
1332
|
+
agentId: ctx.agentId,
|
|
1333
|
+
agentVersion: ctx.agentVersion,
|
|
1334
|
+
conversationKind: ctx.conversationKind,
|
|
1335
|
+
parent: parent === undefined
|
|
1336
|
+
? undefined
|
|
1337
|
+
: {
|
|
1338
|
+
conversationId: parent.conversationId,
|
|
1339
|
+
runId: parent.runId,
|
|
1340
|
+
callId: parent.callId,
|
|
1341
|
+
},
|
|
1342
|
+
},
|
|
1343
|
+
});
|
|
1344
|
+
if (verdict.decision === "ask")
|
|
1345
|
+
return { kind: "ask", unsure: true };
|
|
1346
|
+
decision = { outcome: verdict.decision, reason: verdict.reason, source: "review-model" };
|
|
1347
|
+
}
|
|
1348
|
+
const fileSha256 = callPolicy?.file?.sha256;
|
|
1349
|
+
const event = await this.recordAskDecision(ctx, idemKey, {
|
|
1350
|
+
step: ctx.step,
|
|
1351
|
+
callId: call.id,
|
|
1352
|
+
toolKey: ask.toolKey,
|
|
1353
|
+
specHash: ask.specHash,
|
|
1354
|
+
bindingHash,
|
|
1355
|
+
outcome: decision.outcome,
|
|
1356
|
+
decisionSource: decision.source,
|
|
1357
|
+
reason: decision.reason,
|
|
1358
|
+
profileRevision: resolved.revision,
|
|
1359
|
+
...(fileSha256 !== undefined && { fileSha256 }),
|
|
1360
|
+
});
|
|
1361
|
+
return askDecisionOf(event);
|
|
1362
|
+
}
|
|
1363
|
+
/** Records an automatic decision once (R2) and announces it after the commit. */
|
|
1364
|
+
async recordAskDecision(ctx, idemKey, payload) {
|
|
1365
|
+
const { event, fresh } = await this.recordAskDecisionIn(ctx, idemKey, payload);
|
|
1366
|
+
if (fresh)
|
|
1367
|
+
await this.deps.eventLog.notify(ctx.conversationId, event.seq);
|
|
1368
|
+
return event;
|
|
1369
|
+
}
|
|
1370
|
+
/**
|
|
1371
|
+
* The `tool_ask_decided` event and, when this call wrote it, its audit row
|
|
1372
|
+
* `tool.ask_auto_decided`, in one transaction: a retry or another replica returns the recorded
|
|
1373
|
+
* event and audits nothing (every automatic decision is audited exactly once).
|
|
1374
|
+
*/
|
|
1375
|
+
async recordAskDecisionIn(ctx, idemKey, payload) {
|
|
1376
|
+
const report = await this.deps.eventLog.appendInReport(ctx.conversationId, [
|
|
1377
|
+
{ type: "tool_ask_decided", runId: ctx.runId, idemKey, payload },
|
|
1378
|
+
]);
|
|
1379
|
+
const event = report.events[0];
|
|
1380
|
+
if (event?.type !== "tool_ask_decided")
|
|
1381
|
+
throw new Error("The ask decision was not recorded");
|
|
1382
|
+
const fresh = report.fresh[0] === true;
|
|
1383
|
+
if (fresh) {
|
|
1384
|
+
await audit(this.deps.db, {
|
|
1385
|
+
actorAccountId: ctx.accountId,
|
|
1386
|
+
orgId: ctx.orgId,
|
|
1387
|
+
action: "tool.ask_auto_decided",
|
|
1388
|
+
target: ctx.conversationId,
|
|
1389
|
+
detail: {
|
|
1390
|
+
callId: payload.callId,
|
|
1391
|
+
runId: ctx.runId,
|
|
1392
|
+
toolKey: payload.toolKey,
|
|
1393
|
+
outcome: payload.outcome,
|
|
1394
|
+
decisionSource: payload.decisionSource,
|
|
1395
|
+
profileRevision: payload.profileRevision,
|
|
1396
|
+
reason: payload.reason,
|
|
1397
|
+
},
|
|
1398
|
+
});
|
|
1399
|
+
}
|
|
1400
|
+
return { event, fresh };
|
|
1401
|
+
}
|
|
1174
1402
|
/**
|
|
1175
1403
|
* The command review of one call (auto mode spec §5.1, §5.4), after argument validation and the
|
|
1176
1404
|
* tool policy (and its approval), before the plugin hooks and execution. The device facts come
|
|
@@ -1439,7 +1667,12 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1439
1667
|
const unverified = buildPermissionCandidate({ toolKey: tool.key, specHash: tool.specHash, rawInput: call.input, validatedInput: input }, facts, [device.home, device.deviceHome], { backgroundMaxSeconds: backgroundMaxSeconds(this.config.get()) });
|
|
1440
1668
|
if (unverified.kind === "in-scope")
|
|
1441
1669
|
return null;
|
|
1442
|
-
|
|
1670
|
+
// a device that cannot run scoped work at all says why (R9); one not checked yet says that
|
|
1671
|
+
const content = unverified.kind !== "proposal"
|
|
1672
|
+
? unverified.message
|
|
1673
|
+
: facts.availability.state === "unsupported"
|
|
1674
|
+
? admissionUnavailableText(facts.availability.cause ?? { kind: "runtime" })
|
|
1675
|
+
: PERMISSION_SUPPORT_UNVERIFIED_TEXT;
|
|
1443
1676
|
return { kind: "result", content, review: denyRecord("rule", null, content) };
|
|
1444
1677
|
}
|
|
1445
1678
|
if (tool.key === "Bash" && textField(input, "command").length > COMMAND_ASK_MAX_CHARS)
|
|
@@ -1922,24 +2155,86 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1922
2155
|
return null;
|
|
1923
2156
|
}
|
|
1924
2157
|
/**
|
|
1925
|
-
*
|
|
1926
|
-
*
|
|
2158
|
+
* The secure input of a call with person fields (R4): the latest request of the call, bound like
|
|
2159
|
+
* an approval to the definition and the raw input it was made for. None, or a submitted one made
|
|
2160
|
+
* for another definition or input, asks again; a pending one waits. A cancel, an expiry or a
|
|
2161
|
+
* stopped run ends the call with nothing run; a submitted one returns its id, which the tool
|
|
2162
|
+
* reads the sealed values by. The request goes to the run's person, who alone may submit it.
|
|
2163
|
+
*/
|
|
2164
|
+
async secureInput(ctx, call, tool, policyKey, personFields) {
|
|
2165
|
+
let si = await this.deps.approvals.secureInputForCall(ctx.runId, call.id);
|
|
2166
|
+
const current = si !== null &&
|
|
2167
|
+
si.specHash === tool.specHash &&
|
|
2168
|
+
canonicalJson(si.input) === canonicalJson(call.input ?? {});
|
|
2169
|
+
// only a submitted request is re-asked when stale: a pending one keeps waiting (the person
|
|
2170
|
+
// still sees and may submit it; the stale check then asks again), and a cancelled or expired
|
|
2171
|
+
// one ends the call, as a decided approval keeps governing its call
|
|
2172
|
+
if (si === null || (si.status === "approved" && !current)) {
|
|
2173
|
+
si = await this.deps.approvals.requestSecureInput({
|
|
2174
|
+
attempt: (await this.lastAttempt(ctx.runId, call.id)) + 1,
|
|
2175
|
+
orgId: ctx.orgId,
|
|
2176
|
+
conversationId: ctx.conversationId,
|
|
2177
|
+
runId: ctx.runId,
|
|
2178
|
+
step: ctx.step,
|
|
2179
|
+
callId: call.id,
|
|
2180
|
+
toolKey: policyKey,
|
|
2181
|
+
specHash: tool.specHash,
|
|
2182
|
+
connectorId: tool.source.kind === "connector" ? tool.source.connectorId : null,
|
|
2183
|
+
input: call.input,
|
|
2184
|
+
requestedFor: ctx.accountId,
|
|
2185
|
+
target: personFields.target,
|
|
2186
|
+
personFields: personFields.fields,
|
|
2187
|
+
});
|
|
2188
|
+
}
|
|
2189
|
+
switch (si.status) {
|
|
2190
|
+
case "pending":
|
|
2191
|
+
return { kind: "wait", wait: approvalWait(si) };
|
|
2192
|
+
case "approved":
|
|
2193
|
+
return { kind: "submitted", id: si.id };
|
|
2194
|
+
case "denied":
|
|
2195
|
+
return {
|
|
2196
|
+
kind: "refused",
|
|
2197
|
+
text: withLeakedOnCard(secureInputCancelledText(si.id), si.leakedFields),
|
|
2198
|
+
};
|
|
2199
|
+
case "expired":
|
|
2200
|
+
// the request's own wait (creation to expiry), not the current config
|
|
2201
|
+
return {
|
|
2202
|
+
kind: "refused",
|
|
2203
|
+
text: withLeakedOnCard(secureInputExpiredText(si.id, approvalHours(si)), si.leakedFields),
|
|
2204
|
+
};
|
|
2205
|
+
default:
|
|
2206
|
+
return {
|
|
2207
|
+
kind: "refused",
|
|
2208
|
+
text: withLeakedOnCard(APPROVAL_CANCELLED_TEXT, si.leakedFields),
|
|
2209
|
+
};
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
/** The highest attempt of any approval of the call, of every kind (0: none yet). */
|
|
2213
|
+
async lastAttempt(runId, callId) {
|
|
2214
|
+
const row = await this.deps.db
|
|
2215
|
+
.selectFrom("approvals")
|
|
2216
|
+
.select(sql `max(attempt)`.as("attempt"))
|
|
2217
|
+
.where("run_id", "=", runId)
|
|
2218
|
+
.where("call_id", "=", callId)
|
|
2219
|
+
.executeTakeFirst();
|
|
2220
|
+
return Number(row?.attempt ?? 0);
|
|
2221
|
+
}
|
|
2222
|
+
/**
|
|
2223
|
+
* A decided tool approval other than approved → the model's text; still pending → null (wait).
|
|
2224
|
+
* A tool approval takes no values (a secure input does), so it never names leaked fields.
|
|
1927
2225
|
*/
|
|
1928
2226
|
refusalText(a) {
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
}
|
|
1941
|
-
})();
|
|
1942
|
-
return text === null ? null : withLeakedOnCard(text, a.leakedFields);
|
|
2227
|
+
switch (a.status) {
|
|
2228
|
+
case "denied":
|
|
2229
|
+
return approvalDeniedText(a.denyReason);
|
|
2230
|
+
case "expired":
|
|
2231
|
+
// Use the approval's own wait (creation to expiry), not the current config: it can be hot-reloaded
|
|
2232
|
+
return approvalExpiredText(approvalHours(a));
|
|
2233
|
+
case "cancelled":
|
|
2234
|
+
return APPROVAL_CANCELLED_TEXT;
|
|
2235
|
+
default:
|
|
2236
|
+
return null;
|
|
2237
|
+
}
|
|
1943
2238
|
}
|
|
1944
2239
|
/**
|
|
1945
2240
|
* A handler returned `input_required`: past the round limit, an invalid form
|
|
@@ -1984,7 +2279,11 @@ let ToolPipeline = class ToolPipeline {
|
|
|
1984
2279
|
*/
|
|
1985
2280
|
async execute(tool, input, ctx, callId, resume, stepTools, reviewed,
|
|
1986
2281
|
/** The approved approval of this call, matching its definition and input (builtins only). */
|
|
1987
|
-
approvalId
|
|
2282
|
+
approvalId,
|
|
2283
|
+
/** The automatic decision the call runs under instead of an approval (builtins only, R2). */
|
|
2284
|
+
decision,
|
|
2285
|
+
/** The submitted secure input request of this call (builtins only, R4). */
|
|
2286
|
+
secureInputId) {
|
|
1988
2287
|
const reviewedWorkingRoot = reviewed?.workingRoot;
|
|
1989
2288
|
const reviewedAgainstRoot = reviewed?.against;
|
|
1990
2289
|
if (tool.source.kind === "connector") {
|
|
@@ -2013,6 +2312,8 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2013
2312
|
...(tool.source.kind === "builtin" &&
|
|
2014
2313
|
ctx.deadline !== undefined && { runDeadline: ctx.deadline }),
|
|
2015
2314
|
...(tool.source.kind === "builtin" && approvalId !== undefined && { approvalId }),
|
|
2315
|
+
...(tool.source.kind === "builtin" && decision !== undefined && { decision }),
|
|
2316
|
+
...(tool.source.kind === "builtin" && secureInputId !== undefined && { secureInputId }),
|
|
2016
2317
|
// a reviewed call runs in the working root its review judged (project root spec §4.3)
|
|
2017
2318
|
...(tool.source.kind === "builtin" &&
|
|
2018
2319
|
reviewedWorkingRoot !== undefined && { reviewedWorkingRoot }),
|
|
@@ -2440,6 +2741,9 @@ let ToolPipeline = class ToolPipeline {
|
|
|
2440
2741
|
__decorate([
|
|
2441
2742
|
Transactional({ propagation: "mandatory" })
|
|
2442
2743
|
], ToolPipeline.prototype, "stopOpenAgentCalls", null);
|
|
2744
|
+
__decorate([
|
|
2745
|
+
Transactional()
|
|
2746
|
+
], ToolPipeline.prototype, "recordAskDecisionIn", null);
|
|
2443
2747
|
__decorate([
|
|
2444
2748
|
Transactional()
|
|
2445
2749
|
], ToolPipeline.prototype, "findPermissionGrant", null);
|
|
@@ -2489,6 +2793,10 @@ ToolPipeline = __decorate([
|
|
|
2489
2793
|
__param(26, Optional()),
|
|
2490
2794
|
__param(26, Inject(PERMISSION_CONTEXT_ACTIVATION)),
|
|
2491
2795
|
__param(27, Optional()),
|
|
2492
|
-
__param(27, Inject(SandboxService))
|
|
2796
|
+
__param(27, Inject(SandboxService)),
|
|
2797
|
+
__param(28, Optional()),
|
|
2798
|
+
__param(28, Inject(ConversationApprovalProfile)),
|
|
2799
|
+
__param(29, Optional()),
|
|
2800
|
+
__param(29, Inject(ToolAskReview))
|
|
2493
2801
|
], ToolPipeline);
|
|
2494
2802
|
export { ToolPipeline };
|
package/dist/tools/policy.d.ts
CHANGED
|
@@ -79,9 +79,10 @@ export declare function connectorPolicy(input: {
|
|
|
79
79
|
* - in `fail` mode an ask still left is refused (`{ refused, missingGrant }`, no approval), and
|
|
80
80
|
* `AskUserQuestion` is refused; in `wait` mode both ask the creator as in an attended run.
|
|
81
81
|
*
|
|
82
|
-
* A call
|
|
83
|
-
*
|
|
84
|
-
*
|
|
82
|
+
* A call only the person may confirm (`CallPolicy.personOnly`) is a fixed ask: no grant or agent
|
|
83
|
+
* `allow` lets it through (ruling R6). Person fields (`CallPolicy.personFields`) no longer force
|
|
84
|
+
* the ask (profiles govern every approval, R5): the pipeline asks for their values in a secure
|
|
85
|
+
* input request after the consent. The pipeline refuses both before this in an unattended run.
|
|
85
86
|
*/
|
|
86
87
|
export declare function createDecidePolicy(db: KernelSchemaDb,
|
|
87
88
|
/** Logs (debug: once per call) when an org's stored security setting is unreadable. */
|
package/dist/tools/policy.js
CHANGED
|
@@ -102,9 +102,10 @@ export function connectorPolicy(input) {
|
|
|
102
102
|
* - in `fail` mode an ask still left is refused (`{ refused, missingGrant }`, no approval), and
|
|
103
103
|
* `AskUserQuestion` is refused; in `wait` mode both ask the creator as in an attended run.
|
|
104
104
|
*
|
|
105
|
-
* A call
|
|
106
|
-
*
|
|
107
|
-
*
|
|
105
|
+
* A call only the person may confirm (`CallPolicy.personOnly`) is a fixed ask: no grant or agent
|
|
106
|
+
* `allow` lets it through (ruling R6). Person fields (`CallPolicy.personFields`) no longer force
|
|
107
|
+
* the ask (profiles govern every approval, R5): the pipeline asks for their values in a secure
|
|
108
|
+
* input request after the consent. The pipeline refuses both before this in an unattended run.
|
|
108
109
|
*/
|
|
109
110
|
export function createDecidePolicy(db,
|
|
110
111
|
/** Logs (debug: once per call) when an org's stored security setting is unreadable. */
|
|
@@ -253,10 +254,9 @@ log) {
|
|
|
253
254
|
tool.source.kind === "builtin" &&
|
|
254
255
|
tool.key === BUILTIN.Platform &&
|
|
255
256
|
changesAgentSkills(policyKey);
|
|
256
|
-
// person
|
|
257
|
-
//
|
|
257
|
+
// a call only the person may confirm (its result is shown to them once, R6) asks every time,
|
|
258
|
+
// outside every grant, and no agent `allow` lifts it
|
|
258
259
|
const fixedAsk = unattendedSkillChange ||
|
|
259
|
-
call?.personFields !== undefined ||
|
|
260
260
|
call?.personOnly === true ||
|
|
261
261
|
isFixedAsk(tool) ||
|
|
262
262
|
(call !== null && !call.remember && (call.policy !== "allow" || agentOverride !== undefined));
|