@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.
Files changed (74) hide show
  1. package/dist/agents/readiness.controller.d.ts +4 -3
  2. package/dist/agents/readiness.controller.js +4 -3
  3. package/dist/agents/readiness.service.d.ts +44 -11
  4. package/dist/agents/readiness.service.js +59 -16
  5. package/dist/catalog/catalog-import.module.d.ts +1 -1
  6. package/dist/catalog/catalog-import.module.js +1 -1
  7. package/dist/catalog/cli.d.ts +9 -2
  8. package/dist/catalog/cli.js +10 -4
  9. package/dist/catalog/marketplaces.service.d.ts +1 -1
  10. package/dist/catalog/plugin-upgrade.d.ts +4 -2
  11. package/dist/catalog/plugin-upgrade.js +9 -3
  12. package/dist/db/kernel-schema.d.ts +5 -0
  13. package/dist/devices/device-projects.service.d.ts +3 -12
  14. package/dist/devices/device-projects.service.js +16 -59
  15. package/dist/extensions/bootstrap.d.ts +17 -3
  16. package/dist/extensions/bootstrap.js +56 -14
  17. package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
  18. package/dist/lifecycle/kernel-lifecycle.js +16 -11
  19. package/dist/overrides.d.ts +0 -5
  20. package/dist/overrides.js +0 -2
  21. package/dist/platform/file-ref.d.ts +6 -5
  22. package/dist/platform/ops/agent-skills.ops.js +1 -1
  23. package/dist/platform/ops/agents.ops.js +1 -1
  24. package/dist/runtime/model-call.d.ts +2 -2
  25. package/dist/runtime/project/knowledge.d.ts +1 -1
  26. package/dist/runtime/project/knowledge.js +1 -1
  27. package/dist/runtime/project/knowledge.service.d.ts +5 -11
  28. package/dist/runtime/project/knowledge.service.js +12 -23
  29. package/dist/runtime/providers.d.ts +34 -1
  30. package/dist/runtime/providers.js +56 -7
  31. package/dist/runtime/run-steps.d.ts +4 -6
  32. package/dist/runtime/run-steps.js +7 -15
  33. package/dist/runtime/runtime.module.js +1 -1
  34. package/dist/sandbox/held-operations.d.ts +2 -5
  35. package/dist/sandbox/held-operations.js +0 -14
  36. package/dist/sandbox/managed-device-context.d.ts +1 -1
  37. package/dist/sandbox/managed-device-context.js +1 -1
  38. package/dist/sandbox/permission-context-types.d.ts +0 -11
  39. package/dist/sandbox/permission-context-types.js +0 -13
  40. package/dist/sandbox/providers.d.ts +5 -0
  41. package/dist/sandbox/providers.js +1 -1
  42. package/dist/sandbox/sandbox-file-reader.d.ts +7 -12
  43. package/dist/sandbox/sandbox-file-reader.js +12 -29
  44. package/dist/sandbox/sandbox.service.d.ts +53 -32
  45. package/dist/sandbox/sandbox.service.js +217 -141
  46. package/dist/sandbox/use-context.d.ts +4 -1
  47. package/dist/skills/invoke.d.ts +13 -35
  48. package/dist/skills/invoke.js +23 -162
  49. package/dist/tools/builtins/builtin-tools.d.ts +2 -11
  50. package/dist/tools/builtins/builtin-tools.js +5 -23
  51. package/dist/tools/builtins/image/generate.js +2 -2
  52. package/dist/tools/builtins/sandbox/common.d.ts +32 -80
  53. package/dist/tools/builtins/sandbox/common.js +61 -173
  54. package/dist/tools/builtins/sandbox/deliver.js +2 -2
  55. package/dist/tools/builtins/sandbox/device-owner.d.ts +4 -5
  56. package/dist/tools/builtins/sandbox/device-owner.js +5 -6
  57. package/dist/tools/builtins/sandbox/fetch-attachment.js +2 -2
  58. package/dist/tools/builtins/sandbox/glob.js +1 -1
  59. package/dist/tools/builtins/sandbox/grep.js +1 -1
  60. package/dist/tools/builtins/sandbox/index.d.ts +2 -2
  61. package/dist/tools/builtins/sandbox/index.js +2 -2
  62. package/dist/tools/builtins/sandbox/read.js +1 -1
  63. package/dist/tools/builtins/sandbox/task-output.d.ts +3 -3
  64. package/dist/tools/builtins/sandbox/task-output.js +4 -4
  65. package/dist/tools/builtins/sandbox/task-stop.js +1 -1
  66. package/dist/tools/builtins/skill-load.js +2 -2
  67. package/dist/tools/connectors.service.d.ts +4 -2
  68. package/dist/tools/connectors.service.js +15 -3
  69. package/dist/tools/pipeline.d.ts +0 -2
  70. package/dist/tools/pipeline.js +7 -14
  71. package/dist/tools/tools.module.js +1 -1
  72. package/package.json +2 -2
  73. package/src/migrations/0179_device_report_limit_text.sql +28 -0
  74. package/src/migrations/0180_device_instance_abandoned.sql +6 -0
@@ -3,7 +3,6 @@ import { DeviceProtocolError } from "@capybara-hq/plugin-sdk/device-protocol";
3
3
  import { ANONYMOUS_NO_DEVICE, NO_DEVICE, } from "../../../devices/conversation-devices.js";
4
4
  import { canonicalRoot, workingRootOf } from "../../../devices/working-root.js";
5
5
  import { ApiError } from "../../../errors.js";
6
- import { devicePathsChange } from "../../../runtime/context/device-paths.js";
7
6
  import { ATTACHMENTS_ROOT, attachmentsDir, attachmentsRoot, } from "../../../sandbox/attachments-path.js";
8
7
  import { SandboxPathBusyError } from "../../../sandbox/leases.js";
9
8
  import { MANAGED_DEVICE_CONTEXT_FAILED_TEXT, MANAGED_DEVICE_CONTEXT_STALE_TEXT, MANAGED_DEVICE_CONTEXT_UNAVAILABLE_TEXT, ManagedDeviceContextFailed, ManagedDeviceContextStale, ManagedDeviceContextUnavailable, } from "../../../sandbox/managed-device-context.js";
@@ -153,15 +152,11 @@ export function checkPath(path, roots, field = "path") {
153
152
  return path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path;
154
153
  }
155
154
  /**
156
- * A file tool's path under the session's {@link SandboxSession.pathBound}: bounded by the
157
- * operation's admitted scope, any clean absolute path passes here (shape checks only; the review
158
- * proposes a directory crossing for a path outside the scope, and the device refuses one the
159
- * scope does not cover, protected paths included); bounded by the fixed roots, a path must lie
160
- * under one of them ({@link checkPath}).
155
+ * A file tool's path, bounded by the operation's admitted scope: any clean absolute path passes
156
+ * here (shape checks only; the review proposes a directory crossing for a path outside the scope,
157
+ * and the device refuses one the scope does not cover, protected paths included).
161
158
  */
162
- export function checkToolPath(path, s, field = "path") {
163
- if (s.pathBound === "roots")
164
- return checkPath(path, s.roots, field);
159
+ export function checkToolPath(path, field = "path") {
165
160
  checkPathShape(path, field);
166
161
  return path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path;
167
162
  }
@@ -200,12 +195,9 @@ export function resolveToolPath(path, s) {
200
195
  }
201
196
  /** {@link checkToolPath} for a writing tool: the skills directory stays read-only either way. */
202
197
  export function checkToolWritable(path, s) {
203
- const p = checkToolPath(resolveToolPath(path, s), s, "file_path");
198
+ const p = checkToolPath(resolveToolPath(path, s), "file_path");
204
199
  if (p === s.roots.skills || p.startsWith(`${s.roots.skills}/`)) {
205
- const where = s.pathBound === "scope"
206
- ? "pass another path instead"
207
- : `pass a path under ${s.roots.workspace} or ${s.roots.tmp} instead`;
208
- throw new ToolError(`Path ${clip(p, 200)} is read-only (${s.roots.skills} holds skill files); ${where}.`);
200
+ throw new ToolError(`Path ${clip(p, 200)} is read-only (${s.roots.skills} holds skill files); pass another path instead.`);
209
201
  }
210
202
  return p;
211
203
  }
@@ -268,19 +260,6 @@ export function assignAttachmentNames(items, used) {
268
260
  }
269
261
  return out;
270
262
  }
271
- /** Temporary protocol-2 binding; removed with the active caller cutover in Task8. */
272
- function legacyPreparationSession(s) {
273
- return {
274
- deviceId: s.deviceId,
275
- roots: s.roots,
276
- signal: s.signal,
277
- p: {
278
- readFile: (path, opts) => s.p.readFile(s.h, path, opts),
279
- writeFile: (path, data, signal) => s.p.writeFile(s.h, path, data, signal),
280
- stat: (path, signal) => s.p.stat(s.h, path, signal),
281
- },
282
- };
283
- }
284
263
  /**
285
264
  * Running outside the sandbox refused by policy (B-13): the organization
286
265
  * (`org.outside_sandbox_not_allowed`) or the platform (`deployment.*`) has its outside-sandbox
@@ -473,7 +452,7 @@ export function mapSandboxError(e, log) {
473
452
  if (e.code === "sandbox.create_failed")
474
453
  return new ToolError(SANDBOX_CREATE_FAILED_TEXT);
475
454
  }
476
- // an operation outside withSandbox's own mapping (it records lost files itself)
455
+ // an operation outside the sandbox service's own mapping (it records lost files itself)
477
456
  if (isFileSystemGoneError(e))
478
457
  return new ToolError(ENV_FILES_LOST_TEXT);
479
458
  if (e instanceof DeviceProtocolError)
@@ -485,45 +464,25 @@ export function mapSandboxError(e, log) {
485
464
  return e;
486
465
  }
487
466
  /**
488
- * Runs `fn` in the device of the call's conversation (a sub-agent: its root's): resolves and
489
- * checks the device for the conversation's owner (binding an unbound conversation to the
490
- * owner's default first), then `SandboxService.withSandbox` (the instance created, resumed or
491
- * rebuilt on the kept files as needed, every `exec` carrying the call's actor). It never touches
467
+ * The device entry of every builtin tool (B-17): runs `fn` in the device of the call's
468
+ * conversation (a sub-agent: its root's) on the managed operation route
469
+ * ({@link inSandboxOperations}): the device resolved and checked for the conversation's owner
470
+ * (binding an unbound conversation to the owner's default first), the marked device paths
471
+ * recorded before the callback, every provider call a managed operation. It never touches
492
472
  * attachments: `FetchAttachment` is the only way one enters the device. Returns the value and the
493
- * notices to put before the result (first use, a new instance). When `withSandbox` rebuilds a gone
494
- * instance and calls `fn` again, the notices are the last call's. The instance's roots are recorded
495
- * for the model on the conversation's first call and whenever they change
496
- * ({@link recordDevicePaths}).
497
- */
498
- export async function inSandbox(deps, ctx, fn) {
499
- return inSandboxWith(deps, ctx, fn, false);
500
- }
501
- /**
502
- * The device entry of every builtin tool (B-17): once the one activation gate is on (the managed
503
- * writer required, {@link SandboxToolDeps.managedDeviceContextRequired}) the managed operation
504
- * route ({@link inSandboxOperations}: the marked device paths recorded before the callback, every
505
- * provider call a managed operation); otherwise the legacy route ({@link inSandbox}), unchanged.
473
+ * notices to put before the result (first use, a new instance).
506
474
  */
507
475
  export async function inToolSandbox(deps, ctx, fn) {
508
- return deps.managedDeviceContextRequired
509
- ? inSandboxOperations(deps, ctx, fn)
510
- : inSandbox(deps, ctx, fn);
476
+ return inSandboxOperations(deps, ctx, fn);
511
477
  }
512
478
  export async function inSandboxOperations(deps, ctx, fn, stage) {
513
- return inSandboxWith(deps, ctx, fn, true, stage);
479
+ return inSandboxWith(deps, ctx, fn, stage);
514
480
  }
515
481
  /**
516
- * Trusted copy callbacks only receive preparation's three methods. Once the activation gate is on
517
- * the copy is a trusted preparation on the managed route ({@link inSandboxOperationPreparation},
518
- * scoped to `roots`, after the marked device paths); otherwise the protocol-2 binding.
482
+ * Trusted copy callbacks only receive preparation's three methods: the copy is a trusted
483
+ * preparation on the managed route, scoped to `roots`, after the marked device paths.
519
484
  */
520
485
  export async function inSandboxPreparation(deps, ctx, purpose, roots, fn) {
521
- if (deps.managedDeviceContextRequired)
522
- return inSandboxOperationPreparation(deps, ctx, purpose, roots, fn);
523
- return inSandbox(deps, ctx, (s) => fn(legacyPreparationSession(s)));
524
- }
525
- /** The trusted-copy entry on the managed route ({@link inSandboxPreparation} once activated). */
526
- export async function inSandboxOperationPreparation(deps, ctx, purpose, roots, fn) {
527
486
  let value;
528
487
  return inSandboxOperations(deps, ctx, async () => value, {
529
488
  purpose,
@@ -533,68 +492,18 @@ export async function inSandboxOperationPreparation(deps, ctx, purpose, roots, f
533
492
  },
534
493
  });
535
494
  }
536
- async function inSandboxWith(deps, ctx, fn, operations, stage) {
537
- // a run another account triggered never uses the owner's device (activated): refused first
538
- assertDeviceOfRunAccount(deps.managedDeviceContextRequired, ctx);
495
+ async function inSandboxWith(deps, ctx, fn, stage) {
496
+ // a run another account triggered never uses the owner's device: refused first
497
+ assertDeviceOfRunAccount(ctx);
539
498
  try {
540
- // once activated, only the managed route runs: a legacy route refuses before entering, so v1
541
- // permission context never sits next to old-mode device_paths; a managed route never runs
542
- // without its writer, so no preparation or user callback can run unrecorded
543
- if (!operations && deps.managedDeviceContextRequired)
544
- throw new ManagedDeviceContextFailed("refused");
545
- const managed = operations ? managedWriter(deps) : undefined;
499
+ const managed = deps.managedDeviceContext;
546
500
  const deviceId = await deps.devices.forTool(ctx.orgId, sandboxConversationOf(ctx));
547
- // the mode once per call: the path checks follow it and the device_paths event records it;
548
- // the working facts (workspace, home, project snapshot) are read as the review reads them
549
- // a call the review covered runs in the working root it was reviewed against: never read again
501
+ // a call the review covered runs in the working root it was reviewed against
550
502
  const reviewed = ctx.reviewedWorkingRoot;
551
- const [level, working] = await Promise.all([
552
- deps.devices.modeLevel?.(ctx.orgId, deviceId) ?? null,
553
- reviewed !== undefined
554
- ? null
555
- : (deps.devices.workingFacts?.(ctx.orgId, sandboxConversationOf(ctx), ctx.conversationId, deviceId) ?? null),
556
- ]);
557
- const enter = operations
558
- ? (use, call, signal) => {
559
- const claim = ctx.executionClaim;
560
- if (!claim || !ctx.runId || claim.runId !== ctx.runId || !deps.sandbox.withOperations)
561
- throw new SandboxScopeDeniedError("The tool has no current server execution claim");
562
- return deps.sandbox.withOperations(use, {
563
- claim,
564
- callId: ctx.callId,
565
- deadlineMs: Math.min(ctx.runDeadline ?? Infinity, Date.now() + 30000),
566
- ...(managed && { contextEvidence: true }),
567
- beforeUser: async (staging, info, sig) => {
568
- // the held instance's device paths, recorded before any preparation or user callback
569
- if (managed) {
570
- // no installed evidence to describe the held instance: unavailable, not stale
571
- // (a device or machine that is gone for good says so instead)
572
- if (!info.contextEvidence)
573
- throw ((ctx.runId !== undefined &&
574
- (await managed.goneFor?.({
575
- orgId: ctx.orgId,
576
- conversationId: ctx.conversationId,
577
- runId: ctx.runId,
578
- accountId: ctx.accountId,
579
- }, deviceId))) ||
580
- new ManagedDeviceContextUnavailable());
581
- // B-18: the review judged the call against a root (the workspace included);
582
- // held evidence of another root is stale, refused before anything is recorded
583
- // or run
584
- const against = ctx.reviewedAgainstRoot ?? reviewed;
585
- if (against !== undefined &&
586
- canonicalRoot(against) !== canonicalRoot(info.contextEvidence.workingRoot))
587
- throw new ManagedDeviceContextStale();
588
- await recordManagedDevicePaths({ managedDeviceContext: managed }, ctx, info.contextEvidence, sig);
589
- }
590
- if (stage)
591
- await staging.prepare(stage.purpose, stage.roots(info.roots), (p, signal) => stage.run({ deviceId, roots: info.roots, p, signal }));
592
- sig.throwIfAborted();
593
- },
594
- }, call, signal);
595
- }
596
- : deps.sandbox.withSandbox.bind(deps.sandbox);
597
- return await enter({
503
+ const claim = ctx.executionClaim;
504
+ if (!claim || !ctx.runId || claim.runId !== ctx.runId)
505
+ throw new SandboxScopeDeniedError("The tool has no current server execution claim");
506
+ return await deps.sandbox.withOperations({
598
507
  orgId: ctx.orgId,
599
508
  deviceId,
600
509
  // a sub-agent is told when another holder rebuilt the shared instance (final review m5)
@@ -605,27 +514,51 @@ async function inSandboxWith(deps, ctx, fn, operations, stage) {
605
514
  conversationId: ctx.conversationId,
606
515
  ...(ctx.runId !== undefined && { runId: ctx.runId }),
607
516
  },
517
+ }, {
518
+ claim,
519
+ callId: ctx.callId,
520
+ deadlineMs: Math.min(ctx.runDeadline ?? Infinity, Date.now() + 30000),
521
+ contextEvidence: true,
522
+ beforeUser: async (staging, info, sig) => {
523
+ // the held instance's device paths, recorded before any preparation or user callback
524
+ // no installed evidence to describe the held instance: unavailable, not stale
525
+ // (a device or machine that is gone for good says so instead)
526
+ if (!info.contextEvidence)
527
+ throw ((ctx.runId !== undefined &&
528
+ (await managed.goneFor?.({
529
+ orgId: ctx.orgId,
530
+ conversationId: ctx.conversationId,
531
+ runId: ctx.runId,
532
+ accountId: ctx.accountId,
533
+ }, deviceId))) ||
534
+ new ManagedDeviceContextUnavailable());
535
+ // B-18: the review judged the call against a root (the workspace included);
536
+ // held evidence of another root is stale, refused before anything is recorded
537
+ // or run
538
+ const against = ctx.reviewedAgainstRoot ?? reviewed;
539
+ if (against !== undefined &&
540
+ canonicalRoot(against) !== canonicalRoot(info.contextEvidence.workingRoot))
541
+ throw new ManagedDeviceContextStale();
542
+ await recordManagedDevicePaths({ managedDeviceContext: managed }, ctx, info.contextEvidence, sig);
543
+ if (stage)
544
+ await staging.prepare(stage.purpose, stage.roots(info.roots), (p, signal) => stage.run({ deviceId, roots: info.roots, p, signal }));
545
+ sig.throwIfAborted();
546
+ },
608
547
  }, async (h, p, info, signal) => {
609
- // unknown mode: the strict (sandbox) working root rule stays (fail closed)
610
- const mode = level?.mode ?? "sandbox";
548
+ // the held evidence the callback was admitted with (beforeUser refuses without it)
549
+ const evidence = info.contextEvidence;
550
+ if (!evidence)
551
+ throw new ManagedDeviceContextUnavailable();
611
552
  const s = {
612
553
  deviceId,
613
- // the managed route: the admitted scope of each operation bounds the paths, whatever
614
- // the device's tier (its outside-sandbox setting decides only escalations)
615
- pathBound: sessionPathBound(operations, mode),
616
554
  h,
617
555
  roots: info.roots,
618
556
  // a managed call runs in the working root its device context recorded (admission's),
619
557
  // which a reviewed call's root equals (checked before the callback, B-18)
620
- workingRoot: (managed ? info.contextEvidence?.workingRoot : undefined) ??
621
- reviewed ??
622
- sessionWorkingRoot(working, info.roots.workspace),
558
+ workingRoot: evidence.workingRoot,
623
559
  p,
624
560
  signal,
625
561
  };
626
- // the legacy writer only on unactivated routes: a managed call recorded before preparation
627
- if (!managed)
628
- await recordDevicePaths(deps, ctx, info.roots, level ?? null);
629
562
  const notices = [];
630
563
  if (info.filesReset)
631
564
  notices.push(sandboxFilesResetNotice(info.roots));
@@ -640,17 +573,6 @@ async function inSandboxWith(deps, ctx, fn, operations, stage) {
640
573
  throw mapSandboxError(e, deps.log);
641
574
  }
642
575
  }
643
- /**
644
- * The managed writer of an operations route: the injected one, or none while dormant. Once the
645
- * paired activation requires it, a missing writer refuses the call before anything is entered.
646
- */
647
- function managedWriter(deps) {
648
- if (deps.managedDeviceContext)
649
- return deps.managedDeviceContext;
650
- if (deps.managedDeviceContextRequired)
651
- throw new ManagedDeviceContextFailed("refused");
652
- return undefined;
653
- }
654
576
  /**
655
577
  * Records the managed device paths of the held instance `held` into the calling conversation (a
656
578
  * sub-agent: its own log) for this call's run and actor: a thin delegator to the managed writer,
@@ -666,40 +588,6 @@ export async function recordManagedDevicePaths(deps, ctx, held, signal) {
666
588
  accountId: ctx.accountId,
667
589
  }, held, signal);
668
590
  }
669
- /**
670
- * Environments spec §13.1, ruling R22; auto mode spec §4.2: the calling conversation's log (the
671
- * log its model reads; a sub-agent's own too) gets a `device_paths` event on its first sandbox
672
- * call, the default roots included, and again whenever the held instance's roots or the device's
673
- * mode and network differ from the latest recorded ones; always before the call's result. Two
674
- * indexed reads per call (migration 0094, the device's row); parallel calls that saw the same
675
- * latest event write one event (its idempotency key).
676
- */
677
- async function recordDevicePaths(deps, ctx, roots, level) {
678
- if (!deps.eventLog.latestOfType)
679
- return;
680
- const latest = await deps.eventLog.latestOfType(ctx.conversationId, "device_paths");
681
- const change = devicePathsChange(latest, roots, ctx.runId, level ?? undefined);
682
- if (change)
683
- await deps.eventLog.append(ctx.conversationId, [change]);
684
- }
685
- /**
686
- * The working root of a call: the project root exactly as the review decides it (from the same
687
- * {@link WorkingFacts}); when that falls back to the device's workspace, the held instance's own
688
- * workspace (`workspace`), where the call really runs. Every session built outside `inSandbox` (a
689
- * person's project skill invocation) takes its working root from here too.
690
- */
691
- export function sessionWorkingRoot(working, workspace) {
692
- if (working === null)
693
- return workspace;
694
- const root = workingRootOf(working.project, working);
695
- return root === working.workspace ? workspace : root;
696
- }
697
- /**
698
- * What bounds a session's file-tool paths ({@link SandboxSession.pathBound}): the admitted scope
699
- * on the managed operation route, under every tier; on the legacy route, the fixed roots unless
700
- * the device runs in auto mode.
701
- */
702
- export const sessionPathBound = (operations, mode) => (operations || mode === "auto" ? "scope" : "roots");
703
591
  /** The conversation whose device a call uses (the root conversation's for a sub-agent). */
704
592
  export const sandboxConversationOf = (ctx) => ctx.sandboxConversationId ?? ctx.conversationId;
705
593
  /**
@@ -112,8 +112,8 @@ export function sandboxDeliverTool(deps) {
112
112
  const { value: data, notices } = await inToolSandbox(deps, ctx, async (s) => {
113
113
  const { h, p, signal } = s;
114
114
  // bounded as the other file tools are: the admitted scope (a project file outside the
115
- // workspace too), the fixed roots only on the legacy route in sandbox mode
116
- path = checkToolPath(input.file_path, s, "file_path");
115
+ // workspace too)
116
+ path = checkToolPath(input.file_path, "file_path");
117
117
  const st = await p.stat(h, path, signal);
118
118
  if (st === null)
119
119
  throw new ToolError(notFound(path));
@@ -2,12 +2,11 @@
2
2
  export declare const DEVICE_OF_ANOTHER_ACCOUNT_TEXT = "This conversation's device belongs to its owner, and this run was started by another member, so nothing ran on the device. Continue without the device, or ask the conversation's owner to run this.";
3
3
  /**
4
4
  * The one run-account guard of every device entry (the sandbox tools' `inSandboxWith`, the task
5
- * tools, a background launch before its reservation is written): once the paired activation is
6
- * on, a run whose account is not the conversation's owner (a wake attributed to another member)
7
- * never uses the owner's device, refused before any device or database effect. Dormant, nothing
8
- * changes (the earlier behaviour).
5
+ * tools, a background launch before its reservation is written): a run whose account is not the
6
+ * conversation's owner (a wake attributed to another member) never uses the owner's device,
7
+ * refused before any device or database effect.
9
8
  */
10
- export declare function assertDeviceOfRunAccount(active: boolean | undefined, ctx: {
9
+ export declare function assertDeviceOfRunAccount(ctx: {
11
10
  accountId: string;
12
11
  ownerAccountId?: string | undefined;
13
12
  }): void;
@@ -3,12 +3,11 @@ import { ToolError } from "@capybara-hq/plugin-sdk";
3
3
  export const DEVICE_OF_ANOTHER_ACCOUNT_TEXT = "This conversation's device belongs to its owner, and this run was started by another member, so nothing ran on the device. Continue without the device, or ask the conversation's owner to run this.";
4
4
  /**
5
5
  * The one run-account guard of every device entry (the sandbox tools' `inSandboxWith`, the task
6
- * tools, a background launch before its reservation is written): once the paired activation is
7
- * on, a run whose account is not the conversation's owner (a wake attributed to another member)
8
- * never uses the owner's device, refused before any device or database effect. Dormant, nothing
9
- * changes (the earlier behaviour).
6
+ * tools, a background launch before its reservation is written): a run whose account is not the
7
+ * conversation's owner (a wake attributed to another member) never uses the owner's device,
8
+ * refused before any device or database effect.
10
9
  */
11
- export function assertDeviceOfRunAccount(active, ctx) {
12
- if (active && ctx.ownerAccountId !== undefined && ctx.ownerAccountId !== ctx.accountId)
10
+ export function assertDeviceOfRunAccount(ctx) {
11
+ if (ctx.ownerAccountId !== undefined && ctx.ownerAccountId !== ctx.accountId)
13
12
  throw new ToolError(DEVICE_OF_ANOTHER_ACCOUNT_TEXT);
14
13
  }
@@ -98,8 +98,8 @@ export function sandboxFetchAttachmentTool(deps) {
98
98
  }
99
99
  catch (e) {
100
100
  // an abort (timeout / lost lock / stopped run) and a gone device or instance go to
101
- // withSandbox and mapSandboxError; never the provider's own words (they may name its
102
- // internal address)
101
+ // the sandbox service and mapSandboxError; never the provider's own words (they may
102
+ // name its internal address)
103
103
  if (signal.aborted || isSandboxGoneError(e) || isFileSystemGoneError(e))
104
104
  throw e;
105
105
  // a managed route's typed refusal too: mapSandboxError gives its fixed text
@@ -65,7 +65,7 @@ export function sandboxGlobTool(deps) {
65
65
  const { value: files, notices } = await inToolSandbox(deps, ctx, async (s) => {
66
66
  const { h, p, signal } = s;
67
67
  // default: the working root (a bound project's root, else the workspace)
68
- dir = checkToolPath(input.path ?? s.workingRoot, s);
68
+ dir = checkToolPath(input.path ?? s.workingRoot);
69
69
  const st = await p.stat(h, dir, signal);
70
70
  if (!st?.isDir)
71
71
  throw new ToolError(notDirectory(dir, s.workingRoot));
@@ -166,7 +166,7 @@ export function sandboxGrepTool(deps) {
166
166
  const { value, notices } = await inToolSandbox(deps, ctx, async (s) => {
167
167
  const { h, p, signal } = s;
168
168
  // default: the working root (a bound project's root, else the workspace)
169
- path = checkToolPath(g.path ?? s.workingRoot, s);
169
+ path = checkToolPath(g.path ?? s.workingRoot);
170
170
  const st = await p.stat(h, path, signal);
171
171
  if (st === null)
172
172
  throw new ToolError(notFound(path));
@@ -7,8 +7,8 @@ export { sandboxFetchAttachmentTool } from "./fetch-attachment.js";
7
7
  export { compileGlob, GlobPatternError, MAX_GLOB_STARS } from "./glob-match.js";
8
8
  /**
9
9
  * The sandbox builtins (M5 T8): Bash / Read / Write / Edit / Glob / Grep / Deliver / FetchAttachment,
10
- * all run in the conversation's device (`SandboxService.withSandbox`). Attachments are not copied
11
- * into it by a sandbox call: `FetchAttachment` is the only way in, writing one file under
10
+ * all run in the conversation's device (`SandboxService.withOperations`). Attachments are not
11
+ * copied into it by a sandbox call: `FetchAttachment` is the only way in, writing one file under
12
12
  * `<workspace>/attachments/<conversation>` (the instance's roots, environments spec §13.1).
13
13
  * Unavailable without a provider for it. Allowed by default; with the org setting
14
14
  * `sandboxToolPolicy` set to ask, every one but Read / Glob / Grep / FetchAttachment needs approval
@@ -16,8 +16,8 @@ export { sandboxFetchAttachmentTool } from "./fetch-attachment.js";
16
16
  export { compileGlob, GlobPatternError, MAX_GLOB_STARS } from "./glob-match.js";
17
17
  /**
18
18
  * The sandbox builtins (M5 T8): Bash / Read / Write / Edit / Glob / Grep / Deliver / FetchAttachment,
19
- * all run in the conversation's device (`SandboxService.withSandbox`). Attachments are not copied
20
- * into it by a sandbox call: `FetchAttachment` is the only way in, writing one file under
19
+ * all run in the conversation's device (`SandboxService.withOperations`). Attachments are not
20
+ * copied into it by a sandbox call: `FetchAttachment` is the only way in, writing one file under
21
21
  * `<workspace>/attachments/<conversation>` (the instance's roots, environments spec §13.1).
22
22
  * Unavailable without a provider for it. Allowed by default; with the org setting
23
23
  * `sandboxToolPolicy` set to ask, every one but Read / Glob / Grep / FetchAttachment needs approval
@@ -163,7 +163,7 @@ export function sandboxReadTool(deps) {
163
163
  let path = "";
164
164
  const { value, notices } = await inToolSandbox(deps, ctx, async (s) => {
165
165
  const { h, p, signal } = s;
166
- path = checkToolPath(resolveToolPath(filePath, s), s, "file_path");
166
+ path = checkToolPath(resolveToolPath(filePath, s), "file_path");
167
167
  const st = await p.stat(h, path, signal);
168
168
  if (st === null)
169
169
  throw new ToolError(notFound(path));
@@ -35,9 +35,9 @@ export declare const subagentNotTaskText: (id: string) => string;
35
35
  */
36
36
  export declare function ownedTask(env: TaskEnv, ctx: BuiltinCallContext, id: string): Promise<BackgroundTaskRow>;
37
37
  /**
38
- * The per-call access re-check of every sandbox tool (`inSandbox`): the conversation's device
39
- * may still be used by its owner. The task tools read a task's own instance without `inSandbox`,
40
- * so they check here first; errors become the tools' errors.
38
+ * The per-call access re-check of every sandbox tool (`inToolSandbox`): the conversation's
39
+ * device may still be used by its owner. The task tools read a task's own instance without
40
+ * `inToolSandbox`, so they check here first; errors become the tools' errors.
41
41
  */
42
42
  export declare function recheckDevice(env: TaskEnv, ctx: BuiltinCallContext): Promise<void>;
43
43
  /**
@@ -112,9 +112,9 @@ export async function ownedTask(env, ctx, id) {
112
112
  return task;
113
113
  }
114
114
  /**
115
- * The per-call access re-check of every sandbox tool (`inSandbox`): the conversation's device
116
- * may still be used by its owner. The task tools read a task's own instance without `inSandbox`,
117
- * so they check here first; errors become the tools' errors.
115
+ * The per-call access re-check of every sandbox tool (`inToolSandbox`): the conversation's
116
+ * device may still be used by its owner. The task tools read a task's own instance without
117
+ * `inToolSandbox`, so they check here first; errors become the tools' errors.
118
118
  */
119
119
  export async function recheckDevice(env, ctx) {
120
120
  try {
@@ -185,7 +185,7 @@ export function taskOutputTool(deps) {
185
185
  async run(input, ctx) {
186
186
  const { task_id, block = true, timeout } = input;
187
187
  // another account's run never reads or stops on the owner's device (activated)
188
- assertDeviceOfRunAccount(deps.managedDeviceContextRequired, ctx);
188
+ assertDeviceOfRunAccount(ctx);
189
189
  const env = await taskEnv(deps, ctx);
190
190
  // A sub-agent's agentId is answered, not refused: where its report arrives is the answer
191
191
  // (acceptance 2026-11-13: guidance the model is expected to follow is not a failed call).
@@ -88,7 +88,7 @@ export function taskStopTool(deps) {
88
88
  async run(input, ctx) {
89
89
  const { task_id } = input;
90
90
  // another account's run never reads or stops on the owner's device (activated)
91
- assertDeviceOfRunAccount(deps.managedDeviceContextRequired, ctx);
91
+ assertDeviceOfRunAccount(ctx);
92
92
  const env = await taskEnv(deps, ctx);
93
93
  const task = await ownedTask(env, ctx, task_id);
94
94
  await recheckDevice(env, ctx);
@@ -416,12 +416,12 @@ export async function readProjectSkill(s, root, bare, signal = s.signal) {
416
416
  const dir = `${root}/${PROJECT_SKILLS_DIR}/${bare}`;
417
417
  const path = `${dir}/${SKILL_ENTRY_FILE}`;
418
418
  try {
419
- checkToolPath(path, s);
419
+ checkToolPath(path);
420
420
  }
421
421
  catch (e) {
422
422
  if (!(e instanceof ToolError))
423
423
  throw e;
424
- // only the fixed roots refuse a path, and they bound paths only in sandbox mode (legacy route)
424
+ // only a path whose shape fails (from the recorded root) is refused here
425
425
  throw new ProjectSkillReadError({ kind: "outside_mode", path, mode: "sandbox" });
426
426
  }
427
427
  let read;
@@ -307,7 +307,7 @@ export declare class ConnectorsService {
307
307
  * OAuth the client setup (discovery, dynamic registration or the client credentials token; an
308
308
  * outbound failure -> 502 `connector.connect_failed`). Writes nothing.
309
309
  */
310
- prepareTemplateUpdate(actorAccountId: string, connector: string, input: TemplateUpdateInput): Promise<PreparedTemplateUpdate>;
310
+ prepareTemplateUpdate(actorAccountId: string | null, connector: string, input: TemplateUpdateInput): Promise<PreparedTemplateUpdate>;
311
311
  /**
312
312
  * Applies a prepared template update in the caller's transaction (the caller holds the org row
313
313
  * lock and checked the actor): the endpoint, auth and template version of the connector, the
@@ -317,7 +317,9 @@ export declare class ConnectorsService {
317
317
  * unnamed `derived` tools and the org's own (`admin`) stay (spec §10). Tool definitions are untouched (the next refresh takes the new endpoint through drift review). With `resetCredentials` the credentials are replaced.
318
318
  * Audits `connector.template_applied`. Deleted / missing -> `connector.not_found`.
319
319
  */
320
- applyTemplateIn(orgId: string, connectorId: string, actorAccountId: string, p: PreparedTemplateUpdate, actorTokenId?: string): Promise<void>;
320
+ applyTemplateIn(orgId: string, connectorId: string,
321
+ /** null: the kernel itself (a platform update the bootstrap step runs). */
322
+ actorAccountId: string | null, p: PreparedTemplateUpdate, actorTokenId?: string): Promise<void>;
321
323
  /** Refuses a loaded kind whose extension is not enabled in the org (the same notion as {@link kinds}). */
322
324
  private assertKindAvailable;
323
325
  /**
@@ -313,7 +313,12 @@ let ConnectorsService = class ConnectorsService {
313
313
  return { slug, endpoint };
314
314
  if (auth.type === "none")
315
315
  throw fail("credential", "Auth type none takes no credential");
316
- const owner = auth.ownership === "org" ? { kind: "org" } : { kind: "user", accountId: actorAccountId };
316
+ if (auth.ownership !== "org" && actorAccountId === null) {
317
+ throw new Error("a member's credential needs the acting account");
318
+ }
319
+ const owner = auth.ownership === "org"
320
+ ? { kind: "org" }
321
+ : { kind: "user", accountId: actorAccountId };
317
322
  this.credentials.validate(auth, owner, credential);
318
323
  return { slug, endpoint, owner, secret: credential };
319
324
  }
@@ -524,7 +529,12 @@ let ConnectorsService = class ConnectorsService {
524
529
  return out;
525
530
  if (auth.type === "none")
526
531
  throw fail("credential", "Auth type none takes no credential");
527
- const owner = auth.ownership === "org" ? { kind: "org" } : { kind: "user", accountId: actorAccountId };
532
+ if (auth.ownership !== "org" && actorAccountId === null) {
533
+ throw new Error("a member's credential needs the acting account");
534
+ }
535
+ const owner = auth.ownership === "org"
536
+ ? { kind: "org" }
537
+ : { kind: "user", accountId: actorAccountId };
528
538
  this.credentials.validate(auth, owner, credential);
529
539
  return { ...out, owner, secret: credential };
530
540
  }
@@ -542,7 +552,9 @@ let ConnectorsService = class ConnectorsService {
542
552
  * unnamed `derived` tools and the org's own (`admin`) stay (spec §10). Tool definitions are untouched (the next refresh takes the new endpoint through drift review). With `resetCredentials` the credentials are replaced.
543
553
  * Audits `connector.template_applied`. Deleted / missing -> `connector.not_found`.
544
554
  */
545
- async applyTemplateIn(orgId, connectorId, actorAccountId, p, actorTokenId) {
555
+ async applyTemplateIn(orgId, connectorId,
556
+ /** null: the kernel itself (a platform update the bootstrap step runs). */
557
+ actorAccountId, p, actorTokenId) {
546
558
  const t = this.db;
547
559
  const before = await this.row(t, orgId, connectorId, true);
548
560
  const { input } = p;
@@ -418,8 +418,6 @@ export declare class ToolPipeline {
418
418
  devices?: Pick<ConversationDevices, "reviewFacts">, permissionAuthority?: SandboxOperationAuthority | undefined, permissionGrants?: PermissionCallGrants | undefined,
419
419
  /** Full access auto-grants, recorded exactly once (absent in hand-built pipelines). */
420
420
  autoGrants?: PermissionAutoGrants | undefined, permissionLocks?: PermissionAuthorityLock | undefined,
421
- /** The paired activation gate: on, the managed builtins take the permission review. */
422
- activation?: boolean,
423
421
  /** Starts a cloud device before its first managed call is reviewed (absent: never). */
424
422
  sandboxes?: Pick<SandboxService, "ensureRunning" | "hostRefusal"> | undefined,
425
423
  /**