Skip to content

feat(skills): load_skill tool for app-user sessions (Option A, plan #72) - #74

Merged
cryptolir merged 3 commits into
mainfrom
feat/load-skill-app-sessions
Jun 18, 2026
Merged

cryptolir merged 3 commits into
mainfrom
feat/load-skill-app-sessions

Conversation

@cryptolir

Copy link
Copy Markdown
Owner

Implements the Option A plan from #72 (docs/experiments/plans/app-user-skill-access.md), with the codex 4517821566 refinements folded in.

Problem

App-user chats on life run jailed (tools.fs.workspaceOnly). They already see the live dashboard skills in their prompt, but the jail blocks read-ing the SKILL.md to apply them — which is why the Drive summary method had to be hard-embedded.

What

A read-only, name-scoped load_skill({ name }) tool resolves a skill name to its SKILL.md content server-side (the gateway process isn't jailed). The model never supplies a path → no traversal surface. The per-user file jail is untouched.

Gate

  • vitest: load-skill 11, system-prompt.skills 6 (incl. the normal-session regression assertion), save-user-section 13 unchanged.
  • tsgo: clean on touched files (repo-wide reds are the known ui/* worktree-symlink phantoms + pre-existing extensions/twitch, not present in CI).
  • oxlint --type-aware: 0/0. oxfmt: clean.

Not in this PR: the gateway image roll to life + the AGENTS.md prose note (deploy step) and the optional Drive "embedded → live skill" follow-up.

🤖 Generated with Claude Code

…led)

App-user sessions run jailed (tools.fs.workspaceOnly) and cannot read the shared
SKILL.md by path, so the live dashboard skills listed in their prompt were
unusable (the reason the Havaya Drive method was hard-embedded). Add a read-only,
name-scoped load_skill tool that resolves a skill NAME — from the same filtered,
prompt-visible set the model is shown — to its SKILL.md content, read server-side.
The per-user file jail is untouched.

Implements docs/experiments/plans/app-user-skill-access.md (Option A) with the
codex 4517821566 refinements:
- allowlist = the snapshot's resolvedSkills (filtered/prompt-visible), so it is
  never a side channel to disableModelInvocation/ineligible skills (#2);
- confinement against the matched entry's own baseDir, not a hardcoded path, so
  multi-root (bundled/managed/workspace) skills resolve; symlink-escape rejected (#1);
- gated on a resolved app user via resolveAppUserId ?? appUserIdFromSessionKey
  (turn-1-safe, excludes _no-app-user) (#3);
- 24KB cap + truncated flag; no sibling files in v1 (#4).
The app skills prompt lists name+description only (no <location>, no host-path
leak) and instructs the model to call load_skill; normal sessions unchanged.

Files: new src/agents/tools/load-skill.ts; buildAppSkillsPrompt in
skills/workspace.ts; buildSkillsSection app branch (system-prompt.ts) threaded via
buildEmbeddedSystemPrompt; appSkills wired through pi-tools -> openclaw-tools;
attempt.ts resolves the app user, builds the single skills source, and branches.

Gate: vitest load-skill 11 + system-prompt.skills 6 + save-user-section 13
(unchanged); tsgo clean on touched files; oxlint --type-aware 0/0; oxfmt.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@cryptolir

Copy link
Copy Markdown
Owner Author

@codex please review — implementation of the #72 plan (Option A load_skill), security-sensitive (app-session sandbox boundary).

Focus areas:

  1. Confinement (src/agents/tools/load-skill.ts readSkillByName): the read is confined to the matched entry's own realpath(baseDir) and rejects rel === "" || startsWith("..") || isAbsolute. Is that airtight against a symlinked SKILL.md and against baseDir/filePath edge cases? Note input is a name matched against the allowlist (no model-supplied path).
  2. No drift / no side channel: the tool allowlist and the app prompt are both built from the same appSkills (the snapshot's filtered resolvedSkills) in attempt.ts. Confirm there's no path where the tool could load a name the app prompt didn't show (e.g. snapshot vs fresh-build fallback when skillsSnapshot.resolvedSkills is absent).
  3. Gating: appUserId = isAppUserSession ? (resolveAppUserId ?? appUserIdFromSessionKey) : null; appSkills/load_skill only when appUserId is set. Confirm _no-app-user (neither resolves) is excluded and that it's turn-1-safe (the fix(bootstrap): inject app_profile on the first turn of a new app session #71 fallback).
  4. Normal sessions unchanged: buildSkillsSection only branches on appSkillLoad; buildAppSkillsPrompt omits <location>. The system-prompt.skills.test.ts asserts the normal read-by-<location> instruction is intact. Anything that could regress non-app prompts?
  5. Threading: appSkills rides createOpenClawCodingTools → createOpenClawTools; appSkillLoad rides buildEmbeddedSystemPrompt → buildAgentSystemPrompt → buildSkillsSection. Any other caller of these that should set/forward the new optional params?

Gate: vitest (load-skill 11 + system-prompt.skills 6 + save-user-section 13 unchanged); tsgo clean on touched files (repo-wide reds are the known worktree-symlink ui/* phantoms); oxlint --type-aware 0/0; oxfmt.

@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: a837d85c79

ℹ️ 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".

...(webFetchTool ? [webFetchTool] : []),
...(imageTool ? [imageTool] : []),
...(saveUserSectionTool ? [saveUserSectionTool] : []),
...(loadSkillTool ? [loadSkillTool] : []),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Gate load_skill guidance on the filtered tool set

When an app-user session runs under an explicit tool allowlist/profile that does not include the new load_skill name (for example the existing coding profile expands to fs/runtime/sessions/memory/image), the policy pipeline filters this tool back out after it is added here. attempt.ts still sets appSkillLoad solely from appUserId, so the prompt tells the model to call a tool that is not actually available and app skills remain unusable in those configured sessions; derive the guidance from the final tools list or add load_skill to the relevant core groups/profiles.

Useful? React with 👍 / 👎.

? resolveHeartbeatPrompt(params.config?.agents?.defaults?.heartbeat?.prompt)
: undefined,
skillsPrompt,
appSkillLoad: !!appUserId,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Mirror app skill handling in compaction

This only wires the path-free load_skill prompt for normal run attempts. When an app-user session hits overflow/manual compaction, compactEmbeddedPiSessionDirect still builds skillsPrompt through resolveSkillsPromptForRun and calls buildEmbeddedSystemPrompt without appSkillLoad/appSkills (see compact.ts:365-370 and compact.ts:501-512), so the compaction model gets the snapshot prompt with <location> host paths and no load-by-name behavior. Mirror the same appUserId/appSkills logic in the compaction path to keep the app-session boundary consistent.

Useful? React with 👍 / 👎.

@cryptolir cryptolir left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings for Claude before coding starts:

[P2] load_skill prompt can be enabled when the tool was filtered out

attempt.ts sets appSkillLoad from appUserId, but createOpenClawTools adds load_skill before the later tool-profile/allowlist filtering. In app-user sessions using a restricted profile that does not include load_skill, the prompt tells the model to call a missing tool. Fix by deriving appSkillLoad from the final available tool list, or by adding load_skill to the intended app/coding tool groups.

[P2] App skill behavior is missing from compaction

Normal run attempts get the path-free app skill prompt, but compactEmbeddedPiSessionDirect still uses resolveSkillsPromptForRun and does not pass appSkillLoad/appSkills. That means app-user compaction can still expose <location> paths and loses the load-by-name behavior. Mirror the same app-user skill logic in compact.ts.

[P2] resolvedSkills may bypass the configured prompt limits

The PR treats skillsSnapshot.resolvedSkills as “prompt-visible,” but in the existing snapshot flow resolvedSkills can include more entries than the limited prompt actually rendered after maxSkillsInPrompt / prompt char caps. buildAppSkillsPrompt(appSkills) then emits all of them, and load_skill can load all of them. Better to derive app prompt + load_skill allowlist from the exact limited skill set, or apply the same limits in the app path.

The confinement shape in load-skill.ts looks directionally right: model input is a name, matching is against the allowlist, and the realpath-relative check blocks outside-base symlink escapes. I’d still treat the three issues above as merge blockers for this security-sensitive boundary.

Three P2 fixes to the load_skill app-session path:
- [#1] derive appSkillLoad from the FINAL tool list (tools.some(load_skill)) rather
  than just appUserId, and suppress the app skills section when load_skill was
  filtered out by tool policy — so the model is never told to call a tool it does
  not have. The skills prompt is now built after tool creation in both attempt.ts
  and compact.ts.
- [#2] mirror the whole app-session skill branch in compact.ts, so app-user
  COMPACTION also gets the path-free app prompt + load-by-name (no <location> leak,
  no loss of the load_skill behavior).
- [#3] new limitAppSkills() applies the same maxSkillsInPrompt/char caps as the
  normal prompt; both the app prompt and the load_skill allowlist are built from it,
  so an app session can neither see nor load more skills than a normal prompt shows.

Gate: vitest load-skill 11 + system-prompt.skills 8 (+2 limitAppSkills) +
overflow-compaction; tsgo clean on touched files; oxlint --type-aware 0/0; oxfmt.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@cryptolir

Copy link
Copy Markdown
Owner Author

Thanks — all three P2s fixed in eb18b06ea; normal-session behavior is unchanged.

[P1] Tool-filter consistency — appSkillLoad is now derived from the final tool list (tools.some(t => t.name === "load_skill")), computed after tool creation in both attempt.ts and compact.ts. If load_skill was filtered out by tool policy, the app skills section is suppressed entirely (it's unusable for the jailed session anyway), so the model is never told to call a missing tool.

[P2] Compaction — the whole app-session branch is mirrored in compact.ts: same appUserId resolution, same single appSkills source, the path-free buildAppSkillsPrompt, and appSkillLoad threaded into buildEmbeddedSystemPrompt. App-user compaction no longer leaks <location> or loses load-by-name.

[P3] Prompt limits — new limitAppSkills(skills, config) applies the same maxSkillsInPrompt/char caps (applySkillsPromptLimits) as the normal prompt. Both the app prompt and the load_skill allowlist are built from its output, so an app session can neither see nor load more skills than a normal prompt would show. (+2 unit tests.)

Gate: vitest load-skill 11 + system-prompt.skills 8 + overflow-compaction; tsgo clean on touched files; oxlint --type-aware 0/0; oxfmt.

@cryptolir cryptolir left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked head eb18b06ea for Claude.

No new blocking findings. The three prior issues from review 4519976882 look addressed in code:

  • appSkillLoad is now derived from the final tool list, so the prompt does not advertise load_skill after policy filtering removes it.
  • compact.ts now mirrors the app-user skill path, including path-free prompt construction and appSkillLoad threading.
  • limitAppSkills() applies the normal prompt limits before building both the app prompt and the load_skill allowlist, keeping the visible list and loadable set aligned.

Minor non-blocking cleanup: a couple comments/docs in load-skill.ts / tool option docs still describe the allowlist as the snapshot’s resolvedSkills; after the fix it is really the prompt-limited subset of resolvedSkills. Worth updating so the security invariant remains easy to audit later.

I could not rerun the focused vitest specs in this local shell because pnpm is not installed here, but the patch inspection looks good.

…subset

Codex recheck 4520156223 non-blocking nit: comments in load-skill.ts and the
appSkills option docs (openclaw-tools.ts, pi-tools.ts) described the allowlist as
the snapshot's resolvedSkills; after the limit fix it is the prompt-limited subset
(via limitAppSkills). Comment-only; keeps the security invariant easy to audit.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@cryptolir

Copy link
Copy Markdown
Owner Author

Done. Updated the comments in load-skill.ts and the appSkills option docs (openclaw-tools.ts, pi-tools.ts) to say the allowlist is the prompt-limited subset of the snapshot's resolvedSkills (via limitAppSkills) — so the invariant visible list == loadable set == within prompt limits is explicit for future audits. Comment-only; oxfmt clean. Thanks for the careful recheck.

@cryptolir
cryptolir merged commit 09a99e4 into main Jun 18, 2026
16 of 24 checks passed
@cryptolir
cryptolir deleted the feat/load-skill-app-sessions branch June 18, 2026 17:53
cryptolir added a commit that referenced this pull request Jun 18, 2026
…oad_skill #74) (#75)

Record the load_skill roll: #74 merged, gateway v2026.06.18.1 (sourceSha
09a99e4) pinned to life only — ships the full per-user stack to prod (writer
#65/#66 + injection #68 + first-turn #71 + load_skill #74). Bump the
INFRASTRUCTURE life-ahead tag to v2026.06.18.1 and note the US-host disk cleanup
(97% to 67%, removed 8 unused/unreferenced gateway tags).

Co-authored-by: Liran Peretz <[email protected]>
Co-authored-by: Claude Opus 4.8 <[email protected]>
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