@myrialabs/clopen 0.4.7 → 0.4.9

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.
Files changed (115) hide show
  1. package/backend/artifacts/detect.ts +129 -0
  2. package/backend/artifacts/engine-map.ts +53 -0
  3. package/backend/artifacts/frontmatter.ts +68 -0
  4. package/backend/artifacts/generate.ts +105 -0
  5. package/backend/artifacts/index.ts +34 -0
  6. package/backend/artifacts/markers.ts +76 -0
  7. package/backend/artifacts/matrix.ts +247 -0
  8. package/backend/artifacts/slug.ts +35 -0
  9. package/backend/artifacts/sync.ts +130 -0
  10. package/backend/artifacts/types.ts +152 -0
  11. package/backend/auth/permissions.ts +51 -1
  12. package/backend/chat/stream-manager.ts +14 -1
  13. package/backend/commands/detect.ts +25 -0
  14. package/backend/commands/index.ts +9 -0
  15. package/backend/commands/service.ts +178 -0
  16. package/backend/commands/store.ts +45 -0
  17. package/backend/commands/sync.ts +94 -0
  18. package/backend/database/migrations/045_create_commands_table.ts +28 -0
  19. package/backend/database/migrations/046_create_subagents_table.ts +29 -0
  20. package/backend/database/migrations/047_create_instructions_table.ts +29 -0
  21. package/backend/database/migrations/048_add_mcp_tool_overrides.ts +23 -0
  22. package/backend/database/migrations/049_create_permission_sets_table.ts +50 -0
  23. package/backend/database/migrations/050_create_profiles_tables.ts +57 -0
  24. package/backend/database/migrations/051_add_profile_to_sessions.ts +20 -0
  25. package/backend/database/migrations/052_add_default_profile_to_projects.ts +20 -0
  26. package/backend/database/migrations/053_add_profile_to_permission_sets.ts +37 -0
  27. package/backend/database/migrations/054_drop_subagent_agent_type.ts +20 -0
  28. package/backend/database/migrations/055_artifact_model_tools_per_engine.ts +43 -0
  29. package/backend/database/migrations/index.ts +77 -0
  30. package/backend/database/queries/command-queries.ts +82 -0
  31. package/backend/database/queries/index.ts +12 -2
  32. package/backend/database/queries/instruction-queries.ts +62 -0
  33. package/backend/database/queries/mcp-server-queries.ts +25 -0
  34. package/backend/database/queries/permission-set-queries.ts +155 -0
  35. package/backend/database/queries/profile-queries.ts +118 -0
  36. package/backend/database/queries/project-queries.ts +14 -0
  37. package/backend/database/queries/session-queries.ts +10 -0
  38. package/backend/database/queries/subagent-queries.ts +92 -0
  39. package/backend/db-client/drivers/mysql.ts +21 -0
  40. package/backend/db-client/drivers/postgres.ts +20 -0
  41. package/backend/db-client/drivers/sqlite.ts +21 -0
  42. package/backend/db-client/drivers/types.ts +19 -0
  43. package/backend/db-client/query-executor.ts +89 -1
  44. package/backend/engine/adapters/claude/stream.ts +27 -3
  45. package/backend/engine/adapters/codex/stream.ts +46 -14
  46. package/backend/engine/adapters/copilot/stream.ts +58 -4
  47. package/backend/engine/adapters/opencode/message-converter.ts +22 -2
  48. package/backend/engine/adapters/opencode/server.ts +166 -210
  49. package/backend/engine/adapters/opencode/stream.ts +150 -24
  50. package/backend/engine/adapters/qwen/stream.ts +23 -3
  51. package/backend/engine/artifact-sync.ts +51 -0
  52. package/backend/engine/types.ts +6 -0
  53. package/backend/instructions/index.ts +8 -0
  54. package/backend/instructions/service.ts +63 -0
  55. package/backend/instructions/sync.ts +56 -0
  56. package/backend/mcp/external/config.ts +42 -20
  57. package/backend/mcp/external/proxy.ts +89 -5
  58. package/backend/mcp/external/tools.ts +88 -0
  59. package/backend/mcp/index.ts +38 -15
  60. package/backend/mcp/internal/config.ts +48 -11
  61. package/backend/mcp/internal/remote-server.ts +9 -1
  62. package/backend/permissions/index.ts +27 -0
  63. package/backend/permissions/materialize.ts +96 -0
  64. package/backend/permissions/resolve.test.ts +162 -0
  65. package/backend/permissions/resolve.ts +106 -0
  66. package/backend/permissions/service.ts +167 -0
  67. package/backend/profiles/index.ts +10 -0
  68. package/backend/profiles/service.ts +169 -0
  69. package/backend/skills/index.ts +1 -1
  70. package/backend/skills/sync.ts +88 -128
  71. package/backend/subagents/detect.ts +23 -0
  72. package/backend/subagents/index.ts +10 -0
  73. package/backend/subagents/service.ts +166 -0
  74. package/backend/subagents/store.ts +44 -0
  75. package/backend/subagents/sync.ts +144 -0
  76. package/backend/ws/artifacts/generate.ts +51 -0
  77. package/backend/ws/artifacts/index.ts +8 -0
  78. package/backend/ws/chat/stream.ts +33 -2
  79. package/backend/ws/commands/crud.ts +157 -0
  80. package/backend/ws/commands/index.ts +8 -0
  81. package/backend/ws/db-client/query-history-retention.test.ts +217 -0
  82. package/backend/ws/db-client/query.ts +77 -2
  83. package/backend/ws/git/branch.ts +4 -2
  84. package/backend/ws/git/ignored.ts +65 -0
  85. package/backend/ws/git/index.ts +3 -1
  86. package/backend/ws/git/remote.ts +21 -11
  87. package/backend/ws/index.ts +17 -1
  88. package/backend/ws/instructions/crud.ts +53 -0
  89. package/backend/ws/instructions/index.ts +8 -0
  90. package/backend/ws/mcp/crud.ts +7 -1
  91. package/backend/ws/mcp/index.ts +4 -1
  92. package/backend/ws/mcp/tools.ts +112 -0
  93. package/backend/ws/permissions/crud.ts +72 -0
  94. package/backend/ws/permissions/index.ts +8 -0
  95. package/backend/ws/profiles/crud.ts +149 -0
  96. package/backend/ws/profiles/index.ts +9 -0
  97. package/backend/ws/subagents/crud.ts +136 -0
  98. package/backend/ws/subagents/index.ts +8 -0
  99. package/dist/assets/__vite-browser-external-BIHI7g3E.js +1 -0
  100. package/dist/assets/index-BdRui-1z.js +1 -0
  101. package/dist/assets/{index-xrB3zcfA.js → index-BjaIjmd4.js} +1 -1
  102. package/dist/assets/{main-LBI3a0n5.js → main-Cf8SUfQ1.js} +387 -302
  103. package/dist/assets/main-D4pdkiQK.css +1 -0
  104. package/dist/assets/zipkit-engine-CaR0t_Uy.wasm +0 -0
  105. package/dist/index.html +2 -2
  106. package/package.json +1 -1
  107. package/shared/constants/engine-tools.ts +56 -0
  108. package/shared/types/database/schema.ts +2 -0
  109. package/shared/types/db-client/query.ts +33 -0
  110. package/shared/types/stores/settings.ts +15 -0
  111. package/shared/types/unified/stream.ts +7 -0
  112. package/shared/utils/db-client/split-sql.test.ts +88 -0
  113. package/shared/utils/db-client/split-sql.ts +132 -0
  114. package/shared/utils/logger.ts +6 -0
  115. package/dist/assets/main-BXS8bjJ6.css +0 -1
@@ -9,6 +9,39 @@ export interface DbClientQueryResult {
9
9
  affectedRows: number | null;
10
10
  durationMs: number;
11
11
  driverMeta: Record<string, unknown>;
12
+ /**
13
+ * Present only for multi-statement (batch) executions. The top-level
14
+ * fields mirror the last statement that produced rows (so single-result
15
+ * consumers keep working), while `batch` carries the full per-statement
16
+ * report.
17
+ */
18
+ batch?: DbClientBatchResult;
19
+ }
20
+
21
+ export type DbClientQueryClass = 'read' | 'write' | 'ddl' | 'unknown';
22
+
23
+ export type DbClientStatementStatus = 'success' | 'error' | 'skipped';
24
+
25
+ /** Outcome of a single statement within a batch execution. */
26
+ export interface DbClientStatementResult {
27
+ index: number;
28
+ query: string;
29
+ queryClass: DbClientQueryClass;
30
+ status: DbClientStatementStatus;
31
+ /** The statement's own result set (null for errored / skipped statements). */
32
+ result: DbClientQueryResult | null;
33
+ error: string | null;
34
+ durationMs: number;
35
+ }
36
+
37
+ /** Aggregate outcome of running a `;`-separated batch of statements. */
38
+ export interface DbClientBatchResult {
39
+ statements: DbClientStatementResult[];
40
+ totalDurationMs: number;
41
+ /** Whether the batch ran inside a real (atomic) transaction. */
42
+ transaction: boolean;
43
+ /** True when every statement succeeded. */
44
+ ok: boolean;
12
45
  }
13
46
 
14
47
  export type DbClientSchemaNodeType =
@@ -29,6 +29,19 @@ export interface CommitGeneratorSettings {
29
29
  branchConfig: BranchNameConfig;
30
30
  }
31
31
 
32
+ /**
33
+ * AI authoring model for generating Skills/Commands/Subagents/Instructions from a
34
+ * purpose sentence. Optional — when absent (or `useCustomModel` false), the
35
+ * assistant model (selectedEngine/selectedModel) is used.
36
+ */
37
+ export interface ArtifactGeneratorSettings {
38
+ useCustomModel: boolean;
39
+ engine: EngineType;
40
+ provider: string;
41
+ modelId: string;
42
+ modelName: string;
43
+ }
44
+
32
45
  /** Per-user settings (stored per user) */
33
46
  export interface AppSettings {
34
47
  selectedEngine: EngineType;
@@ -54,6 +67,8 @@ export interface AppSettings {
54
67
  gitDiffSideBySide: boolean;
55
68
  /** AI commit message generator configuration */
56
69
  commitGenerator: CommitGeneratorSettings;
70
+ /** AI authoring model for artifact generation (optional; falls back to assistant model) */
71
+ artifactGenerator?: ArtifactGeneratorSettings;
57
72
  /** Pinned model IDs — shown at top of provider group in model picker */
58
73
  pinnedModels: string[];
59
74
  }
@@ -176,4 +176,11 @@ export interface StreamRequest {
176
176
  prompt: UserMessage;
177
177
  engine: MessageEngine;
178
178
  sender: MessageSender;
179
+ /**
180
+ * Active Profile chosen for this session (bundle of Skills/Commands/Subagents/
181
+ * MCP/Permissions). `null` = explicit "no profile"; `undefined` = client didn't
182
+ * send one → the stream falls back to the project's default profile. Persisted
183
+ * to `chat_sessions.profile_id` like engine/model.
184
+ */
185
+ profileId?: number | null;
179
186
  }
@@ -0,0 +1,88 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import { splitSqlStatements } from './split-sql';
3
+
4
+ describe('splitSqlStatements', () => {
5
+ test('returns a single statement unchanged (no trailing semicolon)', () => {
6
+ expect(splitSqlStatements('SELECT 1')).toEqual(['SELECT 1']);
7
+ });
8
+
9
+ test('trims and drops empty statements', () => {
10
+ expect(splitSqlStatements(' SELECT 1 ; ; SELECT 2 ;')).toEqual(['SELECT 1', 'SELECT 2']);
11
+ });
12
+
13
+ test('splits multiple statements', () => {
14
+ expect(splitSqlStatements('SELECT 1; DELETE FROM users')).toEqual([
15
+ 'SELECT 1',
16
+ 'DELETE FROM users'
17
+ ]);
18
+ });
19
+
20
+ test('ignores semicolons inside single-quoted strings', () => {
21
+ expect(splitSqlStatements("SELECT ';'; SELECT 'a;b'")).toEqual([
22
+ "SELECT ';'",
23
+ "SELECT 'a;b'"
24
+ ]);
25
+ });
26
+
27
+ test('handles doubled single-quote escapes', () => {
28
+ expect(splitSqlStatements("SELECT 'O''Brien; Jr'; SELECT 2")).toEqual([
29
+ "SELECT 'O''Brien; Jr'",
30
+ 'SELECT 2'
31
+ ]);
32
+ });
33
+
34
+ test('handles MySQL backslash escapes inside strings', () => {
35
+ expect(splitSqlStatements("SELECT 'a\\';b'; SELECT 2")).toEqual([
36
+ "SELECT 'a\\';b'",
37
+ 'SELECT 2'
38
+ ]);
39
+ });
40
+
41
+ test('ignores semicolons inside double-quoted identifiers', () => {
42
+ expect(splitSqlStatements('SELECT "a;b" FROM t; SELECT 2')).toEqual([
43
+ 'SELECT "a;b" FROM t',
44
+ 'SELECT 2'
45
+ ]);
46
+ });
47
+
48
+ test('ignores semicolons inside backtick identifiers', () => {
49
+ expect(splitSqlStatements('SELECT `a;b` FROM t; SELECT 2')).toEqual([
50
+ 'SELECT `a;b` FROM t',
51
+ 'SELECT 2'
52
+ ]);
53
+ });
54
+
55
+ test('ignores semicolons inside line comments', () => {
56
+ expect(splitSqlStatements('SELECT 1 -- a; b\n; SELECT 2')).toEqual([
57
+ 'SELECT 1 -- a; b',
58
+ 'SELECT 2'
59
+ ]);
60
+ });
61
+
62
+ test('ignores semicolons inside block comments', () => {
63
+ expect(splitSqlStatements('SELECT 1 /* a; b */; SELECT 2')).toEqual([
64
+ 'SELECT 1 /* a; b */',
65
+ 'SELECT 2'
66
+ ]);
67
+ });
68
+
69
+ test('ignores semicolons inside Postgres dollar-quoted bodies', () => {
70
+ const sql = `CREATE FUNCTION f() RETURNS void AS $$ BEGIN PERFORM 1; PERFORM 2; END; $$ LANGUAGE plpgsql; SELECT 1`;
71
+ expect(splitSqlStatements(sql)).toEqual([
72
+ 'CREATE FUNCTION f() RETURNS void AS $$ BEGIN PERFORM 1; PERFORM 2; END; $$ LANGUAGE plpgsql',
73
+ 'SELECT 1'
74
+ ]);
75
+ });
76
+
77
+ test('handles tagged dollar quotes', () => {
78
+ const sql = `DO $body$ BEGIN RAISE NOTICE 'x;y'; END $body$; SELECT 1`;
79
+ expect(splitSqlStatements(sql)).toEqual([
80
+ "DO $body$ BEGIN RAISE NOTICE 'x;y'; END $body$",
81
+ 'SELECT 1'
82
+ ]);
83
+ });
84
+
85
+ test('returns empty array for whitespace / comment only input', () => {
86
+ expect(splitSqlStatements(' ; ')).toEqual([]);
87
+ });
88
+ });
@@ -0,0 +1,132 @@
1
+ /**
2
+ * db-client — split a SQL string into individual statements on top-level `;`.
3
+ *
4
+ * The splitter is aware of the contexts where a `;` must NOT split a
5
+ * statement:
6
+ * - single/double-quoted strings, incl. doubled-quote (`''`, `""`) and
7
+ * backslash (`\'`, MySQL) escapes;
8
+ * - backtick-quoted identifiers (MySQL);
9
+ * - line (`-- …`) and block (`/* … *\/`) comments;
10
+ * - Postgres dollar-quoted bodies (`$$ … ; … $$`, `$tag$ … $tag$`), which
11
+ * routinely contain semicolons inside function / DO blocks.
12
+ *
13
+ * It is intentionally conservative: it never rewrites the SQL, only slices it
14
+ * on statement boundaries. Anything it can't confidently classify is kept in
15
+ * the current statement so the database — not this splitter — has the final say.
16
+ */
17
+ export function splitSqlStatements(sql: string): string[] {
18
+ const statements: string[] = [];
19
+ let current = '';
20
+ let quote: "'" | '"' | '`' | null = null;
21
+ let inLineComment = false;
22
+ let inBlockComment = false;
23
+ let dollarTag: string | null = null;
24
+
25
+ let i = 0;
26
+ const n = sql.length;
27
+ while (i < n) {
28
+ const ch = sql[i];
29
+ const next = sql[i + 1];
30
+
31
+ if (inLineComment) {
32
+ current += ch;
33
+ if (ch === '\n') inLineComment = false;
34
+ i++;
35
+ continue;
36
+ }
37
+
38
+ if (inBlockComment) {
39
+ if (ch === '*' && next === '/') {
40
+ current += '*/';
41
+ i += 2;
42
+ inBlockComment = false;
43
+ } else {
44
+ current += ch;
45
+ i++;
46
+ }
47
+ continue;
48
+ }
49
+
50
+ if (dollarTag !== null) {
51
+ if (ch === '$' && sql.startsWith(dollarTag, i)) {
52
+ current += dollarTag;
53
+ i += dollarTag.length;
54
+ dollarTag = null;
55
+ } else {
56
+ current += ch;
57
+ i++;
58
+ }
59
+ continue;
60
+ }
61
+
62
+ if (quote !== null) {
63
+ // MySQL backslash escapes apply inside string literals only.
64
+ if (ch === '\\' && quote === "'") {
65
+ current += ch;
66
+ if (next !== undefined) {
67
+ current += next;
68
+ i += 2;
69
+ } else {
70
+ i++;
71
+ }
72
+ continue;
73
+ }
74
+ if (ch === quote) {
75
+ // Doubled quote is an escaped quote, not the end of the literal.
76
+ if (next === quote) {
77
+ current += ch + next;
78
+ i += 2;
79
+ continue;
80
+ }
81
+ quote = null;
82
+ }
83
+ current += ch;
84
+ i++;
85
+ continue;
86
+ }
87
+
88
+ if (ch === '-' && next === '-') {
89
+ inLineComment = true;
90
+ current += ch;
91
+ i++;
92
+ continue;
93
+ }
94
+
95
+ if (ch === '/' && next === '*') {
96
+ inBlockComment = true;
97
+ current += '/*';
98
+ i += 2;
99
+ continue;
100
+ }
101
+
102
+ if (ch === "'" || ch === '"' || ch === '`') {
103
+ quote = ch;
104
+ current += ch;
105
+ i++;
106
+ continue;
107
+ }
108
+
109
+ if (ch === '$') {
110
+ const tagMatch = /^\$(?:[A-Za-z_][A-Za-z0-9_]*)?\$/.exec(sql.slice(i));
111
+ if (tagMatch) {
112
+ dollarTag = tagMatch[0];
113
+ current += dollarTag;
114
+ i += dollarTag.length;
115
+ continue;
116
+ }
117
+ }
118
+
119
+ if (ch === ';') {
120
+ if (current.trim()) statements.push(current.trim());
121
+ current = '';
122
+ i++;
123
+ continue;
124
+ }
125
+
126
+ current += ch;
127
+ i++;
128
+ }
129
+
130
+ if (current.trim()) statements.push(current.trim());
131
+ return statements;
132
+ }
@@ -28,6 +28,12 @@ export type LogLabel =
28
28
  | 'websocket'
29
29
  | 'mcp'
30
30
  | 'skills'
31
+ | 'artifacts'
32
+ | 'commands'
33
+ | 'subagents'
34
+ | 'instructions'
35
+ | 'permissions'
36
+ | 'profiles'
31
37
  | 'notification'
32
38
  | 'rate-limit'
33
39