Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions docs/architecture/core-decomposition.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ owner 边界,否则不要把一个 feature group 继续拆成更小的 crate
rollback / dependency state paths and function-agent Git / AI response
boundaries. Core still owns MiniApp filesystem IO, worker process execution,
built-in asset seeding/source-hash input lookup, host-dispatch execution,
`PathManager` integration, function-agent Git/AI calls, prompt templates,
JSON extraction, and error mapping. The built-in MiniApp bundle/hash/marker/source payload
`PathManager` integration, and function-agent Git/AI calls. Function-agent
prompt templates, response JSON extraction, and domain error-mapping policy
may move only with focused behavior-equivalence tests. The built-in MiniApp bundle/hash/marker/source payload
seed-decision contract plus seed plan / marker wire helper can live in
`bitfun-product-domains`, but bundled
asset includes, marker IO, customized update runtime, and recompile
Expand Down Expand Up @@ -253,8 +254,9 @@ owner 边界,否则不要把一个 feature group 继续拆成更小的 crate
GetToolSpec runtime facade、Tool-result vector adapter 与 readonly enabled filtering 的通用规则委托给
`bitfun-agent-tools`,不改变工具行为。
- H2:product-domain runtime owner 迁移。MiniApp / function-agent 的纯 DTO/helper/port
facade 已外移,filesystem IO、worker process、host dispatch、built-in asset seeding /
marker IO、prompt template、JSON extraction、error mapping、Git/AI 调用仍显式
facade 已外移;本阶段进一步把 function-agent prompt template、AI response JSON
extraction 与 domain error mapping 策略迁入 `product-domains`。filesystem IO、
worker process、host dispatch、built-in asset seeding / marker IO 与 Git/AI 调用仍显式
core-owned。
- H3:remaining service/runtime owner。remote-connect 当前只迁移 tracker / wire /
pure policy / registry lifecycle;dialog submission、terminal pre-warm、file IO/path
Expand All @@ -275,21 +277,21 @@ owner 边界,否则不要把一个 feature group 继续拆成更小的 crate
core 继续持有 SSH manager、remote FS / terminal、MiniApp filesystem IO、worker runtime、
`PathManager` 注入和兼容 facade;不声明 remote-connect、MiniApp IO、function-agent Git/AI
runtime 或 tool runtime 已迁移。
- 本轮 product-domain runtime preflight PR 只补等价快照和边界锚点:MiniApp
- 本轮 product-domain runtime preflight PR 已补等价快照和边界锚点:MiniApp
`import_from_path` / `sync_from_fs` / `recompile` / `rollback` / deps state、
function-agent staged diff snapshotAI response JSON extraction 与 error mapping
仍被记录为 core-owned 行为。后续若继续移动这些 runtime owner,必须以这些快照为
行为等价基线
function-agent staged diff snapshot,以及 function-agent AI response JSON extraction 与
error mapping 的策略等价测试。H2 仅迁移 function-agent prompt/response policy owner
后续若继续移动 MiniApp IO/worker 或 Git/AI 调用 runtime owner,必须以这些快照为行为等价基线
- 当前 `product-domains` runtime port/facade closure 只迁移 port-backed owner
orchestration:MiniApp 的 deps/restart/recompile/sync/rollback 状态持久化可经
storage facade 执行,function-agent commit / work-state facade 可基于 Git/AI port
组装结果。Git commit-message 与 Startchat work-state 产品路径可通过 core-owned Git/AI
adapter 接入该 facade;Startchat 接线必须保留 legacy git-state、git-diff fallback、
`analyze_git=false` time-info 与 `analyzed_at` 时序。
core 仍持有 MiniApp filesystem IO、compiler 调度、worker process、host dispatch、
built-in asset include / seed / marker IO / recompile,以及 function-agent Git/AI service adapter、prompt template、
JSON extraction 和 error mapping;`product-domains` 仅承接 extracted JSON string
domain DTO 的解析 helper,不承接 extraction 或错误映射 owner
built-in asset include / seed / marker IO / recompile,以及 function-agent Git/AI service adapter
和 AI client 调用;`product-domains` 现在承接 function-agent prompt template、AI response JSON
extraction、domain error mapping 与 JSON-to-domain DTO parsing policy

## 产品表面边界(Product Surface Boundary)

Expand Down
28 changes: 17 additions & 11 deletions docs/plans/core-decomposition-plan.md

Large diffs are not rendered by default.

130 changes: 88 additions & 42 deletions scripts/check-core-boundaries.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2683,65 +2683,53 @@ const requiredContentRules = [
{
path: 'src/crates/core/src/function_agents/git-func-agent/ai_service.rs',
reason:
'core must continue owning Git function-agent prompt template, AI call, JSON extraction, and error mapping until AI runtime migration is reviewed',
'core must continue owning Git function-agent AI client calls while product-domains owns prompt and response policy',
patterns: [
{
regex: /\bconst COMMIT_MESSAGE_PROMPT\b/,
message: 'missing core-owned Git function-agent prompt template',
regex: /\bprepare_commit_ai_prompt\b/,
message: 'missing product-domain Git function-agent prompt policy use',
},
{
regex: /\bprepare_commit_prompt\b/,
message: 'missing product-domain prompt preparation helper use',
regex: /\bparse_commit_ai_response\b/,
message: 'missing product-domain Git function-agent response policy use',
},
{
regex: /\bai_client\s*\.\s*send_message\b/,
message: 'missing core-owned function-agent AI call',
},
{
regex: /\bextract_json_from_ai_response\b/,
message: 'missing core-owned AI response JSON extraction',
},
{
regex: /\bparse_commit_analysis_json\b/,
message: 'missing product-domain Git function-agent JSON parser use',
},
{
regex: /\bAgentError::analysis_error\b/,
message: 'missing core-owned AI response error mapping',
regex: /\bAgentError::internal_error\b/,
message: 'missing core-owned function-agent AI transport error mapping',
},
{
regex: /\bparse_commit_response_preserves_core_json_extraction_and_error_mapping\b/,
regex: /\bparse_commit_response_preserves_product_domain_response_policy\b/,
message: 'missing Git function-agent AI response boundary regression test',
},
],
},
{
path: 'src/crates/core/src/function_agents/startchat-func-agent/ai_service.rs',
reason:
'core must continue owning Startchat prompt template, AI call, JSON extraction, and error mapping until AI runtime migration is reviewed',
'core must continue owning Startchat AI client calls while product-domains owns prompt and response policy',
patterns: [
{
regex: /\bconst WORK_STATE_ANALYSIS_PROMPT\b/,
message: 'missing core-owned Startchat prompt template',
regex: /\bbuild_work_state_analysis_prompt\b/,
message: 'missing product-domain Startchat prompt policy use',
},
{
regex: /\bai_client\s*\.\s*send_message\b/,
message: 'missing core-owned Startchat AI call',
regex: /\bparse_work_state_analysis_response\b/,
message: 'missing product-domain Startchat response policy use',
},
{
regex: /\bextract_json_from_ai_response\b/,
message: 'missing core-owned Startchat JSON extraction',
},
{
regex: /\bparse_complete_analysis_json\b/,
message: 'missing product-domain Startchat JSON parser use',
regex: /\bai_client\s*\.\s*send_message\b/,
message: 'missing core-owned Startchat AI call',
},
{
regex: /\bAgentError::internal_error\b/,
message: 'missing core-owned Startchat error mapping',
message: 'missing core-owned Startchat AI transport error mapping',
},
{
regex: /\bparse_complete_analysis_preserves_core_json_extraction_and_error_mapping\b/,
regex: /\bparse_complete_analysis_preserves_product_domain_response_policy\b/,
message: 'missing Startchat AI response boundary regression test',
},
],
Expand Down Expand Up @@ -2882,11 +2870,34 @@ const requiredContentRules = [
},
],
},
{
path: 'src/crates/product-domains/src/function_agents/common.rs',
reason:
'product-domains owns function-agent AI response JSON extraction while core keeps concrete AI clients',
patterns: [
{
regex: /\bfn extract_json_from_ai_response\b/,
message: 'missing function-agent AI response JSON extraction helper',
},
{
regex: /\bfn try_repair_json\b/,
message: 'missing function-agent AI response JSON repair helper',
},
],
},
{
path: 'src/crates/product-domains/src/function_agents/startchat_func_agent/utils.rs',
reason:
'product-domains owns pure Startchat function-agent parsing policy while core keeps AI calls and error mapping',
'product-domains owns Startchat function-agent prompt and response policy while core keeps AI calls',
patterns: [
{
regex: /\bpub const WORK_STATE_ANALYSIS_PROMPT\b/,
message: 'missing product-domain Startchat prompt template',
},
{
regex: /\bpub fn build_work_state_analysis_prompt\b/,
message: 'missing product-domain Startchat prompt builder',
},
{
regex: /\bpub struct ParsedCompleteAnalysis\b/,
message: 'missing Startchat complete-analysis parse result contract',
Expand All @@ -2899,13 +2910,25 @@ const requiredContentRules = [
regex: /\bpub fn parse_complete_analysis_json\b/,
message: 'missing Startchat complete-analysis JSON parser',
},
{
regex: /\bpub fn parse_work_state_analysis_response\b/,
message: 'missing Startchat AI response policy',
},
{
regex: /\bwork_state_ai_response_policy_extracts_json_and_maps_domain_errors\b/,
message: 'missing Startchat AI response policy regression test',
},
],
},
{
path: 'src/crates/product-domains/src/function_agents/git_func_agent/utils.rs',
reason:
'product-domains owns pure Git function-agent response parsing policy while core keeps AI calls and error mapping',
'product-domains owns Git function-agent prompt and response policy while core keeps AI calls',
patterns: [
{
regex: /\bpub const COMMIT_MESSAGE_PROMPT\b/,
message: 'missing product-domain Git function-agent prompt template',
},
{
regex: /\bpub fn parse_commit_analysis_value\b/,
message: 'missing Git function-agent commit analysis value parser',
Expand All @@ -2922,6 +2945,18 @@ const requiredContentRules = [
regex: /\bpub fn prepare_commit_prompt\b/,
message: 'missing Git function-agent prompt preparation helper',
},
{
regex: /\bpub fn prepare_commit_ai_prompt\b/,
message: 'missing Git function-agent AI prompt policy',
},
{
regex: /\bpub fn parse_commit_ai_response\b/,
message: 'missing Git function-agent AI response policy',
},
{
regex: /\bcommit_ai_response_policy_extracts_json_and_maps_domain_errors\b/,
message: 'missing Git function-agent AI response policy regression test',
},
],
},
{
Expand Down Expand Up @@ -3921,24 +3956,21 @@ function runManifestParserSelfTest() {
{
path: 'src/crates/core/src/function_agents/git-func-agent/ai_service.rs',
contracts: [
'COMMIT_MESSAGE_PROMPT',
'prepare_commit_prompt',
'prepare_commit_ai_prompt',
'parse_commit_ai_response',
'send_message',
'extract_json_from_ai_response',
'parse_commit_analysis_json',
'AgentError::analysis_error',
'parse_commit_response_preserves_core_json_extraction_and_error_mapping',
'AgentError::internal_error',
'parse_commit_response_preserves_product_domain_response_policy',
],
},
{
path: 'src/crates/core/src/function_agents/startchat-func-agent/ai_service.rs',
contracts: [
'WORK_STATE_ANALYSIS_PROMPT',
'build_work_state_analysis_prompt',
'parse_work_state_analysis_response',
'send_message',
'extract_json_from_ai_response',
'parse_complete_analysis_json',
'AgentError::internal_error',
'parse_complete_analysis_preserves_core_json_extraction_and_error_mapping',
'parse_complete_analysis_preserves_product_domain_response_policy',
],
},
{
Expand All @@ -3960,17 +3992,31 @@ function runManifestParserSelfTest() {
'startchat_time_snapshot',
],
},
{
path: 'src/crates/product-domains/src/function_agents/common.rs',
contracts: ['extract_json_from_ai_response', 'try_repair_json'],
},
{
path: 'src/crates/product-domains/src/function_agents/startchat_func_agent/utils.rs',
contracts: ['ParsedCompleteAnalysis', 'parse_complete_analysis_value', 'parse_complete_analysis_json'],
contracts: [
'WORK_STATE_ANALYSIS_PROMPT',
'build_work_state_analysis_prompt',
'ParsedCompleteAnalysis',
'parse_complete_analysis_value',
'parse_complete_analysis_json',
'parse_work_state_analysis_response',
],
},
{
path: 'src/crates/product-domains/src/function_agents/git_func_agent/utils.rs',
contracts: [
'COMMIT_MESSAGE_PROMPT',
'parse_commit_analysis_value',
'parse_commit_analysis_json',
'truncate_diff_for_commit_prompt',
'prepare_commit_prompt',
'prepare_commit_ai_prompt',
'parse_commit_ai_response',
],
},
{
Expand Down
26 changes: 7 additions & 19 deletions src/crates/core/src/function_agents/git-func-agent/ai_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@ use super::types::{AICommitAnalysis, CommitMessageOptions, ProjectContext};
use crate::function_agents::common::{AgentError, AgentResult};
use crate::infrastructure::ai::AIClient;
use crate::util::types::Message;
use bitfun_product_domains::function_agents::git_func_agent::{
parse_commit_ai_response, prepare_commit_ai_prompt,
};
/**
* AI service layer
*
* Handles AI client interaction and provides intelligent analysis for commit message generation
*/
use bitfun_product_domains::function_agents::git_func_agent::{
parse_commit_analysis_json, prepare_commit_prompt,
};
use log::{debug, error, warn};
use std::sync::Arc;

/// Prompt template constants (embedded at compile time)
const COMMIT_MESSAGE_PROMPT: &str = include_str!("prompts/commit_message.md");

pub struct AIAnalysisService {
ai_client: Arc<AIClient>,
}
Expand Down Expand Up @@ -49,18 +46,12 @@ impl AIAnalysisService {
return Err(AgentError::invalid_input("Code changes are empty"));
}

let prepared_prompt = prepare_commit_prompt(
COMMIT_MESSAGE_PROMPT,
diff_content,
project_context,
options,
50000,
);
let prepared_prompt = prepare_commit_ai_prompt(diff_content, project_context, options);
if prepared_prompt.truncated {
warn!(
"Diff too large ({} chars), truncating to {} chars",
diff_content.len(),
50000
50_000
);
}

Expand Down Expand Up @@ -98,10 +89,7 @@ impl AIAnalysisService {
}

fn parse_commit_response(&self, response: &str) -> AgentResult<AICommitAnalysis> {
let json_str = crate::util::extract_json_from_ai_response(response)
.ok_or_else(|| AgentError::analysis_error("Cannot extract JSON from response"))?;

parse_commit_analysis_json(&json_str).map_err(AgentError::analysis_error)
parse_commit_ai_response(response)
}
}

Expand Down Expand Up @@ -139,7 +127,7 @@ mod tests {
}

#[test]
fn parse_commit_response_preserves_core_json_extraction_and_error_mapping() {
fn parse_commit_response_preserves_product_domain_response_policy() {
let service = test_service();
let parsed = service
.parse_commit_response(
Expand Down
Loading
Loading