refactor: drop the console announcement when minting project_id

Minting now happens silently. With no message to print, the (id, created)
tuple had no consumer, so simplify the API rather than keep the flag around
for a hypothetical caller:

- get_or_create_project_id() returns `str | None` instead of
  `tuple[str | None, bool]`.
- Remove crewai_cli.utils.ensure_project_id, which existed only to print the
  message and discard the flag. The four call sites (crewai create crew,
  crewai create flow, crewai run, and tool-repository login) now call
  get_or_create_project_id directly.
- Update tests for the simplified signature; still 18 tests covering minting,
  stability, table placement, formatting preservation, five pyproject
  layouts, and missing/malformed/read-only handling.

Behaviour is otherwise unchanged: minting stays restricted to CLI commands
the user invoked, library code still only reads via get_project_id, and a
missing or read-only pyproject.toml still returns None rather than raising.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UNumDnNbiyw3pv1WakAe6t
This commit is contained in:
Joao Moura
2026-08-03 10:55:43 -07:00
parent 7f51bb6137
commit 998691ae22
5 changed files with 24 additions and 59 deletions

View File

@@ -20,7 +20,7 @@ from crewai_cli.input_prompt import (
)
from crewai_cli.utils import (
build_env_with_all_tool_credentials,
ensure_project_id,
get_or_create_project_id,
is_dmn_mode_enabled,
)
from crewai_cli.version import get_crewai_tools_dependency, get_crewai_version
@@ -620,7 +620,7 @@ def run_crew(
"""
# Backfills projects created before project_id existed. Only here, in a
# command the user explicitly invoked - never from the SDK during kickoff.
ensure_project_id()
get_or_create_project_id()
# --definition is a pure override: run that flow directly.
if definition is not None:

View File

@@ -16,7 +16,7 @@ from crewai_cli.config import Settings
from crewai_cli.constants import DEFAULT_CREWAI_ENTERPRISE_URL
from crewai_cli.utils import (
build_env_with_tool_repository_credentials,
ensure_project_id,
get_or_create_project_id,
get_project_description,
get_project_name,
get_project_version,
@@ -231,7 +231,7 @@ class ToolCommand(BaseCommand, PlusAPIMixin):
get_user_id = _require_get_user_id()
login_response = self.plus_api_client.login_to_tool_repository(
user_identifier=get_user_id(),
project_id=ensure_project_id(),
project_id=get_or_create_project_id(),
)
if login_response.status_code != 200:

View File

@@ -31,7 +31,6 @@ __all__ = [
"build_env_with_tool_repository_credentials",
"copy_template",
"enable_prompt_line_editing",
"ensure_project_id",
"fetch_and_json_env_file",
"get_or_create_project_id",
"get_project_description",
@@ -53,32 +52,6 @@ console = Console()
_TEMPLATE_TOKEN_RE = re.compile(r"{{([a-zA-Z_][a-zA-Z0-9_]*)}}")
def ensure_project_id(pyproject_path: str | Path = "pyproject.toml") -> str | None:
"""Return the project's id, minting one and telling the user if it was added.
Safe to call from any CLI command: returns None rather than raising when
there is no project, or when ``pyproject.toml`` is not writable.
Args:
pyproject_path: Path to the project's ``pyproject.toml``.
Returns:
The project id, or None if one could not be read or created.
"""
project_id, created = get_or_create_project_id(pyproject_path)
if created:
console.print(
f"Added [bold]project_id[/bold] to {pyproject_path} under "
# Escaped: Rich would otherwise parse [tool.crewai] as a style tag.
r"[bold]\[tool.crewai][/bold] so this project's runs and traces stay "
"linked. Commit it to share that link with your team.",
style="dim",
)
return project_id
def is_dmn_mode_enabled() -> bool:
"""Return True when the enterprise non-interactive mode is enabled."""
value = os.environ.get("CREWAI_DMN")