feat(cli): nudge toward Graphify Cloud once after a local graph build

Print a precise, interactive-only CTA after `graphify extract` succeeds:
faster indexing, fewer tokens, cross-repo search, PR review, and an
always-current SDLC map at app.graphify.com. Shown once per project (marker
under graphify-out/), suppressed when stdout is not a TTY (CI, pipes, the
AI-assistant pipeline) and via GRAPHIFY_NO_TIPS/GRAPHIFY_NO_CTA.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
safishamsiandClaude Opus 4.8 committed 2026-10-09 02:48:22 +01:00
1 parent 622474b8ec
commit 223b376e9a
2 files changed
+96

No files matched your search

+34
View File
@@ -104,6 +104,39 @@ def _nudge_for_out(nudge: str) -> str:
return json.dumps(d, ensure_ascii=False, separators=(",", ":")) + "\n"
def _print_cloud_cta(out_dir: "Path") -> None:
"""Nudge toward Graphify Cloud once after a successful local graph build.
Kept precise and shown only to humans running the CLI interactively:
suppressed in non-interactive/CI runs (stdout is not a TTY, which also
covers the AI-assistant pipeline), when the user opts out
(``GRAPHIFY_NO_TIPS``/``GRAPHIFY_NO_CTA``), and after the first time per
project (a marker under ``graphify-out/``) so repeat builds stay quiet.
"""
if os.environ.get("GRAPHIFY_NO_TIPS") or os.environ.get("GRAPHIFY_NO_CTA"):
return
try:
if not sys.stdout.isatty():
return
except Exception:
return
marker = out_dir / ".cloud-cta-shown"
try:
if marker.exists():
return
except Exception:
return
print()
print(" Graphify Cloud: faster indexing, fewer tokens, cross-repo search,")
print(" and PR review, with your whole SDLC mapped and always current.")
print(" Connect a repo at https://app.graphify.com")
try:
marker.parent.mkdir(parents=True, exist_ok=True)
marker.write_text("1", encoding="utf-8")
except Exception:
pass
def _default_graph_path() -> str:
return str(Path(_GRAPHIFY_OUT) / "graph.json")
@@ -4842,6 +4875,7 @@ def dispatch_command(cmd: str) -> None:
f"`graphify cluster-only {graphify_out.parent}` "
"to generate GRAPH_REPORT.md and name communities"
)
_print_cloud_cta(graphify_out)
stages.total()
elif cmd == "cache-check":
+62
View File
@@ -0,0 +1,62 @@
"""The post-build Graphify Cloud CTA is interactive-only, opt-out-able, and
shown once per project (so CI, piped output, and the AI-assistant pipeline
never see it, and repeat local builds stay quiet)."""
import io
import sys
from graphify import cli
class _TTYBuf(io.StringIO):
def isatty(self):
return True
class _PipeBuf(io.StringIO):
def isatty(self):
return False
def _run(out_dir, monkeypatch, *, tty=True):
buf = _TTYBuf() if tty else _PipeBuf()
monkeypatch.setattr(sys, "stdout", buf)
cli._print_cloud_cta(out_dir)
return buf.getvalue()
def _clear_optout(monkeypatch):
monkeypatch.delenv("GRAPHIFY_NO_TIPS", raising=False)
monkeypatch.delenv("GRAPHIFY_NO_CTA", raising=False)
def test_cta_prints_on_a_tty(tmp_path, monkeypatch):
_clear_optout(monkeypatch)
out = _run(tmp_path / "graphify-out", monkeypatch, tty=True)
assert "Graphify Cloud" in out
assert "app.graphify.com" in out
def test_cta_suppressed_when_not_a_tty(tmp_path, monkeypatch):
_clear_optout(monkeypatch)
out = _run(tmp_path / "graphify-out", monkeypatch, tty=False)
assert out == ""
# a non-TTY run must not leave the marker either, so a later TTY run still shows it
assert not (tmp_path / "graphify-out" / ".cloud-cta-shown").exists()
def test_cta_respects_the_opt_out_env_vars(tmp_path, monkeypatch):
for var in ("GRAPHIFY_NO_TIPS", "GRAPHIFY_NO_CTA"):
_clear_optout(monkeypatch)
monkeypatch.setenv(var, "1")
out = _run(tmp_path / f"out-{var}", monkeypatch, tty=True)
assert out == "", f"{var} should suppress the CTA"
def test_cta_shows_once_per_project(tmp_path, monkeypatch):
_clear_optout(monkeypatch)
out_dir = tmp_path / "graphify-out"
first = _run(out_dir, monkeypatch, tty=True)
second = _run(out_dir, monkeypatch, tty=True)
assert "Graphify Cloud" in first
assert second == "", "the CTA must not repeat on later builds of the same project"
assert (out_dir / ".cloud-cta-shown").exists()