mfcli 0.2.0__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.
- mfcli/.env.example +72 -0
- mfcli/__init__.py +0 -0
- mfcli/agents/__init__.py +0 -0
- mfcli/agents/controller/__init__.py +0 -0
- mfcli/agents/controller/agent.py +19 -0
- mfcli/agents/controller/config.yaml +27 -0
- mfcli/agents/controller/tools.py +42 -0
- mfcli/agents/tools/general.py +118 -0
- mfcli/alembic/env.py +61 -0
- mfcli/alembic/script.py.mako +28 -0
- mfcli/alembic/versions/6ccc0c7c397c_added_fields_to_pdf_parts_model.py +39 -0
- mfcli/alembic/versions/769019ef4870_added_gemini_file_path_to_pdf_part_model.py +33 -0
- mfcli/alembic/versions/7a2e3a779fdc_added_functional_block_and_component_.py +54 -0
- mfcli/alembic/versions/7d5adb2a47a7_added_pdf_parts_model.py +41 -0
- mfcli/alembic/versions/7fcb7d6a5836_init.py +167 -0
- mfcli/alembic/versions/e0f2b5765c72_added_cascade_delete_for_models_that_.py +32 -0
- mfcli/alembic.ini +147 -0
- mfcli/cli/__init__.py +0 -0
- mfcli/cli/dependencies.py +59 -0
- mfcli/cli/main.py +192 -0
- mfcli/client/__init__.py +0 -0
- mfcli/client/chroma_db.py +184 -0
- mfcli/client/docling.py +44 -0
- mfcli/client/gemini.py +252 -0
- mfcli/client/llama_parse.py +38 -0
- mfcli/client/vector_db.py +93 -0
- mfcli/constants/__init__.py +0 -0
- mfcli/constants/base_enum.py +18 -0
- mfcli/constants/directory_names.py +1 -0
- mfcli/constants/file_types.py +189 -0
- mfcli/constants/gemini.py +1 -0
- mfcli/constants/openai.py +6 -0
- mfcli/constants/pipeline_run_status.py +3 -0
- mfcli/crud/__init__.py +0 -0
- mfcli/crud/file.py +42 -0
- mfcli/crud/functional_blocks.py +26 -0
- mfcli/crud/netlist.py +18 -0
- mfcli/crud/pipeline_run.py +17 -0
- mfcli/crud/project.py +99 -0
- mfcli/digikey/__init__.py +0 -0
- mfcli/digikey/digikey.py +105 -0
- mfcli/main.py +5 -0
- mfcli/mcp/__init__.py +0 -0
- mfcli/mcp/configs/cline_mcp_settings.json +11 -0
- mfcli/mcp/configs/mfcli.mcp.json +7 -0
- mfcli/mcp/mcp_instance.py +6 -0
- mfcli/mcp/server.py +37 -0
- mfcli/mcp/state_manager.py +51 -0
- mfcli/mcp/tools/__init__.py +0 -0
- mfcli/mcp/tools/query_knowledgebase.py +108 -0
- mfcli/models/__init__.py +10 -0
- mfcli/models/base.py +10 -0
- mfcli/models/bom.py +71 -0
- mfcli/models/datasheet.py +10 -0
- mfcli/models/debug_setup.py +64 -0
- mfcli/models/file.py +43 -0
- mfcli/models/file_docket.py +94 -0
- mfcli/models/file_metadata.py +19 -0
- mfcli/models/functional_blocks.py +94 -0
- mfcli/models/llm_response.py +5 -0
- mfcli/models/mcu.py +97 -0
- mfcli/models/mcu_errata.py +26 -0
- mfcli/models/netlist.py +59 -0
- mfcli/models/pdf_parts.py +25 -0
- mfcli/models/pipeline_run.py +34 -0
- mfcli/models/project.py +27 -0
- mfcli/models/project_metadata.py +15 -0
- mfcli/pipeline/__init__.py +0 -0
- mfcli/pipeline/analysis/__init__.py +0 -0
- mfcli/pipeline/analysis/bom_netlist_mapper.py +28 -0
- mfcli/pipeline/analysis/generators/__init__.py +0 -0
- mfcli/pipeline/analysis/generators/bom/__init__.py +0 -0
- mfcli/pipeline/analysis/generators/bom/bom.py +74 -0
- mfcli/pipeline/analysis/generators/debug_setup/__init__.py +0 -0
- mfcli/pipeline/analysis/generators/debug_setup/debug_setup.py +71 -0
- mfcli/pipeline/analysis/generators/debug_setup/instructions.py +150 -0
- mfcli/pipeline/analysis/generators/functional_blocks/__init__.py +0 -0
- mfcli/pipeline/analysis/generators/functional_blocks/functional_blocks.py +93 -0
- mfcli/pipeline/analysis/generators/functional_blocks/instructions.py +34 -0
- mfcli/pipeline/analysis/generators/functional_blocks/validator.py +94 -0
- mfcli/pipeline/analysis/generators/generator.py +258 -0
- mfcli/pipeline/analysis/generators/generator_base.py +18 -0
- mfcli/pipeline/analysis/generators/mcu/__init__.py +0 -0
- mfcli/pipeline/analysis/generators/mcu/instructions.py +156 -0
- mfcli/pipeline/analysis/generators/mcu/mcu.py +84 -0
- mfcli/pipeline/analysis/generators/mcu_errata/__init__.py +1 -0
- mfcli/pipeline/analysis/generators/mcu_errata/instructions.py +77 -0
- mfcli/pipeline/analysis/generators/mcu_errata/mcu_errata.py +95 -0
- mfcli/pipeline/analysis/generators/summary/__init__.py +0 -0
- mfcli/pipeline/analysis/generators/summary/summary.py +47 -0
- mfcli/pipeline/classifier.py +93 -0
- mfcli/pipeline/data_enricher.py +15 -0
- mfcli/pipeline/extractor.py +34 -0
- mfcli/pipeline/extractors/__init__.py +0 -0
- mfcli/pipeline/extractors/pdf.py +12 -0
- mfcli/pipeline/parser.py +120 -0
- mfcli/pipeline/parsers/__init__.py +0 -0
- mfcli/pipeline/parsers/netlist/__init__.py +0 -0
- mfcli/pipeline/parsers/netlist/edif.py +93 -0
- mfcli/pipeline/parsers/netlist/kicad_legacy_net.py +326 -0
- mfcli/pipeline/parsers/netlist/kicad_spice.py +135 -0
- mfcli/pipeline/parsers/netlist/pads.py +185 -0
- mfcli/pipeline/parsers/netlist/protel.py +166 -0
- mfcli/pipeline/parsers/netlist/protel_detector.py +29 -0
- mfcli/pipeline/pipeline.py +419 -0
- mfcli/pipeline/preprocessors/__init__.py +0 -0
- mfcli/pipeline/preprocessors/user_guide.py +127 -0
- mfcli/pipeline/run_context.py +32 -0
- mfcli/pipeline/schema_mapper.py +89 -0
- mfcli/pipeline/sub_classifier.py +115 -0
- mfcli/utils/__init__.py +0 -0
- mfcli/utils/config.py +33 -0
- mfcli/utils/configurator.py +324 -0
- mfcli/utils/data_cleaner.py +82 -0
- mfcli/utils/datasheet_vectorizer.py +281 -0
- mfcli/utils/directory_manager.py +96 -0
- mfcli/utils/file_upload.py +298 -0
- mfcli/utils/files.py +16 -0
- mfcli/utils/http_requests.py +54 -0
- mfcli/utils/kb_lister.py +89 -0
- mfcli/utils/kb_remover.py +173 -0
- mfcli/utils/logger.py +28 -0
- mfcli/utils/mcp_configurator.py +311 -0
- mfcli/utils/migrations.py +18 -0
- mfcli/utils/orm.py +43 -0
- mfcli/utils/pdf_splitter.py +63 -0
- mfcli/utils/query_service.py +22 -0
- mfcli/utils/system_check.py +306 -0
- mfcli/utils/tools.py +31 -0
- mfcli/utils/vectorizer.py +28 -0
- mfcli-0.2.0.dist-info/METADATA +841 -0
- mfcli-0.2.0.dist-info/RECORD +136 -0
- mfcli-0.2.0.dist-info/WHEEL +5 -0
- mfcli-0.2.0.dist-info/entry_points.txt +3 -0
- mfcli-0.2.0.dist-info/licenses/LICENSE +21 -0
- mfcli-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"""init
|
|
2
|
+
|
|
3
|
+
Revision ID: 7fcb7d6a5836
|
|
4
|
+
Revises:
|
|
5
|
+
Create Date: 2025-12-11 22:49:37.368709
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
from typing import Sequence, Union
|
|
9
|
+
|
|
10
|
+
import sqlmodel
|
|
11
|
+
from alembic import op
|
|
12
|
+
import sqlalchemy as sa
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# revision identifiers, used by Alembic.
|
|
16
|
+
revision: str = '7fcb7d6a5836'
|
|
17
|
+
down_revision: Union[str, Sequence[str], None] = None
|
|
18
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
|
19
|
+
depends_on: Union[str, Sequence[str], None] = None
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def upgrade() -> None:
|
|
23
|
+
"""Upgrade schema."""
|
|
24
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
25
|
+
op.create_table('datasheets',
|
|
26
|
+
sa.Column('id', sa.Integer(), nullable=False),
|
|
27
|
+
sa.Column('part_number', sqlmodel.sql.sqltypes.AutoString(length=100), nullable=False),
|
|
28
|
+
sa.Column('datasheet', sqlmodel.sql.sqltypes.AutoString(length=500), nullable=False),
|
|
29
|
+
sa.PrimaryKeyConstraint('id')
|
|
30
|
+
)
|
|
31
|
+
op.create_index(op.f('ix_datasheets_datasheet'), 'datasheets', ['datasheet'], unique=False)
|
|
32
|
+
op.create_index(op.f('ix_datasheets_part_number'), 'datasheets', ['part_number'], unique=False)
|
|
33
|
+
op.create_table('projects',
|
|
34
|
+
sa.Column('id', sa.Integer(), nullable=False),
|
|
35
|
+
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(length=45), nullable=False),
|
|
36
|
+
sa.Column('index_id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
|
37
|
+
sa.Column('repo_dir', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
|
38
|
+
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
|
39
|
+
sa.PrimaryKeyConstraint('id')
|
|
40
|
+
)
|
|
41
|
+
op.create_index(op.f('ix_projects_index_id'), 'projects', ['index_id'], unique=True)
|
|
42
|
+
op.create_index(op.f('ix_projects_name'), 'projects', ['name'], unique=True)
|
|
43
|
+
op.create_index(op.f('ix_projects_repo_dir'), 'projects', ['repo_dir'], unique=True)
|
|
44
|
+
op.create_table('pipeline_runs',
|
|
45
|
+
sa.Column('id', sa.Integer(), nullable=False),
|
|
46
|
+
sa.Column('project_id', sa.Integer(), nullable=True),
|
|
47
|
+
sa.Column('status', sa.Integer(), server_default='0', nullable=False),
|
|
48
|
+
sa.Column('errors', sa.Text(), nullable=True),
|
|
49
|
+
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
|
50
|
+
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
|
51
|
+
sa.ForeignKeyConstraint(['project_id'], ['projects.id'], ondelete='CASCADE'),
|
|
52
|
+
sa.PrimaryKeyConstraint('id')
|
|
53
|
+
)
|
|
54
|
+
op.create_index(op.f('ix_pipeline_runs_project_id'), 'pipeline_runs', ['project_id'], unique=False)
|
|
55
|
+
op.create_table('files',
|
|
56
|
+
sa.Column('id', sa.Integer(), nullable=False),
|
|
57
|
+
sa.Column('pipeline_run_id', sa.Integer(), nullable=False),
|
|
58
|
+
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False),
|
|
59
|
+
sa.Column('type', sa.Integer(), nullable=False),
|
|
60
|
+
sa.Column('sub_type', sa.Integer(), nullable=True),
|
|
61
|
+
sa.Column('mime_type', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False),
|
|
62
|
+
sa.Column('md5', sqlmodel.sql.sqltypes.AutoString(length=32), nullable=False),
|
|
63
|
+
sa.Column('ext', sqlmodel.sql.sqltypes.AutoString(length=10), nullable=True),
|
|
64
|
+
sa.Column('path', sqlmodel.sql.sqltypes.AutoString(length=600), nullable=True),
|
|
65
|
+
sa.Column('gemini_file_id', sqlmodel.sql.sqltypes.AutoString(length=40), nullable=True),
|
|
66
|
+
sa.Column('is_datasheet', sa.Integer(), nullable=False),
|
|
67
|
+
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
|
68
|
+
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
|
69
|
+
sa.ForeignKeyConstraint(['pipeline_run_id'], ['pipeline_runs.id'], ondelete='CASCADE'),
|
|
70
|
+
sa.PrimaryKeyConstraint('id'),
|
|
71
|
+
sa.UniqueConstraint('md5', 'pipeline_run_id', name='uq_file_md5_pipeline_run')
|
|
72
|
+
)
|
|
73
|
+
op.create_index(op.f('ix_files_ext'), 'files', ['ext'], unique=False)
|
|
74
|
+
op.create_index(op.f('ix_files_is_datasheet'), 'files', ['is_datasheet'], unique=False)
|
|
75
|
+
op.create_index(op.f('ix_files_md5'), 'files', ['md5'], unique=False)
|
|
76
|
+
op.create_index(op.f('ix_files_name'), 'files', ['name'], unique=False)
|
|
77
|
+
op.create_index(op.f('ix_files_pipeline_run_id'), 'files', ['pipeline_run_id'], unique=False)
|
|
78
|
+
op.create_index(op.f('ix_files_sub_type'), 'files', ['sub_type'], unique=False)
|
|
79
|
+
op.create_index(op.f('ix_files_type'), 'files', ['type'], unique=False)
|
|
80
|
+
op.create_table('netlists',
|
|
81
|
+
sa.Column('id', sa.Integer(), nullable=False),
|
|
82
|
+
sa.Column('pipeline_run_id', sa.Integer(), nullable=False),
|
|
83
|
+
sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
|
84
|
+
sa.ForeignKeyConstraint(['pipeline_run_id'], ['pipeline_runs.id'], ondelete='CASCADE'),
|
|
85
|
+
sa.PrimaryKeyConstraint('id')
|
|
86
|
+
)
|
|
87
|
+
op.create_index(op.f('ix_netlists_pipeline_run_id'), 'netlists', ['pipeline_run_id'], unique=False)
|
|
88
|
+
op.create_table('bom',
|
|
89
|
+
sa.Column('id', sa.Integer(), nullable=False),
|
|
90
|
+
sa.Column('file_id', sa.Integer(), nullable=False),
|
|
91
|
+
sa.Column('reference', sqlmodel.sql.sqltypes.AutoString(length=100), nullable=False),
|
|
92
|
+
sa.Column('value', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False),
|
|
93
|
+
sa.Column('quantity', sa.Integer(), nullable=False),
|
|
94
|
+
sa.Column('description', sqlmodel.sql.sqltypes.AutoString(length=600), nullable=False),
|
|
95
|
+
sa.Column('manufacturer', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=True),
|
|
96
|
+
sa.Column('mpn', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=True),
|
|
97
|
+
sa.Column('lifecycle_status', sqlmodel.sql.sqltypes.AutoString(length=50), nullable=True),
|
|
98
|
+
sa.Column('supplier', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=True),
|
|
99
|
+
sa.Column('supplier_part', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=True),
|
|
100
|
+
sa.Column('supplier_unit_price', sa.Float(), nullable=True),
|
|
101
|
+
sa.Column('supplier_subtotal', sa.Float(), nullable=True),
|
|
102
|
+
sa.Column('revision_id', sqlmodel.sql.sqltypes.AutoString(length=50), nullable=True),
|
|
103
|
+
sa.Column('revision_state', sqlmodel.sql.sqltypes.AutoString(length=50), nullable=True),
|
|
104
|
+
sa.Column('revision_status', sqlmodel.sql.sqltypes.AutoString(length=100), nullable=True),
|
|
105
|
+
sa.Column('datasheet', sqlmodel.sql.sqltypes.AutoString(length=500), nullable=True),
|
|
106
|
+
sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
|
107
|
+
sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
|
108
|
+
sa.ForeignKeyConstraint(['file_id'], ['files.id'], ondelete='CASCADE'),
|
|
109
|
+
sa.PrimaryKeyConstraint('id')
|
|
110
|
+
)
|
|
111
|
+
op.create_index(op.f('ix_bom_file_id'), 'bom', ['file_id'], unique=False)
|
|
112
|
+
op.create_table('netlist_components',
|
|
113
|
+
sa.Column('id', sa.Integer(), nullable=False),
|
|
114
|
+
sa.Column('netlist_id', sa.Integer(), nullable=False),
|
|
115
|
+
sa.Column('ref_des', sqlmodel.sql.sqltypes.AutoString(length=100), nullable=False),
|
|
116
|
+
sa.Column('part_number', sqlmodel.sql.sqltypes.AutoString(length=255), nullable=False),
|
|
117
|
+
sa.Column('bom_entry_id', sa.Integer(), nullable=True),
|
|
118
|
+
sa.ForeignKeyConstraint(['bom_entry_id'], ['bom.id'], ondelete='CASCADE'),
|
|
119
|
+
sa.ForeignKeyConstraint(['netlist_id'], ['netlists.id'], ondelete='CASCADE'),
|
|
120
|
+
sa.PrimaryKeyConstraint('id')
|
|
121
|
+
)
|
|
122
|
+
op.create_index(op.f('ix_netlist_components_bom_entry_id'), 'netlist_components', ['bom_entry_id'], unique=False)
|
|
123
|
+
op.create_index(op.f('ix_netlist_components_netlist_id'), 'netlist_components', ['netlist_id'], unique=False)
|
|
124
|
+
op.create_index(op.f('ix_netlist_components_part_number'), 'netlist_components', ['part_number'], unique=False)
|
|
125
|
+
op.create_table('netlist_pins',
|
|
126
|
+
sa.Column('id', sa.Integer(), nullable=False),
|
|
127
|
+
sa.Column('netlist_component_id', sa.Integer(), nullable=False),
|
|
128
|
+
sa.Column('pin', sqlmodel.sql.sqltypes.AutoString(length=100), nullable=False),
|
|
129
|
+
sa.Column('net', sqlmodel.sql.sqltypes.AutoString(length=100), nullable=False),
|
|
130
|
+
sa.ForeignKeyConstraint(['netlist_component_id'], ['netlist_components.id'], ondelete='CASCADE'),
|
|
131
|
+
sa.PrimaryKeyConstraint('id')
|
|
132
|
+
)
|
|
133
|
+
op.create_index(op.f('ix_netlist_pins_netlist_component_id'), 'netlist_pins', ['netlist_component_id'], unique=False)
|
|
134
|
+
# ### end Alembic commands ###
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def downgrade() -> None:
|
|
138
|
+
"""Downgrade schema."""
|
|
139
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
140
|
+
op.drop_index(op.f('ix_netlist_pins_netlist_component_id'), table_name='netlist_pins')
|
|
141
|
+
op.drop_table('netlist_pins')
|
|
142
|
+
op.drop_index(op.f('ix_netlist_components_part_number'), table_name='netlist_components')
|
|
143
|
+
op.drop_index(op.f('ix_netlist_components_netlist_id'), table_name='netlist_components')
|
|
144
|
+
op.drop_index(op.f('ix_netlist_components_bom_entry_id'), table_name='netlist_components')
|
|
145
|
+
op.drop_table('netlist_components')
|
|
146
|
+
op.drop_index(op.f('ix_bom_file_id'), table_name='bom')
|
|
147
|
+
op.drop_table('bom')
|
|
148
|
+
op.drop_index(op.f('ix_netlists_pipeline_run_id'), table_name='netlists')
|
|
149
|
+
op.drop_table('netlists')
|
|
150
|
+
op.drop_index(op.f('ix_files_type'), table_name='files')
|
|
151
|
+
op.drop_index(op.f('ix_files_sub_type'), table_name='files')
|
|
152
|
+
op.drop_index(op.f('ix_files_pipeline_run_id'), table_name='files')
|
|
153
|
+
op.drop_index(op.f('ix_files_name'), table_name='files')
|
|
154
|
+
op.drop_index(op.f('ix_files_md5'), table_name='files')
|
|
155
|
+
op.drop_index(op.f('ix_files_is_datasheet'), table_name='files')
|
|
156
|
+
op.drop_index(op.f('ix_files_ext'), table_name='files')
|
|
157
|
+
op.drop_table('files')
|
|
158
|
+
op.drop_index(op.f('ix_pipeline_runs_project_id'), table_name='pipeline_runs')
|
|
159
|
+
op.drop_table('pipeline_runs')
|
|
160
|
+
op.drop_index(op.f('ix_projects_repo_dir'), table_name='projects')
|
|
161
|
+
op.drop_index(op.f('ix_projects_name'), table_name='projects')
|
|
162
|
+
op.drop_index(op.f('ix_projects_index_id'), table_name='projects')
|
|
163
|
+
op.drop_table('projects')
|
|
164
|
+
op.drop_index(op.f('ix_datasheets_part_number'), table_name='datasheets')
|
|
165
|
+
op.drop_index(op.f('ix_datasheets_datasheet'), table_name='datasheets')
|
|
166
|
+
op.drop_table('datasheets')
|
|
167
|
+
# ### end Alembic commands ###
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Added cascade delete for models that did not have it
|
|
2
|
+
|
|
3
|
+
Revision ID: e0f2b5765c72
|
|
4
|
+
Revises: 6ccc0c7c397c
|
|
5
|
+
Create Date: 2025-12-19 02:07:53.180832
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
from typing import Sequence, Union
|
|
9
|
+
|
|
10
|
+
from alembic import op
|
|
11
|
+
import sqlalchemy as sa
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# revision identifiers, used by Alembic.
|
|
15
|
+
revision: str = 'e0f2b5765c72'
|
|
16
|
+
down_revision: Union[str, Sequence[str], None] = '6ccc0c7c397c'
|
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
|
18
|
+
depends_on: Union[str, Sequence[str], None] = None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def upgrade() -> None:
|
|
22
|
+
"""Upgrade schema."""
|
|
23
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
24
|
+
pass
|
|
25
|
+
# ### end Alembic commands ###
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def downgrade() -> None:
|
|
29
|
+
"""Downgrade schema."""
|
|
30
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
31
|
+
pass
|
|
32
|
+
# ### end Alembic commands ###
|
mfcli/alembic.ini
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# A generic, single database configuration.
|
|
2
|
+
|
|
3
|
+
[alembic]
|
|
4
|
+
# path to migration scripts.
|
|
5
|
+
# this is typically a path given in POSIX (e.g. forward slashes)
|
|
6
|
+
# format, relative to the token %(here)s which refers to the location of this
|
|
7
|
+
# ini file
|
|
8
|
+
script_location = %(here)s/alembic
|
|
9
|
+
|
|
10
|
+
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
|
|
11
|
+
# Uncomment the line below if you want the files to be prepended with date and time
|
|
12
|
+
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
|
|
13
|
+
# for all available tokens
|
|
14
|
+
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
|
|
15
|
+
|
|
16
|
+
# sys.path path, will be prepended to sys.path if present.
|
|
17
|
+
# defaults to the current working directory. for multiple paths, the path separator
|
|
18
|
+
# is defined by "path_separator" below.
|
|
19
|
+
prepend_sys_path = .
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# timezone to use when rendering the date within the migration file
|
|
23
|
+
# as well as the filename.
|
|
24
|
+
# If specified, requires the python>=3.9 or backports.zoneinfo library and tzdata library.
|
|
25
|
+
# Any required deps can installed by adding `alembic[tz]` to the pip requirements
|
|
26
|
+
# string value is passed to ZoneInfo()
|
|
27
|
+
# leave blank for localtime
|
|
28
|
+
# timezone =
|
|
29
|
+
|
|
30
|
+
# max length of characters to apply to the "slug" field
|
|
31
|
+
# truncate_slug_length = 40
|
|
32
|
+
|
|
33
|
+
# set to 'true' to run the environment during
|
|
34
|
+
# the 'revision' command, regardless of autogenerate
|
|
35
|
+
# revision_environment = false
|
|
36
|
+
|
|
37
|
+
# set to 'true' to allow .pyc and .pyo files without
|
|
38
|
+
# a source .py file to be detected as revisions in the
|
|
39
|
+
# versions/ directory
|
|
40
|
+
# sourceless = false
|
|
41
|
+
|
|
42
|
+
# version location specification; This defaults
|
|
43
|
+
# to <script_location>/versions. When using multiple version
|
|
44
|
+
# directories, initial revisions must be specified with --version-path.
|
|
45
|
+
# The path separator used here should be the separator specified by "path_separator"
|
|
46
|
+
# below.
|
|
47
|
+
# version_locations = %(here)s/bar:%(here)s/bat:%(here)s/alembic/versions
|
|
48
|
+
|
|
49
|
+
# path_separator; This indicates what character is used to split lists of file
|
|
50
|
+
# paths, including version_locations and prepend_sys_path within configparser
|
|
51
|
+
# files such as alembic.ini.
|
|
52
|
+
# The default rendered in new alembic.ini files is "os", which uses os.pathsep
|
|
53
|
+
# to provide os-dependent path splitting.
|
|
54
|
+
#
|
|
55
|
+
# Note that in order to support legacy alembic.ini files, this default does NOT
|
|
56
|
+
# take place if path_separator is not present in alembic.ini. If this
|
|
57
|
+
# option is omitted entirely, fallback logic is as follows:
|
|
58
|
+
#
|
|
59
|
+
# 1. Parsing of the version_locations option falls back to using the legacy
|
|
60
|
+
# "version_path_separator" key, which if absent then falls back to the legacy
|
|
61
|
+
# behavior of splitting on spaces and/or commas.
|
|
62
|
+
# 2. Parsing of the prepend_sys_path option falls back to the legacy
|
|
63
|
+
# behavior of splitting on spaces, commas, or colons.
|
|
64
|
+
#
|
|
65
|
+
# Valid values for path_separator are:
|
|
66
|
+
#
|
|
67
|
+
# path_separator = :
|
|
68
|
+
# path_separator = ;
|
|
69
|
+
# path_separator = space
|
|
70
|
+
# path_separator = newline
|
|
71
|
+
#
|
|
72
|
+
# Use os.pathsep. Default configuration used for new projects.
|
|
73
|
+
path_separator = os
|
|
74
|
+
|
|
75
|
+
# set to 'true' to search source files recursively
|
|
76
|
+
# in each "version_locations" directory
|
|
77
|
+
# new in Alembic version 1.10
|
|
78
|
+
# recursive_version_locations = false
|
|
79
|
+
|
|
80
|
+
# the output encoding used when revision files
|
|
81
|
+
# are written from script.py.mako
|
|
82
|
+
# output_encoding = utf-8
|
|
83
|
+
|
|
84
|
+
# database URL. This is consumed by the user-maintained env.py script only.
|
|
85
|
+
# other means of configuring database URLs may be customized within the env.py
|
|
86
|
+
# file.
|
|
87
|
+
sqlalchemy.url = driver://user:pass@localhost/dbname
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
[post_write_hooks]
|
|
91
|
+
# post_write_hooks defines scripts or Python functions that are run
|
|
92
|
+
# on newly generated revision scripts. See the documentation for further
|
|
93
|
+
# detail and examples
|
|
94
|
+
|
|
95
|
+
# format using "black" - use the console_scripts runner, against the "black" entrypoint
|
|
96
|
+
# hooks = black
|
|
97
|
+
# black.type = console_scripts
|
|
98
|
+
# black.entrypoint = black
|
|
99
|
+
# black.options = -l 79 REVISION_SCRIPT_FILENAME
|
|
100
|
+
|
|
101
|
+
# lint with attempts to fix using "ruff" - use the module runner, against the "ruff" module
|
|
102
|
+
# hooks = ruff
|
|
103
|
+
# ruff.type = module
|
|
104
|
+
# ruff.module = ruff
|
|
105
|
+
# ruff.options = check --fix REVISION_SCRIPT_FILENAME
|
|
106
|
+
|
|
107
|
+
# Alternatively, use the exec runner to execute a binary found on your PATH
|
|
108
|
+
# hooks = ruff
|
|
109
|
+
# ruff.type = exec
|
|
110
|
+
# ruff.executable = ruff
|
|
111
|
+
# ruff.options = check --fix REVISION_SCRIPT_FILENAME
|
|
112
|
+
|
|
113
|
+
# Logging configuration. This is also consumed by the user-maintained
|
|
114
|
+
# env.py script only.
|
|
115
|
+
[loggers]
|
|
116
|
+
keys = root,sqlalchemy,alembic
|
|
117
|
+
|
|
118
|
+
[handlers]
|
|
119
|
+
keys = console
|
|
120
|
+
|
|
121
|
+
[formatters]
|
|
122
|
+
keys = generic
|
|
123
|
+
|
|
124
|
+
[logger_root]
|
|
125
|
+
level = WARNING
|
|
126
|
+
handlers = console
|
|
127
|
+
qualname =
|
|
128
|
+
|
|
129
|
+
[logger_sqlalchemy]
|
|
130
|
+
level = WARNING
|
|
131
|
+
handlers =
|
|
132
|
+
qualname = sqlalchemy.engine
|
|
133
|
+
|
|
134
|
+
[logger_alembic]
|
|
135
|
+
level = INFO
|
|
136
|
+
handlers =
|
|
137
|
+
qualname = alembic
|
|
138
|
+
|
|
139
|
+
[handler_console]
|
|
140
|
+
class = StreamHandler
|
|
141
|
+
args = (sys.stderr,)
|
|
142
|
+
level = NOTSET
|
|
143
|
+
formatter = generic
|
|
144
|
+
|
|
145
|
+
[formatter_generic]
|
|
146
|
+
format = %(levelname)-5.5s [%(name)s] %(message)s
|
|
147
|
+
datefmt = %H:%M:%S
|
mfcli/cli/__init__.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import subprocess
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from pydantic import ValidationError
|
|
6
|
+
|
|
7
|
+
from mfcli.utils.config import get_config
|
|
8
|
+
from mfcli.utils.directory_manager import app_dirs
|
|
9
|
+
from mfcli.utils.logger import get_logger
|
|
10
|
+
|
|
11
|
+
logger = get_logger(__name__)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def is_playwright_installed() -> bool:
|
|
15
|
+
try:
|
|
16
|
+
from playwright.sync_api import sync_playwright
|
|
17
|
+
with sync_playwright() as p:
|
|
18
|
+
path = p.chromium.executable_path
|
|
19
|
+
if path is None or path.strip() == "":
|
|
20
|
+
return False
|
|
21
|
+
if not os.path.exists(path):
|
|
22
|
+
return False
|
|
23
|
+
return True
|
|
24
|
+
except Exception:
|
|
25
|
+
return False
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def ensure_playwright_installed():
|
|
29
|
+
if not is_playwright_installed():
|
|
30
|
+
try:
|
|
31
|
+
subprocess.run([sys.executable, "-m", "playwright", "install"], check=True)
|
|
32
|
+
except subprocess.CalledProcessError as e:
|
|
33
|
+
logger.error("Failed to install Playwright automatically.")
|
|
34
|
+
logger.error(f"Error details: {e}")
|
|
35
|
+
logger.error("You can try installing Playwright manually by running:")
|
|
36
|
+
logger.error(" python -m playwright install")
|
|
37
|
+
logger.error("For more information, see https://playwright.dev/python/docs/intro")
|
|
38
|
+
sys.exit(1)
|
|
39
|
+
def check_dependencies():
|
|
40
|
+
env_file_path = app_dirs.env_file_path
|
|
41
|
+
logger.debug(f".env file path: {env_file_path}")
|
|
42
|
+
if os.path.exists(env_file_path) and os.access(env_file_path, os.R_OK):
|
|
43
|
+
logger.debug(f".env file found: {env_file_path}")
|
|
44
|
+
else:
|
|
45
|
+
logger.error(f".env file does not exist or cannot be read: {env_file_path}")
|
|
46
|
+
logger.error("Please add your api keys to .env using .env.example in the project folder")
|
|
47
|
+
logger.error(f".env file must be in your home directory: {env_file_path}")
|
|
48
|
+
sys.exit(1)
|
|
49
|
+
try:
|
|
50
|
+
logger.debug(f"Validating .env file: {env_file_path}")
|
|
51
|
+
get_config()
|
|
52
|
+
logger.debug(f".env file validated: {env_file_path}")
|
|
53
|
+
except ValidationError as e:
|
|
54
|
+
logger.exception(e)
|
|
55
|
+
logger.error(f".env file is not formatted properly: {env_file_path}")
|
|
56
|
+
if not is_playwright_installed():
|
|
57
|
+
logger.warning("Playwright is not installed")
|
|
58
|
+
logger.debug("Installing playwright")
|
|
59
|
+
ensure_playwright_installed()
|
mfcli/cli/main.py
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import argparse
|
|
3
|
+
import os.path
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from mfcli.cli.dependencies import check_dependencies
|
|
7
|
+
from mfcli.crud.project import init_project, read_project_config_file
|
|
8
|
+
from mfcli.models.project_metadata import ProjectConfig
|
|
9
|
+
from mfcli.utils.config import get_config
|
|
10
|
+
from mfcli.utils.data_cleaner import clean_app_data
|
|
11
|
+
from mfcli.utils.directory_manager import init_directory_structure
|
|
12
|
+
from mfcli.utils.logger import get_logger
|
|
13
|
+
from mfcli.utils.vectorizer import add_file_to_db
|
|
14
|
+
from mfcli.utils.kb_lister import print_vectorized_files
|
|
15
|
+
from mfcli.utils.kb_remover import remove_files_from_kb
|
|
16
|
+
|
|
17
|
+
# TODO: CREATE PIP PACKAGE
|
|
18
|
+
# TODO: all files go into knowledgebase
|
|
19
|
+
# TODO: HEAD FILES/REMOVE LOG OUTPUT
|
|
20
|
+
# TODO: DATASHEETS DO NOT NEED TO BE VECTORIZED TWICE
|
|
21
|
+
# TODO: IF METADATA FILE EXISTS BUT DB PROJECT DOESN'T - CREATE IT
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
cli_prog_name = "mfcli"
|
|
25
|
+
|
|
26
|
+
desc = "Multifactor AI-powered pipeline to analyze hardware engineering documents like schematics and BOMs"
|
|
27
|
+
|
|
28
|
+
logger = get_logger(__name__)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def init():
|
|
32
|
+
config = get_config()
|
|
33
|
+
os.environ["GOOGLE_API_KEY"] = config.google_api_key
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def run_web_server(port: int):
|
|
37
|
+
import uvicorn
|
|
38
|
+
from fastapi import FastAPI
|
|
39
|
+
from google.adk.cli.fast_api import get_fast_api_app
|
|
40
|
+
agent_dir = str(Path(__file__).parent.parent / "agents")
|
|
41
|
+
db_dir = Path(__file__).parent.parent.parent
|
|
42
|
+
db_url = f"sqlite:///{db_dir / "sessions.db"}"
|
|
43
|
+
app: FastAPI = get_fast_api_app(
|
|
44
|
+
agents_dir=agent_dir,
|
|
45
|
+
session_service_uri=db_url,
|
|
46
|
+
allow_origins=["*"],
|
|
47
|
+
web=True
|
|
48
|
+
)
|
|
49
|
+
uvicorn.run(
|
|
50
|
+
app,
|
|
51
|
+
host="0.0.0.0",
|
|
52
|
+
port=port,
|
|
53
|
+
reload=False
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def start_pipeline(project_config: ProjectConfig):
|
|
58
|
+
from mfcli.pipeline.pipeline import run_pipeline_with_config
|
|
59
|
+
asyncio.run(run_pipeline_with_config(project_config))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def run_cli():
|
|
63
|
+
from mfcli.utils.logger import setup_logging
|
|
64
|
+
|
|
65
|
+
setup_logging()
|
|
66
|
+
init()
|
|
67
|
+
logger.debug("Starting CLI")
|
|
68
|
+
logger.debug("Checking dependencies")
|
|
69
|
+
check_dependencies()
|
|
70
|
+
parser = argparse.ArgumentParser(
|
|
71
|
+
prog=cli_prog_name,
|
|
72
|
+
description=desc
|
|
73
|
+
)
|
|
74
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
75
|
+
init_cmd = sub.add_parser(
|
|
76
|
+
"init",
|
|
77
|
+
help="Initialize a repo containing hardware design documents"
|
|
78
|
+
)
|
|
79
|
+
init_cmd.add_argument(
|
|
80
|
+
"--name",
|
|
81
|
+
type=str,
|
|
82
|
+
default=None,
|
|
83
|
+
help="Project name (defaults to current directory name)"
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
sub.add_parser(
|
|
87
|
+
"run",
|
|
88
|
+
help="Run the analysis pipeline on the current directory"
|
|
89
|
+
)
|
|
90
|
+
web_cmd = sub.add_parser(
|
|
91
|
+
"web",
|
|
92
|
+
help="Start web UI"
|
|
93
|
+
)
|
|
94
|
+
web_cmd.add_argument("--port", type=int, default=9999)
|
|
95
|
+
|
|
96
|
+
clean_cmd = sub.add_parser(
|
|
97
|
+
"clean",
|
|
98
|
+
help="Clean all mfcli app data"
|
|
99
|
+
)
|
|
100
|
+
clean_cmd.add_argument(
|
|
101
|
+
"--accept",
|
|
102
|
+
action="store_true",
|
|
103
|
+
help="Skip confirmation prompt"
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
add_cmd = sub.add_parser(
|
|
107
|
+
"add",
|
|
108
|
+
help="Add a file to the ChromaDB database"
|
|
109
|
+
)
|
|
110
|
+
add_cmd.add_argument(
|
|
111
|
+
"file",
|
|
112
|
+
type=Path,
|
|
113
|
+
help="Path to the file to add to ChromaDB"
|
|
114
|
+
)
|
|
115
|
+
add_cmd.add_argument(
|
|
116
|
+
"--purpose",
|
|
117
|
+
type=str,
|
|
118
|
+
default="datasheet",
|
|
119
|
+
help="Purpose/category for the file (e.g., 'datasheet', 'manual', 'specification'). Default: 'datasheet'"
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
sub.add_parser(
|
|
123
|
+
"ls",
|
|
124
|
+
help="List all files that have been vectorized into the ChromaDB knowledge base"
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
rm_cmd = sub.add_parser(
|
|
128
|
+
"rm",
|
|
129
|
+
help="Remove files from the ChromaDB knowledge base by filename or partial match"
|
|
130
|
+
)
|
|
131
|
+
rm_cmd.add_argument(
|
|
132
|
+
"filename",
|
|
133
|
+
type=str,
|
|
134
|
+
help="Full or partial filename to match (case-insensitive)"
|
|
135
|
+
)
|
|
136
|
+
rm_cmd.add_argument(
|
|
137
|
+
"--yes",
|
|
138
|
+
action="store_true",
|
|
139
|
+
help="Skip confirmation prompt and delete immediately"
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
configure_cmd = sub.add_parser(
|
|
143
|
+
"configure",
|
|
144
|
+
help="Interactive setup wizard to configure API keys and settings"
|
|
145
|
+
)
|
|
146
|
+
configure_cmd.add_argument(
|
|
147
|
+
"--check",
|
|
148
|
+
action="store_true",
|
|
149
|
+
help="Check existing configuration and validate API keys"
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
sub.add_parser(
|
|
153
|
+
"setup-mcp",
|
|
154
|
+
help="Auto-configure MCP server for Cline and Claude Code"
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
sub.add_parser(
|
|
158
|
+
"doctor",
|
|
159
|
+
help="Run system health checks and diagnose issues"
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
args = parser.parse_args()
|
|
163
|
+
|
|
164
|
+
init_directory_structure(os.getcwd())
|
|
165
|
+
if args.command == "init":
|
|
166
|
+
init_project(args.name)
|
|
167
|
+
elif args.command == "clean":
|
|
168
|
+
clean_app_data(args.accept)
|
|
169
|
+
else:
|
|
170
|
+
project_config = read_project_config_file()
|
|
171
|
+
if args.command == "run":
|
|
172
|
+
start_pipeline(project_config)
|
|
173
|
+
elif args.command == "web":
|
|
174
|
+
run_web_server(args.port)
|
|
175
|
+
elif args.command == "add":
|
|
176
|
+
add_file_to_db(project_config.name, args.file, args.purpose)
|
|
177
|
+
elif args.command == "ls":
|
|
178
|
+
print_vectorized_files(project_config.name)
|
|
179
|
+
elif args.command == "rm":
|
|
180
|
+
remove_files_from_kb(project_config.name, args.filename, confirm=not args.yes)
|
|
181
|
+
elif args.command == "configure":
|
|
182
|
+
from mfcli.utils.configurator import run_configuration_wizard, check_configuration
|
|
183
|
+
if args.check:
|
|
184
|
+
check_configuration()
|
|
185
|
+
else:
|
|
186
|
+
run_configuration_wizard()
|
|
187
|
+
elif args.command == "setup-mcp":
|
|
188
|
+
from mfcli.utils.mcp_configurator import setup_mcp_servers
|
|
189
|
+
setup_mcp_servers()
|
|
190
|
+
elif args.command == "doctor":
|
|
191
|
+
from mfcli.utils.system_check import run_system_check
|
|
192
|
+
run_system_check()
|
mfcli/client/__init__.py
ADDED
|
File without changes
|