MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / _copy_or_write

Function _copy_or_write

src/command_system/copy_command.py:185–203  ·  view source on GitHub ↗

TS ``copyOrWriteToFile`` (copy.tsx:81-94), with the honest clipboard-failure divergence (module docstring). ``char_count`` is Python codepoints; TS ``text.length`` is UTF-16 code units (astral chars differ by one).

(text: str, filename: str)

Source from the content-addressed store, hash-verified

183
184
185def _copy_or_write(text: str, filename: str) -> str:
186 """TS ``copyOrWriteToFile`` (copy.tsx:81-94), with the honest clipboard-failure
187 divergence (module docstring). ``char_count`` is Python codepoints; TS
188 ``text.length`` is UTF-16 code units (astral chars differ by one)."""
189 copied = _set_clipboard(text)
190 line_count = text.count("\n") + 1
191 char_count = len(text)
192 try:
193 path = _write_to_file(text, filename)
194 except Exception as exc:
195 if copied:
196 return f"Copied to clipboard ({char_count} characters, {line_count} lines)"
197 return f"Failed to copy: {exc}"
198 if copied:
199 return (
200 f"Copied to clipboard ({char_count} characters, {line_count} lines)\n"
201 f"Also written to {path}"
202 )
203 return f"Written to {path} ({char_count} characters, {line_count} lines)"
204
205
206def _copy_full_response_enabled() -> bool:

Callers 2

runMethod · 0.85
_pickMethod · 0.85

Calls 3

_set_clipboardFunction · 0.85
_write_to_fileFunction · 0.85
countMethod · 0.80

Tested by

no test coverage detected