Skip to content

feat(skills): progressive discovery from centralized skills catalog - #973

Merged
edenreich merged 16 commits into
mainfrom
fix/issue-972
Jul 31, 2026
Merged

edenreich merged 16 commits into
mainfrom
fix/issue-972

Conversation

@inference-gateway-maintainer

Copy link
Copy Markdown
Contributor

Resolves #972

Summary

Adds progressive skill discovery from the centralized skills catalog (inference-gateway/skills). When agent.skills.discovery.enabled is true, the agent can discover and fetch skills at runtime from the registry when no local skill of that name exists. Local skills always take precedence. The feature is disabled by default and gated behind a config toggle.

Changes

  • config/config.go: Added SkillsDiscoveryConfig struct with Enabled, RegistryURL, and Cleanup fields to AgentSkillsConfig
  • internal/domain/skills.go: Added SkillScopeCatalog scope and Discover/CleanupDynamic methods to SkillsService interface
  • internal/services/skills/catalog.go: New file implementing CatalogClient for fetching skill metadata from the registry index (index.json) and downloading skill bodies on demand, reusing the existing Installer
  • internal/services/skills/skills.go: Implemented Discover (progressive lookup + download) and CleanupDynamic (post-session cleanup) methods on the Service struct
  • internal/agent/agent_utils.go: Added SKILLS DISCOVERY section to the system prompt when discovery is enabled, explaining how to fetch skills from the registry; omitted when disabled (YAGNI - tokens saving)
  • internal/container/container.go: Wired CleanupDynamic call in Shutdown for post-session cleanup
  • docs/skills.md: Documented the full discovery order including the catalog as the last fallback, with config example

Adds SkillsDiscoveryConfig with Enabled/RegistryURL/Cleanup fields to AgentSkillsConfig. Adds SkillScopeCatalog scope and Discover/CleanupDynamic methods to SkillsService interface. Implements CatalogClient for fetching skill metadata from the registry index and downloading skill bodies on demand, reusing the existing Installer. Adds SKILLS DISCOVERY section to system prompt when discovery is enabled (omitted when disabled). Wires CleanupDynamic in container Shutdown. Updates docs/skills.md with full discovery order including catalog fallback.
@edenreich
edenreich marked this pull request as ready for review July 30, 2026 21:15
@edenreich
edenreich requested a review from a team as a code owner July 30, 2026 21:15
Comment thread internal/agent/agent_utils.go Resolved
Comment thread internal/container/container.go Resolved
Comment thread internal/services/skills/catalog.go Resolved
Comment thread internal/services/skills/catalog.go Resolved
Comment thread internal/services/skills/skills.go Resolved
Comment thread internal/services/skills/skills.go Resolved
Comment thread internal/services/skills/skills.go Resolved
Comment thread internal/services/skills/skills.go Resolved
Comment thread internal/services/skills/skills.go Resolved
Comment thread internal/services/skills/skills.go Resolved
Comment thread internal/services/skills/skills.go Resolved
Comment thread internal/services/skills/skills.go Resolved
Comment thread config/config.go Resolved
Comment thread internal/agent/agent_utils_test.go Resolved
Comment thread internal/services/skills/skills.go Resolved
…on path

Skill discovery shipped config, an HTTP client and a prompt paragraph but no
execution path: the catalog index was never listed and Discover had no
production callers, so catalog skills never reached the / dropdown.

- catalog: extract a cached Index() from Lookup, fix the default registry to
  catalog.json in inference-gateway/skills, and authenticate the index fetch
  with GITHUB_TOKEN/GH_TOKEN (only for GitHub hosts, so a custom registry_url
  never sees the token)
- skills: merge catalog entries into Load as metadata-only skills with an
  empty Path; Discover fills that Path in place and resolves local skills
  before the discovery gate
- agent: render catalog entries in AVAILABLE SKILLS without a path so the
  static system prompt stays byte-stable when a skill is installed mid-session;
  the concrete path rides in the per-request volatile tail
- chat: prompt for approval before installing a catalog skill, remembering
  declines for the session; headless installs without approval
- ui: color not-installed catalog skills distinctly in the dropdown and input
inference-gateway/skills was hardcoded in two places - the install shorthand
constants and the catalog registry URL - so pointing registry_url at a private
catalog still downloaded the skill bodies from the public repo.

agent.skills.repository (INFER_AGENT_SKILLS_REPOSITORY) now drives all three:
the `infer skills install <name>` shorthand, on-demand catalog downloads, and
the catalog index base, which is derived from it when registry_url is unset. An
explicit registry_url still wins for a catalog hosted outside the repo. A
malformed value is rejected at config load rather than 404ing later.
…prompt

The AVAILABLE SKILLS block applied max_chars inside its loop and then appended
the name of every omitted skill, so a 1000-entry catalog produced ~20KB against
a 4000-char budget. That string rides in the static system prompt, so the cost
was paid on every request and sat in the KV-cache prefix.

Skills with a local SKILL.md are now expanded first, since those are the ones
the model can Read, and the tail is a count pointing at the new search command
rather than a list of names. Catalog descriptions are truncated to the same
limit local skills are validated against, and the index response is capped with
an io.LimitReader.

`infer skills search [term]` fuzzy-matches names and word-matches descriptions
over the fetched index, since catalog.json is a static file with no server-side
query. Descriptions are truncated to keep the table readable (--no-trunc for
the full text) and the header shows the catalog release.
registry_url only redirected the catalog index; the skill bodies always
resolved against agent.skills.repository. So a catalog hosted elsewhere could
only ever list skills that live in that repo anyway, which makes it a knob
promising something the code cannot deliver.

agent.skills.repository already drives the index, the downloads, and the
install shorthand together. Tests keep an unexported newCatalogClientWithBase
seam for pointing at an httptest server.

The key never shipped on main, so there is nothing to migrate.
The Installed column said yes or no. The path is what you want next once
you know a skill is on disk, and it says the same thing by being present.

Rendered relative to the working directory for a project skill and
~-prefixed for a user-global one - an absolute path is 80+ columns and
wraps the table borders the description truncation was added to avoid.
JSON output keeps installed as a bool and adds path.
@edenreich
edenreich merged commit 84b3f57 into main Jul 31, 2026
1 check passed
@edenreich
edenreich deleted the fix/issue-972 branch July 31, 2026 09:07
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.155.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Jul 31, 2026
edenreich added a commit that referenced this pull request Sep 20, 2026
)

## The crash

`infer chat` panics and tears down the TUI the moment `/` is typed:

```
strings: negative Repeat count
strings.Repeat(...)
  tui/autocomplete.(*AutocompleteImpl).renderItems(..., 0x3, 0x1c, 0xb3)
    autocomplete.go:981
```

## Root cause — bytes used as display columns

`formatting.TruncateText` cuts to **display columns**
(`ansi.StringWidth` / `ansi.Truncate`), but `renderItems` padded the
result with `len()` — **bytes**:

```go
description := formatting.TruncateText(cmd.Description, descWidth)
paddedDescription := description + strings.Repeat(" ", descWidth-len(description))
```

One multibyte rune in a description long enough to be truncated pushes
`len()` past the column budget and the count goes negative.

Reproduced with the exact values from the trace: at a 214-column
terminal `descWidth = 214 - 28 - 7 = 179` (the `0xb3`). The
`motion-graphics` skill description truncated to 179 columns is **181
bytes** → `strings.Repeat(" ", -2)`.

## Why it surfaced now

The code was correct until the contract changed under it:

| when | what |
| --- | --- |
| 2026-06-27 | #667 flips `TruncateText` from `len(text) <= maxLength`
(bytes) to `ansi.StringWidth` (columns) — this caller was not touched,
and its padding silently became wrong |
| 2026-07-31 | #973 wires the skills catalog into the autocomplete list,
so skill descriptions reach this renderer |
| 2026-09-16 | `inference-gateway/skills#132` adds `motion-graphics` —
the only one of 25 catalog entries with a non-ASCII description (`—`
U+2014, `→` U+2192) |

Before #667 `len(truncated) <= maxLength` was guaranteed, so the
subtraction could never go negative. Nothing in the CLI changed in
September; the catalog data did.

## The fix

One helper beside the function whose contract caused it, so truncation
and padding always happen in the same unit:

```go
func PadText(text string, width int) string {
	text = TruncateText(text, width)
	return text + strings.Repeat(" ", max(0, width-ansi.StringWidth(text)))
}
```

- `autocomplete.go` — both columns route through `PadText`;
`calculateMaxShortcutWidth` measures with `ansi.StringWidth` instead of
`len`.
- `task_management_view.go` — the two separators now use the
`getSeparatorWidth()` guard that already existed for exactly this case
(`strings.Repeat("─", t.width-4)` panics below 4 columns, and `t.width`
is 0 until the first `WindowSizeMsg`). One copy had no guard; the other
inlined a duplicate of it, now deleted.

`lipgloss.NewStyle().Width(n)` was considered and rejected — it *wraps*
overflow instead of truncating, which would turn one table row into
several.

## Tests

- `TestPadText` — table-driven, asserts `ansi.StringWidth(got) == width`
and valid UTF-8 across narrow-multibyte, wide-rune and ASCII inputs.
- `TestAutocomplete_RenderMultibyteDescription` — feeds the real failing
shape at 214/60/20 columns and asserts the rows stay column-aligned.

Verified the regression test earns its keep: reverting just the two pad
lines makes it panic with the identical `strings: negative Repeat
count`; restoring the fix passes.

## Checks

- `task precommit:run` — 0 issues
- `go test ./internal/presentation/... ./internal/platform/...` — green

## Notes

No docs ticket: bug fix, no public surface change. No cross-repo impact
— the trigger data lives in `inference-gateway/skills`, but nothing
there needs changing.

Found during the sweep, left for separate PRs:

- `task_management_view.go:1116-1152` pads with `%-38s` (rune count)
against a column budget — misalignment only, no panic.
- `agent/infrastructure/formatter.go:258` still does a raw
`text[:maxLength-3]` byte slice and emits invalid UTF-8 on multibyte
input; its own test documents this at `formatter_units_test.go:86`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Dynamic skills: progressive discovery from the centralized skills catalog

1 participant