@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 +2 -2
- package/dist/core/history.js +111 -103
- package/dist/core/session.js +175 -143
- package/dist/html/node/parse5-region-parser.d.ts +1 -1
- package/dist/html/node/parse5-region-parser.js +1 -1
- package/dist/html/regions.js +67 -64
- package/dist/node/project.js +191 -166
- package/dist/node/store.d.ts +11 -11
- package/dist/node/store.js +290 -262
- package/dist/react/components/VibecodingWorkbench.d.ts +4 -1
- package/dist/react/components/VibecodingWorkbench.js +2 -2
- package/dist/tools.js +75 -60
- package/package.json +5 -5
package/dist/node/store.js
CHANGED
|
@@ -190,293 +190,321 @@ export function createProjectStore({ root, stateDir, paths, limits, filesystem }
|
|
|
190
190
|
const manifestPath = (hash) => { assertHash(hash); return resolve(stateDir, 'manifests', `${hash}.json`); };
|
|
191
191
|
const checkpoint = async (step) => { await options.checkpoint?.({ step }); };
|
|
192
192
|
const metadataLimit = limits.maxFiles * 1024 + 4096;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
const existing = await statIfPresent(manifestPath(revisionId));
|
|
238
|
-
if (existing)
|
|
239
|
-
await manifest({ revisionId });
|
|
240
|
-
else
|
|
241
|
-
await filesystem.writeJsonFileAtomicAsync({ filePath: manifestPath(revisionId), data: value }, { createParent: true });
|
|
242
|
-
await checkpoint('manifest');
|
|
243
|
-
return revisionId;
|
|
244
|
-
}
|
|
245
|
-
async function writeObject({ file, bytes }) {
|
|
246
|
-
const exists = await statIfPresent(objectPath(file.hash));
|
|
247
|
-
if (exists)
|
|
248
|
-
await object({ file });
|
|
249
|
-
else
|
|
250
|
-
await filesystem.writeFileAtomicAsync({ filePath: objectPath(file.hash), content: bytes }, { createParent: true });
|
|
193
|
+
const context = { root, stateDir, paths, limits, filesystem, currentPath, objectPath, manifestPath, checkpoint, metadataLimit };
|
|
194
|
+
return {
|
|
195
|
+
readCurrent: () => readCurrent(context), manifest: (input) => manifest(context, input),
|
|
196
|
+
object: (input) => object(context, input),
|
|
197
|
+
prepare: (input) => prepare(context, input),
|
|
198
|
+
scan: (input) => scan(context, input),
|
|
199
|
+
select: (input) => select(context, input),
|
|
200
|
+
collect: (input) => collect(context, input),
|
|
201
|
+
preflight: (input) => preflight(context, input),
|
|
202
|
+
observe: (input) => observe(context, input),
|
|
203
|
+
readWorkingFile: (input) => readWorkingFile(context, input),
|
|
204
|
+
locked: (run) => filesystem.withFileLock({ lockPath: resolve(stateDir, 'project.lock'), run }, { staleMs: Infinity, createParent: true }),
|
|
205
|
+
recover: () => recover(context),
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
async function readCurrent(context) {
|
|
209
|
+
const { root, currentPath, metadataLimit } = context;
|
|
210
|
+
const value = await readJson({ path: currentPath, maxBytes: metadataLimit }).catch(error => {
|
|
211
|
+
if (missing(error))
|
|
212
|
+
return undefined;
|
|
213
|
+
throw error;
|
|
214
|
+
});
|
|
215
|
+
return value === undefined ? null : checkCurrent({ value, root });
|
|
216
|
+
}
|
|
217
|
+
async function manifest(context, { revisionId }) {
|
|
218
|
+
const { paths, limits, manifestPath, metadataLimit } = context;
|
|
219
|
+
const value = await readJson({ path: manifestPath(revisionId), maxBytes: metadataLimit });
|
|
220
|
+
const result = checkManifest({ value, paths, limits });
|
|
221
|
+
if (digest({ bytes: JSON.stringify(result) }) !== revisionId)
|
|
222
|
+
corrupt('manifest digest mismatch');
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
async function object(context, { file }) {
|
|
226
|
+
const { objectPath } = context;
|
|
227
|
+
const handle = await fs.open(objectPath(file.hash), 'r').catch(cause => {
|
|
228
|
+
if (missing(cause))
|
|
229
|
+
throw new ProjectError({ code: 'CORRUPT', message: 'referenced object is missing', cause });
|
|
230
|
+
throw cause;
|
|
231
|
+
});
|
|
232
|
+
try {
|
|
233
|
+
const content = await readBounded({ handle, maxBytes: file.size });
|
|
234
|
+
if (content.byteLength !== file.size || digest({ bytes: content }) !== file.hash)
|
|
235
|
+
corrupt('object digest/size mismatch');
|
|
236
|
+
return content;
|
|
251
237
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
for (const file of files) {
|
|
255
|
-
const absolute = await regularPath({ paths, path: file.path });
|
|
256
|
-
const info = await fs.stat(absolute);
|
|
257
|
-
const bytes = await paths.reader.readBytes({ relativePath: file.path, maxBytes: limits.maxFileBytes });
|
|
258
|
-
const after = await fs.stat(absolute);
|
|
259
|
-
// A watcher may rewrite a file immediately after a rename. Do not cache its new timestamp
|
|
260
|
-
// against old object bytes: leaving it unobserved makes the next capture hash the drift.
|
|
261
|
-
if (sameFingerprint(info, after) && digest({ bytes }) === file.hash)
|
|
262
|
-
result[file.path] = fingerprint(info);
|
|
263
|
-
}
|
|
264
|
-
return result;
|
|
238
|
+
finally {
|
|
239
|
+
await handle.close();
|
|
265
240
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
const previous = new Map(base.files.map(file => [file.path, file]));
|
|
276
|
-
const files = new Map();
|
|
277
|
-
let total = 0;
|
|
278
|
-
const observed = Object.create(null);
|
|
279
|
-
for (const path of names) {
|
|
280
|
-
const scanned = await scanFile({ path, previous: previous.get(path), observed: current?.observed[path] });
|
|
281
|
-
total += scanned.bytes.byteLength;
|
|
282
|
-
if (total > limits.maxTreeBytes || files.size >= limits.maxFiles)
|
|
283
|
-
throw new ProjectError({ code: 'LIMIT', message: 'tree exceeds project limits' });
|
|
284
|
-
files.set(path, scanned.bytes);
|
|
285
|
-
observed[path] = scanned.observed;
|
|
286
|
-
}
|
|
287
|
-
return { files, observed };
|
|
241
|
+
}
|
|
242
|
+
/** Prepare every durable dependency before publishing a pending selection. */
|
|
243
|
+
async function prepare(context, { files }) {
|
|
244
|
+
const { paths, limits, filesystem, manifestPath, checkpoint } = context;
|
|
245
|
+
assertCandidatePaths({ paths: [...files.keys()] });
|
|
246
|
+
const entries = [];
|
|
247
|
+
for (const [path, bytes] of [...files].sort(([a], [b]) => compareCodeUnits(a, b))) {
|
|
248
|
+
const file = { path, hash: digest({ bytes }), size: bytes.byteLength };
|
|
249
|
+
entries.push(file);
|
|
288
250
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
251
|
+
const value = checkManifest({ value: { version: 1, files: entries }, paths, limits });
|
|
252
|
+
for (const file of entries)
|
|
253
|
+
await writeObject(context, { file, bytes: files.get(file.path) });
|
|
254
|
+
await checkpoint('objects');
|
|
255
|
+
const revisionId = digest({ bytes: JSON.stringify(value) });
|
|
256
|
+
const existing = await statIfPresent(manifestPath(revisionId));
|
|
257
|
+
if (existing)
|
|
258
|
+
await manifest(context, { revisionId });
|
|
259
|
+
else
|
|
260
|
+
await filesystem.writeJsonFileAtomicAsync({ filePath: manifestPath(revisionId), data: value }, { createParent: true });
|
|
261
|
+
await checkpoint('manifest');
|
|
262
|
+
return revisionId;
|
|
263
|
+
}
|
|
264
|
+
async function writeObject(context, { file, bytes }) {
|
|
265
|
+
const { filesystem, objectPath } = context;
|
|
266
|
+
const exists = await statIfPresent(objectPath(file.hash));
|
|
267
|
+
if (exists)
|
|
268
|
+
await object(context, { file });
|
|
269
|
+
else
|
|
270
|
+
await filesystem.writeFileAtomicAsync({ filePath: objectPath(file.hash), content: bytes }, { createParent: true });
|
|
271
|
+
}
|
|
272
|
+
async function observations(context, { files }) {
|
|
273
|
+
const { paths, limits } = context;
|
|
274
|
+
const result = Object.create(null);
|
|
275
|
+
for (const file of files) {
|
|
276
|
+
const absolute = await regularPath({ paths, path: file.path });
|
|
292
277
|
const info = await fs.stat(absolute);
|
|
293
|
-
const bytes =
|
|
294
|
-
? await object({ file: previous })
|
|
295
|
-
: await paths.reader.readBytes({ relativePath: path, maxBytes: limits.maxFileBytes });
|
|
278
|
+
const bytes = await paths.reader.readBytes({ relativePath: file.path, maxBytes: limits.maxFileBytes });
|
|
296
279
|
const after = await fs.stat(absolute);
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
/** Read a published live file without scanning/re-hashing the whole project for every viewer read. */
|
|
302
|
-
async function readWorkingFile({ relativePath }) {
|
|
303
|
-
await regularPath({ paths, path: relativePath });
|
|
304
|
-
return paths.reader.readBytes({ relativePath, maxBytes: limits.maxFileBytes });
|
|
280
|
+
// A watcher may rewrite a file immediately after a rename. Do not cache its new timestamp
|
|
281
|
+
// against old object bytes: leaving it unobserved makes the next capture hash the drift.
|
|
282
|
+
if (sameFingerprint(info, after) && digest({ bytes }) === file.hash)
|
|
283
|
+
result[file.path] = fingerprint(info);
|
|
305
284
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
285
|
+
return result;
|
|
286
|
+
}
|
|
287
|
+
/** Capture hashes only files whose disk fingerprint changed; unchanged bytes reuse objects. */
|
|
288
|
+
async function scan(context, { current }) {
|
|
289
|
+
const { paths, limits } = context;
|
|
290
|
+
const listed = paths.reader.list({});
|
|
291
|
+
if (listed.truncated)
|
|
292
|
+
throw new ProjectError({ code: 'LIMIT', message: 'tree traversal exceeded limits' });
|
|
293
|
+
// Host-disallowed files remain unmanaged; malformed allowed names are refused rather than hidden.
|
|
294
|
+
const names = listed.files.filter(relativePath => paths.allows({ relativePath }));
|
|
295
|
+
assertCandidatePaths({ paths: names });
|
|
296
|
+
const base = current ? await manifest(context, { revisionId: current.revision }) : { files: [] };
|
|
297
|
+
const previous = new Map(base.files.map(file => [file.path, file]));
|
|
298
|
+
const files = new Map();
|
|
299
|
+
let total = 0;
|
|
300
|
+
const observed = Object.create(null);
|
|
301
|
+
for (const path of names) {
|
|
302
|
+
const scanned = await scanFile(context, { path, previous: previous.get(path), observed: current?.observed[path] });
|
|
303
|
+
total += scanned.bytes.byteLength;
|
|
304
|
+
if (total > limits.maxTreeBytes || files.size >= limits.maxFiles)
|
|
305
|
+
throw new ProjectError({ code: 'LIMIT', message: 'tree exceeds project limits' });
|
|
306
|
+
files.set(path, scanned.bytes);
|
|
307
|
+
observed[path] = scanned.observed;
|
|
328
308
|
}
|
|
329
|
-
|
|
309
|
+
return { files, observed };
|
|
310
|
+
}
|
|
311
|
+
async function scanFile(context, { path, previous, observed }) {
|
|
312
|
+
const { paths, limits } = context;
|
|
313
|
+
paths.check({ relativePath: path });
|
|
314
|
+
const absolute = await regularPath({ paths, path });
|
|
315
|
+
const info = await fs.stat(absolute);
|
|
316
|
+
const bytes = previous && observed && sameFingerprint(info, observed)
|
|
317
|
+
? await object(context, { file: previous })
|
|
318
|
+
: await paths.reader.readBytes({ relativePath: path, maxBytes: limits.maxFileBytes });
|
|
319
|
+
const after = await fs.stat(absolute);
|
|
320
|
+
if (!sameFingerprint(info, after))
|
|
321
|
+
throw new ProjectError({ code: 'CONFLICT', message: `file changed while capturing: ${path}` });
|
|
322
|
+
return { bytes, observed: fingerprint(info) };
|
|
323
|
+
}
|
|
324
|
+
/** Read a published live file without scanning/re-hashing the whole project for every viewer read. */
|
|
325
|
+
async function readWorkingFile(context, { relativePath }) {
|
|
326
|
+
const { paths, limits } = context;
|
|
327
|
+
await regularPath({ paths, path: relativePath });
|
|
328
|
+
return paths.reader.readBytes({ relativePath, maxBytes: limits.maxFileBytes });
|
|
329
|
+
}
|
|
330
|
+
async function removeManaged(context, { before, after }) {
|
|
331
|
+
const { paths, checkpoint } = context;
|
|
332
|
+
const retained = new Set(after.files.map(file => file.path));
|
|
333
|
+
for (const file of before.files) {
|
|
334
|
+
if (retained.has(file.path))
|
|
335
|
+
continue;
|
|
330
336
|
try {
|
|
331
|
-
await fs.
|
|
337
|
+
await fs.rm(await regularPath({ paths, path: file.path }), { force: true });
|
|
332
338
|
}
|
|
333
339
|
catch (error) {
|
|
334
|
-
if (!['ENOENT', '
|
|
340
|
+
if (!['ENOENT', 'ENOTDIR'].includes(error.code ?? ''))
|
|
335
341
|
throw error;
|
|
336
342
|
}
|
|
343
|
+
await checkpoint('delete');
|
|
337
344
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
for (const folder of [...previous].sort((a, b) => b.length - a.length)) {
|
|
346
|
-
const alias = aliases.get(portablePathKey({ path: folder }));
|
|
347
|
-
if (alias !== undefined && alias !== folder)
|
|
348
|
-
await pruneFolder({ folder });
|
|
349
|
-
}
|
|
345
|
+
}
|
|
346
|
+
/** Prune only directories that contained a removed managed file; never recurse into exclusions. */
|
|
347
|
+
async function prune(context, { before, after }) {
|
|
348
|
+
const { checkpoint } = context;
|
|
349
|
+
const folders = removedFolders({ before, after });
|
|
350
|
+
for (const folder of [...folders].sort((a, b) => b.split('/').length - a.split('/').length)) {
|
|
351
|
+
await pruneFolder(context, { folder });
|
|
350
352
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
const bytes = new Map();
|
|
358
|
-
for (const file of after.files)
|
|
359
|
-
bytes.set(file.path, await object({ file }));
|
|
360
|
-
await removeManaged({ before, after });
|
|
361
|
-
await pruneRenamedFolders({ before, after });
|
|
362
|
-
// Empty folders blocking a directory-to-file transition must be removed before writing it.
|
|
363
|
-
for (const file of writes)
|
|
364
|
-
await removeBlockingFolder({ path: file.path, before });
|
|
365
|
-
for (const file of writes) {
|
|
366
|
-
await filesystem.writeFileAtomicAsync({ filePath: await regularPath({ paths, path: file.path }), content: bytes.get(file.path) }, { createParent: true, refuseSymlink: true, defaultMode: 0o644 });
|
|
367
|
-
await checkpoint('write');
|
|
368
|
-
}
|
|
369
|
-
await prune({ before, after });
|
|
370
|
-
const settled = { ...current, pending: null, observed: await observations(after) };
|
|
371
|
-
await filesystem.writeJsonFileAtomicAsync({ filePath: currentPath, data: settled });
|
|
372
|
-
await checkpoint('clear');
|
|
373
|
-
return settled;
|
|
353
|
+
await checkpoint('prune');
|
|
354
|
+
}
|
|
355
|
+
async function pruneFolder(context, { folder }) {
|
|
356
|
+
const { paths } = context;
|
|
357
|
+
try {
|
|
358
|
+
await fs.rmdir(await regularPath({ paths, path: folder }));
|
|
374
359
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
if (!info?.isDirectory())
|
|
379
|
-
return;
|
|
380
|
-
const folders = removedFolders({ before, after: { version: 1, files: [] } });
|
|
381
|
-
for (const folder of [...folders].sort((a, b) => b.length - a.length)) {
|
|
382
|
-
if (folder.startsWith(`${path}/`))
|
|
383
|
-
await pruneFolder({ folder });
|
|
384
|
-
}
|
|
385
|
-
await fs.rmdir(destination);
|
|
360
|
+
catch (error) {
|
|
361
|
+
if (!['ENOENT', 'ENOTEMPTY', 'EEXIST', 'ENOTDIR'].includes(error.code ?? ''))
|
|
362
|
+
throw error;
|
|
386
363
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
const info = await lstatIfPresent(target);
|
|
400
|
-
assertManagedDestination({ existsAsFile: info?.isFile() ?? false, path: file.path, sources });
|
|
401
|
-
if (info?.isDirectory())
|
|
402
|
-
await assertRemovableFolder({ path: file.path, folders, removed });
|
|
403
|
-
}
|
|
364
|
+
}
|
|
365
|
+
/** On case-insensitive volumes, reusing an empty old directory preserves its old spelling.
|
|
366
|
+
* Remove only empty managed aliases before writes, so a case-only directory rename is real.
|
|
367
|
+
*/
|
|
368
|
+
async function pruneRenamedFolders(context, { before, after }) {
|
|
369
|
+
const previous = removedFolders({ before, after: { version: 1, files: [] } });
|
|
370
|
+
const next = removedFolders({ before: after, after: { version: 1, files: [] } });
|
|
371
|
+
const aliases = new Map([...next].map(folder => [portablePathKey({ path: folder }), folder]));
|
|
372
|
+
for (const folder of [...previous].sort((a, b) => b.length - a.length)) {
|
|
373
|
+
const alias = aliases.get(portablePathKey({ path: folder }));
|
|
374
|
+
if (alias !== undefined && alias !== folder)
|
|
375
|
+
await pruneFolder(context, { folder });
|
|
404
376
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
377
|
+
}
|
|
378
|
+
/** Pre-read/verify every object before the first deletion. Pending remains until all writes land. */
|
|
379
|
+
async function materialize(context, { current }) {
|
|
380
|
+
const { paths, filesystem, currentPath, checkpoint } = context;
|
|
381
|
+
const after = await manifest(context, { revisionId: current.revision });
|
|
382
|
+
const before = current.pending?.from ? await manifest(context, { revisionId: current.pending.from }) : { version: 1, files: [] };
|
|
383
|
+
const previous = new Map(before.files.map(file => [file.path, file.hash]));
|
|
384
|
+
const writes = after.files.filter(file => previous.get(file.path) !== file.hash);
|
|
385
|
+
const bytes = new Map();
|
|
386
|
+
for (const file of after.files)
|
|
387
|
+
bytes.set(file.path, await object(context, { file }));
|
|
388
|
+
await removeManaged(context, { before, after });
|
|
389
|
+
await pruneRenamedFolders(context, { before, after });
|
|
390
|
+
// Empty folders blocking a directory-to-file transition must be removed before writing it.
|
|
391
|
+
for (const file of writes)
|
|
392
|
+
await removeBlockingFolder(context, { path: file.path, before });
|
|
393
|
+
for (const file of writes) {
|
|
394
|
+
await filesystem.writeFileAtomicAsync({ filePath: await regularPath({ paths, path: file.path }), content: bytes.get(file.path) }, { createParent: true, refuseSymlink: true, defaultMode: 0o644 });
|
|
395
|
+
await checkpoint('write');
|
|
410
396
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
397
|
+
await prune(context, { before, after });
|
|
398
|
+
const settled = { ...current, pending: null, observed: await observations(context, after) };
|
|
399
|
+
await filesystem.writeJsonFileAtomicAsync({ filePath: currentPath, data: settled });
|
|
400
|
+
await checkpoint('clear');
|
|
401
|
+
return settled;
|
|
402
|
+
}
|
|
403
|
+
async function removeBlockingFolder(context, { path, before }) {
|
|
404
|
+
const { paths } = context;
|
|
405
|
+
const destination = await regularPath({ paths, path });
|
|
406
|
+
const info = await lstatIfPresent(destination);
|
|
407
|
+
if (!info?.isDirectory())
|
|
408
|
+
return;
|
|
409
|
+
const folders = removedFolders({ before, after: { version: 1, files: [] } });
|
|
410
|
+
for (const folder of [...folders].sort((a, b) => b.length - a.length)) {
|
|
411
|
+
if (folder.startsWith(`${path}/`))
|
|
412
|
+
await pruneFolder(context, { folder });
|
|
421
413
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
414
|
+
await fs.rmdir(destination);
|
|
415
|
+
}
|
|
416
|
+
/** Refuse unsafe/unmanaged obstructions before the journal commit point. */
|
|
417
|
+
async function preflight(context, { current, revisionId }) {
|
|
418
|
+
const { paths } = context;
|
|
419
|
+
const after = await manifest(context, { revisionId });
|
|
420
|
+
const before = current ? await manifest(context, { revisionId: current.revision }) : { version: 1, files: [] };
|
|
421
|
+
const folders = removedFolders({ before, after });
|
|
422
|
+
const kept = new Set(after.files.map(file => file.path));
|
|
423
|
+
const removed = new Set(before.files.filter(file => !kept.has(file.path)).map(file => file.path));
|
|
424
|
+
const sources = new Map(before.files.map(file => [portablePathKey({ path: file.path }), file.path]));
|
|
425
|
+
await assertRenamedFolders(context, { before, after, folders, removed });
|
|
426
|
+
for (const file of after.files) {
|
|
427
|
+
await object(context, { file });
|
|
428
|
+
const target = await regularPath({ paths, path: file.path });
|
|
429
|
+
const info = await lstatIfPresent(target);
|
|
430
|
+
assertManagedDestination({ existsAsFile: info?.isFile() ?? false, path: file.path, sources });
|
|
431
|
+
if (info?.isDirectory())
|
|
432
|
+
await assertRemovableFolder(context, { path: file.path, folders, removed });
|
|
431
433
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
434
|
+
}
|
|
435
|
+
/** An existing filesystem alias must not let a create overwrite a host-disallowed file. */
|
|
436
|
+
function assertManagedDestination({ existsAsFile, path, sources }) {
|
|
437
|
+
if (!existsAsFile || sources.has(portablePathKey({ path })))
|
|
438
|
+
return;
|
|
439
|
+
throw new ProjectError({ code: 'INVALID_CHANGE', message: `unmanaged file blocks ${path}` });
|
|
440
|
+
}
|
|
441
|
+
/** A portable case rename cannot silently retain an unmanaged directory under its old spelling. */
|
|
442
|
+
async function assertRenamedFolders(context, { before, after, folders, removed }) {
|
|
443
|
+
const previous = removedFolders({ before, after: { version: 1, files: [] } });
|
|
444
|
+
const next = removedFolders({ before: after, after: { version: 1, files: [] } });
|
|
445
|
+
const aliases = new Map([...next].map(folder => [portablePathKey({ path: folder }), folder]));
|
|
446
|
+
for (const path of previous) {
|
|
447
|
+
const alias = aliases.get(portablePathKey({ path }));
|
|
448
|
+
if (alias !== undefined && alias !== path)
|
|
449
|
+
await assertRemovableFolder(context, { path, folders, removed });
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
async function assertRemovableFolder(context, { path, folders, removed }) {
|
|
453
|
+
const { paths } = context;
|
|
454
|
+
const inspect = new Set([path, ...[...folders].filter(folder => folder.startsWith(`${path}/`))]);
|
|
455
|
+
for (const folder of inspect) {
|
|
456
|
+
for (const name of await fs.readdir(await regularPath({ paths, path: folder }))) {
|
|
457
|
+
const child = `${folder}/${name}`;
|
|
458
|
+
if (!folders.has(child) && !removed.has(child))
|
|
459
|
+
throw new ProjectError({ code: 'INVALID_CHANGE', message: `unmanaged directory contents block ${path}` });
|
|
443
460
|
}
|
|
444
|
-
return current.pending ? materialize({ current }) : current;
|
|
445
461
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
await filesystem.writeJsonFileAtomicAsync({ filePath: currentPath, data: next });
|
|
454
|
-
await checkpoint('journal');
|
|
455
|
-
return captured ? next : materialize({ current: next });
|
|
462
|
+
}
|
|
463
|
+
async function recover(context) {
|
|
464
|
+
const current = await readCurrent(context);
|
|
465
|
+
if (!current)
|
|
466
|
+
return null;
|
|
467
|
+
try {
|
|
468
|
+
await manifest(context, { revisionId: current.revision });
|
|
456
469
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
const next = { ...current, observed };
|
|
462
|
-
await filesystem.writeJsonFileAtomicAsync({ filePath: currentPath, data: next });
|
|
463
|
-
return next;
|
|
470
|
+
catch (cause) {
|
|
471
|
+
if (missing(cause))
|
|
472
|
+
throw new ProjectError({ code: 'CORRUPT', message: 'current manifest is missing', cause });
|
|
473
|
+
throw cause;
|
|
464
474
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
475
|
+
return current.pending ? materialize(context, { current }) : current;
|
|
476
|
+
}
|
|
477
|
+
/** Journal is the commit point. Reopen rolls it forward; no rollback or guessed replacement. */
|
|
478
|
+
async function select(context, { current, revisionId, captured }) {
|
|
479
|
+
const { root, filesystem, currentPath, checkpoint } = context;
|
|
480
|
+
await manifest(context, { revisionId });
|
|
481
|
+
if (current?.generation === Number.MAX_SAFE_INTEGER)
|
|
482
|
+
throw new ProjectError({ code: 'LIMIT', message: 'generation exhausted' });
|
|
483
|
+
const next = { version: 1, root, revision: revisionId, generation: (current?.generation ?? 0) + 1,
|
|
484
|
+
pending: captured ? null : { from: current?.revision ?? null }, observed: captured ?? {} };
|
|
485
|
+
await filesystem.writeJsonFileAtomicAsync({ filePath: currentPath, data: next });
|
|
486
|
+
await checkpoint('journal');
|
|
487
|
+
return captured ? next : materialize(context, { current: next });
|
|
488
|
+
}
|
|
489
|
+
/** Refresh a same-content capture's fingerprints without inventing a new revision/generation. */
|
|
490
|
+
async function observe(context, { current, observed }) {
|
|
491
|
+
const { filesystem, currentPath } = context;
|
|
492
|
+
if (JSON.stringify(current.observed) === JSON.stringify(observed))
|
|
493
|
+
return current;
|
|
494
|
+
const next = { ...current, observed };
|
|
495
|
+
await filesystem.writeJsonFileAtomicAsync({ filePath: currentPath, data: next });
|
|
496
|
+
return next;
|
|
497
|
+
}
|
|
498
|
+
/** Both stacks pin manifests and blobs. Expired snapshots do not pin storage indefinitely. */
|
|
499
|
+
async function collect(context, { revisions }) {
|
|
500
|
+
const { stateDir } = context;
|
|
501
|
+
const objects = new Set();
|
|
502
|
+
for (const revisionId of revisions) {
|
|
503
|
+
for (const file of (await manifest(context, { revisionId })).files)
|
|
504
|
+
objects.add(file.hash);
|
|
474
505
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
locked: (run) => filesystem.withFileLock({ lockPath: resolve(stateDir, 'project.lock'), run }, { staleMs: Infinity, createParent: true }),
|
|
478
|
-
recover,
|
|
479
|
-
};
|
|
506
|
+
await removeUnreferenced({ directory: resolve(stateDir, 'manifests'), keep: new Set([...revisions].map(id => `${id}.json`)) });
|
|
507
|
+
await removeUnreferenced({ directory: resolve(stateDir, 'objects'), keep: objects });
|
|
480
508
|
}
|
|
481
509
|
/** Generated orphan objects/manifests are safe to discard only while holding the project lock. */
|
|
482
510
|
async function removeUnreferenced({ directory, keep }) {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { type CSSProperties } from 'react';
|
|
12
12
|
import type { VibecodingSession } from '../session.js';
|
|
13
|
+
import { useVibecodingSession } from '../use-vibecoding-session.js';
|
|
13
14
|
export interface VibecodingWorkbenchProps {
|
|
14
15
|
readonly session: VibecodingSession;
|
|
15
16
|
/**
|
|
@@ -34,5 +35,7 @@ export interface VibecodingWorkbenchProps {
|
|
|
34
35
|
*
|
|
35
36
|
* @complexity O(parts.length) to render the viewer; content fetches are cached — see `../session.js`.
|
|
36
37
|
*/
|
|
37
|
-
export declare function VibecodingWorkbench({ session, documentHtml, className, style }: VibecodingWorkbenchProps
|
|
38
|
+
export declare function VibecodingWorkbench({ session, documentHtml, className, style, useVibecodingSessionHook }: VibecodingWorkbenchProps & {
|
|
39
|
+
useVibecodingSessionHook?: typeof useVibecodingSession;
|
|
40
|
+
}): import("react").JSX.Element;
|
|
38
41
|
//# sourceMappingURL=VibecodingWorkbench.d.ts.map
|
|
@@ -57,8 +57,8 @@ const PREVIEW_PANE_STYLE = { flex: 1, minWidth: 0, minHeight: 0 };
|
|
|
57
57
|
*
|
|
58
58
|
* @complexity O(parts.length) to render the viewer; content fetches are cached — see `../session.js`.
|
|
59
59
|
*/
|
|
60
|
-
export function VibecodingWorkbench({ session, documentHtml, className, style }) {
|
|
61
|
-
const { parts, partContent, canUndo, canRedo, lastError, readPart, undo, redo } =
|
|
60
|
+
export function VibecodingWorkbench({ session, documentHtml, className, style, useVibecodingSessionHook = useVibecodingSession }) {
|
|
61
|
+
const { parts, partContent, canUndo, canRedo, lastError, readPart, undo, redo } = useVibecodingSessionHook({ session });
|
|
62
62
|
const [selectedId, setSelectedId] = useState(null);
|
|
63
63
|
const [selectedContent, setSelectedContent] = useState(undefined);
|
|
64
64
|
const [contentLoading, setContentLoading] = useState(false);
|