@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
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
-- Tool naming (spec docs/superpowers/specs/2026-10-29-tool-naming-claude-code-design.md §8.2):
|
|
2
|
+
-- the release candidates' tool keys in mutable state become the current keys. Builtins by the
|
|
3
|
+
-- frozen map of packages/kernel/src/tools/legacy-keys.ts (LEGACY_BUILTINS); an rc `<x>__<tool>`
|
|
4
|
+
-- key becomes `mcp__<x>__<tool>` when `x` is a connector of the row's org (or the row records its
|
|
5
|
+
-- connector) and `plugin__<x>__<tool>` when `x` is an extension of the deployment
|
|
6
|
+
-- (extension_installs, or extension_name_owners for config-declared ones); when both or neither,
|
|
7
|
+
-- the row stays and the kernel's startup notice `tools.legacy_key_unmapped` counts it.
|
|
8
|
+
-- Keys in the current format never match. A grant whose new key already exists for the same
|
|
9
|
+
-- owner is left as it is (the primary key). Decided approvals and answered questions are
|
|
10
|
+
-- history and stay. Logs and recordings are never rewritten (§8). Idempotent: a second run
|
|
11
|
+
-- matches nothing it could change.
|
|
12
|
+
|
|
13
|
+
-- capybara:allow-destructive rewrites rc tool keys in place (the old keys no longer name a tool; the kernel reads only the new ones)
|
|
14
|
+
UPDATE tool_grants g
|
|
15
|
+
SET tool_key = m.new_key
|
|
16
|
+
FROM (VALUES
|
|
17
|
+
('sandbox_bash', 'Bash'), ('sandbox_read', 'Read'), ('sandbox_write', 'Write'),
|
|
18
|
+
('sandbox_edit', 'Edit'), ('sandbox_glob', 'Glob'), ('sandbox_grep', 'Grep'),
|
|
19
|
+
('sandbox_deliver', 'Deliver'), ('skill_load', 'Skill'), ('skill_write', 'SkillWrite'),
|
|
20
|
+
('ask_user', 'AskUserQuestion'), ('read_tool_output', 'ReadToolOutput'),
|
|
21
|
+
('tool_search', 'ToolSearch'), ('agent', 'Agent')
|
|
22
|
+
) AS m(old_key, new_key)
|
|
23
|
+
WHERE g.tool_key = m.old_key
|
|
24
|
+
AND NOT EXISTS (
|
|
25
|
+
SELECT 1 FROM tool_grants x
|
|
26
|
+
WHERE x.org_id = g.org_id AND x.account_id = g.account_id AND x.agent_id = g.agent_id
|
|
27
|
+
AND x.tool_key = m.new_key
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
-- capybara:allow-destructive rewrites rc tool keys in place (the old keys no longer name a tool; the kernel reads only the new ones)
|
|
31
|
+
UPDATE tool_grants g
|
|
32
|
+
SET tool_key = CASE
|
|
33
|
+
WHEN g.connector_id IS NOT NULL OR (
|
|
34
|
+
EXISTS (SELECT 1 FROM connectors c
|
|
35
|
+
WHERE c.org_id = g.org_id AND c.deleted_at IS NULL
|
|
36
|
+
AND c.slug = split_part(g.tool_key, '__', 1))
|
|
37
|
+
AND split_part(g.tool_key, '__', 1) NOT IN (
|
|
38
|
+
SELECT name FROM extension_installs UNION SELECT name FROM extension_name_owners)
|
|
39
|
+
) THEN 'mcp__' || g.tool_key
|
|
40
|
+
ELSE 'plugin__' || g.tool_key
|
|
41
|
+
END
|
|
42
|
+
WHERE g.tool_key ~ '^[a-z0-9][a-z0-9_-]*__.' AND g.tool_key !~ '^(mcp|plugin)__'
|
|
43
|
+
AND (
|
|
44
|
+
g.connector_id IS NOT NULL
|
|
45
|
+
OR (
|
|
46
|
+
EXISTS (SELECT 1 FROM connectors c
|
|
47
|
+
WHERE c.org_id = g.org_id AND c.deleted_at IS NULL
|
|
48
|
+
AND c.slug = split_part(g.tool_key, '__', 1))
|
|
49
|
+
) <> (
|
|
50
|
+
split_part(g.tool_key, '__', 1) IN (
|
|
51
|
+
SELECT name FROM extension_installs UNION SELECT name FROM extension_name_owners)
|
|
52
|
+
)
|
|
53
|
+
)
|
|
54
|
+
AND NOT EXISTS (
|
|
55
|
+
SELECT 1 FROM tool_grants x
|
|
56
|
+
WHERE x.org_id = g.org_id AND x.account_id = g.account_id AND x.agent_id = g.agent_id
|
|
57
|
+
AND x.tool_key IN ('mcp__' || g.tool_key, 'plugin__' || g.tool_key)
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
-- capybara:allow-destructive rewrites rc tool keys in place (the old keys no longer name a tool; the kernel reads only the new ones)
|
|
61
|
+
UPDATE conversation_tool_grants g
|
|
62
|
+
SET tool_key = m.new_key
|
|
63
|
+
FROM (VALUES
|
|
64
|
+
('sandbox_bash', 'Bash'), ('sandbox_read', 'Read'), ('sandbox_write', 'Write'),
|
|
65
|
+
('sandbox_edit', 'Edit'), ('sandbox_glob', 'Glob'), ('sandbox_grep', 'Grep'),
|
|
66
|
+
('sandbox_deliver', 'Deliver'), ('skill_load', 'Skill'), ('skill_write', 'SkillWrite'),
|
|
67
|
+
('ask_user', 'AskUserQuestion'), ('read_tool_output', 'ReadToolOutput'),
|
|
68
|
+
('tool_search', 'ToolSearch'), ('agent', 'Agent')
|
|
69
|
+
) AS m(old_key, new_key)
|
|
70
|
+
WHERE g.tool_key = m.old_key
|
|
71
|
+
AND NOT EXISTS (
|
|
72
|
+
SELECT 1 FROM conversation_tool_grants x
|
|
73
|
+
WHERE x.conversation_id = g.conversation_id AND x.tool_key = m.new_key
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
-- capybara:allow-destructive rewrites rc tool keys in place (the old keys no longer name a tool; the kernel reads only the new ones)
|
|
77
|
+
UPDATE conversation_tool_grants g
|
|
78
|
+
SET tool_key = CASE
|
|
79
|
+
WHEN g.connector_id IS NOT NULL OR (
|
|
80
|
+
EXISTS (SELECT 1 FROM connectors c
|
|
81
|
+
WHERE c.org_id = v.org_id AND c.deleted_at IS NULL
|
|
82
|
+
AND c.slug = split_part(g.tool_key, '__', 1))
|
|
83
|
+
AND split_part(g.tool_key, '__', 1) NOT IN (
|
|
84
|
+
SELECT name FROM extension_installs UNION SELECT name FROM extension_name_owners)
|
|
85
|
+
) THEN 'mcp__' || g.tool_key
|
|
86
|
+
ELSE 'plugin__' || g.tool_key
|
|
87
|
+
END
|
|
88
|
+
FROM conversations v
|
|
89
|
+
WHERE v.id = g.conversation_id
|
|
90
|
+
AND g.tool_key ~ '^[a-z0-9][a-z0-9_-]*__.' AND g.tool_key !~ '^(mcp|plugin)__'
|
|
91
|
+
AND (
|
|
92
|
+
g.connector_id IS NOT NULL
|
|
93
|
+
OR (
|
|
94
|
+
EXISTS (SELECT 1 FROM connectors c
|
|
95
|
+
WHERE c.org_id = v.org_id AND c.deleted_at IS NULL
|
|
96
|
+
AND c.slug = split_part(g.tool_key, '__', 1))
|
|
97
|
+
) <> (
|
|
98
|
+
split_part(g.tool_key, '__', 1) IN (
|
|
99
|
+
SELECT name FROM extension_installs UNION SELECT name FROM extension_name_owners)
|
|
100
|
+
)
|
|
101
|
+
)
|
|
102
|
+
AND NOT EXISTS (
|
|
103
|
+
SELECT 1 FROM conversation_tool_grants x
|
|
104
|
+
WHERE x.conversation_id = g.conversation_id
|
|
105
|
+
AND x.tool_key IN ('mcp__' || g.tool_key, 'plugin__' || g.tool_key)
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
-- capybara:allow-destructive rewrites rc tool keys of pending approvals in place (resumed by run and call id, never by key)
|
|
109
|
+
UPDATE approvals a
|
|
110
|
+
SET tool_key = m.new_key
|
|
111
|
+
FROM (VALUES
|
|
112
|
+
('sandbox_bash', 'Bash'), ('sandbox_read', 'Read'), ('sandbox_write', 'Write'),
|
|
113
|
+
('sandbox_edit', 'Edit'), ('sandbox_glob', 'Glob'), ('sandbox_grep', 'Grep'),
|
|
114
|
+
('sandbox_deliver', 'Deliver'), ('skill_load', 'Skill'), ('skill_write', 'SkillWrite'),
|
|
115
|
+
('ask_user', 'AskUserQuestion'), ('read_tool_output', 'ReadToolOutput'),
|
|
116
|
+
('tool_search', 'ToolSearch'), ('agent', 'Agent')
|
|
117
|
+
) AS m(old_key, new_key)
|
|
118
|
+
WHERE a.status = 'pending' AND a.tool_key = m.old_key;
|
|
119
|
+
|
|
120
|
+
-- capybara:allow-destructive rewrites rc tool keys of pending approvals in place (resumed by run and call id, never by key)
|
|
121
|
+
UPDATE approvals a
|
|
122
|
+
SET tool_key = CASE
|
|
123
|
+
WHEN a.connector_id IS NOT NULL OR (
|
|
124
|
+
EXISTS (SELECT 1 FROM connectors c
|
|
125
|
+
WHERE c.org_id = a.org_id AND c.deleted_at IS NULL
|
|
126
|
+
AND c.slug = split_part(a.tool_key, '__', 1))
|
|
127
|
+
AND split_part(a.tool_key, '__', 1) NOT IN (
|
|
128
|
+
SELECT name FROM extension_installs UNION SELECT name FROM extension_name_owners)
|
|
129
|
+
) THEN 'mcp__' || a.tool_key
|
|
130
|
+
ELSE 'plugin__' || a.tool_key
|
|
131
|
+
END
|
|
132
|
+
WHERE a.status = 'pending'
|
|
133
|
+
AND a.tool_key ~ '^[a-z0-9][a-z0-9_-]*__.' AND a.tool_key !~ '^(mcp|plugin)__'
|
|
134
|
+
AND (
|
|
135
|
+
a.connector_id IS NOT NULL
|
|
136
|
+
OR (
|
|
137
|
+
EXISTS (SELECT 1 FROM connectors c
|
|
138
|
+
WHERE c.org_id = a.org_id AND c.deleted_at IS NULL
|
|
139
|
+
AND c.slug = split_part(a.tool_key, '__', 1))
|
|
140
|
+
) <> (
|
|
141
|
+
split_part(a.tool_key, '__', 1) IN (
|
|
142
|
+
SELECT name FROM extension_installs UNION SELECT name FROM extension_name_owners)
|
|
143
|
+
)
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
-- capybara:allow-destructive rewrites rc tool keys of pending questions in place (resumed by run and call id, never by key)
|
|
147
|
+
UPDATE questions q
|
|
148
|
+
SET spec = jsonb_set(q.spec, '{toolKey}', to_jsonb(m.new_key))
|
|
149
|
+
FROM (VALUES
|
|
150
|
+
('sandbox_bash', 'Bash'), ('sandbox_read', 'Read'), ('sandbox_write', 'Write'),
|
|
151
|
+
('sandbox_edit', 'Edit'), ('sandbox_glob', 'Glob'), ('sandbox_grep', 'Grep'),
|
|
152
|
+
('sandbox_deliver', 'Deliver'), ('skill_load', 'Skill'), ('skill_write', 'SkillWrite'),
|
|
153
|
+
('ask_user', 'AskUserQuestion'), ('read_tool_output', 'ReadToolOutput'),
|
|
154
|
+
('tool_search', 'ToolSearch'), ('agent', 'Agent')
|
|
155
|
+
) AS m(old_key, new_key)
|
|
156
|
+
WHERE q.status = 'pending' AND q.spec->>'toolKey' = m.old_key;
|
|
157
|
+
|
|
158
|
+
-- capybara:allow-destructive rewrites rc tool keys of pending questions in place (resumed by run and call id, never by key)
|
|
159
|
+
UPDATE questions q
|
|
160
|
+
SET spec = jsonb_set(
|
|
161
|
+
q.spec,
|
|
162
|
+
'{toolKey}',
|
|
163
|
+
to_jsonb(CASE
|
|
164
|
+
WHEN EXISTS (SELECT 1 FROM connectors c
|
|
165
|
+
WHERE c.org_id = q.org_id AND c.deleted_at IS NULL
|
|
166
|
+
AND c.slug = split_part(q.spec->>'toolKey', '__', 1))
|
|
167
|
+
THEN 'mcp__' || (q.spec->>'toolKey')
|
|
168
|
+
ELSE 'plugin__' || (q.spec->>'toolKey')
|
|
169
|
+
END)
|
|
170
|
+
)
|
|
171
|
+
WHERE q.status = 'pending'
|
|
172
|
+
AND q.spec->>'toolKey' ~ '^[a-z0-9][a-z0-9_-]*__.' AND q.spec->>'toolKey' !~ '^(mcp|plugin)__'
|
|
173
|
+
AND (
|
|
174
|
+
EXISTS (SELECT 1 FROM connectors c
|
|
175
|
+
WHERE c.org_id = q.org_id AND c.deleted_at IS NULL
|
|
176
|
+
AND c.slug = split_part(q.spec->>'toolKey', '__', 1))
|
|
177
|
+
) <> (
|
|
178
|
+
split_part(q.spec->>'toolKey', '__', 1) IN (
|
|
179
|
+
SELECT name FROM extension_installs UNION SELECT name FROM extension_name_owners)
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
-- What the startup notice counts (rows the statements above could not map), each over a partial
|
|
183
|
+
-- index holding only such rows, so the count at every start reads nearly empty indexes. The
|
|
184
|
+
-- predicate is the one of countLegacyToolKeys (packages/kernel/src/tools/legacy-data.ts).
|
|
185
|
+
CREATE INDEX IF NOT EXISTS tool_grants_legacy_key_idx ON tool_grants (org_id)
|
|
186
|
+
WHERE (tool_key = ANY (ARRAY['sandbox_bash', 'sandbox_read', 'sandbox_write', 'sandbox_edit',
|
|
187
|
+
'sandbox_glob', 'sandbox_grep', 'sandbox_deliver', 'skill_load', 'skill_write', 'ask_user',
|
|
188
|
+
'read_tool_output', 'tool_search', 'agent']::text[])
|
|
189
|
+
OR (tool_key ~ '^[a-z0-9][a-z0-9_-]*__.' AND tool_key !~ '^(mcp|plugin)__'));
|
|
190
|
+
CREATE INDEX IF NOT EXISTS conversation_tool_grants_legacy_key_idx
|
|
191
|
+
ON conversation_tool_grants (conversation_id)
|
|
192
|
+
WHERE (tool_key = ANY (ARRAY['sandbox_bash', 'sandbox_read', 'sandbox_write', 'sandbox_edit',
|
|
193
|
+
'sandbox_glob', 'sandbox_grep', 'sandbox_deliver', 'skill_load', 'skill_write', 'ask_user',
|
|
194
|
+
'read_tool_output', 'tool_search', 'agent']::text[])
|
|
195
|
+
OR (tool_key ~ '^[a-z0-9][a-z0-9_-]*__.' AND tool_key !~ '^(mcp|plugin)__'));
|
|
196
|
+
CREATE INDEX IF NOT EXISTS approvals_legacy_key_idx ON approvals (org_id)
|
|
197
|
+
WHERE status = 'pending'
|
|
198
|
+
AND (tool_key = ANY (ARRAY['sandbox_bash', 'sandbox_read', 'sandbox_write', 'sandbox_edit',
|
|
199
|
+
'sandbox_glob', 'sandbox_grep', 'sandbox_deliver', 'skill_load', 'skill_write', 'ask_user',
|
|
200
|
+
'read_tool_output', 'tool_search', 'agent']::text[])
|
|
201
|
+
OR (tool_key ~ '^[a-z0-9][a-z0-9_-]*__.' AND tool_key !~ '^(mcp|plugin)__'));
|
|
202
|
+
CREATE INDEX IF NOT EXISTS questions_legacy_key_idx ON questions (org_id)
|
|
203
|
+
WHERE status = 'pending'
|
|
204
|
+
AND ((spec->>'toolKey') = ANY (ARRAY['sandbox_bash', 'sandbox_read', 'sandbox_write',
|
|
205
|
+
'sandbox_edit', 'sandbox_glob', 'sandbox_grep', 'sandbox_deliver', 'skill_load', 'skill_write',
|
|
206
|
+
'ask_user', 'read_tool_output', 'tool_search', 'agent']::text[])
|
|
207
|
+
OR ((spec->>'toolKey') ~ '^[a-z0-9][a-z0-9_-]*__.' AND (spec->>'toolKey') !~ '^(mcp|plugin)__'));
|
|
208
|
+
|
|
209
|
+
-- Read before Write / Edit (spec §4.5): EventLog.latestFileState reads the latest tool_result of
|
|
210
|
+
-- a conversation whose view names a file, on every Write and Edit. Without this index it scans
|
|
211
|
+
-- the conversation's events backwards through the primary key, filtering each payload (EXPLAIN
|
|
212
|
+
-- on a 20 000-event conversation: every row removed by the filter for a path never read); with
|
|
213
|
+
-- it, one index probe. Partial: only tool_result rows. Built without CONCURRENTLY (a migration
|
|
214
|
+
-- runs in one transaction), which locks conversation_events against writes while it builds: this
|
|
215
|
+
-- assumes release-candidate-sized event tables, as the event indexes of 0025 and 0040 did. A
|
|
216
|
+
-- deployment with a large table builds it CONCURRENTLY by hand before upgrading; IF NOT EXISTS
|
|
217
|
+
-- then skips it here.
|
|
218
|
+
CREATE INDEX IF NOT EXISTS conversation_events_file_state_idx
|
|
219
|
+
ON conversation_events (conversation_id, ((payload->'view'->'file'->>'path')), seq DESC)
|
|
220
|
+
WHERE type = 'tool_result';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
-- The organization an account last chose as its current one: a new web session (login, SSO, setup,
|
|
2
|
+
-- an accepted invitation) starts in it while the account is still a member and the org is not
|
|
3
|
+
-- deleted, so people don't pick their org again at every sign-in. Written with the session's
|
|
4
|
+
-- current org by `PUT /me/current-org`; NULL = never chosen (a new session then starts in the only
|
|
5
|
+
-- org when there is exactly one). Additive: older replicas never read or write it.
|
|
6
|
+
ALTER TABLE capybara.accounts
|
|
7
|
+
ADD COLUMN IF NOT EXISTS last_org_id text REFERENCES capybara.orgs(id) ON DELETE SET NULL;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- A person archives a conversation (hidden from the default lists, still readable and unarchived
|
|
2
|
+
-- by a new message) or deletes it (soft: hidden everywhere for the owner; the event log, runs and
|
|
3
|
+
-- trajectories stay for enterprise admins).
|
|
4
|
+
ALTER TABLE capybara.conversations ADD COLUMN IF NOT EXISTS archived_at timestamptz;
|
|
5
|
+
ALTER TABLE capybara.conversations ADD COLUMN IF NOT EXISTS deleted_at timestamptz;
|
|
6
|
+
CREATE INDEX IF NOT EXISTS conversations_live_idx
|
|
7
|
+
ON capybara.conversations (org_id, account_id, updated_at DESC)
|
|
8
|
+
WHERE deleted_at IS NULL AND archived_at IS NULL;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
-- The plugin.json `displayName` ({ zh, en }) of an extension package, written when the package is
|
|
2
|
+
-- stored; NULL when the plugin has none and for packages stored before this migration (no
|
|
3
|
+
-- backfill: a name arrives with the next version). Additive: older replicas never read it.
|
|
4
|
+
ALTER TABLE capybara.extension_packages ADD COLUMN IF NOT EXISTS display_name jsonb;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
-- The agent profile (avatar, description, quick actions): display data stored beside the agent,
|
|
2
|
+
-- outside agent_versions, so changing it creates no version. Expand-only.
|
|
3
|
+
-- profile_updated_at is kept at millisecond precision so a client can send it back as expectedUpdatedAt.
|
|
4
|
+
ALTER TABLE capybara.agents ADD COLUMN IF NOT EXISTS profile_avatar jsonb;
|
|
5
|
+
ALTER TABLE capybara.agents ADD COLUMN IF NOT EXISTS profile_description text NOT NULL DEFAULT '';
|
|
6
|
+
ALTER TABLE capybara.agents
|
|
7
|
+
ADD COLUMN IF NOT EXISTS profile_quick_actions jsonb NOT NULL DEFAULT '[]';
|
|
8
|
+
ALTER TABLE capybara.agents
|
|
9
|
+
ADD COLUMN IF NOT EXISTS profile_updated_at timestamptz NOT NULL
|
|
10
|
+
DEFAULT date_trunc('milliseconds', now());
|
|
11
|
+
|
|
12
|
+
-- A definition's avatarUrl becomes an external avatar (once: only where none is set yet).
|
|
13
|
+
UPDATE capybara.agents a
|
|
14
|
+
SET profile_avatar = jsonb_build_object('kind', 'external', 'url', v.definition->>'avatarUrl')
|
|
15
|
+
FROM capybara.agent_versions v
|
|
16
|
+
WHERE v.agent_id = a.id
|
|
17
|
+
AND v.version = a.current_version
|
|
18
|
+
AND a.profile_avatar IS NULL
|
|
19
|
+
AND jsonb_typeof(v.definition->'avatarUrl') = 'string'
|
|
20
|
+
AND v.definition->>'avatarUrl' <> '';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
-- Agent avatar uploads reuse the presigned attachment flow: a new purpose 'agent-avatar' and the
|
|
2
|
+
-- agent whose profile uses the upload (set once on save; a used upload has no expiry).
|
|
3
|
+
ALTER TABLE capybara.attachments DROP CONSTRAINT IF EXISTS attachments_purpose_check;
|
|
4
|
+
ALTER TABLE capybara.attachments
|
|
5
|
+
ADD CONSTRAINT attachments_purpose_check
|
|
6
|
+
CHECK (purpose IN ('chat', 'skill-package', 'agent-avatar'));
|
|
7
|
+
ALTER TABLE capybara.attachments ADD COLUMN IF NOT EXISTS agent_id text;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
-- The agent avatar lookup and the cleanup of an agent's uploads filter attachments by agent_id;
|
|
2
|
+
-- a partial index keeps it small, since most attachments belong to no agent.
|
|
3
|
+
CREATE INDEX IF NOT EXISTS attachments_agent_idx ON capybara.attachments (agent_id) WHERE agent_id IS NOT NULL;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
-- Background Bash (spec 2026-11-05-background-bash-design §4.1): a command started with
|
|
2
|
+
-- run_in_background keeps running in the conversation's sandbox after its tool call returns. One
|
|
3
|
+
-- row per task; the owner is `conversation_id` (the child conversation for a sub-agent) and
|
|
4
|
+
-- `sandbox_conversation_id` is the root conversation that owns the sandbox. Rows go with their
|
|
5
|
+
-- conversations; finished rows are pruned after tools.outputRetentionDays.
|
|
6
|
+
CREATE TABLE IF NOT EXISTS capybara.background_tasks (
|
|
7
|
+
id text PRIMARY KEY,
|
|
8
|
+
org_id text NOT NULL,
|
|
9
|
+
conversation_id text NOT NULL REFERENCES capybara.conversations(id) ON DELETE CASCADE,
|
|
10
|
+
sandbox_conversation_id text NOT NULL REFERENCES capybara.conversations(id) ON DELETE CASCADE,
|
|
11
|
+
run_id text NOT NULL,
|
|
12
|
+
call_id text NOT NULL,
|
|
13
|
+
trigger_account_id text NOT NULL,
|
|
14
|
+
description text NOT NULL,
|
|
15
|
+
command text NOT NULL,
|
|
16
|
+
-- the session id: the pid `setsid` started; stopping and liveness go by the session
|
|
17
|
+
sid text NOT NULL,
|
|
18
|
+
-- relative to /workspace
|
|
19
|
+
output_path text NOT NULL,
|
|
20
|
+
status text NOT NULL DEFAULT 'running'
|
|
21
|
+
CHECK (status IN ('running', 'completed', 'failed', 'stopped', 'timed_out', 'lost')),
|
|
22
|
+
lost_reason text,
|
|
23
|
+
exit_code integer,
|
|
24
|
+
started_at timestamptz NOT NULL DEFAULT now(),
|
|
25
|
+
finished_at timestamptz,
|
|
26
|
+
deadline_at timestamptz NOT NULL,
|
|
27
|
+
-- the sandbox instance the task runs in (the handle plus created_at identify an instance)
|
|
28
|
+
sandbox_created_at timestamptz NOT NULL,
|
|
29
|
+
-- a task marked lost while its process may still exist
|
|
30
|
+
kill_pending boolean NOT NULL DEFAULT false,
|
|
31
|
+
-- the bytes TaskOutput has already returned
|
|
32
|
+
read_offset bigint NOT NULL DEFAULT 0
|
|
33
|
+
);
|
|
34
|
+
CREATE INDEX IF NOT EXISTS background_tasks_running_idx
|
|
35
|
+
ON capybara.background_tasks (sandbox_conversation_id) WHERE status = 'running';
|
|
36
|
+
CREATE INDEX IF NOT EXISTS background_tasks_conversation_idx
|
|
37
|
+
ON capybara.background_tasks (conversation_id, started_at DESC);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
-- Background Bash: a launch reserves its row (status running, counted against
|
|
2
|
+
-- sandbox.background.maxTasks under a transaction-scoped lock) before the launch exec, and sets
|
|
3
|
+
-- sid and sandbox_created_at once the command started. A row without a sid is a reservation: the
|
|
4
|
+
-- poller skips it, and a failed launch finishes it as failed.
|
|
5
|
+
ALTER TABLE IF EXISTS capybara.background_tasks ALTER COLUMN sid DROP NOT NULL;
|
|
6
|
+
ALTER TABLE IF EXISTS capybara.background_tasks ALTER COLUMN sandbox_created_at DROP NOT NULL;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
-- Background Bash: a stop claims its task before it signals the session (stopping_at), so the
|
|
2
|
+
-- poller, which skips a claimed task, cannot finish it meanwhile from what the signals leave
|
|
3
|
+
-- behind (no process, or the wrapper's exit status); the stop's own finish is then the only one.
|
|
4
|
+
-- A launch that finds its reservation claimed kills the command it started at once.
|
|
5
|
+
ALTER TABLE IF EXISTS capybara.background_tasks ADD COLUMN IF NOT EXISTS stopping_at timestamptz;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
-- Web tools (spec §6): an org's default provider of an extension point with `selection:
|
|
2
|
+
-- "org-default"` (`point` is the name without the major, e.g. `web-search`). A row naming an
|
|
3
|
+
-- extension that is disabled or uninstalled stays and is ignored until it is a candidate again.
|
|
4
|
+
CREATE TABLE IF NOT EXISTS capybara.org_extension_point_defaults (
|
|
5
|
+
org_id text NOT NULL REFERENCES capybara.orgs(id) ON DELETE CASCADE,
|
|
6
|
+
point text NOT NULL,
|
|
7
|
+
extension text NOT NULL,
|
|
8
|
+
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
9
|
+
updated_by text REFERENCES capybara.accounts(id) ON DELETE SET NULL,
|
|
10
|
+
PRIMARY KEY (org_id, point)
|
|
11
|
+
);
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 沙箱内置工具的名字(M5 T8,Ruling M12:工具 key 只能含字母数字、`_`、`-`,所以是 `sandbox_<动作>`)。
|
|
3
|
-
* 单独成文件:注册表与策略判定只需要名字,不引入工具实现。
|
|
4
|
-
*/
|
|
5
|
-
export declare const SANDBOX_TOOL_NAMES: readonly ["sandbox_bash", "sandbox_read", "sandbox_write", "sandbox_edit", "sandbox_glob", "sandbox_grep", "sandbox_deliver"];
|
|
6
|
-
/** 组织设置 `sandboxToolPolicy` 为 `ask` 时需要审批的沙箱工具(只读的 read / glob / grep 除外)。 */
|
|
7
|
-
export declare const SANDBOX_ASK_TOOL_NAMES: ReadonlySet<string>;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 沙箱内置工具的名字(M5 T8,Ruling M12:工具 key 只能含字母数字、`_`、`-`,所以是 `sandbox_<动作>`)。
|
|
3
|
-
* 单独成文件:注册表与策略判定只需要名字,不引入工具实现。
|
|
4
|
-
*/
|
|
5
|
-
export const SANDBOX_TOOL_NAMES = [
|
|
6
|
-
"sandbox_bash",
|
|
7
|
-
"sandbox_read",
|
|
8
|
-
"sandbox_write",
|
|
9
|
-
"sandbox_edit",
|
|
10
|
-
"sandbox_glob",
|
|
11
|
-
"sandbox_grep",
|
|
12
|
-
"sandbox_deliver",
|
|
13
|
-
];
|
|
14
|
-
/** 组织设置 `sandboxToolPolicy` 为 `ask` 时需要审批的沙箱工具(只读的 read / glob / grep 除外)。 */
|
|
15
|
-
export const SANDBOX_ASK_TOOL_NAMES = new Set([
|
|
16
|
-
"sandbox_bash",
|
|
17
|
-
"sandbox_write",
|
|
18
|
-
"sandbox_edit",
|
|
19
|
-
"sandbox_deliver",
|
|
20
|
-
]);
|