提供基于文件系统的进程间通信模式,适合无消息队列的本地协作场景
整体看起来是低风险:这是一个纯提示词/模式说明的 Skill,且已判定为 prompt-only、open-source,没有密钥和远程端点。主要注意点仅在于它会指导本地文件式进程通信与读写工作目录。
未声明任何密钥、token 或环境变量;按材料看不涉及凭证收集或滥用。
未提供任何远程端点 host,也未描述向外部服务传输用户数据。
材料描述的是文件式 IPC 模式,可涉及本机进程间通信与异步桥接,但未见额外系统权限或任意代码执行红旗。
会读写工作目录中的 events.jsonl、state.json 及请求/响应文件,属于常规本地文件访问范围;未见越权访问描述。
来源为 GitHub 开源仓库且材料可审计,但许可证未声明、star 为 0、维护状态未知,供应链可信度一般。
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "file-ipc-patterns" 技能: 1. 下载 https://raw.githubusercontent.com/microsoft/amplifier-bundle-skills/main/skills/file-ipc-patterns/SKILL.md 2. 保存为 ~/.claude/skills/file-ipc-patterns/SKILL.md 3. 装好后重载技能,告诉我可以用了
请为两个本地进程设计一个基于 JSONL 文件追加写入的事件通信方案,包含事件字段规范、写入与消费流程、去重策略、文件轮转建议,以及 Python 示例代码。
返回可落地的 JSONL IPC 设计说明、字段定义、流程图思路与示例代码。
我需要让一个进程持续写入最新状态,另一个进程随时读取且不能读到半成品。请设计基于临时文件加重命名的原子快照方案,并给出异常恢复和跨平台注意事项。
返回原子写入方案、读取约定、容错机制及示例实现建议。
请设计一个无需消息中间件的异步请求/响应机制:客户端写入 request 文件,服务端生成 response 文件。需要包含命名规则、超时处理、并发隔离、状态追踪和示例伪代码。
返回基于文件对的异步通信模式,包含目录结构、时序说明与伪代码。
Problem: You have multiple processes (a web server and a container worker, or a host process and a spawned subprocess) that need to exchange messages and stream events. They don't share memory, and you don't want the complexity of a message broker.
Approach: Use the filesystem as the message bus. JSON files as request/response pairs, JSONL append-only logs as event streams, and atomic state.json snapshots for current status. Bridge async code with asyncio.Future objects that resolve when response files appear.
Pattern proven in production across multiple Python CLI tools and web services.
state.json snapshotThe EventEmitter writes two complementary files:
events.jsonl — append-only, one JSON object per line, flushed immediately so tail -f worksstate.json — atomic overwrite of current status, always a complete snapshotdef emit(self, event_type: str, *, phase=None, data=None) -> None:
"""Append a structured event to events.jsonl. Flushes immediately."""
record = {
"schema_version": SCHEMA_VERSION,
"timestamp": datetime.now(UTC).isoformat(),
"instance_id": self._instance_id,
"event_type": event_type,
"phase": phase,
"data": data if data is not None else {},
}
line = json.dumps(record, separators=(",", ":")) + "\n"
with self._lock, (self._work_dir / "events.jsonl").open("a") as fh:
fh.write(line)
fh.flush() # immediate for tail -f
The state snapshot uses atomic write:
def update_state(self, **kwargs) -> None:
"""Overwrite state.json atomically via os.replace."""
snapshot = {
"instance_id": self._instance_id,
"updated_at": datetime.now(UTC).isoformat(),
**kwargs,
}
target = self._work_dir / "state.json"
fd, tmp_path = tempfile.mkstemp(dir=self._work_dir, prefix=".state-", suffix=".tmp")
try:
with os.fdopen(fd, "w") as fh:
json.dump(snapshot, fh)
Path(tmp_path).replace(target) # atomic on POSIX
except Exception:
Path(tmp_path).unlink(missing_ok=True)
raise
Why two files: events.jsonl is the complete history (for replay, debugging, SSE streaming). state.json is the current status (for quick reads without scanning the entire log).
Input requests use a file-per-request convention:
async def request_input(self, request_id, schema):
"""Write a human-input request file and return a Future for the response."""
# Validate request_id to prevent path traversal
safe_name = Path(request_id).name
if not safe_name or safe_name != request_id:
raise ValueError(f"Invalid request_id: {request_id!r}")
input_requests_dir = self._work_dir / "input-requests"
input_requests_dir.mkdir(parents=True, exist_ok=True)
request_data = {
"request_id": request_id,
"schema": schema,
"requested_at": datetime.now(UTC).isoformat(),
}
request_file = input_requests_dir / f"{safe_name}.json"
request_file.write_text(json.dumps(request_data, indent=2))
# Create an asyncio.Future that will be resolved when the response arrives
loop = asyncio.get_running_loop()
future = loop.create_future()
self._pending_futures[request_id] = future
return future
asyncio.Future + file watcher for async request/responseThe request creates a Future. When the response arrives (via an API call from the UI), the Future is resolved thread-safely:
def resolve_input_request(self, request_id, payload):
"""Resolve the pending Future for the given request_id."""
future = self._pending_futures.pop(request_id, None)
if future is None:
return
…
帮助你安全编排 Docker 容器任务,并搭建可复现的开发运行环境
帮助你调研、规划并并行执行大规模代码变更,让多个代理分别提交 PR。
以资深工程师视角审视架构、遗留重构与工具选型,给出务实建议。
用多模型视觉能力分析图片内容、提取文字并回答图像相关问题。
帮助开发者设计安全持久的配置与状态文件管理模式,兼顾默认值合并和崩溃恢复。
帮助开发者构建含生命周期管理、WebSocket与SSE的 HTTP 服务模式
提供安全的跨平台文件系统操作,支持读写、路径处理与编码管理。
通过 MCP 执行文件读写、检索与批量处理,提升自动化文件操作效率。
增强型文件系统 MCP 工具,可搜索、读取、编辑、删除文件并执行命令。
通过 MCP 调用文件系统操作与兼容 OpenAI 的文本生成能力
提供遵循 .gitignore 的文件系统操作,帮助 AI 更高效读取项目文件。
让同机上的 Claude Code 实例通过文件与 JSON 通道稳定协作通信。