# Ephemeral Skill Pack Small-Context Plan

Date: 2026-05-15

## Problem

AIWG and Omnius skills are valuable, but full `SKILL.md` bodies are too large for
small and medium context windows. The main agent should see only a tiny,
task-scoped skill manifest, then delegate full skill unpacking to a sub-agent
that returns a compact extraction.

## Design

1. Build a run-scoped `ephemeral-skill-pack` from top-k task/skill matches.
2. Inject only skill names, sources, short descriptions, first trigger, score,
   and explicit discard semantics into `dynamicContext`.
3. Give the main agent a `skill_extract` tool that loads full skill content out
   of band and returns targeted guidance.
4. When available, `skill_extract` delegates the full `SKILL.md` body to a
   sub-agent and asks it to extract only the parts needed for the current task.
5. If the sub-agent path is unavailable, fall back to deterministic section
   extraction with a strict budget.
6. Keep `skill_execute` for explicit full-skill execution, but prefer
   `skill_extract` first on small and medium models.

## Context Placement

- TUI: append the manifest in `packages/cli/src/tui/interactive.ts` after the
  existing dynamic context enrichments and before the `AgenticRunner` is built.
- Runner: the manifest rides inside `c_know` via the existing structured
  context assembly in `packages/orchestrator/src/agenticRunner.ts`.
- Tool subset: include `skill_extract` in the runner's `skill` tool subset so
  `tool_search("skill")` can promote it alongside `skill_list` and
  `skill_execute`.

## Current Implementation Checklist

- [x] Add task/skill ranking helpers.
- [x] Add `buildEphemeralSkillPack(...)`.
- [x] Add deterministic `extractSkillForQuery(...)` fallback.
- [x] Add `skill_extract` tool with sub-agent extraction callback support.
- [x] Register `skill_extract` in the TUI tool list.
- [x] Wire `skill_extract` to the existing sub-agent tool callback.
- [x] Inject the ephemeral manifest into TUI `dynamicContext`.
- [x] Add tests for selection, manifest shape, and deterministic extraction.
- [x] Add REST `/v1/aiwg/expand` extraction mode.
- [x] Add Telegram action-agent skill-pack injection with public/private scope
  boundaries.
- [x] Add post-compaction re-injection if long runs prove the manifest is lost
  too early.

## Runtime Contract

The manifest is not durable memory. It must not be written to session handoffs,
memory cards, or long-term user profiles. If a skill produces a durable lesson,
the agent should save a separate concise lesson that cites the task outcome, not
the injected skill text.
