jcode
AGENTS.md41 starsChanged 3 months agoMITView on GitHub
Go coding agent — Eino + BubbleTea v2 TUI + React web UI + Tauri 2 desktop shell. The product UI is Re
- Installs packages
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 35,337 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.
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
28 rules. About 0 are common, 3 are distinctive, and 25 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
25
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 102
After publish: update minimumReleaseAgeExclude in all pnpm-workspace.yaml files to the new jcode-ui / jcode-ui-core versions (drop stale …
- Very specific: line 122
Use fmt.Errorf("tool_name: %w", err) for wrapped errors in non-tool code.
- Very specific: line 125
All file paths in tools must be resolved via env.ResolvePath(path).
- Very specific: line 130
Create func (e *Env) NewXxxTool() tool.InvokableTool on *Env
- Distinctive: line 133
If the tool is read-only, also add it to the plan-mode list
- Very specific: line 134
Approval policy: Read-only tools skip approval.
- Distinctive: line 137
Read-only tools (read, grep, glob, todoread, etc.): auto-approved
- Very specific: line 143
Follow standard Go conventions.
- Very specific: line 144
Use context.Context as the first parameter.
- Very specific: line 145
Prefer returning errors over panicking.
- Very specific: line 150
Use sync.RWMutex for shared state in tools (see TodoStore, BackgroundManager).
- Very specific: line 158
Create internal/tools/xxx.go with input struct + NewXxxTool() method on *Env
- Very specific: line 159
Add to buildAllTools()/buildPlanTools() in interactive.go and the inline tool lists in acp.go and web.go
- Distinctive: line 160
If read-only and useful in plan mode, also add to the plan-mode lists
- Very specific: line 162
If the tool needs external dependencies (like BackgroundManager), pass them as parameters to NewXxxTool()
- Very specific: line 166
Add a functional option WithXxx() following the WithCompaction, WithBudget, WithRecovery pattern
- Very specific: line 172
Create a new subcommand in internal/command/ if needed
- Very specific: line 176
Create internal/skills/builtin/{name}/SKILL.md with frontmatter (name, description, optional slash)
- Very specific: line 181
Add fields to the appropriate struct in internal/config/config.go
- Very specific: line 182
Use json:"field_name,omitempty" tags for optional fields
- Very specific: line 187
Run make generate to regenerate
- Very specific: line 201
Don't use
os.Exit()in library code: Only cmd/jcode/main.go should exit. - Very specific: line 202
Don't store mutable state in tool closures: Use *Env or pass state explicitly.
- Very specific: line 244
Test files follow xxx_test.go convention in the same package
- Very specific: line 262
Icons: use @heroicons/react/24/outline exclusively.
- Very specific: line 263
Icon sizing: use Tailwind h-N w-N classes (e.g.
- Very specific: line 264
Colors: every color must come from a CSS custom property (jcode-ui tokens / tokens.generated.css).
- Very specific: line 266
Reusable chat UI: import from the jcode-ui package (workspace:* in web/, registry range in site//examples/*).
≈ “Common” is an estimate: at least 1 in 5 of the 45,344 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
AGENTS.md — JCode Project Development Guide
Go coding agent — Eino + BubbleTea v2 TUI + React web UI + Tauri 2 desktop shell.
- Module:
github.com/cnjack/jcode| Entry:cmd/jcode/| Config dir:~/.jcode/
Quick Start
make build # generate → build-web → go build
make install # generate → build-web → go install
make run # go run ./cmd/jcode/
make lint # golangci-lint + React typecheck (lint-go / lint-web)
make doctor # system check
make desktop-dev # Tauri desktop app in dev mode (rebuilds the Go sidecar first)
make desktop-build # distributable desktop bundle (.app/.dmg/.msi)
make build-ble # optional jcode-ble helper (BLE is a separate binary by design)make build-webrequirespnpm. Frontend builds tointernal/web/dist/.make generaterunsgo generateforinternal/model/...(fetches models.dev data →registry_generated.go) andinternal/theme/...(palette → web CSS/TS tokens). Never edit generated files by hand.- Build injects
Version,BuildTime,GitCommitvia ldflags intointernal/command.
Architecture Overview
cmd/jcode/ # Entry: cobra root (interactive) + subcommands; native-messaging host detour
cmd/jcode-ble/ # BLE helper binary (spawned by the main binary; keeps CoreBluetooth out of jcode)
internal/
command/ # Subcommand implementations + interactive session orchestration + tool wiring
agent/ # ChatModelAgent factory + middleware chain
runner/ # Agent run loop + event bus + approval tiering
handler/ # AgentEventHandler interface (TUI / ACP / Web implementations)
tools/ # All built-in tools + Executor/Env abstraction
model/ # OpenAI-compatible chat model + model registry (build-time generated)
config/ # JSON config loader + logger
prompts/ # System/plan prompts + AGENTS.md injection + env info
session/ # JSONL session recording/replay
skills/ # Skill loader (builtin → user → project override chain)
team/ # Multi-agent team coordination
mode/ # Unified session mode (Ask / Plan / Autopilot) shared by all transports
automation/ # Scheduled/manual agent runs (each run = a tagged session)
browser/ # Browser use: managed Chrome (CDP) + extension WS bridge + native-messaging host
remote/ # SSH / Docker connection helpers (UI-agnostic; /api/remote/*)
channel/ # External messaging channels (e.g. WeChat push)
theme/ # Single source of truth for built-in themes (generates web CSS/TS)
usage/ # Token-usage recording + aggregation (stats views)
feature/ # Compile-time feature flags via build tags (e.g. desktop, jcode_headless, ble)
telemetry/ # Optional Langfuse tracing
tui/ # BubbleTea v2 TUI components
web/ # HTTP server (REST + WS + PTY) + embedded React dist
web/ # React 18 + Vite + RTK product UI (embedded in the binary / Tauri)
packages/ # publish source for the jcode-ui npm packages (still in root pnpm workspace)
jcode-ui/ # styled React chat components → npm: jcode-ui
jcode-ui-core/ # types, ChatRuntime, headless primitives → npm: jcode-ui-core
site/ # React + Vite marketing/docs site → www.j-code.net (docs markdown in site/docs/)
desktop/ # Tauri 2 desktop shell; the Go binary runs as a sidecar
extension/ # jcode Browser Bridge Chrome extension (MV3) for the browser-use extension backend
internal-doc/ # Internal design docs (NOT published; site/docs is the published documentation)
script/ # Build-time code generation + install.sh
agent-eval/ # Agent evaluation harness + showcase generationFrontend (React)
The product UI is React 18 (web/). Internal consumers — web/ and packages/jcode-ui — link jcode-ui / jcode-ui-core via the workspace:* protocol so the monorepo co-evolves and make build-web builds from local source (not the published tarballs). External consumers — site/, examples/* — use registry version ranges.
make build-webtypechecks/builds packagedist/then builds the React app →internal/web/dist/(production embed).make lint-webtypechecks the React app + both packages.- Go
//go:embed dist/*and TaurifrontendDistboth point atinternal/web/dist/. - Internal deps use
workspace:*(web/package.json→jcode-ui/jcode-ui-core;packages/jcode-ui→jcode-ui-core). External consumers (site/,examples/*) declare registry ranges, e.g."jcode-ui": "^0.4.1","jcode-ui-core": "^0.4.0". - Inside
packages/jcode-ui, depend on core viaworkspace:*— neverfile:../jcode-ui-core(afile:link baked into the publishedjcode-uitarball brokejcode-ui@0.1.0on npm).
See packages/jcode-ui/README.md and site/docs/chat-ui/. Published: jcode-ui (styled) + jcode-ui-core (headless). The runtime abstraction (ChatRuntime + createExternalStoreRuntime) is the seam that lets the components render from any Redux-shaped store.
Publishing jcode-ui to npm
Order matters: publish jcode-ui-core first, then jcode-ui.
# 1) bump versions in packages/*/package.json as needed
# 2) build
cd packages/jcode-ui-core && pnpm build
cd ../jcode-ui && pnpm build
# 3) publish (2FA/OTP may be required)
cd packages/jcode-ui-core && npm publish --access public --otp=XXXXXX
cd ../jcode-ui && npm publish --access public --otp=XXXXXXAfter a successful publish, bump the external consumer deps (site/, examples/*) to the new range and run pnpm install (and cd site && pnpm install for the site workspace). Also refresh minimumReleaseAgeExclude entries in every pnpm-workspace.yaml (root, site/, examples/*) so the newly published versions are not blocked by release-age checks. web/ needs no bump — it links local source via workspace:* and picks up packages/ edits on the next make build-web.
Checklist before publish:
jcode-ui→jcode-ui-coreusesworkspace:*locally (neverfile:); only external consumers (site/,examples/*) carry registry ranges- Both packages have fresh
dist/(pnpm build) - Smoke:
npm install jcode-ui@<ver>in a temp dir imports both packages and pulls core transitively - After publish: update
minimumReleaseAgeExcludein allpnpm-workspace.yamlfiles to the newjcode-ui/jcode-ui-coreversions (drop stale entries)
Key Design Decisions
- Three transports, one interface: TUI, ACP (JSON-RPC), and Web all implement
AgentEventHandler. New transports only need to implement this interface. - Middleware chain in
agent/: Ordered outermost→innermost: langfuse → budget → compaction → recovery → approval. Approval is always innermost — never add middleware after it. - Tools are methods on
*Env: Each tool is created viaenv.NewXxxTool(), receives the sharedEnvfor file I/O and command execution. This enables transparent local/SSH switching. - Eino framework: We use cloudwego/eino
adk.ChatModelAgent— not raw LLM calls. Follow Eino'stool.InvokableTool+schema.ToolInfopatterns.
Conventions (MUST follow)
Logging & Output
- All diagnostics go to
config.Logger()(writes to~/.jcode/debug.log). Never usefmt.Print,log.Print, or write to stdout/stderr directly — the TUI owns stdout. - Tool execution errors are returned as plain strings (the agent reads them). Do NOT
panicorlog.Fatalin tool code. - Exclude the script/ directory from the linter — it contains code generation scripts that may not follow all conventions.
Error Handling
- Tools return
(string, error). Return descriptive error strings that help the agent self-correct. Include file paths, line numbers, or command output in error messages. - Use
fmt.Errorf("tool_name: %w", err)for wrapped errors in non-tool code.
File Paths
- All file paths in tools must be resolved via
env.ResolvePath(path). This handles relative→absolute conversion and logs warnings for paths escaping the working directory. - Store and pass absolute paths internally. Only accept relative paths at the tool input boundary.
Tool Development Pattern
- Define
XxxInputstruct withjsontags - Create
func (e *Env) NewXxxTool() tool.InvokableToolon*Env - Build
schema.ToolInfowithschema.NewParamsOneOfByParams(...)— useschema.String,schema.Integer,schema.Boolean,schema.Array - Register it in all three transports:
buildAllTools()/buildPlanTools()ininternal/command/interactive.go, and the inlineall/plantool lists inacp.goandweb.go - If the tool is read-only, also add it to the plan-mode list
- Approval policy: Read-only tools skip approval. Mutating tools require approval unless
AutoApproveis set. Match existing patterns ininternal/runner/approval.go(browser tools additionally tier by action/origin there).
Approval Policy
- Read-only tools (read, grep, glob, todoread, etc.): auto-approved
- Mutating tools (edit, write, execute): require user approval
- Execute exceptions: background commands and safe prefixes (
ls,cat,echo,which,git status,git log, etc.) are auto-approved switch_env: always requires approval
Code Style
- Follow standard Go conventions. The linter config (
.golangci.yml) enforces:errcheck,govet,staticcheck,unused,revive,gocritic,funlen(max 800 lines/600 statements). - Use
context.Contextas the first parameter. Thread cancellation properly. - Prefer returning errors over panicking. Only
panicfor truly unrecoverable programmer errors. - Interfaces live in the package that consumes them (e.g.,
AgentEventHandlerinhandler/,Executorintools/).
Concurrency
AgentEventHandlerimplementations must be goroutine-safe — the runner may call methods from multiple goroutines simultaneously.- Use
sync.RWMutexfor shared state in tools (seeTodoStore,BackgroundManager). - Channel-based coordination in
cmd/jcode/main.go— the main event loop usesfor/selectover typed channels.
How To: Common Tasks
Add a New Tool
- Create
internal/tools/xxx.gowith input struct +NewXxxTool()method on*Env - Add to
buildAllTools()/buildPlanTools()ininteractive.goand the inline tool lists inacp.goandweb.go - If read-only and useful in plan mode, also add to the plan-mode lists
- Set appropriate approval requirements following the approval policy above
- If the tool needs external dependencies (like
BackgroundManager), pass them as parameters toNewXxxTool()
Add a New Middleware
- Implement
adk.ChatModelAgentMiddlewareininternal/agent/ - Add a functional option
WithXxx()following theWithCompaction,WithBudget,WithRecoverypattern - Wire it up in
internal/command/interactive.gowhere the agent is constructed - Insert before approval in the middleware chain — approval must remain innermost
Add a New Handler (Transport)
- Implement
handler.AgentEventHandlerinterface ininternal/handler/ - Create a new subcommand in
internal/command/if needed - The interface is the only contract — keep handler logic independent of agent internals
Add a Builtin Skill
- Create
internal/skills/builtin/{name}/SKILL.mdwith frontmatter (name,description, optionalslash) - It will be automatically embedded via
//go:embed builtinand loaded byskills.Loader - Skill override chain (later wins): builtin →
~/.agents/skills/→~/.jcode/skills/→.jcode/skills/
Modify Config Schema
- Add fields to the appropriate struct in
internal/config/config.go - Use
json:"field_name,omitempty"tags for optional fields - Config is a flat JSON file at
~/.jcode/config.json— keep it backward-compatible
Modify Model Registry
internal/model/registry_generated.gois auto-generated — editscript/generate_models.goinstead- Run
make generateto regenerate
Write Documentation
- Published docs live in
site/docs/**/*.md(rendered at https://www.j-code.net/docs by the React site insite/). Pages need front-mattertitle+nav_order(+parentfor children) to appear in the nav. - Internal design docs (PRDs, design notes, research) go in
internal-doc/— never insite/docs/. - Doc screenshots live in
site/docs/asset/(for GitHub rendering) andsite/public/docs-asset/(served by the site) — keep both copies in sync.
Things to Avoid
- Don't write to stdout/stderr. The TUI controls the terminal. Use
config.Logger()for debug output. - Don't add middleware after approval. The approval middleware must be the innermost handler in the chain.
- Don't manually edit
registry_generated.go. It's overwritten bymake generate. - Don't use
os.Exit()in library code. Onlycmd/jcode/main.goshould exit. - Don't store mutable state in tool closures. Use
*Envor pass state explicitly. Tools may be re-created across mode transitions (normal ↔ plan). - Don't skip
env.ResolvePath(). Raw path concatenation can escape the working directory without warning. - Don't import
internal/tuifrom non-TUI packages. The handler interface is the decoupling boundary. - Don't depend on
jcode-ui/jcode-ui-coreviafile:. Internal links (web/,packages/jcode-ui→core) useworkspace:*; external consumers (site/,examples/*) use registry version ranges. - Don't let tests read the real HOME. The pre-push hook runs the full suite; tests must
t.Setenv("HOME", t.TempDir())whenever code under test resolvesconfig.ConfigDir()(a real~/.jcode/AGENTS.mdbreaksinternal/prompts).
Cloud relay (internal/cloud/)
jcode can log into jcloud (device code) and be remote-controlled via an
outbound-only relay; design contract lives in the cloud repo
(docs/17-jcode-device-relay.md). Durable rules:
- Layout:
credentials.go(~/.jcode/cloud.json, 0600),client.go(transport, 32MB response cap — attachment commands are large),connector.go+supervisor.go(lifecycle, runtime auto_connect toggle),events.go(WS event pump: durable vs ephemeral classification +agent_messagesynthesis),sessions.go(index + capabilities mirror),crypto.go(CEK, AES-256-GCM envelopes, P-256 ECIES, BIP39),pairing_inbox.go(pairing approvals; QR offers auto-approve). - E2EE is the default. Session content, metadata, command bodies/results,
and other content-bearing relay payloads are sealed once a CEK exists; gray
plaintext content is only for pre-CEK or
cloud.e2ee:false. Plaintext is limited to routing metadata required by the orchestrator: ids, seq, kind, timestamps (includinglast_activity_at), and online state. Never add a content-bearing uplink path that bypassessealUplink/openDownlink. - The connector is a client of the local control plane (
/api/*on loopback) — it must never change engine behavior or blockjcode web; failures log and back off (≤60s). - Contract changes are cross-repo: bump the cloud orchestrator first
(strict decode rejects unknown fields), keep
docs/17in sync, and extend the matching e2e journey in the cloud repo (e2e/j7–j11). - Cross-implementation crypto vectors live outside the repos at
jcode-cloud-relay/shared/test-vectors.json;TestSharedVectorsFileskips cleanly when the sibling dir is absent.
Testing
- Run tests:
go test ./... - Test files follow
xxx_test.goconvention in the same package - For tool tests, use
NewEnv()with a temp directory to isolate file operations - Lint is mandatory:
make lintmust pass before any PR
Frontend (web/) — React (production)
- Stack: React 18 + TypeScript + Vite + Redux Toolkit + npm
jcode-ui/jcode-ui-core - Build:
make build-web(package typecheck/build +cd web && npx vite build) - Output: builds to
internal/web/dist/, embedded in the Go binary via//go:embed - Lint:
make lint-web(tsc for web + packages) - Changes to the product UI (
web/) require rebuilding viamake build-webfor the Go binary to pick them up - Changes to the chat library (
packages/jcode-ui*) are picked up byweb/immediately viaworkspace:*(rebuild withmake build-web); onlysite//examples/*need npm publish + version bump +pnpm install - Don't confuse
web/withsite/:web/is the product UI embedded in the binary and reused by the desktop app;site/is the public website + docs at www.j-code.net and is deployed separately (cd site && pnpm build).
Icons & Styling
- Icons: use
@heroicons/react/24/outlineexclusively. Import each icon by name. Do not hand-write inline<svg>icons. - Icon sizing: use Tailwind
h-N w-Nclasses (e.g.className="h-3.5 w-3.5"). - Colors: every color must come from a CSS custom property (jcode-ui tokens /
tokens.generated.css). Never hardcode hex/rgb/#fff/whitein components. - Themes: edit
internal/theme/palette.goand runmake generate— never edittokens.generated.cssorthemes.generated.tsby hand. - Reusable chat UI: import from the
jcode-uipackage (workspace:*inweb/, registry range insite//examples/*); implement/fix library code underpackages/jcode-uiand publish for external consumers. - Product composer: the desktop input experience (
ChatInput+WorkspacePicker/BranchPicker/GoalBanner) lives inpackages/jcode-ui/src/product/and is consumed asjcode-ui/product. The components are Redux/fetch/Tauri/i18next-free — hosts inject aProductComposerHost(state + actions + strings + icons); the web adapter isweb/src/app/composerHost.ts. Package tests:cd packages/jcode-ui && pnpm test(vitest).
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.

