fix: surface skill directory in the loaded-skill context block#785
Merged
Conversation
When a skill was loaded inline (via the Skill tool or a slash command),
the <kimi-skill-loaded> block carried name/trigger/source/args but not
the skill's directory. The agent therefore had no way to locate the
skill's bundled resources (scripts, templates) by relative path unless
the SKILL.md author manually embedded ${KIMI_SKILL_DIR} in the body.
Emit the skill's directory as a `dir` attribute on the loaded block so
the path is always present in context and persists across resume.
Add regression coverage: a prompt-renderer unit test (dir present for
each trigger, XML-escaped, omitted when absent) and an end-to-end
harness test that loads a skill shipping a helper script, resumes in a
fresh runtime, and asserts the directory survives in the rebuilt context.
🦋 Changeset detectedLatest commit: 568e601 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 47bf28f191
ℹ️ 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".
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.
Problem
When a skill is loaded inline — via the
Skilltool (model-invoked) or a/slashcommand (user-invoked) — its body is wrapped in a<kimi-skill-loaded>block before being appended to the agent's context. That block carriedname,trigger,source, andargsattributes, but never the skill's directory.As a result, once a skill was loaded the agent had no way to know where it lived on disk, so it couldn't locate the skill's bundled resources (scripts, templates, data files) by relative path. The only workaround was for the SKILL.md author to manually embed
${KIMI_SKILL_DIR}in the body — which most skills don't.Fix
Always surface the skill's directory on the loaded block:
agent/skill/prompt.ts— add an optionalskillDirtoRenderSkillPromptInput; emit it as an XML-escapeddirattribute (betweensourceandargs).tools/builtin/collaboration/skill-tool.ts— passskillDir: skill.dir(model-tool / nested path).agent/skill/index.ts— passskillDir: skill.dir(user-slash path).SkillDefinitionalready exposeddir, so no new plumbing was needed. The attribute is written towire.jsonl, so it persists and reloads with the conversation on resume.Tests
test/agent/skill-prompt.test.ts— prompt-renderer unit coverage:dirpresent for model-tool / nested-skill / user-slash triggers, XML-escaped, and omitted when no directory is supplied (backward-compat).test/harness/skill-session.test.ts— loads a skill that ships a helper script (and deliberately does not embed${KIMI_SKILL_DIR}), resumes the session in a fresh runtime, and asserts the directory survives in the rebuilt on-disk context and resolves the bundled resource.skill-tool.test.ts,skill-tool-manager.test.ts, andnode-sdk/test/session-skills.test.tsto expect the new attribute.All affected suites pass (38 agent-core skill tests + 6 node-sdk); typecheck clean for both packages.
Real-world verification
Confirmed against a live session (
govuk-plain-english, user-slash activation): the loaded block inwire.jsonlnow reads… source="user" dir="/Users/.../.agents/skills/govuk-plain-english" args="">, the directory exists and holds the skill's resources, and the path is surfaced by the wrapper (the SKILL.md body does not reference its own path).