← 返回 Skills 市场
183
总下载
0
收藏
0
当前安装
2
版本数
在 OpenClaw 中安装
/install contextstable
功能描述
长小说文章上下文稳定输出续写
使用说明 (SKILL.md)
Context Stabilizer Skill
技能名称
Context Stabilizer(长文本上下文稳定器)
技能描述
用于稳定长文本生成的上下文一致性,自动提取核心设定并确保生成内容符合设定。
功能特点
- 自动锚点提取:从文本中自动提取人设、世界观、核心剧情、文风等核心设定
- 增强提示词生成:智能组合相关上下文和锚点,生成更准确的提示词
- 一致性检查:分维度检查生成内容的一致性(人设/剧情/文风/世界观)
- 历史记录管理:追踪多轮对话历史,支持角色状态和剧情时间线管理
- 滑动窗口管理:智能处理超长文本,支持重要片段标记
- 缓存机制:提高嵌入向量计算效率
适用场景
- 小说/故事续写
- 长文档生成
- 多轮对话场景
- 角色设定保持
- 世界观一致性维护
安装依赖
pip install -r requirements.txt
基本使用
from context_stabilizer import LongTextContextStabilizer
# 初始化
stabilizer = LongTextContextStabilizer()
# 添加长文本(自动提取锚点)
long_text = "你的长文本内容..."
stabilizer.init_long_text(long_text, auto_extract=True)
# 生成增强提示词
user_prompt = "你的续写需求..."
enhanced_prompt = stabilizer.get_enhanced_prompt(user_prompt)
# 检查一致性
llm_output = "LLM生成的内容..."
check_result = stabilizer.check_consistency(llm_output, detailed=True)
# 记录历史
stabilizer.record_generation(user_prompt, enhanced_prompt, llm_output, check_result)
高级用法
自定义配置
from context_stabilizer.config import ContextConfig, ConsistencyConfig
custom_config = ContextConfig(
consistency=ConsistencyConfig(threshold=0.75),
history=ContextConfig.__annotations__['history'].__args__[0](
max_history=200, auto_save=True
)
)
stabilizer = LongTextContextStabilizer(custom_config)
手动设置锚点
manual_anchors = {
"人设": "角色设定...",
"世界观": "世界观设定...",
"核心剧情": "剧情设定...",
"文风": "文风设定..."
}
stabilizer.init_long_text(long_text, manual_anchors=manual_anchors, auto_extract=False)
标记重要片段
stabilizer.mark_important_segment(
content="重要内容...",
reason="重要原因...",
importance=2.0
)
保存和加载会话
stabilizer.save_session("session_name")
stabilizer.load_session("session_name")
输出示例
增强提示词
请根据以下需求和上下文,续写/创作文本,严格遵守核心设定,保持文风一致:
【用户需求】
续写第三章,李逍遥和赵灵儿在破庙休息时遭遇拜月教小喽啰袭击
【相关上下文】
第一章 初入江湖
李逍遥,18岁,性格洒脱,嫉恶如仇,手持一把生锈的铁剑,从小在余杭镇长大。
这天,他离开家乡,准备前往苏州城,寻找失散多年的婶婶。
第二章 偶遇灵儿
在去苏州的路上,李逍遥遇到了一位名叫赵灵儿的少女,她温柔善良,身负女娲族的血脉,正被拜月教追杀。
李逍遥出手相救,两人结伴同行。
【核心设定】
人设:李逍遥:18岁,洒脱,嫉恶如仇;赵灵儿:温柔善良,女娲族血脉
世界观:古风武侠仙侠世界
核心剧情:李逍遥寻找婶婶,偶遇赵灵儿,结伴前往苏州城
文风:古风武侠,语言简洁,情感细腻
要求:1. 剧情连贯,不偏离核心设定;2. 人设统一,无矛盾;3. 文风与前文一致。
一致性检查结果
总体一致性: ✓ 通过
发现问题数: 0
各维度评分:
character: 1.00
plot: 1.00
style: 0.90
world: 1.00
改进建议:
无
技术原理
- 文本分块:将长文本分割成适当大小的块
- 锚点提取:自动识别和提取核心设定
- 上下文检索:基于关键词匹配或向量相似度检索相关上下文
- 一致性检查:分维度评估生成内容与设定的一致性
- 历史管理:追踪生成历史,支持多轮对话
注意事项
- 首次运行时会自动下载 sentence-transformers 模型(需要网络连接)
- 对于超长文本,滑动窗口会自动管理上下文大小
- 可通过配置调整分块大小、一致性阈值等参数
- 支持导出故事为 txt 或 json 格式
安全使用建议
This skill appears to do what it claims (extract anchors, manage sliding windows, produce enhanced prompts, and check consistency). Before installing or running it: 1) Run it in an isolated environment (virtualenv/container) because dependencies like faiss-cpu and sentence-transformers can be heavy and install native code. 2) Be prepared for automatic model downloads (sentence-transformers) on first run — ensure you are happy with network access. 3) Do not load pickle files from untrusted sources: the embedding cache uses pickle for persistence, which can execute code when loading; if you enable persistence (persist_dir) or auto-save, point it to a directory you control and avoid sharing those files. 4) Consider setting history.auto_save to false until you review where files are written, and inspect the remaining (truncated) module files (especially __init__.py and vector_store.py) for any network calls or unexpected behavior before enabling automatic features. 5) If you need stricter safety, modify the code to use safe serialization (JSON) for cache persistence or disable loading of persisted caches.
功能分析
Type: OpenClaw Skill
Name: contextstable
Version: 0.0.2
The skill bundle provides a comprehensive framework for maintaining context and consistency in long-form text generation (e.g., novel writing). It implements sophisticated features including automated anchor extraction for characters and world-building (scripts/anchor_extractor.py), sliding window context management (scripts/context_window.py), and multi-dimensional consistency checking (scripts/consistency_checker.py). While the code uses the 'pickle' module for optional embedding cache persistence in scripts/cache_manager.py (which is a known security vulnerability for arbitrary code execution if the cache file is tampered with), there is no evidence of malicious intent or self-exploitation. The behavior is entirely consistent with the stated purpose, and the instructions in SKILL.md are focused on legitimate text generation tasks.
能力评估
Purpose & Capability
Name/description (长文本上下文稳定输出续写) match the provided code and SKILL.md: anchor extraction, chunking, sliding windows, embedding caching, history management and consistency checking. Required Python packages (sentence-transformers, faiss, langchain, pydantic, numpy via deps in files) are reasonable for embedding/vector workflows.
Instruction Scope
SKILL.md instructions focus on initializing text, extracting anchors, generating enhanced prompts, consistency checks and history management. The runtime instructions do not ask the agent to read unrelated system files or environment secrets. It does note that sentence-transformers models will be downloaded on first run (expected).
Install Mechanism
No custom install script; dependencies are via pip (requirements.txt). This is an expected mechanism for a Python library. Be aware some deps (faiss-cpu, sentence-transformers, langchain-community) are heavy and may require native build tools or platform-specific wheels; model downloads occur at runtime.
Credentials
The skill requests no environment variables, no credentials, and no special config paths in its metadata. Code writes/reads session, cache and export files only when explicitly asked (save/load/export functions). There are no unexpected credential accesses.
Persistence & Privilege
The implementation persists caches and history to disk. EmbeddingCache.save_to_disk/_load_from_disk uses pickle to store/load cache data; untrusted pickle files can lead to arbitrary code execution if later loaded. History and export functions write JSON/txt. While persistence is reasonable for a stateful text tool, the use of pickle for disk loading is a security risk and should be used only in controlled directories and with trusted files.
如何使用
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install contextstable - 安装完成后,直接呼叫该 Skill 的名称或使用
/contextstable触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v0.0.2
- Added a new metadata file (_meta.json) to the project.
- No changes to code or main documentation content.
- Internal skill metadata is now more structured and discoverable.
v0.0.1
Initial release of Context Stabilizer for long-form text consistency.
- Automatically extracts core settings (character, world, plot, style) from long texts as anchors.
- Generates enhanced prompts incorporating contextual anchors for improved text continuation.
- Performs multi-dimensional consistency checks on generated content (character, plot, style, world).
- Manages dialog history with support for role states and timeline tracking.
- Implements sliding window and important segment marking for handling very long texts.
- Includes caching for efficient embedding calculations.
- Supports session saving/loading and advanced configuration options.
元数据
常见问题
contextstable 是什么?
长小说文章上下文稳定输出续写. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 183 次。
如何安装 contextstable?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install contextstable」即可一键安装,无需额外配置。
contextstable 是免费的吗?
是的,contextstable 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
contextstable 支持哪些平台?
contextstable 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 contextstable?
由 YIYIYIba(@yiyiyiba)开发并维护,当前版本 v0.0.2。
推荐 Skills