原汁原昧 Claude Code 可运行,可构建, 可调试版; 生产级工程化, 企业级可靠性; 安全无毒, 内存泄露修复
Go to file
2026-05-28 21:42:10 +08:00
.claude merge: sync upstream/main while preserving local brand/config 2026-04-29 09:06:20 +08:00
.github/workflows ci(publish-npm): remove --ignore-scripts from publish command 2026-05-15 11:17:07 +08:00
.husky fix: pre-commit hook 改用 bunx 替代 npx 避免 npm arborist 兼容问题 2026-05-13 17:56:18 +08:00
.vscode chore: 添加 VSCode 推荐扩展列表并固定 Bun 运行时版本 2026-05-01 22:28:34 +08:00
docs 1. 增加统计信息并上报逻辑,用于对账;2. 上报失败超过最大重试次数的消息记录到dead letter jsonl中 2026-05-27 10:49:21 +08:00
learn chore: 清理临时 rebase 脚本 2026-05-13 10:29:34 +08:00
packages fix(search-extra-tools): return input schema in discover mode results 2026-05-21 16:14:00 +08:00
scripts chore(release): bump version to 4.1.4 2026-05-21 06:28:24 +00:00
spec Revert "feat: 添加 GBK 编码自动检测支持,文件读写工具透明处理非 UTF-8 文件" 2026-05-10 22:57:30 +08:00
src 1. 修复统计消息上报时的日期格式;2.修复对.cluade目录会话jsonl格式上的理解错误 2026-05-28 21:42:10 +08:00
teach-me Fix mintlify validate errors (#367) 2026-04-26 11:07:20 +08:00
tests chore: 合并社区 upstream/main 代码至 v2.4.2 2026-05-12 11:55:04 +08:00
vendor style: 完成所有文件的lint 2026-05-01 21:39:30 +08:00
.dockerignore feat: 支持自托管的 remote-control-server (#214) 2026-04-09 17:40:50 +08:00
.editorconfig style: 完成所有文件的lint 2026-05-01 21:39:30 +08:00
.gitignore fix: restore package.json, bun.lock and .gitignore from verified commit 2026-05-12 16:15:26 +08:00
.impeccable.md feat: ACP 协议版本 remote control (#293) 2026-04-18 21:54:22 +08:00
.mintignore fix: 修复 mintlify ignore, 修复侧边栏 2026-04-10 18:14:07 +08:00
.npmrc Revert "Merge pull request #60 from y574444354/feat/migrate-review-agents" 2026-05-12 12:11:37 +08:00
.tool-versions chore: 添加 VSCode 推荐扩展列表并固定 Bun 运行时版本 2026-05-01 22:28:34 +08:00
AGENTS.md chore: 清理仓库审计问题——修正 CLAUDE.md、删除冗余 yoga-layout、清除 621 个未使用的类型 stub (#354) 2026-04-25 08:54:18 +08:00
biome.json style: 修复所有 lint 错误,覆盖 @ant forked 代码 2026-05-01 21:49:21 +08:00
build.ts refactor: dev.ts 和 build.ts 统一从 defines.ts 导入 feature flags 2026-05-18 17:28:16 +08:00
bun.lock 修复LLM response中构建diff不完善的问题 2026-05-25 19:13:47 +08:00
bunfig.toml feat: 搭建单元测试基础设施 — Bun test runner + 示例测试 2026-04-01 02:08:38 +08:00
CHANGELOG.md chore: bump version to 4.0.15 and update CHANGELOG 2026-05-12 15:10:39 +08:00
CLAUDE.md chore: 合并社区 upstream/main 代码至 v2.4.2 2026-05-12 11:55:04 +08:00
codecov.yml chore: 添加 CI 配置、codecov 和测试 mock 基础设施 2026-05-09 23:04:04 +08:00
contributors.svg docs: update contributors 2026-05-18 00:32:15 +00:00
DEV-LOG.md feat: 远程群控 (#243) 2026-04-11 23:22:55 +08:00
docs.json chore: 合并社区 upstream/main 代码至 v2.4.2 2026-05-12 11:55:04 +08:00
Friends.md docs: 新增留影文档 2026-04-06 11:04:13 +08:00
knip.json style: 完成所有文件的lint 2026-05-01 21:39:30 +08:00
mint.json feat: 恢复 --channels 能力 (#297) 2026-04-19 10:24:34 +08:00
package.json 修复LLM response中构建diff不完善的问题 2026-05-25 19:13:47 +08:00
progress.md fix: 优化压缩错误消息和自动压缩提示的可理解性 2026-05-05 07:19:19 +08:00
quickSort.ts feat(costrict): add depthGuard agent and refine strictPlan/strictSpec workflow 2026-04-10 21:42:53 +08:00
README_EN.md Fix mintlify validate errors (#367) 2026-04-26 11:07:20 +08:00
README.md Fix formatting in README.md links section 2026-04-28 11:53:30 +08:00
SECURITY.md Create SECURITY.md 2026-04-01 08:54:08 +08:00
tsconfig.base.json feat: 重构供应商层次 (#286) 2026-04-17 09:33:14 +08:00
tsconfig.json feat: 修复 serve 模式新建会话及消息读取问题 2026-05-09 17:35:05 +08:00
V6.md chore: 清理临时 rebase 脚本 2026-05-13 10:29:34 +08:00
vite.config.ts feat: ai 的随机修复 2026-05-05 19:36:38 +08:00

CoStrict

Enterprise-Grade AI Programming Assistant · Terminal Native

Quick Start · Architecture · Deployment · API Protocol · CoStrict Modules


What is CoStrict

CoStrict is a free open-source AI-assisted programming tool designed for enterprise development scenarios. Supports self-hosted deployment, making it the best choice for organization-level secure and standardized AI development workflows.

Capability Description
CoStrict Enterprise Auth OAuth 2.0 + Casdoor SSO, automatic Token refresh, device fingerprint binding
8 API Protocols CoStrict / Anthropic / OpenAI / Gemini / Grok / Bedrock / Vertex / Foundry
53+ Built-in Tools File I/O, Shell execution, Web search, Agent orchestration, MCP extensions — ready to use
16 Structured Agents Strict requirement analysis → architecture design → task planning → coding → verification full pipeline
Self-hosted Deployment Remote Control Server (Docker) + Bridge Mode, data stays within internal network
Feature Flag System 19+ default features + environment variable hot-switches, enable on-demand without code changes
Security & Compliance Tiered permission modes, Policy gateway, Worktree isolation, audit logs
Cross-platform macOS / Windows / Linux, Computer Use + Chrome Use dual-channel UI automation

Quick Start

Installation

bun i -g @costrict/xxx
csc

From Source

Requirements: Bun >= 1.2.0

git clone https://github.com/y574444354/csc.git
cd csc
bun install
bun run dev       # Version shows 888 when successful
bun run build     # Production build → dist/cli.js + chunk files

First-time Login

After starting, enter /login in the REPL. CoStrict provides two authentication options:

1. CoStrict Enterprise Login (Recommended)

Browser opens CoStrict OAuth page automatically. After SSO login, credentials are written automatically:

/login → Select CoStrict → Browser SSO login → Auto-complete
  • Authentication service: https://zgsm.sangfor.com/oidc-auth
  • Credential storage: ~/.claude/csc-auth.json (0600 permissions)
  • Auto refresh: Three-layer Token validation + preventive refresh + 401 reactive recovery

2. Third-party API Direct Connection

Select Anthropic Compatible / OpenAI / Gemini and fill in Base URL and API Key:

Field Description Example
Base URL API service URL https://api.example.com/v1
API Key Authentication key sk-xxx
Haiku Model Fast model claude-haiku-4-5-20251001
Sonnet Model Balanced model claude-sonnet-4-6
Opus Model High-performance model claude-opus-4-6

You can also edit ~/.claude/settings.json directly:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.example.com/v1",
    "ANTHROPIC_AUTH_TOKEN": "sk-xxx",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-4-5-20251001",
    "ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-4-6",
    "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-4-6"
  }
}

CoStrict Specific Modules

Enterprise Authentication (src/costrict/provider/)

Module Responsibility
auth.ts OAuth 2.0 login flow: browser redirect, Token polling, credential save
credentials.ts Credential management: read/write csc-auth.json, device fingerprint SHA256 generation
token.ts Token lifecycle: JWT parsing, three-layer validation, auto-refresh
fetch.ts Request middleware: dynamic Authorization + custom Headers injection, preventive/reactive Token refresh
oauth-params.ts OAuth parameter construction: Casdoor provider identifier, plugin version, URI Scheme
models.ts Dynamic model list: fetch available models from AI Gateway, 1-hour cache
modelMapping.ts Model name resolution: 5-level priority mapping Anthropic model names to CoStrict model IDs
index.ts Query entry: reuse OpenAI compatible path, inject CoStrict fetch and baseURL

Token Refresh Strategy:

Request start → Read credentials → Token expired?
  ├─ No → Normal request (inject Authorization + X-Costrict-* headers)
  └─ Yes → refresh_token refresh → Success?
       ├─ Yes → Update credentials → Normal request
       └─ No → Try with old Token → 401?
            ├─ Yes → Refresh again → Retry request
            └─ No → Return original response

Model Name Resolution Priority:

  1. Passed model is already a known CoStrict model ID (user explicitly selected via /model)
  2. COSTRICT_MODEL environment variable (admin global override)
  3. COSTRICT_DEFAULT_{HAIKU|SONNET|OPUS}_MODEL environment variables (by family mapping)
  4. First available model from cached model list
  5. Pass through original model name (fallback)

Structured Agents (src/costrict/agents/)

CoStrict provides strictly phased Agent orchestration covering the full pipeline from requirements to delivery:

Agent Phase Responsibility
strictSpec Requirements Requirement clarification → architecture design → task planning → execution (four-stage workflow)
requirement Requirements User requirements → structured system requirements document
designAgent Design Requirements document → C4 Model architecture design
taskPlan Planning Requirements + design → high-level task planning
strictPlan Planning User requirements → actionable implementation plan
subCoding Coding Efficient low-cost code implementation
taskCheck Verification Task quality check and improvement
tddTestDesign Testing Functional requirements → test case design
tddTestPrepare Testing Test environment preparation
tddRunAndFix Testing Execute verification → auto-fix
tddTestAndFix Testing Test execution and diagnostic repair
codeReviewSecurity Security Code security audit
quickExplore Exploration Quick project exploration and code understanding
wikiProjectAnalyze Documentation Project classification analysis
wikiCatalogueDesign Documentation Document structure design
wikiDocumentGenerate Documentation Technical document generation
wikiIndexGeneration Documentation Index document generation

StrictSpec Full Pipeline Orchestration:

User requirements → StrictSpec
  ├─ Stage 1: Requirement → Structured requirements document
  ├─ Stage 2: DesignAgent → C4 Model architecture design
  ├─ Stage 3: TaskPlan → Task planning
  └─ Stage 4: SubCoding → Code implementation

CoStrict Skills (src/costrict/skill/)

Skill Description
projectWiki Project documentation system generation (analysis → design → generation → indexing)
tdd TDD full pipeline (design → prepare → execute → fix)
builtin Built-in skill registration and indexing

Multi-API Protocol Compatibility

CoStrict uses stream adapter pattern to convert all API protocols to internal unified format, with zero downstream code changes.

Protocol Enable Method Use Case
CoStrict /login select CoStrict or CLAUDE_CODE_USE_COSTRICT=1 Enterprise SSO + AI Gateway dynamic models
Anthropic Default Native Messages API
OpenAI CLAUDE_CODE_USE_OPENAI=1 Ollama / DeepSeek / vLLM
Gemini CLAUDE_CODE_USE_GEMINI=1 Google Gemini API
xAI Grok CLAUDE_CODE_USE_GROK=1 xAI Grok API
AWS Bedrock CLAUDE_CODE_USE_BEDROCK=1 AWS Bedrock
Google Vertex CLAUDE_CODE_USE_VERTEX=1 Vertex AI
Foundry CLAUDE_CODE_USE_FOUNDRY=1 Anthropic Foundry

Architecture Overview

┌───────────────────────────────────────────────────────────┐
│  CLI Entry (cli.tsx) — 12 quick paths + main.tsx full CLI │
├───────────────────────────────────────────────────────────┤
│  REPL Conversation Loop                                    │
│  REPL.tsx → QueryEngine → query() → API Client            │
│  Streaming responses · Tool orchestration · Context       │
│  compression · Memory management                           │
├───────────────┬───────────────────────────────────────────┤
│  CoStrict     │         Generic Tool Layer                │
│  ┌──────────┐ │  ┌─────────────────────────────────────┐  │
│  │ Provider  │ │  │ 53+ Built-in Tools                  │  │
│  │  OAuth    │ │  │ File / Shell / Agent / Web / MCP   │  │
│  │  Token    │ │  │ Cron / Worktree / LSP / Skill      │  │
│  │  Fetch    │ │  └─────────────────────────────────────┘  │
│  │ Models    │ ├───────────────────────────────────────────┤
│  │ Mapping   │ │         Agent Orchestration Layer         │
│  └──────────┘ │  ┌─────────────────────────────────────┐  │
│  ┌──────────┐ │  │ CoStrict Agents (16)                │  │
│  │ Agents   │ │  │ StrictSpec · TDD · Wiki · Security  │  │
│  │  (16)    │ │  └─────────────────────────────────────┘  │
│  └──────────┘ │  ┌─────────────────────────────────────┐  │
│  ┌──────────┐ │  │ Generic Agents                      │  │
│  │ Skills   │ │  │ AgentTool · Team · Coordinator      │  │
│  │  (3)     │ │  │ Fork Subagent · Worktree isolation  │  │
│  └──────────┘ │  └─────────────────────────────────────┘  │
├───────────────┴───────────────────────────────────────────┤
│  API Compatibility Layer (8 protocols) → Unified stream  │
│  adapter → Zero downstream code changes                   │
├───────────────────────────────────────────────────────────┤
│  Infrastructure                                            │
│  Feature Flag · Daemon · Bridge/RCS · Voice Mode          │
│  BG Sessions · Policy gateway · Sentry · GrowthBook       │
└───────────────────────────────────────────────────────────┘

CLI Quick Paths

Command Description Feature Gate
--version Version output: 4.0.1 (CoStrict)
--claude-in-chrome-mcp Chrome browser control MCP
--computer-use-mcp Computer Use MCP CHICAGO_MCP
rc / bridge / remote-control Bridge mode BRIDGE_MODE
daemon Daemon mode DAEMON
ps / logs / attach / kill Background session management BG_SESSIONS
new / list / reply Template tasks TEMPLATES
environment-runner BYOC environment runner BYOC_ENVIRONMENT_RUNNER
self-hosted-runner Self-hosted runner SELF_HOSTED_RUNNER
--tmux + --worktree Tmux workspace isolation
Default path Full REPL CLI

Tool System

Built-in Tools Classification

Category Tools Description
File Operations FileReadTool FileEditTool FileWriteTool GlobTool GrepTool Code read/write and search
Shell Execution BashTool PowerShellTool REPLTool Command execution and interactive REPL
Agent Collaboration AgentTool TaskCreateTool TaskUpdateTool TaskListTool TaskGetTool TaskOutputTool TaskStopTool Multi-Agent task orchestration
Team Orchestration TeamCreateTool TeamDeleteTool SendMessageTool Agent Team orchestration
Planning & Verification EnterPlanModeTool ExitPlanModeTool VerifyPlanExecutionTool Structured planning and verification
Web & Network WebFetchTool WebSearchTool WebBrowserTool Web page fetching/search/browser automation
MCP Extensions MCPTool McpAuthTool ListMcpResourcesTool ReadMcpResourceTool Model Context Protocol
Scheduling & Cron CronCreateTool CronDeleteTool CronListTool Cron scheduled tasks
Workspace EnterWorktreeTool ExitWorktreeTool Git Worktree isolation
Interaction Helpers AskUserQuestionTool TodoWriteTool SkillTool ToolSearchTool DiscoverSkillsTool ConfigTool User interaction and configuration
Development Assist LSPTool NotebookEditTool BriefTool LSP / Notebook / session summary
Remote Trigger RemoteTriggerTool MonitorTool Remote Agent trigger and monitoring
Advanced Features SleepTool SnipTool WorkflowTool TungstenTool Proactive / workflows / experimental

MCP Extensions

csc mcp serve     # Start MCP server
csc mcp add       # Add MCP service
csc mcp list      # List configured services

Feature Flag System

All features are enabled on-demand via FEATURE_<FLAG_NAME>=1 environment variables.

Default Enabled (Dev + Build)

Priority Feature Description
Core BUDDY Pet companion
Core TRANSCRIPT_CLASSIFIER Session auto-classification
Core BRIDGE_MODE Bridge / Remote Control
Core AGENT_TRIGGERS_REMOTE Remote Agent trigger
Core CHICAGO_MCP Computer Use MCP
Core VOICE_MODE Voice input
Monitoring SHOT_STATS Stats panel
Monitoring PROMPT_CACHE_BREAK_DETECTION Cache break detection
Monitoring TOKEN_BUDGET Token budget management
P0 AGENT_TRIGGERS Local Agent trigger
P0 ULTRATHINK Deep thinking
P0 BUILTIN_EXPLORE_PLAN_AGENTS Built-in exploration/planning Agents
P0 LODESTONE Lodestone
P1 EXTRACT_MEMORIES Memory extraction
P1 VERIFICATION_AGENT Verification Agent
P1 KAIROS_BRIEF Kairos summary
P1 AWAY_SUMMARY Offline summary
P1 ULTRAPLAN Super planning
P2 DAEMON Daemon mode

On-Demand Enable

Feature Description
BG_SESSIONS Background sessions (ps/logs/attach/kill)
FORK_SUBAGENT Fork subagent parallel execution
PROACTIVE Proactive Agent
KAIROS Kairos full features
COORDINATOR_MODE Coordinator orchestration mode
TEMPLATES Template task system
SSH_REMOTE SSH remote connection
WEB_BROWSER_TOOL Browser automation
WORKFLOW_SCRIPTS Workflow scripts
BYOC_ENVIRONMENT_RUNNER BYOC environment runner
SELF_HOSTED_RUNNER Self-hosted runner
FEATURE_FORK_SUBAGENT=1 FEATURE_BG_SESSIONS=1 bun run dev

Workspace Packages

Package Description Status
@ant/ink Forked Ink terminal UI framework Complete
@ant/computer-use-mcp Computer Use MCP Server Complete
@ant/computer-use-input Keyboard/mouse simulation (multi-platform backend) Complete
@ant/computer-use-swift Screenshot + app management (multi-platform) Complete
@ant/claude-for-chrome-mcp Chrome browser control Complete
remote-control-server Self-hosted RCS (Docker + Web UI) Complete
audio-capture-napi Native audio capture Restored
image-processor-napi Image processing Restored
color-diff-napi Color difference calculation Complete
modifiers-napi Keyboard modifier detection Stub
url-handler-napi URL scheme handling Stub

Testing & Quality

Metric Data
Test count 2430 tests
Test files 137 files
Assertion calls 3982 expect()
Framework bun:test
Lint Biome
Format Biome
bun test                                       # Full test suite
bun test src/utils/__tests__/hash.test.ts       # Single file
bun test --coverage                            # Coverage
bun run lint                                    # Static check
bun run health                                  # Health check

Development & Debugging

Common Scripts

Command Description
bun run dev Development mode (MACRO + all Features)
bun run dev:inspect Dev mode with Inspector
bun run build Production build (code splitting)
bun run lint:fix Auto-fix Lint
bun run format Format all
bun run health Health check
bun run generate:skills Generate Skills index
bun run rcs Start RCS
bun run docs:dev Docs site (Mintlify)

VS Code Debugging

bun run dev:inspect   # → ws://localhost:8888/xxx
# VS Code: F5 → "Attach to Bun (TUI debug)"

Teach Me

Built-in Socratic Q&A learning:

/teach-me CoStrict architecture
/teach-me Tool system --level beginner --resume