# xcode **Repository Path**: xywhsoft/xcode ## Basic Information - **Project Name**: xcode - **Description**: 一个基于浏览器的 AI 代码编写 Agent - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-22 - **Last Updated**: 2026-07-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # xcode v2 `xcode` is a practical C coding-agent CLI built on the sibling `xrt`, `xllm`, and `xwork` repositories. The v2 mainline starts with the smallest useful product loop: resume a durable session, stream a reasoning model, execute workspace tools, compact long context transactionally, and continue until the requested development task is verified. The previous broad implementation remains under `dev/v1` for reference. ## Stack ```text xcode CLI, config, terminal rendering, interactive chat, Ctrl+C -> xwork agent loop, tools, policy, artifacts, compaction scheduling -> xllm-session context ledger, token budgets, journal/recovery, compaction -> xllm provider request, HTTP streaming, SSE/tool-call normalization -> xrt HTTP/1.1, TLS, filesystem, subprocess, platform runtime ``` All four layers are C. HTTP/2 is intentionally outside the current milestone. ## Default GLM Coding Plan profile The default profile uses: - endpoint: `https://open.bigmodel.cn/api/coding/paas/v4`; - model: `glm-5.1`; - context window: 204,800 tokens; - maximum output: 131,072 tokens; - output reserve: 32,768 tokens, separate from the per-call maximum; - safety reserve: dynamic 3%, clamped to 8K–32K (8K at this window); - input budget: 164,032 tokens after output and safety reserves; - per-call `max_tokens`: dynamically capped by the remaining context, while short requests retain the full 131,072-token ceiling; - soft tool-output pruning at 75% pressure; - transactional summary compaction at 95% pressure; - no hard Agent-turn limit; - 64 KiB inline tool output, with larger results saved under `.xcode/artifacts`; - transactional multi-file patching, managed long-running processes, structured permissions, and tool hooks; - a default completion gate that requires a successful verification command after the latest write; - incremental session journal plus atomic checkpoints for process-crash recovery. The Coding Plan endpoint and model are based on the current [Zhipu Coding Plan FAQ](https://docs.bigmodel.cn/cn/coding-plan/faq) and [GLM-5.1 configuration guide](https://docs.bigmodel.cn/cn/coding-plan/using5-1). Hosts may override every value. ## Build From this repository on Windows with GCC available: ```bat build.bat ``` On Linux or macOS with the sibling repositories next to this one: ```sh sh build.sh ``` The POSIX build accepts `CC`, `CFLAGS`, `LDFLAGS`, `LIBS`, `XRT_DIR`, `XLLM_DIR`, and `XWORK_DIR`. Set `RUN_TESTS=0` for a cross build whose binaries cannot run on the build host. The build uses `-Wall -Wextra -Werror -O2`, links all four current sibling mainlines, and validates `version`, `help`, and config-driven `status` behavior. ## Configure authentication The key is resolved in this order: 1. the environment variable named by `provider.api_key_env` (default `ZHIPU_API_KEY`); 2. `GLM_API_KEY` as a compatibility fallback; 3. `.xcode/secrets.local.json` in the workspace. Example environment setup in PowerShell: ```powershell $env:ZHIPU_API_KEY = Read-Host "Zhipu API key" ``` Example local secret file (automatically ignored when it is under the xcode repository root; project repositories should also ignore it): ```json { "api_key": "your-key" } ``` The CLI never prints the key. An owned in-memory copy is cleared when the app shuts down. Copy [xcode.config.example.json](xcode.config.example.json) to `/.xcode/config.json` to customize the provider, budgets, persistence, approval policy, and loop guards. Command-line options override the file. ## Use One-shot autonomous run: ```powershell build\xcode.exe run -C D:\GIT\project -- "Analyze the project, implement the requested feature, run tests, and fix failures." ``` Interactive session that resumes the same context: ```powershell build\xcode.exe chat -C D:\GIT\project ``` Inspect effective configuration and persisted context without calling the provider: ```powershell build\xcode.exe status -C D:\GIT\project ``` Validate workspace access, provider configuration, token budgets, authentication source, artifact storage, and durable-session recovery without sending a model request: ```powershell build\xcode.exe doctor -C D:\GIT\project ``` Force a real model-generated summary checkpoint and atomically persist the compacted session: ```powershell build\xcode.exe compact -C D:\GIT\project ``` Resume a process-interrupted run without appending the user prompt a second time: ```powershell build\xcode.exe continue -C D:\GIT\project ``` `status` reports `continuation: pending_tools`, `model`, or `idle`. Use `continue` for the first two states. Pending side effects have at-least-once recovery semantics: if a tool completed but its result was not journaled before the process stopped, policy checks run again and the call may be retried. Useful controls: - `--new-session` starts fresh instead of recovering `.xcode/session.json` and its journal; - `--session PATH` selects a different durable session; - `--show-reasoning` renders reasoning deltas to stderr; - `--events PATH` writes a versioned `xcode.event.v1` JSONL audit stream while retaining normal terminal output; - `--ask` requires terminal confirmation for writes and commands; - `--read-only` rejects writes and commands; - `--max-turns N` adds an explicit hard cap; `0` remains unlimited; - `compact` (or `/compact` in chat) forces a safe-prefix summary checkpoint for continuation testing; - `continue` recovers an interrupted model/tool loop without duplicating user input; - Ctrl+C requests cooperative cancellation of the active model/tool loop. `exec_command` is a real shell process whose working directory starts inside the workspace; it is not an OS sandbox. Use `--ask` or `--read-only` when commands are not fully trusted. ## Current milestone boundary Implemented now: a stable single-agent coding loop, journal-backed crash recovery, durable multi-turn chat, dynamic long-context handling, eleven workspace/process tools, transactional patch rollback, structured permission and hook boundaries, write-after-verification completion gating, versioned JSONL events, offline readiness diagnostics, artifacts, and safe configuration/secret handling. Deferred until the coding loop is proven on the xlang acceptance task: TUI/IDE surfaces, MCP, semantic memory, multi-agent graphs, remote workers, and deterministic replay.