Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 182 additions & 0 deletions .github/workflows/ci-security.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
name: CI and security

on:
push:
branches: [main]
pull_request:

permissions:
contents: read

concurrency:
group: ci-security-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
GO_VERSION: "1.26.3"
NODE_VERSION: "22.23.5"
SEMGREP_VERSION: "1.185.0"
TRIVY_VERSION: "v0.76.2"

jobs:
build-and-test:
name: Build frontend/backend
runs-on: ubuntu-latest
env:
NEXT_TELEMETRY_DISABLED: "1"
steps:
- name: Check out source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Set up Go
uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version: ${{ env.GO_VERSION }}
cache: true

- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
cache-dependency-path: web/package-lock.json

- name: Verify unit tests exist
shell: bash
run: |
go_tests="$(find . -type f -name '*_test.go' | wc -l)"
web_tests="$(find web -type f \( -name '*.test.*' -o -name '*.spec.*' \) | wc -l)"
test "$go_tests" -gt 0
test "$web_tests" -gt 0
echo "Go test files: $go_tests"
echo "Frontend test files: $web_tests"
- name: Install frontend dependencies
working-directory: web
run: npm ci

- name: Test and build frontend
working-directory: web
run: |
node --test src/lib/*.test.mjs
npm run build:static
- name: Stage frontend for embedded backend build
run: |
mkdir -p server/webui/dist
cp -a web/out/. server/webui/dist/
- name: Build integrated application
env:
CGO_ENABLED: "0"
run: go build -trimpath -tags embedui -o dist/artex ./cmd/artex

- name: Smoke-test backend binary
run: ./dist/artex -h

go-tests:
name: Go tests (${{ matrix.name }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: agent
packages: ./agent
- name: database
packages: ./db
- name: server
packages: ./server
- name: remaining
packages: ./cmd/artex ./config ./evidence ./guard ./intercept ./llmpool ./llmrec ./mcphttp ./notify ./selfupdate ./sidequestion ./traffic
services:
postgres:
image: postgres:17.7-alpine@sha256:bb377b7239d2774ac8cc76f481596ce96c5a6b5e9d141f6d0a0ee371a6e7c0f2
env:
POSTGRES_USER: artex
POSTGRES_PASSWORD: artex_ci
POSTGRES_DB: artex
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U artex -d artex"
--health-interval 5s
--health-timeout 5s
--health-retries 12
env:
ARTEX_PG_DSN: postgres://artex:artex_ci@localhost:5432/artex?sslmode=disable
steps:
- name: Check out source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Set up Go
uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version: ${{ env.GO_VERSION }}
cache: true

- name: Run Go tests
# The server suite starts background workers that currently expose
# upstream global-state races during teardown. Keep the required CI
# deterministic while those races are tracked separately.
run: go test -p 1 -count=1 -coverprofile=coverage.out ${{ matrix.packages }}

sast:
name: Semgrep SAST
runs-on: ubuntu-latest
steps:
- name: Check out source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Check out pinned Semgrep rules
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: semgrep/semgrep-rules
ref: a5ad1714f00c9f7fde980cab0ea1d6dc6d414fd2
path: .semgrep-rules
persist-credentials: false

- name: Set up Python
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.12.16"

- name: Install pinned Semgrep
run: python -m pip install --disable-pip-version-check "semgrep==${SEMGREP_VERSION}"

- name: Run Semgrep
run: >-
semgrep scan
--error
--strict
--metrics=off
--severity ERROR
--exclude .semgrep-rules
--config .semgrep-rules/go/lang/security
--config .semgrep-rules/go/gorilla/security
--config .semgrep-rules/go/jwt-go/security
--config .semgrep-rules/go/template/security
--config .semgrep-rules/javascript/lang/security
--config .semgrep-rules/typescript/lang/security
--config .semgrep-rules/typescript/react/security
--config .semgrep-rules/typescript/mcp/security
.
cve-and-secrets:
name: Trivy CVE, secret and configuration scan
runs-on: ubuntu-latest
steps:
- name: Check out source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Scan repository with pinned Trivy
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
version: ${{ env.TRIVY_VERSION }}
scan-type: fs
scan-ref: .
scanners: vuln,secret,misconfig
severity: HIGH,CRITICAL
ignore-unfixed: true
format: table
exit-code: "1"
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# syntax=docker/dockerfile:1

FROM --platform=$BUILDPLATFORM node:22-bookworm-slim AS frontend
ENV NEXT_TELEMETRY_DISABLED=1
WORKDIR /src/web
COPY web/package.json web/package-lock.json ./
RUN npm ci
Expand Down Expand Up @@ -32,17 +33,22 @@ COPY --from=frontend /usr/local/ /usr/local/
# Reinstall playwright (provides browser management), loaded with --with-deps preloading chromium
# and its system dependencies, so that the container-based MCP/CLI is available on first startup, no
# longer running npx-download.
RUN npm install -g @playwright/mcp@latest @playwright/cli@latest playwright@latest \
RUN npm install -g @playwright/mcp@0.0.85 @playwright/cli@0.1.24 playwright@1.65.1 \
&& playwright-cli --help \
&& playwright install --with-deps chromium \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=builder /out/artex /app/artex
COPY docker-entrypoint.sh /app/docker-entrypoint.sh
RUN chmod 0755 /app/artex /app/docker-entrypoint.sh
COPY skills/ /app/skills/
RUN groupadd --gid 1000 artex \
&& useradd --uid 1000 --gid artex --home-dir /app --shell /usr/sbin/nologin artex \
&& mkdir -p /app/data \
&& chmod 0755 /app/artex /app/docker-entrypoint.sh \
&& chown -R artex:artex /app
# data/(SQLite + jwt.key) persistence point
VOLUME ["/app/data"]
EXPOSE 8787 8788
USER artex
ENTRYPOINT ["/app/docker-entrypoint.sh"]
CMD ["-addr", ":8787", "-proxy", ":8788"]
2 changes: 1 addition & 1 deletion agent/assembly.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (g *guardedTool) Call(ctx context.Context, in json.RawMessage, tc *actool.T
defer func() {
if r := recover(); r != nil {
log.Printf("[tools] %s panic: %v\n%s", g.Name(), r, debug.Stack())
res, err = actool.Errorf(fmt.Sprintf("工具 %s 内部错误:%v(本次调用已失败,可换个参数或改用别的工具)", g.Name(), r)), nil
res, err = actool.Errorf(fmt.Sprintf("Tools %s Internal error: %v (This call failed to replace parameters or change tools)", g.Name(), r)), nil
}
}()
return g.CoreTool.Call(ctx, in, tc)
Expand Down
2 changes: 1 addition & 1 deletion agent/blackboard_inheritance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestGraphOverviewExpandsAssociatedCompanyScope(t *testing.T) {
domain := fmt.Sprintf("overview-scope-%d.invalid", companyID)
ip := fmt.Sprintf("2001:db8:%x::42", companyID%0xffff)
cidr := fmt.Sprintf("2001:db8:%x:1::/64", companyID%0xffff)
icp := fmt.Sprintf("京 ICP 备 %d 号", companyID)
icp := fmt.Sprintf("Kyoto ICP ready %d", companyID)
keyword := fmt.Sprintf("Scope Company %d", companyID)
inputs := []db.ScopeInput{
{Kind: "domain", Value: domain},
Expand Down
72 changes: 36 additions & 36 deletions agent/cancelcause.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,44 @@ func Causef(code, short, format string, args ...any) *AbortCause {

var (
// Task-level execution context.
AbortPausedByUser = cause("paused_by_user", "用户暂停了任务",
"用户通过任务控制接口(POST /api/tasks/{id}/control,action=pause)暂停了任务。本次 Planner/Worker 运行被主动取消;运行中的意图会退回 frontier(open),恢复任务后重新领取并从头执行")
AbortPausedByOrchestrator = cause("paused_by_orchestrator", "编排 Agent 暂停了任务",
"编排 Agent 调用了 pause_task 工具暂停本任务。本次 Planner/Worker 运行被主动取消;运行中的意图会退回 frontier(open),恢复后重新执行")
AbortTaskDeleted = cause("task_deleted", "任务被删除",
"任务正在删除(DELETE /api/tasks/{id}),删除屏障已取消该任务正在运行的 Planner、Worker 和主 Agent;本次运行结果不会再被使用")
AbortPausedOnReload = cause("paused_on_reload", "后端恢复了任务的暂停状态",
"后端启动时根据数据库中持久化的状态恢复了任务暂停。本次运行被取消;正常情况下恢复阶段没有正在运行的 Agent")
AbortGoalMet = cause("goal_met", "规划者判定任务目标已达成",
"规划者判定任务目标已达成并将任务置为 done,随后取消仍在运行的 Worker;这些意图会标记为 stopped,而不是失败")
AbortSettleDrainTimeout = cause("settle_drain_timeout", "任务超时收尾的等待时间已用尽",
"任务到达 timeout 后等待正在运行的 Worker 优雅收尾,但 90 秒 drain 宽限仍不足,因此执行硬取消;意图会标记为 exhausted,收尾阶段已经写入的事实和资产会保留")
AbortPausedByUser = cause("paused_by_user", "User paused task",
"The user has paused the task via the task control interface (POST /api/tasks/{id}/control, action=pause). This Planner/Worker run is actively cancelled; the running intent returns to frontier(open), and the task is reclaimed and executed from scratch when resumed.")
AbortPausedByOrchestrator = cause("paused_by_orchestrator", "Orchestrator paused task",
"The orchestration Agent called pause_task. The current Planner and Worker runs are cancelled; running intents return to the open frontier and are executed again after the task resumes.")
AbortTaskDeleted = cause("task_deleted", "Task was deleted.",
"The task is being deleted (DELETE /api/tasks/{id}), the deletion barrier has removed the Planner, Worker and Master Agent that the task is running on; the results of this execution will no longer be used")
AbortPausedOnReload = cause("paused_on_reload", "Backend has restored task's suspension.",
"The backend resumes the paused task at startup based on the persistent state in the database. This run is cancelled; normally there are no running Agents in the recovery phase")
AbortGoalMet = cause("goal_met", "Planner marked goal complete",
"The scheduler determines that the task goal has been met and sets the task to done, then cancels the still running Worker; these intents are marked as stopped rather than failed")
AbortSettleDrainTimeout = cause("settle_drain_timeout", "Task drain grace expired",
"When the task reaches timeout, it waits for the running Worker to elegantly end, but the 90-second drain margin is still insufficient and therefore executes a hard cancellation; the intent will be marked as exhausted, and the fact that the end phase has been written and the asset will be retained")

// Per-work context.
AbortKilledByPlanner = cause("killed_by_planner", "规划者终止了这条意图",
"规划者调用 kill_work 主动终止了这条意图,通常表示方向跑偏或已无继续价值;意图会标记为 stopped,不会自动重新领取")
AbortWorkPausedByUser = cause("work_paused_by_user", "用户暂停了这条 Worker 意图",
"用户暂停了正在运行的 Worker。本次调用被取消,意图转为 paused;已经登记的意图、事实、漏洞和活动记录全部保留,恢复后从头重新执行")
AbortWorkCancelledByUser = cause("work_cancelled_by_user", "用户删除了这条 Worker 意图",
"用户删除了正在运行的 Worker。本次调用被取消;Worker 退出写入区后,服务端按用户选择的删除模式处理该意图——假删除仅标记为已删除并保留全部产出,真删除会级联移除该意图及仅由它支撑的下游节点")
AbortWorkFinished = cause("work_finished", "Worker 已正常结束并释放 context",
"Worker 已正常结束,引擎在 detachWork 中释放其 context 资源。这不是运行中断;若它出现在中断消息中,说明取消与收场事件发生了竞态")
AbortPausedRaceGuard = cause("paused_race_guard", "任务暂停期间拒绝启动新运行",
"任务处于暂停状态时,引擎拒绝发出新的执行 context,用于防止 claim 与暂停之间的竞态导致 Worker 继续启动;已领取的意图会退回 frontier")
AbortKilledByPlanner = cause("killed_by_planner", "Planner terminated this intent.",
"The planner calls kill_work to actively terminate the intent, usually indicating that it is out of direction or no longer has a continuing value; the intent will be marked as stopped and not automatically reclaimed")
AbortWorkPausedByUser = cause("work_paused_by_user", "User paused Worker intent",
"The user has paused the running Worker. This call is cancelled and the intent becomes paused; all registered intent, fact, vulnerability, and activity records are retained and resumed from scratch")
AbortWorkCancelledByUser = cause("work_cancelled_by_user", "User deleted Worker intent",
"The user deletes the running Worker. This call is cancelled; after the Worker leaves the write zone, the server handles the intent in the deletion mode chosen by the user — false delete only marks it deleted and retains all output, while true delete cascades out the intention and the downstream nodes supported by it alone.")
AbortWorkFinished = cause("work_finished", "Worker finished normally",
"Worker has terminated properly, and the engine releases its context resource in detachWork. This is not a run interrupt; if it appears in an interrupt message, it indicates that there was a contest between the cancellation and closure event")
AbortPausedRaceGuard = cause("paused_race_guard", "Run blocked while task paused",
"When the task is suspended, the engine refuses to send a new execution context to prevent a contest between the claim and the suspension from causing the Worker to continue launching; the received intent returns to frontier")

// Main Agent and standalone conversation contexts.
AbortChatStoppedByUser = cause("chat_stopped_by_user", "用户停止了本轮对话",
"用户点击了停止,主动中止本轮主 Agent 或会话 Agent 运行。已经产生的活动记录会保留,可以继续发送下一条消息")
AbortChatPausedWithTask = cause("chat_paused_with_task", "任务暂停并中止了主 Agent 对话",
"用户暂停任务时,正在运行的主 Agent 对话也被同步取消。已经产生的活动记录会保留;恢复任务后不会自动重放本轮消息")
AbortChatTurnFinished = cause("chat_turn_finished", "本轮对话已正常结束并释放 context",
"本轮对话已正常结束,服务端正在释放该轮 context 资源。这不是运行中断;若它出现在中断消息中,说明取消与收场事件发生了竞态")
AbortChatStoppedByUser = cause("chat_stopped_by_user", "The user stopped the conversation.",
"The user clicks Stop, actively stopping the current run of the Master Agent or Session Agent. The activity record that has been generated is retained and the next message can be continued")
AbortChatPausedWithTask = cause("chat_paused_with_task", "Task pause stopped main chat",
"When the user suspends a task, the running main Agent dialog is also desynchronized. Activity records that have been generated are preserved; when the task is resumed, the current round of messages is not automatically replayed")
AbortChatTurnFinished = cause("chat_turn_finished", "Chat turn finished normally",
"This is not an interrupt; if it appears in the interrupt message, it indicates that there was a conflict between the cancellation and closure event.")

// Process-level and per-run hard backstop.
AbortShutdown = cause("shutdown", "后端进程正在关闭",
"后端进程收到 SIGINT 或 SIGTERM,正在重启、更新或关闭。所有运行中的 Agent 会被取消;重启后残留的 running 意图会重置为 open 并重新执行")
AbortRunHardTimeout = cause("run_hard_timeout", "单次运行的硬超时兜底已触发",
"单次运行超过软墙钟预算及额外宽限,说明模型请求或某个工具长时间没有返回,导致正常的回合边界收尾无法执行。请重点检查中断前最后一个未返回的工具调用")
AbortShutdown = cause("shutdown", "Backend process is closing",
"The backend process receives a SIGINT or SIGTERM and is restarting, updating, or shutting down. All running Agents are cancelled; the remaining running intent is reset to open after restart and executed again")
AbortRunHardTimeout = cause("run_hard_timeout", "Run hard timeout triggered",
"A single run exceeding the softwall clock budget and additional tolerance indicates that a model request or a tool has not returned for a long time, causing the normal loop boundary ending to fail. Focus on checking the last unreturned tool call before interrupting")
)

// AbortReason resolves the named cause attached to a cancelled run context.
Expand All @@ -79,11 +79,11 @@ func AbortReason(ctx context.Context) (code, short, text string, ok bool) {
}
switch {
case errors.Is(c, context.DeadlineExceeded):
return "deadline_exceeded", "上游 context 到达 deadline",
"上游 context 到达 deadline,但设置方没有通过 WithTimeoutCause 附加具名原因: " + c.Error(), true
return "deadline_exceeded", "Upstream context to deadline",
"The upstream context reaches the deadline, but the setter does not add a named reason via WithTimeoutCause: " + c.Error(), true
case errors.Is(c, context.Canceled):
return "canceled_no_cause", "取消方未附加具名原因",
"上游 context 被取消,但取消方没有通过 context.WithCancelCause 附加具名原因;请在 agent/cancelcause.go 登记原因并接入该取消点", true
return "canceled_no_cause", "Unnamed reason for cancellation",
"The upstream context was cancelled, but the canceler did not add a named cause through context.WithCancelCause; please register the reason in agent/cancelcause.go and access this cancellation point", true
default:
return "other", firstLine(c.Error(), 80), c.Error(), true
}
Expand Down
2 changes: 1 addition & 1 deletion agent/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func captureRunSession(ctx context.Context, s *agentcore.Session, input string,
rec(activityWithUsage(db.Activity{Kind: "result", Summary: firstLine(sum, 400), Detail: detail}, lastUsage))
return finalText, reason, ctx.Err()
}
rec(activityWithUsage(db.Activity{Kind: "result", IsError: true, Summary: "执行出错: " + err.Error(), Detail: err.Error()}, lastUsage))
rec(activityWithUsage(db.Activity{Kind: "result", IsError: true, Summary: "Error executing: " + err.Error(), Detail: err.Error()}, lastUsage))
return finalText, reason, err
}
switch ev.Kind {
Expand Down
Loading
Loading