codegpt-ai 2.11.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chat.py +65 -14
- package/package.json +1 -1
package/chat.py
CHANGED
|
@@ -660,40 +660,91 @@ def ask_permission(action, detail=""):
|
|
|
660
660
|
risk_color = RISK_COLORS.get(risk, "yellow")
|
|
661
661
|
risk_icon = RISK_ICONS.get(risk, "?")
|
|
662
662
|
|
|
663
|
-
#
|
|
664
|
-
|
|
665
|
-
"CRITICAL":
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
663
|
+
# Detailed risk info per level
|
|
664
|
+
risk_info = {
|
|
665
|
+
"CRITICAL": {
|
|
666
|
+
"warning": "Can execute code, modify files, or expose data.",
|
|
667
|
+
"examples": "shell commands, code execution, installing software",
|
|
668
|
+
"tip": "Only allow if you trust the command.",
|
|
669
|
+
},
|
|
670
|
+
"HIGH": {
|
|
671
|
+
"warning": "Accesses external services or modifies data.",
|
|
672
|
+
"examples": "opening URLs, GitHub access, deleting data",
|
|
673
|
+
"tip": "Check what it's doing before allowing.",
|
|
674
|
+
},
|
|
675
|
+
"MEDIUM": {
|
|
676
|
+
"warning": "Uses resources or changes settings.",
|
|
677
|
+
"examples": "running agents, saving files, training models",
|
|
678
|
+
"tip": "Generally safe for normal use.",
|
|
679
|
+
},
|
|
680
|
+
"LOW": {
|
|
681
|
+
"warning": "Safe operation with minimal impact.",
|
|
682
|
+
"examples": "switching model, changing persona, forking chat",
|
|
683
|
+
"tip": "Low risk — consider always-allowing.",
|
|
684
|
+
},
|
|
669
685
|
}
|
|
670
|
-
|
|
686
|
+
info = risk_info.get(risk, risk_info["MEDIUM"])
|
|
687
|
+
compact = is_compact()
|
|
671
688
|
|
|
672
|
-
#
|
|
689
|
+
# Permission prompt with full context
|
|
690
|
+
console.print()
|
|
691
|
+
console.print(Rule(style=risk_color.replace("bold ", ""), characters="─"))
|
|
692
|
+
console.print()
|
|
693
|
+
console.print(Text.from_markup(f" [{risk_color}]{risk_icon} {risk}[/] [{risk_color}]{action_desc}[/]"))
|
|
673
694
|
console.print()
|
|
674
|
-
console.print(Text.from_markup(f" [{risk_color}]{risk_icon} {action_desc}[/]"))
|
|
675
695
|
if detail:
|
|
676
|
-
console.print(Text(f" {detail[:70]}"
|
|
677
|
-
|
|
696
|
+
console.print(Text.from_markup(f" [bright_cyan]what:[/] {detail[:70]}"))
|
|
697
|
+
if not compact:
|
|
698
|
+
console.print(Text.from_markup(f" [dim]risk:[/] {info['warning']}"))
|
|
699
|
+
console.print(Text.from_markup(f" [dim]e.g.:[/] {info['examples']}"))
|
|
700
|
+
console.print(Text.from_markup(f" [dim]tip:[/] {info['tip']}"))
|
|
701
|
+
else:
|
|
702
|
+
console.print(Text.from_markup(f" [{risk_color}]{info['warning']}[/]"))
|
|
678
703
|
console.print()
|
|
679
704
|
|
|
680
705
|
try:
|
|
681
706
|
answer = prompt(
|
|
682
|
-
[("class:prompt", "
|
|
707
|
+
[("class:prompt", " (y)es (n)o (a)lways (?) info > ")],
|
|
683
708
|
style=input_style,
|
|
684
709
|
).strip().lower()
|
|
685
710
|
except (KeyboardInterrupt, EOFError):
|
|
711
|
+
audit_log("PERMISSION_DENIED", f"{action}: interrupted")
|
|
686
712
|
return False
|
|
687
713
|
|
|
714
|
+
if answer in ("?", "info", "help"):
|
|
715
|
+
# Show detailed info then re-ask
|
|
716
|
+
console.print()
|
|
717
|
+
console.print(Text.from_markup(
|
|
718
|
+
f" [bold]Action:[/] {action_desc}\n"
|
|
719
|
+
f" [bold]Risk:[/] [{risk_color}]{risk}[/]\n"
|
|
720
|
+
f" [bold]Warning:[/] {info['warning']}\n"
|
|
721
|
+
f" [bold]Examples:[/] {info['examples']}\n"
|
|
722
|
+
f" [bold]Tip:[/] {info['tip']}\n\n"
|
|
723
|
+
f" [dim]What each option does:[/]\n"
|
|
724
|
+
f" [bright_cyan]y[/] Allow this one time\n"
|
|
725
|
+
f" [bright_cyan]n[/] Block this action\n"
|
|
726
|
+
f" [bright_cyan]a[/] Always allow (saved, never asked again)\n"
|
|
727
|
+
))
|
|
728
|
+
try:
|
|
729
|
+
answer = prompt(
|
|
730
|
+
[("class:prompt", " Allow? (y/n/a) > ")],
|
|
731
|
+
style=input_style,
|
|
732
|
+
).strip().lower()
|
|
733
|
+
except (KeyboardInterrupt, EOFError):
|
|
734
|
+
return False
|
|
735
|
+
|
|
688
736
|
if answer in ("a", "always"):
|
|
689
737
|
PERMISSION_ALWAYS_ALLOW.add(action)
|
|
690
738
|
save_permissions()
|
|
691
|
-
console.print(Text(f" ✓ Always allowed", style="green"))
|
|
739
|
+
console.print(Text(f" ✓ Always allowed — {action_desc}", style="green"))
|
|
740
|
+
audit_log("PERMISSION_ALWAYS", action)
|
|
692
741
|
return True
|
|
693
742
|
elif answer in ("y", "yes", ""):
|
|
743
|
+
audit_log("PERMISSION_GRANTED", action)
|
|
694
744
|
return True
|
|
695
745
|
else:
|
|
696
|
-
|
|
746
|
+
console.print(Text(f" ✗ Blocked — {action_desc}", style="red"))
|
|
747
|
+
audit_log("PERMISSION_DENIED", action)
|
|
697
748
|
return False
|
|
698
749
|
|
|
699
750
|
|