[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6HX977AT1KK0NYAD3DXFN31":3,"skill-same:01M6HX977AT1KK0NYAD3DXFN31":81},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":28,"publishedAt":48,"linkOnly":49,"markdownContent":50,"markdownBody":51,"frontMatter":52,"refName":53,"commitSha":54,"skillDirectory":55,"forksCount":56,"repositoryHtmlUrl":57,"repositoryHomepageUrl":6,"ownerHtmlUrl":58,"ownerBlogUrl":59,"ownerDescription":6,"updatedAt":60,"install":61,"resources":74},"01M6HX977AT1KK0NYAD3DXFN31","large-file-write-via-temp-script",null,"Reliable fallback technique for writing large or special-character-heavy file content when inline write_file or shell_agent calls fail with unknown errors — uses a Python helper script written to a temp file to avoid escaping and truncation pitfalls.","HKUDS\u002FAgentPilot","HKUDS","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F118165258?v=4","01M6HW8VRNZP64G0P4MVJW2KKQ","✨Data Intelligence Lab@HKU✨","01M6HW8VWZVHBRHYH3T330PFWV",8029,"MIT","https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot\u002Fblob\u002Fmain\u002Fopenspace\u002Fexamples\u002Fmy-daily-monitor\u002Fskills\u002Flarge-file-write-via-temp-script\u002FSKILL.md",[18,23],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发","SCENARIO","使用场景",{"categoryNo":24,"categoryName":25,"taxonomyType":26,"taxonomyTypeDesc":27},"01JBSEEDCAT000000000000036","内容创作者","PROFESSION","适用职业",[29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47],"large file write via temp script","file","write","via","script","helper","unknown","inline","for","calls","pitfalls","errors","with","writing","character","fallback","shell","content","python","2026-11-10 10:12:30",false,"---\nname: large-file-write-via-temp-script\ndescription: Reliable fallback technique for writing large or special-character-heavy file content when inline write_file or shell_agent calls fail with unknown errors — uses a Python helper script written to a temp file to avoid escaping and truncation pitfalls.\n---\n\n# Large File Write via Temp Script\n\n## Problem\n\nWriting large files — especially TypeScript, TSX, or any content containing\nUnicode emoji, backticks, `${}` template literals, or multi-line heredoc\nconflicts — can silently fail or truncate content when passed inline.\n\n**Failure modes observed:**\n- `write_file` returns `[ERROR] unknown error` on large payloads\n- `node -e '...'` with backtick template literals silently empties the target file\n- `python3 -c '...'` breaks on unescaped quotes or special characters\n- `shell_agent` may time out or fail when the inline content is too large\n\n---\n\n## Solution: Write a Python Script to a Temp File First\n\nInstead of passing file content inline, write a small Python helper script to\n`\u002Ftmp\u002Fwrite_task.py` (or similar), then execute it. The helper script holds\nthe target file content as a raw Python string or via base64 decoding.\n\n---\n\n## Approach A — Python Triple-Quoted String (preferred for readability)\n\nUse `write_file` or a heredoc to create the helper, then run it:\n\n```bash\n# Step 1: Write the helper script to \u002Ftmp\ncat > \u002Ftmp\u002Fwrite_task.py \u003C\u003C 'PYEOF'\nimport pathlib\n\ncontent = r\"\"\"\n\u002F\u002F Your TypeScript \u002F file content goes here\n\u002F\u002F Backticks `like this`, ${template} literals, and emoji ? are all safe\nexport const MyComponent = () => {\n  const msg = `Hello, world!`;\n  return \u003Cdiv>{msg}\u003C\u002Fdiv>;\n};\n\"\"\"\n\npathlib.Path(\"\u002Fpath\u002Fto\u002Ftarget\u002Ffile.ts\").write_text(content.lstrip(\"\\n\"), encoding=\"utf-8\")\nprint(\"Written successfully.\")\nPYEOF\n\n# Step 2: Execute the helper\npython3 \u002Ftmp\u002Fwrite_task.py\n```\n\n> **Why `r\"\"\"`?** A raw triple-quoted string avoids all backslash escaping\n> issues. The only content that cannot appear verbatim is `\"\"\"` itself — if\n> needed, split the string or escape that sequence only.\n\n---\n\n## Approach B — Base64-Encoded Content (most robust for binary\u002Fcomplex content)\n\nWhen the content contains `\"\"\"` or other Python string edge cases:\n\n```bash\n# Step 1: Base64-encode your content (done once, outside the target system)\n# python3 -c \"import base64; print(base64.b64encode(open('file.ts').read().encode()).decode())\"\n\n# Step 2: Embed the base64 blob in the helper script\ncat > \u002Ftmp\u002Fwrite_task.py \u003C\u003C 'PYEOF'\nimport base64, pathlib\n\nb64 = (\n    \"aW1wb3J0IFJlYWN0IGZyb20gJ3JlYWN0JzsKCmV4cG9ydCBjb25zdCBNeUNvbXBvbmVudCA9\"\n    \"ICgpID0+IHsKICByZXR1cm4gPGRpdj5IZWxsbzwvZGl2PjsKfTsK\"\n    # ... more lines if needed\n)\n\ncontent = base64.b64decode(b64).decode(\"utf-8\")\npathlib.Path(\"\u002Fpath\u002Fto\u002Ftarget\u002Ffile.ts\").write_text(content, encoding=\"utf-8\")\nprint(f\"Written {len(content)} bytes successfully.\")\nPYEOF\n\npython3 \u002Ftmp\u002Fwrite_task.py\n```\n\n---\n\n## Approach C — shell_agent Delegation (simplest for agents)\n\nAsk `shell_agent` to perform the write using the temp-script pattern:\n\n> \"Write the following TypeScript content to `\u002Fsrc\u002Fcomponents\u002FMyPanel.ts`.\n> Do NOT use `node -e` or inline Python. Instead write a Python script to\n> `\u002Ftmp\u002Fwrite_panel.py` using a triple-quoted raw string, then execute it.\"\n\n---\n\n## Decision Guide\n\n| Situation | Recommended Approach |\n|---|---|\n| Content has backticks \u002F `${}` template literals | Approach A (raw `r\"\"\"`) |\n| Content has `\"\"\"` sequences | Approach B (base64) |\n| Content is binary or non-UTF-8 | Approach B (base64) |\n| Delegating to shell_agent | Approach C with explicit instructions |\n| Quick small file | Direct `write_file` (no workaround needed) |\n\n---\n\n## Anti-Patterns to Avoid\n\n```bash\n# ❌ DANGEROUS — backtick template literals will break node -e\nnode -e \"const fs = require('fs'); fs.writeFileSync('out.ts', \\`${content}\\`);\"\n\n# ❌ FRAGILE — breaks on unescaped quotes and special characters\npython3 -c \"open('out.ts','w').write('${content}')\"\n\n# ❌ UNRELIABLE for large payloads — may silently truncate\necho \"${large_content}\" > out.ts\n```\n\n---\n\n## Verification Step\n\nAlways verify the write succeeded:\n\n```bash\n# Check file exists and has non-zero size\npython3 -c \"\nimport pathlib\np = pathlib.Path('\u002Fpath\u002Fto\u002Ftarget\u002Ffile.ts')\nassert p.exists() and p.stat().st_size > 0, f'Write failed: {p}'\nprint(f'OK — {p.stat().st_size} bytes written to {p}')\n\"\n```\n\n---\n\n## Notes\n\n- The temp script approach works for **any file type**: `.ts`, `.tsx`, `.js`, `.json`, `.md`, `.py`, etc.\n- Always `lstrip(\"\\n\")` the triple-quoted string to avoid a leading blank line.\n- For very large files (>50 KB), prefer base64 to avoid any risk of heredoc conflicts.\n- Clean up temp scripts after use: `rm \u002Ftmp\u002Fwrite_task.py`","# Large File Write via Temp Script\n\n## Problem\n\nWriting large files — especially TypeScript, TSX, or any content containing\nUnicode emoji, backticks, `${}` template literals, or multi-line heredoc\nconflicts — can silently fail or truncate content when passed inline.\n\n**Failure modes observed:**\n- `write_file` returns `[ERROR] unknown error` on large payloads\n- `node -e '...'` with backtick template literals silently empties the target file\n- `python3 -c '...'` breaks on unescaped quotes or special characters\n- `shell_agent` may time out or fail when the inline content is too large\n\n---\n\n## Solution: Write a Python Script to a Temp File First\n\nInstead of passing file content inline, write a small Python helper script to\n`\u002Ftmp\u002Fwrite_task.py` (or similar), then execute it. The helper script holds\nthe target file content as a raw Python string or via base64 decoding.\n\n---\n\n## Approach A — Python Triple-Quoted String (preferred for readability)\n\nUse `write_file` or a heredoc to create the helper, then run it:\n\n```bash\n# Step 1: Write the helper script to \u002Ftmp\ncat > \u002Ftmp\u002Fwrite_task.py \u003C\u003C 'PYEOF'\nimport pathlib\n\ncontent = r\"\"\"\n\u002F\u002F Your TypeScript \u002F file content goes here\n\u002F\u002F Backticks `like this`, ${template} literals, and emoji ? are all safe\nexport const MyComponent = () => {\n  const msg = `Hello, world!`;\n  return \u003Cdiv>{msg}\u003C\u002Fdiv>;\n};\n\"\"\"\n\npathlib.Path(\"\u002Fpath\u002Fto\u002Ftarget\u002Ffile.ts\").write_text(content.lstrip(\"\\n\"), encoding=\"utf-8\")\nprint(\"Written successfully.\")\nPYEOF\n\n# Step 2: Execute the helper\npython3 \u002Ftmp\u002Fwrite_task.py\n```\n\n> **Why `r\"\"\"`?** A raw triple-quoted string avoids all backslash escaping\n> issues. The only content that cannot appear verbatim is `\"\"\"` itself — if\n> needed, split the string or escape that sequence only.\n\n---\n\n## Approach B — Base64-Encoded Content (most robust for binary\u002Fcomplex content)\n\nWhen the content contains `\"\"\"` or other Python string edge cases:\n\n```bash\n# Step 1: Base64-encode your content (done once, outside the target system)\n# python3 -c \"import base64; print(base64.b64encode(open('file.ts').read().encode()).decode())\"\n\n# Step 2: Embed the base64 blob in the helper script\ncat > \u002Ftmp\u002Fwrite_task.py \u003C\u003C 'PYEOF'\nimport base64, pathlib\n\nb64 = (\n    \"aW1wb3J0IFJlYWN0IGZyb20gJ3JlYWN0JzsKCmV4cG9ydCBjb25zdCBNeUNvbXBvbmVudCA9\"\n    \"ICgpID0+IHsKICByZXR1cm4gPGRpdj5IZWxsbzwvZGl2PjsKfTsK\"\n    # ... more lines if needed\n)\n\ncontent = base64.b64decode(b64).decode(\"utf-8\")\npathlib.Path(\"\u002Fpath\u002Fto\u002Ftarget\u002Ffile.ts\").write_text(content, encoding=\"utf-8\")\nprint(f\"Written {len(content)} bytes successfully.\")\nPYEOF\n\npython3 \u002Ftmp\u002Fwrite_task.py\n```\n\n---\n\n## Approach C — shell_agent Delegation (simplest for agents)\n\nAsk `shell_agent` to perform the write using the temp-script pattern:\n\n> \"Write the following TypeScript content to `\u002Fsrc\u002Fcomponents\u002FMyPanel.ts`.\n> Do NOT use `node -e` or inline Python. Instead write a Python script to\n> `\u002Ftmp\u002Fwrite_panel.py` using a triple-quoted raw string, then execute it.\"\n\n---\n\n## Decision Guide\n\n| Situation | Recommended Approach |\n|---|---|\n| Content has backticks \u002F `${}` template literals | Approach A (raw `r\"\"\"`) |\n| Content has `\"\"\"` sequences | Approach B (base64) |\n| Content is binary or non-UTF-8 | Approach B (base64) |\n| Delegating to shell_agent | Approach C with explicit instructions |\n| Quick small file | Direct `write_file` (no workaround needed) |\n\n---\n\n## Anti-Patterns to Avoid\n\n```bash\n# ❌ DANGEROUS — backtick template literals will break node -e\nnode -e \"const fs = require('fs'); fs.writeFileSync('out.ts', \\`${content}\\`);\"\n\n# ❌ FRAGILE — breaks on unescaped quotes and special characters\npython3 -c \"open('out.ts','w').write('${content}')\"\n\n# ❌ UNRELIABLE for large payloads — may silently truncate\necho \"${large_content}\" > out.ts\n```\n\n---\n\n## Verification Step\n\nAlways verify the write succeeded:\n\n```bash\n# Check file exists and has non-zero size\npython3 -c \"\nimport pathlib\np = pathlib.Path('\u002Fpath\u002Fto\u002Ftarget\u002Ffile.ts')\nassert p.exists() and p.stat().st_size > 0, f'Write failed: {p}'\nprint(f'OK — {p.stat().st_size} bytes written to {p}')\n\"\n```\n\n---\n\n## Notes\n\n- The temp script approach works for **any file type**: `.ts`, `.tsx`, `.js`, `.json`, `.md`, `.py`, etc.\n- Always `lstrip(\"\\n\")` the triple-quoted string to avoid a leading blank line.\n- For very large files (>50 KB), prefer base64 to avoid any risk of heredoc conflicts.\n- Clean up temp scripts after use: `rm \u002Ftmp\u002Fwrite_task.py`",{"name":5,"description":7},"main","6b84b0689ca0d9e7b1e4061188ff6b60758e0f8a","openspace\u002Fexamples\u002Fmy-daily-monitor\u002Fskills\u002Flarge-file-write-via-temp-script",944,"https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot","https:\u002F\u002Fgithub.com\u002FHKUDS","https:\u002F\u002Fsites.google.com\u002Fview\u002Fchaoh","2026-11-12 22:26:39",{"source":8,"skillName":5,"commands":62,"prompt":72,"zipAvailable":73},[63,66,69],{"tool":64,"command":65},"npx","npx skills add HKUDS\u002FAgentPilot --skill large-file-write-via-temp-script",{"tool":67,"command":68},"bunx","bunx skills add HKUDS\u002FAgentPilot --skill large-file-write-via-temp-script",{"tool":70,"command":71},"pnpm","pnpm dlx skills add HKUDS\u002FAgentPilot --skill large-file-write-via-temp-script","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot\u002Fblob\u002Fmain\u002Fopenspace\u002Fexamples\u002Fmy-daily-monitor\u002Fskills\u002Flarge-file-write-via-temp-script\u002FSKILL.md",true,[75],{"path":76,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":79,"sourceHtmlUrl":80},".skill_id","OTHER","其他",46,"https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot\u002Fblob\u002Fmain\u002Fopenspace\u002Fexamples\u002Fmy-daily-monitor\u002Fskills\u002Flarge-file-write-via-temp-script\u002F.skill_id",[82,101,120,141,164,182],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":48},"01M6HYB297NDABRERJRVG0K8R0","agentpilot","Set up AgentPilot and use its single entry to prepare missing inputs and run configured RSI experiments. Use when the user requests AgentPilot installation or work with AgentPilot.","https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot\u002Fblob\u002Fmain\u002Fplugins\u002Fagentpilot\u002Fskills\u002Fagentpilot\u002FSKILL.md",[],[84,89,90,41,91,92,93,94,95,96,97,98,99,100],"prepare","requests","missing","installation","rsi","up","use","user","work","SET","run","experiments",{"skillNo":102,"name":103,"nameZh":6,"description":104,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":105,"categories":106,"keywords":107,"publishedAt":48},"01M6HYAYWXTTE1J7DJM0MFNQ4H","remember","Review auto-memory entries and propose promotions to OPENSPACE.md, OPENSPACE.local.md, or retained auto-memory topics; detect duplicates, stale facts, conflicts, and ambiguous entries before making changes.","https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot\u002Fblob\u002Fmain\u002Fopenspace\u002Fopenspace\u002Fskills\u002Fremember\u002FSKILL.md",[],[103,108,109,110,111,112,113,114,115,116,117,118,119],"memory","review","auto","openspace","changes","facts","detect","entries","local","conflicts","stale","duplicates",{"skillNo":121,"name":122,"nameZh":6,"description":123,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":124,"categories":125,"keywords":127,"publishedAt":48},"01M6HYAVMPM4SBDV60R2B5HPV8","skill-discovery","Search reusable OpenSpace skills locally, and browse cloud packages step by step when a cloud skill may help. Reusing proven skills saves tokens, improves reliability, and extends your capabilities beyond built-in tools.","https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot\u002Fblob\u002Fmain\u002Fopenspace\u002Fopenspace\u002Fhost_skills\u002Fskill-discovery\u002FSKILL.md",[126],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},[128,129,130,111,131,132,133,134,135,136,137,138,139,140],"skill discovery","discovery","reusable","step by step","tokens","packages","help","cloud","reliability","capabilities","browse","search","Tools",{"skillNo":142,"name":143,"nameZh":6,"description":144,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":145,"categories":146,"keywords":148,"publishedAt":48},"01M6HYAR811B3RB0M50RBEDGN6","delegate-task","Delegate tasks to OpenSpace — a full-stack autonomous worker for coding, DevOps, web research, and desktop automation, backed by an extensive MCP tool and skill library. Skills auto-improve through use, reducing token consumption over time. A cloud community lets agents share and collectively evolve reusable skills.","https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot\u002Fblob\u002Fmain\u002Fopenspace\u002Fopenspace\u002Fhost_skills\u002Fdelegate-task\u002FSKILL.md",[147],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},[149,150,151,111,152,153,154,155,156,130,110,95,157,158,159,37,160,161,162,163],"delegate","task","delegate task","time","improve","desktop automation","worker","community","autonomous","tool","stack","share","tasks","automation","MCP",{"skillNo":165,"name":166,"nameZh":6,"description":167,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":168,"categories":169,"keywords":170,"publishedAt":48},"01M6HYAM9FSGV6E52AYENDQXYH","write-special-chars-ts-check","Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) using a Python heredoc script, plus a reliable TypeScript type-checking step that filters output to only the newly-written files to avoid being misled by pre-existing errors.","https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot\u002Fblob\u002Fmain\u002Fopenspace\u002Flegacy\u002Fv1\u002Fshowcase\u002Fskills\u002Fwrite-special-chars-ts-check\u002FSKILL.md",[],[171,31,172,173,174,175,176,177,30,47,178,179,180,181,37,40,33],"write special chars ts check","check","type","files","filters","only","template","typescript","output","Existing","type-checking",{"skillNo":183,"name":184,"nameZh":6,"description":185,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":186,"categories":187,"keywords":188,"publishedAt":48},"01M6HYAH05HGV7SVWSVR8PJRQD","write-special-chars-readback","Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) using a Python heredoc script, with mandatory post-write verification via read_file and cleanup of \u002Ftmp helper scripts.","https:\u002F\u002Fgithub.com\u002FHKUDS\u002FAgentPilot\u002Fblob\u002Fmain\u002Fopenspace\u002Flegacy\u002Fv1\u002Fshowcase\u002Fskills\u002Fwrite-special-chars-readback\u002FSKILL.md",[],[189,190,31,41,37,33,34,191,32,192,193,177,30,194,195,47],"write special chars readback","readback","post","scripts","read","verification","cleanup"]