Adversarial review confirmed the Phase 1 extraction is a verbatim move (no BLOCKERs) and that cmdcore.BoolFlag is equivalent to both original readers. All fixes below are in the Phase 2 additions. Correctness: a CommandSpec declaring neither RunE nor Dispatch no longer runs the whole pipeline (write-confirmation prompt included) and silently exits 0 — it now fails with a typed internal error, which also defuses the FromShortcut trap. FromShortcut no longer double-renders the 参数约束 section (shortcutLongHelp already appends it and NewCommand appends ConstraintHelp again): it now maps intent prose only. Flag usage keeps mount()'s flagHelp decoration (必填/可选值) so projected help matches the live shortcut, and the constraint Flags slice is copied instead of aliasing the shortcut registry. Honesty: the FromShortcut doc block now lists every dropped semantic (Required Changed-vs-effective-value divergence, typed bool/int/slice defaults, Enum, Hidden, Tips to Example, custom constraint, required/enum runtime-schema annotations). cmdcore's package doc no longer claims catalog drift proves runtime behavior — drift covers the build-time projection, unit tests cover the runtime pipeline. leaf.go's stale Phase 1 header updated. Panic messages say command not leaf; doc comments lead with the exported names. Tests: new mount-equivalence test compares the projected command's flag set/types/usage and rendered Long against live mount(s) — the test that would have caught both bugs above; new root-to-child test exercises the inherited/root-persistent --yes/--dry-run lookup that the leaf-local helper never reached; the nil-dispatch test is inverted to assert the error. docs/architecture.md documents internal/cmdcore and how it differs from internal/cobracmd. Verified: drift ok (840 tools, identical hashes), make policy pass, skill-command-integrity ok (1033 paths), cmdcore self-coverage 100%, CI-style changed-code coverage 100% (278 statements), full helpers/cmdcore/shortcut suites green.
6.0 KiB
Architecture
dws is a Go CLI with a versioned, static command surface for DingTalk MCP capabilities. Cobra help serves humans; the embedded Command Catalog serves AI agents.
High-Level Flow
cmdis the CLI entrypoint, invokinginternal/appto build the root Cobra command tree.internal/appwires static utility commands (auth,audit,schema,completion), product helpers, and versioned plugin descriptors.internal/helperscontains the main command handlers for all product surfaces (dev,chat,calendar,contact,aitable, etc.).internal/executorandinternal/transportexecute MCP JSON-RPC calls;internal/outputformats responses.internal/authmanages login state, PAT tokens, and agent-code detection.- Schema generation starts from the reviewed
CommandRegistry, binds each identity to the exact current Cobra leaf, and then resolves typed constraints, sanitized MCP snapshots, Agent hints, and Skills into oneSchemaRegistry. Startup and Schema queries do not call MCPtools/list. - The embedded Catalog is a downstream release artifact and never backfills identity or participates in regeneration. Stable flag-to-interface property bindings come from the reviewed, content-addressed v3 manifest in
schema_parameter_bindings.json; its exact active tuples, corrections, removals, and mapping exclusions are validated against the final boundSchemaRegistry. CLIrequiredand constraints come from the resolved typed contract, while MCPrequiredremains interface-only metadata. - Agent selection results are fixed in versioned review inputs. Every public tool has explicit use/avoid/example and interface disposition metadata; Skill references that are not current leaves require an explicit alias/group/stale/out-of-surface review instead of fuzzy runtime matching.
Repository Structure
cmd: CLI entrypointinternal/app: root command wiring, static utility commands, and plugin loadinginternal/helpers: product command handlers (dev, chat, calendar, contact, etc.)internal/plugin: versioned plugin manifest, hook, skill, and transport descriptor loadinginternal/cli: embedded Agent Command Catalog, static schema query, and catalog contractsinternal/generator: deterministic Agent metadata and Command Catalog generatorsinternal/executor: invocation dispatch and result handlinginternal/transport: MCP HTTP client and request signinginternal/auth: login, token management, agent-code detection, identityinternal/audit: user operation audit log (JSONL, hash chain, forwarding)internal/errors: structured error model with categories and hintsinternal/keychain: OS keychain integration for credential storageinternal/security: endpoint allowlist and domain trustinternal/safety: runtime safety checks (confirm prompts, dry-run guards)internal/cobracmd: shared Cobra command buildersinternal/cmdcore: dispatch-agnostic leaf-command base — flag registration, alias/env/default value resolution, required and cross-flag constraint validation, Risk write confirmation, toolArgs assembly, Runtime Schema projection. Distinct frominternal/cobracmd(generic tree helpers): it owns the declarative leaf contract (CommandSpec) that the LeafSpec framework is built on and that the Shortcut adapter projects into.internal/pat: PAT (Personal Access Token) authorization flowinternal/output: response formatting (json, table, raw, pretty)internal/logging: structured logging and argument sanitizationinternal/tui: terminal UI helpersinternal/recovery: panic recovery and graceful degradationpkg/configmeta: environment variable registry and documentationpkg/config: configuration constants and pathspkg/edition: edition detection (oss vs enterprise)pkg/mcptypes: MCP protocol type definitionsinternal/syncdata: generated static endpoint and command-routing data synced from the Wukong baselineskills/: bundled agent skills (mono/ and multi/ layouts)test/: CLI, integration, contract, unit, and skill E2E testsscripts/: install scripts, policy checks, and CI helpers
Quality Pipeline
Quality enforcement is layered so a pull request receives fast, deterministic admission feedback without pretending that downstream integration has already run.
flowchart TB
PR["Pull request"] --> CLASSIFY["Fail-closed risk classification"]
CLASSIFY --> DOCS["Documentation-only<br/>asset/content validation"]
CLASSIFY --> STANDARD["Standard<br/>affected + reverse-dependent race<br/>scope-matched HEAD/base coverage"]
CLASSIFY --> HIGH["High-risk / main<br/>full race + native tests"]
DOCS --> CA["CI"]
STANDARD --> CA
HIGH --> CA
subgraph CA_CHECKS["Nine required contexts"]
L["Lint"]
T["Test"]
C["Coverage"]
P["Policy"]
E["Edition"]
I["Interface Integrity"]
A["AI Behavior"]
S["CLI Smoke"]
M["Mock MCP"]
end
CA --> CA_CHECKS
CA_CHECKS --> MAIN["Protected main"]
MAIN --> MP["Main Integration — 主干集成<br/>Multi-profile E2E"]
MAIN --> PLATFORM["Risk-selected / release native platform validation"]
MP --> RELEASE["Release delivery"]
PLATFORM --> RELEASE
All nine named contexts are produced for every tier. Domain-specific helpers
run when their owned surface is affected; otherwise the corresponding context
records an explicit unaffected success. Standard code changes still receive
representative Darwin/Windows compilation. High-risk PRs and protected main
run the complete race and native test suites, while platform-sensitive diffs
also receive native changed-code coverage.
Review orchestration is also base-owned: it requests one eligible peer without
executing PR code, re-routes an updated head when needed, and auto-merge
completes only after the latest push has peer approval plus the current
revision's nine strict contexts. Complete Multi-profile E2E remains downstream
of PR admission. See docs/ci-pr-gates.md for the exact
classification, context, reviewer, and ruleset contract.