feat(cli): --format auto (infer workflow format) — keystone for the agent-hook play#59
Open
hatyibei wants to merge 1 commit into
Open
feat(cli): --format auto (infer workflow format) — keystone for the agent-hook play#59hatyibei wants to merge 1 commit into
hatyibei wants to merge 1 commit into
Conversation
…ontent
Until now `--format` had to be passed explicitly (default "json"), which makes
an editor/agent hook awkward: a hook that fires on a saved file can't know
whether it's n8n, LangGraph, CrewAI, … up front. `--format auto` infers it from
the file extension plus a lightweight content sniff (import statements /
node-type signatures), so a hook can run `shingan analyze --format auto --input
<file>` on anything and skip cleanly when nothing matches.
Detection:
.py -> pydantic-graph | crewai | llamaindex | autogen | langgraph
.ts/.js/… -> mastra | openai-agents | langgraph-js
.go -> adk-go (google.golang.org/adk / LoopAgent signatures)
.json -> n8n (n8n-nodes-*/@n8n/* node types, robust even when the trailing
`connections` block sits past the 16KB sniff window) else json
Directories resolve to the most common framework; a generic json hit never
wins over a framework hit. Unrecognised input returns "" so the CLI errors
clearly ("pass --format explicitly") instead of mis-parsing.
Measured on 308 real n8n workflows: 307/308 auto-detected as n8n (the one miss
is a node-catalog file, not a workflow). Default stays "json" for backward
compatibility; "auto" is opt-in.
Tests: cli/detect_test.go (per-format files, large-export sniff-window case,
dir-prefers-framework, missing path). go test ./cli/ + go vet green.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The keystone for the agent/editor hook distribution play (ADR-019 direction): a hook that fires when an AI agent saves a workflow file can't know the framework up front. Until now
--formatwas required (defaultjson), so a hook had to hard-code one format — and the existing pre-commit hook does exactly that (--format langgraph), breaking on any other project.--format autoinfers the format from extension + a lightweight content sniff, so a hook can runshingan analyze --format auto --input <file>on anything and skip cleanly when nothing matches.Detection
.py.ts.js.mts….gogoogle.golang.org/adk/LoopAgentsignatures).jsonn8n-nodes-*/@n8n/*node types) else genericjsonnodesarray, so detection is robust even when the trailingconnectionsblock sits past the 16KB sniff window (a real failure I hit on a 38-node export — fixed + regression-tested).jsonhit never wins over a framework hit.""→ the CLI errors clearly (pass --format explicitly) instead of mis-parsing.Accuracy
Measured on 308 real n8n workflows (
enescingoz/awesome-n8n-templates): 307/308 auto-detected as n8n. The one miss is a node-catalog file, not a workflow.Compatibility
Default stays
json;autois opt-in. No existing behaviour changes.Tests
cli/detect_test.go: per-format files (all 11 formats + unknown), large-export sniff-window case, dir-prefers-framework, missing path.go test ./cli/+go vetgreen.Next (not in this PR)
With
--format autolanded, the follow-up is a Claude Code / Cursor hook that runsshingan analyze --format autoon saved workflow files and blocks on Critical findings (the self-repair loop). The low-FP work in #56/#58 is what makes that safe to put inside an agent's context.🤖 Generated with Claude Code