@herbertgao/pi-extensions 2026.10.17 → 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.
Files changed (170) hide show
  1. package/README.md +6 -7
  2. package/THIRD_PARTY_NOTICES.md +0 -1
  3. package/node_modules/@dietrichgebert/ponytail/.qoder-plugin/plugin.json +1 -1
  4. package/node_modules/@dietrichgebert/ponytail/hooks/band/metrics.ts +5 -11
  5. package/node_modules/@dietrichgebert/ponytail/hooks/band/register.tsx +69 -46
  6. package/node_modules/@dietrichgebert/ponytail/hooks/band/types.d.ts +0 -1
  7. package/node_modules/@dietrichgebert/ponytail/hooks/claude-codex-hooks.json +3 -3
  8. package/node_modules/@dietrichgebert/ponytail/hooks/copilot-hooks.json +2 -2
  9. package/node_modules/@dietrichgebert/ponytail/hooks/cursor-hooks.json +2 -2
  10. package/node_modules/@dietrichgebert/ponytail/hooks/ponytail-activate.js +4 -3
  11. package/node_modules/@dietrichgebert/ponytail/hooks/ponytail-map.js +4 -1
  12. package/node_modules/@dietrichgebert/ponytail/package.json +1 -1
  13. package/node_modules/@narumitw/pi-btw/README.md +3 -1
  14. package/node_modules/@narumitw/pi-btw/dist/index.ts +26 -5
  15. package/node_modules/@narumitw/pi-btw/dist/index.ts.map +2 -2
  16. package/node_modules/@narumitw/pi-btw/docs/core-alignment.md +40 -0
  17. package/node_modules/@narumitw/pi-btw/docs/workflows.md +3 -0
  18. package/node_modules/@narumitw/pi-btw/package.json +1 -1
  19. package/node_modules/@narumitw/pi-btw/src/btw.ts +31 -5
  20. package/node_modules/@narumitw/pi-btw/src/fullscreen-ui.ts +13 -0
  21. package/node_modules/pi-lens/CHANGELOG.md +83 -0
  22. package/node_modules/pi-lens/README.md +5 -1
  23. package/node_modules/pi-lens/dist/{chunk-JL6CXUMW.js → chunk-24BILSZW.js} +1 -1
  24. package/node_modules/pi-lens/dist/{chunk-S67UJDGQ.js → chunk-2TF6RXWB.js} +5 -5
  25. package/node_modules/pi-lens/dist/{chunk-ARD426WI.js → chunk-3F6BMY53.js} +1 -1
  26. package/node_modules/pi-lens/dist/{chunk-5ZR3APIM.js → chunk-3FRLWYBG.js} +26 -26
  27. package/node_modules/pi-lens/dist/{chunk-T7FTXGS3.js → chunk-3K2F6UDZ.js} +30 -30
  28. package/node_modules/pi-lens/dist/{chunk-HK6JVFZC.js → chunk-3YY7IXIL.js} +2 -2
  29. package/node_modules/pi-lens/dist/chunk-46TNM7XZ.js +88 -0
  30. package/node_modules/pi-lens/dist/{chunk-4AVZ3TG7.js → chunk-4L36HG27.js} +8 -8
  31. package/node_modules/pi-lens/dist/{chunk-PO45POGF.js → chunk-4LM3VAZH.js} +1 -1
  32. package/node_modules/pi-lens/dist/{chunk-UN4TEBWN.js → chunk-4LOE5R5P.js} +9 -9
  33. package/node_modules/pi-lens/dist/{chunk-KLQVC3XC.js → chunk-4YHYPW2G.js} +30 -7
  34. package/node_modules/pi-lens/dist/{chunk-W5LGKNET.js → chunk-4ZYJHQMB.js} +6 -6
  35. package/node_modules/pi-lens/dist/{chunk-W2V54OCL.js → chunk-6IR3ZYIB.js} +2 -2
  36. package/node_modules/pi-lens/dist/{chunk-FJIVKLPH.js → chunk-72OKUXSD.js} +10 -10
  37. package/node_modules/pi-lens/dist/{chunk-7RQXA5GG.js → chunk-75GAYVNO.js} +10 -9
  38. package/node_modules/pi-lens/dist/{chunk-V3APN3DY.js → chunk-7E2563GA.js} +12 -12
  39. package/node_modules/pi-lens/dist/{chunk-4WX4CTUE.js → chunk-7GLOLOSH.js} +25 -25
  40. package/node_modules/pi-lens/dist/{chunk-BWYQUPOS.js → chunk-ABPKUVA4.js} +1 -1
  41. package/node_modules/pi-lens/dist/{chunk-IPDG45G5.js → chunk-AKUUMGD5.js} +9 -9
  42. package/node_modules/pi-lens/dist/{chunk-Q6D6VMI4.js → chunk-ASUXV767.js} +6 -6
  43. package/node_modules/pi-lens/dist/{chunk-BM5GS6ZH.js → chunk-AWDSEDER.js} +2 -2
  44. package/node_modules/pi-lens/dist/{chunk-MA77RSFN.js → chunk-BZARLRJW.js} +4 -4
  45. package/node_modules/pi-lens/dist/{chunk-EVDGNG4F.js → chunk-CB4WHS4H.js} +3 -3
  46. package/node_modules/pi-lens/dist/{chunk-FA5LDARD.js → chunk-CCV2EU7T.js} +7 -7
  47. package/node_modules/pi-lens/dist/{chunk-U6OC3QEM.js → chunk-CE6VMBCB.js} +15 -15
  48. package/node_modules/pi-lens/dist/{chunk-AMXIUN2R.js → chunk-CPSR3AVL.js} +2 -2
  49. package/node_modules/pi-lens/dist/{chunk-SXGD4ANG.js → chunk-CTADOKYM.js} +7 -7
  50. package/node_modules/pi-lens/dist/{chunk-63RIVFQI.js → chunk-DH5JPM3K.js} +1 -1
  51. package/node_modules/pi-lens/dist/{chunk-MT6BVNFW.js → chunk-DPGEAHZT.js} +3 -3
  52. package/node_modules/pi-lens/dist/{chunk-4PCQCU47.js → chunk-DQZFQSR5.js} +2 -2
  53. package/node_modules/pi-lens/dist/{chunk-BHUWL2Y3.js → chunk-E7HJ56Y7.js} +5 -5
  54. package/node_modules/pi-lens/dist/{chunk-DQXSPYRI.js → chunk-EAOK7MIZ.js} +2 -2
  55. package/node_modules/pi-lens/dist/{chunk-2RLWJO5K.js → chunk-EKWX4WD3.js} +3 -3
  56. package/node_modules/pi-lens/dist/{chunk-WIZWZR4C.js → chunk-F7K5IBZG.js} +30 -28
  57. package/node_modules/pi-lens/dist/{chunk-VQH24FIP.js → chunk-FB5SCCPT.js} +9 -9
  58. package/node_modules/pi-lens/dist/{chunk-GZE7WOI4.js → chunk-FZKFVUEC.js} +438 -140
  59. package/node_modules/pi-lens/dist/{chunk-TIYGSODX.js → chunk-H7OR7DFZ.js} +15 -13
  60. package/node_modules/pi-lens/dist/{chunk-CJYKEW2L.js → chunk-HO6LWE2E.js} +1 -1
  61. package/node_modules/pi-lens/dist/{chunk-YSBHPOY6.js → chunk-HR3OJ3TH.js} +8 -8
  62. package/node_modules/pi-lens/dist/{chunk-CFRQMBGP.js → chunk-HWDAVBFU.js} +14 -14
  63. package/node_modules/pi-lens/dist/{chunk-2X4VLOCC.js → chunk-JJ2RRESP.js} +8 -5
  64. package/node_modules/pi-lens/dist/{chunk-YBSONGSZ.js → chunk-JMEKXFOL.js} +24 -24
  65. package/node_modules/pi-lens/dist/{chunk-MKVZQUEG.js → chunk-KDX35VXP.js} +69 -13
  66. package/node_modules/pi-lens/dist/{chunk-75SY4F24.js → chunk-KKCK636N.js} +7 -7
  67. package/node_modules/pi-lens/dist/{chunk-OLAWH5UQ.js → chunk-KPPJTH44.js} +2 -1
  68. package/node_modules/pi-lens/dist/{chunk-5APMQ2IJ.js → chunk-KW5JQPO5.js} +1 -1
  69. package/node_modules/pi-lens/dist/{chunk-SCIUNBPF.js → chunk-L3CMBQMH.js} +11 -11
  70. package/node_modules/pi-lens/dist/{chunk-GAACZY6R.js → chunk-L5JYIU47.js} +7 -7
  71. package/node_modules/pi-lens/dist/{chunk-2DDDCJDL.js → chunk-LBLBAFG3.js} +3 -3
  72. package/node_modules/pi-lens/dist/{chunk-NNKXDXXS.js → chunk-LLS45EWB.js} +8 -0
  73. package/node_modules/pi-lens/dist/{chunk-WQOIR3QY.js → chunk-LS3QJRUB.js} +7 -7
  74. package/node_modules/pi-lens/dist/{chunk-XCUHKYCQ.js → chunk-LSC3VADM.js} +6 -6
  75. package/node_modules/pi-lens/dist/{chunk-GMTFDAOK.js → chunk-LUBPZN36.js} +6 -6
  76. package/node_modules/pi-lens/dist/{chunk-DMSLNKF7.js → chunk-LV4UMYVH.js} +19 -19
  77. package/node_modules/pi-lens/dist/{chunk-XAIT2YGS.js → chunk-MB6PXBUA.js} +2 -2
  78. package/node_modules/pi-lens/dist/{chunk-AE37FEGH.js → chunk-MNJIXFX4.js} +1 -1
  79. package/node_modules/pi-lens/dist/{chunk-OJLTLYHB.js → chunk-MPKRJBPK.js} +30 -10
  80. package/node_modules/pi-lens/dist/{chunk-QGSTQH4D.js → chunk-N5WSK2K7.js} +6 -6
  81. package/node_modules/pi-lens/dist/{chunk-Z7IGUAXL.js → chunk-NA7SEXHE.js} +10 -6
  82. package/node_modules/pi-lens/dist/{chunk-UHGF5UT5.js → chunk-O4BJFESU.js} +1 -1
  83. package/node_modules/pi-lens/dist/{chunk-UCGQT677.js → chunk-OE5ZBP7F.js} +10 -10
  84. package/node_modules/pi-lens/dist/{chunk-KSR7RGQY.js → chunk-OXOI55RU.js} +4 -4
  85. package/node_modules/pi-lens/dist/{chunk-NDMCVUYK.js → chunk-PR6PO3ES.js} +2 -2
  86. package/node_modules/pi-lens/dist/{chunk-NIU2IPC5.js → chunk-PUZ3E2J4.js} +3 -3
  87. package/node_modules/pi-lens/dist/{chunk-2DMLM3ZO.js → chunk-QHSNL7B2.js} +8 -8
  88. package/node_modules/pi-lens/dist/{chunk-ZYNI26MI.js → chunk-QOE342SU.js} +1 -1
  89. package/node_modules/pi-lens/dist/{chunk-3WEPUD2V.js → chunk-R5MOQM2H.js} +98 -31
  90. package/node_modules/pi-lens/dist/{chunk-PPIBVH4R.js → chunk-RC2Z6K47.js} +4 -4
  91. package/node_modules/pi-lens/dist/{chunk-LEJOJDXL.js → chunk-RORGS5II.js} +4 -4
  92. package/node_modules/pi-lens/dist/{chunk-K2YGBXOA.js → chunk-RQS4QQSD.js} +1 -1
  93. package/node_modules/pi-lens/dist/{chunk-XQCSWV2G.js → chunk-RRV3FNNM.js} +10 -10
  94. package/node_modules/pi-lens/dist/{chunk-GTAI2J6U.js → chunk-SHLDT3OI.js} +8 -8
  95. package/node_modules/pi-lens/dist/{chunk-VPBIMOAQ.js → chunk-SNDXCFRS.js} +11 -9
  96. package/node_modules/pi-lens/dist/{chunk-Q4FCYCRE.js → chunk-T7A2HK2B.js} +10 -10
  97. package/node_modules/pi-lens/dist/{chunk-MN7MHUXQ.js → chunk-U5HPROLA.js} +1 -1
  98. package/node_modules/pi-lens/dist/{chunk-ZUUI3ZSA.js → chunk-U6VN4NVL.js} +1 -1
  99. package/node_modules/pi-lens/dist/{chunk-W5R5SABV.js → chunk-U7BD2QL7.js} +6 -6
  100. package/node_modules/pi-lens/dist/{chunk-P4QNXS6I.js → chunk-UF7RTZSO.js} +8 -8
  101. package/node_modules/pi-lens/dist/{chunk-A3YNG5KP.js → chunk-URCQWAQ4.js} +11 -11
  102. package/node_modules/pi-lens/dist/{chunk-FFL3A2VP.js → chunk-VUZWQ7UG.js} +4 -4
  103. package/node_modules/pi-lens/dist/{chunk-YRD4ISED.js → chunk-W4WP2ERB.js} +10 -10
  104. package/node_modules/pi-lens/dist/{chunk-OOU2WZZE.js → chunk-WDBICWH3.js} +1 -1
  105. package/node_modules/pi-lens/dist/{chunk-BI5LAQ3Y.js → chunk-WGRJOXED.js} +114 -148
  106. package/node_modules/pi-lens/dist/{chunk-ZQ6NZZTB.js → chunk-WME2OQST.js} +33 -0
  107. package/node_modules/pi-lens/dist/{chunk-DC4CFXM5.js → chunk-XT2HTCJ5.js} +1 -1
  108. package/node_modules/pi-lens/dist/{chunk-SJJYRZB4.js → chunk-Y7F7IEE3.js} +55 -23
  109. package/node_modules/pi-lens/dist/{chunk-2F47TQOA.js → chunk-YES5CACN.js} +29 -29
  110. package/node_modules/pi-lens/dist/{chunk-H7HTEQUZ.js → chunk-YHC2O2WO.js} +7 -7
  111. package/node_modules/pi-lens/dist/{chunk-Q3UZHW6N.js → chunk-YVHBNSME.js} +6 -10
  112. package/node_modules/pi-lens/dist/{chunk-3MYEA7QD.js → chunk-ZE3KXHS7.js} +2 -2
  113. package/node_modules/pi-lens/dist/{chunk-VG5JS5SW.js → chunk-ZGSJDWQU.js} +2 -2
  114. package/node_modules/pi-lens/dist/{chunk-5CV5ITZF.js → chunk-ZJTT47IG.js} +1 -1
  115. package/node_modules/pi-lens/dist/{chunk-Q4EMRFNA.js → chunk-ZMAUPOMG.js} +24 -24
  116. package/node_modules/pi-lens/dist/index.js +1925 -944
  117. package/node_modules/pi-lens/dist/mcp/analyze-cli.js +6 -6
  118. package/node_modules/pi-lens/dist/mcp/cli.js +30 -30
  119. package/node_modules/pi-lens/dist/mcp/server.js +707 -455
  120. package/node_modules/pi-lens/dist/mcp/worker.js +48 -48
  121. package/node_modules/pi-lens/dist/probes/installer.js +13 -13
  122. package/node_modules/pi-lens/docs/agent-tools.md +11 -3
  123. package/node_modules/pi-lens/docs/defect-shapes.md +15 -1
  124. package/node_modules/pi-lens/docs/dependencies.md +1 -0
  125. package/node_modules/pi-lens/docs/environment-variables.md +14 -0
  126. package/node_modules/pi-lens/docs/features.md +11 -1
  127. package/node_modules/pi-lens/docs/globalconfig.md +12 -1
  128. package/node_modules/pi-lens/docs/invariants/git-guard-host.md +34 -0
  129. package/node_modules/pi-lens/docs/invariants/lsp-trust-exec.md +6 -0
  130. package/node_modules/pi-lens/docs/invariants/session-telemetry.md +42 -2
  131. package/node_modules/pi-lens/docs/lsp-capability-matrix.md +89 -45
  132. package/node_modules/pi-lens/docs/lsp-idle-eviction.md +3 -5
  133. package/node_modules/pi-lens/docs/pi-lens-fixer.md +8 -1
  134. package/node_modules/pi-lens/docs/pi-lens-merge-policy.md +7 -4
  135. package/node_modules/pi-lens/docs/pi-lens-subagent.md +7 -4
  136. package/node_modules/pi-lens/docs/schema/pi-lens-config-v1.json +23 -0
  137. package/node_modules/pi-lens/docs/servercapabilities.md +1 -1
  138. package/node_modules/pi-lens/docs/settings.md +5 -0
  139. package/node_modules/pi-lens/docs/usage.md +5 -0
  140. package/node_modules/pi-lens/package.json +1 -1
  141. package/node_modules/pi-web-access/CHANGELOG.md +32 -1
  142. package/node_modules/pi-web-access/README.md +53 -15
  143. package/node_modules/pi-web-access/cloudflare-search.ts +237 -0
  144. package/node_modules/pi-web-access/curator-page.ts +12 -1
  145. package/node_modules/pi-web-access/curator-server.ts +3 -0
  146. package/node_modules/pi-web-access/dist/index.js +9450 -8642
  147. package/node_modules/pi-web-access/dist/mcp-cli.js +16742 -15954
  148. package/node_modules/pi-web-access/exa.ts +94 -20
  149. package/node_modules/pi-web-access/extract.ts +61 -9
  150. package/node_modules/pi-web-access/gemini-search.ts +17 -7
  151. package/node_modules/pi-web-access/index.ts +6 -0
  152. package/node_modules/pi-web-access/mcp-tool-definitions.ts +50 -34
  153. package/node_modules/pi-web-access/openai-search.ts +3 -1
  154. package/node_modules/pi-web-access/package.json +3 -2
  155. package/node_modules/pi-web-access/page-query.ts +13 -3
  156. package/node_modules/pi-web-access/pdf-extract.ts +1 -5
  157. package/node_modules/pi-web-access/perplexity.ts +2 -0
  158. package/node_modules/pi-web-access/searchapi.ts +202 -0
  159. package/node_modules/pi-web-access/source-check.ts +7 -0
  160. package/node_modules/pi-web-access/ssrf-protection.ts +25 -1
  161. package/node_modules/pi-web-access/summary-review.ts +21 -10
  162. package/node_modules/pi-web-access/tabstack.ts +289 -0
  163. package/node_modules/pi-web-access/utils.ts +79 -16
  164. package/node_modules/pi-web-access/web-tool-core.ts +10 -1
  165. package/node_modules/pi-web-access/xai-search.ts +3 -1
  166. package/package.json +5 -8
  167. package/node_modules/@tifan/pi-inline-skills/README.md +0 -41
  168. package/node_modules/@tifan/pi-inline-skills/package.json +0 -44
  169. package/node_modules/@tifan/pi-inline-skills/src/index.ts +0 -646
  170. package/node_modules/pi-lens/dist/chunk-G2B7F6ZU.js +0 -88
@@ -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, "&amp;")
244
- .replace(/"/g, "&quot;")
245
- .replace(/</g, "&lt;")
246
- .replace(/>/g, "&gt;")
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
- }