We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
fal run --scripts selector with global scripts not working
<!-- *** Make sure you have searched for an existing bug report for this issue *** -->

**Describe the bug**
Fal CLI `run` command using `--scripts` flag selector does not execute any script when the script passed is under the `before` key in the `schema.yml` configuration.

**Your environment**
- OS: macOS Monterrey 12.6
- Paste the following commands output:
```
fal --0.6.0
dbt --1.2.1
```
- Adapter being used: bigquery

**How to reproduce**
Add scripts to run under `--before` key in the `schema.yml`:
```
version: 2

fal:
  scripts:
    before:
      - fal_scripts/delete_bq_datasets.py
      - fal_scripts/download_prod_artifacts.py
```
File structure:
```
dbt_project
├── analysis
├── dbt_packages
├── dbt_project.yml
├── fal_scripts
│   ├── delete_bq_datasets.py
│   └── download_prod_artifacts.py
├── logs
├── macros
├── models
│   ├── exposures
│   └── schema.yml
├── packages.yml
├── seeds
├── snapshots
├── target
└── tests

```
Then run:
```sh
fal run --before --scripts download_prod_artifacts.py
```
Or:
```sh
fal run --scripts download_prod_artifacts.py
```

**Expected behavior**
Run only the script passed to the `--scripts` flag: `download_prod_artifacts.py`.  

**Actual behavior**
Does nothing for neither case.

```sh
fal run --scripts download_prod_artifacts.py
```
```
13:25:19  Found 370 models, 544 tests, 0 snapshots, 18 analyses, 583 macros, 0 operations, 42 seed files, 129 sources, 2 exposures, 0 metrics
13:25:19  Could not read dbt sources artifact
```
```sh
fal run --before --scripts download_prod_artifacts.py
```
```
13:27:34  Found 370 models, 544 tests, 0 snapshots, 18 analyses, 583 macros, 0 operations, 42 seed files, 129 sources, 2 exposures, 0 metrics
13:27:34  Could not read dbt sources artifact
```
**Additional context**
The issue might be [this](https://github.com/fal-ai/fal/blob/771ad3dc8946dbda57e91b188719f8a20c6eb353/src/fal/cli/fal_runner.py#L47) section of code (related with `scripts` and `global_scripts` variables).


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/fal/cli/fal_runner.py`
Content:
```
1 import argparse
2 from pathlib import Path
3 from typing import Dict, List
4 
5 from dbt.flags import PROFILES_DIR
6 from fal.planner.executor import parallel_executor
7 from fal.planner.schedule import Scheduler
8 from fal.planner.tasks import FalLocalHookTask, Status, TaskGroup
9 
10 from fal.fal_script import FalScript
11 from faldbt.project import DbtModel, FalDbt, FalGeneralException
12 
13 
14 def create_fal_dbt(
15     args: argparse.Namespace, generated_models: Dict[str, Path] = {}
16 ) -> FalDbt:
17     profiles_dir = PROFILES_DIR
18     if args.profiles_dir is not None:
19         profiles_dir = args.profiles_dir
20 
21     real_state = None
22     if hasattr(args, "state") and args.state is not None:
23         real_state = args.state
24 
25     return FalDbt(
26         args.project_dir,
27         profiles_dir,
28         args.select,
29         args.exclude,
30         args.selector,
31         args.keyword,
32         args.threads,
33         real_state,
34         args.target,
35         getattr(args, "vars", "{}"),
36         generated_models,
37     )
38 
39 
40 def fal_run(args: argparse.Namespace):
41     "Runs the fal run command in a subprocess"
42 
43     selector_flags = args.select or args.exclude or args.selector
44     if args.all and selector_flags:
45         raise FalGeneralException(
46             "Cannot pass --all flag alongside selection flags (--select/--models, --exclude, --selector)"
47         )
48 
49     faldbt = create_fal_dbt(args)
50     models = _get_filtered_models(faldbt, args.all, selector_flags, args.before)
51 
52     scripts = _select_scripts(args, models, faldbt)
53 
54     global_scripts = _get_global_scripts(faldbt, args.before)
55 
56     if args.before:
57         if not _scripts_flag(args):
58             # run globals when no --script is passed
59             _run_scripts(args, global_scripts, faldbt)
60 
61         pre_hook_scripts = _get_hooks_for_model(models, faldbt, "pre-hook")
62         _run_scripts(args, pre_hook_scripts, faldbt)
63 
64         _run_scripts(args, scripts, faldbt)
65 
66     else:
67         _run_scripts(args, scripts, faldbt)
68 
69         post_hook_scripts = _get_hooks_for_model(models, faldbt, "post-hook")
70         _run_scripts(args, post_hook_scripts, faldbt)
71 
72         if not _scripts_flag(args):
73             # run globals when no --script is passed
74             _run_scripts(args, global_scripts, faldbt)
75 
76 
77 def _run_scripts(args: argparse.Namespace, scripts: List[FalScript], faldbt: FalDbt):
78     scheduler = Scheduler(
79         [TaskGroup(FalLocalHookTask.from_fal_script(script)) for script in scripts]
80     )
81     parallel_executor(args, faldbt, scheduler)
82 
83     failed_tasks: List[FalLocalHookTask] = [
84         group.task for group in scheduler.filter_groups(Status.FAILURE)
85     ]  # type: ignore
86     failed_script_ids = [task.build_fal_script(faldbt).id for task in failed_tasks]
87     if failed_script_ids:
88         raise RuntimeError(f"Error in scripts {str.join(', ',failed_script_ids)}")
89 
90 
91 def _scripts_flag(args: argparse.Namespace) -> bool:
92     return bool(args.scripts)
93 
94 
95 def _get_hooks_for_model(
96     models: List[DbtModel], faldbt: FalDbt, hook_type: str
97 ) -> List[FalScript]:
98     return [
99         FalScript.from_hook(faldbt, model, hook)
100         for model in models
101         for hook in model._get_hooks(hook_type=hook_type)
102     ]
103 
104 
105 def _select_scripts(
106     args: argparse.Namespace, models: List[DbtModel], faldbt: FalDbt
107 ) -> List[FalScript]:
108     scripts = []
109     scripts_flag = _scripts_flag(args)
110 
111     for model in models:
112         model_scripts = model.get_scripts(args.keyword, before=bool(args.before))
113         for path in model_scripts:
114             if not scripts_flag:
115                 # run all scripts when no --script is passed
116                 scripts.append(FalScript(faldbt, model, path))
117             elif path in args.scripts:
118                 # if --script selector is there only run selected scripts
119                 scripts.append(FalScript(faldbt, model, path))
120 
121     return scripts
122 
123 
124 def _get_global_scripts(faldbt: FalDbt, is_before: bool):
125     return [
126         FalScript(faldbt, None, path)
127         for path in faldbt._global_script_paths["before" if is_before else "after"]
128     ]
129 
130 
131 def _get_models_with_keyword(faldbt: FalDbt) -> List[DbtModel]:
132     return list(
133         filter(lambda model: faldbt.keyword in model.meta, faldbt.list_models())
134     )
135 
136 
137 def _get_filtered_models(faldbt: FalDbt, all, selected, before) -> List[DbtModel]:
138     selected_ids = _models_ids(faldbt._compile_task._flattened_nodes)
139     filtered_models: List[DbtModel] = []
140 
141     if (
142         not all
143         and not selected
144         and not before
145         and faldbt._run_results.nativeRunResult is None
146     ):
147         from faldbt.parse import FalParseError
148 
149         raise FalParseError(
150             "Cannot define models to run without selection flags or dbt run_results artifact or --before flag"
151         )
152 
153     models = _get_models_with_keyword(faldbt)
154 
155     for node in models:
156         if selected:
157             if node.unique_id in selected_ids:
158                 filtered_models.append(node)
159         elif before:
160             if node.get_scripts(faldbt.keyword, before=before) != []:
161                 filtered_models.append(node)
162         elif all:
163             filtered_models.append(node)
164         elif node.status != "skipped":
165             filtered_models.append(node)
166 
167     return filtered_models
168 
169 
170 def _models_ids(models):
171     return list(map(lambda r: r.unique_id, models))
172
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/fal/cli/fal_runner.py b/src/fal/cli/fal_runner.py
--- a/src/fal/cli/fal_runner.py
+++ b/src/fal/cli/fal_runner.py
@@ -50,15 +50,15 @@
     models = _get_filtered_models(faldbt, args.all, selector_flags, args.before)
 
     scripts = _select_scripts(args, models, faldbt)
-
-    global_scripts = _get_global_scripts(faldbt, args.before)
+    global_scripts = _get_global_scripts(faldbt, args)
 
     if args.before:
-        if not _scripts_flag(args):
-            # run globals when no --script is passed
+        if not _scripts_flag(args) or not selector_flags:
+            # run globals when no --script is passed or no selector is passed
             _run_scripts(args, global_scripts, faldbt)
 
         pre_hook_scripts = _get_hooks_for_model(models, faldbt, "pre-hook")
+
         _run_scripts(args, pre_hook_scripts, faldbt)
 
         _run_scripts(args, scripts, faldbt)
@@ -69,7 +69,7 @@
         post_hook_scripts = _get_hooks_for_model(models, faldbt, "post-hook")
         _run_scripts(args, post_hook_scripts, faldbt)
 
-        if not _scripts_flag(args):
+        if not _scripts_flag(args) or not selector_flags:
             # run globals when no --script is passed
             _run_scripts(args, global_scripts, faldbt)
 
@@ -121,10 +121,12 @@
     return scripts
 
 
-def _get_global_scripts(faldbt: FalDbt, is_before: bool):
+def _get_global_scripts(faldbt: FalDbt, args: argparse.Namespace):
+    scripts_flag = _scripts_flag(args)
     return [
         FalScript(faldbt, None, path)
-        for path in faldbt._global_script_paths["before" if is_before else "after"]
+        for path in faldbt._global_script_paths["before" if args.before else "after"]
+        if not scripts_flag or path in args.scripts
     ]

{"golden_diff": "diff --git a/src/fal/cli/fal_runner.py b/src/fal/cli/fal_runner.py\n--- a/src/fal/cli/fal_runner.py\n+++ b/src/fal/cli/fal_runner.py\n@@ -50,15 +50,15 @@\n     models = _get_filtered_models(faldbt, args.all, selector_flags, args.before)\n \n     scripts = _select_scripts(args, models, faldbt)\n-\n-    global_scripts = _get_global_scripts(faldbt, args.before)\n+    global_scripts = _get_global_scripts(faldbt, args)\n \n     if args.before:\n-        if not _scripts_flag(args):\n-            # run globals when no --script is passed\n+        if not _scripts_flag(args) or not selector_flags:\n+            # run globals when no --script is passed or no selector is passed\n             _run_scripts(args, global_scripts, faldbt)\n \n         pre_hook_scripts = _get_hooks_for_model(models, faldbt, \"pre-hook\")\n+\n         _run_scripts(args, pre_hook_scripts, faldbt)\n \n         _run_scripts(args, scripts, faldbt)\n@@ -69,7 +69,7 @@\n         post_hook_scripts = _get_hooks_for_model(models, faldbt, \"post-hook\")\n         _run_scripts(args, post_hook_scripts, faldbt)\n \n-        if not _scripts_flag(args):\n+        if not _scripts_flag(args) or not selector_flags:\n             # run globals when no --script is passed\n             _run_scripts(args, global_scripts, faldbt)\n \n@@ -121,10 +121,12 @@\n     return scripts\n \n \n-def _get_global_scripts(faldbt: FalDbt, is_before: bool):\n+def _get_global_scripts(faldbt: FalDbt, args: argparse.Namespace):\n+    scripts_flag = _scripts_flag(args)\n     return [\n         FalScript(faldbt, None, path)\n-        for path in faldbt._global_script_paths[\"before\" if is_before else \"after\"]\n+        for path in faldbt._global_script_paths[\"before\" if args.before else \"after\"]\n+        if not scripts_flag or path in args.scripts\n     ]\n", "issue": "fal run --scripts selector with global scripts not working\n<!-- *** Make sure you have searched for an existing bug report for this issue *** -->\r\n\r\n**Describe the bug**\r\nFal CLI `run` command using `--scripts` flag selector does not execute any script when the script passed is under the `before` key in the `schema.yml` configuration.\r\n\r\n**Your environment**\r\n- OS: macOS Monterrey 12.6\r\n- Paste the following commands output:\r\n```\r\nfal --0.6.0\r\ndbt --1.2.1\r\n```\r\n- Adapter being used: bigquery\r\n\r\n**How to reproduce**\r\nAdd scripts to run under `--before` key in the `schema.yml`:\r\n```\r\nversion: 2\r\n\r\nfal:\r\n  scripts:\r\n    before:\r\n      - fal_scripts/delete_bq_datasets.py\r\n      - fal_scripts/download_prod_artifacts.py\r\n```\r\nFile structure:\r\n```\r\ndbt_project\r\n\u251c\u2500\u2500 analysis\r\n\u251c\u2500\u2500 dbt_packages\r\n\u251c\u2500\u2500 dbt_project.yml\r\n\u251c\u2500\u2500 fal_scripts\r\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 delete_bq_datasets.py\r\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 download_prod_artifacts.py\r\n\u251c\u2500\u2500 logs\r\n\u251c\u2500\u2500 macros\r\n\u251c\u2500\u2500 models\r\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 exposures\r\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 schema.yml\r\n\u251c\u2500\u2500 packages.yml\r\n\u251c\u2500\u2500 seeds\r\n\u251c\u2500\u2500 snapshots\r\n\u251c\u2500\u2500 target\r\n\u2514\u2500\u2500 tests\r\n\r\n```\r\nThen run:\r\n```sh\r\nfal run --before --scripts download_prod_artifacts.py\r\n```\r\nOr:\r\n```sh\r\nfal run --scripts download_prod_artifacts.py\r\n```\r\n\r\n**Expected behavior**\r\nRun only the script passed to the `--scripts` flag: `download_prod_artifacts.py`.  \r\n\r\n**Actual behavior**\r\nDoes nothing for neither case.\r\n\r\n```sh\r\nfal run --scripts download_prod_artifacts.py\r\n```\r\n```\r\n13:25:19  Found 370 models, 544 tests, 0 snapshots, 18 analyses, 583 macros, 0 operations, 42 seed files, 129 sources, 2 exposures, 0 metrics\r\n13:25:19  Could not read dbt sources artifact\r\n```\r\n```sh\r\nfal run --before --scripts download_prod_artifacts.py\r\n```\r\n```\r\n13:27:34  Found 370 models, 544 tests, 0 snapshots, 18 analyses, 583 macros, 0 operations, 42 seed files, 129 sources, 2 exposures, 0 metrics\r\n13:27:34  Could not read dbt sources artifact\r\n```\r\n**Additional context**\r\nThe issue might be [this](https://github.com/fal-ai/fal/blob/771ad3dc8946dbda57e91b188719f8a20c6eb353/src/fal/cli/fal_runner.py#L47) section of code (related with `scripts` and `global_scripts` variables).\r\n\n", "before_files": [{"content": "import argparse\nfrom pathlib import Path\nfrom typing import Dict, List\n\nfrom dbt.flags import PROFILES_DIR\nfrom fal.planner.executor import parallel_executor\nfrom fal.planner.schedule import Scheduler\nfrom fal.planner.tasks import FalLocalHookTask, Status, TaskGroup\n\nfrom fal.fal_script import FalScript\nfrom faldbt.project import DbtModel, FalDbt, FalGeneralException\n\n\ndef create_fal_dbt(\n    args: argparse.Namespace, generated_models: Dict[str, Path] = {}\n) -> FalDbt:\n    profiles_dir = PROFILES_DIR\n    if args.profiles_dir is not None:\n        profiles_dir = args.profiles_dir\n\n    real_state = None\n    if hasattr(args, \"state\") and args.state is not None:\n        real_state = args.state\n\n    return FalDbt(\n        args.project_dir,\n        profiles_dir,\n        args.select,\n        args.exclude,\n        args.selector,\n        args.keyword,\n        args.threads,\n        real_state,\n        args.target,\n        getattr(args, \"vars\", \"{}\"),\n        generated_models,\n    )\n\n\ndef fal_run(args: argparse.Namespace):\n    \"Runs the fal run command in a subprocess\"\n\n    selector_flags = args.select or args.exclude or args.selector\n    if args.all and selector_flags:\n        raise FalGeneralException(\n            \"Cannot pass --all flag alongside selection flags (--select/--models, --exclude, --selector)\"\n        )\n\n    faldbt = create_fal_dbt(args)\n    models = _get_filtered_models(faldbt, args.all, selector_flags, args.before)\n\n    scripts = _select_scripts(args, models, faldbt)\n\n    global_scripts = _get_global_scripts(faldbt, args.before)\n\n    if args.before:\n        if not _scripts_flag(args):\n            # run globals when no --script is passed\n            _run_scripts(args, global_scripts, faldbt)\n\n        pre_hook_scripts = _get_hooks_for_model(models, faldbt, \"pre-hook\")\n        _run_scripts(args, pre_hook_scripts, faldbt)\n\n        _run_scripts(args, scripts, faldbt)\n\n    else:\n        _run_scripts(args, scripts, faldbt)\n\n        post_hook_scripts = _get_hooks_for_model(models, faldbt, \"post-hook\")\n        _run_scripts(args, post_hook_scripts, faldbt)\n\n        if not _scripts_flag(args):\n            # run globals when no --script is passed\n            _run_scripts(args, global_scripts, faldbt)\n\n\ndef _run_scripts(args: argparse.Namespace, scripts: List[FalScript], faldbt: FalDbt):\n    scheduler = Scheduler(\n        [TaskGroup(FalLocalHookTask.from_fal_script(script)) for script in scripts]\n    )\n    parallel_executor(args, faldbt, scheduler)\n\n    failed_tasks: List[FalLocalHookTask] = [\n        group.task for group in scheduler.filter_groups(Status.FAILURE)\n    ]  # type: ignore\n    failed_script_ids = [task.build_fal_script(faldbt).id for task in failed_tasks]\n    if failed_script_ids:\n        raise RuntimeError(f\"Error in scripts {str.join(', ',failed_script_ids)}\")\n\n\ndef _scripts_flag(args: argparse.Namespace) -> bool:\n    return bool(args.scripts)\n\n\ndef _get_hooks_for_model(\n    models: List[DbtModel], faldbt: FalDbt, hook_type: str\n) -> List[FalScript]:\n    return [\n        FalScript.from_hook(faldbt, model, hook)\n        for model in models\n        for hook in model._get_hooks(hook_type=hook_type)\n    ]\n\n\ndef _select_scripts(\n    args: argparse.Namespace, models: List[DbtModel], faldbt: FalDbt\n) -> List[FalScript]:\n    scripts = []\n    scripts_flag = _scripts_flag(args)\n\n    for model in models:\n        model_scripts = model.get_scripts(args.keyword, before=bool(args.before))\n        for path in model_scripts:\n            if not scripts_flag:\n                # run all scripts when no --script is passed\n                scripts.append(FalScript(faldbt, model, path))\n            elif path in args.scripts:\n                # if --script selector is there only run selected scripts\n                scripts.append(FalScript(faldbt, model, path))\n\n    return scripts\n\n\ndef _get_global_scripts(faldbt: FalDbt, is_before: bool):\n    return [\n        FalScript(faldbt, None, path)\n        for path in faldbt._global_script_paths[\"before\" if is_before else \"after\"]\n    ]\n\n\ndef _get_models_with_keyword(faldbt: FalDbt) -> List[DbtModel]:\n    return list(\n        filter(lambda model: faldbt.keyword in model.meta, faldbt.list_models())\n    )\n\n\ndef _get_filtered_models(faldbt: FalDbt, all, selected, before) -> List[DbtModel]:\n    selected_ids = _models_ids(faldbt._compile_task._flattened_nodes)\n    filtered_models: List[DbtModel] = []\n\n    if (\n        not all\n        and not selected\n        and not before\n        and faldbt._run_results.nativeRunResult is None\n    ):\n        from faldbt.parse import FalParseError\n\n        raise FalParseError(\n            \"Cannot define models to run without selection flags or dbt run_results artifact or --before flag\"\n        )\n\n    models = _get_models_with_keyword(faldbt)\n\n    for node in models:\n        if selected:\n            if node.unique_id in selected_ids:\n                filtered_models.append(node)\n        elif before:\n            if node.get_scripts(faldbt.keyword, before=before) != []:\n                filtered_models.append(node)\n        elif all:\n            filtered_models.append(node)\n        elif node.status != \"skipped\":\n            filtered_models.append(node)\n\n    return filtered_models\n\n\ndef _models_ids(models):\n    return list(map(lambda r: r.unique_id, models))\n", "path": "src/fal/cli/fal_runner.py"}], "after_files": [{"content": "import argparse\nfrom pathlib import Path\nfrom typing import Dict, List\n\nfrom dbt.flags import PROFILES_DIR\nfrom fal.planner.executor import parallel_executor\nfrom fal.planner.schedule import Scheduler\nfrom fal.planner.tasks import FalLocalHookTask, Status, TaskGroup\n\nfrom fal.fal_script import FalScript\nfrom faldbt.project import DbtModel, FalDbt, FalGeneralException\n\n\ndef create_fal_dbt(\n    args: argparse.Namespace, generated_models: Dict[str, Path] = {}\n) -> FalDbt:\n    profiles_dir = PROFILES_DIR\n    if args.profiles_dir is not None:\n        profiles_dir = args.profiles_dir\n\n    real_state = None\n    if hasattr(args, \"state\") and args.state is not None:\n        real_state = args.state\n\n    return FalDbt(\n        args.project_dir,\n        profiles_dir,\n        args.select,\n        args.exclude,\n        args.selector,\n        args.keyword,\n        args.threads,\n        real_state,\n        args.target,\n        getattr(args, \"vars\", \"{}\"),\n        generated_models,\n    )\n\n\ndef fal_run(args: argparse.Namespace):\n    \"Runs the fal run command in a subprocess\"\n\n    selector_flags = args.select or args.exclude or args.selector\n    if args.all and selector_flags:\n        raise FalGeneralException(\n            \"Cannot pass --all flag alongside selection flags (--select/--models, --exclude, --selector)\"\n        )\n\n    faldbt = create_fal_dbt(args)\n    models = _get_filtered_models(faldbt, args.all, selector_flags, args.before)\n\n    scripts = _select_scripts(args, models, faldbt)\n    global_scripts = _get_global_scripts(faldbt, args)\n\n    if args.before:\n        if not _scripts_flag(args) or not selector_flags:\n            # run globals when no --script is passed or no selector is passed\n            _run_scripts(args, global_scripts, faldbt)\n\n        pre_hook_scripts = _get_hooks_for_model(models, faldbt, \"pre-hook\")\n\n        _run_scripts(args, pre_hook_scripts, faldbt)\n\n        _run_scripts(args, scripts, faldbt)\n\n    else:\n        _run_scripts(args, scripts, faldbt)\n\n        post_hook_scripts = _get_hooks_for_model(models, faldbt, \"post-hook\")\n        _run_scripts(args, post_hook_scripts, faldbt)\n\n        if not _scripts_flag(args) or not selector_flags:\n            # run globals when no --script is passed\n            _run_scripts(args, global_scripts, faldbt)\n\n\ndef _run_scripts(args: argparse.Namespace, scripts: List[FalScript], faldbt: FalDbt):\n    scheduler = Scheduler(\n        [TaskGroup(FalLocalHookTask.from_fal_script(script)) for script in scripts]\n    )\n    parallel_executor(args, faldbt, scheduler)\n\n    failed_tasks: List[FalLocalHookTask] = [\n        group.task for group in scheduler.filter_groups(Status.FAILURE)\n    ]  # type: ignore\n    failed_script_ids = [task.build_fal_script(faldbt).id for task in failed_tasks]\n    if failed_script_ids:\n        raise RuntimeError(f\"Error in scripts {str.join(', ',failed_script_ids)}\")\n\n\ndef _scripts_flag(args: argparse.Namespace) -> bool:\n    return bool(args.scripts)\n\n\ndef _get_hooks_for_model(\n    models: List[DbtModel], faldbt: FalDbt, hook_type: str\n) -> List[FalScript]:\n    return [\n        FalScript.from_hook(faldbt, model, hook)\n        for model in models\n        for hook in model._get_hooks(hook_type=hook_type)\n    ]\n\n\ndef _select_scripts(\n    args: argparse.Namespace, models: List[DbtModel], faldbt: FalDbt\n) -> List[FalScript]:\n    scripts = []\n    scripts_flag = _scripts_flag(args)\n\n    for model in models:\n        model_scripts = model.get_scripts(args.keyword, before=bool(args.before))\n        for path in model_scripts:\n            if not scripts_flag:\n                # run all scripts when no --script is passed\n                scripts.append(FalScript(faldbt, model, path))\n            elif path in args.scripts:\n                # if --script selector is there only run selected scripts\n                scripts.append(FalScript(faldbt, model, path))\n\n    return scripts\n\n\ndef _get_global_scripts(faldbt: FalDbt, args: argparse.Namespace):\n    scripts_flag = _scripts_flag(args)\n    return [\n        FalScript(faldbt, None, path)\n        for path in faldbt._global_script_paths[\"before\" if args.before else \"after\"]\n        if not scripts_flag or path in args.scripts\n    ]\n\n\ndef _get_models_with_keyword(faldbt: FalDbt) -> List[DbtModel]:\n    return list(\n        filter(lambda model: faldbt.keyword in model.meta, faldbt.list_models())\n    )\n\n\ndef _get_filtered_models(faldbt: FalDbt, all, selected, before) -> List[DbtModel]:\n    selected_ids = _models_ids(faldbt._compile_task._flattened_nodes)\n    filtered_models: List[DbtModel] = []\n\n    if (\n        not all\n        and not selected\n        and not before\n        and faldbt._run_results.nativeRunResult is None\n    ):\n        from faldbt.parse import FalParseError\n\n        raise FalParseError(\n            \"Cannot define models to run without selection flags or dbt run_results artifact or --before flag\"\n        )\n\n    models = _get_models_with_keyword(faldbt)\n\n    for node in models:\n        if selected:\n            if node.unique_id in selected_ids:\n                filtered_models.append(node)\n        elif before:\n            if node.get_scripts(faldbt.keyword, before=before) != []:\n                filtered_models.append(node)\n        elif all:\n            filtered_models.append(node)\n        elif node.status != \"skipped\":\n            filtered_models.append(node)\n\n    return filtered_models\n\n\ndef _models_ids(models):\n    return list(map(lambda r: r.unique_id, models))\n", "path": "src/fal/cli/fal_runner.py"}]}