@myrialabs/clopen 0.4.35 → 0.4.37

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 (91) hide show
  1. package/backend/artifacts/sync.test.ts +63 -0
  2. package/backend/artifacts/sync.ts +56 -3
  3. package/backend/database/migrations/070_create_worktrees_table.ts +67 -0
  4. package/backend/database/migrations/index.ts +7 -0
  5. package/backend/database/queries/index.ts +1 -0
  6. package/backend/database/queries/session-queries.ts +50 -11
  7. package/backend/database/queries/worktree-queries.ts +148 -0
  8. package/backend/engine/adapters/opencode/server.ts +389 -83
  9. package/backend/engine/adapters/opencode/stream.ts +14 -14
  10. package/backend/engine/hot-reload.ts +25 -10
  11. package/backend/files/file-watcher.ts +35 -9
  12. package/backend/git/conflict-state.test.ts +396 -0
  13. package/backend/git/git-executor.ts +6 -0
  14. package/backend/git/git-parser.ts +144 -48
  15. package/backend/git/git-service.ts +727 -57
  16. package/backend/git/push-target.test.ts +264 -0
  17. package/backend/host/metrics.test.ts +110 -0
  18. package/backend/host/metrics.ts +235 -0
  19. package/backend/index.ts +5 -2
  20. package/backend/mcp/internal/servers/browser-automation/context.ts +16 -2
  21. package/backend/ports/attribute.test.ts +3 -2
  22. package/backend/ports/attribute.ts +5 -44
  23. package/backend/preview/browser/browser-pool.ts +81 -0
  24. package/backend/preview/browser/browser-preview-service.ts +142 -32
  25. package/backend/preview/browser/browser-tab-manager.ts +350 -113
  26. package/backend/preview/browser/types.ts +9 -0
  27. package/backend/project/status-manager.ts +20 -0
  28. package/backend/projects/project-cleanup.integration.test.ts +1 -1
  29. package/backend/projects/project-cleanup.ts +7 -1
  30. package/backend/projects/shell-ownership.ts +65 -0
  31. package/backend/snapshot/snapshot-service.ts +6 -2
  32. package/backend/terminal/ptykit.ts +35 -6
  33. package/backend/utils/ws.ts +21 -1
  34. package/backend/worktrees/clone.ts +222 -0
  35. package/backend/worktrees/index.ts +29 -0
  36. package/backend/worktrees/merge.test.ts +93 -0
  37. package/backend/worktrees/merge.ts +232 -0
  38. package/backend/worktrees/paths.test.ts +60 -0
  39. package/backend/worktrees/paths.ts +60 -0
  40. package/backend/worktrees/resolve.ts +67 -0
  41. package/backend/worktrees/service.ts +315 -0
  42. package/backend/worktrees/tree.ts +59 -0
  43. package/backend/ws/access.ts +18 -0
  44. package/backend/ws/artifacts/generate.ts +2 -2
  45. package/backend/ws/chat/stream.ts +9 -2
  46. package/backend/ws/files/panel-state-scope.test.ts +102 -0
  47. package/backend/ws/files/path-access.test.ts +93 -1
  48. package/backend/ws/files/path-access.ts +54 -5
  49. package/backend/ws/files/read.ts +15 -10
  50. package/backend/ws/files/search.ts +7 -7
  51. package/backend/ws/files/state.ts +70 -8
  52. package/backend/ws/files/watch.ts +16 -14
  53. package/backend/ws/git/branch-name.ts +9 -8
  54. package/backend/ws/git/branch.ts +58 -16
  55. package/backend/ws/git/commit-message.ts +16 -13
  56. package/backend/ws/git/commit.ts +17 -17
  57. package/backend/ws/git/conflict.ts +116 -13
  58. package/backend/ws/git/diff-budget.test.ts +125 -0
  59. package/backend/ws/git/diff-budget.ts +220 -0
  60. package/backend/ws/git/diff.ts +9 -9
  61. package/backend/ws/git/ignored.ts +9 -9
  62. package/backend/ws/git/log.ts +28 -3
  63. package/backend/ws/git/remote.ts +118 -44
  64. package/backend/ws/git/staging.ts +16 -16
  65. package/backend/ws/git/status.ts +13 -13
  66. package/backend/ws/index.ts +4 -0
  67. package/backend/ws/preview/access.ts +11 -3
  68. package/backend/ws/projects/index.ts +5 -1
  69. package/backend/ws/projects/info.test.ts +54 -0
  70. package/backend/ws/projects/info.ts +398 -0
  71. package/backend/ws/sessions/crud.ts +21 -6
  72. package/backend/ws/snapshot/restore.ts +11 -14
  73. package/backend/ws/system/device-info.ts +62 -144
  74. package/backend/ws/worktrees/crud.ts +187 -0
  75. package/backend/ws/worktrees/index.ts +33 -0
  76. package/backend/ws/worktrees/transfer.ts +88 -0
  77. package/dist/assets/{index-BRJqss6F.js → index-Bik9TCBi.js} +1 -1
  78. package/dist/assets/{index-B0iIhSO9.js → index-sJmS_CCm.js} +1 -1
  79. package/dist/assets/main-DLqolBI2.css +1 -0
  80. package/dist/assets/main-Df1I3hnw.js +1096 -0
  81. package/dist/index.html +2 -2
  82. package/package.json +1 -1
  83. package/shared/types/database/schema.ts +26 -0
  84. package/shared/types/git.ts +123 -0
  85. package/shared/utils/logger.ts +1 -0
  86. package/shared/utils/workspace-scope.test.ts +80 -0
  87. package/shared/utils/workspace-scope.ts +57 -0
  88. package/shared/utils/ws-client.ts +25 -5
  89. package/shared/utils/ws-server.ts +19 -3
  90. package/dist/assets/main-Buko4D0t.css +0 -1
  91. package/dist/assets/main-C_iGUZyL.js +0 -1078
@@ -14,7 +14,8 @@ import type {
14
14
  GitCommit,
15
15
  GitRemote,
16
16
  GitStashEntry,
17
- GitConflictMarker
17
+ GitConflictMarker,
18
+ GitReflogEntry
18
19
  } from '$shared/types/git';
19
20
 
20
21
  /**
@@ -120,10 +121,15 @@ export function parseBranches(localOutput: string, remoteOutput: string): GitBra
120
121
  // Parse local branches
121
122
  const localLines = localOutput.split('\n').filter(Boolean);
122
123
  for (const line of localLines) {
123
- const dateSep = line.lastIndexOf('|');
124
+ // The upstream is appended after a 0x1F unit separator rather than another
125
+ // `|`, because the subject in the middle of the line can contain `|` and
126
+ // the legacy fields are still split positionally.
127
+ const [legacy, upstreamField = ''] = line.split('\x1f');
128
+
129
+ const dateSep = legacy.lastIndexOf('|');
124
130
  if (dateSep === -1) continue;
125
- const lastCommitDate = line.substring(dateSep + 1);
126
- const head = line.substring(0, dateSep);
131
+ const lastCommitDate = legacy.substring(dateSep + 1);
132
+ const head = legacy.substring(0, dateSep);
127
133
 
128
134
  // head = "<*>|<name>|<hash>|<subject>"
129
135
  const parts = head.split('|', 4);
@@ -135,7 +141,7 @@ export function parseBranches(localOutput: string, remoteOutput: string): GitBra
135
141
 
136
142
  if (isCurrent) current = name;
137
143
 
138
- local.push({
144
+ const branch: GitBranch = {
139
145
  name,
140
146
  isCurrent,
141
147
  isRemote: false,
@@ -144,7 +150,10 @@ export function parseBranches(localOutput: string, remoteOutput: string): GitBra
144
150
  lastCommit,
145
151
  lastCommitMessage,
146
152
  lastCommitDate
147
- } as GitBranch);
153
+ };
154
+ if (upstreamField.trim()) branch.upstream = upstreamField.trim();
155
+
156
+ local.push(branch);
148
157
  }
149
158
 
150
159
  // Parse remote branches
@@ -394,58 +403,145 @@ export function parseStashList(output: string): GitStashEntry[] {
394
403
  /**
395
404
  * Parse conflict markers from file content
396
405
  */
406
+ /**
407
+ * Conflict markers are exactly seven repeated characters followed by a space or
408
+ * the end of the line. Matching a bare `startsWith('<<<<<<<')` also fires on
409
+ * ordinary content — an eight-arrow ASCII divider, a diff quoted inside a
410
+ * markdown file — and turns a clean file into a phantom conflict.
411
+ */
412
+ const MARKER_OURS = /^<{7}(?:[ \t\r]|$)/;
413
+ const MARKER_BASE = /^\|{7}(?:[ \t\r]|$)/;
414
+ const MARKER_SEP = /^={7}(?:[ \t\r]|$)/;
415
+ const MARKER_THEIRS = /^>{7}(?:[ \t\r]|$)/;
416
+
417
+ /**
418
+ * True when the text still contains an unresolved conflict block. Used as a
419
+ * guard before staging: `git add` happily records a file that still has markers
420
+ * in it, which silently commits `<<<<<<<` into the tree.
421
+ */
422
+ export function hasConflictMarkers(content: string): boolean {
423
+ return parseConflictMarkers(content).length > 0;
424
+ }
425
+
397
426
  export function parseConflictMarkers(content: string): GitConflictMarker[] {
398
427
  const markers: GitConflictMarker[] = [];
399
428
  const lines = content.split('\n');
400
429
 
401
430
  let i = 0;
402
431
  while (i < lines.length) {
403
- if (lines[i].startsWith('<<<<<<<')) {
404
- const ourStart = i;
405
- let baseStart: number | undefined;
406
- let separatorIndex = -1;
407
- let theirEnd = -1;
408
-
409
- // Find the rest of the conflict
410
- let j = i + 1;
411
- while (j < lines.length) {
412
- if (lines[j].startsWith('|||||||')) {
413
- baseStart = j;
414
- } else if (lines[j].startsWith('=======')) {
415
- separatorIndex = j;
416
- } else if (lines[j].startsWith('>>>>>>>')) {
417
- theirEnd = j;
418
- break;
419
- }
420
- j++;
421
- }
432
+ if (!MARKER_OURS.test(lines[i])) {
433
+ i++;
434
+ continue;
435
+ }
422
436
 
423
- if (separatorIndex >= 0 && theirEnd >= 0) {
424
- const ourContentStart = ourStart + 1;
425
- const ourContentEnd = baseStart !== undefined ? baseStart : separatorIndex;
426
- const theirContentStart = separatorIndex + 1;
427
-
428
- const marker: GitConflictMarker = {
429
- ourStart,
430
- ourEnd: separatorIndex,
431
- theirStart: separatorIndex,
432
- theirEnd,
433
- ourContent: lines.slice(ourContentStart, ourContentEnd).join('\n'),
434
- theirContent: lines.slice(theirContentStart, theirEnd).join('\n')
435
- };
436
-
437
- if (baseStart !== undefined) {
438
- marker.baseStart = baseStart;
439
- marker.baseContent = lines.slice(baseStart + 1, separatorIndex).join('\n');
440
- }
441
-
442
- markers.push(marker);
443
- i = theirEnd + 1;
444
- continue;
437
+ const ourStart = i;
438
+ let baseStart: number | undefined;
439
+ let separatorIndex = -1;
440
+ let theirEnd = -1;
441
+ let restartAt = -1;
442
+
443
+ let j = i + 1;
444
+ while (j < lines.length) {
445
+ const line = lines[j];
446
+ if (MARKER_OURS.test(line)) {
447
+ // A second opener before this one closed means the first was never a
448
+ // real conflict. Drop it and re-scan from the opener we just found.
449
+ restartAt = j;
450
+ break;
445
451
  }
452
+ if (MARKER_BASE.test(line)) baseStart = j;
453
+ else if (MARKER_SEP.test(line)) separatorIndex = j;
454
+ else if (MARKER_THEIRS.test(line)) {
455
+ theirEnd = j;
456
+ break;
457
+ }
458
+ j++;
446
459
  }
447
- i++;
460
+
461
+ if (restartAt >= 0) {
462
+ i = restartAt;
463
+ continue;
464
+ }
465
+
466
+ if (separatorIndex < 0 || theirEnd < 0) {
467
+ i = ourStart + 1;
468
+ continue;
469
+ }
470
+
471
+ const ourContentEnd = baseStart !== undefined ? baseStart : separatorIndex;
472
+ const marker: GitConflictMarker = {
473
+ ourStart,
474
+ ourEnd: separatorIndex,
475
+ theirStart: separatorIndex,
476
+ theirEnd,
477
+ ourContent: lines.slice(ourStart + 1, ourContentEnd).join('\n'),
478
+ theirContent: lines.slice(separatorIndex + 1, theirEnd).join('\n')
479
+ };
480
+
481
+ if (baseStart !== undefined) {
482
+ marker.baseStart = baseStart;
483
+ marker.baseContent = lines.slice(baseStart + 1, separatorIndex).join('\n');
484
+ }
485
+
486
+ markers.push(marker);
487
+ i = theirEnd + 1;
448
488
  }
449
489
 
450
490
  return markers;
451
491
  }
492
+
493
+ /**
494
+ * Parse `git reflog --format=%H|||%h|||%gd|||%gs|||%cI`.
495
+ *
496
+ * `%gs` (the reflog subject) already carries both halves — "commit: fix thing",
497
+ * "rebase (finish): returning to refs/heads/main" — so we split on the first
498
+ * ": " to separate the action from the description.
499
+ */
500
+ export function parseReflog(output: string): GitReflogEntry[] {
501
+ const SEPARATOR = '|||';
502
+ const entries: GitReflogEntry[] = [];
503
+
504
+ for (const line of output.split('\n')) {
505
+ if (!line.trim()) continue;
506
+ const parts = line.split(SEPARATOR);
507
+ if (parts.length < 5) continue;
508
+ const [hash, hashShort, selector, gs, date] = parts;
509
+ const colon = gs.indexOf(': ');
510
+ entries.push({
511
+ hash,
512
+ hashShort,
513
+ selector,
514
+ action: colon >= 0 ? gs.slice(0, colon) : gs,
515
+ subject: colon >= 0 ? gs.slice(colon + 2) : '',
516
+ date
517
+ });
518
+ }
519
+
520
+ return entries;
521
+ }
522
+
523
+ /**
524
+ * Parse `git ls-files -u -z`: one row per unmerged *stage* (1 = base, 2 = ours,
525
+ * 3 = theirs), so a path shows up two or three times. Which stages are present
526
+ * is what distinguishes a both-modified conflict from a delete/modify one, and
527
+ * unlike `git status` this never omits a path whose working-tree file is gone.
528
+ */
529
+ export function parseUnmergedStages(output: string): Map<string, Set<number>> {
530
+ const stages = new Map<string, Set<number>>();
531
+
532
+ for (const row of output.split('\0')) {
533
+ if (!row.trim()) continue;
534
+ // "<mode> <sha> <stage>\t<path>"
535
+ const tab = row.indexOf('\t');
536
+ if (tab < 0) continue;
537
+ const meta = row.slice(0, tab).trim().split(/\s+/);
538
+ const path = row.slice(tab + 1);
539
+ const stage = Number(meta[2]);
540
+ if (!path || !Number.isInteger(stage)) continue;
541
+ const set = stages.get(path) ?? new Set<number>();
542
+ set.add(stage);
543
+ stages.set(path, set);
544
+ }
545
+
546
+ return stages;
547
+ }