@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
3 lines (2 loc) • 1.11 kB
JavaScript
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url); { const __piWorkerThreads = require("node:worker_threads"); if (typeof __piWorkerThreads.markAsUncloneable !== "function") { __piWorkerThreads.markAsUncloneable = () => {}; } }
function hierarchy(ranges){let roots=[],stack=[];for(let range of[...ranges].sort((a,b)=>a.startLine-b.startLine||b.endLine-a.endLine)){for(;stack.length&&range.startLine>stack[stack.length-1].endLine;)stack.pop();let parent=stack[stack.length-1];if(parent&&range.startLine===parent.startLine&&range.endLine===parent.endLine)continue;if(parent&&(range.startLine<=parent.startLine||range.endLine>=parent.endLine))return;let node={...range,children:[]};(parent?parent.children:roots).push(node),stack.push(node)}return roots}function composeFoldResult(text,scan){switch(scan.status){case"parse_failure":return scan;case"parsed":{let ranges=hierarchy(scan.ranges);return ranges?{status:"parsed",text,ranges}:{status:"parse_failure",reason:"ambiguous_line_boundaries"}}default:return scan}}export{composeFoldResult};