-
Notifications
You must be signed in to change notification settings - Fork 0
feat: measure agent install success #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Gradata
wants to merge
1
commit into
main
Choose a base branch
from
GRA-2507-install-success
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| """Local install-success measurement for Gradata agent integrations. | ||
|
|
||
| Records every `gradata install --agent ...` attempt to a user-level JSONL file | ||
| so distribution experiments can separate successful installs, code failures, and | ||
| docs/setup friction across the supported AI coding CLIs. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from datetime import UTC, datetime | ||
| from pathlib import Path | ||
| from typing import Final, Literal | ||
|
|
||
| from gradata._config_paths import get_config_file | ||
| from gradata.hooks.adapters._base import InstallResult | ||
|
|
||
| MEASURED_INSTALL_AGENTS: Final[tuple[str, ...]] = ( | ||
| "claude-code", | ||
| "codex", | ||
| "hermes", | ||
| "cursor", | ||
| ) | ||
| INSTALL_MEASUREMENTS_FILE: Final[str] = "install_measurements.jsonl" | ||
| FailureKind = Literal["none", "code_failure", "docs_friction"] | ||
|
|
||
|
|
||
| def measurement_path() -> Path: | ||
| return get_config_file(INSTALL_MEASUREMENTS_FILE) | ||
|
|
||
|
|
||
| def classify_result(result: InstallResult) -> FailureKind: | ||
| if result.action != "failed": | ||
| return "none" | ||
| return "code_failure" | ||
|
|
||
|
|
||
| def append_measurement( | ||
| result: InstallResult, | ||
| *, | ||
| brain_dir: Path, | ||
| source: str = "gradata install --agent", | ||
| failure_kind: FailureKind | None = None, | ||
| ) -> dict[str, object]: | ||
| status = "success" if result.action != "failed" else "failure" | ||
| payload: dict[str, object] = { | ||
| "ts": datetime.now(UTC).isoformat(), | ||
| "source": source, | ||
| "agent": result.agent, | ||
| "status": status, | ||
| "action": result.action, | ||
| "failure_kind": failure_kind or classify_result(result), | ||
| "config_path": str(result.config_path), | ||
| "brain_dir": str(brain_dir), | ||
| "message": result.message, | ||
| } | ||
| path = measurement_path() | ||
| path.parent.mkdir(parents=True, exist_ok=True) | ||
| with path.open("a", encoding="utf-8") as f: | ||
| f.write(json.dumps(payload, sort_keys=True) + "\n") | ||
| return payload | ||
|
|
||
|
|
||
| def append_docs_friction( | ||
| agent: str, | ||
| *, | ||
| config_path: Path, | ||
| brain_dir: Path, | ||
| message: str, | ||
| source: str = "gradata install --agent all", | ||
| ) -> dict[str, object]: | ||
| return append_measurement( | ||
| InstallResult(agent, config_path, "failed", message), | ||
| brain_dir=brain_dir, | ||
| source=source, | ||
| failure_kind="docs_friction", | ||
| ) | ||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use atomic-write helper for JSONL append to prevent partial-write corruption.
The coding guidelines require: "Use atomic-write helper when writing JSON files to prevent corruption from mid-write crashes." While this is append-only JSONL, a crash during the write could leave a partial line that breaks downstream parsing. Consider using an atomic-write pattern (write to temp file, then rename) to ensure each measurement is fully written or not at all.
🛡️ Suggested atomic-write pattern
Alternatively, use a project-standard atomic-write helper if one exists in the codebase.
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Coding guidelines