Skip to content

fix: surface skill directory in the loaded-skill context block#785

Merged
chengluyu merged 2 commits into
mainfrom
fix/persistent-skill-read
Jun 15, 2026
Merged

fix: surface skill directory in the loaded-skill context block#785
chengluyu merged 2 commits into
mainfrom
fix/persistent-skill-read

Conversation

@chengluyu

Copy link
Copy Markdown
Collaborator

Problem

When a skill is loaded inline — via the Skill tool (model-invoked) or a /slash command (user-invoked) — its body is wrapped in a <kimi-skill-loaded> block before being appended to the agent's context. That block carried name, trigger, source, and args attributes, 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:

<kimi-skill-loaded name="…" trigger="…" source="…" dir="/abs/path/to/skill" args="…">
  • agent/skill/prompt.ts — add an optional skillDir to RenderSkillPromptInput; emit it as an XML-escaped dir attribute (between source and args).
  • tools/builtin/collaboration/skill-tool.ts — pass skillDir: skill.dir (model-tool / nested path).
  • agent/skill/index.ts — pass skillDir: skill.dir (user-slash path).

SkillDefinition already exposed dir, so no new plumbing was needed. The attribute is written to wire.jsonl, so it persists and reloads with the conversation on resume.

Tests

  • New test/agent/skill-prompt.test.ts — prompt-renderer unit coverage: dir present for model-tool / nested-skill / user-slash triggers, XML-escaped, and omitted when no directory is supplied (backward-compat).
  • New end-to-end harness test in 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.
  • Updated existing assertions in skill-tool.test.ts, skill-tool-manager.test.ts, and node-sdk/test/session-skills.test.ts to 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 in wire.jsonl now 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).

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-bot

changeset-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 568e601

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/agent-core Patch
@moonshot-ai/kimi-code Patch

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

@pkg-pr-new

pkg-pr-new Bot commented Jun 15, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@568e601
npx https://pkg.pr.new/@moonshot-ai/kimi-code@568e601

commit: 568e601

@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: 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".

Comment thread packages/agent-core/src/agent/skill/prompt.ts
@chengluyu chengluyu merged commit 4578f05 into main Jun 15, 2026
8 checks passed
@chengluyu chengluyu deleted the fix/persistent-skill-read branch June 15, 2026 14:29
@github-actions github-actions Bot mentioned this pull request Jun 15, 2026
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