@herbertgao/pi-extensions 2026.10.18 → 2026.10.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -29,7 +29,6 @@ The package bundles 6 active `@herbertgao/*` child packages—`pi-agency`, `pi-b
|
|
|
29
29
|
- `@pi-plugins/fast-mode@0.1.14`
|
|
30
30
|
- `@tifan/pi-copy-response@0.2.7`
|
|
31
31
|
- `@tifan/pi-handoff@2.2.2`
|
|
32
|
-
- `@tifan/pi-inline-skills@1.0.7`
|
|
33
32
|
- `@tifan/pi-mermaid-open@0.2.2`
|
|
34
33
|
- `@tifan/pi-preferred-thinking@1.0.2`
|
|
35
34
|
- `@tifan/pi-recap@0.4.8`
|
package/THIRD_PARTY_NOTICES.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@herbertgao/pi-extensions",
|
|
3
|
-
"version": "2026.10.
|
|
3
|
+
"version": "2026.10.19",
|
|
4
4
|
"description": "Aggregate installer for HerbertGao-maintained Pi extensions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"extensions",
|
|
@@ -56,7 +56,6 @@
|
|
|
56
56
|
"@shikijs/cli": "^4.0.2",
|
|
57
57
|
"@tifan/pi-copy-response": "0.2.7",
|
|
58
58
|
"@tifan/pi-handoff": "2.2.2",
|
|
59
|
-
"@tifan/pi-inline-skills": "1.0.7",
|
|
60
59
|
"@tifan/pi-mermaid-open": "0.2.2",
|
|
61
60
|
"@tifan/pi-preferred-thinking": "1.0.2",
|
|
62
61
|
"@tifan/pi-recap": "0.4.8",
|
|
@@ -113,7 +112,6 @@
|
|
|
113
112
|
"@pi-plugins/fast-mode",
|
|
114
113
|
"@tifan/pi-copy-response",
|
|
115
114
|
"@tifan/pi-handoff",
|
|
116
|
-
"@tifan/pi-inline-skills",
|
|
117
115
|
"@tifan/pi-mermaid-open",
|
|
118
116
|
"@tifan/pi-preferred-thinking",
|
|
119
117
|
"@tifan/pi-recap",
|
|
@@ -137,7 +135,6 @@
|
|
|
137
135
|
"./node_modules/@tifan/pi-copy-response/src/index.ts",
|
|
138
136
|
"./node_modules/@tifan/pi-handoff/src/index.ts",
|
|
139
137
|
"./node_modules/@tifan/pi-handoff/src/session-query.ts",
|
|
140
|
-
"./node_modules/@tifan/pi-inline-skills/src/index.ts",
|
|
141
138
|
"./node_modules/@tifan/pi-mermaid-open/src/index.ts",
|
|
142
139
|
"./node_modules/@tifan/pi-preferred-thinking/src/index.ts",
|
|
143
140
|
"./node_modules/@tifan/pi-recap/src/index.ts",
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# @tifan/pi-inline-skills
|
|
2
|
-
|
|
3
|
-
Load skills from inside a pi prompt.
|
|
4
|
-
|
|
5
|
-
Type `/` and part of a skill name, pick a skill, then keep writing. On submit, the prompt stays unchanged and the matching skill content is loaded for that turn.
|
|
6
|
-
|
|
7
|
-

|
|
8
|
-
|
|
9
|
-
## Install
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
pi install npm:@tifan/pi-inline-skills
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Usage
|
|
16
|
-
|
|
17
|
-
```text
|
|
18
|
-
let's /tdd this and /review when done
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
This loads `tdd` and `review` behind the scenes. Slash tokens stay in the visible prompt, so rewinding and editing previous prompts is easy.
|
|
22
|
-
|
|
23
|
-
Notes:
|
|
24
|
-
|
|
25
|
-
- Already-loaded skills are not injected again on the same session branch.
|
|
26
|
-
- Skills with `disable-model-invocation: true` work because this extension reads skill files directly.
|
|
27
|
-
- A registered pi command wins at the start of a prompt. Otherwise, a starting token like `/tdd` is treated as an inline skill.
|
|
28
|
-
|
|
29
|
-
## Commands
|
|
30
|
-
|
|
31
|
-
- `/loaded-skills`: List skills loaded in the current session.
|
|
32
|
-
|
|
33
|
-

|
|
34
|
-
|
|
35
|
-
## Release notes
|
|
36
|
-
|
|
37
|
-
See [CHANGELOG.md](https://github.com/tifandotme/pi-extensions/blob/master/packages/pi-inline-skills/CHANGELOG.md)
|
|
38
|
-
|
|
39
|
-
## License
|
|
40
|
-
|
|
41
|
-
[MIT](https://github.com/tifandotme/pi-extensions/blob/master/LICENSE)
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@tifan/pi-inline-skills",
|
|
3
|
-
"version": "1.0.7",
|
|
4
|
-
"description": "Inline /skill autocomplete in the pi editor.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"autocomplete",
|
|
7
|
-
"pi",
|
|
8
|
-
"pi-extension",
|
|
9
|
-
"pi-package",
|
|
10
|
-
"skills"
|
|
11
|
-
],
|
|
12
|
-
"homepage": "https://github.com/tifandotme/pi-extensions/tree/master/packages/pi-inline-skills#readme",
|
|
13
|
-
"bugs": "https://github.com/tifandotme/pi-extensions/issues",
|
|
14
|
-
"license": "MIT",
|
|
15
|
-
"author": "Tifan Dwi Avianto <hi@tifan.me>",
|
|
16
|
-
"repository": {
|
|
17
|
-
"type": "git",
|
|
18
|
-
"url": "git+https://github.com/tifandotme/pi-extensions.git",
|
|
19
|
-
"directory": "packages/pi-inline-skills"
|
|
20
|
-
},
|
|
21
|
-
"files": [
|
|
22
|
-
"src/**/*.ts",
|
|
23
|
-
"!src/**/*.test.ts",
|
|
24
|
-
"README.md",
|
|
25
|
-
"LICENSE"
|
|
26
|
-
],
|
|
27
|
-
"type": "module",
|
|
28
|
-
"publishConfig": {
|
|
29
|
-
"access": "public",
|
|
30
|
-
"provenance": true
|
|
31
|
-
},
|
|
32
|
-
"scripts": {
|
|
33
|
-
"test": "node --experimental-strip-types --test src/index.test.ts"
|
|
34
|
-
},
|
|
35
|
-
"engines": {
|
|
36
|
-
"node": ">=20"
|
|
37
|
-
},
|
|
38
|
-
"pi": {
|
|
39
|
-
"extensions": [
|
|
40
|
-
"./src/index.ts"
|
|
41
|
-
],
|
|
42
|
-
"image": "https://raw.githubusercontent.com/tifandotme/pi-extensions/refs/heads/master/packages/pi-inline-skills/assets/skills-selector-triggered-inline.webp"
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,646 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync, realpathSync } from "node:fs"
|
|
2
|
-
import { dirname, resolve } from "node:path"
|
|
3
|
-
import {
|
|
4
|
-
CustomEditor,
|
|
5
|
-
type ExtensionAPI,
|
|
6
|
-
type ExtensionContext,
|
|
7
|
-
SkillInvocationMessageComponent,
|
|
8
|
-
type ParsedSkillBlock,
|
|
9
|
-
} from "@earendil-works/pi-coding-agent"
|
|
10
|
-
import { Box, Container, Text } from "@earendil-works/pi-tui"
|
|
11
|
-
|
|
12
|
-
type AutocompleteItem = {
|
|
13
|
-
value: string
|
|
14
|
-
label: string
|
|
15
|
-
description?: string
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type AutocompleteSuggestions = {
|
|
19
|
-
items: AutocompleteItem[]
|
|
20
|
-
prefix: string
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type AutocompleteProvider = {
|
|
24
|
-
getSuggestions(
|
|
25
|
-
lines: string[],
|
|
26
|
-
cursorLine: number,
|
|
27
|
-
cursorCol: number,
|
|
28
|
-
options: { signal: AbortSignal; force?: boolean },
|
|
29
|
-
): Promise<AutocompleteSuggestions | null>
|
|
30
|
-
applyCompletion(
|
|
31
|
-
lines: string[],
|
|
32
|
-
cursorLine: number,
|
|
33
|
-
cursorCol: number,
|
|
34
|
-
item: AutocompleteItem,
|
|
35
|
-
prefix: string,
|
|
36
|
-
): { lines: string[]; cursorLine: number; cursorCol: number }
|
|
37
|
-
shouldTriggerFileCompletion?(
|
|
38
|
-
lines: string[],
|
|
39
|
-
cursorLine: number,
|
|
40
|
-
cursorCol: number,
|
|
41
|
-
): boolean
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
type SkillCommand = {
|
|
45
|
-
name: string
|
|
46
|
-
description?: string
|
|
47
|
-
source: string
|
|
48
|
-
sourceInfo: {
|
|
49
|
-
path: string
|
|
50
|
-
source: string
|
|
51
|
-
scope: "user" | "project" | "temporary"
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
type SkillInfo = {
|
|
56
|
-
name: string
|
|
57
|
-
description?: string
|
|
58
|
-
sourceInfo?: SkillCommand["sourceInfo"]
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
type LoadedSkillEntryData = {
|
|
62
|
-
name?: string
|
|
63
|
-
source?: "tool-result"
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
type InlineSkillMessageDetails = {
|
|
67
|
-
names?: string[]
|
|
68
|
-
skills?: ParsedSkillBlock[]
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
type InlineSkillSessionEntry = {
|
|
72
|
-
type: string
|
|
73
|
-
customType?: string
|
|
74
|
-
data?: LoadedSkillEntryData
|
|
75
|
-
details?: InlineSkillMessageDetails
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const LOADED_SKILL_ENTRY_TYPE = "loaded-skill"
|
|
79
|
-
const INLINE_SKILL_MESSAGE_TYPE = "inline-skill"
|
|
80
|
-
const MAX_SUGGESTIONS = 30
|
|
81
|
-
const SKILL_TOKEN_RE =
|
|
82
|
-
/(^|[\s([{,])\/([a-z0-9][a-z0-9-]{0,63})(?![a-z0-9-]|[:/])/gi
|
|
83
|
-
const SLASH_SKILL_CONTEXT_RE = /(?:^|[\s([{,])\/[a-z0-9-]*$/i
|
|
84
|
-
|
|
85
|
-
function fuzzyScore(value: string, query: string): number {
|
|
86
|
-
const target = value.toLowerCase()
|
|
87
|
-
const needle = query.toLowerCase()
|
|
88
|
-
if (!needle) return 1
|
|
89
|
-
if (target === needle) return 1000
|
|
90
|
-
if (target.startsWith(needle)) return 800 - target.length
|
|
91
|
-
if (target.includes(needle))
|
|
92
|
-
return 600 - target.indexOf(needle) - target.length
|
|
93
|
-
|
|
94
|
-
let score = 0
|
|
95
|
-
let lastIndex = -1
|
|
96
|
-
for (const char of needle) {
|
|
97
|
-
const index = target.indexOf(char, lastIndex + 1)
|
|
98
|
-
if (index === -1) return 0
|
|
99
|
-
score += index === lastIndex + 1 ? 20 : 5
|
|
100
|
-
lastIndex = index
|
|
101
|
-
}
|
|
102
|
-
return score - target.length
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function filterSkills(skills: SkillInfo[], query: string): SkillInfo[] {
|
|
106
|
-
return skills
|
|
107
|
-
.map((skill) => ({ skill, score: fuzzyScore(skill.name, query) }))
|
|
108
|
-
.filter((entry) => entry.score > 0)
|
|
109
|
-
.toSorted(
|
|
110
|
-
(a, b) => b.score - a.score || a.skill.name.localeCompare(b.skill.name),
|
|
111
|
-
)
|
|
112
|
-
.map((entry) => entry.skill)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function getAutocompleteSourceTag(
|
|
116
|
-
sourceInfo: SkillCommand["sourceInfo"] | undefined,
|
|
117
|
-
): string | undefined {
|
|
118
|
-
if (!sourceInfo) return undefined
|
|
119
|
-
|
|
120
|
-
const scopePrefix =
|
|
121
|
-
sourceInfo.scope === "user"
|
|
122
|
-
? "u"
|
|
123
|
-
: sourceInfo.scope === "project"
|
|
124
|
-
? "p"
|
|
125
|
-
: "t"
|
|
126
|
-
const source = sourceInfo.source.trim()
|
|
127
|
-
if (source === "auto" || source === "local" || source === "cli") {
|
|
128
|
-
return scopePrefix
|
|
129
|
-
}
|
|
130
|
-
if (source.startsWith("npm:")) return `${scopePrefix}:${source}`
|
|
131
|
-
return scopePrefix
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function prefixAutocompleteDescription(skill: SkillInfo): string | undefined {
|
|
135
|
-
const sourceTag = getAutocompleteSourceTag(skill.sourceInfo)
|
|
136
|
-
if (!sourceTag) return skill.description
|
|
137
|
-
return skill.description
|
|
138
|
-
? `[${sourceTag}] ${skill.description}`
|
|
139
|
-
: `[${sourceTag}]`
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function getSkills(pi: ExtensionAPI): SkillInfo[] {
|
|
143
|
-
return (pi.getCommands() as SkillCommand[])
|
|
144
|
-
.filter(
|
|
145
|
-
(command) =>
|
|
146
|
-
command.source === "skill" && command.name.startsWith("skill:"),
|
|
147
|
-
)
|
|
148
|
-
.map((command) => {
|
|
149
|
-
const skill: SkillInfo = {
|
|
150
|
-
name: command.name.slice("skill:".length),
|
|
151
|
-
sourceInfo: command.sourceInfo,
|
|
152
|
-
}
|
|
153
|
-
if (command.description) skill.description = command.description
|
|
154
|
-
return skill
|
|
155
|
-
})
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function hasStartingCommandConflict(pi: ExtensionAPI, text: string): boolean {
|
|
159
|
-
const match = text.match(/^\/([a-z0-9][a-z0-9-]{0,63})(?![a-z0-9-]|[:/])/i)
|
|
160
|
-
if (!match?.[1]) return false
|
|
161
|
-
|
|
162
|
-
const name = match[1].toLowerCase()
|
|
163
|
-
return (pi.getCommands() as SkillCommand[]).some(
|
|
164
|
-
(command) =>
|
|
165
|
-
command.source !== "skill" && command.name.toLowerCase() === name,
|
|
166
|
-
)
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function normalizePath(path: string, cwd: string): string {
|
|
170
|
-
const absolutePath = path.startsWith("/") ? path : resolve(cwd, path)
|
|
171
|
-
try {
|
|
172
|
-
if (existsSync(absolutePath)) return realpathSync.native(absolutePath)
|
|
173
|
-
} catch {
|
|
174
|
-
// Fall back to the resolved path below.
|
|
175
|
-
}
|
|
176
|
-
return absolutePath
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function getCurrentSkillPathMap(
|
|
180
|
-
pi: ExtensionAPI,
|
|
181
|
-
cwd: string,
|
|
182
|
-
): Map<string, string> {
|
|
183
|
-
const skills = new Map<string, string>()
|
|
184
|
-
|
|
185
|
-
for (const command of pi.getCommands() as SkillCommand[]) {
|
|
186
|
-
if (command.source !== "skill") continue
|
|
187
|
-
if (!command.name?.startsWith("skill:")) continue
|
|
188
|
-
if (!command.sourceInfo?.path) continue
|
|
189
|
-
|
|
190
|
-
skills.set(
|
|
191
|
-
normalizePath(command.sourceInfo.path, cwd),
|
|
192
|
-
command.name.slice("skill:".length),
|
|
193
|
-
)
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return skills
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function restoreLoadedSkills(ctx: ExtensionContext): Set<string> {
|
|
200
|
-
const loadedSkills = new Set<string>()
|
|
201
|
-
|
|
202
|
-
for (const entry of ctx.sessionManager.getBranch() as InlineSkillSessionEntry[]) {
|
|
203
|
-
if (
|
|
204
|
-
entry.type === "custom" &&
|
|
205
|
-
entry.customType === LOADED_SKILL_ENTRY_TYPE
|
|
206
|
-
) {
|
|
207
|
-
const data = entry.data
|
|
208
|
-
if (
|
|
209
|
-
data?.source === "tool-result" &&
|
|
210
|
-
typeof data.name === "string" &&
|
|
211
|
-
data.name.trim()
|
|
212
|
-
) {
|
|
213
|
-
loadedSkills.add(data.name)
|
|
214
|
-
}
|
|
215
|
-
continue
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (
|
|
219
|
-
entry.type === "custom_message" &&
|
|
220
|
-
entry.customType === INLINE_SKILL_MESSAGE_TYPE
|
|
221
|
-
) {
|
|
222
|
-
for (const skill of entry.details?.skills ?? []) {
|
|
223
|
-
if (skill.name.trim()) loadedSkills.add(skill.name)
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return loadedSkills
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function stripFrontmatter(content: string): string {
|
|
232
|
-
if (!content.startsWith("---")) return content
|
|
233
|
-
|
|
234
|
-
const end = content.indexOf("\n---", 3)
|
|
235
|
-
if (end === -1) return content
|
|
236
|
-
|
|
237
|
-
const afterEnd = content.indexOf("\n", end + 4)
|
|
238
|
-
return afterEnd === -1 ? "" : content.slice(afterEnd + 1)
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function escapeXmlAttribute(value: string): string {
|
|
242
|
-
return value
|
|
243
|
-
.replace(/&/g, "&")
|
|
244
|
-
.replace(/"/g, """)
|
|
245
|
-
.replace(/</g, "<")
|
|
246
|
-
.replace(/>/g, ">")
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
function buildSkillBlock(
|
|
250
|
-
skill: SkillInfo,
|
|
251
|
-
cwd: string,
|
|
252
|
-
): { text: string; skillBlock: ParsedSkillBlock } {
|
|
253
|
-
const skillPath = skill.sourceInfo?.path
|
|
254
|
-
if (!skillPath) {
|
|
255
|
-
throw new Error(`missing path for skill ${skill.name}`)
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const normalizedPath = normalizePath(skillPath, cwd)
|
|
259
|
-
const content = readFileSync(normalizedPath, "utf-8")
|
|
260
|
-
const body = stripFrontmatter(content).trim()
|
|
261
|
-
const skillContent = `References are relative to ${dirname(normalizedPath)}.\n\n${body}`
|
|
262
|
-
return {
|
|
263
|
-
text: `<skill name="${escapeXmlAttribute(skill.name)}" location="${escapeXmlAttribute(normalizedPath)}">\n${skillContent}\n</skill>`,
|
|
264
|
-
skillBlock: {
|
|
265
|
-
name: skill.name,
|
|
266
|
-
location: normalizedPath,
|
|
267
|
-
content: skillContent,
|
|
268
|
-
userMessage: undefined,
|
|
269
|
-
},
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function buildInlineSkillContent(
|
|
274
|
-
skills: SkillInfo[],
|
|
275
|
-
cwd: string,
|
|
276
|
-
): { content: string; skillBlocks: ParsedSkillBlock[] } {
|
|
277
|
-
const skillBlocks = skills.map((skill) => buildSkillBlock(skill, cwd))
|
|
278
|
-
const blocks = skillBlocks.map((skill) => skill.text).join("\n\n")
|
|
279
|
-
return {
|
|
280
|
-
content: `<inline_skills>\nThe following inline skill contents are already loaded. Do not load them again unless the user asks to inspect the source file.\n\n${blocks}\n</inline_skills>`,
|
|
281
|
-
skillBlocks: skillBlocks.map((skill) => skill.skillBlock),
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
function findInlineSkills(
|
|
286
|
-
text: string,
|
|
287
|
-
skills: SkillInfo[],
|
|
288
|
-
): { selected: SkillInfo[] } | undefined {
|
|
289
|
-
const byName = new Map(
|
|
290
|
-
skills.map((skill) => [skill.name.toLowerCase(), skill]),
|
|
291
|
-
)
|
|
292
|
-
const selected: SkillInfo[] = []
|
|
293
|
-
const seen = new Set<string>()
|
|
294
|
-
|
|
295
|
-
text.replace(
|
|
296
|
-
SKILL_TOKEN_RE,
|
|
297
|
-
(match, _boundary: string, skillName: string) => {
|
|
298
|
-
const skill = byName.get(skillName.toLowerCase())
|
|
299
|
-
if (!skill) return match
|
|
300
|
-
if (!seen.has(skill.name)) {
|
|
301
|
-
seen.add(skill.name)
|
|
302
|
-
selected.push(skill)
|
|
303
|
-
}
|
|
304
|
-
return match
|
|
305
|
-
},
|
|
306
|
-
)
|
|
307
|
-
|
|
308
|
-
if (selected.length === 0) return undefined
|
|
309
|
-
|
|
310
|
-
return { selected }
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
function extractSlashSkillPrefix(textBeforeCursor: string): string | undefined {
|
|
314
|
-
const match = textBeforeCursor.match(/(?:^|[\s([{,])\/([a-z0-9-]*)$/i)
|
|
315
|
-
return match?.[1]
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
function isPromptStartSlashToken(
|
|
319
|
-
lines: string[],
|
|
320
|
-
cursorLine: number,
|
|
321
|
-
textBeforeCursor: string,
|
|
322
|
-
prefix: string,
|
|
323
|
-
): boolean {
|
|
324
|
-
const slashPrefixStart = textBeforeCursor.length - prefix.length - 1
|
|
325
|
-
if (slashPrefixStart < 0) return false
|
|
326
|
-
const earlierLinesAreBlank = lines
|
|
327
|
-
.slice(0, cursorLine)
|
|
328
|
-
.every((line) => line.trim().length === 0)
|
|
329
|
-
return (
|
|
330
|
-
earlierLinesAreBlank &&
|
|
331
|
-
textBeforeCursor.slice(0, slashPrefixStart).trim() === ""
|
|
332
|
-
)
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
function mergeAutocompleteItems(options: {
|
|
336
|
-
current: AutocompleteSuggestions | null
|
|
337
|
-
skillItems: AutocompleteItem[]
|
|
338
|
-
preferCommands: boolean
|
|
339
|
-
prefix: string
|
|
340
|
-
}): AutocompleteSuggestions {
|
|
341
|
-
const currentItems = options.current?.items ?? []
|
|
342
|
-
const orderedItems = options.preferCommands
|
|
343
|
-
? [...currentItems, ...options.skillItems]
|
|
344
|
-
: [...options.skillItems, ...currentItems]
|
|
345
|
-
const seen = new Set<string>()
|
|
346
|
-
const items = orderedItems.filter((item) => {
|
|
347
|
-
const key = `${item.label}\u0000${item.value}`
|
|
348
|
-
if (seen.has(key)) return false
|
|
349
|
-
seen.add(key)
|
|
350
|
-
return true
|
|
351
|
-
})
|
|
352
|
-
|
|
353
|
-
return {
|
|
354
|
-
prefix: options.current?.prefix ?? `/${options.prefix}`,
|
|
355
|
-
items: items.slice(0, MAX_SUGGESTIONS),
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
function installSlashAutocompleteTrigger(): void {
|
|
360
|
-
const proto = CustomEditor.prototype as unknown as {
|
|
361
|
-
handleInput(data: string): void
|
|
362
|
-
inlineSkillsSlashTriggerInstalled?: boolean
|
|
363
|
-
}
|
|
364
|
-
if (proto.inlineSkillsSlashTriggerInstalled) return
|
|
365
|
-
|
|
366
|
-
const originalHandleInput = proto.handleInput
|
|
367
|
-
proto.handleInput = function patchedHandleInput(
|
|
368
|
-
this: unknown,
|
|
369
|
-
data: string,
|
|
370
|
-
): void {
|
|
371
|
-
const editor = this as {
|
|
372
|
-
isShowingAutocomplete?: () => boolean
|
|
373
|
-
state?: { cursorLine: number; cursorCol: number; lines: string[] }
|
|
374
|
-
tryTriggerAutocomplete?: () => void
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
originalHandleInput.call(this, data)
|
|
378
|
-
if (
|
|
379
|
-
editor.isShowingAutocomplete?.() ||
|
|
380
|
-
!editor.state ||
|
|
381
|
-
typeof editor.tryTriggerAutocomplete !== "function"
|
|
382
|
-
)
|
|
383
|
-
return
|
|
384
|
-
if (!/^[a-zA-Z0-9\-_/]$/.test(data)) return
|
|
385
|
-
|
|
386
|
-
const currentLine = editor.state.lines[editor.state.cursorLine] ?? ""
|
|
387
|
-
const textBeforeCursor = currentLine.slice(0, editor.state.cursorCol)
|
|
388
|
-
if (SLASH_SKILL_CONTEXT_RE.test(textBeforeCursor)) {
|
|
389
|
-
editor.tryTriggerAutocomplete()
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
proto.inlineSkillsSlashTriggerInstalled = true
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
function createSlashSkillAutocompleteProvider(
|
|
396
|
-
pi: ExtensionAPI,
|
|
397
|
-
current: AutocompleteProvider,
|
|
398
|
-
): AutocompleteProvider {
|
|
399
|
-
return {
|
|
400
|
-
async getSuggestions(
|
|
401
|
-
lines,
|
|
402
|
-
cursorLine,
|
|
403
|
-
cursorCol,
|
|
404
|
-
options,
|
|
405
|
-
): Promise<AutocompleteSuggestions | null> {
|
|
406
|
-
const currentLine = lines[cursorLine] ?? ""
|
|
407
|
-
const textBeforeCursor = currentLine.slice(0, cursorCol)
|
|
408
|
-
const query = extractSlashSkillPrefix(textBeforeCursor)
|
|
409
|
-
if (query === undefined || (query === "" && textBeforeCursor === "/")) {
|
|
410
|
-
return current.getSuggestions(lines, cursorLine, cursorCol, options)
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
const currentSuggestions = await current.getSuggestions(
|
|
414
|
-
lines,
|
|
415
|
-
cursorLine,
|
|
416
|
-
cursorCol,
|
|
417
|
-
options,
|
|
418
|
-
)
|
|
419
|
-
const skills = getSkills(pi)
|
|
420
|
-
if (options.signal.aborted || skills.length === 0) {
|
|
421
|
-
return currentSuggestions
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
const matches = query
|
|
425
|
-
? filterSkills(skills, query).slice(0, MAX_SUGGESTIONS)
|
|
426
|
-
: skills.slice(0, MAX_SUGGESTIONS)
|
|
427
|
-
|
|
428
|
-
if (matches.length === 0) return currentSuggestions
|
|
429
|
-
|
|
430
|
-
const skillItems = matches.map((skill): AutocompleteItem => {
|
|
431
|
-
const item: AutocompleteItem = {
|
|
432
|
-
value: `/${skill.name}`,
|
|
433
|
-
label: `skill:${skill.name}`,
|
|
434
|
-
}
|
|
435
|
-
const description = prefixAutocompleteDescription(skill)
|
|
436
|
-
if (description) item.description = description
|
|
437
|
-
return item
|
|
438
|
-
})
|
|
439
|
-
|
|
440
|
-
return mergeAutocompleteItems({
|
|
441
|
-
current: currentSuggestions,
|
|
442
|
-
skillItems,
|
|
443
|
-
preferCommands: isPromptStartSlashToken(
|
|
444
|
-
lines,
|
|
445
|
-
cursorLine,
|
|
446
|
-
textBeforeCursor,
|
|
447
|
-
query,
|
|
448
|
-
),
|
|
449
|
-
prefix: query,
|
|
450
|
-
})
|
|
451
|
-
},
|
|
452
|
-
|
|
453
|
-
applyCompletion(lines, cursorLine, cursorCol, item, prefix) {
|
|
454
|
-
const currentLine = lines[cursorLine] ?? ""
|
|
455
|
-
const prefixStart = cursorCol - prefix.length
|
|
456
|
-
const slashPrefixStart = prefix.startsWith("/")
|
|
457
|
-
? prefixStart
|
|
458
|
-
: prefixStart - 1
|
|
459
|
-
const isSlashSkillCompletion =
|
|
460
|
-
item.label.startsWith("skill:") &&
|
|
461
|
-
item.value.startsWith("/") &&
|
|
462
|
-
slashPrefixStart >= 0 &&
|
|
463
|
-
currentLine[slashPrefixStart] === "/"
|
|
464
|
-
|
|
465
|
-
if (!isSlashSkillCompletion) {
|
|
466
|
-
return current.applyCompletion(
|
|
467
|
-
lines,
|
|
468
|
-
cursorLine,
|
|
469
|
-
cursorCol,
|
|
470
|
-
item,
|
|
471
|
-
prefix,
|
|
472
|
-
)
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
const beforePrefix = currentLine.slice(0, slashPrefixStart)
|
|
476
|
-
const afterCursor = currentLine.slice(cursorCol)
|
|
477
|
-
const suffix = afterCursor.startsWith(" ") ? "" : " "
|
|
478
|
-
const nextLines = [...lines]
|
|
479
|
-
nextLines[cursorLine] =
|
|
480
|
-
`${beforePrefix}${item.value}${suffix}${afterCursor}`
|
|
481
|
-
return {
|
|
482
|
-
lines: nextLines,
|
|
483
|
-
cursorLine,
|
|
484
|
-
cursorCol: beforePrefix.length + item.value.length + suffix.length,
|
|
485
|
-
}
|
|
486
|
-
},
|
|
487
|
-
|
|
488
|
-
shouldTriggerFileCompletion(lines, cursorLine, cursorCol) {
|
|
489
|
-
return (
|
|
490
|
-
current.shouldTriggerFileCompletion?.(lines, cursorLine, cursorCol) ??
|
|
491
|
-
true
|
|
492
|
-
)
|
|
493
|
-
},
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
export default function (pi: ExtensionAPI): void {
|
|
498
|
-
let pendingInlineSkillContent: string | undefined
|
|
499
|
-
let pendingInlineSkillNames: string[] = []
|
|
500
|
-
let pendingInlineSkillBlocks: ParsedSkillBlock[] = []
|
|
501
|
-
let loadedSkills = new Set<string>()
|
|
502
|
-
|
|
503
|
-
installSlashAutocompleteTrigger()
|
|
504
|
-
|
|
505
|
-
pi.registerMessageRenderer(
|
|
506
|
-
INLINE_SKILL_MESSAGE_TYPE,
|
|
507
|
-
(message, { expanded }, theme) => {
|
|
508
|
-
const details = message.details as InlineSkillMessageDetails | undefined
|
|
509
|
-
const names = details?.names?.length ? details.names.join(", ") : "skill"
|
|
510
|
-
const label = theme.fg(
|
|
511
|
-
"customMessageLabel",
|
|
512
|
-
`\x1b[1m[${INLINE_SKILL_MESSAGE_TYPE}]\x1b[22m`,
|
|
513
|
-
)
|
|
514
|
-
|
|
515
|
-
if (details?.skills?.length) {
|
|
516
|
-
const container = new Container()
|
|
517
|
-
for (const skill of details.skills) {
|
|
518
|
-
const component = new SkillInvocationMessageComponent(skill)
|
|
519
|
-
component.setExpanded(expanded)
|
|
520
|
-
container.addChild(component)
|
|
521
|
-
}
|
|
522
|
-
return container
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
const box = new Box(1, 1, (text) => theme.bg("customMessageBg", text))
|
|
526
|
-
box.addChild(
|
|
527
|
-
new Text(
|
|
528
|
-
`${label} ${theme.fg("customMessageText", names)}${theme.fg("dim", " (ctrl+o to expand)")}`,
|
|
529
|
-
0,
|
|
530
|
-
0,
|
|
531
|
-
),
|
|
532
|
-
)
|
|
533
|
-
return box
|
|
534
|
-
},
|
|
535
|
-
)
|
|
536
|
-
|
|
537
|
-
pi.registerCommand("loaded-skills", {
|
|
538
|
-
description: "List skills loaded in this session",
|
|
539
|
-
handler: async (_args, ctx) => {
|
|
540
|
-
const names = [...restoreLoadedSkills(ctx)].toSorted((a, b) =>
|
|
541
|
-
a.localeCompare(b),
|
|
542
|
-
)
|
|
543
|
-
|
|
544
|
-
if (names.length === 0) {
|
|
545
|
-
ctx.ui.notify("No skills loaded yet", "info")
|
|
546
|
-
return
|
|
547
|
-
}
|
|
548
|
-
ctx.ui.notify(`Loaded skills: ${names.join(", ")}`, "info")
|
|
549
|
-
},
|
|
550
|
-
})
|
|
551
|
-
|
|
552
|
-
pi.on("session_start", async (_event, ctx) => {
|
|
553
|
-
loadedSkills = restoreLoadedSkills(ctx)
|
|
554
|
-
ctx.ui.addAutocompleteProvider((current) =>
|
|
555
|
-
createSlashSkillAutocompleteProvider(pi, current),
|
|
556
|
-
)
|
|
557
|
-
})
|
|
558
|
-
|
|
559
|
-
pi.on("session_tree", async (_event, ctx) => {
|
|
560
|
-
loadedSkills = restoreLoadedSkills(ctx)
|
|
561
|
-
})
|
|
562
|
-
|
|
563
|
-
pi.on("tool_result", async (event, ctx) => {
|
|
564
|
-
if (event.toolName !== "read" || event.isError) return
|
|
565
|
-
|
|
566
|
-
const input = event.input as { path?: unknown }
|
|
567
|
-
if (typeof input.path !== "string") return
|
|
568
|
-
|
|
569
|
-
const readPath = normalizePath(input.path, ctx.cwd)
|
|
570
|
-
const skillName = getCurrentSkillPathMap(pi, ctx.cwd).get(readPath)
|
|
571
|
-
if (!skillName || loadedSkills.has(skillName)) return
|
|
572
|
-
|
|
573
|
-
loadedSkills.add(skillName)
|
|
574
|
-
pi.appendEntry(LOADED_SKILL_ENTRY_TYPE, {
|
|
575
|
-
name: skillName,
|
|
576
|
-
source: "tool-result",
|
|
577
|
-
})
|
|
578
|
-
})
|
|
579
|
-
|
|
580
|
-
pi.on("input", async (event, ctx) => {
|
|
581
|
-
pendingInlineSkillContent = undefined
|
|
582
|
-
pendingInlineSkillNames = []
|
|
583
|
-
pendingInlineSkillBlocks = []
|
|
584
|
-
loadedSkills = restoreLoadedSkills(ctx)
|
|
585
|
-
if (event.source === "extension" || !event.text.includes("/")) {
|
|
586
|
-
return { action: "continue" }
|
|
587
|
-
}
|
|
588
|
-
if (hasStartingCommandConflict(pi, event.text)) {
|
|
589
|
-
return { action: "continue" }
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
const expanded = findInlineSkills(event.text, getSkills(pi))
|
|
593
|
-
if (!expanded) return { action: "continue" }
|
|
594
|
-
|
|
595
|
-
const skillsToInject = expanded.selected.filter(
|
|
596
|
-
(skill) => !loadedSkills.has(skill.name),
|
|
597
|
-
)
|
|
598
|
-
|
|
599
|
-
if (skillsToInject.length > 0) {
|
|
600
|
-
try {
|
|
601
|
-
const inlineSkillContent = buildInlineSkillContent(
|
|
602
|
-
skillsToInject,
|
|
603
|
-
ctx.cwd,
|
|
604
|
-
)
|
|
605
|
-
pendingInlineSkillContent = inlineSkillContent.content
|
|
606
|
-
pendingInlineSkillBlocks = inlineSkillContent.skillBlocks
|
|
607
|
-
pendingInlineSkillNames = skillsToInject.map((skill) => skill.name)
|
|
608
|
-
for (const skill of skillsToInject) {
|
|
609
|
-
loadedSkills.add(skill.name)
|
|
610
|
-
}
|
|
611
|
-
} catch (error) {
|
|
612
|
-
pendingInlineSkillContent = undefined
|
|
613
|
-
pendingInlineSkillNames = []
|
|
614
|
-
pendingInlineSkillBlocks = []
|
|
615
|
-
ctx.ui.notify(
|
|
616
|
-
`inline-skills: failed to load skill: ${error instanceof Error ? error.message : String(error)}`,
|
|
617
|
-
"error",
|
|
618
|
-
)
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
return {
|
|
623
|
-
action: "transform",
|
|
624
|
-
text: event.text,
|
|
625
|
-
...(event.images ? { images: event.images } : {}),
|
|
626
|
-
}
|
|
627
|
-
})
|
|
628
|
-
|
|
629
|
-
pi.on("before_agent_start", async () => {
|
|
630
|
-
if (!pendingInlineSkillContent) return
|
|
631
|
-
const content = pendingInlineSkillContent
|
|
632
|
-
const names = pendingInlineSkillNames
|
|
633
|
-
const skills = pendingInlineSkillBlocks
|
|
634
|
-
pendingInlineSkillContent = undefined
|
|
635
|
-
pendingInlineSkillNames = []
|
|
636
|
-
pendingInlineSkillBlocks = []
|
|
637
|
-
return {
|
|
638
|
-
message: {
|
|
639
|
-
customType: INLINE_SKILL_MESSAGE_TYPE,
|
|
640
|
-
content,
|
|
641
|
-
display: true,
|
|
642
|
-
details: { names, skills },
|
|
643
|
-
},
|
|
644
|
-
}
|
|
645
|
-
})
|
|
646
|
-
}
|