ai-dev-flow 3.10.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 (35) hide show
  1. ai_dev_flow/__init__.py +5 -0
  2. ai_dev_flow/__main__.py +6 -0
  3. ai_dev_flow/checkpoint.py +65 -0
  4. ai_dev_flow/cli.py +598 -0
  5. ai_dev_flow/config.py +404 -0
  6. ai_dev_flow/data/pipeline.yaml +193 -0
  7. ai_dev_flow/data/profiles/java-spring.yml +140 -0
  8. ai_dev_flow/data/recipes/steps/00-init-project.yaml +168 -0
  9. ai_dev_flow/data/recipes/steps/01-refine-requirement.yaml +117 -0
  10. ai_dev_flow/data/recipes/steps/02-analysis.yaml +97 -0
  11. ai_dev_flow/data/recipes/steps/03-design.yaml +91 -0
  12. ai_dev_flow/data/recipes/steps/03.5-decompose.yaml +120 -0
  13. ai_dev_flow/data/recipes/steps/05-build.yaml +72 -0
  14. ai_dev_flow/data/recipes/steps/06-review.yaml +115 -0
  15. ai_dev_flow/data/recipes/steps/07-delivery.yaml +76 -0
  16. ai_dev_flow/data/recipes/steps/task-template.yaml +74 -0
  17. ai_dev_flow/error_handler.py +122 -0
  18. ai_dev_flow/executor.py +406 -0
  19. ai_dev_flow/git_ops.py +187 -0
  20. ai_dev_flow/knowledge_accumulator.py +121 -0
  21. ai_dev_flow/logger.py +84 -0
  22. ai_dev_flow/sandbox.py +291 -0
  23. ai_dev_flow/semantic_summarizer.py +351 -0
  24. ai_dev_flow/snapshot.py +210 -0
  25. ai_dev_flow/state.py +87 -0
  26. ai_dev_flow/task_context.py +134 -0
  27. ai_dev_flow/task_graph.py +841 -0
  28. ai_dev_flow/task_state.py +151 -0
  29. ai_dev_flow/watchdog.py +120 -0
  30. ai_dev_flow-3.10.0.dist-info/METADATA +171 -0
  31. ai_dev_flow-3.10.0.dist-info/RECORD +35 -0
  32. ai_dev_flow-3.10.0.dist-info/WHEEL +5 -0
  33. ai_dev_flow-3.10.0.dist-info/entry_points.txt +2 -0
  34. ai_dev_flow-3.10.0.dist-info/licenses/LICENSE +21 -0
  35. ai_dev_flow-3.10.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,134 @@
1
+ """上下文组装器 — 为每个任务构建独立的 goose 会话上下文。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ import logging
6
+ from pathlib import Path
7
+
8
+ from ai_dev_flow.semantic_summarizer import SemanticSummarizer
9
+
10
+ logger = logging.getLogger("ai-dev-flow")
11
+
12
+ MAX_FILE_SIZE_FULL = 10 * 1024 # 10KB: 全文注入
13
+ MAX_FILE_SIZE_SLIM = 50 * 1024 # 50KB: 语义摘要模式
14
+
15
+
16
+ class TaskContext:
17
+ """组装好的任务上下文。"""
18
+ def __init__(self, task_name: str, task_description: str, context_notes: str,
19
+ input_contents: dict[str, str], doc_excerpts: dict[str, str]):
20
+ self.task_name = task_name
21
+ self.task_description = task_description
22
+ self.context_notes = context_notes
23
+ self.input_contents = input_contents
24
+ self.doc_excerpts = doc_excerpts
25
+
26
+
27
+ class ContextAssembler:
28
+ """读取任务指定的输入文件,组装上下文。支持增量扫描+语义摘要。"""
29
+
30
+ def __init__(self, project_root: Path, ai_dev_dir: Path, snapshot_mgr=None):
31
+ self.project_root = project_root
32
+ self.outputs_dir = ai_dev_dir / "outputs"
33
+ self._snapshot = snapshot_mgr
34
+ self._changed_files: set[str] | None = None # 当前变更集
35
+ self._summarizer = SemanticSummarizer(ai_dev_dir)
36
+
37
+ def _get_changed_set(self) -> set[str]:
38
+ """获取自上次快照以来的变更文件集合(惰性初始化)。"""
39
+ if self._changed_files is not None:
40
+ return self._changed_files
41
+ if self._snapshot:
42
+ diff = self._snapshot.get_changed_files()
43
+ self._changed_files = set(diff.added + diff.modified)
44
+ if self._changed_files:
45
+ logger.debug(f"Incremental scan: {len(self._changed_files)} changed files")
46
+ else:
47
+ self._changed_files = set() # 无快照管理器时每次都读
48
+ return self._changed_files
49
+
50
+ def assemble(self, task) -> TaskContext:
51
+ """为单个任务组装上下文。task 是 TaskConfig。"""
52
+ changed = self._get_changed_set()
53
+
54
+ input_contents: dict[str, str] = {}
55
+ for file_path in task.input_files:
56
+ full_path = self.project_root / file_path
57
+ # 增量模式:仅变更文件重新读取,未变更用缓存
58
+ if not self._snapshot or file_path in changed or not changed:
59
+ content = self._read_file_smart(full_path)
60
+ if content is not None:
61
+ input_contents[file_path] = content
62
+ if self._snapshot:
63
+ self._snapshot._content_cache[file_path] = content
64
+ elif file_path in self._snapshot._content_cache:
65
+ input_contents[file_path] = self._snapshot._content_cache[file_path]
66
+ else:
67
+ # 未变更但缓存缺失:首次读取并缓存
68
+ content = self._read_file_smart(full_path)
69
+ if content is not None:
70
+ input_contents[file_path] = content
71
+ self._snapshot._content_cache[file_path] = content
72
+
73
+ doc_excerpts: dict[str, str] = {}
74
+ for doc_name in task.reference_docs:
75
+ doc_path = self.outputs_dir / doc_name
76
+ # reference_docs 每次都读(通常是小文件且内容会变化)
77
+ content = self._read_file_smart(doc_path)
78
+ if content is not None:
79
+ doc_excerpts[doc_name] = content
80
+
81
+ return TaskContext(
82
+ task_name=task.name,
83
+ task_description=task.description,
84
+ context_notes=task.context_notes,
85
+ input_contents=input_contents,
86
+ doc_excerpts=doc_excerpts,
87
+ )
88
+
89
+ def _read_file_smart(self, filepath: Path) -> str | None:
90
+ """智能读取文件:
91
+ - 小于 10KB:全文注入
92
+ - 10KB 以上:语义结构提取(类/函数签名、关键注释、文档结构)
93
+ 摘要结果自动缓存到 .ai-dev/summaries/,同内容文件跳过重复提取。
94
+ """
95
+ if not filepath.exists():
96
+ logger.debug(f"Context file not found: {filepath}")
97
+ return None
98
+ try:
99
+ content = filepath.read_text(encoding="utf-8", errors="replace")
100
+ except Exception:
101
+ return None
102
+
103
+ size = len(content.encode("utf-8"))
104
+ if size <= MAX_FILE_SIZE_FULL:
105
+ return content
106
+
107
+ # 中大型文件:语义结构提取
108
+ summary = self._summarizer.summarize(filepath)
109
+ if summary:
110
+ return summary
111
+
112
+ # Fallback:摘要器无法处理时的简单截断
113
+ lines = content.splitlines()
114
+ return "\n".join(lines[:200])
115
+
116
+
117
+ def render_prompt(self, task, ctx: TaskContext) -> str:
118
+ """将组装的上下文渲染为任务 prompt 片段(供 recipe 的 context_notes 使用)。"""
119
+ parts = [f"## Task: {ctx.task_name}\n\n{ctx.task_description}\n"]
120
+
121
+ if ctx.context_notes:
122
+ parts.append(f"### Implementation Context\n\n{ctx.context_notes}\n")
123
+
124
+ if ctx.doc_excerpts:
125
+ parts.append("### Reference Documents\n")
126
+ for name, content in ctx.doc_excerpts.items():
127
+ parts.append(f"#### {name}\n```\n{content[:2000]}\n```\n")
128
+
129
+ if ctx.input_contents:
130
+ parts.append("### Relevant Input Files\n")
131
+ for path, content in ctx.input_contents.items():
132
+ parts.append(f"#### {path}\n```\n{content[:3000]}\n```\n")
133
+
134
+ return "\n".join(parts)