@myrialabs/clopen 0.4.40 → 0.4.42

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 (141) hide show
  1. package/.env.example +1 -1
  2. package/backend/artifacts/detect.ts +15 -3
  3. package/backend/artifacts/generate.ts +2 -2
  4. package/backend/artifacts/index.ts +12 -4
  5. package/backend/artifacts/markers.ts +24 -1
  6. package/backend/artifacts/matrix.ts +47 -3
  7. package/backend/artifacts/sync.test.ts +3 -3
  8. package/backend/artifacts/sync.ts +8 -20
  9. package/backend/artifacts/types.ts +9 -3
  10. package/backend/auth/permissions.ts +6 -11
  11. package/backend/auth/session-cleanup.ts +10 -1
  12. package/backend/auth/tokens.ts +9 -1
  13. package/backend/chat/stream-manager.ts +50 -0
  14. package/backend/database/crypto/secret-columns.ts +5 -1
  15. package/backend/database/index.ts +18 -0
  16. package/backend/database/migrations/079_merge_commands_into_skills.ts +222 -0
  17. package/backend/database/migrations/080_create_file_shares.ts +111 -0
  18. package/backend/database/migrations/081_create_push_subscriptions.ts +32 -0
  19. package/backend/database/migrations/082_create_git_identities.test.ts +186 -0
  20. package/backend/database/migrations/082_create_git_identities.ts +122 -0
  21. package/backend/database/migrations/index.ts +28 -0
  22. package/backend/database/queries/file-share-queries.ts +163 -0
  23. package/backend/database/queries/git-identity-queries.ts +290 -0
  24. package/backend/database/queries/index.ts +8 -4
  25. package/backend/database/queries/profile-queries.ts +5 -3
  26. package/backend/database/queries/push-subscription-queries.test.ts +90 -0
  27. package/backend/database/queries/push-subscription-queries.ts +99 -0
  28. package/backend/database/queries/skill-queries.ts +96 -18
  29. package/backend/engine/adapters/claude/environment.ts +11 -1
  30. package/backend/engine/adapters/claude/stream.ts +3 -2
  31. package/backend/engine/adapters/cline/stream.ts +3 -3
  32. package/backend/engine/adapters/codex/stream.ts +38 -6
  33. package/backend/engine/adapters/copilot/stream.ts +3 -3
  34. package/backend/engine/adapters/cursor/stream.ts +25 -3
  35. package/backend/engine/adapters/opencode/server.ts +26 -2
  36. package/backend/engine/adapters/opencode/stream.ts +8 -7
  37. package/backend/engine/adapters/pi/stream.ts +2 -2
  38. package/backend/engine/adapters/qwen/stream.ts +5 -3
  39. package/backend/engine/artifact-sync.ts +26 -20
  40. package/backend/engine/docs/artifacts.md +81 -22
  41. package/backend/engine/docs/quick-reference.md +2 -1
  42. package/backend/engine/resolve-model.test.ts +108 -0
  43. package/backend/engine/resolve-model.ts +53 -10
  44. package/backend/engine/structured-helpers.ts +22 -0
  45. package/backend/engine/types.ts +10 -0
  46. package/backend/files/file-shares.ts +369 -0
  47. package/backend/files/path-browsing.ts +27 -21
  48. package/backend/git/git-executor.ts +28 -2
  49. package/backend/git/git-service.ts +59 -40
  50. package/backend/git/identity/cli.test.ts +58 -0
  51. package/backend/git/identity/cli.ts +201 -0
  52. package/backend/git/identity/credential-helper.test.ts +242 -0
  53. package/backend/git/identity/env.test.ts +214 -0
  54. package/backend/git/identity/env.ts +193 -0
  55. package/backend/git/identity/import-local.test.ts +199 -0
  56. package/backend/git/identity/import-local.ts +141 -0
  57. package/backend/git/identity/index.ts +78 -0
  58. package/backend/git/identity/keys.ts +183 -0
  59. package/backend/git/identity/resolve.ts +140 -0
  60. package/backend/git/identity/scope-config.test.ts +145 -0
  61. package/backend/git/identity/scope-config.ts +175 -0
  62. package/backend/git/identity/service.ts +297 -0
  63. package/backend/http/files-shared.test.ts +505 -0
  64. package/backend/http/files-shared.ts +351 -0
  65. package/backend/http/push.ts +150 -0
  66. package/backend/index.ts +24 -0
  67. package/backend/instructions/index.ts +1 -1
  68. package/backend/instructions/sync.ts +30 -6
  69. package/backend/memory/compose.ts +2 -2
  70. package/backend/memory/consolidate.ts +2 -2
  71. package/backend/memory/extract/episodic.ts +2 -2
  72. package/backend/memory/judge.ts +2 -2
  73. package/backend/preview/browser/browser-console-manager.ts +214 -34
  74. package/backend/preview/browser/browser-pool.ts +526 -123
  75. package/backend/preview/browser/browser-preview-service.ts +192 -8
  76. package/backend/preview/browser/browser-tab-lifecycle.test.ts +240 -0
  77. package/backend/preview/browser/browser-tab-lifecycle.ts +495 -0
  78. package/backend/preview/browser/browser-tab-manager.ts +291 -65
  79. package/backend/preview/browser/capture-profile.ts +15 -1
  80. package/backend/preview/browser/types.ts +26 -1
  81. package/backend/profiles/service.ts +7 -6
  82. package/backend/push/sender.ts +172 -0
  83. package/backend/push/tags.ts +25 -0
  84. package/backend/push/vapid-keys.ts +77 -0
  85. package/backend/push/webpush-crypto.test.ts +200 -0
  86. package/backend/push/webpush-crypto.ts +231 -0
  87. package/backend/skills/detect.ts +28 -0
  88. package/backend/skills/index.ts +22 -4
  89. package/backend/skills/invoke.test.ts +114 -0
  90. package/backend/skills/invoke.ts +222 -0
  91. package/backend/skills/service.ts +194 -44
  92. package/backend/skills/spec.ts +35 -0
  93. package/backend/skills/sync.ts +85 -55
  94. package/backend/subagents/detect.ts +2 -3
  95. package/backend/subagents/sync.ts +15 -8
  96. package/backend/terminal/ptykit.ts +24 -0
  97. package/backend/work/pull-requests.ts +2 -2
  98. package/backend/ws/chat/stream.ts +100 -8
  99. package/backend/ws/files/index.ts +4 -0
  100. package/backend/ws/files/share.ts +95 -0
  101. package/backend/ws/git/branch-name.ts +2 -2
  102. package/backend/ws/git/branch.ts +17 -6
  103. package/backend/ws/git/commit-message.ts +2 -2
  104. package/backend/ws/git/commit.ts +6 -5
  105. package/backend/ws/git/conflict.ts +3 -2
  106. package/backend/ws/git/identity-context.ts +91 -0
  107. package/backend/ws/git/identity.ts +200 -0
  108. package/backend/ws/git/index.ts +3 -1
  109. package/backend/ws/git/remote.ts +57 -11
  110. package/backend/ws/index.ts +3 -4
  111. package/backend/ws/preview/browser/data.ts +60 -0
  112. package/backend/ws/preview/browser/interact.ts +6 -0
  113. package/backend/ws/preview/browser/tab-info.ts +9 -1
  114. package/backend/ws/preview/browser/tab.ts +64 -8
  115. package/backend/ws/preview/index.ts +21 -0
  116. package/backend/ws/profiles/crud.ts +2 -3
  117. package/backend/ws/skills/catalog.ts +5 -1
  118. package/backend/ws/skills/crud.ts +128 -22
  119. package/backend/ws/skills/index.ts +4 -1
  120. package/backend/ws/user/crud.ts +12 -3
  121. package/bin/clopen.ts +9 -0
  122. package/dist/assets/{index-D4igjF6e.js → index-BynqyvF4.js} +1 -1
  123. package/dist/assets/{index-DONNwiXm.js → index-DLoJsmNQ.js} +1 -1
  124. package/dist/assets/{main-BrfXH1bL.js → main-CUyZAmqt.js} +601 -592
  125. package/dist/assets/main-DVCW3cfr.css +1 -0
  126. package/dist/index.html +7 -2
  127. package/dist/sw.js +112 -0
  128. package/package.json +2 -2
  129. package/shared/constants/engine-tools.ts +31 -6
  130. package/shared/constants/notification-messages.ts +142 -0
  131. package/shared/types/git-identity.ts +112 -0
  132. package/shared/types/unified/stream.ts +7 -0
  133. package/backend/commands/detect.ts +0 -25
  134. package/backend/commands/index.ts +0 -9
  135. package/backend/commands/service.ts +0 -178
  136. package/backend/commands/store.ts +0 -45
  137. package/backend/commands/sync.ts +0 -94
  138. package/backend/database/queries/command-queries.ts +0 -82
  139. package/backend/ws/commands/crud.ts +0 -157
  140. package/backend/ws/commands/index.ts +0 -8
  141. package/dist/assets/main-CT1PygsW.css +0 -1
@@ -25,7 +25,7 @@
25
25
  */
26
26
 
27
27
  import { initializeEngine } from '$backend/engine';
28
- import { resolveGenerationTarget } from '$backend/engine/resolve-model';
28
+ import { resolveGenerationTarget, GENERATION_SETTINGS } from '$backend/engine/resolve-model';
29
29
  import { getDatabase } from '$backend/database';
30
30
  import { graphQueries } from '$backend/database/queries/graph-queries';
31
31
  import { debug } from '$shared/utils/logger';
@@ -62,7 +62,7 @@ async function generate<T>(model: MemoryModelConfig, prompt: string, schema: Rec
62
62
  try {
63
63
  const engine = await initializeEngine(model.engine);
64
64
  if (!engine.generateStructured) return null;
65
- const target = await resolveGenerationTarget(engine, model.modelId, model.providerSlug);
65
+ const target = await resolveGenerationTarget(engine, model.modelId, model.providerSlug, GENERATION_SETTINGS.memory);
66
66
  const accountId = model.accountId ?? target.accountId;
67
67
  return await engine.generateStructured<T>({
68
68
  prompt,
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from 'events';
2
- import type { Page, ConsoleMessage as PuppeteerConsoleMessage, HTTPResponse } from 'puppeteer';
2
+ import type { JSHandle, Page, ConsoleMessage as PuppeteerConsoleMessage, HTTPResponse } from 'puppeteer';
3
3
  import type { BrowserConsoleMessage, BrowserConsoleValue, BrowserTab } from './types';
4
4
 
5
5
  import { debug } from '$shared/utils/logger';
@@ -8,6 +8,87 @@ import { debug } from '$shared/utils/logger';
8
8
  const MAX_LOGS = 1000;
9
9
  const TRIM_TO = 500;
10
10
 
11
+ /**
12
+ * Per-tab ceiling on page-originated console traffic.
13
+ *
14
+ * Every message costs a structured payload to each viewer in the project, and
15
+ * a dev build in a re-render loop can produce thousands a second. Past the
16
+ * ceiling the messages are counted rather than carried, and the count is
17
+ * reported — a panel that says "4,812 dropped" is honest, whereas one that
18
+ * silently keeps up is the one that makes the whole workspace stutter.
19
+ */
20
+ const RATE_WINDOW_MS = 1000;
21
+ const MAX_MESSAGES_PER_WINDOW = 60;
22
+
23
+ interface ConsoleBudget {
24
+ windowStart: number;
25
+ used: number;
26
+ dropped: number;
27
+ }
28
+
29
+ /** What the manager needs to know about the world outside it. */
30
+ export interface ConsoleManagerDeps {
31
+ /**
32
+ * Whether anyone is actually looking at this tab.
33
+ *
34
+ * Console capture used to be unconditional: every tab, watched or not,
35
+ * paid a CDP round-trip per logged argument and a broadcast per message,
36
+ * for a panel that in most cases was not even open. Unwatched tabs now
37
+ * keep a text-only history — enough to read back when the panel opens,
38
+ * with none of the per-message cost.
39
+ */
40
+ isWatched(sessionId: string): boolean;
41
+ }
42
+
43
+ function shorten(text: string, limit = 200): string {
44
+ return text.length > limit ? `${text.slice(0, limit)}…` : text;
45
+ }
46
+
47
+ /**
48
+ * Read an argument's value straight off the CDP payload Chrome already sent.
49
+ *
50
+ * Primitives — which is what the overwhelming majority of logs are made of —
51
+ * arrive complete with the console event, so evaluating in the page to learn
52
+ * what `"hello"` is costs a round-trip for something already in hand. Returns
53
+ * null for anything that genuinely needs the page to describe it.
54
+ */
55
+ function valueFromRemoteObject(handle: JSHandle): BrowserConsoleValue | null {
56
+ const remote = handle.remoteObject();
57
+
58
+ switch (remote.type) {
59
+ case 'string':
60
+ return { type: 'string', preview: shorten(String(remote.value), 1000) };
61
+ case 'number':
62
+ return { type: 'number', preview: remote.unserializableValue ?? String(remote.value) };
63
+ case 'boolean':
64
+ return { type: 'boolean', preview: String(remote.value) };
65
+ case 'undefined':
66
+ return { type: 'undefined', preview: 'undefined' };
67
+ case 'bigint':
68
+ return { type: 'bigint', preview: remote.unserializableValue ?? `${String(remote.value)}n` };
69
+ case 'symbol':
70
+ return { type: 'symbol', preview: remote.description ?? 'Symbol()' };
71
+ case 'function': {
72
+ // `description` is the function's source; its signature is the part
73
+ // before the body, which is what DevTools shows too.
74
+ const signature = (remote.description ?? '').split('{')[0].trim().replace(/^function\s*/, '');
75
+ return { type: 'function', preview: `ƒ ${shorten(signature || '()', 80)}` };
76
+ }
77
+ case 'object':
78
+ if (remote.subtype === 'null') return { type: 'null', preview: 'null' };
79
+ return null;
80
+ default:
81
+ return null;
82
+ }
83
+ }
84
+
85
+ /** The shape of an object, without asking the page to walk it. */
86
+ function outlineFromRemoteObject(handle: JSHandle): BrowserConsoleValue {
87
+ const remote = handle.remoteObject();
88
+ const label = remote.className || remote.subtype || 'Object';
89
+ return { type: 'object', preview: remote.description ? shorten(remote.description) : label };
90
+ }
91
+
11
92
  /**
12
93
  * Flatten a page value into something renderable.
13
94
  *
@@ -160,8 +241,87 @@ function normalizeConsoleType(type: string): BrowserConsoleMessage['type'] {
160
241
  }
161
242
 
162
243
  export class BrowserConsoleManager extends EventEmitter {
163
- constructor() {
244
+ private deps: ConsoleManagerDeps;
245
+ private budgets = new Map<string, ConsoleBudget>();
246
+
247
+ constructor(deps: ConsoleManagerDeps) {
164
248
  super();
249
+ this.deps = deps;
250
+ }
251
+
252
+ private isWatched(sessionId: string): boolean {
253
+ try {
254
+ return this.deps.isWatched(sessionId);
255
+ } catch {
256
+ return true;
257
+ }
258
+ }
259
+
260
+ /**
261
+ * Whether this tab may spend another message this second.
262
+ *
263
+ * Rolling the window is also where a burst gets reported, so the drop is
264
+ * visible in the panel at the point it happened rather than inferred from
265
+ * a gap in the log.
266
+ */
267
+ private admit(session: BrowserTab): boolean {
268
+ const now = Date.now();
269
+ let budget = this.budgets.get(session.id);
270
+
271
+ if (!budget || now - budget.windowStart >= RATE_WINDOW_MS) {
272
+ const dropped = budget?.dropped ?? 0;
273
+ budget = { windowStart: now, used: 0, dropped: 0 };
274
+ this.budgets.set(session.id, budget);
275
+
276
+ if (dropped > 0) {
277
+ budget.used += 1;
278
+ this.record(session, {
279
+ id: BrowserConsoleManager.makeId('console'),
280
+ type: 'warn',
281
+ text: `${dropped} more console message${dropped === 1 ? '' : 's'} dropped (rate limit)`,
282
+ timestamp: now
283
+ });
284
+ }
285
+ }
286
+
287
+ if (budget.used >= MAX_MESSAGES_PER_WINDOW) {
288
+ budget.dropped += 1;
289
+ return false;
290
+ }
291
+
292
+ budget.used += 1;
293
+ return true;
294
+ }
295
+
296
+ /**
297
+ * Turn a console call's arguments into renderable values.
298
+ *
299
+ * Primitives are read off the event itself. Objects need the page to walk
300
+ * them, which is a round-trip per argument — worth paying while someone is
301
+ * watching, and not worth paying at all for a tab in the background, which
302
+ * gets the outline Chrome already sent instead.
303
+ */
304
+ private async collectValues(
305
+ consoleMessage: PuppeteerConsoleMessage,
306
+ watched: boolean
307
+ ): Promise<BrowserConsoleValue[]> {
308
+ const args = consoleMessage.args();
309
+ if (args.length === 0) return [];
310
+
311
+ // Still one Promise.all: the arguments that do need the page are walked
312
+ // concurrently, as they always were. What changed is how few of them
313
+ // reach that path at all.
314
+ return Promise.all(
315
+ args.map((arg) => {
316
+ const cheap = valueFromRemoteObject(arg);
317
+ if (cheap) return cheap;
318
+ if (!watched) return outlineFromRemoteObject(arg);
319
+
320
+ return arg
321
+ .evaluate(serializeConsoleValue as never)
322
+ .catch(() => ({ type: 'object', preview: '[unserializable]' }) as BrowserConsoleValue);
323
+ })
324
+ );
165
325
  }
166
326
 
167
327
  /**
@@ -169,7 +329,12 @@ export class BrowserConsoleManager extends EventEmitter {
169
329
  * a counter the way DevTools does — a page logging inside a rAF loop would
170
330
  * otherwise flood the panel and evict everything useful.
171
331
  */
172
- private record(session: BrowserTab, message: BrowserConsoleMessage): void {
332
+ private record(session: BrowserTab, message: BrowserConsoleMessage, force = false): void {
333
+ // The buffer is always kept — it is what the panel reads back when it
334
+ // opens. Only the live broadcast is conditional: pushing a message to
335
+ // every viewer in the project for a tab none of them is looking at is
336
+ // work that ends in nothing being displayed.
337
+ const publish = force || this.isWatched(session.id);
173
338
  const previous = session.consoleLogs[session.consoleLogs.length - 1];
174
339
 
175
340
  if (
@@ -181,7 +346,7 @@ export class BrowserConsoleManager extends EventEmitter {
181
346
  ) {
182
347
  previous.count = (previous.count ?? 1) + 1;
183
348
  previous.timestamp = message.timestamp;
184
- this.emit('console-message', { sessionId: session.id, message: previous });
349
+ if (publish) this.emit('console-message', { sessionId: session.id, message: previous });
185
350
  return;
186
351
  }
187
352
 
@@ -190,7 +355,7 @@ export class BrowserConsoleManager extends EventEmitter {
190
355
  session.consoleLogs = session.consoleLogs.slice(-TRIM_TO);
191
356
  }
192
357
 
193
- this.emit('console-message', { sessionId: session.id, message });
358
+ if (publish) this.emit('console-message', { sessionId: session.id, message });
194
359
  }
195
360
 
196
361
  private static makeId(prefix: string): string {
@@ -207,6 +372,8 @@ export class BrowserConsoleManager extends EventEmitter {
207
372
  return;
208
373
  }
209
374
 
375
+ if (!this.admit(session)) return;
376
+
210
377
  try {
211
378
  const text = consoleMessage.text();
212
379
  const type = normalizeConsoleType(consoleMessage.type());
@@ -226,16 +393,7 @@ export class BrowserConsoleManager extends EventEmitter {
226
393
  // which make `jsonValue()` throw and used to be dropped entirely.
227
394
  let values: BrowserConsoleValue[] = [];
228
395
  try {
229
- const args = consoleMessage.args();
230
- if (args.length > 0) {
231
- values = await Promise.all(
232
- args.map((arg) =>
233
- arg
234
- .evaluate(serializeConsoleValue as never)
235
- .catch(() => ({ type: 'object', preview: '[unserializable]' }) as BrowserConsoleValue)
236
- )
237
- );
238
- }
396
+ values = await this.collectValues(consoleMessage, this.isWatched(session.id));
239
397
  } catch (error) {
240
398
  debug.warn('preview', 'Could not extract console message args:', error);
241
399
  }
@@ -265,6 +423,8 @@ export class BrowserConsoleManager extends EventEmitter {
265
423
  return;
266
424
  }
267
425
 
426
+ if (!this.admit(session)) return;
427
+
268
428
  try {
269
429
  const error = err as Error;
270
430
  this.record(session, {
@@ -283,6 +443,7 @@ export class BrowserConsoleManager extends EventEmitter {
283
443
  page.on('response', (response: HTTPResponse) => {
284
444
  if (!session.consoleEnabled) return;
285
445
  if (response.ok() || response.status() < 400) return;
446
+ if (!this.admit(session)) return;
286
447
 
287
448
  try {
288
449
  this.record(session, {
@@ -307,6 +468,7 @@ export class BrowserConsoleManager extends EventEmitter {
307
468
  // would otherwise be invisible in the panel.
308
469
  page.on('requestfailed', (request) => {
309
470
  if (!session.consoleEnabled) return;
471
+ if (!this.admit(session)) return;
310
472
 
311
473
  try {
312
474
  const failure = request.failure();
@@ -331,6 +493,7 @@ export class BrowserConsoleManager extends EventEmitter {
331
493
  if (!session) return false;
332
494
 
333
495
  session.consoleLogs = [];
496
+ this.budgets.delete(session.id);
334
497
 
335
498
  // Emit clear event
336
499
  this.emit('console-clear', {
@@ -341,6 +504,11 @@ export class BrowserConsoleManager extends EventEmitter {
341
504
  return true;
342
505
  }
343
506
 
507
+ /** Drop a closed tab's rate-limit bookkeeping. */
508
+ forgetSession(sessionId: string): void {
509
+ this.budgets.delete(sessionId);
510
+ }
511
+
344
512
  toggleConsoleLogging(session: BrowserTab, enabled: boolean): boolean {
345
513
  if (!session) return false;
346
514
 
@@ -359,12 +527,16 @@ export class BrowserConsoleManager extends EventEmitter {
359
527
  async executeConsoleCommand(session: BrowserTab, command: string): Promise<BrowserConsoleValue> {
360
528
  if (!session) throw new Error('Session not found');
361
529
 
362
- this.record(session, {
363
- id: BrowserConsoleManager.makeId('input'),
364
- type: 'input',
365
- text: command,
366
- timestamp: Date.now()
367
- });
530
+ this.record(
531
+ session,
532
+ {
533
+ id: BrowserConsoleManager.makeId('input'),
534
+ type: 'input',
535
+ text: command,
536
+ timestamp: Date.now()
537
+ },
538
+ true
539
+ );
368
540
 
369
541
  try {
370
542
  const outcome = await session.page.evaluate(
@@ -392,24 +564,32 @@ export class BrowserConsoleManager extends EventEmitter {
392
564
  serializeConsoleValue.toString()
393
565
  );
394
566
 
395
- this.record(session, {
396
- id: BrowserConsoleManager.makeId('result'),
397
- type: outcome.failed ? 'error' : 'result',
398
- text: outcome.value.preview,
399
- values: [outcome.value],
400
- timestamp: Date.now()
401
- });
567
+ this.record(
568
+ session,
569
+ {
570
+ id: BrowserConsoleManager.makeId('result'),
571
+ type: outcome.failed ? 'error' : 'result',
572
+ text: outcome.value.preview,
573
+ values: [outcome.value],
574
+ timestamp: Date.now()
575
+ },
576
+ true
577
+ );
402
578
 
403
579
  return outcome.value;
404
580
  } catch (error) {
405
581
  const message = error instanceof Error ? error.message : String(error);
406
582
 
407
- this.record(session, {
408
- id: BrowserConsoleManager.makeId('result'),
409
- type: 'error',
410
- text: message,
411
- timestamp: Date.now()
412
- });
583
+ this.record(
584
+ session,
585
+ {
586
+ id: BrowserConsoleManager.makeId('result'),
587
+ type: 'error',
588
+ text: message,
589
+ timestamp: Date.now()
590
+ },
591
+ true
592
+ );
413
593
 
414
594
  throw error;
415
595
  }