Commit Graph

16 Commits

Author SHA1 Message Date
zbc
455489cc89 1. 修改上报队列机制,确保上报失败有可靠的重试机制,不会静默失败;2.修改conversation上报遗漏的问题; 2026-05-27 09:48:38 +08:00
zbc
c8586ee6ee 1. 修复匿名上报url错误; 2.增加注释; 3.增加异常场景处理提升获取对话diff的健壮性“ 2026-05-26 16:39:19 +08:00
zbc
7ae2c9ba08 修复LLM response中构建diff不完善的问题 2026-05-25 19:13:47 +08:00
林凯90331
ad90f40088 feat(rawDump): add parent_ids to commit payload
Include parent commit hashes in raw dump commit reporting.
- git log format now includes %P (parent hashes)
- parseCommitLog extracts parent_ids as string array
- CommitPayload type extended with parent_ids field
- merge commits may have multiple parents

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-18 20:06:15 +08:00
linkai0924
0b271a7847
Merge pull request #86 from IronRookieCoder/fix-snip-tool
fix(builtin-tools): handle undefined message_ids in SnipTool.call()
2026-05-15 17:01:26 +08:00
IronRookieCoder
39106e4f9d
Merge branch 'main' into fix-snip-tool 2026-05-15 14:40:34 +08:00
林凯90331
3be987891b fix(raw-dump): add user-agent header to worker requests
Set User-Agent to csc/${version} in both auth() and authWithFallback()

Signed-off-by: 林凯90331 <90331@sangfor.com>

Co-authored-by: CoStrict <zgsm@sangfor.com.cn>
2026-05-15 14:33:33 +08:00
IronRookieCoder
a8c8c533d0 fix(builtin-tools): handle undefined message_ids in SnipTool.call()
## Bug 详情
调用 Snip 工具时,若模型通过 ExecuteExtraTool 传入空 params,
SnipTool.call() 中访问 input.message_ids.length 会抛出
`Cannot read properties of undefined (reading 'length')`。

## 根因
Snip 是延迟工具(非 CORE_TOOLS),需通过 ExecuteExtraTool 间接调用。
ExecuteExtraTool 将 params 直接透传给目标工具,不做 Zod schema 验证。
当 params 为空对象 {} 时,input.message_ids 为 undefined。

## 修复方案
在 SnipTool.call() 中使用 optional chaining 安全访问 message_ids。

## 变更要点
- packages/builtin-tools/src/tools/SnipTool/SnipTool.ts: 防御性处理空 message_ids
- src/costrict/provider/auth.ts: 删除 unreachable continue(lint 自动修复)
- src/services/rawDump/worker.ts: Math.pow → **(lint 自动修复)

## 自测
- 已人工验证

Co-Authored-By: Auto <noreply@anthropic.com>
2026-05-14 15:47:35 +08:00
DoSun
cbc948b044 Merge branch 'feat/server-refactor'
# Conflicts:
#	build.ts
#	src/main.tsx
#	src/services/rawDump/worker.ts
2026-05-14 15:21:25 +08:00
林凯90331
12caa6706b perf(rawDump): reduce CPU usage and fix worker spawn reliability
Add session messages and repo info caching to avoid repeated JSONL
parsing and git subprocess spawning across tasks.

Share state across all tasks in a single batch to minimize file lock
contention and JSON parse overhead.

Convert queue operations from sync to async to prevent event loop
blocking in the main process.

Restore inline batch worker fallback when external spawn fails,
and increase worker interval from 30s to 2min to reduce CPU impact.

Add 5s debounce per session+messageID to prevent duplicate enqueues.

Improve binary mode spawn reliability by falling back to node runtime
when bun is not available.

Signed-off-by: 林凯90331 <90331@sangfor.com>
Co-authored-by: CoStrict <zgsm@sangfor.com.cn>
2026-05-14 11:07:02 +08:00
林凯90331
e24ed3b63d feat(rawDump): add raw dump reporting module with local mode and deduplication
Implement the raw dump data reporting module for uploading conversation,
summary, and commit data to the CoStrict endpoint.

Key features:
- Local dump mode for debugging without network
- PID-based file locking to prevent state corruption with multiple csc instances
- 5-minute deduplication window for summary uploads
- Auto-detect sender (user/agent) and conditional user_input
- Repository fields (repo_addr, repo_branch, work_dir) in conversation
- Anonymous interface fallback when auth fails
- Filter commits to current user and limit fetch range
- Skip empty intermediate conversation turns
- Fix worker spawning for build and binary modes
- Remove git diff HEAD fallback to avoid unrelated working tree changes

Signed-off-by: 林凯90331 <90331@sangfor.com>
Co-authored-by: CoStrict <zgsm@sangfor.com.cn>
2026-05-13 23:49:20 +08:00
DoSun
3abca0c053 merge: 合并 origin/main 到 feat/server-refactor,解决冲突并保留 server 完整实现 2026-05-13 10:27:14 +08:00
DoSun
3aab6fb889 fix: 修复 services/utils 层 strict 模式类型错误
- api/errors: formatAPIError 参数类型适配
- rawDump/logger: 导出可同时作为函数和对象调用的 log
- rawDump/worker: postJson body 类型断言、reduce 泛型标注
- sideQueryOpenAICompat: tool_calls 类型收窄为 FunctionToolCall
2026-05-11 14:33:50 +08:00
林凯90331
1240a1a499 fix(rawDump): prevent batch worker concurrency cascade and add fetch timeout
- Add in-process isRunning flag to block reentrant runBatch (file lock
  fails when pid === process.pid)
- Replace setInterval + double immediate trigger with self-scheduling
  setTimeout that only fires after previous batch awaits
- Move clearQueue() to right after readQueue() so any unexpected
  concurrent runBatch sees an empty queue and exits immediately
- Cache repoInfo and workingTreeDiff in processTask, pass into all three
  upload functions to halve git invocations per task
- Add 30s AbortController timeout on postJson fetch so the worker no
  longer hangs indefinitely on unresponsive networks

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-11 11:34:44 +08:00
林凯90331
f3ece2f469 refactor(rawDump): prevent 429 with queue + batch worker
Replace per-turn detached workers with a file-backed queue consumed by
a single long-running batch worker (30s interval, 0-10s jitter).

- queue.ts, batchWorker.ts: file queue with pid-based lock for worker
  singleton; tasks deduped by sessionID:messageID before processing
- worker.ts: retry with backoff (5s, 10s) for 429 and network errors;
  update commit state per upload so partial failures resume cleanly;
  export auth, loadSessionMessages, getSessionDirectory and upload*
  helpers for batchWorker reuse
- git.ts: cap commit log at 50 entries within last 7 days; pause 500ms
  every 10 commits to spread load
- worker.ts: resolve session jsonl via ~/.claude/projects/{normalized}
  with fallbacks, scanning for the file containing the target session
- logger.ts: file + stderr logger gated by CSC_RAW_DUMP_DEBUG, default
  silent
- sessionDataUploader.ts: implement createSessionTurnUploader to pick
  the last assistant message; query.ts fires uploadSessionTurn after
  query_api_streaming_end (non-blocking)

Signed-off-by: 林凯90331 <90331@sangfor.com>
Co-authored-by: CoStrict <zgsm@sangfor.com.cn>
2026-05-07 21:45:20 +08:00
林凯90331
28d4f1f4e5 feat(rawDump): add session data raw-dump reporting module
Introduce a framework-decoupled raw-dump module that uploads conversation, summary, and commits data to the CoStrict server in a non-blocking detached worker process.

- Add src/services/rawDump/ with index, types, state, spawn, git, worker, and README

- Implement reportTurn and reportSession entry points with in-memory dedup and env-based disable switch (CSC_DISABLE_RAW_DUMP / COSTRICT_DISABLE_RAW_DUMP)

- Replace sessionDataUploader stub with uploadSessionTurn that delegates to reportTurn

Signed-off-by: 林凯90331 <90331@sangfor.com>

Co-authored-by: CoStrict <zgsm@sangfor.com.cn>
2026-05-07 17:27:56 +08:00