@capybara-hq/kernel 0.1.0-rc.97 → 0.1.0-rc.99
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 +17 -17
- package/dist/catalog/git-source.d.ts +5 -0
- package/dist/catalog/git-source.js +9 -5
- package/dist/catalog/marketplace-fetch.d.ts +9 -0
- package/dist/catalog/marketplace-fetch.js +9 -5
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/channels.schemas.d.ts +10 -0
- package/dist/channels/channels.schemas.js +7 -0
- package/dist/channels/connections.service.d.ts +7 -0
- package/dist/channels/connections.service.js +4 -0
- package/dist/channels/features.d.ts +18 -1
- package/dist/channels/features.js +22 -0
- package/dist/channels/outbound.d.ts +19 -0
- package/dist/channels/outbound.js +531 -18
- package/dist/channels/phrases.d.ts +10 -0
- package/dist/channels/phrases.js +4 -0
- package/dist/channels/progress.d.ts +75 -0
- package/dist/channels/progress.js +216 -0
- package/dist/conversations/event-log.d.ts +8 -2
- package/dist/conversations/events.d.ts +6 -0
- package/dist/conversations/events.js +7 -1
- package/dist/conversations/prompt-suggestions.js +2 -2
- package/dist/db/kernel-schema.d.ts +16 -0
- package/dist/evals/run-replay.js +2 -2
- package/dist/evals/step-replay.js +2 -2
- package/dist/evals/worker.js +3 -1
- package/dist/extensions/plugin-icons.d.ts +7 -0
- package/dist/extensions/plugin-icons.js +8 -0
- package/dist/models/purposes.js +2 -2
- package/dist/net/safe-fetch.d.ts +22 -4
- package/dist/net/safe-fetch.js +74 -0
- package/dist/platform/file-ref.d.ts +2 -0
- package/dist/platform/file-ref.js +1 -3
- package/dist/platform/ops/channels.ops.js +24 -5
- package/dist/runtime/model-call.d.ts +23 -2
- package/dist/runtime/model-call.js +64 -9
- package/dist/runtime/run-drafts.d.ts +46 -4
- package/dist/runtime/run-drafts.js +110 -9
- package/dist/runtime/run-steps.d.ts +2 -1
- package/dist/runtime/run-steps.js +6 -2
- package/dist/runtime/runtime.module.js +3 -0
- package/dist/runtime/stream.controller.d.ts +7 -5
- package/dist/runtime/stream.controller.js +10 -6
- package/dist/runtime/stream.js +9 -1
- package/dist/runtime/write-base.d.ts +95 -0
- package/dist/runtime/write-base.js +281 -0
- package/dist/runtime/write-base.service.d.ts +68 -0
- package/dist/runtime/write-base.service.js +184 -0
- package/dist/sandbox/kernel-read.d.ts +39 -9
- package/dist/sandbox/kernel-read.js +33 -3
- package/dist/sandbox/operation-authority.d.ts +16 -12
- package/dist/sandbox/operation-authority.js +33 -20
- package/dist/sandbox/operation-intents.d.ts +10 -4
- package/dist/sandbox/operation-intents.js +31 -11
- package/dist/sandbox/sandbox.service.d.ts +30 -7
- package/dist/sandbox/sandbox.service.js +47 -13
- package/dist/tools/builtins/agent.js +4 -0
- package/dist/tools/builtins/image/generate.js +1 -0
- package/dist/tools/builtins/platform.js +4 -3
- package/dist/tools/builtins/sandbox/bash.d.ts +3 -1
- package/dist/tools/builtins/sandbox/bash.js +23 -11
- package/dist/tools/builtins/sandbox/common.d.ts +4 -1
- package/dist/tools/builtins/sandbox/common.js +5 -2
- package/dist/tools/builtins/sandbox/edit.js +1 -0
- package/dist/tools/builtins/sandbox/glob.js +2 -1
- package/dist/tools/builtins/sandbox/grep.js +2 -1
- package/dist/tools/builtins/sandbox/search-command.d.ts +4 -3
- package/dist/tools/builtins/sandbox/search-command.js +11 -3
- package/dist/tools/builtins/sandbox/write.js +1 -0
- package/dist/tools/builtins/send-message.js +1 -0
- package/dist/tools/info.d.ts +21 -2
- package/dist/tools/info.js +55 -12
- package/dist/tools/network-asks.d.ts +23 -0
- package/dist/tools/network-asks.js +24 -5
- package/dist/tools/pipeline.d.ts +3 -1
- package/dist/tools/pipeline.js +76 -12
- package/dist/tools/registry.d.ts +12 -11
- package/dist/tools/registry.js +6 -5
- package/package.json +3 -3
- package/src/migrations/0185_channel_process_display.sql +13 -0
|
@@ -70,7 +70,7 @@ import { canonicalJson } from "../tools/canonical-json.js";
|
|
|
70
70
|
import { attachmentsDir } from "./attachments-path.js";
|
|
71
71
|
import { CloudPermissionSnapshots, } from "./cloud-permission-snapshot.js";
|
|
72
72
|
import { DeviceReports } from "./device-reports.js";
|
|
73
|
-
import { isKernelReadMethod, KernelReadNotAdmitted, KernelReadUnsupported, } from "./kernel-read.js";
|
|
73
|
+
import { isKernelReadMethod, KernelReadInstanceNotRunning, KernelReadNotAdmitted, KernelReadUnsupported, } from "./kernel-read.js";
|
|
74
74
|
import { SandboxLeases, SandboxLockLostError, sandboxBusy, } from "./leases.js";
|
|
75
75
|
import { isKnownProvider, LegacyRetirementStore } from "./legacy-retirement.js";
|
|
76
76
|
import { ManagedDeviceContextFailed } from "./managed-device-context.js";
|
|
@@ -756,7 +756,7 @@ let SandboxService = class SandboxService {
|
|
|
756
756
|
const impl = tagged(p.impl, lease.token, undefined, () => this.register(env, lease.token));
|
|
757
757
|
const sig = AbortSignal.any([signal, lease.signal]);
|
|
758
758
|
try {
|
|
759
|
-
return { kind: "ran", value: await fn(impl, e.handle, sig) };
|
|
759
|
+
return { kind: "ran", value: await fn(impl, e.handle, sig, e) };
|
|
760
760
|
}
|
|
761
761
|
catch (err) {
|
|
762
762
|
if (isFileSystemGoneError(err))
|
|
@@ -1083,23 +1083,57 @@ let SandboxService = class SandboxService {
|
|
|
1083
1083
|
}
|
|
1084
1084
|
}
|
|
1085
1085
|
/**
|
|
1086
|
-
* A
|
|
1087
|
-
*
|
|
1088
|
-
*
|
|
1089
|
-
*
|
|
1090
|
-
*
|
|
1091
|
-
*
|
|
1092
|
-
*
|
|
1086
|
+
* A kernel read of the device on behalf of a run (permission activation L2), whose provider
|
|
1087
|
+
* stats, reads and lists only, each call a kernel read admitted and claimed on its own
|
|
1088
|
+
* (`SandboxOperationIntents.admitKernelRead`: the run's current claim with its run in the state
|
|
1089
|
+
* the purpose needs, a random operation id, the profile scope narrowed to the one covering
|
|
1090
|
+
* path). Any other method is refused before admission. No path lease is taken. By purpose:
|
|
1091
|
+
* - `project_root` (Hook 1, the run `queued`): the use a tool call's would be (the instance made
|
|
1092
|
+
* or resumed, the read silent for the holder), narrowed to the root, its `AGENTS.md` and its
|
|
1093
|
+
* `.agents/skills`.
|
|
1094
|
+
* - `write_base` (streaming tool input spec §4.1, the run `running`): only on the device's
|
|
1095
|
+
* running instance, as an owner browse is ({@link ifRunning}): it never makes, wakes, resumes
|
|
1096
|
+
* or rebuilds one (else {@link KernelReadInstanceNotRunning}) and touches no seen record;
|
|
1097
|
+
* `stat` and `readFile` of exactly its path.
|
|
1098
|
+
* Only the kernel's own run code calls this: no tool context, Platform operation or route has it.
|
|
1093
1099
|
*/
|
|
1094
1100
|
async withKernelRead(ctx, read, fn, signal) {
|
|
1095
1101
|
const c = read.claim;
|
|
1096
|
-
if (read.purpose !== "project_root" ||
|
|
1102
|
+
if ((read.purpose !== "project_root" && read.purpose !== "write_base") ||
|
|
1097
1103
|
c.orgId !== ctx.orgId ||
|
|
1098
1104
|
c.conversationId !== ctx.holderConversationId ||
|
|
1099
1105
|
c.runId !== ctx.actor.runId ||
|
|
1100
1106
|
ctx.actor.conversationId !== ctx.holderConversationId)
|
|
1101
|
-
throw new SandboxScopeDeniedError("The kernel read does not match its run
|
|
1102
|
-
|
|
1107
|
+
throw new SandboxScopeDeniedError("The kernel read does not match its run");
|
|
1108
|
+
if (read.purpose === "project_root")
|
|
1109
|
+
return this.withSandboxUse(ctx, { kind: "kernelRead", read, fn }, signal);
|
|
1110
|
+
return this.withRunningKernelRead(ctx, read, fn, signal);
|
|
1111
|
+
}
|
|
1112
|
+
/**
|
|
1113
|
+
* A `write_base` kernel read ({@link withKernelRead}) on the instance the device runs now, under
|
|
1114
|
+
* a shared lease taken the way {@link ifRunning} takes it (B1 reconcile marker and retirement
|
|
1115
|
+
* gate included): a device with no running instance, or one that changes instance before the
|
|
1116
|
+
* lease, throws {@link KernelReadInstanceNotRunning} with nothing made, woken or sent.
|
|
1117
|
+
*
|
|
1118
|
+
* Unlike a use's `enter`, this path neither applies changed limits (`mustApply`, which needs the
|
|
1119
|
+
* exclusive lease and may rebuild the instance) nor refreshes stale cloud evidence
|
|
1120
|
+
* (`refreshCloudSupport`, B-15), since either would be lifecycle work a display-only read must
|
|
1121
|
+
* not cause. That is acceptable here: the read only stats and reads one file, its scope carries
|
|
1122
|
+
* no write roots (an instance boundary's own scope aside) and network `none`, and the boundary
|
|
1123
|
+
* is the kernel-side covering-path check at admission and claim, not the instance's applied
|
|
1124
|
+
* limits. Stale evidence still picks among the routes `kernelReadRoute` allows (Full access
|
|
1125
|
+
* only on an instance boundary), so the read stays one path, read-only, with no network; a
|
|
1126
|
+
* provider that no longer accepts the scope refuses it, and the person just gets no base.
|
|
1127
|
+
*/
|
|
1128
|
+
async withRunningKernelRead(ctx, read, fn, signal) {
|
|
1129
|
+
const p = await this.require(ctx.deviceId, ctx.orgId);
|
|
1130
|
+
const row = await this.readRow(ctx);
|
|
1131
|
+
if (!this.usable(row, p, null))
|
|
1132
|
+
throw new KernelReadInstanceNotRunning();
|
|
1133
|
+
const result = await this.ifRunningAs(ctx.deviceId, { createdAt: row.created_at }, (_tagged, h, sig, held) => fn(h, this.kernelReadProvider(held, ctx, p, read, sig), { fresh: false, restarted: false, roots: rootsOf(h) }, sig), signal, true);
|
|
1134
|
+
if (result.kind !== "ran")
|
|
1135
|
+
throw new KernelReadInstanceNotRunning();
|
|
1136
|
+
return result.value;
|
|
1103
1137
|
}
|
|
1104
1138
|
async withOperations(ctx, invocation, fn, signal) {
|
|
1105
1139
|
return this.withSandboxUse(ctx, { kind: "operations", invocation, fn }, signal);
|
|
@@ -1493,7 +1527,7 @@ let SandboxService = class SandboxService {
|
|
|
1493
1527
|
sig.throwIfAborted();
|
|
1494
1528
|
try {
|
|
1495
1529
|
const value = await invoke(parseSandboxOperationScope(admitted.scope), sig);
|
|
1496
|
-
await runOutsideTransaction(() => this.operationIntents.complete(admitted.operation_id, admitted.execution_id, value));
|
|
1530
|
+
await runOutsideTransaction(() => this.operationIntents.complete(admitted.operation_id, admitted.execution_id, value, read.purpose));
|
|
1497
1531
|
return value;
|
|
1498
1532
|
}
|
|
1499
1533
|
catch (error) {
|
|
@@ -21,6 +21,8 @@ export const AgentToolInput = z
|
|
|
21
21
|
.strict();
|
|
22
22
|
/** Display only (UI refresh B): the task name, then the type; never sent to the model. */
|
|
23
23
|
const KEY_ARGS = ["description", "subagent_type"];
|
|
24
|
+
/** Display only: the brief streams as text while the call is written. */
|
|
25
|
+
const INPUT_VIEW = { kind: "text", field: "prompt" };
|
|
24
26
|
const INPUT_SCHEMA = {
|
|
25
27
|
type: "object",
|
|
26
28
|
properties: {
|
|
@@ -96,6 +98,7 @@ export function agentToolSpec(roster, maxConcurrent) {
|
|
|
96
98
|
description: head(maxConcurrent) + roster.map(rosterLine).join("\n"),
|
|
97
99
|
inputSchema: INPUT_SCHEMA,
|
|
98
100
|
keyArgs: KEY_ARGS,
|
|
101
|
+
inputView: INPUT_VIEW,
|
|
99
102
|
};
|
|
100
103
|
}
|
|
101
104
|
/**
|
|
@@ -122,6 +125,7 @@ const SPEC = {
|
|
|
122
125
|
"- general-purpose: a copy of you with your tools and skills, for multi-step work.",
|
|
123
126
|
inputSchema: INPUT_SCHEMA,
|
|
124
127
|
keyArgs: KEY_ARGS,
|
|
128
|
+
inputView: INPUT_VIEW,
|
|
125
129
|
};
|
|
126
130
|
/** Refusals (§4.5): `isError` results written without starting anything (model-visible). */
|
|
127
131
|
export const AGENT_REFUSALS = {
|
|
@@ -57,6 +57,7 @@ export const GENERATE_IMAGE_SPEC = {
|
|
|
57
57
|
name: "GenerateImage",
|
|
58
58
|
// Display only (the tool row; not in the fingerprint, never sent to the model).
|
|
59
59
|
keyArgs: ["prompt"],
|
|
60
|
+
inputView: { kind: "text", field: "prompt" },
|
|
60
61
|
description: "Generate images from a text prompt with this organization's image model, and deliver them to " +
|
|
61
62
|
"the user in the conversation. Write a specific prompt: subject, composition, style, lighting, " +
|
|
62
63
|
"any text that must appear. " +
|
|
@@ -382,7 +382,7 @@ export function platformTool(deps) {
|
|
|
382
382
|
let file;
|
|
383
383
|
let card = null;
|
|
384
384
|
try {
|
|
385
|
-
file = await fileOf(op, params, deps, octx, ctx.signal);
|
|
385
|
+
file = await fileOf(op, params, deps, octx, ctx.rootConversationId ?? ctx.conversationId, ctx.signal);
|
|
386
386
|
if (file !== null)
|
|
387
387
|
card = await fileCardDetail(file);
|
|
388
388
|
}
|
|
@@ -510,7 +510,7 @@ export function platformTool(deps) {
|
|
|
510
510
|
let result;
|
|
511
511
|
try {
|
|
512
512
|
// the file is read again, and must be the bytes the person confirmed (Review Focus 5)
|
|
513
|
-
const file = await fileOf(op, params, deps, octx, ctx.signal);
|
|
513
|
+
const file = await fileOf(op, params, deps, octx, ctx.rootConversationId, ctx.signal);
|
|
514
514
|
if (file !== null) {
|
|
515
515
|
// fails closed: bytes run only under this call's approval whose card showed them or,
|
|
516
516
|
// with no approval, the automatic decision that was bound to them (R7); a grant, an
|
|
@@ -637,7 +637,7 @@ export function platformTool(deps) {
|
|
|
637
637
|
* against its limits; null when the operation takes none for this input. Refusals are
|
|
638
638
|
* model-visible `ToolError`s; other errors propagate.
|
|
639
639
|
*/
|
|
640
|
-
async function fileOf(op, params, deps, ctx, signal) {
|
|
640
|
+
async function fileOf(op, params, deps, ctx, rootConversationId, signal) {
|
|
641
641
|
const wanted = op.fileRef?.(params) ?? null;
|
|
642
642
|
if (wanted === null)
|
|
643
643
|
return null;
|
|
@@ -646,6 +646,7 @@ async function fileOf(op, params, deps, ctx, signal) {
|
|
|
646
646
|
return deps.files.resolve(wanted.ref, wanted.limits, {
|
|
647
647
|
orgId: ctx.orgId,
|
|
648
648
|
conversationId: ctx.conversationId,
|
|
649
|
+
rootConversationId,
|
|
649
650
|
signal: signal ?? ctx.signal,
|
|
650
651
|
});
|
|
651
652
|
}
|
|
@@ -51,11 +51,13 @@ export declare const sandboxDenied: (r: ExecResult) => boolean;
|
|
|
51
51
|
* sandbox closes, then either the invitation to retry escalated (this device and org allow running
|
|
52
52
|
* outside the sandbox) or why that is not possible here and who can change it (the per-layer
|
|
53
53
|
* escalation refusal). Empty for an escalated call, a call without escalation facts, or no signal.
|
|
54
|
+
* `afterAddressNote`: the line follows a network note that already says private and local
|
|
55
|
+
* addresses are closed inside the sandbox, so a network denial's lead is left out.
|
|
54
56
|
*/
|
|
55
57
|
export declare function sandboxDenialHint(r: ExecResult, escalation: {
|
|
56
58
|
escalation?: "available" | "escalated";
|
|
57
59
|
refusal?: string;
|
|
58
|
-
}): string;
|
|
60
|
+
}, afterAddressNote?: boolean): string;
|
|
59
61
|
/**
|
|
60
62
|
* {@link SCOPE_DENIED_TOOL_TEXT} followed by {@link ESCALATION_RETRY_HINT}, written out as a literal
|
|
61
63
|
* for the tool design check (a unit test keeps the two copies equal).
|
|
@@ -18,6 +18,7 @@ const SPEC = {
|
|
|
18
18
|
name: "Bash",
|
|
19
19
|
// Display only (the tool row; not in the fingerprint, never sent to the model).
|
|
20
20
|
keyArgs: ["command"],
|
|
21
|
+
inputView: { kind: "command", command: "command", description: "description" },
|
|
21
22
|
description: "Run a shell command (bash) in this conversation's sandbox, an isolated machine. " +
|
|
22
23
|
"Use it to run programs and scripts, install packages, process files and inspect the " +
|
|
23
24
|
"filesystem. The working directory is the workspace directory; files persist between calls in the same " +
|
|
@@ -418,15 +419,19 @@ export const sandboxDenied = (r) => sandboxDenial(r) !== null;
|
|
|
418
419
|
* sandbox closes, then either the invitation to retry escalated (this device and org allow running
|
|
419
420
|
* outside the sandbox) or why that is not possible here and who can change it (the per-layer
|
|
420
421
|
* escalation refusal). Empty for an escalated call, a call without escalation facts, or no signal.
|
|
422
|
+
* `afterAddressNote`: the line follows a network note that already says private and local
|
|
423
|
+
* addresses are closed inside the sandbox, so a network denial's lead is left out.
|
|
421
424
|
*/
|
|
422
|
-
export function sandboxDenialHint(r, escalation) {
|
|
425
|
+
export function sandboxDenialHint(r, escalation, afterAddressNote = false) {
|
|
423
426
|
if (escalation.escalation !== "available" && escalation.refusal === undefined)
|
|
424
427
|
return "";
|
|
425
428
|
const kind = sandboxDenial(r);
|
|
426
429
|
if (kind === null)
|
|
427
430
|
return "";
|
|
428
431
|
const lead = kind === "network"
|
|
429
|
-
?
|
|
432
|
+
? afterAddressNote
|
|
433
|
+
? "\n[sandbox]"
|
|
434
|
+
: "\n[sandbox] The OS sandbox may have blocked this command's connection: private and local addresses are closed inside the sandbox, and so is any host the sandbox network does not allow."
|
|
430
435
|
: "\n[sandbox] The OS sandbox may have blocked this command.";
|
|
431
436
|
return escalation.escalation === "available"
|
|
432
437
|
? `${lead}${ESCALATION_RETRY_HINT}`
|
|
@@ -510,14 +515,21 @@ export function sandboxBashTool(deps) {
|
|
|
510
515
|
const lowered = requested !== undefined && requested > maxMs
|
|
511
516
|
? `\n[timeout ${requested} ms is over the deployment maximum; it was lowered to ${maxMs} ms.]`
|
|
512
517
|
: "";
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
518
|
+
const facts = {
|
|
519
|
+
...(ctx.sandboxEscalation !== undefined && { escalation: ctx.sandboxEscalation }),
|
|
520
|
+
...(ctx.sandboxEscalationRefusal !== undefined && {
|
|
521
|
+
refusal: ctx.sandboxEscalationRefusal,
|
|
522
|
+
}),
|
|
523
|
+
};
|
|
524
|
+
// refused hosts become network notes in the pipeline, which picks the denial line that goes
|
|
525
|
+
// with them (`denialHintFor`): none after an address note that says how to run outside the
|
|
526
|
+
// sandbox, so the result carries one instruction about it
|
|
527
|
+
const reported = blocked.length > 0 && deviceId !== "";
|
|
528
|
+
const denialHint = {
|
|
529
|
+
full: sandboxDenialHint(r, facts),
|
|
530
|
+
afterAddressFact: sandboxDenialHint(r, facts, true),
|
|
531
|
+
};
|
|
532
|
+
const text = formatExec(r, seconds, clamped, workspace) + lowered + (reported ? "" : denialHint.full);
|
|
521
533
|
return {
|
|
522
534
|
content: [{ type: "text", text: withNotices(notices, text) }],
|
|
523
535
|
isError: r.timedOut || r.exitCode === null,
|
|
@@ -534,7 +546,7 @@ export function sandboxBashTool(deps) {
|
|
|
534
546
|
? display(`命令被中止:${shown}`, `Command stopped: ${shown}`)
|
|
535
547
|
: display(`运行命令(退出码 ${r.exitCode}):${shown}`, `Ran command (exit ${r.exitCode}): ${shown}`),
|
|
536
548
|
// kernel-internal: the pipeline asks the device owner or writes notes (spec §6.2)
|
|
537
|
-
...(
|
|
549
|
+
...(reported && { networkReport: { deviceId, blocked, denialHint } }),
|
|
538
550
|
// kernel-internal: the pipeline writes the display-only `device_code` event (auto mode §6)
|
|
539
551
|
...(loginCode !== null && { loginCode }),
|
|
540
552
|
};
|
|
@@ -330,7 +330,10 @@ export declare function inSandboxPreparation<T>(deps: SandboxToolDeps, ctx: Buil
|
|
|
330
330
|
export declare function recordManagedDevicePaths(deps: {
|
|
331
331
|
managedDeviceContext: ManagedDeviceContextPort;
|
|
332
332
|
}, ctx: BuiltinCallContext, held: Readonly<HeldDeviceContextEvidence>, signal: AbortSignal): Promise<void>;
|
|
333
|
-
/**
|
|
333
|
+
/**
|
|
334
|
+
* The conversation whose device a call uses (sub-agents spec §10.1, agent map spec §6): the tree
|
|
335
|
+
* root for a sub-agent's call at any depth, the conversation itself otherwise.
|
|
336
|
+
*/
|
|
334
337
|
export declare const sandboxConversationOf: (ctx: BuiltinCallContext) => string;
|
|
335
338
|
/**
|
|
336
339
|
* Runs `fn` under the per-path lease of `path` in the session's device (spec §10.4: the
|
|
@@ -593,8 +593,11 @@ export async function recordManagedDevicePaths(deps, ctx, held, signal) {
|
|
|
593
593
|
accountId: ctx.accountId,
|
|
594
594
|
}, held, signal);
|
|
595
595
|
}
|
|
596
|
-
/**
|
|
597
|
-
|
|
596
|
+
/**
|
|
597
|
+
* The conversation whose device a call uses (sub-agents spec §10.1, agent map spec §6): the tree
|
|
598
|
+
* root for a sub-agent's call at any depth, the conversation itself otherwise.
|
|
599
|
+
*/
|
|
600
|
+
export const sandboxConversationOf = (ctx) => ctx.rootConversationId;
|
|
598
601
|
/**
|
|
599
602
|
* Runs `fn` under the per-path lease of `path` in the session's device (spec §10.4: the
|
|
600
603
|
* kernel's own read-modify-write of one file never loses another holder's update, from any
|
|
@@ -9,6 +9,7 @@ const SPEC = {
|
|
|
9
9
|
name: "Edit",
|
|
10
10
|
// Display only (the tool row; not in the fingerprint, never sent to the model).
|
|
11
11
|
keyArgs: ["file_path"],
|
|
12
|
+
inputView: { kind: "file_edit", path: "file_path", old: "old_string", new: "new_string" },
|
|
12
13
|
description: "Edit a text file in this conversation's sandbox by replacing exact text. old_string must match " +
|
|
13
14
|
"the file exactly (including whitespace and indentation) and, unless replace_all is true, occur " +
|
|
14
15
|
"exactly once; include enough surrounding lines to make it unique. Read the file first; " +
|
|
@@ -14,7 +14,8 @@ const SPEC = {
|
|
|
14
14
|
'locate files by name, e.g. pattern "**/*.py" for all Python files. The pattern is matched ' +
|
|
15
15
|
"against paths relative to path (default: the workspace directory): * matches within one directory, ** " +
|
|
16
16
|
"matches across directories, ? matches one character, {a,b} matches either. Returns absolute " +
|
|
17
|
-
"paths sorted by name, up to 1000. Skips .git
|
|
17
|
+
"paths sorted by name, up to 1000. Skips version control (.git, .hg, .svn, .jj), " +
|
|
18
|
+
"node_modules and .cache directories and, where the " +
|
|
18
19
|
"device supports it, files ignored by .gitignore, .ignore or .rgignore files; to list files " +
|
|
19
20
|
"inside a skipped directory, pass that directory as path. To search file contents, use Grep. " +
|
|
20
21
|
"In auto mode paths may be anywhere on the machine.",
|
|
@@ -18,7 +18,8 @@ const SPEC = {
|
|
|
18
18
|
'syntax as in grep -E, e.g. "log.*Error" or "def (load|save)"; no backreferences or ' +
|
|
19
19
|
"look-around). Use it to find where something is defined or mentioned. Searches path (a " +
|
|
20
20
|
"file, or a directory recursively; default: the workspace directory). A directory search " +
|
|
21
|
-
"skips binary files, .git
|
|
21
|
+
"skips binary files, version control (.git, .hg, .svn, .jj), node_modules and .cache " +
|
|
22
|
+
"directories and, where the device supports it, " +
|
|
22
23
|
"files ignored by .gitignore, .ignore or .rgignore files; to search inside a skipped " +
|
|
23
24
|
"directory, pass that directory or a file in it as path. glob limits " +
|
|
24
25
|
'the files searched by name, e.g. "*.py". output_mode picks what comes back: ' +
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Directories `Grep` and `Glob` never walk into, whatever the ignore files say: version control
|
|
3
|
-
* metadata
|
|
4
|
-
*
|
|
3
|
+
* metadata, installed packages and tool caches (`.cache`: a docker device's HOME is the workspace,
|
|
4
|
+
* so a search of the workspace outside a repository would walk its caches). A path given
|
|
5
|
+
* explicitly is still searched (only directories met while walking are skipped).
|
|
5
6
|
*/
|
|
6
|
-
export declare const ALWAYS_SKIPPED_DIRS: readonly [".git", ".hg", ".svn", ".jj", "node_modules"];
|
|
7
|
+
export declare const ALWAYS_SKIPPED_DIRS: readonly [".git", ".hg", ".svn", ".jj", "node_modules", ".cache"];
|
|
7
8
|
export type GrepMode = "content" | "files_with_matches" | "count";
|
|
8
9
|
export interface GrepCommandOptions {
|
|
9
10
|
mode: GrepMode;
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { shellQuote } from "./common.js";
|
|
2
2
|
/**
|
|
3
3
|
* Directories `Grep` and `Glob` never walk into, whatever the ignore files say: version control
|
|
4
|
-
* metadata
|
|
5
|
-
*
|
|
4
|
+
* metadata, installed packages and tool caches (`.cache`: a docker device's HOME is the workspace,
|
|
5
|
+
* so a search of the workspace outside a repository would walk its caches). A path given
|
|
6
|
+
* explicitly is still searched (only directories met while walking are skipped).
|
|
6
7
|
*/
|
|
7
|
-
export const ALWAYS_SKIPPED_DIRS = [
|
|
8
|
+
export const ALWAYS_SKIPPED_DIRS = [
|
|
9
|
+
".git",
|
|
10
|
+
".hg",
|
|
11
|
+
".svn",
|
|
12
|
+
".jj",
|
|
13
|
+
"node_modules",
|
|
14
|
+
".cache",
|
|
15
|
+
];
|
|
8
16
|
/**
|
|
9
17
|
* Runs `rg` when the device has it, else `fallback`, in one shell command (no extra round trip
|
|
10
18
|
* to find out). Both branches print the same format, so the caller parses either the same way.
|
|
@@ -7,6 +7,7 @@ const SPEC = {
|
|
|
7
7
|
name: "Write",
|
|
8
8
|
// Display only (the tool row; not in the fingerprint, never sent to the model).
|
|
9
9
|
keyArgs: ["file_path"],
|
|
10
|
+
inputView: { kind: "file_write", path: "file_path", content: "content" },
|
|
10
11
|
description: "Write a text file in this conversation's sandbox, creating parent directories as needed. " +
|
|
11
12
|
"Each call replaces the whole file (it is created if missing). Use it to create scripts, " +
|
|
12
13
|
"source files and data files. The path is absolute, under the workspace directory or the " +
|
|
@@ -46,6 +46,7 @@ const SPEC = {
|
|
|
46
46
|
},
|
|
47
47
|
// display only (UI refresh B): who the message goes to; never sent to the model
|
|
48
48
|
keyArgs: ["to"],
|
|
49
|
+
inputView: { kind: "text", field: "message" },
|
|
49
50
|
};
|
|
50
51
|
/** `12345` → `12,345` (no locale data involved, so the text is the same on every replica). */
|
|
51
52
|
const count = (n) => String(Math.round(n)).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
package/dist/tools/info.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { type LocalizedName, type ToolAnnotations } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import { type LocalizedName, type ToolAnnotations, type ToolInputView } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { ConversationAccess } from "../conversations/access.js";
|
|
3
3
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
4
|
+
import { PluginIcons } from "../extensions/plugin-icons.js";
|
|
4
5
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
5
6
|
import { OrgToolSwitches } from "./org-tool-switches.js";
|
|
6
7
|
import { ToolRegistry } from "./registry.js";
|
|
@@ -12,16 +13,31 @@ import { ToolRegistry } from "./registry.js";
|
|
|
12
13
|
export type ToolKind = "command" | "read" | "edit" | "search" | "connector" | "meta"
|
|
13
14
|
/** Reading background tasks (`TaskOutput`, `TaskList`): neither a file read nor a command. */
|
|
14
15
|
| "task" | "tool";
|
|
16
|
+
/**
|
|
17
|
+
* The icon a step of a run shows: a named design icon, or an org catalog item's icon (web:
|
|
18
|
+
* `${org}/catalog/${itemId}/icon`). Display only.
|
|
19
|
+
*/
|
|
20
|
+
export type ToolIcon = {
|
|
21
|
+
kind: "name";
|
|
22
|
+
name: "terminal" | "file-text" | "square-pen" | "search" | "globe" | "skills" | "agent" | "list-checks" | "connector" | "extension";
|
|
23
|
+
} | {
|
|
24
|
+
kind: "catalog";
|
|
25
|
+
itemId: string;
|
|
26
|
+
};
|
|
15
27
|
export interface ToolInfo {
|
|
16
28
|
/** The model-visible tool key, as asked for. */
|
|
17
29
|
key: string;
|
|
18
30
|
/** The declared display title (`ToolSpec.title`), or null. */
|
|
19
31
|
title: string | null;
|
|
20
32
|
kind: ToolKind;
|
|
33
|
+
/** The step's icon in the conversation's process block. */
|
|
34
|
+
icon: ToolIcon;
|
|
21
35
|
/** True exactly for the builtin tools that run in the conversation's sandbox. */
|
|
22
36
|
sandbox: boolean;
|
|
23
37
|
/** The declared key arguments (`ToolSpec.keyArgs`), or []. */
|
|
24
38
|
keyArgs: string[];
|
|
39
|
+
/** The declared streaming input preview (`ToolSpec.inputView`), or null. */
|
|
40
|
+
inputView: ToolInputView | null;
|
|
25
41
|
/**
|
|
26
42
|
* The local tool name parsed from a connector or extension key (`mcp__crm__delete` -> `delete`),
|
|
27
43
|
* shown in brackets after the source's display name; null for builtins and unparsable keys.
|
|
@@ -52,6 +68,8 @@ export declare const TOOL_INFO_KEY_MAX = 200;
|
|
|
52
68
|
export interface ToolInfoDeps {
|
|
53
69
|
db: KernelSchemaDb;
|
|
54
70
|
registry: Pick<ToolRegistry, "builtinSpecs" | "extensionToolSpecs">;
|
|
71
|
+
/** Without it every extension tool gets the generic icon (display-text callers need none). */
|
|
72
|
+
icons?: Pick<PluginIcons, "itemIdsWithIcon">;
|
|
55
73
|
}
|
|
56
74
|
/**
|
|
57
75
|
* Presentation metadata for `keys` in this org, in request order with repeats dropped. Builtins
|
|
@@ -76,9 +94,10 @@ export declare class ConversationToolInfo {
|
|
|
76
94
|
private readonly registry;
|
|
77
95
|
/** Conversation visibility (the same rule as the events API). */
|
|
78
96
|
private readonly access;
|
|
97
|
+
private readonly icons;
|
|
79
98
|
constructor(db: KernelDb, registry: Pick<ToolRegistry, "builtinSpecs" | "extensionToolSpecs">,
|
|
80
99
|
/** Conversation visibility (the same rule as the events API). */
|
|
81
|
-
access: Pick<ConversationAccess, "isAccessible"
|
|
100
|
+
access: Pick<ConversationAccess, "isAccessible">, icons: PluginIcons);
|
|
82
101
|
get(orgId: string, conversationId: string, viewerAccountId: string, keys: readonly string[]): Promise<ToolInfo[]>;
|
|
83
102
|
}
|
|
84
103
|
/** One tool of {@link OrgExtensionTools}. Display only, for the agent form. */
|
package/dist/tools/info.js
CHANGED
|
@@ -7,10 +7,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
|
-
import { connectorToolKey, extensionToolKey, parseToolKey, } from "@capybara-hq/plugin-sdk";
|
|
10
|
+
import { connectorToolKey, extensionToolKey, parseToolKey, validateToolPresentation, } from "@capybara-hq/plugin-sdk";
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { ConversationAccess } from "../conversations/access.js";
|
|
13
13
|
import { ApiError } from "../errors.js";
|
|
14
|
+
import { PluginIcons } from "../extensions/plugin-icons.js";
|
|
14
15
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
15
16
|
import { UUID_RE } from "../ui/registry.js";
|
|
16
17
|
import { BUILTIN_TOOL_KINDS, SANDBOX_TOOL_NAMES } from "./builtin-names.js";
|
|
@@ -18,6 +19,27 @@ import { pluginDisplayNames } from "./display-names.js";
|
|
|
18
19
|
import { toolKeyIssue } from "./naming.js";
|
|
19
20
|
import { OrgToolSwitches } from "./org-tool-switches.js";
|
|
20
21
|
import { policyFromAnnotations, ToolRegistry } from "./registry.js";
|
|
22
|
+
/** Builtin tools whose icon follows the key, ahead of the kind. */
|
|
23
|
+
const BUILTIN_ICONS = {
|
|
24
|
+
WebSearch: "globe",
|
|
25
|
+
WebFetch: "globe",
|
|
26
|
+
Skill: "skills",
|
|
27
|
+
Agent: "agent",
|
|
28
|
+
TaskList: "list-checks",
|
|
29
|
+
// background tasks are commands (process blocks spec §2)
|
|
30
|
+
TaskOutput: "terminal",
|
|
31
|
+
TaskStop: "terminal",
|
|
32
|
+
};
|
|
33
|
+
const KIND_ICONS = {
|
|
34
|
+
command: "terminal",
|
|
35
|
+
read: "file-text",
|
|
36
|
+
edit: "square-pen",
|
|
37
|
+
search: "search",
|
|
38
|
+
};
|
|
39
|
+
const named = (name) => ({
|
|
40
|
+
kind: "name",
|
|
41
|
+
name,
|
|
42
|
+
});
|
|
21
43
|
export { BUILTIN_TOOL_KINDS } from "./builtin-names.js";
|
|
22
44
|
/** At most this many keys per request, each at most {@link TOOL_INFO_KEY_MAX} characters. */
|
|
23
45
|
export const TOOL_INFO_MAX_KEYS = 100;
|
|
@@ -25,6 +47,9 @@ export const TOOL_INFO_KEY_MAX = 200;
|
|
|
25
47
|
const display = (spec) => ({
|
|
26
48
|
title: typeof spec?.title === "string" ? spec.title : null,
|
|
27
49
|
keyArgs: Array.isArray(spec?.keyArgs) ? [...spec.keyArgs] : [],
|
|
50
|
+
inputView: spec?.inputView !== undefined && validateToolPresentation(spec).length === 0
|
|
51
|
+
? structuredClone(spec.inputView)
|
|
52
|
+
: null,
|
|
28
53
|
});
|
|
29
54
|
/**
|
|
30
55
|
* Presentation metadata for `keys` in this org, in request order with repeats dropped. Builtins
|
|
@@ -69,18 +94,27 @@ export async function toolInfo(deps, orgId, keys) {
|
|
|
69
94
|
const e = extensions.get(k);
|
|
70
95
|
return e ? [e.plugin] : [];
|
|
71
96
|
}));
|
|
97
|
+
// An extension's icon is its plugin's catalog item icon, when the org's catalog shows one.
|
|
98
|
+
const catalogItems = (await deps.icons?.itemIdsWithIcon(unique.flatMap((k) => {
|
|
99
|
+
const e = extensions.get(k);
|
|
100
|
+
return e ? [e.plugin] : [];
|
|
101
|
+
}), { kind: "org", orgId, isAdmin: false })) ?? new Map();
|
|
72
102
|
const localTool = (key) => {
|
|
73
103
|
const p = parseToolKey(key);
|
|
74
104
|
return p && p.kind !== "builtin" ? p.tool : null;
|
|
75
105
|
};
|
|
76
|
-
const builtinInfo = (key, spec) =>
|
|
77
|
-
key
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
106
|
+
const builtinInfo = (key, spec) => {
|
|
107
|
+
const kind = BUILTIN_TOOL_KINDS[key] ?? "tool";
|
|
108
|
+
return {
|
|
109
|
+
key,
|
|
110
|
+
...display(spec),
|
|
111
|
+
kind,
|
|
112
|
+
icon: named(BUILTIN_ICONS[key] ?? KIND_ICONS[kind] ?? "extension"),
|
|
113
|
+
sandbox: SANDBOX_TOOL_NAMES.includes(key),
|
|
114
|
+
tool: null,
|
|
115
|
+
source: { kind: "builtin" },
|
|
116
|
+
};
|
|
117
|
+
};
|
|
84
118
|
return unique.map((key) => {
|
|
85
119
|
const b = builtins.get(key);
|
|
86
120
|
if (b)
|
|
@@ -91,6 +125,9 @@ export async function toolInfo(deps, orgId, keys) {
|
|
|
91
125
|
key,
|
|
92
126
|
...display(e.spec),
|
|
93
127
|
kind: "tool",
|
|
128
|
+
icon: catalogItems.has(e.plugin)
|
|
129
|
+
? { kind: "catalog", itemId: catalogItems.get(e.plugin) }
|
|
130
|
+
: named("extension"),
|
|
94
131
|
sandbox: false,
|
|
95
132
|
tool: e.spec.name,
|
|
96
133
|
source: {
|
|
@@ -106,6 +143,7 @@ export async function toolInfo(deps, orgId, keys) {
|
|
|
106
143
|
key,
|
|
107
144
|
...display(c.spec),
|
|
108
145
|
kind: "connector",
|
|
146
|
+
icon: named("connector"),
|
|
109
147
|
sandbox: false,
|
|
110
148
|
tool: c.tool,
|
|
111
149
|
source: { kind: "connector", id: c.id, name: c.name },
|
|
@@ -115,8 +153,10 @@ export async function toolInfo(deps, orgId, keys) {
|
|
|
115
153
|
key,
|
|
116
154
|
title: null,
|
|
117
155
|
kind: "tool",
|
|
156
|
+
icon: named("extension"),
|
|
118
157
|
sandbox: false,
|
|
119
158
|
keyArgs: [],
|
|
159
|
+
inputView: null,
|
|
120
160
|
tool: localTool(key),
|
|
121
161
|
source: { kind: "unknown" },
|
|
122
162
|
};
|
|
@@ -127,26 +167,29 @@ let ConversationToolInfo = class ConversationToolInfo {
|
|
|
127
167
|
db;
|
|
128
168
|
registry;
|
|
129
169
|
access;
|
|
170
|
+
icons;
|
|
130
171
|
constructor(db, registry,
|
|
131
172
|
/** Conversation visibility (the same rule as the events API). */
|
|
132
|
-
access) {
|
|
173
|
+
access, icons) {
|
|
133
174
|
this.db = db;
|
|
134
175
|
this.registry = registry;
|
|
135
176
|
this.access = access;
|
|
177
|
+
this.icons = icons;
|
|
136
178
|
}
|
|
137
179
|
async get(orgId, conversationId, viewerAccountId, keys) {
|
|
138
180
|
if (!UUID_RE.test(conversationId) ||
|
|
139
181
|
!(await this.access.isAccessible(orgId, conversationId, viewerAccountId))) {
|
|
140
182
|
throw new ApiError("conversation.not_found", "Conversation not found");
|
|
141
183
|
}
|
|
142
|
-
return toolInfo({ db: this.db.db, registry: this.registry }, orgId, keys);
|
|
184
|
+
return toolInfo({ db: this.db.db, registry: this.registry, icons: this.icons }, orgId, keys);
|
|
143
185
|
}
|
|
144
186
|
};
|
|
145
187
|
ConversationToolInfo = __decorate([
|
|
146
188
|
Injectable(),
|
|
147
189
|
__param(0, Inject(KernelDb)),
|
|
148
190
|
__param(1, Inject(ToolRegistry)),
|
|
149
|
-
__param(2, Inject(ConversationAccess))
|
|
191
|
+
__param(2, Inject(ConversationAccess)),
|
|
192
|
+
__param(3, Inject(PluginIcons))
|
|
150
193
|
], ConversationToolInfo);
|
|
151
194
|
export { ConversationToolInfo };
|
|
152
195
|
/**
|
|
@@ -203,7 +203,30 @@ export interface NetworkPlan {
|
|
|
203
203
|
notes: string[];
|
|
204
204
|
/** `missing_grants` keys of an unattended run (`network:<host>`). */
|
|
205
205
|
missingGrants: string[];
|
|
206
|
+
/**
|
|
207
|
+
* Whether `notes` hold a private-address note ({@link addressEscalationNote} or
|
|
208
|
+
* {@link addressLayerNote}) and what it says about running outside the sandbox: `remedy` when it
|
|
209
|
+
* also says how (retry escalated) or why that is not possible here, `fact` when it only says
|
|
210
|
+
* that a command run outside the sandbox reaches the address. Absent: no address note.
|
|
211
|
+
*/
|
|
212
|
+
addressNote?: "remedy" | "fact";
|
|
206
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* The two forms of the `Bash` tool's sandbox denial line for a command whose refused hosts become
|
|
216
|
+
* network notes (kernel-internal, `BuiltinResult.networkReport.denialHint`): `full` when no note
|
|
217
|
+
* covers a private address, `afterAddressFact` (without the closed-address lead the note already
|
|
218
|
+
* states) after an address note of kind `fact`.
|
|
219
|
+
*/
|
|
220
|
+
export interface DenialHint {
|
|
221
|
+
full: string;
|
|
222
|
+
afterAddressFact: string;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* The sandbox denial line a command result keeps beside its network notes: one instruction about
|
|
226
|
+
* running outside the sandbox, never two. An address note that says how (or why not) replaces the
|
|
227
|
+
* line; one that states only the fact keeps the line's retry part; without one the line is whole.
|
|
228
|
+
*/
|
|
229
|
+
export declare function denialHintFor(hint: DenialHint | undefined, addressNote: NetworkPlan["addressNote"]): string;
|
|
207
230
|
/** The hosts of a `network_blocked` event: valid, deduplicated, at most {@link NETWORK_ASK_MAX_HOSTS}. */
|
|
208
231
|
export declare function blockedEventHosts(blocked: readonly NetworkBlockedHost[]): NetworkBlockedHost[];
|
|
209
232
|
/**
|