feat(agent): skill system, on-demand compaction, unified truncation, runSession helper, shouldStop hook, /compact command, settings preview#25
Merged
Conversation
Introduce on-demand context compaction and a shared truncation utility, refactor agent loop wiring, and update coding tools/UI accordingly. - New truncation library (electron/lib/truncation.ts) with truncateOutput, defaults and structured TruncationResult; replaces ad-hoc byte/line slicing across tools. - /compact slash command: pi-agent:compact-now IPC handler, compactNow API in compaction.ts, and renderer + preload hooks to trigger/display compact results (PiAgentPane, preload.ts, PiMessageBubble rendering for system messages). - Extracted runSession() in electron/ipc/pi-agent.ts to centralise compaction setup, IPC callbacks, and runAgentLoop invocation; persist compactionTransformer on PiAgentSession and reset it on pi-agent:clear. - Compaction fixes: buildCompactionTransformer now reads session.abortCtrl.signal live; compactNow awaits LLM summary and emits pi-agent:compact-result. - runAgentLoop additions: shouldStop hook (AgentLoopCallbacks) to allow semantic stop conditions; documentation/invariant advising callers to use runSession in Electron main process. - Update coding tools (bash, grep, find, ls, read) to use truncateOutput and DEFAULT limits and standardised hint formatting; small UX/format adjustments for streamed hints. These changes unify output truncation, enable explicit user-triggered compaction, preserve compaction cache across prompts, remove duplicated IPC wiring, and add a clean semantic loop-stop hook.
Introduce a SKILL.md-based skill system and UI preview for the pi-agent. - Add electron/lib/skills.ts: discoverSkills(), loadSkill(), renderSkillsXml() and types (SkillMeta, SkillContent). Scans project-local and global skill directories, validates SKILL.md frontmatter, and lists co-located resources. Metadata is token-efficiently injected into prompts; full bodies are lazy-loaded. - Add electron/lib/coding-tools/skill.ts: skill tool implementation and dynamic makeSkillToolDefinition(skills). Exposes SkillArgs and integrates with coding tools barrel export. - Integrate skills into agent loop and prompts: pi-agent-loop gains skills in AgentToolContext, conditionally includes the skill tool, allows "skill" in plan/execute, and routes tool calls to skillTool; pi-agent-prompt injects a <available_skills> XML block into both plan and execute prompts. - IPC & preload: electron/ipc/pi-agent.ts calls discoverSkills() and renderSkillsXml() when building prompts, passes skills to tool context, and adds pi-agent:preview-prompt handler; preload exposes piAgent.previewPrompt to the renderer. - UI: src/components/settings/AgentSettings.tsx adds a Skills & System Prompt preview section (skill list, mode toggle, refresh, collapsible prompt with copy), plus SkillRow and PromptPreview components. - Update changelog to document the feature and touched files. This implements a compatible, token-conscious skill workflow (OpenCode/Cline/Claude Code formats supported) and a renderer preview for developers to inspect available skills and the assembled system prompt.
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.
What does this PR do?
Brings the pi-agent harness to parity with the Pi monorepo coding agent across two independently-useful areas:
v1.4.0 refactors —
runSession()helper eliminates ~120 lines of duplicated IPC handler code;truncateOutput()replaces ad-hoc byte/line capping across all coding tools;AgentLoopCallbacks.shouldStop?hook enables clean early exit; on-demand compaction via/compactslash command backed bypi-agent:compact-now; compaction state persisted across multi-turn sessions.Skill system — the agent discovers
SKILL.mdfiles by walking from the code directory up to the git root, checking.cairn/skills/,.opencode/skills/,.cline/skills/,.claude/skills/, and.agents/skills/at every ancestor. Metadata is injected into the system prompt as<available_skills>XML; full body loaded on demand via askilltool call. Compatible with OpenCode, Cline, and Claude Code skill format. Settings → Coding Agents shows discovered skills and the full assembled system prompt with a mode toggle and copy button.Type of change
Screenshots / recording
Checklist
npm run type-checkpassesnpm run lintpassesnpm testpassesnpm run test:e2epasses (run before merging UI changes or cutting a release)var(--accent),var(--text-primary), etc.)text-[Npx]pixel font classes — rem equivalents only (text-[0.714rem],text-xs, etc.)handle()and returnIpcResult<T>schema.tsmcp-server.tschanges use inlined SQL only — no import fromqueries.tsNotes for reviewer
discoverSkills(cwd)walks up to the git root (stops at.git/) — skills placed at the repo root are always found even whencodeDirectoryis a subdirectory likepackages/web/makeSkillToolDefinition(skills)is dynamic — the tool description lists available skill names, so the model knows what to ask for without reading the bodypi-agent:preview-promptis aipcMain.handle(invoke, not fire-and-forget) — returns{ systemPrompt, skills }synchronously for the settings panelPiAgentSession(not rebuilt per prompt) socachedSummarysurvives multi-turn sessions;pi-agent:clearresets itrunSession()is the single mandatory path torunAgentLoopin production; tests callrunAgentLoopdirectly and are unaffectedshouldStop?fires after tool results, before the next LLM call — triggersonDone, notonError