@myrialabs/clopen 0.4.8 → 0.4.10
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/README.md +10 -7
- package/backend/artifacts/detect.ts +129 -0
- package/backend/artifacts/engine-map.ts +53 -0
- package/backend/artifacts/frontmatter.ts +68 -0
- package/backend/artifacts/generate.ts +105 -0
- package/backend/artifacts/index.ts +34 -0
- package/backend/artifacts/markers.ts +76 -0
- package/backend/artifacts/matrix.ts +247 -0
- package/backend/artifacts/slug.ts +35 -0
- package/backend/artifacts/sync.ts +130 -0
- package/backend/artifacts/types.ts +152 -0
- package/backend/auth/permissions.ts +51 -1
- package/backend/chat/stream-manager.ts +14 -1
- package/backend/commands/detect.ts +25 -0
- package/backend/commands/index.ts +9 -0
- package/backend/commands/service.ts +178 -0
- package/backend/commands/store.ts +45 -0
- package/backend/commands/sync.ts +94 -0
- package/backend/database/migrations/045_create_commands_table.ts +28 -0
- package/backend/database/migrations/046_create_subagents_table.ts +29 -0
- package/backend/database/migrations/047_create_instructions_table.ts +29 -0
- package/backend/database/migrations/048_add_mcp_tool_overrides.ts +23 -0
- package/backend/database/migrations/049_create_permission_sets_table.ts +50 -0
- package/backend/database/migrations/050_create_profiles_tables.ts +57 -0
- package/backend/database/migrations/051_add_profile_to_sessions.ts +20 -0
- package/backend/database/migrations/052_add_default_profile_to_projects.ts +20 -0
- package/backend/database/migrations/053_add_profile_to_permission_sets.ts +37 -0
- package/backend/database/migrations/054_drop_subagent_agent_type.ts +20 -0
- package/backend/database/migrations/055_artifact_model_tools_per_engine.ts +43 -0
- package/backend/database/migrations/index.ts +77 -0
- package/backend/database/queries/command-queries.ts +82 -0
- package/backend/database/queries/index.ts +12 -2
- package/backend/database/queries/instruction-queries.ts +62 -0
- package/backend/database/queries/mcp-server-queries.ts +25 -0
- package/backend/database/queries/permission-set-queries.ts +155 -0
- package/backend/database/queries/profile-queries.ts +118 -0
- package/backend/database/queries/project-queries.ts +14 -0
- package/backend/database/queries/session-queries.ts +21 -0
- package/backend/database/queries/subagent-queries.ts +92 -0
- package/backend/engine/adapters/claude/stream.ts +27 -3
- package/backend/engine/adapters/codex/stream.ts +46 -14
- package/backend/engine/adapters/copilot/stream.ts +58 -4
- package/backend/engine/adapters/opencode/message-converter.ts +22 -2
- package/backend/engine/adapters/opencode/server.ts +166 -210
- package/backend/engine/adapters/opencode/stream.ts +150 -24
- package/backend/engine/adapters/qwen/stream.ts +23 -3
- package/backend/engine/artifact-sync.ts +51 -0
- package/backend/engine/types.ts +6 -0
- package/backend/instructions/index.ts +8 -0
- package/backend/instructions/service.ts +63 -0
- package/backend/instructions/sync.ts +56 -0
- package/backend/mcp/external/config.ts +42 -20
- package/backend/mcp/external/proxy.ts +89 -5
- package/backend/mcp/external/tools.ts +88 -0
- package/backend/mcp/index.ts +38 -15
- package/backend/mcp/internal/config.ts +48 -11
- package/backend/mcp/internal/remote-server.ts +9 -1
- package/backend/permissions/index.ts +27 -0
- package/backend/permissions/materialize.ts +96 -0
- package/backend/permissions/resolve.test.ts +162 -0
- package/backend/permissions/resolve.ts +106 -0
- package/backend/permissions/service.ts +167 -0
- package/backend/profiles/index.ts +10 -0
- package/backend/profiles/service.ts +169 -0
- package/backend/project/status-manager.ts +7 -25
- package/backend/skills/index.ts +1 -1
- package/backend/skills/sync.ts +88 -128
- package/backend/subagents/detect.ts +23 -0
- package/backend/subagents/index.ts +10 -0
- package/backend/subagents/service.ts +166 -0
- package/backend/subagents/store.ts +44 -0
- package/backend/subagents/sync.ts +144 -0
- package/backend/utils/static-curl.ts +12 -54
- package/backend/ws/artifacts/generate.ts +51 -0
- package/backend/ws/artifacts/index.ts +8 -0
- package/backend/ws/chat/stream.ts +33 -2
- package/backend/ws/commands/crud.ts +157 -0
- package/backend/ws/commands/index.ts +8 -0
- package/backend/ws/git/branch.ts +4 -2
- package/backend/ws/git/remote.ts +21 -11
- package/backend/ws/index.ts +17 -1
- package/backend/ws/instructions/crud.ts +53 -0
- package/backend/ws/instructions/index.ts +8 -0
- package/backend/ws/mcp/crud.ts +7 -1
- package/backend/ws/mcp/index.ts +4 -1
- package/backend/ws/mcp/tools.ts +112 -0
- package/backend/ws/permissions/crud.ts +72 -0
- package/backend/ws/permissions/index.ts +8 -0
- package/backend/ws/profiles/crud.ts +149 -0
- package/backend/ws/profiles/index.ts +9 -0
- package/backend/ws/sessions/crud.ts +12 -0
- package/backend/ws/subagents/crud.ts +136 -0
- package/backend/ws/subagents/index.ts +8 -0
- package/dist/assets/{index-jGo0X72U.js → index-C3kp8wpM.js} +1 -1
- package/dist/assets/{index-B_F_OgoC.js → index-cVUk7das.js} +1 -1
- package/dist/assets/main-CuCxUeqZ.js +533 -0
- package/dist/assets/main-D4pdkiQK.css +1 -0
- package/dist/index.html +2 -2
- package/package.json +24 -24
- package/shared/constants/engine-tools.ts +56 -0
- package/shared/types/database/schema.ts +2 -0
- package/shared/types/stores/settings.ts +15 -0
- package/shared/types/unified/stream.ts +7 -0
- package/shared/utils/interactive-input.ts +71 -0
- package/shared/utils/logger.ts +6 -0
- package/dist/assets/main-BkCc3WEB.js +0 -481
- package/dist/assets/main-CWDwET4x.css +0 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { DatabaseConnection } from '$shared/types/database/connection';
|
|
2
|
+
import { debug } from '$shared/utils/logger';
|
|
3
|
+
|
|
4
|
+
export const description = 'Drop unused agent_type column from subagents';
|
|
5
|
+
|
|
6
|
+
export const up = (db: DatabaseConnection): void => {
|
|
7
|
+
// `agent_type` was carried in the subagent frontmatter but never consumed by
|
|
8
|
+
// any engine: Claude ignores the non-standard key, OpenCode explicitly drops
|
|
9
|
+
// it, and the synthetic preamble only lists name/slug/description. Delegation
|
|
10
|
+
// identity is the subagent's `name`/`slug`, so the column is dead metadata.
|
|
11
|
+
debug.log('migration', 'Dropping agent_type from subagents...');
|
|
12
|
+
db.exec(`ALTER TABLE subagents DROP COLUMN agent_type`);
|
|
13
|
+
debug.log('migration', 'subagents.agent_type dropped');
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const down = (db: DatabaseConnection): void => {
|
|
17
|
+
debug.log('migration', 'Restoring agent_type on subagents...');
|
|
18
|
+
db.exec(`ALTER TABLE subagents ADD COLUMN agent_type TEXT`);
|
|
19
|
+
debug.log('migration', 'subagents.agent_type restored');
|
|
20
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { DatabaseConnection } from '$shared/types/database/connection';
|
|
2
|
+
import { debug } from '$shared/utils/logger';
|
|
3
|
+
|
|
4
|
+
export const description = 'Store command/subagent model (and subagent tools) per engine';
|
|
5
|
+
|
|
6
|
+
// Model/tools materialize differently per engine (Claude & OpenCode read a native
|
|
7
|
+
// frontmatter; the rest fall back to a synthetic preamble). A single value forced
|
|
8
|
+
// one namespace onto every engine, so we move to a per-engine JSON map keyed by
|
|
9
|
+
// EngineType ({} = inherit/all). Existing single values were written into the
|
|
10
|
+
// Claude-shaped canonical file, so they migrate into the `claude-code` slot.
|
|
11
|
+
export const up = (db: DatabaseConnection): void => {
|
|
12
|
+
debug.log('migration', 'Restructuring command/subagent model & tools per engine...');
|
|
13
|
+
|
|
14
|
+
db.exec(`ALTER TABLE commands ADD COLUMN model_by_engine TEXT NOT NULL DEFAULT '{}'`);
|
|
15
|
+
db.exec(`UPDATE commands SET model_by_engine = json_object('claude-code', model) WHERE model IS NOT NULL AND model != ''`);
|
|
16
|
+
db.exec(`ALTER TABLE commands DROP COLUMN model`);
|
|
17
|
+
|
|
18
|
+
db.exec(`ALTER TABLE subagents ADD COLUMN model_by_engine TEXT NOT NULL DEFAULT '{}'`);
|
|
19
|
+
db.exec(`ALTER TABLE subagents ADD COLUMN tools_by_engine TEXT NOT NULL DEFAULT '{}'`);
|
|
20
|
+
db.exec(`UPDATE subagents SET model_by_engine = json_object('claude-code', model) WHERE model IS NOT NULL AND model != ''`);
|
|
21
|
+
db.exec(`UPDATE subagents SET tools_by_engine = json_object('claude-code', tools) WHERE tools IS NOT NULL AND tools != ''`);
|
|
22
|
+
db.exec(`ALTER TABLE subagents DROP COLUMN model`);
|
|
23
|
+
db.exec(`ALTER TABLE subagents DROP COLUMN tools`);
|
|
24
|
+
|
|
25
|
+
debug.log('migration', 'per-engine model/tools columns ready');
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const down = (db: DatabaseConnection): void => {
|
|
29
|
+
debug.log('migration', 'Reverting per-engine model/tools...');
|
|
30
|
+
|
|
31
|
+
db.exec(`ALTER TABLE commands ADD COLUMN model TEXT`);
|
|
32
|
+
db.exec(`UPDATE commands SET model = json_extract(model_by_engine, '$."claude-code"')`);
|
|
33
|
+
db.exec(`ALTER TABLE commands DROP COLUMN model_by_engine`);
|
|
34
|
+
|
|
35
|
+
db.exec(`ALTER TABLE subagents ADD COLUMN model TEXT`);
|
|
36
|
+
db.exec(`ALTER TABLE subagents ADD COLUMN tools TEXT`);
|
|
37
|
+
db.exec(`UPDATE subagents SET model = json_extract(model_by_engine, '$."claude-code"')`);
|
|
38
|
+
db.exec(`UPDATE subagents SET tools = json_extract(tools_by_engine, '$."claude-code"')`);
|
|
39
|
+
db.exec(`ALTER TABLE subagents DROP COLUMN model_by_engine`);
|
|
40
|
+
db.exec(`ALTER TABLE subagents DROP COLUMN tools_by_engine`);
|
|
41
|
+
|
|
42
|
+
debug.log('migration', 'per-engine model/tools reverted');
|
|
43
|
+
};
|
|
@@ -43,6 +43,17 @@ import * as migration041 from './041_add_mcp_config_schema';
|
|
|
43
43
|
import * as migration042 from './042_add_mcp_oauth';
|
|
44
44
|
import * as migration043 from './043_relocate_engine_config_dirs';
|
|
45
45
|
import * as migration044 from './044_create_skills_table';
|
|
46
|
+
import * as migration045 from './045_create_commands_table';
|
|
47
|
+
import * as migration046 from './046_create_subagents_table';
|
|
48
|
+
import * as migration047 from './047_create_instructions_table';
|
|
49
|
+
import * as migration048 from './048_add_mcp_tool_overrides';
|
|
50
|
+
import * as migration049 from './049_create_permission_sets_table';
|
|
51
|
+
import * as migration050 from './050_create_profiles_tables';
|
|
52
|
+
import * as migration051 from './051_add_profile_to_sessions';
|
|
53
|
+
import * as migration052 from './052_add_default_profile_to_projects';
|
|
54
|
+
import * as migration053 from './053_add_profile_to_permission_sets';
|
|
55
|
+
import * as migration054 from './054_drop_subagent_agent_type';
|
|
56
|
+
import * as migration055 from './055_artifact_model_tools_per_engine';
|
|
46
57
|
|
|
47
58
|
// Export all migrations in order
|
|
48
59
|
export const migrations = [
|
|
@@ -309,6 +320,72 @@ export const migrations = [
|
|
|
309
320
|
description: migration044.description,
|
|
310
321
|
up: migration044.up,
|
|
311
322
|
down: migration044.down
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
id: '045',
|
|
326
|
+
description: migration045.description,
|
|
327
|
+
up: migration045.up,
|
|
328
|
+
down: migration045.down
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
id: '046',
|
|
332
|
+
description: migration046.description,
|
|
333
|
+
up: migration046.up,
|
|
334
|
+
down: migration046.down
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
id: '047',
|
|
338
|
+
description: migration047.description,
|
|
339
|
+
up: migration047.up,
|
|
340
|
+
down: migration047.down
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
id: '048',
|
|
344
|
+
description: migration048.description,
|
|
345
|
+
up: migration048.up,
|
|
346
|
+
down: migration048.down
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
id: '049',
|
|
350
|
+
description: migration049.description,
|
|
351
|
+
up: migration049.up,
|
|
352
|
+
down: migration049.down
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
id: '050',
|
|
356
|
+
description: migration050.description,
|
|
357
|
+
up: migration050.up,
|
|
358
|
+
down: migration050.down
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
id: '051',
|
|
362
|
+
description: migration051.description,
|
|
363
|
+
up: migration051.up,
|
|
364
|
+
down: migration051.down
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
id: '052',
|
|
368
|
+
description: migration052.description,
|
|
369
|
+
up: migration052.up,
|
|
370
|
+
down: migration052.down
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
id: '053',
|
|
374
|
+
description: migration053.description,
|
|
375
|
+
up: migration053.up,
|
|
376
|
+
down: migration053.down
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
id: '054',
|
|
380
|
+
description: migration054.description,
|
|
381
|
+
up: migration054.up,
|
|
382
|
+
down: migration054.down
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
id: '055',
|
|
386
|
+
description: migration055.description,
|
|
387
|
+
up: migration055.up,
|
|
388
|
+
down: migration055.down
|
|
312
389
|
}
|
|
313
390
|
];
|
|
314
391
|
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command Queries
|
|
3
|
+
*
|
|
4
|
+
* CRUD for user-managed custom slash Commands (Settings → Commands). Like
|
|
5
|
+
* Skills, the `commands` table holds only METADATA + the enable toggle; the
|
|
6
|
+
* command's Markdown document lives on disk in the canonical store under
|
|
7
|
+
* `{clopenDir}/commands/<slug>.md` (see `backend/commands/store.ts`).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { getDatabase } from '../index';
|
|
11
|
+
|
|
12
|
+
export type CommandSource = 'custom' | 'imported';
|
|
13
|
+
|
|
14
|
+
export interface CommandRow {
|
|
15
|
+
id: number;
|
|
16
|
+
slug: string;
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
argument_hint: string | null;
|
|
20
|
+
/** JSON map of EngineType → model id ({} = inherit everywhere). */
|
|
21
|
+
model_by_engine: string;
|
|
22
|
+
source: CommandSource;
|
|
23
|
+
is_enabled: number;
|
|
24
|
+
created_at: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface CommandInput {
|
|
28
|
+
slug: string;
|
|
29
|
+
name: string;
|
|
30
|
+
description: string;
|
|
31
|
+
argumentHint?: string | null;
|
|
32
|
+
/** JSON string: EngineType → model id. */
|
|
33
|
+
modelByEngine?: string;
|
|
34
|
+
source?: CommandSource;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const commandQueries = {
|
|
38
|
+
getAll(): CommandRow[] {
|
|
39
|
+
return getDatabase().prepare(`SELECT * FROM commands ORDER BY created_at ASC`).all() as CommandRow[];
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
getEnabled(): CommandRow[] {
|
|
43
|
+
return getDatabase().prepare(`SELECT * FROM commands WHERE is_enabled = 1 ORDER BY created_at ASC`).all() as CommandRow[];
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
getById(id: number): CommandRow | null {
|
|
47
|
+
return getDatabase().prepare(`SELECT * FROM commands WHERE id = ?`).get(id) as CommandRow | null;
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
getBySlug(slug: string): CommandRow | null {
|
|
51
|
+
return getDatabase().prepare(`SELECT * FROM commands WHERE slug = ?`).get(slug) as CommandRow | null;
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
insert(input: CommandInput): CommandRow {
|
|
55
|
+
const result = getDatabase().prepare(
|
|
56
|
+
`INSERT INTO commands (slug, name, description, argument_hint, model_by_engine, source)
|
|
57
|
+
VALUES (?, ?, ?, ?, ?, ?)`
|
|
58
|
+
).run(
|
|
59
|
+
input.slug,
|
|
60
|
+
input.name,
|
|
61
|
+
input.description,
|
|
62
|
+
input.argumentHint ?? null,
|
|
63
|
+
input.modelByEngine ?? '{}',
|
|
64
|
+
input.source ?? 'custom'
|
|
65
|
+
) as { lastInsertRowid: number | bigint };
|
|
66
|
+
return this.getById(Number(result.lastInsertRowid))!;
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
updateMeta(id: number, name: string, description: string, argumentHint: string | null, modelByEngine: string): void {
|
|
70
|
+
getDatabase().prepare(
|
|
71
|
+
`UPDATE commands SET name = ?, description = ?, argument_hint = ?, model_by_engine = ? WHERE id = ?`
|
|
72
|
+
).run(name, description, argumentHint, modelByEngine, id);
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
setEnabled(id: number, enabled: boolean): void {
|
|
76
|
+
getDatabase().prepare(`UPDATE commands SET is_enabled = ? WHERE id = ?`).run(enabled ? 1 : 0, id);
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
remove(id: number): void {
|
|
80
|
+
getDatabase().prepare(`DELETE FROM commands WHERE id = ?`).run(id);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
@@ -13,6 +13,16 @@ export { dbClientQueryHistoryQueries } from './db-client-query-history-queries';
|
|
|
13
13
|
export { auditLogQueries } from './audit-log-queries';
|
|
14
14
|
export { fileAuditLogQueries } from './file-audit-log-queries';
|
|
15
15
|
export { mcpServerQueries } from './mcp-server-queries';
|
|
16
|
-
export type { McpServerRow, McpServerInput, McpTransport, McpSource, McpConfigField } from './mcp-server-queries';
|
|
16
|
+
export type { McpServerRow, McpServerInput, McpTransport, McpSource, McpConfigField, McpToolOverride, McpToolOverrides } from './mcp-server-queries';
|
|
17
17
|
export { skillQueries } from './skill-queries';
|
|
18
|
-
export type { SkillRow, SkillInput, SkillSource } from './skill-queries';
|
|
18
|
+
export type { SkillRow, SkillInput, SkillSource } from './skill-queries';
|
|
19
|
+
export { commandQueries } from './command-queries';
|
|
20
|
+
export type { CommandRow, CommandInput, CommandSource } from './command-queries';
|
|
21
|
+
export { subagentQueries } from './subagent-queries';
|
|
22
|
+
export type { SubagentRow, SubagentInput, SubagentSource } from './subagent-queries';
|
|
23
|
+
export { instructionQueries } from './instruction-queries';
|
|
24
|
+
export type { InstructionRow, InstructionScope } from './instruction-queries';
|
|
25
|
+
export { permissionSetQueries } from './permission-set-queries';
|
|
26
|
+
export type { PermissionSet, PermissionScope } from './permission-set-queries';
|
|
27
|
+
export { profileQueries, PROFILE_ITEM_TYPES } from './profile-queries';
|
|
28
|
+
export type { ProfileRow, ProfileItemRow, ProfileInput, ProfileItemInput, ProfileItemType } from './profile-queries';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instruction Queries
|
|
3
|
+
*
|
|
4
|
+
* Stores the Clopen-managed instruction block for the single global scope
|
|
5
|
+
* (`project_id` NULL) and per project. The content is materialized into each
|
|
6
|
+
* engine's memory file as a marker-region (see `backend/instructions/sync.ts`),
|
|
7
|
+
* so hand-written parts of `CLAUDE.md` / `AGENTS.md` are never overwritten.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { getDatabase } from '../index';
|
|
11
|
+
|
|
12
|
+
export type InstructionScope = 'global' | 'project';
|
|
13
|
+
|
|
14
|
+
export interface InstructionRow {
|
|
15
|
+
id: number;
|
|
16
|
+
scope: InstructionScope;
|
|
17
|
+
project_id: string | null;
|
|
18
|
+
content: string;
|
|
19
|
+
is_enabled: number;
|
|
20
|
+
updated_at: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const instructionQueries = {
|
|
24
|
+
getGlobal(): InstructionRow | null {
|
|
25
|
+
return getDatabase()
|
|
26
|
+
.prepare(`SELECT * FROM instructions WHERE scope = 'global' AND project_id IS NULL`)
|
|
27
|
+
.get() as InstructionRow | null;
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
getForProject(projectId: string): InstructionRow | null {
|
|
31
|
+
return getDatabase()
|
|
32
|
+
.prepare(`SELECT * FROM instructions WHERE scope = 'project' AND project_id = ?`)
|
|
33
|
+
.get(projectId) as InstructionRow | null;
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
getAllEnabledProjects(): InstructionRow[] {
|
|
37
|
+
return getDatabase()
|
|
38
|
+
.prepare(`SELECT * FROM instructions WHERE scope = 'project' AND is_enabled = 1`)
|
|
39
|
+
.all() as InstructionRow[];
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Upsert the block for a scope target (global = null projectId). Done as an
|
|
44
|
+
* explicit get-then-update/insert because SQLite treats NULL as distinct in
|
|
45
|
+
* UNIQUE constraints, so `ON CONFLICT` never fires for the global row.
|
|
46
|
+
*/
|
|
47
|
+
upsert(scope: InstructionScope, projectId: string | null, content: string, enabled: boolean): InstructionRow {
|
|
48
|
+
const db = getDatabase();
|
|
49
|
+
const existing = scope === 'global' ? this.getGlobal() : projectId ? this.getForProject(projectId) : null;
|
|
50
|
+
if (existing) {
|
|
51
|
+
db.prepare(
|
|
52
|
+
`UPDATE instructions SET content = ?, is_enabled = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?`
|
|
53
|
+
).run(content, enabled ? 1 : 0, existing.id);
|
|
54
|
+
} else {
|
|
55
|
+
db.prepare(
|
|
56
|
+
`INSERT INTO instructions (scope, project_id, content, is_enabled) VALUES (?, ?, ?, ?)`
|
|
57
|
+
).run(scope, projectId, content, enabled ? 1 : 0);
|
|
58
|
+
}
|
|
59
|
+
const row = scope === 'global' ? this.getGlobal() : this.getForProject(projectId!);
|
|
60
|
+
return row!;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
@@ -14,10 +14,27 @@
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import { getDatabase } from '../index';
|
|
17
|
+
import type { EngineType } from '$shared/types/unified';
|
|
17
18
|
|
|
18
19
|
export type McpTransport = 'stdio' | 'http' | 'sse';
|
|
19
20
|
export type McpSource = 'registry' | 'custom' | 'internal';
|
|
20
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Per-tool exposure override for one upstream MCP tool. Stored in the
|
|
24
|
+
* `tool_overrides` JSON column, keyed by the tool's bare name.
|
|
25
|
+
* - `enabled: false` → the tool is hidden from EVERY engine.
|
|
26
|
+
* - `engines: { codex: false }` → the tool is hidden from that engine only.
|
|
27
|
+
* An absent field means "default on", so an absent override (or `{}`) exposes
|
|
28
|
+
* the tool everywhere — matching the pre-column behaviour.
|
|
29
|
+
*/
|
|
30
|
+
export interface McpToolOverride {
|
|
31
|
+
enabled?: boolean;
|
|
32
|
+
engines?: Partial<Record<EngineType, boolean>>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Map of bare tool name → its exposure override. */
|
|
36
|
+
export type McpToolOverrides = Record<string, McpToolOverride>;
|
|
37
|
+
|
|
21
38
|
/**
|
|
22
39
|
* A single configurable field, captured from the registry catalog at install
|
|
23
40
|
* time so the "Configure" UI can render the same labelled fields it showed at
|
|
@@ -50,6 +67,8 @@ export interface McpServerRow {
|
|
|
50
67
|
config_schema: string;
|
|
51
68
|
/** JSON OAuth state Clopen manages (registration + tokens), or null. */
|
|
52
69
|
oauth: string | null;
|
|
70
|
+
/** JSON `McpToolOverrides` — per-tool + per-engine exposure control. Defaults to `'{}'`. */
|
|
71
|
+
tool_overrides: string;
|
|
53
72
|
source: McpSource;
|
|
54
73
|
is_enabled: number;
|
|
55
74
|
created_at: string;
|
|
@@ -163,6 +182,12 @@ export const mcpServerQueries = {
|
|
|
163
182
|
db.prepare(`UPDATE mcp_servers SET oauth = ? WHERE id = ?`).run(oauth, id);
|
|
164
183
|
},
|
|
165
184
|
|
|
185
|
+
/** Persist the per-tool + per-engine exposure overrides for a server. */
|
|
186
|
+
updateToolOverrides(id: number, overrides: McpToolOverrides): void {
|
|
187
|
+
const db = getDatabase();
|
|
188
|
+
db.prepare(`UPDATE mcp_servers SET tool_overrides = ? WHERE id = ?`).run(JSON.stringify(overrides), id);
|
|
189
|
+
},
|
|
190
|
+
|
|
166
191
|
remove(id: number): void {
|
|
167
192
|
const db = getDatabase();
|
|
168
193
|
db.prepare(`DELETE FROM mcp_servers WHERE id = ?`).run(id);
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Permission Set Queries
|
|
3
|
+
*
|
|
4
|
+
* CRUD for per-engine tool allow/deny rules (Settings → Permissions). Each row
|
|
5
|
+
* carries the `allow` + `deny` tool-pattern lists for one
|
|
6
|
+
* `(scope, project_id, engine)` combination — see migration 049 for the resolved
|
|
7
|
+
* semantics. Instance-global + admin-managed (no `user_id`), mirroring
|
|
8
|
+
* `skills` / `mcp_servers` / `subagents`.
|
|
9
|
+
*
|
|
10
|
+
* `allow` / `deny` are stored as JSON `string[]`; callers get parsed arrays back
|
|
11
|
+
* via {@link PermissionSet}. The raw JSON never leaves this module.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { getDatabase } from '../index';
|
|
15
|
+
import type { EngineType } from '$shared/types/unified';
|
|
16
|
+
|
|
17
|
+
export type PermissionScope = 'global' | 'project' | 'profile';
|
|
18
|
+
|
|
19
|
+
interface PermissionSetRow {
|
|
20
|
+
id: number;
|
|
21
|
+
scope: PermissionScope;
|
|
22
|
+
project_id: string | null;
|
|
23
|
+
profile_id: number | null;
|
|
24
|
+
engine: EngineType;
|
|
25
|
+
allow: string;
|
|
26
|
+
deny: string;
|
|
27
|
+
created_at: string;
|
|
28
|
+
updated_at: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A resolved permission set with `allow`/`deny` parsed into string arrays. */
|
|
32
|
+
export interface PermissionSet {
|
|
33
|
+
id: number;
|
|
34
|
+
scope: PermissionScope;
|
|
35
|
+
projectId: string | null;
|
|
36
|
+
profileId: number | null;
|
|
37
|
+
engine: EngineType;
|
|
38
|
+
allow: string[];
|
|
39
|
+
deny: string[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function parseList(raw: string): string[] {
|
|
43
|
+
try {
|
|
44
|
+
const parsed = JSON.parse(raw);
|
|
45
|
+
return Array.isArray(parsed) ? parsed.filter((x): x is string => typeof x === 'string') : [];
|
|
46
|
+
} catch {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function toSet(row: PermissionSetRow): PermissionSet {
|
|
52
|
+
return {
|
|
53
|
+
id: row.id,
|
|
54
|
+
scope: row.scope,
|
|
55
|
+
projectId: row.project_id,
|
|
56
|
+
profileId: row.profile_id,
|
|
57
|
+
engine: row.engine,
|
|
58
|
+
allow: parseList(row.allow),
|
|
59
|
+
deny: parseList(row.deny)
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const permissionSetQueries = {
|
|
64
|
+
/** Every stored set (both scopes), for the Settings listing. */
|
|
65
|
+
getAll(): PermissionSet[] {
|
|
66
|
+
const rows = getDatabase()
|
|
67
|
+
.prepare(`SELECT * FROM permission_sets ORDER BY scope ASC, engine ASC`)
|
|
68
|
+
.all() as PermissionSetRow[];
|
|
69
|
+
return rows.map(toSet);
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
/** Global-scope sets (project_id IS NULL), keyed by engine downstream. */
|
|
73
|
+
getGlobal(): PermissionSet[] {
|
|
74
|
+
const rows = getDatabase()
|
|
75
|
+
.prepare(`SELECT * FROM permission_sets WHERE scope = 'global'`)
|
|
76
|
+
.all() as PermissionSetRow[];
|
|
77
|
+
return rows.map(toSet);
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
/** Project-scope sets for one project. */
|
|
81
|
+
getForProject(projectId: string): PermissionSet[] {
|
|
82
|
+
const rows = getDatabase()
|
|
83
|
+
.prepare(`SELECT * FROM permission_sets WHERE scope = 'project' AND project_id = ?`)
|
|
84
|
+
.all(projectId) as PermissionSetRow[];
|
|
85
|
+
return rows.map(toSet);
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
/** Profile-scope sets for one profile (the per-profile allow/deny overlay). */
|
|
89
|
+
getForProfile(profileId: number): PermissionSet[] {
|
|
90
|
+
const rows = getDatabase()
|
|
91
|
+
.prepare(`SELECT * FROM permission_sets WHERE scope = 'profile' AND profile_id = ?`)
|
|
92
|
+
.all(profileId) as PermissionSetRow[];
|
|
93
|
+
return rows.map(toSet);
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
/** The set for one exact (scope, project, profile, engine), or null. */
|
|
97
|
+
getOne(
|
|
98
|
+
scope: PermissionScope,
|
|
99
|
+
projectId: string | null,
|
|
100
|
+
profileId: number | null,
|
|
101
|
+
engine: EngineType
|
|
102
|
+
): PermissionSet | null {
|
|
103
|
+
const row = getDatabase()
|
|
104
|
+
.prepare(
|
|
105
|
+
`SELECT * FROM permission_sets
|
|
106
|
+
WHERE scope = ? AND COALESCE(project_id, '') = COALESCE(?, '')
|
|
107
|
+
AND COALESCE(profile_id, -1) = COALESCE(?, -1) AND engine = ?`
|
|
108
|
+
)
|
|
109
|
+
.get(scope, projectId, profileId, engine) as PermissionSetRow | undefined;
|
|
110
|
+
return row ? toSet(row) : null;
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Upsert the allow/deny lists for one (scope, project, profile, engine). When
|
|
115
|
+
* both lists are empty the row is deleted so the table only ever holds real
|
|
116
|
+
* rules (keeps resolution cheap and "any restriction?" a simple emptiness
|
|
117
|
+
* check). `projectId` is only kept for `scope='project'`, `profileId` only for
|
|
118
|
+
* `scope='profile'`.
|
|
119
|
+
*/
|
|
120
|
+
save(
|
|
121
|
+
scope: PermissionScope,
|
|
122
|
+
projectId: string | null,
|
|
123
|
+
profileId: number | null,
|
|
124
|
+
engine: EngineType,
|
|
125
|
+
allow: string[],
|
|
126
|
+
deny: string[]
|
|
127
|
+
): void {
|
|
128
|
+
const db = getDatabase();
|
|
129
|
+
const normProject = scope === 'project' ? projectId : null;
|
|
130
|
+
const normProfile = scope === 'profile' ? profileId : null;
|
|
131
|
+
const where = `scope = ? AND COALESCE(project_id, '') = COALESCE(?, '')
|
|
132
|
+
AND COALESCE(profile_id, -1) = COALESCE(?, -1) AND engine = ?`;
|
|
133
|
+
if (allow.length === 0 && deny.length === 0) {
|
|
134
|
+
db.prepare(`DELETE FROM permission_sets WHERE ${where}`)
|
|
135
|
+
.run(scope, normProject, normProfile, engine);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
// Explicit exists → update/insert rather than ON CONFLICT: the uniqueness
|
|
139
|
+
// lives in an EXPRESSION index (COALESCE(...)), which is awkward to name as
|
|
140
|
+
// an upsert conflict target across SQLite builds.
|
|
141
|
+
const existing = db
|
|
142
|
+
.prepare(`SELECT id FROM permission_sets WHERE ${where}`)
|
|
143
|
+
.get(scope, normProject, normProfile, engine) as { id: number } | undefined;
|
|
144
|
+
if (existing) {
|
|
145
|
+
db.prepare(
|
|
146
|
+
`UPDATE permission_sets SET allow = ?, deny = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?`
|
|
147
|
+
).run(JSON.stringify(allow), JSON.stringify(deny), existing.id);
|
|
148
|
+
} else {
|
|
149
|
+
db.prepare(
|
|
150
|
+
`INSERT INTO permission_sets (scope, project_id, profile_id, engine, allow, deny)
|
|
151
|
+
VALUES (?, ?, ?, ?, ?, ?)`
|
|
152
|
+
).run(scope, normProject, normProfile, engine, JSON.stringify(allow), JSON.stringify(deny));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profile Queries
|
|
3
|
+
*
|
|
4
|
+
* CRUD for reusable Profiles (Settings → Profiles) — named bundles that
|
|
5
|
+
* reference existing artifacts (Skills, Commands, Subagents, MCP Connectors) by
|
|
6
|
+
* their stable slug. The `profiles` table holds only the bundle metadata; the
|
|
7
|
+
* `profile_items` table holds the (artifact_type, ref) references. Neither
|
|
8
|
+
* duplicates artifact data — see migration 050.
|
|
9
|
+
*
|
|
10
|
+
* Instance-global + admin-managed (no `user_id`), mirroring
|
|
11
|
+
* `skills` / `mcp_servers` / `subagents` / `permission_sets`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { getDatabase } from '../index';
|
|
15
|
+
|
|
16
|
+
/** Artifact kinds a profile can bundle. Permissions are handled separately
|
|
17
|
+
* (they are a per-engine allow/deny overlay, not a slug-referenced artifact). */
|
|
18
|
+
export type ProfileItemType = 'skill' | 'command' | 'subagent' | 'mcp';
|
|
19
|
+
|
|
20
|
+
export const PROFILE_ITEM_TYPES: ProfileItemType[] = ['skill', 'command', 'subagent', 'mcp'];
|
|
21
|
+
|
|
22
|
+
export interface ProfileRow {
|
|
23
|
+
id: number;
|
|
24
|
+
slug: string;
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
created_at: string;
|
|
28
|
+
updated_at: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ProfileItemRow {
|
|
32
|
+
id: number;
|
|
33
|
+
profile_id: number;
|
|
34
|
+
artifact_type: ProfileItemType;
|
|
35
|
+
ref: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface ProfileInput {
|
|
39
|
+
slug: string;
|
|
40
|
+
name: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** One reference inside a profile. */
|
|
45
|
+
export interface ProfileItemInput {
|
|
46
|
+
artifactType: ProfileItemType;
|
|
47
|
+
ref: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const profileQueries = {
|
|
51
|
+
getAll(): ProfileRow[] {
|
|
52
|
+
return getDatabase().prepare(`SELECT * FROM profiles ORDER BY created_at ASC`).all() as ProfileRow[];
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
getById(id: number): ProfileRow | null {
|
|
56
|
+
return getDatabase().prepare(`SELECT * FROM profiles WHERE id = ?`).get(id) as ProfileRow | null;
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
getBySlug(slug: string): ProfileRow | null {
|
|
60
|
+
return getDatabase().prepare(`SELECT * FROM profiles WHERE slug = ?`).get(slug) as ProfileRow | null;
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
insert(input: ProfileInput): ProfileRow {
|
|
64
|
+
const result = getDatabase().prepare(
|
|
65
|
+
`INSERT INTO profiles (slug, name, description) VALUES (?, ?, ?)`
|
|
66
|
+
).run(input.slug, input.name, input.description ?? '') as { lastInsertRowid: number | bigint };
|
|
67
|
+
return this.getById(Number(result.lastInsertRowid))!;
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
updateMeta(id: number, name: string, description: string): void {
|
|
71
|
+
getDatabase().prepare(
|
|
72
|
+
`UPDATE profiles SET name = ?, description = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?`
|
|
73
|
+
).run(name, description, id);
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
remove(id: number): void {
|
|
77
|
+
const db = getDatabase();
|
|
78
|
+
// profile_items has ON DELETE CASCADE, but foreign-key enforcement is not
|
|
79
|
+
// guaranteed on across every SQLite handle — delete items explicitly too.
|
|
80
|
+
db.prepare(`DELETE FROM profile_items WHERE profile_id = ?`).run(id);
|
|
81
|
+
db.prepare(`DELETE FROM profiles WHERE id = ?`).run(id);
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
// ── Items ────────────────────────────────────────────────────────────────
|
|
85
|
+
|
|
86
|
+
getItems(profileId: number): ProfileItemRow[] {
|
|
87
|
+
return getDatabase()
|
|
88
|
+
.prepare(`SELECT * FROM profile_items WHERE profile_id = ? ORDER BY artifact_type ASC, ref ASC`)
|
|
89
|
+
.all(profileId) as ProfileItemRow[];
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
/** Whether ANY profile references this artifact (by type + slug). Used to let a
|
|
93
|
+
* profile-activated but globally-disabled artifact through its enable gate. */
|
|
94
|
+
isArtifactReferenced(type: ProfileItemType, ref: string): boolean {
|
|
95
|
+
const row = getDatabase()
|
|
96
|
+
.prepare(`SELECT 1 AS ok FROM profile_items WHERE artifact_type = ? AND ref = ? LIMIT 1`)
|
|
97
|
+
.get(type, ref) as { ok: number } | undefined;
|
|
98
|
+
return !!row;
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
/** Refs of one artifact type inside a profile (used by the stream-time filter). */
|
|
102
|
+
getRefsByType(profileId: number, type: ProfileItemType): string[] {
|
|
103
|
+
const rows = getDatabase()
|
|
104
|
+
.prepare(`SELECT ref FROM profile_items WHERE profile_id = ? AND artifact_type = ?`)
|
|
105
|
+
.all(profileId, type) as { ref: string }[];
|
|
106
|
+
return rows.map(r => r.ref);
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
/** Replace a profile's entire item set (delete-then-insert). */
|
|
110
|
+
setItems(profileId: number, items: ProfileItemInput[]): void {
|
|
111
|
+
const db = getDatabase();
|
|
112
|
+
db.prepare(`DELETE FROM profile_items WHERE profile_id = ?`).run(profileId);
|
|
113
|
+
const insert = db.prepare(
|
|
114
|
+
`INSERT OR IGNORE INTO profile_items (profile_id, artifact_type, ref) VALUES (?, ?, ?)`
|
|
115
|
+
);
|
|
116
|
+
for (const item of items) insert.run(profileId, item.artifactType, item.ref);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
@@ -67,6 +67,20 @@ export const projectQueries = {
|
|
|
67
67
|
`).run(now, id);
|
|
68
68
|
},
|
|
69
69
|
|
|
70
|
+
/** The project-wide default profile (shared by all collaborators), or null. */
|
|
71
|
+
getDefaultProfileId(id: string): number | null {
|
|
72
|
+
const db = getDatabase();
|
|
73
|
+
const row = db.prepare(`SELECT default_profile_id FROM projects WHERE id = ?`)
|
|
74
|
+
.get(id) as { default_profile_id: number | null } | undefined;
|
|
75
|
+
return row?.default_profile_id ?? null;
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
/** Set (or clear, with null) the project-wide default profile. */
|
|
79
|
+
setDefaultProfileId(id: string, profileId: number | null): void {
|
|
80
|
+
const db = getDatabase();
|
|
81
|
+
db.prepare(`UPDATE projects SET default_profile_id = ? WHERE id = ?`).run(profileId, id);
|
|
82
|
+
},
|
|
83
|
+
|
|
70
84
|
deleteProject(id: string): void {
|
|
71
85
|
const db = getDatabase();
|
|
72
86
|
db.prepare('DELETE FROM user_projects WHERE project_id = ?').run(id);
|