MCPcopy
hub / github.com/OpenCoworkAI/open-codesign / replaceTweakSchema

Function replaceTweakSchema

packages/shared/src/editmode.ts:334–349  ·  view source on GitHub ↗
(source: string, schema: TweakSchema)

Source from the content-addressed store, hash-verified

332 * artifact has a TWEAK_DEFAULTS block first.
333 */
334export function replaceTweakSchema(source: string, schema: TweakSchema): string {
335 const json = JSON.stringify(schema, null, 2);
336 if (findMarkerBlock(source, 'TWEAK-SCHEMA')) {
337 return replaceMarkerBlock(source, 'TWEAK-SCHEMA', json);
338 }
339 const marked = findMarkerBlock(source, 'EDITMODE');
340 if (marked) {
341 // Find the end of the statement containing the EDITMODE block (next ';').
342 const editEnd = marked.end;
343 const semi = source.indexOf(';', editEnd);
344 const insertAt = semi >= 0 ? semi + 1 : editEnd;
345 const block = `\nconst TWEAK_SCHEMA = /*TWEAK-SCHEMA-BEGIN*/${json}/*TWEAK-SCHEMA-END*/;`;
346 return `${source.slice(0, insertAt)}${block}${source.slice(insertAt)}`;
347 }
348 return source;
349}

Callers 1

editmode.test.tsFile · 0.90

Calls 2

findMarkerBlockFunction · 0.85
replaceMarkerBlockFunction · 0.85

Tested by

no test coverage detected