arch-ops-server 0.1.3__py3-none-any.whl → 3.0.0__py3-none-any.whl

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.
arch_ops_server/server.py CHANGED
@@ -24,16 +24,59 @@ from mcp.types import (
24
24
  )
25
25
 
26
26
  from . import (
27
+ # Wiki functions
27
28
  search_wiki,
28
29
  get_wiki_page_as_text,
30
+ # AUR functions
29
31
  search_aur,
30
32
  get_aur_info,
31
33
  get_pkgbuild,
32
34
  analyze_pkgbuild_safety,
33
35
  analyze_package_metadata_risk,
36
+ install_package_secure,
37
+ # Pacman functions
34
38
  get_official_package_info,
35
39
  check_updates_dry_run,
36
- install_package_secure,
40
+ remove_package,
41
+ remove_packages_batch,
42
+ list_orphan_packages,
43
+ remove_orphans,
44
+ find_package_owner,
45
+ list_package_files,
46
+ search_package_files,
47
+ verify_package_integrity,
48
+ list_package_groups,
49
+ list_group_packages,
50
+ list_explicit_packages,
51
+ mark_as_explicit,
52
+ mark_as_dependency,
53
+ check_database_freshness,
54
+ # System functions
55
+ get_system_info,
56
+ check_disk_space,
57
+ get_pacman_cache_stats,
58
+ check_failed_services,
59
+ get_boot_logs,
60
+ # News functions
61
+ get_latest_news,
62
+ check_critical_news,
63
+ get_news_since_last_update,
64
+ # Logs functions
65
+ get_transaction_history,
66
+ find_when_installed,
67
+ find_failed_transactions,
68
+ get_database_sync_history,
69
+ # Mirrors functions
70
+ list_active_mirrors,
71
+ test_mirror_speed,
72
+ suggest_fastest_mirrors,
73
+ check_mirrorlist_health,
74
+ # Config functions
75
+ analyze_pacman_conf,
76
+ analyze_makepkg_conf,
77
+ check_ignored_packages,
78
+ get_parallel_downloads_setting,
79
+ # Utils
37
80
  IS_ARCH,
38
81
  run_command,
39
82
  )
@@ -58,12 +101,14 @@ async def list_resources() -> list[Resource]:
58
101
  List of Resource objects describing available URI schemes
59
102
  """
60
103
  return [
104
+ # Wiki resources
61
105
  Resource(
62
106
  uri="archwiki://Installation_guide",
63
107
  name="Arch Wiki - Installation Guide",
64
108
  mimeType="text/markdown",
65
109
  description="Example: Fetch Arch Wiki pages as Markdown"
66
110
  ),
111
+ # AUR resources
67
112
  Resource(
68
113
  uri="aur://yay/pkgbuild",
69
114
  name="AUR - yay PKGBUILD",
@@ -76,18 +121,134 @@ async def list_resources() -> list[Resource]:
76
121
  mimeType="application/json",
77
122
  description="Example: Fetch AUR package metadata (votes, maintainer, etc)"
78
123
  ),
124
+ # Official repository resources
79
125
  Resource(
80
126
  uri="archrepo://vim",
81
127
  name="Official Repository - Package Info",
82
128
  mimeType="application/json",
83
129
  description="Example: Fetch official repository package details"
84
130
  ),
131
+ # Pacman resources
85
132
  Resource(
86
133
  uri="pacman://installed",
87
134
  name="System - Installed Packages",
88
135
  mimeType="application/json",
89
136
  description="List installed packages on Arch Linux system"
90
137
  ),
138
+ Resource(
139
+ uri="pacman://orphans",
140
+ name="System - Orphan Packages",
141
+ mimeType="application/json",
142
+ description="List orphaned packages (dependencies no longer required)"
143
+ ),
144
+ Resource(
145
+ uri="pacman://explicit",
146
+ name="System - Explicitly Installed Packages",
147
+ mimeType="application/json",
148
+ description="List packages explicitly installed by user"
149
+ ),
150
+ Resource(
151
+ uri="pacman://groups",
152
+ name="System - Package Groups",
153
+ mimeType="application/json",
154
+ description="List all available package groups"
155
+ ),
156
+ Resource(
157
+ uri="pacman://group/base-devel",
158
+ name="System - Packages in base-devel Group",
159
+ mimeType="application/json",
160
+ description="Example: List packages in a specific group"
161
+ ),
162
+ # System resources
163
+ Resource(
164
+ uri="system://info",
165
+ name="System - System Information",
166
+ mimeType="application/json",
167
+ description="Get system information (kernel, arch, memory, uptime)"
168
+ ),
169
+ Resource(
170
+ uri="system://disk",
171
+ name="System - Disk Space",
172
+ mimeType="application/json",
173
+ description="Check disk space usage for critical paths"
174
+ ),
175
+ Resource(
176
+ uri="system://services/failed",
177
+ name="System - Failed Services",
178
+ mimeType="application/json",
179
+ description="List failed systemd services"
180
+ ),
181
+ Resource(
182
+ uri="system://logs/boot",
183
+ name="System - Boot Logs",
184
+ mimeType="text/plain",
185
+ description="Get recent boot logs from journalctl"
186
+ ),
187
+ # News resources
188
+ Resource(
189
+ uri="archnews://latest",
190
+ name="Arch News - Latest",
191
+ mimeType="application/json",
192
+ description="Get latest Arch Linux news announcements"
193
+ ),
194
+ Resource(
195
+ uri="archnews://critical",
196
+ name="Arch News - Critical",
197
+ mimeType="application/json",
198
+ description="Get critical Arch Linux news requiring manual intervention"
199
+ ),
200
+ Resource(
201
+ uri="archnews://since-update",
202
+ name="Arch News - Since Last Update",
203
+ mimeType="application/json",
204
+ description="Get news posted since last pacman update"
205
+ ),
206
+ # Transaction log resources
207
+ Resource(
208
+ uri="pacman://log/recent",
209
+ name="Pacman Log - Recent Transactions",
210
+ mimeType="application/json",
211
+ description="Get recent package transactions from pacman log"
212
+ ),
213
+ Resource(
214
+ uri="pacman://log/failed",
215
+ name="Pacman Log - Failed Transactions",
216
+ mimeType="application/json",
217
+ description="Get failed package transactions"
218
+ ),
219
+ # Mirror resources
220
+ Resource(
221
+ uri="mirrors://active",
222
+ name="Mirrors - Active Configuration",
223
+ mimeType="application/json",
224
+ description="Get currently configured mirrors"
225
+ ),
226
+ Resource(
227
+ uri="mirrors://health",
228
+ name="Mirrors - Health Status",
229
+ mimeType="application/json",
230
+ description="Get mirror configuration health assessment"
231
+ ),
232
+ # Config resources
233
+ Resource(
234
+ uri="config://pacman",
235
+ name="Config - pacman.conf",
236
+ mimeType="application/json",
237
+ description="Get parsed pacman.conf configuration"
238
+ ),
239
+ Resource(
240
+ uri="config://makepkg",
241
+ name="Config - makepkg.conf",
242
+ mimeType="application/json",
243
+ description="Get parsed makepkg.conf configuration"
244
+ ),
245
+ # Database resources
246
+ Resource(
247
+ uri="pacman://database/freshness",
248
+ name="Pacman - Database Freshness",
249
+ mimeType="application/json",
250
+ description="Check when package databases were last synchronized"
251
+ ),
91
252
  ]
92
253
 
93
254
 
@@ -95,20 +256,28 @@ async def list_resources() -> list[Resource]:
95
256
  async def read_resource(uri: str) -> str:
96
257
  """
97
258
  Read a resource by URI.
98
-
259
+
99
260
  Supported schemes:
100
261
  - archwiki://{page_title} - Returns Wiki page as Markdown
101
262
  - aur://{package}/pkgbuild - Returns raw PKGBUILD file
102
263
  - aur://{package}/info - Returns AUR package metadata
103
264
  - archrepo://{package} - Returns official repository package info
104
265
  - pacman://installed - Returns list of installed packages (Arch only)
105
-
266
+ - pacman://orphans - Returns list of orphaned packages (Arch only)
267
+ - pacman://explicit - Returns list of explicitly installed packages (Arch only)
268
+ - pacman://groups - Returns list of all package groups (Arch only)
269
+ - pacman://group/{group_name} - Returns packages in a specific group (Arch only)
270
+ - system://info - Returns system information
271
+ - system://disk - Returns disk space information
272
+ - system://services/failed - Returns failed systemd services
273
+ - system://logs/boot - Returns recent boot logs
274
+
106
275
  Args:
107
276
  uri: Resource URI (can be string or AnyUrl object)
108
-
277
+
109
278
  Returns:
110
279
  Resource content as string
111
-
280
+
112
281
  Raises:
113
282
  ValueError: If URI scheme is unsupported or resource not found
114
283
  """
@@ -169,26 +338,159 @@ async def read_resource(uri: str) -> str:
169
338
  return json.dumps(package_info, indent=2)
170
339
 
171
340
  elif scheme == "pacman":
172
- if parsed.netloc == "installed" or parsed.path == "/installed":
173
- if not IS_ARCH:
174
- raise ValueError("pacman://installed only available on Arch Linux systems")
175
-
341
+ if not IS_ARCH:
342
+ raise ValueError(f"pacman:// resources only available on Arch Linux systems")
343
+
344
+ resource_path = parsed.netloc or parsed.path.lstrip('/')
345
+
346
+ if resource_path == "installed":
176
347
  # Get installed packages
177
- result = run_command(["pacman", "-Q"])
178
- if result.returncode != 0:
179
- raise ValueError(f"Failed to get installed packages: {result.stderr}")
180
-
348
+ exit_code, stdout, stderr = await run_command(["pacman", "-Q"])
349
+ if exit_code != 0:
350
+ raise ValueError(f"Failed to get installed packages: {stderr}")
351
+
181
352
  # Parse pacman output
182
353
  packages = []
183
- for line in result.stdout.strip().split('\n'):
354
+ for line in stdout.strip().split('\n'):
184
355
  if line.strip():
185
356
  name, version = line.strip().rsplit(' ', 1)
186
357
  packages.append({"name": name, "version": version})
187
-
358
+
188
359
  return json.dumps(packages, indent=2)
360
+
361
+ elif resource_path == "orphans":
362
+ # Get orphan packages
363
+ result = await list_orphan_packages()
364
+ return json.dumps(result, indent=2)
365
+
366
+ elif resource_path == "explicit":
367
+ # Get explicitly installed packages
368
+ result = await list_explicit_packages()
369
+ return json.dumps(result, indent=2)
370
+
371
+ elif resource_path == "groups":
372
+ # Get all package groups
373
+ result = await list_package_groups()
374
+ return json.dumps(result, indent=2)
375
+
376
+ elif resource_path.startswith("group/"):
377
+ # Get packages in specific group
378
+ group_name = resource_path.split('/', 1)[1]
379
+ if not group_name:
380
+ raise ValueError("Group name required (e.g., pacman://group/base-devel)")
381
+ result = await list_group_packages(group_name)
382
+ return json.dumps(result, indent=2)
383
+
384
+ elif resource_path.startswith("log/"):
385
+ # Transaction log resources
386
+ log_type = resource_path.split('/', 1)[1] if '/' in resource_path else ""
387
+
388
+ if log_type == "recent":
389
+ result = await get_transaction_history()
390
+ return json.dumps(result, indent=2)
391
+ elif log_type == "failed":
392
+ result = await find_failed_transactions()
393
+ return json.dumps(result, indent=2)
394
+ else:
395
+ raise ValueError(f"Unsupported log resource: {log_type}")
396
+
397
+ elif resource_path == "database/freshness":
398
+ # Database freshness check
399
+ result = await check_database_freshness()
400
+ return json.dumps(result, indent=2)
401
+
189
402
  else:
190
- raise ValueError("Unsupported pacman resource (only pacman://installed supported)")
191
-
403
+ raise ValueError(f"Unsupported pacman resource: {resource_path}")
404
+
405
+ elif scheme == "system":
406
+ resource_path = parsed.netloc or parsed.path.lstrip('/')
407
+
408
+ if resource_path == "info":
409
+ # Get system information
410
+ result = await get_system_info()
411
+ return json.dumps(result, indent=2)
412
+
413
+ elif resource_path == "disk":
414
+ # Get disk space information
415
+ result = await check_disk_space()
416
+ return json.dumps(result, indent=2)
417
+
418
+ elif resource_path == "services/failed":
419
+ # Get failed services
420
+ result = await check_failed_services()
421
+ return json.dumps(result, indent=2)
422
+
423
+ elif resource_path == "logs/boot":
424
+ # Get boot logs
425
+ result = await get_boot_logs()
426
+ # Return raw text for logs
427
+ if result.get("success"):
428
+ return result.get("logs", "")
429
+ else:
430
+ raise ValueError(result.get("error", "Failed to get boot logs"))
431
+
432
+ else:
433
+ raise ValueError(f"Unsupported system resource: {resource_path}")
434
+
435
+ elif scheme == "archnews":
436
+ resource_path = parsed.netloc or parsed.path.lstrip('/')
437
+
438
+ if resource_path == "latest":
439
+ # Get latest news
440
+ result = await get_latest_news()
441
+ return json.dumps(result, indent=2)
442
+
443
+ elif resource_path == "critical":
444
+ # Get critical news
445
+ result = await check_critical_news()
446
+ return json.dumps(result, indent=2)
447
+
448
+ elif resource_path == "since-update":
449
+ # Get news since last update
450
+ result = await get_news_since_last_update()
451
+ return json.dumps(result, indent=2)
452
+
453
+ else:
454
+ raise ValueError(f"Unsupported archnews resource: {resource_path}")
455
+
456
+ elif scheme == "mirrors":
457
+ if not IS_ARCH:
458
+ raise ValueError(f"mirrors:// resources only available on Arch Linux systems")
459
+
460
+ resource_path = parsed.netloc or parsed.path.lstrip('/')
461
+
462
+ if resource_path == "active":
463
+ # Get active mirrors
464
+ result = await list_active_mirrors()
465
+ return json.dumps(result, indent=2)
466
+
467
+ elif resource_path == "health":
468
+ # Get mirror health
469
+ result = await check_mirrorlist_health()
470
+ return json.dumps(result, indent=2)
471
+
472
+ else:
473
+ raise ValueError(f"Unsupported mirrors resource: {resource_path}")
474
+
475
+ elif scheme == "config":
476
+ if not IS_ARCH:
477
+ raise ValueError(f"config:// resources only available on Arch Linux systems")
478
+
479
+ resource_path = parsed.netloc or parsed.path.lstrip('/')
480
+
481
+ if resource_path == "pacman":
482
+ # Get pacman.conf
483
+ result = await analyze_pacman_conf()
484
+ return json.dumps(result, indent=2)
485
+
486
+ elif resource_path == "makepkg":
487
+ # Get makepkg.conf
488
+ result = await analyze_makepkg_conf()
489
+ return json.dumps(result, indent=2)
490
+
491
+ else:
492
+ raise ValueError(f"Unsupported config resource: {resource_path}")
493
+
192
494
  else:
193
495
  raise ValueError(f"Unsupported URI scheme: {scheme}")
194
496
 
@@ -253,73 +555,549 @@ async def list_tools() -> list[Tool]:
253
555
  "required": ["query"]
254
556
  }
255
557
  ),
256
-
558
+
559
+ Tool(
560
+ name="get_official_package_info",
561
+ description="Get information about an official Arch repository package (Core, Extra, etc.). Uses local pacman if available, otherwise queries archlinux.org API. Always prefer official packages over AUR when available.",
562
+ inputSchema={
563
+ "type": "object",
564
+ "properties": {
565
+ "package_name": {
566
+ "type": "string",
567
+ "description": "Exact package name"
568
+ }
569
+ },
570
+ "required": ["package_name"]
571
+ }
572
+ ),
573
+
574
+ Tool(
575
+ name="check_updates_dry_run",
576
+ description="Check for available system updates without applying them. Only works on Arch Linux systems. Requires pacman-contrib package. Safe read-only operation that shows pending updates.",
577
+ inputSchema={
578
+ "type": "object",
579
+ "properties": {}
580
+ }
581
+ ),
582
+
583
+ Tool(
584
+ name="install_package_secure",
585
+ description="Install a package with comprehensive security checks. Workflow: 1. Check official repos first (safer) 2. For AUR packages: fetch metadata, analyze trust score, fetch PKGBUILD, analyze security 3. Block installation if critical security issues found 4. Check for AUR helper (paru > yay) 5. Install with --noconfirm if all checks pass. Only works on Arch Linux. Requires sudo access and paru/yay for AUR packages.",
586
+ inputSchema={
587
+ "type": "object",
588
+ "properties": {
589
+ "package_name": {
590
+ "type": "string",
591
+ "description": "Name of package to install (checks official repos first, then AUR)"
592
+ }
593
+ },
594
+ "required": ["package_name"]
595
+ }
596
+ ),
597
+
598
+ Tool(
599
+ name="analyze_pkgbuild_safety",
600
+ description="Analyze PKGBUILD content for security issues and dangerous patterns. Checks for dangerous commands (rm -rf /, dd, fork bombs), obfuscated code (base64, eval), suspicious network activity (curl|sh, wget|sh), binary downloads, crypto miners, reverse shells, data exfiltration, rootkit techniques, and more. Returns risk score (0-100) and detailed findings. Use this tool to manually audit AUR packages before installation.",
601
+ inputSchema={
602
+ "type": "object",
603
+ "properties": {
604
+ "pkgbuild_content": {
605
+ "type": "string",
606
+ "description": "Raw PKGBUILD content to analyze"
607
+ }
608
+ },
609
+ "required": ["pkgbuild_content"]
610
+ }
611
+ ),
612
+
613
+ Tool(
614
+ name="analyze_package_metadata_risk",
615
+ description="Analyze AUR package metadata for trustworthiness and security indicators. Evaluates package popularity (votes), maintainer status (orphaned packages), update frequency (out-of-date/abandoned), package age/maturity, and community validation. Returns trust score (0-100) with risk factors and trust indicators. Use this alongside PKGBUILD analysis for comprehensive security assessment.",
616
+ inputSchema={
617
+ "type": "object",
618
+ "properties": {
619
+ "package_info": {
620
+ "type": "object",
621
+ "description": "Package metadata from AUR (from search_aur or get_aur_info results)"
622
+ }
623
+ },
624
+ "required": ["package_info"]
625
+ }
626
+ ),
627
+
628
+ # Package Removal Tools
629
+ Tool(
630
+ name="remove_package",
631
+ description="Remove a package from the system. Supports various removal strategies: basic removal, removal with dependencies, or forced removal. Only works on Arch Linux. Requires sudo access.",
632
+ inputSchema={
633
+ "type": "object",
634
+ "properties": {
635
+ "package_name": {
636
+ "type": "string",
637
+ "description": "Name of the package to remove"
638
+ },
639
+ "remove_dependencies": {
640
+ "type": "boolean",
641
+ "description": "Remove package and its dependencies (pacman -Rs). Default: false",
642
+ "default": False
643
+ },
644
+ "force": {
645
+ "type": "boolean",
646
+ "description": "Force removal ignoring dependencies (pacman -Rdd). Use with caution! Default: false",
647
+ "default": False
648
+ }
649
+ },
650
+ "required": ["package_name"]
651
+ }
652
+ ),
653
+
654
+ Tool(
655
+ name="remove_packages_batch",
656
+ description="Remove multiple packages in a single transaction. More efficient than removing packages one by one. Only works on Arch Linux. Requires sudo access.",
657
+ inputSchema={
658
+ "type": "object",
659
+ "properties": {
660
+ "package_names": {
661
+ "type": "array",
662
+ "items": {"type": "string"},
663
+ "description": "List of package names to remove"
664
+ },
665
+ "remove_dependencies": {
666
+ "type": "boolean",
667
+ "description": "Remove packages and their dependencies. Default: false",
668
+ "default": False
669
+ }
670
+ },
671
+ "required": ["package_names"]
672
+ }
673
+ ),
674
+
675
+ # Orphan Package Management
676
+ Tool(
677
+ name="list_orphan_packages",
678
+ description="List all orphaned packages (dependencies no longer required by any installed package). Shows package names and total disk space usage. Only works on Arch Linux.",
679
+ inputSchema={
680
+ "type": "object",
681
+ "properties": {}
682
+ }
683
+ ),
684
+
685
+ Tool(
686
+ name="remove_orphans",
687
+ description="Remove all orphaned packages to free up disk space. Supports dry-run mode to preview changes and package exclusion. Only works on Arch Linux. Requires sudo access.",
688
+ inputSchema={
689
+ "type": "object",
690
+ "properties": {
691
+ "dry_run": {
692
+ "type": "boolean",
693
+ "description": "Preview what would be removed without actually removing. Default: true",
694
+ "default": True
695
+ },
696
+ "exclude": {
697
+ "type": "array",
698
+ "items": {"type": "string"},
699
+ "description": "List of package names to exclude from removal"
700
+ }
701
+ },
702
+ "required": []
703
+ }
704
+ ),
705
+
706
+ # Package Ownership Tools
707
+ Tool(
708
+ name="find_package_owner",
709
+ description="Find which package owns a specific file on the system. Useful for troubleshooting and understanding file origins. Only works on Arch Linux.",
710
+ inputSchema={
711
+ "type": "object",
712
+ "properties": {
713
+ "file_path": {
714
+ "type": "string",
715
+ "description": "Absolute path to the file (e.g., /usr/bin/vim)"
716
+ }
717
+ },
718
+ "required": ["file_path"]
719
+ }
720
+ ),
721
+
722
+ Tool(
723
+ name="list_package_files",
724
+ description="List all files owned by a package. Supports optional filtering by pattern. Only works on Arch Linux.",
725
+ inputSchema={
726
+ "type": "object",
727
+ "properties": {
728
+ "package_name": {
729
+ "type": "string",
730
+ "description": "Name of the package"
731
+ },
732
+ "filter_pattern": {
733
+ "type": "string",
734
+ "description": "Optional regex pattern to filter files (e.g., '*.conf' or '/etc/')"
735
+ }
736
+ },
737
+ "required": ["package_name"]
738
+ }
739
+ ),
740
+
741
+ Tool(
742
+ name="search_package_files",
743
+ description="Search for files across all packages in repositories. Requires package database sync (pacman -Fy). Only works on Arch Linux.",
744
+ inputSchema={
745
+ "type": "object",
746
+ "properties": {
747
+ "filename_pattern": {
748
+ "type": "string",
749
+ "description": "File name or pattern to search for (e.g., 'vim' or '*.service')"
750
+ }
751
+ },
752
+ "required": ["filename_pattern"]
753
+ }
754
+ ),
755
+
756
+ # Package Verification
757
+ Tool(
758
+ name="verify_package_integrity",
759
+ description="Verify the integrity of installed package files. Detects modified, missing, or corrupted files. Only works on Arch Linux.",
760
+ inputSchema={
761
+ "type": "object",
762
+ "properties": {
763
+ "package_name": {
764
+ "type": "string",
765
+ "description": "Name of the package to verify"
766
+ },
767
+ "thorough": {
768
+ "type": "boolean",
769
+ "description": "Perform thorough check including file attributes. Default: false",
770
+ "default": False
771
+ }
772
+ },
773
+ "required": ["package_name"]
774
+ }
775
+ ),
776
+
777
+ # Package Groups
778
+ Tool(
779
+ name="list_package_groups",
780
+ description="List all available package groups (e.g., base, base-devel, gnome). Only works on Arch Linux.",
781
+ inputSchema={
782
+ "type": "object",
783
+ "properties": {}
784
+ }
785
+ ),
786
+
787
+ Tool(
788
+ name="list_group_packages",
789
+ description="List all packages in a specific group. Only works on Arch Linux.",
790
+ inputSchema={
791
+ "type": "object",
792
+ "properties": {
793
+ "group_name": {
794
+ "type": "string",
795
+ "description": "Name of the package group (e.g., 'base-devel', 'gnome')"
796
+ }
797
+ },
798
+ "required": ["group_name"]
799
+ }
800
+ ),
801
+
802
+ # Install Reason Management
803
+ Tool(
804
+ name="list_explicit_packages",
805
+ description="List all packages explicitly installed by the user (not installed as dependencies). Useful for creating backup lists or understanding system composition. Only works on Arch Linux.",
806
+ inputSchema={
807
+ "type": "object",
808
+ "properties": {}
809
+ }
810
+ ),
811
+
812
+ Tool(
813
+ name="mark_as_explicit",
814
+ description="Mark a package as explicitly installed. Prevents it from being removed as an orphan. Only works on Arch Linux.",
815
+ inputSchema={
816
+ "type": "object",
817
+ "properties": {
818
+ "package_name": {
819
+ "type": "string",
820
+ "description": "Name of the package to mark as explicit"
821
+ }
822
+ },
823
+ "required": ["package_name"]
824
+ }
825
+ ),
826
+
827
+ Tool(
828
+ name="mark_as_dependency",
829
+ description="Mark a package as a dependency. Allows it to be removed as an orphan if no packages depend on it. Only works on Arch Linux.",
830
+ inputSchema={
831
+ "type": "object",
832
+ "properties": {
833
+ "package_name": {
834
+ "type": "string",
835
+ "description": "Name of the package to mark as dependency"
836
+ }
837
+ },
838
+ "required": ["package_name"]
839
+ }
840
+ ),
841
+
842
+ # System Diagnostic Tools
843
+ Tool(
844
+ name="get_system_info",
845
+ description="Get comprehensive system information including kernel version, architecture, hostname, uptime, and memory statistics. Works on any system.",
846
+ inputSchema={
847
+ "type": "object",
848
+ "properties": {}
849
+ }
850
+ ),
851
+
852
+ Tool(
853
+ name="check_disk_space",
854
+ description="Check disk space usage for critical filesystem paths including root, home, var, and pacman cache. Warns when space is low. Works on any system.",
855
+ inputSchema={
856
+ "type": "object",
857
+ "properties": {}
858
+ }
859
+ ),
860
+
861
+ Tool(
862
+ name="get_pacman_cache_stats",
863
+ description="Analyze pacman package cache statistics including size, package count, and cache age. Only works on Arch Linux.",
864
+ inputSchema={
865
+ "type": "object",
866
+ "properties": {}
867
+ }
868
+ ),
869
+
870
+ Tool(
871
+ name="check_failed_services",
872
+ description="Check for failed systemd services. Useful for diagnosing system issues. Works on systemd-based systems.",
873
+ inputSchema={
874
+ "type": "object",
875
+ "properties": {}
876
+ }
877
+ ),
878
+
879
+ Tool(
880
+ name="get_boot_logs",
881
+ description="Retrieve recent boot logs from journalctl. Useful for troubleshooting boot issues. Works on systemd-based systems.",
882
+ inputSchema={
883
+ "type": "object",
884
+ "properties": {
885
+ "lines": {
886
+ "type": "integer",
887
+ "description": "Number of log lines to retrieve. Default: 100",
888
+ "default": 100
889
+ }
890
+ },
891
+ "required": []
892
+ }
893
+ ),
894
+
895
+ # News Tools
896
+ Tool(
897
+ name="get_latest_news",
898
+ description="Fetch recent Arch Linux news from RSS feed. Returns title, date, summary, and link for each news item.",
899
+ inputSchema={
900
+ "type": "object",
901
+ "properties": {
902
+ "limit": {
903
+ "type": "integer",
904
+ "description": "Maximum number of news items to return (default 10)",
905
+ "default": 10
906
+ },
907
+ "since_date": {
908
+ "type": "string",
909
+ "description": "Optional date in ISO format (YYYY-MM-DD) to filter news"
910
+ }
911
+ },
912
+ "required": []
913
+ }
914
+ ),
915
+
916
+ Tool(
917
+ name="check_critical_news",
918
+ description="Check for critical Arch Linux news requiring manual intervention. Scans recent news for keywords: 'manual intervention', 'action required', 'breaking change', etc.",
919
+ inputSchema={
920
+ "type": "object",
921
+ "properties": {
922
+ "limit": {
923
+ "type": "integer",
924
+ "description": "Number of recent news items to check (default 20)",
925
+ "default": 20
926
+ }
927
+ },
928
+ "required": []
929
+ }
930
+ ),
931
+
932
+ Tool(
933
+ name="get_news_since_last_update",
934
+ description="Get news posted since last pacman update. Parses /var/log/pacman.log for last update timestamp. Only works on Arch Linux.",
935
+ inputSchema={
936
+ "type": "object",
937
+ "properties": {}
938
+ }
939
+ ),
940
+
941
+ # Transaction Log Tools
942
+ Tool(
943
+ name="get_transaction_history",
944
+ description="Get recent package transactions from pacman log. Shows installed, upgraded, and removed packages. Only works on Arch Linux.",
945
+ inputSchema={
946
+ "type": "object",
947
+ "properties": {
948
+ "limit": {
949
+ "type": "integer",
950
+ "description": "Maximum number of transactions to return (default 50)",
951
+ "default": 50
952
+ },
953
+ "transaction_type": {
954
+ "type": "string",
955
+ "description": "Filter by type: install/remove/upgrade/all (default all)",
956
+ "enum": ["all", "install", "remove", "upgrade"],
957
+ "default": "all"
958
+ }
959
+ },
960
+ "required": []
961
+ }
962
+ ),
963
+
964
+ Tool(
965
+ name="find_when_installed",
966
+ description="Find when a package was first installed and its upgrade history. Only works on Arch Linux.",
967
+ inputSchema={
968
+ "type": "object",
969
+ "properties": {
970
+ "package_name": {
971
+ "type": "string",
972
+ "description": "Name of the package to search for"
973
+ }
974
+ },
975
+ "required": ["package_name"]
976
+ }
977
+ ),
978
+
979
+ Tool(
980
+ name="find_failed_transactions",
981
+ description="Find failed package transactions in pacman log. Only works on Arch Linux.",
982
+ inputSchema={
983
+ "type": "object",
984
+ "properties": {}
985
+ }
986
+ ),
987
+
988
+ Tool(
989
+ name="get_database_sync_history",
990
+ description="Get database synchronization history. Shows when 'pacman -Sy' was run. Only works on Arch Linux.",
991
+ inputSchema={
992
+ "type": "object",
993
+ "properties": {
994
+ "limit": {
995
+ "type": "integer",
996
+ "description": "Maximum number of sync events to return (default 20)",
997
+ "default": 20
998
+ }
999
+ },
1000
+ "required": []
1001
+ }
1002
+ ),
1003
+
1004
+ # Mirror Management Tools
1005
+ Tool(
1006
+ name="list_active_mirrors",
1007
+ description="List currently configured mirrors from mirrorlist. Only works on Arch Linux.",
1008
+ inputSchema={
1009
+ "type": "object",
1010
+ "properties": {}
1011
+ }
1012
+ ),
1013
+
1014
+ Tool(
1015
+ name="test_mirror_speed",
1016
+ description="Test mirror response time. Can test a specific mirror or all active mirrors. Only works on Arch Linux.",
1017
+ inputSchema={
1018
+ "type": "object",
1019
+ "properties": {
1020
+ "mirror_url": {
1021
+ "type": "string",
1022
+ "description": "Specific mirror URL to test, or omit to test all active mirrors"
1023
+ }
1024
+ },
1025
+ "required": []
1026
+ }
1027
+ ),
1028
+
1029
+ Tool(
1030
+ name="suggest_fastest_mirrors",
1031
+ description="Suggest optimal mirrors based on official mirror status from archlinux.org. Filters by country if specified.",
1032
+ inputSchema={
1033
+ "type": "object",
1034
+ "properties": {
1035
+ "country": {
1036
+ "type": "string",
1037
+ "description": "Optional country code to filter mirrors (e.g., 'US', 'DE')"
1038
+ },
1039
+ "limit": {
1040
+ "type": "integer",
1041
+ "description": "Number of mirrors to suggest (default 10)",
1042
+ "default": 10
1043
+ }
1044
+ },
1045
+ "required": []
1046
+ }
1047
+ ),
1048
+
1049
+ Tool(
1050
+ name="check_mirrorlist_health",
1051
+ description="Verify mirror configuration health. Checks for common issues like no active mirrors, outdated mirrorlist, high latency. Only works on Arch Linux.",
1052
+ inputSchema={
1053
+ "type": "object",
1054
+ "properties": {}
1055
+ }
1056
+ ),
1057
+
1058
+ # Configuration Tools
257
1059
  Tool(
258
- name="get_official_package_info",
259
- description="Get information about an official Arch repository package (Core, Extra, etc.). Uses local pacman if available, otherwise queries archlinux.org API. Always prefer official packages over AUR when available.",
1060
+ name="analyze_pacman_conf",
1061
+ description="Parse and analyze pacman.conf. Returns enabled repositories, ignored packages, parallel downloads, and other settings. Only works on Arch Linux.",
260
1062
  inputSchema={
261
1063
  "type": "object",
262
- "properties": {
263
- "package_name": {
264
- "type": "string",
265
- "description": "Exact package name"
266
- }
267
- },
268
- "required": ["package_name"]
1064
+ "properties": {}
269
1065
  }
270
1066
  ),
271
-
1067
+
272
1068
  Tool(
273
- name="check_updates_dry_run",
274
- description="Check for available system updates without applying them. Only works on Arch Linux systems. Requires pacman-contrib package. Safe read-only operation that shows pending updates.",
1069
+ name="analyze_makepkg_conf",
1070
+ description="Parse and analyze makepkg.conf. Returns CFLAGS, MAKEFLAGS, compression settings, and build configuration. Only works on Arch Linux.",
275
1071
  inputSchema={
276
1072
  "type": "object",
277
1073
  "properties": {}
278
1074
  }
279
1075
  ),
280
-
1076
+
281
1077
  Tool(
282
- name="install_package_secure",
283
- description="Install a package with comprehensive security checks. Workflow: 1. Check official repos first (safer) 2. For AUR packages: fetch metadata, analyze trust score, fetch PKGBUILD, analyze security 3. Block installation if critical security issues found 4. Check for AUR helper (paru > yay) 5. Install with --noconfirm if all checks pass. Only works on Arch Linux. Requires sudo access and paru/yay for AUR packages.",
1078
+ name="check_ignored_packages",
1079
+ description="List packages ignored in updates from pacman.conf. Warns if critical system packages are ignored. Only works on Arch Linux.",
284
1080
  inputSchema={
285
1081
  "type": "object",
286
- "properties": {
287
- "package_name": {
288
- "type": "string",
289
- "description": "Name of package to install (checks official repos first, then AUR)"
290
- }
291
- },
292
- "required": ["package_name"]
1082
+ "properties": {}
293
1083
  }
294
1084
  ),
295
-
1085
+
296
1086
  Tool(
297
- name="analyze_pkgbuild_safety",
298
- description="Analyze PKGBUILD content for security issues and dangerous patterns. Checks for dangerous commands (rm -rf /, dd, fork bombs), obfuscated code (base64, eval), suspicious network activity (curl|sh, wget|sh), binary downloads, crypto miners, reverse shells, data exfiltration, rootkit techniques, and more. Returns risk score (0-100) and detailed findings. Use this tool to manually audit AUR packages before installation.",
1087
+ name="get_parallel_downloads_setting",
1088
+ description="Get parallel downloads configuration from pacman.conf and provide recommendations. Only works on Arch Linux.",
299
1089
  inputSchema={
300
1090
  "type": "object",
301
- "properties": {
302
- "pkgbuild_content": {
303
- "type": "string",
304
- "description": "Raw PKGBUILD content to analyze"
305
- }
306
- },
307
- "required": ["pkgbuild_content"]
1091
+ "properties": {}
308
1092
  }
309
1093
  ),
310
-
1094
+
311
1095
  Tool(
312
- name="analyze_package_metadata_risk",
313
- description="Analyze AUR package metadata for trustworthiness and security indicators. Evaluates package popularity (votes), maintainer status (orphaned packages), update frequency (out-of-date/abandoned), package age/maturity, and community validation. Returns trust score (0-100) with risk factors and trust indicators. Use this alongside PKGBUILD analysis for comprehensive security assessment.",
1096
+ name="check_database_freshness",
1097
+ description="Check when package databases were last synchronized. Warns if databases are stale (> 24 hours). Only works on Arch Linux.",
314
1098
  inputSchema={
315
1099
  "type": "object",
316
- "properties": {
317
- "package_info": {
318
- "type": "object",
319
- "description": "Package metadata from AUR (from search_aur or get_aur_info results)"
320
- }
321
- },
322
- "required": ["package_info"]
1100
+ "properties": {}
323
1101
  }
324
1102
  ),
325
1103
  ]
@@ -384,7 +1162,265 @@ async def call_tool(name: str, arguments: dict[str, Any]) -> list[TextContent |
384
1162
  package_info = arguments["package_info"]
385
1163
  result = analyze_package_metadata_risk(package_info)
386
1164
  return [TextContent(type="text", text=json.dumps(result, indent=2))]
387
-
1165
+
1166
+ # Package Removal Tools
1167
+ elif name == "remove_package":
1168
+ if not IS_ARCH:
1169
+ return [TextContent(type="text", text="Error: remove_package only available on Arch Linux systems")]
1170
+
1171
+ package_name = arguments["package_name"]
1172
+ remove_dependencies = arguments.get("remove_dependencies", False)
1173
+ force = arguments.get("force", False)
1174
+ result = await remove_package(package_name, remove_dependencies, force)
1175
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1176
+
1177
+ elif name == "remove_packages_batch":
1178
+ if not IS_ARCH:
1179
+ return [TextContent(type="text", text="Error: remove_packages_batch only available on Arch Linux systems")]
1180
+
1181
+ package_names = arguments["package_names"]
1182
+ remove_dependencies = arguments.get("remove_dependencies", False)
1183
+ result = await remove_packages_batch(package_names, remove_dependencies)
1184
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1185
+
1186
+ # Orphan Package Management
1187
+ elif name == "list_orphan_packages":
1188
+ if not IS_ARCH:
1189
+ return [TextContent(type="text", text="Error: list_orphan_packages only available on Arch Linux systems")]
1190
+
1191
+ result = await list_orphan_packages()
1192
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1193
+
1194
+ elif name == "remove_orphans":
1195
+ if not IS_ARCH:
1196
+ return [TextContent(type="text", text="Error: remove_orphans only available on Arch Linux systems")]
1197
+
1198
+ dry_run = arguments.get("dry_run", True)
1199
+ exclude = arguments.get("exclude", None)
1200
+ result = await remove_orphans(dry_run, exclude)
1201
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1202
+
1203
+ # Package Ownership Tools
1204
+ elif name == "find_package_owner":
1205
+ if not IS_ARCH:
1206
+ return [TextContent(type="text", text="Error: find_package_owner only available on Arch Linux systems")]
1207
+
1208
+ file_path = arguments["file_path"]
1209
+ result = await find_package_owner(file_path)
1210
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1211
+
1212
+ elif name == "list_package_files":
1213
+ if not IS_ARCH:
1214
+ return [TextContent(type="text", text="Error: list_package_files only available on Arch Linux systems")]
1215
+
1216
+ package_name = arguments["package_name"]
1217
+ filter_pattern = arguments.get("filter_pattern", None)
1218
+ result = await list_package_files(package_name, filter_pattern)
1219
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1220
+
1221
+ elif name == "search_package_files":
1222
+ if not IS_ARCH:
1223
+ return [TextContent(type="text", text="Error: search_package_files only available on Arch Linux systems")]
1224
+
1225
+ filename_pattern = arguments["filename_pattern"]
1226
+ result = await search_package_files(filename_pattern)
1227
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1228
+
1229
+ # Package Verification
1230
+ elif name == "verify_package_integrity":
1231
+ if not IS_ARCH:
1232
+ return [TextContent(type="text", text="Error: verify_package_integrity only available on Arch Linux systems")]
1233
+
1234
+ package_name = arguments["package_name"]
1235
+ thorough = arguments.get("thorough", False)
1236
+ result = await verify_package_integrity(package_name, thorough)
1237
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1238
+
1239
+ # Package Groups
1240
+ elif name == "list_package_groups":
1241
+ if not IS_ARCH:
1242
+ return [TextContent(type="text", text="Error: list_package_groups only available on Arch Linux systems")]
1243
+
1244
+ result = await list_package_groups()
1245
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1246
+
1247
+ elif name == "list_group_packages":
1248
+ if not IS_ARCH:
1249
+ return [TextContent(type="text", text="Error: list_group_packages only available on Arch Linux systems")]
1250
+
1251
+ group_name = arguments["group_name"]
1252
+ result = await list_group_packages(group_name)
1253
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1254
+
1255
+ # Install Reason Management
1256
+ elif name == "list_explicit_packages":
1257
+ if not IS_ARCH:
1258
+ return [TextContent(type="text", text="Error: list_explicit_packages only available on Arch Linux systems")]
1259
+
1260
+ result = await list_explicit_packages()
1261
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1262
+
1263
+ elif name == "mark_as_explicit":
1264
+ if not IS_ARCH:
1265
+ return [TextContent(type="text", text="Error: mark_as_explicit only available on Arch Linux systems")]
1266
+
1267
+ package_name = arguments["package_name"]
1268
+ result = await mark_as_explicit(package_name)
1269
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1270
+
1271
+ elif name == "mark_as_dependency":
1272
+ if not IS_ARCH:
1273
+ return [TextContent(type="text", text="Error: mark_as_dependency only available on Arch Linux systems")]
1274
+
1275
+ package_name = arguments["package_name"]
1276
+ result = await mark_as_dependency(package_name)
1277
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1278
+
1279
+ # System Diagnostic Tools
1280
+ elif name == "get_system_info":
1281
+ result = await get_system_info()
1282
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1283
+
1284
+ elif name == "check_disk_space":
1285
+ result = await check_disk_space()
1286
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1287
+
1288
+ elif name == "get_pacman_cache_stats":
1289
+ if not IS_ARCH:
1290
+ return [TextContent(type="text", text="Error: get_pacman_cache_stats only available on Arch Linux systems")]
1291
+
1292
+ result = await get_pacman_cache_stats()
1293
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1294
+
1295
+ elif name == "check_failed_services":
1296
+ result = await check_failed_services()
1297
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1298
+
1299
+ elif name == "get_boot_logs":
1300
+ lines = arguments.get("lines", 100)
1301
+ result = await get_boot_logs(lines)
1302
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1303
+
1304
+ # News tools
1305
+ elif name == "get_latest_news":
1306
+ limit = arguments.get("limit", 10)
1307
+ since_date = arguments.get("since_date")
1308
+ result = await get_latest_news(limit=limit, since_date=since_date)
1309
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1310
+
1311
+ elif name == "check_critical_news":
1312
+ limit = arguments.get("limit", 20)
1313
+ result = await check_critical_news(limit=limit)
1314
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1315
+
1316
+ elif name == "get_news_since_last_update":
1317
+ if not IS_ARCH:
1318
+ return [TextContent(type="text", text="Error: get_news_since_last_update only available on Arch Linux systems")]
1319
+
1320
+ result = await get_news_since_last_update()
1321
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1322
+
1323
+ # Transaction log tools
1324
+ elif name == "get_transaction_history":
1325
+ if not IS_ARCH:
1326
+ return [TextContent(type="text", text="Error: get_transaction_history only available on Arch Linux systems")]
1327
+
1328
+ limit = arguments.get("limit", 50)
1329
+ transaction_type = arguments.get("transaction_type", "all")
1330
+ result = await get_transaction_history(limit=limit, transaction_type=transaction_type)
1331
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1332
+
1333
+ elif name == "find_when_installed":
1334
+ if not IS_ARCH:
1335
+ return [TextContent(type="text", text="Error: find_when_installed only available on Arch Linux systems")]
1336
+
1337
+ package_name = arguments.get("package_name")
1338
+ if not package_name:
1339
+ return [TextContent(type="text", text="Error: package_name required")]
1340
+
1341
+ result = await find_when_installed(package_name)
1342
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1343
+
1344
+ elif name == "find_failed_transactions":
1345
+ if not IS_ARCH:
1346
+ return [TextContent(type="text", text="Error: find_failed_transactions only available on Arch Linux systems")]
1347
+
1348
+ result = await find_failed_transactions()
1349
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1350
+
1351
+ elif name == "get_database_sync_history":
1352
+ if not IS_ARCH:
1353
+ return [TextContent(type="text", text="Error: get_database_sync_history only available on Arch Linux systems")]
1354
+
1355
+ limit = arguments.get("limit", 20)
1356
+ result = await get_database_sync_history(limit=limit)
1357
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1358
+
1359
+ # Mirror management tools
1360
+ elif name == "list_active_mirrors":
1361
+ if not IS_ARCH:
1362
+ return [TextContent(type="text", text="Error: list_active_mirrors only available on Arch Linux systems")]
1363
+
1364
+ result = await list_active_mirrors()
1365
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1366
+
1367
+ elif name == "test_mirror_speed":
1368
+ if not IS_ARCH:
1369
+ return [TextContent(type="text", text="Error: test_mirror_speed only available on Arch Linux systems")]
1370
+
1371
+ mirror_url = arguments.get("mirror_url")
1372
+ result = await test_mirror_speed(mirror_url=mirror_url)
1373
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1374
+
1375
+ elif name == "suggest_fastest_mirrors":
1376
+ country = arguments.get("country")
1377
+ limit = arguments.get("limit", 10)
1378
+ result = await suggest_fastest_mirrors(country=country, limit=limit)
1379
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1380
+
1381
+ elif name == "check_mirrorlist_health":
1382
+ if not IS_ARCH:
1383
+ return [TextContent(type="text", text="Error: check_mirrorlist_health only available on Arch Linux systems")]
1384
+
1385
+ result = await check_mirrorlist_health()
1386
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1387
+
1388
+ # Configuration tools
1389
+ elif name == "analyze_pacman_conf":
1390
+ if not IS_ARCH:
1391
+ return [TextContent(type="text", text="Error: analyze_pacman_conf only available on Arch Linux systems")]
1392
+
1393
+ result = await analyze_pacman_conf()
1394
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1395
+
1396
+ elif name == "analyze_makepkg_conf":
1397
+ if not IS_ARCH:
1398
+ return [TextContent(type="text", text="Error: analyze_makepkg_conf only available on Arch Linux systems")]
1399
+
1400
+ result = await analyze_makepkg_conf()
1401
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1402
+
1403
+ elif name == "check_ignored_packages":
1404
+ if not IS_ARCH:
1405
+ return [TextContent(type="text", text="Error: check_ignored_packages only available on Arch Linux systems")]
1406
+
1407
+ result = await check_ignored_packages()
1408
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1409
+
1410
+ elif name == "get_parallel_downloads_setting":
1411
+ if not IS_ARCH:
1412
+ return [TextContent(type="text", text="Error: get_parallel_downloads_setting only available on Arch Linux systems")]
1413
+
1414
+ result = await get_parallel_downloads_setting()
1415
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1416
+
1417
+ elif name == "check_database_freshness":
1418
+ if not IS_ARCH:
1419
+ return [TextContent(type="text", text="Error: check_database_freshness only available on Arch Linux systems")]
1420
+
1421
+ result = await check_database_freshness()
1422
+ return [TextContent(type="text", text=json.dumps(result, indent=2))]
1423
+
388
1424
  else:
389
1425
  raise ValueError(f"Unknown tool: {name}")
390
1426
 
@@ -440,6 +1476,11 @@ async def list_prompts() -> list[Prompt]:
440
1476
  }
441
1477
  ]
442
1478
  ),
1479
+ Prompt(
1480
+ name="safe_system_update",
1481
+ description="Enhanced system update workflow that checks for critical news, disk space, and failed services before updating",
1482
+ arguments=[]
1483
+ ),
443
1484
  ]
444
1485
 
445
1486
 
@@ -669,5 +1710,160 @@ paru -S {package_name} # or yay -S {package_name}
669
1710
  ]
670
1711
  )
671
1712
 
1713
+ elif name == "safe_system_update":
1714
+ if not IS_ARCH:
1715
+ return GetPromptResult(
1716
+ description="Safe system update workflow",
1717
+ messages=[
1718
+ PromptMessage(
1719
+ role="assistant",
1720
+ content=PromptMessage.TextContent(
1721
+ type="text",
1722
+ text="Error: safe_system_update prompt only available on Arch Linux systems"
1723
+ )
1724
+ )
1725
+ ]
1726
+ )
1727
+
1728
+ analysis = "# Safe System Update Workflow\n\n"
1729
+ warnings = []
1730
+ recommendations = []
1731
+
1732
+ # Step 1: Check for critical news
1733
+ try:
1734
+ critical_news = await check_critical_news(limit=10)
1735
+
1736
+ if critical_news.get("has_critical"):
1737
+ analysis += "## ⚠️ Critical Arch Linux News\n\n"
1738
+ for news_item in critical_news.get("critical_news", [])[:3]:
1739
+ analysis += f"**{news_item['title']}**\n"
1740
+ analysis += f"Published: {news_item['published']}\n"
1741
+ analysis += f"{news_item['summary'][:200]}...\n"
1742
+ analysis += f"[Read more]({news_item['link']})\n\n"
1743
+
1744
+ warnings.append("Critical news requiring manual intervention found!")
1745
+ recommendations.append("Read all critical news articles before updating")
1746
+ else:
1747
+ analysis += "## ✓ No Critical News\n\nNo manual intervention required for recent updates.\n\n"
1748
+ except Exception as e:
1749
+ analysis += f"## ⚠️ News Check Failed\n\n{str(e)}\n\n"
1750
+
1751
+ # Step 2: Check disk space
1752
+ try:
1753
+ disk_space = await check_disk_space()
1754
+ disk_usage = disk_space.get("disk_usage", {})
1755
+
1756
+ analysis += "## Disk Space Status\n\n"
1757
+ for path, info in disk_usage.items():
1758
+ if "warning" in info:
1759
+ analysis += f"- ⚠️ {path}: {info['available']} available ({info['use_percent']} used) - {info['warning']}\n"
1760
+ warnings.append(f"Low disk space on {path}")
1761
+ else:
1762
+ analysis += f"- ✓ {path}: {info['available']} available ({info['use_percent']} used)\n"
1763
+ analysis += "\n"
1764
+ except Exception as e:
1765
+ analysis += f"## ⚠️ Disk Space Check Failed\n\n{str(e)}\n\n"
1766
+
1767
+ # Step 3: Check pending updates
1768
+ try:
1769
+ updates = await check_updates_dry_run()
1770
+
1771
+ if updates.get("updates_available"):
1772
+ count = updates.get("count", 0)
1773
+ analysis += f"## Pending Updates ({count} packages)\n\n"
1774
+
1775
+ # Show first 10 updates
1776
+ for update in updates.get("packages", [])[:10]:
1777
+ analysis += f"- {update['package']}: {update['current_version']} → {update['new_version']}\n"
1778
+
1779
+ if count > 10:
1780
+ analysis += f"\n...and {count - 10} more packages\n"
1781
+ analysis += "\n"
1782
+ else:
1783
+ analysis += "## ✓ System Up to Date\n\nNo updates available.\n\n"
1784
+ return GetPromptResult(
1785
+ description="System is already up to date",
1786
+ messages=[
1787
+ PromptMessage(
1788
+ role="assistant",
1789
+ content=PromptMessage.TextContent(
1790
+ type="text",
1791
+ text=analysis
1792
+ )
1793
+ )
1794
+ ]
1795
+ )
1796
+ except Exception as e:
1797
+ analysis += f"## ⚠️ Update Check Failed\n\n{str(e)}\n\n"
1798
+
1799
+ # Step 4: Check failed services
1800
+ try:
1801
+ failed_services = await check_failed_services()
1802
+
1803
+ if not failed_services.get("all_ok"):
1804
+ analysis += "## ⚠️ Failed Services Detected\n\n"
1805
+ for service in failed_services.get("failed_services", [])[:5]:
1806
+ analysis += f"- {service['unit']}\n"
1807
+ warnings.append("System has failed services")
1808
+ recommendations.append("Investigate failed services before updating")
1809
+ analysis += "\n"
1810
+ else:
1811
+ analysis += "## ✓ All Services Running\n\nNo failed systemd services.\n\n"
1812
+ except Exception as e:
1813
+ analysis += f"## ⚠️ Service Check Failed\n\n{str(e)}\n\n"
1814
+
1815
+ # Step 5: Check database freshness
1816
+ try:
1817
+ db_freshness = await check_database_freshness()
1818
+
1819
+ if db_freshness.get("needs_sync"):
1820
+ analysis += "## Database Synchronization\n\n"
1821
+ analysis += f"Databases are {db_freshness.get('oldest_age_hours', 0):.1f} hours old.\n"
1822
+ recommendations.append("Database will be synchronized during update")
1823
+ analysis += "\n"
1824
+ except Exception as e:
1825
+ logger.warning(f"Database freshness check failed: {e}")
1826
+
1827
+ # Step 6: Summary and recommendations
1828
+ analysis += "## Recommendations\n\n"
1829
+
1830
+ if warnings:
1831
+ analysis += "### Warnings:\n"
1832
+ for warning in warnings:
1833
+ analysis += f"- ⚠️ {warning}\n"
1834
+ analysis += "\n"
1835
+
1836
+ if recommendations:
1837
+ analysis += "### Before Updating:\n"
1838
+ for rec in recommendations:
1839
+ analysis += f"- {rec}\n"
1840
+ analysis += "\n"
1841
+
1842
+ if not warnings:
1843
+ analysis += "✓ System is ready for update\n\n"
1844
+ analysis += "Run: `sudo pacman -Syu`\n"
1845
+ else:
1846
+ analysis += "⚠️ **Address warnings before updating**\n"
1847
+
1848
+ return GetPromptResult(
1849
+ description="Safe system update analysis",
1850
+ messages=[
1851
+ PromptMessage(
1852
+ role="user",
1853
+ content=PromptMessage.TextContent(
1854
+ type="text",
1855
+ text="Check if my system is ready for a safe update"
1856
+ )
1857
+ ),
1858
+ PromptMessage(
1859
+ role="assistant",
1860
+ content=PromptMessage.TextContent(
1861
+ type="text",
1862
+ text=analysis
1863
+ )
1864
+ )
1865
+ ]
1866
+ )
1867
+
672
1868
  else:
673
1869
  raise ValueError(f"Unknown prompt: {name}")