Skip to content

Commit 81ee875

Browse files
authored
Merge pull request #10 from pickbitsai/agent/weaver-s7-studio
Story-so-far setup, reviews with triage and rulings, and the studio
2 parents 22b6370 + 331f240 commit 81ee875

32 files changed

Lines changed: 2210 additions & 26 deletions

‎README.md‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ npx weaver status --root ./my-book
4747
npx weaver grounding 1-1 --root ./my-book
4848
```
4949

50+
## The studio
51+
52+
Start the local author page with `weaver studio --root ./my-book`. It listens
53+
only on `127.0.0.1:4187`; open `http://127.0.0.1:4187/` on the same computer.
54+
Use `--port N` to choose another port, or set `"studio": { "port": N }` in
55+
`project.json`. The studio works offline and uses no web services for its pages.
56+
Review and bootstrap jobs use the book's configured command-line AI host.
57+
58+
The home page shows approval progress and findings. Book is the reader, with
59+
chapter and scene status. Character pages show aliases, voice evidence, facts,
60+
and spoken scenes. Places and Threads follow the facts ledger and narrative
61+
state. Findings is the decision queue, Changes compares approved and new text,
62+
History shows decisions and offers undo, and Jobs runs review or story-so-far
63+
bootstrap and lets the author read and accept the resulting state. The doctor footer appears on every page. Every button performs the
64+
same engine action as its matching Weaver command and obeys the same doctor
65+
refusal. The author can read and decide entirely on the local page.
66+
5067
## Repair a finished book
5168

5269
Use one Weaver project for each book in a series. Start an empty book, import
@@ -136,6 +153,33 @@ manuscript hash and Git commit; working-tree edits do not make them stale.
136153
Voice findings are warnings for the author to judge; Weaver never decides that
137154
a voice is right.
138155

156+
## Reviews and triage
157+
158+
Run the continuity, style, and critic lenses for one chapter with
159+
`weaver review --chapter 1 --run --root ./my-book`. The configured host runs the
160+
three lenses concurrently. Omit `--run` to write interactive packets, then use
161+
`weaver submit <packet-id> --file <answer>`. Reviews cite a scene, paragraph,
162+
and verbatim reader-text quote; invalid citations are dropped. A review becomes
163+
out of date when its chapter prose changes, or when the continuity facts context
164+
changes.
165+
166+
`weaver findings --root ./my-book` gives the author one queue across rules,
167+
voice, and reviews. Definite review problems enter the queue. A failing critic
168+
adds at most its first two craft or definite findings. Other review findings
169+
remain notes, visible with `weaver findings --all`. At most six review findings
170+
are queued per chapter, with continuity before style before critic. The queue
171+
also reports out-of-date reviews. Every finding has a stable ID.
172+
173+
## Rulings
174+
175+
Decide once with `weaver rule <finding-id> --decision fix|allow|intended
176+
--root ./my-book`. `fix` keeps the item in `weaver findings --to-fix`; `allow`
177+
and `intended` suppress it while its paragraph stays unchanged. Editing the
178+
paragraph lapses the ruling and shows the finding again with a lapse note.
179+
`weaver rulings` shows active, lapsed, and resolved decisions. Each decision is
180+
its own Git commit containing only `continuity/rulings.json`. Allowed blocking
181+
style findings are listed by ID in `check` and `approve` output.
182+
139183
## Claude Code hooks
140184

141185
Run `weaver hooks install --root ./my-book` to merge Weaver's PreToolUse and
@@ -181,6 +225,38 @@ npx weaver release --root ./my-book --id beta-01
181225
If an earlier scene changes, `state:status` marks it and all later scenes stale.
182226
Re-derive them in order before accepting state again.
183227

228+
## Story-so-far setup
229+
230+
Imported books have prose but no trusted scene-by-scene story-so-far records.
231+
Bootstrap derives those records and a facts ledger before release. Weaver only
232+
builds packets and checks answers; a configured command-line host does the AI
233+
work, and the author still accepts the resulting state:
234+
235+
```bash
236+
npx weaver state bootstrap --run --root ./my-book
237+
npx weaver state:accept --through 3-2 --root ./my-book
238+
npx weaver facts build --root ./my-book
239+
```
240+
241+
For an interactive Claude Code session, print one packet and submit its answer:
242+
243+
```bash
244+
npx weaver packet state --scene 1-1 --root ./my-book
245+
npx weaver submit <packet-id> --file ./answer.md --root ./my-book
246+
```
247+
248+
Answers contain a Markdown narrative-state record and a fenced JSON facts
249+
block. Every fact quote must be a verbatim 3–25 word excerpt from that scene;
250+
quotes from elsewhere are rejected, including after the single repair round.
251+
`continuity/facts.json` is deterministic derived state: it keeps facts in scene
252+
order and records the first scene that establishes each normalized value.
253+
254+
The host defaults to Claude Code (`claude -p --output-format text`) and can be
255+
set in `project.json` with `host.command`, `host.args`, `host.concurrency`, and
256+
`host.timeout_seconds`. Weaver removes `ANTHROPIC_API_KEY` from the child
257+
environment, so host runs use the user's Claude subscription rather than
258+
silently billing an API key. A missing host is a doctor warning, not a block.
259+
184260
## Commands
185261

186262
| Command | Purpose |
@@ -189,20 +265,29 @@ Re-derive them in order before accepting state again.
189265
| `import <source>` | Import a finished DOCX, Markdown, text file, or folder into an empty book |
190266
| `export --format md\|docx --out <file>` | Export the current manuscript without overwriting the source or an existing file |
191267
| `doctor` | Check the book folder, Git, host, and Weaver installation |
268+
| `studio` | Open the local author page (`--port N` supported) |
192269
| `status` | Summarize manuscript hash, words, scenes, and state freshness |
193270
| `check` | Run project, critical-path, repetition, and state gates |
194271
| `rules` | Run deterministic style rules (`--scene`, `--json` supported) |
195272
| `characters seed` | Add imported POV names to the character registry |
196273
| `voices build` | Build deterministic character voice profiles |
197274
| `voices check` | Show voice warnings (`--scene`, `--pending`, `--json` supported) |
275+
| `review --chapter N` | Run or prepare chapter review lenses (`--lenses`, `--run` supported) |
276+
| `findings` | Show the triaged queue (`--chapter`, `--all`, `--to-fix`, `--json` supported) |
277+
| `rule <finding-id>` | Save an author decision (`--decision`, `--note` supported) |
278+
| `rulings` | List active, lapsed, and resolved decisions (`--json` supported) |
198279
| `changes` | Show pending scene edits grouped by chapter (`--json` supported) |
199280
| `approve` | Save one chapter's pending edits as an approval |
200281
| `reject` | Save and restore one chapter's pending edits |
201282
| `undo` | Revert the most recent approval with a new Git commit |
202283
| `history` | Show approvals and undos (`--json` supported) |
203284
| `hooks install` | Install or merge Claude Code scene-edit hooks |
204285
| `state:status` | Show current and stale derived-state records |
286+
| `state bootstrap` | Build story-so-far packets, optionally run them through the host |
205287
| `state:accept` | Stamp reviewed narrative state through a scene |
288+
| `packet state` | Print an interactive story-so-far packet |
289+
| `submit` | Validate and record a packet answer |
290+
| `facts build` | Rebuild the deterministic facts ledger |
206291
| `grounding <scene-id>` | Assemble the context packet for a writing pass |
207292
| `release --id <id>` | Build an immutable Markdown/HTML reader release |
208293

‎contracts/facts-ledger.schema.json‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://raw.githubusercontent.com/pickbitsai/weaver/main/contracts/facts-ledger.schema.json",
4+
"title": "Weaver facts ledger",
5+
"type": "object",
6+
"additionalProperties": false,
7+
"required": ["$schema", "generator", "manuscript_sha256", "subjects", "first_established"],
8+
"properties": {
9+
"$schema": { "const": "https://pickbits.ai/schemas/weaver/facts-ledger-1.json" },
10+
"generator": { "type": "string", "minLength": 1 },
11+
"manuscript_sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
12+
"subjects": {
13+
"type": "object",
14+
"additionalProperties": {
15+
"type": "array",
16+
"items": {
17+
"type": "object",
18+
"additionalProperties": false,
19+
"required": ["scene_id", "kind", "value", "quote"],
20+
"properties": {
21+
"scene_id": { "type": "string", "pattern": "^[0-9]+-[0-9]+$" },
22+
"kind": { "enum": ["location", "knowledge", "possession", "relationship", "event", "time"] },
23+
"value": { "type": "string", "minLength": 1 },
24+
"quote": { "type": "string", "minLength": 1 }
25+
}
26+
}
27+
}
28+
},
29+
"first_established": {
30+
"type": "array",
31+
"items": {
32+
"type": "object",
33+
"additionalProperties": false,
34+
"required": ["normalized_value", "subject", "kind", "scene_id"],
35+
"properties": {
36+
"normalized_value": { "type": "string", "minLength": 1 },
37+
"subject": { "type": "string", "minLength": 1 },
38+
"kind": { "enum": ["location", "knowledge", "possession", "relationship", "event", "time"] },
39+
"scene_id": { "type": "string", "pattern": "^[0-9]+-[0-9]+$" }
40+
}
41+
}
42+
}
43+
}
44+
}

‎contracts/facts.schema.json‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://raw.githubusercontent.com/pickbitsai/weaver/main/contracts/facts.schema.json",
4+
"title": "Weaver scene facts",
5+
"type": "object",
6+
"additionalProperties": false,
7+
"required": ["$schema", "scene_id", "prose_sha256", "packet_id", "generator", "facts"],
8+
"properties": {
9+
"$schema": { "const": "https://pickbits.ai/schemas/weaver/facts-1.json" },
10+
"scene_id": { "type": "string", "pattern": "^[0-9]+-[0-9]+$" },
11+
"prose_sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
12+
"packet_id": { "type": "string", "pattern": "^[a-f0-9]{12}$" },
13+
"generator": { "type": "string", "minLength": 1 },
14+
"facts": {
15+
"type": "array",
16+
"items": {
17+
"type": "object",
18+
"additionalProperties": false,
19+
"required": ["kind", "subject", "value", "quote"],
20+
"properties": {
21+
"kind": { "enum": ["location", "knowledge", "possession", "relationship", "event", "time"] },
22+
"subject": { "type": "string", "minLength": 1 },
23+
"value": { "type": "string", "minLength": 1 },
24+
"quote": { "type": "string", "minLength": 1 }
25+
}
26+
}
27+
}
28+
}
29+
}

‎contracts/project.schema.json‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@
3030
"reader_state_path": { "type": "string", "minLength": 1 },
3131
"outline_scene_root": { "type": "string", "minLength": 1 },
3232
"require_current_state_for_release": { "type": "boolean" },
33+
"host": {
34+
"type": "object",
35+
"additionalProperties": false,
36+
"properties": {
37+
"command": { "type": "string", "minLength": 1 },
38+
"args": { "type": "array", "items": { "type": "string" } },
39+
"concurrency": { "type": "integer", "minimum": 1, "maximum": 4 },
40+
"timeout_seconds": { "type": "integer", "minimum": 1 }
41+
}
42+
},
43+
"studio": {
44+
"type": "object",
45+
"additionalProperties": false,
46+
"properties": { "port": { "type": "integer", "minimum": 1, "maximum": 65535 } }
47+
},
3348
"chapters": {
3449
"type": "object",
3550
"additionalProperties": { "type": "string" }

‎contracts/review.schema.json‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://raw.githubusercontent.com/pickbitsai/weaver/main/contracts/review.schema.json",
4+
"title": "Weaver chapter review",
5+
"type": "object",
6+
"additionalProperties": false,
7+
"required": ["$schema", "chapter", "lens", "verdict", "findings", "dropped_findings", "chapter_prose_sha256", "facts_sha256", "packet_id", "generator"],
8+
"properties": {
9+
"$schema": { "const": "https://pickbits.ai/schemas/weaver/review-1.json" },
10+
"chapter": { "type": "integer", "minimum": 1 },
11+
"lens": { "enum": ["continuity", "style", "critic"] },
12+
"verdict": { "enum": ["CLEAR", "FLAGS", "CONSISTENT", "DRIFT", "PASS", "FAIL"] },
13+
"findings": {
14+
"type": "array",
15+
"items": {
16+
"type": "object",
17+
"additionalProperties": false,
18+
"required": ["severity", "scene_id", "paragraph", "quote", "issue", "repair"],
19+
"properties": {
20+
"severity": { "enum": ["definite", "ambiguity", "minor", "craft"] },
21+
"scene_id": { "type": "string", "pattern": "^[0-9]+-[0-9]+$" },
22+
"paragraph": { "type": "integer", "minimum": 1 },
23+
"quote": { "type": "string", "minLength": 1 },
24+
"issue": { "type": "string", "minLength": 1 },
25+
"repair": { "type": "string", "minLength": 1 }
26+
}
27+
}
28+
},
29+
"dropped_findings": { "type": "integer", "minimum": 0 },
30+
"chapter_prose_sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
31+
"facts_sha256": { "type": ["string", "null"], "pattern": "^[a-f0-9]{64}$" },
32+
"packet_id": { "type": "string", "pattern": "^[a-f0-9]{12}$" },
33+
"generator": { "type": "string", "minLength": 1 }
34+
}
35+
}

‎contracts/rulings.schema.json‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://raw.githubusercontent.com/pickbitsai/weaver/main/contracts/rulings.schema.json",
4+
"title": "Weaver author rulings",
5+
"type": "object",
6+
"additionalProperties": false,
7+
"required": ["$schema", "generator", "entries"],
8+
"properties": {
9+
"$schema": { "const": "https://pickbits.ai/schemas/weaver/rulings-1.json" },
10+
"generator": { "type": "string", "minLength": 1 },
11+
"entries": {
12+
"type": "array",
13+
"items": {
14+
"type": "object",
15+
"additionalProperties": false,
16+
"required": ["finding_id", "kind", "source", "scene_id", "paragraph", "passage_sha256", "decision", "note", "ruled_at", "generator"],
17+
"properties": {
18+
"finding_id": { "type": "string", "pattern": "^[a-f0-9]{10}$" },
19+
"kind": { "enum": ["rule", "voice", "judgment"] },
20+
"source": { "type": "string", "minLength": 1 },
21+
"scene_id": { "type": "string", "pattern": "^[0-9]+-[0-9]+$" },
22+
"paragraph": { "type": "integer", "minimum": 1 },
23+
"passage_sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
24+
"decision": { "enum": ["fix", "allow", "intended"] },
25+
"note": { "type": "string" },
26+
"ruled_at": { "type": "string", "format": "date-time" },
27+
"generator": { "type": "string", "minLength": 1 }
28+
}
29+
}
30+
}
31+
}
32+
}

‎docs/WORKFLOW.md‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Writing and revision workflow
22

3+
## The author's daily loop in the studio
4+
5+
Open the local page started by `weaver studio --root ./my-book`. On Home, check
6+
approved chapters, open findings, and the doctor footer. Read Book by chapter
7+
and scene; paragraph markers lead to the relevant finding. Character, Place,
8+
and Thread pages provide the current story context.
9+
10+
On Jobs, run a chapter review or bootstrap story-so-far state. Read each new
11+
state record there and explicitly accept it before release. Return to
12+
Findings, read the cited passage and suggested repair, then choose **Fix this**,
13+
**It's intended**, or **Allow**. Recheck a changed passage because its earlier
14+
ruling may lapse. Open Changes to compare approved and new paragraphs and
15+
their style findings. Approve or reject one chapter there. History records the
16+
decisions and offers a confirmed undo of the last approval. The studio calls
17+
the same engine operations as the matching commands below, including their
18+
doctor refusal.
19+
320
## 0. Check the setup
421

522
Before working on a book, run:
@@ -10,6 +27,13 @@ weaver doctor --root ./my-book
1027

1128
## Repair path
1229

30+
For each chapter, run `weaver review --chapter N --run`, then inspect
31+
`weaver findings --chapter N`. Use `--all` to see lower-priority review notes.
32+
Decide an item with `weaver rule <finding-id> --decision fix|allow|intended`.
33+
Work from `weaver findings --to-fix --chapter N` for requested repairs, rerun
34+
the reviews after prose changes, then approve the chapter. An allowed blocking
35+
style finding appears in the approval and check audit output by ID.
36+
1337
For a finished book, create a separate Weaver project with `--empty`; this
1438
removes the starter scene and starter critical-path fixture while preserving
1539
the generic project configuration. Importing never merges with existing scene
@@ -32,6 +56,22 @@ chapter and scene counts, POV decisions, and scene word counts. Imported books
3256
begin with missing or stale narrative state by design; `check` reports that
3357
state but does not fail on it until the project's state workflow is bootstrapped.
3458

59+
Before release, bootstrap the story-so-far records and facts ledger. The host
60+
answers deterministic packets, then the author reviews and accepts the records:
61+
62+
```bash
63+
weaver state bootstrap --run --root ./my-book
64+
weaver state:accept --through 3-2 --root ./my-book
65+
weaver facts build --root ./my-book
66+
```
67+
68+
The interactive route is `weaver packet state --scene 1-1`, followed by
69+
`weaver submit <packet-id> --file answer.md`. A malformed or deterministic
70+
validation failure gets one host repair attempt. Scene facts must use registry
71+
IDs (or `world`) and every quote must be a verbatim excerpt from that scene;
72+
invalid answers are skipped and never written. Editing an earlier scene makes
73+
its state and downstream state stale again, so bootstrap in reading order.
74+
3575
The repair path uses the same author approval boundary: imported or AI-edited
3676
scene changes appear in `weaver changes`, and the author approves or rejects
3777
one chapter at a time before continuing to state review and export.

‎engine/changes.mjs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ function chapterFindings(root, project, pending) {
111111
const result = runRules(root, project, { sceneIds: available });
112112
const voice = runVoiceCheck(root, project, { sceneIds: available });
113113
const byScene = new Map();
114+
byScene.allowed_blocking = result.allowed_blocking;
114115
for (const finding of result.findings) {
115116
if (!byScene.has(finding.scene_id)) byScene.set(finding.scene_id, []);
116117
byScene.get(finding.scene_id).push(finding);
@@ -184,7 +185,7 @@ function gitStatusAll(root) {
184185
return parseStatus(result.stdout);
185186
}
186187

187-
function ensureIdentity(root, project) {
188+
export function ensureIdentity(root, project) {
188189
const name = git(root, ["config", "--get", "user.name"], { stdio: ["ignore", "pipe", "ignore"] });
189190
const email = git(root, ["config", "--get", "user.email"], { stdio: ["ignore", "pipe", "ignore"] });
190191
if (name.status !== 0 || !name.stdout.trim()) {
@@ -228,7 +229,7 @@ export function approveChapter(root, project, chapter = null, note = "") {
228229
const sha = git(root, ["rev-parse", "--short", "HEAD"], { stdio: ["ignore", "pipe", "pipe"] });
229230
if (sha.status !== 0) throw new Error("approval was saved, but its id could not be read from Git");
230231
const voices = buildVoiceProfiles(root, project);
231-
return { chapter: selectedChapter, id: sha.stdout.trim(), paths, message: subject, voice_profiles: voices.profiles.length };
232+
return { chapter: selectedChapter, id: sha.stdout.trim(), paths, message: subject, voice_profiles: voices.profiles.length, allowed_blocking: selectedFindings.allowed_blocking || [] };
232233
}
233234

234235
// An imported book is the author's existing work: it is the starting point, not a pending change.

0 commit comments

Comments
 (0)