ara-cli 0.1.9.96__py3-none-any.whl → 0.1.10.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ara-cli might be problematic. Click here for more details.

Files changed (48) hide show
  1. ara_cli/__init__.py +1 -1
  2. ara_cli/__main__.py +141 -103
  3. ara_cli/ara_command_action.py +65 -7
  4. ara_cli/ara_config.py +118 -94
  5. ara_cli/ara_subcommands/__init__.py +0 -0
  6. ara_cli/ara_subcommands/autofix.py +26 -0
  7. ara_cli/ara_subcommands/chat.py +27 -0
  8. ara_cli/ara_subcommands/classifier_directory.py +16 -0
  9. ara_cli/ara_subcommands/common.py +100 -0
  10. ara_cli/ara_subcommands/create.py +75 -0
  11. ara_cli/ara_subcommands/delete.py +22 -0
  12. ara_cli/ara_subcommands/extract.py +22 -0
  13. ara_cli/ara_subcommands/fetch_templates.py +14 -0
  14. ara_cli/ara_subcommands/list.py +65 -0
  15. ara_cli/ara_subcommands/list_tags.py +25 -0
  16. ara_cli/ara_subcommands/load.py +48 -0
  17. ara_cli/ara_subcommands/prompt.py +136 -0
  18. ara_cli/ara_subcommands/read.py +47 -0
  19. ara_cli/ara_subcommands/read_status.py +20 -0
  20. ara_cli/ara_subcommands/read_user.py +20 -0
  21. ara_cli/ara_subcommands/reconnect.py +27 -0
  22. ara_cli/ara_subcommands/rename.py +22 -0
  23. ara_cli/ara_subcommands/scan.py +14 -0
  24. ara_cli/ara_subcommands/set_status.py +22 -0
  25. ara_cli/ara_subcommands/set_user.py +22 -0
  26. ara_cli/ara_subcommands/template.py +16 -0
  27. ara_cli/artefact_models/artefact_model.py +88 -19
  28. ara_cli/artefact_models/artefact_templates.py +18 -9
  29. ara_cli/artefact_models/userstory_artefact_model.py +2 -2
  30. ara_cli/artefact_scan.py +2 -2
  31. ara_cli/chat.py +204 -142
  32. ara_cli/commands/read_command.py +17 -4
  33. ara_cli/completers.py +144 -0
  34. ara_cli/prompt_handler.py +268 -127
  35. ara_cli/tag_extractor.py +33 -16
  36. ara_cli/template_loader.py +245 -0
  37. ara_cli/version.py +1 -1
  38. {ara_cli-0.1.9.96.dist-info → ara_cli-0.1.10.1.dist-info}/METADATA +3 -1
  39. {ara_cli-0.1.9.96.dist-info → ara_cli-0.1.10.1.dist-info}/RECORD +47 -23
  40. tests/test_artefact_scan.py +1 -1
  41. tests/test_chat.py +1840 -574
  42. tests/test_prompt_handler.py +40 -4
  43. tests/test_tag_extractor.py +19 -13
  44. tests/test_template_loader.py +192 -0
  45. ara_cli/ara_command_parser.py +0 -565
  46. {ara_cli-0.1.9.96.dist-info → ara_cli-0.1.10.1.dist-info}/WHEEL +0 -0
  47. {ara_cli-0.1.9.96.dist-info → ara_cli-0.1.10.1.dist-info}/entry_points.txt +0 -0
  48. {ara_cli-0.1.9.96.dist-info → ara_cli-0.1.10.1.dist-info}/top_level.txt +0 -0
ara_cli/__init__.py CHANGED
@@ -14,7 +14,7 @@ RESET = '\033[0m'
14
14
 
15
15
 
16
16
  def format_warning(message, category, *args, **kwargs):
17
- return f'{YELLOW}{category.__name__}: {message}{RESET}\n'
17
+ return f'{YELLOW}[WARNING] {category.__name__}: {message}{RESET}\n'
18
18
 
19
19
 
20
20
  warnings.formatwarning = format_warning
ara_cli/__main__.py CHANGED
@@ -1,60 +1,36 @@
1
- # PYTHON_ARGCOMPLETE_OK
2
- from ara_cli.ara_command_parser import action_parser
3
- from ara_cli.error_handler import AraError
4
- from ara_cli.version import __version__
5
- from ara_cli.ara_command_action import (
6
- create_action,
7
- delete_action,
8
- rename_action,
9
- list_action,
10
- list_tags_action,
11
- prompt_action,
12
- chat_action,
13
- template_action,
14
- fetch_templates_action,
15
- read_action,
16
- reconnect_action,
17
- read_status_action,
18
- read_user_action,
19
- set_status_action,
20
- set_user_action,
21
- classifier_directory_action,
22
- scan_action,
23
- autofix_action,
24
- extract_action
25
- )
26
- from . import error_handler
27
- import argcomplete
1
+ import typer
28
2
  import sys
3
+ from typing import Optional
29
4
  from os import getenv
30
-
31
-
32
- def define_action_mapping():
33
- return {
34
- "create": create_action,
35
- "delete": delete_action,
36
- "rename": rename_action,
37
- "list": list_action,
38
- "list-tags": list_tags_action,
39
- "prompt": prompt_action,
40
- "chat": chat_action,
41
- "template": template_action,
42
- "fetch-templates": fetch_templates_action,
43
- "read": read_action,
44
- "reconnect": reconnect_action,
45
- "read-status": read_status_action,
46
- "read-user": read_user_action,
47
- "set-status": set_status_action,
48
- "set-user": set_user_action,
49
- "classifier-directory": classifier_directory_action,
50
- "scan": scan_action,
51
- "autofix": autofix_action,
52
- "extract": extract_action
53
- }
54
-
55
-
56
- def handle_invalid_action(args):
57
- raise AraError("Invalid action provided. Type ara -h for help", error_code=1)
5
+ from ara_cli.error_handler import AraError
6
+ from ara_cli.version import __version__
7
+ from ara_cli import error_handler
8
+ from ara_cli.ara_subcommands.create import register as register_create_cli
9
+ from ara_cli.ara_subcommands.delete import register as register_delete_cli
10
+ from ara_cli.ara_subcommands.rename import register as register_rename_cli
11
+ from ara_cli.ara_subcommands.list import register as register_list_cli
12
+ from ara_cli.ara_subcommands.list_tags import register as register_list_tags_cli
13
+ from ara_cli.ara_subcommands.prompt import register as register_prompt_cli
14
+ from ara_cli.ara_subcommands.chat import register as register_chat_cli
15
+ from ara_cli.ara_subcommands.template import register as register_template_cli
16
+ from ara_cli.ara_subcommands.fetch_templates import register as register_fetch_templates_cli
17
+ from ara_cli.ara_subcommands.read import register as register_read_cli
18
+ from ara_cli.ara_subcommands.reconnect import register as register_reconnect_cli
19
+ from ara_cli.ara_subcommands.read_status import register as register_read_status_cli
20
+ from ara_cli.ara_subcommands.read_user import register as register_read_user_cli
21
+ from ara_cli.ara_subcommands.set_status import register as register_set_status_cli
22
+ from ara_cli.ara_subcommands.set_user import register as register_set_user_cli
23
+ from ara_cli.ara_subcommands.classifier_directory import register as register_classifier_directory_cli
24
+ from ara_cli.ara_subcommands.scan import register as register_scan_cli
25
+ from ara_cli.ara_subcommands.autofix import register as register_autofix_cli
26
+ from ara_cli.ara_subcommands.extract import register as register_extract_cli
27
+ from ara_cli.ara_subcommands.load import register as register_load_cli
28
+
29
+
30
+ def version_callback(value: bool):
31
+ if value:
32
+ typer.echo(f"ara {__version__}")
33
+ raise typer.Exit()
58
34
 
59
35
 
60
36
  def is_debug_mode_enabled():
@@ -62,66 +38,128 @@ def is_debug_mode_enabled():
62
38
  return getenv('ARA_DEBUG', '').lower() in ('1', 'true', 'yes')
63
39
 
64
40
 
65
- def setup_parser():
66
- """Create and configure the argument parser."""
67
- parser = action_parser()
68
-
69
- # Show examples when help is called
70
- if any(arg in sys.argv for arg in ["-h", "--help"]):
71
- parser.add_examples = True
72
-
73
- parser.add_argument(
74
- "-v", "--version", action="version", version=f"%(prog)s {__version__}"
75
- )
76
-
77
- parser.add_argument(
78
- "--debug", action="store_true", help="Enable debug mode for detailed error output"
79
- )
80
-
81
- return parser
82
-
83
-
84
- def configure_debug_mode(args, env_debug_mode):
41
+ def configure_debug_mode(debug: bool, env_debug_mode: bool):
85
42
  """Configure debug mode based on arguments and environment."""
86
- if (hasattr(args, 'debug') and args.debug) or env_debug_mode:
43
+ if debug or env_debug_mode:
87
44
  error_handler.debug_mode = True
88
45
 
89
46
 
90
- def should_show_help(args):
91
- """Check if help should be displayed."""
92
- return not hasattr(args, "action") or not args.action
93
-
47
+ def create_app():
48
+ app = typer.Typer(
49
+ help="""The ara cli terminal tool is a management tool for classified ara artefacts.
50
+
51
+ Valid classified artefacts are: businessgoal, vision, capability, keyfeature, feature, epic, userstory, example, feature, task.
52
+
53
+ The default ara directory structure of classified artefact of the ara cli tool is:
54
+ .
55
+ └── ara
56
+ ├── businessgoals
57
+ ├── capabilities
58
+ ├── epics
59
+ ├── examples
60
+ ├── features
61
+ ├── keyfeatures
62
+ ├── tasks
63
+ ├── userstories
64
+ └── vision
65
+
66
+ ara artefact handling examples:
67
+ > create a new artefact for e.g. a feature: ara create feature {feature_name}
68
+ > create a new artefact for e.g. a feature that contributes to an userstory: ara create feature {feature_name} contributes-to userstory {story_name}
69
+ > read an artefact and return the content as terminal output, for eg. of a task: ara read task {task_name}
70
+ > read an artefact and its full chain of contributions to its parents and return
71
+ the content as terminal output, for eg. of a task: ara read task {task_name} --branch
72
+ > delete an artefact for e.g. feature: ara delete feature {feature_name}
73
+ > rename artefact and artefact data directory for e.g. a feature: ara rename feature {initial_feature_name} {new_feature_name}
74
+ > create additional templates for a specific aspect (valid aspects are: customer,
75
+ persona, concept, technology) related to an existing artefact like a feature: ara create feature {feature_name} aspect {aspect_name}
76
+ > list artefact data with .md file extension ara list --data {classifier} {artefact_name} --include-extension .md
77
+ > list artefact data with .md and .json file extensions ara list --data {classifier} {artefact_name} --include-extension .md .json
78
+ > list everything but userstories ara list --exclude-extension .userstory
79
+ > list all existing features: ara list --include-extension .feature
80
+ > list all child artefacts contributing value to a parent artefact: ara list --include-content "Contributes to {name_of_parent_artefact} {ara classifier_of_parent_artefact}"
81
+ > list tasks which contain 'example content' ara list --include-extension .task --include-content "example content"
82
+ > list children artefacts of a userstory ara list --children userstory {name_of_userstory}
83
+ > list parent artefacts of a userstory ara list --branch userstory {name_of_userstory}
84
+ > list parent businessgoal artefact of a userstory ara list --branch userstory {name_of_userstory} --include-extension .businessgoal
85
+ > print any artefact template for e.g. a feature file template in the terminal: ara template feature
86
+
87
+ ara prompt templates examples:
88
+ > get and copy all prompt templates (blueprints, rules, intentions, commands
89
+ in the ara/.araconfig/global-prompt-modules directory: ara fetch-templates
90
+
91
+ ara chat examples:
92
+ > chat with ara and save the default chat.md file in the working directory: ara chat
93
+ > chat with ara and save the default task_chat.md file in the task.data directory: ara prompt chat task {task_name}
94
+
95
+ > initialize a macro prompt for a task: ara prompt init task {task_name}
96
+ > load selected templates in config_prompt_templates.md for the task {task_name}: ara prompt load task {task_name}
97
+ > create and send configured prompt of the task {task_name} to the configured LLM: ara prompt send task {task_name}
98
+ > extract the selected LLM response in task.exploration.md and save to disk: ara prompt extract task {task_name}
99
+ """,
100
+ no_args_is_help=True,
101
+ add_completion=True,
102
+ rich_markup_mode="rich"
103
+ )
94
104
 
95
- def execute_action(args, action_mapping):
96
- """Execute the specified action."""
97
- action = action_mapping.get(args.action, handle_invalid_action)
98
- action(args)
105
+ @app.callback(invoke_without_command=True)
106
+ def main(
107
+ ctx: typer.Context,
108
+ version: Optional[bool] = typer.Option(
109
+ None, "--version", "-v",
110
+ callback=version_callback,
111
+ is_eager=True,
112
+ help="Show version and exit"
113
+ ),
114
+ debug: bool = typer.Option(
115
+ False, "--debug",
116
+ help="Enable debug mode for detailed error output"
117
+ )
118
+ ):
119
+ """The ara cli terminal tool is a management tool for classified ara artefacts."""
120
+ debug_mode = is_debug_mode_enabled()
121
+ configure_debug_mode(debug, debug_mode)
122
+
123
+ # Only show help if no subcommand is invoked
124
+ if ctx.invoked_subcommand is None:
125
+ ctx.get_help()
126
+ ctx.exit()
127
+
128
+ # Register all commands
129
+ register_create_cli(app)
130
+ register_delete_cli(app)
131
+ register_rename_cli(app)
132
+ register_list_cli(app)
133
+ register_list_tags_cli(app)
134
+ register_prompt_cli(app)
135
+ register_chat_cli(app)
136
+ register_template_cli(app)
137
+ register_fetch_templates_cli(app)
138
+ register_read_cli(app)
139
+ register_reconnect_cli(app)
140
+ register_read_status_cli(app)
141
+ register_read_user_cli(app)
142
+ register_set_status_cli(app)
143
+ register_set_user_cli(app)
144
+ register_classifier_directory_cli(app)
145
+ register_scan_cli(app)
146
+ register_autofix_cli(app)
147
+ register_extract_cli(app)
148
+ register_load_cli(app)
149
+
150
+ return app
99
151
 
100
152
 
101
153
  def cli():
102
- debug_mode = is_debug_mode_enabled()
103
-
154
+ app = create_app()
104
155
  try:
105
- parser = setup_parser()
106
- action_mapping = define_action_mapping()
107
-
108
- argcomplete.autocomplete(parser)
109
- args = parser.parse_args()
110
-
111
- configure_debug_mode(args, debug_mode)
112
-
113
- if should_show_help(args):
114
- parser.print_help()
115
- return
116
-
117
- execute_action(args, action_mapping)
118
-
156
+ app()
119
157
  except KeyboardInterrupt:
120
- print("\n[INFO] Operation cancelled by user", file=sys.stderr)
121
- sys.exit(130) # Standard exit code for Ctrl+C
158
+ typer.echo("\n[INFO] Operation cancelled by user", err=True)
159
+ raise typer.Exit(130) # Standard exit code for Ctrl+C
122
160
  except Exception as e:
123
161
  error_handler.handle_error(e, context="cli")
124
162
 
125
163
 
126
164
  if __name__ == "__main__":
127
- cli()
165
+ cli()
@@ -130,9 +130,6 @@ def list_action(args):
130
130
  )
131
131
  return
132
132
 
133
- if (args.tags):
134
- artefact_lister.list_files(tags=args.tags, list_filter=list_filter)
135
- return
136
133
  artefact_lister.list_files(list_filter=list_filter)
137
134
 
138
135
 
@@ -147,17 +144,25 @@ def list_tags_action(args):
147
144
  )
148
145
 
149
146
  tag_extractor = TagExtractor()
150
- tags = tag_extractor.extract_tags(
147
+ tag_groups = tag_extractor.extract_tags(
151
148
  filtered_extra_column=getattr(args, "filtered_extra_column", False),
152
149
  list_filter=list_filter
153
150
  )
154
151
 
155
152
  if args.json:
156
- output = json.dumps({"tags": tags})
153
+ all_tags = []
154
+ for group in tag_groups.values():
155
+ all_tags.extend(group)
156
+ output = json.dumps({"tags": sorted(all_tags)})
157
157
  print(output)
158
158
  return
159
159
 
160
- output = "\n".join(f"- {tag}" for tag in tags)
160
+ output_lines = []
161
+ for key in sorted(tag_groups.keys()):
162
+ line = " ".join(sorted(list(tag_groups[key])))
163
+ output_lines.append(line)
164
+
165
+ output = "\n".join(f"- {tag}" for tag in output_lines)
161
166
  print(output)
162
167
 
163
168
 
@@ -261,6 +266,59 @@ def chat_action(args):
261
266
  chat.start()
262
267
 
263
268
 
269
+ def _find_chat_file(chat_name: str) -> str | None:
270
+ """Resolves the chat file path based on common naming conventions."""
271
+ # Logic from setup_chat for finding existing files.
272
+ if os.path.exists(chat_name) and os.path.isfile(chat_name):
273
+ return chat_name
274
+
275
+ chat_name_md = f"{chat_name}.md"
276
+ if os.path.exists(chat_name_md) and os.path.isfile(chat_name_md):
277
+ return chat_name_md
278
+
279
+ chat_name_chat_md = f"{chat_name}_chat.md"
280
+ if os.path.exists(chat_name_chat_md) and os.path.isfile(chat_name_chat_md):
281
+ return chat_name_chat_md
282
+
283
+ return None
284
+
285
+
286
+ @handle_errors(context="load action", error_handler=error_handler)
287
+ def load_action(args):
288
+ from ara_cli.template_loader import TemplateLoader
289
+
290
+ chat_name = args.chat_name
291
+ template_type = args.template_type
292
+ template_name = args.template_name
293
+
294
+ chat_file_path = _find_chat_file(chat_name)
295
+
296
+ if not chat_file_path:
297
+ raise AraError(f"Chat file for '{chat_name}' not found.")
298
+
299
+ default_patterns = {
300
+ "rules": "*.rules.md",
301
+ "intention": "*.intention.md",
302
+ "commands": "*.commands.md"
303
+ }
304
+
305
+ default_pattern = default_patterns.get(template_type)
306
+
307
+ if not template_name and not default_pattern:
308
+ raise AraError(f"A template name is required for template type '{template_type}'.")
309
+
310
+ loader = TemplateLoader() # No chat instance for CLI context
311
+ success = loader.load_template(
312
+ template_name=template_name,
313
+ template_type=template_type,
314
+ chat_file_path=chat_file_path,
315
+ default_pattern=default_pattern
316
+ )
317
+
318
+ if not success:
319
+ sys.exit(1)
320
+
321
+
264
322
  @handle_errors(context="template action", error_handler=error_handler)
265
323
  def template_action(args):
266
324
  from ara_cli.classifier import Classifier
@@ -615,4 +673,4 @@ def extract_action(args):
615
673
  write=write,
616
674
  output=lambda msg: print(msg, file=sys.stdout)
617
675
  )
618
- command.execute()
676
+ command.execute()