@capybara-hq/kernel 0.1.0-rc.49 → 0.1.0-rc.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/admin.schemas.d.ts +0 -6
- package/dist/background/launch.d.ts +7 -61
- package/dist/background/launch.js +8 -133
- package/dist/background/poll.job.d.ts +19 -23
- package/dist/background/poll.job.js +30 -66
- package/dist/background/render.d.ts +9 -0
- package/dist/background/render.js +19 -0
- package/dist/background/session.d.ts +3 -66
- package/dist/background/session.js +3 -114
- package/dist/background/stop.d.ts +26 -33
- package/dist/background/stop.js +59 -90
- package/dist/background/store.d.ts +26 -60
- package/dist/background/store.js +23 -108
- package/dist/background/tasks.service.d.ts +9 -29
- package/dist/background/tasks.service.js +18 -115
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/cards.d.ts +3 -0
- package/dist/channels/cards.js +29 -2
- package/dist/channels/phrases.d.ts +35 -0
- package/dist/channels/phrases.js +32 -0
- package/dist/config/load.d.ts +3 -10
- package/dist/config/load.js +26 -21
- package/dist/config/schema.js +3 -3
- package/dist/conversations/events.d.ts +45 -2
- package/dist/conversations/events.js +44 -4
- package/dist/db/kernel-schema.d.ts +9 -4
- package/dist/devices/devices.service.js +1 -1
- package/dist/devices/errors.d.ts +5 -0
- package/dist/devices/errors.js +5 -0
- package/dist/devices/project-rules.d.ts +2 -2
- package/dist/errors.d.ts +9 -11
- package/dist/errors.js +9 -11
- package/dist/identity/settings.d.ts +4 -17
- package/dist/identity/settings.js +9 -32
- package/dist/infra/config/kernel-config.service.js +2 -9
- package/dist/infra/outbox/registry.d.ts +13 -0
- package/dist/infra/outbox/registry.js +8 -0
- package/dist/local-devices/device-auth.controller.d.ts +1 -1
- package/dist/local-devices/device-auth.controller.js +1 -1
- package/dist/local-devices/device-auth.d.ts +4 -3
- package/dist/local-devices/device-auth.js +1 -1
- package/dist/local-devices/device-policy.service.d.ts +6 -6
- package/dist/local-devices/device-routes.d.ts +4 -2
- package/dist/local-devices/device-routes.js +7 -6
- package/dist/local-devices/instance-bindings.d.ts +4 -4
- package/dist/local-devices/instance-bindings.js +2 -2
- package/dist/local-devices/local-device-gateway.d.ts +12 -12
- package/dist/local-devices/local-device-gateway.js +94 -129
- package/dist/local-devices/local-device-provider.d.ts +19 -87
- package/dist/local-devices/local-device-provider.js +43 -158
- package/dist/local-devices/local-devices.module.d.ts +4 -5
- package/dist/local-devices/local-devices.module.js +6 -9
- package/dist/local-devices/machines.d.ts +6 -6
- package/dist/local-devices/machines.js +4 -4
- package/dist/local-devices/owner-report.d.ts +3 -3
- package/dist/local-devices/owner-report.js +4 -4
- package/dist/local-devices/owner-reports.js +2 -2
- package/dist/local-devices/policy-summary.js +2 -2
- package/dist/local-devices/relay.d.ts +12 -25
- package/dist/local-devices/relay.js +17 -31
- package/dist/orgs/settings.controller.d.ts +1 -4
- package/dist/orgs/settings.controller.js +3 -3
- package/dist/orgs/settings.service.d.ts +7 -21
- package/dist/orgs/settings.service.js +16 -40
- package/dist/overrides.d.ts +3 -3
- package/dist/platform/ops/admin.ops.js +6 -8
- package/dist/platform/ops/org-settings.ops.js +4 -4
- package/dist/platform/ops/orgs.ops.js +0 -1
- package/dist/runtime/maintenance.d.ts +1 -1
- package/dist/runtime/maintenance.js +7 -1
- package/dist/runtime/run-steps.js +2 -2
- package/dist/sandbox/held-operations.d.ts +7 -0
- package/dist/sandbox/held-operations.js +25 -1
- package/dist/sandbox/leases.d.ts +6 -3
- package/dist/sandbox/leases.js +16 -10
- package/dist/sandbox/legacy-retirement.d.ts +0 -19
- package/dist/sandbox/legacy-retirement.js +6 -37
- package/dist/sandbox/managed-device-context.d.ts +12 -0
- package/dist/sandbox/managed-device-context.js +49 -1
- package/dist/sandbox/modes.d.ts +9 -8
- package/dist/sandbox/modes.js +4 -15
- package/dist/sandbox/operation-authority-types.d.ts +18 -1
- package/dist/sandbox/operation-authority-types.js +20 -1
- package/dist/sandbox/operation-authority.d.ts +14 -0
- package/dist/sandbox/operation-authority.js +120 -18
- package/dist/sandbox/operation-intents.d.ts +43 -0
- package/dist/sandbox/operation-intents.js +107 -4
- package/dist/sandbox/operation-reconcile.job.d.ts +12 -1
- package/dist/sandbox/operation-reconcile.job.js +53 -6
- package/dist/sandbox/permission-call-grants.d.ts +4 -0
- package/dist/sandbox/permission-call-grants.js +32 -3
- package/dist/sandbox/permission-call-types.d.ts +27 -2
- package/dist/sandbox/permission-ceiling-writes.js +2 -1
- package/dist/sandbox/permission-context-types.d.ts +2 -2
- package/dist/sandbox/permission-context-types.js +2 -2
- package/dist/sandbox/permission-facts.js +10 -2
- package/dist/sandbox/platform-full-access.d.ts +8 -26
- package/dist/sandbox/platform-full-access.js +8 -20
- package/dist/sandbox/review/classifier.d.ts +2 -2
- package/dist/sandbox/review/classifier.js +18 -5
- package/dist/sandbox/review/permission-candidate.d.ts +59 -3
- package/dist/sandbox/review/permission-candidate.js +192 -25
- package/dist/sandbox/review/review.service.d.ts +18 -0
- package/dist/sandbox/review/review.service.js +158 -12
- package/dist/sandbox/sandbox.service.d.ts +71 -47
- package/dist/sandbox/sandbox.service.js +234 -133
- package/dist/tools/approvals.service.d.ts +6 -1
- package/dist/tools/approvals.service.js +10 -0
- package/dist/tools/builtins/builtin-tools.d.ts +1 -4
- package/dist/tools/builtins/builtin-tools.js +13 -18
- package/dist/tools/builtins/sandbox/bash.d.ts +16 -3
- package/dist/tools/builtins/sandbox/bash.js +92 -270
- package/dist/tools/builtins/sandbox/common.d.ts +15 -9
- package/dist/tools/builtins/sandbox/common.js +55 -19
- package/dist/tools/builtins/sandbox/device-owner.d.ts +13 -0
- package/dist/tools/builtins/sandbox/device-owner.js +14 -0
- package/dist/tools/builtins/sandbox/task-list.js +2 -2
- package/dist/tools/builtins/sandbox/task-output.d.ts +14 -57
- package/dist/tools/builtins/sandbox/task-output.js +88 -210
- package/dist/tools/builtins/sandbox/task-stop.d.ts +2 -2
- package/dist/tools/builtins/sandbox/task-stop.js +15 -26
- package/dist/tools/pipeline.d.ts +31 -2
- package/dist/tools/pipeline.js +273 -43
- package/dist/tools/registry.d.ts +7 -0
- package/package.json +4 -4
- package/src/migrations/0162_permission_call_escalation.sql +9 -0
- package/dist/background/status.d.ts +0 -35
- package/dist/background/status.js +0 -57
|
@@ -3,14 +3,15 @@ import { ANONYMOUS_NO_DEVICE, } from "../../../devices/conversation-devices.js";
|
|
|
3
3
|
import { canonicalRoot, workingRootOf } from "../../../devices/working-root.js";
|
|
4
4
|
import { ApiError } from "../../../errors.js";
|
|
5
5
|
import { InstanceBindingError } from "../../../local-devices/instance-bindings.js";
|
|
6
|
-
import { AUTO_MODE_NOT_ALLOWED_TEXT } from "../../../local-devices/local-device-provider.js";
|
|
7
6
|
import { isDeviceRequestNotSent } from "../../../local-devices/relay.js";
|
|
8
7
|
import { devicePathsChange } from "../../../runtime/context/device-paths.js";
|
|
9
8
|
import { ATTACHMENTS_ROOT, attachmentsDir, attachmentsRoot, } from "../../../sandbox/attachments-path.js";
|
|
10
9
|
import { SandboxPathBusyError } from "../../../sandbox/leases.js";
|
|
11
10
|
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";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
11
|
+
import { isEscalationGrantMissing } from "../../../sandbox/operation-authority-types.js";
|
|
12
|
+
import { RetirementPendingError, SandboxLockLostError, } from "../../../sandbox/sandbox.service.js";
|
|
13
|
+
import { providerConnectionFailure, SandboxProviderUnreachableError, } from "../../../sandbox/unreachable.js";
|
|
14
|
+
import { assertDeviceOfRunAccount } from "./device-owner.js";
|
|
14
15
|
// ---- 模型可见文案(英文) ----
|
|
15
16
|
/**
|
|
16
17
|
* This conversation's first use of its device. The working directory is the instance's workspace,
|
|
@@ -268,35 +269,45 @@ function legacyPreparationSession(s) {
|
|
|
268
269
|
};
|
|
269
270
|
}
|
|
270
271
|
/**
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*/
|
|
274
|
-
const AUTO_MODE_TOOL_TEXT = `${AUTO_MODE_NOT_ALLOWED_TEXT} Ask the user to switch it on the machine, or to start a new conversation on another device.`;
|
|
275
|
-
/**
|
|
276
|
-
* Full access refused by policy (B-13: `org.*` / `deployment.*`, old and renamed codes): the
|
|
277
|
-
* organization or the platform has it off. The kernel's own message is never shown.
|
|
272
|
+
* Full access refused by policy (B-13: `org.*` / `deployment.*`): the organization or the
|
|
273
|
+
* platform has it off. The kernel's own message is never shown.
|
|
278
274
|
*/
|
|
279
275
|
export const FULL_ACCESS_OFF_BY_POLICY_TOOL_TEXT = "Full access is turned off by your organization's or the platform's policy, so nothing ran. Continue with the Request approval or Approve for me permission profile, or ask an org admin (or a super admin) to allow Full access.";
|
|
280
276
|
/**
|
|
281
277
|
* The device's owner ceiling does not allow Full access (`device.full_access_not_allowed`).
|
|
282
278
|
*/
|
|
283
279
|
export const FULL_ACCESS_CEILING_TOOL_TEXT = "This device's owner ceiling does not allow Full access, so nothing ran. Ask the device's owner to raise it with `capybara-device ceiling set` on that machine, or continue with the Request approval or Approve for me permission profile.";
|
|
284
|
-
/**
|
|
285
|
-
* The full-access refusal codes off by policy: the renamed ones (W5-P3b) and the old organization
|
|
286
|
-
* and platform names until that rename lands; `device.auto_mode_not_allowed` keeps its machine
|
|
287
|
-
* text ({@link AUTO_MODE_TOOL_TEXT}).
|
|
288
|
-
*/
|
|
280
|
+
/** The full-access refusal codes off by policy (organization and platform). */
|
|
289
281
|
const FULL_ACCESS_OFF_BY_POLICY_CODES = new Set([
|
|
290
282
|
"org.full_access_not_allowed",
|
|
291
283
|
"deployment.full_access_not_allowed",
|
|
292
|
-
"org.auto_mode_not_allowed",
|
|
293
|
-
"deployment.auto_mode_not_allowed",
|
|
294
284
|
]);
|
|
285
|
+
/**
|
|
286
|
+
* The legacy retirement gate's refusals (`RetirementPendingError`, permission runtime cutover
|
|
287
|
+
* 8.5): the device's earlier instance may still run background work an earlier version started.
|
|
288
|
+
* Each says what clears it; the generic `device.unavailable` text would name an inactive provider.
|
|
289
|
+
*/
|
|
290
|
+
export const RETIREMENT_PENDING_TOOL_TEXT = "This device is unavailable: background work started by an earlier version may still run on its previous instance, which has not been confirmed destroyed yet, so nothing ran. Retry later (a cloud device becomes usable once its provider confirms the old instance destroyed), continue without the device, or ask the user to start a new conversation on another device.";
|
|
291
|
+
export const RETIREMENT_RESTART_TOOL_TEXT = "Background work started by an earlier version may still be running on this device's computer, so nothing ran. Ask the user to restart that computer to finish the upgrade, then retry; or continue without the device.";
|
|
292
|
+
export const RETIREMENT_RECREATE_TOOL_TEXT = "Background work started by an earlier version may still be running on an earlier instance of this device, which can no longer be verified as destroyed, so nothing ran. Ask the device's owner to delete the device and create it again, or ask the user to start a new conversation on another device.";
|
|
293
|
+
export const RETIREMENT_REPLACE_TOOL_TEXT = "Background work started by an earlier version may still be running on this device's computer, which cannot prove a restart, so nothing ran. Ask the device's owner to delete the device and connect the computer again as a new device, or ask the user to start a new conversation on another device.";
|
|
294
|
+
/** The model-facing text of a retirement refusal's code (`device.unavailable` for any other). */
|
|
295
|
+
function retirementToolText(code) {
|
|
296
|
+
if (code === "device.restart_required")
|
|
297
|
+
return RETIREMENT_RESTART_TOOL_TEXT;
|
|
298
|
+
if (code === "device.recreate_required")
|
|
299
|
+
return RETIREMENT_RECREATE_TOOL_TEXT;
|
|
300
|
+
if (code === "device.replace_required")
|
|
301
|
+
return RETIREMENT_REPLACE_TOOL_TEXT;
|
|
302
|
+
return RETIREMENT_PENDING_TOOL_TEXT;
|
|
303
|
+
}
|
|
295
304
|
/**
|
|
296
305
|
* A managed operation outside the admitted scope (`SandboxScopeDeniedError`): fixed text, never
|
|
297
306
|
* the refusal's own message (a provider may write it).
|
|
298
307
|
*/
|
|
299
308
|
export const SCOPE_DENIED_TOOL_TEXT = "This operation reaches outside what this conversation's permission profile allows on the device (a path outside the directories it may read or write, or a host it may not reach), so it did not run. Keep the call inside the working directory and the directories already granted, or ask the user to grant the directory or choose a broader permission profile, then retry.";
|
|
309
|
+
/** An approved sandbox escalation whose grant no longer matches at admission (nothing ran). */
|
|
310
|
+
export const ESCALATION_GRANT_MISSING_TEXT = 'This Bash call was approved to run outside the sandbox, but the approval no longer matches: the device, its Full access ceiling or this conversation\'s permission scope changed since it was approved, so it did not run. Call Bash again with sandbox: "escalated" and a justification to ask again, or call it without sandbox to run it inside the sandbox.';
|
|
300
311
|
/** A staged request the machine never got: it reconnected before the request was sent. */
|
|
301
312
|
export const DEVICE_REQUEST_NOT_SENT_TOOL_TEXT = "The device's machine reconnected before this operation was sent, so nothing ran. Retry the tool call.";
|
|
302
313
|
/** The device cannot enforce the conversation's profile (`SandboxPermissionUnsupportedError`). */
|
|
@@ -312,6 +323,14 @@ export const OUTCOME_UNKNOWN_TOOL_TEXT = "The device may or may not have run thi
|
|
|
312
323
|
*/
|
|
313
324
|
const RECONCILE_REQUIRED_TEXT = "This device's sandbox limits must be established again before it runs anything, so nothing ran. Ask the person to reset the device's files on the devices page, then retry, or to start a new conversation on another device.";
|
|
314
325
|
const INSTANCE_BINDING_TEXT = "The device's machine has not confirmed its current instance, so nothing ran. Ask the person to restart capybara-device on that machine (updating it if it is outdated), then retry, or to start a new conversation on another device.";
|
|
326
|
+
/** The provider connection failure behind an unknown outcome, with the raw error to log. */
|
|
327
|
+
function unreachableCause(cause) {
|
|
328
|
+
if (cause instanceof SandboxProviderUnreachableError)
|
|
329
|
+
return { failure: cause.failure, err: cause.cause };
|
|
330
|
+
const failure = providerConnectionFailure(cause);
|
|
331
|
+
return failure ? { failure, err: cause } : undefined;
|
|
332
|
+
}
|
|
333
|
+
export { DEVICE_OF_ANOTHER_ACCOUNT_TEXT } from "./device-owner.js";
|
|
315
334
|
export function mapSandboxError(e, log) {
|
|
316
335
|
if (e instanceof ManagedDeviceContextStale)
|
|
317
336
|
return new ToolError(MANAGED_DEVICE_CONTEXT_STALE_TEXT, { kind: "unavailable" });
|
|
@@ -321,12 +340,26 @@ export function mapSandboxError(e, log) {
|
|
|
321
340
|
return new ToolError(MANAGED_DEVICE_CONTEXT_FAILED_TEXT, { kind: "unavailable" });
|
|
322
341
|
// the managed route's typed refusals (unknown first: it never proves the operation had no effect)
|
|
323
342
|
if (isSandboxOperationOutcomeUnknownError(e)) {
|
|
343
|
+
// the provider could not be reached after the durable dispatch: the ledger keeps the outcome
|
|
344
|
+
// unknown, the model gets the actionable connection text (a connection never made did
|
|
345
|
+
// nothing; a broken one may have acted)
|
|
346
|
+
const unreachable = unreachableCause(e.cause);
|
|
347
|
+
if (unreachable) {
|
|
348
|
+
log?.warn("sandbox provider unreachable", { ...unreachable, outcome: "unknown" });
|
|
349
|
+
if (unreachable.failure === "connect")
|
|
350
|
+
return new ToolError(SANDBOX_UNREACHABLE_TEXT, { kind: "unavailable" });
|
|
351
|
+
return new ToolError(SANDBOX_CONNECTION_DROPPED_TEXT, { kind: "unavailable" });
|
|
352
|
+
}
|
|
324
353
|
log?.warn("sandbox operation outcome unknown", { err: e });
|
|
325
354
|
return new ToolError(OUTCOME_UNKNOWN_TOOL_TEXT, { kind: "unavailable" });
|
|
326
355
|
}
|
|
327
356
|
// kernel-typed, before the scope refusal it extends: nothing was sent, a retry is safe
|
|
328
357
|
if (isDeviceRequestNotSent(e))
|
|
329
358
|
return new ToolError(DEVICE_REQUEST_NOT_SENT_TOOL_TEXT, { kind: "unavailable" });
|
|
359
|
+
if (isEscalationGrantMissing(e)) {
|
|
360
|
+
log?.warn("sandbox escalation grant no longer matches", { err: e });
|
|
361
|
+
return new ToolError(ESCALATION_GRANT_MISSING_TEXT);
|
|
362
|
+
}
|
|
330
363
|
if (isSandboxScopeDeniedError(e)) {
|
|
331
364
|
log?.warn("sandbox operation outside its scope", { err: e });
|
|
332
365
|
return new ToolError(SCOPE_DENIED_TOOL_TEXT);
|
|
@@ -342,6 +375,9 @@ export function mapSandboxError(e, log) {
|
|
|
342
375
|
}
|
|
343
376
|
return new ToolError(SANDBOX_CONNECTION_DROPPED_TEXT, { kind: "unavailable" });
|
|
344
377
|
}
|
|
378
|
+
if (e instanceof RetirementPendingError) {
|
|
379
|
+
return new ToolError(retirementToolText(e.code));
|
|
380
|
+
}
|
|
345
381
|
if (e instanceof ApiError) {
|
|
346
382
|
if (e.code === "sandbox.busy")
|
|
347
383
|
return new ToolError(BUSY_TEXT);
|
|
@@ -370,8 +406,6 @@ export function mapSandboxError(e, log) {
|
|
|
370
406
|
return new ToolError(DEVICE_OFFLINE_TEXT);
|
|
371
407
|
if (e.code === "device.program_outdated")
|
|
372
408
|
return new ToolError(DEVICE_OUTDATED_TEXT);
|
|
373
|
-
if (e.code === "device.auto_mode_not_allowed")
|
|
374
|
-
return new ToolError(AUTO_MODE_TOOL_TEXT);
|
|
375
409
|
if (e.code === "device.full_access_not_allowed")
|
|
376
410
|
return new ToolError(FULL_ACCESS_CEILING_TOOL_TEXT);
|
|
377
411
|
if (FULL_ACCESS_OFF_BY_POLICY_CODES.has(e.code))
|
|
@@ -450,6 +484,8 @@ export async function inSandboxOperationPreparation(deps, ctx, purpose, roots, f
|
|
|
450
484
|
});
|
|
451
485
|
}
|
|
452
486
|
async function inSandboxWith(deps, ctx, fn, operations, stage) {
|
|
487
|
+
// a run another account triggered never uses the owner's device (activated): refused first
|
|
488
|
+
assertDeviceOfRunAccount(deps.managedDeviceContextRequired, ctx);
|
|
453
489
|
try {
|
|
454
490
|
// once activated, only the managed route runs: a legacy route refuses before entering, so v1
|
|
455
491
|
// permission context never sits next to old-mode device_paths; a managed route never runs
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** What a run another account triggered gets from every device entry. */
|
|
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
|
+
/**
|
|
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).
|
|
9
|
+
*/
|
|
10
|
+
export declare function assertDeviceOfRunAccount(active: boolean | undefined, ctx: {
|
|
11
|
+
accountId: string;
|
|
12
|
+
ownerAccountId?: string | undefined;
|
|
13
|
+
}): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ToolError } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
/** What a run another account triggered gets from every device entry. */
|
|
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
|
+
/**
|
|
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).
|
|
10
|
+
*/
|
|
11
|
+
export function assertDeviceOfRunAccount(active, ctx) {
|
|
12
|
+
if (active && ctx.ownerAccountId !== undefined && ctx.ownerAccountId !== ctx.accountId)
|
|
13
|
+
throw new ToolError(DEVICE_OF_ANOTHER_ACCOUNT_TEXT);
|
|
14
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { formatElapsed,
|
|
1
|
+
import { formatElapsed, taskReasonText } from "../../../background/render.js";
|
|
2
2
|
import { isManagedTask } from "../../../background/store.js";
|
|
3
3
|
import { clip, display, sandboxBaseTimeoutMs, unavailableWhenNoSandbox, } from "./common.js";
|
|
4
4
|
import { outputFile, taskEnv } from "./task-output.js";
|
|
@@ -38,7 +38,7 @@ function taskState(task, now) {
|
|
|
38
38
|
}
|
|
39
39
|
let s = task.status;
|
|
40
40
|
if (task.lostReason !== null)
|
|
41
|
-
s += ` (${
|
|
41
|
+
s += ` (${taskReasonText(task)})`;
|
|
42
42
|
if (task.exitCode !== null)
|
|
43
43
|
s += `, exit code ${task.exitCode}`;
|
|
44
44
|
return `${s}, after ${elapsed}`;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { type SandboxHandle } from "@capybara-hq/plugin-sdk";
|
|
2
1
|
import { type BackgroundTaskRow } from "../../../background/store.js";
|
|
3
|
-
import
|
|
2
|
+
import { type IfRunningResult, type SandboxService } from "../../../sandbox/sandbox.service.js";
|
|
4
3
|
import type { BuiltinCallContext, BuiltinTool } from "../../registry.js";
|
|
5
4
|
import { type SandboxToolDeps } from "./common.js";
|
|
6
5
|
/** How long `TaskOutput` waits with `block` when `timeout` is not given (ms). */
|
|
7
6
|
export declare const TASK_OUTPUT_DEFAULT_TIMEOUT_MS = 30000;
|
|
8
7
|
/** The longest `TaskOutput` wait (ms). */
|
|
9
8
|
export declare const TASK_OUTPUT_MAX_TIMEOUT_MS = 600000;
|
|
10
|
-
/** How often a blocking `TaskOutput` checks the task (each check
|
|
9
|
+
/** How often a blocking `TaskOutput` checks the task (each check an exact status read). */
|
|
11
10
|
export declare const TASK_CHECK_INTERVAL_MS = 2000;
|
|
12
11
|
/** What `TaskOutput` and `TaskStop` work with. */
|
|
13
12
|
export interface TaskEnv {
|
|
@@ -41,12 +40,6 @@ export declare function ownedTask(env: TaskEnv, ctx: BuiltinCallContext, id: str
|
|
|
41
40
|
* so they check here first; errors become the tools' errors.
|
|
42
41
|
*/
|
|
43
42
|
export declare function recheckDevice(env: TaskEnv, ctx: BuiltinCallContext): Promise<void>;
|
|
44
|
-
/**
|
|
45
|
-
* `ifRunning` on the task's own device instance (its execs act for the task's trigger in its
|
|
46
|
-
* conversation); sandbox errors become the tools' errors. A task from before devices has no
|
|
47
|
-
* instance (`not_running`).
|
|
48
|
-
*/
|
|
49
|
-
export declare function onTaskInstance<T>(env: TaskEnv, task: BackgroundTaskRow, fn: (p: HeldProvider, h: SandboxHandle, signal: AbortSignal) => Promise<T>, signal: AbortSignal): Promise<IfRunningResult<T>>;
|
|
50
43
|
/**
|
|
51
44
|
* The task's status line: `Status: running (2m05s)`, `Status: failed, exit code 3, after 4m12s`,
|
|
52
45
|
* `Status: stopped after 1m00s`, `Status: lost (the sandbox was suspended) after 3s`.
|
|
@@ -56,55 +49,19 @@ export declare function statusLine(task: BackgroundTaskRow, now?: Date): string;
|
|
|
56
49
|
export declare const outputFile: (task: BackgroundTaskRow) => string;
|
|
57
50
|
/** Why the output cannot be read: the task's sandbox instance is not running. */
|
|
58
51
|
export declare function unavailableText(task: BackgroundTaskRow, r: IfRunningResult<unknown>): string;
|
|
59
|
-
/**
|
|
60
|
-
* The exec that checks and reads task `t` (relative to the workspace root): for a running task first
|
|
61
|
-
* its status line (the poller's, {@link pollScript}: liveness, then the exit file), then
|
|
62
|
-
* `size <bytes>` and `out <base64>`, at most `cap` bytes of the output from byte `offset` on.
|
|
63
|
-
* The file is never read whole: `tail -c +<offset+1> | head -c <cap>`. Without `read` only the
|
|
64
|
-
* status line.
|
|
65
|
-
*/
|
|
66
|
-
export declare function taskReadScript(t: {
|
|
67
|
-
id: string;
|
|
68
|
-
sid: string | null;
|
|
69
|
-
running: boolean;
|
|
70
|
-
}, offset: number, cap: number, read?: boolean): string;
|
|
71
|
-
/**
|
|
72
|
-
* How many bytes before the read offset a `TaskOutput` read also reads again, so a prompt split
|
|
73
|
-
* across reads still matches: `gh auth login --web` prints its one-time code and its URL line
|
|
74
|
-
* separately, and a read that lands between them (or a read cap that splits them) otherwise sees
|
|
75
|
-
* only one half, and no later read sees both. The tail only ever holds this many already-delivered
|
|
76
|
-
* bytes, whatever the task's output size: a read's buffer stays bounded.
|
|
77
|
-
*/
|
|
78
|
-
export declare const READ_TAIL_BYTES = 4096;
|
|
79
|
-
/** The byte window one `TaskOutput` read covers. */
|
|
80
|
-
export interface ReadWindow {
|
|
81
|
-
/** Where the read exec starts (the output offset minus at most {@link READ_TAIL_BYTES}). */
|
|
82
|
-
offset: number;
|
|
83
|
-
/** How many bytes the exec reads from there. */
|
|
84
|
-
cap: number;
|
|
85
|
-
/** How many of the returned bytes were already delivered by earlier reads. */
|
|
86
|
-
skip: number;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* The window of a read at `offset` (the output bytes already delivered) with `cap` new bytes: it
|
|
90
|
-
* starts up to {@link READ_TAIL_BYTES} earlier, and the first `skip` bytes of what it returns were
|
|
91
|
-
* delivered already, so the parser can match a pattern spanning the boundary. Bounded: the window
|
|
92
|
-
* is `cap + READ_TAIL_BYTES` bytes at most, never more as the output grows.
|
|
93
|
-
*/
|
|
94
|
-
export declare function readWindow(offset: number, cap: number): ReadWindow;
|
|
95
|
-
/**
|
|
96
|
-
* The bytes of `buf` up to its last whole UTF-8 character: a character cut by the read's cap is
|
|
97
|
-
* left for the next read.
|
|
98
|
-
*/
|
|
99
|
-
export declare function wholeUtf8Length(buf: Uint8Array): number;
|
|
100
52
|
/**
|
|
101
53
|
* Built-in `TaskOutput` (spec 2026-11-05-background-bash-design §2.2): a task's status and the
|
|
102
|
-
* output since this conversation's last read of it
|
|
103
|
-
* `SandboxService.ifRunning` on the task's own
|
|
104
|
-
* sandbox, so a suspended or rebuilt one means the task is lost (its output
|
|
105
|
-
* `block`, checks every {@link TASK_CHECK_INTERVAL_MS}, each under a lease of
|
|
106
|
-
* task ends or the wait (at most `timeout` and the run's time left) is over
|
|
107
|
-
*
|
|
108
|
-
*
|
|
54
|
+
* output since this conversation's last read of it, by the task's exact ref only (no exec, no
|
|
55
|
+
* path) through `SandboxService.ifRunning` on the task's own instance: it never creates or
|
|
56
|
+
* resumes a sandbox, so a suspended or rebuilt one means the task is lost (its output
|
|
57
|
+
* unavailable). With `block`, checks every {@link TASK_CHECK_INTERVAL_MS}, each under a lease of
|
|
58
|
+
* its own, until the task ends or the wait (at most `timeout` and the run's time left) is over.
|
|
59
|
+
* The output read is capped at `tools.outputSpillChars` bytes; the pipeline spills the result
|
|
60
|
+
* beyond that. A legacy (SID) task is never read live ({@link legacyTaskOutput}).
|
|
109
61
|
*/
|
|
110
62
|
export declare function taskOutputTool(deps: SandboxToolDeps): BuiltinTool;
|
|
63
|
+
/**
|
|
64
|
+
* The retirement gate's refusal as the tool's error (the generic `device.unavailable` text would
|
|
65
|
+
* name an inactive provider); anything else mapped as usual.
|
|
66
|
+
*/
|
|
67
|
+
export declare function retirementRefusal(e: unknown, env: Pick<TaskEnv, "log">): unknown;
|