write-special-chars-ts-check

使用 Python heredoc 脚本解决因特殊字符(如撇号、反引号、模板字面量)导致的 write_file 失败问题;并结合可靠的 TypeScript 类型检查步骤,仅过滤并显示新写入文件的输出,以避免被已有错误误导。

仓库最近推送
GitHub Stars
8,134
Forks
953
Issues / PRs
39

预览截图

来自skillπ 实验室的展示

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "write-special-chars-ts-check":https://skillpi.com/zh/skills/deepskill-d826922fc0507bb760920c09f66ea88dfd70eb56913e32de8f03929d340ee521。安装前核对上游来源和版本:https://github.com/HKUDS/OpenSpace。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

使用 Python heredoc 脚本解决因特殊字符(如撇号、反引号、模板字面量)导致的 write_file 失败问题;并结合可靠的 TypeScript 类型检查步骤,仅过滤并显示新写入文件的输出,以避免被已有错误误导。

0 下载

介绍来源: third_party · HKUDS · 0.0.1 参考来源

SkillPi 解读

能完成的任务
使用 Python 异端脚本,加上一个可靠的 TypeScript 类型检查步骤,将输出过滤到仅新写入的文件,以避免被先前存在的错误误导,从而导致特殊字符(apostrophies, backticks,模板字节)的写入 文件失败。
适合谁
`write_file` 返回时 `[ERROR] unknown error` 用于特定文件。 文件包含TypeScript/JavaScript模板文字. 文件包含混合引用样式或类似 shell 的特殊字符. 任何时间直接文件写入失败,内容都无法轻易消毒. 在写入TypeScript文件后,需要可靠的类型检查.
输入和输出
** 无输出 / 空结果 ** — grep 在您的新文件中没有发现错误 。 ✅ 文件是类型正确的(在别处先前存在的错误无关). ** 线条已打印 ** — 您的新文件中存在类型错误 。 修复和重新检查。 示例干净输出( 无新错误 ) : 有错误的示例:
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: write-special-chars-ts-check
description: 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.

Write File Special Characters Workaround (with TypeScript Verification)

Problem

The write_file tool may fail with [ERROR] unknown error when file content contains special characters such as:

  • Apostrophes / single quotes (')
  • Backticks (`)
  • Template literals (`${variable}`) common in TypeScript/JavaScript
  • Complex combinations of quotes and escape sequences

This is especially common when writing TypeScript, JavaScript, shell scripts, or any source file with string interpolation syntax.

Additionally, after writing TypeScript files, you need to verify they are type-correct — but common methods like npx tsc or ./node_modules/.bin/tsc can fail with [ERROR] unknown error due to timeout or symlink resolution issues. The reliable method is to call the TypeScript binary directly.

Solution: Python Heredoc Workaround + Direct TSC Verification

Phase 1: Write Files via Python Heredoc

Write a small Python script to /tmp/ that uses triple-quoted strings to embed the file content, then execute it with python3.

Step-by-Step

  1. Compose a Python writer script using triple-quoted strings ("""...""").
  2. Write the Python script itself to /tmp/ — its content is plain enough that write_file will succeed (no problematic characters in the wrapper).
  3. Execute the script with run_shell: python3 /tmp/write_<name>.py

Escaping Rules Inside the Python Script

Character How to handle
Backslash \ Escape as \\
Triple double-quote """ Escape as \"\"\" or use ''' strings instead
Everything else (backticks, $, ', {}) No escaping needed

Template

#!/usr/bin/env python3
content = """
<YOUR FILE CONTENT HERE>
""".lstrip("\n")

with open("/path/to/target/file.ts", "w") as f:
    f.write(content)

print("File written successfully.")

Concrete Example

Suppose you need to write a TypeScript file with template literals and apostrophes that causes write_file to fail:

Step 1 — Write the Python helper to /tmp/:

Use write_file with path /tmp/write_greeting.py and content:

#!/usr/bin/env python3
content = """
export function greet(name: string): string {
  const msg = `Hello, ${name}! It's a great day.`;
  console.log(`Greeting: ${msg}`);
  return msg;
}
""".lstrip("\n")

with open("/app/src/greeting.ts", "w") as f:
    f.write(content)

print("Written: /app/src/greeting.ts")

Step 2 — Execute the helper:

python3 /tmp/write_greeting.py

Step 3 — Verify the file was created:

cat /app/src/greeting.ts

Phase 2: TypeScript Type-Checking (Reliable Method)

After writing TypeScript files, always verify they introduce zero new type errors. Use the direct binary path — not npx or .bin symlinks, which are prone to timeout and path-resolution failures.

The Reliable TSC Command

node node_modules/typescript/bin/tsc --noEmit 2>&1 | grep "src/greeting.ts"

Key points:

  • node node_modules/typescript/bin/tsc — invokes TypeScript directly via node, bypassing npx overhead and symlink resolution entirely.
  • --noEmit — type-checks only; does not write output files.
  • 2>&1 — merges stderr into stdout so grep can filter everything.
  • | grep "<filename>" — filters output to only lines mentioning your newly-written file(s), so pre-existing errors in other files do not create false alarms.

Why Not npx or .bin Symlinks?

Method Risk
npx tsc --noEmit Frequently returns [ERROR] unknown error (timeout, network, PATH issues)
./node_modules/.bin/tsc --noEmit Symlink resolution can fail in some environments
node node_modules/typescript/bin/tsc --noEmit Reliable — direct JS execution, no symlinks, no network

Filtering for Multiple New Files

When you've written several files, pipe through a more specific grep pattern:

node node_modules/typescript/bin/tsc --noEmit 2>&1 | grep -E "src/(greeting|utils|component)\.ts"

Or use a directory prefix to catch all new files in one folder:

node node_modules/typescript/bin/tsc --noEmit 2>&1 | grep "src/myfeature/"

Interpreting the Output

  • No output / empty result — grep found no errors in your new files. ✅ The files are type-correct (pre-existing errors elsewhere are unrelated).
  • Lines printed — type errors exist in your new files. ❌ Fix and re-check.

Example clean output (no new errors):

(no output)

Example with errors:

src/greeting.ts(3,14): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.

Full End-to-End Example

Writing multiple TypeScript files and verifying them

Step 1 — Write the Python helper to /tmp/:

Use write_file with path /tmp/write_settings_files.py:

#!/usr/bin/env python3
import os

files = {
    "/app/src/settings/settings-keys.ts": """
export const SETTINGS_KEYS = {
  theme: 'app.theme',
  language: 'app.language',
} as const;

export type SettingKey = keyof typeof SETTINGS_KEYS;
""".lstrip("\n"),

    "/app/src/settings/settings-store.ts": """
import { SETTINGS_KEYS, SettingKey } from './settings-keys';

export class SettingsStore {
  private data: Record<string, string> = {};

  get(key: SettingKey): string | undefined {
    return this.data[SETTINGS_KEYS[key]];
  }

  set(key: SettingKey, value: string): void {
    this.data[SETTINGS_KEYS[key]] = value;
  }
}
""".lstrip("\n"),
}

for path, content in files.items():
    os.makedirs(os.path.dirname(path), exist_ok=True)
    with open(path, "w") as f:
        f.write(content)
    print(f"Written: {path}")

Step 2 — Execute the helper:

python3 /tmp/write_settings_files.py

Step 3 — Verify file contents:

cat /app/src/settings/settings-keys.ts
cat /app/src/settings/settings-store.ts

Step 4 — Type-check only the new files:

cd /app && node node_modules/typescript/bin/tsc --noEmit 2>&1 | grep "src/settings/"

Expected output if all is well: (empty — no errors in the new files)

Step 5 — Optional cleanup:

rm /tmp/write_settings_files.py

When to Use This Pattern

  • write_file returns [ERROR] unknown error for a specific file.
  • The file contains TypeScript/JavaScript template literals.
  • The file contains mixed quote styles or shell-like special characters.
  • Any time direct file writing fails and content cannot be easily sanitized.
  • After writing TypeScript files and needing reliable type-checking.

Multiple Files

For writing several problematic files in one pass, consolidate them into a single Python script:

#!/usr/bin/env python3
import os

files = {
    "/app/src/component.tsx": """
import React from 'react';

const App = () => (
  <div className={`container`}>
    <h1>It's working!</h1>
  </div>
);

export default App;
""".lstrip("\n"),

    "/app/src/utils.ts": """
export const format = (val: number) => `Value: ${val.toFixed(2)}`;
""".lstrip("\n"),
}

for path, content in files.items():
    os.makedirs(os.path.dirname(path), exist_ok=True)
    with open(path, "w") as f:
        f.write(content)
    print(f"Written: {path}")

Key Advantages

  • No shell escaping required — Python triple-quoted strings are literal.
  • Handles all TypeScript syntax — template literals, generics, JSX, etc.
  • Atomic — the target file is only created if the Python script succeeds.
  • Debuggable — the intermediate .py file can be inspected if needed.
  • Reliable type-checking — direct node invocation avoids npx/symlink failures.
  • Targeted verification — grep filtering isolates errors in new files only, preventing pre-existing project errors from masking or confusing results.
  • Cleanup (optional): rm /tmp/write_*.py after all files are written.

当前收录版本

0.0.1

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值92/100

亮点

  • 解决 write_file 工具在处理特殊字符时失败的实际痛点
  • 提供可靠 TypeScript 类型检查方法,显著提升开发效率
  • 适用于高频开发场景,具有广泛实用价值
触发精准88/100

亮点

  • 触发词精准完整,覆盖多种变体
  • 边界清晰,避免误触/漏触
结构规范95/100

亮点

  • Phase/步骤清晰,有出口条件
  • 含端到端示例,frontmatter完整
  • 单文件≤500行,结构规范
执行可靠90/100

亮点

  • 工具来源明确,参数正确
  • 覆盖主要异常,不可逆操作有确认机制
  • 提供可靠的执行流程和错误处理
证据可验 (前四项均值)91/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。