@capybara-hq/kernel 0.1.0-rc.96 → 0.1.0-rc.98
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/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 +5 -0
- package/dist/conversations/events.js +5 -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/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/sandbox/bash.js +1 -0
- package/dist/tools/builtins/sandbox/edit.js +1 -0
- 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/pipeline.d.ts +3 -1
- package/dist/tools/pipeline.js +37 -3
- package/dist/tools/registry.d.ts +6 -5
- package/dist/tools/registry.js +6 -5
- package/package.json +3 -3
- package/src/migrations/0185_channel_process_display.sql +13 -0
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
import type { ExecutionClaim } from "../runtime/run-execution.js";
|
|
2
2
|
/**
|
|
3
|
-
* A kernel read of a device on behalf of a run
|
|
4
|
-
* run's current execution claim and what is read.
|
|
5
|
-
* `AGENTS.md` and `.agents/skills
|
|
6
|
-
*
|
|
3
|
+
* A kernel read of a device on behalf of a run (permission activation L2), never a tool's, a
|
|
4
|
+
* Platform operation's or an HTTP route's: the run's current execution claim and what is read.
|
|
5
|
+
* - `project_root`: the bound project's `AGENTS.md` and `.agents/skills/**`, read by
|
|
6
|
+
* `ProjectKnowledgeService` before the run's first model call (the run still `queued`).
|
|
7
|
+
* - `write_base`: the current content of the one file a streaming `Write` is about to overwrite,
|
|
8
|
+
* read only to show the person a live diff (streaming tool input spec §4.1): the run `running`,
|
|
9
|
+
* `stat` and `readFile` of exactly `path`, never making, waking or resuming an instance, no path
|
|
10
|
+
* lease. Display only: it never reaches the model, the log or a hook.
|
|
7
11
|
*/
|
|
8
|
-
export
|
|
12
|
+
export type KernelReadInvocation = {
|
|
9
13
|
claim: ExecutionClaim;
|
|
10
14
|
purpose: "project_root";
|
|
11
15
|
/** The conversation's bound project root (`conversations.project_path`). */
|
|
12
16
|
root: string;
|
|
13
|
-
}
|
|
17
|
+
} | {
|
|
18
|
+
claim: ExecutionClaim;
|
|
19
|
+
purpose: "write_base";
|
|
20
|
+
/** The one clean, absolute file path the read may reach. */
|
|
21
|
+
path: string;
|
|
22
|
+
};
|
|
23
|
+
/** What a kernel read reaches, without its claim. */
|
|
24
|
+
export type KernelReadTarget = Omit<Extract<KernelReadInvocation, {
|
|
25
|
+
purpose: "project_root";
|
|
26
|
+
}>, "claim"> | Omit<Extract<KernelReadInvocation, {
|
|
27
|
+
purpose: "write_base";
|
|
28
|
+
}>, "claim">;
|
|
14
29
|
/** The directory of a project's skills, relative to its root (project root spec §4.7). */
|
|
15
30
|
export declare const PROJECT_SKILLS_DIR = ".agents/skills";
|
|
16
31
|
/** The methods a kernel read may use: never a write, an exec or a scan. */
|
|
@@ -25,9 +40,24 @@ export declare const isKernelReadMethod: (method: string) => method is KernelRea
|
|
|
25
40
|
*/
|
|
26
41
|
export declare function kernelReadRoot(root: string, method: KernelReadMethod, path: string): string | null;
|
|
27
42
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
43
|
+
* The one path a kernel read of `read` may reach with `method` that covers `path`, the
|
|
44
|
+
* operation's only read root; null when the read is outside it. `project_root`: {@link
|
|
45
|
+
* kernelReadRoot}. `write_base`: `stat` or `readFile` of exactly its clean, absolute path, nothing
|
|
46
|
+
* else (no `list`, no other path, no parent or child).
|
|
47
|
+
*/
|
|
48
|
+
export declare function kernelReadCovering(read: KernelReadTarget, method: KernelReadMethod, path: string): string | null;
|
|
49
|
+
/**
|
|
50
|
+
* A `write_base` kernel read of a device whose instance is not running (none yet, suspended,
|
|
51
|
+
* being made, destroyed or replaced): nothing was made, woken or resumed and nothing was sent.
|
|
52
|
+
*/
|
|
53
|
+
export declare class KernelReadInstanceNotRunning extends Error {
|
|
54
|
+
constructor();
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A kernel read that was not admitted (its run is no longer the claim's run in the state its
|
|
58
|
+
* purpose needs, the authority refused it, its scope changed before dispatch): nothing was sent to
|
|
59
|
+
* the device. The knowledge read treats it as a device that could not be asked, never as an
|
|
60
|
+
* unreadable project.
|
|
31
61
|
*/
|
|
32
62
|
export declare class KernelReadNotAdmitted extends Error {
|
|
33
63
|
constructor(cause: unknown);
|
|
@@ -28,9 +28,39 @@ export function kernelReadRoot(root, method, path) {
|
|
|
28
28
|
return null;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
* The one path a kernel read of `read` may reach with `method` that covers `path`, the
|
|
32
|
+
* operation's only read root; null when the read is outside it. `project_root`: {@link
|
|
33
|
+
* kernelReadRoot}. `write_base`: `stat` or `readFile` of exactly its clean, absolute path, nothing
|
|
34
|
+
* else (no `list`, no other path, no parent or child).
|
|
35
|
+
*/
|
|
36
|
+
export function kernelReadCovering(read, method, path) {
|
|
37
|
+
if (read.purpose === "project_root")
|
|
38
|
+
return kernelReadRoot(read.root, method, path);
|
|
39
|
+
if (read.purpose !== "write_base")
|
|
40
|
+
return null;
|
|
41
|
+
if (method !== "stat" && method !== "readFile")
|
|
42
|
+
return null;
|
|
43
|
+
if (validateSandboxPathShape(read.path).length > 0 || posix.normalize(read.path) !== read.path)
|
|
44
|
+
return null;
|
|
45
|
+
if (read.path === "/" || path !== read.path)
|
|
46
|
+
return null;
|
|
47
|
+
return read.path;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A `write_base` kernel read of a device whose instance is not running (none yet, suspended,
|
|
51
|
+
* being made, destroyed or replaced): nothing was made, woken or resumed and nothing was sent.
|
|
52
|
+
*/
|
|
53
|
+
export class KernelReadInstanceNotRunning extends Error {
|
|
54
|
+
constructor() {
|
|
55
|
+
super("The device's instance is not running; a display-only read never starts it");
|
|
56
|
+
this.name = "KernelReadInstanceNotRunning";
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A kernel read that was not admitted (its run is no longer the claim's run in the state its
|
|
61
|
+
* purpose needs, the authority refused it, its scope changed before dispatch): nothing was sent to
|
|
62
|
+
* the device. The knowledge read treats it as a device that could not be asked, never as an
|
|
63
|
+
* unreadable project.
|
|
34
64
|
*/
|
|
35
65
|
export class KernelReadNotAdmitted extends Error {
|
|
36
66
|
constructor(cause) {
|
|
@@ -4,7 +4,7 @@ import { PermissionProfileStore } from "../conversations/permission-profile-stor
|
|
|
4
4
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
5
5
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
6
6
|
import type { DeviceSandbox } from "./device-sandbox.js";
|
|
7
|
-
import { type
|
|
7
|
+
import { type KernelReadMethod, type KernelReadTarget } from "./kernel-read.js";
|
|
8
8
|
import { NetworkGrants } from "./network-grants.js";
|
|
9
9
|
import { PermissionAuthorityEpochStore } from "./permission-authority-epochs.js";
|
|
10
10
|
import { PermissionAuthorityLock } from "./permission-authority-lock.js";
|
|
@@ -94,19 +94,23 @@ export declare class SandboxOperationAuthority {
|
|
|
94
94
|
executionGrants: import("./operation-authority-types.js").StartingExecutionGrants | null;
|
|
95
95
|
}>;
|
|
96
96
|
/**
|
|
97
|
-
* The scope of one kernel read (permission activation L2
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
97
|
+
* The scope of one kernel read (permission activation L2): the conversation's profile scope from
|
|
98
|
+
* the same authority snapshot admission reads, intersected with the one path the read may reach
|
|
99
|
+
* ({@link kernelReadCovering}). By purpose:
|
|
100
|
+
* - `project_root` (Hook 1): the bound project as the working root it becomes once read (the
|
|
101
|
+
* review's fallbacks apply: a root outside the mode or above the home is refused); the root's
|
|
102
|
+
* `stat`, `AGENTS.md`, `.agents/skills/**`.
|
|
103
|
+
* - `write_base` (streaming tool input spec §4.1): the working root admission decides for a tool
|
|
104
|
+
* call; `stat` and `readFile` of exactly the one path, which must lie strictly inside that
|
|
105
|
+
* working root, never the root itself (a path a `Write` reaches only by escalation gets no
|
|
106
|
+
* base).
|
|
107
|
+
* The restricted {@link KERNEL_READ_PROFILE} whenever the runtime enforces it (the runtime then
|
|
108
|
+
* enforces the read root, symlinks included); the conversation's admitted Full access only on an
|
|
109
|
+
* isolated Full-only runtime; a host machine without restricted enforcement throws
|
|
105
110
|
* {@link KernelReadUnsupported} ({@link kernelReadRoute}). No write roots, no hosts, never a
|
|
106
|
-
* per-call grant. Called under the run
|
|
107
|
-
* check that its run is still `queued`).
|
|
111
|
+
* per-call grant. Called under the run's claim only (the intents check its run state).
|
|
108
112
|
*/
|
|
109
|
-
resolveKernelRead(ctx: SandboxUseContext, read:
|
|
113
|
+
resolveKernelRead(ctx: SandboxUseContext, read: KernelReadTarget, method: KernelReadMethod, path: string, signal: AbortSignal): Promise<SandboxOperationScope>;
|
|
110
114
|
private scopeOf;
|
|
111
115
|
private snapshot;
|
|
112
116
|
/**
|
|
@@ -19,7 +19,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
19
19
|
import { TransactionHost, withTransactionFencePrelude, } from "../infra/database/transaction-host.js";
|
|
20
20
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
21
21
|
import { hostGrantable } from "./device-sandbox.js";
|
|
22
|
-
import { KernelReadUnsupported,
|
|
22
|
+
import { KernelReadUnsupported, kernelReadCovering, kernelReadRoute, } from "./kernel-read.js";
|
|
23
23
|
import { coversHost } from "./modes.js";
|
|
24
24
|
import { NetworkGrants } from "./network-grants.js";
|
|
25
25
|
import { EscalationGrantMissingError, isExecutionMethod, parseStartingExecutionGrants, } from "./operation-authority-types.js";
|
|
@@ -324,30 +324,43 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
324
324
|
return { scope, permissionGrantId, grantedHosts: hosts, executionGrants };
|
|
325
325
|
}
|
|
326
326
|
/**
|
|
327
|
-
* The scope of one kernel read (permission activation L2
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
327
|
+
* The scope of one kernel read (permission activation L2): the conversation's profile scope from
|
|
328
|
+
* the same authority snapshot admission reads, intersected with the one path the read may reach
|
|
329
|
+
* ({@link kernelReadCovering}). By purpose:
|
|
330
|
+
* - `project_root` (Hook 1): the bound project as the working root it becomes once read (the
|
|
331
|
+
* review's fallbacks apply: a root outside the mode or above the home is refused); the root's
|
|
332
|
+
* `stat`, `AGENTS.md`, `.agents/skills/**`.
|
|
333
|
+
* - `write_base` (streaming tool input spec §4.1): the working root admission decides for a tool
|
|
334
|
+
* call; `stat` and `readFile` of exactly the one path, which must lie strictly inside that
|
|
335
|
+
* working root, never the root itself (a path a `Write` reaches only by escalation gets no
|
|
336
|
+
* base).
|
|
337
|
+
* The restricted {@link KERNEL_READ_PROFILE} whenever the runtime enforces it (the runtime then
|
|
338
|
+
* enforces the read root, symlinks included); the conversation's admitted Full access only on an
|
|
339
|
+
* isolated Full-only runtime; a host machine without restricted enforcement throws
|
|
335
340
|
* {@link KernelReadUnsupported} ({@link kernelReadRoute}). No write roots, no hosts, never a
|
|
336
|
-
* per-call grant. Called under the run
|
|
337
|
-
* check that its run is still `queued`).
|
|
341
|
+
* per-call grant. Called under the run's claim only (the intents check its run state).
|
|
338
342
|
*/
|
|
339
343
|
async resolveKernelRead(ctx, read, method, path, signal) {
|
|
340
|
-
if (read.purpose !== "project_root")
|
|
344
|
+
if (read.purpose !== "project_root" && read.purpose !== "write_base")
|
|
341
345
|
throw new ApiError("forbidden", "Unknown kernel read purpose");
|
|
342
|
-
const covering =
|
|
346
|
+
const covering = kernelReadCovering(read, method, path);
|
|
343
347
|
if (covering === null)
|
|
344
|
-
throw new ApiError("forbidden",
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
348
|
+
throw new ApiError("forbidden", read.purpose === "project_root"
|
|
349
|
+
? "A kernel read reaches only the project's root, its AGENTS.md and its .agents/skills"
|
|
350
|
+
: "A write base read reaches only its one file, by stat or readFile");
|
|
351
|
+
const f = await this.snapshot(ctx, { runId: ctx.actor.runId ?? "", callId: "" }, signal, undefined, read.purpose === "project_root" ? { projectUsable: true } : {});
|
|
352
|
+
if (read.purpose === "project_root") {
|
|
353
|
+
const bound = await this.profiles.readOwnedRoot(ctx.orgId, ctx.holderConversationId, ctx.actor.accountId);
|
|
354
|
+
if (bound.project_path === null ||
|
|
355
|
+
canonicalRoot(bound.project_path) !== canonicalRoot(read.root) ||
|
|
356
|
+
canonicalRoot(f.workingRoot) !== canonicalRoot(read.root))
|
|
357
|
+
throw new ApiError("forbidden", "The kernel read's root is not the conversation's usable project root");
|
|
358
|
+
}
|
|
359
|
+
else if (
|
|
360
|
+
// exactly one file inside the working root, never the root directory itself
|
|
361
|
+
canonicalRoot(covering) === canonicalRoot(f.workingRoot) ||
|
|
362
|
+
!withinDirectory(covering, f.workingRoot))
|
|
363
|
+
throw new ApiError("forbidden", "The write base read is outside the conversation's working root");
|
|
351
364
|
// the recorded runtime support decides the route: restricted when enforced, Full access only
|
|
352
365
|
// on an isolated Full-only runtime, nothing on a host machine without restricted enforcement
|
|
353
366
|
const availability = f.availability;
|
|
@@ -104,9 +104,10 @@ export declare class SandboxOperationIntents {
|
|
|
104
104
|
accountId: string;
|
|
105
105
|
}, instance: OperationInstance, method: "stat" | "list" | "scan", input: unknown, signal: AbortSignal): Promise<OperationIntent>;
|
|
106
106
|
/**
|
|
107
|
-
* The run
|
|
108
|
-
*
|
|
109
|
-
*
|
|
107
|
+
* The run of a kernel read (permission activation L2): the run must still be the claim's
|
|
108
|
+
* execution, triggered by the actor and in the state its purpose reads in, checked in PG under
|
|
109
|
+
* the authority locks the caller already holds. `project_root` reads before its run's first
|
|
110
|
+
* model call (`queued`); `write_base` reads while its run streams a `Write` (`running`).
|
|
110
111
|
*/
|
|
111
112
|
private assertKernelReadRun;
|
|
112
113
|
/**
|
|
@@ -202,7 +203,12 @@ export declare class SandboxOperationIntents {
|
|
|
202
203
|
* retention expiry job settles what is never resolved.
|
|
203
204
|
*/
|
|
204
205
|
deferBackgroundRecovery(id: string): Promise<void>;
|
|
205
|
-
complete(id: string, executionId: string, result: unknown
|
|
206
|
+
complete(id: string, executionId: string, result: unknown,
|
|
207
|
+
/**
|
|
208
|
+
* A kernel read's purpose: required for a row with a run and no tool call (a kernel read),
|
|
209
|
+
* whose run state it decides; never defaulted, so a caller that forgets it fails loudly.
|
|
210
|
+
*/
|
|
211
|
+
kernelRead?: KernelReadInvocation["purpose"]): Promise<void>;
|
|
206
212
|
result(row: OperationIntent): Promise<unknown>;
|
|
207
213
|
/**
|
|
208
214
|
* The dispatcher with `executionId` gave up on its dispatch: its outcome is unknown. Fenced by
|
|
@@ -311,11 +311,18 @@ let SandboxOperationIntents = class SandboxOperationIntents {
|
|
|
311
311
|
return row;
|
|
312
312
|
}
|
|
313
313
|
/**
|
|
314
|
-
* The run
|
|
315
|
-
*
|
|
316
|
-
*
|
|
314
|
+
* The run of a kernel read (permission activation L2): the run must still be the claim's
|
|
315
|
+
* execution, triggered by the actor and in the state its purpose reads in, checked in PG under
|
|
316
|
+
* the authority locks the caller already holds. `project_root` reads before its run's first
|
|
317
|
+
* model call (`queued`); `write_base` reads while its run streams a `Write` (`running`).
|
|
317
318
|
*/
|
|
318
|
-
async assertKernelReadRun(ctx,
|
|
319
|
+
async assertKernelReadRun(ctx, read) {
|
|
320
|
+
const c = read.claim;
|
|
321
|
+
const status = read.purpose === "project_root"
|
|
322
|
+
? "queued"
|
|
323
|
+
: read.purpose === "write_base"
|
|
324
|
+
? "running"
|
|
325
|
+
: denied("Unknown kernel read purpose");
|
|
319
326
|
const run = await this.db
|
|
320
327
|
.selectFrom("runs")
|
|
321
328
|
.select(["execution_id", "trigger_account_id", "status"])
|
|
@@ -326,8 +333,8 @@ let SandboxOperationIntents = class SandboxOperationIntents {
|
|
|
326
333
|
if (!run ||
|
|
327
334
|
run.execution_id !== c.executionId ||
|
|
328
335
|
run.trigger_account_id !== ctx.actor.accountId ||
|
|
329
|
-
run.status !==
|
|
330
|
-
denied("The
|
|
336
|
+
run.status !== status)
|
|
337
|
+
denied("The kernel read's execution claim is no longer current");
|
|
331
338
|
}
|
|
332
339
|
/**
|
|
333
340
|
* Admits one kernel read (Hook 1), modelled on {@link admitBrowse}: a random operation id per
|
|
@@ -348,7 +355,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
|
|
|
348
355
|
const scope = await this.authority.resolveKernelRead(ctx, read, method, input.path, signal);
|
|
349
356
|
if (scope.rootConversationId !== c.rootId)
|
|
350
357
|
denied("The kernel read's root no longer matches the execution claim");
|
|
351
|
-
await this.assertKernelReadRun(ctx,
|
|
358
|
+
await this.assertKernelReadRun(ctx, read);
|
|
352
359
|
const described = describeOperationPayload(input);
|
|
353
360
|
const payload = payloadReference("input", described);
|
|
354
361
|
const vector = await this.epochs.readLocked({
|
|
@@ -407,7 +414,7 @@ let SandboxOperationIntents = class SandboxOperationIntents {
|
|
|
407
414
|
const initial = await this.read(id);
|
|
408
415
|
await this.locks.acquire(subjectOf(initial), { kind: "admit" });
|
|
409
416
|
const c = read.claim;
|
|
410
|
-
await this.assertKernelReadRun(ctx,
|
|
417
|
+
await this.assertKernelReadRun(ctx, read);
|
|
411
418
|
const row = await this.db
|
|
412
419
|
.selectFrom("sandbox_operation_intents")
|
|
413
420
|
.selectAll()
|
|
@@ -1040,16 +1047,29 @@ let SandboxOperationIntents = class SandboxOperationIntents {
|
|
|
1040
1047
|
runAt,
|
|
1041
1048
|
});
|
|
1042
1049
|
}
|
|
1043
|
-
async complete(id, executionId, result
|
|
1050
|
+
async complete(id, executionId, result,
|
|
1051
|
+
/**
|
|
1052
|
+
* A kernel read's purpose: required for a row with a run and no tool call (a kernel read),
|
|
1053
|
+
* whose run state it decides; never defaulted, so a caller that forgets it fails loudly.
|
|
1054
|
+
*/
|
|
1055
|
+
kernelRead) {
|
|
1044
1056
|
const initial = await this.read(id);
|
|
1045
1057
|
if (initial.run_id !== null) {
|
|
1046
|
-
// a kernel read (no tool call) serves a run start, which reads while its run is queued
|
|
1058
|
+
// a kernel read (no tool call) serves a run start, which reads while its run is queued, or a
|
|
1059
|
+
// write base, which reads while its run is running
|
|
1060
|
+
let status = "running";
|
|
1061
|
+
if (initial.call_id === null) {
|
|
1062
|
+
if (kernelRead === "project_root")
|
|
1063
|
+
status = "queued";
|
|
1064
|
+
else if (kernelRead !== "write_base")
|
|
1065
|
+
throw new Error("A kernel read's completion must name its purpose");
|
|
1066
|
+
}
|
|
1047
1067
|
const run = await this.db
|
|
1048
1068
|
.selectFrom("runs")
|
|
1049
1069
|
.select("id")
|
|
1050
1070
|
.where("id", "=", initial.run_id)
|
|
1051
1071
|
.where("execution_id", "=", executionId)
|
|
1052
|
-
.where("status", "=",
|
|
1072
|
+
.where("status", "=", status)
|
|
1053
1073
|
.forShare()
|
|
1054
1074
|
.executeTakeFirst();
|
|
1055
1075
|
if (!run)
|
|
@@ -588,15 +588,38 @@ export declare class SandboxService {
|
|
|
588
588
|
*/
|
|
589
589
|
applyLimitsIfRunning(use: SandboxUseContext, signal: AbortSignal): Promise<"applied" | "unchanged" | "not_running">;
|
|
590
590
|
/**
|
|
591
|
-
* A
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
*
|
|
596
|
-
*
|
|
597
|
-
*
|
|
591
|
+
* A kernel read of the device on behalf of a run (permission activation L2), whose provider
|
|
592
|
+
* stats, reads and lists only, each call a kernel read admitted and claimed on its own
|
|
593
|
+
* (`SandboxOperationIntents.admitKernelRead`: the run's current claim with its run in the state
|
|
594
|
+
* the purpose needs, a random operation id, the profile scope narrowed to the one covering
|
|
595
|
+
* path). Any other method is refused before admission. No path lease is taken. By purpose:
|
|
596
|
+
* - `project_root` (Hook 1, the run `queued`): the use a tool call's would be (the instance made
|
|
597
|
+
* or resumed, the read silent for the holder), narrowed to the root, its `AGENTS.md` and its
|
|
598
|
+
* `.agents/skills`.
|
|
599
|
+
* - `write_base` (streaming tool input spec §4.1, the run `running`): only on the device's
|
|
600
|
+
* running instance, as an owner browse is ({@link ifRunning}): it never makes, wakes, resumes
|
|
601
|
+
* or rebuilds one (else {@link KernelReadInstanceNotRunning}) and touches no seen record;
|
|
602
|
+
* `stat` and `readFile` of exactly its path.
|
|
603
|
+
* Only the kernel's own run code calls this: no tool context, Platform operation or route has it.
|
|
598
604
|
*/
|
|
599
605
|
withKernelRead<T>(ctx: SandboxUseContext, read: KernelReadInvocation, fn: (h: SandboxHandle, p: HeldProvider, info: SandboxUseInfo, signal: AbortSignal) => Promise<T>, signal: AbortSignal): Promise<T>;
|
|
606
|
+
/**
|
|
607
|
+
* A `write_base` kernel read ({@link withKernelRead}) on the instance the device runs now, under
|
|
608
|
+
* a shared lease taken the way {@link ifRunning} takes it (B1 reconcile marker and retirement
|
|
609
|
+
* gate included): a device with no running instance, or one that changes instance before the
|
|
610
|
+
* lease, throws {@link KernelReadInstanceNotRunning} with nothing made, woken or sent.
|
|
611
|
+
*
|
|
612
|
+
* Unlike a use's `enter`, this path neither applies changed limits (`mustApply`, which needs the
|
|
613
|
+
* exclusive lease and may rebuild the instance) nor refreshes stale cloud evidence
|
|
614
|
+
* (`refreshCloudSupport`, B-15), since either would be lifecycle work a display-only read must
|
|
615
|
+
* not cause. That is acceptable here: the read only stats and reads one file, its scope carries
|
|
616
|
+
* no write roots (an instance boundary's own scope aside) and network `none`, and the boundary
|
|
617
|
+
* is the kernel-side covering-path check at admission and claim, not the instance's applied
|
|
618
|
+
* limits. Stale evidence still picks among the routes `kernelReadRoute` allows (Full access
|
|
619
|
+
* only on an instance boundary), so the read stays one path, read-only, with no network; a
|
|
620
|
+
* provider that no longer accepts the scope refuses it, and the person just gets no base.
|
|
621
|
+
*/
|
|
622
|
+
private withRunningKernelRead;
|
|
600
623
|
withOperations<T>(ctx: SandboxUseContext, invocation: OperationSessionInvocation, fn: (h: SandboxHandle, p: HeldProvider, info: SandboxUseInfo, signal: AbortSignal) => Promise<T>, signal: AbortSignal): Promise<T>;
|
|
601
624
|
/**
|
|
602
625
|
* Every use of the device's instance ({@link withOperations}, {@link withPreparation},
|
|
@@ -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. " +
|
|
@@ -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 " +
|
|
@@ -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; " +
|
|
@@ -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, ",");
|