-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ts
More file actions
1882 lines (1817 loc) · 73.7 KB
/
Copy pathcli.ts
File metadata and controls
1882 lines (1817 loc) · 73.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { defineCommand, runMain } from "citty";
import { deputiesTool } from "./tools/deputies.js";
import { senatorsTool } from "./tools/senators.js";
import { billsTool } from "./tools/bills.js";
import { votesTool } from "./tools/votes.js";
import { searchTool } from "./tools/search.js";
import { legislaturesTool } from "./tools/legislatures.js";
import { groupsTool } from "./tools/groups.js";
import { sessionsTool } from "./tools/sessions.js";
import { governmentsTool } from "./tools/governments.js";
import { deputyTool } from "./tools/deputy.js";
import { senatorTool } from "./tools/senator.js";
import { billTool } from "./tools/bill.js";
import { rolesTool } from "./tools/roles.js";
import { speechesTool } from "./tools/speeches.js";
import { aicTool } from "./tools/aic.js";
import { voteDetailTool } from "./tools/vote-detail.js";
import { attendanceTool } from "./tools/attendance.js";
import { senatoAttendanceTool } from "./tools/senato-attendance.js";
import { groupMembersTool } from "./tools/group-members.js";
import { senatorGroupMembersTool } from "./tools/senator-group-members.js";
import { govMembersTool } from "./tools/gov-members.js";
import { committeesTool } from "./tools/committees.js";
import { billProgressTool } from "./tools/bill-progress.js";
import { billSignatoriesTool } from "./tools/bill-signatories.js";
import { cameraAmendmentsTool } from "./tools/camera-amendments.js";
import { billRapporteursTool } from "./tools/bill-rapporteurs.js";
import { billCommitteesTool } from "./tools/bill-committees.js";
import { amendmentsTool } from "./tools/amendments.js";
import { documentsTool } from "./tools/documents.js";
import { sparqlTool } from "./tools/sparql.js";
import { rankTool } from "./tools/rank.js";
import { sindacatoIspettivoTool } from "./tools/sindacato-ispettivo.js";
import { committeeMembersTool } from "./tools/committee-members.js";
import { memberBillsTool } from "./tools/member-bills.js";
import { billTextTool } from "./tools/bill-text.js";
import { senatoGroupsTool } from "./tools/senato-groups.js";
import { senatoVotesTool } from "./tools/senato-votes.js";
import { senatoVoteDetailTool } from "./tools/senato-vote-detail.js";
import { groupRankTool } from "./tools/group-rank.js";
import { committeeSessionsTool } from "./tools/committee-sessions.js";
import { personCareerTool } from "./tools/person-career.js";
import { peopleTool } from "./tools/people.js";
import { audizioniTool } from "./tools/audizioni.js";
import { fetchSenatoText } from "./core/fetch-text.js";
import { CAPABILITIES, capabilityScore } from "./core/capabilities.js";
import { formatRows, type Format } from "./core/format.js";
import { SparqlError } from "./core/client.js";
import { ZodError } from "zod";
import type { ToolResult } from "./tools/types.js";
import { withEmptyHint } from "./core/empty-hint.js";
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const { version } = require("../package.json") as { version: string };
function exitOnEpipe(err: NodeJS.ErrnoException): never {
if (err.code === "EPIPE") process.exit(0);
throw err;
}
process.stdout.on("error", exitOnEpipe);
process.stderr.on("error", exitOnEpipe);
function withExamples(description: string, examples: string[]): string {
return `${description}\n\nExamples:\n${examples.map((e) => ` ${e}`).join("\n")}`;
}
function emit(result: ToolResult, format: Format): void {
process.stdout.write(formatRows(result.rows, format, result.columns) + "\n");
// Hint dinamico su risultato vuoto → stderr, per non sporcare l'output
// parsabile (CSV/JSONL) di pipeline e redirezioni.
if (result.rows.length === 0 && result.hint) {
process.stderr.write(result.hint + "\n");
}
}
// Valida l'input con lo schema Zod del tool PRIMA di eseguirlo: così gli enum
// errati (--vote-type, --rank-by, ...) producono un ZodError con i valori validi
// invece di scivolare nella query come stringa.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async function runTool(tool: { inputSchema: { parse(i: unknown): any }; execute(i: any): Promise<ToolResult>; emptyHint?: string }, input: unknown): Promise<ToolResult> {
let parsed: unknown;
try {
parsed = tool.inputSchema.parse(input);
} catch (e) {
if (e instanceof ZodError) {
const msgs = e.issues.map((i) => {
const field = i.path.join(".") || "input";
return i.code === "invalid_enum_value"
? `--${field}: valore non valido "${(i as { received?: string }).received ?? ""}". Ammessi: ${i.options.join(" | ")}.`
: `--${field}: ${i.message}`;
});
throw new Error(msgs.join("\n"));
}
throw e;
}
// Fallback allineato al path MCP (result.hint ?? emptyHint): su risultato
// vuoto senza hint dinamico, usa l'emptyHint statico del tool così emit()
// lo scrive su stderr.
return withEmptyHint(await tool.execute(parsed), tool.emptyHint);
}
function parseFormat(raw: string): Format {
if (raw === "csv" || raw === "jsonl") return raw;
throw new Error(
`Invalid --format value "${raw}". Allowed: csv, jsonl.\nExample: --format jsonl`,
);
}
function parseIntFlag(raw: string | undefined, name: string): number | undefined {
if (raw === undefined || raw === "") return undefined;
const n = Number(raw);
if (!Number.isInteger(n) || n <= 0) {
throw new Error(
`Invalid --${name} value "${raw}". Expected a positive integer.`,
);
}
return n;
}
function parseBoolFlag(
raw: string | boolean | undefined,
name: string,
): boolean | undefined {
if (raw === undefined || raw === "") return undefined;
if (raw === true || raw === "true") return true;
if (raw === false || raw === "false") return false;
throw new Error(
`Invalid --${name} value "${raw}". Expected: true or false.`,
);
}
const deputiesList = defineCommand({
meta: {
name: "list",
description: withExamples(
"List deputies of the Italian Camera dei Deputati.",
deputiesTool.examples,
),
},
args: {
legislature: {
type: "string",
description: "Legislature number (e.g. 19)",
},
region: {
type: "string",
description: "Filter by constituency/region (case-insensitive, e.g. sicilia)",
},
gender: {
type: "string",
description: "Filter by gender: male | female",
},
"born-from": {
type: "string",
description: "Born on or after (YYYY-MM-DD)",
},
"born-to": {
type: "string",
description: "Born on or before (YYYY-MM-DD)",
},
"birth-place": {
type: "string",
description: "Filter by birthplace (comune/provincia/regione/stato, case-insensitive, e.g. sicilia)",
},
limit: {
type: "string",
description: "Max rows to return (default 100, max 1000)",
default: "100",
},
offset: {
type: "string",
description: "Offset for pagination (default 0)",
default: "0",
},
format: {
type: "string",
description: "Output format: csv (default) or jsonl",
default: "csv",
},
},
async run({ args }) {
const result = await runTool(deputiesTool, {
legislature: parseIntFlag(args.legislature as string, "legislature"),
region: (args.region as string) || undefined,
gender: (args.gender as "male" | "female" | undefined) || undefined,
bornFrom: (args["born-from"] as string) || undefined,
bornTo: (args["born-to"] as string) || undefined,
birthPlace: (args["birth-place"] as string) || undefined,
limit: parseIntFlag(args.limit as string, "limit") ?? 100,
offset: Number(args.offset ?? 0),
});
emit(result, parseFormat(args.format as string));
},
});
const senatorsList = defineCommand({
meta: {
name: "list",
description: withExamples(
"List senators of the Italian Senato della Repubblica.",
senatorsTool.examples,
),
},
args: {
legislature: {
type: "string",
description: "Legislature number (e.g. 19)",
},
"active-only": {
type: "boolean",
description:
"Only senators currently in office (default: true if no --legislature)",
},
gender: {
type: "string",
description: "Filter by gender: male | female",
},
"born-from": {
type: "string",
description: "Born on or after (YYYY-MM-DD)",
},
"born-to": {
type: "string",
description: "Born on or before (YYYY-MM-DD)",
},
"birth-place": {
type: "string",
description: "Filter by birth city (case-insensitive; Senato exposes city only, no province/region)",
},
limit: {
type: "string",
description: "Max rows to return (default 300, max 1000)",
default: "300",
},
offset: {
type: "string",
description: "Offset for pagination",
default: "0",
},
format: {
type: "string",
description: "Output format: csv (default) or jsonl",
default: "csv",
},
},
async run({ args }) {
const activeOnlyRaw = args["active-only"];
const result = await runTool(senatorsTool, {
legislature: parseIntFlag(args.legislature as string, "legislature"),
activeOnly:
activeOnlyRaw === undefined ? undefined : Boolean(activeOnlyRaw),
gender: (args.gender as "male" | "female" | undefined) || undefined,
bornFrom: (args["born-from"] as string) || undefined,
bornTo: (args["born-to"] as string) || undefined,
birthPlace: (args["birth-place"] as string) || undefined,
limit: parseIntFlag(args.limit as string, "limit") ?? 300,
offset: Number(args.offset ?? 0),
});
emit(result, parseFormat(args.format as string));
},
});
const billsList = defineCommand({
meta: {
name: "list",
description: withExamples(
"List bills (atti) of the Italian Camera dei Deputati.",
billsTool.examples,
),
},
args: {
legislature: { type: "string", description: "Legislature number" },
type: {
type: "string",
description: 'Filter by bill type (case-insensitive substring match)',
},
initiative: {
type: "string",
description: "Filter by initiative: Popolare, Governo, Parlamentare, Regioni",
},
keyword: {
type: "string",
description: "Search in bill title (case-insensitive)",
},
"date-from": { type: "string", description: "Start date YYYY-MM-DD" },
"date-to": { type: "string", description: "End date YYYY-MM-DD" },
limit: { type: "string", default: "100", description: "Max rows to return" },
offset: { type: "string", default: "0", description: "Offset for pagination" },
"count-only": { type: "boolean", description: "Return only the total count (column count)" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const result = await runTool(billsTool, {
countOnly: args["count-only"] === true,
legislature: parseIntFlag(args.legislature as string, "legislature"),
type: (args.type as string) || undefined,
initiative: (args.initiative as string) || undefined,
keyword: (args.keyword as string) || undefined,
dateFrom: (args["date-from"] as string) || undefined,
dateTo: (args["date-to"] as string) || undefined,
limit: parseIntFlag(args.limit as string, "limit") ?? 100,
offset: Number(args.offset ?? 0),
});
emit(result, parseFormat(args.format as string));
},
});
const votesList = defineCommand({
meta: {
name: "list",
description: withExamples(
"List votes of the Italian Camera dei Deputati.",
votesTool.examples,
),
},
args: {
legislature: { type: "string", description: "Legislature number" },
approved: {
type: "string",
description: "Filter by approval: true or false",
},
"confidence-vote": {
type: "string",
description: "Filter confidence votes: true or false",
},
keyword: {
type: "string",
description: "Search in vote title (case-insensitive)",
},
"date-from": { type: "string", description: "Start date YYYY-MM-DD" },
"date-to": { type: "string", description: "End date YYYY-MM-DD" },
"bill-code": { type: "string", description: "Filter votes by bill number (e.g. '2807', '1665')" },
"count-only": { type: "boolean", description: "Return only the total count (column count)" },
limit: { type: "string", default: "100", description: "Max rows to return" },
offset: { type: "string", default: "0", description: "Offset for pagination" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
let approved: boolean | undefined;
if (args.approved !== undefined && args.approved !== "") {
if (args.approved === "true") approved = true;
else if (args.approved === "false") approved = false;
else
throw new Error(
`Invalid --approved value "${args.approved}". Expected: true or false.`,
);
}
let confidenceVote: boolean | undefined;
if (args["confidence-vote"] !== undefined && args["confidence-vote"] !== "") {
if (args["confidence-vote"] === "true") confidenceVote = true;
else if (args["confidence-vote"] === "false") confidenceVote = false;
else
throw new Error(
`Invalid --confidence-vote value "${args["confidence-vote"]}". Expected: true or false.`,
);
}
const result = await runTool(votesTool, {
countOnly: args["count-only"] === true,
legislature: parseIntFlag(args.legislature as string, "legislature"),
approved,
confidenceVote,
keyword: (args.keyword as string) || undefined,
dateFrom: (args["date-from"] as string) || undefined,
dateTo: (args["date-to"] as string) || undefined,
billCode: (args["bill-code"] as string) || undefined,
limit: parseIntFlag(args.limit as string, "limit") ?? 100,
offset: Number(args.offset ?? 0),
});
emit(result, parseFormat(args.format as string));
},
});
const searchFind = defineCommand({
meta: {
name: "find",
description: withExamples(
"Search parliamentarians by name in Camera, Senato or both.",
searchTool.examples,
),
},
args: {
name: {
type: "string",
description: "Name or surname to search (required)",
required: true,
},
chamber: {
type: "string",
description: "camera | senato | both (default: both)",
default: "both",
},
legislature: { type: "string", description: "Legislature number" },
"active-only": {
type: "boolean",
description: "Only senators currently in office (Senato side)",
},
limit: { type: "string", default: "50", description: "Max rows to return" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const chamber = args.chamber as string;
if (chamber !== "camera" && chamber !== "senato" && chamber !== "both") {
throw new Error(
`Invalid --chamber value "${chamber}". Allowed: camera, senato, both.`,
);
}
const activeOnlyRaw = args["active-only"];
const result = await runTool(searchTool, {
name: args.name as string,
chamber,
legislature: parseIntFlag(args.legislature as string, "legislature"),
activeOnly:
activeOnlyRaw === undefined ? undefined : Boolean(activeOnlyRaw),
limit: parseIntFlag(args.limit as string, "limit") ?? 50,
});
emit(result, parseFormat(args.format as string));
},
});
const legislaturesList = defineCommand({
meta: {
name: "list",
description: withExamples(
"List all legislatures of the Camera dei Deputati.",
legislaturesTool.examples,
),
},
args: {
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const result = await runTool(legislaturesTool, {});
emit(result, parseFormat(args.format as string));
},
});
const groupsList = defineCommand({
meta: {
name: "list",
description: withExamples(
"List parliamentary groups of the Camera dei Deputati.",
groupsTool.examples,
),
},
args: {
legislature: { type: "string", description: "Legislature number" },
limit: { type: "string", default: "100", description: "Max rows to return" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const result = await runTool(groupsTool, {
legislature: parseIntFlag(args.legislature as string, "legislature"),
limit: parseIntFlag(args.limit as string, "limit") ?? 100,
});
emit(result, parseFormat(args.format as string));
},
});
const senatoGroupsList = defineCommand({
meta: {
name: "list",
description: withExamples(
"List parliamentary groups of the Senato della Repubblica with member count.",
senatoGroupsTool.examples,
),
},
args: {
legislature: { type: "string", description: "Legislature number (e.g. 19)" },
"as-of": { type: "string", description: "Reference date YYYY-MM-DD (default: today). For past legislatures use the last date of that legislature (e.g. 2022-10-12 for XVIII)" },
limit: { type: "string", default: "100", description: "Max rows to return" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const result = await runTool(senatoGroupsTool, {
legislature: parseIntFlag(args.legislature as string, "legislature"),
asOf: (args["as-of"] as string) || undefined,
limit: parseIntFlag(args.limit as string, "limit") ?? 100,
});
emit(result, parseFormat(args.format as string));
},
});
const sessionsList = defineCommand({
meta: {
name: "list",
description: withExamples(
"List parliamentary sessions (sedute) of the Camera dei Deputati.",
sessionsTool.examples,
),
},
args: {
legislature: { type: "string", description: "Legislature number" },
"date-from": { type: "string", description: "Start date YYYY-MM-DD" },
"date-to": { type: "string", description: "End date YYYY-MM-DD" },
limit: { type: "string", default: "100", description: "Max rows to return" },
offset: { type: "string", default: "0", description: "Offset for pagination" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const result = await runTool(sessionsTool, {
legislature: parseIntFlag(args.legislature as string, "legislature"),
dateFrom: (args["date-from"] as string) || undefined,
dateTo: (args["date-to"] as string) || undefined,
limit: parseIntFlag(args.limit as string, "limit") ?? 100,
offset: Number(args.offset ?? 0),
});
emit(result, parseFormat(args.format as string));
},
});
const governmentsList = defineCommand({
meta: {
name: "list",
description: withExamples(
"List Italian governments referenced in Camera membroGoverno records.",
governmentsTool.examples,
),
},
args: {
legislature: { type: "string", description: "Legislature number" },
limit: { type: "string", default: "100", description: "Max rows to return" },
offset: { type: "string", default: "0", description: "Offset for pagination" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const result = await runTool(governmentsTool, {
legislature: parseIntFlag(args.legislature as string, "legislature"),
limit: parseIntFlag(args.limit as string, "limit") ?? 100,
offset: Number(args.offset ?? 0),
});
emit(result, parseFormat(args.format as string));
},
});
const deputyShow = defineCommand({
meta: {
name: "show",
description: withExamples(
"Show all RDF properties of a single deputy.",
deputyTool.examples,
),
},
args: {
uri: { type: "string", description: "Full URI of the deputy" },
id: { type: "string", description: "Numeric deputy ID (use with --legislature)" },
legislature: { type: "string", description: "Legislature number (use with --id)" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const result = await runTool(deputyTool, {
uri: (args.uri as string) || undefined,
id: parseIntFlag(args.id as string, "id"),
legislature: parseIntFlag(args.legislature as string, "legislature"),
});
emit(result, parseFormat(args.format as string));
},
});
const senatorShow = defineCommand({
meta: {
name: "show",
description: withExamples(
"Show all RDF properties of a single senator.",
senatorTool.examples,
),
},
args: {
uri: { type: "string", description: "Full URI of the senator", required: true },
legislature: { type: "string", description: "Legislature number (default: 19)" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const result = await runTool(senatorTool, {
uri: args.uri as string,
legislature: parseIntFlag(args.legislature as string, "legislature"),
});
emit(result, parseFormat(args.format as string));
},
});
const billShow = defineCommand({
meta: {
name: "show",
description: withExamples(
"Show all RDF properties of a single Camera bill.",
billTool.examples,
),
},
args: {
uri: { type: "string", description: "Full URI of the bill", required: true },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const result = await runTool(billTool, { uri: args.uri as string });
emit(result, parseFormat(args.format as string));
},
});
const rolesList = defineCommand({
meta: {
name: "list",
description: withExamples(
"List parliamentary roles (incarichi) of Camera deputies.",
rolesTool.examples,
),
},
args: {
"deputy-uri": { type: "string", description: "Full URI of a deputy" },
"group-uri": { type: "string", description: "Full URI of a parliamentary group" },
legislature: { type: "string", description: "Legislature number" },
limit: { type: "string", default: "100", description: "Max rows to return" },
offset: { type: "string", default: "0", description: "Offset for pagination" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const result = await runTool(rolesTool, {
deputyUri: (args["deputy-uri"] as string) || undefined,
groupUri: (args["group-uri"] as string) || undefined,
legislature: parseIntFlag(args.legislature as string, "legislature"),
limit: parseIntFlag(args.limit as string, "limit") ?? 100,
offset: Number(args.offset ?? 0),
});
emit(result, parseFormat(args.format as string));
},
});
const speechesList = defineCommand({
meta: {
name: "list",
description: withExamples(
"List speeches (interventi) in Camera or Senato.",
speechesTool.examples,
),
},
args: {
chamber: {
type: "string",
default: "camera",
description: "camera or senato",
},
legislature: { type: "string", description: "Legislature number" },
"deputy-uri": {
type: "string",
description: "Full URI of a deputy/senator",
},
"count-only": {
type: "boolean",
description: "Return only the total count",
},
limit: { type: "string", default: "100", description: "Max rows to return" },
offset: { type: "string", default: "0", description: "Offset for pagination" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const chamber = (args.chamber as string) === "senato" ? "senato" : "camera";
const result = await runTool(speechesTool, {
chamber,
legislature: parseIntFlag(args.legislature as string, "legislature"),
deputyUri: (args["deputy-uri"] as string) || undefined,
countOnly: Boolean(args["count-only"]),
limit: parseIntFlag(args.limit as string, "limit") ?? 100,
offset: Number(args.offset ?? 0),
});
emit(result, parseFormat(args.format as string));
},
});
const aicList = defineCommand({
meta: {
name: "list",
description: withExamples(
"List atti di indirizzo e controllo of Camera dei Deputati.",
aicTool.examples,
),
},
args: {
legislature: { type: "string", description: "Legislature number" },
"deputy-uri": { type: "string", description: "Full URI of a deputy (signatory)" },
"primary-only": { type: "boolean", description: "Only primary signatory matches" },
keyword: { type: "string", description: "Search in the act text/object (label, title, description), word-boundary match" },
type: { type: "string", description: "Filter by act type (partial match on dc:type, e.g. 'immediata' for question time)" },
"date-from": { type: "string", description: "Start date YYYY-MM-DD" },
"date-to": { type: "string", description: "End date YYYY-MM-DD" },
"count-only": { type: "boolean", description: "Return only the total count (column count)" },
limit: { type: "string", default: "100", description: "Max rows to return" },
offset: { type: "string", default: "0", description: "Offset for pagination" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const result = await runTool(aicTool, {
countOnly: args["count-only"] === true,
legislature: parseIntFlag(args.legislature as string, "legislature"),
deputyUri: (args["deputy-uri"] as string) || undefined,
primaryOnly: args["primary-only"] === true,
keyword: (args.keyword as string) || undefined,
type: (args.type as string) || undefined,
dateFrom: (args["date-from"] as string) || undefined,
dateTo: (args["date-to"] as string) || undefined,
limit: parseIntFlag(args.limit as string, "limit") ?? 100,
offset: Number(args.offset ?? 0),
});
emit(result, parseFormat(args.format as string));
},
});
const voteDetailShow = defineCommand({
meta: {
name: "show",
description: withExamples(
"Show individual deputy votes for a single Camera votazione.",
voteDetailTool.examples,
),
},
args: {
"vote-uri": { type: "string", description: "Full URI of the votazione", required: true },
"group-acronym": { type: "string", description: "Filter by group acronym (es. FDI, PD-IDP, M5S)" },
"vote-type": { type: "string", description: "Filter by vote type: Favorevole|Contrario|Astensione|Non ha votato" },
limit: { type: "string", default: "700", description: "Max rows to return" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const result = await runTool(voteDetailTool, {
voteUri: args["vote-uri"] as string,
groupAcronym: args["group-acronym"] as string | undefined,
voteType: args["vote-type"] as "Favorevole" | "Contrario" | "Astensione" | "Non ha votato" | undefined,
limit: parseIntFlag(args.limit as string, "limit") ?? 700,
});
emit(result, parseFormat(args.format as string));
},
});
const attendanceShow = defineCommand({
meta: {
name: "show",
description: withExamples(
"Aggregate vote counts for a single deputy across a legislature.",
attendanceTool.examples,
),
},
args: {
uri: { type: "string", description: "Full URI of the deputy" },
id: { type: "string", description: "Numeric deputy ID (use with --legislature)" },
legislature: { type: "string", description: "Legislature number (use with --id)" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const result = await runTool(attendanceTool, {
uri: (args.uri as string) || undefined,
id: parseIntFlag(args.id as string, "id"),
legislature: parseIntFlag(args.legislature as string, "legislature"),
});
emit(result, parseFormat(args.format as string));
},
});
const senatoAttendanceShow = defineCommand({
meta: {
name: "show",
description: withExamples(
"Aggregate vote counts for a single senator across a legislature.",
senatoAttendanceTool.examples,
),
},
args: {
"senator-uri": { type: "string", description: "Full URI of the senator", required: true },
legislature: { type: "string", default: "19", description: "Legislature number (default 19)" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const result = await runTool(senatoAttendanceTool, {
senatorUri: args["senator-uri"] as string,
legislature: parseIntFlag(args.legislature as string, "legislature") ?? 19,
});
emit(result, parseFormat(args.format as string));
},
});
const groupMembersList = defineCommand({
meta: {
name: "list",
description: withExamples(
"List members of Camera parliamentary groups.",
groupMembersTool.examples,
),
},
args: {
"group-uri": { type: "string", description: "Full URI of a parliamentary group" },
"deputy-uri": { type: "string", description: "Full URI of a deputy (returns all groups)" },
legislature: { type: "string", description: "Legislature number" },
limit: { type: "string", default: "200", description: "Max rows to return" },
offset: { type: "string", default: "0", description: "Offset for pagination" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const result = await runTool(groupMembersTool, {
groupUri: (args["group-uri"] as string) || undefined,
deputyUri: (args["deputy-uri"] as string) || undefined,
legislature: parseIntFlag(args.legislature as string, "legislature"),
limit: parseIntFlag(args.limit as string, "limit") ?? 200,
offset: Number(args.offset ?? 0),
});
emit(result, parseFormat(args.format as string));
},
});
const senatorGroupMembersList = defineCommand({
meta: {
name: "list",
description: withExamples(
"List members of Senato parliamentary groups.",
senatorGroupMembersTool.examples,
),
},
args: {
"group-uri": { type: "string", description: "Full URI of a Senato parliamentary group" },
legislature: { type: "string", description: "Legislature number" },
"as-of": { type: "string", description: "Date YYYY-MM-DD (default: today)" },
limit: { type: "string", default: "200", description: "Max rows to return" },
offset: { type: "string", default: "0", description: "Offset for pagination" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const result = await runTool(senatorGroupMembersTool, {
groupUri: (args["group-uri"] as string) || undefined,
legislature: parseIntFlag(args.legislature as string, "legislature"),
asOf: (args["as-of"] as string) || undefined,
limit: parseIntFlag(args.limit as string, "limit") ?? 200,
offset: Number(args.offset ?? 0),
});
emit(result, parseFormat(args.format as string));
},
});
const govMembersList = defineCommand({
meta: {
name: "list",
description: withExamples(
"List members of Italian governments.",
govMembersTool.examples,
),
},
args: {
"government-uri": { type: "string", description: "Full URI of a government" },
legislature: { type: "string", description: "Legislature number" },
name: { type: "string", description: "Search by name (case-insensitive)" },
limit: { type: "string", default: "100", description: "Max rows to return" },
offset: { type: "string", default: "0", description: "Offset for pagination" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const result = await runTool(govMembersTool, {
governmentUri: (args["government-uri"] as string) || undefined,
legislature: parseIntFlag(args.legislature as string, "legislature"),
name: (args.name as string) || undefined,
limit: parseIntFlag(args.limit as string, "limit") ?? 100,
offset: Number(args.offset ?? 0),
});
emit(result, parseFormat(args.format as string));
},
});
const committeesList = defineCommand({
meta: {
name: "list",
description: withExamples(
"List Camera/Senato committees.",
committeesTool.examples,
),
},
args: {
chamber: { type: "string", default: "both", description: "camera, senato, or both" },
legislature: { type: "string", description: "Legislature number (Camera default: 19; Senato: shows only active committees)" },
limit: { type: "string", default: "300", description: "Max rows to return" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const chamber = (args.chamber as string) || "both";
if (!["camera", "senato", "both"].includes(chamber)) {
throw new Error(`Invalid --chamber "${chamber}". Expected: camera, senato, both.`);
}
const result = await runTool(committeesTool, {
chamber: chamber as "camera" | "senato" | "both",
legislature: parseIntFlag(args.legislature as string, "legislature"),
limit: parseIntFlag(args.limit as string, "limit") ?? 300,
});
emit(result, parseFormat(args.format as string));
},
});
const billProgressList = defineCommand({
meta: {
name: "list",
description: withExamples(
"Bill progress / iter. Senato: list DDL with current status. Camera: full iter timeline of a single atto (use --uri).",
billProgressTool.examples,
),
},
args: {
"ddl-uri": { type: "string", description: "Full URI of a Senato DDL" },
uri: {
type: "string",
description:
"Full URI of a Camera atto (e.g. http://dati.camera.it/ocd/attocamera.rdf/ac19_2822): returns the full iter timeline",
},
keyword: {
type: "string",
description: "Search in DDL title (case-insensitive)",
},
number: {
type: "string",
description: "Senato act number (e.g. 1809 for S.1809); pair with --branch",
},
branch: {
type: "string",
description: "Branch for --number: S (Senato, default) or C (Camera)",
},
"date-from": {
type: "string",
description: "Presentation start date (YYYY-MM-DD)",
},
"date-to": {
type: "string",
description: "Presentation end date (YYYY-MM-DD)",
},
legislature: { type: "string", description: "Legislature number" },
limit: { type: "string", default: "100", description: "Max rows to return" },
offset: { type: "string", default: "0", description: "Offset for pagination" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const branchRaw = (args.branch as string) || undefined;
if (branchRaw && branchRaw !== "S" && branchRaw !== "C") {
throw new Error("--branch must be S or C");
}
const result = await runTool(billProgressTool, {
ddlUri: (args["ddl-uri"] as string) || undefined,
uri: (args.uri as string) || undefined,
keyword: (args.keyword as string) || undefined,
number: (args.number as string) || undefined,
branch: branchRaw as "S" | "C" | undefined,
dateFrom: (args["date-from"] as string) || undefined,
dateTo: (args["date-to"] as string) || undefined,
legislature: parseIntFlag(args.legislature as string, "legislature"),
limit: parseIntFlag(args.limit as string, "limit") ?? 100,
offset: Number(args.offset ?? 0),
});
emit(result, parseFormat(args.format as string));
},
});
const billSignatoriesShow = defineCommand({
meta: {
name: "show",
description: withExamples(
"Show signatories of a DDL (Camera or Senato, auto-detected from the URI).",
billSignatoriesTool.examples,
),
},
args: {
"bill-uri": { type: "string", description: "Full URI of a DDL (Camera or Senato)" },
"ddl-uri": { type: "string", description: "Alias of --bill-uri (deprecated)" },
limit: { type: "string", default: "200", description: "Max rows to return" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const billUri = (args["bill-uri"] as string) || (args["ddl-uri"] as string);
if (!billUri) throw new Error("--bill-uri is required");
const result = await runTool(billSignatoriesTool, {
billUri,
limit: parseIntFlag(args.limit as string, "limit") ?? 200,
});
emit(result, parseFormat(args.format as string));
},
});
const billRapporteursList = defineCommand({
meta: {
name: "list",
description: withExamples(
"List rapporteurs of a DDL (Camera or Senato, auto-detected from the URI).",
billRapporteursTool.examples,
),
},
args: {
"bill-uri": { type: "string", description: "Full URI of a DDL (Camera or Senato)", required: true },
limit: { type: "string", default: "100", description: "Max rows to return" },
format: { type: "string", default: "csv", description: "csv | jsonl" },
},
async run({ args }) {
const result = await runTool(billRapporteursTool, {
billUri: args["bill-uri"] as string,
limit: parseIntFlag(args.limit as string, "limit") ?? 100,
});
emit(result, parseFormat(args.format as string));
},
});
const billCommitteesList = defineCommand({
meta: {