@capybara-hq/kernel 0.1.0-rc.74 → 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 (94) hide show
  1. package/bootstrap.json +3 -3
  2. package/dist/agents/readiness.controller.d.ts +4 -3
  3. package/dist/agents/readiness.controller.js +4 -3
  4. package/dist/agents/readiness.service.d.ts +44 -11
  5. package/dist/agents/readiness.service.js +59 -16
  6. package/dist/catalog/catalog-import.module.d.ts +1 -1
  7. package/dist/catalog/catalog-import.module.js +1 -1
  8. package/dist/catalog/cli.d.ts +9 -2
  9. package/dist/catalog/cli.js +10 -4
  10. package/dist/catalog/marketplaces.service.d.ts +1 -1
  11. package/dist/catalog/plugin-upgrade.d.ts +4 -2
  12. package/dist/catalog/plugin-upgrade.js +9 -3
  13. package/dist/db/kernel-schema.d.ts +5 -0
  14. package/dist/devices/device-projects.service.d.ts +3 -12
  15. package/dist/devices/device-projects.service.js +20 -63
  16. package/dist/devices/devices.service.d.ts +15 -12
  17. package/dist/devices/devices.service.js +25 -19
  18. package/dist/dial-in/machines.d.ts +3 -15
  19. package/dist/dial-in/machines.js +4 -60
  20. package/dist/extensions/bootstrap.d.ts +17 -3
  21. package/dist/extensions/bootstrap.js +56 -14
  22. package/dist/http/meta.controller.d.ts +0 -1
  23. package/dist/http/meta.controller.js +2 -6
  24. package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
  25. package/dist/lifecycle/kernel-lifecycle.js +16 -11
  26. package/dist/overrides.d.ts +0 -5
  27. package/dist/overrides.js +0 -2
  28. package/dist/platform/file-ref.d.ts +6 -5
  29. package/dist/platform/ops/agent-skills.ops.js +1 -1
  30. package/dist/platform/ops/agents.ops.js +1 -1
  31. package/dist/runtime/model-call.d.ts +2 -2
  32. package/dist/runtime/project/knowledge.d.ts +1 -1
  33. package/dist/runtime/project/knowledge.js +1 -1
  34. package/dist/runtime/project/knowledge.service.d.ts +5 -11
  35. package/dist/runtime/project/knowledge.service.js +12 -23
  36. package/dist/runtime/providers.d.ts +34 -1
  37. package/dist/runtime/providers.js +56 -7
  38. package/dist/runtime/run-steps.d.ts +4 -6
  39. package/dist/runtime/run-steps.js +7 -15
  40. package/dist/runtime/runtime.module.js +1 -1
  41. package/dist/sandbox/device-sandbox.d.ts +16 -2
  42. package/dist/sandbox/device-sandbox.js +13 -5
  43. package/dist/sandbox/held-operations.d.ts +2 -5
  44. package/dist/sandbox/held-operations.js +0 -14
  45. package/dist/sandbox/managed-device-context.d.ts +1 -1
  46. package/dist/sandbox/managed-device-context.js +1 -1
  47. package/dist/sandbox/operation-authority.js +3 -1
  48. package/dist/sandbox/permission-authority-lock.d.ts +6 -0
  49. package/dist/sandbox/permission-authority-lock.js +14 -0
  50. package/dist/sandbox/permission-context-types.d.ts +0 -11
  51. package/dist/sandbox/permission-context-types.js +0 -13
  52. package/dist/sandbox/permission-facts.d.ts +4 -0
  53. package/dist/sandbox/permission-facts.js +6 -1
  54. package/dist/sandbox/providers.d.ts +5 -0
  55. package/dist/sandbox/providers.js +1 -1
  56. package/dist/sandbox/review/permission-candidate.d.ts +12 -7
  57. package/dist/sandbox/review/permission-candidate.js +28 -7
  58. package/dist/sandbox/sandbox-file-reader.d.ts +7 -12
  59. package/dist/sandbox/sandbox-file-reader.js +12 -29
  60. package/dist/sandbox/sandbox.service.d.ts +53 -32
  61. package/dist/sandbox/sandbox.service.js +217 -141
  62. package/dist/sandbox/use-context.d.ts +4 -1
  63. package/dist/setup/setup-guides.service.d.ts +1 -2
  64. package/dist/setup/setup-guides.service.js +1 -4
  65. package/dist/shares/sweep.job.d.ts +2 -0
  66. package/dist/shares/sweep.job.js +3 -1
  67. package/dist/skills/invoke.d.ts +13 -35
  68. package/dist/skills/invoke.js +23 -162
  69. package/dist/tools/builtins/builtin-tools.d.ts +2 -11
  70. package/dist/tools/builtins/builtin-tools.js +5 -23
  71. package/dist/tools/builtins/image/generate.js +2 -2
  72. package/dist/tools/builtins/sandbox/common.d.ts +32 -80
  73. package/dist/tools/builtins/sandbox/common.js +61 -173
  74. package/dist/tools/builtins/sandbox/deliver.js +2 -2
  75. package/dist/tools/builtins/sandbox/device-owner.d.ts +4 -5
  76. package/dist/tools/builtins/sandbox/device-owner.js +5 -6
  77. package/dist/tools/builtins/sandbox/fetch-attachment.js +2 -2
  78. package/dist/tools/builtins/sandbox/glob.js +1 -1
  79. package/dist/tools/builtins/sandbox/grep.js +1 -1
  80. package/dist/tools/builtins/sandbox/index.d.ts +2 -2
  81. package/dist/tools/builtins/sandbox/index.js +2 -2
  82. package/dist/tools/builtins/sandbox/read.js +1 -1
  83. package/dist/tools/builtins/sandbox/task-output.d.ts +3 -3
  84. package/dist/tools/builtins/sandbox/task-output.js +4 -4
  85. package/dist/tools/builtins/sandbox/task-stop.js +1 -1
  86. package/dist/tools/builtins/skill-load.js +2 -2
  87. package/dist/tools/connectors.service.d.ts +4 -2
  88. package/dist/tools/connectors.service.js +15 -3
  89. package/dist/tools/pipeline.d.ts +0 -2
  90. package/dist/tools/pipeline.js +7 -14
  91. package/dist/tools/tools.module.js +1 -1
  92. package/package.json +2 -2
  93. package/src/migrations/0179_device_report_limit_text.sql +28 -0
  94. package/src/migrations/0180_device_instance_abandoned.sql +6 -0
@@ -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
  /**
@@ -43,7 +43,6 @@ import { SandboxOperationAuthority } from "../sandbox/operation-authority.js";
43
43
  import { PermissionAuthorityLock } from "../sandbox/permission-authority-lock.js";
44
44
  import { PermissionAutoGrants } from "../sandbox/permission-auto-grants.js";
45
45
  import { PermissionCallGrants } from "../sandbox/permission-call-grants.js";
46
- import { PERMISSION_CONTEXT_ACTIVATION, permissionContextActive, } from "../sandbox/permission-context-types.js";
47
46
  import { permissionScopeHash } from "../sandbox/permission-facts.js";
48
47
  import { isSessionGrantableRule, } from "../sandbox/review/index.js";
49
48
  import { approverForCrossing, buildPermissionCandidate, crossingOfCandidate, ESCALATION_RETRY_HINT, ESCALATION_UNATTENDED_WHY, escalationRefusedText, isEscalatedCall, } from "../sandbox/review/permission-candidate.js";
@@ -262,7 +261,7 @@ const FAIL_CLOSED_CODES = new Set([
262
261
  ]);
263
262
  /** What the model gets when the permission check of its call refused (fail closed). */
264
263
  export const permissionCheckFailedText = (why) => `The permission check for this call could not be completed (${why.replace(/\.$/, "")}), so it did not run. Retry the call once; if it fails again, ask the user to check the conversation's permission profile or to approve the call again.`;
265
- /** The builtins whose device entry is the managed operation route once activated. */
264
+ /** The builtins whose device entry is the managed operation route. */
266
265
  const MANAGED_OPERATION_TOOLS = new Set([
267
266
  BUILTIN.Bash,
268
267
  BUILTIN.Read,
@@ -499,8 +498,6 @@ let ToolPipeline = class ToolPipeline {
499
498
  devices, permissionAuthority, permissionGrants,
500
499
  /** Full access auto-grants, recorded exactly once (absent in hand-built pipelines). */
501
500
  autoGrants, permissionLocks,
502
- /** The paired activation gate: on, the managed builtins take the permission review. */
503
- activation,
504
501
  /** Starts a cloud device before its first managed call is reviewed (absent: never). */
505
502
  sandboxes,
506
503
  /**
@@ -520,12 +517,10 @@ let ToolPipeline = class ToolPipeline {
520
517
  this.approvalProfile = approvalProfile;
521
518
  this.toolReview = toolReview;
522
519
  this.deps = {
523
- // the builtins that enter a device on the managed operation route once activated (common.ts
520
+ // the builtins that enter a device on the managed operation route (common.ts
524
521
  // `inToolSandbox`, `inSandboxPreparation`): their review is the permission review, whose
525
- // approvals issue the exact call grants admission reads; dormant, none (the command review)
526
- permissionOperations: permissionContextActive(activation)
527
- ? MANAGED_OPERATION_TOOLS
528
- : new Set(),
522
+ // approvals issue the exact call grants admission reads
523
+ permissionOperations: MANAGED_OPERATION_TOOLS,
529
524
  get db() {
530
525
  return kdb.db;
531
526
  },
@@ -2796,12 +2791,10 @@ ToolPipeline = __decorate([
2796
2791
  __param(24, Optional()),
2797
2792
  __param(24, Inject(PermissionAuthorityLock)),
2798
2793
  __param(25, Optional()),
2799
- __param(25, Inject(PERMISSION_CONTEXT_ACTIVATION)),
2794
+ __param(25, Inject(SandboxService)),
2800
2795
  __param(26, Optional()),
2801
- __param(26, Inject(SandboxService)),
2796
+ __param(26, Inject(ConversationApprovalProfile)),
2802
2797
  __param(27, Optional()),
2803
- __param(27, Inject(ConversationApprovalProfile)),
2804
- __param(28, Optional()),
2805
- __param(28, Inject(ToolAskReview))
2798
+ __param(27, Inject(ToolAskReview))
2806
2799
  ], ToolPipeline);
2807
2800
  export { ToolPipeline };
@@ -82,7 +82,7 @@ ToolsModule = __decorate([
82
82
  SubagentsModule,
83
83
  // the builtin sandbox and skill tools run in the conversation's device
84
84
  SandboxModule,
85
- // the managed sandbox route's device context writer (passed only once activated)
85
+ // the managed sandbox route's device context writer
86
86
  ManagedDeviceContextModule,
87
87
  DevicesModule,
88
88
  // network asks read the run tree's network grants
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.74",
3
+ "version": "0.1.0-rc.76",
4
4
  "description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -66,7 +66,7 @@
66
66
  "yaml": "^2.9.1",
67
67
  "yauzl": "3.4.0",
68
68
  "zod": "^4.6.7",
69
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.59"
69
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.61"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@langchain/langgraph-checkpoint-validation": "^1.2.0",
@@ -0,0 +1,28 @@
1
+ -- A device report's limit value became text (`DeviceReportLimit.value` is `{ en, zh? }`, core#663):
2
+ -- a stored report whose limit values are plain strings (written before) no longer passes
3
+ -- `parseDeviceReport`, so its device would show no report and lose its home until the next
4
+ -- refresh. Each string value becomes `{ "en": value }`; the order of the limits and every other
5
+ -- key (`support` included) are kept. Idempotent: a report without string values is not touched.
6
+ UPDATE devices
7
+ SET report = jsonb_set(
8
+ report,
9
+ '{limits}',
10
+ (
11
+ SELECT jsonb_agg(
12
+ CASE
13
+ WHEN jsonb_typeof(l.value -> 'value') = 'string'
14
+ THEN jsonb_set(l.value, '{value}', jsonb_build_object('en', l.value -> 'value'))
15
+ ELSE l.value
16
+ END
17
+ ORDER BY l.ordinality
18
+ )
19
+ FROM jsonb_array_elements(report -> 'limits') WITH ORDINALITY AS l(value, ordinality)
20
+ )
21
+ )
22
+ WHERE report IS NOT NULL
23
+ AND jsonb_typeof(report -> 'limits') = 'array'
24
+ AND EXISTS (
25
+ SELECT 1
26
+ FROM jsonb_array_elements(report -> 'limits') AS s(value)
27
+ WHERE jsonb_typeof(s.value -> 'value') = 'string'
28
+ );
@@ -0,0 +1,6 @@
1
+ -- Issue #675: a device instance whose provider plugin is no longer installed on this deployment
2
+ -- (no extension_installs row, or its catalog item removed) can never be destroyed by the kernel.
3
+ -- Deleting its device marks the row abandoned instead of retrying forever: abandoned_at is when,
4
+ -- and the row keeps the provider-side names (handle, fs_handle, prev_handle) for the super admin.
5
+ -- NULL for every other row. A provider of that name installed again destroys it as before.
6
+ ALTER TABLE device_instances ADD COLUMN IF NOT EXISTS abandoned_at timestamptz;