@capybara-hq/kernel 0.1.0-rc.2 → 0.1.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/admin.controller.d.ts +9 -4
- package/dist/admin/admin.controller.js +13 -4
- package/dist/admin/extensions.controller.d.ts +8 -1
- package/dist/admin/extensions.controller.js +22 -2
- package/dist/agents/agent-lookup.d.ts +3 -0
- package/dist/agents/agent-lookup.js +20 -2
- package/dist/agents/agent-profile.service.d.ts +29 -0
- package/dist/agents/agent-profile.service.js +117 -0
- package/dist/agents/agents.controller.d.ts +93 -3
- package/dist/agents/agents.controller.js +114 -4
- package/dist/agents/agents.module.js +6 -2
- package/dist/agents/agents.service.d.ts +13 -5
- package/dist/agents/agents.service.js +49 -13
- package/dist/agents/definition.d.ts +35 -8
- package/dist/agents/definition.js +203 -17
- package/dist/agents/instruction-files.d.ts +60 -0
- package/dist/agents/instruction-files.js +111 -0
- package/dist/agents/models.controller.d.ts +9 -3
- package/dist/agents/models.controller.js +19 -4
- package/dist/agents/profile.d.ts +96 -0
- package/dist/agents/profile.js +51 -0
- package/dist/agents/readiness.controller.d.ts +26 -0
- package/dist/agents/readiness.controller.js +56 -0
- package/dist/agents/templates.js +20 -5
- package/dist/background/background.controller.d.ts +38 -0
- package/dist/background/background.controller.js +87 -0
- package/dist/background/background.module.d.ts +10 -0
- package/dist/background/background.module.js +32 -0
- package/dist/background/finish.d.ts +43 -0
- package/dist/background/finish.js +94 -0
- package/dist/background/launch-lock.d.ts +14 -0
- package/dist/background/launch-lock.js +39 -0
- package/dist/background/launch.d.ts +36 -0
- package/dist/background/launch.js +70 -0
- package/dist/background/poll.job.d.ts +53 -0
- package/dist/background/poll.job.js +182 -0
- package/dist/background/render.d.ts +23 -0
- package/dist/background/render.js +48 -0
- package/dist/background/session.d.ts +37 -0
- package/dist/background/session.js +66 -0
- package/dist/background/status.d.ts +35 -0
- package/dist/background/status.js +57 -0
- package/dist/background/stop.d.ts +62 -0
- package/dist/background/stop.js +225 -0
- package/dist/background/store.d.ts +150 -0
- package/dist/background/store.js +351 -0
- package/dist/background/store.module.d.ts +6 -0
- package/dist/background/store.module.js +22 -0
- package/dist/background/tasks.service.d.ts +67 -0
- package/dist/background/tasks.service.js +186 -0
- package/dist/background/wake-rules.d.ts +57 -0
- package/dist/background/wake-rules.js +83 -0
- package/dist/background/wake.d.ts +28 -0
- package/dist/background/wake.js +57 -0
- package/dist/catalog/catalog-content.js +4 -1
- package/dist/catalog/claude/agents.js +15 -10
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/plugin-import.js +1 -1
- package/dist/catalog/plugin-upgrade.js +1 -1
- package/dist/channels/cards.d.ts +8 -2
- package/dist/channels/cards.js +17 -9
- package/dist/channels/connections.service.d.ts +16 -1
- package/dist/channels/connections.service.js +38 -4
- package/dist/channels/threads.d.ts +5 -0
- package/dist/channels/threads.js +8 -0
- package/dist/config/schema.d.ts +18 -0
- package/dist/config/schema.js +104 -2
- package/dist/conversations/access.js +2 -0
- package/dist/conversations/artifacts.d.ts +1 -1
- package/dist/conversations/artifacts.js +1 -1
- package/dist/conversations/attachments.service.d.ts +30 -0
- package/dist/conversations/attachments.service.js +130 -5
- package/dist/conversations/conversations.controller.d.ts +36 -5
- package/dist/conversations/conversations.controller.js +62 -12
- package/dist/conversations/conversations.module.js +3 -0
- package/dist/conversations/conversations.service.d.ts +44 -2
- package/dist/conversations/conversations.service.js +140 -12
- package/dist/conversations/event-log.d.ts +12 -1
- package/dist/conversations/event-log.js +29 -1
- package/dist/conversations/events.d.ts +81 -3
- package/dist/conversations/events.js +83 -16
- package/dist/conversations/queue.d.ts +3 -1
- package/dist/conversations/queue.js +13 -2
- package/dist/conversations/queue.service.js +3 -1
- package/dist/conversations/titles.d.ts +7 -0
- package/dist/conversations/titles.js +15 -0
- package/dist/db/kernel-schema.d.ts +60 -4
- package/dist/db/pool.d.ts +5 -0
- package/dist/db/pool.js +3 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +8 -0
- package/dist/evals/recorded-tools.d.ts +27 -1
- package/dist/evals/recorded-tools.js +85 -10
- package/dist/evals/run-replay.d.ts +10 -2
- package/dist/evals/run-replay.js +49 -12
- package/dist/evals/step-replay.js +12 -6
- package/dist/evals/trajectory.d.ts +2 -2
- package/dist/evals/trajectory.js +1 -1
- package/dist/extensions/admin-ops.js +2 -0
- package/dist/extensions/admin-view.d.ts +3 -1
- package/dist/extensions/admin-view.js +10 -2
- package/dist/extensions/blobs.js +1 -0
- package/dist/extensions/config-issues.d.ts +13 -1
- package/dist/extensions/config-issues.js +22 -5
- package/dist/extensions/config-json-schema.d.ts +43 -7
- package/dist/extensions/config-json-schema.js +124 -58
- package/dist/extensions/deployment-config-store.d.ts +6 -0
- package/dist/extensions/deployment-config.d.ts +50 -3
- package/dist/extensions/deployment-config.js +125 -28
- package/dist/extensions/display-name.d.ts +22 -0
- package/dist/extensions/display-name.js +77 -0
- package/dist/extensions/extensions.module.js +6 -0
- package/dist/extensions/host.d.ts +26 -1
- package/dist/extensions/host.js +82 -9
- package/dist/extensions/org-config.controller.d.ts +11 -3
- package/dist/extensions/org-config.controller.js +14 -6
- package/dist/extensions/org-config.d.ts +6 -0
- package/dist/extensions/org-config.js +12 -13
- package/dist/extensions/package.d.ts +14 -1
- package/dist/extensions/package.js +51 -2
- package/dist/extensions/permission-view.d.ts +3 -0
- package/dist/extensions/point-defaults.controller.d.ts +34 -0
- package/dist/extensions/point-defaults.controller.js +71 -0
- package/dist/extensions/point-defaults.d.ts +64 -0
- package/dist/extensions/point-defaults.js +206 -0
- package/dist/extensions/registry.d.ts +1 -1
- package/dist/extensions/registry.js +2 -0
- package/dist/http/api.module.js +8 -0
- package/dist/http/nest-logger.d.ts +6 -5
- package/dist/http/nest-logger.js +24 -10
- package/dist/identity/auth.controller.js +9 -5
- package/dist/identity/cookies.d.ts +20 -5
- package/dist/identity/cookies.js +44 -6
- package/dist/identity/me.controller.d.ts +5 -1
- package/dist/identity/me.controller.js +12 -3
- package/dist/identity/sessions.d.ts +12 -0
- package/dist/identity/sessions.js +45 -0
- package/dist/identity/settings.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/infra/config/kernel-config.service.js +6 -0
- package/dist/infra/database/database.module.js +1 -0
- package/dist/infra/events/kernel-events.d.ts +8 -0
- package/dist/infra/lifecycle/process-guards.js +4 -0
- package/dist/infra/logging/logging.module.d.ts +4 -2
- package/dist/infra/logging/logging.module.js +24 -6
- package/dist/infra/queue/redis-connection.d.ts +6 -0
- package/dist/infra/queue/redis-connection.js +7 -0
- package/dist/infra/redis/redis.module.js +6 -2
- package/dist/infra/tokens.d.ts +6 -1
- package/dist/infra/tokens.js +6 -1
- package/dist/lifecycle/kernel-lifecycle.js +5 -0
- package/dist/log.d.ts +13 -1
- package/dist/log.js +93 -17
- package/dist/models/purposes.d.ts +23 -0
- package/dist/models/purposes.js +31 -10
- package/dist/orgs/offboarding.d.ts +3 -1
- package/dist/orgs/offboarding.js +26 -16
- package/dist/orgs/settings.service.d.ts +7 -2
- package/dist/orgs/settings.service.js +15 -4
- package/dist/roles/worker.module.js +6 -0
- package/dist/runtime/context/build.d.ts +15 -13
- package/dist/runtime/context/build.js +45 -27
- package/dist/runtime/context/claude-tools.d.ts +3 -1
- package/dist/runtime/context/claude-tools.js +12 -12
- package/dist/runtime/context/compaction.js +4 -0
- package/dist/runtime/context/legacy-text.d.ts +22 -0
- package/dist/runtime/context/legacy-text.js +37 -0
- package/dist/runtime/context/skills.d.ts +29 -11
- package/dist/runtime/context/skills.js +37 -30
- package/dist/runtime/langgraph-loop.js +3 -2
- package/dist/runtime/loop.d.ts +5 -4
- package/dist/runtime/maintenance.d.ts +4 -2
- package/dist/runtime/maintenance.js +17 -5
- package/dist/runtime/model-call.d.ts +17 -1
- package/dist/runtime/model-call.js +4 -3
- package/dist/runtime/providers.d.ts +6 -0
- package/dist/runtime/providers.js +8 -0
- package/dist/runtime/run-finish.d.ts +1 -1
- package/dist/runtime/run-queue.d.ts +28 -5
- package/dist/runtime/run-queue.js +131 -35
- package/dist/runtime/run-worker.d.ts +2 -2
- package/dist/runtime/run-worker.js +20 -7
- package/dist/runtime/runtime.module.js +8 -3
- package/dist/runtime/step-log.d.ts +6 -0
- package/dist/runtime/step-log.js +16 -2
- package/dist/runtime/subagents/definition.d.ts +1 -6
- package/dist/runtime/subagents/definition.js +14 -13
- package/dist/runtime/subagents/dispatch.d.ts +2 -2
- package/dist/runtime/subagents/dispatch.js +2 -2
- package/dist/runtime/subagents/org-agents.js +2 -1
- package/dist/runtime/subagents/roster.d.ts +1 -1
- package/dist/runtime/subagents/roster.js +1 -1
- package/dist/runtime/subagents/skill-fork.d.ts +2 -2
- package/dist/runtime/subagents/skill-fork.js +2 -2
- package/dist/runtime/subagents/subagents.service.d.ts +3 -3
- package/dist/runtime/subagents/subagents.service.js +3 -3
- package/dist/runtime/usage-report.d.ts +2 -1
- package/dist/runtime/usage-report.js +2 -1
- package/dist/runtime/waits.d.ts +13 -7
- package/dist/runtime/waits.js +42 -16
- package/dist/sandbox/sandbox.module.js +6 -1
- package/dist/sandbox/sandbox.service.d.ts +61 -3
- package/dist/sandbox/sandbox.service.js +141 -7
- package/dist/skills/catalog.d.ts +4 -4
- package/dist/skills/catalog.js +4 -4
- package/dist/skills/changes.service.d.ts +2 -2
- package/dist/skills/changes.service.js +5 -4
- package/dist/skills/invocation-keys.d.ts +1 -1
- package/dist/skills/invocation-keys.js +1 -1
- package/dist/skills/invoke.d.ts +1 -1
- package/dist/skills/invoke.js +5 -4
- package/dist/tools/approvals.service.d.ts +6 -0
- package/dist/tools/approvals.service.js +21 -1
- package/dist/tools/builtin-names.d.ts +91 -0
- package/dist/tools/builtin-names.js +143 -0
- package/dist/tools/builtins/agent.d.ts +7 -7
- package/dist/tools/builtins/agent.js +7 -11
- package/dist/tools/builtins/ask-user.d.ts +1 -1
- package/dist/tools/builtins/ask-user.js +2 -2
- package/dist/tools/builtins/builtin-tools.d.ts +17 -3
- package/dist/tools/builtins/builtin-tools.js +36 -4
- package/dist/tools/builtins/read-tool-output.d.ts +1 -1
- package/dist/tools/builtins/read-tool-output.js +2 -2
- package/dist/tools/builtins/sandbox/bash.d.ts +4 -4
- package/dist/tools/builtins/sandbox/bash.js +259 -29
- package/dist/tools/builtins/sandbox/common.d.ts +30 -7
- package/dist/tools/builtins/sandbox/common.js +9 -5
- package/dist/tools/builtins/sandbox/deliver.d.ts +1 -1
- package/dist/tools/builtins/sandbox/deliver.js +12 -12
- package/dist/tools/builtins/sandbox/edit.d.ts +1 -1
- package/dist/tools/builtins/sandbox/edit.js +41 -30
- package/dist/tools/builtins/sandbox/file-state.d.ts +34 -0
- package/dist/tools/builtins/sandbox/file-state.js +34 -0
- package/dist/tools/builtins/sandbox/glob-match.d.ts +1 -1
- package/dist/tools/builtins/sandbox/glob-match.js +1 -1
- package/dist/tools/builtins/sandbox/glob.d.ts +1 -1
- package/dist/tools/builtins/sandbox/glob.js +4 -4
- package/dist/tools/builtins/sandbox/grep.d.ts +7 -4
- package/dist/tools/builtins/sandbox/grep.js +147 -30
- package/dist/tools/builtins/sandbox/index.d.ts +3 -1
- package/dist/tools/builtins/sandbox/index.js +7 -1
- package/dist/tools/builtins/sandbox/read.d.ts +2 -2
- package/dist/tools/builtins/sandbox/read.js +21 -14
- package/dist/tools/builtins/sandbox/task-output.d.ts +63 -0
- package/dist/tools/builtins/sandbox/task-output.js +304 -0
- package/dist/tools/builtins/sandbox/task-stop.d.ts +10 -0
- package/dist/tools/builtins/sandbox/task-stop.js +112 -0
- package/dist/tools/builtins/sandbox/write.d.ts +1 -1
- package/dist/tools/builtins/sandbox/write.js +37 -33
- package/dist/tools/builtins/skill-load.d.ts +3 -3
- package/dist/tools/builtins/skill-load.js +32 -16
- package/dist/tools/builtins/skill-write.d.ts +4 -4
- package/dist/tools/builtins/skill-write.js +10 -10
- package/dist/tools/builtins/tool-search.d.ts +13 -9
- package/dist/tools/builtins/tool-search.js +25 -14
- package/dist/tools/builtins/web/errors.d.ts +8 -0
- package/dist/tools/builtins/web/errors.js +53 -0
- package/dist/tools/builtins/web/extract.d.ts +62 -0
- package/dist/tools/builtins/web/extract.js +267 -0
- package/dist/tools/builtins/web/fetch.d.ts +55 -0
- package/dist/tools/builtins/web/fetch.js +174 -0
- package/dist/tools/builtins/web/index.d.ts +13 -0
- package/dist/tools/builtins/web/index.js +12 -0
- package/dist/tools/builtins/web/page-cache.d.ts +25 -0
- package/dist/tools/builtins/web/page-cache.js +77 -0
- package/dist/tools/builtins/web/search.d.ts +25 -0
- package/dist/tools/builtins/web/search.js +209 -0
- package/dist/tools/builtins/web/url.d.ts +17 -0
- package/dist/tools/builtins/web/url.js +43 -0
- package/dist/tools/connectors.service.js +4 -4
- package/dist/tools/display-names.d.ts +9 -0
- package/dist/tools/display-names.js +24 -0
- package/dist/tools/drift.js +5 -5
- package/dist/tools/elicitation.js +1 -1
- package/dist/tools/info.d.ts +20 -4
- package/dist/tools/info.js +55 -32
- package/dist/tools/legacy-data.d.ts +34 -0
- package/dist/tools/legacy-data.js +76 -0
- package/dist/tools/legacy-keys.d.ts +51 -0
- package/dist/tools/legacy-keys.js +115 -0
- package/dist/tools/naming.d.ts +1 -5
- package/dist/tools/naming.js +1 -7
- package/dist/tools/oauth/flow-paths.d.ts +1 -1
- package/dist/tools/oauth/flow-paths.js +1 -1
- package/dist/tools/outputs.js +1 -1
- package/dist/tools/pipeline.d.ts +13 -7
- package/dist/tools/pipeline.js +112 -39
- package/dist/tools/policy.d.ts +1 -14
- package/dist/tools/policy.js +13 -19
- package/dist/tools/questions.controller.d.ts +1 -1
- package/dist/tools/questions.controller.js +1 -1
- package/dist/tools/questions.service.d.ts +1 -1
- package/dist/tools/registry.d.ts +38 -24
- package/dist/tools/registry.js +54 -47
- package/dist/tools/resources.d.ts +1 -1
- package/dist/tools/resources.js +1 -1
- package/dist/tools/tools.module.js +13 -1
- package/dist/tools/validate.js +1 -1
- package/package.json +3 -3
- package/src/migrations/0063_tool_keys_claude_code.sql +220 -0
- package/src/migrations/0064_account_last_org.sql +7 -0
- package/src/migrations/0065_conversation_archive.sql +8 -0
- package/src/migrations/0066_extension_display_name.sql +4 -0
- package/src/migrations/0067_agent_profiles.sql +20 -0
- package/src/migrations/0068_agent_avatar_uploads.sql +7 -0
- package/src/migrations/0069_attachments_agent_idx.sql +3 -0
- package/src/migrations/0070_background_tasks.sql +37 -0
- package/src/migrations/0071_background_tasks_reserve.sql +6 -0
- package/src/migrations/0072_background_tasks_stopping.sql +5 -0
- package/src/migrations/0073_org_extension_point_defaults.sql +11 -0
- package/dist/tools/builtins/sandbox/names.d.ts +0 -7
- package/dist/tools/builtins/sandbox/names.js +0 -20
|
@@ -8,10 +8,11 @@ import { OrgLock } from "./org-lock.js";
|
|
|
8
8
|
/**
|
|
9
9
|
* 组织设置(`capybara.orgs.settings` jsonb)。读取宽松:缺失或非法的字段按默认值,未知键保留不动
|
|
10
10
|
* (更新时与存量合并),新版本加字段不需要迁移。
|
|
11
|
-
* - `toolSearch`:工具超过阈值时是否改用目录 + `
|
|
11
|
+
* - `toolSearch`:工具超过阈值时是否改用目录 + `ToolSearch`(D11,默认 on)。
|
|
12
12
|
* - `locale`:组织默认语言(`zh` / `en`,默认 en),机器人在 IM 里说的固定话术按它选择。
|
|
13
13
|
* - `sandboxToolPolicy`:沙箱工具的默认策略(M5 T8,默认 allow)。为 `ask` 时除只读的
|
|
14
|
-
* `
|
|
14
|
+
* `Read` / `Glob` / `Grep` 外都需要审批(执行时实时读取)。
|
|
15
|
+
* - `wakeOnBackgroundTask`:组织对 `runtime.wakeOnBackgroundTask` 的覆盖(缺省跟随部署),见 {@link effectiveWakeOnBackgroundTask}。
|
|
15
16
|
* - `sandboxEgress`:组织的沙箱出站(Ruling M19 / D6),缺省跟随部署的 `sandbox.limits.egress` + `allowHosts`。
|
|
16
17
|
* 见 {@link effectiveSandboxEgress}。存量值非法时按 `none` 读(宁可断网,不悄悄放宽到部署默认)。
|
|
17
18
|
*/
|
|
@@ -49,6 +50,7 @@ export declare const OrgSettingsSchema: z.ZodObject<{
|
|
|
49
50
|
}>;
|
|
50
51
|
allowHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
51
52
|
}, z.core.$strict>>>;
|
|
53
|
+
wakeOnBackgroundTask: z.ZodCatch<z.ZodOptional<z.ZodBoolean>>;
|
|
52
54
|
}, z.core.$strip>;
|
|
53
55
|
export type OrgSettings = z.infer<typeof OrgSettingsSchema>;
|
|
54
56
|
/** PATCH 体:只改给出的字段;未知字段 → 400。 */
|
|
@@ -65,6 +67,7 @@ export declare const OrgSettingsPatchSchema: z.ZodObject<{
|
|
|
65
67
|
allow: "allow";
|
|
66
68
|
ask: "ask";
|
|
67
69
|
}>>;
|
|
70
|
+
wakeOnBackgroundTask: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
68
71
|
sandboxEgress: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
69
72
|
mode: z.ZodEnum<{
|
|
70
73
|
allowlist: "allowlist";
|
|
@@ -81,6 +84,8 @@ export type DeploymentEgress = Pick<SandboxLimits, "egress" | "allowHosts">;
|
|
|
81
84
|
* (省略时用部署的),但部署是 `none` 时仍为 `none`(组织永远不比部署放得更开,部署改成 none 后存量设置也随之收紧)。
|
|
82
85
|
*/
|
|
83
86
|
export declare function effectiveSandboxEgress(deployment: DeploymentEgress, org: SandboxEgressSetting | undefined): DeploymentEgress;
|
|
87
|
+
/** Whether a finished background task wakes an idle conversation: the org's setting, else the deployment's. */
|
|
88
|
+
export declare function effectiveWakeOnBackgroundTask(deployment: boolean, org: OrgSettings["wakeOnBackgroundTask"]): boolean;
|
|
84
89
|
/**
|
|
85
90
|
* 组织实际生效的沙箱限额(C19 / Ruling M16):企业管理员的覆盖(部署设置 `sandboxLimitOverrides[orgId]`)
|
|
86
91
|
* 给出的 cpu / memoryMb 替换部署默认,未给的项、disk 与出站沿用 `deployment`。只在创建沙箱时读取。
|
|
@@ -21,10 +21,11 @@ import { OrgLock } from "./org-lock.js";
|
|
|
21
21
|
/**
|
|
22
22
|
* 组织设置(`capybara.orgs.settings` jsonb)。读取宽松:缺失或非法的字段按默认值,未知键保留不动
|
|
23
23
|
* (更新时与存量合并),新版本加字段不需要迁移。
|
|
24
|
-
* - `toolSearch`:工具超过阈值时是否改用目录 + `
|
|
24
|
+
* - `toolSearch`:工具超过阈值时是否改用目录 + `ToolSearch`(D11,默认 on)。
|
|
25
25
|
* - `locale`:组织默认语言(`zh` / `en`,默认 en),机器人在 IM 里说的固定话术按它选择。
|
|
26
26
|
* - `sandboxToolPolicy`:沙箱工具的默认策略(M5 T8,默认 allow)。为 `ask` 时除只读的
|
|
27
|
-
* `
|
|
27
|
+
* `Read` / `Glob` / `Grep` 外都需要审批(执行时实时读取)。
|
|
28
|
+
* - `wakeOnBackgroundTask`:组织对 `runtime.wakeOnBackgroundTask` 的覆盖(缺省跟随部署),见 {@link effectiveWakeOnBackgroundTask}。
|
|
28
29
|
* - `sandboxEgress`:组织的沙箱出站(Ruling M19 / D6),缺省跟随部署的 `sandbox.limits.egress` + `allowHosts`。
|
|
29
30
|
* 见 {@link effectiveSandboxEgress}。存量值非法时按 `none` 读(宁可断网,不悄悄放宽到部署默认)。
|
|
30
31
|
*/
|
|
@@ -58,6 +59,8 @@ export const OrgSettingsSchema = z.object({
|
|
|
58
59
|
locale: z.enum(["zh", "en"]).default("en").catch("en"),
|
|
59
60
|
sandboxToolPolicy: z.enum(["allow", "ask"]).default("allow").catch("allow"),
|
|
60
61
|
sandboxEgress: SandboxEgressSettingSchema.optional().catch({ mode: "none" }),
|
|
62
|
+
/** Overrides `runtime.wakeOnBackgroundTask`; absent follows the deployment. */
|
|
63
|
+
wakeOnBackgroundTask: z.boolean().optional().catch(undefined),
|
|
61
64
|
});
|
|
62
65
|
/** PATCH 体:只改给出的字段;未知字段 → 400。 */
|
|
63
66
|
export const OrgSettingsPatchSchema = z
|
|
@@ -65,6 +68,8 @@ export const OrgSettingsPatchSchema = z
|
|
|
65
68
|
toolSearch: z.enum(["on", "off"]).optional(),
|
|
66
69
|
locale: z.enum(["zh", "en"]).optional(),
|
|
67
70
|
sandboxToolPolicy: z.enum(["allow", "ask"]).optional(),
|
|
71
|
+
/** null clears (follow the deployment again). */
|
|
72
|
+
wakeOnBackgroundTask: z.boolean().nullable().optional(),
|
|
68
73
|
/** null 清除(恢复跟随部署默认)。 */
|
|
69
74
|
sandboxEgress: SandboxEgressSettingSchema.nullable().optional(),
|
|
70
75
|
})
|
|
@@ -80,6 +85,10 @@ export function effectiveSandboxEgress(deployment, org) {
|
|
|
80
85
|
return { egress: "none", allowHosts: [] };
|
|
81
86
|
return { egress: "allowlist", allowHosts: [...(org.allowHosts ?? deployment.allowHosts)] };
|
|
82
87
|
}
|
|
88
|
+
/** Whether a finished background task wakes an idle conversation: the org's setting, else the deployment's. */
|
|
89
|
+
export function effectiveWakeOnBackgroundTask(deployment, org) {
|
|
90
|
+
return org ?? deployment;
|
|
91
|
+
}
|
|
83
92
|
/**
|
|
84
93
|
* 组织实际生效的沙箱限额(C19 / Ruling M16):企业管理员的覆盖(部署设置 `sandboxLimitOverrides[orgId]`)
|
|
85
94
|
* 给出的 cpu / memoryMb 替换部署默认,未给的项、disk 与出站沿用 `deployment`。只在创建沙箱时读取。
|
|
@@ -169,15 +178,17 @@ let OrgSettingsService = class OrgSettingsService {
|
|
|
169
178
|
const before = parseOrgSettings(stored);
|
|
170
179
|
const changes = Object.fromEntries(Object.entries(patch)
|
|
171
180
|
.filter(([, v]) => v !== undefined)
|
|
172
|
-
// null
|
|
181
|
+
// null clears sandboxEgress / wakeOnBackgroundTask: follow the deployment default again
|
|
173
182
|
.map(([k, v]) => [k, v === null ? undefined : v]));
|
|
174
183
|
const after = { ...before, ...changes };
|
|
175
184
|
if (after.sandboxEgress === undefined)
|
|
176
185
|
delete after.sandboxEgress;
|
|
186
|
+
if (after.wakeOnBackgroundTask === undefined)
|
|
187
|
+
delete after.wakeOnBackgroundTask;
|
|
177
188
|
if (sameSettings(before, after))
|
|
178
189
|
return before;
|
|
179
190
|
// 与存量合并:保留本版本不认识的键(清除的 sandboxEgress 不留在存量里)
|
|
180
|
-
const { sandboxEgress: _old, ...rest } = stored;
|
|
191
|
+
const { sandboxEgress: _old, wakeOnBackgroundTask: _oldWake, ...rest } = stored;
|
|
181
192
|
await this.db
|
|
182
193
|
.updateTable("orgs")
|
|
183
194
|
.set({ settings: JSON.stringify({ ...rest, ...after }) })
|
|
@@ -6,12 +6,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
var WorkerModule_1;
|
|
8
8
|
import { Module } from "@nestjs/common";
|
|
9
|
+
import { BackgroundModule } from "../background/background.module.js";
|
|
10
|
+
import { BackgroundTaskPollJob } from "../background/poll.job.js";
|
|
9
11
|
import { CatalogModule } from "../catalog/catalog.module.js";
|
|
10
12
|
import { CatalogJobs } from "../catalog/jobs.js";
|
|
11
13
|
import { ChannelsModule, ChannelWorkersModule } from "../channels/channels.module.js";
|
|
12
14
|
import { GatewayCheckJob } from "../channels/supervisor.js";
|
|
13
15
|
import { AttachmentsModule } from "../conversations/attachments.module.js";
|
|
14
16
|
import { AttachmentCleanupJob } from "../conversations/attachments.service.js";
|
|
17
|
+
import { EventLogModule } from "../conversations/event-log.js";
|
|
15
18
|
import { TitlesModule } from "../conversations/titles.js";
|
|
16
19
|
import { EvalWorkersModule } from "../evals/evals.module.js";
|
|
17
20
|
import { ExtensionsModule } from "../extensions/extensions.module.js";
|
|
@@ -59,6 +62,8 @@ let WorkerModule = WorkerModule_1 = class WorkerModule {
|
|
|
59
62
|
AttachmentsModule,
|
|
60
63
|
StorageModule,
|
|
61
64
|
SandboxModule,
|
|
65
|
+
BackgroundModule,
|
|
66
|
+
EventLogModule,
|
|
62
67
|
ToolsModule,
|
|
63
68
|
CatalogModule,
|
|
64
69
|
OrgsModule,
|
|
@@ -71,6 +76,7 @@ let WorkerModule = WorkerModule_1 = class WorkerModule {
|
|
|
71
76
|
AttachmentCleanupJob,
|
|
72
77
|
StoragePurgeJob,
|
|
73
78
|
SandboxSweepJobs,
|
|
79
|
+
BackgroundTaskPollJob,
|
|
74
80
|
ToolJobs,
|
|
75
81
|
CatalogJobs,
|
|
76
82
|
DirectoryScanJob,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ContentBlock, type ModelInfo, type ModelRequest, type ParamValue } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { AgentDefinition } from "../../agents/definition.js";
|
|
3
|
-
import type
|
|
3
|
+
import { type ConversationEvent, type EventPayload } from "../../conversations/events.js";
|
|
4
4
|
import type { ResolvedTool } from "../../tools/registry.js";
|
|
5
5
|
/**
|
|
6
6
|
* 平台行为规范(模型可见,英文)。短而通用(spec 6 原则 5);不放时间戳、会话 ID 等会变化的内容,
|
|
@@ -25,13 +25,13 @@ export interface ModelCallMeta {
|
|
|
25
25
|
params: Record<string, ParamValue>;
|
|
26
26
|
/**
|
|
27
27
|
* 请求带的工具(按发送顺序)及定义指纹;定义本身按指纹存在 `capybara.tool_specs`。
|
|
28
|
-
* 未启用
|
|
28
|
+
* 未启用 ToolSearch 时按 key 排序;启用时见 {@link BuildModelRequestInput.toolSearch}。
|
|
29
29
|
*/
|
|
30
30
|
tools: {
|
|
31
31
|
key: string;
|
|
32
32
|
specHash: string;
|
|
33
33
|
}[];
|
|
34
|
-
/** 启用
|
|
34
|
+
/** 启用 ToolSearch 时 system 第二块目录里的工具(按 key 排序)及定义指纹;未启用没有该字段。 */
|
|
35
35
|
catalog?: {
|
|
36
36
|
key: string;
|
|
37
37
|
specHash: string;
|
|
@@ -54,13 +54,14 @@ export interface BuildModelRequestInput {
|
|
|
54
54
|
model: ModelInfo;
|
|
55
55
|
step: number;
|
|
56
56
|
/**
|
|
57
|
-
* loop
|
|
58
|
-
*
|
|
59
|
-
* -
|
|
57
|
+
* loop 已吸收到的位置(R31):the largest seq of the absorbable events (`user_message` and
|
|
58
|
+
* `background_task_finished`, {@link isAbsorbable}) the loop took. 提供时:
|
|
59
|
+
* - seq 大于它的可吸收事件不进请求(运行中途到达、尚未被吸收的插话或后台任务结束,由后续步骤吸收或触发下一轮);
|
|
60
|
+
* - 每个可吸收事件放在**吸收它的那次模型调用**的位置:日志里第一个 `request.absorbedUpToSeq`
|
|
60
61
|
* 不小于它的 `model_call` 之前(没有该字段的旧 model_call 视为吸收了它之前的全部消息),
|
|
61
62
|
* 本次请求吸收的放在末尾。于是模型看到的历史只追加(插话不会插到已发送的回复之前),
|
|
62
63
|
* 且请求可由日志 + `model_call` 精确还原。
|
|
63
|
-
* 不提供时按 seq
|
|
64
|
+
* 不提供时按 seq 原样回放全部可吸收事件。
|
|
64
65
|
*/
|
|
65
66
|
absorbedUpToSeq?: number;
|
|
66
67
|
/**
|
|
@@ -75,8 +76,8 @@ export interface BuildModelRequestInput {
|
|
|
75
76
|
*/
|
|
76
77
|
tools?: RequestTool[];
|
|
77
78
|
/**
|
|
78
|
-
* 启用
|
|
79
|
-
* - `tools` 只放内置工具(含 `
|
|
79
|
+
* 启用 ToolSearch(spec 5.5,由 `ToolRegistry.forAgent` 判定)。启用且有工具时:
|
|
80
|
+
* - `tools` 只放内置工具(含 `ToolSearch`,按 key 排序)与**已加载**工具的完整定义;
|
|
80
81
|
* 已加载 = 日志中全部 `tool_result.loadedTools` 的并集(含摘要之前的;不在本步可用工具中的忽略),
|
|
81
82
|
* 按首次加载顺序追加在内置工具之后——新加载只在末尾追加,已发送的工具顺序不变;
|
|
82
83
|
* - 其余工具(不论是否已加载)以目录形式放进 system 第二个块(按 key 排序,打缓存断点),
|
|
@@ -224,17 +225,18 @@ export declare function summaryText(summary: string): string;
|
|
|
224
225
|
* 由会话事件日志 + agent 定义构建模型请求(纯函数,不做 I/O)。
|
|
225
226
|
* - system:`BEHAVIOR_RULES + "\n\n" + agent.instructions` 一个块,打缓存断点(a sub-agent's log:
|
|
226
227
|
* `BEHAVIOR_RULES`, its preamble and its instructions, all from its `subagent_started`);日志里第一份 `skills_catalog`
|
|
227
|
-
* 快照在任何 `model_call` 之前时,技能目录接在这个块末尾(Ruling M17,见 ./skills.ts);启用
|
|
228
|
+
* 快照在任何 `model_call` 之前时,技能目录接在这个块末尾(Ruling M17,见 ./skills.ts);启用 ToolSearch 时
|
|
228
229
|
* 第二个块是工具目录(见 {@link BuildModelRequestInput.toolSearch});
|
|
229
230
|
* - 之后的 `skills_catalog` 在所在位置渲染为 system 变更提醒;被压缩摘要覆盖的,若摘要时生效的目录与 system 里的
|
|
230
231
|
* 不同,紧随摘要补一条完整的当前目录;
|
|
231
232
|
* - messages:最近一条摘要(若有)作为首条 user 消息,其后按 seq 回放 `coversUpToSeq` 之后的
|
|
232
233
|
* `user_message` / `assistant_message`(content 原样,含 opaque;aborted 的也回放;媒体引用按
|
|
233
234
|
* {@link resolveMedia} 换成 base64 或文字占位)/ `reminder`
|
|
234
|
-
* (`role: "system"
|
|
235
|
+
* (`role: "system"`,放在它所在的位置)/ `background_task_finished`(`role: "system"`, the text of
|
|
236
|
+
* {@link renderBackgroundFinished}, placed like a user_message);`tool_result` 事件还原为紧随其 assistant 消息之后的一条 user 消息
|
|
235
237
|
* (同一步的多个结果合并,按该 assistant 消息里 tool_call 的顺序;找不到对应调用的结果不进请求)。
|
|
236
238
|
* 其他事件不进请求。提供 `absorbedUpToSeq` 时,
|
|
237
|
-
*
|
|
239
|
+
* 尚未被吸收的可吸收事件不进请求,运行中途到达的放在吸收它的调用处(见 BuildModelRequestInput)。
|
|
238
240
|
* 只追加:新事件只会在 messages 末尾追加;唯一的前缀变化来自新的压缩摘要。
|
|
239
241
|
* `step` 与 `agentVersion` 不进请求内容(保证缓存前缀稳定),由调用方写入 `model_call` 事件。
|
|
240
242
|
*/
|
|
@@ -245,7 +247,7 @@ export declare function buildModelRequest(input: BuildModelRequestInput): {
|
|
|
245
247
|
mediaTokens: number;
|
|
246
248
|
};
|
|
247
249
|
/**
|
|
248
|
-
* 日志里 `
|
|
250
|
+
* 日志里 `ToolSearch` 加载过的工具 key(全部 `tool_result.loadedTools` 的并集,按首次出现顺序)。
|
|
249
251
|
* 不看压缩摘要的边界:加载过的工具在摘要之后仍保持加载(模型可能凭摘要继续使用它们,且已发送的工具列表只追加)。
|
|
250
252
|
*/
|
|
251
253
|
export declare function loadedToolKeys(events: readonly ConversationEvent[]): string[];
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { MEDIA_LIMITS, } from "@capybara-hq/plugin-sdk";
|
|
3
|
+
import { renderBackgroundFinished } from "../../background/render.js";
|
|
4
|
+
import { isAbsorbable, } from "../../conversations/events.js";
|
|
3
5
|
import { catalogText, isAlwaysLoaded } from "../../tools/builtins/tool-search.js";
|
|
4
|
-
import {
|
|
6
|
+
import { LEGACY_CATALOG_HEADER, LEGACY_SKILL_TEXTS, usesLegacyToolNames } from "./legacy-text.js";
|
|
7
|
+
import { invokedSkillNames, invokedSkillsText, SKILL_TEXTS, skillsCatalogEvents, snapshotChangeText, snapshotCurrentText, snapshotSystemText, systemSkillsCatalog, } from "./skills.js";
|
|
5
8
|
/**
|
|
6
9
|
* 平台行为规范(模型可见,英文)。短而通用(spec 6 原则 5);不放时间戳、会话 ID 等会变化的内容,
|
|
7
10
|
* 保证同一 agent 版本在所有会话中 system 前缀一致、可命中提示词缓存。改动它会让所有缓存失效。
|
|
@@ -322,17 +325,18 @@ export function summaryText(summary) {
|
|
|
322
325
|
* 由会话事件日志 + agent 定义构建模型请求(纯函数,不做 I/O)。
|
|
323
326
|
* - system:`BEHAVIOR_RULES + "\n\n" + agent.instructions` 一个块,打缓存断点(a sub-agent's log:
|
|
324
327
|
* `BEHAVIOR_RULES`, its preamble and its instructions, all from its `subagent_started`);日志里第一份 `skills_catalog`
|
|
325
|
-
* 快照在任何 `model_call` 之前时,技能目录接在这个块末尾(Ruling M17,见 ./skills.ts);启用
|
|
328
|
+
* 快照在任何 `model_call` 之前时,技能目录接在这个块末尾(Ruling M17,见 ./skills.ts);启用 ToolSearch 时
|
|
326
329
|
* 第二个块是工具目录(见 {@link BuildModelRequestInput.toolSearch});
|
|
327
330
|
* - 之后的 `skills_catalog` 在所在位置渲染为 system 变更提醒;被压缩摘要覆盖的,若摘要时生效的目录与 system 里的
|
|
328
331
|
* 不同,紧随摘要补一条完整的当前目录;
|
|
329
332
|
* - messages:最近一条摘要(若有)作为首条 user 消息,其后按 seq 回放 `coversUpToSeq` 之后的
|
|
330
333
|
* `user_message` / `assistant_message`(content 原样,含 opaque;aborted 的也回放;媒体引用按
|
|
331
334
|
* {@link resolveMedia} 换成 base64 或文字占位)/ `reminder`
|
|
332
|
-
* (`role: "system"
|
|
335
|
+
* (`role: "system"`,放在它所在的位置)/ `background_task_finished`(`role: "system"`, the text of
|
|
336
|
+
* {@link renderBackgroundFinished}, placed like a user_message);`tool_result` 事件还原为紧随其 assistant 消息之后的一条 user 消息
|
|
333
337
|
* (同一步的多个结果合并,按该 assistant 消息里 tool_call 的顺序;找不到对应调用的结果不进请求)。
|
|
334
338
|
* 其他事件不进请求。提供 `absorbedUpToSeq` 时,
|
|
335
|
-
*
|
|
339
|
+
* 尚未被吸收的可吸收事件不进请求,运行中途到达的放在吸收它的调用处(见 BuildModelRequestInput)。
|
|
336
340
|
* 只追加:新事件只会在 messages 末尾追加;唯一的前缀变化来自新的压缩摘要。
|
|
337
341
|
* `step` 与 `agentVersion` 不进请求内容(保证缓存前缀稳定),由调用方写入 `model_call` 事件。
|
|
338
342
|
*/
|
|
@@ -377,7 +381,7 @@ export function buildModelRequest(input) {
|
|
|
377
381
|
lastCall = absorbedBy(e);
|
|
378
382
|
}
|
|
379
383
|
/**
|
|
380
|
-
* 第 i
|
|
384
|
+
* 第 i 个事件(可吸收事件:user_message / background_task_finished)的放置方式:
|
|
381
385
|
* - `inline`:在吸收它的调用(之后第一个 `absorbedBy ≥ seq` 的 model_call,或本次请求)之前,
|
|
382
386
|
* 没有「由未吸收它的调用生成的回复」→ 按 seq 原位回放(常规情况,与不提供 absorbedUpToSeq 时一致);
|
|
383
387
|
* - `deferred`:它之后有非空 assistant_message 是由一次没有吸收它的 model_call 生成的(它在那一步
|
|
@@ -461,8 +465,12 @@ export function buildModelRequest(input) {
|
|
|
461
465
|
const blocks = blocksOf(u.payload.content);
|
|
462
466
|
return report === undefined ? blocks : [...blocks, { type: "text", text: report }];
|
|
463
467
|
};
|
|
464
|
-
/**
|
|
468
|
+
/** 被某次模型调用跳过(运行中途到达)、尚未被吸收的可吸收事件,按 seq 升序。 */
|
|
465
469
|
let deferred = [];
|
|
470
|
+
/** An absorbable event as a request message: a user turn, or a finished task's system text. */
|
|
471
|
+
const absorbableMessage = (e) => e.type === "user_message"
|
|
472
|
+
? { role: "user", content: userBlocks(e) }
|
|
473
|
+
: { role: "system", content: renderBackgroundFinished(e.payload) };
|
|
466
474
|
/**
|
|
467
475
|
* 把已被吸收(seq ≤ upTo)的延后消息按 seq 顺序放进 messages,插在末尾连续的 system 提醒之前
|
|
468
476
|
* (若有)。这样某一步自己写在 model_call 之前的提醒(含收尾提醒)仍排在它所跟随的用户消息之后,
|
|
@@ -476,7 +484,7 @@ export function buildModelRequest(input) {
|
|
|
476
484
|
let at = messages.length;
|
|
477
485
|
while (at > 0 && messages[at - 1]?.role === "system")
|
|
478
486
|
at--;
|
|
479
|
-
messages.splice(at, 0, ...ready.map(
|
|
487
|
+
messages.splice(at, 0, ...ready.map(absorbableMessage));
|
|
480
488
|
};
|
|
481
489
|
/** (runId, callId) → 该调用的 tool_result 事件(同一调用只取第一个)。 */
|
|
482
490
|
const results = new Map();
|
|
@@ -488,6 +496,10 @@ export function buildModelRequest(input) {
|
|
|
488
496
|
if (!results.has(k))
|
|
489
497
|
results.set(k, e.payload);
|
|
490
498
|
}
|
|
499
|
+
// System texts naming a builtin: a request whose tools were recorded before the tool rename
|
|
500
|
+
// renders the frozen pre-rename wording, so it rebuilds exactly (tool naming spec §10)
|
|
501
|
+
const legacyNames = usesLegacyToolNames(input.tools ?? []);
|
|
502
|
+
const skillTexts = legacyNames ? LEGACY_SKILL_TEXTS : SKILL_TEXTS;
|
|
491
503
|
// 技能目录(Ruling M17):第一份快照进 system;之后的每份在所在位置追加变更提醒(相对上一份快照)。
|
|
492
504
|
const skillSnaps = skillsCatalogEvents(events);
|
|
493
505
|
const systemSkills = systemSkillsCatalog(events);
|
|
@@ -504,33 +516,34 @@ export function buildModelRequest(input) {
|
|
|
504
516
|
const covered = skillSnaps.filter((e) => e.seq <= after).at(-1);
|
|
505
517
|
// (phase B: plus the current pinned skills and tool-name map when they differ from system's)
|
|
506
518
|
if (covered && covered !== systemSkills) {
|
|
507
|
-
const text = snapshotCurrentText(systemSkills?.payload, covered.payload);
|
|
519
|
+
const text = snapshotCurrentText(systemSkills?.payload, covered.payload, skillTexts);
|
|
508
520
|
if (text !== "")
|
|
509
521
|
messages.push({ role: "system", content: text });
|
|
510
522
|
}
|
|
511
523
|
// phase D: the skills a person invoked in the summarised range, by name (from the log only)
|
|
512
|
-
const invoked = invokedSkillsText(invokedSkillNames(events, after));
|
|
524
|
+
const invoked = invokedSkillsText(invokedSkillNames(events, after), skillTexts);
|
|
513
525
|
if (invoked !== "")
|
|
514
526
|
messages.push({ role: "system", content: invoked });
|
|
515
527
|
}
|
|
516
528
|
for (const [i, e] of events.entries()) {
|
|
517
529
|
if (e.seq <= after)
|
|
518
530
|
continue;
|
|
531
|
+
if (isAbsorbable(e)) {
|
|
532
|
+
switch (absorbed === undefined ? "inline" : placement(i, e.seq)) {
|
|
533
|
+
case "inline":
|
|
534
|
+
// seq 更小的延后事件被同一次或更早的调用吸收:先放它们,保持发送顺序。
|
|
535
|
+
flush(e.seq - 1);
|
|
536
|
+
messages.push(absorbableMessage(e));
|
|
537
|
+
break;
|
|
538
|
+
case "deferred":
|
|
539
|
+
deferred.push(e);
|
|
540
|
+
break;
|
|
541
|
+
default:
|
|
542
|
+
break;
|
|
543
|
+
}
|
|
544
|
+
continue;
|
|
545
|
+
}
|
|
519
546
|
switch (e.type) {
|
|
520
|
-
case "user_message":
|
|
521
|
-
switch (absorbed === undefined ? "inline" : placement(i, e.seq)) {
|
|
522
|
-
case "inline":
|
|
523
|
-
// seq 更小的延后消息被同一次或更早的调用吸收:先放它们,保持用户消息的发送顺序。
|
|
524
|
-
flush(e.seq - 1);
|
|
525
|
-
messages.push({ role: "user", content: userBlocks(e) });
|
|
526
|
-
break;
|
|
527
|
-
case "deferred":
|
|
528
|
-
deferred.push(e);
|
|
529
|
-
break;
|
|
530
|
-
default:
|
|
531
|
-
break;
|
|
532
|
-
}
|
|
533
|
-
break;
|
|
534
547
|
case "model_call":
|
|
535
548
|
emitRaced(e.payload.request.toSeq);
|
|
536
549
|
if (absorbed !== undefined)
|
|
@@ -588,7 +601,7 @@ export function buildModelRequest(input) {
|
|
|
588
601
|
break;
|
|
589
602
|
case "skills_catalog":
|
|
590
603
|
if (e !== systemSkills) {
|
|
591
|
-
const text = snapshotChangeText(prevSnapshot.get(e.seq), e.payload);
|
|
604
|
+
const text = snapshotChangeText(prevSnapshot.get(e.seq), e.payload, skillTexts);
|
|
592
605
|
if (text !== "")
|
|
593
606
|
messages.push({ role: "system", content: text });
|
|
594
607
|
}
|
|
@@ -608,7 +621,9 @@ export function buildModelRequest(input) {
|
|
|
608
621
|
: `${BEHAVIOR_RULES}\n\n${agent.instructions}`;
|
|
609
622
|
const system = [
|
|
610
623
|
{
|
|
611
|
-
text: systemSkills
|
|
624
|
+
text: systemSkills
|
|
625
|
+
? `${base}\n\n${snapshotSystemText(systemSkills.payload, skillTexts)}`
|
|
626
|
+
: base,
|
|
612
627
|
cache: true,
|
|
613
628
|
},
|
|
614
629
|
];
|
|
@@ -622,7 +637,10 @@ export function buildModelRequest(input) {
|
|
|
622
637
|
tools = [...sorted.filter((t) => isAlwaysLoaded(t.key)), ...loaded];
|
|
623
638
|
if (deferred.length > 0) {
|
|
624
639
|
catalog = deferred;
|
|
625
|
-
system.push({
|
|
640
|
+
system.push({
|
|
641
|
+
text: catalogText(deferred, legacyNames ? LEGACY_CATALOG_HEADER : undefined),
|
|
642
|
+
cache: true,
|
|
643
|
+
});
|
|
626
644
|
}
|
|
627
645
|
}
|
|
628
646
|
const request = {
|
|
@@ -664,7 +682,7 @@ export function buildModelRequest(input) {
|
|
|
664
682
|
return { request, meta, mediaTokens };
|
|
665
683
|
}
|
|
666
684
|
/**
|
|
667
|
-
* 日志里 `
|
|
685
|
+
* 日志里 `ToolSearch` 加载过的工具 key(全部 `tool_result.loadedTools` 的并集,按首次出现顺序)。
|
|
668
686
|
* 不看压缩摘要的边界:加载过的工具在摘要之后仍保持加载(模型可能凭摘要继续使用它们,且已发送的工具列表只追加)。
|
|
669
687
|
*/
|
|
670
688
|
export function loadedToolKeys(events) {
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* English, fixed (Decision 15: not tailored to the agent's tools; it says "when it is in your
|
|
7
7
|
* tools" instead). Changing it only affects snapshots written afterwards: a conversation's next
|
|
8
8
|
* run writes a new snapshot announcing the new map, and old snapshots keep their text (phase C
|
|
9
|
-
* changed the Task / Agent line, sub-agents spec §16.5
|
|
9
|
+
* changed the Task / Agent line, sub-agents spec §16.5; the tool-naming change shortened it to the
|
|
10
|
+
* Claude Code names, spec 2026-10-29 §6; background Bash made TaskOutput and TaskStop available,
|
|
11
|
+
* spec 2026-11-05 §4.4; WebFetch and WebSearch joined the same-name list with the web tools).
|
|
10
12
|
*/
|
|
11
13
|
export declare const CLAUDE_CODE_TOOL_MAP: string;
|
|
@@ -6,19 +6,19 @@
|
|
|
6
6
|
* English, fixed (Decision 15: not tailored to the agent's tools; it says "when it is in your
|
|
7
7
|
* tools" instead). Changing it only affects snapshots written afterwards: a conversation's next
|
|
8
8
|
* run writes a new snapshot announcing the new map, and old snapshots keep their text (phase C
|
|
9
|
-
* changed the Task / Agent line, sub-agents spec §16.5
|
|
9
|
+
* changed the Task / Agent line, sub-agents spec §16.5; the tool-naming change shortened it to the
|
|
10
|
+
* Claude Code names, spec 2026-10-29 §6; background Bash made TaskOutput and TaskStop available,
|
|
11
|
+
* spec 2026-11-05 §4.4; WebFetch and WebSearch joined the same-name list with the web tools).
|
|
10
12
|
*/
|
|
11
13
|
export const CLAUDE_CODE_TOOL_MAP = [
|
|
12
|
-
"Some skills in this conversation were written for Claude Code
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
"- TodoWrite ->
|
|
17
|
-
"-
|
|
18
|
-
"-
|
|
19
|
-
"-
|
|
20
|
-
"- TaskOutput, TaskStop -> not available",
|
|
21
|
-
"- Any other tool a skill names (for example WebFetch, WebSearch, NotebookEdit, EnterWorktree) -> not available unless one of your tools does the same job",
|
|
14
|
+
"Some skills in this conversation were written for Claude Code. Its tools Bash, Read, Write, Edit,",
|
|
15
|
+
"Glob, Grep, Skill, AskUserQuestion, ToolSearch, Agent, WebFetch and WebSearch have the same names here, when they are",
|
|
16
|
+
"in your tools. For the others:",
|
|
17
|
+
"- MultiEdit -> several Edit calls",
|
|
18
|
+
"- TodoWrite -> plugin__todo__write when it is in your tools; otherwise keep the task list in your replies",
|
|
19
|
+
"- Task -> Agent; SendMessage to a sub-agent -> Agent with resume; model names haiku / sonnet / opus -> fast / standard / capable",
|
|
20
|
+
"- TaskOutput -> TaskOutput, TaskStop -> TaskStop",
|
|
21
|
+
"- Any other tool a skill names (for example NotebookEdit, EnterWorktree) -> not available unless one of your tools does the same job",
|
|
22
22
|
// biome-ignore lint/suspicious/noTemplateCurlyInString: the literal Claude Code variable the model reads
|
|
23
|
-
"The sandbox tools exist only when this agent has a sandbox; without them a skill's scripts cannot run. A path such as ${CLAUDE_PLUGIN_ROOT}/skills/<name>/... means /skills/<name>/... after
|
|
23
|
+
"The sandbox tools exist only when this agent has a sandbox; without them a skill's scripts cannot run. A path such as ${CLAUDE_PLUGIN_ROOT}/skills/<name>/... means /skills/<name>/... after Skill has copied that skill into the sandbox.",
|
|
24
24
|
].join("\n");
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { renderBackgroundFinished } from "../../background/render.js";
|
|
1
2
|
import { latestSummary } from "./build.js";
|
|
2
3
|
/** 压缩请求的标记:放在 system 中,便于识别(model-fake 据此返回摘要)。 */
|
|
3
4
|
export const COMPACTION_MARKER = "CAPYBARA_COMPACTION";
|
|
@@ -111,6 +112,9 @@ function transcriptLine(e) {
|
|
|
111
112
|
}
|
|
112
113
|
case "reminder":
|
|
113
114
|
return `System reminder: ${e.payload.text}`;
|
|
115
|
+
// a finished background task is a system message of the request (build.ts)
|
|
116
|
+
case "background_task_finished":
|
|
117
|
+
return `System reminder: ${renderBackgroundFinished(e.payload)}`;
|
|
114
118
|
// phase D: a forked skill's report is user content of the request (build.ts)
|
|
115
119
|
case "skill_fork_result":
|
|
116
120
|
return `User: ${e.payload.text}`;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SkillTexts } from "./skills.js";
|
|
2
|
+
/**
|
|
3
|
+
* The system texts of a request as the release candidates rendered them, naming the old builtins
|
|
4
|
+
* (`skill_load`, `tool_search`). FROZEN: verbatim copies from `main` at 02b9634b
|
|
5
|
+
* (`runtime/context/skills.ts`, `tools/builtins/tool-search.ts`); never edit them. A request whose
|
|
6
|
+
* tools hold an old builtin key (a recording made before the rename) is rebuilt with these, so it
|
|
7
|
+
* reconstructs with no `system_hash` drift (tool naming spec §10). `check:terms` exempts this file.
|
|
8
|
+
*
|
|
9
|
+
* The skills texts (`skills.ts`) naming `skill_load`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const LEGACY_SKILL_TEXTS: SkillTexts;
|
|
12
|
+
/** The tool catalog header (`tools/builtins/tool-search.ts` `CATALOG_HEADER`) naming `tool_search`. */
|
|
13
|
+
export declare const LEGACY_CATALOG_HEADER: string;
|
|
14
|
+
/**
|
|
15
|
+
* Was this request's tool list recorded before the rename? True when one of its tool keys is a
|
|
16
|
+
* release-candidate builtin name (the run's tools, as the request carries them). Every request
|
|
17
|
+
* that renders one of these texts offers the tool it names (`skill_load` whenever the log has a
|
|
18
|
+
* skills catalog or an invocation, `tool_search` with a tool catalog), so the tools decide it.
|
|
19
|
+
*/
|
|
20
|
+
export declare function usesLegacyToolNames(tools: readonly {
|
|
21
|
+
key: string;
|
|
22
|
+
}[]): boolean;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { isLegacyBuiltinKey } from "../../tools/legacy-keys.js";
|
|
2
|
+
/**
|
|
3
|
+
* The system texts of a request as the release candidates rendered them, naming the old builtins
|
|
4
|
+
* (`skill_load`, `tool_search`). FROZEN: verbatim copies from `main` at 02b9634b
|
|
5
|
+
* (`runtime/context/skills.ts`, `tools/builtins/tool-search.ts`); never edit them. A request whose
|
|
6
|
+
* tools hold an old builtin key (a recording made before the rename) is rebuilt with these, so it
|
|
7
|
+
* reconstructs with no `system_hash` drift (tool naming spec §10). `check:terms` exempts this file.
|
|
8
|
+
*
|
|
9
|
+
* The skills texts (`skills.ts`) naming `skill_load`.
|
|
10
|
+
*/
|
|
11
|
+
export const LEGACY_SKILL_TEXTS = Object.freeze({
|
|
12
|
+
skillsCatalogHeader: "Skills are available in this conversation. A skill is a set of instructions, sometimes with " +
|
|
13
|
+
"scripts or other files, for a specific kind of task. When a task matches a skill's description, " +
|
|
14
|
+
"call skill_load with the skill's name to read its instructions before you start; do not guess " +
|
|
15
|
+
"what a skill says. Available skills:",
|
|
16
|
+
newSkills: "New skills (call skill_load with the name to use one):",
|
|
17
|
+
updatedSkills: "Updated skills (call skill_load again before relying on earlier instructions):",
|
|
18
|
+
currentSkills: "Skills available in this conversation now (this replaces any earlier list of skills; call " +
|
|
19
|
+
"skill_load with a name to read a skill's instructions):",
|
|
20
|
+
invokedSkills: (names) => `Skills the user invoked earlier in this conversation: ${names.join(", ")}. Call skill_load with a name to read its instructions again.`,
|
|
21
|
+
pinnedSkillsHeader: "Pinned skills: the owner of this agent pinned these skills, so their instructions apply " +
|
|
22
|
+
"throughout this conversation. Follow them without calling skill_load; call skill_load " +
|
|
23
|
+
"only to copy a pinned skill's files into the sandbox.",
|
|
24
|
+
});
|
|
25
|
+
/** The tool catalog header (`tools/builtins/tool-search.ts` `CATALOG_HEADER`) naming `tool_search`. */
|
|
26
|
+
export const LEGACY_CATALOG_HEADER = "More tools are available but not loaded. To use one, first call tool_search with keywords; " +
|
|
27
|
+
"it returns the full definitions and loads the matching tools for your next step. " +
|
|
28
|
+
"Calling a tool that is not loaded returns an error. Tool catalog:";
|
|
29
|
+
/**
|
|
30
|
+
* Was this request's tool list recorded before the rename? True when one of its tool keys is a
|
|
31
|
+
* release-candidate builtin name (the run's tools, as the request carries them). Every request
|
|
32
|
+
* that renders one of these texts offers the tool it names (`skill_load` whenever the log has a
|
|
33
|
+
* skills catalog or an invocation, `tool_search` with a tool catalog), so the tools decide it.
|
|
34
|
+
*/
|
|
35
|
+
export function usesLegacyToolNames(tools) {
|
|
36
|
+
return tools.some((t) => isLegacyBuiltinKey(t.key));
|
|
37
|
+
}
|
|
@@ -13,14 +13,32 @@ export type PinnedSkill = NonNullable<SkillsSnapshot["pinned"]>[number];
|
|
|
13
13
|
export type SkillsCatalogEvent = Extract<ConversationEvent, {
|
|
14
14
|
type: "skills_catalog";
|
|
15
15
|
}>;
|
|
16
|
-
/**
|
|
17
|
-
|
|
16
|
+
/**
|
|
17
|
+
* The model-visible skills texts that name the skill-loading builtin. A request recorded before the
|
|
18
|
+
* tool rename renders {@link LEGACY_SKILL_TEXTS} instead (`./legacy-text.ts`, chosen from the
|
|
19
|
+
* request's tools by `usesLegacyToolNames`), so its system text stays as it was sent.
|
|
20
|
+
*/
|
|
21
|
+
export interface SkillTexts {
|
|
22
|
+
/** The header of the first catalog (in the system cache segment). */
|
|
23
|
+
skillsCatalogHeader: string;
|
|
24
|
+
/** The heading of the added skills in a change notice. */
|
|
25
|
+
newSkills: string;
|
|
26
|
+
/** The heading of the updated skills in a change notice. */
|
|
27
|
+
updatedSkills: string;
|
|
28
|
+
/** The heading of the current catalog after a compaction summary. */
|
|
29
|
+
currentSkills: string;
|
|
30
|
+
/** The line restored after a compaction summary for the invoked skills (`names` non-empty). */
|
|
31
|
+
invokedSkills: (names: readonly string[]) => string;
|
|
32
|
+
/** The header of the pinned skills in the system cache segment. */
|
|
33
|
+
pinnedSkillsHeader: string;
|
|
34
|
+
}
|
|
35
|
+
export declare const SKILL_TEXTS: SkillTexts;
|
|
18
36
|
/** 目录开头的说明(system 缓存段里的第一份目录)。 */
|
|
19
37
|
export declare const SKILLS_CATALOG_HEADER: string;
|
|
20
|
-
/** 目录里每个技能描述最多的码点数(超出确定地截断;`
|
|
38
|
+
/** 目录里每个技能描述最多的码点数(超出确定地截断;`Skill` 仍返回完整正文)。 */
|
|
21
39
|
export declare const CATALOG_DESCRIPTION_MAX_CHARS = 300;
|
|
22
40
|
/** 第一份目录(进 system 缓存段),按名字排序。 */
|
|
23
|
-
export declare function skillsCatalogText(skills: readonly CatalogSkill[]): string;
|
|
41
|
+
export declare function skillsCatalogText(skills: readonly CatalogSkill[], texts?: SkillTexts): string;
|
|
24
42
|
/** 两份快照是否相同(按 id、版本、名字、描述与来源)。顺序无关。 */
|
|
25
43
|
export declare function sameSkills(a: readonly CatalogSkill[], b: readonly CatalogSkill[]): boolean;
|
|
26
44
|
/**
|
|
@@ -41,14 +59,14 @@ export declare function sameSnapshot(a: SkillsSnapshot, b: SkillsSnapshot): bool
|
|
|
41
59
|
* 试用草稿被拒绝 / 批准了别人的同号版本时,内容变了而版本号可能不变)。
|
|
42
60
|
* `prev` 为上一份快照(没有为空)。
|
|
43
61
|
*/
|
|
44
|
-
export declare function skillsChangeText(prev: readonly CatalogSkill[], next: readonly CatalogSkill[], pinnedIds?: ReadonlySet<string
|
|
62
|
+
export declare function skillsChangeText(prev: readonly CatalogSkill[], next: readonly CatalogSkill[], pinnedIds?: ReadonlySet<string>, texts?: SkillTexts): string;
|
|
45
63
|
/** 压缩摘要之后补上的「当前目录」(与 system 里的第一份不同时):完整列出,替代之前的目录与提醒。 */
|
|
46
|
-
export declare function skillsCurrentText(skills: readonly CatalogSkill[]): string;
|
|
64
|
+
export declare function skillsCurrentText(skills: readonly CatalogSkill[], texts?: SkillTexts): string;
|
|
47
65
|
/**
|
|
48
66
|
* The line restored after a compaction summary whose range holds inline skill invocations
|
|
49
67
|
* (`names`: distinct, code point order); empty for none. Bodies are not re-injected.
|
|
50
68
|
*/
|
|
51
|
-
export declare function invokedSkillsText(names: readonly string[]): string;
|
|
69
|
+
export declare function invokedSkillsText(names: readonly string[], texts?: SkillTexts): string;
|
|
52
70
|
/** The distinct names (code point order) of the inline invocations in `events` up to `upToSeq`. */
|
|
53
71
|
export declare function invokedSkillNames(events: readonly ConversationEvent[], upToSeq: number): string[];
|
|
54
72
|
/** A skill a person invoked: the version recorded in their message. */
|
|
@@ -78,7 +96,7 @@ export declare const PINNED_SKILLS_HEADER: string;
|
|
|
78
96
|
/** One pinned skill with its body. */
|
|
79
97
|
export declare function pinnedBlock(p: PinnedSkill): string;
|
|
80
98
|
/** The pinned skills of the system snapshot (non-empty), after the catalog. */
|
|
81
|
-
export declare function pinnedSystemText(pinned: readonly PinnedSkill[]): string;
|
|
99
|
+
export declare function pinnedSystemText(pinned: readonly PinnedSkill[], texts?: SkillTexts): string;
|
|
82
100
|
/**
|
|
83
101
|
* The pinned change notice between two snapshots ({@link samePinned} false): each entry that is new
|
|
84
102
|
* or has another version or source, with its whole body; then the names of the removed ones.
|
|
@@ -94,12 +112,12 @@ export declare function toolMapChangeText(next: string | undefined): string;
|
|
|
94
112
|
* nothing else differs: logs before phase B render exactly as before), the pinned change, the
|
|
95
113
|
* tool-name map change; joined by blank lines.
|
|
96
114
|
*/
|
|
97
|
-
export declare function snapshotChangeText(prev: SkillsSnapshot | undefined, next: SkillsSnapshot): string;
|
|
115
|
+
export declare function snapshotChangeText(prev: SkillsSnapshot | undefined, next: SkillsSnapshot, texts?: SkillTexts): string;
|
|
98
116
|
/**
|
|
99
117
|
* What follows a compaction summary when the covered snapshot is not the system one: today's
|
|
100
118
|
* current catalog (when the skills differ from the system snapshot's), the current pinned skills
|
|
101
119
|
* (when they differ), the tool-name map (when it differs); joined by blank lines, "" for nothing.
|
|
102
120
|
*/
|
|
103
|
-
export declare function snapshotCurrentText(system: SkillsSnapshot | undefined, covered: SkillsSnapshot): string;
|
|
121
|
+
export declare function snapshotCurrentText(system: SkillsSnapshot | undefined, covered: SkillsSnapshot, texts?: SkillTexts): string;
|
|
104
122
|
/** The system snapshot's text after the agent's instructions: catalog, pinned skills, tool map. */
|
|
105
|
-
export declare function snapshotSystemText(s: SkillsSnapshot): string;
|
|
123
|
+
export declare function snapshotSystemText(s: SkillsSnapshot, texts?: SkillTexts): string;
|