Project Root Guard (must be confirmed first)
- Must be executed in the project root directory (requires the existence of
.webnovel/state.json) - Use the unified entry point to resolve the project root to avoid writing to the wrong directory:
export WORKSPACE_ROOT="${CLAUDE_PROJECT_DIR:-$PWD}"
export SCRIPTS_DIR="${CLAUDE_PLUGIN_ROOT:?}/scripts"
export PROJECT_ROOT="$(python -X utf8 "${SCRIPTS_DIR}/webnovel.py" --project-root "${WORKSPACE_ROOT}" where)"
Goal
Extract reusable writing patterns (hooks/pacing/dialogue/micro-payoffs, etc.) and append them to .webnovel/project_memory.json。
Execution Flow
- Read
"$PROJECT_ROOT/.webnovel/state.json"'sprogress.current_chapteras the current chapter number; if missing, usesource_chapter: null, without blocking. - Parse the user input (the experience text after
/webnovel-learn; if empty, take the writing approach approved by the user in this conversation), and categorize it aspattern_type(hook/pacing/dialogue/payoff/emotion/format/other; if it cannot be categorized, useother)。 - Call
project-memory add-patternto write; do not hand-write or concatenate JSON:
python -X utf8 "${SCRIPTS_DIR}/webnovel.py" --project-root "${PROJECT_ROOT}" project-memory add-pattern \
--pattern-type "{pattern_type}" \
--description "{用户输入或提炼后的完整描述}" \
--category "{分类,可空}" \
--importance "{high|medium|low}"
Constraints
- Do not delete old records; only append.
- Before appending, scan existing
patterns;pattern_type+description; if completely identical, skip and inform the user; partially similar entries are not deduplicated. - Do not use
Writeor manually edit.webnovel/project_memory.json。
Success Criteria
project_memory.jsonexists and is in a valid format, and the new pattern has been appended to thepatternsarray.- The output includes
status: successand the completelearnedobject.
Failure Recovery
| Failure | Recovery Method |
|---|---|
project_memory.json does not exist |
The script automatically initializes {"patterns": []} and then continues |
| JSON parsing fails | Do not write dirty data; inform the user that the file is corrupted and suggest manual repair |
state.json is missing, so the chapter number cannot be obtained |
Use source_chapter: null, without blocking |