Skip to content

feat: 跨主机 agent 日志实时上报 (issue #18) - #21

Merged
surenny merged 3 commits into
surenny:mainfrom
Camille1024:feat/ingest-remote-logs
May 7, 2026
Merged

feat: 跨主机 agent 日志实时上报 (issue #18)#21
surenny merged 3 commits into
surenny:mainfrom
Camille1024:feat/ingest-remote-logs

Conversation

@Camille1024

Copy link
Copy Markdown
Collaborator

关联 issue:#18

完成了什么

让不同机器上跑的 agent,日志能实时汇聚到部署在服务器上的 dashboard,不需要登录工作机也能监控运行进度。

改动说明

ui/server/src/routes/ingest.ts(新文件)

新增 POST /api/ingest 端点:

  • 可选 Bearer token 鉴权(服务器设置 KIP_INGEST_TOKEN 环境变量)
  • 校验 agent/runId 为安全路径段,防止路径穿越
  • 第一条 event 到达时自动创建 agents/<agent>/logs/<runId>/ 目录和 meta.json
  • session_end event 时更新 meta.json 的 completedAtstatus
  • 将 event 追加写入 absorber.jsonl
  • 无需额外 WebSocket 代码——logs.ts 里已有的 fs.watch 检测到新字节后会自动推送给前端

agents/blueprint-absorber/run.sh

在 Python 内联日志解析脚本的 emit() 函数末尾加了 ingest(row) 调用:

  • 读取 KIP_INGEST_URL / KIP_INGEST_TOKEN 环境变量
  • 未设置 KIP_INGEST_URL 时为 no-op,本地模式完全不受影响
  • 3秒超时,失败静默忽略,不阻塞 agent 运行

工作机使用方式

# 在工作机的 ~/.bashrc 或运行前设置
export KIP_INGEST_URL=https://kip.opensii.ai/dashboard/api/ingest
export KIP_INGEST_TOKEN=<token>   # 与服务器 KIP_INGEST_TOKEN 一致

# 正常跑 agent,日志自动上报
./agents/blueprint-absorber/run.sh draft-hint/foo.md

验证

# 模拟工作机上报一条 event
curl -X POST https://kip.opensii.ai/dashboard/api/ingest \
  -H "Content-Type: application/json" \
  -d '{"agent":"blueprint-absorber","runId":"run-2026-04-30T10-00-00Z",
       "hintFile":"draft-hint/test.md",
       "row":{"ts":"2026-04-30T10:00:00Z","event":"text","content":"hello"}}'
# → HTTP 204,宿主机 agents/blueprint-absorber/logs/run-.../absorber.jsonl 有内容
# → dashboard /logs 页面实时显示该条记录

chorewer and others added 3 commits April 30, 2026 18:01
Add POST /api/ingest endpoint and run.sh upload hook so agents running
on any machine can stream their JSONL events to the deployed dashboard
in real time.

- ui/server/src/routes/ingest.ts: new endpoint. Validates Bearer token
  (KIP_INGEST_TOKEN env var, optional), checks agent/runId are safe path
  segments, writes events to agents/<agent>/logs/<runId>/absorber.jsonl
  and maintains meta.json (creates on first event, updates completedAt
  and status on session_end). No extra WebSocket wiring needed — the
  existing fs.watch in logs.ts detects the appended bytes and pushes
  them to connected clients automatically.
- ui/server/src/index.ts: register ingest route.
- agents/blueprint-absorber/run.sh: add ingest() inside the inline
  Python log-parser. Reads KIP_INGEST_URL / KIP_INGEST_TOKEN from env;
  if KIP_INGEST_URL is unset the function is a no-op so local-only mode
  is unchanged. Fire-and-forget with 3s timeout — failures are silently
  ignored and never block the agent.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@surenny

surenny commented May 6, 2026

Copy link
Copy Markdown
Owner

这个写的是只针对于absorber的,还会有其他的agent负责不同的环节。我们后面把其他流程的agent都做好了,再合并这个pr

@surenny
surenny merged commit 3aaa04a into surenny:main May 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants