@jini-ai/vibecoding 0.7.2 → 0.7.3-next.2

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/CHANGELOG.md CHANGED
@@ -105,7 +105,7 @@
105
105
  examples in comments and literal-text bodies (including `noscript`), and collapse reconstructed
106
106
  formatting clones to one unsafe address. The scan path keeps safe regions usable alongside
107
107
  malformed markup.
108
- - HTML5 recovery differs from Tovu's former lexical scanner: non-void self-closing syntax remains
108
+ - HTML5 recovery differs from the first host's former lexical scanner: non-void self-closing syntax remains
109
109
  open, an explicit later close permits editing, unclosed top-level elements use recovered advice
110
110
  boundaries, malformed tokens follow parse5 recovery, and unquoted/upper-case handle attributes
111
111
  are recognized.
@@ -127,7 +127,7 @@
127
127
 
128
128
  ### Patch Changes
129
129
 
130
- - Tovu clean-up release (2026-10-08): code Tovu moved into Jini, plus the Jini clean-up (see the commit log since 0.4.0).
130
+ - Host clean-up release (2026-10-08): code the first host moved into Jini, plus the Jini clean-up (see the commit log since 0.4.0).
131
131
 
132
132
  ## 0.4.0 — 2026-10-02
133
133
 
@@ -7,6 +7,111 @@ async function readCurrent(target, id) {
7
7
  return { content: "", existed: false };
8
8
  }
9
9
  }
10
+ function pushEntry({ undoStack, redoStack, limit }, entry) {
11
+ undoStack.push(entry);
12
+ while (undoStack.length > limit)
13
+ undoStack.shift();
14
+ redoStack.length = 0;
15
+ }
16
+ /**
17
+ * Replay part contents directly, deliberately skipping `validate` — see this module's doc for
18
+ * why an intermediate state of a multi-part rewind must not be judged.
19
+ */
20
+ async function replayChanges({ target, changes, side }) {
21
+ for (const change of changes) {
22
+ await target.replacePart({ id: change.id, content: side === "before" ? change.before : change.after });
23
+ }
24
+ }
25
+ /** A view of the target whose writes are recorded into `changes`. */
26
+ function recordingTarget({ target, changes }) {
27
+ return {
28
+ listParts: () => target.listParts(),
29
+ readPart: (args) => target.readPart(args),
30
+ snapshot: () => target.snapshot(),
31
+ restore: (args) => target.restore(args),
32
+ validate: (candidate) => target.validate(candidate),
33
+ async replacePart({ id, content }) {
34
+ const current = await readCurrent(target, id);
35
+ await target.replacePart({ id, content });
36
+ // A write that changed nothing is not a step a person can meaningfully undo.
37
+ if (current.existed && current.content === content)
38
+ return;
39
+ changes.push({
40
+ id,
41
+ before: current.content,
42
+ after: content,
43
+ existedBefore: current.existed,
44
+ });
45
+ },
46
+ };
47
+ }
48
+ async function runTransaction({ state, work, label }) {
49
+ if (state.transactionOpen) {
50
+ throw new Error("a transaction is already open — overlapping transactions would interleave their changes into one another's entries");
51
+ }
52
+ state.transactionOpen = true;
53
+ const changes = [];
54
+ try {
55
+ return await work(recordingTarget({ target: state.target, changes }));
56
+ }
57
+ finally {
58
+ state.transactionOpen = false;
59
+ // Committed even when `work` threw: partial writes already reached the artifact, and the
60
+ // caller needs them to be undoable.
61
+ if (changes.length > 0)
62
+ pushEntry(state, label === undefined ? { changes } : { label, changes });
63
+ }
64
+ }
65
+ async function undoLast(state) {
66
+ const { undoStack, redoStack } = state;
67
+ // Peeked, not popped: a `replacePart` that throws partway through leaves the earlier parts
68
+ // already rewound, and popping first would strand that half-applied entry in NEITHER stack —
69
+ // the artifact changed and the history API could no longer reach it. Same principle decision
70
+ // 3 in this module's doc states for `transaction`. Moving between stacks only after a clean
71
+ // replay means a failed undo is simply retryable: replaying `before` again rewrites the
72
+ // parts that already landed with the content they already hold (a no-op) and retries the one
73
+ // that failed.
74
+ const entry = undoStack[undoStack.length - 1];
75
+ if (!entry)
76
+ return null;
77
+ await replayChanges({ target: state.target, changes: [...entry.changes].reverse(), side: "before" });
78
+ undoStack.pop();
79
+ redoStack.push(entry);
80
+ return entry;
81
+ }
82
+ async function redoLast(state) {
83
+ const { undoStack, redoStack } = state;
84
+ // Peeked for the same reason as `undo` above, in the other direction.
85
+ const entry = redoStack[redoStack.length - 1];
86
+ if (!entry)
87
+ return null;
88
+ await replayChanges({ target: state.target, changes: entry.changes, side: "after" });
89
+ redoStack.pop();
90
+ undoStack.push(entry);
91
+ return entry;
92
+ }
93
+ async function restoreSnapshot(state, snapshot) {
94
+ const { target } = state;
95
+ const changes = [];
96
+ for (const [id, after] of Object.entries(snapshot.parts)) {
97
+ const current = await readCurrent(target, id);
98
+ if (current.existed && current.content === after)
99
+ continue;
100
+ changes.push({ id, before: current.content, after, existedBefore: current.existed });
101
+ }
102
+ if (changes.length === 0)
103
+ return null;
104
+ // Recorded BEFORE the replay, not after. A restore that throws on its second part has still
105
+ // changed the first, and pushing afterwards left those writes with no undo record at all —
106
+ // the destructive-restore failure mode decision 2 in this module's doc exists to prevent,
107
+ // reached by a different route. The `before` sides were captured above and are correct
108
+ // regardless of how far the replay got: undoing a partially-applied restore rewrites every
109
+ // listed part with the content it had before, which is a no-op for the ones never reached.
110
+ const entry = { label: `restore ${snapshot.id}`, changes };
111
+ pushEntry(state, entry);
112
+ await replayChanges({ target, changes, side: "after" });
113
+ return entry;
114
+ }
10
115
  /**
11
116
  * Create an undo/redo stack over one target.
12
117
  *
@@ -16,112 +121,15 @@ async function readCurrent(target, id) {
16
121
  * @complexity 4
17
122
  */
18
123
  export function createEditHistory({ target }, options = {}) {
19
- const limit = options.limit ?? 50;
20
- const undoStack = [];
21
- const redoStack = [];
22
- let transactionOpen = false;
23
- function push(entry) {
24
- undoStack.push(entry);
25
- while (undoStack.length > limit)
26
- undoStack.shift();
27
- redoStack.length = 0;
28
- }
29
- /**
30
- * Replay part contents directly, deliberately skipping `validate` — see this module's doc for
31
- * why an intermediate state of a multi-part rewind must not be judged.
32
- */
33
- async function replay(changes, side) {
34
- for (const change of changes) {
35
- await target.replacePart({ id: change.id, content: side === "before" ? change.before : change.after });
36
- }
37
- }
124
+ const state = { target, limit: options.limit ?? 50, undoStack: [], redoStack: [], transactionOpen: false };
125
+ const { undoStack, redoStack } = state;
38
126
  return {
39
- async transaction({ work }, { label } = {}) {
40
- if (transactionOpen) {
41
- throw new Error("a transaction is already open — overlapping transactions would interleave their changes into one another's entries");
42
- }
43
- transactionOpen = true;
44
- const changes = [];
45
- const recording = {
46
- listParts: () => target.listParts(),
47
- readPart: (args) => target.readPart(args),
48
- snapshot: () => target.snapshot(),
49
- restore: (args) => target.restore(args),
50
- validate: (candidate) => target.validate(candidate),
51
- async replacePart({ id, content }) {
52
- const current = await readCurrent(target, id);
53
- await target.replacePart({ id, content });
54
- // A write that changed nothing is not a step a person can meaningfully undo.
55
- if (current.existed && current.content === content)
56
- return;
57
- changes.push({
58
- id,
59
- before: current.content,
60
- after: content,
61
- existedBefore: current.existed,
62
- });
63
- },
64
- };
65
- try {
66
- return await work(recording);
67
- }
68
- finally {
69
- transactionOpen = false;
70
- // Committed even when `work` threw: partial writes already reached the artifact, and the
71
- // caller needs them to be undoable.
72
- if (changes.length > 0)
73
- push(label === undefined ? { changes } : { label, changes });
74
- }
75
- },
127
+ transaction: ({ work }, { label } = {}) => runTransaction({ state, work, label }),
76
128
  canUndo: () => undoStack.length > 0,
77
129
  canRedo: () => redoStack.length > 0,
78
- async undo() {
79
- // Peeked, not popped: a `replacePart` that throws partway through leaves the earlier parts
80
- // already rewound, and popping first would strand that half-applied entry in NEITHER stack —
81
- // the artifact changed and the history API could no longer reach it. Same principle decision
82
- // 3 in this module's doc states for `transaction`. Moving between stacks only after a clean
83
- // replay means a failed undo is simply retryable: replaying `before` again rewrites the
84
- // parts that already landed with the content they already hold (a no-op) and retries the one
85
- // that failed.
86
- const entry = undoStack[undoStack.length - 1];
87
- if (!entry)
88
- return null;
89
- await replay([...entry.changes].reverse(), "before");
90
- undoStack.pop();
91
- redoStack.push(entry);
92
- return entry;
93
- },
94
- async redo() {
95
- // Peeked for the same reason as `undo` above, in the other direction.
96
- const entry = redoStack[redoStack.length - 1];
97
- if (!entry)
98
- return null;
99
- await replay(entry.changes, "after");
100
- redoStack.pop();
101
- undoStack.push(entry);
102
- return entry;
103
- },
104
- async restore({ snapshot }) {
105
- const changes = [];
106
- for (const [id, after] of Object.entries(snapshot.parts)) {
107
- const current = await readCurrent(target, id);
108
- if (current.existed && current.content === after)
109
- continue;
110
- changes.push({ id, before: current.content, after, existedBefore: current.existed });
111
- }
112
- if (changes.length === 0)
113
- return null;
114
- // Recorded BEFORE the replay, not after. A restore that throws on its second part has still
115
- // changed the first, and pushing afterwards left those writes with no undo record at all —
116
- // the destructive-restore failure mode decision 2 in this module's doc exists to prevent,
117
- // reached by a different route. The `before` sides were captured above and are correct
118
- // regardless of how far the replay got: undoing a partially-applied restore rewrites every
119
- // listed part with the content it had before, which is a no-op for the ones never reached.
120
- const entry = { label: `restore ${snapshot.id}`, changes };
121
- push(entry);
122
- await replay(changes, "after");
123
- return entry;
124
- },
130
+ undo: () => undoLast(state),
131
+ redo: () => redoLast(state),
132
+ restore: ({ snapshot }) => restoreSnapshot(state, snapshot),
125
133
  entries: () => [...undoStack],
126
134
  retainedEntries: () => [...undoStack, ...redoStack],
127
135
  clear() {
@@ -17,7 +17,7 @@ export function createVibecodingSession({ target }, options = {}) {
17
17
  const applyTurn = options.applyTurn;
18
18
  const listeners = new Set();
19
19
  const partContent = new Map();
20
- let current = {
20
+ const current = {
21
21
  status: 'idle',
22
22
  parts: [],
23
23
  partContent,
@@ -25,154 +25,186 @@ export function createVibecodingSession({ target }, options = {}) {
25
25
  canRedo: history.canRedo(),
26
26
  lastError: READY_ERROR,
27
27
  };
28
- /** Replaces `current` with a fresh object carrying `patch`, then notifies subscribers. A fresh
29
- * `partContent` Map reference is handed out only when the map's contents actually changed
30
- * (callers pass a new Map in `patch` for that case); reusing the same Map reference otherwise
31
- * is what keeps an unrelated status change (e.g. `'loading'` -> `'ready'`) from invalidating a
32
- * component's memoized read of `partContent`. */
33
- function commit(patch) {
34
- current = { ...current, ...patch };
35
- for (const listener of listeners)
36
- listener();
28
+ const context = { target, history, applyTurn, listeners, partContent, current };
29
+ return {
30
+ target, history,
31
+ getSnapshot: () => context.current,
32
+ subscribe({ listener }) {
33
+ listeners.add(listener);
34
+ return () => listeners.delete(listener);
35
+ },
36
+ refresh: () => refresh(context),
37
+ readPart: input => readPart(context, input),
38
+ applyEdits: (input, options = {}) => applyEdits(context, input, options),
39
+ undo: () => undo(context),
40
+ redo: () => redo(context),
41
+ takeSnapshot: () => run(context, async () => ({ result: await target.snapshot(), patch: {} })),
42
+ restoreSnapshot: input => restoreSnapshot(context, input),
43
+ };
44
+ }
45
+ /** Replaces `current` with a fresh object carrying `patch`, then notifies subscribers. A fresh
46
+ * `partContent` Map reference is handed out only when the map's contents actually changed
47
+ * (callers pass a new Map in `patch` for that case); reusing the same Map reference otherwise
48
+ * is what keeps an unrelated status change (e.g. `'loading'` -> `'ready'`) from invalidating a
49
+ * component's memoized read of `partContent`. */
50
+ function commit(context, patch) {
51
+ const { listeners } = context;
52
+ context.current = { ...context.current, ...patch };
53
+ for (const listener of listeners)
54
+ listener();
55
+ }
56
+ /**
57
+ * Runs `work`, tagging the session `'loading'` -> `'ready'`/`'error'` and always returning
58
+ * control to the caller — a rejection is recorded as `lastError` AND rethrown, so a component
59
+ * can render `lastError` passively while a tool handler that needs to fail loudly still can.
60
+ *
61
+ * `work` returns its data `patch` alongside its `result` rather than calling `commit` itself, so
62
+ * the success path here can fold that patch into the SAME commit as the `'ready'` status
63
+ * transition — one notification per operation instead of two, which matters to a
64
+ * `useSyncExternalStore` subscriber re-rendering on every commit.
65
+ */
66
+ async function run(context, work) {
67
+ const { history, applyTurn, partContent } = context;
68
+ commit(context, { status: 'loading' });
69
+ try {
70
+ const { result, patch } = await work();
71
+ commit(context, { ...patch, status: 'ready', lastError: READY_ERROR });
72
+ return result;
37
73
  }
38
- /**
39
- * Runs `work`, tagging the session `'loading'` -> `'ready'`/`'error'` and always returning
40
- * control to the caller — a rejection is recorded as `lastError` AND rethrown, so a component
41
- * can render `lastError` passively while a tool handler that needs to fail loudly still can.
42
- *
43
- * `work` returns its data `patch` alongside its `result` rather than calling `commit` itself, so
44
- * the success path here can fold that patch into the SAME commit as the `'ready'` status
45
- * transition — one notification per operation instead of two, which matters to a
46
- * `useSyncExternalStore` subscriber re-rendering on every commit.
47
- */
48
- async function run(work) {
49
- commit({ status: 'loading' });
50
- try {
51
- const { result, patch } = await work();
52
- commit({ ...patch, status: 'ready', lastError: READY_ERROR });
53
- return result;
54
- }
55
- catch (thrown) {
56
- const message = thrown instanceof Error ? thrown.message : String(thrown);
57
- if (applyTurn)
58
- partContent.clear();
59
- commit({ status: 'error', lastError: message, partContent: new Map(partContent), canUndo: history.canUndo(), canRedo: history.canRedo() });
60
- throw thrown;
61
- }
74
+ catch (thrown) {
75
+ const message = thrown instanceof Error ? thrown.message : String(thrown);
76
+ if (applyTurn)
77
+ partContent.clear();
78
+ commit(context, { status: 'error', lastError: message, partContent: new Map(partContent), canUndo: history.canUndo(), canRedo: history.canRedo() });
79
+ throw thrown;
62
80
  }
63
- /** Mirrors a replayed change in the cache. Undoing creation keeps empty content because the
64
- * target's upsert port has no delete operation; see `./history.ts`. */
65
- function cacheChange(change, side) {
66
- partContent.set(change.id, side === 'after' ? change.after : change.before);
81
+ }
82
+ /** Mirrors a replayed change in the cache. Undoing creation keeps empty content because the
83
+ * target's upsert port has no delete operation; see `./history.ts`. */
84
+ function cacheChange(context, change, side) {
85
+ const { partContent } = context;
86
+ partContent.set(change.id, side === 'after' ? change.after : change.before);
87
+ }
88
+ /** Mirrors a recorded snapshot restore in the cache and re-reads the part list it may have grown. */
89
+ async function restoredPatch(context, entry) {
90
+ const { target, history, applyTurn, partContent } = context;
91
+ if (applyTurn)
92
+ partContent.clear();
93
+ else
94
+ for (const change of entry.changes)
95
+ cacheChange(context, change, 'after');
96
+ const parts = await target.listParts();
97
+ return { parts, partContent: new Map(partContent), canUndo: history.canUndo(), canRedo: history.canRedo() };
98
+ }
99
+ function refresh(context) {
100
+ const { target, history, applyTurn, partContent } = context;
101
+ return run(context, async () => {
102
+ const parts = await target.listParts();
103
+ if (applyTurn)
104
+ partContent.clear();
105
+ const known = new Set(parts.map((p) => p.id));
106
+ // Drop cached content for parts the host no longer lists — stale content for an
107
+ // unaddressable id would otherwise linger forever with nothing to invalidate it.
108
+ for (const id of partContent.keys())
109
+ if (!known.has(id))
110
+ partContent.delete(id);
111
+ return {
112
+ result: undefined,
113
+ patch: { parts, partContent: new Map(partContent), canUndo: history.canUndo(), canRedo: history.canRedo() },
114
+ };
115
+ });
116
+ }
117
+ function readPart(context, { id }) {
118
+ const { target, history, applyTurn, partContent } = context;
119
+ return run(context, async () => {
120
+ const cached = applyTurn ? undefined : partContent.get(id);
121
+ if (cached !== undefined)
122
+ return { result: cached, patch: {} };
123
+ if (applyTurn)
124
+ partContent.clear();
125
+ const content = await target.readPart({ id });
126
+ partContent.set(id, content);
127
+ return { result: content, patch: { partContent: new Map(partContent), canUndo: history.canUndo(), canRedo: history.canRedo() } };
128
+ });
129
+ }
130
+ function applyEdits(context, { edits }, options = {}) {
131
+ const { target, history, applyTurn, partContent } = context;
132
+ return run(context, async () => {
133
+ const outcomes = await (applyTurn
134
+ ? applyTurn({ edits }, options)
135
+ : history.transaction({ work: (recording) => applyEditsToTarget({ target: recording, edits }) }, options));
136
+ if (applyTurn)
137
+ partContent.clear();
138
+ cacheAppliedEdits(context, edits, outcomes);
139
+ const parts = await target.listParts();
140
+ return {
141
+ result: { outcomes, corrections: correctionsFor({ outcomes }) },
142
+ patch: {
143
+ parts,
144
+ partContent: new Map(partContent),
145
+ canUndo: history.canUndo(),
146
+ canRedo: history.canRedo(),
147
+ },
148
+ };
149
+ });
150
+ }
151
+ function cacheAppliedEdits(context, edits, outcomes) {
152
+ const { applyTurn, partContent } = context;
153
+ // Outcomes are aligned with proposals, including repeated ids. Matching only by id
154
+ // would cache the first proposal instead of the last successful write for that part.
155
+ // This pass is O(edits.length), with no additional reads through the target port.
156
+ for (const [index, outcome] of outcomes.entries()) {
157
+ if (outcome.status !== 'applied')
158
+ continue;
159
+ const edit = edits[index];
160
+ if (edit && !applyTurn)
161
+ partContent.set(edit.id, edit.content);
67
162
  }
68
- /** Mirrors a recorded snapshot restore in the cache and re-reads the part list it may have grown. */
69
- async function restoredPatch(entry) {
163
+ }
164
+ function undo(context) {
165
+ const { target, history, applyTurn, partContent } = context;
166
+ return run(context, async () => {
167
+ const entry = await history.undo();
168
+ if (!entry)
169
+ return { result: entry, patch: {} };
170
+ // Undo replays in reverse order. Repeated ids must leave the earliest before value
171
+ // cached, matching what history wrote to the target.
172
+ if (applyTurn)
173
+ partContent.clear();
174
+ else
175
+ for (const change of [...entry.changes].reverse())
176
+ cacheChange(context, change, 'before');
177
+ const parts = applyTurn ? await target.listParts() : context.current.parts;
178
+ return {
179
+ result: entry,
180
+ patch: { parts, partContent: new Map(partContent), canUndo: history.canUndo(), canRedo: history.canRedo() },
181
+ };
182
+ });
183
+ }
184
+ function redo(context) {
185
+ const { target, history, applyTurn, partContent } = context;
186
+ return run(context, async () => {
187
+ const entry = await history.redo();
188
+ if (!entry)
189
+ return { result: entry, patch: {} };
70
190
  if (applyTurn)
71
191
  partContent.clear();
72
192
  else
73
193
  for (const change of entry.changes)
74
- cacheChange(change, 'after');
75
- const parts = await target.listParts();
76
- return { parts, partContent: new Map(partContent), canUndo: history.canUndo(), canRedo: history.canRedo() };
77
- }
78
- return {
79
- target,
80
- history,
81
- getSnapshot: () => current,
82
- subscribe({ listener }) {
83
- listeners.add(listener);
84
- return () => listeners.delete(listener);
85
- },
86
- refresh: () => run(async () => {
87
- const parts = await target.listParts();
88
- if (applyTurn)
89
- partContent.clear();
90
- const known = new Set(parts.map((p) => p.id));
91
- // Drop cached content for parts the host no longer lists — stale content for an
92
- // unaddressable id would otherwise linger forever with nothing to invalidate it.
93
- for (const id of partContent.keys())
94
- if (!known.has(id))
95
- partContent.delete(id);
96
- return {
97
- result: undefined,
98
- patch: { parts, partContent: new Map(partContent), canUndo: history.canUndo(), canRedo: history.canRedo() },
99
- };
100
- }),
101
- readPart: ({ id }) => run(async () => {
102
- const cached = applyTurn ? undefined : partContent.get(id);
103
- if (cached !== undefined)
104
- return { result: cached, patch: {} };
105
- if (applyTurn)
106
- partContent.clear();
107
- const content = await target.readPart({ id });
108
- partContent.set(id, content);
109
- return { result: content, patch: { partContent: new Map(partContent), canUndo: history.canUndo(), canRedo: history.canRedo() } };
110
- }),
111
- applyEdits: ({ edits }, options = {}) => run(async () => {
112
- const outcomes = await (applyTurn
113
- ? applyTurn({ edits }, options)
114
- : history.transaction({ work: (recording) => applyEditsToTarget({ target: recording, edits }) }, options));
115
- if (applyTurn)
116
- partContent.clear();
117
- // Outcomes are aligned with proposals, including repeated ids. Matching only by id
118
- // would cache the first proposal instead of the last successful write for that part.
119
- // This pass is O(edits.length), with no additional reads through the target port.
120
- for (const [index, outcome] of outcomes.entries()) {
121
- if (outcome.status !== 'applied')
122
- continue;
123
- const edit = edits[index];
124
- if (edit && !applyTurn)
125
- partContent.set(edit.id, edit.content);
126
- }
127
- const parts = await target.listParts();
128
- return {
129
- result: { outcomes, corrections: correctionsFor({ outcomes }) },
130
- patch: {
131
- parts,
132
- partContent: new Map(partContent),
133
- canUndo: history.canUndo(),
134
- canRedo: history.canRedo(),
135
- },
136
- };
137
- }),
138
- undo: () => run(async () => {
139
- const entry = await history.undo();
140
- if (!entry)
141
- return { result: entry, patch: {} };
142
- // Undo replays in reverse order. Repeated ids must leave the earliest before value
143
- // cached, matching what history wrote to the target.
144
- if (applyTurn)
145
- partContent.clear();
146
- else
147
- for (const change of [...entry.changes].reverse())
148
- cacheChange(change, 'before');
149
- const parts = applyTurn ? await target.listParts() : current.parts;
150
- return {
151
- result: entry,
152
- patch: { parts, partContent: new Map(partContent), canUndo: history.canUndo(), canRedo: history.canRedo() },
153
- };
154
- }),
155
- redo: () => run(async () => {
156
- const entry = await history.redo();
157
- if (!entry)
158
- return { result: entry, patch: {} };
159
- if (applyTurn)
160
- partContent.clear();
161
- else
162
- for (const change of entry.changes)
163
- cacheChange(change, 'after');
164
- const parts = applyTurn ? await target.listParts() : current.parts;
165
- return {
166
- result: entry,
167
- patch: { parts, partContent: new Map(partContent), canUndo: history.canUndo(), canRedo: history.canRedo() },
168
- };
169
- }),
170
- takeSnapshot: () => run(async () => ({ result: await target.snapshot(), patch: {} })),
171
- restoreSnapshot: ({ snapshot }) => run(async () => {
172
- const entry = await history.restore({ snapshot });
173
- // A restore that already matched records no entry and changes nothing to mirror.
174
- return { result: entry, patch: entry ? await restoredPatch(entry) : {} };
175
- }),
176
- };
194
+ cacheChange(context, change, 'after');
195
+ const parts = applyTurn ? await target.listParts() : context.current.parts;
196
+ return {
197
+ result: entry,
198
+ patch: { parts, partContent: new Map(partContent), canUndo: history.canUndo(), canRedo: history.canRedo() },
199
+ };
200
+ });
201
+ }
202
+ function restoreSnapshot(context, { snapshot }) {
203
+ const { history } = context;
204
+ return run(context, async () => {
205
+ const entry = await history.restore({ snapshot });
206
+ // A restore that already matched records no entry and changes nothing to mirror.
207
+ return { result: entry, patch: entry ? await restoredPatch(context, entry) : {} };
208
+ });
177
209
  }
178
210
  //# sourceMappingURL=session.js.map
@@ -15,7 +15,7 @@ export declare function scanHtmlRegions({ html: html_ }: {
15
15
  };
16
16
  /**
17
17
  * Build the parse5-backed `HtmlRegionParser`. Stateless — a single instance is safe to share as a
18
- * module-level singleton across every call, per `./regions.js`'s injected-port contract.
18
+ * module-level singleton across every call, per `packages/vibecoding/src/html/regions.ts`'s injected-port contract.
19
19
  *
20
20
  * @returns a parser ready to hand to `createHtmlRegionTarget`, with `checkWellFormed` always
21
21
  * present even though the generic parser port allows implementations to omit it.
@@ -274,7 +274,7 @@ function locationProblem(scan) {
274
274
  }
275
275
  /**
276
276
  * Build the parse5-backed `HtmlRegionParser`. Stateless — a single instance is safe to share as a
277
- * module-level singleton across every call, per `./regions.js`'s injected-port contract.
277
+ * module-level singleton across every call, per `packages/vibecoding/src/html/regions.ts`'s injected-port contract.
278
278
  *
279
279
  * @returns a parser ready to hand to `createHtmlRegionTarget`, with `checkWellFormed` always
280
280
  * present even though the generic parser port allows implementations to omit it.