rewritable 0.1.0 → 0.3.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/README.md CHANGED
@@ -33,6 +33,7 @@ Embeds the input file's content as the document's initial state. Supported forma
33
33
 
34
34
  - `.md`, `.markdown` — converted via [`marked`](https://marked.js.org/) (GFM enabled)
35
35
  - `.html`, `.htm` — `<!DOCTYPE>`/`<html>`/`<head>`/`<body>` shells stripped, `<style>` tags retained from `<head>`, body content kept as-is. **`<script>` tags are preserved** (rwa documents support inline JS); a stderr warning is printed when scripts are detected.
36
+ - `.csv` — parsed via [`papaparse`](https://www.papaparse.com/) (RFC 4180; handles quoted commas, embedded newlines, escaped quotes, BOM). First row becomes `<thead>`, remaining rows `<tbody>`; every cell is HTML-escaped. Parse warnings print to stderr but don't abort the import.
36
37
  - `.txt` — paragraph-split on blank lines, HTML chars escaped
37
38
 
38
39
  Output defaults to `<input-basename>.html` in the input's directory. Conversion is deterministic and offline — no API key, no network.
@@ -42,6 +43,7 @@ Output defaults to `<input-basename>.html` in the input's directory. Conversion
42
43
  | Flag | Effect |
43
44
  |---|---|
44
45
  | `--force`, `-f` | overwrite the destination if it exists |
46
+ | `--open`, `-o` | open the resulting file in the default app |
45
47
  | `--version` | print version |
46
48
  | `--help`, `-h` | usage |
47
49
 
package/bin/rwa.mjs CHANGED
@@ -11,10 +11,33 @@ Usage:
11
11
 
12
12
  Flags:
13
13
  --force, -f overwrite the destination if it exists
14
+ --open, -o open the resulting file in the default app. First-paint
15
+ sessionStorage is pre-populated from env / ./.env:
16
+ OPENROUTER_API_KEY → ?key=… (lifted into rwa_apikey)
17
+ RWA_BACKEND → ?backend= (openrouter|ollama|lmstudio|bridge)
18
+ RWA_MODEL → ?model=… (model name string)
19
+ The bootstrap lifts each into sessionStorage and scrubs the
20
+ URL bar on first paint, so the values don't sit in history.
21
+ --vision (import only, .pdf only) send the PDF to OpenRouter and
22
+ ask the model to convert it to clean HTML. Bypasses the
23
+ local pdfjs heuristic entirely. Requires OPENROUTER_API_KEY.
24
+ Costs ~$0.001-$0.05 per page in API tokens depending on model.
25
+ --claude (import only, .pdf or .docx) spawn \`claude -p\` to convert
26
+ the file using the local pdf/docx skills (Anthropic
27
+ official). Best fidelity for documents that benefit from
28
+ skill-driven extraction (multi-column, tables, tracked
29
+ changes). Requires the \`claude\` CLI installed and runs
30
+ with --permission-mode bypassPermissions; only use on
31
+ files you trust.
32
+ --model <id> (with --vision) override the OpenRouter model id.
33
+ Default: google/gemini-3-flash-preview.
34
+ --timeout <s> (with --claude) wall-clock cap for the subprocess in
35
+ seconds. Default: 1200 (20 minutes). Long academic
36
+ papers may need more.
14
37
  --version print version and exit
15
38
  --help, -h this help
16
39
 
17
- Supported import formats: .md, .markdown, .html, .htm, .txt
40
+ Supported import formats: .md, .markdown, .html, .htm, .csv, .txt, .docx, .pdf
18
41
  `;
19
42
 
20
43
  const args = process.argv.slice(2);
@@ -33,16 +56,29 @@ const verb = args[0];
33
56
  }
34
57
  const rest = args.slice(1);
35
58
  const force = rest.includes('--force') || rest.includes('-f');
36
- const positional = rest.filter(a => !a.startsWith('-'));
59
+ const open = rest.includes('--open') || rest.includes('-o');
60
+ const vision = rest.includes('--vision');
61
+ const claude = rest.includes('--claude');
62
+ // --model and --timeout take a value: find the index, then take the next arg.
63
+ const modelIdx = rest.indexOf('--model');
64
+ const model = modelIdx >= 0 ? rest[modelIdx + 1] : undefined;
65
+ const timeoutIdx = rest.indexOf('--timeout');
66
+ const timeoutSec = timeoutIdx >= 0 ? Number(rest[timeoutIdx + 1]) : undefined;
67
+ if (timeoutIdx >= 0 && (!Number.isFinite(timeoutSec) || timeoutSec <= 0)) {
68
+ console.error(`rwa: --timeout requires a positive number of seconds (got "${rest[timeoutIdx + 1]}")`);
69
+ process.exitCode = 2;
70
+ return;
71
+ }
72
+ const positional = rest.filter((a, i) => !a.startsWith('-') && rest[i - 1] !== '--model' && rest[i - 1] !== '--timeout');
37
73
  if (verb === 'new') {
38
- await newCmd({ outPath: positional[0], force });
74
+ await newCmd({ outPath: positional[0], force, open });
39
75
  } else if (verb === 'import') {
40
76
  if (!positional[0]) {
41
77
  console.error('rwa import: missing <input> argument');
42
78
  process.exitCode = 2;
43
79
  return;
44
80
  }
45
- await importCmd({ inputPath: positional[0], outPath: positional[1], force });
81
+ await importCmd({ inputPath: positional[0], outPath: positional[1], force, open, vision, claude, model, timeoutSec });
46
82
  } else {
47
83
  console.error(`rwa: unknown verb "${verb}". Try --help.`);
48
84
  process.exitCode = 2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rewritable",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "CLI for re-writeable: emit and import single-file rwa documents.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -13,10 +13,13 @@
13
13
  "README.md"
14
14
  ],
15
15
  "engines": {
16
- "node": ">=18"
16
+ "node": ">=20.16.0"
17
17
  },
18
18
  "dependencies": {
19
- "marked": "^14.1.0"
19
+ "mammoth": "1.11.0",
20
+ "marked": "^14.1.0",
21
+ "papaparse": "^5.4.1",
22
+ "pdfjs-dist": "5.4.149"
20
23
  },
21
24
  "scripts": {
22
25
  "prepublishOnly": "mkdir -p seeds && cp ../seeds/rewritable.html seeds/rewritable.html"