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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-worklog",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "AI 对话工作日志自动收集工具 —— 从 Claude Code / Codex 对话记录生成每日工作日志并推送到 GitLab",
5
5
  "bin": {
6
6
  "ai-worklog": "./bin/index.js"
@@ -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
- msgs_parts.append(f"[Claude Code 对话 {len(data['claude'])} 条]")
287
- for i, m in enumerate(data["claude"], 1):
288
- # 截断过长消息
289
- msg = m if len(m) <= 500 else m[:500] + "..."
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
- msgs_parts.append(f"[Codex 对话 {len(data['codex'])} 条]")
293
- for i, m in enumerate(data["codex"], 1):
294
- msg = m if len(m) <= 500 else m[:500] + "..."
295
- msgs_parts.append(f" {i}. {msg}")
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
- r = subprocess.run(cmd, cwd=REPO_DIR, capture_output=True, text=True)
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: