Open
Conversation
Collaborator
RoniCycode
commented
Apr 9, 2026
- Change "ensure-auth" to "session-start" which includes conversation creation and MCP usage checks (once per session)
Ilanlido
reviewed
Apr 9, 2026
Comment on lines
+71
to
+75
| # Step 2: Read stdin payload (backward compat: old hooks pipe no stdin) | ||
| if sys.stdin.isatty(): | ||
| logger.debug('No stdin payload (TTY), skipping session initialization') | ||
| return | ||
|
|
Collaborator
Author
There was a problem hiding this comment.
What it does: sys.stdin.isatty() returns True when stdin is attached to a terminal — i.e. nothing is piped in. If we didn't have this guard, sys.stdin.read() on the next line would block forever waiting
for input that never arrives.
Why it's needed:
- Manual/interactive invocation. If you run cycode ai-guardrails session-start in a shell to debug it, stdin is the terminal. Without this check, the command would hang.
- Backward compat with the old ensure-auth hook. In init.py we kept ensure-auth as a deprecated alias:
app.command(hidden=True, name='ensure-auth', ...)(session_start_command) - Users who installed hooks before this branch have cycode ai-guardrails ensure-auth wired into their IDE config. The old command only ran auth and didn't read stdin. After they upgrade the CLI, that same
hook now invokes session_start_command. The guard ensures that even if the invocation context somehow doesn't provide a JSON payload on stdin, we still do the auth step (which is what the old command did)
and then gracefully skip the conversation/MCP reporting steps instead of hanging.
Flow:
- Hook invoked by IDE → stdin is a pipe → isatty() is False → read JSON, create conversation, report MCP
- Hook invoked with no stdin (manual / edge case) → isatty() is True → auth happens above, then we return early
If you want to make the intent clearer, the comment could be:
- No piped input: would block forever on read(). Happens when run manually,
- or with the legacy
ensure-authhook which didn't supply stdin.
Ilanlido
reviewed
Apr 13, 2026
| def _build_session_payload(payload: dict, ide: str) -> AIHookPayload: | ||
| """Build an AIHookPayload from a session-start stdin payload.""" | ||
| if ide == AIIDEType.CLAUDE_CODE: | ||
| ide_version, model, _ = _extract_from_claude_transcript(payload.get('transcript_path')) |
Collaborator
There was a problem hiding this comment.
remove this function definition and conversation creation on every hook
| model=payload.get('model'), | ||
| ide_provider=AIIDEType.CLAUDE_CODE.value, | ||
| ide_version=ide_version, | ||
| ide_version=None, |
Collaborator
There was a problem hiding this comment.
we still need to get the version
| if not mcp_servers: | ||
| return | ||
| try: | ||
| ai_client.report_data_flow(mcp_servers) |
| return | ||
| try: | ||
| ai_client.report_data_flow(mcp_servers) | ||
| except Exception as e: |
Collaborator
There was a problem hiding this comment.
you already have try catch inside report_data_flow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.