Skip to content

feat(hosts): add Grok CLI host adapter - #52

Open
Kyncc wants to merge 3 commits into
QoderAI:mainfrom
Kyncc:feat/grok-host-adapter
Open

feat(hosts): add Grok CLI host adapter#52
Kyncc wants to merge 3 commits into
QoderAI:mainfrom
Kyncc:feat/grok-host-adapter

Conversation

@Kyncc

@Kyncc Kyncc commented Aug 2, 2026

Copy link
Copy Markdown

Summary

  • Add a first-class Grok CLI host adapter for configured assets (scripts/agent-customize/providers/grok.mjs) and session evidence (scripts/session-analysis/platforms/grok.mjs).
  • Wire Grok into session-analysis, agent-customize, asset baseline/integrity, evidence-bundle, report-run, task-loop-source, and portable HTML report routing (.grok/better-harness).
  • Document Grok as Adapter support (not Verified Quickstart) in the adapter matrix, homepage cards, README, and sessions diagnostics.
  • Make walkFiles follow directory symlinks so Grok skills installed with ln -s under ~/.grok/skills are inventoried.

Spec / acceptance

See docs/specs/2026-08-02-grok-host-adapter.md (Grok-A1/A2, Grok-S1–S4, Grok-R1/R2).

Install path for local use:

ln -sfn <repo>/skills/better-harness ~/.grok/skills/better-harness
# then /better-harness in Grok TUI

Test plan

  • Focused unit tests: node --test test/session-analysis-providers.test.mjs test/agent-customize.test.mjs test/support-declarations.test.mjs test/coding-agent-platform-notes.test.mjs test/docs-entrypoints.test.mjs test/better-harness-evidence-bundle.test.mjs test/docs-site.test.mjs (126 pass)
  • Local smoke: session-analysis sources --platform grok discovers workspace sessions
  • Local smoke: agent-customize inventory --provider grok finds symlink-installed better-harness skill
  • Local smoke: harness evidence-bundle --platform grok --depth quick returns status=complete with available lanes
  • CI full suite on this PR
  • Maintainer: optional interactive /better-harness report-loop smoke before Quickstart promotion

Register Grok as a first-class adapter for configured assets, session
evidence, evidence bundles, and portable HTML report routing. Skills
installed via symlink under ~/.grok/skills are now inventoried.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

本 PR 在 Better Harness 中新增 Grok CLI 作为一等公民的宿主适配器:补齐会话证据读取(session-analysis)、已配置资产盘点(agent-customize / coding-agent-practices)、证据束(evidence-bundle)与 HTML 报告输出路由(.grok/better-harness),并同步更新文档矩阵与站点入口以将 Grok 标注为 Adapter support(非 Verified Quickstart)。实现与验收标准对齐到 docs/specs/2026-08-02-grok-host-adapter.md(Grok-A1/A2、Grok-S1–S4、Grok-R1/R2)。

Changes:

  • 新增 Grok 会话平台:实现对 ~/.grok/sessions/<url-encoded-cwd>/<session-id>/ 的发现、范围限定、事件归一化与可选 signals.json 用量读取
  • 新增 Grok 资产盘点:读取 config.toml MCP servers、skills、hooks、installed plugins 与 workspace .grok / .agents 资产
  • 更新 CLI/路由/文档与测试:将 grok 纳入平台枚举、帮助文案、适配矩阵、主页卡片与相关单测

Reviewed changes

Copilot reviewed 38 out of 39 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/support-declarations.test.mjs 扩展支持平台列表并更新 portable HTML 路由一致性断言以包含 Grok
test/session-analysis-providers.test.mjs 为 Grok provider 添加 dispatcher 覆盖与会话事件/隔离/缺失 signals 的单测
test/docs-site.test.mjs 更新站点统计与矩阵边界断言(adapter 数从 2→3)
test/docs-entrypoints.test.mjs 将 Grok 加入 adapter-support hosts、主页卡片计数与中英矩阵断言
test/coding-agent-platform-notes.test.mjs 将 Grok 纳入 Sessions Diagnostics 的平台说明与支持列表
test/better-harness-evidence-bundle.test.mjs evidence-bundle help 覆盖 Grok,并检查 --grok-home
test/agent-customize.test.mjs 新增 Grok 资产盘点与 --grok-home 覆盖的端到端测试夹具
templates/reporting/routing.md 将 Grok 加入 portable HTML report 的宿主路由条件
scripts/session-analysis/usage-summary.mjs --platform help 列表加入 grok
scripts/session-analysis/selection-profile.mjs --platform help 列表加入 grok
scripts/session-analysis/platforms/grok.mjs 新增 Grok 会话证据适配器实现(sources/sessions/events/facts)
scripts/session-analysis/lifecycle-demand-signals.mjs safeHost 白名单加入 grok
scripts/session-analysis/fs.mjs walkFiles 改为可跟随目录 symlink(用于 Grok skills 软链场景)
scripts/session-analysis/analyzer.mjs 注册 Grok 平台模块并更新帮助与 --grok-home
scripts/harness-analysis/task-loop-source.mjs task-loop-source 平台枚举与 inventory 路由加入 grokHome/grok
scripts/harness-analysis/report-run.mjs report 平台枚举与允许参数集合加入 grok/grok-home
scripts/harness-analysis/render-report.mjs 为 grok 的 html 输出默认目录引入 .grok/better-harness 分支
scripts/harness-analysis/evidence-bundle/contract.mjs evidence-bundle providers 集合加入 grok
scripts/harness-analysis/evidence-bundle/cli.mjs evidence-bundle CLI 帮助/参数白名单加入 --grok-home
scripts/harness-analysis/evidence-bundle/agent-customize.mjs asset providers 集合加入 grok
scripts/coding-agent-practices/inventory.mjs 平台提示与 userBase 推断加入 grokHome
scripts/coding-agent-practices/asset-integrity.mjs provider 白名单与错误文案加入 grok
scripts/coding-agent-practices/asset-baseline.mjs provider 白名单与错误文案加入 grok
scripts/agent-lint/cli.mjs agent-assets-review provider 列表加入 grok
scripts/agent-customize/providers/index.mjs 注册 Grok provider collector
scripts/agent-customize/providers/grok.mjs 新增 Grok 配置资产盘点(skills/hooks/mcp/plugins/workspace primitives)
scripts/agent-customize/cli.mjs CLI usage/参数透传加入 --grok-home
references/session-evidence/sessions-diagnostics.md 文档增加 Grok 平台诊断与证据位置说明
README.zh-CN.md 文案更新:总适配器数与 adapter-support 列表加入 Grok
README.md 文案更新:总适配器数与 adapter-support 列表加入 Grok
docs/src/pages/index.js 主页新增 Grok host card,并更新架构说明/QuickStart 文案
docs/specs/2026-08-02-grok-host-adapter.md 新增 Grok 适配器 spec(验收、隐私边界、冒烟步骤)
docs/i18n/zh-Hans/docusaurus-plugin-content-docs/current/installation.mdx 中文安装页:适配器总数更新为 9
docs/i18n/zh-Hans/docusaurus-plugin-content-docs/current/hosts/adapter-matrix.md 中文矩阵:加入 Grok 条目与边界说明
docs/i18n/zh-Hans/code.json 中文主页翻译新增 Grok host card 文案并更新计数文案
docs/docs/installation.mdx 英文安装页:适配器总数更新为 9
docs/docs/hosts/adapter-matrix.md 英文矩阵:加入 Grok 条目与边界说明
docs/adapters/README.md Canonical 矩阵:加入 Grok 行与相关说明段落
assets/better-harness-architecture-en.svg 架构图文字更新:capability adapters 数量与 adapter-support 列表加入 Grok
Suppressed comments (1)

docs/src/pages/index.js:537

  • This QuickStart intro still says "Eight host adapters" even though the rest of the PR bumps the declared total to nine. Update the English copy to match the docs and tests.
            Eight host adapters are supported. Six have verified setup paths;
            Pi, WorkBuddy, and Grok link to their current support boundaries.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +82 to 86
// Dirent isDirectory/isFile are false for symlinks; follow them so hosts
// that install skills via ln -s (e.g. Grok ~/.grok/skills) are inventoried.
const linkedDirectory = entry.isSymbolicLink() ? await isDirectory(fullPath) : false;
if (entry.isDirectory() || linkedDirectory) {
await visit(fullPath, depth + 1);
Comment thread docs/src/pages/index.js
Comment on lines 512 to 514
Eight capability-level host adapters feed the same evidence
pipeline. Six have verified Quickstart paths; Pi and WorkBuddy keep
pipeline. Six have verified Quickstart paths; Pi, WorkBuddy, and Grok keep
their current adapter-support boundaries explicit.
Comment on lines +90 to +94
options.out ??= options.mode === "cursor-canvas"
? ".cursor/better-harness"
: options.mode === "html" && String(options.platform ?? options.provider ?? "").toLowerCase() === "grok"
? ".grok/better-harness"
: ".qoder/better-harness";
Update frozen help fixtures, CLI registry summary, portable-HTML routing
assertions, and Windows-portable Grok session path encoding checks.
OnMyAgent keeps SoT under .agents/skills and links .grok/skills to it.
Inventory previously listed both paths, inflating owner routes past the
16-entry baseline and marking agentCustomize partial for normal depth.
@phodal

phodal commented Aug 2, 2026

Copy link
Copy Markdown
Member

Local validation update

I completed local validation against PR head fe4739f using Grok CLI 0.2.118 and Node.js 22.20.0.

The isolated skill-symlink path works: both native grok inspect --json and the Better Harness adapter discover better-harness when it is linked under $GROK_HOME/skills. The 127 focused tests pass, the full Node test suite exits successfully, pack:verify passes, and the English/Chinese Docusaurus production build succeeds. The current GitHub CI jobs are also green.

However, local validation found several issues that I believe should be addressed before merge:

  1. The configured-asset inventory does not match Grok's effective configuration. In the same workspace, native grok inspect --json reported 5 plugins, 28 skills, 1 hook, and 5 MCP servers, while agent-customize inventory --provider grok reported 0, 25, 0, and 0. The adapter hard-codes $GROK_HOME/installed-plugins, but Grok 0.2.118 discovers plugins from ~/.grok/plugins, project .grok/plugins, configured plugin paths, and compatibility sources. It also misses user ~/.agents/skills, project .grok/config.toml, and effective enablement/precedence.

  2. Tool lifecycle events are inflated. The adapter treats every tool_call_update as a terminal result, including progress and status-less updates. In one real local session, 20 raw tool calls became 46 normalized tool.result events, and all 20 invocation IDs had duplicate results.

  3. Token usage is mapped incorrectly. signals.contextTokensUsed is treated as total token consumption, while the actual _x.ai/session/update:turn_completed usage records are reduced to metadata. In the sampled session, the adapter emitted 44,532 total tokens while the recorded turn usage summed to 279,425.

  4. Messages are double-counted. Grok documents updates.jsonl as the authoritative conversation log, but the adapter also converts chat_history.jsonl into user/assistant events without correlation or deduplication.

  5. The Grok HTML default output route is unreachable. render-report.mjs checks options.platform/options.provider, but its argument parser rejects both flags. Running with --platform grok returns Unknown argument: --platform.

  6. Long workspace paths are not discoverable. When an encoded cwd exceeds 255 bytes, Grok uses a slug-plus-hash group directory and stores the original path in .cwd. The adapter only matches the direct encodeURIComponent(cwd) name.

  7. Directory-symlink traversal needs realpath-based visited tracking. Existing callers are depth-bounded, so the current automated review overstates the immediate unbounded-recursion risk, but cycles can still duplicate traversal and the shared helper defaults to infinite depth.

  8. A few readiness details remain open. The English homepage still says “Eight” adapters in two places; git diff --check fails on four trailing-whitespace lines in the spec; the spec smoke command invokes scripts/session-analysis/analyzer.mjs, which exits successfully without producing output instead of using the public scripts/session-analysis.mjs entrypoint; and the three commits do not include the repository-required single Co-authored-by line.

Because the synthetic fixtures currently encode several assumptions that differ from Grok 0.2.118's native behavior, green tests alone do not validate the claimed “Verified assets + sessions + HTML render path” boundary. Please align the adapter and fixtures with the native CLI output, then repeat the real-host comparison.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants