zerochat 10.31.0__tar.gz → 10.32.0__tar.gz
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.
- {zerochat-10.31.0/zerochat.egg-info → zerochat-10.32.0}/PKG-INFO +1 -1
- {zerochat-10.31.0 → zerochat-10.32.0}/pyproject.toml +1 -1
- {zerochat-10.31.0 → zerochat-10.32.0/zerochat.egg-info}/PKG-INFO +1 -1
- {zerochat-10.31.0 → zerochat-10.32.0}/zerochat.py +67 -32
- {zerochat-10.31.0 → zerochat-10.32.0}/LICENSE +0 -0
- {zerochat-10.31.0 → zerochat-10.32.0}/README.md +0 -0
- {zerochat-10.31.0 → zerochat-10.32.0}/setup.cfg +0 -0
- {zerochat-10.31.0 → zerochat-10.32.0}/zerochat.egg-info/SOURCES.txt +0 -0
- {zerochat-10.31.0 → zerochat-10.32.0}/zerochat.egg-info/dependency_links.txt +0 -0
- {zerochat-10.31.0 → zerochat-10.32.0}/zerochat.egg-info/entry_points.txt +0 -0
- {zerochat-10.31.0 → zerochat-10.32.0}/zerochat.egg-info/top_level.txt +0 -0
|
@@ -1577,7 +1577,7 @@ def dispatch_browser(method: str, params: dict) -> RpcOutcome:
|
|
|
1577
1577
|
|
|
1578
1578
|
|
|
1579
1579
|
|
|
1580
|
-
SOURCE_BACKEND_VERSION = "10.
|
|
1580
|
+
SOURCE_BACKEND_VERSION = "10.32.0"
|
|
1581
1581
|
|
|
1582
1582
|
|
|
1583
1583
|
def _read_source_version(filename: str) -> str | None:
|
|
@@ -2392,8 +2392,7 @@ def normalize_directory_path(value: str) -> str:
|
|
|
2392
2392
|
|
|
2393
2393
|
GLOBAL_POLICY_ASK = "ask"
|
|
2394
2394
|
GLOBAL_POLICY_ALLOW_ALL = "allow_all"
|
|
2395
|
-
|
|
2396
|
-
GLOBAL_POLICIES = (GLOBAL_POLICY_ASK, GLOBAL_POLICY_ALLOW_ALL, GLOBAL_POLICY_WORKSPACE_TRUST)
|
|
2395
|
+
GLOBAL_POLICIES = (GLOBAL_POLICY_ASK, GLOBAL_POLICY_ALLOW_ALL)
|
|
2397
2396
|
POLICY_ALLOW = "allow"
|
|
2398
2397
|
POLICY_DENY = "deny"
|
|
2399
2398
|
POLICY_ASK = "ask"
|
|
@@ -2660,7 +2659,7 @@ def normalize_command_patterns(raw) -> dict:
|
|
|
2660
2659
|
MAX_COMMAND_PATTERNS en total. Los de sesión nunca forman parte del estado guardado.
|
|
2661
2660
|
"""
|
|
2662
2661
|
if not isinstance(raw, dict):
|
|
2663
|
-
raise ValueError("commandPatterns debe ser un diccionario con global y
|
|
2662
|
+
raise ValueError("commandPatterns debe ser un diccionario con global y project.")
|
|
2664
2663
|
raw_projects = raw.get("projects") or {}
|
|
2665
2664
|
if not isinstance(raw_projects, dict):
|
|
2666
2665
|
raise ValueError("commandPatterns.projects debe ser un diccionario de proyecto a patrones.")
|
|
@@ -6867,9 +6866,11 @@ class AccessController:
|
|
|
6867
6866
|
# run_command nunca se guarda autorizado entero: sus permisos permanentes son patrones.
|
|
6868
6867
|
tools = {tid: entry for tid, entry in dict(data.get("tools") or {}).items()
|
|
6869
6868
|
if not (tid == COMMAND_TOOL and isinstance(entry, dict) and entry.get("policy") == POLICY_ALLOW)}
|
|
6869
|
+
raw_global = data.get("globalMcpPolicy")
|
|
6870
|
+
global_policy = GLOBAL_POLICY_ASK if raw_global in (None, "", "workspace_trust") else raw_global
|
|
6870
6871
|
return {
|
|
6871
6872
|
"version": POLICY_STATE_VERSION,
|
|
6872
|
-
"globalMcpPolicy":
|
|
6873
|
+
"globalMcpPolicy": global_policy,
|
|
6873
6874
|
"directoryRules": dir_rules,
|
|
6874
6875
|
"tools": tools,
|
|
6875
6876
|
"servers": dict(data.get("servers") or {}),
|
|
@@ -6896,18 +6897,23 @@ class AccessController:
|
|
|
6896
6897
|
dir_rules = list(state["directoryRules"][context.key])
|
|
6897
6898
|
else:
|
|
6898
6899
|
dir_rules = [default_rule]
|
|
6900
|
+
saved_patterns = state["commandPatterns"]
|
|
6899
6901
|
return {
|
|
6900
6902
|
"globalMcpPolicy": session.global_policy if session.global_policy is not None else state["globalMcpPolicy"],
|
|
6901
6903
|
"directoryRules": dir_rules,
|
|
6902
6904
|
"tools": {**state["tools"], **session.tools},
|
|
6903
6905
|
"servers": {**state["servers"], **session.servers},
|
|
6904
|
-
"commandPatterns": {
|
|
6906
|
+
"commandPatterns": {
|
|
6907
|
+
"global": list(saved_patterns["global"]),
|
|
6908
|
+
"project": list(saved_patterns["projects"].get(context.key) or []),
|
|
6909
|
+
"session": list(session.command_patterns)
|
|
6910
|
+
}
|
|
6905
6911
|
}
|
|
6906
6912
|
|
|
6907
|
-
def _command_patterns(self, view: dict
|
|
6913
|
+
def _command_patterns(self, view: dict) -> list[str]:
|
|
6908
6914
|
"""Patrones que rigen en el proyecto: los de todos los proyectos, los de este y los de la sesión."""
|
|
6909
6915
|
patterns = view["commandPatterns"]
|
|
6910
|
-
return [*patterns["global"], *
|
|
6916
|
+
return [*patterns["global"], *patterns["project"], *patterns["session"]]
|
|
6911
6917
|
|
|
6912
6918
|
def export_state(self, context: SecurityContext) -> dict:
|
|
6913
6919
|
return {
|
|
@@ -6984,7 +6990,7 @@ class AccessController:
|
|
|
6984
6990
|
|
|
6985
6991
|
clean_global = None
|
|
6986
6992
|
if "globalMcpPolicy" in state:
|
|
6987
|
-
pol = state["globalMcpPolicy"]
|
|
6993
|
+
pol = GLOBAL_POLICY_ASK if state["globalMcpPolicy"] == "workspace_trust" else state["globalMcpPolicy"]
|
|
6988
6994
|
if pol not in GLOBAL_POLICIES:
|
|
6989
6995
|
raise ValueError(f"Política global no válida: '{pol}'. Válidas: {GLOBAL_POLICIES}")
|
|
6990
6996
|
clean_global = pol
|
|
@@ -6994,15 +7000,33 @@ class AccessController:
|
|
|
6994
7000
|
clean_servers = self._validate_policy_entries(state["servers"], "servers", scope) if "servers" in state else None
|
|
6995
7001
|
return clean_global, clean_rules, clean_tools, clean_servers
|
|
6996
7002
|
|
|
7003
|
+
@staticmethod
|
|
7004
|
+
def _validate_command_patterns_patch(raw) -> dict:
|
|
7005
|
+
"""Valida un parche de commandPatterns: {global, project} o legado {global, projects}."""
|
|
7006
|
+
if not isinstance(raw, dict):
|
|
7007
|
+
raise ValueError("commandPatterns debe ser un diccionario con global y project.")
|
|
7008
|
+
has_projects = "projects" in raw
|
|
7009
|
+
if has_projects and "project" not in raw:
|
|
7010
|
+
return {"mode": "full", "patterns": normalize_command_patterns(raw)}
|
|
7011
|
+
global_patterns = clean_pattern_list(raw.get("global") or [], "commandPatterns.global")
|
|
7012
|
+
project_patterns = clean_pattern_list(raw.get("project") or [], "commandPatterns.project")
|
|
7013
|
+
base = normalize_command_patterns({"global": global_patterns, "projects": raw["projects"]}) if has_projects else None
|
|
7014
|
+
return {
|
|
7015
|
+
"mode": "scoped",
|
|
7016
|
+
"global": global_patterns,
|
|
7017
|
+
"project": project_patterns,
|
|
7018
|
+
"projects": base["projects"] if base is not None else None,
|
|
7019
|
+
}
|
|
7020
|
+
|
|
6997
7021
|
def import_state(self, state: dict, context: SecurityContext):
|
|
6998
7022
|
"""
|
|
6999
7023
|
Aplica un parche parcial persistente (None revoca) y devuelve el estado exportado.
|
|
7000
7024
|
`addDirectoryRules` añade reglas a las guardadas dentro de la misma transacción y
|
|
7001
|
-
`commandPatterns` sustituye los patrones
|
|
7025
|
+
`commandPatterns` sustituye los patrones globales y del proyecto actual sin tocar otros proyectos.
|
|
7002
7026
|
"""
|
|
7003
7027
|
clean_global, clean_rules, clean_tools, clean_servers = self._validate_state_payload(state, SCOPE_PERMANENT)
|
|
7004
7028
|
added_rules = self._validate_directory_rules(state["addDirectoryRules"]) if "addDirectoryRules" in state else []
|
|
7005
|
-
clean_patterns =
|
|
7029
|
+
clean_patterns = self._validate_command_patterns_patch(state["commandPatterns"]) if "commandPatterns" in state else None
|
|
7006
7030
|
|
|
7007
7031
|
project = context.key
|
|
7008
7032
|
default_rule = self.get_default_directory_rule(context)
|
|
@@ -7032,7 +7056,18 @@ class AccessController:
|
|
|
7032
7056
|
if clean_servers is not None:
|
|
7033
7057
|
current["servers"] = self._apply_entry_patch(current.get("servers"), clean_servers)
|
|
7034
7058
|
if clean_patterns is not None:
|
|
7035
|
-
current["commandPatterns"] = clean_patterns
|
|
7059
|
+
current["commandPatterns"] = self._merge_command_patterns(current["commandPatterns"], clean_patterns, project)
|
|
7060
|
+
|
|
7061
|
+
@staticmethod
|
|
7062
|
+
def _merge_command_patterns(current_patterns: dict, patch: dict, project: str) -> dict:
|
|
7063
|
+
if patch["mode"] == "full":
|
|
7064
|
+
return patch["patterns"]
|
|
7065
|
+
projects = dict(patch["projects"] if patch["projects"] is not None else current_patterns["projects"])
|
|
7066
|
+
if patch["project"]:
|
|
7067
|
+
projects[project] = patch["project"]
|
|
7068
|
+
else:
|
|
7069
|
+
projects.pop(project, None)
|
|
7070
|
+
return normalize_command_patterns({"global": patch["global"], "projects": projects})
|
|
7036
7071
|
|
|
7037
7072
|
def _forget_session_overrides(self, project: str, clean_global, clean_rules, added_rules, clean_tools, clean_servers):
|
|
7038
7073
|
"""Lo guardado sustituye o revoca lo equivalente en la sesión (las reglas de carpeta, solo en su proyecto)."""
|
|
@@ -7321,8 +7356,8 @@ class AccessController:
|
|
|
7321
7356
|
3. Política global allow_all -> allow incondicional.
|
|
7322
7357
|
4. Política granular de herramienta -> allow.
|
|
7323
7358
|
5. Política de servidor completo -> allow incondicional para sus herramientas.
|
|
7324
|
-
6. run_command:
|
|
7325
|
-
7. Herramientas con ruta: reglas de directorio
|
|
7359
|
+
6. run_command: reglas de directorio (RWX:/** permite todo; X habilita la carpeta) y patrones de comando.
|
|
7360
|
+
7. Herramientas con ruta: reglas de directorio.
|
|
7326
7361
|
8. Por defecto -> ask (solicitar confirmación), con la regla sugerida si la hay.
|
|
7327
7362
|
"""
|
|
7328
7363
|
status, reason, details, offer = self._evaluate(tool_name, dict(raw_args or {}), context, server_id)
|
|
@@ -7373,7 +7408,7 @@ class AccessController:
|
|
|
7373
7408
|
return raw_path if re.match(r"^(/|[A-Za-z]:[\\/])", raw_path) else str(cwd / raw_path)
|
|
7374
7409
|
|
|
7375
7410
|
def _is_allowed_trust_segment(self, segment: str, cwd: Path, directory_rules: list[str], ctx: SecurityContext) -> bool:
|
|
7376
|
-
"""Subcomando permitido por
|
|
7411
|
+
"""Subcomando permitido por las reglas del proyecto: local o con rutas dentro de reglas RW."""
|
|
7377
7412
|
refs = command_outside_references(segment)
|
|
7378
7413
|
if refs is None:
|
|
7379
7414
|
return False
|
|
@@ -7384,14 +7419,13 @@ class AccessController:
|
|
|
7384
7419
|
|
|
7385
7420
|
def _evaluate_command(self, raw_command: str, view: dict, ctx: SecurityContext) -> tuple[str, str, str, dict | None]:
|
|
7386
7421
|
"""
|
|
7387
|
-
Valida cada subcomando por separado:
|
|
7388
|
-
|
|
7389
|
-
|
|
7390
|
-
reglas RW del proyecto (tras una tubería, solo
|
|
7391
|
-
|
|
7422
|
+
Valida cada subcomando por separado: con RWX:/** el proyecto queda sin restricción de comandos.
|
|
7423
|
+
En otro caso, la carpeta donde se ejecuta (inicial y tras cada cd) requiere permiso X en directoryRules;
|
|
7424
|
+
cada cd debe llevar a una carpeta cubierta por las reglas de directorio, y el resto tiene que estar
|
|
7425
|
+
cubierto por un patrón o quedarse en el proyecto o en reglas RW del proyecto (tras una tubería, solo
|
|
7426
|
+
un filtro).
|
|
7392
7427
|
"""
|
|
7393
|
-
|
|
7394
|
-
if trust and self._has_full_directory_access(view["directoryRules"]):
|
|
7428
|
+
if self._has_full_directory_access(view["directoryRules"]):
|
|
7395
7429
|
return POLICY_ALLOW, "directory_rule_allow", "", None
|
|
7396
7430
|
if not self.evaluate_directory_rule("X", str(ctx.workspace_dir), view["directoryRules"], ctx)["allowed"]:
|
|
7397
7431
|
return (POLICY_ASK, "command_directory_without_execute",
|
|
@@ -7400,8 +7434,8 @@ class AccessController:
|
|
|
7400
7434
|
if segments is None:
|
|
7401
7435
|
return (POLICY_ASK, "command_chaining_requires_approval",
|
|
7402
7436
|
f"El comando usa sintaxis de shell que no se puede validar por partes: {raw_command}", None)
|
|
7403
|
-
patterns = self._command_patterns(view
|
|
7404
|
-
cwd,
|
|
7437
|
+
patterns = self._command_patterns(view)
|
|
7438
|
+
cwd, by_rule, uncovered = ctx.workspace_dir, False, []
|
|
7405
7439
|
for operator, segment in segments:
|
|
7406
7440
|
directory = cd_target(segment)
|
|
7407
7441
|
if directory is not None:
|
|
@@ -7415,17 +7449,18 @@ class AccessController:
|
|
|
7415
7449
|
f"La carpeta no tiene permiso de ejecución (X): {cwd}", None)
|
|
7416
7450
|
elif any(matches_command_pattern(segment, p) for p in patterns):
|
|
7417
7451
|
continue
|
|
7418
|
-
elif
|
|
7452
|
+
elif self._is_allowed_trust_segment(segment, cwd, view["directoryRules"], ctx) and (
|
|
7419
7453
|
operator != "|" or segment.split()[0] in WORKSPACE_TRUST_PIPE_FILTERS):
|
|
7420
|
-
|
|
7454
|
+
by_rule = True
|
|
7421
7455
|
else:
|
|
7422
7456
|
uncovered.append(segment)
|
|
7423
7457
|
if not uncovered:
|
|
7424
|
-
return POLICY_ALLOW, "
|
|
7425
|
-
|
|
7426
|
-
|
|
7427
|
-
|
|
7428
|
-
|
|
7458
|
+
return POLICY_ALLOW, "directory_rule_allow" if by_rule else "command_pattern_allow", "", None
|
|
7459
|
+
reason, details = (
|
|
7460
|
+
("command_outside_allowed_patterns", f"Comando fuera de los patrones autorizados: {'; '.join(uncovered)}")
|
|
7461
|
+
if patterns
|
|
7462
|
+
else ("command_outside_directory_rules", "El comando accede a recursos globales o rutas fuera de las reglas de directorio.")
|
|
7463
|
+
)
|
|
7429
7464
|
return POLICY_ASK, reason, details, command_rule_offer(uncovered)
|
|
7430
7465
|
|
|
7431
7466
|
def _evaluate_path(self, tool_name: str, access: str, path: str, view: dict, ctx: SecurityContext) -> tuple[str, str, str, dict | None]:
|
|
@@ -10082,7 +10117,7 @@ def reset_session_authorizations():
|
|
|
10082
10117
|
ACCESS_CONTROLLER.apply_tool_decision(tool_decision, ctx, server_id=server_id)
|
|
10083
10118
|
permanent_tools = ACCESS_CONTROLLER.export_state(ctx).get("tools") or {}
|
|
10084
10119
|
ACCESS_CONTROLLER.apply_session_overlay({
|
|
10085
|
-
"globalMcpPolicy":
|
|
10120
|
+
"globalMcpPolicy": GLOBAL_POLICY_ASK,
|
|
10086
10121
|
"tools": {
|
|
10087
10122
|
name: {"policy": POLICY_ALLOW}
|
|
10088
10123
|
for name in LOCAL_TOOL_HANDLERS
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|