jarvis-ai-assistant 0.1.180__py3-none-any.whl → 0.1.182__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.

Potentially problematic release.


This version of jarvis-ai-assistant might be problematic. Click here for more details.

jarvis/jarvis_dev/main.py CHANGED
@@ -38,9 +38,8 @@ PM_PROMPT = f"""
38
38
  <step>
39
39
  ### 1. 需求接收与分析
40
40
  1. 接收用户需求,使用ask_user工具澄清不明确点
41
- 2. 使用ask_codebase分析现有系统状态
42
- 3. 使用search_web研究相关领域知识
43
- 4. 使用file_operation记录需求文档
41
+ 2. 使用search_web研究相关领域知识
42
+ 3. 使用file_operation记录需求文档
44
43
  </step>
45
44
 
46
45
  <step>
@@ -118,7 +117,6 @@ PM_PROMPT = f"""
118
117
  - **search_web**:研究相关领域知识,寻找最佳实践
119
118
  - **execute_script**:监控项目状态,执行自动化任务
120
119
  - **methodology**:采用适当的项目方法论和最佳实践
121
- - **ask_codebase**:分析代码库,了解系统实现和技术债务
122
120
  </tools>
123
121
 
124
122
  <message_template>
@@ -205,9 +203,8 @@ BA_PROMPT = f"""
205
203
  ### 1. 需求接收与分析
206
204
  1. 接收PM的需求任务
207
205
  2. 使用ask_user工具澄清不明确点
208
- 3. 使用ask_codebase分析现有系统状态
209
- 4. 使用search_web研究相关领域知识
210
- 5. 使用file_operation记录需求文档
206
+ 3. 使用search_web研究相关领域知识
207
+ 4. 使用file_operation记录需求文档
211
208
  </step>
212
209
 
213
210
  <step>
@@ -252,7 +249,6 @@ BA_PROMPT = f"""
252
249
  - **ask_user**:获取用户需求和反馈,澄清不明确的需求点
253
250
  - **file_operation**:创建和管理需求文档,跟踪需求状态
254
251
  - **search_web**:研究相关领域知识,寻找最佳实践
255
- - **ask_codebase**:分析代码库,了解系统实现和业务逻辑
256
252
  </tools>
257
253
 
258
254
  <message_template>
@@ -340,64 +336,57 @@ SA_PROMPT = f"""
340
336
  <step>
341
337
  ### 1. 需求分析与理解
342
338
  1. 接收PM分配的架构设计任务
343
- 2. 使用ask_codebase分析现有系统架构
344
- 3. 使用read_code深入理解关键代码
345
- 4. 使用search_web研究技术趋势
346
- 5. 使用file_operation记录需求理解
339
+ 2. 使用read_code深入理解关键代码
340
+ 3. 使用search_web研究技术趋势
341
+ 4. 使用file_operation记录需求理解
347
342
  </step>
348
343
 
349
344
  <step>
350
345
  ### 2. 架构设计规划
351
346
  1. 使用methodology选择架构设计方法
352
- 2. 使用ask_codebase分析技术约束
353
- 3. 使用execute_script检查系统环境
354
- 4. 使用search_web研究架构模式
355
- 5. 使用file_operation记录设计规划
347
+ 2. 使用execute_script检查系统环境
348
+ 3. 使用search_web研究架构模式
349
+ 4. 使用file_operation记录设计规划
356
350
  </step>
357
351
 
358
352
  <step>
359
353
  ### 3. 系统架构设计
360
354
  1. 设计系统整体架构
361
355
  2. 使用file_operation记录架构文档
362
- 3. 使用ask_codebase验证架构可行性
363
- 4. 使用search_web研究技术选型
364
- 5. 使用file_operation更新架构设计
356
+ 3. 使用search_web研究技术选型
357
+ 4. 使用file_operation更新架构设计
365
358
  </step>
366
359
 
367
360
  <step>
368
361
  ### 4. 组件设计
369
362
  1. 设计系统组件和模块
370
363
  2. 使用file_operation记录组件规格
371
- 3. 使用ask_codebase分析组件依赖
372
- 4. 使用execute_script验证组件接口
373
- 5. 使用file_operation更新组件设计
364
+ 3. 使用execute_script验证组件接口
365
+ 4. 使用file_operation更新组件设计
374
366
  </step>
375
367
 
376
368
  <step>
377
369
  ### 5. 接口设计
378
370
  1. 设计系统接口和API
379
371
  2. 使用file_operation记录接口文档
380
- 3. 使用ask_codebase分析接口实现
381
- 4. 使用search_web研究接口规范
382
- 5. 使用file_operation更新接口设计
372
+ 3. 使用search_web研究接口规范
373
+ 4. 使用file_operation更新接口设计
383
374
  </step>
384
375
 
385
376
  <step>
386
377
  ### 6. 数据模型设计
387
378
  1. 设计系统数据模型
388
379
  2. 使用file_operation记录数据模型
389
- 3. 使用ask_codebase分析数据流
390
- 4. 使用execute_script验证数据约束
391
- 5. 使用file_operation更新数据模型
380
+ 3. 使用execute_script验证数据约束
381
+ 4. 使用file_operation更新数据模型
392
382
  </step>
393
383
 
394
384
  <step>
395
385
  ### 7. 架构验证与交付
396
- 1. 使用ask_codebase验证架构完整性
397
- 2. 使用file_operation整理架构文档
398
- 3. 使用execute_script生成架构报告
399
- 4. 向PM提交架构设计结果
400
- 5. 使用file_operation归档架构文档
386
+ 1. 使用file_operation整理架构文档
387
+ 2. 使用execute_script生成架构报告
388
+ 3. 向PM提交架构设计结果
389
+ 4. 使用file_operation归档架构文档
401
390
  </step>
402
391
  </workflow>
403
392
 
@@ -405,7 +394,6 @@ SA_PROMPT = f"""
405
394
  ## 工具使用指南
406
395
  - **file_operation**:创建和管理架构文档和技术规格
407
396
  - **search_web**:研究架构模式和技术趋势
408
- - **ask_codebase**:分析代码库,理解系统实现
409
397
  - **execute_script**:检查系统环境和依赖关系
410
398
  - **read_code**:阅读和理解关键代码段
411
399
  - **methodology**:应用架构设计方法论和模式
@@ -497,46 +485,40 @@ TL_PROMPT = f"""
497
485
  <step>
498
486
  ### 1. 架构理解与规划
499
487
  1. 接收PM分配的技术实施任务
500
- 2. 使用ask_codebase分析架构设计
501
- 3. 使用lsp_get_diagnostics检查代码问题
502
- 4. 使用execute_script验证技术环境
503
- 5. 使用file_operation记录技术规划
488
+ 2. 使用lsp_get_diagnostics检查代码问题
489
+ 3. 使用execute_script验证技术环境
490
+ 4. 使用file_operation记录技术规划
504
491
  </step>
505
492
 
506
493
  <step>
507
494
  ### 2. 技术方案制定
508
495
  1. 使用methodology选择开发方法
509
- 2. 使用ask_codebase分析实现路径
510
- 3. 使用ask_codebase评估技术债务
511
- 4. 使用execute_script验证技术方案
512
- 5. 使用file_operation记录技术方案
496
+ 2. 使用execute_script验证技术方案
497
+ 3. 使用file_operation记录技术方案
513
498
  </step>
514
499
 
515
500
  <step>
516
501
  ### 3. 开发规范制定
517
502
  1. 制定代码规范和标准
518
503
  2. 使用file_operation记录开发规范
519
- 3. 使用ask_codebase分析现有规范
520
- 4. 使用execute_script验证规范执行
521
- 5. 使用file_operation更新开发规范
504
+ 3. 使用execute_script验证规范执行
505
+ 4. 使用file_operation更新开发规范
522
506
  </step>
523
507
 
524
508
  <step>
525
509
  ### 4. 任务分解与分配
526
510
  1. 分解技术任务为可执行单元
527
511
  2. 使用file_operation记录任务分解
528
- 3. 使用ask_codebase分析任务依赖
529
- 4. 使用execute_script验证任务划分
530
- 5. 使用file_operation更新任务分配
512
+ 3. 使用execute_script验证任务划分
513
+ 4. 使用file_operation更新任务分配
531
514
  </step>
532
515
 
533
516
  <step>
534
517
  ### 5. 技术指导与支持
535
518
  1. 向DEV提供技术指导
536
519
  2. 使用file_operation记录指导内容
537
- 3. 使用ask_codebase分析技术问题
538
- 4. 使用lsp_get_diagnostics检查代码质量
539
- 5. 使用file_operation更新技术文档
520
+ 3. 使用lsp_get_diagnostics检查代码质量
521
+ 4. 使用file_operation更新技术文档
540
522
  </step>
541
523
 
542
524
  <step>
@@ -550,18 +532,16 @@ TL_PROMPT = f"""
550
532
 
551
533
  <step>
552
534
  ### 7. 技术总结与交付
553
- 1. 使用ask_codebase验证技术实现
554
- 2. 使用file_operation整理技术文档
555
- 3. 使用execute_script生成技术报告
556
- 4. 向PM提交技术实施结果
557
- 5. 使用file_operation归档技术文档
535
+ 1. 使用file_operation整理技术文档
536
+ 2. 使用execute_script生成技术报告
537
+ 3. 向PM提交技术实施结果
538
+ 4. 使用file_operation归档技术文档
558
539
  </step>
559
540
  </workflow>
560
541
 
561
542
  <tools>
562
543
  ## 工具使用指南
563
544
  - **file_operation**:管理技术文档和指导文件
564
- - **ask_codebase**:分析代码库,理解实现细节
565
545
  - **execute_script**:执行开发工具和命令
566
546
  - **methodology**:应用开发方法论和最佳实践
567
547
  </tools>
@@ -651,28 +631,25 @@ DEV_PROMPT = f"""
651
631
  <step>
652
632
  ### 1. 任务理解与分析
653
633
  1. 接收TL分配的开发任务
654
- 2. 使用ask_codebase分析相关代码
655
- 3. 使用read_code理解现有实现
656
- 4. 使用execute_script验证开发环境
657
- 5. 使用file_operation记录任务分析
634
+ 2. 使用read_code理解现有实现
635
+ 3. 使用execute_script验证开发环境
636
+ 4. 使用file_operation记录任务分析
658
637
  </step>
659
638
 
660
639
  <step>
661
640
  ### 2. 技术方案设计
662
641
  1. 分析实现方案
663
642
  2. 使用file_operation记录设计方案
664
- 3. 使用ask_codebase验证方案可行性
665
- 4. 使用execute_script验证技术选型
666
- 5. 使用file_operation更新技术方案
643
+ 3. 使用execute_script验证技术选型
644
+ 4. 使用file_operation更新技术方案
667
645
  </step>
668
646
 
669
647
  <step>
670
648
  ### 3. 代码实现
671
649
  1. 使用create_code_agent生成代码
672
650
  2. 使用file_operation记录代码实现
673
- 3. 使用ask_codebase分析代码质量
674
- 4. 使用execute_script验证代码功能
675
- 5. 使用file_operation更新代码文档
651
+ 3. 使用execute_script验证代码功能
652
+ 4. 使用file_operation更新代码文档
676
653
  </step>
677
654
 
678
655
  <step>
@@ -680,17 +657,15 @@ DEV_PROMPT = f"""
680
657
  1. 编写单元测试代码
681
658
  2. 使用file_operation记录测试用例
682
659
  3. 使用execute_script运行单元测试
683
- 4. 使用ask_codebase分析测试覆盖
684
- 5. 使用file_operation更新测试文档
660
+ 4. 使用file_operation更新测试文档
685
661
  </step>
686
662
 
687
663
  <step>
688
664
  ### 5. 代码优化与重构
689
665
  1. 优化代码实现
690
666
  2. 使用file_operation记录优化方案
691
- 3. 使用ask_codebase分析性能问题
692
- 4. 使用execute_script验证优化效果
693
- 5. 使用file_operation更新优化文档
667
+ 3. 使用execute_script验证优化效果
668
+ 4. 使用file_operation更新优化文档
694
669
  </step>
695
670
 
696
671
  <step>
@@ -704,11 +679,10 @@ DEV_PROMPT = f"""
704
679
 
705
680
  <step>
706
681
  ### 7. 代码提交与交付
707
- 1. 使用ask_codebase验证代码完整性
708
- 2. 使用file_operation整理代码文档
709
- 3. 使用execute_script生成提交报告
710
- 4. 向TL提交代码实现结果
711
- 5. 使用file_operation归档开发文档
682
+ 1. 使用file_operation整理代码文档
683
+ 2. 使用execute_script生成提交报告
684
+ 3. 向TL提交代码实现结果
685
+ 4. 使用file_operation归档开发文档
712
686
  </step>
713
687
  </workflow>
714
688
 
@@ -716,7 +690,6 @@ DEV_PROMPT = f"""
716
690
  ## 工具使用指南
717
691
  - **create_code_agent**:创建专业代码开发代理
718
692
  - **file_operation**:管理源代码和配置文件
719
- - **ask_codebase**:了解代码库实现细节
720
693
  - **execute_script**:执行开发命令和测试脚本
721
694
  - **read_code**:阅读和理解关键代码段
722
695
  - **create_sub_agent**:创建专门的子代理处理特定任务
@@ -832,37 +805,33 @@ QA_PROMPT = f"""
832
805
  <step>
833
806
  ### 1. 测试需求分析
834
807
  1. 接收PM分配的测试任务
835
- 2. 使用ask_codebase分析测试范围
836
- 3. 使用read_code理解功能实现
837
- 4. 使用execute_script验证测试环境
838
- 5. 使用file_operation记录测试需求
808
+ 2. 使用read_code理解功能实现
809
+ 3. 使用execute_script验证测试环境
810
+ 4. 使用file_operation记录测试需求
839
811
  </step>
840
812
 
841
813
  <step>
842
814
  ### 2. 测试计划制定
843
815
  1. 使用methodology选择测试方法
844
816
  2. 使用file_operation记录测试计划
845
- 3. 使用ask_codebase分析测试重点
846
- 4. 使用execute_script验证测试工具
847
- 5. 使用file_operation更新测试计划
817
+ 3. 使用execute_script验证测试工具
818
+ 4. 使用file_operation更新测试计划
848
819
  </step>
849
820
 
850
821
  <step>
851
822
  ### 3. 测试用例设计
852
823
  1. 设计测试用例
853
824
  2. 使用file_operation记录测试用例
854
- 3. 使用ask_codebase分析测试覆盖
855
- 4. 使用execute_script验证测试用例
856
- 5. 使用file_operation更新测试用例
825
+ 3. 使用execute_script验证测试用例
826
+ 4. 使用file_operation更新测试用例
857
827
  </step>
858
828
 
859
829
  <step>
860
830
  ### 4. 测试环境准备
861
831
  1. 配置测试环境
862
832
  2. 使用file_operation记录环境配置
863
- 3. 使用ask_codebase分析环境需求
864
- 4. 使用execute_script验证环境配置
865
- 5. 使用file_operation更新环境文档
833
+ 3. 使用execute_script验证环境配置
834
+ 4. 使用file_operation更新环境文档
866
835
  </step>
867
836
 
868
837
  <step>
@@ -878,18 +847,16 @@ QA_PROMPT = f"""
878
847
  ### 6. 缺陷管理
879
848
  1. 分析缺陷
880
849
  2. 使用file_operation记录缺陷信息
881
- 3. 使用ask_codebase分析缺陷原因
882
- 4. 使用execute_script验证缺陷修复
883
- 5. 使用file_operation更新缺陷报告
850
+ 3. 使用execute_script验证缺陷修复
851
+ 4. 使用file_operation更新缺陷报告
884
852
  </step>
885
853
 
886
854
  <step>
887
855
  ### 7. 质量评估与交付
888
- 1. 使用ask_codebase验证测试覆盖
889
- 2. 使用file_operation整理测试文档
890
- 3. 使用execute_script生成质量报告
891
- 4. 向PM提交测试结果
892
- 5. 使用file_operation归档测试文档
856
+ 1. 使用file_operation整理测试文档
857
+ 2. 使用execute_script生成质量报告
858
+ 3. 向PM提交测试结果
859
+ 4. 使用file_operation归档测试文档
893
860
  </step>
894
861
  </workflow>
895
862
 
@@ -897,7 +864,6 @@ QA_PROMPT = f"""
897
864
  ## 工具使用指南
898
865
  - **create_code_agent**:创建测试代码开发代理
899
866
  - **file_operation**:管理测试文档和测试脚本
900
- - **ask_codebase**:了解代码库实现以设计测试
901
867
  - **execute_script**:执行测试命令和测试套件
902
868
  - **read_code**:阅读和理解代码以设计测试用例
903
869
  - **methodology**:应用测试方法论和最佳实践
@@ -994,7 +960,6 @@ def create_dev_team() -> MultiAgent:
994
960
  "search_web",
995
961
  "execute_script",
996
962
  "methodology",
997
- "ask_codebase",
998
963
  "edit_file",
999
964
  "rewrite_file",
1000
965
  ])
@@ -1007,7 +972,6 @@ def create_dev_team() -> MultiAgent:
1007
972
  "execute_script",
1008
973
  "read_webpage",
1009
974
  "methodology",
1010
- "ask_codebase",
1011
975
  "edit_file",
1012
976
  "rewrite_file",
1013
977
  ])
@@ -1016,7 +980,6 @@ def create_dev_team() -> MultiAgent:
1016
980
  SA_output_handler.use_tools([
1017
981
  "file_operation",
1018
982
  "search_web",
1019
- "ask_codebase",
1020
983
  "execute_script",
1021
984
  "read_code",
1022
985
  "methodology",
@@ -1027,7 +990,6 @@ def create_dev_team() -> MultiAgent:
1027
990
  TL_output_handler = ToolRegistry()
1028
991
  TL_output_handler.use_tools([
1029
992
  "file_operation",
1030
- "ask_codebase",
1031
993
  "execute_script",
1032
994
  "methodology",
1033
995
  "edit_file",
@@ -1038,7 +1000,6 @@ def create_dev_team() -> MultiAgent:
1038
1000
  DEV_output_handler.use_tools([
1039
1001
  "create_code_agent",
1040
1002
  "file_operation",
1041
- "ask_codebase",
1042
1003
  "execute_script",
1043
1004
  "read_code",
1044
1005
  "create_sub_agent",
@@ -1051,7 +1012,6 @@ def create_dev_team() -> MultiAgent:
1051
1012
  QA_output_handler.use_tools([
1052
1013
  "create_code_agent",
1053
1014
  "file_operation",
1054
- "ask_codebase",
1055
1015
  "execute_script",
1056
1016
  "read_code",
1057
1017
  "methodology",
@@ -1067,7 +1027,6 @@ def create_dev_team() -> MultiAgent:
1067
1027
  - **search_web**:研究相关领域知识,寻找最佳实践
1068
1028
  - **execute_script**:监控项目状态,执行自动化任务
1069
1029
  - **methodology**:采用适当的项目方法论和最佳实践
1070
- - **ask_codebase**:分析代码库,了解系统实现和技术债务
1071
1030
 
1072
1031
  ## 文档管理规范
1073
1032
  每一步工作后,必须使用file_operation工具将结论性输出记录到项目文档中:
@@ -1089,7 +1048,6 @@ def create_dev_team() -> MultiAgent:
1089
1048
  - **execute_script**:查询系统环境和配置信息
1090
1049
  - **read_webpage**:收集用户体验和行业趋势信息
1091
1050
  - **methodology**:应用需求分析和用户故事映射方法论
1092
- - **ask_codebase**:分析代码库中的功能实现,了解现有系统能力和限制,分析业务逻辑
1093
1051
 
1094
1052
  ## 文档管理规范
1095
1053
  每一步分析后,必须使用file_operation工具将结论性输出记录到分析文档中:
@@ -1108,7 +1066,6 @@ def create_dev_team() -> MultiAgent:
1108
1066
  ## 工具使用指南
1109
1067
  - **file_operation**:创建和管理架构文档和技术规格
1110
1068
  - **search_web**:研究架构模式和技术趋势
1111
- - **ask_codebase**:分析代码库,理解系统实现
1112
1069
  - **execute_script**:检查系统环境和依赖关系
1113
1070
  - **read_code**:阅读和理解关键代码段
1114
1071
  - **methodology**:应用架构设计方法论和模式
@@ -1129,7 +1086,6 @@ def create_dev_team() -> MultiAgent:
1129
1086
  TL_PROMPT_EXTENSION = """
1130
1087
  ## 工具使用指南
1131
1088
  - **file_operation**:管理技术文档和指导文件
1132
- - **ask_codebase**:分析代码库,理解实现细节
1133
1089
  - **execute_script**:执行开发工具和命令
1134
1090
 
1135
1091
  ## 文档管理规范
@@ -1150,7 +1106,6 @@ def create_dev_team() -> MultiAgent:
1150
1106
  ## 工具使用指南
1151
1107
  - **create_code_agent**:创建专业代码开发代理
1152
1108
  - **file_operation**:管理源代码和配置文件
1153
- - **ask_codebase**:了解代码库实现细节
1154
1109
  - **execute_script**:执行开发命令和测试脚本
1155
1110
  - **read_code**:阅读和理解关键代码段
1156
1111
  - **create_sub_agent**:创建专门的子代理处理特定任务
@@ -1173,7 +1128,6 @@ def create_dev_team() -> MultiAgent:
1173
1128
  ## 工具使用指南
1174
1129
  - **create_code_agent**:创建测试代码开发代理
1175
1130
  - **file_operation**:管理测试文档和测试脚本
1176
- - **ask_codebase**:了解代码库实现以设计测试
1177
1131
  - **execute_script**:执行测试命令和测试套件
1178
1132
  - **execute_script**:执行各类脚本(Shell命令、Shell脚本、Python脚本)
1179
1133
  - **read_code**:阅读和理解代码以设计测试用例
@@ -126,9 +126,11 @@ class BasePlatform(ABC):
126
126
  return response
127
127
 
128
128
  def chat_until_success(self, message: str) -> str:
129
- if is_print_prompt():
129
+ """Chat with model until successful response"""
130
+ if not self.suppress_output and is_print_prompt():
130
131
  PrettyOutput.print(f"{message}", OutputType.USER)
131
- return while_true(lambda: while_success(lambda: self._chat(message), 5), 5)
132
+ result: str = while_true(lambda: while_success(lambda: self._chat(message), 5), 5)
133
+ return result
132
134
 
133
135
  @abstractmethod
134
136
  def name(self) -> str:
@@ -14,7 +14,6 @@ from yaspin.api import Yaspin
14
14
  from yaspin.spinners import Spinners
15
15
 
16
16
  from jarvis.jarvis_platform.base import BasePlatform
17
- from jarvis.jarvis_utils.config import get_data_dir
18
17
  from jarvis.jarvis_utils.output import OutputType, PrettyOutput
19
18
  from jarvis.jarvis_utils.utils import while_success
20
19
 
@@ -92,7 +92,6 @@ class CodePlanTool:
92
92
  tool_registry.use_tools([
93
93
  "execute_script",
94
94
  "read_code",
95
- "ask_codebase",
96
95
  "search_web",
97
96
  "ask_user"
98
97
  ])
@@ -157,7 +156,7 @@ class CodePlanTool:
157
156
 
158
157
  ## 工作流程
159
158
  1. **需求理解阶段**:
160
- - 使用ask_codebase工具查询相关代码
159
+ - 使用execute_script工具和read_code工具理解代码
161
160
  - 必要时使用search_web搜索补充信息
162
161
  - 使用ask_user工具向用户确认模糊点
163
162
 
@@ -185,7 +184,6 @@ class CodePlanTool:
185
184
 
186
185
  ## 工具使用优先级
187
186
  1. **代码查询工具**:
188
- - ask_codebase: 查询功能位置和实现
189
187
  - fd/rg: 查找文件和代码模式
190
188
  - read_code: 读取文件内容
191
189
 
@@ -138,6 +138,7 @@ class FileSearchReplaceTool:
138
138
 
139
139
  file_path = args["file"]
140
140
  changes = args["changes"]
141
+ agent = args.get("agent", None)
141
142
 
142
143
  # 创建已处理文件变量,用于失败时回滚
143
144
  original_content = None
@@ -153,6 +154,17 @@ class FileSearchReplaceTool:
153
154
  with open(file_path, 'r', encoding='utf-8') as f:
154
155
  content = f.read()
155
156
  original_content = content
157
+
158
+ if file_exists and agent:
159
+ files = agent.get_user_data("files")
160
+ if not files or files.get(file_path, None) is None:
161
+ return {
162
+ "success": False,
163
+ "stdout": "",
164
+ "stderr": f"请先读取文件 {file_path} 的内容后再编辑"
165
+ }
166
+
167
+
156
168
  with yaspin(text=f"正在处理文件 {file_path}...", color="cyan") as spinner:
157
169
  success, temp_content = fast_edit(file_path, changes, spinner)
158
170
  if not success:
@@ -61,6 +61,30 @@ class ScriptTool:
61
61
  "g++": "cpp",
62
62
  }
63
63
 
64
+ def get_display_output(self, file_path: str) -> str:
65
+ """消除控制字符,得到用户实际看到的文本,去除script命令首尾行"""
66
+ import re
67
+ # 读取文件内容并尝试多种编码
68
+ with open(file_path, 'rb') as f:
69
+ data = f.read()
70
+
71
+ import pyte
72
+ screen = pyte.Screen(300, 100000)
73
+ stream = pyte.ByteStream(screen)
74
+ stream.feed(data)
75
+
76
+ # 清理每行右侧空格,并过滤空行
77
+ cleaned = []
78
+ cleaned = []
79
+ for y in range(screen.lines):
80
+ line = screen.buffer[y]
81
+ stripped = "".join(
82
+ char.data for char in line.values()
83
+ ).rstrip()
84
+ if stripped:
85
+ cleaned.append(stripped)
86
+ return "\n".join(cleaned[1:-1])
87
+
64
88
  def _execute_script_with_interpreter(self, interpreter: str, script_content: str) -> Dict[str, Any]:
65
89
  """Execute a script with the specified interpreter
66
90
 
@@ -90,13 +114,8 @@ class ScriptTool:
90
114
 
91
115
  # Read and process output file
92
116
  try:
93
- with open(output_file, 'r', encoding='utf-8', errors='ignore') as f:
94
- output = f.read()
95
- # Remove header and footer added by script command (if any)
96
- if output:
97
- lines = output.splitlines()
98
- if len(lines) > 2:
99
- output = "\n".join(lines[1:-1])
117
+ # 消除控制字符,得到用户实际看到的文本
118
+ output = self.get_display_output(output_file)
100
119
  except Exception as e:
101
120
  output = f"读取输出文件失败: {str(e)}"
102
121
 
@@ -150,4 +169,8 @@ class ScriptTool:
150
169
  "success": False,
151
170
  "stdout": "",
152
171
  "stderr": str(e)
153
- }
172
+ }
173
+
174
+ if __name__ == "__main__":
175
+ script_tool = ScriptTool()
176
+ print(script_tool.get_display_output("/home/wangmaobin/code/Jarvis/a.txt"))
@@ -50,7 +50,7 @@ class FileOperationTool:
50
50
  return None # 如果没有合适的处理器,返回None
51
51
 
52
52
  def _handle_single_file(self, operation: str, filepath: str, content: str = "",
53
- start_line: int = 1, end_line: int = -1) -> Dict[str, Any]:
53
+ start_line: int = 1, end_line: int = -1, agent: Any = None) -> Dict[str, Any]:
54
54
  """Handle operations for a single file"""
55
55
  try:
56
56
  abs_path = os.path.abspath(filepath)
@@ -128,6 +128,15 @@ class FileOperationTool:
128
128
 
129
129
  spinner.text = f"文件读取完成: {abs_path}"
130
130
  spinner.ok("✅")
131
+
132
+ if agent:
133
+ files = agent.get_user_data("files")
134
+ if files:
135
+ files.append(abs_path)
136
+ else:
137
+ files = [abs_path]
138
+ agent.set_user_data("files", files)
139
+
131
140
  return {
132
141
  "success": True,
133
142
  "stdout": output,
@@ -173,7 +182,7 @@ class FileOperationTool:
173
182
  """
174
183
  try:
175
184
  operation = args["operation"].strip()
176
-
185
+ agent = args.get("agent", None)
177
186
  if "files" not in args or not isinstance(args["files"], list):
178
187
  return {
179
188
  "success": False,
@@ -194,7 +203,8 @@ class FileOperationTool:
194
203
  file_info["path"].strip(),
195
204
  content,
196
205
  file_info.get("start_line", 1),
197
- file_info.get("end_line", -1)
206
+ file_info.get("end_line", -1),
207
+ agent
198
208
  )
199
209
 
200
210
  if result["success"]:
@@ -31,7 +31,7 @@ class ReadCodeTool:
31
31
  "required": ["files"]
32
32
  }
33
33
 
34
- def _handle_single_file(self, filepath: str, start_line: int = 1, end_line: int = -1) -> Dict[str, Any]:
34
+ def _handle_single_file(self, filepath: str, start_line: int = 1, end_line: int = -1, agent: Any = None) -> Dict[str, Any]:
35
35
  """处理单个文件的读取操作
36
36
 
37
37
  Args:
@@ -99,6 +99,14 @@ class ReadCodeTool:
99
99
  spinner.text = f"文件读取完成: {abs_path}"
100
100
  spinner.ok("✅")
101
101
 
102
+ if agent:
103
+ files = agent.get_user_data("files")
104
+ if files:
105
+ files.append(abs_path)
106
+ else:
107
+ files = [abs_path]
108
+ agent.set_user_data("files", files)
109
+
102
110
  return {
103
111
  "success": True,
104
112
  "stdout": output,
@@ -123,6 +131,7 @@ class ReadCodeTool:
123
131
  Dict[str, Any]: 包含成功状态、输出内容和错误信息的字典
124
132
  """
125
133
  try:
134
+ agent = args.get("agent", None)
126
135
  if "files" not in args or not isinstance(args["files"], list):
127
136
  return {
128
137
  "success": False,
@@ -140,7 +149,8 @@ class ReadCodeTool:
140
149
  result = self._handle_single_file(
141
150
  file_info["path"].strip(),
142
151
  file_info.get("start_line", 1),
143
- file_info.get("end_line", -1)
152
+ file_info.get("end_line", -1),
153
+ agent
144
154
  )
145
155
 
146
156
  if result["success"]: