Skip to content

feat(cli): --format auto (infer workflow format) — keystone for the agent-hook play#59

Open
hatyibei wants to merge 1 commit into
mainfrom
feat/format-auto-detect
Open

feat(cli): --format auto (infer workflow format) — keystone for the agent-hook play#59
hatyibei wants to merge 1 commit into
mainfrom
feat/format-auto-detect

Conversation

@hatyibei

Copy link
Copy Markdown
Owner

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 --format was required (default json), 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 auto infers the format from extension + a lightweight content sniff, so a hook can run shingan analyze --format auto --input <file> on anything and skip cleanly when nothing matches.

Detection

ext resolves to
.py pydantic-graph / crewai / llamaindex / autogen / langgraph (by import)
.ts .js .mts mastra / openai-agents / langgraph-js
.go adk-go (google.golang.org/adk / LoopAgent signatures)
.json n8n (n8n-nodes-* / @n8n/* node types) else generic json
  • The n8n signature is the node type string near the top of the nodes array, so detection is robust even when the trailing connections block sits past the 16KB sniff window (a real failure I hit on a 38-node export — fixed + regression-tested).
  • Directories resolve to the most common framework; a generic json hit never wins over a framework hit.
  • Unrecognised input returns "" → 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; auto is 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 vet green.

Next (not in this PR)

With --format auto landed, the follow-up is a Claude Code / Cursor hook that runs shingan analyze --format auto on 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

…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>
@ecc-tools

ecc-tools Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR.

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.

1 participant