@devosurf/vynt 0.1.4 → 0.1.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devosurf/vynt",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "bin",
package/src/bridge.ts CHANGED
@@ -383,14 +383,9 @@ async function applySelectionsWithActiveRollback(
383
383
  throw error
384
384
  }
385
385
 
386
- const allowDirtyFiles = collectActiveSelectionChangedFiles(state)
387
- if (allowDirtyFiles.length === 0) {
388
- throw new Error(
389
- `${message}. No active changedFiles available for safe auto-rollback; run rollback first or register variants with changed files.`,
390
- )
391
- }
392
-
393
- await rollbackWorkspaceToSnapshot(projectRoot, undefined, { allowDirtyFiles })
386
+ await rollbackWorkspaceToSnapshot(projectRoot, undefined, {
387
+ allowDirtyFiles: collectActiveSelectionChangedFiles(state),
388
+ })
394
389
  return applySelectionsToWorkspace(projectRoot, state.baseRef, selections)
395
390
  }
396
391
  }
package/src/switch.ts CHANGED
@@ -24,10 +24,6 @@ export interface StoredSwitchSnapshot extends SwitchSnapshot {
24
24
  filePath: string
25
25
  }
26
26
 
27
- export interface RollbackWorkspaceOptions {
28
- allowDirtyFiles?: string[]
29
- }
30
-
31
27
  async function runGit(projectRoot: string, args: string[]): Promise<string> {
32
28
  try {
33
29
  const { stdout } = await execFileAsync("git", args, {
@@ -94,18 +90,65 @@ async function listDirtyTrackedFiles(projectRoot: string): Promise<string[]> {
94
90
  return [...new Set(files)]
95
91
  }
96
92
 
97
- async function ensureRollbackSafety(projectRoot: string, allowDirtyFiles: string[]): Promise<void> {
93
+ async function listFilesFromPatch(patchFile: string): Promise<string[]> {
94
+ const raw = await readFile(patchFile, "utf8")
95
+ const matches = raw.matchAll(/^diff --git a\/(.+?) b\/(.+)$/gm)
96
+ const files = new Set<string>()
97
+
98
+ for (const match of matches) {
99
+ const fromPath = normalizeRepoPath(match[1] ?? "")
100
+ const toPath = normalizeRepoPath(match[2] ?? "")
101
+
102
+ if (toPath.length > 0 && toPath !== "dev/null") {
103
+ files.add(toPath)
104
+ continue
105
+ }
106
+
107
+ if (fromPath.length > 0 && fromPath !== "dev/null") {
108
+ files.add(fromPath)
109
+ }
110
+ }
111
+
112
+ return [...files]
113
+ }
114
+
115
+ async function collectRollbackTargetFiles(snapshot: StoredSwitchSnapshot): Promise<string[]> {
116
+ const fromMetadata = snapshot.selections
117
+ .flatMap((selection) => selection.changedFiles ?? [])
118
+ .map(normalizeRepoPath)
119
+ .filter((file) => file.length > 0)
120
+
121
+ const fromPatchFiles = await Promise.all(snapshot.selections.map((selection) => listFilesFromPatch(selection.patchFile)))
122
+ const flattenedPatchFiles = fromPatchFiles.flat().map(normalizeRepoPath).filter((file) => file.length > 0)
123
+
124
+ return [...new Set([...fromMetadata, ...flattenedPatchFiles])]
125
+ }
126
+
127
+ async function ensureRollbackSafety(
128
+ projectRoot: string,
129
+ rollbackTargetFiles: string[],
130
+ allowDirtyFiles: string[],
131
+ ): Promise<void> {
98
132
  const dirtyFiles = await listDirtyTrackedFiles(projectRoot)
99
133
  if (dirtyFiles.length === 0) return
100
134
 
101
- const allowed = new Set(allowDirtyFiles.map(normalizeRepoPath))
102
- const disallowed = dirtyFiles.filter((file) => !allowed.has(normalizeRepoPath(file)))
135
+ const normalizedTargets = new Set(rollbackTargetFiles.map(normalizeRepoPath).filter((file) => file.length > 0))
136
+ if (normalizedTargets.size === 0) {
137
+ await ensureCleanWorkspace(projectRoot)
138
+ return
139
+ }
140
+
141
+ const overlapping = dirtyFiles.filter((file) => normalizedTargets.has(normalizeRepoPath(file)))
142
+ if (overlapping.length === 0) return
143
+
144
+ const allowed = new Set(allowDirtyFiles.map(normalizeRepoPath).filter((file) => file.length > 0))
145
+ const disallowed = overlapping.filter((file) => !allowed.has(normalizeRepoPath(file)))
103
146
  if (disallowed.length === 0) return
104
147
 
105
148
  const listed = disallowed.slice(0, 5).join(", ")
106
149
  const remainder = disallowed.length > 5 ? `, +${disallowed.length - 5} more` : ""
107
150
  throw new Error(
108
- `Rollback would overwrite uncommitted changes outside active variant files: ${listed}${remainder}. Commit or stash these changes before rollback.`,
151
+ `Rollback would overwrite uncommitted changes in files touched by the snapshot: ${listed}${remainder}. Commit or stash these changes before rollback.`,
109
152
  )
110
153
  }
111
154
 
@@ -159,6 +202,9 @@ function parseSnapshot(content: unknown, filePath: string): StoredSwitchSnapshot
159
202
  objectiveId: item.objectiveId,
160
203
  variantId: item.variantId,
161
204
  patchFile: item.patchFile,
205
+ changedFiles: Array.isArray(item.changedFiles)
206
+ ? item.changedFiles.filter((file): file is string => typeof file === "string")
207
+ : undefined,
162
208
  }
163
209
  })
164
210
 
@@ -329,10 +375,14 @@ export async function rollbackWorkspaceToSnapshot(
329
375
  throw new Error("No snapshots found. Run apply/profile apply first.")
330
376
  }
331
377
 
332
- await ensureRollbackSafety(projectRoot, options.allowDirtyFiles ?? [])
378
+ const rollbackTargetFiles = await collectRollbackTargetFiles(snapshot)
379
+ await ensureRollbackSafety(projectRoot, rollbackTargetFiles, options.allowDirtyFiles ?? [])
333
380
 
334
381
  await verifyBaseRef(projectRoot, snapshot.head)
335
- await restoreWorkspaceToBase(projectRoot, snapshot.head)
382
+ await restoreWorkspaceToBase(projectRoot, snapshot.head, rollbackTargetFiles)
336
383
 
337
384
  return { snapshot }
338
385
  }
386
+ export interface RollbackWorkspaceOptions {
387
+ allowDirtyFiles?: string[]
388
+ }
@@ -27,6 +27,7 @@
27
27
  hoveredObjectiveElement: null,
28
28
  statusText: "Connecting...",
29
29
  position: null,
30
+ lastExpandedWidth: null,
30
31
  };
31
32
 
32
33
  let eventSource = null;
@@ -39,7 +40,7 @@
39
40
  next: `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 18 15 12 9 6"></polyline></svg>`,
40
41
  apply: `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"></polyline></svg>`,
41
42
  collapse: `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>`,
42
- vynt: `<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/></svg>`
43
+ vynt: `<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><path d="M4 6.5L10.5 18L14 11.5L20 18"/><path d="M9.6 6.5H20"/></svg>`
43
44
  };
44
45
 
45
46
  const css = `
@@ -696,6 +697,44 @@
696
697
  root.style.bottom = "auto";
697
698
  }
698
699
 
700
+ function getCollapsedWidth() {
701
+ const cssValue = parseFloat(getComputedStyle(shell).getPropertyValue("--vynt-height"));
702
+ return Number.isFinite(cssValue) && cssValue > 0 ? cssValue : 48;
703
+ }
704
+
705
+ function adjustPositionForCollapse(nextCollapsed) {
706
+ if (!state.position) return;
707
+
708
+ const currentWidth = shell.getBoundingClientRect().width;
709
+ if (!(currentWidth > 0)) return;
710
+
711
+ if (nextCollapsed) {
712
+ state.lastExpandedWidth = currentWidth;
713
+ const targetCollapsedWidth = getCollapsedWidth();
714
+ const delta = Math.max(0, currentWidth - targetCollapsedWidth);
715
+ if (delta > 0) {
716
+ state.position = {
717
+ x: state.position.x + delta,
718
+ y: state.position.y,
719
+ };
720
+ }
721
+ } else {
722
+ const targetExpandedWidth =
723
+ typeof state.lastExpandedWidth === "number" && state.lastExpandedWidth > 0
724
+ ? state.lastExpandedWidth
725
+ : currentWidth;
726
+ const delta = Math.max(0, targetExpandedWidth - currentWidth);
727
+ if (delta > 0) {
728
+ state.position = {
729
+ x: state.position.x - delta,
730
+ y: state.position.y,
731
+ };
732
+ }
733
+ }
734
+
735
+ state.position = constrainPosition(state.position);
736
+ }
737
+
699
738
  function persistPosition() {
700
739
  if (!state.position) return;
701
740
  try {
@@ -796,6 +835,13 @@
796
835
  }
797
836
 
798
837
  renderObjectiveOverlay();
838
+
839
+ if (hasOptions && !state.collapsed) {
840
+ const expandedWidth = shell.getBoundingClientRect().width;
841
+ if (expandedWidth > 0) {
842
+ state.lastExpandedWidth = expandedWidth;
843
+ }
844
+ }
799
845
  }
800
846
 
801
847
  async function api(path, init) {
@@ -1013,7 +1059,9 @@
1013
1059
  }, 300);
1014
1060
  } else {
1015
1061
  if (state.collapsed && isLogoBtn) {
1062
+ adjustPositionForCollapse(false);
1016
1063
  state.collapsed = false;
1064
+ persistPosition();
1017
1065
  render();
1018
1066
  }
1019
1067
  }
@@ -1049,7 +1097,9 @@
1049
1097
 
1050
1098
  collapseBtn.addEventListener("click", (event) => {
1051
1099
  event.stopPropagation();
1100
+ adjustPositionForCollapse(true);
1052
1101
  state.collapsed = true;
1102
+ persistPosition();
1053
1103
  render();
1054
1104
  });
1055
1105