@capybara-hq/kernel 0.1.0-rc.36 → 0.1.0-rc.37
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 +5 -5
- package/dist/admin/admin.module.d.ts +3 -3
- package/dist/admin/admin.module.js +6 -6
- package/dist/admin/audit-log.service.d.ts +51 -0
- package/dist/admin/{platform-audit.service.js → audit-log.service.js} +20 -12
- package/dist/admin/audit.controller.d.ts +18 -6
- package/dist/admin/audit.controller.js +36 -6
- package/dist/admin/audit.schemas.d.ts +9 -1
- package/dist/admin/audit.schemas.js +22 -2
- package/dist/admin/outbox-dead.controller.d.ts +4 -6
- package/dist/admin/outbox-dead.controller.js +9 -6
- package/dist/admin/outbox-dead.schemas.d.ts +16 -0
- package/dist/admin/outbox-dead.schemas.js +25 -1
- package/dist/admin/outbox-dead.service.d.ts +16 -7
- package/dist/admin/outbox-dead.service.js +34 -10
- package/dist/admin/overview.service.d.ts +3 -3
- package/dist/admin/overview.service.js +0 -1
- package/dist/agents/agent-lookup.js +2 -10
- package/dist/agents/agents.service.js +9 -20
- package/dist/agents/definition.d.ts +3 -51
- package/dist/agents/definition.js +4 -254
- package/dist/agents/org-templates.js +2 -6
- package/dist/agents/readiness.controller.d.ts +4 -12
- package/dist/agents/readiness.controller.js +4 -12
- package/dist/agents/readiness.service.d.ts +23 -11
- package/dist/agents/readiness.service.js +31 -14
- package/dist/agents/templates.d.ts +0 -6
- package/dist/agents/templates.js +8 -34
- package/dist/background/store.d.ts +2 -0
- package/dist/background/store.js +3 -1
- package/dist/background/wake-rules.js +2 -1
- package/dist/catalog/admin-catalog.controller.d.ts +1 -2
- package/dist/catalog/admin-catalog.controller.js +1 -2
- package/dist/catalog/appearance.service.js +1 -3
- package/dist/catalog/catalog-content.d.ts +1 -1
- package/dist/catalog/catalog-content.js +1 -4
- package/dist/catalog/catalog-items.js +3 -3
- package/dist/catalog/catalog-scope.service.d.ts +10 -28
- package/dist/catalog/catalog-scope.service.js +22 -73
- package/dist/catalog/cli.d.ts +0 -11
- package/dist/catalog/cli.js +0 -20
- package/dist/catalog/component-scope.service.js +0 -2
- package/dist/catalog/component-state.js +2 -2
- package/dist/catalog/install-status.d.ts +6 -0
- package/dist/catalog/install-status.js +6 -0
- package/dist/catalog/job-ids.d.ts +0 -4
- package/dist/catalog/job-ids.js +0 -4
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.d.ts +2 -0
- package/dist/catalog/org-catalog.service.js +8 -3
- package/dist/catalog/org-extension-switch.d.ts +7 -2
- package/dist/catalog/org-extension-switch.js +56 -9
- package/dist/catalog/org-plugin-uploads.d.ts +6 -15
- package/dist/catalog/org-plugin-uploads.js +9 -27
- package/dist/catalog/owned-items.js +1 -3
- package/dist/catalog/platform-import-update.js +1 -1
- package/dist/catalog/plugin-import.d.ts +15 -13
- package/dist/catalog/plugin-import.js +21 -30
- package/dist/catalog/plugin-install.d.ts +3 -43
- package/dist/catalog/plugin-install.js +8 -150
- package/dist/catalog/plugin-package.d.ts +5 -10
- package/dist/catalog/plugin-package.js +12 -33
- package/dist/catalog/plugin-upgrade.js +5 -4
- package/dist/catalog/scope-jobs.d.ts +34 -34
- package/dist/catalog/scope-jobs.js +50 -37
- package/dist/catalog/scope-orgs.d.ts +1 -1
- package/dist/catalog/scope-orgs.js +1 -2
- package/dist/catalog/scope-sync-workers.d.ts +4 -3
- package/dist/catalog/scope-sync-workers.js +18 -6
- package/dist/catalog/scope-sync.d.ts +56 -59
- package/dist/catalog/scope-sync.js +96 -166
- package/dist/catalog/unshare.d.ts +3 -4
- package/dist/catalog/unshare.js +5 -8
- package/dist/channels/job-ids.d.ts +2 -6
- package/dist/channels/job-ids.js +2 -6
- package/dist/channels/outbound.d.ts +1 -1
- package/dist/channels/outbound.js +1 -1
- package/dist/channels/supervisor.d.ts +2 -3
- package/dist/channels/supervisor.js +2 -3
- package/dist/client/client-access.service.js +1 -1
- package/dist/config/env.js +19 -1
- package/dist/config/load.d.ts +0 -6
- package/dist/config/load.js +8 -27
- package/dist/config/schema.d.ts +53 -47
- package/dist/config/schema.js +190 -40
- package/dist/conversations/attachments.service.d.ts +10 -3
- package/dist/conversations/attachments.service.js +49 -16
- package/dist/conversations/conversations.controller.d.ts +0 -39
- package/dist/conversations/conversations.controller.js +0 -39
- package/dist/conversations/events.d.ts +71 -46
- package/dist/conversations/events.js +124 -112
- package/dist/conversations/media-types.d.ts +25 -0
- package/dist/conversations/media-types.js +38 -0
- package/dist/conversations/queue.d.ts +3 -1
- package/dist/conversations/queue.service.js +9 -2
- package/dist/conversations/titles.js +6 -0
- package/dist/ctx/create-ctx.js +1 -2
- package/dist/ctx/secrets.d.ts +24 -7
- package/dist/ctx/secrets.js +97 -30
- package/dist/db/kernel-schema.d.ts +17 -6
- package/dist/errors.d.ts +5 -2
- package/dist/errors.js +5 -2
- package/dist/evals/reconstruct.d.ts +4 -17
- package/dist/evals/reconstruct.js +13 -53
- package/dist/evals/recorded-tools.d.ts +0 -27
- package/dist/evals/recorded-tools.js +2 -92
- package/dist/evals/run-replay.d.ts +1 -6
- package/dist/evals/run-replay.js +10 -17
- package/dist/evals/sets.service.d.ts +17 -5
- package/dist/evals/sets.service.js +33 -12
- package/dist/evals/snapshot.d.ts +1 -2
- package/dist/evals/snapshot.js +4 -17
- package/dist/extensions/admin-ops.d.ts +6 -1
- package/dist/extensions/admin-ops.js +17 -4
- package/dist/extensions/admin-view.d.ts +7 -4
- package/dist/extensions/admin-view.js +27 -21
- package/dist/extensions/bootstrap.js +0 -1
- package/dist/extensions/cli.js +0 -1
- package/dist/extensions/host.d.ts +2 -3
- package/dist/extensions/host.js +1 -5
- package/dist/extensions/installs.d.ts +1 -3
- package/dist/extensions/instance.d.ts +0 -2
- package/dist/extensions/instance.js +0 -3
- package/dist/extensions/org-config.d.ts +4 -4
- package/dist/extensions/org-config.js +13 -22
- package/dist/extensions/package.d.ts +6 -6
- package/dist/extensions/package.js +3 -7
- package/dist/extensions/permission-view.d.ts +2 -4
- package/dist/extensions/plugin-items.d.ts +21 -1
- package/dist/extensions/plugin-items.js +28 -0
- package/dist/extensions/sync.js +5 -10
- package/dist/extensions/unavailable.js +0 -1
- package/dist/http/api.module.js +2 -1
- package/dist/identity/audit.d.ts +0 -12
- package/dist/identity/audit.js +0 -27
- package/dist/identity/auth.controller.js +5 -9
- package/dist/identity/cookies.d.ts +4 -9
- package/dist/identity/cookies.js +8 -32
- package/dist/identity/initial-passwords.d.ts +1 -1
- package/dist/identity/initial-passwords.js +1 -2
- package/dist/identity/sessions.d.ts +0 -6
- package/dist/identity/sessions.js +0 -18
- package/dist/inbox/platform-inbox.service.d.ts +33 -1
- package/dist/inbox/platform-inbox.service.js +56 -6
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
- package/dist/infra/cli/master-key-rewrap.js +24 -0
- package/dist/infra/config/kernel-config.service.js +0 -17
- package/dist/infra/health/health.controller.js +8 -0
- package/dist/infra/health/process-fault.d.ts +16 -0
- package/dist/infra/health/process-fault.js +49 -0
- package/dist/infra/lifecycle/process-guards.d.ts +8 -2
- package/dist/infra/lifecycle/process-guards.js +12 -3
- package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
- package/dist/infra/lifecycle/shutdown-signals.js +28 -13
- package/dist/infra/outbox/outbox.service.d.ts +12 -9
- package/dist/infra/outbox/outbox.service.js +22 -26
- package/dist/infra/outbox/registry.d.ts +15 -7
- package/dist/infra/outbox/registry.js +39 -23
- package/dist/lifecycle/kernel-lifecycle.js +1 -7
- package/dist/models/enablement.d.ts +5 -6
- package/dist/models/enablement.js +7 -14
- package/dist/orgs/orgs.module.d.ts +2 -2
- package/dist/orgs/orgs.module.js +2 -2
- package/dist/orgs/settings.controller.d.ts +3 -2
- package/dist/orgs/settings.service.d.ts +59 -14
- package/dist/orgs/settings.service.js +102 -20
- package/dist/overrides.d.ts +3 -7
- package/dist/overrides.js +2 -4
- package/dist/packages/tgz.d.ts +0 -2
- package/dist/packages/tgz.js +0 -2
- package/dist/platform/exclusions.js +0 -5
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/admin.ops.d.ts +2 -2
- package/dist/platform/ops/admin.ops.js +9 -6
- package/dist/platform/ops/agents.ops.js +1 -1
- package/dist/platform/ops/connectors.ops.js +46 -1
- package/dist/platform/ops/evals.ops.js +1 -64
- package/dist/platform/ops/extensions-admin.ops.js +1 -1
- package/dist/platform/ops/inbox.ops.js +16 -3
- package/dist/platform/ops/org-plugins.ops.js +1 -1
- package/dist/platform/ops/orgs.ops.d.ts +5 -3
- package/dist/platform/ops/orgs.ops.js +19 -4
- package/dist/platform/ops/outbox.ops.js +5 -5
- package/dist/roles/worker-role.d.ts +2 -3
- package/dist/roles/worker-role.js +3 -13
- package/dist/runtime/context/build.d.ts +56 -18
- package/dist/runtime/context/build.js +143 -50
- package/dist/runtime/context/compaction.d.ts +1 -3
- package/dist/runtime/context/compaction.js +42 -8
- package/dist/runtime/context/run-context.js +1 -2
- package/dist/runtime/context/skills.d.ts +27 -56
- package/dist/runtime/context/skills.js +42 -114
- package/dist/runtime/context/tool-changes.d.ts +3 -3
- package/dist/runtime/context/tool-changes.js +6 -16
- package/dist/runtime/hook-calls.d.ts +6 -6
- package/dist/runtime/hook-calls.js +7 -7
- package/dist/runtime/langgraph-loop.js +1 -0
- package/dist/runtime/maintenance.d.ts +3 -11
- package/dist/runtime/maintenance.js +5 -20
- package/dist/runtime/model-call.d.ts +5 -0
- package/dist/runtime/model-call.js +48 -36
- package/dist/runtime/providers.d.ts +33 -35
- package/dist/runtime/providers.js +64 -109
- package/dist/runtime/run-context.service.js +7 -22
- package/dist/runtime/run-deletion.d.ts +6 -0
- package/dist/runtime/run-deletion.js +39 -16
- package/dist/runtime/run-execution.js +4 -3
- package/dist/runtime/run-finish.js +2 -1
- package/dist/runtime/run-liveness.d.ts +11 -0
- package/dist/runtime/run-liveness.js +19 -0
- package/dist/runtime/run-orphan-check.job.js +2 -1
- package/dist/runtime/run-queue.js +8 -16
- package/dist/runtime/run-worker.d.ts +2 -2
- package/dist/runtime/run-worker.js +8 -6
- package/dist/runtime/subagents/definition.d.ts +16 -20
- package/dist/runtime/subagents/definition.js +27 -27
- package/dist/runtime/subagents/dispatch.d.ts +6 -2
- package/dist/runtime/subagents/dispatch.js +17 -3
- package/dist/runtime/subagents/org-agents.js +1 -2
- package/dist/runtime/subagents/preamble.d.ts +3 -2
- package/dist/runtime/subagents/preamble.js +3 -2
- package/dist/runtime/subagents/render.d.ts +1 -2
- package/dist/runtime/subagents/render.js +1 -2
- package/dist/runtime/subagents/skill-fork.d.ts +2 -4
- package/dist/runtime/subagents/template-skills.d.ts +47 -0
- package/dist/runtime/subagents/template-skills.js +76 -0
- package/dist/schedules/effective-settings.d.ts +9 -3
- package/dist/schedules/effective-settings.js +5 -4
- package/dist/schedules/fire.js +11 -0
- package/dist/schedules/scheduled-tasks.service.js +5 -0
- package/dist/schedules/unattended.d.ts +2 -0
- package/dist/schedules/unattended.js +6 -1
- package/dist/skills/agent-skills.service.js +1 -2
- package/dist/skills/catalog.d.ts +1 -3
- package/dist/skills/catalog.js +1 -3
- package/dist/skills/conversation-catalog.d.ts +1 -2
- package/dist/skills/conversation-catalog.js +1 -2
- package/dist/skills/usable.js +2 -3
- package/dist/storage/storage.service.js +9 -1
- package/dist/tools/approvals.service.js +2 -4
- package/dist/tools/builtin-names.d.ts +2 -9
- package/dist/tools/builtin-names.js +4 -13
- package/dist/tools/builtins/sandbox/bash.js +3 -3
- package/dist/tools/builtins/sandbox/common.d.ts +7 -13
- package/dist/tools/builtins/sandbox/common.js +8 -115
- package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
- package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
- package/dist/tools/builtins/sandbox/glob.js +1 -3
- package/dist/tools/builtins/sandbox/grep.js +3 -5
- package/dist/tools/builtins/sandbox/index.d.ts +8 -5
- package/dist/tools/builtins/sandbox/index.js +10 -5
- package/dist/tools/builtins/sandbox/read.js +3 -2
- package/dist/tools/builtins/tool-search.d.ts +4 -7
- package/dist/tools/builtins/tool-search.js +6 -10
- package/dist/tools/connector-account-policies.d.ts +30 -3
- package/dist/tools/connector-account-policies.js +54 -7
- package/dist/tools/connectors.controller.d.ts +24 -11
- package/dist/tools/connectors.controller.js +35 -6
- package/dist/tools/connectors.schemas.d.ts +14 -1
- package/dist/tools/connectors.schemas.js +14 -2
- package/dist/tools/connectors.service.d.ts +22 -0
- package/dist/tools/connectors.service.js +56 -0
- package/dist/tools/drift.d.ts +1 -1
- package/dist/tools/drift.js +1 -1
- package/dist/tools/git-push-policy.d.ts +4 -1
- package/dist/tools/git-push-policy.js +3 -1
- package/dist/tools/info.d.ts +1 -7
- package/dist/tools/info.js +5 -18
- package/dist/tools/job-ids.d.ts +0 -4
- package/dist/tools/job-ids.js +1 -6
- package/dist/tools/pipeline.d.ts +4 -10
- package/dist/tools/pipeline.js +16 -62
- package/dist/tools/policy.d.ts +6 -2
- package/dist/tools/policy.js +14 -12
- package/dist/tools/registry.js +1 -5
- package/dist/ui/views.d.ts +5 -5
- package/dist/ui/views.js +10 -16
- package/package.json +3 -3
- package/src/migrations/0137_audit_org_idx.sql +5 -0
- package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
- package/src/migrations/0139_retire_legacy_forms.sql +183 -0
- package/src/migrations/0140_retire_history_forms.sql +148 -0
- package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
- package/src/migrations/0142_backfill_event_fields.sql +74 -0
- package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
- package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
- package/dist/admin/platform-audit.service.d.ts +0 -41
- package/dist/conversations/job-ids.d.ts +0 -6
- package/dist/conversations/job-ids.js +0 -6
- package/dist/extensions/job-ids.d.ts +0 -6
- package/dist/extensions/job-ids.js +0 -6
- package/dist/infra/queue/retired-schedulers.d.ts +0 -7
- package/dist/infra/queue/retired-schedulers.js +0 -9
- package/dist/orgs/job-ids.d.ts +0 -8
- package/dist/orgs/job-ids.js +0 -8
- package/dist/runtime/context/legacy-text.d.ts +0 -22
- package/dist/runtime/context/legacy-text.js +0 -37
- package/dist/runtime/job-ids.d.ts +0 -10
- package/dist/runtime/job-ids.js +0 -10
- package/dist/runtime/retired-schedulers.d.ts +0 -7
- package/dist/runtime/retired-schedulers.js +0 -31
- package/dist/storage/job-ids.d.ts +0 -6
- package/dist/storage/job-ids.js +0 -6
- package/dist/tools/legacy-data.d.ts +0 -34
- package/dist/tools/legacy-data.js +0 -76
- package/dist/tools/legacy-keys.d.ts +0 -51
- package/dist/tools/legacy-keys.js +0 -114
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_SANDBOX_ROOTS, DeviceProtocolError, isFileSystemGoneError,
|
|
1
|
+
import { DEFAULT_SANDBOX_ROOTS, DeviceProtocolError, isFileSystemGoneError, ToolError, validateSandboxPath, validateSandboxPathShape, } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { ANONYMOUS_NO_DEVICE, } from "../../../devices/conversation-devices.js";
|
|
3
3
|
import { workingRootOf } from "../../../devices/working-root.js";
|
|
4
4
|
import { ApiError } from "../../../errors.js";
|
|
@@ -70,19 +70,6 @@ export const ATTACHMENTS_ROOT = attachmentsRoot(DEFAULT_SANDBOX_ROOTS);
|
|
|
70
70
|
* UUID, so conversations sharing a device do not overwrite each other's files.
|
|
71
71
|
*/
|
|
72
72
|
export const attachmentsDir = (roots, rootConversationId) => `${attachmentsRoot(roots)}/${rootConversationId.replaceAll("-", "").slice(0, 12)}`;
|
|
73
|
-
/** The conversation's marker of synced attachments: `{ <attachment id>: <file name> }`. */
|
|
74
|
-
export const syncMarkerPath = (roots, rootConversationId) => `${attachmentsDir(roots, rootConversationId)}/.capybara-sync.json`;
|
|
75
|
-
const SYNC_MARKER_NAME = ".capybara-sync.json";
|
|
76
|
-
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
77
|
-
/**
|
|
78
|
-
* Whether a path, or a Grep output line starting with one, belongs to a sync marker of the
|
|
79
|
-
* instance with `roots` (hidden from Glob / Grep). Build it once per call and test every entry.
|
|
80
|
-
*/
|
|
81
|
-
export function syncMarkerMatcher(roots = DEFAULT_SANDBOX_ROOTS) {
|
|
82
|
-
const re = new RegExp(`^${escapeRe(attachmentsRoot(roots))}/[^/]+/${escapeRe(SYNC_MARKER_NAME)}(?=$|[:-])`);
|
|
83
|
-
return (pathOrLine) => re.test(pathOrLine);
|
|
84
|
-
}
|
|
85
|
-
const MARKER_MAX_BYTES = 1024 * 1024;
|
|
86
73
|
/** 附件文件名的上限(UTF-8 字节,常见文件系统单个文件名上限 255 字节,留出 `-N` 后缀的余量)。 */
|
|
87
74
|
export const ATTACHMENT_NAME_MAX_BYTES = 200;
|
|
88
75
|
/**
|
|
@@ -216,7 +203,6 @@ export function checkToolWritable(path, s) {
|
|
|
216
203
|
export function shellQuote(s) {
|
|
217
204
|
return `'${s.replace(/'/g, `'\\''`)}'`;
|
|
218
205
|
}
|
|
219
|
-
const utf8 = new TextEncoder();
|
|
220
206
|
const byteLength = (s) => Buffer.byteLength(s, "utf8");
|
|
221
207
|
/** 拆成主名与扩展名(扩展名不超过 20 字节,`.` 开头的隐藏文件没有扩展名)。 */
|
|
222
208
|
function splitExt(n) {
|
|
@@ -250,12 +236,11 @@ function sanitizeName(raw) {
|
|
|
250
236
|
}
|
|
251
237
|
/**
|
|
252
238
|
* 给附件分配沙箱里的文件名(按给定顺序,确定性):清理成安全的路径段(≤ {@link ATTACHMENT_NAME_MAX_BYTES}
|
|
253
|
-
* 字节),与 `used
|
|
239
|
+
* 字节),与 `used`(已占用的)及彼此不重名,重名时加 `-2`、`-3`……(加在扩展名之前)。
|
|
254
240
|
* 清理后仍不是合法沙箱路径的用 `attachment-<id 前 8 位>`。
|
|
255
241
|
*/
|
|
256
242
|
export function assignAttachmentNames(items, used) {
|
|
257
243
|
const taken = new Set(used);
|
|
258
|
-
taken.add(SYNC_MARKER_NAME);
|
|
259
244
|
const out = new Map();
|
|
260
245
|
for (const a of items) {
|
|
261
246
|
let base = sanitizeName(a.name);
|
|
@@ -273,94 +258,6 @@ export function assignAttachmentNames(items, used) {
|
|
|
273
258
|
}
|
|
274
259
|
return out;
|
|
275
260
|
}
|
|
276
|
-
/** 解析标记文件;坏的按空处理(重新同步,同名文件被覆盖)。 */
|
|
277
|
-
function parseMarker(data) {
|
|
278
|
-
try {
|
|
279
|
-
const v = JSON.parse(new TextDecoder().decode(data));
|
|
280
|
-
if (v === null || typeof v !== "object" || Array.isArray(v))
|
|
281
|
-
return {};
|
|
282
|
-
return Object.fromEntries(Object.entries(v).filter((e) => typeof e[1] === "string"));
|
|
283
|
-
}
|
|
284
|
-
catch {
|
|
285
|
-
return {};
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
/** 一个附件复制失败时给模型的原因(不带内部细节)。 */
|
|
289
|
-
function copyFailureReason(e) {
|
|
290
|
-
if (e instanceof ApiError && e.code === "storage.unavailable") {
|
|
291
|
-
return "file storage is unavailable";
|
|
292
|
-
}
|
|
293
|
-
return "a temporary error occurred; it will be retried on the next sandbox call";
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* 把本对话已 ready 的附件复制到 `<workspace>/attachments/<conversation>/<name>`({@link attachmentsDir}),
|
|
297
|
-
* 标记文件记下已复制的(不重复复制)。对象已不在的附件跳过(下次再试)。
|
|
298
|
-
* 每复制一个就更新标记文件:中途超时 / 中止,下次从停下的地方继续。
|
|
299
|
-
* 单个附件失败(存储故障等)只跳过它并给出说明,不让工具调用失败;signal 已中止或实例已不在时照常抛出。
|
|
300
|
-
* 返回本次复制的沙箱路径与失败说明。
|
|
301
|
-
*/
|
|
302
|
-
async function syncAttachments(deps, ctx, s) {
|
|
303
|
-
const none = { copied: [], failures: [] };
|
|
304
|
-
const conv = sandboxConversationOf(ctx);
|
|
305
|
-
const list = await deps.attachments.listForConversation(ctx.orgId, conv);
|
|
306
|
-
if (list.length === 0)
|
|
307
|
-
return none;
|
|
308
|
-
// nothing to copy (the usual case): no path lease, so calls do not queue on the marker
|
|
309
|
-
const marker = await readSyncMarker(s, conv);
|
|
310
|
-
if (list.every((a) => Object.hasOwn(marker, a.id)))
|
|
311
|
-
return none;
|
|
312
|
-
// the sync marker is read, changed and written: one holder at a time
|
|
313
|
-
return withPathLease(deps, s, syncMarkerPath(s.roots, conv), s.signal, (signal) => copyAttachments(deps, ctx, { ...s, signal }, conv, list));
|
|
314
|
-
}
|
|
315
|
-
/** The sync marker's entries (`{}` when it is missing, too large or unreadable). */
|
|
316
|
-
async function readSyncMarker(s, conv) {
|
|
317
|
-
const m = await s.p.readFile(s.h, syncMarkerPath(s.roots, conv), {
|
|
318
|
-
maxBytes: MARKER_MAX_BYTES,
|
|
319
|
-
signal: s.signal,
|
|
320
|
-
});
|
|
321
|
-
return m && !m.truncated ? parseMarker(m.data) : {};
|
|
322
|
-
}
|
|
323
|
-
async function copyAttachments(deps, ctx, s, conv, list) {
|
|
324
|
-
const none = { copied: [], failures: [] };
|
|
325
|
-
let marker = await readSyncMarker(s, conv);
|
|
326
|
-
const pending = list.filter((a) => !Object.hasOwn(marker, a.id));
|
|
327
|
-
if (pending.length === 0)
|
|
328
|
-
return none;
|
|
329
|
-
const names = assignAttachmentNames(pending, new Set(Object.values(marker)));
|
|
330
|
-
const copied = [];
|
|
331
|
-
const failures = [];
|
|
332
|
-
for (const a of pending) {
|
|
333
|
-
const name = names.get(a.id);
|
|
334
|
-
const path = `${attachmentsDir(s.roots, conv)}/${name}`;
|
|
335
|
-
try {
|
|
336
|
-
const opened = await deps.attachments.openForConversation(ctx.orgId, conv, a.id);
|
|
337
|
-
if (!opened)
|
|
338
|
-
continue;
|
|
339
|
-
const bytes = new Uint8Array(await new Response(opened.body).arrayBuffer());
|
|
340
|
-
await s.p.writeFile(s.h, path, bytes, s.signal);
|
|
341
|
-
}
|
|
342
|
-
catch (e) {
|
|
343
|
-
// 中止(超时 / 锁丢失 / 运行停止)与实例已不在(withSandbox 据此重建)不吞
|
|
344
|
-
if (s.signal.aborted || isSandboxGoneError(e))
|
|
345
|
-
throw e;
|
|
346
|
-
failures.push(`Attachment ${name} could not be copied: ${copyFailureReason(e)}.`);
|
|
347
|
-
continue;
|
|
348
|
-
}
|
|
349
|
-
// 文件已复制:本次算复制成功。标记写成功后才记进内存里的标记(之后的写入不带上未落盘的项);
|
|
350
|
-
// 标记写失败只意味着下次会重新复制这个文件
|
|
351
|
-
copied.push(path);
|
|
352
|
-
const next = { ...marker, [a.id]: name };
|
|
353
|
-
try {
|
|
354
|
-
await s.p.writeFile(s.h, syncMarkerPath(s.roots, conv), utf8.encode(JSON.stringify(next)), s.signal);
|
|
355
|
-
marker = next;
|
|
356
|
-
}
|
|
357
|
-
catch (e) {
|
|
358
|
-
if (s.signal.aborted || isSandboxGoneError(e))
|
|
359
|
-
throw e;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
return { copied, failures };
|
|
363
|
-
}
|
|
364
261
|
/**
|
|
365
262
|
* A machine that reports auto mode while the organization allows only sandbox mode (auto mode
|
|
366
263
|
* spec §4.3): the kernel's refusal text plus what the model can do.
|
|
@@ -432,11 +329,12 @@ export function mapSandboxError(e, log) {
|
|
|
432
329
|
* Runs `fn` in the device of the call's conversation (a sub-agent: its root's): resolves and
|
|
433
330
|
* checks the device for the conversation's owner (binding an unbound conversation to the
|
|
434
331
|
* owner's default first), then `SandboxService.withSandbox` (the instance created, resumed or
|
|
435
|
-
* rebuilt on the kept files as needed, every `exec` carrying the call's actor).
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
-
* `fn` again, the notices are the last call's. The instance's roots are recorded
|
|
439
|
-
* on the conversation's first call and whenever they change
|
|
332
|
+
* rebuilt on the kept files as needed, every `exec` carrying the call's actor). It never touches
|
|
333
|
+
* attachments: `FetchAttachment` is the only way one enters the device. Returns the value and the
|
|
334
|
+
* notices to put before the result (first use, a new instance). When `withSandbox` rebuilds a gone
|
|
335
|
+
* instance and calls `fn` again, the notices are the last call's. The instance's roots are recorded
|
|
336
|
+
* for the model on the conversation's first call and whenever they change
|
|
337
|
+
* ({@link recordDevicePaths}).
|
|
440
338
|
*/
|
|
441
339
|
export async function inSandbox(deps, ctx, fn) {
|
|
442
340
|
try {
|
|
@@ -482,11 +380,6 @@ export async function inSandbox(deps, ctx, fn) {
|
|
|
482
380
|
notices.push(SANDBOX_RESTARTED_NOTICE);
|
|
483
381
|
else if (info.fresh)
|
|
484
382
|
notices.push(sandboxStartedNotice(info.roots, s.workingRoot));
|
|
485
|
-
const { copied, failures } = await syncAttachments(deps, ctx, s);
|
|
486
|
-
if (copied.length > 0) {
|
|
487
|
-
notices.push(`Attachments copied into the sandbox: ${copied.join(", ")}.`);
|
|
488
|
-
}
|
|
489
|
-
notices.push(...failures);
|
|
490
383
|
return { value: await fn(s), notices };
|
|
491
384
|
}, ctx.signal);
|
|
492
385
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BuiltinTool } from "../../registry.js";
|
|
2
|
+
import { type SandboxToolDeps } from "./common.js";
|
|
3
|
+
/**
|
|
4
|
+
* The builtin `FetchAttachment`: copy one attachment of this conversation into the device
|
|
5
|
+
* ({@link attachmentsDir}); it runs nothing. Names come from the conversation's whole attachment
|
|
6
|
+
* list ({@link assignAttachmentNames}), so a given attachment always lands on the same path;
|
|
7
|
+
* copying it twice writes the same bytes and returns the same path. A failure is an ordinary tool
|
|
8
|
+
* error and the run continues.
|
|
9
|
+
*/
|
|
10
|
+
export declare function sandboxFetchAttachmentTool(deps: SandboxToolDeps): BuiltinTool;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { isFileSystemGoneError, isSandboxGoneError, ToolError, } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { ApiError } from "../../../errors.js";
|
|
3
|
+
import { assignAttachmentNames, attachmentsDir, clip, display, inSandbox, sandboxBaseTimeoutMs, sandboxConversationOf, unavailableWhenNoSandbox, withNotices, } from "./common.js";
|
|
4
|
+
const SPEC = {
|
|
5
|
+
name: "FetchAttachment",
|
|
6
|
+
// Display only (the tool row; not in the fingerprint, never sent to the model).
|
|
7
|
+
keyArgs: ["file"],
|
|
8
|
+
description: "Copy a file the user attached to this conversation into the device, so you can open it with Bash or the file tools. " +
|
|
9
|
+
"Attachments are not in the device until this call; the user's message names each file and, for a file the model cannot read, " +
|
|
10
|
+
"its unsigned reference. Pass the file name as the message shows it, that reference, or the attachment id. " +
|
|
11
|
+
"The file is written under the workspace's attachments directory, and a given file always lands on the same path.",
|
|
12
|
+
inputSchema: {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
file: {
|
|
16
|
+
type: "string",
|
|
17
|
+
minLength: 1,
|
|
18
|
+
description: "The attachment's file name as the user's message shows it, its unsigned object reference, or its id.",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
required: ["file"],
|
|
22
|
+
additionalProperties: false,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
/** Attachment ids are lower-case UUIDs; the reference's last path segment is the id. */
|
|
26
|
+
const ATTACHMENT_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
27
|
+
const noAttachmentsText = (file) => `No attachment named "${clip(file, 200)}"; this conversation has no attachments. Ask the user to send the file, then retry.`;
|
|
28
|
+
const unknownFileText = (file, list) => `No attachment named "${clip(file, 200)}"; this conversation has: ${list
|
|
29
|
+
.slice(0, 5)
|
|
30
|
+
.map((a) => clip(a.name, 200))
|
|
31
|
+
.join(", ")}. Use the name as the attachment line shows it, its reference or its id.`;
|
|
32
|
+
const goneText = (name) => `Attachment "${clip(name, 200)}" is no longer in this conversation: it was deleted, or its upload did not finish. Ask the user to send it again, then retry.`;
|
|
33
|
+
const storageText = (name) => `File storage is unavailable, so "${clip(name, 200)}" could not be copied; ask an administrator to check the deployment's object store, then retry.`;
|
|
34
|
+
const copyFailedText = (name) => `Copying "${clip(name, 200)}" into the device failed (a temporary error); retry the call, or check that the device has free space.`;
|
|
35
|
+
/**
|
|
36
|
+
* The attachment `file` names, among the conversation's ready ones (the caller's list): the exact
|
|
37
|
+
* file name, then the name the copy assigns it (a sanitized or de-duplicated name shown in an
|
|
38
|
+
* earlier result's path), then the bare attachment id or a reference whose last path segment is the
|
|
39
|
+
* id (`s3://<bucket>/<key>/attachments/<id>`, `capybara://attachments/<id>`). Names are exact and
|
|
40
|
+
* case-sensitive; nothing else resolves.
|
|
41
|
+
*/
|
|
42
|
+
function resolveAttachment(file, list, assigned) {
|
|
43
|
+
const byName = list.find((a) => a.name === file);
|
|
44
|
+
if (byName !== undefined)
|
|
45
|
+
return byName;
|
|
46
|
+
const byAssigned = list.find((a) => assigned.get(a.id) === file);
|
|
47
|
+
if (byAssigned !== undefined)
|
|
48
|
+
return byAssigned;
|
|
49
|
+
const tail = file.slice(file.lastIndexOf("/") + 1);
|
|
50
|
+
if (!ATTACHMENT_ID.test(tail))
|
|
51
|
+
return undefined;
|
|
52
|
+
const id = tail.toLowerCase();
|
|
53
|
+
return list.find((a) => a.id.toLowerCase() === id);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The builtin `FetchAttachment`: copy one attachment of this conversation into the device
|
|
57
|
+
* ({@link attachmentsDir}); it runs nothing. Names come from the conversation's whole attachment
|
|
58
|
+
* list ({@link assignAttachmentNames}), so a given attachment always lands on the same path;
|
|
59
|
+
* copying it twice writes the same bytes and returns the same path. A failure is an ordinary tool
|
|
60
|
+
* error and the run continues.
|
|
61
|
+
*/
|
|
62
|
+
export function sandboxFetchAttachmentTool(deps) {
|
|
63
|
+
return {
|
|
64
|
+
spec: SPEC,
|
|
65
|
+
defaultPolicy: "allow",
|
|
66
|
+
unavailable: unavailableWhenNoSandbox(deps),
|
|
67
|
+
timeoutMs: () => sandboxBaseTimeoutMs(deps.config.get()),
|
|
68
|
+
async run(input, ctx) {
|
|
69
|
+
const file = input.file;
|
|
70
|
+
const conv = sandboxConversationOf(ctx);
|
|
71
|
+
// the list is read before any device is touched: an unknown file starts no device
|
|
72
|
+
const list = await deps.attachments.listForConversation(ctx.orgId, conv);
|
|
73
|
+
const assigned = assignAttachmentNames(list, new Set());
|
|
74
|
+
const attachment = resolveAttachment(file, list, assigned);
|
|
75
|
+
if (attachment === undefined) {
|
|
76
|
+
if (list.length === 0)
|
|
77
|
+
throw new ToolError(noAttachmentsText(file));
|
|
78
|
+
throw new ToolError(unknownFileText(file, list));
|
|
79
|
+
}
|
|
80
|
+
// the whole list names the file, so its name never changes between calls; the path's last
|
|
81
|
+
// segment is only ever the sanitized, de-duplicated name the assignment gave it (never the
|
|
82
|
+
// raw name, which may hold `/` or `..`). Every row of the list gets one, so a miss means the
|
|
83
|
+
// list changed under this call: write nothing and answer as for an unknown file.
|
|
84
|
+
const name = assigned.get(attachment.id);
|
|
85
|
+
if (name === undefined)
|
|
86
|
+
throw new ToolError(unknownFileText(file, list));
|
|
87
|
+
const { value, notices } = await inSandbox(deps, ctx, async ({ h, roots, p, signal }) => {
|
|
88
|
+
const path = `${attachmentsDir(roots, conv)}/${name}`;
|
|
89
|
+
let bytes;
|
|
90
|
+
try {
|
|
91
|
+
const opened = await deps.attachments.openForConversation(ctx.orgId, conv, attachment.id);
|
|
92
|
+
if (opened === null)
|
|
93
|
+
throw new ToolError(goneText(name));
|
|
94
|
+
bytes = new Uint8Array(await new Response(opened.body).arrayBuffer());
|
|
95
|
+
await p.writeFile(h, path, bytes, signal);
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
// an abort (timeout / lost lock / stopped run) and a gone device or instance go to
|
|
99
|
+
// withSandbox and mapSandboxError; never the provider's own words (they may name its
|
|
100
|
+
// internal address)
|
|
101
|
+
if (signal.aborted || isSandboxGoneError(e) || isFileSystemGoneError(e))
|
|
102
|
+
throw e;
|
|
103
|
+
if (e instanceof ToolError)
|
|
104
|
+
throw e;
|
|
105
|
+
if (e instanceof ApiError && e.code === "storage.unavailable") {
|
|
106
|
+
throw new ToolError(storageText(name));
|
|
107
|
+
}
|
|
108
|
+
throw new ToolError(copyFailedText(name));
|
|
109
|
+
}
|
|
110
|
+
return { path, size: bytes.byteLength };
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
content: [{ type: "text", text: withNotices(notices, `Copied ${name} to ${value.path}.`) }],
|
|
114
|
+
// the row names the file and its size; the path is in the result's text
|
|
115
|
+
display: display(`复制 ${clip(name, 170)}(${value.size} 字节)`, `Copied ${clip(name, 170)} (${value.size} bytes)`),
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ToolError } from "@capybara-hq/plugin-sdk";
|
|
2
|
-
import { checkPathShape, checkToolPath, clip, display, inSandbox, sandboxBaseTimeoutMs, searchTimeoutMs,
|
|
2
|
+
import { checkPathShape, checkToolPath, clip, display, inSandbox, sandboxBaseTimeoutMs, searchTimeoutMs, unavailableWhenNoSandbox, withNotices, } from "./common.js";
|
|
3
3
|
import { compileGlob, GlobPatternError } from "./glob-match.js";
|
|
4
4
|
/** 最多列出的文件数。 */
|
|
5
5
|
const MAX_RESULTS = 1000;
|
|
@@ -84,13 +84,11 @@ export function sandboxGlobTool(deps) {
|
|
|
84
84
|
if (r.truncated)
|
|
85
85
|
names.pop();
|
|
86
86
|
const base = dir === "/" ? "" : dir;
|
|
87
|
-
const isMarker = syncMarkerMatcher(s.roots);
|
|
88
87
|
return (names
|
|
89
88
|
.filter((l) => l.startsWith("./"))
|
|
90
89
|
.map((l) => l.slice(2))
|
|
91
90
|
.filter((rel) => matches(rel))
|
|
92
91
|
.map((rel) => `${base}/${rel}`)
|
|
93
|
-
.filter((abs) => !isMarker(abs))
|
|
94
92
|
.sort()
|
|
95
93
|
// 文件名里的换行显示为 `\n`(与 Grep 一致),一行一个文件
|
|
96
94
|
.map((abs) => abs.replace(/\n/g, "\\n")));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ToolError } from "@capybara-hq/plugin-sdk";
|
|
2
|
-
import { checkPathShape, checkToolPath, clip, display, inSandbox, sandboxBaseTimeoutMs, searchTimeoutMs, shellQuote,
|
|
2
|
+
import { checkPathShape, checkToolPath, clip, display, inSandbox, sandboxBaseTimeoutMs, searchTimeoutMs, shellQuote, unavailableWhenNoSandbox, withNotices, } from "./common.js";
|
|
3
3
|
/** The most output entries (lines, files or counts) returned in one call, whatever `head_limit` says. */
|
|
4
4
|
const MAX_MATCHES = 500;
|
|
5
5
|
/** `head_limit` when the model gives none. */
|
|
@@ -212,13 +212,11 @@ export function sandboxGrepTool(deps) {
|
|
|
212
212
|
: mode === "count"
|
|
213
213
|
? parseCounts(r.stdout, base)
|
|
214
214
|
: parseGrepNull(r.stdout, base, numbered);
|
|
215
|
-
|
|
216
|
-
const entries = all.filter((l) => !isMarker(l));
|
|
217
|
-
// 退出码 2 = 有错误(如个别文件不可读);有输出时照常返回(可能为空:只匹配到隐藏的标记文件)并附上说明
|
|
215
|
+
// 退出码 2 = 有错误(如个别文件不可读);有输出时照常返回并附上说明
|
|
218
216
|
if (r.exitCode !== 0 && all.length === 0)
|
|
219
217
|
throw new ToolError(failed(r.stderr));
|
|
220
218
|
const warning = r.exitCode !== 0 ? clip(r.stderr, 300) : null;
|
|
221
|
-
return { entries, warning };
|
|
219
|
+
return { entries: all, warning };
|
|
222
220
|
});
|
|
223
221
|
const { entries, warning } = value;
|
|
224
222
|
const total = entries.length;
|
|
@@ -3,13 +3,16 @@ import type { SandboxToolDeps } from "./common.js";
|
|
|
3
3
|
export { SANDBOX_ASK_TOOL_NAMES, SANDBOX_TOOL_NAMES } from "../../builtin-names.js";
|
|
4
4
|
export { BASH_SPILL_CHARS, formatExec } from "./bash.js";
|
|
5
5
|
export { assignAttachmentNames, RUN_DEADLINE_MARGIN_MS, runTimeLeftMs, SANDBOX_RESTARTED_NOTICE, SANDBOX_SETUP_MARGIN_MS, SANDBOX_STARTED_NOTICE, SANDBOX_UNAVAILABLE_REASON, type SandboxToolDeps, sandboxBaseTimeoutMs, sandboxStartedNotice, sandboxUsable, searchTimeoutMs, shellQuote, } from "./common.js";
|
|
6
|
+
export { sandboxFetchAttachmentTool } from "./fetch-attachment.js";
|
|
6
7
|
export { compileGlob, GlobPatternError, MAX_GLOB_STARS } from "./glob-match.js";
|
|
7
8
|
/**
|
|
8
|
-
* The sandbox builtins (M5 T8): Bash / Read / Write / Edit / Glob / Grep / Deliver
|
|
9
|
-
* conversation's device (`SandboxService.withSandbox`)
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* The sandbox builtins (M5 T8): Bash / Read / Write / Edit / Glob / Grep / Deliver / FetchAttachment,
|
|
10
|
+
* all run in the conversation's device (`SandboxService.withSandbox`). Attachments are not copied
|
|
11
|
+
* into it by a sandbox call: `FetchAttachment` is the only way in, writing one file under
|
|
12
|
+
* `<workspace>/attachments/<conversation>` (the instance's roots, environments spec §13.1).
|
|
13
|
+
* Unavailable without a provider for it. Allowed by default; with the org setting
|
|
14
|
+
* `sandboxToolPolicy` set to ask, every one but Read / Glob / Grep / FetchAttachment needs approval
|
|
15
|
+
* (see policy.ts).
|
|
13
16
|
* `TaskOutput` and `TaskStop` read and stop background `Bash` tasks through
|
|
14
17
|
* `SandboxService.ifRunning` (never creating or resuming a sandbox); `TaskList` lists them and the
|
|
15
18
|
* conversation's sub-agents from PG; all three always allowed.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { sandboxBashTool } from "./bash.js";
|
|
2
2
|
import { sandboxDeliverTool } from "./deliver.js";
|
|
3
3
|
import { sandboxEditTool } from "./edit.js";
|
|
4
|
+
import { sandboxFetchAttachmentTool } from "./fetch-attachment.js";
|
|
4
5
|
import { sandboxGlobTool } from "./glob.js";
|
|
5
6
|
import { sandboxGrepTool } from "./grep.js";
|
|
6
7
|
import { sandboxReadTool } from "./read.js";
|
|
@@ -11,13 +12,16 @@ import { sandboxWriteTool } from "./write.js";
|
|
|
11
12
|
export { SANDBOX_ASK_TOOL_NAMES, SANDBOX_TOOL_NAMES } from "../../builtin-names.js";
|
|
12
13
|
export { BASH_SPILL_CHARS, formatExec } from "./bash.js";
|
|
13
14
|
export { assignAttachmentNames, RUN_DEADLINE_MARGIN_MS, runTimeLeftMs, SANDBOX_RESTARTED_NOTICE, SANDBOX_SETUP_MARGIN_MS, SANDBOX_STARTED_NOTICE, SANDBOX_UNAVAILABLE_REASON, sandboxBaseTimeoutMs, sandboxStartedNotice, sandboxUsable, searchTimeoutMs, shellQuote, } from "./common.js";
|
|
15
|
+
export { sandboxFetchAttachmentTool } from "./fetch-attachment.js";
|
|
14
16
|
export { compileGlob, GlobPatternError, MAX_GLOB_STARS } from "./glob-match.js";
|
|
15
17
|
/**
|
|
16
|
-
* The sandbox builtins (M5 T8): Bash / Read / Write / Edit / Glob / Grep / Deliver
|
|
17
|
-
* conversation's device (`SandboxService.withSandbox`)
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
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
|
|
21
|
+
* `<workspace>/attachments/<conversation>` (the instance's roots, environments spec §13.1).
|
|
22
|
+
* Unavailable without a provider for it. Allowed by default; with the org setting
|
|
23
|
+
* `sandboxToolPolicy` set to ask, every one but Read / Glob / Grep / FetchAttachment needs approval
|
|
24
|
+
* (see policy.ts).
|
|
21
25
|
* `TaskOutput` and `TaskStop` read and stop background `Bash` tasks through
|
|
22
26
|
* `SandboxService.ifRunning` (never creating or resuming a sandbox); `TaskList` lists them and the
|
|
23
27
|
* conversation's sub-agents from PG; all three always allowed.
|
|
@@ -31,6 +35,7 @@ export function sandboxTools(deps) {
|
|
|
31
35
|
sandboxGlobTool(deps),
|
|
32
36
|
sandboxGrepTool(deps),
|
|
33
37
|
sandboxDeliverTool(deps),
|
|
38
|
+
sandboxFetchAttachmentTool(deps),
|
|
34
39
|
taskOutputTool(deps),
|
|
35
40
|
taskStopTool(deps),
|
|
36
41
|
taskListTool(deps),
|
|
@@ -13,8 +13,9 @@ const SPEC = {
|
|
|
13
13
|
// Display only (the tool row; not in the fingerprint, never sent to the model).
|
|
14
14
|
keyArgs: ["file_path"],
|
|
15
15
|
description: "Read a text file from this conversation's sandbox, with line numbers. Use it to look at " +
|
|
16
|
-
"source code, data files, logs and files the user attached (
|
|
17
|
-
"the workspace directory). Paths are absolute,
|
|
16
|
+
"source code, data files, logs and files the user attached (not in the device until " +
|
|
17
|
+
"FetchAttachment copies one into the workspace's attachments directory). Paths are absolute, " +
|
|
18
|
+
"under the workspace directory, the skills " +
|
|
18
19
|
"directory or the temporary files directory. Lines are numbered from 1; pass " +
|
|
19
20
|
"offset and limit to read part of a long file. Binary files are not shown; use Bash " +
|
|
20
21
|
"to inspect them. Do not use it to list directories; use Glob instead. Read a file before you " +
|
|
@@ -6,10 +6,7 @@ export declare const TOOL_SEARCH_SPEC: ToolSpec;
|
|
|
6
6
|
export declare const CATALOG_HEADER: string;
|
|
7
7
|
/** 调用目录里尚未加载的工具(模型可见,英文;spec 5.5:不自动加载)。 */
|
|
8
8
|
export declare const notLoadedText: (key: string) => string;
|
|
9
|
-
/**
|
|
10
|
-
* 始终完整加载、不进目录的工具(内置工具)。A release-candidate builtin key counts too: a request
|
|
11
|
-
* recorded before the tool rename is rebuilt with its old keys, and its builtins were loaded.
|
|
12
|
-
*/
|
|
9
|
+
/** Tools always loaded in full and never in the catalog (the builtins). */
|
|
13
10
|
export declare const isAlwaysLoaded: (key: string) => boolean;
|
|
14
11
|
type CatalogTool = Pick<ResolvedTool, "key" | "spec">;
|
|
15
12
|
/** 分词:切开驼峰,按非字母数字切分,转小写。 */
|
|
@@ -23,10 +20,10 @@ export declare function searchTools<T extends CatalogTool>(query: string, tools:
|
|
|
23
20
|
/** 目录行:`- <key>: <描述的第一行>`(超长截断)。 */
|
|
24
21
|
export declare function catalogLine(t: CatalogTool): string;
|
|
25
22
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
23
|
+
* The catalog text: the header, then one line per tool sorted by key. It depends only on the tool
|
|
24
|
+
* set, never on what is loaded (a stable cache prefix).
|
|
28
25
|
*/
|
|
29
|
-
export declare function catalogText(tools: readonly CatalogTool[]
|
|
26
|
+
export declare function catalogText(tools: readonly CatalogTool[]): string;
|
|
30
27
|
/**
|
|
31
28
|
* 内置工具 `ToolSearch`(spec 5.5):在本次运行可用、但未直接加载的工具中按关键词搜索,返回完整定义,
|
|
32
29
|
* 并在结果里带 `loadedTools`(管线写进 `tool_result.loadedTools`;已加载集合只由日志还原)。
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { parseToolKey } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { BUILTIN_TOOL_NAMES, TOOL_SEARCH } from "../builtin-names.js";
|
|
3
|
-
import { isLegacyBuiltinKey } from "../legacy-keys.js";
|
|
4
3
|
export { TOOL_SEARCH } from "../builtin-names.js";
|
|
5
4
|
/** 默认返回的匹配数。 */
|
|
6
5
|
const DEFAULT_LIMIT = 5;
|
|
@@ -47,11 +46,8 @@ export const CATALOG_HEADER = "More tools are available but not loaded, even whe
|
|
|
47
46
|
"returns the full definitions and loads the matching tools for your next step. Tool catalog:";
|
|
48
47
|
/** 调用目录里尚未加载的工具(模型可见,英文;spec 5.5:不自动加载)。 */
|
|
49
48
|
export const notLoadedText = (key) => `Tool "${key}" is not loaded. Call ToolSearch first with keywords for this tool, then call it in a later step.`;
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
* recorded before the tool rename is rebuilt with its old keys, and its builtins were loaded.
|
|
53
|
-
*/
|
|
54
|
-
export const isAlwaysLoaded = (key) => BUILTIN_TOOL_NAMES.includes(key) || isLegacyBuiltinKey(key);
|
|
49
|
+
/** Tools always loaded in full and never in the catalog (the builtins). */
|
|
50
|
+
export const isAlwaysLoaded = (key) => BUILTIN_TOOL_NAMES.includes(key);
|
|
55
51
|
/** 分词:切开驼峰,按非字母数字切分,转小写。 */
|
|
56
52
|
export function tokenize(text) {
|
|
57
53
|
const parsed = parseToolKey(text);
|
|
@@ -116,12 +112,12 @@ export function catalogLine(t) {
|
|
|
116
112
|
return `- ${t.key}: ${desc}`;
|
|
117
113
|
}
|
|
118
114
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
115
|
+
* The catalog text: the header, then one line per tool sorted by key. It depends only on the tool
|
|
116
|
+
* set, never on what is loaded (a stable cache prefix).
|
|
121
117
|
*/
|
|
122
|
-
export function catalogText(tools
|
|
118
|
+
export function catalogText(tools) {
|
|
123
119
|
const sorted = [...tools].sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
|
|
124
|
-
return [
|
|
120
|
+
return [CATALOG_HEADER, ...sorted.map(catalogLine)].join("\n");
|
|
125
121
|
}
|
|
126
122
|
/** 一个工具的完整定义文本(`ToolSearch` 的结果)。 */
|
|
127
123
|
function definitionText(t) {
|
|
@@ -28,10 +28,30 @@ export declare const personalAuth: (auth: unknown) => boolean;
|
|
|
28
28
|
* The tool name of a member's own policy for pushes to one repository on one host through the
|
|
29
29
|
* connector (sandbox git credentials spec §7: the virtual tool `git_push`,
|
|
30
30
|
* `git_push:<host>/<owner>/<repo>`, so an allow never covers another host). No
|
|
31
|
-
* `connector_tools` row backs it
|
|
32
|
-
*
|
|
31
|
+
* `connector_tools` row backs it: the Permissions sheet lists these apart from the tools
|
|
32
|
+
* ({@link ConnectorAccountPolicies.gitPush}), and the member may only clear one there;
|
|
33
|
+
* "Always allow" on a git push ask writes it.
|
|
33
34
|
*/
|
|
34
35
|
export declare const gitPushPolicyName: (host: string, repo: string) => string;
|
|
36
|
+
/** One standing push decision of the member for one repository (a `git_push:*` row). */
|
|
37
|
+
export interface MemberGitPushGrant {
|
|
38
|
+
/** The row's tool name, `git_push:<host>/<owner>/<repo>`: the key that clears it. */
|
|
39
|
+
name: string;
|
|
40
|
+
host: string;
|
|
41
|
+
/** `<owner>/<repo>`. */
|
|
42
|
+
repo: string;
|
|
43
|
+
policy: ToolPolicy;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The git push part of the member's Permissions sheet (sandbox git credentials spec §7): the org's
|
|
47
|
+
* default for pushes through the connector and the member's standing decisions per repository.
|
|
48
|
+
* Null on a connector that declares no git hosts and holds no such decision.
|
|
49
|
+
*/
|
|
50
|
+
export interface MemberGitPushView {
|
|
51
|
+
/** `connectors.git_push_policy`: what applies to a repository without a decision. */
|
|
52
|
+
orgDefault: ToolPolicy;
|
|
53
|
+
grants: MemberGitPushGrant[];
|
|
54
|
+
}
|
|
35
55
|
/**
|
|
36
56
|
* A member's own tool policies for their own connection of a personal-credential connector
|
|
37
57
|
* (maintainer decision 2026-11-09, the connector card's 权限). They apply to every agent the
|
|
@@ -48,10 +68,17 @@ export declare class ConnectorAccountPolicies {
|
|
|
48
68
|
private get db();
|
|
49
69
|
/** The connector's tools with the account's settings; not personal -> 409 `connector.not_personal`. */
|
|
50
70
|
read(orgId: string, connectorId: string, accountId: string): Promise<MemberToolPolicyView[]>;
|
|
71
|
+
/**
|
|
72
|
+
* The account's standing git push decisions on the connector and the org's default; not
|
|
73
|
+
* personal -> 409 `connector.not_personal`.
|
|
74
|
+
*/
|
|
75
|
+
gitPush(orgId: string, connectorId: string, accountId: string): Promise<MemberGitPushView | null>;
|
|
51
76
|
/**
|
|
52
77
|
* Sets (a policy) or clears (null) the account's policies for some of the connector's tools;
|
|
53
78
|
* an unknown tool -> 404 `connector.tool_not_found`. Locked tools may hold a setting: it does not
|
|
54
|
-
* apply while the lock lasts.
|
|
79
|
+
* apply while the lock lasts. A `git_push:*` name may only be cleared (a standing push decision
|
|
80
|
+
* is written by "Always allow" on a push ask; setting one here -> 400 `validation_failed`).
|
|
81
|
+
* Audits `connector.member_policies_changed`.
|
|
55
82
|
*/
|
|
56
83
|
set(orgId: string, connectorId: string, accountId: string, changes: Record<string, ToolPolicy | null>, actorTokenId?: string): Promise<void>;
|
|
57
84
|
/** The org's live personal-credential connector, else 404 / 409. */
|