npcsh 0.3.31__py3-none-any.whl → 1.0.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.
Files changed (91) hide show
  1. npcsh/_state.py +942 -0
  2. npcsh/alicanto.py +1074 -0
  3. npcsh/guac.py +785 -0
  4. npcsh/mcp_helpers.py +357 -0
  5. npcsh/mcp_npcsh.py +822 -0
  6. npcsh/mcp_server.py +184 -0
  7. npcsh/npc.py +218 -0
  8. npcsh/npcsh.py +1161 -0
  9. npcsh/plonk.py +387 -269
  10. npcsh/pti.py +234 -0
  11. npcsh/routes.py +958 -0
  12. npcsh/spool.py +315 -0
  13. npcsh/wander.py +550 -0
  14. npcsh/yap.py +573 -0
  15. npcsh-1.0.0.dist-info/METADATA +596 -0
  16. npcsh-1.0.0.dist-info/RECORD +21 -0
  17. {npcsh-0.3.31.dist-info → npcsh-1.0.0.dist-info}/WHEEL +1 -1
  18. npcsh-1.0.0.dist-info/entry_points.txt +9 -0
  19. {npcsh-0.3.31.dist-info → npcsh-1.0.0.dist-info}/licenses/LICENSE +1 -1
  20. npcsh/audio.py +0 -210
  21. npcsh/cli.py +0 -545
  22. npcsh/command_history.py +0 -566
  23. npcsh/conversation.py +0 -291
  24. npcsh/data_models.py +0 -46
  25. npcsh/dataframes.py +0 -163
  26. npcsh/embeddings.py +0 -168
  27. npcsh/helpers.py +0 -641
  28. npcsh/image.py +0 -298
  29. npcsh/image_gen.py +0 -79
  30. npcsh/knowledge_graph.py +0 -1006
  31. npcsh/llm_funcs.py +0 -2027
  32. npcsh/load_data.py +0 -83
  33. npcsh/main.py +0 -5
  34. npcsh/model_runner.py +0 -189
  35. npcsh/npc_compiler.py +0 -2870
  36. npcsh/npc_sysenv.py +0 -383
  37. npcsh/npc_team/assembly_lines/test_pipeline.py +0 -181
  38. npcsh/npc_team/corca.npc +0 -13
  39. npcsh/npc_team/foreman.npc +0 -7
  40. npcsh/npc_team/npcsh.ctx +0 -11
  41. npcsh/npc_team/sibiji.npc +0 -4
  42. npcsh/npc_team/templates/analytics/celona.npc +0 -0
  43. npcsh/npc_team/templates/hr_support/raone.npc +0 -0
  44. npcsh/npc_team/templates/humanities/eriane.npc +0 -4
  45. npcsh/npc_team/templates/it_support/lineru.npc +0 -0
  46. npcsh/npc_team/templates/marketing/slean.npc +0 -4
  47. npcsh/npc_team/templates/philosophy/maurawa.npc +0 -0
  48. npcsh/npc_team/templates/sales/turnic.npc +0 -4
  49. npcsh/npc_team/templates/software/welxor.npc +0 -0
  50. npcsh/npc_team/tools/bash_executer.tool +0 -32
  51. npcsh/npc_team/tools/calculator.tool +0 -8
  52. npcsh/npc_team/tools/code_executor.tool +0 -16
  53. npcsh/npc_team/tools/generic_search.tool +0 -27
  54. npcsh/npc_team/tools/image_generation.tool +0 -25
  55. npcsh/npc_team/tools/local_search.tool +0 -149
  56. npcsh/npc_team/tools/npcsh_executor.tool +0 -9
  57. npcsh/npc_team/tools/screen_cap.tool +0 -27
  58. npcsh/npc_team/tools/sql_executor.tool +0 -26
  59. npcsh/response.py +0 -623
  60. npcsh/search.py +0 -248
  61. npcsh/serve.py +0 -1460
  62. npcsh/shell.py +0 -538
  63. npcsh/shell_helpers.py +0 -3529
  64. npcsh/stream.py +0 -700
  65. npcsh/video.py +0 -49
  66. npcsh-0.3.31.data/data/npcsh/npc_team/bash_executer.tool +0 -32
  67. npcsh-0.3.31.data/data/npcsh/npc_team/calculator.tool +0 -8
  68. npcsh-0.3.31.data/data/npcsh/npc_team/celona.npc +0 -0
  69. npcsh-0.3.31.data/data/npcsh/npc_team/code_executor.tool +0 -16
  70. npcsh-0.3.31.data/data/npcsh/npc_team/corca.npc +0 -13
  71. npcsh-0.3.31.data/data/npcsh/npc_team/eriane.npc +0 -4
  72. npcsh-0.3.31.data/data/npcsh/npc_team/foreman.npc +0 -7
  73. npcsh-0.3.31.data/data/npcsh/npc_team/generic_search.tool +0 -27
  74. npcsh-0.3.31.data/data/npcsh/npc_team/image_generation.tool +0 -25
  75. npcsh-0.3.31.data/data/npcsh/npc_team/lineru.npc +0 -0
  76. npcsh-0.3.31.data/data/npcsh/npc_team/local_search.tool +0 -149
  77. npcsh-0.3.31.data/data/npcsh/npc_team/maurawa.npc +0 -0
  78. npcsh-0.3.31.data/data/npcsh/npc_team/npcsh.ctx +0 -11
  79. npcsh-0.3.31.data/data/npcsh/npc_team/npcsh_executor.tool +0 -9
  80. npcsh-0.3.31.data/data/npcsh/npc_team/raone.npc +0 -0
  81. npcsh-0.3.31.data/data/npcsh/npc_team/screen_cap.tool +0 -27
  82. npcsh-0.3.31.data/data/npcsh/npc_team/sibiji.npc +0 -4
  83. npcsh-0.3.31.data/data/npcsh/npc_team/slean.npc +0 -4
  84. npcsh-0.3.31.data/data/npcsh/npc_team/sql_executor.tool +0 -26
  85. npcsh-0.3.31.data/data/npcsh/npc_team/test_pipeline.py +0 -181
  86. npcsh-0.3.31.data/data/npcsh/npc_team/turnic.npc +0 -4
  87. npcsh-0.3.31.data/data/npcsh/npc_team/welxor.npc +0 -0
  88. npcsh-0.3.31.dist-info/METADATA +0 -1853
  89. npcsh-0.3.31.dist-info/RECORD +0 -76
  90. npcsh-0.3.31.dist-info/entry_points.txt +0 -3
  91. {npcsh-0.3.31.dist-info → npcsh-1.0.0.dist-info}/top_level.txt +0 -0
npcsh/load_data.py DELETED
@@ -1,83 +0,0 @@
1
- import fitz # PyMuPDF
2
- import pandas as pd
3
- import json
4
- import io
5
- from PIL import Image
6
- import numpy as np
7
- from typing import Optional
8
-
9
-
10
- def load_csv(file_path):
11
- df = pd.read_csv(file_path)
12
- return df
13
-
14
-
15
- def load_json(file_path):
16
- with open(file_path, "r") as f:
17
- data = json.load(f)
18
- df = pd.DataFrame(data)
19
- return df
20
-
21
-
22
- def load_txt(file_path):
23
- with open(file_path, "r") as f:
24
- text = f.read()
25
- df = pd.DataFrame({"text": [text]})
26
- return df
27
-
28
-
29
- def load_excel(file_path):
30
- df = pd.read_excel(file_path)
31
- return df
32
-
33
-
34
- def load_image(file_path):
35
- img = Image.open(file_path)
36
- img_array = np.array(img)
37
- df = pd.DataFrame(
38
- {
39
- "image_array": [img_array.tobytes()],
40
- "shape": [img_array.shape],
41
- "dtype": [img_array.dtype.str],
42
- }
43
- )
44
- return df
45
-
46
-
47
- def load_pdf(file_path):
48
- pdf_document = fitz.open(file_path)
49
- texts = []
50
- images = []
51
-
52
- for page_num, page in enumerate(pdf_document):
53
- # Extract text
54
- text = page.get_text()
55
- texts.append({"page": page_num + 1, "content": text})
56
-
57
- # Extract images
58
- image_list = page.get_images(full=True)
59
- for img_index, img in enumerate(image_list):
60
- xref = img[0]
61
- base_image = pdf_document.extract_image(xref)
62
- image_bytes = base_image["image"]
63
-
64
- # Convert image to numpy array
65
- image = Image.open(io.BytesIO(image_bytes))
66
- img_array = np.array(image)
67
-
68
- images.append(
69
- {
70
- "page": page_num + 1,
71
- "index": img_index + 1,
72
- "array": img_array.tobytes(),
73
- "shape": img_array.shape,
74
- "dtype": str(img_array.dtype),
75
- }
76
- )
77
-
78
- # Create DataFrame
79
- df = pd.DataFrame(
80
- {"texts": json.dumps(texts), "images": json.dumps(images)}, index=[0]
81
- )
82
-
83
- return df
npcsh/main.py DELETED
@@ -1,5 +0,0 @@
1
- def main():
2
- print("Hello from npcsh!")
3
-
4
- if __name__ == "__main__":
5
- main()
npcsh/model_runner.py DELETED
@@ -1,189 +0,0 @@
1
- import pandas as pd
2
- import sqlite3
3
- from datetime import datetime
4
-
5
-
6
- class NPCModelRunner:
7
- def __init__(self, npc_compiler: NPCCompiler):
8
- self.compiler = npc_compiler
9
- self.sql_ops = NPCSQLOperations(npc_compiler)
10
- self.history_db = os.path.expanduser("~/npcsh_history.db")
11
- self.model_registry = {}
12
-
13
- def _init_history_db(self):
14
- with sqlite3.connect(self.history_db) as conn:
15
- conn.execute(
16
- """
17
- CREATE TABLE IF NOT EXISTS model_runs (
18
- model_name TEXT,
19
- run_timestamp DATETIME,
20
- run_status TEXT,
21
- metadata TEXT,
22
- output_preview TEXT
23
- )
24
- """
25
- )
26
-
27
- conn.execute(
28
- """
29
- CREATE TABLE IF NOT EXISTS model_dependencies (
30
- model_name TEXT,
31
- depends_on TEXT,
32
- created_at DATETIME
33
- )
34
- """
35
- )
36
-
37
- def _load_sample_data(self):
38
- # For testing purposes
39
- return pd.DataFrame(
40
- {
41
- "customer_id": range(1, 4),
42
- "feedback_text": [
43
- "Great service but expensive",
44
- "Product needs improvement",
45
- "Amazing experience overall",
46
- ],
47
- "customer_segment": ["premium", "basic", "premium"],
48
- }
49
- )
50
-
51
- def run_model(self, model_name: str, model_sql: str, sample_data=None):
52
- try:
53
- # Load or use sample data
54
- if sample_data is None:
55
- raw_data = self._load_sample_data()
56
- else:
57
- raw_data = sample_data
58
-
59
- # Register the raw data as a table
60
- self.model_registry["raw_customer_feedback"] = raw_data
61
-
62
- # Parse SQL and execute with our custom functions
63
- if "{{ ref(" in model_sql:
64
- # Handle model dependencies
65
- for dep in self._extract_dependencies(model_sql):
66
- if dep not in self.model_registry:
67
- raise ValueError(f"Dependent model {dep} not found")
68
-
69
- # Replace ref() calls with actual data
70
- model_sql = self._resolve_refs(model_sql)
71
-
72
- # Execute the model
73
- result_df = self._execute_model(model_sql)
74
-
75
- # Store in registry
76
- self.model_registry[model_name] = result_df
77
-
78
- # Log to history
79
- self._log_model_run(model_name, result_df)
80
-
81
- return result_df
82
-
83
- except Exception as e:
84
- self._log_model_run(model_name, None, status="failed", error=str(e))
85
- raise e
86
-
87
- def _execute_model(self, model_sql: str) -> pd.DataFrame:
88
- # This is a simplified version - you'd want to properly parse the SQL
89
- # For now, let's implement basic synthesize functionality
90
-
91
- if "synthesize(" in model_sql:
92
- raw_data = self.model_registry["raw_customer_feedback"]
93
- return self.sql_ops.synthesize(
94
- df=raw_data,
95
- column="feedback_text",
96
- npc="analyst",
97
- context="customer_segment",
98
- framework="satisfaction",
99
- )
100
-
101
- if "spread_and_sync(" in model_sql:
102
- input_data = self.model_registry["customer_feedback"]
103
- return self.sql_ops.spread_and_sync(
104
- df=input_data,
105
- column="feedback_analysis",
106
- npc="strategy_agent",
107
- variations=["short_term", "long_term"],
108
- sync_strategy="balanced_analysis",
109
- context=self._load_vars()["business_context"],
110
- )
111
-
112
- return pd.DataFrame() # Fallback
113
-
114
- def _log_model_run(self, model_name: str, result_df, status="success", error=None):
115
- with sqlite3.connect(self.history_db) as conn:
116
- metadata = {
117
- "status": status,
118
- "error": error,
119
- "rows_processed": len(result_df) if result_df is not None else 0,
120
- }
121
-
122
- preview = result_df.head().to_dict() if result_df is not None else None
123
-
124
- conn.execute(
125
- """INSERT INTO model_runs
126
- (model_name, run_timestamp, run_status, metadata, output_preview)
127
- VALUES (?, ?, ?, ?, ?)""",
128
- (
129
- model_name,
130
- datetime.now().isoformat(),
131
- status,
132
- json.dumps(metadata),
133
- json.dumps(preview),
134
- ),
135
- )
136
-
137
- def _load_vars(self):
138
- with open("npc_project.yml", "r") as f:
139
- return yaml.safe_load(f).get("vars", {})
140
-
141
- def _extract_dependencies(self, model_sql: str) -> List[str]:
142
- # Simple regex to extract model names from ref() calls
143
- import re
144
-
145
- refs = re.findall(r'{{\s*ref\([\'"](.+?)[\'"]\)\s*}}', model_sql)
146
- return refs
147
-
148
- def _resolve_refs(self, model_sql: str) -> str:
149
- # Replace ref() calls with actual table references
150
- import re
151
-
152
- def replace_ref(match):
153
- model_name = match.group(1)
154
- if model_name in self.model_registry:
155
- return f"model_{model_name}"
156
- raise ValueError(f"Model {model_name} not found")
157
-
158
- return re.sub(r'{{\s*ref\([\'"](.+?)[\'"]\)\s*}}', replace_ref, model_sql)
159
-
160
-
161
- # Usage example:
162
- def main():
163
- # Initialize
164
- npc_compiler = NPCCompiler("~/.npcsh/npc_team", "~/npcsh_history.db")
165
- runner = NPCModelRunner(npc_compiler)
166
-
167
- # Run first model
168
- with open("models/customer_feedback.sql", "r") as f:
169
- feedback_model = runner.run_model("customer_feedback", f.read())
170
- print("First model results:")
171
- print(feedback_model.head())
172
-
173
- # Run second model that depends on the first
174
- with open("models/customer_insights.sql", "r") as f:
175
- insights_model = runner.run_model("customer_insights", f.read())
176
- print("\nSecond model results:")
177
- print(insights_model.head())
178
-
179
- # Check history
180
- with sqlite3.connect(runner.history_db) as conn:
181
- history = pd.read_sql(
182
- "SELECT * FROM model_runs ORDER BY run_timestamp DESC", conn
183
- )
184
- print("\nModel run history:")
185
- print(history)
186
-
187
-
188
- if __name__ == "__main__":
189
- main()