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/src/cli.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { dirname, resolve } from 'path';
|
|
4
|
+
import process from 'process';
|
|
5
|
+
import { readFile } from 'fs/promises';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import { realpathSync } from 'fs';
|
|
8
|
+
import { initializeWorkspace } from './server/workspace.js';
|
|
9
|
+
import { startServer } from './server/index.js';
|
|
10
|
+
import { AGENT_PROVIDERS } from './server/agent-adapters.js';
|
|
11
|
+
import { createWorkspaceRegistry } from './server/workspace-registry.js';
|
|
12
|
+
|
|
13
|
+
const PACKAGE_FILE = fileURLToPath(new URL('../package.json', import.meta.url));
|
|
14
|
+
const BUILT_IN_DEMO_WORKSPACE = resolve(dirname(PACKAGE_FILE), 'example');
|
|
15
|
+
export function parseCliArgs(argv, cwd = process.cwd()) {
|
|
16
|
+
const options = { workspaceRoot: null, port: 3000, provider: 'mock', demo: false, resume: false, help: false, version: false };
|
|
17
|
+
const positional = [];
|
|
18
|
+
|
|
19
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
20
|
+
const argument = argv[index];
|
|
21
|
+
if (argument === '--help' || argument === '-h') options.help = true;
|
|
22
|
+
else if (argument === '--version' || argument === '-v') options.version = true;
|
|
23
|
+
else if (argument === '--port' || argument === '-p') options.port = Number(argv[++index]);
|
|
24
|
+
else if (argument.startsWith('--port=')) options.port = Number(argument.slice('--port='.length));
|
|
25
|
+
else if (argument === '--agent') options.provider = argv[++index];
|
|
26
|
+
else if (argument.startsWith('--agent=')) options.provider = argument.slice('--agent='.length);
|
|
27
|
+
else if (argument === '--workspace' || argument === '-w') options.workspaceRoot = argv[++index];
|
|
28
|
+
else if (argument.startsWith('--workspace=')) options.workspaceRoot = argument.slice('--workspace='.length);
|
|
29
|
+
else if (argument === '--demo') options.demo = true;
|
|
30
|
+
else if (argument === '--resume') options.resume = true;
|
|
31
|
+
else if (argument.startsWith('-')) throw new Error(`Unknown option: ${argument}`);
|
|
32
|
+
else positional.push(argument);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (positional.length > 1 || (positional.length === 1 && options.workspaceRoot)) {
|
|
36
|
+
throw new Error('Provide one workspace as either a positional argument or --workspace');
|
|
37
|
+
}
|
|
38
|
+
if (options.resume && (positional.length > 0 || options.workspaceRoot)) {
|
|
39
|
+
throw new Error('--resume cannot be combined with an explicit workspace');
|
|
40
|
+
}
|
|
41
|
+
if (options.resume && options.demo) {
|
|
42
|
+
throw new Error('--resume cannot be combined with --demo');
|
|
43
|
+
}
|
|
44
|
+
options.workspaceRoot = resolve(cwd, options.workspaceRoot || positional[0] || '.');
|
|
45
|
+
if (!Number.isInteger(options.port) || options.port < 0 || options.port > 65535) {
|
|
46
|
+
throw new Error('Port must be an integer between 0 and 65535');
|
|
47
|
+
}
|
|
48
|
+
if (!AGENT_PROVIDERS.includes(options.provider)) {
|
|
49
|
+
throw new Error(`Agent must be one of: ${AGENT_PROVIDERS.join(', ')}`);
|
|
50
|
+
}
|
|
51
|
+
return options;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function helpText() {
|
|
55
|
+
return `Papergod — local-first AI LaTeX writing platform
|
|
56
|
+
|
|
57
|
+
Usage:
|
|
58
|
+
papergod [workspace] [options]
|
|
59
|
+
|
|
60
|
+
Options:
|
|
61
|
+
-w, --workspace <path> Paper workspace (default: current directory)
|
|
62
|
+
-p, --port <number> Local HTTP port (default: 3000; 0 selects a free port)
|
|
63
|
+
--agent <provider> mock, codex, claude-code, opencode, or pi (default: mock)
|
|
64
|
+
--demo Seed built-in prompts, libraries, vocabulary, and demo paper
|
|
65
|
+
--resume Reopen the last selected paper (built-in demo on first run)
|
|
66
|
+
-h, --help Show help
|
|
67
|
+
-v, --version Show version
|
|
68
|
+
`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function resolveStartupWorkspace(options, {
|
|
72
|
+
registry = createWorkspaceRegistry(),
|
|
73
|
+
fallbackWorkspace = BUILT_IN_DEMO_WORKSPACE,
|
|
74
|
+
} = {}) {
|
|
75
|
+
if (!options.resume) return options;
|
|
76
|
+
const active = await registry.getActive();
|
|
77
|
+
return {
|
|
78
|
+
...options,
|
|
79
|
+
workspaceRoot: active?.path || fallbackWorkspace,
|
|
80
|
+
demo: !active,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function run(argv = process.argv.slice(2)) {
|
|
85
|
+
let options = parseCliArgs(argv);
|
|
86
|
+
if (options.help) {
|
|
87
|
+
process.stdout.write(helpText());
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
if (options.version) {
|
|
91
|
+
const packageData = JSON.parse(await readFile(PACKAGE_FILE, 'utf-8'));
|
|
92
|
+
process.stdout.write(`${packageData.version}\n`);
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
options = await resolveStartupWorkspace(options);
|
|
97
|
+
|
|
98
|
+
const initialization = await initializeWorkspace(options.workspaceRoot, { demo: options.demo });
|
|
99
|
+
const server = await startServer(options);
|
|
100
|
+
const address = server.address();
|
|
101
|
+
const url = `http://127.0.0.1:${address.port}`;
|
|
102
|
+
process.stdout.write(`Papergod running at ${url}\n`);
|
|
103
|
+
process.stdout.write(`Workspace: ${options.workspaceRoot}\n`);
|
|
104
|
+
process.stdout.write(`Agent: ${options.provider}${initialization.createdSample ? ' (sample main.tex created)' : ''}\n`);
|
|
105
|
+
|
|
106
|
+
const shutdown = () => {
|
|
107
|
+
process.stdout.write('\nShutting down...\n');
|
|
108
|
+
server.close(() => process.exit(0));
|
|
109
|
+
setTimeout(() => process.exit(1), 5000).unref();
|
|
110
|
+
};
|
|
111
|
+
process.once('SIGINT', shutdown);
|
|
112
|
+
process.once('SIGTERM', shutdown);
|
|
113
|
+
return server;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const isMainModule = process.argv[1] && (() => {
|
|
117
|
+
try {
|
|
118
|
+
return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
|
|
119
|
+
} catch {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
})();
|
|
123
|
+
if (isMainModule) {
|
|
124
|
+
run().catch((error) => {
|
|
125
|
+
process.stderr.write(`Papergod failed to start: ${error.message}\n`);
|
|
126
|
+
process.exitCode = 1;
|
|
127
|
+
});
|
|
128
|
+
}
|