(
connection: sqlite3.Connection, workspace_id: str, *, thread_id: str | None = None
)
| 2904 | |
| 2905 | |
| 2906 | def workspace_state( |
| 2907 | connection: sqlite3.Connection, workspace_id: str, *, thread_id: str | None = None |
| 2908 | ) -> dict[str, Any]: |
| 2909 | workspace = require_workspace(connection, workspace_id) |
| 2910 | if thread_id is not None and workspace["thread_id"] != optional_text(thread_id, maximum=512): |
| 2911 | raise SystemExit("Codex Security workspace not found in this thread.") |
| 2912 | persisted_diff_target = stored_diff_target(workspace) |
| 2913 | result: dict[str, Any] = { |
| 2914 | "id": workspace["id"], |
| 2915 | "diffTarget": persisted_diff_target, |
| 2916 | "diffResolutionId": workspace["diff_resolution_id"], |
| 2917 | "mode": workspace["default_mode"], |
| 2918 | "recentTargets": [], |
| 2919 | "scope": workspace["default_scope"], |
| 2920 | "setup": {"submitted": bool(workspace["submitted"])}, |
| 2921 | "setupValidation": {"error": None, "valid": bool(workspace["submitted"])}, |
| 2922 | "targetPath": workspace["target_path"], |
| 2923 | "targetSummary": workspace["target_summary"], |
| 2924 | "targetTitle": workspace["target_title"], |
| 2925 | "updatedAt": workspace["updated_at"], |
| 2926 | "userContext": workspace["user_context"], |
| 2927 | } |
| 2928 | if workspace["capability_preflight_json"]: |
| 2929 | result["capabilityPreflight"] = json.loads(workspace["capability_preflight_json"]) |
| 2930 | if workspace["active_scan_id"]: |
| 2931 | result["results"] = scan_result( |
| 2932 | connection, require_scan(connection, workspace["active_scan_id"]) |
| 2933 | ) |
| 2934 | return result |
| 2935 | |
| 2936 | target_metadata = None |
| 2937 | setup_error = None |
| 2938 | validated_diff_target = None |
| 2939 | if workspace["target_path"]: |
| 2940 | try: |
| 2941 | inspected = inspect_setup_values( |
| 2942 | workspace["target_path"], |
| 2943 | workspace["default_scope"], |
| 2944 | workspace["default_mode"], |
| 2945 | workspace["diff_target_kind"], |
| 2946 | workspace["diff_base_revision"], |
| 2947 | workspace["diff_head_revision"], |
| 2948 | workspace["diff_content_digest"], |
| 2949 | ) |
| 2950 | target_metadata = inspected["target"]["targetMetadata"] |
| 2951 | validated_diff_target = inspected["diffTarget"] |
| 2952 | except SystemExit as exc: |
| 2953 | setup_error = str(exc) |
| 2954 | try: |
| 2955 | target = require_target(workspace["target_path"]) |
| 2956 | target_metadata = git_target_metadata(target) |
| 2957 | except SystemExit: |
| 2958 | pass |
| 2959 | result["diffTarget"] = validated_diff_target or persisted_diff_target |
| 2960 | result["recentTargets"] = recent_targets(connection) |
| 2961 | result["setupValidation"] = { |
| 2962 | "error": setup_error, |
| 2963 | "valid": setup_error is None and bool(target_metadata), |
no test coverage detected