Files
Jyotisha/scripts/vedastro_switch/__init__.py
T
ClaudeandClaude 4b8a645357
Independent Staging Quality Gate / validate-python (push) Successful in 5m2s
Independent Staging Quality Gate / validate-frontend (push) Successful in 5m44s
Independent Staging Quality Gate / publish (push) Successful in 12m12s
fix(vedastro): one switch, off by default; an official chart replaces the local one only on a matching echo (BUG-2427, #327)
Owner decision 2026-11-26: the product stops using VedAstro.
- scripts/vedastro_switch: VEDASTRO_ENABLED=1 turns it on; default off.
- Adapter, gateway, foreground session, consult gate, orchestrator,
  user entrypoint, REST/MCP/SDK bridges answer "disabled" at once:
  no network, no subprocess, no wait, no cache writes.
- vedastro_priority: a disabled snapshot leaves the local chart as is;
  an official chart replaces it only when every chart/house answer
  echoes the requested time, place and ayanamsa.
- Model input drops VedAstro audit rows, cross-check and must-use layer;
  privacy policy drops the VedAstro data line.
- VEDASTRO_API_KEY optional and unused; env examples, deploy/README,
  AGENTS.md updated. Frozen files untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
2026-11-26 23:33:41 +08:00

71 lines
2.3 KiB
Python

"""One switch for every VedAstro call (BUG-2427, issue #327).
Owner decision 2026-11-26: the product stops using VedAstro. Since July every
call had failed and users only ever saw the local engine's results; a half-fixed
request could also have swapped in the API's own sample chart. VedAstro is
therefore OFF unless ``VEDASTRO_ENABLED`` is set to 1/true/yes/on.
While it is off:
- no network call, subprocess bridge, wait, timeout or cache write happens;
- every entry point returns :func:`disabled_packet` at once;
- the packet is backstage-only. Consumers must not turn it into a user-facing
or model-visible "external check blocked / not done" line.
``VEDASTRO_API_KEY`` is no longer required anywhere; it is read only when the
switch is on.
"""
from __future__ import annotations
import os
from typing import Any
ENABLED_ENV = "VEDASTRO_ENABLED"
DISABLED_STATUS = "disabled"
DISABLED_REASON = "vedastro_disabled_by_owner_decision"
DISABLED_DECISION = "owner_decision_2026_11_26"
_TRUE = {"1", "true", "yes", "on"}
def vedastro_enabled() -> bool:
"""True only when ``VEDASTRO_ENABLED`` is explicitly switched on."""
return os.environ.get(ENABLED_ENV, "").strip().lower() in _TRUE
def disabled_packet(scope: str = "vedastro", **extra: Any) -> dict[str, Any]:
"""The answer every VedAstro entry point gives while the switch is off."""
packet: dict[str, Any] = {
"scope": scope,
"backend": "vedastro_disabled",
"available": False,
"status": DISABLED_STATUS,
"official_closure_state": DISABLED_STATUS,
"official_closure_reason": DISABLED_REASON,
"reason": DISABLED_REASON,
"decision": DISABLED_DECISION,
"enable_env": ENABLED_ENV,
"user_visibility": "backstage_only",
}
packet.update(extra)
return packet
def is_disabled_packet(value: Any) -> bool:
return isinstance(value, dict) and (
value.get("official_closure_reason") == DISABLED_REASON or value.get("reason") == DISABLED_REASON
)
class VedastroDisabledError(RuntimeError):
"""Raised by a low-level transport that was reached while the switch is off."""
def __init__(self) -> None:
super().__init__(DISABLED_REASON)
def require_enabled() -> None:
"""Hard stop for network/subprocess transports (defence in depth)."""
if not vedastro_enabled():
raise VedastroDisabledError()