codrax

command module
v0.0.0-...-84b3d7d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 3 Imported by: 0

README

Codrax

CODRAX — Code Of Deterministic Reasoning, Anchored eXplanation.

Codrax 是一个面向工程现场的 AI 协作工具。它的核心目标不是“聊代码”,而是把代码、日志、trace、外部工具和变更流程放到同一个可审计的工作台里,让复杂问题有证据、有边界、有后续动作。

快速开始:问第一个代码问题

Codrax 默认把启动时所在目录当作要分析的代码仓库。第一次使用时,先 cd 到目标代码仓,再启动 Codrax:

cd /path/to/your/code-repo
codrax

进入 REPL 后直接提问,例如:

这个项目的入口在哪里?请给出关键文件和调用链。

也可以用单次命令:

cd /path/to/your/code-repo
codrax --request "这个项目的入口在哪里?请给出关键文件和调用链。"

如果你不想切换当前目录,可以显式指定仓库:

codrax --repo /path/to/your/code-repo --request "这个配置项在哪里定义和消费?"

LLM provider、MCP、trace、operation skills 等详细配置见 docs/user_guide.md。

编译

Codrax 是 Go 项目,推荐 Go 1.22.5 或更新版本。因为仓库使用 CGO 和本地解析依赖,编译机器需要可用的 C/C++ 工具链。

make          # 编译当前平台二进制 ./codrax
make test     # 运行测试
make info     # 查看当前平台、Go、工具链信息

常见平台准备:

  • macOS:安装 Xcode Command Line Tools。
  • Linux:安装 gcc / g++ 等基础编译工具。
  • Windows:可用原生 MinGW 工具链;需要 Linux static 包时使用 WSL。

跨平台编译

跨平台编译同样受 CGO 目标平台工具链约束。Makefile 已提供常用目标:

目标 命令 说明
当前平台 make 生成 ./codrax
Linux 标准内嵌构建 make cross-linux dist/codrax-linux-amd64 为 glibc/default-tag 开发构建,默认内嵌 Linux trace_streamer;该子工具最低要求 glibc 2.34
Linux 静态内嵌构建 make static Linux/WSL 生成 fully-static Codrax 父程序 ./codrax,并内嵌独立执行的 Linux trace_streamer 子工具;子工具自身仍要求 glibc ≥ 2.34 及其共享库
Linux 静态精简构建 make static-slim Linux/WSL 生成 fully-static ./codrax-static-slim,显式不内嵌 trace_streamer,需配置外部兼容工具
Linux arm64 make cross-linux-arm64 需要 aarch64-linux-gnu-gcc 等工具链
macOS amd64 make cross-darwin 推荐在 macOS 上构建
macOS arm64 make cross-darwin-arm64 推荐在 macOS 上构建
Windows amd64 make cross-windows 需要 MinGW 目标工具链
正式发布矩阵 make release 先执行 payload-scoped 法务批准、SBOM、依赖许可/NOTICE 与构建证明门;当前 NOASSERTION/blocked 状态会在清理或构建前 fail-loud

适合什么场景

代码理解与影响分析

当你面对一个不熟悉的仓库、模块或函数时,Codrax 可以帮助你快速回答:

  • 入口在哪里,调用链怎么走。
  • 某个配置、接口、状态字段在哪里定义和消费。
  • 一次改动可能影响哪些模块、测试和运行路径。
  • 多仓或大仓里,相关代码散落在哪里。

它适合做带 file:line 证据的代码解释,而不是只给一段泛泛总结。

运行日志与故障定位

当问题来自线上日志、崩溃栈、告警或客户粘贴的运行片段时,Codrax 可以把外部现象和当前仓库源码放在一起分析:

  • 根据日志中的错误、栈帧、关键字定位源码锚点。
  • 区分外部观察和当前源码证据,避免把日志内容误当源码引用。
  • 在证据不足时保留不确定性,而不是强行编出结论。
Trace / 性能根因分析

Codrax 支持面向 Android、Harmony / HiTrace、东湖等运行时 trace 的性能调查场景,适合分析:

  • UI 卡顿、丢帧、长时间 sleep、runnable wait。
  • 多跳唤醒链、binder 链路、D 状态、IO wait、锁竞争。
  • 同时间窗 CPU 压力、频点、IRQ、内存、后台负载等辅助证据。
  • trace 缺口、平台优先级语义、时间单位等容易误判的边界。

这类问题不应该只靠模型手写 grep/awk 反复试探,Codrax 会尽量把可确定的 trace 事实结构化为证据包。

本地数据清洗与汇总

当任务的核心是读取本地结构化或半结构化材料并计算结果时,Codrax 会尽量走独立的数据处理通道,而不是把数据材料误当源码文件:

  • CSV / TSV / JSON / JSONL / 文本化附件索引的清洗、过滤、去重、join、汇总。
  • 需要抽取的非文本材料会先作为客观材料进入目录;只有任务确实需要且配置了对应抽取器时,才会转成文本证据后继续计算。
  • 条目级判定、数值字段计算、异常记录筛选。
  • 严格输出 JSON-only、CSV-only、单行字符串或 Markdown 表格。
  • 对需要过滤、归一、汇总和对账的任务,会尽量生成可审计的材料覆盖、贡献记录和对账摘要,减少“脚本跑通但结果漂移”。

纯只读数据计算不需要 command-operation 审批,也不走源码 citation gate;如果用户同时要求检查代码实现,才会进入数据 + 源码的混合分析。

数据处理运行会在 .codrax/data-audit/ 留下终态审计文件。中断后需要继续时,可以显式指定 checkpoint:

codrax --mode=data --data-resume .codrax/data-audit/<checkpoint>.json -r "继续完成这个数据任务"

它不会自动恢复旧任务;只有提供 --data-resume 时才会读取 checkpoint。

外部工具与电脑操作工作流

Codrax 可以通过 MCP 或 operation skills 接入外部能力,例如:

  • 公司内告警、工单、日志检索系统。
  • 本地脚本、二进制工具、PPT / 文档 / 表格生成器。
  • 需要先读说明、提炼参数、再调用下游工具的多步骤 workflow。

这些外部结果会进入独立的外部观察 / operation handoff 通道,不会混进当前源码 citation。低/中风险安全动作可按 operation 策略自动推进;高风险动作需要用户批准,特别危险的操作会被直接拒绝。

变更方案与沙箱执行

在明确开启写模式后,Codrax 可以辅助完成代码变更闭环:

  • 先产出改动方案。
  • 在隔离 worktree 中应用修改。
  • 执行验证并区分本次改动引入的问题、已有问题和环境缺失。
  • 由用户决定是否接受和合并。

它的定位是“带审批和验证的工程助手”,不是自动改主仓的脚本。

不适合什么场景

  • 没有仓库、日志、trace 或外部证据,却要求确定性结论。
  • 需要绕过审批执行高风险电脑操作。
  • 希望模型凭感觉给出无法复核的性能或代码根因。
  • 把外部日志、MCP 输出、trace 行号当成当前源码引用。

设计取向

Codrax 的默认取向是:

  • 精确信号用于硬门,噪声信号只做软提示。
  • 源码证据、运行时证据、外部工具结果分 lane 传递。
  • 用户能看到关键过程,最终答案能回到具体证据。
  • 普通代码分析、trace/log 分析、外部 skills、写代码流程彼此隔离,按 typed 意图进入对应路径。

进一步了解

开源协议

本仓库代码以 MIT License 开源。third_party/ 下的第三方组件保留其各自的原始协议(如 hmtrace 为 Apache-2.0,见 third_party/hmtrace/LICENSE.hmtrace.txt)。

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package cmd implements the Cobra-based CLI for codrax.
Package cmd implements the Cobra-based CLI for codrax.
eval
repomap_v3/fixturegen command
Package main regenerates the repomap_v3 symbol ground-truth fixture (eval/repomap_v3/fixtures/symbols.json) against the CURRENT HEAD.
Package main regenerates the repomap_v3 symbol ground-truth fixture (eval/repomap_v3/fixtures/symbols.json) against the CURRENT HEAD.
repomap_v3/harness command
Package main is the deterministic repomap_v3 eval harness.
Package main is the deterministic repomap_v3 eval harness.
repomap_v3/probe_ast command
One-shot diagnostic: parse a Go source file with tree-sitter-go and dump the AST shape of each import_declaration so we can verify whether grouped imports (import ( ...
One-shot diagnostic: parse a Go source file with tree-sitter-go and dump the AST shape of each import_declaration so we can verify whether grouped imports (import ( ...
repomap_v3/probe_receivers command
Diagnostic: dump receiver text distribution from the graph's call relations so we can see why unambig_by_receiver_type is small.
Diagnostic: dump receiver text distribution from the graph's call relations so we can see why unambig_by_receiver_type is small.
telemetry command
internal
agent
Several functions in this file (parseEvidenceItems, groundEvidenceItems, mergeEvidenceItems, rankEvidenceByRelevance, scrubSiblingEvidenceBlocks) form filters F4..F7 and F9 of the post-hoc filtering pipeline.
Several functions in this file (parseEvidenceItems, groundEvidenceItems, mergeEvidenceItems, rankEvidenceByRelevance, scrubSiblingEvidenceBlocks) form filters F4..F7 and F9 of the post-hoc filtering pipeline.
analysis/aggregator
Package aggregator is the Session 11 F2 RootCauseAggregator.
Package aggregator is the Session 11 F2 RootCauseAggregator.
analysis/amplifier
Package amplifier augments the LLM-emitted RequestModel with deterministic structural inferences derived from existing typed signals on the model itself.
Package amplifier augments the LLM-emitted RequestModel with deterministic structural inferences derived from existing typed signals on the model itself.
analysis/axis
Package axis implements the PredicateAxis × AnchorKind affinity matrix used by the evidence ranker to bias evidence items whose AnchorKind matches the user's question axis.
Package axis implements the PredicateAxis × AnchorKind affinity matrix used by the evidence ranker to bias evidence items whose AnchorKind matches the user's question axis.
analysis/binder
Package binder attaches hypotheses to TaskGraph nodes by relevance.
Package binder attaches hypotheses to TaskGraph nodes by relevance.
analysis/budget
Package budget computes the EvidencePlan.Budget as a function of Complexity × term cardinality × hypothesis count × prescan hit ratio.
Package budget computes the EvidencePlan.Budget as a function of Complexity × term cardinality × hypothesis count × prescan hit ratio.
analysis/compiler
Package compiler turns a RequestModel into a fully populated TaskGraph + EvidencePlan + AnswerContract according to a pluggable scenario template.
Package compiler turns a RequestModel into a fully populated TaskGraph + EvidencePlan + AnswerContract according to a pluggable scenario template.
analysis/contract
Package contract is the runtime answer-contract checker.
Package contract is the runtime answer-contract checker.
analysis/counterfactual
Package counterfactual expands a task graph with alternative explanation paths when the request is ambiguous enough to warrant them.
Package counterfactual expands a task graph with alternative explanation paths when the request is ambiguous enough to warrant them.
analysis/criterion
Package criterion is the executable-contract layer of Analyzer v3.
Package criterion is the executable-contract layer of Analyzer v3.
analysis/declarative
Package declarative identifies "declarative" source files — those whose primary content is a map literal, a const block, a registry table, or a routes manifest rather than function bodies.
Package declarative identifies "declarative" source files — those whose primary content is a map literal, a const block, a registry table, or a routes manifest rather than function bodies.
analysis/findings_validator
Package findings_validator scrubs the analyzer's free-form prose (auto-captured into StageOutput.StageReport and rendered downstream as the "Prior Stage Findings" section) so any file path or backticked symbol name the LLM dropped into the narrative is cross-checked against repo state.
Package findings_validator scrubs the analyzer's free-form prose (auto-captured into StageOutput.StageReport and rendered downstream as the "Prior Stage Findings" section) so any file path or backticked symbol name the LLM dropped into the narrative is cross-checked against repo state.
analysis/gate
Package gate — fingerprint.go
Package gate — fingerprint.go
analysis/hdp
Package hdp implements the Hypothesis-Driven Planning layer of the Analyzer v3 refactor.
Package hdp implements the Hypothesis-Driven Planning layer of the Analyzer v3 refactor.
analysis/hint
Package hint is the Session 11 F4 HintComposer — the single structured entry point for every retry hint the orchestrator injects into a downstream agent's prompt.
Package hint is the Session 11 F4 HintComposer — the single structured entry point for every retry hint the orchestrator injects into a downstream agent's prompt.
analysis/logtriage
Package logtriage holds the system-side helpers for the log_triage pre-stage.
Package logtriage holds the system-side helpers for the log_triage pre-stage.
analysis/normalizer
Package normalizer turns a raw natural-language + code user request into a canonical TermGraph that downstream stages (explorer, ERM, finalizer) can consume without re-deriving terminology every time.
Package normalizer turns a raw natural-language + code user request into a canonical TermGraph that downstream stages (explorer, ERM, finalizer) can consume without re-deriving terminology every time.
analysis/patcher
Package patcher is the Session 11 F3 IRPatchEngine — the deterministic reconciler that applies targeted mutations to a RequestModel after the analyzer has emitted the initial IR.
Package patcher is the Session 11 F3 IRPatchEngine — the deterministic reconciler that applies targeted mutations to a RequestModel after the analyzer has emitted the initial IR.
analysis/perftriage
Package perftriage holds validation + merge helpers for the perf channel, mirroring internal/analysis/logtriage.
Package perftriage holds validation + merge helpers for the perf channel, mirroring internal/analysis/logtriage.
analysis/priority
Package priority scores hypotheses on four dimensions and collapses the result into a single integer the gate and scheduler can compare.
Package priority scores hypotheses on four dimensions and collapses the result into a single integer the gate and scheduler can compare.
analysis/risk
Package risk evaluates the six-dimensional risk matrix for a RequestModel.
Package risk evaluates the six-dimensional risk matrix for a RequestModel.
analysis/sourcemix
Package sourcemix compiles the template-level SourceMix ratios into NodeBudgetHints and checks per-tool budgets at dispatch time.
Package sourcemix compiles the template-level SourceMix ratios into NodeBudgetHints and checks per-tool budgets at dispatch time.
analysis/stopcond
Package stopcond evaluates EvidencePlan.StopConditions at each scheduler round.
Package stopcond evaluates EvidencePlan.StopConditions at each scheduler round.
analysis/subject
Package subject provides the AnswerSubject taxonomy and the per- kind judge functions the chain ranker / shape reconciler / retry- hint renderer all dispatch on.
Package subject provides the AnswerSubject taxonomy and the per- kind judge functions the chain ranker / shape reconciler / retry- hint renderer all dispatch on.
analysis/tracefinding
Package tracefinding compiles the frozen typed candidate contract for one trace analysis and binds the model's ordered candidate selection into the public root-cause sidecar; the model never authors a system-owned field.
Package tracefinding compiles the frozen typed candidate contract for one trace analysis and binds the model's ordered candidate selection into the public root-cause sidecar; the model never authors a system-owned field.
authority
Package authority centralises the AuthorityCeiling axis projection logic.
Package authority centralises the AuthorityCeiling axis projection logic.
canonpath
Package canonpath holds the repo-relative path canonicaliser used by BOTH the types data model (EvidenceClosure.ReadSet) and the higher layers (tool/ground, agent/explorer).
Package canonpath holds the repo-relative path canonicaliser used by BOTH the types data model (EvidenceClosure.ReadSet) and the higher layers (tool/ground, agent/explorer).
context
Package context — builder_skill_tier.go (P5-B step 3, 2026-05-10).
Package context — builder_skill_tier.go (P5-B step 3, 2026-05-10).
env
Package env is the public façade callers (run_tests, REPL, etc) import.
Package env is the public façade callers (run_tests, REPL, etc) import.
env/cache
Package cache holds the user-home-anchored disk cache for env_recommend's LLM fallback results.
Package cache holds the user-home-anchored disk cache for env_recommend's LLM fallback results.
env/diag
Package diag implements Layer 1 of env_recommend — turning a raw failure (stderr / runner / EnvFacts) into a structured Diagnosis.
Package diag implements Layer 1 of env_recommend — turning a raw failure (stderr / runner / EnvFacts) into a structured Diagnosis.
env/probe
Package probe implements the Layer 2 environment scanner that produces a types.EnvFacts snapshot for the env_recommend subsystem.
Package probe implements the Layer 2 environment scanner that produces a types.EnvFacts snapshot for the env_recommend subsystem.
env/recommend
Package recommend is Layer 3 of env_recommend — turning a Diagnosis + EnvFacts into a sorted list of install candidates the Renderer surfaces to the user.
Package recommend is Layer 3 of env_recommend — turning a Diagnosis + EnvFacts into a sorted list of install candidates the Renderer surfaces to the user.
llm
logging
Package logging provides a leveled, file-rotating logger used by the codrax binary.
Package logging provides a leveled, file-rotating logger used by the codrax binary.
loopkernel
Package loopkernel contains the deterministic state substrate for Codrax's next-generation read/write execution loop.
Package loopkernel contains the deterministic state substrate for Codrax's next-generation read/write execution loop.
markdownext
Package markdownext holds goldmark extensions shared by codrax's markdown render faces (browser/HTML face in internal/preview, terminal ANSI face in internal/render).
Package markdownext holds goldmark extensions shared by codrax's markdown render faces (browser/HTML face in internal/preview, terminal ANSI face in internal/render).
mcp
memlimit
Package memlimit derives and installs a soft heap limit (GOMEMLIMIT) for the codrax process at startup.
Package memlimit derives and installs a soft heap limit (GOMEMLIMIT) for the codrax process at startup.
memory
Package memory persists multi-turn REPL conversations and compacts older turns into a searchable MEMORY.md index.
Package memory persists multi-turn REPL conversations and compacts older turns into a searchable MEMORY.md index.
reasoninggraph
Package reasoninggraph contains Codrax's cross-mode typed reasoning evidence ledger.
Package reasoninggraph contains Codrax's cross-mode typed reasoning evidence ledger.
render
Package render provides a rich CLI rendering system for the codrax pipeline.
Package render provides a rich CLI rendering system for the codrax pipeline.
repl
Interactive input helpers for the REPL.
Interactive input helpers for the REPL.
skill/glossarylint
Package glossarylint is the single scanner behind every "no internal jargon in model-facing text" lint in the repository.
Package glossarylint is the single scanner behind every "no internal jargon in model-facing text" lint in the repository.
stageauthority
Package stageauthority exposes checkout-verified read-mode stage facts to prompt and validation consumers through one typed provider.
Package stageauthority exposes checkout-verified read-mode stage facts to prompt and validation consumers through one typed provider.
threadidentity
Package threadidentity owns the selector grammar shared by trace queries and typed evidence consumers.
Package threadidentity owns the selector grammar shared by trace queries and typed evidence consumers.
tool
Package tool — answer_document_artifact_quote_check.go (XGAP-FIX ⑤ independent arm, §29.104.8, witness 20260715-202022.323-89609).
Package tool — answer_document_artifact_quote_check.go (XGAP-FIX ⑤ independent arm, §29.104.8, witness 20260715-202022.323-89609).
tool/ground
Package ground validates the file:line citation attached to each LLM-emitted EvidenceItem and assigns a three-way GroundingStatus (grounded / recovered / ungrounded).
Package ground validates the file:line citation attached to each LLM-emitted EvidenceItem and assigns a three-way GroundingStatus (grounded / recovered / ungrounded).
tool/multipath
Package multipath replaces the predecessor "multi-path coverage parity" pre-complete gate (raiseMultiPathCoverageParity in internal/tool/emit_investigation_complete.go, retired 2026-05-01) with a layered, anchor-driven verification that works for code AND non-code files (config / docs / manifests).
Package multipath replaces the predecessor "multi-path coverage parity" pre-complete gate (raiseMultiPathCoverageParity in internal/tool/emit_investigation_complete.go, retired 2026-05-01) with a layered, anchor-driven verification that works for code AND non-code files (config / docs / manifests).
tool/repomap
Package repomap is the top-level facade for the tree-sitter- powered repository index.
Package repomap is the top-level facade for the tree-sitter- powered repository index.
tool/repomap/multigraph
Package multigraph holds the multi-repo carrier (Z+Y hybrid: SymbolOracle/SymbolLocator fan-out + raw-field flatten/owner-aware access) consumed by the read pipeline when codrax.yaml :: multi_repo_enabled is true (default).
Package multigraph holds the multi-repo carrier (Z+Y hybrid: SymbolOracle/SymbolLocator fan-out + raw-field flatten/owner-aware access) consumed by the read pipeline when codrax.yaml :: multi_repo_enabled is true (default).
tool/repomap/topology
Package topology models a parent directory's set of git sub-repos and answers "which sub-repo owns this relative path?" lookups for the multi-repo runtime (see docs/design/multi_repo_discovery_and_lazy_load.md).
Package topology models a parent directory's set of git sub-repos and answers "which sub-repo owns this relative path?" lookups for the multi-repo runtime (see docs/design/multi_repo_discovery_and_lazy_load.md).
tool/repomap/types
Package types defines the core data types and Graph query methods that are shared by every other repomap sub-package (index, retrieve, render).
Package types defines the core data types and Graph query methods that are shared by every other repomap sub-package (index, retrieve, render).
tool/width
Package width is the central width governor for tool result production: the single source of truth for the per-tool raw-output width/entry caps that decide when a tool result is compacted and when a typed refinement hint fires (Batch F4, 2026-07-03).
Package width is the central width governor for tool result production: the single source of truth for the per-tool raw-output width/entry caps that decide when a tool result is compacted and when a typed refinement hint fires (Batch F4, 2026-07-03).
tracebundle
Package tracebundle provides bounded, generation-bound intake for trace bundle manifests.
Package tracebundle provides bounded, generation-bound intake for trace bundle manifests.
tracediag
Package tracediag implements the TDIAG (§28.12, user ruling 2026-07-09) deterministic trace diagnostic collector: a zero-LLM, read-only CLI mode that runs a YAML collection script of tracequery steps against a trace file and renders a single evidence-faithful text report for customer round-trip collection (single result ≤1000 lines per step).
Package tracediag implements the TDIAG (§28.12, user ruling 2026-07-09) deterministic trace diagnostic collector: a zero-LLM, read-only CLI mode that runs a YAML collection script of tracequery steps against a trace file and renders a single evidence-faithful text report for customer round-trip collection (single result ≤1000 lines per step).
tracefence
Package tracefence is the SINGLE SOURCE for the trace causal-projection fence recognition contract shared by the fence generator (internal/tool, runtimeTraceProjTreeFence) and the HTML preview classifier (internal/preview, isTraceCausalProjectionFence).
Package tracefence is the SINGLE SOURCE for the trace causal-projection fence recognition contract shared by the fence generator (internal/tool, runtimeTraceProjTreeFence) and the HTML preview classifier (internal/preview, isTraceCausalProjectionFence).
traceinput
Package traceinput prepares complete physical trace attachments at product boundaries.
Package traceinput prepares complete physical trace attachments at product boundaries.
types
Package types — evidence_floor_waiver.go (2026-05-10).
Package types — evidence_floor_waiver.go (2026-05-10).
userhint
Package userhint holds tiny shared extractors for operator-typed hints (PIB-5c @path pins; TTY-3 steering notes) so the REPL and the orchestrator consume ONE implementation instead of drifting copies.
Package userhint holds tiny shared extractors for operator-typed hints (PIB-5c @path pins; TTY-3 steering notes) so the REPL and the orchestrator consume ONE implementation instead of drifting copies.
worktree
Package worktree manages git worktree lifecycles for the B0 write-mode pipeline stages (plan / apply / verify).
Package worktree manages git worktree lifecycles for the B0 write-mode pipeline stages (plan / apply / verify).
writeflow
Package writeflow contains deterministic write-mode workflow helpers.
Package writeflow contains deterministic write-mode workflow helpers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL