empathy-framework 4.6.2__py3-none-any.whl → 4.6.3__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.
Files changed (53) hide show
  1. {empathy_framework-4.6.2.dist-info → empathy_framework-4.6.3.dist-info}/METADATA +1 -1
  2. {empathy_framework-4.6.2.dist-info → empathy_framework-4.6.3.dist-info}/RECORD +53 -20
  3. {empathy_framework-4.6.2.dist-info → empathy_framework-4.6.3.dist-info}/WHEEL +1 -1
  4. empathy_os/__init__.py +1 -1
  5. empathy_os/cli.py +361 -32
  6. empathy_os/config/xml_config.py +8 -3
  7. empathy_os/core.py +37 -4
  8. empathy_os/leverage_points.py +2 -1
  9. empathy_os/memory/short_term.py +45 -1
  10. empathy_os/meta_workflows/agent_creator 2.py +254 -0
  11. empathy_os/meta_workflows/builtin_templates 2.py +567 -0
  12. empathy_os/meta_workflows/cli_meta_workflows 2.py +1551 -0
  13. empathy_os/meta_workflows/form_engine 2.py +304 -0
  14. empathy_os/meta_workflows/intent_detector 2.py +298 -0
  15. empathy_os/meta_workflows/pattern_learner 2.py +754 -0
  16. empathy_os/meta_workflows/session_context 2.py +398 -0
  17. empathy_os/meta_workflows/template_registry 2.py +229 -0
  18. empathy_os/meta_workflows/workflow 2.py +980 -0
  19. empathy_os/models/token_estimator.py +16 -9
  20. empathy_os/models/validation.py +7 -1
  21. empathy_os/orchestration/pattern_learner 2.py +699 -0
  22. empathy_os/orchestration/real_tools 2.py +938 -0
  23. empathy_os/orchestration/real_tools.py +4 -2
  24. empathy_os/socratic/__init__ 2.py +273 -0
  25. empathy_os/socratic/ab_testing 2.py +969 -0
  26. empathy_os/socratic/blueprint 2.py +532 -0
  27. empathy_os/socratic/cli 2.py +689 -0
  28. empathy_os/socratic/collaboration 2.py +1112 -0
  29. empathy_os/socratic/domain_templates 2.py +916 -0
  30. empathy_os/socratic/embeddings 2.py +734 -0
  31. empathy_os/socratic/engine 2.py +729 -0
  32. empathy_os/socratic/explainer 2.py +663 -0
  33. empathy_os/socratic/feedback 2.py +767 -0
  34. empathy_os/socratic/forms 2.py +624 -0
  35. empathy_os/socratic/generator 2.py +716 -0
  36. empathy_os/socratic/llm_analyzer 2.py +635 -0
  37. empathy_os/socratic/mcp_server 2.py +751 -0
  38. empathy_os/socratic/session 2.py +306 -0
  39. empathy_os/socratic/storage 2.py +635 -0
  40. empathy_os/socratic/storage.py +2 -1
  41. empathy_os/socratic/success 2.py +719 -0
  42. empathy_os/socratic/visual_editor 2.py +812 -0
  43. empathy_os/socratic/web_ui 2.py +925 -0
  44. empathy_os/tier_recommender.py +5 -2
  45. empathy_os/workflow_commands.py +11 -6
  46. empathy_os/workflows/base.py +1 -1
  47. empathy_os/workflows/batch_processing 2.py +310 -0
  48. empathy_os/workflows/release_prep_crew 2.py +968 -0
  49. empathy_os/workflows/test_coverage_boost_crew 2.py +848 -0
  50. empathy_os/workflows/test_maintenance.py +3 -2
  51. {empathy_framework-4.6.2.dist-info → empathy_framework-4.6.3.dist-info}/entry_points.txt +0 -0
  52. {empathy_framework-4.6.2.dist-info → empathy_framework-4.6.3.dist-info}/licenses/LICENSE +0 -0
  53. {empathy_framework-4.6.2.dist-info → empathy_framework-4.6.3.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,624 @@
1
+ """Socratic Forms System
2
+
3
+ Structured questionnaires with branching logic for gathering requirements.
4
+
5
+ Supports multiple field types:
6
+ - Single select (radio buttons)
7
+ - Multi-select (checkboxes)
8
+ - Text input (short answer)
9
+ - Text area (long form)
10
+ - Slider (numeric range)
11
+ - Conditional fields (appear based on previous answers)
12
+
13
+ Copyright 2026 Smart-AI-Memory
14
+ Licensed under Fair Source License 0.9
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ from collections.abc import Callable
20
+ from dataclasses import dataclass, field
21
+ from enum import Enum
22
+ from typing import Any
23
+
24
+
25
+ class FieldType(Enum):
26
+ """Types of form fields."""
27
+
28
+ # Single selection from options
29
+ SINGLE_SELECT = "single_select"
30
+
31
+ # Multiple selection from options
32
+ MULTI_SELECT = "multi_select"
33
+
34
+ # Short text input
35
+ TEXT = "text"
36
+
37
+ # Long text input
38
+ TEXT_AREA = "text_area"
39
+
40
+ # Numeric slider with range
41
+ SLIDER = "slider"
42
+
43
+ # Yes/No toggle
44
+ BOOLEAN = "boolean"
45
+
46
+ # Numeric input
47
+ NUMBER = "number"
48
+
49
+ # Grouped fields (sub-form)
50
+ GROUP = "group"
51
+
52
+
53
+ @dataclass
54
+ class FieldOption:
55
+ """An option for select-type fields."""
56
+
57
+ # Option value (stored in response)
58
+ value: str
59
+
60
+ # Display label
61
+ label: str
62
+
63
+ # Optional description/help text
64
+ description: str = ""
65
+
66
+ # Optional icon or emoji
67
+ icon: str = ""
68
+
69
+ # Whether this is the recommended option
70
+ recommended: bool = False
71
+
72
+ # Conditions that enable/disable this option
73
+ enabled_when: dict[str, Any] | None = None
74
+
75
+
76
+ @dataclass
77
+ class FieldValidation:
78
+ """Validation rules for a field."""
79
+
80
+ # Whether field is required
81
+ required: bool = False
82
+
83
+ # Minimum length (for text fields)
84
+ min_length: int | None = None
85
+
86
+ # Maximum length (for text fields)
87
+ max_length: int | None = None
88
+
89
+ # Minimum value (for numeric fields)
90
+ min_value: float | None = None
91
+
92
+ # Maximum value (for numeric fields)
93
+ max_value: float | None = None
94
+
95
+ # Regex pattern (for text fields)
96
+ pattern: str | None = None
97
+
98
+ # Custom validation function
99
+ custom_validator: Callable[[Any], tuple[bool, str]] | None = None
100
+
101
+ # Error message template
102
+ error_message: str = "Invalid value"
103
+
104
+
105
+ @dataclass
106
+ class FormField:
107
+ """A single field in a Socratic form.
108
+
109
+ Example:
110
+ >>> field = FormField(
111
+ ... id="languages",
112
+ ... field_type=FieldType.MULTI_SELECT,
113
+ ... label="What programming languages does your team use?",
114
+ ... help_text="Select all that apply",
115
+ ... options=[
116
+ ... FieldOption("python", "Python", recommended=True),
117
+ ... FieldOption("typescript", "TypeScript"),
118
+ ... FieldOption("javascript", "JavaScript"),
119
+ ... FieldOption("go", "Go"),
120
+ ... FieldOption("rust", "Rust"),
121
+ ... ],
122
+ ... validation=FieldValidation(required=True)
123
+ ... )
124
+ """
125
+
126
+ # Unique field identifier
127
+ id: str
128
+
129
+ # Type of field
130
+ field_type: FieldType
131
+
132
+ # Display label (the question)
133
+ label: str
134
+
135
+ # Help text explaining the question
136
+ help_text: str = ""
137
+
138
+ # Placeholder text for input fields
139
+ placeholder: str = ""
140
+
141
+ # Options for select fields
142
+ options: list[FieldOption] = field(default_factory=list)
143
+
144
+ # Default value
145
+ default: Any = None
146
+
147
+ # Validation rules
148
+ validation: FieldValidation = field(default_factory=FieldValidation)
149
+
150
+ # Conditions for showing this field (based on other answers)
151
+ show_when: dict[str, Any] | None = None
152
+
153
+ # Category/section this field belongs to
154
+ category: str = "general"
155
+
156
+ # Order within category
157
+ order: int = 0
158
+
159
+ # Additional metadata
160
+ metadata: dict[str, Any] = field(default_factory=dict)
161
+
162
+ def validate(self, value: Any) -> tuple[bool, str]:
163
+ """Validate a value for this field.
164
+
165
+ Args:
166
+ value: The value to validate
167
+
168
+ Returns:
169
+ Tuple of (is_valid, error_message)
170
+ """
171
+ v = self.validation
172
+
173
+ # Check required
174
+ if v.required:
175
+ if value is None:
176
+ return False, f"{self.label} is required"
177
+ if isinstance(value, str) and not value.strip():
178
+ return False, f"{self.label} is required"
179
+ if isinstance(value, list) and not value:
180
+ return False, f"Please select at least one option for {self.label}"
181
+
182
+ # Skip further validation if empty and not required
183
+ if value is None or (isinstance(value, str) and not value.strip()):
184
+ return True, ""
185
+
186
+ # Check string length
187
+ if isinstance(value, str):
188
+ if v.min_length and len(value) < v.min_length:
189
+ return False, f"Minimum {v.min_length} characters required"
190
+ if v.max_length and len(value) > v.max_length:
191
+ return False, f"Maximum {v.max_length} characters allowed"
192
+
193
+ # Check numeric range
194
+ if isinstance(value, (int, float)):
195
+ if v.min_value is not None and value < v.min_value:
196
+ return False, f"Value must be at least {v.min_value}"
197
+ if v.max_value is not None and value > v.max_value:
198
+ return False, f"Value must be at most {v.max_value}"
199
+
200
+ # Check pattern
201
+ if v.pattern and isinstance(value, str):
202
+ import re
203
+ if not re.match(v.pattern, value):
204
+ return False, v.error_message
205
+
206
+ # Custom validation
207
+ if v.custom_validator:
208
+ return v.custom_validator(value)
209
+
210
+ return True, ""
211
+
212
+ def should_show(self, current_answers: dict[str, Any]) -> bool:
213
+ """Check if this field should be shown based on current answers.
214
+
215
+ Args:
216
+ current_answers: Dictionary of field_id -> value
217
+
218
+ Returns:
219
+ True if field should be shown
220
+ """
221
+ if self.show_when is None:
222
+ return True
223
+
224
+ for field_id, expected in self.show_when.items():
225
+ actual = current_answers.get(field_id)
226
+
227
+ # Handle "any of" conditions (list of acceptable values)
228
+ if isinstance(expected, list):
229
+ if actual not in expected:
230
+ # Also check if actual is a list (multi-select)
231
+ if isinstance(actual, list):
232
+ if not any(v in expected for v in actual):
233
+ return False
234
+ else:
235
+ return False
236
+ # Handle exact match
237
+ elif actual != expected:
238
+ return False
239
+
240
+ return True
241
+
242
+
243
+ @dataclass
244
+ class Form:
245
+ """A Socratic questionnaire form.
246
+
247
+ Example:
248
+ >>> form = Form(
249
+ ... id="code_review_setup",
250
+ ... title="Code Review Configuration",
251
+ ... description="Help us understand your code review needs",
252
+ ... fields=[
253
+ ... FormField(
254
+ ... id="languages",
255
+ ... field_type=FieldType.MULTI_SELECT,
256
+ ... label="What languages?",
257
+ ... options=[...]
258
+ ... ),
259
+ ... FormField(
260
+ ... id="team_size",
261
+ ... field_type=FieldType.SLIDER,
262
+ ... label="How large is your team?",
263
+ ... validation=FieldValidation(min_value=1, max_value=100)
264
+ ... ),
265
+ ... ]
266
+ ... )
267
+ """
268
+
269
+ # Unique form identifier
270
+ id: str
271
+
272
+ # Form title
273
+ title: str
274
+
275
+ # Form description/instructions
276
+ description: str = ""
277
+
278
+ # Fields in this form
279
+ fields: list[FormField] = field(default_factory=list)
280
+
281
+ # Round number (for multi-round questioning)
282
+ round_number: int = 1
283
+
284
+ # Progress indicator (0-1)
285
+ progress: float = 0.0
286
+
287
+ # Whether this is the final form
288
+ is_final: bool = False
289
+
290
+ # Category groupings for display
291
+ categories: list[str] = field(default_factory=list)
292
+
293
+ def get_visible_fields(self, current_answers: dict[str, Any]) -> list[FormField]:
294
+ """Get fields that should be visible based on current answers.
295
+
296
+ Args:
297
+ current_answers: Dictionary of answered field values
298
+
299
+ Returns:
300
+ List of visible FormField objects
301
+ """
302
+ return [f for f in self.fields if f.should_show(current_answers)]
303
+
304
+ def get_fields_by_category(
305
+ self,
306
+ current_answers: dict[str, Any] | None = None,
307
+ ) -> dict[str, list[FormField]]:
308
+ """Get fields grouped by category.
309
+
310
+ Args:
311
+ current_answers: Optional answers for visibility filtering
312
+
313
+ Returns:
314
+ Dictionary mapping category name to list of fields
315
+ """
316
+ current_answers = current_answers or {}
317
+ result: dict[str, list[FormField]] = {}
318
+
319
+ for f in self.fields:
320
+ if f.should_show(current_answers):
321
+ if f.category not in result:
322
+ result[f.category] = []
323
+ result[f.category].append(f)
324
+
325
+ # Sort fields within each category
326
+ for category in result:
327
+ result[category].sort(key=lambda x: x.order)
328
+
329
+ return result
330
+
331
+ def to_dict(self) -> dict[str, Any]:
332
+ """Serialize form to dictionary for JSON/API response."""
333
+ return {
334
+ "id": self.id,
335
+ "title": self.title,
336
+ "description": self.description,
337
+ "round_number": self.round_number,
338
+ "progress": self.progress,
339
+ "is_final": self.is_final,
340
+ "categories": self.categories,
341
+ "fields": [
342
+ {
343
+ "id": f.id,
344
+ "type": f.field_type.value,
345
+ "label": f.label,
346
+ "help_text": f.help_text,
347
+ "placeholder": f.placeholder,
348
+ "default": f.default,
349
+ "category": f.category,
350
+ "options": [
351
+ {
352
+ "value": o.value,
353
+ "label": o.label,
354
+ "description": o.description,
355
+ "icon": o.icon,
356
+ "recommended": o.recommended,
357
+ }
358
+ for o in f.options
359
+ ] if f.options else [],
360
+ "validation": {
361
+ "required": f.validation.required,
362
+ "min_length": f.validation.min_length,
363
+ "max_length": f.validation.max_length,
364
+ "min_value": f.validation.min_value,
365
+ "max_value": f.validation.max_value,
366
+ "pattern": f.validation.pattern,
367
+ },
368
+ "show_when": f.show_when,
369
+ }
370
+ for f in self.fields
371
+ ],
372
+ }
373
+
374
+
375
+ @dataclass
376
+ class ValidationResult:
377
+ """Result of validating a form response."""
378
+
379
+ # Whether validation passed
380
+ is_valid: bool
381
+
382
+ # Field-level errors (field_id -> error message)
383
+ field_errors: dict[str, str] = field(default_factory=dict)
384
+
385
+ # Form-level errors
386
+ form_errors: list[str] = field(default_factory=list)
387
+
388
+ @property
389
+ def all_errors(self) -> list[str]:
390
+ """Get all errors as a flat list."""
391
+ errors = list(self.form_errors)
392
+ errors.extend(f"{k}: {v}" for k, v in self.field_errors.items())
393
+ return errors
394
+
395
+
396
+ @dataclass
397
+ class FormResponse:
398
+ """A user's response to a form.
399
+
400
+ Example:
401
+ >>> response = FormResponse(
402
+ ... form_id="code_review_setup",
403
+ ... answers={
404
+ ... "languages": ["python", "typescript"],
405
+ ... "team_size": 8,
406
+ ... "focus_areas": ["security", "performance"]
407
+ ... }
408
+ ... )
409
+ """
410
+
411
+ # ID of the form being responded to
412
+ form_id: str
413
+
414
+ # Answers keyed by field ID
415
+ answers: dict[str, Any] = field(default_factory=dict)
416
+
417
+ # When the response was submitted
418
+ submitted_at: str = ""
419
+
420
+ # Whether the user skipped optional questions
421
+ skipped_fields: list[str] = field(default_factory=list)
422
+
423
+ # Additional notes from user
424
+ notes: str = ""
425
+
426
+ def validate(self, form: Form) -> ValidationResult:
427
+ """Validate this response against a form.
428
+
429
+ Args:
430
+ form: The Form to validate against
431
+
432
+ Returns:
433
+ ValidationResult with any errors
434
+ """
435
+ result = ValidationResult(is_valid=True)
436
+
437
+ # Get visible fields based on current answers
438
+ visible_fields = form.get_visible_fields(self.answers)
439
+
440
+ for f in visible_fields:
441
+ value = self.answers.get(f.id)
442
+ is_valid, error = f.validate(value)
443
+
444
+ if not is_valid:
445
+ result.is_valid = False
446
+ result.field_errors[f.id] = error
447
+
448
+ return result
449
+
450
+
451
+ # =============================================================================
452
+ # FORM BUILDER HELPERS
453
+ # =============================================================================
454
+
455
+
456
+ def create_language_field(
457
+ id: str = "languages",
458
+ required: bool = True,
459
+ ) -> FormField:
460
+ """Create a standard programming language selection field."""
461
+ return FormField(
462
+ id=id,
463
+ field_type=FieldType.MULTI_SELECT,
464
+ label="What programming languages does your team primarily use?",
465
+ help_text="Select all that apply. This helps us customize analysis tools.",
466
+ options=[
467
+ FieldOption("python", "Python", icon="🐍", recommended=True),
468
+ FieldOption("typescript", "TypeScript", icon="📘"),
469
+ FieldOption("javascript", "JavaScript", icon="📒"),
470
+ FieldOption("java", "Java", icon="☕"),
471
+ FieldOption("go", "Go", icon="🐹"),
472
+ FieldOption("rust", "Rust", icon="🦀"),
473
+ FieldOption("csharp", "C#", icon="🎯"),
474
+ FieldOption("cpp", "C++", icon="⚡"),
475
+ FieldOption("ruby", "Ruby", icon="💎"),
476
+ FieldOption("php", "PHP", icon="🐘"),
477
+ FieldOption("other", "Other", icon="🔧"),
478
+ ],
479
+ validation=FieldValidation(required=required),
480
+ category="technical",
481
+ )
482
+
483
+
484
+ def create_quality_focus_field(
485
+ id: str = "quality_focus",
486
+ required: bool = True,
487
+ ) -> FormField:
488
+ """Create a quality focus area selection field."""
489
+ return FormField(
490
+ id=id,
491
+ field_type=FieldType.MULTI_SELECT,
492
+ label="What quality attributes are most important?",
493
+ help_text="Select your top priorities. We'll optimize agents for these.",
494
+ options=[
495
+ FieldOption(
496
+ "security",
497
+ "Security",
498
+ description="Vulnerability detection, secure coding practices",
499
+ icon="🔒",
500
+ ),
501
+ FieldOption(
502
+ "performance",
503
+ "Performance",
504
+ description="Speed, memory usage, scalability",
505
+ icon="⚡",
506
+ ),
507
+ FieldOption(
508
+ "maintainability",
509
+ "Maintainability",
510
+ description="Code clarity, documentation, modularity",
511
+ icon="🧩",
512
+ ),
513
+ FieldOption(
514
+ "reliability",
515
+ "Reliability",
516
+ description="Error handling, edge cases, stability",
517
+ icon="🛡️",
518
+ ),
519
+ FieldOption(
520
+ "testability",
521
+ "Testability",
522
+ description="Test coverage, test quality, mocking",
523
+ icon="🧪",
524
+ ),
525
+ ],
526
+ validation=FieldValidation(required=required),
527
+ category="quality",
528
+ )
529
+
530
+
531
+ def create_team_size_field(
532
+ id: str = "team_size",
533
+ required: bool = False,
534
+ ) -> FormField:
535
+ """Create a team size input field."""
536
+ return FormField(
537
+ id=id,
538
+ field_type=FieldType.SINGLE_SELECT,
539
+ label="How large is your development team?",
540
+ help_text="This helps us calibrate review thoroughness.",
541
+ options=[
542
+ FieldOption("solo", "Solo developer", description="Just me"),
543
+ FieldOption("small", "Small team (2-5)", description="Close collaboration"),
544
+ FieldOption("medium", "Medium team (6-15)", description="Multiple reviewers"),
545
+ FieldOption("large", "Large team (16+)", description="Formal review process"),
546
+ ],
547
+ validation=FieldValidation(required=required),
548
+ category="context",
549
+ )
550
+
551
+
552
+ def create_automation_level_field(
553
+ id: str = "automation_level",
554
+ required: bool = True,
555
+ ) -> FormField:
556
+ """Create an automation preference field."""
557
+ return FormField(
558
+ id=id,
559
+ field_type=FieldType.SINGLE_SELECT,
560
+ label="How much automation do you want?",
561
+ help_text="Higher automation means less human intervention required.",
562
+ options=[
563
+ FieldOption(
564
+ "advisory",
565
+ "Advisory Only",
566
+ description="Suggestions for humans to review and apply",
567
+ icon="💡",
568
+ ),
569
+ FieldOption(
570
+ "semi_auto",
571
+ "Semi-Automated",
572
+ description="Auto-fix simple issues, flag complex ones",
573
+ icon="⚙️",
574
+ recommended=True,
575
+ ),
576
+ FieldOption(
577
+ "fully_auto",
578
+ "Fully Automated",
579
+ description="Auto-fix everything possible, minimal human review",
580
+ icon="🤖",
581
+ ),
582
+ ],
583
+ validation=FieldValidation(required=required),
584
+ category="preferences",
585
+ )
586
+
587
+
588
+ def create_goal_text_field(
589
+ id: str = "goal",
590
+ required: bool = True,
591
+ ) -> FormField:
592
+ """Create the initial goal capture field."""
593
+ return FormField(
594
+ id=id,
595
+ field_type=FieldType.TEXT_AREA,
596
+ label="What do you want to accomplish?",
597
+ help_text=(
598
+ "Describe your goal in your own words. Be as specific as you like - "
599
+ "we'll ask clarifying questions if needed."
600
+ ),
601
+ placeholder="e.g., I want to automate code reviews to catch security issues...",
602
+ validation=FieldValidation(
603
+ required=required,
604
+ min_length=10,
605
+ max_length=2000,
606
+ ),
607
+ category="goal",
608
+ )
609
+
610
+
611
+ def create_additional_context_field(
612
+ id: str = "additional_context",
613
+ required: bool = False,
614
+ ) -> FormField:
615
+ """Create an optional additional context field."""
616
+ return FormField(
617
+ id=id,
618
+ field_type=FieldType.TEXT_AREA,
619
+ label="Anything else we should know?",
620
+ help_text="Optional: Share any additional context, constraints, or preferences.",
621
+ placeholder="e.g., We use a monorepo, have strict SLAs, prefer verbose output...",
622
+ validation=FieldValidation(max_length=1000),
623
+ category="context",
624
+ )