Preserve experimental Live app-server workstream

Snapshot the current app-server implementation, shared Live optimizations, generated harness output, and in-progress site work before restoring polling as the primary runtime path.

Prepared with Codex assistance under maintainer direction.
This commit is contained in:
Paul Bakaus
2026-07-15 16:07:34 -07:00
parent ed7a6fbe4e
commit ead6ddabe5
603 changed files with 148852 additions and 7584 deletions
+92 -4
View File
@@ -30,6 +30,10 @@ import {
inlineVueComponentAccept,
retireVueComponentSession,
} from './live/vue-component.mjs';
import {
findSourceArtifactManifest,
removeSourceArtifactSession,
} from './live/source-artifact.mjs';
const EXTENSIONS = ['.html', '.jsx', '.tsx', '.vue', '.svelte', '.astro'];
const ACCEPT_LOCK_WAIT_MS = 1_000;
@@ -106,15 +110,60 @@ Output (JSON):
}
// Find the file containing this session's markers
const found = findSessionFile(id, process.cwd());
const sourceArtifactManifest = findSourceArtifactManifest(id, process.cwd());
const found = sourceArtifactManifest ? null : findSessionFile(id, process.cwd());
const svelteComponentManifest = found ? null : findSvelteComponentManifest(id, process.cwd());
const vueComponentManifest = found || svelteComponentManifest ? null : findVueComponentManifest(id, process.cwd());
if (!found && !svelteComponentManifest && !vueComponentManifest) {
if (!found && !sourceArtifactManifest && !svelteComponentManifest && !vueComponentManifest) {
console.log(JSON.stringify({ handled: false, error: 'Session markers not found for id: ' + id }));
process.exit(0);
}
if (sourceArtifactManifest) {
if (isDiscard) {
removeSourceArtifactSession(id, process.cwd());
emitResult({
handled: true,
file: sourceArtifactManifest.sourceFile,
sourceFile: sourceArtifactManifest.sourceFile,
previewMode: sourceArtifactManifest.previewMode,
carbonize: false,
});
return;
}
let result;
try {
result = withSourceLockSync(
sourceArtifactManifest.sourcePath,
'accept:' + id,
() => acceptSourceArtifact(sourceArtifactManifest, variantNum, paramValues),
{ waitMs: ACCEPT_LOCK_WAIT_MS },
);
} catch (err) {
result = { handled: false, error: err.message };
}
if (result.handled !== false) {
removeSourceArtifactSession(id, process.cwd());
try {
scrubManualEditsAgainstOriginalBlock(result.acceptedOriginalText || '', process.cwd(), pageUrl);
} catch {}
}
delete result.acceptedOriginalText;
if (result.carbonize) {
result.todo = 'REQUIRED before next poll: carbonize cleanup in ' + sourceArtifactManifest.sourceFile + '. See reference/live.md "Required after accept".';
}
emitResult({
handled: result.handled !== false,
file: sourceArtifactManifest.sourceFile,
sourceFile: sourceArtifactManifest.sourceFile,
previewMode: sourceArtifactManifest.previewMode,
...result,
});
return;
}
if (vueComponentManifest) {
if (isDiscard) {
let result;
@@ -447,6 +496,16 @@ function handleAccept(id, variantNum, _lines, targetFile, paramValues) {
}
function handleAcceptUnlocked(id, variantNum, lines, targetFile, paramValues) {
const built = buildAcceptedWrappedSource(id, variantNum, lines, targetFile, paramValues);
if (built.handled === false) return built;
fs.writeFileSync(targetFile, built.content, 'utf-8');
return {
carbonize: built.carbonize,
acceptedOriginalText: built.acceptedOriginalText,
};
}
function buildAcceptedWrappedSource(id, variantNum, lines, targetFile, paramValues) {
const block = findMarkerBlock(id, lines);
if (!block) return { handled: false, error: 'Markers not found' };
@@ -491,9 +550,38 @@ function handleAcceptUnlocked(id, variantNum, lines, targetFile, paramValues) {
...replacement,
...lines.slice(replaceRange.end + 1),
];
fs.writeFileSync(targetFile, newLines.join('\n'), 'utf-8');
return {
content: newLines.join('\n'),
carbonize: needsCarbonize,
acceptedOriginalText: originalContent.join('\n'),
};
}
return { carbonize: needsCarbonize, acceptedOriginalText: originalContent.join('\n') };
function acceptSourceArtifact(manifest, variantNum, paramValues) {
const source = fs.readFileSync(manifest.sourcePath, 'utf-8');
const preview = fs.readFileSync(manifest.previewPath, 'utf-8');
const original = String(manifest.originalSource || '');
if (!original) return { handled: false, error: 'source_artifact_original_missing' };
const first = source.indexOf(original);
if (first < 0) return { handled: false, error: 'source_artifact_original_changed' };
if (source.indexOf(original, first + original.length) >= 0) {
return { handled: false, error: 'source_artifact_original_ambiguous' };
}
const wrapped = source.slice(0, first) + preview + source.slice(first + original.length);
const built = buildAcceptedWrappedSource(
manifest.id,
variantNum,
wrapped.split('\n'),
manifest.sourcePath,
paramValues,
);
if (built.handled === false) return built;
fs.writeFileSync(manifest.sourcePath, built.content, 'utf-8');
return {
handled: true,
carbonize: built.carbonize,
acceptedOriginalText: built.acceptedOriginalText,
};
}
function readSourceShadowPreviewMeta(content, id) {