autocoder-nano 0.1.37__py3-none-any.whl → 0.1.38__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.
@@ -11,16 +11,13 @@ import uuid
11
11
  from autocoder_nano.agent.agentic_edit import AgenticEdit
12
12
  from autocoder_nano.agent.agentic_edit_types import AgenticEditRequest
13
13
  from autocoder_nano.chat import stream_chat_display
14
- from autocoder_nano.edit import Dispacher
14
+ from autocoder_nano.edit import coding
15
15
  from autocoder_nano.helper import show_help
16
16
  from autocoder_nano.project import project_source
17
17
  from autocoder_nano.index import (index_export, index_import, index_build,
18
18
  index_build_and_filter, extract_symbols)
19
- # from autocoder_nano.index.entry import build_index_and_filter_files
20
- # from autocoder_nano.index.index_manager import IndexManager
21
- # from autocoder_nano.index.symbols_utils import extract_symbols
19
+ from autocoder_nano.rules import rules_from_active_files, rules_from_commit_changes, get_rules_context
22
20
  from autocoder_nano.llm_client import AutoLLM
23
- from autocoder_nano.rules.rules_learn import AutoRulesLearn
24
21
  from autocoder_nano.utils.completer_utils import CommandCompleter
25
22
  from autocoder_nano.version import __version__
26
23
  from autocoder_nano.llm_types import *
@@ -29,7 +26,6 @@ from autocoder_nano.templates import create_actions
29
26
  from autocoder_nano.git_utils import (repo_init, commit_changes, revert_changes,
30
27
  get_uncommitted_changes, generate_commit_message)
31
28
  from autocoder_nano.sys_utils import default_exclude_dirs, detect_env
32
- # from autocoder_nano.project import PyProject, SuffixProject, project_source
33
29
  from autocoder_nano.utils.printer_utils import Printer
34
30
 
35
31
  import yaml
@@ -52,11 +48,12 @@ from rich.text import Text
52
48
 
53
49
  printer = Printer()
54
50
  console = printer.get_console()
55
- # console = Console()
51
+
52
+
56
53
  project_root = os.getcwd()
57
54
  base_persist_dir = os.path.join(project_root, ".auto-coder", "plugins", "chat-auto-coder")
58
- # defaut_exclude_dirs = [".git", ".svn", "node_modules", "dist", "build", "__pycache__", ".auto-coder", "actions",
59
- # ".vscode", ".idea", ".hg"]
55
+
56
+
60
57
  commands = [
61
58
  "/add_files", "/remove_files", "/list_files", "/conf", "/coding", "/chat", "/revert", "/index/query",
62
59
  "/index/build", "/exclude_dirs", "/exclude_files", "/help", "/shell", "/exit", "/mode", "/models", "/commit",
@@ -68,8 +65,6 @@ memory = {
68
65
  "current_files": {"files": [], "groups": {}},
69
66
  "conf": {
70
67
  "auto_merge": "editblock",
71
- # "current_chat_model": "",
72
- # "current_code_model": "",
73
68
  "chat_model": "",
74
69
  "code_model": "",
75
70
  },
@@ -622,14 +617,46 @@ def prepare_chat_yaml():
622
617
  return
623
618
 
624
619
 
625
- def coding(query: str, llm: AutoLLM):
620
+ def get_conversation_history() -> str:
621
+ memory_dir = os.path.join(project_root, ".auto-coder", "memory")
622
+ os.makedirs(memory_dir, exist_ok=True)
623
+ memory_file = os.path.join(memory_dir, "chat_history.json")
624
+
625
+ def error_message():
626
+ printer.print_panel(Text("未找到可应用聊天记录.", style="yellow"), title="Chat History", center=True)
627
+
628
+ if not os.path.exists(memory_file):
629
+ error_message()
630
+ return ""
631
+
632
+ with open(memory_file, "r") as f:
633
+ chat_history = json.load(f)
634
+
635
+ if not chat_history["ask_conversation"]:
636
+ error_message()
637
+ return ""
638
+
639
+ conversations = chat_history["ask_conversation"]
640
+
641
+ context = ""
642
+ context += f"下面是我们的历史对话,参考我们的历史对话从而更好的理解需求和修改代码。\n\n<history>\n"
643
+ for conv in conversations:
644
+ if conv["role"] == "user":
645
+ context += f"用户: {conv['content']}\n"
646
+ elif conv["role"] == "assistant":
647
+ context += f"你: {conv['content']}\n"
648
+ context += "</history>\n"
649
+ return context
650
+
651
+
652
+ def coding_command(query: str, llm: AutoLLM):
626
653
  is_apply = query.strip().startswith("/apply")
627
654
  if is_apply:
628
655
  query = query.replace("/apply", "", 1).strip()
656
+ is_rules = False
629
657
 
630
658
  memory["conversation"].append({"role": "user", "content": query})
631
659
  conf = memory.get("conf", {})
632
- current_files = memory["current_files"]["files"]
633
660
 
634
661
  prepare_chat_yaml() # 复制上一个序号的 yaml 文件, 生成一个新的聊天 yaml 文件
635
662
  latest_yaml_file = get_last_yaml_file(os.path.join(project_root, "actions"))
@@ -650,52 +677,14 @@ def coding(query: str, llm: AutoLLM):
650
677
  if converted_value is not None:
651
678
  yaml_config[key] = converted_value
652
679
 
653
- yaml_config["urls"] = current_files
680
+ yaml_config["urls"] = memory["current_files"]["files"]
654
681
  yaml_config["query"] = query
655
682
 
656
683
  if is_apply:
657
- memory_dir = os.path.join(project_root, ".auto-coder", "memory")
658
- os.makedirs(memory_dir, exist_ok=True)
659
- memory_file = os.path.join(memory_dir, "chat_history.json")
684
+ yaml_config["context"] += get_conversation_history()
660
685
 
661
- def error_message():
662
- printer.print_panel(
663
- Text("No chat history found to apply.", style="yellow"), title="Chat History", center=True
664
- )
665
-
666
- if not os.path.exists(memory_file):
667
- error_message()
668
- return
669
-
670
- with open(memory_file, "r") as f:
671
- chat_history = json.load(f)
672
-
673
- if not chat_history["ask_conversation"]:
674
- error_message()
675
- return
676
- conversations = chat_history["ask_conversation"]
677
-
678
- yaml_config["context"] += f"下面是我们的历史对话,参考我们的历史对话从而更好的理解需求和修改代码。\n\n<history>\n"
679
- for conv in conversations:
680
- if conv["role"] == "user":
681
- yaml_config["context"] += f"用户: {conv['content']}\n"
682
- elif conv["role"] == "assistant":
683
- yaml_config["context"] += f"你: {conv['content']}\n"
684
- yaml_config["context"] += "</history>\n"
685
-
686
- # todo:暂时注释,后续通过一个 is_rules 的参数来控制
687
- # if args.enable_rules:
688
- # rules_dir_path = os.path.join(project_root, ".auto-coder", "autocoderrules")
689
- # printer.print_text("已开启 Rules 模式", style="green")
690
- # yaml_config["context"] += f"下面是我们对代码进行深入分析,提取具有通用价值的功能模式和设计模式,可在其他需求中复用的Rules\n"
691
- # yaml_config["context"] += "你在编写代码时可以参考以下Rules\n"
692
- # yaml_config["context"] += "<rules>\n"
693
- # for rules_name in os.listdir(rules_dir_path):
694
- # printer.print_text(f"正在加载 Rules:{rules_name}", style="green")
695
- # rules_file_path = os.path.join(rules_dir_path, rules_name)
696
- # with open(rules_file_path, "r") as fp:
697
- # yaml_config["context"] += f"{fp.read()}\n"
698
- # yaml_config["context"] += "</rules>\n"
686
+ if is_rules:
687
+ yaml_config["context"] += get_rules_context()
699
688
 
700
689
  yaml_config["file"] = latest_yaml_file
701
690
  yaml_content = convert_yaml_config_to_str(yaml_config=yaml_config)
@@ -704,8 +693,7 @@ def coding(query: str, llm: AutoLLM):
704
693
  f.write(yaml_content)
705
694
  args = convert_yaml_to_config(execute_file)
706
695
 
707
- dispacher = Dispacher(args=args, llm=llm)
708
- dispacher.dispach()
696
+ coding(llm=llm, args=args)
709
697
  else:
710
698
  printer.print_text(f"创建新的 YAML 文件失败.", style="yellow")
711
699
 
@@ -1538,43 +1526,15 @@ def rules(query_args: List[str], llm: AutoLLM):
1538
1526
 
1539
1527
  if query_args[0] == "/commit":
1540
1528
  commit_id = query_args[1].strip()
1541
- auto_learn = AutoRulesLearn(llm=llm, args=args)
1542
-
1543
- try:
1544
- result = auto_learn.analyze_commit_changes(commit_id=commit_id, conversations=[])
1545
- rules_file = os.path.join(rules_dir_path, f"rules-commit-{uuid.uuid4()}.md")
1546
- with open(rules_file, "w", encoding="utf-8") as f:
1547
- f.write(result)
1548
- printer.print_text(f"代码变更[{commit_id}]生成 Rules 成功", style="green")
1549
- except Exception as e:
1550
- printer.print_text(f"代码变更[{commit_id}]生成 Rules 失败: {e}", style="red")
1529
+ rules_from_commit_changes(commit_id=commit_id, llm=llm, args=args)
1551
1530
 
1552
1531
  if query_args[0] == "/analyze":
1553
- auto_learn = AutoRulesLearn(llm=llm, args=args)
1554
-
1555
1532
  files = memory.get("current_files", {}).get("files", [])
1556
1533
  if not files:
1557
1534
  printer.print_text("当前无活跃文件用于生成 Rules", style="yellow")
1558
1535
  return
1559
1536
 
1560
- sources = SourceCodeList([])
1561
- for file in files:
1562
- try:
1563
- with open(file, "r", encoding="utf-8") as f:
1564
- source_code = f.read()
1565
- sources.sources.append(SourceCode(module_name=file, source_code=source_code))
1566
- except Exception as e:
1567
- printer.print_text(f"读取文件生成 Rules 失败: {e}", style="yellow")
1568
- continue
1569
-
1570
- try:
1571
- result = auto_learn.analyze_modules(sources=sources, conversations=[])
1572
- rules_file = os.path.join(rules_dir_path, f"rules-modules-{uuid.uuid4()}.md")
1573
- with open(rules_file, "w", encoding="utf-8") as f:
1574
- f.write(result)
1575
- printer.print_text(f"活跃文件[Files:{len(files)}]生成 Rules 成功", style="green")
1576
- except Exception as e:
1577
- printer.print_text(f"活跃文件生成 Rules 失败: {e}", style="red")
1537
+ rules_from_active_files(files=files, llm=llm, args=args)
1578
1538
 
1579
1539
  completer.refresh_files()
1580
1540
 
@@ -1765,7 +1725,7 @@ def main():
1765
1725
  if not query:
1766
1726
  printer.print_text("Please enter your request.", style="yellow")
1767
1727
  continue
1768
- coding(query=query, llm=auto_llm)
1728
+ coding_command(query=query, llm=auto_llm)
1769
1729
  elif user_input.startswith("/auto"):
1770
1730
  query = user_input[len("/auto"):].strip()
1771
1731
  if not query:
@@ -17,4 +17,12 @@ class Dispacher:
17
17
  ]
18
18
  for action in dispacher_actions:
19
19
  if action.run():
20
- return
20
+ return
21
+
22
+
23
+ def coding(llm: AutoLLM, args: AutoCoderArgs):
24
+ dispacher = Dispacher(args=args, llm=llm)
25
+ dispacher.dispach()
26
+
27
+
28
+ __all__ = ["coding"]
@@ -0,0 +1,67 @@
1
+ import os
2
+ import uuid
3
+
4
+ from autocoder_nano.llm_client import AutoLLM
5
+ from autocoder_nano.llm_types import AutoCoderArgs, SourceCodeList, SourceCode
6
+ from autocoder_nano.rules.rules_learn import AutoRulesLearn
7
+ from autocoder_nano.utils.printer_utils import Printer
8
+
9
+
10
+ printer = Printer()
11
+
12
+
13
+ def rules_from_commit_changes(commit_id: str, llm: AutoLLM, args: AutoCoderArgs):
14
+ rules_dir_path = os.path.join(args.source_dir, ".auto-coder", "autocoderrules")
15
+ auto_learn = AutoRulesLearn(llm=llm, args=args)
16
+
17
+ try:
18
+ result = auto_learn.analyze_commit_changes(commit_id=commit_id, conversations=[])
19
+ rules_file = os.path.join(rules_dir_path, f"rules-commit-{uuid.uuid4()}.md")
20
+ with open(rules_file, "w", encoding="utf-8") as f:
21
+ f.write(result)
22
+ printer.print_text(f"代码变更[{commit_id}]生成 Rules 成功", style="green")
23
+ except Exception as e:
24
+ printer.print_text(f"代码变更[{commit_id}]生成 Rules 失败: {e}", style="red")
25
+
26
+
27
+ def rules_from_active_files(files: list[str], llm: AutoLLM, args: AutoCoderArgs):
28
+ rules_dir_path = os.path.join(args.source_dir, ".auto-coder", "autocoderrules")
29
+ auto_learn = AutoRulesLearn(llm=llm, args=args)
30
+
31
+ sources = SourceCodeList([])
32
+ for file in files:
33
+ try:
34
+ with open(file, "r", encoding="utf-8") as f:
35
+ source_code = f.read()
36
+ sources.sources.append(SourceCode(module_name=file, source_code=source_code))
37
+ except Exception as e:
38
+ printer.print_text(f"读取文件生成 Rules 失败: {e}", style="yellow")
39
+ continue
40
+
41
+ try:
42
+ result = auto_learn.analyze_modules(sources=sources, conversations=[])
43
+ rules_file = os.path.join(rules_dir_path, f"rules-modules-{uuid.uuid4()}.md")
44
+ with open(rules_file, "w", encoding="utf-8") as f:
45
+ f.write(result)
46
+ printer.print_text(f"活跃文件[Files:{len(files)}]生成 Rules 成功", style="green")
47
+ except Exception as e:
48
+ printer.print_text(f"活跃文件生成 Rules 失败: {e}", style="red")
49
+
50
+
51
+ def get_rules_context(project_root):
52
+ rules_dir_path = os.path.join(project_root, ".auto-coder", "autocoderrules")
53
+ printer.print_text("已开启 Rules 模式", style="green")
54
+ context = ""
55
+ context += f"下面是我们对代码进行深入分析,提取具有通用价值的功能模式和设计模式,可在其他需求中复用的Rules\n"
56
+ context += "你在编写代码时可以参考以下Rules\n"
57
+ context += "<rules>\n"
58
+ for rules_name in os.listdir(rules_dir_path):
59
+ printer.print_text(f"正在加载 Rules:{rules_name}", style="green")
60
+ rules_file_path = os.path.join(rules_dir_path, rules_name)
61
+ with open(rules_file_path, "r") as fp:
62
+ context += f"{fp.read()}\n"
63
+ context += "</rules>\n"
64
+ return context
65
+
66
+
67
+ __all__ = ["get_rules_context", "rules_from_commit_changes", "rules_from_active_files"]
autocoder_nano/version.py CHANGED
@@ -1,3 +1,3 @@
1
- __version__ = "0.1.37"
1
+ __version__ = "0.1.38"
2
2
  __author__ = "moofs"
3
3
  __license__ = "Apache License 2.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: autocoder_nano
3
- Version: 0.1.37
3
+ Version: 0.1.38
4
4
  Summary: AutoCoder Nano
5
5
  Author: moofs
6
6
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
@@ -1,5 +1,5 @@
1
1
  autocoder_nano/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- autocoder_nano/auto_coder_nano.py,sha256=AMJiNqQyEKaU5KqEOo9EzQwQDi5K3lr4YTeuMqdqWSA,74671
2
+ autocoder_nano/auto_coder_nano.py,sha256=rTcAq-GXnGxxmN5pIQfh7siYQAFjyIlZiPLjsaUXI9U,71685
3
3
  autocoder_nano/auto_coder_nano_rag.py,sha256=9BtNZ6nC5D5SPTIuziXZOfouCBLOMNzvJMTdDPQEgO8,10436
4
4
  autocoder_nano/auto_coder_nano_ui.py,sha256=ZBskcIJMeTJY7_JipGJaee58G9fUJaOv3LV4hptLc6c,12669
5
5
  autocoder_nano/file_utils.py,sha256=iGbkbQ191nKL4aNufdexYYYQSDM1XrDC9Uxp_PIbawY,661
@@ -10,7 +10,7 @@ autocoder_nano/llm_prompt.py,sha256=ViWUfCZp0gDESAAPHBhZc2WhHiFUHIxK6a2xbFu0sjU,
10
10
  autocoder_nano/llm_types.py,sha256=T0ugeWdwejy6BJaQrAlk8Pk5qweW2xbggxzHaSpTBOg,11588
11
11
  autocoder_nano/sys_utils.py,sha256=Sn6kr5diaEkVWbYDBrtenr9zw32jVIWvsAReY7_uEd0,1638
12
12
  autocoder_nano/templates.py,sha256=fqlRtnx6HvPE4CbdnPcnLBB-flPwufwcGRpsFD3aW2c,4271
13
- autocoder_nano/version.py,sha256=zGimidx6OporaPNCY3Rm74IgiKpb8FGFXs-gXvOb2SY,79
13
+ autocoder_nano/version.py,sha256=n-gEsFbSQhkVooPpwNmF2t1Qt1jwBdkbwO_3nOzXhPA,79
14
14
  autocoder_nano/agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  autocoder_nano/agent/agent_base.py,sha256=O5Hq6VnoqrXnBE_oXZHXlbmSRdOEe28H65bJ1WhAQjg,16377
16
16
  autocoder_nano/agent/agentic_edit.py,sha256=I1HjRhMabDmtfxcCOKawUJV0wU1GNzKtof19_GNgAjU,88749
@@ -50,7 +50,7 @@ autocoder_nano/app/templates/partials/input.html,sha256=8CY3JcHaA4nPZ2Vu4ragdYZz
50
50
  autocoder_nano/app/templates/partials/message.html,sha256=HWEh_j_yJAbP7zFs6jt88BDzkP7dG6VgPUbS2MT5Ax4,1548
51
51
  autocoder_nano/chat/__init__.py,sha256=FuXp0tcnegngct9Jp8HbgwFkwnhxMirwNFHtoa_vACw,2441
52
52
  autocoder_nano/data/tokenizer.json,sha256=7Lb5_DaYlDRvBRH0B0ynXO5c1fOwbQLxujX805-OEh0,7847602
53
- autocoder_nano/edit/__init__.py,sha256=QPMuW7tBTUe0Q00gUPJEmdxWqvunqko9_dsim0ncr7c,623
53
+ autocoder_nano/edit/__init__.py,sha256=9_6am33w8U6nh1oMjWF-KmE1VmXe6UTTGd2CxSRaf5A,765
54
54
  autocoder_nano/edit/actions.py,sha256=N4qzSIE7Ifm7r6Sk-HbgWmbDqMP6jfrpByfpV7rbEo8,6480
55
55
  autocoder_nano/edit/text.py,sha256=nC7VkQYHCDdT3ULpy0DIjkFwB9suhjIxK39AEzXqbno,1150
56
56
  autocoder_nano/edit/code/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -79,7 +79,7 @@ autocoder_nano/rag/doc_storage.py,sha256=sEfX-2PsRTOk7MiwqtY3u0lzqMBwTsPXeIknkAY
79
79
  autocoder_nano/rag/long_context_rag.py,sha256=jpTfJg38pfVgL0FGFwe6nmBgQAMEAYtBw9ZLQQcFfpM,21862
80
80
  autocoder_nano/rag/token_counter.py,sha256=tHuht9huViEnpqiUVN_xUcgBOHJ0T-6dmk4IWzc_Cd0,1979
81
81
  autocoder_nano/research/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
82
- autocoder_nano/rules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
82
+ autocoder_nano/rules/__init__.py,sha256=cNglrWEQ4d-xXhbuS6CCFY6DZHRRWANmUayCNnhYOJY,2941
83
83
  autocoder_nano/rules/rules_learn.py,sha256=P65_wwZ1sBxcQPTwdb7roqmkW_bj1SJQaZMLpUkglL4,7297
84
84
  autocoder_nano/ss/__init__.py,sha256=jp9Az7c0uafZcC6qfxjyZnSnVLtgA_4UdakSOcp8osE,34
85
85
  autocoder_nano/ss/search_engine.py,sha256=4_RcxF1almJX5XlLWB7d9UXM92YDK2bOqoCrkuGg5Mc,3720
@@ -91,9 +91,9 @@ autocoder_nano/utils/config_utils.py,sha256=r5n0De4mz5sL_nj-CeT_F5TxtgWQIN5vv0Z5
91
91
  autocoder_nano/utils/formatted_log_utils.py,sha256=1d3xvZ1Bo3-I1wQOMdXpwsMX5cl2FWkmpgHGHvTPEvI,5457
92
92
  autocoder_nano/utils/printer_utils.py,sha256=6rGHihCh8DDESWs6qWqwsf3B6qaeM_CNx6crzkl9UCk,15303
93
93
  autocoder_nano/utils/shell_utils.py,sha256=llVTrOrmS1RH2ws7W69tofVtf53Kq04uh-sURphejrU,2477
94
- autocoder_nano-0.1.37.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
95
- autocoder_nano-0.1.37.dist-info/METADATA,sha256=hHgyCckA57oWf1OHZlguJgB9IMxqiolJp-6jyQ3yxvY,13591
96
- autocoder_nano-0.1.37.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
97
- autocoder_nano-0.1.37.dist-info/entry_points.txt,sha256=Dj8gGZ_AgLy8ANqr2do_DJjpsR3JMh-ztsrUXo4Vn5Q,194
98
- autocoder_nano-0.1.37.dist-info/top_level.txt,sha256=D7s34cwIs1F4EAjRRDvO_zTHtUz1Z7UVccFUNlJn7HI,15
99
- autocoder_nano-0.1.37.dist-info/RECORD,,
94
+ autocoder_nano-0.1.38.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
95
+ autocoder_nano-0.1.38.dist-info/METADATA,sha256=TMDwPdAc0EKiR8VAMbV6z8Xjs6yBnuGpzHR9Q09AmeQ,13591
96
+ autocoder_nano-0.1.38.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
97
+ autocoder_nano-0.1.38.dist-info/entry_points.txt,sha256=Dj8gGZ_AgLy8ANqr2do_DJjpsR3JMh-ztsrUXo4Vn5Q,194
98
+ autocoder_nano-0.1.38.dist-info/top_level.txt,sha256=D7s34cwIs1F4EAjRRDvO_zTHtUz1Z7UVccFUNlJn7HI,15
99
+ autocoder_nano-0.1.38.dist-info/RECORD,,