@var-ia/cli 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.
Files changed (36) hide show
  1. package/README.md +27 -0
  2. package/dist/src/commands/analyze.d.ts +6 -2
  3. package/dist/src/commands/analyze.d.ts.map +1 -1
  4. package/dist/src/commands/analyze.js +240 -14
  5. package/dist/src/commands/analyze.js.map +1 -1
  6. package/dist/src/commands/cache.d.ts +2 -2
  7. package/dist/src/commands/cache.d.ts.map +1 -1
  8. package/dist/src/commands/cache.js.map +1 -1
  9. package/dist/src/commands/claim.d.ts +5 -1
  10. package/dist/src/commands/claim.d.ts.map +1 -1
  11. package/dist/src/commands/claim.js +34 -5
  12. package/dist/src/commands/claim.js.map +1 -1
  13. package/dist/src/commands/eval.d.ts +2 -0
  14. package/dist/src/commands/eval.d.ts.map +1 -0
  15. package/dist/src/commands/eval.js +38 -0
  16. package/dist/src/commands/eval.js.map +1 -0
  17. package/dist/src/commands/export.d.ts +2 -1
  18. package/dist/src/commands/export.d.ts.map +1 -1
  19. package/dist/src/commands/export.js +80 -8
  20. package/dist/src/commands/export.js.map +1 -1
  21. package/dist/src/commands/watch.d.ts +1 -1
  22. package/dist/src/commands/watch.d.ts.map +1 -1
  23. package/dist/src/commands/watch.js +2 -2
  24. package/dist/src/commands/watch.js.map +1 -1
  25. package/dist/src/index.d.ts.map +1 -1
  26. package/dist/src/index.js +80 -30
  27. package/dist/src/index.js.map +1 -1
  28. package/dist/tsconfig.tsbuildinfo +1 -1
  29. package/package.json +11 -7
  30. package/src/commands/analyze.ts +291 -15
  31. package/src/commands/cache.ts +3 -2
  32. package/src/commands/claim.ts +39 -5
  33. package/src/commands/eval.ts +41 -0
  34. package/src/commands/export.ts +107 -8
  35. package/src/commands/watch.ts +2 -1
  36. package/src/index.ts +98 -35
@@ -7,8 +7,9 @@ const POLL_INTERVAL_MS = 60_000;
7
7
  export async function runWatch(
8
8
  pageTitle: string,
9
9
  section?: string,
10
+ apiUrl?: string,
10
11
  ): Promise<void> {
11
- const client = new MediaWikiClient();
12
+ const client = new MediaWikiClient(apiUrl ? { apiUrl } : undefined);
12
13
  console.log(`Watching "${pageTitle}"${section ? ` section="${section}"` : ""}`);
13
14
  console.log(`Polling every ${POLL_INTERVAL_MS / 1000}s. Press Ctrl+C to stop.\n`);
14
15
 
package/src/index.ts CHANGED
@@ -1,25 +1,34 @@
1
1
  import { runAnalyze } from "./commands/analyze.js";
2
2
  import { runClaim } from "./commands/claim.js";
3
+ import { runEval } from "./commands/eval.js";
3
4
  import { runExport } from "./commands/export.js";
4
5
  import { runWatch } from "./commands/watch.js";
6
+ import type { ModelConfig } from "@var-ia/interpreter";
5
7
 
6
8
  const HELP = `
7
9
  wikihistory — Wikipedia edit history analysis
8
10
 
9
11
  Usage:
10
- wikihistory analyze <page> [--depth brief|detailed|forensic] [--from <revId>] [--to <revId>] [--cache]
11
- wikihistory claim <page> --text "<claim text>" [--cache]
12
- wikihistory export <page> --format json|csv
12
+ wikihistory analyze <page> [--depth brief|detailed|forensic] [--from <revId>] [--to <revId>] [--cache] [--model <provider>]
13
+ wikihistory analyze --pages-file <path> [--depth brief|detailed|forensic] [--cache] [--model <provider>]
14
+ wikihistory claim <page> --text "<claim text>" [--cache] [--model <provider>]
15
+ wikihistory export <page> --format json|csv [--bundle] [--model <provider>]
13
16
  wikihistory watch <page> [--section <name>]
17
+ wikihistory eval [--page <title>]
14
18
 
15
19
  Options:
16
- --depth Analysis depth (default: detailed)
17
- --text Claim text to track across revisions
18
- --format Export format (json, csv)
19
- --section Watch a specific section only
20
- --from Start revision ID
21
- --to End revision ID
22
- --cache Cache revisions in SQLite (~/.wikihistory/varia.db)
20
+ --depth Analysis depth (default: detailed)
21
+ --text Claim text to track across revisions
22
+ --format Export format (json, csv)
23
+ --section Watch a specific section only
24
+ --from Start revision ID
25
+ --to End revision ID
26
+ --cache Cache revisions in SQLite (~/.wikihistory/varia.db)
27
+ --model Model provider for semantic interpretation (openai, anthropic, deepseek, local, byok)
28
+ --model-api-key API key for model provider (or set env var OPENAI_API_KEY etc.)
29
+ --model-name Model name override (default: provider-specific)
30
+ --model-endpoint API endpoint override
31
+ --api MediaWiki API base URL (default: https://en.wikipedia.org/w/api.php)
23
32
  `;
24
33
 
25
34
  export async function cli(args: string[]): Promise<void> {
@@ -28,33 +37,59 @@ export async function cli(args: string[]): Promise<void> {
28
37
  switch (command) {
29
38
  case "analyze": {
30
39
  const pageTitle = args[1];
31
- if (!pageTitle) {
32
- console.error("Usage: wikihistory analyze <page> [--depth brief|detailed|forensic] [--cache]");
33
- process.exit(1);
34
- }
40
+ const pagesFile = parseFlag(args, "pages-file");
35
41
  const depth = parseFlag(args, "depth") ?? "detailed";
36
42
  const fromRev = parseFlag(args, "from");
37
43
  const toRev = parseFlag(args, "to");
38
44
  const useCache = args.includes("--cache");
45
+ const modelConfig = parseModelConfig(args);
46
+ const apiUrl = parseFlag(args, "api");
39
47
 
40
- const events = await runAnalyze(
41
- pageTitle,
42
- depth,
43
- fromRev ? parseInt(fromRev, 10) : undefined,
44
- toRev ? parseInt(toRev, 10) : undefined,
45
- useCache,
46
- );
48
+ if (pagesFile) {
49
+ const result = await runAnalyze(
50
+ "",
51
+ depth,
52
+ fromRev ? parseInt(fromRev, 10) : undefined,
53
+ toRev ? parseInt(toRev, 10) : undefined,
54
+ useCache,
55
+ modelConfig,
56
+ apiUrl,
57
+ pagesFile,
58
+ );
59
+ const events = result.events;
60
+ console.log(`\nBatch complete. Total events: ${events.length}`);
61
+ } else {
62
+ if (!pageTitle) {
63
+ console.error("Usage: wikihistory analyze <page> [--depth brief|detailed|forensic] [--cache] [--model <provider>]");
64
+ process.exit(1);
65
+ }
66
+ const { events } = await runAnalyze(
67
+ pageTitle,
68
+ depth,
69
+ fromRev ? parseInt(fromRev, 10) : undefined,
70
+ toRev ? parseInt(toRev, 10) : undefined,
71
+ useCache,
72
+ modelConfig,
73
+ apiUrl,
74
+ );
47
75
 
48
- console.log(`\n=== Analysis Results ===`);
49
- console.log(`Page: ${pageTitle}`);
50
- console.log(`Events detected: ${events.length}`);
51
- console.log();
76
+ console.log(`\n=== Analysis Results ===`);
77
+ console.log(`Page: ${pageTitle}`);
78
+ console.log(`Events detected: ${events.length}`);
79
+ console.log();
52
80
 
53
- for (const event of events) {
54
- console.log(`[${event.timestamp}] ${event.eventType} (rev ${event.fromRevisionId}→${event.toRevisionId})`);
55
- if (event.section) console.log(` Section: ${event.section}`);
56
- for (const fact of event.deterministicFacts) {
57
- console.log(` • ${fact.fact}${fact.detail ? `: ${fact.detail}` : ""}`);
81
+ for (const event of events) {
82
+ console.log(`[${event.timestamp}] ${event.eventType} (rev ${event.fromRevisionId}→${event.toRevisionId})`);
83
+ if (event.section) console.log(` Section: ${event.section}`);
84
+ for (const fact of event.deterministicFacts) {
85
+ console.log(` • ${fact.fact}${fact.detail ? `: ${fact.detail}` : ""}`);
86
+ }
87
+ if (event.modelInterpretation) {
88
+ console.log(` ↳ ${event.modelInterpretation.semanticChange} (confidence: ${event.modelInterpretation.confidence.toFixed(2)})`);
89
+ if (event.modelInterpretation.policyDimension) {
90
+ console.log(` ↳ policy: ${event.modelInterpretation.policyDimension}`);
91
+ }
92
+ }
58
93
  }
59
94
  }
60
95
  break;
@@ -63,21 +98,26 @@ export async function cli(args: string[]): Promise<void> {
63
98
  const pageTitle = args[1];
64
99
  const claimText = parseFlag(args, "text");
65
100
  if (!pageTitle || !claimText) {
66
- console.error('Usage: wikihistory claim <page> --text "<claim text>" [--cache]');
101
+ console.error('Usage: wikihistory claim <page> --text "<claim text>" [--cache] [--model <provider>]');
67
102
  process.exit(1);
68
103
  }
69
104
  const useCache = args.includes("--cache");
70
- await runClaim(pageTitle, claimText, useCache);
105
+ const modelConfig = parseModelConfig(args);
106
+ const apiUrl = parseFlag(args, "api");
107
+ await runClaim(pageTitle, claimText, useCache, modelConfig, apiUrl);
71
108
  break;
72
109
  }
73
110
  case "export": {
74
111
  const pageTitle = args[1];
75
112
  const format = parseFlag(args, "format") ?? "json";
113
+ const bundle = args.includes("--bundle");
76
114
  if (!pageTitle) {
77
- console.error("Usage: wikihistory export <page> --format json|csv");
115
+ console.error("Usage: wikihistory export <page> --format json|csv [--bundle] [--model <provider>]");
78
116
  process.exit(1);
79
117
  }
80
- await runExport(pageTitle, format);
118
+ const modelConfig = parseModelConfig(args);
119
+ const apiUrl = parseFlag(args, "api");
120
+ await runExport(pageTitle, format, modelConfig, apiUrl, bundle);
81
121
  break;
82
122
  }
83
123
  case "watch": {
@@ -87,7 +127,13 @@ export async function cli(args: string[]): Promise<void> {
87
127
  process.exit(1);
88
128
  }
89
129
  const section = parseFlag(args, "section");
90
- await runWatch(pageTitle, section);
130
+ const apiUrl = parseFlag(args, "api");
131
+ await runWatch(pageTitle, section, apiUrl);
132
+ break;
133
+ }
134
+ case "eval": {
135
+ const pageOverride = parseFlag(args, "page");
136
+ await runEval(pageOverride);
91
137
  break;
92
138
  }
93
139
  case "--help":
@@ -109,3 +155,20 @@ export function parseFlag(args: string[], name: string): string | undefined {
109
155
  }
110
156
  return undefined;
111
157
  }
158
+
159
+ function parseModelConfig(args: string[]): ModelConfig | undefined {
160
+ const provider = parseFlag(args, "model");
161
+ if (!provider) return undefined;
162
+
163
+ if (!["openai", "anthropic", "deepseek", "local", "byok"].includes(provider)) {
164
+ console.error(`Unknown model provider: ${provider}. Use openai, anthropic, deepseek, local, or byok.`);
165
+ process.exit(1);
166
+ }
167
+
168
+ return {
169
+ provider: provider as ModelConfig["provider"],
170
+ apiKey: parseFlag(args, "model-api-key"),
171
+ model: parseFlag(args, "model-name"),
172
+ endpoint: parseFlag(args, "model-endpoint"),
173
+ };
174
+ }