@capybara-hq/kernel 0.1.0-rc.40 → 0.1.0-rc.42
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 +10 -1
- package/dist/admin/admin.schemas.d.ts +6 -0
- package/dist/admin/org-network.service.d.ts +3 -1
- package/dist/admin/org-network.service.js +10 -2
- package/dist/app.d.ts +4 -0
- package/dist/app.js +2 -0
- package/dist/background/finish.d.ts +9 -1
- package/dist/background/finish.js +57 -4
- package/dist/background/launch.d.ts +23 -0
- package/dist/background/launch.js +55 -1
- package/dist/background/managed-output.d.ts +110 -0
- package/dist/background/managed-output.js +219 -0
- package/dist/background/managed.d.ts +52 -0
- package/dist/background/managed.js +128 -0
- package/dist/background/poll.job.d.ts +35 -1
- package/dist/background/poll.job.js +174 -9
- package/dist/background/render.js +1 -0
- package/dist/background/retire-legacy-tasks.job.d.ts +57 -0
- package/dist/background/retire-legacy-tasks.job.js +149 -0
- package/dist/background/session.d.ts +15 -5
- package/dist/background/session.js +22 -6
- package/dist/background/stop.d.ts +35 -5
- package/dist/background/stop.js +94 -8
- package/dist/background/store.d.ts +110 -3
- package/dist/background/store.js +205 -3
- package/dist/background/tasks.service.d.ts +18 -1
- package/dist/background/tasks.service.js +99 -9
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/cards.js +1 -1
- package/dist/channels/inbound.js +2 -0
- package/dist/channels/phrases.d.ts +4 -0
- package/dist/channels/phrases.js +4 -0
- package/dist/config/load.d.ts +18 -0
- package/dist/config/load.js +39 -1
- package/dist/config/permission-migration.d.ts +26 -0
- package/dist/config/permission-migration.js +64 -0
- package/dist/config/schema.d.ts +1 -1
- package/dist/config/schema.js +11 -10
- package/dist/conversations/conversations.controller.d.ts +1 -1
- package/dist/conversations/conversations.controller.js +1 -1
- package/dist/conversations/conversations.module.js +12 -0
- package/dist/conversations/conversations.service.d.ts +11 -2
- package/dist/conversations/conversations.service.js +97 -27
- package/dist/conversations/event-log.d.ts +1 -1
- package/dist/conversations/event-log.js +10 -2
- package/dist/conversations/events.d.ts +304 -4
- package/dist/conversations/events.js +279 -29
- package/dist/conversations/permission-profile-store.d.ts +50 -0
- package/dist/conversations/permission-profile-store.js +67 -0
- package/dist/conversations/permission-profile-store.module.d.ts +2 -0
- package/dist/conversations/permission-profile-store.module.js +19 -0
- package/dist/conversations/permission-profiles.controller.d.ts +84 -0
- package/dist/conversations/permission-profiles.controller.js +105 -0
- package/dist/conversations/permission-profiles.schemas.d.ts +31 -0
- package/dist/conversations/permission-profiles.schemas.js +23 -0
- package/dist/conversations/permission-profiles.service.d.ts +56 -0
- package/dist/conversations/permission-profiles.service.js +179 -0
- package/dist/db/kernel-schema.d.ts +238 -3
- package/dist/devices/access.js +1 -1
- package/dist/devices/access.module.d.ts +2 -0
- package/dist/devices/access.module.js +19 -0
- package/dist/devices/conversation-devices.d.ts +8 -29
- package/dist/devices/conversation-devices.js +37 -73
- package/dist/devices/device-projects.service.d.ts +26 -28
- package/dist/devices/device-projects.service.js +123 -127
- package/dist/devices/devices.controller.js +3 -1
- package/dist/devices/devices.module.js +11 -9
- package/dist/devices/devices.service.d.ts +116 -8
- package/dist/devices/devices.service.js +252 -20
- package/dist/devices/dto.d.ts +16 -0
- package/dist/devices/dto.js +34 -6
- package/dist/devices/errors.d.ts +8 -0
- package/dist/devices/errors.js +10 -0
- package/dist/devices/project-rules.d.ts +44 -0
- package/dist/devices/project-rules.js +27 -0
- package/dist/devices/working-root.d.ts +6 -0
- package/dist/devices/working-root.js +12 -1
- package/dist/errors.d.ts +31 -0
- package/dist/errors.js +31 -0
- package/dist/evals/reconstruct.d.ts +19 -2
- package/dist/evals/reconstruct.js +40 -2
- package/dist/evals/recorded-permission-context.d.ts +77 -0
- package/dist/evals/recorded-permission-context.js +151 -0
- package/dist/evals/recorded-tools.d.ts +10 -1
- package/dist/evals/recorded-tools.js +27 -3
- package/dist/evals/run-replay.d.ts +8 -2
- package/dist/evals/run-replay.js +18 -2
- package/dist/evals/trajectory.d.ts +1 -1
- package/dist/evals/worker.d.ts +10 -1
- package/dist/evals/worker.js +23 -14
- package/dist/http/api.module.js +2 -0
- package/dist/identity/accounts.d.ts +14 -1
- package/dist/identity/accounts.js +61 -5
- package/dist/identity/identity.module.js +2 -0
- package/dist/identity/settings.d.ts +28 -12
- package/dist/identity/settings.js +89 -33
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/infra/cli/kernel-cli.module.d.ts +2 -2
- package/dist/infra/cli/kernel-cli.module.js +5 -2
- package/dist/infra/cli/permission-cutover.d.ts +59 -0
- package/dist/infra/cli/permission-cutover.js +107 -0
- package/dist/infra/config/kernel-config.service.d.ts +2 -2
- package/dist/infra/config/kernel-config.service.js +31 -11
- package/dist/infra/database/startup-activation-transaction.d.ts +36 -0
- package/dist/infra/database/startup-activation-transaction.js +242 -0
- package/dist/infra/database/transaction-host.d.ts +47 -0
- package/dist/infra/database/transaction-host.js +119 -0
- package/dist/infra/database/xact-lock.d.ts +1 -0
- package/dist/infra/database/xact-lock.js +6 -0
- package/dist/infra/outbox/registry.d.ts +39 -0
- package/dist/infra/outbox/registry.js +18 -0
- package/dist/kernel.module.js +2 -0
- package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +55 -28
- package/dist/local-devices/device-auth.js +1 -1
- package/dist/local-devices/device-policy.service.d.ts +35 -5
- package/dist/local-devices/device-policy.service.js +188 -13
- package/dist/local-devices/instance-bindings.d.ts +82 -0
- package/dist/local-devices/instance-bindings.js +304 -0
- package/dist/local-devices/keys.d.ts +5 -0
- package/dist/local-devices/keys.js +5 -0
- package/dist/local-devices/local-device-gateway.d.ts +19 -4
- package/dist/local-devices/local-device-gateway.js +185 -17
- package/dist/local-devices/local-device-provider.d.ts +42 -7
- package/dist/local-devices/local-device-provider.js +185 -10
- package/dist/local-devices/local-devices.module.d.ts +17 -2
- package/dist/local-devices/local-devices.module.js +49 -8
- package/dist/local-devices/machines.d.ts +35 -12
- package/dist/local-devices/machines.js +203 -8
- package/dist/local-devices/network-grants.js +3 -3
- package/dist/local-devices/network-grants.module.d.ts +2 -0
- package/dist/local-devices/network-grants.module.js +14 -0
- package/dist/local-devices/owner-report.d.ts +79 -0
- package/dist/local-devices/owner-report.js +155 -0
- package/dist/local-devices/owner-reports.d.ts +48 -0
- package/dist/local-devices/owner-reports.js +190 -0
- package/dist/local-devices/policy-summary.d.ts +24 -1
- package/dist/local-devices/policy-summary.js +48 -0
- package/dist/local-devices/relay.d.ts +82 -6
- package/dist/local-devices/relay.js +187 -16
- package/dist/local-devices/targets.d.ts +16 -1
- package/dist/local-devices/targets.js +35 -2
- package/dist/orgs/cloud-network-setting.d.ts +33 -0
- package/dist/orgs/cloud-network-setting.js +47 -0
- package/dist/orgs/offboarding.d.ts +3 -1
- package/dist/orgs/offboarding.js +8 -2
- package/dist/orgs/org-lock.d.ts +10 -4
- package/dist/orgs/org-lock.js +10 -4
- package/dist/orgs/orgs.service.d.ts +3 -1
- package/dist/orgs/orgs.service.js +8 -2
- package/dist/orgs/settings.controller.d.ts +4 -1
- package/dist/orgs/settings.controller.js +3 -3
- package/dist/orgs/settings.service.d.ts +48 -56
- package/dist/orgs/settings.service.js +144 -101
- package/dist/overrides.d.ts +6 -1
- package/dist/overrides.js +2 -0
- package/dist/platform/exclusions.js +20 -0
- package/dist/platform/ops/admin.ops.js +14 -11
- package/dist/platform/ops/agent-skills.ops.js +2 -0
- package/dist/platform/ops/devices.ops.js +10 -2
- package/dist/platform/ops/org-settings.ops.js +6 -6
- package/dist/platform/ops/orgs.ops.js +1 -0
- package/dist/roles/worker.module.js +4 -0
- package/dist/runtime/context/build.d.ts +3 -1
- package/dist/runtime/context/build.js +19 -3
- package/dist/runtime/context/compaction.js +5 -0
- package/dist/runtime/context/device-paths.d.ts +9 -2
- package/dist/runtime/context/device-paths.js +20 -0
- package/dist/runtime/context/permission-profile.d.ts +46 -0
- package/dist/runtime/context/permission-profile.js +194 -0
- package/dist/runtime/maintenance.d.ts +7 -1
- package/dist/runtime/maintenance.js +43 -15
- package/dist/runtime/model-call.d.ts +32 -0
- package/dist/runtime/model-call.js +67 -0
- package/dist/runtime/permission-context-errors.d.ts +39 -0
- package/dist/runtime/permission-context-errors.js +67 -0
- package/dist/runtime/permission-context.service.d.ts +60 -0
- package/dist/runtime/permission-context.service.js +286 -0
- package/dist/runtime/project/knowledge.d.ts +7 -2
- package/dist/runtime/project/knowledge.js +5 -2
- package/dist/runtime/project/knowledge.service.d.ts +17 -2
- package/dist/runtime/project/knowledge.service.js +76 -12
- package/dist/runtime/run-execution.d.ts +4 -1
- package/dist/runtime/run-execution.js +14 -5
- package/dist/runtime/run-steps.d.ts +11 -3
- package/dist/runtime/run-steps.js +27 -4
- package/dist/runtime/runtime.module.js +11 -0
- package/dist/sandbox/attachments-path.d.ts +15 -0
- package/dist/sandbox/attachments-path.js +15 -0
- package/dist/sandbox/cloud-permission-snapshot.d.ts +159 -0
- package/dist/sandbox/cloud-permission-snapshot.js +407 -0
- package/dist/sandbox/cloud-permission-snapshot.module.d.ts +8 -0
- package/dist/sandbox/cloud-permission-snapshot.module.js +34 -0
- package/dist/sandbox/held-operations.d.ts +39 -0
- package/dist/sandbox/held-operations.js +119 -0
- package/dist/sandbox/jobs.d.ts +14 -3
- package/dist/sandbox/jobs.js +20 -2
- package/dist/sandbox/kernel-read.d.ts +55 -0
- package/dist/sandbox/kernel-read.js +57 -0
- package/dist/sandbox/legacy-retirement.d.ts +336 -0
- package/dist/sandbox/legacy-retirement.js +1063 -0
- package/dist/sandbox/legacy-retirement.module.d.ts +8 -0
- package/dist/sandbox/legacy-retirement.module.js +25 -0
- package/dist/sandbox/managed-device-context.d.ts +94 -0
- package/dist/sandbox/managed-device-context.js +308 -0
- package/dist/sandbox/managed-device-context.module.d.ts +6 -0
- package/dist/sandbox/managed-device-context.module.js +33 -0
- package/dist/sandbox/modes.d.ts +56 -8
- package/dist/sandbox/modes.js +92 -8
- package/dist/sandbox/operation-authority-types.d.ts +8 -0
- package/dist/sandbox/operation-authority-types.js +32 -0
- package/dist/sandbox/operation-authority.d.ts +145 -0
- package/dist/sandbox/operation-authority.js +783 -0
- package/dist/sandbox/operation-authority.module.d.ts +2 -0
- package/dist/sandbox/operation-authority.module.js +29 -0
- package/dist/sandbox/operation-intents.d.ts +206 -0
- package/dist/sandbox/operation-intents.js +1252 -0
- package/dist/sandbox/operation-intents.module.d.ts +2 -0
- package/dist/sandbox/operation-intents.module.js +21 -0
- package/dist/sandbox/operation-payloads.d.ts +33 -0
- package/dist/sandbox/operation-payloads.js +332 -0
- package/dist/sandbox/operation-reconcile.job.d.ts +49 -0
- package/dist/sandbox/operation-reconcile.job.js +247 -0
- package/dist/sandbox/permission-authority-epochs.d.ts +18 -0
- package/dist/sandbox/permission-authority-epochs.js +83 -0
- package/dist/sandbox/permission-authority-lock.d.ts +38 -0
- package/dist/sandbox/permission-authority-lock.js +147 -0
- package/dist/sandbox/permission-authority.module.d.ts +9 -0
- package/dist/sandbox/permission-authority.module.js +55 -0
- package/dist/sandbox/permission-availability.d.ts +18 -0
- package/dist/sandbox/permission-availability.js +19 -0
- package/dist/sandbox/permission-call-grants.d.ts +34 -0
- package/dist/sandbox/permission-call-grants.js +349 -0
- package/dist/sandbox/permission-call-grants.module.d.ts +2 -0
- package/dist/sandbox/permission-call-grants.module.js +21 -0
- package/dist/sandbox/permission-call-types.d.ts +82 -0
- package/dist/sandbox/permission-call-types.js +1 -0
- package/dist/sandbox/permission-ceiling-writes.d.ts +47 -0
- package/dist/sandbox/permission-ceiling-writes.js +223 -0
- package/dist/sandbox/permission-config-publication.d.ts +76 -0
- package/dist/sandbox/permission-config-publication.js +339 -0
- package/dist/sandbox/permission-context-types.d.ts +64 -0
- package/dist/sandbox/permission-context-types.js +24 -0
- package/dist/sandbox/permission-facts.d.ts +206 -0
- package/dist/sandbox/permission-facts.js +627 -0
- package/dist/sandbox/permission-facts.module.d.ts +2 -0
- package/dist/sandbox/permission-facts.module.js +20 -0
- package/dist/sandbox/permission-instance-writes.d.ts +90 -0
- package/dist/sandbox/permission-instance-writes.js +305 -0
- package/dist/sandbox/permission-runtime-reports.d.ts +83 -0
- package/dist/sandbox/permission-runtime-reports.js +354 -0
- package/dist/sandbox/permission-transitions.d.ts +31 -0
- package/dist/sandbox/permission-transitions.js +155 -0
- package/dist/sandbox/platform-full-access.d.ts +128 -0
- package/dist/sandbox/platform-full-access.js +210 -0
- package/dist/sandbox/providers.d.ts +22 -0
- package/dist/sandbox/providers.js +10 -2
- package/dist/sandbox/providers.module.d.ts +2 -0
- package/dist/sandbox/providers.module.js +19 -0
- package/dist/sandbox/request-not-sent.d.ts +13 -0
- package/dist/sandbox/request-not-sent.js +13 -0
- package/dist/sandbox/review/classifier.d.ts +2 -0
- package/dist/sandbox/review/classifier.js +8 -0
- package/dist/sandbox/review/permission-candidate.d.ts +12 -0
- package/dist/sandbox/review/permission-candidate.js +129 -0
- package/dist/sandbox/review/review.service.d.ts +4 -1
- package/dist/sandbox/review/review.service.js +19 -5
- package/dist/sandbox/sandbox-file-reader.d.ts +18 -1
- package/dist/sandbox/sandbox-file-reader.js +51 -7
- package/dist/sandbox/sandbox.module.js +26 -6
- package/dist/sandbox/sandbox.service.d.ts +230 -34
- package/dist/sandbox/sandbox.service.js +1368 -199
- package/dist/sandbox/unreachable.js +17 -3
- package/dist/sandbox/use-context.d.ts +17 -0
- package/dist/sandbox/use-context.js +1 -0
- package/dist/skills/invoke.d.ts +27 -4
- package/dist/skills/invoke.js +72 -7
- package/dist/tools/approvals.controller.d.ts +1 -0
- package/dist/tools/approvals.schemas.d.ts +1 -0
- package/dist/tools/approvals.schemas.js +3 -1
- package/dist/tools/approvals.service.d.ts +23 -10
- package/dist/tools/approvals.service.js +104 -26
- package/dist/tools/builtins/builtin-tools.d.ts +16 -2
- package/dist/tools/builtins/builtin-tools.js +38 -10
- package/dist/tools/builtins/sandbox/bash.d.ts +25 -1
- package/dist/tools/builtins/sandbox/bash.js +201 -5
- package/dist/tools/builtins/sandbox/common.d.ts +92 -20
- package/dist/tools/builtins/sandbox/common.js +201 -17
- package/dist/tools/builtins/sandbox/deliver.js +2 -2
- package/dist/tools/builtins/sandbox/edit.js +2 -2
- package/dist/tools/builtins/sandbox/fetch-attachment.js +11 -4
- package/dist/tools/builtins/sandbox/glob.js +2 -2
- package/dist/tools/builtins/sandbox/grep.js +2 -2
- package/dist/tools/builtins/sandbox/read.js +2 -2
- package/dist/tools/builtins/sandbox/task-list.js +7 -1
- package/dist/tools/builtins/sandbox/task-output.d.ts +1 -1
- package/dist/tools/builtins/sandbox/task-output.js +172 -0
- package/dist/tools/builtins/sandbox/task-stop.js +25 -3
- package/dist/tools/builtins/sandbox/write.js +2 -2
- package/dist/tools/builtins/skill-load.js +9 -6
- package/dist/tools/device-op-resolver.d.ts +1 -1
- package/dist/tools/device-op-resolver.js +13 -3
- package/dist/tools/permission-approval-jobs.d.ts +18 -0
- package/dist/tools/permission-approval-jobs.js +92 -0
- package/dist/tools/pipeline.d.ts +17 -2
- package/dist/tools/pipeline.js +300 -19
- package/dist/tools/registry.d.ts +9 -0
- package/dist/tools/tools.module.js +12 -0
- package/package.json +4 -3
- package/src/migrations/0146_permission_authority_epochs.sql +6 -0
- package/src/migrations/0147_conversation_permission_profiles.sql +4 -0
- package/src/migrations/0148_first_message_request_hash.sql +2 -0
- package/src/migrations/0149_sandbox_operation_intents.sql +66 -0
- package/src/migrations/0150_permission_call_grants_and_approvals.sql +36 -0
- package/src/migrations/0151_starting_execution_grants.sql +8 -0
- package/src/migrations/0152_background_launch_identity.sql +66 -0
- package/src/migrations/0153_background_cancel_requester.sql +13 -0
- package/src/migrations/0154_cloud_owner_ceiling.sql +14 -0
- package/src/migrations/0155_device_instance_generations.sql +30 -0
- package/src/migrations/0156_device_owner_report.sql +7 -0
- package/src/migrations/0157_legacy_retirement.sql +116 -0
- package/src/migrations/0158_legacy_freeze_enumerated.sql +5 -0
- package/src/migrations/0159_retirement_exact_cancel.sql +9 -0
- package/dist/sandbox/platform-auto-mode.d.ts +0 -63
- package/dist/sandbox/platform-auto-mode.js +0 -63
|
@@ -33,7 +33,13 @@ export declare function workingRootOf(project: WorkingProject | null | undefined
|
|
|
33
33
|
mode: SandboxMode;
|
|
34
34
|
workspace: string;
|
|
35
35
|
home?: string | null;
|
|
36
|
+
reach?: "workspace" | "os-user" | undefined;
|
|
36
37
|
}): string;
|
|
38
|
+
/**
|
|
39
|
+
* A root in the one form two roots are compared in (B-18): POSIX-normalized (`.` and doubled `/`
|
|
40
|
+
* segments dropped) and without a trailing slash, `/` itself kept.
|
|
41
|
+
*/
|
|
42
|
+
export declare function canonicalRoot(root: string): string;
|
|
37
43
|
/**
|
|
38
44
|
* A file-tool path as the command review judged it, for the person approving it: a relative path
|
|
39
45
|
* joined to the working root and normalized; an absolute or `~` path as given.
|
|
@@ -33,12 +33,23 @@ export function workingRootOf(project, device) {
|
|
|
33
33
|
: project.root;
|
|
34
34
|
if (validateSandboxPathShape(root).length > 0)
|
|
35
35
|
return device.workspace;
|
|
36
|
-
|
|
36
|
+
// B2: a root outside the workspace needs the wider restricted reach (`reach`, given apart from
|
|
37
|
+
// the Full mode); without it, the protocol 2 encoding (`mode: auto` was that reach)
|
|
38
|
+
const wide = device.reach !== undefined ? device.reach === "os-user" : device.mode === "auto";
|
|
39
|
+
if (!wide && !isInside(root, device.workspace))
|
|
37
40
|
return device.workspace;
|
|
38
41
|
if (aboveHome(root, device.home))
|
|
39
42
|
return device.workspace;
|
|
40
43
|
return root;
|
|
41
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* A root in the one form two roots are compared in (B-18): POSIX-normalized (`.` and doubled `/`
|
|
47
|
+
* segments dropped) and without a trailing slash, `/` itself kept.
|
|
48
|
+
*/
|
|
49
|
+
export function canonicalRoot(root) {
|
|
50
|
+
const n = posix.normalize(root);
|
|
51
|
+
return n.length > 1 && n.endsWith("/") ? n.slice(0, -1) : n;
|
|
52
|
+
}
|
|
42
53
|
/**
|
|
43
54
|
* A file-tool path as the command review judged it, for the person approving it: a relative path
|
|
44
55
|
* joined to the working root and normalized; an absolute or `~` path as given.
|
package/dist/errors.d.ts
CHANGED
|
@@ -389,6 +389,25 @@ export declare const ERROR_CODES: {
|
|
|
389
389
|
* `capybara-device mode sandbox`.
|
|
390
390
|
*/
|
|
391
391
|
readonly "device.auto_mode_not_allowed": 403;
|
|
392
|
+
/**
|
|
393
|
+
* B1: a cloud device's snapshot found applied limits it could not establish exactly; no operation
|
|
394
|
+
* is admitted until a lifecycle action (a file reset) establishes them.
|
|
395
|
+
*/
|
|
396
|
+
readonly "device.permission_reconcile_required": 409;
|
|
397
|
+
/**
|
|
398
|
+
* B1: a cloud device's owner ceiling PATCH before its snapshot exists (not migrated yet); the old
|
|
399
|
+
* sandbox switch still narrows it. A file reset does not change this.
|
|
400
|
+
*/
|
|
401
|
+
readonly "device.permission_not_migrated": 409;
|
|
402
|
+
readonly "device.owner_report_stale": 409;
|
|
403
|
+
/** A local device's old instance may still run legacy work until the computer restarts (8.5). */
|
|
404
|
+
readonly "device.restart_required": 503;
|
|
405
|
+
/** A local device's old instance may still run legacy work and no restart can prove it (8.5). */
|
|
406
|
+
readonly "device.replace_required": 503;
|
|
407
|
+
/** A cloud device's earlier instance may run legacy work no evidence can cover (8.5). */
|
|
408
|
+
readonly "device.recreate_required": 503;
|
|
409
|
+
readonly "device.owner_ceiling_confirmation_required": 409;
|
|
410
|
+
readonly "device.full_access_not_allowed": 409;
|
|
392
411
|
/**
|
|
393
412
|
* A device's mode is not a stored setting: a local device's mode lives on its machine
|
|
394
413
|
* (`capybara-device mode` or the device page's policy op), and a cloud device has none to choose.
|
|
@@ -406,6 +425,11 @@ export declare const ERROR_CODES: {
|
|
|
406
425
|
readonly "device.projects_unsupported": 409;
|
|
407
426
|
/** The device could not be asked about its directories now; the message says why. */
|
|
408
427
|
readonly "device.projects_unavailable": 503;
|
|
428
|
+
/**
|
|
429
|
+
* An owner browse found the device's instance not running (it stopped after being started for
|
|
430
|
+
* the owner, or could not be started): retrying starts it first.
|
|
431
|
+
*/
|
|
432
|
+
readonly "device.not_running": 409;
|
|
409
433
|
/** Not a valid project name (1-64 characters, no `/`, no control characters, not `.` / `..`). */
|
|
410
434
|
readonly "device.project_name_invalid": 422;
|
|
411
435
|
/** The device already has a project with this name. */
|
|
@@ -507,6 +531,13 @@ export declare const ERROR_CODES: {
|
|
|
507
531
|
readonly "eval.too_many_cases": 409;
|
|
508
532
|
readonly "eval.agent_mismatch": 409;
|
|
509
533
|
readonly "eval.compact_not_replayable": 422;
|
|
534
|
+
/**
|
|
535
|
+
* The case snapshot holds a recorded record replay cannot read (a permission context with an
|
|
536
|
+
* unsupported version or invalid payload, an invalid tool-result review, model calls out of
|
|
537
|
+
* step / attempt order): the case cannot be replayed, and the failure is the snapshot's, never
|
|
538
|
+
* the provider's.
|
|
539
|
+
*/
|
|
540
|
+
readonly "eval.snapshot_invalid": 422;
|
|
510
541
|
readonly "eval.run_not_found": 404;
|
|
511
542
|
readonly "eval.token_cap_invalid": 400;
|
|
512
543
|
readonly "eval.run_finished": 409;
|
package/dist/errors.js
CHANGED
|
@@ -389,6 +389,25 @@ export const ERROR_CODES = {
|
|
|
389
389
|
* `capybara-device mode sandbox`.
|
|
390
390
|
*/
|
|
391
391
|
"device.auto_mode_not_allowed": 403,
|
|
392
|
+
/**
|
|
393
|
+
* B1: a cloud device's snapshot found applied limits it could not establish exactly; no operation
|
|
394
|
+
* is admitted until a lifecycle action (a file reset) establishes them.
|
|
395
|
+
*/
|
|
396
|
+
"device.permission_reconcile_required": 409,
|
|
397
|
+
/**
|
|
398
|
+
* B1: a cloud device's owner ceiling PATCH before its snapshot exists (not migrated yet); the old
|
|
399
|
+
* sandbox switch still narrows it. A file reset does not change this.
|
|
400
|
+
*/
|
|
401
|
+
"device.permission_not_migrated": 409,
|
|
402
|
+
"device.owner_report_stale": 409,
|
|
403
|
+
/** A local device's old instance may still run legacy work until the computer restarts (8.5). */
|
|
404
|
+
"device.restart_required": 503,
|
|
405
|
+
/** A local device's old instance may still run legacy work and no restart can prove it (8.5). */
|
|
406
|
+
"device.replace_required": 503,
|
|
407
|
+
/** A cloud device's earlier instance may run legacy work no evidence can cover (8.5). */
|
|
408
|
+
"device.recreate_required": 503,
|
|
409
|
+
"device.owner_ceiling_confirmation_required": 409,
|
|
410
|
+
"device.full_access_not_allowed": 409,
|
|
392
411
|
/**
|
|
393
412
|
* A device's mode is not a stored setting: a local device's mode lives on its machine
|
|
394
413
|
* (`capybara-device mode` or the device page's policy op), and a cloud device has none to choose.
|
|
@@ -406,6 +425,11 @@ export const ERROR_CODES = {
|
|
|
406
425
|
"device.projects_unsupported": 409,
|
|
407
426
|
/** The device could not be asked about its directories now; the message says why. */
|
|
408
427
|
"device.projects_unavailable": 503,
|
|
428
|
+
/**
|
|
429
|
+
* An owner browse found the device's instance not running (it stopped after being started for
|
|
430
|
+
* the owner, or could not be started): retrying starts it first.
|
|
431
|
+
*/
|
|
432
|
+
"device.not_running": 409,
|
|
409
433
|
/** Not a valid project name (1-64 characters, no `/`, no control characters, not `.` / `..`). */
|
|
410
434
|
"device.project_name_invalid": 422,
|
|
411
435
|
/** The device already has a project with this name. */
|
|
@@ -507,6 +531,13 @@ export const ERROR_CODES = {
|
|
|
507
531
|
"eval.too_many_cases": 409,
|
|
508
532
|
"eval.agent_mismatch": 409,
|
|
509
533
|
"eval.compact_not_replayable": 422,
|
|
534
|
+
/**
|
|
535
|
+
* The case snapshot holds a recorded record replay cannot read (a permission context with an
|
|
536
|
+
* unsupported version or invalid payload, an invalid tool-result review, model calls out of
|
|
537
|
+
* step / attempt order): the case cannot be replayed, and the failure is the snapshot's, never
|
|
538
|
+
* the provider's.
|
|
539
|
+
*/
|
|
540
|
+
"eval.snapshot_invalid": 422,
|
|
510
541
|
"eval.run_not_found": 404,
|
|
511
542
|
"eval.token_cap_invalid": 400,
|
|
512
543
|
"eval.run_finished": 409,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ModelInfo, type ModelRequest, type ParamValue } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { type AgentDefinition, type ModelRef } from "../agents/definition.js";
|
|
3
|
-
import type
|
|
3
|
+
import { type ConversationEvent, type EventPayload } from "../conversations/events.js";
|
|
4
4
|
import { type MediaBytes, type MediaInfo, type ModelCallMeta } from "../runtime/context/build.js";
|
|
5
5
|
import { type MediaSourceDeps } from "../runtime/model-call.js";
|
|
6
6
|
import { type CaseSnapshot } from "./snapshot.js";
|
|
@@ -28,7 +28,9 @@ import { type CaseSnapshot } from "./snapshot.js";
|
|
|
28
28
|
/** 还原结果与原请求不一致的原因。 */
|
|
29
29
|
export type DriftReason = "system_hash" | "tools_changed" | "tool_spec_missing" | "definition_missing"
|
|
30
30
|
/** A child case's candidate has another effective definition than the logged one (phase C). */
|
|
31
|
-
| "subagent_changed"
|
|
31
|
+
| "subagent_changed"
|
|
32
|
+
/** Original bounded permission contributions or their recorded locator/hash differ. */
|
|
33
|
+
| "permission_profile_changed" | "params_changed"
|
|
32
34
|
/**
|
|
33
35
|
* UI refresh B: a non-baseline reconstruction whose run used a person's mid-conversation model
|
|
34
36
|
* switch (`model_switched`) and whose candidate model (`modelRef`) replaces it.
|
|
@@ -86,6 +88,21 @@ export interface ReconstructResult {
|
|
|
86
88
|
/** 请求里媒体的估算 token(`estimateTokens` 用;回放失败时按估算计费)。 */
|
|
87
89
|
mediaTokens: number;
|
|
88
90
|
}
|
|
91
|
+
type ModelCallEvent = Extract<ConversationEvent, {
|
|
92
|
+
type: "model_call";
|
|
93
|
+
}>;
|
|
94
|
+
/**
|
|
95
|
+
* A corrupt recorded permission context is the snapshot's failure: a 4xx `eval.snapshot_invalid`
|
|
96
|
+
* (an `ApiError`, so the eval worker records it as a non-retryable replay error, never as
|
|
97
|
+
* `run.provider_error`), checked over the whole snapshot before anything renders.
|
|
98
|
+
*/
|
|
99
|
+
export declare function assertSnapshotPermissionEvents(events: readonly ConversationEvent[]): void;
|
|
100
|
+
/**
|
|
101
|
+
* Compare only the original request range, never live state or candidate-generated history.
|
|
102
|
+
* Throws `eval.snapshot_invalid` first when any recorded v1 event in the snapshot
|
|
103
|
+
* (inside or outside the range, covered by a summary or not) fails its strict schema.
|
|
104
|
+
*/
|
|
105
|
+
export declare function recordedPermissionContextDrift(events: readonly ConversationEvent[], call: ModelCallEvent): DriftReason[];
|
|
89
106
|
export declare function reconstructRequest(s: CaseSnapshot, modelCallSeq: number, opts: ReconstructOptions): ReconstructResult;
|
|
90
107
|
type SubagentStarted = EventPayload<"subagent_started">;
|
|
91
108
|
/** The `subagent_started` of a sub-agent's (child) log, or undefined for any other conversation. */
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { sanitizeParams, } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { AgentDefinitionSchema, builtinDisabled, canonicalDisabledSkills, canonicalDisabledTools, normalizeStoredDefinition, } from "../agents/definition.js";
|
|
3
|
+
import { PermissionContextMetaV1Schema, } from "../conversations/events.js";
|
|
3
4
|
import { sameModel, selectionAt } from "../conversations/selection.js";
|
|
4
5
|
import { ApiError } from "../errors.js";
|
|
5
6
|
import { COMPACTION_SETTINGS } from "../identity/settings.js";
|
|
6
|
-
import { mediaRefs, planMedia, } from "../runtime/context/build.js";
|
|
7
|
+
import { latestSummary, mediaRefs, planMedia, } from "../runtime/context/build.js";
|
|
7
8
|
import { applyFit, estimateAfterFit, planFit, planningBounds, planSqueezedFit, sentOutputCap, } from "../runtime/context/fit.js";
|
|
9
|
+
import { assertRecordedPermissionEvents, permissionContextHistory, RecordedPermissionContextError, } from "../runtime/context/permission-profile.js";
|
|
8
10
|
import { estimateTokens } from "../runtime/context/tokens.js";
|
|
9
11
|
import { assembleModelRequest } from "../runtime/model-call.js";
|
|
10
12
|
import { CHILD_REMOVED_TOOLS } from "../runtime/subagents/definition.js";
|
|
@@ -37,6 +39,7 @@ const DRIFT_ORDER = [
|
|
|
37
39
|
"tool_spec_missing",
|
|
38
40
|
"definition_missing",
|
|
39
41
|
"subagent_changed",
|
|
42
|
+
"permission_profile_changed",
|
|
40
43
|
"params_changed",
|
|
41
44
|
"model_switched",
|
|
42
45
|
"media_missing",
|
|
@@ -56,6 +59,41 @@ function inputEvents(events, call) {
|
|
|
56
59
|
const upTo = Math.min(call.payload.request.toSeq, call.seq - 1);
|
|
57
60
|
return events.filter((e) => e.seq <= upTo);
|
|
58
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* A corrupt recorded permission context is the snapshot's failure: a 4xx `eval.snapshot_invalid`
|
|
64
|
+
* (an `ApiError`, so the eval worker records it as a non-retryable replay error, never as
|
|
65
|
+
* `run.provider_error`), checked over the whole snapshot before anything renders.
|
|
66
|
+
*/
|
|
67
|
+
export function assertSnapshotPermissionEvents(events) {
|
|
68
|
+
try {
|
|
69
|
+
assertRecordedPermissionEvents(events);
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
if (err instanceof RecordedPermissionContextError)
|
|
73
|
+
throw new ApiError("eval.snapshot_invalid", err.message);
|
|
74
|
+
throw err;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Compare only the original request range, never live state or candidate-generated history.
|
|
79
|
+
* Throws `eval.snapshot_invalid` first when any recorded v1 event in the snapshot
|
|
80
|
+
* (inside or outside the range, covered by a summary or not) fails its strict schema.
|
|
81
|
+
*/
|
|
82
|
+
export function recordedPermissionContextDrift(events, call) {
|
|
83
|
+
assertSnapshotPermissionEvents(events);
|
|
84
|
+
const bounded = inputEvents(events, call);
|
|
85
|
+
const rebuilt = permissionContextHistory(bounded, latestSummary(bounded)?.payload.coversUpToSeq).meta;
|
|
86
|
+
const recorded = call.payload.request.permissionContext;
|
|
87
|
+
if (recorded === undefined && rebuilt === undefined)
|
|
88
|
+
return [];
|
|
89
|
+
const parsed = PermissionContextMetaV1Schema.safeParse(recorded);
|
|
90
|
+
if (!parsed.success ||
|
|
91
|
+
rebuilt === undefined ||
|
|
92
|
+
parsed.data.contextSeq !== rebuilt.contextSeq ||
|
|
93
|
+
parsed.data.hash !== rebuilt.hash)
|
|
94
|
+
return ["permission_profile_changed"];
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
59
97
|
/** 该请求的 agent 版本:所属运行的 `run_started`;没有(不应出现)时用快照运行的版本。 */
|
|
60
98
|
function recordedVersion(s, events, call) {
|
|
61
99
|
const started = events.find((e) => e.type === "run_started" && e.runId === call.runId);
|
|
@@ -71,7 +109,7 @@ export function reconstructRequest(s, modelCallSeq, opts) {
|
|
|
71
109
|
const all = toEvents(s);
|
|
72
110
|
const call = findCall(all, modelCallSeq);
|
|
73
111
|
const rec = call.payload.request;
|
|
74
|
-
const drift = new Set();
|
|
112
|
+
const drift = new Set(recordedPermissionContextDrift(all, call));
|
|
75
113
|
const origVersion = recordedVersion(s, all, call);
|
|
76
114
|
const version = opts.agentVersion ?? origVersion;
|
|
77
115
|
const started = subagentStartedOf(all);
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { EventLog } from "../conversations/event-log.js";
|
|
2
|
+
import type { ConversationEvent } from "../conversations/events.js";
|
|
3
|
+
import type { PermissionContextPort } from "../runtime/model-call.js";
|
|
4
|
+
import { type CaseSnapshot } from "./snapshot.js";
|
|
5
|
+
/**
|
|
6
|
+
* Recorded-only permission context for a full-run replay (permission context replay spec B4).
|
|
7
|
+
*
|
|
8
|
+
* The seed copies the events before the original run's `run_started` (seq < R) at their own seqs,
|
|
9
|
+
* so an earlier run's `permission_context` is in the eval conversation once and is never appended
|
|
10
|
+
* again. The feeder only ever appends the original run's own `permission_context` events
|
|
11
|
+
* (seq > R), each at the generated request boundary where the original run had made it visible:
|
|
12
|
+
* the original requests `C = (step, attempt, callSeq, U = min(toSeq, callSeq - 1))` are mapped to
|
|
13
|
+
* a generated `(step, attempt)` by {@link selectOriginalRequest}, the consumed boundary only moves
|
|
14
|
+
* forward, and an event is fed once its first visible original request is at or before it. Replays
|
|
15
|
+
* never read live permission state, call a reviewer, preview, admit, provision, resume, probe or
|
|
16
|
+
* touch a device: the feeder writes recorded payloads into the eval conversation and nothing else.
|
|
17
|
+
*/
|
|
18
|
+
/** One original agent request of the replayed run, in source `callSeq` order. */
|
|
19
|
+
export interface OriginalRequest {
|
|
20
|
+
step: number;
|
|
21
|
+
attempt: number;
|
|
22
|
+
callSeq: number;
|
|
23
|
+
/** The last event seq the request could see: `min(request.toSeq, callSeq - 1)`. */
|
|
24
|
+
upTo: number;
|
|
25
|
+
}
|
|
26
|
+
/** A target-run `permission_context` and the first original request that saw it. */
|
|
27
|
+
export interface FeedableContext {
|
|
28
|
+
seq: number;
|
|
29
|
+
payload: unknown;
|
|
30
|
+
/** Index into the original requests of the first one whose `upTo` covers `seq`. */
|
|
31
|
+
firstVisible: number;
|
|
32
|
+
}
|
|
33
|
+
/** What a recording schedules for its replay: the original requests and the feedable events. */
|
|
34
|
+
export interface PermissionFeedPlan {
|
|
35
|
+
requests: OriginalRequest[];
|
|
36
|
+
contexts: FeedableContext[];
|
|
37
|
+
}
|
|
38
|
+
/** Whether the recording holds any v1 permission marker (event, managed path or metadata). */
|
|
39
|
+
export declare function hasPermissionMarkers(events: readonly ConversationEvent[]): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* The original requests of the run started at `runStartedSeq` and its feedable contexts. Rejects
|
|
42
|
+
* (`eval.snapshot_invalid`) a duplicate `(step, attempt)`, a step or attempt going backwards in
|
|
43
|
+
* `callSeq` order, and a visibility bound `upTo` going backwards: a valid log only appends.
|
|
44
|
+
*/
|
|
45
|
+
export declare function permissionFeedPlan(events: readonly ConversationEvent[], runId: string, runStartedSeq: number): PermissionFeedPlan;
|
|
46
|
+
/**
|
|
47
|
+
* The original request that supplies a generated `(step, attempt)`'s permission context (spec B4
|
|
48
|
+
* table), as an index into `requests`; undefined when there is none (seeded history only):
|
|
49
|
+
* - the same step's exact attempt; inside a gap, the greatest earlier attempt of that step; before
|
|
50
|
+
* its first recorded attempt, that first attempt (the first actually sent request supplies the
|
|
51
|
+
* initial context); past its last, its last;
|
|
52
|
+
* - a step with no original request: the last request of the greatest earlier original step,
|
|
53
|
+
* never a later step (past every original step: the final request);
|
|
54
|
+
* - before every original step, or a run without requests: none.
|
|
55
|
+
*/
|
|
56
|
+
export declare function selectOriginalRequest(requests: readonly OriginalRequest[], step: number, attempt: number): number | undefined;
|
|
57
|
+
/** The persistent identity of a fed event: the generated run and the original event's seq. */
|
|
58
|
+
export declare const replayPermissionContextIdemKey: (generatedRunId: string, originalSeq: number) => string;
|
|
59
|
+
/** The replayed (generated) conversation and run the feeder may write to. */
|
|
60
|
+
export interface ReplayTarget {
|
|
61
|
+
conversationId: string;
|
|
62
|
+
runId: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Recorded original-coordinate diagnostics over every original request of the replayed run (spec
|
|
66
|
+
* "Replay and meaningful drift detection"): true when any of them cannot reproduce its recorded
|
|
67
|
+
* permission metadata from its own bounded range. Throws `eval.snapshot_invalid` for a recorded
|
|
68
|
+
* v1 event its strict schema rejects. Never compares generated seqs or hashes with the original.
|
|
69
|
+
*/
|
|
70
|
+
export declare function recordedRunPermissionDrift(s: CaseSnapshot): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* The recorded-only feeder for the replay of `s` (spec B4) into `target`, or undefined for a
|
|
73
|
+
* recording without any v1 permission marker, so the request boundary stays absent and old
|
|
74
|
+
* recordings build their requests exactly as before. A marked recording gets a feeder even when no
|
|
75
|
+
* target-run event is feedable (an earlier run's seeded context still applies).
|
|
76
|
+
*/
|
|
77
|
+
export declare function recordedPermissionContext(s: CaseSnapshot, eventLog: Pick<EventLog, "append">, target: ReplayTarget): PermissionContextPort | undefined;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { ApiError } from "../errors.js";
|
|
2
|
+
import { assertSnapshotPermissionEvents, recordedPermissionContextDrift } from "./reconstruct.js";
|
|
3
|
+
import { toEvents } from "./snapshot.js";
|
|
4
|
+
const invalid = (message) => new ApiError("eval.snapshot_invalid", message);
|
|
5
|
+
/** Whether the recording holds any v1 permission marker (event, managed path or metadata). */
|
|
6
|
+
export function hasPermissionMarkers(events) {
|
|
7
|
+
return events.some((e) => e.type === "permission_context" ||
|
|
8
|
+
(e.type === "device_paths" &&
|
|
9
|
+
e.payload.permissionContextVersion !==
|
|
10
|
+
undefined) ||
|
|
11
|
+
(e.type === "model_call" &&
|
|
12
|
+
e.payload.request.permissionContext !== undefined));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The original requests of the run started at `runStartedSeq` and its feedable contexts. Rejects
|
|
16
|
+
* (`eval.snapshot_invalid`) a duplicate `(step, attempt)`, a step or attempt going backwards in
|
|
17
|
+
* `callSeq` order, and a visibility bound `upTo` going backwards: a valid log only appends.
|
|
18
|
+
*/
|
|
19
|
+
export function permissionFeedPlan(events, runId, runStartedSeq) {
|
|
20
|
+
const sorted = [...events].sort((a, b) => a.seq - b.seq);
|
|
21
|
+
const requests = [];
|
|
22
|
+
for (const e of sorted) {
|
|
23
|
+
if (e.type !== "model_call" || e.runId !== runId || e.seq <= runStartedSeq)
|
|
24
|
+
continue;
|
|
25
|
+
const p = e.payload;
|
|
26
|
+
const r = {
|
|
27
|
+
step: p.step,
|
|
28
|
+
// a legacy record without an attempt is the step's first (the replay's existing fallback)
|
|
29
|
+
attempt: p.attempt ?? 1,
|
|
30
|
+
callSeq: e.seq,
|
|
31
|
+
upTo: Math.min(p.request.toSeq, e.seq - 1),
|
|
32
|
+
};
|
|
33
|
+
const prev = requests.at(-1);
|
|
34
|
+
if (prev !== undefined) {
|
|
35
|
+
if (r.step < prev.step || (r.step === prev.step && r.attempt <= prev.attempt)) {
|
|
36
|
+
throw invalid(`Recorded model_call at seq ${e.seq} repeats or goes back from step ${prev.step} attempt ${prev.attempt}`);
|
|
37
|
+
}
|
|
38
|
+
if (r.upTo < prev.upTo) {
|
|
39
|
+
throw invalid(`Recorded model_call at seq ${e.seq} sees fewer events than the one before`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
requests.push(r);
|
|
43
|
+
}
|
|
44
|
+
const contexts = [];
|
|
45
|
+
for (const e of sorted) {
|
|
46
|
+
if (e.type !== "permission_context" || e.runId !== runId || e.seq <= runStartedSeq)
|
|
47
|
+
continue;
|
|
48
|
+
const firstVisible = requests.findIndex((r) => r.upTo >= e.seq);
|
|
49
|
+
// never seen by an original request (logged after the last one): never fed
|
|
50
|
+
if (firstVisible < 0)
|
|
51
|
+
continue;
|
|
52
|
+
contexts.push({ seq: e.seq, payload: e.payload, firstVisible });
|
|
53
|
+
}
|
|
54
|
+
return { requests, contexts };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The original request that supplies a generated `(step, attempt)`'s permission context (spec B4
|
|
58
|
+
* table), as an index into `requests`; undefined when there is none (seeded history only):
|
|
59
|
+
* - the same step's exact attempt; inside a gap, the greatest earlier attempt of that step; before
|
|
60
|
+
* its first recorded attempt, that first attempt (the first actually sent request supplies the
|
|
61
|
+
* initial context); past its last, its last;
|
|
62
|
+
* - a step with no original request: the last request of the greatest earlier original step,
|
|
63
|
+
* never a later step (past every original step: the final request);
|
|
64
|
+
* - before every original step, or a run without requests: none.
|
|
65
|
+
*/
|
|
66
|
+
export function selectOriginalRequest(requests, step, attempt) {
|
|
67
|
+
let lastEarlier;
|
|
68
|
+
let sameStep = [];
|
|
69
|
+
for (const [i, r] of requests.entries()) {
|
|
70
|
+
if (r.step < step)
|
|
71
|
+
lastEarlier = i;
|
|
72
|
+
else if (r.step === step)
|
|
73
|
+
sameStep.push(i);
|
|
74
|
+
}
|
|
75
|
+
if (sameStep.length > 0) {
|
|
76
|
+
sameStep = sameStep.sort((a, b) => requests[a].attempt - requests[b].attempt);
|
|
77
|
+
const exact = sameStep.find((i) => requests[i].attempt === attempt);
|
|
78
|
+
if (exact !== undefined)
|
|
79
|
+
return exact;
|
|
80
|
+
const earlier = sameStep.filter((i) => requests[i].attempt < attempt);
|
|
81
|
+
// before the first recorded attempt: that first attempt, by explicit policy (spec B4)
|
|
82
|
+
return earlier.at(-1) ?? sameStep[0];
|
|
83
|
+
}
|
|
84
|
+
return lastEarlier;
|
|
85
|
+
}
|
|
86
|
+
/** The persistent identity of a fed event: the generated run and the original event's seq. */
|
|
87
|
+
export const replayPermissionContextIdemKey = (generatedRunId, originalSeq) => `replay_permission_context:${generatedRunId}:${originalSeq}`;
|
|
88
|
+
/**
|
|
89
|
+
* Recorded original-coordinate diagnostics over every original request of the replayed run (spec
|
|
90
|
+
* "Replay and meaningful drift detection"): true when any of them cannot reproduce its recorded
|
|
91
|
+
* permission metadata from its own bounded range. Throws `eval.snapshot_invalid` for a recorded
|
|
92
|
+
* v1 event its strict schema rejects. Never compares generated seqs or hashes with the original.
|
|
93
|
+
*/
|
|
94
|
+
export function recordedRunPermissionDrift(s) {
|
|
95
|
+
const events = toEvents(s);
|
|
96
|
+
if (!hasPermissionMarkers(events))
|
|
97
|
+
return false;
|
|
98
|
+
assertSnapshotPermissionEvents(events);
|
|
99
|
+
return events.some((e) => e.type === "model_call" &&
|
|
100
|
+
e.runId === s.runId &&
|
|
101
|
+
recordedPermissionContextDrift(events, e).length > 0);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The recorded-only feeder for the replay of `s` (spec B4) into `target`, or undefined for a
|
|
105
|
+
* recording without any v1 permission marker, so the request boundary stays absent and old
|
|
106
|
+
* recordings build their requests exactly as before. A marked recording gets a feeder even when no
|
|
107
|
+
* target-run event is feedable (an earlier run's seeded context still applies).
|
|
108
|
+
*/
|
|
109
|
+
export function recordedPermissionContext(s, eventLog, target) {
|
|
110
|
+
const events = toEvents(s);
|
|
111
|
+
if (!hasPermissionMarkers(events))
|
|
112
|
+
return undefined;
|
|
113
|
+
assertSnapshotPermissionEvents(events);
|
|
114
|
+
const start = events.find((e) => e.runId === s.runId && e.type === "run_started");
|
|
115
|
+
if (start === undefined) {
|
|
116
|
+
throw new ApiError("eval.call_not_found", "The snapshot does not contain the run's start");
|
|
117
|
+
}
|
|
118
|
+
const plan = permissionFeedPlan(events, s.runId, start.seq);
|
|
119
|
+
/** The furthest original request reached so far (monotone). */
|
|
120
|
+
let reached = -1;
|
|
121
|
+
/** Accelerator only: original seq → generated seq; the idem keys are the durable truth. */
|
|
122
|
+
const fed = new Map();
|
|
123
|
+
return {
|
|
124
|
+
async beforeRequest(input) {
|
|
125
|
+
// fail closed: this feeder writes only into the eval conversation it was made for
|
|
126
|
+
if (input.conversationId !== target.conversationId || input.runId !== target.runId) {
|
|
127
|
+
throw new Error("The recorded permission feeder belongs to another replay");
|
|
128
|
+
}
|
|
129
|
+
if (input.signal.aborted)
|
|
130
|
+
return;
|
|
131
|
+
const chosen = selectOriginalRequest(plan.requests, input.step, input.attempt);
|
|
132
|
+
if (chosen !== undefined)
|
|
133
|
+
reached = Math.max(reached, chosen);
|
|
134
|
+
const due = plan.contexts.filter((c) => c.firstVisible <= reached && !fed.has(c.seq));
|
|
135
|
+
if (due.length === 0)
|
|
136
|
+
return;
|
|
137
|
+
// one batch in source order; an idem hit returns the event an earlier entry already wrote
|
|
138
|
+
const written = await eventLog.append(target.conversationId, due.map((c) => ({
|
|
139
|
+
type: "permission_context",
|
|
140
|
+
runId: target.runId,
|
|
141
|
+
idemKey: replayPermissionContextIdemKey(target.runId, c.seq),
|
|
142
|
+
payload: structuredClone(c.payload),
|
|
143
|
+
})));
|
|
144
|
+
for (const [i, c] of due.entries()) {
|
|
145
|
+
const w = written[i];
|
|
146
|
+
if (w !== undefined)
|
|
147
|
+
fed.set(c.seq, w.seq);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { EventLog } from "../conversations/event-log.js";
|
|
2
|
+
import { type ReviewRecord } from "../conversations/events.js";
|
|
2
3
|
import { type DevicePathsPayload } from "../runtime/context/device-paths.js";
|
|
3
4
|
import { type ToolPipeline, type ToolStepContext } from "../tools/pipeline.js";
|
|
4
5
|
import type { CaseSnapshot } from "./snapshot.js";
|
|
@@ -26,9 +27,17 @@ export interface RecordedCall {
|
|
|
26
27
|
* the original run had logged by this call's step (environments spec §13.1, ruling R22): set on
|
|
27
28
|
* every recorded call from the step where an event was logged onward. A replay that matches the
|
|
28
29
|
* call writes the event when the eval conversation's latest one differs, so a candidate whose
|
|
29
|
-
* first sandbox call lands in another step still gets the line, once.
|
|
30
|
+
* first sandbox call lands in another step still gets the line, once. A managed v1 payload
|
|
31
|
+
* (`permissionContextVersion: 1`) is kept whole (permission context replay spec B4); older ones
|
|
32
|
+
* keep their roots-and-level shape and change semantics.
|
|
30
33
|
*/
|
|
31
34
|
devicePaths?: DevicePathsPayload;
|
|
35
|
+
/**
|
|
36
|
+
* The original result's command review record, copied exactly (spec B4): a matched replay result
|
|
37
|
+
* carries it verbatim, so a recorded allow, deny or ask stays that decision; absent when the
|
|
38
|
+
* original had none. Never part of matching, the content or any request.
|
|
39
|
+
*/
|
|
40
|
+
review?: ReviewRecord;
|
|
32
41
|
}
|
|
33
42
|
/** 规范化 JSON:对象键递归按码点排序,数组保持顺序;`undefined` 按 JSON 规则省略。 */
|
|
34
43
|
export declare function canonicalJson(v: unknown): string;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReviewRecordSchema } from "../conversations/events.js";
|
|
2
|
+
import { ApiError } from "../errors.js";
|
|
3
|
+
import { devicePathsChangeFromPayload, devicePathsLevel, } from "../runtime/context/device-paths.js";
|
|
2
4
|
import { assistantIdemKey } from "../runtime/model-call.js";
|
|
3
5
|
import { MATCH_IGNORED_FIELDS } from "../tools/builtin-names.js";
|
|
4
6
|
import { RUN_STOPPED_TEXT } from "../tools/pipeline.js";
|
|
@@ -46,11 +48,13 @@ export function matchKey(toolKey, input) {
|
|
|
46
48
|
export function recordedCalls(s) {
|
|
47
49
|
const own = s.events.filter((e) => e.runId === s.runId);
|
|
48
50
|
const results = new Map();
|
|
51
|
+
const resultSeq = new Map();
|
|
49
52
|
const started = new Map();
|
|
50
53
|
for (const e of own) {
|
|
51
54
|
if (e.type === "tool_result") {
|
|
52
55
|
const p = e.payload;
|
|
53
56
|
results.set(p.callId, p);
|
|
57
|
+
resultSeq.set(p.callId, e.seq);
|
|
54
58
|
}
|
|
55
59
|
else if (e.type === "tool_call_started") {
|
|
56
60
|
const p = e.payload;
|
|
@@ -70,7 +74,10 @@ export function recordedCalls(s) {
|
|
|
70
74
|
const e = own[next];
|
|
71
75
|
if (e.type === "device_paths" && e.seq > a) {
|
|
72
76
|
const p = e.payload;
|
|
73
|
-
current =
|
|
77
|
+
current =
|
|
78
|
+
p.permissionContextVersion === 1
|
|
79
|
+
? structuredClone(p)
|
|
80
|
+
: { roots: p.roots, ...devicePathsLevel(p) };
|
|
74
81
|
}
|
|
75
82
|
}
|
|
76
83
|
if (current !== undefined)
|
|
@@ -98,11 +105,25 @@ export function recordedCalls(s) {
|
|
|
98
105
|
...(r.contentTypes !== undefined && { contentTypes: r.contentTypes }),
|
|
99
106
|
specHash: started.get(call.id) ?? "",
|
|
100
107
|
...(paths !== undefined && { devicePaths: paths }),
|
|
108
|
+
...(r.review !== undefined && {
|
|
109
|
+
review: recordedReview(r.review, resultSeq.get(call.id) ?? 0),
|
|
110
|
+
}),
|
|
101
111
|
});
|
|
102
112
|
}
|
|
103
113
|
}
|
|
104
114
|
return out;
|
|
105
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* A recorded result's review, validated by the schema the log writes it with and copied, never
|
|
118
|
+
* defaulted or repaired: an invalid one makes the snapshot unreplayable (`eval.snapshot_invalid`).
|
|
119
|
+
*/
|
|
120
|
+
function recordedReview(review, seq) {
|
|
121
|
+
const parsed = ReviewRecordSchema.safeParse(review);
|
|
122
|
+
if (!parsed.success) {
|
|
123
|
+
throw new ApiError("eval.snapshot_invalid", `Recorded tool_result at seq ${seq} has an invalid review record`);
|
|
124
|
+
}
|
|
125
|
+
return structuredClone(review);
|
|
126
|
+
}
|
|
106
127
|
/** 与真实管线相同的幂等键(同一调用重入时不重复写)。 */
|
|
107
128
|
const idem = {
|
|
108
129
|
started: (runId, callId) => `tool_started:${runId}:${callId}`,
|
|
@@ -148,10 +169,11 @@ export class RecordedToolPipeline {
|
|
|
148
169
|
this.misses++;
|
|
149
170
|
// the original run had told the model the instance's directories by this call: so does the
|
|
150
171
|
// replay, when the eval conversation's latest record differs (as the sandbox tools write it)
|
|
172
|
+
// (a managed v1 payload whole; older ones by their old roots-and-level comparison)
|
|
151
173
|
const paths = rec?.devicePaths;
|
|
152
174
|
const change = paths === undefined
|
|
153
175
|
? null
|
|
154
|
-
:
|
|
176
|
+
: devicePathsChangeFromPayload(await eventLog.latestOfType(ctx.conversationId, "device_paths"), paths, ctx.runId);
|
|
155
177
|
await eventLog.append(ctx.conversationId, [
|
|
156
178
|
...(change ? [change] : []),
|
|
157
179
|
{
|
|
@@ -171,6 +193,8 @@ export class RecordedToolPipeline {
|
|
|
171
193
|
isError: rec.isError,
|
|
172
194
|
...(rec.loadedTools !== undefined && { loadedTools: rec.loadedTools }),
|
|
173
195
|
...(rec.contentTypes !== undefined && { contentTypes: rec.contentTypes }),
|
|
196
|
+
// the recorded decision, verbatim: nothing is reviewed or admitted again
|
|
197
|
+
...(rec.review !== undefined && { review: structuredClone(rec.review) }),
|
|
174
198
|
}
|
|
175
199
|
: { content: REPLAY_NO_RECORDING, isError: true }),
|
|
176
200
|
]);
|
|
@@ -42,9 +42,15 @@ export interface RunReplayResult {
|
|
|
42
42
|
usage: ModelUsage;
|
|
43
43
|
steps: number;
|
|
44
44
|
unmatched: number;
|
|
45
|
+
/**
|
|
46
|
+
* Set when an original request of the run cannot reproduce its recorded permission context from
|
|
47
|
+
* the snapshot (permission context replay spec B4: original-coordinate diagnostics); the result
|
|
48
|
+
* reports `permission_profile_changed`.
|
|
49
|
+
*/
|
|
50
|
+
permissionContextDrift?: true;
|
|
45
51
|
}
|
|
46
52
|
/** 原运行(基线)的同形摘要。 */
|
|
47
|
-
export type RunBaseline = Omit<RunReplayResult, "conversationId" | "outcome" | "unmatched">;
|
|
53
|
+
export type RunBaseline = Omit<RunReplayResult, "conversationId" | "outcome" | "unmatched" | "permissionContextDrift">;
|
|
48
54
|
/** 测试钩子。 */
|
|
49
55
|
export interface EvalReplayHooks {
|
|
50
56
|
/** 种子已写入(评测对话已记到结果上)、loop 开始之前调用:抛错即模拟此时崩溃。 */
|
|
@@ -74,7 +80,7 @@ export interface RunReplayDeps {
|
|
|
74
80
|
/**
|
|
75
81
|
* 构建评测用的 loop:与运行时同一个 `LangGraphLoop`(同一工厂),只换掉工具管线、模型注册表(计费)与附件来源。
|
|
76
82
|
*/
|
|
77
|
-
loop(d: Pick<LoopDeps, "toolPipeline" | "registry" | "media" | "skillForks">): AgentLoop;
|
|
83
|
+
loop(d: Pick<LoopDeps, "toolPipeline" | "registry" | "media" | "skillForks" | "permissionContext">): AgentLoop;
|
|
78
84
|
/** 本次执行是否仍持有结果的认领(失去认领 → 不再发请求);不给 = 不检查。 */
|
|
79
85
|
stillClaimed?: () => Promise<boolean>;
|
|
80
86
|
/**
|