papergod 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +244 -0
- package/ROADMAP.md +171 -0
- package/example/main.tex +360 -0
- package/frontend/src/components/ui/badge.jsx +5 -0
- package/frontend/src/components/ui/button.jsx +24 -0
- package/frontend/src/components/workbench.jsx +182 -0
- package/frontend/src/lib/utils.js +6 -0
- package/frontend/src/main.jsx +19 -0
- package/frontend/src/theme.css +256 -0
- package/frontend/vite.config.js +23 -0
- package/package.json +73 -0
- package/papergod-demo.png +0 -0
- package/public/app.js +5480 -0
- package/public/brand/papergod-logo.png +0 -0
- package/public/i18n.js +95 -0
- package/public/index.html +480 -0
- package/public/pdf-sentence-mapping.js +142 -0
- package/public/react/app.js +209 -0
- package/public/react/assets/addon-fit-YJmn1quW.js +12 -0
- package/public/react/assets/addon-web-links-BWjmmSgS.js +12 -0
- package/public/react/assets/main.css +32 -0
- package/public/react/assets/xterm-BqvuqXEL.js +27 -0
- package/public/style.css +1462 -0
- package/src/cli.js +128 -0
- package/src/server/agent-adapters.js +1240 -0
- package/src/server/agent-errors.js +105 -0
- package/src/server/agent-runtime.js +81 -0
- package/src/server/agent.js +173 -0
- package/src/server/app-version.js +86 -0
- package/src/server/change-history.js +114 -0
- package/src/server/document-structure.js +174 -0
- package/src/server/index.js +1442 -0
- package/src/server/latex-structure.js +344 -0
- package/src/server/latex.js +67 -0
- package/src/server/library-engine.js +193 -0
- package/src/server/library-files.js +134 -0
- package/src/server/literature-review.js +122 -0
- package/src/server/orchestration-engine.js +662 -0
- package/src/server/paragraph-analysis.js +300 -0
- package/src/server/project-resources.js +290 -0
- package/src/server/project-store.js +808 -0
- package/src/server/prompt-manifest.js +300 -0
- package/src/server/references.js +425 -0
- package/src/server/review-panel.js +263 -0
- package/src/server/revise-workflow.js +278 -0
- package/src/server/revision-engine.js +607 -0
- package/src/server/security.js +16 -0
- package/src/server/text-extraction.js +149 -0
- package/src/server/workspace-browser.js +49 -0
- package/src/server/workspace-registry.js +143 -0
- package/src/server/workspace-terminal.js +99 -0
- package/src/server/workspace.js +223 -0
- package/src/server/zotero.js +98 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SHENGYU LIU
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# Papergod
|
|
2
|
+
|
|
3
|
+
AI-powered LaTeX writing platform — a local-first Overleaf-style editor with safe compilation, structured writing context, and Mock/Codex/Claude Code/OpenCode/Pi Agent assistants.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install
|
|
9
|
+
npm run papergod
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Open http://127.0.0.1:3000 in your browser.
|
|
13
|
+
|
|
14
|
+
`npm run papergod` reopens the paper workspace most recently selected in the app. On the very first run, when no workspace has been recorded yet, it falls back to the built-in demo and safely fills its missing demo content. To seed another disposable workspace explicitly, use `papergod ./demo-paper --demo`. Ordinary `papergod ./my-paper` runs add only the non-destructive starter writing library; existing resources are never overwritten.
|
|
15
|
+
|
|
16
|
+
When installed as a package, run Papergod in any paper directory:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npx papergod .
|
|
20
|
+
npx papergod ./my-paper --port 4312 --agent codex
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The CLI initializes `main.tex` when the workspace contains no TeX files and stores Papergod metadata in `.papergod/project.json`. Agent choices are `mock`, `codex`, `claude-code`, `opencode`, and `pi`. External providers require an installed and authenticated CLI; Papergod invokes them non-interactively with structured output, timeouts, output limits, and analysis-only permissions.
|
|
24
|
+
|
|
25
|
+
### Multiple paper workspaces
|
|
26
|
+
|
|
27
|
+
Open **Tools → Workspaces** to register an existing local folder and switch papers without restarting the server. A folder may be a normal directory or a repository created with `git clone`; Papergod does not take over Git credentials or change the repository workflow, so commit and push with Git as usual. The browser reloads after a successful switch to discard stale PDF and editor state.
|
|
28
|
+
|
|
29
|
+
**Browse…** first attempts a local operating-system picker (`zenity`, `kdialog`, then Python/Tk on Linux and WSL). If none is available, Papergod automatically opens an in-browser directory navigator rooted at the user's home directory; paths outside that browsing boundary can still be entered explicitly and are validated before use.
|
|
30
|
+
|
|
31
|
+
**Tools → Terminal** opens a real PTY shell whose working directory is the current paper workspace. It supports ANSI output, interactive input, resizing, scrollback, reconnecting after the dialog is closed, and an explicit stop action. Terminal code is loaded only when the tool is opened, so it does not increase the main workbench JavaScript payload.
|
|
32
|
+
|
|
33
|
+
The recent-workspace registry is stored in `~/.papergod/workspaces.json`. Paper content, prompts, revision history, writing libraries, and Agent profiles remain isolated in each folder's `.papergod/project.json`. Switching is refused while an Agent task is running, and the current source is saved before a browser-initiated switch. New or existing workspaces receive missing starter checklists, eight academic sentence patterns, and ten precision-focused vocabulary entries by stable ID; user-created entries are preserved.
|
|
34
|
+
|
|
35
|
+
### References and Zotero
|
|
36
|
+
|
|
37
|
+
Open **Tools → References** to build one searchable citation library from local literature folders and Zotero Desktop. Local folders are scanned recursively for `.bib`, `.bibtex`, and `.pdf` files. Existing BibTeX is treated as authoritative; PDF first pages are inspected for DOI/arXiv identifiers, and uncertain records remain visibly marked for review instead of being guessed. DOI records can be verified against Crossref on demand.
|
|
38
|
+
|
|
39
|
+
Papergod connects to Zotero's read-only local API at `127.0.0.1:23119`, so ordinary local use requires no Zotero cloud key. In Zotero, enable **Settings → Advanced → Allow other applications on this computer to communicate with Zotero**, then use **Connect Zotero** to search the library or a collection. Better BibTeX is detected when installed but is optional. Imported entries, local entries, and citation status are indexed in `.papergod/references.json`; the compilable `references.bib` stays in the paper workspace and can be tracked with Git.
|
|
40
|
+
|
|
41
|
+
Reference cards can be selected for two separate actions: **Insert selected** writes a `\cite{...}` command at the editor cursor, while selection also makes those verified records available to the Agent prompt. Citation checking reports missing citekeys and missing bibliography setup. Agent revisions that introduce a citekey absent from the managed bibliography are rejected before source is changed.
|
|
42
|
+
|
|
43
|
+
**Generate a review paragraph**: select several references (local or imported from Zotero), optionally describe what the paragraph should cover, and run **Generate review paragraph**. Papergod composes a draft that cites each selected record with `\citep{...}` (Mock synthesizes deterministically from bibliographic metadata; a configured external Agent writes a substantive synthesis). The draft stays reviewable until **Insert at cursor** applies it through the same atomic revision flow.
|
|
44
|
+
|
|
45
|
+
### Paragraph Analysis
|
|
46
|
+
|
|
47
|
+
- Click the **📊** button next to any paragraph in the outline, or use **Tools → Paragraph analysis** to analyze the whole paper
|
|
48
|
+
- Every analysis reports sentence lengths (in words), and document/section analyses also report paragraph lengths
|
|
49
|
+
- Statistics include the mean μ, sample standard deviation s, coefficient of variation CV = s/μ, median, range, IQR, adjacent-sentence change Δ, and the normalized change Δ/μ — all with the exact formulas shown in the panel
|
|
50
|
+
- A 0–100 **variation index** VI = 100·(0.6·min(1, CV/0.5) + 0.4·min(1, (Δ/μ)/0.8)) combines CV and adjacent change into a single rhythm score
|
|
51
|
+
- The verdict reads the score for you: highly uniform rhythms (low VI) are typical of template-generated text, while high variation resembles organic human drafting — uniformity alone is not proof of AI writing
|
|
52
|
+
|
|
53
|
+
### Writing Libraries
|
|
54
|
+
|
|
55
|
+
- **Extract from PDF** reads the text layer of any PDF in the workspace, extracts reusable academic sentence patterns (deterministic rules for Mock, structured Agent extraction for external providers), and lets you add each confirmed candidate to the sentence-pattern library
|
|
56
|
+
|
|
57
|
+

|
|
58
|
+
|
|
59
|
+
## Architecture
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
Browser (React workbench + progressive legacy workflow migration)
|
|
63
|
+
│
|
|
64
|
+
│ shadcn-style primitives + CodeMirror editor + structured outline + PDF.js + AI panel
|
|
65
|
+
│
|
|
66
|
+
▼
|
|
67
|
+
Express server (127.0.0.1 only)
|
|
68
|
+
├── /api/files/* — read/write .tex files (path-traversal protected)
|
|
69
|
+
├── /api/compile — LaTeX compilation (pdflatex/xelatex/lualatex/tectonic)
|
|
70
|
+
├── /api/engines — list available LaTeX engines
|
|
71
|
+
├── /api/agent/* — scoped AI suggestions + audited CLI runs
|
|
72
|
+
├── /api/documents/* — LaTeX structure synchronization + layered prompts
|
|
73
|
+
├── /api/libraries/* — corpora, sentence patterns, and scoped vocabulary
|
|
74
|
+
├── /api/annotations — range-anchored writing and review comments
|
|
75
|
+
├── /api/review/* — atomic review-opinion extraction
|
|
76
|
+
├── /api/reviews/* — configurable peer-review panels and synthesis
|
|
77
|
+
├── /api/revisions/* — reviewable plans, decisions, apply, and rollback
|
|
78
|
+
├── /api/generate/* — prompt/library-controlled full-paper drafts
|
|
79
|
+
├── /api/workflow/* — complete history and portable export bundles
|
|
80
|
+
├── /api/workspaces/* — local workspace registration and runtime switching
|
|
81
|
+
├── /api/references/* — folders, Zotero, BibTeX generation, citekey checks, and review paragraphs
|
|
82
|
+
├── /api/analysis/* — sentence/paragraph rhythm statistics (mean, stddev, CV, variation index)
|
|
83
|
+
├── /api/orchestrations/* — multi-agent graphs, gates, runs, and audit records
|
|
84
|
+
└── /workspace/* — static serving of compiled PDFs
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Security
|
|
88
|
+
|
|
89
|
+
- Server binds only to `127.0.0.1` — no network exposure
|
|
90
|
+
- All file paths validated against workspace root (path traversal blocked)
|
|
91
|
+
- LaTeX compilation uses `execFile` with `shell: false`, shell escape disabled, a 30s timeout, and `SIGKILL` on overrun
|
|
92
|
+
- Only `.tex` files can be written or compiled
|
|
93
|
+
- Dotfiles denied in static serving
|
|
94
|
+
- External Agents read only the current workspace and never receive the manuscript or library body in their prompt (workspace-index mode); their output quotes are validated against the in-memory source, and any write still flows through the visible diff review
|
|
95
|
+
- CodeMirror is installed locally from npm; the editor does not depend on a public CDN
|
|
96
|
+
|
|
97
|
+
### Agent System
|
|
98
|
+
|
|
99
|
+
- The assistant is organized into Agent Configuration, assembled Prompt Context, a one-run Temporary Prompt, and the single **请神** invocation button
|
|
100
|
+
- **请神** first shows a confirmation dialog, then submits one merged `Prompt Context + Temporary Prompt` instruction to the active Agent
|
|
101
|
+
- A compact **Agent Activity** bar below the invocation button shows context preparation, live CLI output, atomic application, PDF compilation, elapsed time, cancellation, and the final result without blocking the paper
|
|
102
|
+
- Ordinary Agent suggestions are applied together as one atomic revision instead of requiring repeated Accept clicks; the Agent Activity result can roll that revision back as long as no later source edit would be lost
|
|
103
|
+
- **Change history** in Tools keeps the reading view clean while exposing the five most recent applied versions, per-change before/after diffs, source navigation for the current version, and checksum-protected whole-revision rollback
|
|
104
|
+
- Agent configuration uses one shared provider shape for Mock, Codex CLI, Claude Code, OpenCode, and Pi Agent; every external adapter supports revision, paragraph drafting, peer review, review orchestration, and full-paper generation
|
|
105
|
+
- Papergod detects CLI versions and non-secret authentication readiness with a fast **Check setup** action; actual model validation happens in the ordinary reviewable writing workflow
|
|
106
|
+
- Custom CLI paths, prefix arguments, and model overrides are persisted in `.papergod/project.json`, reloaded on later runs, and passed to the real CLI invocation
|
|
107
|
+
- Preview the complete invocation context assembled from project/document/element prompts, summaries, sentence intent, selected libraries, temporary instructions, and target source
|
|
108
|
+
- **Mock agent**: deterministic suggestions based on pattern matching (passive voice, "very + adjective", short conclusions)
|
|
109
|
+
- **CLI agents**: Codex, Claude Code, OpenCode, and Pi Agent run non-interactively with validated structured output, analysis-only execution, timeouts, cancellation, and audit records
|
|
110
|
+
- **Provider isolation**: Codex uses a read-only ephemeral execution; OpenCode runs in a temporary directory with permissions denied; Pi runs in JSON mode with sessions, project context, extensions, and skills disabled
|
|
111
|
+
- **Workspace-index context**: for suggest, peer-review, and review-orchestration runs, the prompt inlines only the workspace absolute path, a flat directory/file listing, the target file's byte range `[start, end)`, and the `.papergod/library/*` paths — the manuscript body and library text are never sent. The Agent reads the files it needs on demand, and its `originalText`/`quote` outputs are still validated against the in-memory target as exact contiguous substrings
|
|
112
|
+
- **On-demand read access**: Pi runs with `--tools read`, Claude Code with `--tools Read,Grep,Glob`, OpenCode with `--dir <workspace>` plus read-only permissions, and Codex with its read-only sandbox pointed at the workspace, so each CLI can read the paper and library files without being able to write them
|
|
113
|
+
- **Structured workflows**: editing, review orchestration, peer review, and full-paper generation each use a dedicated validated JSON protocol
|
|
114
|
+
- **Accept/Reject**: both decisions are persisted; accepted edits use atomic revisions and checksum recovery points
|
|
115
|
+
- **Element scope**: select a section, paragraph, or sentence from the outline to constrain prompts and diffs to that exact source range
|
|
116
|
+
|
|
117
|
+
### Structured Writing
|
|
118
|
+
|
|
119
|
+
- LaTeX sections, paragraphs, and sentences are mapped to stable IDs and exact source ranges
|
|
120
|
+
- The outline exposes editable document/element prompts, summaries, and sentence intents
|
|
121
|
+
- Clicking any outline node highlights and scrolls to the matching text in the compiled PDF (text-layer matching with graceful fallback to the source editor); recompile to refresh the PDF text layer
|
|
122
|
+
- **Focus Annotation** opens an immersive three-column reader: paper outline on the left, one paragraph and its revision prompt in the center, and sentence-by-sentence reading with intent and prompt fields on the right
|
|
123
|
+
- Paragraph and sentence navigation automatically preserves draft annotations; **Open in editor** returns the selected paragraph to CodeMirror
|
|
124
|
+
- Sentence-level Agent requests inherit both the parent paragraph prompt and the sentence prompt, so focused annotations become actionable revision context
|
|
125
|
+
- Metadata is persisted atomically in `.papergod/project.json`
|
|
126
|
+
- Project schema v2 automatically migrates existing schema-v1 review records
|
|
127
|
+
- Stale source ranges are rejected before an Agent suggestion can be applied
|
|
128
|
+
|
|
129
|
+
### Writing Libraries
|
|
130
|
+
|
|
131
|
+
- Manage algorithm corpora, tagged sentence patterns, citations, and required template slots
|
|
132
|
+
- Keep global vocabulary separate from vocabulary agreed for the current writing session
|
|
133
|
+
- Select resources explicitly or let Papergod retrieve them by text, tags, and section type
|
|
134
|
+
- Generate a reviewable paragraph draft, then insert it only after user confirmation
|
|
135
|
+
- Extract candidate expressions from the current paper; candidates require confirmation before entering a library
|
|
136
|
+
- Agent runs distinguish resources provided as context from resources the Agent reports actually using
|
|
137
|
+
|
|
138
|
+
### Review & Revise
|
|
139
|
+
|
|
140
|
+
- Work through one unified two-stage workspace: **Opinions & plans** followed by **Responses & delivery**
|
|
141
|
+
- Anchor a comment to an exact editor selection, or import numbered/bulleted reviewer feedback
|
|
142
|
+
- Use Mock or any configured external Agent to split feedback into atomic categorized opinions, exact quotes, suggested fixes, dependencies, and document-node assignments
|
|
143
|
+
- Build revision plans with visible before/after text plus dependency and conflict information
|
|
144
|
+
- Accept, reject, or defer changes individually; executable changes can also be accepted in a batch
|
|
145
|
+
- Apply accepted edits atomically only after explicit review
|
|
146
|
+
- Create checksum-protected recovery points and refuse rollback when it would discard later author edits
|
|
147
|
+
|
|
148
|
+
### Peer Review Panels
|
|
149
|
+
|
|
150
|
+
- Start from methodology, statistics, writing, domain, and reproducibility reviewer profiles
|
|
151
|
+
- Build a custom panel, add reviewer-specific instructions, and edit weighted rubric criteria
|
|
152
|
+
- Run reviewers independently through Mock or any configured external Agent with one audited Agent run per report
|
|
153
|
+
- Validate exact manuscript quotes and rubric references in every external Agent response
|
|
154
|
+
- Synthesize consensus clusters, conflicting assessments, an overall verdict, and prioritized concerns
|
|
155
|
+
- Select concerns and send them directly into the reviewable M6 revision workflow
|
|
156
|
+
|
|
157
|
+
### Responses, Verification & Full-Paper Generation
|
|
158
|
+
|
|
159
|
+
- Continue from revision planning in the same Review & Revise drawer instead of switching tools
|
|
160
|
+
- Turn a revision plan into an editable point-by-point response letter and precise change list
|
|
161
|
+
- Apply revisions atomically, recompile the manuscript, and report every unresolved or deferred opinion
|
|
162
|
+
- Generate a complete LaTeX draft from project/document prompts, outline and paragraph prompts, plus selected corpora, patterns, and vocabulary
|
|
163
|
+
- Preview generated source and accept it only through the same visible revision diff used by ordinary edits
|
|
164
|
+
- Record accepted and rejected Agent decisions; accepted suggestions and paragraph insertions receive checksum recovery points
|
|
165
|
+
- Browse a unified history of Agent runs, peer reviews, and revisions
|
|
166
|
+
- Download source, annotations, reports, revisions, responses, change lists, history, and recovery metadata as a portable JSON bundle
|
|
167
|
+
|
|
168
|
+
### Multi-Agent Orchestration
|
|
169
|
+
|
|
170
|
+
- Open **Tools → Agent orchestration** to arrange configured local Agents on a native canvas
|
|
171
|
+
- Agent nodes declare a provider (Mock or any configured local CLI) and a task: suggest edits, peer review, draft a paragraph, or generate a full paper
|
|
172
|
+
- Approval-gate nodes pause the run until a human approves or rejects; rejection stops the run and skips downstream nodes
|
|
173
|
+
- Nodes run in parallel whenever their dependencies are satisfied; serial review loops are just chains with gates
|
|
174
|
+
- Every node output is stored as a structured record, every edge carries the input summary passed downstream, and each node execution writes an audited Agent run
|
|
175
|
+
- A cyclic graph is rejected before running; edits and deletions are refused while a run is active
|
|
176
|
+
- Only locally configured CLIs are orchestrated — Papergod never creates or logs into accounts
|
|
177
|
+
|
|
178
|
+
### LaTeX Compilation
|
|
179
|
+
|
|
180
|
+
- Auto-detects available engines in order: tectonic → pdflatex → xelatex → lualatex
|
|
181
|
+
- Opens an available paper directly in the compiled PDF view; LaTeX source remains available as an advanced tool
|
|
182
|
+
- Renders compiled PDFs as clean, continuous, width-fitted paper pages without the browser PDF viewer chrome
|
|
183
|
+
- Adds a PDF.js text layer: click manuscript text, choose word/sentence/paragraph scope, and save a persistent modification intent without changing the source immediately
|
|
184
|
+
- Queued modification intents remain editable/removable, are assembled into one document-level prompt when **请神** is invoked, and are resolved together after one atomic revision; undoing that revision reopens the original intent queue
|
|
185
|
+
- Source and rendered pages share one switchable workspace, leaving the assistant column fully available
|
|
186
|
+
- Graceful degradation: if no engine found, compile button is disabled but editor works normally
|
|
187
|
+
- Compilation errors displayed to the user
|
|
188
|
+
|
|
189
|
+
## Requirements
|
|
190
|
+
|
|
191
|
+
- Node.js ≥ 18
|
|
192
|
+
- A LaTeX distribution (optional, for compilation): TeX Live, MiKTeX, or Tectonic
|
|
193
|
+
- The corresponding provider CLI and login for external Agents. Pi Agent is not bundled; install and authenticate the current `pi` CLI using its official coding-agent documentation before selecting it.
|
|
194
|
+
|
|
195
|
+
## Testing
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
npm test
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Project Structure
|
|
202
|
+
|
|
203
|
+
```
|
|
204
|
+
src/server/
|
|
205
|
+
index.js — Express app + API routes
|
|
206
|
+
security.js — Path sanitization + security headers
|
|
207
|
+
latex.js — Engine detection + compilation
|
|
208
|
+
agent.js — Suggestion store and deterministic Mock agent
|
|
209
|
+
agent-adapters.js — Codex/Claude Code/OpenCode/Pi non-interactive adapters
|
|
210
|
+
project-store.js — Versioned project metadata and validation
|
|
211
|
+
project-resources.js — Corpus, vocabulary, annotation, and revision resources
|
|
212
|
+
latex-structure.js — LaTeX structure/range parser
|
|
213
|
+
document-structure.js — Structure synchronization and metadata APIs
|
|
214
|
+
library-engine.js — Retrieval, scoped vocabulary, template rendering, extraction, and prompt context
|
|
215
|
+
revision-engine.js — Opinion extraction, revision planning, atomic apply, and safe rollback
|
|
216
|
+
review-panel.js — Reviewer profiles, independent reports, synthesis, and revision handoff
|
|
217
|
+
revise-workflow.js — Response letters, verification, full-paper generation, history, and export
|
|
218
|
+
orchestration-engine.js — Multi-agent graphs, gate execution, and audit records
|
|
219
|
+
paragraph-analysis.js — Sentence/paragraph rhythm statistics and the variation index
|
|
220
|
+
literature-review.js — Reference synthesis paragraphs with citable \citep output
|
|
221
|
+
text-extraction.js — PDF text to reusable sentence-pattern candidates
|
|
222
|
+
public/
|
|
223
|
+
index.html — Static entry and workflow overlay compatibility layer
|
|
224
|
+
style.css — Legacy workflow layout styles
|
|
225
|
+
app.js — Existing workflow and API integration logic
|
|
226
|
+
react/ — Production React bundle generated by Vite
|
|
227
|
+
frontend/
|
|
228
|
+
src/components/ — React workbench and shadcn-style UI primitives
|
|
229
|
+
src/theme.css — White lightweight design tokens and compatibility theme
|
|
230
|
+
vite.config.js — Production build into public/react
|
|
231
|
+
example/
|
|
232
|
+
main.tex — Sample LaTeX document
|
|
233
|
+
tests/
|
|
234
|
+
api.test.js — Integration tests
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Current Scope
|
|
238
|
+
|
|
239
|
+
- Single-user, local only
|
|
240
|
+
- External Agent quality and availability depend on the user's installed/authenticated CLI
|
|
241
|
+
- No concurrent editing / CRDT
|
|
242
|
+
- No file upload (only pre-existing .tex files in workspace)
|
|
243
|
+
- PDF-only reference identification is best-effort; records without a reliable DOI, arXiv ID, or existing BibTeX require user confirmation
|
|
244
|
+
- PDF-to-source targeting currently matches PDF.js text against parsed manuscript sentences and paragraphs. Complex macros, equations, repeated fragments, and transformed text may not map; SyncTeX-backed coordinate mapping is the planned precision upgrade.
|
package/ROADMAP.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# Papergod 长期实现路线图
|
|
2
|
+
|
|
3
|
+
## 目标
|
|
4
|
+
|
|
5
|
+
Papergod 是一个可通过 npm 安装和启动的、本地优先的 AI LaTeX 写作平台。界面提供类似 Overleaf 的文件编辑、编译和 PDF 预览;写作、分析、评审与修订由 Codex、OpenCode 等 Agent CLI 驱动,并通过结构化数据和可审阅 diff 保证用户始终掌握最终修改权。
|
|
6
|
+
|
|
7
|
+
## 当前功能覆盖
|
|
8
|
+
|
|
9
|
+
| 能力 | 状态 | 当前实现 |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| npm 安装并启动本地网页 | 已实现 | 提供 `papergod` bin、`npx papergod [workspace]` 与首次初始化 |
|
|
12
|
+
| 多论文工作区切换 | 已实现 | Tools 中集中添加/切换本地目录,论文、历史、写作库与 Agent 配置按目录隔离 |
|
|
13
|
+
| 工作区目录浏览与终端 | 已实现 | 原生选择器失败时提供受限网页目录浏览;Tools 提供按 workspace 隔离的交互式 PTY/xterm |
|
|
14
|
+
| 文献引用与 Zotero | 已实现(MVP) | 本地 BibTeX/PDF 文件夹扫描、Zotero Desktop/collection 搜索、可选 Better BibTeX 检测、统一 references.bib、citekey 检查与插入 |
|
|
15
|
+
| 文献综述生成与插入 | 已实现 | References 中多选文献 → 生成可审阅综述段落(Mock 确定性 / 外部 Agent 实质性综述),确认后经原子修订插入,\citep 引用可溯源 |
|
|
16
|
+
| Overleaf 风格编辑界面 | 已实现(Demo) | 文件栏、CodeMirror、PDF 预览、AI 面板 |
|
|
17
|
+
| LaTeX 编辑、保存与编译 | 已实现(基础) | 支持 `.tex` 文件和多种本地引擎,含安全边界与错误反馈 |
|
|
18
|
+
| Agent 建议、diff、接受/拒绝 | 已实现 | Mock/Codex/Claude Code/OpenCode 统一生成结构化建议,逐条接受或拒绝 |
|
|
19
|
+
| Agent CLI 接入 | 已实现 | 自动探测 Codex/Claude Code/OpenCode 的版本与认证状态,支持路径、前置参数、模型覆盖、连接检查及安全结构化调用 |
|
|
20
|
+
| 多 Agent 协作图 | 已实现 | 原生编排画布:Agent 节点/审批关卡、任务连线、输入输出摘要、调度/运行/失败/完成状态、审计记录 |
|
|
21
|
+
| 文章/段落/句子/词汇模型 | 已实现 | 稳定节点 ID、精确范围、摘要、意图和两级词汇作用域 |
|
|
22
|
+
| 全文 Prompt 与每段 Prompt | 已实现 | 全文核心 Prompt 与元素级 Prompt 均可编辑并持久化 |
|
|
23
|
+
| 算法语料与句型库 | 已实现 | 支持存储、检索、变量槽、来源和候选提取,并内置开箱即用的学术句式与检查表 |
|
|
24
|
+
| 通用/本轮协作词汇库 | 已实现 | 全局/本轮作用域合并、检索和采用记录,并提供精确表达 starter vocabulary |
|
|
25
|
+
| 句子意图与段落大意提取 | 已实现(基础) | 大纲展示段落摘要、逐句意图并可单独编辑 |
|
|
26
|
+
| 段落节奏统计分析 | 已实现 | 段落/文档级句长与段长统计(均值、样本标准差、变异系数、中位数、极差、IQR、相邻变化 Δ、变化程度指标 VI 0–100),公式逐条展示,柱状图可视化,并对“AI 机械感”给出启发式判定 |
|
|
27
|
+
| PDF 句式提取入库 | 已实现 | 工作区 PDF 文本层提取(Mock 规则/外部 Agent),候选句式泛化槽位,用户确认后加入句型库 |
|
|
28
|
+
| 专注批注阅读 | 已实现 | 三栏沉浸大窗按小标题、自然段和句子逐级聚焦,分别记录段落/逐句 Prompt,并接入后续 Agent 上下文 |
|
|
29
|
+
| 阅读批注与意见管理 | 已实现 | 精确范围锚点、类别、严重度、状态和来源 |
|
|
30
|
+
| 全文意见编排与任务分配 | 已实现 | Mock/Codex/Claude Code/OpenCode 结构化编排、原子意见、节点分配、依赖/冲突图与显式决策 |
|
|
31
|
+
| 同行评审/论文评审团 | 已实现 | 五类预设/自定义 reviewer、rubric、独立 Agent 报告、共识/冲突汇总及 M6 交接 |
|
|
32
|
+
| 自助 revise | 已实现 | 意见导入、计划执行、可编辑回复信、修改清单、编译复核、未处理检查和导出 |
|
|
33
|
+
| 一键生成论文 | 已实现 | 核心/分层 Prompt、结构大纲和写作库受控生成,全文 diff 审阅后方可应用 |
|
|
34
|
+
| 修改位置与历史 | 已实现 | 最近 5 次版本抽屉、逐块 diff、源码定位、持久 revision、恢复点、校验和与安全回滚 |
|
|
35
|
+
| 自动化测试 | 已实现 | 125 项 API、结构、CLI、工作区/PTY、BibTeX/Zotero、Agent 配置、写作库、评审、修订、生成、编排、统计分析、综述、PDF 提取、安全和编译测试通过 |
|
|
36
|
+
| Agent 上下文工程(文件索引 + 按需读取) | 已实现 | 写作库物化为 `.papergod/library/` 可读文件,prompt 仅注入项目绝对路径、目录清单、目标文件字节范围与库路径;各外部 CLI 放开 workspace 只读访问,正文与库全文不再进入 prompt |
|
|
37
|
+
|
|
38
|
+
## 目标架构
|
|
39
|
+
|
|
40
|
+
```text
|
|
41
|
+
Browser
|
|
42
|
+
├─ LaTeX editor / PDF preview / file tree
|
|
43
|
+
├─ Document outline / paragraph & sentence inspector
|
|
44
|
+
├─ Prompt / corpus / vocabulary workspace
|
|
45
|
+
└─ Review / revise / diff history
|
|
46
|
+
│
|
|
47
|
+
Local Node.js service
|
|
48
|
+
├─ Project & structured document store
|
|
49
|
+
├─ LaTeX compiler
|
|
50
|
+
├─ Corpus and vocabulary service
|
|
51
|
+
├─ Annotation and revision service
|
|
52
|
+
├─ Agent orchestrator + JSON validation
|
|
53
|
+
└─ Codex / OpenCode / Mock adapters
|
|
54
|
+
│
|
|
55
|
+
Local workspace
|
|
56
|
+
├─ *.tex / bibliography / assets
|
|
57
|
+
└─ .papergod/project.json + runs + revisions
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 实施里程碑
|
|
61
|
+
|
|
62
|
+
### M1:项目模型与持久化基础
|
|
63
|
+
|
|
64
|
+
- [x] 定义 project/document/section/paragraph/sentence 的稳定 ID 与排序字段
|
|
65
|
+
- [x] 定义全文 Prompt、段落 Prompt、句子意图和摘要字段
|
|
66
|
+
- [x] 定义 corpus、sentence pattern、global/session vocabulary
|
|
67
|
+
- [x] 定义 annotation、review、revision、agent run 数据结构
|
|
68
|
+
- [x] 在工作区 `.papergod/` 中原子化持久化并提供 API
|
|
69
|
+
- [x] 增加 schema 校验、迁移版本和测试
|
|
70
|
+
|
|
71
|
+
验收:项目元数据可创建、读取、更新;重新启动服务后数据不丢失;路径与输入校验测试通过。
|
|
72
|
+
|
|
73
|
+
### M2:可发布 npm CLI
|
|
74
|
+
|
|
75
|
+
- [x] 提供 `papergod` bin 与 `npx papergod [workspace]`
|
|
76
|
+
- [x] 支持端口、工作区、Agent provider 等 CLI 参数
|
|
77
|
+
- [x] 完善 npm `files`、版本、启动错误和首次初始化
|
|
78
|
+
- [x] 验证干净目录安装、启动、关闭流程
|
|
79
|
+
|
|
80
|
+
验收:在任意论文目录执行 `npx papergod` 可初始化并打开本地服务。
|
|
81
|
+
|
|
82
|
+
### M3:真实 Agent CLI 适配层
|
|
83
|
+
|
|
84
|
+
- [x] 探测 Codex/Claude Code/OpenCode 可用性、版本与认证状态
|
|
85
|
+
- [x] 以参数数组、超时、工作目录和最小环境安全调用 CLI
|
|
86
|
+
- [x] 统一结构化 JSON 请求/响应协议
|
|
87
|
+
- [x] 对输出做 schema 校验、大小限制、错误归一化和取消处理
|
|
88
|
+
- [x] 持久化 CLI 路径、前置参数和模型覆盖,并提供连接检查
|
|
89
|
+
- [x] 保留确定性 Mock,测试永不调用外部 Agent
|
|
90
|
+
|
|
91
|
+
验收:用户可选择 provider;真实 CLI 能只读分析并生成结构化建议;失败时不会损坏论文。
|
|
92
|
+
|
|
93
|
+
### M4:结构化论文工作台
|
|
94
|
+
|
|
95
|
+
- [x] 解析 LaTeX 的 section/paragraph/sentence 映射
|
|
96
|
+
- [x] 展示全文大纲、段落摘要、逐句意图
|
|
97
|
+
- [x] 支持元素级选择、编辑和 AI 重写
|
|
98
|
+
- [x] 支持全文及每段 Prompt 编辑
|
|
99
|
+
- [x] 提供专注批注大窗,按章节、段落、句子逐级阅读并维护两级修改 Prompt
|
|
100
|
+
- [x] 保持结构节点与 `.tex` 文本范围同步
|
|
101
|
+
|
|
102
|
+
验收:用户能定位任一段/句,查看它的作用并进行局部重写,diff 精确回到原文位置。
|
|
103
|
+
|
|
104
|
+
### M5:语料、句型与词汇协作
|
|
105
|
+
|
|
106
|
+
- [x] 管理算法语料与可复用句型模板
|
|
107
|
+
- [x] 管理通用词汇库和本轮协作词汇库
|
|
108
|
+
- [x] 提供标签、适用章节、变量槽位和引用来源
|
|
109
|
+
- [x] Agent 生成时检索并记录实际采用的句型/词汇
|
|
110
|
+
- [x] 支持从现有论文提取候选表达,经用户确认后入库
|
|
111
|
+
|
|
112
|
+
验收:可选择语料和词汇约束生成段落,并追溯每个表达来自哪个库。
|
|
113
|
+
|
|
114
|
+
### M6:批注、意见编排与可审阅修订
|
|
115
|
+
|
|
116
|
+
- [x] 建立文本范围锚定的批注与处理状态
|
|
117
|
+
- [x] 从用户输入/审稿意见中提取原子意见
|
|
118
|
+
- [x] 把意见分配到文章、段落或句子并形成依赖图
|
|
119
|
+
- [x] 分步执行修改,展示 before/after、原因和影响范围
|
|
120
|
+
- [x] 支持逐条/批量接受、拒绝、延期和回滚
|
|
121
|
+
|
|
122
|
+
验收:一轮批注可转成可执行修订计划,任何文本写入都必须经过可见 diff。
|
|
123
|
+
|
|
124
|
+
### M7:抽象同行评审团
|
|
125
|
+
|
|
126
|
+
- [x] 定义方法、统计、写作、领域、复现性等 reviewer profile
|
|
127
|
+
- [x] 支持构造自定义评审团和评审 rubric
|
|
128
|
+
- [x] 并行产生独立意见并进行冲突/共识汇总
|
|
129
|
+
- [x] 评审结论可一键进入 M6 修订工作流
|
|
130
|
+
|
|
131
|
+
验收:同一稿件能得到角色独立、可追溯、可合并的结构化评审报告。
|
|
132
|
+
|
|
133
|
+
### M8:自助 Revise 与一键生成
|
|
134
|
+
|
|
135
|
+
- [x] 导入审稿意见并关联原文
|
|
136
|
+
- [x] 生成 response letter 与修订计划
|
|
137
|
+
- [x] 按计划修订、重新编译并检查未处理意见
|
|
138
|
+
- [x] 从论文核心 Prompt、段落 Prompt、语料和词汇生成初稿
|
|
139
|
+
- [x] 提供完整运行历史、修改清单、导出和恢复点
|
|
140
|
+
|
|
141
|
+
验收:从“粘贴审稿意见”到“修订稿 + 回复信 + 修改清单”形成完整闭环。
|
|
142
|
+
|
|
143
|
+
### M9:多 Agent 可视化编排
|
|
144
|
+
|
|
145
|
+
- [x] 定义 Agent 节点、角色、能力、输入输出端口和任务连线
|
|
146
|
+
- [x] 提供 Papergod 原生的 Agent 编排画布,显示调度、运行、失败和完成状态
|
|
147
|
+
- [x] 支持串行、并行、评审回路和人工确认关卡
|
|
148
|
+
- [x] 为每条边保存输入摘要,为每个节点保存结构化输出和审计记录
|
|
149
|
+
- [x] 第一版仅编排用户已经配置好的本地 CLI,不自动创建或登录账号
|
|
150
|
+
|
|
151
|
+
验收:用户能在画布上连接多个本地 Agent,运行一次可追踪协作流程,并定位每一步的输入、输出和失败原因。
|
|
152
|
+
|
|
153
|
+
### M10:Agent 上下文工程(文件索引 + 按需读取)
|
|
154
|
+
|
|
155
|
+
- [x] 把写作库(语料/句型/词汇)物化为 workspace 内可读文件(`.papergod/library/corpus.md`、`patterns.md`、`vocabulary-global.md`、`vocabulary-session.md` 与 `.papergod/index.json`),外部 Agent 调用前落盘
|
|
156
|
+
- [x] 精简 Agent prompt:只注入项目绝对路径、各层目录清单、目标文件字节范围 `[start, end)` 与库文件路径,不再注入文档正文与库全文
|
|
157
|
+
- [x] 摘要、评审、意见编排等结构化工作流统一走 workspace-index 分支;编排器内对非文件输入仍保留内联(节点输入原文即 prompt,非文件)
|
|
158
|
+
- [x] 放开各外部 CLI 在 workspace 内的只读访问:Pi `--tools read`、Claude Code `--tools Read,Grep,Glob`、OpenCode `--dir workspaceRoot` + 只读权限、Codex 只读沙箱读取当前工作目录
|
|
159
|
+
- [x] Mock 与既有建议/评审/段落/全文生成/编排/综述/PDF 提取工作流兼容新协议,自动化测试通过
|
|
160
|
+
- [x] 保留安全边界:建议/评审的 `originalText`/`quote` 仍以内存中的 `request.content` 校验为精确连续子串,写入仍走可见 diff 审阅
|
|
161
|
+
|
|
162
|
+
验收:外部 Agent 通过路径自行读取论文与库文件后返回结构化建议,prompt 中不再出现正文全文;所有工作流测试通过且安全边界不变。
|
|
163
|
+
|
|
164
|
+
## 实现原则
|
|
165
|
+
|
|
166
|
+
- 本地优先:服务仅绑定 `127.0.0.1`,论文内容默认不离开本机。
|
|
167
|
+
- 用户控制:Agent 先提出结构化 patch,用户审阅后才写入源文件。
|
|
168
|
+
- 可追溯:每次生成记录 provider、prompt、输入范围、语料引用、输出和决定。
|
|
169
|
+
- 可恢复:修改前建立恢复点,批量操作具有原子性。
|
|
170
|
+
- 可替换:业务层只依赖统一 Agent 接口,不绑定某一个 CLI。
|
|
171
|
+
- 可测试:自动测试使用 Mock adapter,不依赖网络或外部模型。
|