github mksglu/context-mode v1.0.162

5 hours ago

πŸš€ v1.0.162 β€” multilingual prompt analytics, accurate cost, 13 new extractors

13 commits Β· 8 PRD issues Β· 2 verify-gap fixes Β· 13 new test files Β· 80+ tracers since v1.0.161. Cross-repo PRD-driven sprint β€” wire-format expansion, privacy-first multilingual analytics, and a pricing accuracy catch-up that had been stale since v1.0.103. πŸ’œ


✨ Highlights

  • 🌍 Β§11 multilingual prompt features β€” Layer 1 expanded from 5 β†’ 10 typed columns plus a new prompt_word_tokens[] Layer 3 array, fully script-agnostic via Unicode property escapes (\p{L}, \p{Script=X}). Latin, Cyrillic, Han, Hangul, Arabic, Hebrew, Thai, Greek, Devanagari, Hiragana, Katakana β€” one code path, no franc / fasttext / compromise dependency. Bundle unchanged.
  • πŸ’° Honest cost accounting β€” MODEL_PRICING_USD_PER_MTOK lands with verified 2026-06 Anthropic rates (Opus 4.7/4.8 $5/$25, Sonnet 4.6 $3/$15, Haiku 4.5 $1/$5). extractAgentUsage derives cost_usd from per-model rates Γ— usage block. ctx-stats headline corrected from $1399.73 of Opus 4 tokens to $466.58 of Opus 4.7 tokens β€” same fixture, accurate rate (Opus 4 β†’ Opus 4.7 was a 3Γ— price cut that never propagated to analytics.ts).
  • πŸͺ 9 new event types from existing tool calls β€” bash_outcome, file_read_metadata, webfetch_metadata, worktree_exit, agent_usage, session_settings_snapshot, git_commit (discriminated from generic git), plan_enter (slash variant), and enriched plan_exit with plan_bytes/plan_hash. All ride the existing {...ev} envelope per ABI Β§5.4 β€” zero platform-side schema migrations.
  • 🩹 commit_message capture finally works β€” symmetric rollup stamp + per-event gate on type='git_commit'. POSIX argv tokenizer handles -m, -am, --message=, --message ARG, env-prefixed (GIT_AUTHOR=... git commit -m ...), --amend fallback, empty -m "". Closes the ~92% NULL-on-has_commit=1 ingestion drift surfaced by prod D1 telemetry.
  • 🧭 Cross-project attribution β€” git -C /other/path commit -m "x" from cwd=projectA now attributes to project B's canonical identity. Tilde (~/path) and equals-form (--directory=/path) both parsed correctly across macOS / Linux / Windows.
  • πŸ“ /plan slash fallback β€” Claude Code Bug #15660 workaround. The slash command emits plan_enter via UserPromptSubmit; ~60-80% of plan-mode entries that were previously telemetry-invisible (slash + Shift+Tab don't fire PostToolUse) are now captured. Shift+Tab remains upstream-blocked.
  • πŸ›‘οΈ Zero new runtime dependencies β€” 13 extractors, 22 multilingual feature paths, and a per-model pricing table added. Bundle stays at 58 KB total across all 5 hook bundles. Algorithmic POSIX argv parsing, FNV-1a hashing, Unicode regex via stdlib only.

🐞 Bug Fixes

Commit message capture (Bug 1 + Bug 2)

  • POSIX argv tokenizer for commit messages β€” extractGit parses -m, -am, --message=, separate-token --message, env-prefixed invocations, --amend fallback, and empty -m "". Emits type='git_commit' (distinct from generic git) when a message is captured. Symmetric rollup stamp via getSessionRollup so every event in a commit-bearing session carries commit_message, closing the asymmetric-NULL drift seen on platform D1.
  • Cross-project attribution (Bug 8) β€” git -C <dir> scope hint now flows through parseGitInvocation and shadows the in-batch inputProjectDir. Subsequent events in the same Bash call attribute to the scoped directory, not the hook's startup cwd.

Cost derivation (verify-gap Gap #1)

  • cost_usd on agent_usage β€” derives from tokens Γ— per-MTok rate using the new MODEL_PRICING table. Model resolution: tool_input.model β†’ input.model β†’ response.model β†’ default (Sonnet rates). Prefix match for date-suffixed ids (claude-haiku-4-5-20251001 β†’ claude-haiku-4-5). Zero-token sessions skip cost_usd so dashboards don't render $0.00 for nothing. Unknown model id falls back to default β€” never null.

Git parsing (verify-gap Gap #2)

  • Tilde expansion β€” git -C ~/repos/myrepo status now expands to $HOME/repos/myrepo (or USERPROFILE on Windows, with HOMEDRIVE+HOMEPATH fallback). ~user/path (other-user form) intentionally NOT expanded β€” bridge does not do passwd lookups.
  • --directory=value equals-form β€” parsed alongside the existing space-form --directory <value>. Tokenizer kept the equals-attached argument as one token; parser now slices on the --directory= prefix.

Prompt analytics (Issue #5 + Issue #8 Β§11)

  • Multilingual Layer 1 alignment β€” replaced the F1 Β§2 5-field stub with Β§11's 10-field shape: prompt_length, prompt_word_count, prompt_uppercase_ratio, prompt_file_ref_count, prompt_path_ref_count, prompt_script_primary, prompt_script_count, prompt_question_glyph_count (counts ASCII ?, fullwidth ?, Arabic ؟), prompt_code_block_count, prompt_url_count. The prompt_first_word field from the stub was removed β€” prompt_word_count covers the same insight script-agnostically.
  • Layer 3 word tokens β€” prompt_word_tokens: string[] carries letter-only words β‰₯3 chars, lowercased, deduplicated within the prompt. Platform UPSERTs into prompt_word_count(org_id, week, word, count) for emergent vocabulary surfacing at 5%-50% rate thresholds. Aggregated per org+week; no individual prompt token surfaces in any UI.

CI / cross-platform

  • Windows statusline timeout parity β€” slice-2 multi-adapter test now reuses STATUSLINE_SQLITE_TIMEOUT_MS (300s Windows / 30s elsewhere) instead of a stale hardcoded 60s. CI #401 had observed 186s with retry x2 on windows-latest β€” flake fixed.
  • 2 stale pricing-test assertions β€” format-cost.test.ts ($1399.73 β†’ $466.58 of Opus 4.7 tokens) and format-report-real-bytes.test.ts (regex updated). Both surfaced by the pricing-constant sync.

🎨 Features

  • 9 new event types for prompt analytics, cost accounting, and tool-response metadata β€” all ride the existing universal envelope ({...ev, platform, ts} per ABI Β§5.4). Platform Zod schema is forward-compatible; no wire-side migration required.
  • extractAgentUsage β€” fires on tool_name === "Task" (sub-agent dispatcher). Captures totalTokens, totalDurationMs, tokens_in, tokens_out, cache_create, cache_read, tier, plus derived cost_usd.
  • extractBashOutcome β€” three real signals from BashOutput: interrupted (bool), returnCodeInterpretation (semantic non-zero hint), stderr length-only (privacy). No exit_code field exists in the SDK; the verify-gap PRD's anti-hallucination block specifically flagged this.
  • extractFileReadMetadata β€” branches on text vs image variant. Text: numLines/totalLines/startLine. Image: originalSize/dimensions (formatted as WxH).
  • extractWebFetchMetadata β€” code/bytes/durMs/host. URL host extracted algorithmically (no regex), query string stripped before stamping. No redirect_url field exists; temporal correlation handles redirect-loop detection at the platform.
  • extractWorktree extended for ExitWorktree β€” emits worktree_exit with discard_changes flag, alongside the existing EnterWorktree handler.
  • extractPlan ExitPlanMode metadata β€” plan_bytes (length) + plan_hash (8-char FNV-1a hex) on the existing plan_exit event. Plan source: tool_input.plan first, fall back to tool_response.plan (SDK actually carries it on the OUTPUT per ExitPlanModeOutput @ sdk-tools.d.ts:2222).
  • extractSessionSettings β€” emits session_settings_snapshot from SessionStart with mcp_count, mcp_servers (first 8 names), model, permission_mode. Wired into emitSessionStartLifecycle opportunistically β€” never blocks lifecycle on snapshot failure.
  • extractUserPlan β€” UserPromptSubmit-driven /plan slash detector. Algorithmic char-code scan (no regex), word-boundary check so /plans does not match, argument truncated at 120 chars.

⚑ Performance

  • Zero bundle bloat β€” hooks/session-extract.bundle.mjs is 13,694 bytes, total of all 5 hook bundles is 58 KB. 13 new extractors + multilingual feature engine added with zero new runtime dependencies. esbuild minifies; nothing leaks.
  • Β§11 multilingual is O(n) per feature on the prompt string β€” prompt.match(/\p{L}+/gu) and the 11-script loop bound the cost. Spec-mandated p95 ≀ 15 ms on a 10 KB prompt.
  • FNV-1a 32-bit hash for plan_hash β€” deterministic, stable across platforms, no crypto library required.

πŸ“š Docs / Ops

  • Cross-PRD cross-repo workflow β€” this release closes 8 issues from 09-oss-handoff-prd.md and 2 gaps from 16-oss-verify-gap-prd.md. The verify-gap PRD is a separate-LLM verification pass on the OSS work β€” a novel cross-agent OSS workflow.
  • STYLE-ANCHOR-v1.0.152.md added to repo (developer-facing) β€” documents the v1.0.152 release-notes template so future releases stay community-grade. v1.0.153 through v1.0.161 will be rewritten to this style.
  • Anti-hallucination ground truth β€” every cited SDK line in the PRDs was re-verified against refs/platforms/claude-code/sdk-tools.d.ts before implementation. The verify-gap PRD specifically flagged stale citations (BashOutput.exit_code does not exist; WebFetchOutput.redirect_url does not exist) β€” both correctly worked around in the new extractors.

πŸ“‹ PRD-driven work

This release is the first end-to-end product of the OSS handoff + verify-gap cross-PRD pipeline:

PRD Repo Issues / Gaps closed
09-oss-handoff-prd.md v3 context-mode-platform #1 release, #2 AgentOutput.usage, #3 FileReadOutput, #4 SessionStart settings, #5 Β§11 alignment, #6 ExitPlanMode, #7 ExitWorktree, #8 Layer 3 word_tokens
16-oss-verify-gap-prd.md context-mode-platform Gap #1 (P1) cost_usd, Gap #2 (P2) tilde / --directory= git parsing
10-prompt-analytics-strategy.md context-mode-platform F1 Β§2 β†’ Β§11 alignment (signal catalog reference)
11-multilingual-prompt-algorithm.md context-mode-platform Verbatim mirror in src/session/extract.ts:extractUserPromptFeatures

PRD design, verification, and cross-repo authoring by @mksglu. Verify-gap PRD authored by a separate LLM-as-PO instance to ensure the OSS bridge didn't over-promise.


🚫 Intentionally out of scope

To keep the release scope honest:

  • Shift+Tab plan-mode detection β€” Claude Code Bug #15660 needs an upstream SDK fix. Only /plan slash is captured.
  • OpenCode / Qwen / Kilo hook bridges β€” deferred to a future adapter-coverage release.
  • Bash exit_code β€” SDK does not expose it. The three real signals (interrupted, returnCodeInterpretation, stderr length) are captured instead.
  • WebFetch redirect_url β€” does not exist on the SDK. Redirect-loop detection is temporal-correlation on the platform.
  • Top-level typed DB columns for agent_usage token fields β€” stays in event.data until platform observes and auto-migrates per ABI Β§5.4. Local SessionDB stays slim deliberately.
  • Fast-mode Opus / Sonnet pricing tiers β€” separate model ids not mapped; would dilute standard-tier dashboards.

🎟️ Closed issues / Gaps

#3 Β· #4 Β· #5 Β· #6 Β· #7 Β· #8 β€” v1.0.162 PRD. Gap #1 + Gap #2 β€” verify-gap PRD. Bug 1 + Bug 2 + Bug 8 β€” pre-release hotfixes folded into this release.


πŸ“¦ Install / upgrade

# Fresh install (Claude Code plugin marketplace)
/plugin add https://github.com/mksglu/context-mode

# npm global
npm install -g context-mode@1.0.162

# Existing install β€” in-place upgrade
context-mode upgrade

Then restart your MCP session (or run /reload-plugins in Claude Code).

πŸ”— Full changelog

v1.0.161...v1.0.162


πŸ€– Powered by context-mode-ops parallel orchestration β€” 3 paralel research agent + grill-me discipline + cross-PRD doğrulama + verify-gap LLM kontrolΓΌ. Codex EM bot'unu geΓ§tik mi acaba? πŸ˜‰

Don't miss a new context-mode release

NewReleases is sending notifications on new releases.