MCPcopy Create free account
hub / github.com/CommonstackAI/UncommonRoute / upsert_shell_block

Function upsert_shell_block

uncommon_route/onboarding.py:239–256  ·  view source on GitHub ↗
(path: Path, block_name: str, lines: list[str])

Source from the content-addressed store, hash-verified

237
238
239def upsert_shell_block(path: Path, block_name: str, lines: list[str]) -> Path:
240 start_marker = f"# >>> uncommon-route {block_name} >>>"
241 end_marker = f"# <<< uncommon-route {block_name} <<<"
242 block_lines = [start_marker, "# Added by `uncommon-route init`.", *lines, end_marker]
243 block = "\n".join(block_lines)
244
245 existing = path.read_text() if path.exists() else ""
246 if start_marker in existing and end_marker in existing:
247 start = existing.index(start_marker)
248 end = existing.index(end_marker, start) + len(end_marker)
249 updated = f"{existing[:start].rstrip()}\n\n{block}\n{existing[end:].lstrip()}"
250 else:
251 separator = "\n\n" if existing.strip() else ""
252 updated = f"{existing.rstrip()}{separator}{block}\n"
253
254 path.parent.mkdir(parents=True, exist_ok=True)
255 path.write_text(updated)
256 return path

Callers 2

_cmd_initFunction · 0.90
apply_planFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected