ara-cli 0.1.10.0__py3-none-any.whl → 0.1.10.4__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 (49) hide show
  1. ara_cli/__main__.py +252 -97
  2. ara_cli/ara_command_action.py +11 -6
  3. ara_cli/ara_subcommands/__init__.py +0 -0
  4. ara_cli/ara_subcommands/autofix.py +26 -0
  5. ara_cli/ara_subcommands/chat.py +27 -0
  6. ara_cli/ara_subcommands/classifier_directory.py +16 -0
  7. ara_cli/ara_subcommands/common.py +100 -0
  8. ara_cli/ara_subcommands/create.py +75 -0
  9. ara_cli/ara_subcommands/delete.py +22 -0
  10. ara_cli/ara_subcommands/extract.py +22 -0
  11. ara_cli/ara_subcommands/fetch_templates.py +14 -0
  12. ara_cli/ara_subcommands/list.py +65 -0
  13. ara_cli/ara_subcommands/list_tags.py +25 -0
  14. ara_cli/ara_subcommands/load.py +48 -0
  15. ara_cli/ara_subcommands/prompt.py +136 -0
  16. ara_cli/ara_subcommands/read.py +47 -0
  17. ara_cli/ara_subcommands/read_status.py +20 -0
  18. ara_cli/ara_subcommands/read_user.py +20 -0
  19. ara_cli/ara_subcommands/reconnect.py +27 -0
  20. ara_cli/ara_subcommands/rename.py +22 -0
  21. ara_cli/ara_subcommands/scan.py +14 -0
  22. ara_cli/ara_subcommands/set_status.py +22 -0
  23. ara_cli/ara_subcommands/set_user.py +22 -0
  24. ara_cli/ara_subcommands/template.py +16 -0
  25. ara_cli/artefact_autofix.py +44 -6
  26. ara_cli/artefact_models/artefact_model.py +106 -25
  27. ara_cli/artefact_models/artefact_templates.py +18 -9
  28. ara_cli/artefact_models/epic_artefact_model.py +11 -2
  29. ara_cli/artefact_models/feature_artefact_model.py +31 -1
  30. ara_cli/artefact_models/userstory_artefact_model.py +15 -3
  31. ara_cli/artefact_scan.py +2 -2
  32. ara_cli/chat.py +1 -19
  33. ara_cli/commands/read_command.py +17 -4
  34. ara_cli/completers.py +144 -0
  35. ara_cli/file_loaders/text_file_loader.py +2 -2
  36. ara_cli/prompt_extractor.py +97 -79
  37. ara_cli/prompt_handler.py +160 -59
  38. ara_cli/tag_extractor.py +38 -18
  39. ara_cli/template_loader.py +1 -1
  40. ara_cli/version.py +1 -1
  41. {ara_cli-0.1.10.0.dist-info → ara_cli-0.1.10.4.dist-info}/METADATA +2 -1
  42. {ara_cli-0.1.10.0.dist-info → ara_cli-0.1.10.4.dist-info}/RECORD +48 -26
  43. tests/test_artefact_scan.py +1 -1
  44. tests/test_prompt_handler.py +12 -4
  45. tests/test_tag_extractor.py +19 -13
  46. ara_cli/ara_command_parser.py +0 -605
  47. {ara_cli-0.1.10.0.dist-info → ara_cli-0.1.10.4.dist-info}/WHEEL +0 -0
  48. {ara_cli-0.1.10.0.dist-info → ara_cli-0.1.10.4.dist-info}/entry_points.txt +0 -0
  49. {ara_cli-0.1.10.0.dist-info → ara_cli-0.1.10.4.dist-info}/top_level.txt +0 -0
@@ -184,6 +184,10 @@ class Artefact(BaseModel, ABC):
184
184
  default=[],
185
185
  description="Optional list of tags (0-many)",
186
186
  )
187
+ author: Optional[str] = Field(
188
+ default="creator_unknown",
189
+ description="Author of the artefact, must be a single entry of the form 'creator_<someone>'."
190
+ )
187
191
  title: str = Field(
188
192
  ...,
189
193
  description="Descriptive Artefact title (mandatory)",
@@ -252,6 +256,17 @@ class Artefact(BaseModel, ABC):
252
256
  raise ValueError(f"Tag '{tag}' has the form of a status tag. Set `status` field instead of passing it with other tags")
253
257
  if tag.startswith("user_"):
254
258
  raise ValueError(f"Tag '{tag} has the form of a user tag. Set `users` field instead of passing it with other tags")
259
+ if tag.startswith("creator_"):
260
+ raise ValueError(f"Tag '{tag}' has the form of an author tag. Set `author` field instead of passing it with other tags")
261
+ return v
262
+
263
+ @field_validator('author')
264
+ def validate_author(cls, v):
265
+ if v:
266
+ if not v.startswith("creator_"):
267
+ raise ValueError(f"Author '{v}' must start with 'creator_'.")
268
+ if len(v) <= len("creator_"):
269
+ raise ValueError("Creator name cannot be empty in author tag.")
255
270
  return v
256
271
 
257
272
  @field_validator('title')
@@ -291,32 +306,81 @@ class Artefact(BaseModel, ABC):
291
306
  tag_line = lines[0]
292
307
  if not tag_line.startswith('@'):
293
308
  return {}, lines
309
+
294
310
  tags = tag_line.split()
311
+ tag_dict = cls._process_tags(tags)
312
+ return tag_dict, lines[1:]
313
+
314
+ @classmethod
315
+ def _process_tags(cls, tags) -> Dict[str, str]:
316
+ """Process a list of tags and return a dictionary with categorized tags."""
295
317
  status = None
296
318
  regular_tags = []
297
319
  users = []
298
- status_list = ["@to-do", "@in-progress", "@review", "@done", "@closed"]
299
- user_prefix = "@user_"
300
- user_prefix_length = len(user_prefix)
301
-
320
+ author = None
321
+
302
322
  for tag in tags:
303
- if not tag.startswith('@'):
304
- raise ValueError(f"Tag '{tag}' should start with '@' but started with '{tag[0]}'")
305
- if tag in status_list and status is not None:
306
- raise ValueError(f"Multiple status tags found: '@{status}' and '{tag}'")
307
- if tag in status_list:
308
- status = tag[1:]
309
- continue
310
- if tag.startswith("@user_") and len(tag) > user_prefix_length + 1:
311
- users.append(tag[user_prefix_length:])
312
- continue
313
- regular_tags.append(tag[1:])
314
- tag_dict = {
323
+ cls._validate_tag_format(tag)
324
+
325
+ if cls._is_status_tag(tag):
326
+ status = cls._process_status_tag(tag, status)
327
+ elif cls._is_user_tag(tag):
328
+ users.append(cls._extract_user_from_tag(tag))
329
+ elif cls._is_author_tag(tag):
330
+ author = cls._process_author_tag(tag, author)
331
+ else:
332
+ regular_tags.append(tag[1:])
333
+
334
+ return {
315
335
  "status": status,
316
336
  "users": users,
317
- "tags": regular_tags
337
+ "tags": regular_tags,
338
+ "author": author
318
339
  }
319
- return tag_dict, lines[1:]
340
+
341
+ @classmethod
342
+ def _validate_tag_format(cls, tag):
343
+ """Validate that tag starts with @."""
344
+ if not tag.startswith('@'):
345
+ raise ValueError(f"Tag '{tag}' should start with '@' but started with '{tag[0]}'")
346
+
347
+ @classmethod
348
+ def _is_status_tag(cls, tag) -> bool:
349
+ """Check if tag is a status tag."""
350
+ status_list = ["@to-do", "@in-progress", "@review", "@done", "@closed"]
351
+ return tag in status_list
352
+
353
+ @classmethod
354
+ def _process_status_tag(cls, tag, current_status):
355
+ """Process status tag and check for duplicates."""
356
+ if current_status is not None:
357
+ raise ValueError(f"Multiple status tags found: '@{current_status}' and '{tag}'")
358
+ return tag[1:] # Remove @ prefix
359
+
360
+ @classmethod
361
+ def _is_user_tag(cls, tag) -> bool:
362
+ """Check if tag is a user tag."""
363
+ user_prefix = "@user_"
364
+ return tag.startswith(user_prefix) and len(tag) > len(user_prefix)
365
+
366
+ @classmethod
367
+ def _extract_user_from_tag(cls, tag) -> str:
368
+ """Extract username from user tag."""
369
+ user_prefix = "@user_"
370
+ return tag[len(user_prefix):]
371
+
372
+ @classmethod
373
+ def _is_author_tag(cls, tag) -> bool:
374
+ """Check if tag is an author tag."""
375
+ creator_prefix = "@creator_"
376
+ return tag.startswith(creator_prefix) and len(tag) > len(creator_prefix)
377
+
378
+ @classmethod
379
+ def _process_author_tag(cls, tag, current_author):
380
+ """Process author tag and check for duplicates."""
381
+ if current_author is not None:
382
+ raise ValueError(f"Multiple author tags found: '@{current_author}' and '@{tag[1:]}'")
383
+ return tag[1:]
320
384
 
321
385
  @classmethod
322
386
  def _deserialize_title(cls, lines) -> (str, List[str]):
@@ -346,14 +410,26 @@ class Artefact(BaseModel, ABC):
346
410
  return contribution, lines
347
411
 
348
412
  @classmethod
349
- def _deserialize_description(cls, lines) -> (Optional[str], List[str]):
413
+ def _deserialize_description(cls, lines: List[str]) -> (Optional[str], List[str]):
350
414
  description_start = cls._description_starts_with()
415
+ start_index = -1
351
416
  for i, line in enumerate(lines):
352
417
  if line.startswith(description_start):
353
- description = line[len(description_start):].strip()
354
- del lines[i]
355
- return description, lines
356
- return None, lines
418
+ start_index = i
419
+ break
420
+
421
+ if start_index == -1:
422
+ return None, lines
423
+
424
+ first_line_content = lines[start_index][len(description_start):].strip()
425
+
426
+ description_lines = ([first_line_content] if first_line_content else []) + lines[start_index + 1:]
427
+
428
+ description = "\n".join(description_lines)
429
+
430
+ remaining_lines = lines[:start_index]
431
+
432
+ return (description if description else None), remaining_lines
357
433
 
358
434
  @classmethod
359
435
  def _parse_common_fields(cls, text: str) -> dict:
@@ -367,7 +443,7 @@ class Artefact(BaseModel, ABC):
367
443
  contribution, remaining_lines = cls._deserialize_contribution(remaining_lines)
368
444
  description, remaining_lines = cls._deserialize_description(remaining_lines)
369
445
 
370
- return {
446
+ fields = {
371
447
  'artefact_type': cls._artefact_type(),
372
448
  'tags': tags.get('tags', []),
373
449
  'users': tags.get('users', []),
@@ -376,6 +452,9 @@ class Artefact(BaseModel, ABC):
376
452
  'contribution': contribution,
377
453
  'description': description,
378
454
  }
455
+ if tags.get("author"):
456
+ fields["author"] = tags.get("author")
457
+ return fields
379
458
 
380
459
  @classmethod
381
460
  def deserialize(cls, text: str) -> 'Artefact':
@@ -407,6 +486,8 @@ class Artefact(BaseModel, ABC):
407
486
  tags.append(f"@{self.status}")
408
487
  for user in self.users:
409
488
  tags.append(f"@user_{user}")
489
+ if self.author:
490
+ tags.append(f"@{self.author}")
410
491
  for tag in self.tags:
411
492
  tags.append(f"@{tag}")
412
493
  return ' '.join(tags)
@@ -430,4 +511,4 @@ class Artefact(BaseModel, ABC):
430
511
  classifier=classifier,
431
512
  rule=rule
432
513
  )
433
- self.contribution = contribution
514
+ self.contribution = contribution
@@ -29,7 +29,8 @@ def _default_vision(title: str, use_default_contribution: bool) -> VisionArtefac
29
29
  our_product="<statement of primary differentiation>"
30
30
  )
31
31
  return VisionArtefact(
32
- tags=["sample_tag"],
32
+ tags=[],
33
+ author="creator_unknown",
33
34
  title=title,
34
35
  description="<further optional description to understand the vision, markdown capable text formatting>",
35
36
  intent=intent,
@@ -44,7 +45,8 @@ def _default_businessgoal(title: str, use_default_contribution: bool) -> Busines
44
45
  i_want="<something that helps me to reach my monetary goal>"
45
46
  )
46
47
  return BusinessgoalArtefact(
47
- tags=["sample_tag"],
48
+ tags=[],
49
+ author="creator_unknown",
48
50
  title=title,
49
51
  description="<further optional description to understand the businessgoal, markdown capable text formatting>",
50
52
  intent=intent,
@@ -57,7 +59,8 @@ def _default_capability(title: str, use_default_contribution: bool) -> Capabilit
57
59
  to_be_able_to="<needed capability for stakeholders that are the enablers/relevant for reaching the business goal>"
58
60
  )
59
61
  return CapabilityArtefact(
60
- tags=["sample_tag"],
62
+ tags=[],
63
+ author="creator_unknown",
61
64
  title=title,
62
65
  description="<further optional description to understand the capability, markdown capable text formatting>",
63
66
  intent=intent,
@@ -77,7 +80,8 @@ def _default_epic(title: str, use_default_contribution: bool) -> EpicArtefact:
77
80
  "<rule needed to fulfill the wanted product behavior>"
78
81
  ]
79
82
  return EpicArtefact(
80
- tags=["sample_tag"],
83
+ tags=[],
84
+ author="creator_unknown",
81
85
  title=title,
82
86
  description="<further optional description to understand the epic, markdown capable text formatting>",
83
87
  intent=intent,
@@ -98,7 +102,8 @@ def _default_userstory(title: str, use_default_contribution: bool) -> UserstoryA
98
102
  "<rule needed to fulfill the wanted product behavior>"
99
103
  ]
100
104
  return UserstoryArtefact(
101
- tags=["sample_tag"],
105
+ tags=[],
106
+ author="creator_unknown",
102
107
  title=title,
103
108
  description="<further optional description to understand the userstory, markdown capable text formatting>",
104
109
  intent=intent,
@@ -110,7 +115,8 @@ def _default_userstory(title: str, use_default_contribution: bool) -> UserstoryA
110
115
 
111
116
  def _default_example(title: str, use_default_contribution: bool) -> ExampleArtefact:
112
117
  return ExampleArtefact(
113
- tags=["sample_tag"],
118
+ tags=[],
119
+ author="creator_unknown",
114
120
  title=title,
115
121
  description="<further optional description to understand the example, markdown capable text formatting>",
116
122
  contribution=default_contribution() if use_default_contribution else None
@@ -130,7 +136,8 @@ def _default_keyfeature(title: str, use_default_contribution: bool) -> Keyfeatur
130
136
  THEN some result is to be expected
131
137
  AND some other result is to be expected>"""
132
138
  return KeyfeatureArtefact(
133
- tags=["sample_tag"],
139
+ tags=[],
140
+ author="creator_unknown",
134
141
  title=title,
135
142
  description=description,
136
143
  intent=intent,
@@ -185,7 +192,8 @@ def _default_feature(title: str, use_default_contribution: bool) -> FeatureArtef
185
192
  description = """<further optional description to understand the feature, no format defined, the example artefact is only a placeholder>"""
186
193
 
187
194
  return FeatureArtefact(
188
- tags=["sample_tag"],
195
+ tags=[],
196
+ author="creator_unknown",
189
197
  title=title,
190
198
  description=description,
191
199
  intent=intent,
@@ -214,7 +222,8 @@ def _default_issue(title: str, use_default_contribution: bool) -> IssueArtefact:
214
222
  *or optional free text description*"""
215
223
 
216
224
  return IssueArtefact(
217
- tags=["sample_tag"],
225
+ tags=[],
226
+ author="creator_unknown",
218
227
  title=title,
219
228
  description=description,
220
229
  additional_description=additional_description,
@@ -1,5 +1,5 @@
1
1
  from ara_cli.artefact_models.artefact_model import Artefact, ArtefactType, Intent
2
- from pydantic import Field, field_validator
2
+ from pydantic import Field, field_validator, model_validator
3
3
  from typing import List, Tuple, Optional
4
4
 
5
5
 
@@ -91,6 +91,15 @@ class EpicArtefact(Artefact):
91
91
  description="Rules the epic defines. It is recommended to create rules to clarify the desired outcome"
92
92
  )
93
93
 
94
+ @model_validator(mode='after')
95
+ def check_for_misplaced_rules(self) -> 'EpicArtefact':
96
+ if self.description:
97
+ desc_lines = self.description.split('\n')
98
+ for line in desc_lines:
99
+ if line.strip().startswith("Rule:"):
100
+ raise ValueError("Found 'Rule:' inside description. Rules must be defined before the 'Description:' section.")
101
+ return self
102
+
94
103
  @field_validator('artefact_type')
95
104
  def validate_artefact_type(cls, v):
96
105
  if v != ArtefactType.epic:
@@ -166,4 +175,4 @@ class EpicArtefact(Artefact):
166
175
  lines.append("")
167
176
  lines.append(description)
168
177
  lines.append("")
169
- return "\n".join(lines)
178
+ return "\n".join(lines)
@@ -301,6 +301,36 @@ class FeatureArtefact(Artefact):
301
301
  f"FeatureArtefact must have artefact_type of '{ArtefactType.feature}', not '{v}'")
302
302
  return v
303
303
 
304
+ @classmethod
305
+ def _deserialize_description(cls, lines: List[str]) -> (Optional[str], List[str]):
306
+ description_start = cls._description_starts_with()
307
+ scenario_markers = ["Scenario:", "Scenario Outline:"]
308
+
309
+ start_index = -1
310
+ for i, line in enumerate(lines):
311
+ if line.startswith(description_start):
312
+ start_index = i
313
+ break
314
+
315
+ if start_index == -1:
316
+ return None, lines
317
+
318
+ end_index = len(lines)
319
+ for i in range(start_index + 1, len(lines)):
320
+ if any(lines[i].startswith(marker) for marker in scenario_markers):
321
+ end_index = i
322
+ break
323
+
324
+ first_line_content = lines[start_index][len(description_start):].strip()
325
+
326
+ description_lines_list = [first_line_content] if first_line_content else []
327
+ description_lines_list.extend(lines[start_index+1:end_index])
328
+
329
+ description = "\n".join(description_lines_list).strip() or None
330
+
331
+ remaining_lines = lines[:start_index] + lines[end_index:]
332
+
333
+ return description, remaining_lines
304
334
 
305
335
  @classmethod
306
336
  def _title_prefix(cls) -> str:
@@ -519,4 +549,4 @@ class FeatureArtefact(Artefact):
519
549
  # or the placeholder is at the end of a line (e.g., "Then I see... __PLACEHOLDER__").
520
550
  step = step.replace(key, value)
521
551
  rehydrated_steps.append(step)
522
- return rehydrated_steps
552
+ return rehydrated_steps
@@ -1,5 +1,5 @@
1
1
  from ara_cli.artefact_models.artefact_model import Artefact, ArtefactType, Intent
2
- from pydantic import Field, field_validator
2
+ from pydantic import Field, field_validator, model_validator
3
3
  from typing import List, Tuple
4
4
 
5
5
 
@@ -92,6 +92,18 @@ class UserstoryArtefact(Artefact):
92
92
  default_factory=list,
93
93
  description="Rules the userstory defines. It is recommended to create rules to clarify the desired outcome")
94
94
 
95
+ @model_validator(mode='after')
96
+ def check_for_misplaced_content(self) -> 'UserstoryArtefact':
97
+ if self.description:
98
+ desc_lines = self.description.split('\n')
99
+ for line in desc_lines:
100
+ stripped_line = line.strip()
101
+ if stripped_line.startswith("Rule:"):
102
+ raise ValueError("Found 'Rule:' inside description. Rules must be defined before the 'Description:' section.")
103
+ if stripped_line.startswith("Estimate:"):
104
+ raise ValueError("Found 'Estimate:' inside description. Estimate must be defined before the 'Description:' section.")
105
+ return self
106
+
95
107
  @field_validator('artefact_type')
96
108
  def validate_artefact_type(cls, v):
97
109
  if v != ArtefactType.userstory:
@@ -171,7 +183,7 @@ class UserstoryArtefact(Artefact):
171
183
  rules = self._serialize_rules()
172
184
 
173
185
  lines = []
174
- if self.tags:
186
+ if tags: # Changed from self.tags to tags to include all tag types
175
187
  lines.append(tags)
176
188
  lines.append(title)
177
189
  lines.append("")
@@ -188,4 +200,4 @@ class UserstoryArtefact(Artefact):
188
200
  lines.append(description)
189
201
  lines.append("")
190
202
 
191
- return '\n'.join(lines)
203
+ return '\n'.join(lines)
ara_cli/artefact_scan.py CHANGED
@@ -25,10 +25,10 @@ def is_rule_valid(contribution, classified_artefact_info) -> bool:
25
25
  if not rule:
26
26
  return True
27
27
  parent = ArtefactReader.read_artefact(contribution.artefact_name, contribution.classifier)
28
- if not parent or not parent.rules:
28
+ if not parent:
29
29
  return True
30
30
  rules = parent.rules
31
- if rule not in rules:
31
+ if not rules or rule not in rules:
32
32
  return False
33
33
  return True
34
34
 
ara_cli/chat.py CHANGED
@@ -13,25 +13,6 @@ from ara_cli.file_loaders.binary_file_loader import BinaryFileLoader
13
13
  from ara_cli.file_loaders.text_file_loader import TextFileLoader
14
14
 
15
15
 
16
- extract_parser = argparse.ArgumentParser()
17
- extract_parser.add_argument(
18
- "-f", "--force", action="store_true", help="Force extraction"
19
- )
20
- extract_parser.add_argument(
21
- "-w",
22
- "--write",
23
- action="store_true",
24
- help="Overwrite existing files without using LLM for merging.",
25
- )
26
-
27
- load_parser = argparse.ArgumentParser()
28
- load_parser.add_argument("file_name", nargs="?", default="", help="File to load")
29
- load_parser.add_argument(
30
- "--load-images",
31
- action="store_true",
32
- help="Extract and describe images from documents",
33
- )
34
-
35
16
  extract_parser = argparse.ArgumentParser()
36
17
  extract_parser.add_argument(
37
18
  "-f", "--force", action="store_true", help="Force extraction"
@@ -763,6 +744,7 @@ Start chatting (type 'HELP'/'h' for available commands, 'QUIT'/'q' to exit chat
763
744
  return
764
745
  self.create_empty_chat_file(self.chat_name)
765
746
  self.chat_history = self.load_chat_history(self.chat_name)
747
+ self.message_buffer.clear()
766
748
  print(f"Cleared content of {self.chat_name}")
767
749
 
768
750
  @cmd2.with_category(CATEGORY_CHAT_CONTROL)
@@ -30,6 +30,11 @@ class ReadCommand(Command):
30
30
  """Execute the read command and return success status."""
31
31
  file_classifier = FileClassifier(os)
32
32
  classified_artefacts = ArtefactReader.read_artefacts()
33
+
34
+ if not self.classifier or not self.artefact_name:
35
+ self._filter_and_print(classified_artefacts, file_classifier)
36
+ return True
37
+
33
38
  artefacts = classified_artefacts.get(self.classifier, [])
34
39
  all_artefact_names = [a.title for a in artefacts]
35
40
 
@@ -62,10 +67,11 @@ class ReadCommand(Command):
62
67
  )
63
68
 
64
69
  # Apply filtering and print results
65
- filtered_artefacts = self._apply_filtering(artefacts_by_classifier)
66
- file_classifier.print_classified_files(
67
- filtered_artefacts, print_content=True
68
- )
70
+ self._filter_and_print(artefacts_by_classifier, file_classifier)
71
+ # filtered_artefacts = self._apply_filtering(artefacts_by_classifier)
72
+ # file_classifier.print_classified_files(
73
+ # filtered_artefacts, print_content=True
74
+ # )
69
75
  return True
70
76
 
71
77
  except Exception as e:
@@ -102,3 +108,10 @@ class ReadCommand(Command):
102
108
  file_path_retrieval=artefact_path_retrieval,
103
109
  tag_retrieval=artefact_tags_retrieval
104
110
  )
111
+
112
+ def _filter_and_print(self, artefacts_by_classifier, file_classifier):
113
+ """Apply list filtering and print results"""
114
+ filtered_artefacts = self._apply_filtering(artefacts_by_classifier)
115
+ file_classifier.print_classified_files(
116
+ filtered_artefacts, print_content=True
117
+ )
ara_cli/completers.py ADDED
@@ -0,0 +1,144 @@
1
+ import os
2
+ from typing import List, Optional
3
+ from pathlib import Path
4
+ import typer
5
+
6
+ from ara_cli.classifier import Classifier
7
+ from ara_cli.template_manager import SpecificationBreakdownAspects
8
+
9
+
10
+ def complete_classifier(incomplete: str) -> List[str]:
11
+ """Complete classifier names."""
12
+ classifiers = Classifier.ordered_classifiers()
13
+ return [c for c in classifiers if c.startswith(incomplete)]
14
+
15
+
16
+ def complete_aspect(incomplete: str) -> List[str]:
17
+ """Complete aspect names."""
18
+ aspects = SpecificationBreakdownAspects.VALID_ASPECTS
19
+ return [a for a in aspects if a.startswith(incomplete)]
20
+
21
+
22
+ def complete_status(incomplete: str) -> List[str]:
23
+ """Complete task status values."""
24
+ statuses = ["to-do", "in-progress", "review", "done", "closed"]
25
+ return [s for s in statuses if s.startswith(incomplete)]
26
+
27
+
28
+ def complete_template_type(incomplete: str) -> List[str]:
29
+ """Complete template type values."""
30
+ template_types = ["rules", "intention", "commands", "blueprint"]
31
+ return [t for t in template_types if t.startswith(incomplete)]
32
+
33
+
34
+ def complete_artefact_name(classifier: str) -> List[str]:
35
+ """Complete artefact names for a given classifier."""
36
+ try:
37
+ # Get the directory for the classifier
38
+ classifier_dir = f"ara/{Classifier.get_sub_directory(classifier)}"
39
+
40
+ if not os.path.exists(classifier_dir):
41
+ return []
42
+
43
+ # Find all files with the classifier extension
44
+ artefacts = []
45
+ for file in os.listdir(classifier_dir):
46
+ if file.endswith(f'.{classifier}'):
47
+ # Remove the extension to get the artefact name
48
+ name = file[:-len(f'.{classifier}')]
49
+ artefacts.append(name)
50
+
51
+ return sorted(artefacts)
52
+ except Exception:
53
+ return []
54
+
55
+
56
+ def complete_artefact_name_for_classifier(classifier: str):
57
+ """Create a completer function for artefact names of a specific classifier."""
58
+ def completer(incomplete: str) -> List[str]:
59
+ artefacts = complete_artefact_name(classifier)
60
+ return [a for a in artefacts if a.startswith(incomplete)]
61
+ return completer
62
+
63
+
64
+ def complete_chat_files(incomplete: str) -> List[str]:
65
+ """Complete chat file names (without .md extension)."""
66
+ try:
67
+ chat_files = []
68
+ current_dir = Path.cwd()
69
+
70
+ # Look for .md files in current directory
71
+ for file in current_dir.glob("*.md"):
72
+ name = file.stem
73
+ if name.startswith(incomplete):
74
+ chat_files.append(name)
75
+
76
+ return sorted(chat_files)
77
+ except Exception:
78
+ return []
79
+
80
+
81
+ # Dynamic completers that need context
82
+ class DynamicCompleters:
83
+ @staticmethod
84
+ def create_classifier_completer():
85
+ """Create a completer for classifiers."""
86
+ def completer(ctx: typer.Context, incomplete: str) -> List[str]:
87
+ return complete_classifier(incomplete)
88
+ return completer
89
+
90
+ @staticmethod
91
+ def create_aspect_completer():
92
+ """Create a completer for aspects."""
93
+ def completer(ctx: typer.Context, incomplete: str) -> List[str]:
94
+ return complete_aspect(incomplete)
95
+ return completer
96
+
97
+ @staticmethod
98
+ def create_status_completer():
99
+ """Create a completer for status values."""
100
+ def completer(ctx: typer.Context, incomplete: str) -> List[str]:
101
+ return complete_status(incomplete)
102
+ return completer
103
+
104
+ @staticmethod
105
+ def create_template_type_completer():
106
+ """Create a completer for template types."""
107
+ def completer(ctx: typer.Context, incomplete: str) -> List[str]:
108
+ return complete_template_type(incomplete)
109
+ return completer
110
+
111
+ @staticmethod
112
+ def create_artefact_name_completer():
113
+ """Create a completer for artefact names based on classifier context."""
114
+ def completer(ctx: typer.Context, incomplete: str) -> List[str]:
115
+ # Try to get classifier from context
116
+ if hasattr(ctx, 'params') and 'classifier' in ctx.params:
117
+ classifier = ctx.params['classifier']
118
+ if hasattr(classifier, 'value'):
119
+ classifier = classifier.value
120
+ artefacts = complete_artefact_name(classifier)
121
+ return [a for a in artefacts if a.startswith(incomplete)]
122
+ return []
123
+ return completer
124
+
125
+ @staticmethod
126
+ def create_parent_name_completer():
127
+ """Create a completer for parent artefact names based on parent classifier context."""
128
+ def completer(ctx: typer.Context, incomplete: str) -> List[str]:
129
+ # Try to get parent_classifier from context
130
+ if hasattr(ctx, 'params') and 'parent_classifier' in ctx.params:
131
+ parent_classifier = ctx.params['parent_classifier']
132
+ if hasattr(parent_classifier, 'value'):
133
+ parent_classifier = parent_classifier.value
134
+ artefacts = complete_artefact_name(parent_classifier)
135
+ return [a for a in artefacts if a.startswith(incomplete)]
136
+ return []
137
+ return completer
138
+
139
+ @staticmethod
140
+ def create_chat_file_completer():
141
+ """Create a completer for chat files."""
142
+ def completer(ctx: typer.Context, incomplete: str) -> List[str]:
143
+ return complete_chat_files(incomplete)
144
+ return completer
@@ -19,14 +19,14 @@ class TextFileLoader(FileLoader):
19
19
 
20
20
  if is_md_file and extract_images:
21
21
  reader = MarkdownReader(file_path)
22
- file_content = reader.read(extract_images=True)
22
+ file_content = reader.read(extract_images=True).replace('\r\n', '\n')
23
23
  else:
24
24
  # Use charset-normalizer to detect encoding
25
25
  encoded_content = from_path(file_path).best()
26
26
  if not encoded_content:
27
27
  print(f"Failed to detect encoding for {file_path}")
28
28
  return False
29
- file_content = str(encoded_content)
29
+ file_content = str(encoded_content).replace('\r\n', '\n')
30
30
 
31
31
  if block_delimiter:
32
32
  file_content = f"{block_delimiter}\n{file_content}\n{block_delimiter}"