@unieai/rabi-skill 0.0.0-stage → 0.2.2-rc.5

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.
@@ -0,0 +1,298 @@
1
+ /**
2
+ * Agent skill provider registry.
3
+ *
4
+ * This package owns the Service Definition role of the skill capability seam.
5
+ * Concrete
6
+ * providers such as `@unieai/rabi-skill-filesystem` decide where skills come
7
+ * from; this service only merges provider catalogs, resolves the winning skill
8
+ * for a name, and exposes the winning summaries and definitions to consumers.
9
+ *
10
+ * @module @unieai/rabi-skill
11
+ */
12
+ import { Context, Service } from '@unieai/cordis';
13
+ import type { ScopeKey } from '@unieai/rabi-scope';
14
+ import type Schema from '@unieai/schemastery';
15
+ /** Standard precedence rank for packaged skill providers and local bundled roots. */
16
+ export declare const BUNDLED_SKILL_RANK = 600;
17
+ /**
18
+ * Return whether a string is a valid kebab-case skill name.
19
+ * @param name - candidate skill name to validate.
20
+ * @returns whether the name matches the public skill-name grammar.
21
+ */
22
+ export declare function isSkillName(name: string): boolean;
23
+ /** Origin bucket for a skill contribution. The value is prompt-visible metadata, not precedence by itself. */
24
+ export type SkillSource = 'project-rabi' | 'project-agents' | 'runtime' | 'user-rabi' | 'user-agents' | 'custom' | 'bundled' | (string & {});
25
+ /** Optional provider-specific base used by loaded skill bodies to resolve relative resources. */
26
+ export type SkillResourceBase = {
27
+ readonly kind: 'directory';
28
+ readonly path: string;
29
+ } | {
30
+ readonly kind: 'url';
31
+ readonly url: string;
32
+ } | {
33
+ readonly kind: 'opaque';
34
+ readonly description: string;
35
+ };
36
+ /** Invocation controls shared by skill discovery consumers. */
37
+ export interface SkillInvocationPolicy {
38
+ /** Whether model-facing catalogs and loaders include this skill. */
39
+ readonly modelInvocable: boolean;
40
+ /** Whether human-facing command catalogs and loaders include this skill. */
41
+ readonly userInvocable: boolean;
42
+ }
43
+ /** Invocation-neutral skill metadata returned by `ctx.skills.list()`. */
44
+ export interface SkillSummary {
45
+ /** Absolute instruction file path when supplied by the provider; absent for virtual skills. */
46
+ readonly path?: string;
47
+ /** Kebab-case identifier used to address the skill. */
48
+ readonly name: string;
49
+ /** Short routing description shown by discovery consumers. */
50
+ readonly description: string;
51
+ /** Optional extra routing guidance. */
52
+ readonly whenToUse?: string;
53
+ /** Resolved model and user invocation controls. */
54
+ readonly invocation: SkillInvocationPolicy;
55
+ /** Discovery source that produced this winning skill. */
56
+ readonly source: SkillSource;
57
+ /** Provider that owns this skill body. */
58
+ readonly provider: string;
59
+ /** Provider-specific base for relative resources. */
60
+ readonly resourceBase?: SkillResourceBase;
61
+ }
62
+ /** Provider catalog entry used by the registry to merge and later load skills. */
63
+ export interface SkillCandidate extends SkillSummary {
64
+ /** Lower ranks win duplicate skill names before provider registration order is considered. */
65
+ readonly rank: number;
66
+ /** Opaque provider-owned handle passed back to `provider.get()`. */
67
+ readonly locator: unknown;
68
+ /** Parsed optional metadata object from provider-specific skill frontmatter. */
69
+ readonly metadata?: Readonly<Record<string, unknown>>;
70
+ }
71
+ /** Complete parsed skill definition, including the body loaded by `ctx.skills.get()`. */
72
+ export interface SkillDefinition extends SkillSummary {
73
+ /** Markdown instruction body after any provider-specific metadata removal. */
74
+ readonly content: string;
75
+ /** Parsed optional metadata object from frontmatter. */
76
+ readonly metadata?: Readonly<Record<string, unknown>>;
77
+ }
78
+ /** Runtime skill contribution accepted by `ctx.skills.register()`. */
79
+ export type SkillRegistration = Omit<SkillDefinition, 'invocation' | 'provider'> & {
80
+ /** Invocation controls; omission permits both model and user surfaces. */
81
+ readonly invocation?: SkillInvocationPolicy;
82
+ /** Provider label; omission uses the registry-owned runtime provider. */
83
+ readonly provider?: string;
84
+ };
85
+ /** Caller context used for cwd-sensitive and abortable provider work. */
86
+ export interface SkillLookupOptions {
87
+ /** Workspace selector for the current lookup. */
88
+ readonly cwd?: string | undefined;
89
+ /** Abort discovery or loading work for the current caller. */
90
+ readonly signal?: AbortSignal | undefined;
91
+ }
92
+ /**
93
+ * Registry read options: provider lookup context plus the viewing scope.
94
+ * The registry consumes `scope` to select layers; providers receive the same
95
+ * borrowed options object and read only their {@link SkillLookupOptions}
96
+ * contract from it.
97
+ */
98
+ export interface SkillViewOptions extends SkillLookupOptions {
99
+ /** Viewing scope (the calling agent); omitted reads the global layer alone. */
100
+ readonly scope?: ScopeKey | undefined;
101
+ }
102
+ /**
103
+ * Return whether a skill may be advertised to and loaded by a model.
104
+ * @param skill - skill metadata carrying resolved invocation controls.
105
+ * @returns whether the policy permits model invocation.
106
+ */
107
+ export declare function isModelInvocable(skill: Pick<SkillSummary, 'invocation'>): boolean;
108
+ /**
109
+ * Return whether a skill may be advertised to and loaded by a human-facing command.
110
+ * @param skill - skill metadata carrying resolved invocation controls.
111
+ * @returns whether the policy permits user invocation.
112
+ */
113
+ export declare function isUserInvocable(skill: Pick<SkillSummary, 'invocation'>): boolean;
114
+ /**
115
+ * Durable source for the context message a user-explicit skill invocation
116
+ * injects: the user's own words ride a plain user message, and the rendered
117
+ * skill body follows as injected `instructions`-form context carrying this
118
+ * source, so transcript consumers present the injection from metadata
119
+ * instead of re-parsing the model-facing text.
120
+ */
121
+ export interface SkillInvocationSource {
122
+ readonly kind: 'skill-invocation';
123
+ /** Invoked skill name, validated user-invocable at the injecting boundary. */
124
+ readonly name: string;
125
+ /** Injected skill bodies are instructions for the model to follow. */
126
+ readonly form: 'instructions';
127
+ }
128
+ declare module '@unieai/rabi-llm' {
129
+ interface MessageSourceMap {
130
+ /** A user-explicit skill invocation injected by the host. */
131
+ 'skill-invocation': SkillInvocationSource;
132
+ }
133
+ }
134
+ /**
135
+ * Render one loaded skill for the model. The output is shared verbatim by the
136
+ * `skill` tool result and the user-explicit invocation injection, so the model
137
+ * sees one canonical `<skill_content>` shape on both paths. The name rides an
138
+ * escaped attribute; the body is embedded verbatim (skills are trusted local
139
+ * content, and user-supplied invocation text stays outside this wrapper).
140
+ * @param skill - name, provider, optional resource base, and body to render.
141
+ * @returns the complete model-facing `<skill_content>` block.
142
+ */
143
+ export declare function renderSkillContent(skill: Pick<SkillDefinition, 'name' | 'provider' | 'resourceBase' | 'content'>): string;
144
+ /**
145
+ * Escape model-facing prose embedded inside skill markup so provider-supplied
146
+ * text cannot open or close framing tags.
147
+ * @param value - raw prose to embed.
148
+ * @returns the escaped text.
149
+ */
150
+ export declare function escapeText(value: string): string;
151
+ /** One catalog observation plus whether discovery completed within a stable catalog revision. */
152
+ export interface SkillCatalogSnapshot {
153
+ /** Sorted invocation-neutral summaries collected in this observation. */
154
+ readonly skills: SkillSummary[];
155
+ /** Whether every registered provider completed without a concurrent catalog revision. */
156
+ readonly complete: boolean;
157
+ }
158
+ /** Provider candidates plus whether the current discovery is authoritative. */
159
+ export interface SkillProviderObservation {
160
+ /** Candidates available from the current provider discovery. */
161
+ readonly candidates: readonly SkillCandidate[];
162
+ /** Whether discovery completed and these candidates may be cached. */
163
+ readonly complete: boolean;
164
+ }
165
+ /** Provider interface for one source of skills, such as local directories or a remote registry. */
166
+ export interface SkillProvider {
167
+ /** Unique provider name in the `ctx.skills` registry. */
168
+ readonly name: string;
169
+ /**
170
+ * List available skill candidates for the current lookup context. Provider
171
+ * plugins register synchronously during `apply()`; remote initialization,
172
+ * authentication, and discovery are awaited inside this method. Implementations
173
+ * should settle promptly when `options.signal` aborts.
174
+ * @param options - lookup options; `cwd` selects workspace-sensitive skills and `signal` cancels work.
175
+ * @returns provider candidates as a complete-array shorthand, or an explicit
176
+ * observation when usable candidates came from incomplete discovery.
177
+ */
178
+ readonly list: (options: SkillLookupOptions) => Promise<readonly SkillCandidate[] | SkillProviderObservation>;
179
+ /**
180
+ * Load a complete skill body for a previously listed candidate.
181
+ * @param candidate - the winning candidate originally returned by this provider.
182
+ * @param options - lookup options; `cwd` selects workspace-sensitive skills and `signal` cancels work.
183
+ * @returns the full skill body, or `undefined` if it is no longer loadable.
184
+ */
185
+ readonly get: (candidate: SkillCandidate, options: SkillLookupOptions) => Promise<SkillDefinition | undefined>;
186
+ }
187
+ /** Registration-scoped lifecycle and invalidation capability borrowed by one provider. */
188
+ export interface SkillProviderControl {
189
+ /** Aborts if registration fails or when the exact provider registration is disposed. */
190
+ readonly signal: AbortSignal;
191
+ /** Invalidate completed catalogs and notify consumers only while the exact registration remains active. */
192
+ readonly invalidate: () => void;
193
+ }
194
+ /** Skill registry configuration. */
195
+ export interface Config {
196
+ /** Maximum number of completed cwd/provider catalogs kept in memory. */
197
+ readonly collectCacheMaxEntries?: number;
198
+ }
199
+ declare module '@unieai/cordis' {
200
+ interface Context {
201
+ skills: SkillRegistry;
202
+ }
203
+ interface Events {
204
+ /**
205
+ * A skill provider, runtime contribution, or provider-backed catalog may
206
+ * have changed. This is an unfiltered invalidation notification; consumers
207
+ * refetch the catalog for their own lookup options. Listener failures are
208
+ * contained and cannot veto the registry mutation.
209
+ * @mode emit
210
+ */
211
+ 'skills/change'(): void;
212
+ }
213
+ }
214
+ /**
215
+ * Layered registry of skill providers, the host+per-scope shape the tools
216
+ * registry established. A registration files into the layer of its calling
217
+ * context's scope ({@link scopeOf}): host rows and repository plugins land in
218
+ * the global layer, while a plugin mounted by an agent preset's standing
219
+ * composition lands in that preset's layer. A read merges the global layer
220
+ * with the viewing scope's chain — the nearest layer's entry wins a duplicate
221
+ * name outright, and the rank order decides duplicates only within one layer.
222
+ * It exposes sorted invocation-neutral summaries and loads full skill bodies
223
+ * on demand.
224
+ */
225
+ export declare class SkillRegistry extends Service {
226
+ static Config: Schema<Config>;
227
+ private readonly collectCacheMaxEntries;
228
+ private readonly layers;
229
+ private readonly collectCache;
230
+ private revision;
231
+ private nextProviderOrder;
232
+ /** Stable identities for cache keys; scope keys are opaque identity-compared objects. */
233
+ private readonly scopeIds;
234
+ private nextScopeId;
235
+ constructor(ctx: Context, config?: Config);
236
+ /**
237
+ * Register a borrowed same-process provider synchronously during plugin
238
+ * apply, into the calling context's layer: a scoped context (an agent
239
+ * preset's standing mount) registers for that scope alone, an unscoped
240
+ * context registers globally. Duplicate names within one layer and reserved
241
+ * names throw; remote initialization belongs in `list()`. Fiber disposal
242
+ * unregisters the provider and invalidates catalog caches.
243
+ * @param create - synchronous factory receiving this registration's lifecycle and invalidation control.
244
+ * @returns the exact Cordis effect disposer that unregisters this provider;
245
+ * composite effects may yield it directly to preserve teardown ordering.
246
+ */
247
+ registerProvider(create: (control: SkillProviderControl) => SkillProvider): () => void;
248
+ /**
249
+ * Register a borrowed readonly runtime skill into the calling context's
250
+ * layer. Project entries outrank runtime entries, which outrank user
251
+ * entries, within one layer. Same-name runtime entries in one layer are
252
+ * first-wins; a duplicate logs a warning and receives a no-op disposer so
253
+ * it cannot remove the winner.
254
+ * @param skill - the skill definition input; omitted invocation and provider fields receive defaults.
255
+ * @returns the exact Cordis effect disposer, preserving composite teardown order and invalidating caches.
256
+ */
257
+ register(skill: SkillRegistration): () => void;
258
+ /**
259
+ * List invocation-neutral skill summaries for a workspace. Consumers apply
260
+ * model or user invocation policy at their operational boundary. Lookup
261
+ * options and provider candidates are readonly same-process values borrowed
262
+ * throughout discovery.
263
+ * @param options - view options; `scope` selects the viewing agent's layers, `cwd` selects project roots, and `signal` cancels discovery.
264
+ * @returns all sorted winning summaries.
265
+ */
266
+ list(options?: SkillViewOptions): Promise<SkillSummary[]>;
267
+ /**
268
+ * Observe the current invocation-neutral catalog and whether discovery completed within a stable revision.
269
+ * Incomplete observations are never cached, allowing consumers to retain last-good state and
270
+ * retry on their next request boundary.
271
+ * @param options - view options; `scope` selects the viewing agent's layers, `cwd` selects project roots, and `signal` cancels discovery.
272
+ * @returns sorted summaries plus discovery-completeness state.
273
+ */
274
+ snapshot(options?: SkillViewOptions): Promise<SkillCatalogSnapshot>;
275
+ /**
276
+ * Load and validate the winning candidate, passing its opaque discovery locator back to the
277
+ * provider. Cancellation is rechecked after selection, including cache hits, and raced against
278
+ * loading so an uncooperative provider cannot hang the caller.
279
+ * @param name - kebab-case skill name.
280
+ * @param options - view options; `scope` selects the viewing agent's layers,
281
+ * `cwd` selects workspace-sensitive skills, and `signal` cancels work.
282
+ * @returns the full skill, including body content, or `undefined`.
283
+ */
284
+ get(name: string, options?: SkillViewOptions): Promise<SkillDefinition | undefined>;
285
+ private collect;
286
+ private collectFresh;
287
+ private collectLayer;
288
+ private listLayerCandidates;
289
+ private invalidateCache;
290
+ /** Invalidate after a stale definition load, only while the exact registration that produced the entry is still live. */
291
+ private invalidateEntry;
292
+ private scopeId;
293
+ private collectCacheKey;
294
+ /** Notify catalog observers without making their refresh work load-bearing. */
295
+ private notifyChange;
296
+ }
297
+ export default SkillRegistry;
298
+ //# sourceMappingURL=index.d.ts.map
package/locale/de.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Geschicklichkeit",
4
+ "description": "Fassen Sie Fähigkeiten aus verschiedenen Quellen zusammen, damit die KI sie abfragen und verwenden kann."
5
+ }
6
+ }
package/locale/en.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "meta": {
3
+ "title": "skill"
4
+ }
5
+ }
package/locale/es.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "habilidad",
4
+ "description": "Agregue habilidades de diferentes fuentes para que la IA las consulte y utilice."
5
+ }
6
+ }
package/locale/fr.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "compétence",
4
+ "description": "Regroupez les compétences de différentes sources pour que l’IA puisse les interroger et les utiliser."
5
+ }
6
+ }
package/locale/ja.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "スキル登録サービス",
4
+ "description": "異なる提供元のスキルを集約し、AI が検索、利用できるようにします。"
5
+ }
6
+ }
package/locale/pt.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "habilidade",
4
+ "description": "Agregue habilidades de diferentes fontes para a IA consultar e usar."
5
+ }
6
+ }
package/locale/ru.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "умение",
4
+ "description": "Объединяйте навыки из разных источников, чтобы ИИ мог их запрашивать и использовать."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "技能注册服务",
4
+ "description": "汇总不同来源的技能,供 AI 查询和使用。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,39 @@
1
1
  {
2
2
  "name": "@unieai/rabi-skill",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "description": "Agent skill provider registry for the Rabi Harness",
4
+ "version": "0.2.2-rc.5",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "type": "module",
9
+ "main": "lib/index.js",
10
+ "types": "lib/types/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./lib/types/index.d.ts",
14
+ "default": "./lib/index.js"
15
+ },
16
+ "./src/*": "./src/*",
17
+ "./package.json": "./package.json",
18
+ "./locale/*.json": "./locale/*.json"
19
+ },
20
+ "files": [
21
+ "locale/*.json",
22
+ "lib/index.js",
23
+ "lib/types/**/*.d.ts",
24
+ "lib/types/**/*.d.ts.map",
25
+ "lib/**/*.js.map",
26
+ "src",
27
+ "README.md"
28
+ ],
29
+ "license": "MIT",
30
+ "peerDependencies": {
31
+ "@unieai/cordis": "4.1.0",
32
+ "@unieai/rabi-llm": "0.2.2-rc.5",
33
+ "@unieai/rabi-scope": "0.2.2-rc.5"
34
+ },
35
+ "dependencies": {
36
+ "@unieai/rabi-util-values": "0.2.2-rc.5",
37
+ "@unieai/schemastery": "3.19.0"
38
+ }
39
+ }