Skip to content

fix: validate and correct AI agent skill examples - #73

Open
kayx23 wants to merge 6 commits into
masterfrom
agent/skills-hub-rework
Open

fix: validate and correct AI agent skill examples#73
kayx23 wants to merge 6 commits into
masterfrom
agent/skills-hub-rework

Conversation

@kayx23

@kayx23 kayx23 commented Aug 6, 2026

Copy link
Copy Markdown

Summary

  • correct stale command names and flags in the API7 persona skills
  • migrate authentication examples to credential subresources
  • align service and route examples with the current API7 resource model
  • extend skill tests to validate shell examples against the current Cobra command tree
  • document project-scoped, per-skill installation and approval-first agent usage

Why

The Skills Hub audit found that the existing validation could pass while skill bodies still referenced removed commands, flags, malformed credential requests, and outdated resource relationships. Agents may execute these examples directly, so command examples need validation against the released CLI surface.

Impact

This is a documentation and test change. It does not alter a7 runtime behavior. The extended test fails when a shell example uses an unknown command or long flag.

Validation

  • make validate-skills
  • make test-skills

Follow-up

After merge, publish a reviewed skill-bearing release so api7/docs can pin the redesigned Skills Hub catalog to this corrected artifact.

Summary by CodeRabbit

  • Documentation

    • Clarified supported installation targets, focused installation, safe first-run procedures, and local validation steps.
    • Updated CLI examples for current command names, options, route IDs, credential setup, service configuration, routing, and logging.
    • Added guidance for protecting private keys and limiting or redacting request headers during troubleshooting.
    • Updated gateway-group and multi-tenant examples to use explicit names, descriptions, and reusable IDs.
  • Tests

    • Added automated validation for shell commands, flags, positional arguments, multiline commands, and nested CLI help paths in skill documentation.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: dd3433f7-9ade-4baf-8876-2ae6e1df8aaa

📥 Commits

Reviewing files that changed from the base of the PR and between 69a08a2 and b447495.

📒 Files selected for processing (1)
  • skills/a7-recipe-multi-tenant/SKILL.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • skills/a7-recipe-multi-tenant/SKILL.md

📝 Walkthrough

Walkthrough

Changes

Skill documentation

Layer / File(s) Summary
Installation and validation guidance
docs/skills.md
Documents supported installation targets, skill selection, copy-only installation, safe first-run steps, and local and CI validation commands.
CLI workflow examples
skills/a7-persona-*/SKILL.md, skills/a7-plugin-{basic-auth,hmac-auth,key-auth,jwt-auth}/SKILL.md, docs/user-guide/gateway-group.md
Updates API7 CLI commands, trace options, credential workflows, service creation, route references, and gateway-group flags.
Global rule and tenant workflows
skills/a7-plugin-{http-logger,kafka-logger,prometheus,skywalking,zipkin}/SKILL.md, skills/a7-recipe-multi-tenant/SKILL.md
Uses CLI-derived Global Rule IDs and captured gateway-group IDs across multi-tenant resource, sync, and verification commands.
Skill command validation
test/e2e/skills/skills_test.go
Parses shell examples and validates API7 CLI commands, nested commands, flags, values, and positional arguments through CLI help resolution.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SkillDocs
  participant SkillsTest
  participant A7CLI
  SkillDocs->>SkillsTest: provide fenced shell examples
  SkillsTest->>SkillsTest: tokenize and resolve commands
  SkillsTest->>A7CLI: request command help
  A7CLI-->>SkillsTest: return commands and flags
  SkillsTest-->>SkillDocs: report validation errors
Loading
🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
E2e Test Quality Review ⚠️ Warning Blocking: the added E2E test only builds a7 and invokes --help while scanning Markdown; it never executes a documented API/resource flow or checks payload relationships. Add a disposable API7-backed test, or a justified request-capture harness, that runs representative credential, service, and route flows and asserts their relationships and invalid cases.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: correcting AI agent skill examples and adding validation for them.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Security Check ✅ Passed The PR changes only 14 docs and one validation test; no production handlers, persistence, logging, TLS, authorization, or secret-resolution code changed, and sample secrets pre-existed.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/skills-hub-rework

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 04835b138d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread test/e2e/skills/skills_test.go Outdated
Comment thread test/e2e/skills/skills_test.go Outdated

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@skills/a7-plugin-jwt-auth/SKILL.md`:
- Around line 148-153: Update the RS256 setup instructions around the credential
creation command to ensure consumer bob exists first: either add the consumer
creation step before a7 credential create or associate the credential with an
already existing consumer. Preserve the --consumer bob association when using
the newly created consumer.

In `@test/e2e/skills/skills_test.go`:
- Around line 221-227: Update the skill-file validation setup before the loop
over matches to fail the test when filepath.Glob returns an empty slice. Keep
the existing filepath.Glob error handling and per-file validation unchanged.
- Around line 285-303: Update resolveCommand to reject an unknown non-flag,
non-argument token when availableCommands(help) advertises nested subcommands,
instead of silently treating it as positional. Preserve handling for flags and
valid positional arguments, and add a regression case covering a misspelled
nested command such as a7 global-rule crte.
- Around line 240-245: Update the flag validation loop using longFlagPattern and
validHelp so it parses complete flag tokens from the help output, builds exact
flag-name membership, and checks each discovered flag against that set instead
of using strings.Contains. Preserve the existing --help exclusion and
unsupported-flag failure behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 74c924ec-e595-4f58-b4f3-62c819a70253

📥 Commits

Reviewing files that changed from the base of the PR and between 8f79c4c and 04835b1.

📒 Files selected for processing (13)
  • docs/skills.md
  • skills/a7-persona-developer/SKILL.md
  • skills/a7-persona-operator/SKILL.md
  • skills/a7-plugin-basic-auth/SKILL.md
  • skills/a7-plugin-hmac-auth/SKILL.md
  • skills/a7-plugin-http-logger/SKILL.md
  • skills/a7-plugin-jwt-auth/SKILL.md
  • skills/a7-plugin-kafka-logger/SKILL.md
  • skills/a7-plugin-key-auth/SKILL.md
  • skills/a7-plugin-prometheus/SKILL.md
  • skills/a7-plugin-skywalking/SKILL.md
  • skills/a7-plugin-zipkin/SKILL.md
  • test/e2e/skills/skills_test.go

Comment thread skills/a7-plugin-jwt-auth/SKILL.md Outdated
Comment thread test/e2e/skills/skills_test.go
Comment thread test/e2e/skills/skills_test.go Outdated
Comment thread test/e2e/skills/skills_test.go Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 60dc7c1a32

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread skills/a7-persona-developer/SKILL.md Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e1f0ebb004

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread test/e2e/skills/skills_test.go Outdated
Comment thread test/e2e/skills/skills_test.go

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
test/e2e/skills/skills_test.go (1)

18-19: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Check only real CLI flags for shell blocks.

longFlagPattern runs over the joined shell line, so a7 init --name="text --nested" and comment text containing --comment are reported as unsupported flags. Parse flags from fields/subfields first, then handle =value assignments, before comparing against valid flags.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/e2e/skills/skills_test.go` around lines 18 - 19, Update the shell-block
flag validation around longFlagPattern to tokenize each parsed shell field and
its subfields before matching long options, rather than scanning the joined
command text. Strip or separately handle =value assignments before comparing
flags against the valid-flag set, so quoted values and comments containing
--text are not reported as CLI flags.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@skills/a7-plugin-jwt-auth/SKILL.md`:
- Around line 157-168: Clarify the `bob-rs256-credential.yaml` instructions so
the `public_key` value is unambiguous: either instruct readers to paste only the
base64 text between the `public.pem` delimiters while retaining the template
delimiters, or remove the template delimiters and instruct them to paste the
complete PEM block. Ensure the final guidance cannot produce duplicated PEM
headers or footers.

---

Outside diff comments:
In `@test/e2e/skills/skills_test.go`:
- Around line 18-19: Update the shell-block flag validation around
longFlagPattern to tokenize each parsed shell field and its subfields before
matching long options, rather than scanning the joined command text. Strip or
separately handle =value assignments before comparing flags against the
valid-flag set, so quoted values and comments containing --text are not reported
as CLI flags.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1ded68dc-6061-4d06-b698-f217a2173616

📥 Commits

Reviewing files that changed from the base of the PR and between 04835b1 and e1f0ebb.

📒 Files selected for processing (6)
  • docs/user-guide/gateway-group.md
  • skills/a7-persona-developer/SKILL.md
  • skills/a7-persona-operator/SKILL.md
  • skills/a7-plugin-jwt-auth/SKILL.md
  • skills/a7-recipe-multi-tenant/SKILL.md
  • test/e2e/skills/skills_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • skills/a7-persona-developer/SKILL.md
  • skills/a7-persona-operator/SKILL.md

Comment thread skills/a7-plugin-jwt-auth/SKILL.md

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be9c0b3036

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread skills/a7-plugin-http-logger/SKILL.md
Comment thread skills/a7-recipe-multi-tenant/SKILL.md Outdated
Comment thread test/e2e/skills/skills_test.go

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 69a08a2ffd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread skills/a7-recipe-multi-tenant/SKILL.md Outdated

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (3)
test/e2e/skills/skills_test.go (3)

409-452: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Cache commandHelp results.

resolveCommand calls commandHelp for the first token and again for every resolved subcommand. The test runs this for every a7 invocation in every SKILL.md. Each call starts the built a7 binary, so the same help output is produced many times. Add a memo keyed by the joined command path.

♻️ Proposed refactor
+var (
+	helpCacheMu sync.Mutex
+	helpCache   = map[string]string{}
+)
+
+func cachedCommandHelp(t *testing.T, path []string) string {
+	t.Helper()
+	key := strings.Join(path, " ")
+	helpCacheMu.Lock()
+	defer helpCacheMu.Unlock()
+	if help, ok := helpCache[key]; ok {
+		return help
+	}
+	help := commandHelp(t, path)
+	helpCache[key] = help
+	return help
+}

Then replace the commandHelp(t, path) calls in resolveCommand with cachedCommandHelp(t, path).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/e2e/skills/skills_test.go` around lines 409 - 452, Cache command help
output by joined command path: add a memoized cachedCommandHelp helper and
replace both commandHelp calls in resolveCommand, including the initial path and
each resolved subcommand, while preserving existing help lookup behavior.

302-324: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Derive the global value flags from the command tree.

a7GlobalValueFlags hardcodes the persistent flags that rootcmd.NewCmd declares. commandFields also builds the map again on every call. If a persistent flag is added or renamed in pkg/cmd/root/root.go, this map goes stale and the test silently mis-parses examples.

Build the set once from newA7CommandTree().PersistentFlags() and pass it to commandFields.

♻️ Proposed refactor
-func commandFields(fields []string) []string {
-	valueFlags := a7GlobalValueFlags()
+func commandFields(fields []string, valueFlags map[string]bool) []string {
 	for len(fields) > 0 && strings.HasPrefix(fields[0], "-") {
 		flag := strings.SplitN(fields[0], "=", 2)[0]
 		hasInlineValue := strings.Contains(fields[0], "=")
 		fields = fields[1:]
 		if valueFlags[flag] && !hasInlineValue && len(fields) > 0 {
 			fields = fields[1:]
 		}
 	}
 	return fields
 }
 
-func a7GlobalValueFlags() map[string]bool {
-	return map[string]bool{
-		"--gateway-group": true,
-		"--output":        true,
-		"--server":        true,
-		"--token":         true,
-		"-g":              true,
-		"-o":              true,
-	}
-}
+func a7GlobalValueFlags(root *cobra.Command) map[string]bool {
+	valueFlags := map[string]bool{}
+	root.PersistentFlags().VisitAll(func(flag *pflag.Flag) {
+		if flag.NoOptDefVal != "" {
+			return
+		}
+		valueFlags["--"+flag.Name] = true
+		if flag.Shorthand != "" {
+			valueFlags["-"+flag.Shorthand] = true
+		}
+	})
+	return valueFlags
+}

Update the two call sites at Line 230 and Line 280 to pass commandTree.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/e2e/skills/skills_test.go` around lines 302 - 324, Replace the hardcoded
a7GlobalValueFlags map with a value-flag set derived once from
newA7CommandTree().PersistentFlags(), and update commandFields to accept that
set instead of constructing it internally. Adjust both commandFields call sites
around the existing test flows to pass the command tree-derived flags, keeping
argument parsing behavior unchanged.

284-292: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider dropping the help-text flag scan.

longFlagPattern.FindAllString(invocation, -1) scans the raw invocation string, including quoted values and text after a -- separator. It then validates against a set parsed from help output, where a flag name inside a description also becomes "valid". positionalArgs already resolves each flag through lookupFlag and lookupShorthandFlag on the exact Cobra command, which is stricter and token-aware.

Remove this block and rely on validatePositionalArgs, or keep it only for the shorthand cases that positionalArgs does not reach.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/e2e/skills/skills_test.go` around lines 284 - 292, Remove the
longFlagPattern-based validation loop that scans raw invocation text and relies
on help-derived validFlags. Use validatePositionalArgs and its token-aware
lookupFlag/lookupShorthandFlag validation as the sole long-flag validation path,
preserving shorthand validation only if those cases are not covered there.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@test/e2e/skills/skills_test.go`:
- Around line 409-452: Cache command help output by joined command path: add a
memoized cachedCommandHelp helper and replace both commandHelp calls in
resolveCommand, including the initial path and each resolved subcommand, while
preserving existing help lookup behavior.
- Around line 302-324: Replace the hardcoded a7GlobalValueFlags map with a
value-flag set derived once from newA7CommandTree().PersistentFlags(), and
update commandFields to accept that set instead of constructing it internally.
Adjust both commandFields call sites around the existing test flows to pass the
command tree-derived flags, keeping argument parsing behavior unchanged.
- Around line 284-292: Remove the longFlagPattern-based validation loop that
scans raw invocation text and relies on help-derived validFlags. Use
validatePositionalArgs and its token-aware lookupFlag/lookupShorthandFlag
validation as the sole long-flag validation path, preserving shorthand
validation only if those cases are not covered there.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2aa63aab-fdd6-44ec-84f5-17bd2afd5d66

📥 Commits

Reviewing files that changed from the base of the PR and between e1f0ebb and 69a08a2.

📒 Files selected for processing (8)
  • skills/a7-plugin-http-logger/SKILL.md
  • skills/a7-plugin-jwt-auth/SKILL.md
  • skills/a7-plugin-kafka-logger/SKILL.md
  • skills/a7-plugin-prometheus/SKILL.md
  • skills/a7-plugin-skywalking/SKILL.md
  • skills/a7-plugin-zipkin/SKILL.md
  • skills/a7-recipe-multi-tenant/SKILL.md
  • test/e2e/skills/skills_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • skills/a7-plugin-skywalking/SKILL.md
  • skills/a7-plugin-kafka-logger/SKILL.md
  • skills/a7-plugin-prometheus/SKILL.md
  • skills/a7-plugin-http-logger/SKILL.md

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