Skip to content

Commit 428caf4

Browse files
committed
Version 1.0.4 is expected to be released.
1 parent fbdd5f2 commit 428caf4

12 files changed

Lines changed: 260 additions & 263 deletions

File tree

counter.dart

Lines changed: 73 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,73 @@
1-
// import 'dart:io';
2-
//
3-
// void main(List<String> args) async {
4-
// final rootPath = args.isNotEmpty ? args[0] : '.';
5-
//
6-
// int totalLines = 0;
7-
// int blankLines = 0;
8-
// int commentLines = 0;
9-
// int codeLines = 0;
10-
// int fileCount = 0;
11-
//
12-
// await for (final entity
13-
// in Directory(rootPath).list(recursive: true, followLinks: false)) {
14-
// if (entity is! File) continue;
15-
// if (!entity.path.endsWith('.dart')) continue;
16-
//
17-
// fileCount++;
18-
//
19-
// final lines = await entity.readAsLines();
20-
//
21-
// bool inBlockComment = false;
22-
//
23-
// for (var line in lines) {
24-
// totalLines++;
25-
//
26-
// final text = line.trim();
27-
//
28-
// if (text.isEmpty) {
29-
// blankLines++;
30-
// continue;
31-
// }
32-
//
33-
// if (inBlockComment) {
34-
// commentLines++;
35-
// if (text.contains('*/')) {
36-
// inBlockComment = false;
37-
// }
38-
// continue;
39-
// }
40-
//
41-
// if (text.startsWith('//')) {
42-
// commentLines++;
43-
// continue;
44-
// }
45-
//
46-
// if (text.startsWith('/*')) {
47-
// commentLines++;
48-
// if (!text.contains('*/')) {
49-
// inBlockComment = true;
50-
// }
51-
// continue;
52-
// }
53-
//
54-
// codeLines++;
55-
// }
56-
// }
57-
//
58-
// print('统计结果');
59-
// print('======================');
60-
// print('Dart文件数 : $fileCount');
61-
// print('总代码行数 : $totalLines');
62-
// print('代码行数 : $codeLines');
63-
// print('注释行数 : $commentLines');
64-
// if (kDebugMode) {
65-
// print('空白行数 : $blankLines');
66-
// }
67-
// }
68-
//
1+
import 'dart:io';
2+
3+
class Statistics {
4+
int files = 0;
5+
int totalLines = 0;
6+
int codeLines = 0;
7+
int commentLines = 0;
8+
int blankLines = 0;
9+
}
10+
11+
void main(List<String> args) {
12+
final directory = Directory(args.isEmpty ? '.' : args.first);
13+
14+
if (!directory.existsSync()) {
15+
print('目录不存在');
16+
return;
17+
}
18+
19+
final stat = Statistics();
20+
21+
for (final entity in directory.listSync(recursive: true)) {
22+
if (entity is! File || !entity.path.endsWith('.dart')) {
23+
continue;
24+
}
25+
26+
stat.files++;
27+
28+
bool inBlockComment = false;
29+
30+
for (final line in entity.readAsLinesSync()) {
31+
stat.totalLines++;
32+
33+
final text = line.trim();
34+
35+
if (text.isEmpty) {
36+
stat.blankLines++;
37+
continue;
38+
}
39+
40+
if (inBlockComment) {
41+
stat.commentLines++;
42+
if (text.contains('*/')) {
43+
inBlockComment = false;
44+
}
45+
continue;
46+
}
47+
48+
if (text.startsWith('//')) {
49+
stat.commentLines++;
50+
continue;
51+
}
52+
53+
if (text.startsWith('/*')) {
54+
stat.commentLines++;
55+
if (!text.contains('*/')) {
56+
inBlockComment = true;
57+
}
58+
continue;
59+
}
60+
61+
stat.codeLines++;
62+
}
63+
}
64+
65+
print('========== 总计 ==========');
66+
print('Dart 文件数 : ${stat.files}');
67+
print('总代码行数 : ${stat.totalLines}');
68+
print('有效代码行 : ${stat.codeLines}');
69+
print('注释行数 : ${stat.commentLines}');
70+
print('空行数 : ${stat.blankLines}');
71+
}
72+
73+
// dart compile exe counter.dart -o counter.exe

lib/core/agent/agent_context.dart

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ class AgentContextBuilder {
161161
}
162162
} catch (e) {
163163
// DB 查询失败不应阻断主流程(可能是首次运行、表还未建好等)
164-
AppLogger.instance.log(
165-
'[AgentContext] 尝试恢复 worktree 会话失败(忽略): $e',
166-
);
164+
AppLogger.instance.log('[AgentContext] 尝试恢复 worktree 会话失败(忽略): $e');
167165
}
168166
}
169167

@@ -184,10 +182,7 @@ class AgentContextBuilder {
184182
_ref.read(activeWorktreeProvider.notifier).state = '';
185183
try {
186184
final dao = WorktreeSessionsDao(_ref.read(databaseProvider));
187-
await dao.recordEnd(
188-
worktreePath: normalized,
189-
action: 'discard',
190-
);
185+
await dao.recordEnd(worktreePath: normalized, action: 'discard');
191186
} catch (_) {}
192187
}
193188
}
@@ -530,9 +525,7 @@ class AgentContextBuilder {
530525
);
531526
} catch (e) {
532527
// 写入失败不阻断主流程——最坏情况就是退化为纯内存态。
533-
AppLogger.instance.log(
534-
'[AgentContext] worktree 会话记录写入失败(忽略): $e',
535-
);
528+
AppLogger.instance.log('[AgentContext] worktree 会话记录写入失败(忽略): $e');
536529
}
537530
}
538531
return jsonEncode(result);
@@ -588,9 +581,7 @@ class AgentContextBuilder {
588581
action: result['action'] as String? ?? action,
589582
);
590583
} catch (e) {
591-
AppLogger.instance.log(
592-
'[AgentContext] worktree 会话结束记录写入失败(忽略): $e',
593-
);
584+
AppLogger.instance.log('[AgentContext] worktree 会话结束记录写入失败(忽略): $e');
594585
}
595586
}
596587
return jsonEncode(result);
@@ -715,7 +706,10 @@ class AgentContextBuilder {
715706
final rawPaths = args['paths'];
716707
List<String>? paths;
717708
if (rawPaths is List) {
718-
paths = rawPaths.cast<String>().where((s) => s.trim().isNotEmpty).toList();
709+
paths = rawPaths
710+
.cast<String>()
711+
.where((s) => s.trim().isNotEmpty)
712+
.toList();
719713
if (paths.isEmpty) paths = null;
720714
}
721715

lib/core/db/daos/worktree_sessions_dao.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,16 @@ class WorktreeSession {
135135
bool get isActive => status == 'active';
136136

137137
Map<String, dynamic> toJson() => {
138-
'id': id,
139-
'work_dir': workDir,
140-
'worktree_path': worktreePath,
141-
'branch': branch,
142-
'name': name,
143-
'status': status,
144-
'base_commit': baseCommit,
145-
'end_action': endAction,
146-
'end_commit': endCommit,
147-
'created_at': createdAt.toIso8601String(),
148-
'ended_at': endedAt?.toIso8601String() ?? '',
149-
};
138+
'id': id,
139+
'work_dir': workDir,
140+
'worktree_path': worktreePath,
141+
'branch': branch,
142+
'name': name,
143+
'status': status,
144+
'base_commit': baseCommit,
145+
'end_action': endAction,
146+
'end_commit': endCommit,
147+
'created_at': createdAt.toIso8601String(),
148+
'ended_at': endedAt?.toIso8601String() ?? '',
149+
};
150150
}

0 commit comments

Comments
 (0)