@ggts-sh/cli

中文文档
0.48.3发布于 2026/11/06MITTypeScriptES Module构建来源已验证近 30 天下载 2109

ggts: validate and render plot specs (JSON) to SVG from the command line — the feedback loop for agents that author charts in sandboxes.

原始使用文档
文档目录6 节
  1. Why this package exists
  2. What the CLI covers (and what it does not)
  3. Install
  4. Usage
  5. Exit codes
  6. Reference

@ggts-sh/cli

codecov

ggts check and ggts render: validate and render a ggts plot spec (JSON) to SVG from the command line. This is the feedback loop for agents that author specs — it surfaces the validation errors, warnings, and advisories a JSON-only workflow never sees.

Why this package exists

An embedded analytics agent writes a spec, the host webapp renders it with @ggts-sh/react or @ggts-sh/svelte. Without this CLI in the agent's sandbox, the agent ships the spec blind: a spec can be schema-valid yet draw a misleading chart, and the pipeline's warnings (degenerate stacks, single-observation groups, scale inference problems) fire in the webapp where nobody reads them. With the CLI, the agent renders locally, reads the JSONL diagnostics on stderr, and fixes the spec before anyone sees it.

If you embed spec-writing agents, treat this package as part of the install contract, not an option.

What the CLI covers (and what it does not)

Covered on every renderOpt-in / host-side
Schema validation (validate)Host inspect mode and most interaction wiring
Pipeline warnings and advisoriesRuntime key/lineage errors (need a live plot)
Scale-inference diagnostics (source: "scale")Composition/deprecation ondiagnostic without a host
Spec-lint advisories (source: "spec-lint")Full tooltip visual QA

Inspect mode is a host capability (<Inspect mode="xy" /> / plot inspect), not a PortableSpec field. To surface the same inspect×geom advisories agents would only see via ondiagnostic in a browser, declare host intent:

ggts render --inspect xy spec.json > out.svg
# stderr may include:
# {"kind":"advisory","source":"interaction","code":"INTERACTION_INSPECT_X_ON_COL",…}

Modes: auto, exact, x, y, xy (same enum as the host). Without --inspect, interaction codes are not invented — headless SVG-only charts stay quiet. Today this path covers bar/col x-guide pure collectors (including alias rewrite so geom: "histogram" matches host normalize); high-cardinality and runtime key/lineage diagnostics still need a mounted host. See ADR 0024.

Install

npm install --save-dev --save-exact @ggts-sh/cli
npm exec -- ggts check spec.json
npm exec -- ggts render spec.json > out.svg

In an agent sandbox image:

FROM node:24-slim
RUN npm install -g @ggts-sh/cli
# agents can now run: ggts render spec.json > out.svg

Pin the same version as the framework adapter your webapp renders with — all @ggts-sh/* packages version in lockstep.

Usage

check runs the same pipeline and rendering checks as render, suppressing SVG output. Both preserve the same diagnostic and exit-code contract.

ggts check spec.json                        # full checks without SVG
ggts render spec.json > out.svg          # spec from a file
ggts render < spec.json > out.svg        # spec from stdin
ggts render spec.json --data data.json   # named datasets from a file
ggts render spec.json --width 832 --height 400
ggts render --inspect xy spec.json > out.svg   # host inspect intent
  • render writes SVG to stdout; check leaves stdout empty.
  • Diagnostics go to stderr as JSON lines: {"kind":"error",…} | {"kind":"warning",…} | {"kind":"advisory",…}. Scale-inference diagnostics set source: "scale"; spec-lint sets source: "spec-lint"; interaction intent (--inspect) sets source: "interaction".

Exit codes

CodeMeaning
0checked or rendered
1render failed (pipeline error — spec was structurally valid)
2usage error (bad flags, unreadable input, invalid JSON)
3invalid spec (validation errors — see stderr JSON lines)

An agent loop: render, and on exit 3 apply the fix.example from each stderr error at its path, re-render; on exit 0 still read stderr — warnings and advisories are chart-quality feedback.

Reference

  • CLI reference — all options and diagnostics
  • Programmatic use without spawning: runCommand accepts render/check. The existing runCLI programmatic API remains available.

版本与发布记录

@ggts-sh/cli 共发布 11 个版本,首次发布于 2026/09/08;过去 12 个月发布了 11 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.48.3latest2026/11/0610 天前
0.48.22026/11/0610 天前
0.48.12026/11/0511 天前
0.48.02026/11/0511 天前
0.47.02026/11/0313 天前
0.46.02026/11/0313 天前

关于 @ggts-sh/cli 的常见问题

@ggts-sh/cli 是什么?

ggts: validate and render plot specs (JSON) to SVG from the command line — the feedback loop for agents that author charts in sandboxes.

如何安装 @ggts-sh/cli?

在项目目录运行 npm install @ggts-sh/cli,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 ggts,可以用 npx ggts 直接运行。

@ggts-sh/cli 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ggts-sh/cli 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@ggts-sh/cli 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ggts-sh/cli 可以商用吗?

@ggts-sh/cli 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ggts-sh/cli 的下载量有多少?

根据 npm 官方下载统计,@ggts-sh/cli 在 2026/10/17 – 2026/11/15 这 30 天内被下载 2,109 次,日均约 70 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ggts-sh/cli 还在维护吗?

最新版本 0.48.3 发布于 2026/11/06(10 天前);至今共发布 11 个版本,其中过去 12 个月发布了 11 个;首次发布于 2026/09/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。