ai-worklog 1.0.2 → 1.0.3
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.
- package/package.json +1 -1
- package/scripts/collect_work_log.py +24 -12
package/package.json
CHANGED
|
@@ -278,21 +278,31 @@ def generate_summary(
|
|
|
278
278
|
if total_sessions == 0:
|
|
279
279
|
return _generate_empty_log(target_date)
|
|
280
280
|
|
|
281
|
-
# 构建给 AI
|
|
281
|
+
# 构建给 AI 的原始数据(去重 + 截断,控制 token 消耗)
|
|
282
|
+
def dedup_and_trim(msgs: list[str], max_chars: int = 200) -> list[str]:
|
|
283
|
+
seen: set[str] = set()
|
|
284
|
+
result = []
|
|
285
|
+
for m in msgs:
|
|
286
|
+
key = m[:80] # 用前 80 字符去重
|
|
287
|
+
if key in seen:
|
|
288
|
+
continue
|
|
289
|
+
seen.add(key)
|
|
290
|
+
result.append(m if len(m) <= max_chars else m[:max_chars] + "…")
|
|
291
|
+
return result
|
|
292
|
+
|
|
282
293
|
project_sections = []
|
|
283
294
|
for proj_name, data in all_projects.items():
|
|
284
295
|
msgs_parts = []
|
|
285
296
|
if data["claude"]:
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
msgs_parts.append(f" {i}. {msg}")
|
|
297
|
+
trimmed = dedup_and_trim(data["claude"])
|
|
298
|
+
msgs_parts.append(f"[Claude Code {len(data['claude'])} 条,去重后 {len(trimmed)} 条]")
|
|
299
|
+
for i, m in enumerate(trimmed, 1):
|
|
300
|
+
msgs_parts.append(f" {i}. {m}")
|
|
291
301
|
if data["codex"]:
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
msgs_parts.append(f" {i}. {
|
|
302
|
+
trimmed = dedup_and_trim(data["codex"])
|
|
303
|
+
msgs_parts.append(f"[Codex {len(data['codex'])} 条,去重后 {len(trimmed)} 条]")
|
|
304
|
+
for i, m in enumerate(trimmed, 1):
|
|
305
|
+
msgs_parts.append(f" {i}. {m}")
|
|
296
306
|
project_sections.append(f"项目: {proj_name}\n" + "\n".join(msgs_parts))
|
|
297
307
|
|
|
298
308
|
raw_data = "\n\n".join(project_sections)
|
|
@@ -462,7 +472,9 @@ def git_commit_and_push(log_file: Path, target_date: str, push: bool = True) ->
|
|
|
462
472
|
"""全自动 git init → GitLab 项目创建 → commit → push"""
|
|
463
473
|
|
|
464
474
|
def run(cmd: list[str], check_err: bool = True) -> subprocess.CompletedProcess:
|
|
465
|
-
|
|
475
|
+
env = os.environ.copy()
|
|
476
|
+
env["LC_ALL"] = "C" # 强制英文输出,保证字符串匹配不受本地化影响
|
|
477
|
+
r = subprocess.run(cmd, cwd=REPO_DIR, capture_output=True, text=True, env=env)
|
|
466
478
|
if check_err and r.returncode != 0:
|
|
467
479
|
print(f"命令失败: {' '.join(cmd)}\n{r.stderr.strip()}", file=sys.stderr)
|
|
468
480
|
return r
|
|
@@ -496,7 +508,7 @@ def git_commit_and_push(log_file: Path, target_date: str, push: bool = True) ->
|
|
|
496
508
|
run(["git", "add", "-A"])
|
|
497
509
|
run(["git", "commit", "-m", "init: 初始化工作日志仓库"])
|
|
498
510
|
|
|
499
|
-
# ── 4. 提交日志
|
|
511
|
+
# ── 4. 提交日志 ───────────────────────────────────────────────────────────
|
|
500
512
|
rel_path = log_file.relative_to(REPO_DIR)
|
|
501
513
|
print(f"Git: 添加 {rel_path}")
|
|
502
514
|
if run(["git", "add", str(rel_path)]).returncode != 0:
|