code-puppy 0.0.66__tar.gz → 0.0.68__tar.gz

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 (27) hide show
  1. {code_puppy-0.0.66 → code_puppy-0.0.68}/PKG-INFO +1 -1
  2. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/command_line/meta_command_handler.py +17 -9
  3. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/config.py +12 -0
  4. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/main.py +44 -3
  5. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/models.json +11 -0
  6. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/tools/ts_code_map.py +139 -11
  7. {code_puppy-0.0.66 → code_puppy-0.0.68}/pyproject.toml +1 -1
  8. {code_puppy-0.0.66 → code_puppy-0.0.68}/.gitignore +0 -0
  9. {code_puppy-0.0.66 → code_puppy-0.0.68}/LICENSE +0 -0
  10. {code_puppy-0.0.66 → code_puppy-0.0.68}/README.md +0 -0
  11. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/__init__.py +0 -0
  12. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/agent.py +0 -0
  13. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/agent_prompts.py +0 -0
  14. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/command_line/__init__.py +0 -0
  15. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/command_line/file_path_completion.py +0 -0
  16. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/command_line/model_picker_completion.py +0 -0
  17. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/command_line/prompt_toolkit_completion.py +0 -0
  18. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/command_line/utils.py +0 -0
  19. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/model_factory.py +0 -0
  20. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/session_memory.py +0 -0
  21. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/tools/__init__.py +0 -0
  22. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/tools/command_runner.py +0 -0
  23. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/tools/common.py +0 -0
  24. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/tools/file_modifications.py +0 -0
  25. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/tools/file_operations.py +0 -0
  26. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/tools/web_search.py +0 -0
  27. {code_puppy-0.0.66 → code_puppy-0.0.68}/code_puppy/version_checker.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: code-puppy
3
- Version: 0.0.66
3
+ Version: 0.0.68
4
4
  Summary: Code generation agent
5
5
  Author: Michael Pfaffenberger
6
6
  License: MIT
@@ -15,11 +15,15 @@ META_COMMANDS_HELP = """
15
15
  ~cd [dir] Change directory or show directories
16
16
  ~codemap [dir] Show code structure for [dir]
17
17
  ~m <model> Set active model
18
- ~show Show puppy status info
18
+ ~motd Show the latest message of the day (MOTD)
19
+ ~show Show puppy config key-values
20
+ ~set Set puppy config key-values
19
21
  ~<unknown> Show unknown meta command warning
20
22
  """
21
23
 
22
24
 
25
+ from code_puppy.command_line.motd import print_motd
26
+
23
27
  def handle_meta_command(command: str, console: Console) -> bool:
24
28
  """
25
29
  Handle meta/config commands prefixed with '~'.
@@ -27,6 +31,10 @@ def handle_meta_command(command: str, console: Console) -> bool:
27
31
  """
28
32
  command = command.strip()
29
33
 
34
+ if command.strip().startswith("~motd"):
35
+ print_motd(console, force=True)
36
+ return True
37
+
30
38
  # ~codemap (code structure visualization)
31
39
  if command.startswith("~codemap"):
32
40
  from code_puppy.tools.ts_code_map import make_code_map
@@ -67,20 +75,20 @@ def handle_meta_command(command: str, console: Console) -> bool:
67
75
 
68
76
  if command.strip().startswith("~show"):
69
77
  from code_puppy.command_line.model_picker_completion import get_active_model
70
- from code_puppy.config import get_owner_name, get_puppy_name
71
-
78
+ from code_puppy.config import get_owner_name, get_puppy_name, get_yolo_mode, get_message_history_limit
72
79
  puppy_name = get_puppy_name()
73
80
  owner_name = get_owner_name()
74
81
  model = get_active_model()
75
- from code_puppy.config import get_yolo_mode
76
-
77
82
  yolo_mode = get_yolo_mode()
78
- console.print(f"""[bold magenta]🐶 Puppy Status[/bold magenta]
79
- \n[bold]puppy_name:[/bold] [cyan]{puppy_name}[/cyan]
83
+ msg_limit = get_message_history_limit()
84
+ console.print(f'''[bold magenta]🐶 Puppy Status[/bold magenta]
85
+
86
+ [bold]puppy_name:[/bold] [cyan]{puppy_name}[/cyan]
80
87
  [bold]owner_name:[/bold] [cyan]{owner_name}[/cyan]
81
88
  [bold]model:[/bold] [green]{model}[/green]
82
- [bold]YOLO_MODE:[/bold] {"[red]ON[/red]" if yolo_mode else "[yellow]off[/yellow]"}
83
- """)
89
+ [bold]YOLO_MODE:[/bold] {'[red]ON[/red]' if yolo_mode else '[yellow]off[/yellow]'}
90
+ [bold]message_history_limit:[/bold] Keeping last [cyan]{msg_limit}[/cyan] messages in context
91
+ ''')
84
92
  return True
85
93
 
86
94
  if command.startswith("~set"):
@@ -57,6 +57,18 @@ def get_owner_name():
57
57
  return get_value("owner_name") or "Master"
58
58
 
59
59
 
60
+ def get_message_history_limit():
61
+ """
62
+ Returns the user-configured message truncation limit (for remembering context),
63
+ or 40 if unset or misconfigured.
64
+ Configurable by 'message_history_limit' key.
65
+ """
66
+ val = get_value("message_history_limit")
67
+ try:
68
+ return max(1, int(val)) if val else 40
69
+ except (ValueError, TypeError):
70
+ return 40
71
+
60
72
  # --- CONFIG SETTER STARTS HERE ---
61
73
  def get_config_keys():
62
74
  """
@@ -4,6 +4,7 @@ import os
4
4
  import sys
5
5
 
6
6
  from dotenv import load_dotenv
7
+ from pydantic_ai.messages import ToolCallPart, ToolReturnPart
7
8
  from rich.console import Console, ConsoleOptions, RenderResult
8
9
  from rich.markdown import CodeBlock, Markdown
9
10
  from rich.syntax import Syntax
@@ -111,6 +112,12 @@ async def interactive_mode(history_file_path: str) -> None:
111
112
  from code_puppy.command_line.meta_command_handler import META_COMMANDS_HELP
112
113
 
113
114
  console.print(META_COMMANDS_HELP)
115
+ # Show MOTD if user hasn't seen it after an update
116
+ try:
117
+ from code_puppy.command_line.motd import print_motd
118
+ print_motd(console, force=False)
119
+ except Exception as e:
120
+ console.print(f'[yellow]MOTD error: {e}[/yellow]')
114
121
 
115
122
  # Check if prompt_toolkit is installed
116
123
  try:
@@ -224,10 +231,44 @@ async def interactive_mode(history_file_path: str) -> None:
224
231
  for m in new_msgs
225
232
  if not (isinstance(m, dict) and m.get("role") == "system")
226
233
  ]
227
- # 2. Append to existing history and keep only the most recent 40
234
+ # 2. Append to existing history and keep only the most recent set by config
235
+ from code_puppy.config import get_message_history_limit
228
236
  message_history.extend(filtered)
229
- if len(message_history) > 40:
230
- message_history = message_history[-40:]
237
+
238
+ # --- BEGIN GROUP-AWARE TRUNCATION LOGIC ---
239
+ limit = get_message_history_limit()
240
+ if len(message_history) > limit:
241
+ def group_by_tool_call_id(msgs):
242
+ grouped = {}
243
+ no_group = []
244
+ for m in msgs:
245
+ # Find all tool_call_id in message parts
246
+ tool_call_ids = set()
247
+ for part in getattr(m, 'parts', []):
248
+ if hasattr(part, 'tool_call_id') and part.tool_call_id:
249
+ tool_call_ids.add(part.tool_call_id)
250
+ if tool_call_ids:
251
+ for tcid in tool_call_ids:
252
+ grouped.setdefault(tcid, []).append(m)
253
+ else:
254
+ no_group.append(m)
255
+ return grouped, no_group
256
+
257
+ grouped, no_group = group_by_tool_call_id(message_history)
258
+ # Flatten into groups or singletons
259
+ grouped_msgs = list(grouped.values()) + [[m] for m in no_group]
260
+ # Flattened history (latest groups/singletons last, trunc to N messages total),
261
+ # but always keep complete tool_call_id groups together
262
+ truncated = []
263
+ count = 0
264
+ for group in reversed(grouped_msgs):
265
+ if count + len(group) > limit:
266
+ break
267
+ truncated[:0] = group # insert at front
268
+ count += len(group)
269
+ message_history = truncated
270
+ # --- END GROUP-AWARE TRUNCATION LOGIC ---
271
+
231
272
 
232
273
  if agent_response and agent_response.awaiting_user_input:
233
274
  console.print(
@@ -15,6 +15,10 @@
15
15
  "type": "openai",
16
16
  "name": "gpt-4.1-nano"
17
17
  },
18
+ "o3": {
19
+ "type": "openai",
20
+ "name": "o3"
21
+ },
18
22
  "gpt-4.1-custom": {
19
23
  "type": "custom_openai",
20
24
  "name": "gpt-4.1-custom",
@@ -55,5 +59,12 @@
55
59
  "api_version": "2024-12-01-preview",
56
60
  "api_key": "$AZURE_OPENAI_API_KEY",
57
61
  "azure_endpoint": "$AZURE_OPENAI_ENDPOINT"
62
+ },
63
+ "Llama-4-Scout-17B-16E-Instruct": {
64
+ "type": "azure_openai",
65
+ "name": "Llama-4-Scout-17B-16E-Instruct",
66
+ "api_version": "2024-12-01-preview",
67
+ "api_key": "$AZURE_OPENAI_API_KEY",
68
+ "azure_endpoint": "$AZURE_OPENAI_ENDPOINT"
58
69
  }
59
70
  }
@@ -266,6 +266,19 @@ LANGS = {
266
266
  "struct_definition": partial(_f("struct {name}"), style="magenta"),
267
267
  },
268
268
  },
269
+ # ──────── markup / style ─────────────────────────────────────────
270
+ ".html": {
271
+ "lang": "html",
272
+ "name_field": None,
273
+ "nodes": {
274
+ # rely on parser presence; generic element handling not needed for tests
275
+ },
276
+ },
277
+ ".css": {
278
+ "lang": "css",
279
+ "name_field": None,
280
+ "nodes": {},
281
+ },
269
282
  # ───────── scripting (shell / infra) ─────────────────────────────
270
283
  ".sh": {
271
284
  "lang": "bash",
@@ -281,7 +294,37 @@ LANGS = {
281
294
  },
282
295
  }
283
296
 
284
- # Cache parsers so we don’t re-create them file-after-file
297
+ # ---------------------------------------------------------------------------
298
+ # Emoji helpers (cute! 🐶)
299
+ # ---------------------------------------------------------------------------
300
+
301
+ _NODE_EMOJIS = {
302
+ "function": "🦴",
303
+ "class": "🏠",
304
+ "struct": "🏗️",
305
+ "interface": "🎛️",
306
+ "trait": "💎",
307
+ "type": "🧩",
308
+ "object": "📦",
309
+ "export": "📤",
310
+ }
311
+
312
+ _FILE_EMOJIS = {
313
+ ".py": "🐍",
314
+ ".js": "✨",
315
+ ".jsx": "✨",
316
+ ".ts": "🌀",
317
+ ".tsx": "🌀",
318
+ ".rb": "💎",
319
+ ".go": "🐹",
320
+ ".rs": "🦀",
321
+ ".java": "☕️",
322
+ ".c": "🔧",
323
+ ".cpp": "➕",
324
+ ".hpp": "➕",
325
+ ".swift": "🕊️",
326
+ ".kt": "🤖",
327
+ }
285
328
  _PARSER_CACHE = {}
286
329
 
287
330
 
@@ -313,6 +356,55 @@ def _span(node):
313
356
  return Text(f" [{start_line}:{end_line}]", style="bold white")
314
357
 
315
358
 
359
+ def _emoji_for_node_type(ts_type: str) -> str:
360
+ """Return a cute emoji for a given Tree-sitter node type (best-effort)."""
361
+ # naive mapping based on substrings – keeps it simple
362
+ if "function" in ts_type or "method" in ts_type or ts_type.startswith("fn_"):
363
+ return _NODE_EMOJIS["function"]
364
+ if "class" in ts_type:
365
+ return _NODE_EMOJIS["class"]
366
+ if "struct" in ts_type:
367
+ return _NODE_EMOJIS["struct"]
368
+ if "interface" in ts_type:
369
+ return _NODE_EMOJIS["interface"]
370
+ if "trait" in ts_type:
371
+ return _NODE_EMOJIS["trait"]
372
+ if "type_spec" in ts_type or "type_declaration" in ts_type:
373
+ return _NODE_EMOJIS["type"]
374
+ if "object" in ts_type:
375
+ return _NODE_EMOJIS["object"]
376
+ if ts_type.startswith("export"):
377
+ return _NODE_EMOJIS["export"]
378
+ return ""
379
+
380
+
381
+ # ----------------------------------------------------------------------
382
+ # traversal (clean)
383
+ # ----------------------------------------------------------------------
384
+
385
+
386
+ def _walk_fix(ts_node, rich_parent, info):
387
+ """Recursive traversal adding child nodes with emoji labels."""
388
+ nodes_cfg = info["nodes"]
389
+ name_field = info["name_field"]
390
+
391
+ for child in ts_node.children:
392
+ n_type = child.type
393
+ if n_type in nodes_cfg:
394
+ style = nodes_cfg[n_type].keywords["style"]
395
+ ident = child.child_by_field_name(name_field) if name_field else _first_identifier(child)
396
+ label_text = ident.text.decode() if ident else "<anon>"
397
+ label = nodes_cfg[n_type].func(label_text)
398
+ emoji = _emoji_for_node_type(n_type)
399
+ if emoji:
400
+ label = f"{emoji} {label}"
401
+ branch = rich_parent.add(Text(label, style=style) + _span(child))
402
+ _walk_fix(child, branch, info)
403
+ else:
404
+ _walk_fix(child, rich_parent, info)
405
+ # ----------------------------------------------------------------------
406
+
407
+
316
408
  def _walk(ts_node, rich_parent, info):
317
409
  nodes_cfg = info["nodes"]
318
410
  name_field = info["name_field"]
@@ -329,6 +421,9 @@ def _walk(ts_node, rich_parent, info):
329
421
 
330
422
  label_text = ident.text.decode() if ident else "<anon>"
331
423
  label = nodes_cfg[t].func(label_text)
424
+ emoji = _emoji_for_node_type(t)
425
+ if emoji:
426
+ label = f"{emoji} {label}"
332
427
  branch = rich_parent.add(Text(label, style=style) + _span(child))
333
428
  _walk(child, branch, info)
334
429
  else:
@@ -345,35 +440,68 @@ def map_code_file(filepath):
345
440
  parser = parser_for(info["lang"])
346
441
  tree = parser.parse(code)
347
442
 
348
- root_label = Path(filepath).name
443
+ file_emoji = _FILE_EMOJIS.get(ext, "📄")
444
+ root_label = f"{file_emoji} {Path(filepath).name}"
349
445
  base = RichTree(Text(root_label, style="bold cyan"))
350
446
 
351
447
  if tree.root_node.has_error:
352
448
  base.add(Text("⚠️ syntax error", style="bold red"))
353
449
 
354
- _walk(tree.root_node, base, info)
450
+ _walk_fix(tree.root_node, base, info)
355
451
  return base
356
452
 
357
453
 
358
454
  def make_code_map(directory: str, ignore_tests: bool = True) -> str:
455
+ """Generate a Rich-rendered code map including directory hierarchy.
456
+
457
+ Args:
458
+ directory: Root directory to scan.
459
+ ignore_tests: Whether to skip files with 'test' in the name.
460
+
461
+ Returns:
462
+ Plain-text rendering of the generated Rich tree (last 1k chars).
463
+ """
464
+ # Create root of tree representing starting directory
359
465
  base_tree = RichTree(Text(Path(directory).name, style="bold magenta"))
360
466
 
467
+ # Cache to ensure we reuse RichTree nodes per directory path
468
+ dir_nodes: dict[str, RichTree] = {Path(directory).resolve(): base_tree} # key=abs path
469
+
361
470
  for root, dirs, files in os.walk(directory):
471
+ # ignore dot-folders early
362
472
  dirs[:] = [d for d in dirs if not d.startswith(".")]
473
+
474
+ abs_root = Path(root).resolve()
475
+
476
+ # Ensure current directory has a node; create if coming from parent
477
+ if abs_root not in dir_nodes and abs_root != Path(directory).resolve():
478
+ rel_parts = abs_root.relative_to(directory).parts
479
+ parent_path = Path(directory).resolve()
480
+ for part in rel_parts: # walk down creating nodes as needed
481
+ parent_node = dir_nodes[parent_path]
482
+ current_path = parent_path / part
483
+ if current_path not in dir_nodes:
484
+ dir_label = Text(part, style="bold magenta")
485
+ dir_node = parent_node.add(dir_label)
486
+ dir_nodes[current_path] = dir_node
487
+ parent_path = current_path
488
+
489
+ current_node = dir_nodes.get(abs_root, base_tree)
490
+
363
491
  for f in files:
364
- if (
365
- should_ignore_path(os.path.join(root, f))
366
- or ignore_tests
367
- and "test" in f
368
- ):
492
+ file_path = os.path.join(root, f)
493
+ if should_ignore_path(file_path):
494
+ continue
495
+ if ignore_tests and "test" in f:
369
496
  continue
370
497
  try:
371
- file_tree = map_code_file(os.path.join(root, f))
498
+ file_tree = map_code_file(file_path)
372
499
  if file_tree is not None:
373
- base_tree.add(file_tree)
500
+ current_node.add(file_tree)
374
501
  except Exception:
375
- base_tree.add(Text(f"[error reading {f}]", style="bold red"))
502
+ current_node.add(Text(f"[error reading {f}]", style="bold red"))
376
503
 
504
+ # Render and return last 1000 characters
377
505
  buf = Console(record=True, width=120)
378
506
  buf.print(base_tree)
379
507
  return buf.export_text()[-1000:]
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "code-puppy"
7
- version = "0.0.66"
7
+ version = "0.0.68"
8
8
  description = "Code generation agent"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
File without changes
File without changes
File without changes