@dsh-cc/skill-loader 0.5.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/LICENSE +201 -0
- package/README.i18n.yaml +6 -0
- package/README.md +75 -0
- package/README.zh.md +75 -0
- package/lib/bundled/batch.d.ts +15 -0
- package/lib/bundled/batch.d.ts.map +1 -0
- package/lib/bundled/batch.js +97 -0
- package/lib/bundled/batch.js.map +1 -0
- package/lib/bundled/debug.d.ts +14 -0
- package/lib/bundled/debug.d.ts.map +1 -0
- package/lib/bundled/debug.js +51 -0
- package/lib/bundled/debug.js.map +1 -0
- package/lib/bundled/index.d.ts +36 -0
- package/lib/bundled/index.d.ts.map +1 -0
- package/lib/bundled/index.js +47 -0
- package/lib/bundled/index.js.map +1 -0
- package/lib/bundled/simplify.d.ts +12 -0
- package/lib/bundled/simplify.d.ts.map +1 -0
- package/lib/bundled/simplify.js +67 -0
- package/lib/bundled/simplify.js.map +1 -0
- package/lib/discovery.d.ts +70 -0
- package/lib/discovery.d.ts.map +1 -0
- package/lib/discovery.js +165 -0
- package/lib/discovery.js.map +1 -0
- package/lib/frontmatter.d.ts +72 -0
- package/lib/frontmatter.d.ts.map +1 -0
- package/lib/frontmatter.js +200 -0
- package/lib/frontmatter.js.map +1 -0
- package/lib/index.d.ts +100 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +343 -0
- package/lib/index.js.map +1 -0
- package/lib/invariant.d.ts +16 -0
- package/lib/invariant.d.ts.map +1 -0
- package/lib/invariant.js +22 -0
- package/lib/invariant.js.map +1 -0
- package/lib/render.d.ts +111 -0
- package/lib/render.d.ts.map +1 -0
- package/lib/render.js +179 -0
- package/lib/render.js.map +1 -0
- package/lib/translate.d.ts +66 -0
- package/lib/translate.d.ts.map +1 -0
- package/lib/translate.js +134 -0
- package/lib/translate.js.map +1 -0
- package/lib/types.d.ts +46 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +8 -0
- package/lib/types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,UAAU,eAAe,CAAC,IAAY;IACzC,IAAI,GAAW,CAAA;IACf,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IACpC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,MAAM,QAAQ,GAAG,0BAA0B,CAAC,GAAG,CAAC,CAAA;IAChD,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IAC5C,MAAM,MAAM,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAA;IACtC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IAC1C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAA;AACxC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-owned invariant companion for `@dsh-cc/skill-loader`.
|
|
3
|
+
* @module @dsh-cc/skill-loader/invariant
|
|
4
|
+
*/
|
|
5
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
6
|
+
/** Cordis companion plugin name. */
|
|
7
|
+
export declare const name = "skill-claude-code-invariant";
|
|
8
|
+
/** Service required before the companion can reserve package ownership. */
|
|
9
|
+
export declare const inject: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Register this package's invariant companion.
|
|
12
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
13
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
14
|
+
*/
|
|
15
|
+
export declare const apply: (ctx: Context) => Promise<() => void>;
|
|
16
|
+
//# sourceMappingURL=invariant.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invariant.d.ts","sourceRoot":"","sources":["../src/invariant.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAKlD,oCAAoC;AACpC,eAAO,MAAM,IAAI,gCAAgC,CAAA;AACjD,2EAA2E;AAC3E,eAAO,MAAM,MAAM,UAAiB,CAAA;AAQpC;;;;GAIG;AACH,eAAO,MAAM,KAAK,GAAI,KAAK,OAAO,KAAG,OAAO,CAAC,MAAM,IAAI,CACU,CAAA"}
|
package/lib/invariant.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-owned invariant companion for `@dsh-cc/skill-loader`.
|
|
3
|
+
* @module @dsh-cc/skill-loader/invariant
|
|
4
|
+
*/
|
|
5
|
+
const PACKAGE_NAME = '@dsh-cc/skill-loader';
|
|
6
|
+
/** Cordis companion plugin name. */
|
|
7
|
+
export const name = 'skill-claude-code-invariant';
|
|
8
|
+
/** Service required before the companion can reserve package ownership. */
|
|
9
|
+
export const inject = ['invariants'];
|
|
10
|
+
/**
|
|
11
|
+
* No runtime invariant: discovery and loading are read-only and validated at
|
|
12
|
+
* parse time; activation semantics compose consumer-side.
|
|
13
|
+
*/
|
|
14
|
+
const install = () => { };
|
|
15
|
+
/**
|
|
16
|
+
* Register this package's invariant companion.
|
|
17
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
18
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
19
|
+
*/
|
|
20
|
+
export const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
|
|
21
|
+
/* jscpd:ignore-end */
|
|
22
|
+
//# sourceMappingURL=invariant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invariant.js","sourceRoot":"","sources":["../src/invariant.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,MAAM,YAAY,GAAG,sBAAsB,CAAA;AAE3C,oCAAoC;AACpC,MAAM,CAAC,MAAM,IAAI,GAAG,6BAA6B,CAAA;AACjD,2EAA2E;AAC3E,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,YAAY,CAAC,CAAA;AAEpC;;;GAGG;AACH,MAAM,OAAO,GAAuB,GAAG,EAAE,GAAE,CAAC,CAAA;AAE5C;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,GAAY,EAAuB,EAAE,CACzD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAA;AACjE,sBAAsB"}
|
package/lib/render.d.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill body rendering: argument interpolation, placeholder substitution, and
|
|
3
|
+
* inline-shell segmentation.
|
|
4
|
+
*
|
|
5
|
+
* Rendering is pure and side-effect free: it produces the substituted body text
|
|
6
|
+
* plus any `` !`...` `` inline-shell commands it found. Executing those commands
|
|
7
|
+
* is the caller's responsibility (guarded by `allowInlineShell`, which MCP-sourced
|
|
8
|
+
* skills must force off).
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
/** One text-or-shell segment of a rendered skill body. */
|
|
13
|
+
export type SkillRenderSegment = {
|
|
14
|
+
readonly kind: 'text';
|
|
15
|
+
readonly text: string;
|
|
16
|
+
} | {
|
|
17
|
+
readonly kind: 'shell';
|
|
18
|
+
readonly command: string;
|
|
19
|
+
};
|
|
20
|
+
/** Options controlling one `renderSkillBody` pass. */
|
|
21
|
+
export interface RenderSkillBodyOptions {
|
|
22
|
+
/** Raw arguments string, or undefined when the skill was invoked without them. */
|
|
23
|
+
readonly args?: string | undefined;
|
|
24
|
+
/** Named argument placeholders in frontmatter order. */
|
|
25
|
+
readonly argumentNames: readonly string[];
|
|
26
|
+
/** The skill's own directory, for `${CLAUDE_SKILL_DIR}`. */
|
|
27
|
+
readonly skillDir?: string;
|
|
28
|
+
/** The current session id, for `${CLAUDE_SESSION_ID}`. */
|
|
29
|
+
readonly sessionId: string;
|
|
30
|
+
/** Whether inline shell execution is permitted; MCP-sourced skills force it off. */
|
|
31
|
+
readonly allowInlineShell: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** A fully substituted body plus any inline-shell segments awaiting execution. */
|
|
34
|
+
export interface RenderedSkillBody {
|
|
35
|
+
/** Substituted text with inline-shell placeholders removed. */
|
|
36
|
+
readonly text: string;
|
|
37
|
+
/** Inline-shell commands extracted in document order. */
|
|
38
|
+
readonly inlineShell: readonly string[];
|
|
39
|
+
}
|
|
40
|
+
/** A shell-segmented body before execution. */
|
|
41
|
+
export interface SegmentedSkillBody {
|
|
42
|
+
/** Ordered text and shell segments. */
|
|
43
|
+
readonly segments: readonly SkillRenderSegment[];
|
|
44
|
+
/** Inline-shell commands in document order. */
|
|
45
|
+
readonly inlineShell: readonly string[];
|
|
46
|
+
/** Plain text after placeholder substitution, shell placeholders removed. */
|
|
47
|
+
readonly text: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Split a skill body on `` !`...` `` inline-shell markers into ordered text and
|
|
51
|
+
* shell segments. The regex is intentionally loose (anything but a backtick so
|
|
52
|
+
* embedded backticks do not break segmentation); validation of the command is
|
|
53
|
+
* the executing shell's job.
|
|
54
|
+
* @param content - body text after argument/placeholder substitution.
|
|
55
|
+
* @returns the ordered segments and their pending shell commands.
|
|
56
|
+
*/
|
|
57
|
+
export declare function segmentSkillBody(content: string): SegmentedSkillBody;
|
|
58
|
+
/**
|
|
59
|
+
* Render a skill body with argument and placeholder substitution, returning the
|
|
60
|
+
* substituted text plus extracted inline-shell commands. Inline-shell commands
|
|
61
|
+
* are never executed here.
|
|
62
|
+
* @param content - raw skill body.
|
|
63
|
+
* @param options - substitution and shell-policy inputs.
|
|
64
|
+
* @returns the substituted text and pending shell commands.
|
|
65
|
+
*/
|
|
66
|
+
export declare function renderSkillBody(content: string, options: RenderSkillBodyOptions): RenderedSkillBody;
|
|
67
|
+
/**
|
|
68
|
+
* Extract inline-shell segments from already-substituted body text.
|
|
69
|
+
* @param content - body text with arguments and placeholders already substituted.
|
|
70
|
+
* @returns the ordered segments; a single text segment when no inline shell is present.
|
|
71
|
+
*/
|
|
72
|
+
export declare function extractInlineShell(content: string): readonly SkillRenderSegment[];
|
|
73
|
+
/**
|
|
74
|
+
* Substitute `$ARGUMENTS`, `$ARGUMENTS[n]`, `$n`, and named `$name` placeholders
|
|
75
|
+
* in a skill body with positional argument values. Named arguments map to
|
|
76
|
+
* positions by frontmatter order. When `args` is undefined the content is
|
|
77
|
+
* returned unchanged; when a non-empty `args` matched no placeholder it is
|
|
78
|
+
* appended as an `ARGUMENTS:` line.
|
|
79
|
+
* @param content - body text to substitute.
|
|
80
|
+
* @param args - raw arguments string, or undefined for none.
|
|
81
|
+
* @param argumentNames - named placeholders in frontmatter order.
|
|
82
|
+
* @returns the substituted body.
|
|
83
|
+
*/
|
|
84
|
+
export declare function substituteArguments(content: string, args: string | undefined, argumentNames: readonly string[]): string;
|
|
85
|
+
/**
|
|
86
|
+
* Parse a raw arguments string into positionally indexed values, honoring
|
|
87
|
+
* single and double quotes. Shell operators and unquoted whitespace collapse;
|
|
88
|
+
* quoted spaces are preserved.
|
|
89
|
+
* @param args - raw arguments string.
|
|
90
|
+
* @returns the positional argument values.
|
|
91
|
+
*/
|
|
92
|
+
export declare function parseArguments(args: string): readonly string[];
|
|
93
|
+
/**
|
|
94
|
+
* Substitute `${CLAUDE_SKILL_DIR}` and `${CLAUDE_SESSION_ID}` placeholders.
|
|
95
|
+
* @param content - body text after argument substitution.
|
|
96
|
+
* @param skillDir - the skill's own directory, or undefined to leave the placeholder.
|
|
97
|
+
* @param sessionId - the current session id.
|
|
98
|
+
* @returns the substituted body.
|
|
99
|
+
*/
|
|
100
|
+
export declare function substitutePlaceholders(content: string, skillDir: string | undefined, sessionId: string): string;
|
|
101
|
+
/**
|
|
102
|
+
* Estimate the catalog-facing token cost of a skill from its frontmatter only:
|
|
103
|
+
* name, description, and `when_to_use`. The full body is never counted here
|
|
104
|
+
* because it is loaded only on invocation.
|
|
105
|
+
* @param name - skill name.
|
|
106
|
+
* @param description - routing description.
|
|
107
|
+
* @param whenToUse - optional routing guidance.
|
|
108
|
+
* @returns a rough token estimate over the joined frontmatter fields.
|
|
109
|
+
*/
|
|
110
|
+
export declare function estimateFrontmatterTokens(name: string, description: string, whenToUse: string | undefined): number;
|
|
111
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,0DAA0D;AAC1D,MAAM,MAAM,kBAAkB,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChD;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAA;AAExD,sDAAsD;AACtD,MAAM,WAAW,sBAAsB;IACrC,kFAAkF;IAClF,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAClC,wDAAwD;IACxD,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAA;IACzC,4DAA4D;IAC5D,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAC1B,0DAA0D;IAC1D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,oFAAoF;IACpF,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAA;CACnC;AAED,kFAAkF;AAClF,MAAM,WAAW,iBAAiB;IAChC,+DAA+D;IAC/D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,yDAAyD;IACzD,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAA;CACxC;AAED,+CAA+C;AAC/C,MAAM,WAAW,kBAAkB;IACjC,uCAAuC;IACvC,QAAQ,CAAC,QAAQ,EAAE,SAAS,kBAAkB,EAAE,CAAA;IAChD,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAA;IACvC,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB;AAID;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,CAsBpE;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB,GAAG,iBAAiB,CAInG;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,kBAAkB,EAAE,CAEjF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,aAAa,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAevH;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAoC9D;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAK/G;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAAG,SAAS,GAC5B,MAAM,CAGR"}
|
package/lib/render.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill body rendering: argument interpolation, placeholder substitution, and
|
|
3
|
+
* inline-shell segmentation.
|
|
4
|
+
*
|
|
5
|
+
* Rendering is pure and side-effect free: it produces the substituted body text
|
|
6
|
+
* plus any `` !`...` `` inline-shell commands it found. Executing those commands
|
|
7
|
+
* is the caller's responsibility (guarded by `allowInlineShell`, which MCP-sourced
|
|
8
|
+
* skills must force off).
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
const INLINE_SHELL = /!`([^`]*)`/g;
|
|
13
|
+
/**
|
|
14
|
+
* Split a skill body on `` !`...` `` inline-shell markers into ordered text and
|
|
15
|
+
* shell segments. The regex is intentionally loose (anything but a backtick so
|
|
16
|
+
* embedded backticks do not break segmentation); validation of the command is
|
|
17
|
+
* the executing shell's job.
|
|
18
|
+
* @param content - body text after argument/placeholder substitution.
|
|
19
|
+
* @returns the ordered segments and their pending shell commands.
|
|
20
|
+
*/
|
|
21
|
+
export function segmentSkillBody(content) {
|
|
22
|
+
const segments = [];
|
|
23
|
+
const inlineShell = [];
|
|
24
|
+
let lastIndex = 0;
|
|
25
|
+
let text = '';
|
|
26
|
+
for (const match of content.matchAll(INLINE_SHELL)) {
|
|
27
|
+
const index = match.index;
|
|
28
|
+
const lead = content.slice(lastIndex, index);
|
|
29
|
+
if (lead.length > 0) {
|
|
30
|
+
segments.push({ kind: 'text', text: lead });
|
|
31
|
+
text += lead;
|
|
32
|
+
}
|
|
33
|
+
const command = match[1] ?? '';
|
|
34
|
+
segments.push({ kind: 'shell', command });
|
|
35
|
+
inlineShell.push(command);
|
|
36
|
+
lastIndex = index + match[0].length;
|
|
37
|
+
}
|
|
38
|
+
if (lastIndex < content.length) {
|
|
39
|
+
segments.push({ kind: 'text', text: content.slice(lastIndex) });
|
|
40
|
+
text += content.slice(lastIndex);
|
|
41
|
+
}
|
|
42
|
+
return { segments, inlineShell, text };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Render a skill body with argument and placeholder substitution, returning the
|
|
46
|
+
* substituted text plus extracted inline-shell commands. Inline-shell commands
|
|
47
|
+
* are never executed here.
|
|
48
|
+
* @param content - raw skill body.
|
|
49
|
+
* @param options - substitution and shell-policy inputs.
|
|
50
|
+
* @returns the substituted text and pending shell commands.
|
|
51
|
+
*/
|
|
52
|
+
export function renderSkillBody(content, options) {
|
|
53
|
+
const substituted = substituteArguments(content, options.args, options.argumentNames);
|
|
54
|
+
const placed = substitutePlaceholders(substituted, options.skillDir, options.sessionId);
|
|
55
|
+
return segmentSkillBody(placed);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Extract inline-shell segments from already-substituted body text.
|
|
59
|
+
* @param content - body text with arguments and placeholders already substituted.
|
|
60
|
+
* @returns the ordered segments; a single text segment when no inline shell is present.
|
|
61
|
+
*/
|
|
62
|
+
export function extractInlineShell(content) {
|
|
63
|
+
return segmentSkillBody(content).segments;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Substitute `$ARGUMENTS`, `$ARGUMENTS[n]`, `$n`, and named `$name` placeholders
|
|
67
|
+
* in a skill body with positional argument values. Named arguments map to
|
|
68
|
+
* positions by frontmatter order. When `args` is undefined the content is
|
|
69
|
+
* returned unchanged; when a non-empty `args` matched no placeholder it is
|
|
70
|
+
* appended as an `ARGUMENTS:` line.
|
|
71
|
+
* @param content - body text to substitute.
|
|
72
|
+
* @param args - raw arguments string, or undefined for none.
|
|
73
|
+
* @param argumentNames - named placeholders in frontmatter order.
|
|
74
|
+
* @returns the substituted body.
|
|
75
|
+
*/
|
|
76
|
+
export function substituteArguments(content, args, argumentNames) {
|
|
77
|
+
if (args === undefined)
|
|
78
|
+
return content;
|
|
79
|
+
const parsed = parseArguments(args);
|
|
80
|
+
let out = content;
|
|
81
|
+
const original = content;
|
|
82
|
+
for (let i = 0; i < argumentNames.length; i++) {
|
|
83
|
+
const name = argumentNames[i];
|
|
84
|
+
if (name === undefined)
|
|
85
|
+
continue;
|
|
86
|
+
out = out.replace(new RegExp(`\\$${name}(?![\\[\\w])`, 'g'), parsed[i] ?? '');
|
|
87
|
+
}
|
|
88
|
+
out = out.replace(/\$ARGUMENTS\[(\d+)\]/g, (_, index) => parsed[Number(index)] ?? '');
|
|
89
|
+
out = out.replace(/\$(\d+)(?!\w)/g, (_, index) => parsed[Number(index)] ?? '');
|
|
90
|
+
out = out.replaceAll('$ARGUMENTS', args);
|
|
91
|
+
if (out === original && args.length > 0)
|
|
92
|
+
out = `${out}\n\nARGUMENTS: ${args}`;
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Parse a raw arguments string into positionally indexed values, honoring
|
|
97
|
+
* single and double quotes. Shell operators and unquoted whitespace collapse;
|
|
98
|
+
* quoted spaces are preserved.
|
|
99
|
+
* @param args - raw arguments string.
|
|
100
|
+
* @returns the positional argument values.
|
|
101
|
+
*/
|
|
102
|
+
export function parseArguments(args) {
|
|
103
|
+
const trimmed = args.trim();
|
|
104
|
+
if (trimmed.length === 0)
|
|
105
|
+
return [];
|
|
106
|
+
const result = [];
|
|
107
|
+
let current = '';
|
|
108
|
+
let quoted;
|
|
109
|
+
let tokenOpen = false;
|
|
110
|
+
for (let i = 0; i < trimmed.length; i++) {
|
|
111
|
+
// oxlint-disable-next-line typescript/no-non-null-assertion -- the loop bound proves the index exists.
|
|
112
|
+
const char = trimmed[i];
|
|
113
|
+
if (quoted === undefined) {
|
|
114
|
+
if (char === '"' || char === "'") {
|
|
115
|
+
quoted = char;
|
|
116
|
+
tokenOpen = true;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (/\s/.test(char)) {
|
|
120
|
+
if (tokenOpen) {
|
|
121
|
+
result.push(current);
|
|
122
|
+
current = '';
|
|
123
|
+
tokenOpen = false;
|
|
124
|
+
}
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
current += char;
|
|
128
|
+
tokenOpen = true;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (char === quoted) {
|
|
132
|
+
quoted = undefined;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
current += char;
|
|
136
|
+
}
|
|
137
|
+
if (tokenOpen)
|
|
138
|
+
result.push(current);
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Substitute `${CLAUDE_SKILL_DIR}` and `${CLAUDE_SESSION_ID}` placeholders.
|
|
143
|
+
* @param content - body text after argument substitution.
|
|
144
|
+
* @param skillDir - the skill's own directory, or undefined to leave the placeholder.
|
|
145
|
+
* @param sessionId - the current session id.
|
|
146
|
+
* @returns the substituted body.
|
|
147
|
+
*/
|
|
148
|
+
export function substitutePlaceholders(content, skillDir, sessionId) {
|
|
149
|
+
let out = content;
|
|
150
|
+
if (skillDir !== undefined)
|
|
151
|
+
out = out.replaceAll('${CLAUDE_SKILL_DIR}', skillDir);
|
|
152
|
+
out = out.replaceAll('${CLAUDE_SESSION_ID}', sessionId);
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Estimate the catalog-facing token cost of a skill from its frontmatter only:
|
|
157
|
+
* name, description, and `when_to_use`. The full body is never counted here
|
|
158
|
+
* because it is loaded only on invocation.
|
|
159
|
+
* @param name - skill name.
|
|
160
|
+
* @param description - routing description.
|
|
161
|
+
* @param whenToUse - optional routing guidance.
|
|
162
|
+
* @returns a rough token estimate over the joined frontmatter fields.
|
|
163
|
+
*/
|
|
164
|
+
export function estimateFrontmatterTokens(name, description, whenToUse) {
|
|
165
|
+
const text = [name, description, whenToUse].filter(Boolean).join(' ');
|
|
166
|
+
return roughTokenCount(text);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* A rough token estimate without a statistical model: every four code points
|
|
170
|
+
* (approximating one token per ~4 characters) plus a minimum of one.
|
|
171
|
+
* @param text - the text to estimate.
|
|
172
|
+
* @returns the estimated token count.
|
|
173
|
+
*/
|
|
174
|
+
function roughTokenCount(text) {
|
|
175
|
+
if (text.length === 0)
|
|
176
|
+
return 0;
|
|
177
|
+
return Math.max(1, Math.ceil(text.length / 4));
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"m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E,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAA;AAChD,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic translation of Claude Code skill frontmatter onto harness seams.
|
|
3
|
+
*
|
|
4
|
+
* This module turns the parsed fields into actionable harness primitives:
|
|
5
|
+
* an `allowed-tools` allow-list into a `tools.restrict()` filter, `paths` into a
|
|
6
|
+
* conditional-activation matcher wired onto `fs/observed`, and the execution
|
|
7
|
+
* controls a consumer forwards to `ctx.subagents`. Translation is pure where it
|
|
8
|
+
* can be; only path activation registers a listener.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
13
|
+
import { type ToolRestriction } from '@dsh-cc/tools';
|
|
14
|
+
/**
|
|
15
|
+
* Build an allow-only tool restriction from a Claude Code `allowed-tools` list.
|
|
16
|
+
* Names are translated leniently via {@link translateToolNames}: known CC names
|
|
17
|
+
* map to harness names (e.g. `Read` → `read` + `read_image`), names already in
|
|
18
|
+
* the harness registry pass through, and any unknown name is dropped — with a
|
|
19
|
+
* diagnostic — rather than crashing the session, because skill activation is
|
|
20
|
+
* user/model-driven. Arg-spec parens are stripped (name-level gate only), and
|
|
21
|
+
* every input dropping to nothing yields `undefined` (no restriction). A `*`
|
|
22
|
+
* entry (allow every tool) and an empty/missing list also produce `undefined`,
|
|
23
|
+
* meaning no restriction applies; the skill then inherits the caller's surface.
|
|
24
|
+
* Consumers apply the returned filter via `ctx.tools.restrict()` at activation.
|
|
25
|
+
* @param allowedTools - parsed `allowed-tools` names, or undefined when absent.
|
|
26
|
+
* @param onDiagnostic - invoked for each dropped name; defaults to a no-op.
|
|
27
|
+
* @returns an allow-only restriction, or `undefined` when nothing to restrict.
|
|
28
|
+
*/
|
|
29
|
+
export declare function ccRestriction(allowedTools: readonly string[] | undefined, onDiagnostic?: (message: string) => void): ToolRestriction | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Build a gitignore-style path matcher over Claude Code `paths` patterns.
|
|
32
|
+
* Patterns are matched against PROJECT-RELATIVE paths (the same base a
|
|
33
|
+
* `.gitignore` uses). A bare directory pattern matches that directory and
|
|
34
|
+
* everything beneath it; `**` spans any number of path segments; `*` and `?`
|
|
35
|
+
* match within one segment.
|
|
36
|
+
* @param patterns - parsed `paths` patterns.
|
|
37
|
+
* @returns a matcher returning whether a project-relative path matches.
|
|
38
|
+
*/
|
|
39
|
+
export declare function ccPathMatcher(patterns: readonly string[]): (path: string) => boolean;
|
|
40
|
+
/** One project's conditional-activation wiring. */
|
|
41
|
+
export interface PathActivationProject {
|
|
42
|
+
/** Project root whose touched files are considered. */
|
|
43
|
+
readonly root: string;
|
|
44
|
+
/** Matcher over absolute paths; true touches activate the listed skills. */
|
|
45
|
+
readonly matcher: (path: string) => boolean;
|
|
46
|
+
/** Skill names to activate when the matcher fires. */
|
|
47
|
+
readonly skillNames: readonly string[];
|
|
48
|
+
}
|
|
49
|
+
/** Options for {@link registerPathActivator}. */
|
|
50
|
+
export interface RegisterPathActivatorOptions {
|
|
51
|
+
/** Per-project matchers and the skills they activate. */
|
|
52
|
+
readonly projects: readonly PathActivationProject[];
|
|
53
|
+
/** Callback invoked with each activated skill name on a matching touch. */
|
|
54
|
+
onActivate(name: string): void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Register an `fs/observed` listener that activates path-conditional skills
|
|
58
|
+
* when a Read/Write/Edit tool touches a matching file. The listener is a
|
|
59
|
+
* synchronous recorder: it must not throw or await. Only `read`, `write`, and
|
|
60
|
+
* `edit` tool actors (identified by their `name`) trigger activation.
|
|
61
|
+
* @param ctx - active context.
|
|
62
|
+
* @param options - project matchers and the activation callback.
|
|
63
|
+
* @returns the exact disposer that removes the listener.
|
|
64
|
+
*/
|
|
65
|
+
export declare function registerPathActivator(ctx: Context, options: RegisterPathActivatorOptions): () => void;
|
|
66
|
+
//# sourceMappingURL=translate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translate.d.ts","sourceRoot":"","sources":["../src/translate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,OAAO,EAAsB,KAAK,eAAe,EAAE,MAAM,eAAe,CAAA;AAKxE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAC3B,YAAY,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EAC3C,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GACvC,eAAe,GAAG,SAAS,CAM7B;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAQpF;AAyCD,mDAAmD;AACnD,MAAM,WAAW,qBAAqB;IACpC,uDAAuD;IACvD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,4EAA4E;IAC5E,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAA;IAC3C,sDAAsD;IACtD,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAA;CACvC;AAED,iDAAiD;AACjD,MAAM,WAAW,4BAA4B;IAC3C,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,EAAE,SAAS,qBAAqB,EAAE,CAAA;IACnD,2EAA2E;IAC3E,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAC/B;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,4BAA4B,GAAG,MAAM,IAAI,CAgBrG"}
|
package/lib/translate.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Semantic translation of Claude Code skill frontmatter onto harness seams.
|
|
3
|
+
*
|
|
4
|
+
* This module turns the parsed fields into actionable harness primitives:
|
|
5
|
+
* an `allowed-tools` allow-list into a `tools.restrict()` filter, `paths` into a
|
|
6
|
+
* conditional-activation matcher wired onto `fs/observed`, and the execution
|
|
7
|
+
* controls a consumer forwards to `ctx.subagents`. Translation is pure where it
|
|
8
|
+
* can be; only path activation registers a listener.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import { relative } from 'node:path';
|
|
13
|
+
import { translateToolNames } from '@dsh-cc/tools';
|
|
14
|
+
/** Mutating first-party fs tools that should trigger path activation. */
|
|
15
|
+
const TOUCH_TOOLS = new Set(['read', 'write', 'edit']);
|
|
16
|
+
/**
|
|
17
|
+
* Build an allow-only tool restriction from a Claude Code `allowed-tools` list.
|
|
18
|
+
* Names are translated leniently via {@link translateToolNames}: known CC names
|
|
19
|
+
* map to harness names (e.g. `Read` → `read` + `read_image`), names already in
|
|
20
|
+
* the harness registry pass through, and any unknown name is dropped — with a
|
|
21
|
+
* diagnostic — rather than crashing the session, because skill activation is
|
|
22
|
+
* user/model-driven. Arg-spec parens are stripped (name-level gate only), and
|
|
23
|
+
* every input dropping to nothing yields `undefined` (no restriction). A `*`
|
|
24
|
+
* entry (allow every tool) and an empty/missing list also produce `undefined`,
|
|
25
|
+
* meaning no restriction applies; the skill then inherits the caller's surface.
|
|
26
|
+
* Consumers apply the returned filter via `ctx.tools.restrict()` at activation.
|
|
27
|
+
* @param allowedTools - parsed `allowed-tools` names, or undefined when absent.
|
|
28
|
+
* @param onDiagnostic - invoked for each dropped name; defaults to a no-op.
|
|
29
|
+
* @returns an allow-only restriction, or `undefined` when nothing to restrict.
|
|
30
|
+
*/
|
|
31
|
+
export function ccRestriction(allowedTools, onDiagnostic) {
|
|
32
|
+
if (allowedTools === undefined || allowedTools.length === 0)
|
|
33
|
+
return undefined;
|
|
34
|
+
if (allowedTools.includes('*'))
|
|
35
|
+
return undefined;
|
|
36
|
+
const translated = translateToolNames(allowedTools, 'lenient', onDiagnostic);
|
|
37
|
+
if (translated === undefined)
|
|
38
|
+
return undefined;
|
|
39
|
+
return { allow: translated };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Build a gitignore-style path matcher over Claude Code `paths` patterns.
|
|
43
|
+
* Patterns are matched against PROJECT-RELATIVE paths (the same base a
|
|
44
|
+
* `.gitignore` uses). A bare directory pattern matches that directory and
|
|
45
|
+
* everything beneath it; `**` spans any number of path segments; `*` and `?`
|
|
46
|
+
* match within one segment.
|
|
47
|
+
* @param patterns - parsed `paths` patterns.
|
|
48
|
+
* @returns a matcher returning whether a project-relative path matches.
|
|
49
|
+
*/
|
|
50
|
+
export function ccPathMatcher(patterns) {
|
|
51
|
+
const matchers = patterns
|
|
52
|
+
.map(pattern => globToRegex(pattern))
|
|
53
|
+
.filter((regex) => regex !== undefined);
|
|
54
|
+
return (path) => {
|
|
55
|
+
const normalized = path.replaceAll('\\', '/');
|
|
56
|
+
return matchers.some(regex => regex.test(normalized));
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function globToRegex(pattern) {
|
|
60
|
+
if (pattern.length === 0)
|
|
61
|
+
return undefined;
|
|
62
|
+
let out = '^';
|
|
63
|
+
let i = 0;
|
|
64
|
+
const n = pattern.length;
|
|
65
|
+
while (i < n) {
|
|
66
|
+
// oxlint-disable-next-line typescript/no-non-null-assertion -- the loop bound proves the index exists.
|
|
67
|
+
const char = pattern[i];
|
|
68
|
+
if (char === '*') {
|
|
69
|
+
if (pattern[i + 1] === '*') {
|
|
70
|
+
// `**/` matches any number of leading components (possibly none).
|
|
71
|
+
if (pattern[i + 2] === '/') {
|
|
72
|
+
out += '(?:[^/]+/)*';
|
|
73
|
+
i += 3;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
out += '.*';
|
|
77
|
+
i += 2;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
out += '[^/]*';
|
|
81
|
+
i += 1;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (char === '?') {
|
|
85
|
+
out += '[^/]';
|
|
86
|
+
i += 1;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const escaped = /[\\^$.*+?()[\]{}|]/.test(char) ? `\\${char}` : char;
|
|
90
|
+
out += escaped;
|
|
91
|
+
i += 1;
|
|
92
|
+
}
|
|
93
|
+
// A pattern naming a directory (or a file) also matches beneath it, matching
|
|
94
|
+
// the `ignore` library's "path matches everything inside" behavior.
|
|
95
|
+
out += '(?:/.*)?$';
|
|
96
|
+
return new RegExp(out);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Register an `fs/observed` listener that activates path-conditional skills
|
|
100
|
+
* when a Read/Write/Edit tool touches a matching file. The listener is a
|
|
101
|
+
* synchronous recorder: it must not throw or await. Only `read`, `write`, and
|
|
102
|
+
* `edit` tool actors (identified by their `name`) trigger activation.
|
|
103
|
+
* @param ctx - active context.
|
|
104
|
+
* @param options - project matchers and the activation callback.
|
|
105
|
+
* @returns the exact disposer that removes the listener.
|
|
106
|
+
*/
|
|
107
|
+
export function registerPathActivator(ctx, options) {
|
|
108
|
+
const normalized = options.projects.map(project => ({
|
|
109
|
+
root: project.root.replaceAll('\\', '/'),
|
|
110
|
+
matcher: project.matcher,
|
|
111
|
+
skillNames: project.skillNames,
|
|
112
|
+
}));
|
|
113
|
+
return ctx.on('fs/observed', (target, _observation, actor) => {
|
|
114
|
+
if (!touchActor(actor))
|
|
115
|
+
return;
|
|
116
|
+
const path = target.displayPath.replaceAll('\\', '/');
|
|
117
|
+
for (const project of normalized) {
|
|
118
|
+
if (!path.startsWith(project.root))
|
|
119
|
+
continue;
|
|
120
|
+
const rel = relative(project.root, target.displayPath).replaceAll('\\', '/');
|
|
121
|
+
if (!project.matcher(rel))
|
|
122
|
+
continue;
|
|
123
|
+
for (const name of project.skillNames)
|
|
124
|
+
options.onActivate(name);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function touchActor(actor) {
|
|
129
|
+
if (actor === undefined || !('name' in actor))
|
|
130
|
+
return false;
|
|
131
|
+
const value = actor.name;
|
|
132
|
+
return typeof value === 'string' && TOUCH_TOOLS.has(value);
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=translate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translate.js","sourceRoot":"","sources":["../src/translate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAGpC,OAAO,EAAE,kBAAkB,EAAwB,MAAM,eAAe,CAAA;AAExE,yEAAyE;AACzE,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAA;AAEtD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,aAAa,CAC3B,YAA2C,EAC3C,YAAwC;IAExC,IAAI,YAAY,KAAK,SAAS,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAA;IAC7E,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,SAAS,CAAA;IAChD,MAAM,UAAU,GAAG,kBAAkB,CAAC,YAAY,EAAE,SAAS,EAAE,YAAY,CAAC,CAAA;IAC5E,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IAC9C,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,CAAA;AAC9B,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,QAA2B;IACvD,MAAM,QAAQ,GAAG,QAAQ;SACtB,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;SACpC,MAAM,CAAC,CAAC,KAAK,EAAmB,EAAE,CAAC,KAAK,KAA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BAAE,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;QACjE,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,KAAyB;IAC3C,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IAC3D,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAA;IACxB,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;AAC5D,CAAC"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider metadata carried on Claude Code skill candidates and definitions.
|
|
3
|
+
* Consumers translate these into harness seams at activation time.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import type { CcSkillSource } from './discovery.ts';
|
|
8
|
+
/** Full Claude Code skill metadata surfaces on `SkillCandidate.metadata`. */
|
|
9
|
+
export interface CcSkillMetadata {
|
|
10
|
+
/** `allowed-tools` allow-list, translated to a `tools.restrict()` filter. */
|
|
11
|
+
readonly allowedTools: readonly string[];
|
|
12
|
+
/** Optional `argument-hint` usage hint. */
|
|
13
|
+
readonly argumentHint?: string;
|
|
14
|
+
/** Named `arguments` placeholders in frontmatter order. */
|
|
15
|
+
readonly arguments: readonly string[];
|
|
16
|
+
/** Optional `version`. */
|
|
17
|
+
readonly version?: string;
|
|
18
|
+
/** Resolved `model`; `inherit` is omitted (inherit the caller). */
|
|
19
|
+
readonly model?: string;
|
|
20
|
+
/** `context: fork` selects subagent execution via `ctx.subagents.start()`. */
|
|
21
|
+
readonly executionContext?: 'fork';
|
|
22
|
+
/** Optional `agent` target persona. */
|
|
23
|
+
readonly agent?: string;
|
|
24
|
+
/** Optional `effort` level or integer. */
|
|
25
|
+
readonly effort?: string;
|
|
26
|
+
/** `shell` inline-shell toggle (false forces inline shell off). */
|
|
27
|
+
readonly shell?: boolean;
|
|
28
|
+
/** Raw validated `hooks` object, preserved verbatim. */
|
|
29
|
+
readonly hooks?: unknown;
|
|
30
|
+
/** Gitignore-style `paths` for conditional activation. */
|
|
31
|
+
readonly paths?: readonly string[];
|
|
32
|
+
/** Whether this skill came from a legacy `.claude/commands/*.md` file. */
|
|
33
|
+
readonly deprecated: boolean;
|
|
34
|
+
/** Discovery source bucket (`bundled` for in-package bundled skills). */
|
|
35
|
+
readonly source: 'bundled' | CcSkillSource;
|
|
36
|
+
/** Unknown frontmatter keys, preserved for tolerant downstream consumers. */
|
|
37
|
+
readonly unknown: Readonly<Record<string, unknown>>;
|
|
38
|
+
}
|
|
39
|
+
/** Invocation policy resolved from Claude Code bool frontmatter. */
|
|
40
|
+
export interface CcInvocationPolicy {
|
|
41
|
+
/** Whether the skill appears in model-facing catalogs. */
|
|
42
|
+
readonly modelInvocable: boolean;
|
|
43
|
+
/** Whether a human may invoke the skill directly. */
|
|
44
|
+
readonly userInvocable: boolean;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD,6EAA6E;AAC7E,MAAM,WAAW,eAAe;IAC9B,6EAA6E;IAC7E,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAA;IACxC,2CAA2C;IAC3C,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;IAC9B,2DAA2D;IAC3D,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAA;IACrC,0BAA0B;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,mEAAmE;IACnE,QAAQ,CAAC,KAAK,CAAC,EAAE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