fix: book create recovers from interrupted init + ensure chapters dir

This commit is contained in:
Ma
2026-03-16 22:43:35 +08:00
parent 5e29461b82
commit bc6c7a1c00
3 changed files with 21 additions and 6 deletions
+9 -1
View File
@@ -45,7 +45,15 @@ bookCommand
const bookDir = join(root, "books", bookId);
try {
await access(bookDir);
throw new Error(`Book "${bookId}" already exists at books/${bookId}/. Use a different title or delete the existing book first.`);
// Directory exists — check if it's a complete book or an interrupted init
try {
await access(join(bookDir, "story", "story_bible.md"));
throw new Error(`Book "${bookId}" already exists at books/${bookId}/. Use a different title or delete the existing book first.`);
} catch (inner) {
if (inner instanceof Error && inner.message.includes("already exists")) throw inner;
// story_bible.md missing → incomplete init, allow re-run
if (!opts.json) log(`Resuming incomplete book creation for "${bookId}"...`);
}
} catch (e) {
if (e instanceof Error && e.message.includes("already exists")) throw e;
// Directory doesn't exist, good
+3
View File
@@ -186,6 +186,9 @@ export class PipelineRunner {
const { profile: gp } = await this.loadGenreProfile(book.genre);
const foundation = await architect.generateFoundation(book, this.config.externalContext);
await architect.writeFoundationFiles(bookDir, foundation, gp.numericalSystem);
// Ensure chapters directory exists (prevents ENOENT if init was previously interrupted)
await mkdir(join(bookDir, "chapters"), { recursive: true });
await this.state.saveChapterIndex(book.id, []);
}
+9 -5
View File
@@ -1,7 +1,7 @@
---
name: inkos
description: Autonomous novel writing CLI agent - use for creative fiction writing, novel generation, style imitation, chapter continuation/import, and AIGC detection. Supports Chinese web novel genres (xuanhuan, xianxia, urban, horror, other) with multi-agent pipeline, two-phase writer (creative + settlement), and 33-dimension auditing.
version: 1.1.0
description: Autonomous novel writing CLI agent - use for creative fiction writing, novel generation, style imitation, chapter continuation/import, EPUB export, and AIGC detection. Supports Chinese web novel genres (xuanhuan, xianxia, urban, horror, other) with multi-agent pipeline, two-phase writer (creative + settlement), 33-dimension auditing, and token usage analytics.
version: 1.3.0
metadata: { "openclaw": { "emoji": "📖", "requires": { "bins": ["inkos", "node"], "env": [] }, "primaryEnv": "", "homepage": "https://github.com/Narcooo/inkos", "install": [{ "id": "npm", "kind": "node", "package": "@actalk/inkos", "label": "Install InkOS (npm)" }] } }
---
@@ -67,9 +67,10 @@ inkos status
inkos review approve-all book-id
```
4. **Export the book**:
4. **Export the book** (supports txt, md, epub):
```bash
inkos export book-id
inkos export book-id --format epub
```
### Workflow 2: Continue Writing Existing Novel
@@ -195,10 +196,13 @@ inkos detect book-id --all
```bash
inkos analytics book-id --json
# Shorthand alias
inkos stats book-id --json
```
- Total chapters, word count, average words per chapter
- Audit pass rate and top issue categories
- Chapters with most issues, status distribution
- **Token usage stats**: total prompt/completion tokens, avg tokens per chapter, recent trend
## Advanced: Natural Language Agent Mode
@@ -290,8 +294,8 @@ inkos genre copy xuanhuan --name "dark-xuanhuan" --rules "darker tone, more viol
| `inkos import canon` | Link spinoff to parent | For prequels/sequels |
| `inkos import chapters` | Import existing chapters | Reverse-engineers truth files for continuation |
| `inkos detect` | AIGC detection | Flags AI-generated passages |
| `inkos export` | Export finished book | Outputs formatted manuscript |
| `inkos analytics` | View book statistics | Word count, audit rates, issues |
| `inkos export` | Export finished book | Formats: txt, md, epub |
| `inkos analytics` / `inkos stats` | View book statistics | Word count, audit rates, token usage |
| `inkos radar scan` | Platform trend analysis | Informs new book ideas |
| `inkos config set-global` | Configure LLM provider | OpenAI/Anthropic/compatible |
| `inkos doctor` | Diagnose issues | Check installation |