agent-sphere
AGENTS.md119 starsChanged 2 months agoMITView on GitHub
Git root holds four independent projects (no shared root build/lockfile): - agent-sphere/ — Java 21 / Spring Boot backend. See agent-sphere/AGENTS.md for module layout, Maven commands, Flyway, MyBatis-Plus, and code-style rules. - agent-sphere-ui/ — React 19 / UmiJS Max frontend (Ant Design Pro base). - agent-sphere-copilot-widget/ — embeddable chat widget (Vite lib IIFE + self-built REST/SSE timeline chat), see below. - agent-sphere-chrome-extension/ — Manifest V3 Chrome extension (bridges backend with the browser for automated ops). See agent-sphere-chrome-extension/AGENTS.md. No build step:…
- Reads credentials
- Deletes or force-pushes
- Commits and pushes
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository2 other files it gives its agents.
- agent-sphere/AGENTS.mdAGENTS.md
- agent-sphere-chrome-extension/AGENTS.mdAGENTS.md
The file
We split this AGENTS.md into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 91
Every new table adds the shared status/audit columns, aligned with the sys_* tables (reference entities: SysRole, IdentityProvider, …
- Very specific: line 118
Never inline raw strings/numbers in business logic.
- Very specific: line 133
Verify order: npm run biome → npm run lint → npm test.
- Very specific: line 141
Default locale zh-CN; moment2dayjs rewrites moment→dayjs.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AgentSphere — monorepo
回答语言 (response language)
- 默认使用中文回答用户;只有用户明确要求时才使用其他语言。
Git root holds four independent projects (no shared root build/lockfile):
agent-sphere/— Java 21 / Spring Boot backend. Seeagent-sphere/AGENTS.mdfor module layout, Maven commands, Flyway, MyBatis-Plus, and code-style rules.agent-sphere-ui/— React 19 / UmiJS Max frontend (Ant Design Pro base).agent-sphere-copilot-widget/— embeddable chat widget (Vite lib IIFE + self-built REST/SSE timeline chat), see below.agent-sphere-chrome-extension/— Manifest V3 Chrome extension (bridges backend with the browser for automated ops). Seeagent-sphere-chrome-extension/AGENTS.md. No build step: background is native ESM (background.js+lib/*.js), execution layer iscontent.js/content-locator.js, SSE lives inoffscreen.js, MAIN-world bridges arepage-script.js.src/is empty stubs andnpm run buildhas nobuild.js— edit files directly and load unpacked. Plugin supports vision operation:screenshot(CDP capture, viewport + full-page) +clickAt(x,y)on viewport screenshot device pixels; plugin tabs auto-group underAgentSphere;chrome.debuggeris confined tolib/cdp-client.js. Keepoffscreen.jsparams whitelist in sync withChromeCommandDTOwhen adding command fields.
GitHub flow off main. No test CI — run each project's tests before pushing. The only workflow is a deploy pipeline (see Deploy below).
How the two apps connect
- Backend serves API at
http://localhost:8080with prefix/api/v1/...; SSE routes contain/stream. - UI
npm run dev(port 8000) proxies/api/→http://localhost:8080(seeagent-sphere-ui/config/proxy.ts). For/streamrequests the proxy stripsAccept-Encodingand setsCache-Control: no-transform— preserve this logic, SSE breaks without it. - Typical local flow: start backend (
mvn -pl agent-sphere-bootstrap spring-boot:run -am, needs Postgres+Redis), then UI (cd agent-sphere-ui && npm run dev).
Infra / runtime prerequisites
- Postgres + Redis via
agent-sphere/agent-docker-middleware/docker-compose.yml(note: underagent-sphere/, not the repo root). Volume paths are hardcoded to macOS (/Users/elvin/Desktop/...) — override or remove on other machines. - Postgres DB name is
buukle_agent_2026061101(set inapplication.ymland the compose file). Env overrides:DB_HOST,DB_PORT,DB_USERNAME,DB_PASSWORD,REDIS_HOST,REDIS_PORT. - Backend JVM/Jackson timezone
Asia/Shanghai; virtual threads on by default.
Deploy (k3s / GitOps)
.github/workflows/deploy.ymlis the only workflow. Triggers onv*tags (or manualworkflow_dispatch): builds & pushes backend/frontend/widget images to Aliyun ACR, rewrites image tags ink8s/05-backend.yaml,06-frontend.yaml,08-widget.yaml, commits them tomain(Fleet applies them on k3s), and attaches the chrome-extension zip (packaged from the root-level extension files) to a GitHub Release. No test job — verify locally before tagging.k8s/holds the namespace + postgres/redis/backend/frontend/widget/ingress manifests;04-backend-config.yamlsets backend env (DB, Redis, JWT, etc.).- Frontend image build takes
build-args: COMMIT_HASH— referenced in the UI's version display.
Tagging & pushing (deploy trigger)
- Tag convention:
v1.0.NN-alpha(next after the latest remote tag). Create annotated tag onmainHEAD:git tag -a v1.0.NN-alpha -m "v1.0.NN-alpha". This environment has no SSH key / gh CLI — the
originremote (git@github.com:...) will fail withPermission denied (publickey). Push tags (and any auth-required git op) over HTTPS using the GitHub token inlocal-config/token.json(/local-configis gitignored, never commit it):TOKEN=$(node -p "require('./local-config/token.json').github.token") git push "https://nullpointexception-i:${TOKEN}@github.com/nullpointexception-i/agent-sphere.git" v1.0.NN-alpha- Pushing the
v*tag triggers the deploy workflow (see above); verify the run at the repo's Actions tab.
本地 CI(.local-workflow)— 替代慢的 GitHub Action
deploy.yml 的唯一 job 要把镜像跨境推到阿里云 ACR,这是全流程最慢的一步。.local-workflow/deploy.sh 在本地复刻同一流程( ACR 登录 → buildx 串行构建推送三镜像 → 改写 k8s tag 并 commit&push main → 自动递增版本号 → 打包扩展 → 建 GitHub Release ),缓存用 type=local 落在 .local-workflow/.cache/,用 --dry-run 可先看计划(不改任何文件)。
cp .local-workflow/.env.example .local-workflow/.env # 填 ACR_USERNAME / ACR_PASSWORD
./.local-workflow/deploy.sh --dry-run # 预演
./.local-workflow/deploy.sh # 完整发版
./.local-workflow/deploy.sh --skip-existing # 重跑:镜像已在 ACR 就跳过
./.local-workflow/deploy.sh --no-tag --only backend # 只发镜像不发 Release- 脚本入库,
.env/.cache//output/被 gitignore;ACR 凭据在.env,GitHub token 复用local-config/token.json(或GITHUB_TOKEN环境变量)。 - 与
deploy.yml的关键差异:要求当前分支 =main且工作树干净;ACR_REGISTRY未配置时从k8s/05-backend.yaml反推;git 走 HTTPS +GIT_ASKPASS(token 不进 argv/日志);扩展打包在mktemp -d里改版本号(deploy.yml直接改仓库内manifest.json且不还原);版本号由脚本 patch+1 自动递增并保留-alpha后缀。tag 仍锚在改 k8s 之前的提交,与deploy.yml同序。 - 三个镜像每次全部重建推送(
--skip-existing/--only可裁剪)。buildx 必须是docker-containerdriver 才支持cache-to type=local,脚本会自动建as-builder。arm64 宿主自动加--platform linux/amd64(k3s 节点是 amd64)。 - 本地 CI 不含 lint / test / typecheck,改代码仍按各项目约定自测(见下)。
agent-sphere-copilot-widget (chat widget)
Independent package — install/build only from inside agent-sphere-copilot-widget/. Stack: Vite 6 (lib mode, IIFE AgentSphereWidget), React 19, TypeScript (strict). No CopilotKit / AG-UI — chat renders a typed REST+SSE timeline (same shape as the main UI chat page).
Commands (run inside agent-sphere-copilot-widget/):
npm run dev # vite dev on :5173, proxies /api -> http://localhost:8080
npm run build # tsc --noEmit && vite build (lib IIFE -> dist/agent-sphere-widget.js)
npm run typecheck # tsc --noEmitHow it works:
AgentSphereWidget.init({ apiBase?, provider?, autoLogin?, title? })mounts into a shadow DOM root; CSS inlined via Vite?inline(src/styles.css).- OIDC SSO: consumes
?otc=→POST /auth/sso/exchange→ token insessionStorage(agent-sphere-widget:agent-user);autoLogindoes a one-shot silent probe (prompt=none);?otc=/?error=stripped after handling. - Timeline channel (
useTimelineStream):GET {apiBase}/instance/sessions/{sid}/timeline(paged bybeforeSeq/afterSeq, limit 5–50) + SSE{apiBase}/runtime/{sid}/stream(Bearer). SSE drives anassistanttypewriter (pushcontent_token/reasoning_tokenontoseq+kind==='assistant'rows) and sub-agent live aggregation;run_completed/failed/cancelled/awaiting_user,tool_call_*,clarification_*trigger anafterSeqrefresh for authoritative merge (mergeTimelinededupes byseq, placeholder sub-agent rows carryseq<0). - Send:
POST {apiBase}/runtime/{sid}/chat→{runId}; clarify:POST /runtime/{sid}/run/{runId}/clarify. - Chat input is self-built (textarea + send/stop); stop calls
POST /runtime/{sid}/stop.WidgetTimelinerenders user/assistant/tool/clarification/subagent/run_status rows with copy buttons, RUNNING wobble dot, inline sub-agent cards (tool detail single-open, auto-scroll), inline clarification options. - Vite proxy strips
Accept-Encodingfor/streamroutes and setsCache-Control: no-transform— SSE breaks without this. Preserve it.
Gotchas:
- Never copy
node_modules/package-lock.jsonacross machines. rollup 4 declares platform binaries as optionalDependencies (@rollup/rollup-darwin-x64,-linux-x64-gnu, …). Reusing anode_modules/lockfile generated on another OS/arch (e.g. Linux container) on macOS makes npm skip the current platform's binary →npm run devfails withCannot find module @rollup/rollup-darwin-x64(npm/cli#4828). Fix on the target machine:rm -rf node_modules package-lock.json && npm i.package-lock.jsonis gitignored — keep it machine-local. - Timeline
rowson the SSE wire: backendAgentTimelineVO.contentis a resolveString-keyed object (not part arrays) — don't switch unless the backend DTO is updated.sendMessagereturns{runId,status}synchronously; the rest arrives via SSE +afterSeqpulls. useTimelineStream.connect(sessionId, token)replaces state on session switch — call it in an effect keyed on the selected session id.
Backend conventions (apply when touching agent-sphere/)
数据库表通用字段 (common columns)
Every new table adds the shared status/audit columns, aligned with the sys_* tables (reference entities: SysRole, IdentityProvider, SsoIdentity):
status VARCHAR(20) NOT NULL DEFAULT 'ACTIVE', -- sys_* default
remark VARCHAR(500) NULL,
delete_flag -- logical delete, never hard-delete
created_by VARCHAR(100) NULL,
updated_by VARCHAR(100) NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW()Entity mapping (MyBatis-Plus AuditMetaObjectHandler fills these automatically):
private String status;
private String remark;
@TableField(fill = FieldFill.INSERT) private String createdBy;
@TableField(fill = FieldFill.INSERT_UPDATE) private String updatedBy;
@TableField(fill = FieldFill.INSERT) private LocalDateTime createdAt;
@TableField(fill = FieldFill.INSERT_UPDATE) private LocalDateTime updatedAt;
// when the table has delete_flag:
@TableLogic private Boolean deleteFlag;魔法值禁用 (no magic values)
Never inline raw strings/numbers in business logic. Reuse existing constants/enums by scope before declaring new ones: method-local → private static final on the class → module-wide constants class / enum (e.g. SsoConstants, SsoProviderType, AguiEventType, AguiConstants).
agent-sphere-ui (frontend)
Stack: UmiJS Max, React 19, antd 6, TypeScript (strict), Biome for lint+format, Tailwind v4 (via @tailwindcss/postcss), Jest. Node >=20. .npmrc sets legacy-peer-deps=true — required for install to resolve.
Commands (run inside agent-sphere-ui/):
npm run dev # dev server on :8000, MOCK=none, proxies /api -> backend:8080
npm run build # max build (hash + manifest + exportStatic)
npm run biome # biome check --write (auto-fix; run this first)
npm run lint # biome lint && tsc --noEmit (checks only, no write)
npm run tsc # typecheck only (tsc --noEmit)
npm test # jestVerify order: npm run biome → npm run lint → npm test.
Conventions / gotchas:
- Routing is config-based in
config/routes.ts, not file-based. Page dirs mirror backend domains:dashboard,chat,instances,model-providers,capabilities/{mcp,skill,cli,builtin},account,user. src/.umi/**is generated bymax dev/max setup(runs inprepare) — never hand-edit. Path alias@@/*resolves there.- Path aliases:
@/*→src/*,@@/*→src/.umi/*,@root/*→repo root. - Biome ignores
src/servicesandmock(seebiome.json). The hand-written API clientsrc/services/agentSphere/api.ts(usesBASE = '/api/v1') is therefore not linted — keep it tidy manually. - Biome style: single quotes, space indent,
jsxRuntime: reactClassic.noExplicitAnyanduseExhaustiveDependenciesare off. - Default locale
zh-CN;moment2dayjsrewrites moment→dayjs.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

