@capybara-hq/kernel 0.1.0-rc.75 → 0.1.0-rc.76
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/dist/agents/readiness.controller.d.ts +4 -3
- package/dist/agents/readiness.controller.js +4 -3
- package/dist/agents/readiness.service.d.ts +44 -11
- package/dist/agents/readiness.service.js +59 -16
- package/dist/catalog/catalog-import.module.d.ts +1 -1
- package/dist/catalog/catalog-import.module.js +1 -1
- package/dist/catalog/cli.d.ts +9 -2
- package/dist/catalog/cli.js +10 -4
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/plugin-upgrade.d.ts +4 -2
- package/dist/catalog/plugin-upgrade.js +9 -3
- package/dist/db/kernel-schema.d.ts +5 -0
- package/dist/devices/device-projects.service.d.ts +3 -12
- package/dist/devices/device-projects.service.js +16 -59
- package/dist/extensions/bootstrap.d.ts +17 -3
- package/dist/extensions/bootstrap.js +56 -14
- package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +16 -11
- package/dist/overrides.d.ts +0 -5
- package/dist/overrides.js +0 -2
- package/dist/platform/file-ref.d.ts +6 -5
- package/dist/platform/ops/agent-skills.ops.js +1 -1
- package/dist/platform/ops/agents.ops.js +1 -1
- package/dist/runtime/model-call.d.ts +2 -2
- package/dist/runtime/project/knowledge.d.ts +1 -1
- package/dist/runtime/project/knowledge.js +1 -1
- package/dist/runtime/project/knowledge.service.d.ts +5 -11
- package/dist/runtime/project/knowledge.service.js +12 -23
- package/dist/runtime/providers.d.ts +34 -1
- package/dist/runtime/providers.js +56 -7
- package/dist/runtime/run-steps.d.ts +4 -6
- package/dist/runtime/run-steps.js +7 -15
- package/dist/runtime/runtime.module.js +1 -1
- package/dist/sandbox/held-operations.d.ts +2 -5
- package/dist/sandbox/held-operations.js +0 -14
- package/dist/sandbox/managed-device-context.d.ts +1 -1
- package/dist/sandbox/managed-device-context.js +1 -1
- package/dist/sandbox/permission-context-types.d.ts +0 -11
- package/dist/sandbox/permission-context-types.js +0 -13
- package/dist/sandbox/providers.d.ts +5 -0
- package/dist/sandbox/providers.js +1 -1
- package/dist/sandbox/sandbox-file-reader.d.ts +7 -12
- package/dist/sandbox/sandbox-file-reader.js +12 -29
- package/dist/sandbox/sandbox.service.d.ts +53 -32
- package/dist/sandbox/sandbox.service.js +217 -141
- package/dist/sandbox/use-context.d.ts +4 -1
- package/dist/skills/invoke.d.ts +13 -35
- package/dist/skills/invoke.js +23 -162
- package/dist/tools/builtins/builtin-tools.d.ts +2 -11
- package/dist/tools/builtins/builtin-tools.js +5 -23
- package/dist/tools/builtins/image/generate.js +2 -2
- package/dist/tools/builtins/sandbox/common.d.ts +32 -80
- package/dist/tools/builtins/sandbox/common.js +61 -173
- package/dist/tools/builtins/sandbox/deliver.js +2 -2
- package/dist/tools/builtins/sandbox/device-owner.d.ts +4 -5
- package/dist/tools/builtins/sandbox/device-owner.js +5 -6
- package/dist/tools/builtins/sandbox/fetch-attachment.js +2 -2
- package/dist/tools/builtins/sandbox/glob.js +1 -1
- package/dist/tools/builtins/sandbox/grep.js +1 -1
- package/dist/tools/builtins/sandbox/index.d.ts +2 -2
- package/dist/tools/builtins/sandbox/index.js +2 -2
- package/dist/tools/builtins/sandbox/read.js +1 -1
- package/dist/tools/builtins/sandbox/task-output.d.ts +3 -3
- package/dist/tools/builtins/sandbox/task-output.js +4 -4
- package/dist/tools/builtins/sandbox/task-stop.js +1 -1
- package/dist/tools/builtins/skill-load.js +2 -2
- package/dist/tools/connectors.service.d.ts +4 -2
- package/dist/tools/connectors.service.js +15 -3
- package/dist/tools/pipeline.d.ts +0 -2
- package/dist/tools/pipeline.js +7 -14
- package/dist/tools/tools.module.js +1 -1
- package/package.json +2 -2
- package/src/migrations/0179_device_report_limit_text.sql +28 -0
- package/src/migrations/0180_device_instance_abandoned.sql +6 -0
package/dist/skills/invoke.js
CHANGED
|
@@ -7,26 +7,20 @@ 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 { escapeSkillInvocationTags, hasShellInjection, parseSkillMd, renderSkillBody, renderSkillInvocation, SKILL_ENTRY_FILE, SKILL_INVOCATION_LIMITS, skillDigest,
|
|
11
|
-
import { Inject, Injectable
|
|
10
|
+
import { escapeSkillInvocationTags, hasShellInjection, parseSkillMd, renderSkillBody, renderSkillInvocation, SKILL_ENTRY_FILE, SKILL_INVOCATION_LIMITS, skillDigest, } from "@capybara-hq/plugin-sdk";
|
|
11
|
+
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { AgentLookup } from "../agents/agent-lookup.js";
|
|
13
13
|
import { builtinDisabled } from "../agents/definition.js";
|
|
14
14
|
import { EventLog } from "../conversations/event-log.js";
|
|
15
|
-
import { ConversationDevices } from "../devices/conversation-devices.js";
|
|
16
|
-
import { providerUnreachable } from "../devices/device-projects.service.js";
|
|
17
15
|
import { ApiError } from "../errors.js";
|
|
18
16
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
19
17
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
20
18
|
import { callableProjectSkills, projectSkillName, projectSkillOf, } from "../runtime/context/project-root.js";
|
|
21
19
|
import { isGeneralAlias, resolveSkillForkType } from "../runtime/subagents/roster.js";
|
|
22
20
|
import { PROJECT_SKILLS_DIR } from "../sandbox/kernel-read.js";
|
|
23
|
-
import { PERMISSION_CONTEXT_ACTIVATION, permissionContextActive, } from "../sandbox/permission-context-types.js";
|
|
24
|
-
import { SandboxService } from "../sandbox/sandbox.service.js";
|
|
25
|
-
import { SandboxProviderUnreachableError } from "../sandbox/unreachable.js";
|
|
26
21
|
import { StorageService } from "../storage/storage.service.js";
|
|
27
22
|
import { BUILTIN } from "../tools/builtin-names.js";
|
|
28
|
-
import {
|
|
29
|
-
import { findSkillVersion, PROJECT_DIR_DIGEST, ProjectSkillReadError, readProjectSkill, readSkillFile, SkillIntegrityError, } from "../tools/builtins/skill-load.js";
|
|
23
|
+
import { findSkillVersion, readSkillFile, SkillIntegrityError, } from "../tools/builtins/skill-load.js";
|
|
30
24
|
import { invocationOf, resolveSkills } from "./catalog.js";
|
|
31
25
|
import { skillFileStore } from "./usable.js";
|
|
32
26
|
/** A leading `/<name>` or `/<plugin>:<name>`, then whitespace or the end (spec §3.2). */
|
|
@@ -55,21 +49,6 @@ export const notInvocable = (reason, name) => new ApiError("skill.not_invocable"
|
|
|
55
49
|
: `Skill "${name}" cannot be invoked by a person`, [{ reason }]);
|
|
56
50
|
/** A project skill the project lists but cannot be used now: the person is told why. */
|
|
57
51
|
const projectUnavailable = (reason, message) => new ApiError("skill.project_unavailable", message, [{ reason }]);
|
|
58
|
-
/** The refusal of a {@link ProjectSkillProblem}: its reason and the person's text. */
|
|
59
|
-
function projectProblemRefusal(name, p) {
|
|
60
|
-
switch (p.kind) {
|
|
61
|
-
case "outside_mode":
|
|
62
|
-
return projectUnavailable("outside_mode", `Skill "${name}" cannot be invoked: ${p.path} is outside what the device can read in ${p.mode} mode now`);
|
|
63
|
-
case "gone":
|
|
64
|
-
return projectUnavailable("gone", `Skill "${name}" cannot be invoked: ${p.path} is no longer on the device`);
|
|
65
|
-
case "read_failed":
|
|
66
|
-
return projectUnavailable("unreadable", `Skill "${name}" cannot be invoked: reading ${p.path} on the device failed (${p.why.slice(0, 300)})`);
|
|
67
|
-
case "invalid":
|
|
68
|
-
return projectUnavailable("unparsable", `Skill "${name}" cannot be invoked: ${p.path} is not a valid SKILL.md (${p.why.slice(0, 300)})`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/** The longest a person's invocation waits for its project skill's SKILL.md on the device. */
|
|
72
|
-
const PROJECT_SKILL_READ_TIMEOUT_MS = 30_000;
|
|
73
52
|
/** Where an effective skill comes from, for the `/` menu ({@link InvocableSource}). */
|
|
74
53
|
export const invocableSource = (r) => r.scope === "agent" ? "agent" : r.skill.plugin !== undefined ? "plugin" : "platform";
|
|
75
54
|
/**
|
|
@@ -130,12 +109,12 @@ export async function recordedSkillBlocked(db, a) {
|
|
|
130
109
|
/** The model-visible text of a fork invocation in the parent's log (spec §6.3, frozen). */
|
|
131
110
|
export const forkLeadText = (name, agentType, args) => escapeSkillInvocationTags(`The user ran the skill "${name}" in a sub-agent (${agentType}) with /${name}${args === "" ? "" : ` ${args}`}. The sub-agent gets the skill's instructions as its task; its report follows. Do not do the task yourself.`);
|
|
132
111
|
/**
|
|
133
|
-
* A person's `/project:<name>` invocation
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
112
|
+
* A person's `/project:<name>` invocation (permission activation L2, Hook 2): no device read at
|
|
113
|
+
* send time (a person's send has no run, so nothing could admit it). The message is a stub
|
|
114
|
+
* rendered from the conversation's latest `project_root` (the skill's name, its recorded digest,
|
|
115
|
+
* its directory in the project and the person's arguments) telling the agent to load
|
|
116
|
+
* `project:<name>` with its `Skill` tool, which reads it under the run's admission. Model-visible,
|
|
117
|
+
* so English; tags in the arguments stay inert. Always inline, as before.
|
|
139
118
|
*/
|
|
140
119
|
export function projectSkillStub(a, latest, bare) {
|
|
141
120
|
const skill = latest.skills.find((s) => s.name === bare);
|
|
@@ -182,24 +161,14 @@ let SkillInvoker = class SkillInvoker {
|
|
|
182
161
|
agents;
|
|
183
162
|
log;
|
|
184
163
|
eventLog;
|
|
185
|
-
sandbox;
|
|
186
|
-
devices;
|
|
187
|
-
activation;
|
|
188
164
|
constructor(db, storage, agents, log,
|
|
189
165
|
/** A bound conversation's latest `project_root` (its project skills). */
|
|
190
|
-
eventLog
|
|
191
|
-
/** A project skill's SKILL.md is read through the conversation's device. */
|
|
192
|
-
sandbox, devices,
|
|
193
|
-
/** The paired activation gate: once on, no raw device use reads a project skill. */
|
|
194
|
-
activation) {
|
|
166
|
+
eventLog) {
|
|
195
167
|
this.db = db;
|
|
196
168
|
this.storage = storage;
|
|
197
169
|
this.agents = agents;
|
|
198
170
|
this.log = log;
|
|
199
171
|
this.eventLog = eventLog;
|
|
200
|
-
this.sandbox = sandbox;
|
|
201
|
-
this.devices = devices;
|
|
202
|
-
this.activation = activation;
|
|
203
172
|
}
|
|
204
173
|
/**
|
|
205
174
|
* The `/` menu for `accountId`: the agent must be usable by them (`agent.not_found`), and with
|
|
@@ -230,8 +199,8 @@ let SkillInvoker = class SkillInvoker {
|
|
|
230
199
|
});
|
|
231
200
|
if (conversationId === undefined)
|
|
232
201
|
return skills;
|
|
233
|
-
//
|
|
234
|
-
if (
|
|
202
|
+
// a project skill is loaded by the agent's Skill tool: none without it
|
|
203
|
+
if (!hasBuiltin(agent.definition, BUILTIN.Skill))
|
|
235
204
|
return skills;
|
|
236
205
|
const latest = await this.eventLog.latestOfType(conversationId, "project_root");
|
|
237
206
|
return [...skills, ...projectInvocables(latest?.payload)];
|
|
@@ -327,17 +296,12 @@ let SkillInvoker = class SkillInvoker {
|
|
|
327
296
|
}
|
|
328
297
|
/**
|
|
329
298
|
* A person's invocation of `project:<name>` (project root spec §4.6): resolved from the
|
|
330
|
-
* conversation's latest `project_root` (what the model saw)
|
|
331
|
-
* the
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
* `skill.
|
|
335
|
-
* `
|
|
336
|
-
* cannot be used), the device's own refusals as they are (`device.offline`, ...),
|
|
337
|
-
* `device.projects_unavailable` when the device cannot be asked. Once the activation gate is on
|
|
338
|
-
* the device is not read at send time: the invocation is the recorded stub
|
|
339
|
-
* ({@link projectSkillStub}) and only the first two refusals remain, plus
|
|
340
|
-
* `skill.project_unavailable` `skill_tool_off` for an agent without the `Skill` tool.
|
|
299
|
+
* conversation's latest `project_root` (what the model saw). The device is not read at send
|
|
300
|
+
* time: the invocation is the recorded stub ({@link projectSkillStub}), which the agent's
|
|
301
|
+
* `Skill` tool loads. Refusals: `skill.not_invocable` `not_found` (no conversation yet, no
|
|
302
|
+
* project, a name it does not list), `skill.project_unavailable` with its reason (the latest
|
|
303
|
+
* project is unavailable), and `skill.project_unavailable` `skill_tool_off` for an agent without
|
|
304
|
+
* the `Skill` tool.
|
|
341
305
|
*/
|
|
342
306
|
async prepareProject(a, bare) {
|
|
343
307
|
const { conversationId } = a;
|
|
@@ -350,109 +314,10 @@ let SkillInvoker = class SkillInvoker {
|
|
|
350
314
|
if (projectSkillBlocked(latest, a.name) !== null || latest === undefined) {
|
|
351
315
|
throw notInvocable("not_found", a.name);
|
|
352
316
|
}
|
|
353
|
-
//
|
|
354
|
-
if (
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
return projectSkillStub(a, latest, bare);
|
|
358
|
-
}
|
|
359
|
-
const file = await this.readProjectFile({ ...a, conversationId }, latest.root, bare);
|
|
360
|
-
const args = a.args.trim();
|
|
361
|
-
// the renderer's skills-root directory becomes the skill's directory in the project (a closing
|
|
362
|
-
// tag in the path stays inert, as in the body)
|
|
363
|
-
const dir = file.dir.replace(/<\//g, "<\\/");
|
|
364
|
-
const text = rendered(() => renderSkillInvocation({
|
|
365
|
-
name: a.name,
|
|
366
|
-
skillName: bare,
|
|
367
|
-
digest: PROJECT_DIR_DIGEST,
|
|
368
|
-
version: 0,
|
|
369
|
-
body: file.body,
|
|
370
|
-
invocation: file.invocation,
|
|
371
|
-
args: a.args,
|
|
372
|
-
lines: {
|
|
373
|
-
...(hasShellInjection(file.body) &&
|
|
374
|
-
hasBuiltin(a.agent, BUILTIN.Bash) && { shellHint: true }),
|
|
375
|
-
},
|
|
376
|
-
})).replaceAll(skillSandboxDir(bare, PROJECT_DIR_DIGEST), dir);
|
|
377
|
-
const full = [
|
|
378
|
-
text,
|
|
379
|
-
...(file.truncated
|
|
380
|
-
? [
|
|
381
|
-
`Its SKILL.md was cut at 1 MiB when it was read; the rest of its instructions is missing.`,
|
|
382
|
-
]
|
|
383
|
-
: []),
|
|
384
|
-
`Its other files, if any, are in ${dir}/ on the device; use them there.`,
|
|
385
|
-
].join("\n\n");
|
|
386
|
-
// the closing lines count toward the limit too
|
|
387
|
-
if (full.length > SKILL_INVOCATION_LIMITS.renderedMaxChars) {
|
|
388
|
-
throw new ApiError("validation_failed", "Request validation failed", [
|
|
389
|
-
{
|
|
390
|
-
path: "text",
|
|
391
|
-
message: `the rendered skill must be at most ${SKILL_INVOCATION_LIMITS.renderedMaxChars} characters; shorten the arguments`,
|
|
392
|
-
},
|
|
393
|
-
]);
|
|
394
|
-
}
|
|
395
|
-
return {
|
|
396
|
-
text: full,
|
|
397
|
-
skill: {
|
|
398
|
-
id: a.name,
|
|
399
|
-
version: 0,
|
|
400
|
-
source: "project",
|
|
401
|
-
name: a.name,
|
|
402
|
-
arguments: args,
|
|
403
|
-
mode: "inline",
|
|
404
|
-
},
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* {@link readProjectSkill} in a silent use of the conversation's device, as its owner (gate off
|
|
409
|
-
* only: once activated a person's invocation renders {@link projectSkillStub} and never reads
|
|
410
|
-
* the device at send time).
|
|
411
|
-
*/
|
|
412
|
-
async readProjectFile(a, root, bare) {
|
|
413
|
-
try {
|
|
414
|
-
const deviceId = await this.devices.forTool(a.orgId, a.conversationId);
|
|
415
|
-
// a person invokes in a root conversation: it is its own sandbox conversation
|
|
416
|
-
const [level, working] = await Promise.all([
|
|
417
|
-
this.devices.modeLevel(a.orgId, deviceId),
|
|
418
|
-
this.devices.workingFacts(a.orgId, a.conversationId, a.conversationId, deviceId),
|
|
419
|
-
]);
|
|
420
|
-
// unknown mode: the strict (sandbox) path checks stay (fail closed), as in a tool call
|
|
421
|
-
const mode = level?.mode ?? "sandbox";
|
|
422
|
-
return await this.sandbox.withSandbox({
|
|
423
|
-
orgId: a.orgId,
|
|
424
|
-
deviceId,
|
|
425
|
-
holderConversationId: a.conversationId,
|
|
426
|
-
// tells the model nothing: its next tool call still learns what the device did
|
|
427
|
-
silent: true,
|
|
428
|
-
actor: { accountId: a.accountId, conversationId: a.conversationId },
|
|
429
|
-
}, (h, p, info, signal) => readProjectSkill({
|
|
430
|
-
deviceId,
|
|
431
|
-
// the legacy route (gate off): the fixed roots unless the device runs in auto mode
|
|
432
|
-
pathBound: sessionPathBound(false, mode),
|
|
433
|
-
h,
|
|
434
|
-
roots: info.roots,
|
|
435
|
-
// the working root a tool call of this conversation would get (one rule)
|
|
436
|
-
workingRoot: sessionWorkingRoot(working, info.roots.workspace),
|
|
437
|
-
p,
|
|
438
|
-
signal,
|
|
439
|
-
}, root, bare), AbortSignal.timeout(PROJECT_SKILL_READ_TIMEOUT_MS));
|
|
440
|
-
}
|
|
441
|
-
catch (e) {
|
|
442
|
-
if (e instanceof ProjectSkillReadError)
|
|
443
|
-
throw projectProblemRefusal(a.name, e.problem);
|
|
444
|
-
if (e instanceof ApiError)
|
|
445
|
-
throw e;
|
|
446
|
-
if (e instanceof SandboxProviderUnreachableError)
|
|
447
|
-
throw providerUnreachable();
|
|
448
|
-
this.log.warn("project skill unreadable: the device could not be asked", {
|
|
449
|
-
orgId: a.orgId,
|
|
450
|
-
conversationId: a.conversationId,
|
|
451
|
-
skill: a.name,
|
|
452
|
-
err: e,
|
|
453
|
-
});
|
|
454
|
-
throw new ApiError("device.projects_unavailable", "The device could not be reached to read the project skill; retry later");
|
|
455
|
-
}
|
|
317
|
+
// no device read at send time: the agent loads the skill with Skill
|
|
318
|
+
if (!hasBuiltin(a.agent, BUILTIN.Skill))
|
|
319
|
+
throw projectUnavailable("skill_tool_off", `Skill "${a.name}" cannot be invoked: this agent cannot load project skills; turn on its ${BUILTIN.Skill} tool`);
|
|
320
|
+
return projectSkillStub(a, latest, bare);
|
|
456
321
|
}
|
|
457
322
|
/**
|
|
458
323
|
* The task of a fork invocation's sub-agent (spec §6.2), rendered at dispatch from the version
|
|
@@ -556,11 +421,7 @@ SkillInvoker = __decorate([
|
|
|
556
421
|
__param(1, Inject(StorageService)),
|
|
557
422
|
__param(2, Inject(AgentLookup)),
|
|
558
423
|
__param(3, Inject(KERNEL_LOGGER)),
|
|
559
|
-
__param(4, Inject(EventLog))
|
|
560
|
-
__param(5, Inject(SandboxService)),
|
|
561
|
-
__param(6, Inject(ConversationDevices)),
|
|
562
|
-
__param(7, Optional()),
|
|
563
|
-
__param(7, Inject(PERMISSION_CONTEXT_ACTIVATION))
|
|
424
|
+
__param(4, Inject(EventLog))
|
|
564
425
|
], SkillInvoker);
|
|
565
426
|
export { SkillInvoker };
|
|
566
427
|
/**
|
|
@@ -18,13 +18,12 @@ import { SealedInputs } from "../../platform/sealed-inputs.js";
|
|
|
18
18
|
import type { HookRunner } from "../../runtime/hook-calls.js";
|
|
19
19
|
import { ProviderRegistry } from "../../runtime/providers.js";
|
|
20
20
|
import { StepLog } from "../../runtime/step-log.js";
|
|
21
|
-
import {
|
|
21
|
+
import { ManagedDeviceContextRecorder } from "../../sandbox/managed-device-context.js";
|
|
22
22
|
import { SandboxService } from "../../sandbox/sandbox.service.js";
|
|
23
23
|
import { ScheduledTaskStore } from "../../schedules/store.js";
|
|
24
24
|
import { StorageService } from "../../storage/storage.service.js";
|
|
25
25
|
import { ToolOutputs } from "../outputs.js";
|
|
26
26
|
import type { BuiltinCallContext, BuiltinTool } from "../registry.js";
|
|
27
|
-
import type { SandboxToolDeps } from "./sandbox/common.js";
|
|
28
27
|
import { ScheduleToolsPort, ScheduleUpdates } from "./schedules.js";
|
|
29
28
|
import { WebPages } from "./web/index.js";
|
|
30
29
|
/**
|
|
@@ -54,18 +53,10 @@ export declare class BuiltinTools {
|
|
|
54
53
|
images: ModelImages, providers: ProviderRegistry,
|
|
55
54
|
/** The clock `CurrentTime` reads (the run context's clock seam; `Date.now` by default). */
|
|
56
55
|
/** The managed sandbox route's device context writer (permission context replay spec B3). */
|
|
57
|
-
managedDeviceContext: ManagedDeviceContextRecorder, now?: () => number
|
|
58
|
-
/** The paired activation gate (one switch with the runtime's request boundary). */
|
|
59
|
-
activation?: boolean);
|
|
56
|
+
managedDeviceContext: ManagedDeviceContextRecorder, now?: () => number);
|
|
60
57
|
/** The builtin tools, in a fixed order. */
|
|
61
58
|
list(): readonly BuiltinTool[];
|
|
62
59
|
}
|
|
63
|
-
/**
|
|
64
|
-
* The managed device context fields of the builtin sandbox tools' deps (spec B3): the injected
|
|
65
|
-
* writer, required, only when the one activation gate is on; otherwise no keys at all, and the
|
|
66
|
-
* legacy writer stays.
|
|
67
|
-
*/
|
|
68
|
-
export declare function managedSandboxDeps(recorder: ManagedDeviceContextPort, activation: boolean | undefined): Pick<SandboxToolDeps, "managedDeviceContext" | "managedDeviceContextRequired">;
|
|
69
60
|
/**
|
|
70
61
|
* Whether "the chat model" of a `Read` call can view images (vision-read design §1.2): the model
|
|
71
62
|
* of the latest `model_call` of the call's run (a fallback step's model when the step fell back),
|
|
@@ -33,8 +33,7 @@ import { SealedInputs } from "../../platform/sealed-inputs.js";
|
|
|
33
33
|
import { ProviderListError, ProviderRegistry } from "../../runtime/providers.js";
|
|
34
34
|
import { conversationTimeZone, RUN_CONTEXT_CLOCK } from "../../runtime/run-context.service.js";
|
|
35
35
|
import { StepLog } from "../../runtime/step-log.js";
|
|
36
|
-
import { ManagedDeviceContextRecorder
|
|
37
|
-
import { PERMISSION_CONTEXT_ACTIVATION, permissionContextActive, } from "../../sandbox/permission-context-types.js";
|
|
36
|
+
import { ManagedDeviceContextRecorder } from "../../sandbox/managed-device-context.js";
|
|
38
37
|
import { SandboxService } from "../../sandbox/sandbox.service.js";
|
|
39
38
|
import { ScheduledTaskStore } from "../../schedules/store.js";
|
|
40
39
|
import { StorageService } from "../../storage/storage.service.js";
|
|
@@ -77,12 +76,7 @@ let BuiltinTools = class BuiltinTools {
|
|
|
77
76
|
images, providers,
|
|
78
77
|
/** The clock `CurrentTime` reads (the run context's clock seam; `Date.now` by default). */
|
|
79
78
|
/** The managed sandbox route's device context writer (permission context replay spec B3). */
|
|
80
|
-
managedDeviceContext, now
|
|
81
|
-
/** The paired activation gate (one switch with the runtime's request boundary). */
|
|
82
|
-
activation) {
|
|
83
|
-
// dormant: the builtins keep the legacy route until the paired activation turns the gate on;
|
|
84
|
-
// then every builtin entering a device (the skill tool too) takes the managed route
|
|
85
|
-
const managed = managedSandboxDeps(managedDeviceContext, activation);
|
|
79
|
+
managedDeviceContext, now) {
|
|
86
80
|
// `Read` beyond the device (vision-read design §1): files by id, the vision read with its
|
|
87
81
|
// hooks (as the WebFetch extraction), the stored copies and the chat model's capabilities
|
|
88
82
|
const vision = { purposes, eventLog, stepLog, config, log, hooks: host?.hooks };
|
|
@@ -112,7 +106,7 @@ let BuiltinTools = class BuiltinTools {
|
|
|
112
106
|
eventLog,
|
|
113
107
|
config,
|
|
114
108
|
log,
|
|
115
|
-
|
|
109
|
+
managedDeviceContext,
|
|
116
110
|
read,
|
|
117
111
|
};
|
|
118
112
|
this.tools = [
|
|
@@ -135,7 +129,7 @@ let BuiltinTools = class BuiltinTools {
|
|
|
135
129
|
attachments,
|
|
136
130
|
eventLog,
|
|
137
131
|
log,
|
|
138
|
-
|
|
132
|
+
managedDeviceContext,
|
|
139
133
|
get db() {
|
|
140
134
|
return db.db;
|
|
141
135
|
},
|
|
@@ -265,21 +259,9 @@ BuiltinTools = __decorate([
|
|
|
265
259
|
__param(26, Inject(ProviderRegistry)),
|
|
266
260
|
__param(27, Inject(ManagedDeviceContextRecorder)),
|
|
267
261
|
__param(28, Optional()),
|
|
268
|
-
__param(28, Inject(RUN_CONTEXT_CLOCK))
|
|
269
|
-
__param(29, Optional()),
|
|
270
|
-
__param(29, Inject(PERMISSION_CONTEXT_ACTIVATION))
|
|
262
|
+
__param(28, Inject(RUN_CONTEXT_CLOCK))
|
|
271
263
|
], BuiltinTools);
|
|
272
264
|
export { BuiltinTools };
|
|
273
|
-
/**
|
|
274
|
-
* The managed device context fields of the builtin sandbox tools' deps (spec B3): the injected
|
|
275
|
-
* writer, required, only when the one activation gate is on; otherwise no keys at all, and the
|
|
276
|
-
* legacy writer stays.
|
|
277
|
-
*/
|
|
278
|
-
export function managedSandboxDeps(recorder, activation) {
|
|
279
|
-
if (!permissionContextActive(activation))
|
|
280
|
-
return {};
|
|
281
|
-
return { managedDeviceContext: recorder, managedDeviceContextRequired: true };
|
|
282
|
-
}
|
|
283
265
|
/**
|
|
284
266
|
* Whether "the chat model" of a `Read` call can view images (vision-read design §1.2): the model
|
|
285
267
|
* of the latest `model_call` of the call's run (a fallback step's model when the step fell back),
|
|
@@ -442,8 +442,8 @@ async function recordDenial(deps, ctx, runId, verdict) {
|
|
|
442
442
|
/**
|
|
443
443
|
* Writes the images into the call's device at `filePath` (several: `-1`, `-2`… before the
|
|
444
444
|
* extension, {@link generateImagePaths}) with `Write`'s checks (spec §5.3): the device entry every
|
|
445
|
-
* builtin takes ({@link inToolSandbox}: the managed route and its marked device paths
|
|
446
|
-
*
|
|
445
|
+
* builtin takes ({@link inToolSandbox}: the managed route and its marked device paths),
|
|
446
|
+
* each path checked as `Write` checks it, and under its path lease a directory refused
|
|
447
447
|
* and an existing file replaced only when this conversation read it and it is unchanged
|
|
448
448
|
* ({@link assertReadAndUnchanged}). The images are already delivered, so a copy that cannot be made
|
|
449
449
|
* is a line of the result, not a tool error: no device, or the reason the copy stopped, after the
|
|
@@ -6,11 +6,10 @@ import type { KernelConfig } from "../../../config/schema.js";
|
|
|
6
6
|
import type { ChildAgent } from "../../../conversations/agent-tree.js";
|
|
7
7
|
import type { AttachmentsService } from "../../../conversations/attachments.service.js";
|
|
8
8
|
import type { EventLog } from "../../../conversations/event-log.js";
|
|
9
|
-
import { type ConversationDevices, type DeviceUnusableReason
|
|
9
|
+
import { type ConversationDevices, type DeviceUnusableReason } from "../../../devices/conversation-devices.js";
|
|
10
10
|
import type { KernelConfigService } from "../../../infra/config/kernel-config.service.js";
|
|
11
11
|
import { ATTACHMENTS_ROOT, attachmentsDir, attachmentsRoot } from "../../../sandbox/attachments-path.js";
|
|
12
12
|
import { type ManagedDeviceContextPort } from "../../../sandbox/managed-device-context.js";
|
|
13
|
-
import type { SandboxMode } from "../../../sandbox/modes.js";
|
|
14
13
|
import { PermissionAdmissionUnavailable, type PermissionAvailabilityCause } from "../../../sandbox/permission-availability.js";
|
|
15
14
|
import type { HeldDeviceContextEvidence } from "../../../sandbox/permission-context-types.js";
|
|
16
15
|
import { type HeldProvider, type SandboxService } from "../../../sandbox/sandbox.service.js";
|
|
@@ -20,19 +19,18 @@ import type { ReadFileDeps } from "./read.js";
|
|
|
20
19
|
/** 沙箱工具的依赖(都按调用时取,多副本下无进程内状态)。 */
|
|
21
20
|
export interface SandboxToolDeps {
|
|
22
21
|
/**
|
|
23
|
-
* `pathLease` may be absent (test
|
|
24
|
-
*
|
|
25
|
-
*
|
|
22
|
+
* Every device call is a managed operation (`withOperations`). `pathLease` may be absent (test
|
|
23
|
+
* stubs): the kernel's own file writes then take no path lease. `currentInstance` too: a
|
|
24
|
+
* background `Bash` launch records the instance it started in; and `ifRunning`, which
|
|
25
|
+
* `TaskOutput` reads a task through.
|
|
26
26
|
*/
|
|
27
|
-
sandbox: Pick<SandboxService, "
|
|
27
|
+
sandbox: Pick<SandboxService, "withOperations"> & Partial<Pick<SandboxService, "pathLease" | "currentInstance" | "ifRunning">>;
|
|
28
28
|
/**
|
|
29
29
|
* The device a call enters: the root conversation's, checked for its owner every call.
|
|
30
30
|
* `usableNow` (absent in test stubs: the device's provider serves the org) tells a listing
|
|
31
|
-
* whether a conversation's device has its provider on in the org (ruling R8).
|
|
32
|
-
* (absent in test stubs: free mode) gives what decides the working root, read as the review
|
|
33
|
-
* reads it.
|
|
31
|
+
* whether a conversation's device has its provider on in the org (ruling R8).
|
|
34
32
|
*/
|
|
35
|
-
devices: Pick<ConversationDevices, "forTool"> & Partial<Pick<ConversationDevices, "usableNow" | "unusableReason"
|
|
33
|
+
devices: Pick<ConversationDevices, "forTool"> & Partial<Pick<ConversationDevices, "usableNow" | "unusableReason">>;
|
|
36
34
|
/** Background `Bash` tasks; absent in test stubs, where `run_in_background` is refused. */
|
|
37
35
|
background?: Pick<BackgroundTaskStore, "releaseStop" | "get" | "advanceOffset" | "runningOwnedBy" | "finishedOwnedBy"> & Partial<Pick<BackgroundTaskStore, "reserveManaged" | "failManagedPreEffect">>;
|
|
38
36
|
/**
|
|
@@ -56,24 +54,17 @@ export interface SandboxToolDeps {
|
|
|
56
54
|
storage: Pick<StorageService, "kernel" | "deployment" | "available">;
|
|
57
55
|
/**
|
|
58
56
|
* `readDeliveryScope`: `Deliver`'s delivery scope (truthful delivery spec §2). `publishChanged`:
|
|
59
|
-
* `Deliver` announces `changed: files` (UI refresh B).
|
|
60
|
-
* conversation's latest `device_paths` (absent in test stubs, which record none).
|
|
57
|
+
* `Deliver` announces `changed: files` (UI refresh B).
|
|
61
58
|
*/
|
|
62
|
-
eventLog: Pick<EventLog, "append" | "latestFileState" | "readDeliveryScope"> & Partial<Pick<EventLog, "publishChanged" | "
|
|
59
|
+
eventLog: Pick<EventLog, "append" | "latestFileState" | "readDeliveryScope"> & Partial<Pick<EventLog, "publishChanged" | "findByIdem">>;
|
|
63
60
|
config: Pick<KernelConfigService, "get">;
|
|
64
61
|
/** Where a mapped provider failure keeps its raw error (warn); absent in test stubs. */
|
|
65
62
|
log?: Pick<Logger, "warn">;
|
|
66
63
|
/**
|
|
67
|
-
* The managed device context writer (permission context replay spec B3):
|
|
68
|
-
*
|
|
69
|
-
* `device_paths` writer. Absent while dormant (the legacy writer stays on unactivated routes).
|
|
64
|
+
* The managed device context writer (permission context replay spec B3): it records the marked
|
|
65
|
+
* device paths before any preparation or user callback of every device call.
|
|
70
66
|
*/
|
|
71
|
-
managedDeviceContext
|
|
72
|
-
/**
|
|
73
|
-
* The paired activation (`PERMISSION_CONTEXT_ACTIVATION`): the managed route then requires
|
|
74
|
-
* {@link managedDeviceContext} and refuses before entering without it.
|
|
75
|
-
*/
|
|
76
|
-
managedDeviceContextRequired?: boolean;
|
|
67
|
+
managedDeviceContext: ManagedDeviceContextPort;
|
|
77
68
|
/**
|
|
78
69
|
* `Read` beyond the device (vision-read design §1): reads by `file_id`, images shown or read by
|
|
79
70
|
* the vision purpose, their stored copies. Absent in test stubs: `Read` then reads the device
|
|
@@ -82,22 +73,16 @@ export interface SandboxToolDeps {
|
|
|
82
73
|
read?: ReadFileDeps;
|
|
83
74
|
}
|
|
84
75
|
/**
|
|
85
|
-
* The sandbox a callback gets: the instance handle, the provider (every
|
|
86
|
-
*
|
|
87
|
-
*
|
|
76
|
+
* The sandbox a callback gets: the instance handle, the provider (every call a managed operation
|
|
77
|
+
* under the admitted scope) and the call's signal combined with the lease's (pass it to every
|
|
78
|
+
* provider call). The file tools' paths are bounded by each operation's admitted scope (project
|
|
79
|
+
* roots plus directory grants, protected paths excluded), which the device enforces, as for
|
|
80
|
+
* `Bash`, never by the device's tier or its outside-sandbox setting; the kernel checks only a
|
|
81
|
+
* path's shape ({@link checkToolPath}).
|
|
88
82
|
*/
|
|
89
83
|
export interface SandboxSession {
|
|
90
84
|
/** The device the call runs in (path leases are taken on it). */
|
|
91
85
|
deviceId: string;
|
|
92
|
-
/**
|
|
93
|
-
* What bounds the file tools' paths ({@link checkToolPath}), never the device's tier or its
|
|
94
|
-
* outside-sandbox setting (approval-only profiles: the sandbox is the same under every profile):
|
|
95
|
-
* - `scope`: the operation's admitted scope. On the managed route every native request carries
|
|
96
|
-
* it (project roots plus directory grants, protected paths excluded) and the device enforces
|
|
97
|
-
* it, as for `Bash`, so the kernel checks only a path's shape; legacy auto mode too.
|
|
98
|
-
* - `roots`: the instance's fixed roots (the legacy route in sandbox mode only).
|
|
99
|
-
*/
|
|
100
|
-
pathBound: "scope" | "roots";
|
|
101
86
|
h: SandboxHandle;
|
|
102
87
|
/** The instance's roots: every path the call builds or checks is under one of them. */
|
|
103
88
|
roots: SandboxRoots;
|
|
@@ -216,13 +201,11 @@ export declare function checkPathShape(path: string, field?: string): void;
|
|
|
216
201
|
*/
|
|
217
202
|
export declare function checkPath(path: string, roots: SandboxRoots, field?: string): string;
|
|
218
203
|
/**
|
|
219
|
-
* A file tool's path
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
* scope does not cover, protected paths included); bounded by the fixed roots, a path must lie
|
|
223
|
-
* under one of them ({@link checkPath}).
|
|
204
|
+
* A file tool's path, bounded by the operation's admitted scope: any clean absolute path passes
|
|
205
|
+
* here (shape checks only; the review proposes a directory crossing for a path outside the scope,
|
|
206
|
+
* and the device refuses one the scope does not cover, protected paths included).
|
|
224
207
|
*/
|
|
225
|
-
export declare function checkToolPath(path: string,
|
|
208
|
+
export declare function checkToolPath(path: string, field?: string): string;
|
|
226
209
|
/**
|
|
227
210
|
* The shape checks of a file tool's path before the call enters its device: an absolute path gets
|
|
228
211
|
* {@link checkPathShape}; a relative one (resolved against the working root inside,
|
|
@@ -237,7 +220,7 @@ export declare function checkFilePathShape(path: string, field?: string): void;
|
|
|
237
220
|
*/
|
|
238
221
|
export declare function resolveToolPath(path: string, s: Pick<SandboxSession, "workingRoot">): string;
|
|
239
222
|
/** {@link checkToolPath} for a writing tool: the skills directory stays read-only either way. */
|
|
240
|
-
export declare function checkToolWritable(path: string, s: Pick<SandboxSession, "roots" | "
|
|
223
|
+
export declare function checkToolWritable(path: string, s: Pick<SandboxSession, "roots" | "workingRoot">): string;
|
|
241
224
|
/** POSIX shell 单引号转义。 */
|
|
242
225
|
export declare function shellQuote(s: string): string;
|
|
243
226
|
/**
|
|
@@ -311,25 +294,13 @@ export declare const OUTCOME_UNKNOWN_TOOL_TEXT = "The device may or may not have
|
|
|
311
294
|
export { DEVICE_OF_ANOTHER_ACCOUNT_TEXT } from "./device-owner.js";
|
|
312
295
|
export declare function mapSandboxError(e: unknown, log: Pick<Logger, "warn"> | undefined): unknown;
|
|
313
296
|
/**
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
297
|
+
* The device entry of every builtin tool (B-17): runs `fn` in the device of the call's
|
|
298
|
+
* conversation (a sub-agent: its root's) on the managed operation route
|
|
299
|
+
* ({@link inSandboxOperations}): the device resolved and checked for the conversation's owner
|
|
300
|
+
* (binding an unbound conversation to the owner's default first), the marked device paths
|
|
301
|
+
* recorded before the callback, every provider call a managed operation. It never touches
|
|
318
302
|
* attachments: `FetchAttachment` is the only way one enters the device. Returns the value and the
|
|
319
|
-
* notices to put before the result (first use, a new instance).
|
|
320
|
-
* instance and calls `fn` again, the notices are the last call's. The instance's roots are recorded
|
|
321
|
-
* for the model on the conversation's first call and whenever they change
|
|
322
|
-
* ({@link recordDevicePaths}).
|
|
323
|
-
*/
|
|
324
|
-
export declare function inSandbox<T>(deps: SandboxToolDeps, ctx: BuiltinCallContext, fn: (s: SandboxSession) => Promise<T>): Promise<{
|
|
325
|
-
value: T;
|
|
326
|
-
notices: string[];
|
|
327
|
-
}>;
|
|
328
|
-
/**
|
|
329
|
-
* The device entry of every builtin tool (B-17): once the one activation gate is on (the managed
|
|
330
|
-
* writer required, {@link SandboxToolDeps.managedDeviceContextRequired}) the managed operation
|
|
331
|
-
* route ({@link inSandboxOperations}: the marked device paths recorded before the callback, every
|
|
332
|
-
* provider call a managed operation); otherwise the legacy route ({@link inSandbox}), unchanged.
|
|
303
|
+
* notices to put before the result (first use, a new instance).
|
|
333
304
|
*/
|
|
334
305
|
export declare function inToolSandbox<T>(deps: SandboxToolDeps, ctx: BuiltinCallContext, fn: (s: SandboxSession) => Promise<T>): Promise<{
|
|
335
306
|
value: T;
|
|
@@ -344,19 +315,13 @@ export declare function inSandboxOperations<T>(deps: SandboxToolDeps, ctx: Built
|
|
|
344
315
|
notices: string[];
|
|
345
316
|
}>;
|
|
346
317
|
/**
|
|
347
|
-
* Trusted copy callbacks only receive preparation's three methods
|
|
348
|
-
* the
|
|
349
|
-
* scoped to `roots`, after the marked device paths); otherwise the protocol-2 binding.
|
|
318
|
+
* Trusted copy callbacks only receive preparation's three methods: the copy is a trusted
|
|
319
|
+
* preparation on the managed route, scoped to `roots`, after the marked device paths.
|
|
350
320
|
*/
|
|
351
321
|
export declare function inSandboxPreparation<T>(deps: SandboxToolDeps, ctx: BuiltinCallContext, purpose: SandboxPreparationScope["purpose"], roots: (roots: SandboxRoots) => readonly string[], fn: (s: PreparationSession) => Promise<T>): Promise<{
|
|
352
322
|
value: T;
|
|
353
323
|
notices: string[];
|
|
354
324
|
}>;
|
|
355
|
-
/** The trusted-copy entry on the managed route ({@link inSandboxPreparation} once activated). */
|
|
356
|
-
export declare function inSandboxOperationPreparation<T>(deps: SandboxToolDeps, ctx: BuiltinCallContext, purpose: SandboxPreparationScope["purpose"], roots: (roots: SandboxRoots) => readonly string[], fn: (s: PreparationSession) => Promise<T>): Promise<{
|
|
357
|
-
value: T;
|
|
358
|
-
notices: string[];
|
|
359
|
-
}>;
|
|
360
325
|
/**
|
|
361
326
|
* Records the managed device paths of the held instance `held` into the calling conversation (a
|
|
362
327
|
* sub-agent: its own log) for this call's run and actor: a thin delegator to the managed writer,
|
|
@@ -365,19 +330,6 @@ export declare function inSandboxOperationPreparation<T>(deps: SandboxToolDeps,
|
|
|
365
330
|
export declare function recordManagedDevicePaths(deps: {
|
|
366
331
|
managedDeviceContext: ManagedDeviceContextPort;
|
|
367
332
|
}, ctx: BuiltinCallContext, held: Readonly<HeldDeviceContextEvidence>, signal: AbortSignal): Promise<void>;
|
|
368
|
-
/**
|
|
369
|
-
* The working root of a call: the project root exactly as the review decides it (from the same
|
|
370
|
-
* {@link WorkingFacts}); when that falls back to the device's workspace, the held instance's own
|
|
371
|
-
* workspace (`workspace`), where the call really runs. Every session built outside `inSandbox` (a
|
|
372
|
-
* person's project skill invocation) takes its working root from here too.
|
|
373
|
-
*/
|
|
374
|
-
export declare function sessionWorkingRoot(working: WorkingFacts | null, workspace: string): string;
|
|
375
|
-
/**
|
|
376
|
-
* What bounds a session's file-tool paths ({@link SandboxSession.pathBound}): the admitted scope
|
|
377
|
-
* on the managed operation route, under every tier; on the legacy route, the fixed roots unless
|
|
378
|
-
* the device runs in auto mode.
|
|
379
|
-
*/
|
|
380
|
-
export declare const sessionPathBound: (operations: boolean, mode: SandboxMode) => SandboxSession["pathBound"];
|
|
381
333
|
/** The conversation whose device a call uses (the root conversation's for a sub-agent). */
|
|
382
334
|
export declare const sandboxConversationOf: (ctx: BuiltinCallContext) => string;
|
|
383
335
|
/**
|