@mrclrchtr/supi-skills 4.7.0
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 +46 -0
- package/node_modules/@mrclrchtr/supi-core/README.md +112 -0
- package/node_modules/@mrclrchtr/supi-core/package.json +76 -0
- package/node_modules/@mrclrchtr/supi-core/src/api.ts +40 -0
- package/node_modules/@mrclrchtr/supi-core/src/config/config.ts +201 -0
- package/node_modules/@mrclrchtr/supi-core/src/config/prompt-surface.ts +363 -0
- package/node_modules/@mrclrchtr/supi-core/src/config.ts +10 -0
- package/node_modules/@mrclrchtr/supi-core/src/context/context-provider-registry.ts +36 -0
- package/node_modules/@mrclrchtr/supi-core/src/context/context-tag.ts +31 -0
- package/node_modules/@mrclrchtr/supi-core/src/context.ts +8 -0
- package/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +287 -0
- package/node_modules/@mrclrchtr/supi-core/src/evidence-badge.ts +41 -0
- package/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +57 -0
- package/node_modules/@mrclrchtr/supi-core/src/index.ts +34 -0
- package/node_modules/@mrclrchtr/supi-core/src/llm.ts +201 -0
- package/node_modules/@mrclrchtr/supi-core/src/model-selection.ts +134 -0
- package/node_modules/@mrclrchtr/supi-core/src/path-utils.ts +44 -0
- package/node_modules/@mrclrchtr/supi-core/src/path.ts +2 -0
- package/node_modules/@mrclrchtr/supi-core/src/project-roots.ts +170 -0
- package/node_modules/@mrclrchtr/supi-core/src/project.ts +15 -0
- package/node_modules/@mrclrchtr/supi-core/src/prompt-surface.ts +4 -0
- package/node_modules/@mrclrchtr/supi-core/src/registry-utils.ts +93 -0
- package/node_modules/@mrclrchtr/supi-core/src/report.ts +121 -0
- package/node_modules/@mrclrchtr/supi-core/src/session-utils.ts +71 -0
- package/node_modules/@mrclrchtr/supi-core/src/session.ts +8 -0
- package/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +102 -0
- package/node_modules/@mrclrchtr/supi-core/src/settings/settings-schema.ts +453 -0
- package/node_modules/@mrclrchtr/supi-core/src/settings.ts +36 -0
- package/node_modules/@mrclrchtr/supi-core/src/spinner-frames.ts +11 -0
- package/node_modules/@mrclrchtr/supi-core/src/status-spinner.ts +68 -0
- package/node_modules/@mrclrchtr/supi-core/src/terminal.ts +60 -0
- package/package.json +64 -0
- package/src/extension.ts +9 -0
- package/src/skill-catalog.ts +153 -0
- package/src/skill-load-settings.ts +305 -0
- package/src/skill-model-invocation.ts +134 -0
- package/src/skill-settings.ts +400 -0
- package/src/skill-shortcut.ts +123 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
// Configurable tool prompt-surface overrides.
|
|
2
|
+
//
|
|
3
|
+
// Resolution order: package defaults ← global SuPi config ← trusted project SuPi config.
|
|
4
|
+
// Project overrides are trust-gated; they require PI project trust and a PI-recognized
|
|
5
|
+
// trust-requiring resource (e.g. .pi/settings.json).
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
type ExtensionContext,
|
|
9
|
+
hasTrustRequiringProjectResources,
|
|
10
|
+
} from "@earendil-works/pi-coding-agent";
|
|
11
|
+
import { loadSupiConfigSectionForScope, type SupiConfigOptions } from "./config.ts";
|
|
12
|
+
|
|
13
|
+
// ── Public types ───────────────────────────────────────────────────────────
|
|
14
|
+
|
|
15
|
+
/** Model-facing text that PI adds to one registered tool's prompt surface. */
|
|
16
|
+
export interface SuiPiToolPromptSurface {
|
|
17
|
+
description: string;
|
|
18
|
+
promptSnippet: string;
|
|
19
|
+
promptGuidelines: string[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type ToolPromptSurfaceDiagnosticCode =
|
|
23
|
+
| "invalidPromptSurfaceConfig"
|
|
24
|
+
| "invalidPromptSurfaceField"
|
|
25
|
+
| "projectPromptSurfaceIgnored";
|
|
26
|
+
|
|
27
|
+
export interface ToolPromptSurfaceDiagnostic {
|
|
28
|
+
code: ToolPromptSurfaceDiagnosticCode;
|
|
29
|
+
scope: "global" | "project";
|
|
30
|
+
section: string;
|
|
31
|
+
toolName: string;
|
|
32
|
+
message: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ResolveToolPromptSurfaceOptions extends SupiConfigOptions {
|
|
36
|
+
section: string;
|
|
37
|
+
toolName: string;
|
|
38
|
+
defaults: SuiPiToolPromptSurface;
|
|
39
|
+
ctx: Pick<ExtensionContext, "cwd" | "isProjectTrusted">;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ResolveToolPromptSurfaceResult {
|
|
43
|
+
surface: SuiPiToolPromptSurface;
|
|
44
|
+
diagnostics: ToolPromptSurfaceDiagnostic[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ── Private types ──────────────────────────────────────────────────────────
|
|
48
|
+
|
|
49
|
+
type PromptSurfaceField = keyof SuiPiToolPromptSurface;
|
|
50
|
+
type PromptSurfaceScope = ToolPromptSurfaceDiagnostic["scope"];
|
|
51
|
+
|
|
52
|
+
const PROMPT_SURFACE_FIELDS = new Set<string>(["description", "promptSnippet", "promptGuidelines"]);
|
|
53
|
+
|
|
54
|
+
const PROMPT_SURFACE_DIAGNOSTICS_KEY = Symbol.for(
|
|
55
|
+
"@mrclrchtr/supi-core/tool-prompt-surface/notified-diagnostics",
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// ── Resolution ─────────────────────────────────────────────────────────────
|
|
59
|
+
|
|
60
|
+
/** Resolve a tool's model-facing prompt surface from defaults + SuPi config overrides. */
|
|
61
|
+
export function resolveToolPromptSurface(
|
|
62
|
+
options: ResolveToolPromptSurfaceOptions,
|
|
63
|
+
): ResolveToolPromptSurfaceResult {
|
|
64
|
+
const diagnostics: ToolPromptSurfaceDiagnostic[] = [];
|
|
65
|
+
let surface = clonePromptSurface(options.defaults);
|
|
66
|
+
|
|
67
|
+
const globalSection = loadSupiConfigSectionForScope(options.section, options.ctx.cwd, {
|
|
68
|
+
scope: "global",
|
|
69
|
+
homeDir: options.homeDir,
|
|
70
|
+
});
|
|
71
|
+
surface = applyPromptSurfaceScope(surface, options, "global", globalSection, diagnostics);
|
|
72
|
+
|
|
73
|
+
const projectSection = loadSupiConfigSectionForScope(options.section, options.ctx.cwd, {
|
|
74
|
+
scope: "project",
|
|
75
|
+
homeDir: options.homeDir,
|
|
76
|
+
});
|
|
77
|
+
const projectPromptSurface = getPromptSurfaceConfig(projectSection, options.toolName, {
|
|
78
|
+
diagnostics,
|
|
79
|
+
options,
|
|
80
|
+
scope: "project",
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
if (projectPromptSurface) {
|
|
84
|
+
const hasTrustMarker = hasTrustRequiringProjectResources(options.ctx.cwd);
|
|
85
|
+
const projectTrusted = options.ctx.isProjectTrusted();
|
|
86
|
+
if (hasTrustMarker && projectTrusted) {
|
|
87
|
+
surface = applyPromptSurfaceConfig(
|
|
88
|
+
surface,
|
|
89
|
+
options.defaults,
|
|
90
|
+
projectPromptSurface,
|
|
91
|
+
options,
|
|
92
|
+
"project",
|
|
93
|
+
diagnostics,
|
|
94
|
+
);
|
|
95
|
+
} else {
|
|
96
|
+
diagnostics.push({
|
|
97
|
+
code: "projectPromptSurfaceIgnored",
|
|
98
|
+
scope: "project",
|
|
99
|
+
section: options.section,
|
|
100
|
+
toolName: options.toolName,
|
|
101
|
+
message: hasTrustMarker
|
|
102
|
+
? `Project prompt-surface overrides for ${options.toolName} were ignored because the project is not trusted in PI.`
|
|
103
|
+
: `Project prompt-surface overrides for ${options.toolName} were ignored because ${options.ctx.cwd}/.pi/supi/config.json is not PI trust-gated. Add .pi/settings.json and trust the project to enable them.`,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return { surface, diagnostics };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Notify prompt-surface diagnostics once per session/tool/diagnostic code. */
|
|
112
|
+
export function notifyToolPromptSurfaceDiagnostics(
|
|
113
|
+
ctx: Pick<ExtensionContext, "sessionManager" | "ui">,
|
|
114
|
+
diagnostics: readonly ToolPromptSurfaceDiagnostic[],
|
|
115
|
+
): void {
|
|
116
|
+
const globalRecord = globalThis as Record<symbol, Set<string> | undefined>;
|
|
117
|
+
const notified = globalRecord[PROMPT_SURFACE_DIAGNOSTICS_KEY] ?? new Set<string>();
|
|
118
|
+
globalRecord[PROMPT_SURFACE_DIAGNOSTICS_KEY] = notified;
|
|
119
|
+
const sessionId = ctx.sessionManager.getSessionId();
|
|
120
|
+
|
|
121
|
+
for (const diagnostic of diagnostics) {
|
|
122
|
+
const key = `${sessionId}:${diagnostic.section}:${diagnostic.toolName}:${diagnostic.code}`;
|
|
123
|
+
if (notified.has(key)) continue;
|
|
124
|
+
notified.add(key);
|
|
125
|
+
ctx.ui.notify(diagnostic.message, "warning");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// ── Scope helpers ──────────────────────────────────────────────────────────
|
|
130
|
+
|
|
131
|
+
// biome-ignore lint/complexity/useMaxParams: resolver dispatch with diagnostics
|
|
132
|
+
function applyPromptSurfaceScope(
|
|
133
|
+
current: SuiPiToolPromptSurface,
|
|
134
|
+
options: ResolveToolPromptSurfaceOptions,
|
|
135
|
+
scope: PromptSurfaceScope,
|
|
136
|
+
sectionConfig: Record<string, unknown> | null,
|
|
137
|
+
diagnostics: ToolPromptSurfaceDiagnostic[],
|
|
138
|
+
): SuiPiToolPromptSurface {
|
|
139
|
+
const promptSurface = getPromptSurfaceConfig(sectionConfig, options.toolName, {
|
|
140
|
+
diagnostics,
|
|
141
|
+
options,
|
|
142
|
+
scope,
|
|
143
|
+
});
|
|
144
|
+
if (!promptSurface) return current;
|
|
145
|
+
return applyPromptSurfaceConfig(
|
|
146
|
+
current,
|
|
147
|
+
options.defaults,
|
|
148
|
+
promptSurface,
|
|
149
|
+
options,
|
|
150
|
+
scope,
|
|
151
|
+
diagnostics,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// biome-ignore lint/complexity/useMaxParams: per-scope config merger with diagnostics
|
|
156
|
+
function applyPromptSurfaceConfig(
|
|
157
|
+
current: SuiPiToolPromptSurface,
|
|
158
|
+
defaults: SuiPiToolPromptSurface,
|
|
159
|
+
config: Record<string, unknown>,
|
|
160
|
+
options: ResolveToolPromptSurfaceOptions,
|
|
161
|
+
scope: PromptSurfaceScope,
|
|
162
|
+
diagnostics: ToolPromptSurfaceDiagnostic[],
|
|
163
|
+
): SuiPiToolPromptSurface {
|
|
164
|
+
let next = clonePromptSurface(current);
|
|
165
|
+
|
|
166
|
+
for (const field of getResetFields(config.$reset, options, scope, diagnostics)) {
|
|
167
|
+
next = { ...next, [field]: clonePromptSurfaceField(defaults[field]) };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const description = getOptionalNonEmptyString(
|
|
171
|
+
config.description,
|
|
172
|
+
"description",
|
|
173
|
+
options,
|
|
174
|
+
scope,
|
|
175
|
+
diagnostics,
|
|
176
|
+
);
|
|
177
|
+
if (description !== undefined) next.description = description;
|
|
178
|
+
|
|
179
|
+
const promptSnippet = getOptionalNonEmptyString(
|
|
180
|
+
config.promptSnippet,
|
|
181
|
+
"promptSnippet",
|
|
182
|
+
options,
|
|
183
|
+
scope,
|
|
184
|
+
diagnostics,
|
|
185
|
+
);
|
|
186
|
+
if (promptSnippet !== undefined) next.promptSnippet = promptSnippet;
|
|
187
|
+
|
|
188
|
+
const promptGuidelines = getOptionalStringArray(
|
|
189
|
+
config.promptGuidelines,
|
|
190
|
+
"promptGuidelines",
|
|
191
|
+
options,
|
|
192
|
+
scope,
|
|
193
|
+
diagnostics,
|
|
194
|
+
);
|
|
195
|
+
if (promptGuidelines !== undefined) next.promptGuidelines = promptGuidelines;
|
|
196
|
+
|
|
197
|
+
const prepend = getOptionalStringArray(
|
|
198
|
+
config.prependPromptGuidelines,
|
|
199
|
+
"prependPromptGuidelines",
|
|
200
|
+
options,
|
|
201
|
+
scope,
|
|
202
|
+
diagnostics,
|
|
203
|
+
);
|
|
204
|
+
if (prepend !== undefined) next.promptGuidelines = [...prepend, ...next.promptGuidelines];
|
|
205
|
+
|
|
206
|
+
const append = getOptionalStringArray(
|
|
207
|
+
config.appendPromptGuidelines,
|
|
208
|
+
"appendPromptGuidelines",
|
|
209
|
+
options,
|
|
210
|
+
scope,
|
|
211
|
+
diagnostics,
|
|
212
|
+
);
|
|
213
|
+
if (append !== undefined) next.promptGuidelines = [...next.promptGuidelines, ...append];
|
|
214
|
+
|
|
215
|
+
return next;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// ── Config extraction ──────────────────────────────────────────────────────
|
|
219
|
+
|
|
220
|
+
function getPromptSurfaceConfig(
|
|
221
|
+
sectionConfig: Record<string, unknown> | null,
|
|
222
|
+
toolName: string,
|
|
223
|
+
deps: {
|
|
224
|
+
diagnostics: ToolPromptSurfaceDiagnostic[];
|
|
225
|
+
options: ResolveToolPromptSurfaceOptions;
|
|
226
|
+
scope: PromptSurfaceScope;
|
|
227
|
+
},
|
|
228
|
+
): Record<string, unknown> | null {
|
|
229
|
+
if (!sectionConfig) return null;
|
|
230
|
+
if (sectionConfig.tools === undefined) return null;
|
|
231
|
+
if (!isRecord(sectionConfig.tools)) {
|
|
232
|
+
pushInvalidConfig(deps, "tools must be an object.");
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
const toolConfig = sectionConfig.tools[toolName];
|
|
236
|
+
if (toolConfig === undefined) return null;
|
|
237
|
+
if (!isRecord(toolConfig)) {
|
|
238
|
+
pushInvalidConfig(deps, `tools.${toolName} must be an object.`);
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
if (toolConfig.promptSurface === undefined) return null;
|
|
242
|
+
if (!isRecord(toolConfig.promptSurface)) {
|
|
243
|
+
pushInvalidConfig(deps, `tools.${toolName}.promptSurface must be an object.`);
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
return toolConfig.promptSurface;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// ── Field validation ───────────────────────────────────────────────────────
|
|
250
|
+
|
|
251
|
+
function getResetFields(
|
|
252
|
+
value: unknown,
|
|
253
|
+
options: ResolveToolPromptSurfaceOptions,
|
|
254
|
+
scope: PromptSurfaceScope,
|
|
255
|
+
diagnostics: ToolPromptSurfaceDiagnostic[],
|
|
256
|
+
): PromptSurfaceField[] {
|
|
257
|
+
if (value === undefined) return [];
|
|
258
|
+
if (!Array.isArray(value)) {
|
|
259
|
+
pushInvalidField(options, scope, diagnostics, "$reset", "must be an array.");
|
|
260
|
+
return [];
|
|
261
|
+
}
|
|
262
|
+
const fields: PromptSurfaceField[] = [];
|
|
263
|
+
for (const item of value) {
|
|
264
|
+
if (typeof item === "string" && PROMPT_SURFACE_FIELDS.has(item)) {
|
|
265
|
+
fields.push(item as PromptSurfaceField);
|
|
266
|
+
} else {
|
|
267
|
+
pushInvalidField(
|
|
268
|
+
options,
|
|
269
|
+
scope,
|
|
270
|
+
diagnostics,
|
|
271
|
+
"$reset",
|
|
272
|
+
`contains unsupported field ${JSON.stringify(item)}.`,
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return fields;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// biome-ignore lint/complexity/useMaxParams: validation helper with diagnostics
|
|
280
|
+
function getOptionalNonEmptyString(
|
|
281
|
+
value: unknown,
|
|
282
|
+
field: string,
|
|
283
|
+
options: ResolveToolPromptSurfaceOptions,
|
|
284
|
+
scope: PromptSurfaceScope,
|
|
285
|
+
diagnostics: ToolPromptSurfaceDiagnostic[],
|
|
286
|
+
): string | undefined {
|
|
287
|
+
if (value === undefined) return undefined;
|
|
288
|
+
if (typeof value === "string" && value.length > 0) return value;
|
|
289
|
+
pushInvalidField(options, scope, diagnostics, field, "must be a non-empty string.");
|
|
290
|
+
return undefined;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// biome-ignore lint/complexity/useMaxParams: validation helper with diagnostics
|
|
294
|
+
function getOptionalStringArray(
|
|
295
|
+
value: unknown,
|
|
296
|
+
field: string,
|
|
297
|
+
options: ResolveToolPromptSurfaceOptions,
|
|
298
|
+
scope: PromptSurfaceScope,
|
|
299
|
+
diagnostics: ToolPromptSurfaceDiagnostic[],
|
|
300
|
+
): string[] | undefined {
|
|
301
|
+
if (value === undefined) return undefined;
|
|
302
|
+
if (Array.isArray(value) && value.every((item) => typeof item === "string")) {
|
|
303
|
+
return [...value];
|
|
304
|
+
}
|
|
305
|
+
pushInvalidField(options, scope, diagnostics, field, "must be an array of strings.");
|
|
306
|
+
return undefined;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// ── Diagnostics ────────────────────────────────────────────────────────────
|
|
310
|
+
|
|
311
|
+
function pushInvalidConfig(
|
|
312
|
+
deps: {
|
|
313
|
+
diagnostics: ToolPromptSurfaceDiagnostic[];
|
|
314
|
+
options: ResolveToolPromptSurfaceOptions;
|
|
315
|
+
scope: PromptSurfaceScope;
|
|
316
|
+
},
|
|
317
|
+
detail: string,
|
|
318
|
+
): void {
|
|
319
|
+
deps.diagnostics.push({
|
|
320
|
+
// biome-ignore lint/security/noSecrets: false positive on string constant
|
|
321
|
+
code: "invalidPromptSurfaceConfig",
|
|
322
|
+
scope: deps.scope,
|
|
323
|
+
section: deps.options.section,
|
|
324
|
+
toolName: deps.options.toolName,
|
|
325
|
+
message: `Invalid prompt-surface config for ${deps.options.section}.${deps.options.toolName}: ${detail}`,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// biome-ignore lint/complexity/useMaxParams: diagnostics utility with many fields
|
|
330
|
+
function pushInvalidField(
|
|
331
|
+
options: ResolveToolPromptSurfaceOptions,
|
|
332
|
+
scope: PromptSurfaceScope,
|
|
333
|
+
diagnostics: ToolPromptSurfaceDiagnostic[],
|
|
334
|
+
field: string,
|
|
335
|
+
detail: string,
|
|
336
|
+
): void {
|
|
337
|
+
diagnostics.push({
|
|
338
|
+
// biome-ignore lint/security/noSecrets: false positive on string constant
|
|
339
|
+
code: "invalidPromptSurfaceField",
|
|
340
|
+
scope,
|
|
341
|
+
section: options.section,
|
|
342
|
+
toolName: options.toolName,
|
|
343
|
+
message: `Invalid prompt-surface field ${field} for ${options.section}.${options.toolName}: ${detail}`,
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// ── Cloning ────────────────────────────────────────────────────────────────
|
|
348
|
+
|
|
349
|
+
function clonePromptSurface(surface: SuiPiToolPromptSurface): SuiPiToolPromptSurface {
|
|
350
|
+
return {
|
|
351
|
+
description: surface.description,
|
|
352
|
+
promptSnippet: surface.promptSnippet,
|
|
353
|
+
promptGuidelines: [...surface.promptGuidelines],
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function clonePromptSurfaceField<T extends string | string[]>(value: T): T {
|
|
358
|
+
return (Array.isArray(value) ? [...value] : value) as T;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
362
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
363
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// supi-core config domain — config loading.
|
|
2
|
+
export type { SupiConfigLocation, SupiConfigOptions } from "./config/config.ts";
|
|
3
|
+
export {
|
|
4
|
+
loadSupiConfig,
|
|
5
|
+
loadSupiConfigForScope,
|
|
6
|
+
loadSupiConfigSectionForScope,
|
|
7
|
+
readJsonFile,
|
|
8
|
+
removeSupiConfigKey,
|
|
9
|
+
writeSupiConfig,
|
|
10
|
+
} from "./config/config.ts";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Context provider registry for SuPi extensions.
|
|
2
|
+
//
|
|
3
|
+
// Extensions declare context data providers via `registerContextProvider()` during their
|
|
4
|
+
// factory function. The `/supi-context` command reads them via `getRegisteredContextProviders()`.
|
|
5
|
+
|
|
6
|
+
import { createRegistry } from "../registry-utils.ts";
|
|
7
|
+
|
|
8
|
+
export interface ContextProvider {
|
|
9
|
+
/** Unique identifier — e.g. "lsp" */
|
|
10
|
+
id: string;
|
|
11
|
+
/** Human-readable label shown in the report */
|
|
12
|
+
label: string;
|
|
13
|
+
/** Return structured data for display, or null when unavailable. */
|
|
14
|
+
getData: () => Record<string, string | number> | null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const registry = createRegistry<ContextProvider>("context-provider-registry");
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Register a context data provider for an extension.
|
|
21
|
+
* Call during the extension factory function (not async handlers).
|
|
22
|
+
* Duplicate ids replace the previous registration.
|
|
23
|
+
*/
|
|
24
|
+
export function registerContextProvider(provider: ContextProvider): void {
|
|
25
|
+
registry.register(provider.id, provider);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Get all registered context providers in registration order. */
|
|
29
|
+
export function getRegisteredContextProviders(): ContextProvider[] {
|
|
30
|
+
return registry.getAll();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Clear the registry — used by tests. */
|
|
34
|
+
export function clearRegisteredContextProviders(): void {
|
|
35
|
+
registry.clear();
|
|
36
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// XML context tag wrapping for SuPi extensions.
|
|
2
|
+
//
|
|
3
|
+
// Produces machine-parseable <extension-context> blocks that:
|
|
4
|
+
// - Are LLM-friendly (structured XML)
|
|
5
|
+
// - Carry metadata via attributes (source, file, turn, etc.)
|
|
6
|
+
// - Can be reconstructed from session history via regex
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Wrap content in an `<extension-context>` XML tag.
|
|
10
|
+
*
|
|
11
|
+
* @param source - Extension identifier (e.g. "supi-claude-md", "supi-lsp")
|
|
12
|
+
* @param content - The text content to wrap
|
|
13
|
+
* @param attrs - Optional additional attributes (rendered as key="value")
|
|
14
|
+
* @returns Formatted XML string
|
|
15
|
+
*/
|
|
16
|
+
export function wrapExtensionContext(
|
|
17
|
+
source: string,
|
|
18
|
+
content: string,
|
|
19
|
+
attrs?: Record<string, string | number>,
|
|
20
|
+
): string {
|
|
21
|
+
const attrParts = [`source="${source}"`];
|
|
22
|
+
|
|
23
|
+
if (attrs) {
|
|
24
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
25
|
+
attrParts.push(`${key}="${String(value)}"`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const openTag = `<extension-context ${attrParts.join(" ")}>`;
|
|
30
|
+
return `${openTag}\n${content}\n</extension-context>`;
|
|
31
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// supi-core context domain — context providers and XML tags.
|
|
2
|
+
export type { ContextProvider } from "./context/context-provider-registry.ts";
|
|
3
|
+
export {
|
|
4
|
+
clearRegisteredContextProviders,
|
|
5
|
+
getRegisteredContextProviders,
|
|
6
|
+
registerContextProvider,
|
|
7
|
+
} from "./context/context-provider-registry.ts";
|
|
8
|
+
export { wrapExtensionContext } from "./context/context-tag.ts";
|