@kirkchinese/harness-forge 0.0.0-stage → 0.4.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.
Files changed (246) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +42 -2
  3. package/assets/icon.svg +12 -0
  4. package/cordis.patch.yml +28 -0
  5. package/lib/agents/presets.d.ts +91 -0
  6. package/lib/agents/presets.js +282 -0
  7. package/lib/agents/profiles.d.ts +58 -0
  8. package/lib/agents/profiles.js +278 -0
  9. package/lib/agents/row.d.ts +17 -0
  10. package/lib/agents/row.js +146 -0
  11. package/lib/client/styles.d.ts +8 -0
  12. package/lib/client/styles.js +89 -0
  13. package/lib/client/typert.d.ts +14 -0
  14. package/lib/client/typert.js +110 -0
  15. package/lib/client.js +22500 -0
  16. package/lib/commands/definition.d.ts +40 -0
  17. package/lib/commands/definition.js +113 -0
  18. package/lib/commands/output-styles.d.ts +42 -0
  19. package/lib/commands/output-styles.js +152 -0
  20. package/lib/commands/row.d.ts +9 -0
  21. package/lib/commands/row.js +157 -0
  22. package/lib/context/instructions.d.ts +32 -0
  23. package/lib/context/instructions.js +88 -0
  24. package/lib/context/row.d.ts +16 -0
  25. package/lib/context/row.js +17 -0
  26. package/lib/dsh/commands.d.ts +30 -0
  27. package/lib/dsh/commands.js +61 -0
  28. package/lib/dsh/host.d.ts +107 -0
  29. package/lib/dsh/host.js +214 -0
  30. package/lib/dsh/model-route.d.ts +21 -0
  31. package/lib/dsh/model-route.js +37 -0
  32. package/lib/dsh/session-records.d.ts +78 -0
  33. package/lib/dsh/session-records.js +36 -0
  34. package/lib/dsh/subagents.d.ts +46 -0
  35. package/lib/dsh/subagents.js +14 -0
  36. package/lib/forge/contract.d.ts +231 -0
  37. package/lib/forge/contract.js +43 -0
  38. package/lib/forge/ledger.d.ts +143 -0
  39. package/lib/forge/ledger.js +733 -0
  40. package/lib/forge/live-mounts.d.ts +45 -0
  41. package/lib/forge/live-mounts.js +78 -0
  42. package/lib/forge/marketplace-install.d.ts +3 -0
  43. package/lib/forge/marketplace-install.js +64 -0
  44. package/lib/forge/npm.d.ts +31 -0
  45. package/lib/forge/npm.js +60 -0
  46. package/lib/forge/projects.d.ts +94 -0
  47. package/lib/forge/projects.js +336 -0
  48. package/lib/forge/receipts.d.ts +5 -0
  49. package/lib/forge/receipts.js +31 -0
  50. package/lib/forge/row.d.ts +32 -0
  51. package/lib/forge/row.js +59 -0
  52. package/lib/forge/service.d.ts +105 -0
  53. package/lib/forge/service.js +274 -0
  54. package/lib/forge/settings.d.ts +41 -0
  55. package/lib/forge/settings.js +115 -0
  56. package/lib/forge/state.d.ts +69 -0
  57. package/lib/forge/state.js +150 -0
  58. package/lib/forge/trust.d.ts +48 -0
  59. package/lib/forge/trust.js +107 -0
  60. package/lib/forge/turns.d.ts +13 -0
  61. package/lib/forge/turns.js +56 -0
  62. package/lib/hooks/broker/engine.d.ts +112 -0
  63. package/lib/hooks/broker/engine.js +728 -0
  64. package/lib/hooks/broker/helpers.d.ts +10 -0
  65. package/lib/hooks/broker/helpers.js +22 -0
  66. package/lib/hooks/broker/lifecycle.d.ts +65 -0
  67. package/lib/hooks/broker/lifecycle.js +342 -0
  68. package/lib/hooks/broker/session-events.d.ts +22 -0
  69. package/lib/hooks/broker/session-events.js +196 -0
  70. package/lib/hooks/broker/tools.d.ts +52 -0
  71. package/lib/hooks/broker/tools.js +424 -0
  72. package/lib/hooks/broker/types.d.ts +262 -0
  73. package/lib/hooks/broker/types.js +1 -0
  74. package/lib/hooks/broker.d.ts +80 -0
  75. package/lib/hooks/broker.js +95 -0
  76. package/lib/hooks/codex-user.d.ts +5 -0
  77. package/lib/hooks/codex-user.js +109 -0
  78. package/lib/hooks/condition.d.ts +11 -0
  79. package/lib/hooks/condition.js +181 -0
  80. package/lib/hooks/config.d.ts +85 -0
  81. package/lib/hooks/config.js +150 -0
  82. package/lib/hooks/matcher.d.ts +20 -0
  83. package/lib/hooks/matcher.js +39 -0
  84. package/lib/hooks/notice.d.ts +17 -0
  85. package/lib/hooks/notice.js +39 -0
  86. package/lib/hooks/output.d.ts +56 -0
  87. package/lib/hooks/output.js +214 -0
  88. package/lib/hooks/permissions.d.ts +14 -0
  89. package/lib/hooks/permissions.js +109 -0
  90. package/lib/hooks/process.d.ts +47 -0
  91. package/lib/hooks/process.js +134 -0
  92. package/lib/hooks/row.d.ts +17 -0
  93. package/lib/hooks/row.js +94 -0
  94. package/lib/hooks/runner.d.ts +85 -0
  95. package/lib/hooks/runner.js +293 -0
  96. package/lib/hooks/shell-commands.d.ts +19 -0
  97. package/lib/hooks/shell-commands.js +177 -0
  98. package/lib/hooks/shell.d.ts +43 -0
  99. package/lib/hooks/shell.js +126 -0
  100. package/lib/hooks/transcript.d.ts +28 -0
  101. package/lib/hooks/transcript.js +141 -0
  102. package/lib/hooks/vocabulary.d.ts +57 -0
  103. package/lib/hooks/vocabulary.js +364 -0
  104. package/lib/index.d.ts +31 -0
  105. package/lib/index.js +287 -0
  106. package/lib/mcp/auth.d.ts +35 -0
  107. package/lib/mcp/auth.js +178 -0
  108. package/lib/mcp/catalog.d.ts +36 -0
  109. package/lib/mcp/catalog.js +61 -0
  110. package/lib/mcp/mount.d.ts +75 -0
  111. package/lib/mcp/mount.js +217 -0
  112. package/lib/mcp/remote.d.ts +45 -0
  113. package/lib/mcp/remote.js +143 -0
  114. package/lib/mcp/row.d.ts +9 -0
  115. package/lib/mcp/row.js +131 -0
  116. package/lib/mods/bundler.d.ts +38 -0
  117. package/lib/mods/bundler.js +157 -0
  118. package/lib/mods/chain.d.ts +103 -0
  119. package/lib/mods/chain.js +436 -0
  120. package/lib/mods/claude.d.ts +27 -0
  121. package/lib/mods/claude.js +56 -0
  122. package/lib/mods/engine.d.ts +160 -0
  123. package/lib/mods/engine.js +701 -0
  124. package/lib/mods/expect.d.ts +8 -0
  125. package/lib/mods/expect.js +248 -0
  126. package/lib/mods/host.d.ts +105 -0
  127. package/lib/mods/host.js +462 -0
  128. package/lib/mods/loader.d.ts +53 -0
  129. package/lib/mods/loader.js +227 -0
  130. package/lib/mods/ops.d.ts +13 -0
  131. package/lib/mods/ops.js +117 -0
  132. package/lib/mods/row.d.ts +9 -0
  133. package/lib/mods/row.js +77 -0
  134. package/lib/mods/runtime.d.ts +60 -0
  135. package/lib/mods/runtime.js +133 -0
  136. package/lib/mods/service/commands.d.ts +17 -0
  137. package/lib/mods/service/commands.js +121 -0
  138. package/lib/mods/service/drawings.d.ts +36 -0
  139. package/lib/mods/service/drawings.js +64 -0
  140. package/lib/mods/service/sessions.d.ts +63 -0
  141. package/lib/mods/service/sessions.js +345 -0
  142. package/lib/mods/service/tools.d.ts +32 -0
  143. package/lib/mods/service/tools.js +253 -0
  144. package/lib/mods/service/turns.d.ts +32 -0
  145. package/lib/mods/service/turns.js +161 -0
  146. package/lib/mods/service/types.d.ts +151 -0
  147. package/lib/mods/service/types.js +1 -0
  148. package/lib/mods/service.d.ts +72 -0
  149. package/lib/mods/service.js +104 -0
  150. package/lib/mods/surfaces.d.ts +93 -0
  151. package/lib/mods/surfaces.js +309 -0
  152. package/lib/mods/values.d.ts +30 -0
  153. package/lib/mods/values.js +95 -0
  154. package/lib/opencode/bun.d.ts +40 -0
  155. package/lib/opencode/bun.js +156 -0
  156. package/lib/opencode/convert.d.ts +53 -0
  157. package/lib/opencode/convert.js +255 -0
  158. package/lib/opencode/row.d.ts +9 -0
  159. package/lib/opencode/row.js +86 -0
  160. package/lib/opencode/runtime/core.d.ts +74 -0
  161. package/lib/opencode/runtime/core.js +249 -0
  162. package/lib/opencode/runtime/events.d.ts +80 -0
  163. package/lib/opencode/runtime/events.js +281 -0
  164. package/lib/opencode/runtime/mount.d.ts +27 -0
  165. package/lib/opencode/runtime/mount.js +283 -0
  166. package/lib/opencode/runtime/server.d.ts +27 -0
  167. package/lib/opencode/runtime/server.js +353 -0
  168. package/lib/opencode/runtime/types.d.ts +109 -0
  169. package/lib/opencode/runtime/types.js +1 -0
  170. package/lib/opencode/runtime.d.ts +55 -0
  171. package/lib/opencode/runtime.js +79 -0
  172. package/lib/porting/port-gap.d.ts +30 -0
  173. package/lib/porting/port-gap.js +122 -0
  174. package/lib/porting/port-sessions.d.ts +41 -0
  175. package/lib/porting/port-sessions.js +98 -0
  176. package/lib/porting/prompt.d.ts +23 -0
  177. package/lib/porting/prompt.js +49 -0
  178. package/lib/porting/row.d.ts +16 -0
  179. package/lib/porting/row.js +25 -0
  180. package/lib/porting/verify-port.d.ts +53 -0
  181. package/lib/porting/verify-port.js +104 -0
  182. package/lib/presets/fs-search.d.ts +25 -0
  183. package/lib/presets/fs-search.js +17 -0
  184. package/lib/presets/tool-filter.d.ts +35 -0
  185. package/lib/presets/tool-filter.js +91 -0
  186. package/lib/sessions/claude.d.ts +29 -0
  187. package/lib/sessions/claude.js +83 -0
  188. package/lib/sessions/codex.d.ts +30 -0
  189. package/lib/sessions/codex.js +303 -0
  190. package/lib/sessions/opencode.d.ts +32 -0
  191. package/lib/sessions/opencode.js +320 -0
  192. package/lib/sessions/row.d.ts +14 -0
  193. package/lib/sessions/row.js +35 -0
  194. package/lib/shared/invocation.d.ts +169 -0
  195. package/lib/shared/invocation.js +325 -0
  196. package/lib/shared/render.d.ts +72 -0
  197. package/lib/shared/render.js +588 -0
  198. package/lib/shared/util.d.ts +21 -0
  199. package/lib/shared/util.js +32 -0
  200. package/lib/skills/bundled.d.ts +3 -0
  201. package/lib/skills/bundled.js +42 -0
  202. package/lib/skills/provider.d.ts +72 -0
  203. package/lib/skills/provider.js +340 -0
  204. package/lib/skills/row.d.ts +22 -0
  205. package/lib/skills/row.js +204 -0
  206. package/lib/workbench/adapter-coverage.d.ts +47 -0
  207. package/lib/workbench/adapter-coverage.js +102 -0
  208. package/lib/workbench/model-tools.d.ts +10 -0
  209. package/lib/workbench/model-tools.js +122 -0
  210. package/lib/workbench/overview.d.ts +103 -0
  211. package/lib/workbench/overview.js +159 -0
  212. package/lib/workbench/remote.d.ts +118 -0
  213. package/lib/workbench/remote.js +422 -0
  214. package/lib/workbench/row.d.ts +15 -0
  215. package/lib/workbench/row.js +16 -0
  216. package/lib/workbench/settings.d.ts +15 -0
  217. package/lib/workbench/settings.js +56 -0
  218. package/lib/workbench/workbench.d.ts +100 -0
  219. package/lib/workbench/workbench.js +260 -0
  220. package/locale/agents/en.json +6 -0
  221. package/locale/agents/zh.json +6 -0
  222. package/locale/commands/en.json +6 -0
  223. package/locale/commands/zh.json +6 -0
  224. package/locale/context/en.json +6 -0
  225. package/locale/context/zh.json +6 -0
  226. package/locale/en.json +6 -0
  227. package/locale/hooks/en.json +6 -0
  228. package/locale/hooks/zh.json +6 -0
  229. package/locale/mcp/en.json +6 -0
  230. package/locale/mcp/zh.json +6 -0
  231. package/locale/mods/en.json +6 -0
  232. package/locale/mods/zh.json +6 -0
  233. package/locale/opencode/en.json +6 -0
  234. package/locale/opencode/zh.json +6 -0
  235. package/locale/porter/en.json +6 -0
  236. package/locale/porter/zh.json +6 -0
  237. package/locale/sessions/en.json +6 -0
  238. package/locale/sessions/zh.json +6 -0
  239. package/locale/skills/en.json +6 -0
  240. package/locale/skills/zh.json +6 -0
  241. package/locale/workbench/en.json +6 -0
  242. package/locale/workbench/zh.json +6 -0
  243. package/locale/zh.json +6 -0
  244. package/package.json +246 -3
  245. package/runtime/opencode-host.mjs +270 -0
  246. package/skills/harness-forge/SKILL.md +47 -0
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Bundle the Harness Forge skills with the plugin so the workbench is
3
+ * available in every installed profile.
4
+ * @module @kirkchinese/harness-forge
5
+ */
6
+ import { readdirSync } from 'node:fs';
7
+ import { join } from 'node:path';
8
+ import { fileURLToPath } from 'node:url';
9
+ import { parseSkillFrontmatter, readMarkdownAsset, } from '@kirkchinese/harness-forge-core';
10
+ /** Register every `skills/<name>/SKILL.md` bundled with this package. */
11
+ export function registerBundledSkills(ctx) {
12
+ const root = fileURLToPath(new URL('../../skills', import.meta.url));
13
+ let names;
14
+ try {
15
+ names = readdirSync(root, { withFileTypes: true }).filter(entry => entry.isDirectory()).map(entry => entry.name);
16
+ }
17
+ catch {
18
+ return;
19
+ }
20
+ for (const directory of names) {
21
+ const bodyPath = join(root, directory, 'SKILL.md');
22
+ const asset = readMarkdownAsset(bodyPath);
23
+ if (asset === undefined)
24
+ continue;
25
+ const parsed = parseSkillFrontmatter(asset.data, directory);
26
+ const frontmatter = parsed.frontmatter;
27
+ if (frontmatter.description.length === 0)
28
+ continue;
29
+ ctx.effect(() => ctx.skills.register({
30
+ name: frontmatter.name,
31
+ description: frontmatter.description,
32
+ ...(frontmatter.whenToUse !== undefined ? { whenToUse: frontmatter.whenToUse } : {}),
33
+ content: asset.body,
34
+ source: 'bundled',
35
+ invocation: {
36
+ modelInvocable: frontmatter.modelInvocable,
37
+ userInvocable: frontmatter.userInvocable,
38
+ },
39
+ ...(frontmatter.metadata !== undefined ? { metadata: frontmatter.metadata } : {}),
40
+ }), `harness-forge.bundled-skill:${directory}`);
41
+ }
42
+ }
@@ -0,0 +1,72 @@
1
+ import type { SkillCandidate, SkillDefinition, SkillLookupOptions, SkillProvider, SkillProviderControl } from '@deepseek-ai/dsh-skill';
2
+ import type { ForeignShell } from '../hooks/shell.js';
3
+ import { type TrustCheck } from '../forge/trust.js';
4
+ /** The provider label used by the registry and diagnostics. */
5
+ export declare const PROVIDER_NAME = "harness-forge";
6
+ /** What a skill root belongs to. */
7
+ export interface SkillRootOrigin {
8
+ readonly pluginRoot?: string;
9
+ /** The plugin's name; a skill a DSH-native skill would shadow is listed as `<plugin>-<skill>`. */
10
+ readonly pluginName?: string;
11
+ readonly dataDir?: string;
12
+ /** A project's skills are listed only to sessions whose directory is inside the project. */
13
+ readonly projectRoot?: string;
14
+ /** Whose skills these are, for what `@file` may attach; a configured root (no plugin) is the person's own. */
15
+ readonly scope?: 'user' | 'project' | 'plugin';
16
+ }
17
+ /**
18
+ * Which files a session has worked with, for skills whose `paths` limit when
19
+ * the model may load them.
20
+ */
21
+ export interface WorkedFiles {
22
+ (sessionId: string): ReadonlySet<string>;
23
+ }
24
+ /** Mutable-root foreign skill provider. */
25
+ export declare class ForeignSkillProvider implements SkillProvider {
26
+ private readonly shell?;
27
+ private readonly onLoad?;
28
+ private readonly worked?;
29
+ /** A project's skill runs shell lines only while its workspace is trusted, checked each time it renders. */
30
+ private readonly trust?;
31
+ readonly name = "harness-forge";
32
+ /** Directories the person configured: every skill in them is served. */
33
+ private readonly roots;
34
+ /** Skills mounted one by one, by body path, with the number of mounts using each. */
35
+ private readonly skills;
36
+ private control;
37
+ constructor(shell?: ForeignShell | undefined, onLoad?: ((bodyPath: string) => void) | undefined, worked?: WorkedFiles | undefined,
38
+ /** A project's skill runs shell lines only while its workspace is trusted, checked each time it renders. */
39
+ trust?: TrustCheck | undefined);
40
+ /** Attach the registration-scoped invalidation capability. */
41
+ attach(control: SkillProviderControl): void;
42
+ /** Add roots and refresh the catalog. */
43
+ addRoots(roots: Iterable<string>, origin?: SkillRootOrigin): void;
44
+ /** Remove roots and refresh the catalog. */
45
+ removeRoots(roots: Iterable<string>): void;
46
+ /**
47
+ * Serve one skill by its body path (`<dir>/SKILL.md` or a flat `<name>.md`).
48
+ * Returns its withdrawal; a body mounted twice stays until both withdraw.
49
+ */
50
+ addSkill(bodyPath: string, origin?: SkillRootOrigin): () => void;
51
+ /** The body paths of the skills mounted one by one, for diagnostics. */
52
+ listSkills(): readonly string[];
53
+ /** Re-read every root (a hook installed new skills). */
54
+ refresh(): void;
55
+ /** The configured roots, for diagnostics. */
56
+ listRoots(): readonly string[];
57
+ list(options: SkillLookupOptions): Promise<readonly SkillCandidate[]>;
58
+ /**
59
+ * Render a skill body for one invocation: `/name args` gives it the
60
+ * arguments a model-loaded skill never has.
61
+ */
62
+ renderFor(bodyPath: string, rawArguments: string, cwd: string, sessionId: string | undefined, signal?: AbortSignal): Promise<string | undefined>;
63
+ /**
64
+ * What a body renders with. The body is the one just read, so whether its
65
+ * shell lines may run is decided now, for this content: a project's skill
66
+ * in a workspace that is not trusted (any more) runs none.
67
+ */
68
+ private renderContext;
69
+ private originOf;
70
+ get(candidate: SkillCandidate, options: SkillLookupOptions): Promise<SkillDefinition | undefined>;
71
+ private candidate;
72
+ }
@@ -0,0 +1,340 @@
1
+ /**
2
+ * Zero-copy skill provider for foreign skills. A mounted skill is served by
3
+ * its exact body path, so a sibling skill in the same directory (switched off,
4
+ * new or never reviewed) stays out of the catalog; only roots the person
5
+ * configured (`skillRoots`) are scanned whole. Both are mutable so installing
6
+ * or removing a plugin does not restart the host; each change invalidates the
7
+ * DSH skill catalog. Loading a skill renders it as Claude Code
8
+ * would (`${CLAUDE_SKILL_DIR}`, `${CLAUDE_PLUGIN_ROOT}`, `` !`cmd` ``).
9
+ * @module @kirkchinese/harness-forge
10
+ */
11
+ import { createHash } from 'node:crypto';
12
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
13
+ import { homedir } from 'node:os';
14
+ import { basename, dirname, join, resolve } from 'node:path';
15
+ import { childDirectories, isFile, isInside, parseSkillFrontmatter, readMarkdownAsset, shortHash, stem, toolList, } from '@kirkchinese/harness-forge-core';
16
+ import { pathPatternMatches } from '../hooks/condition.js';
17
+ import { untrustedShell } from '../forge/trust.js';
18
+ import { renderBody } from '../shared/render.js';
19
+ /** The provider label used by the registry and diagnostics. */
20
+ export const PROVIDER_NAME = 'harness-forge';
21
+ /** Rank: after DSH custom roots, before user roots, so native skills win. */
22
+ const RANK = 350;
23
+ /** Mutable-root foreign skill provider. */
24
+ export class ForeignSkillProvider {
25
+ shell;
26
+ onLoad;
27
+ worked;
28
+ trust;
29
+ name = PROVIDER_NAME;
30
+ /** Directories the person configured: every skill in them is served. */
31
+ roots = new Map();
32
+ /** Skills mounted one by one, by body path, with the number of mounts using each. */
33
+ skills = new Map();
34
+ control;
35
+ constructor(shell, onLoad, worked,
36
+ /** A project's skill runs shell lines only while its workspace is trusted, checked each time it renders. */
37
+ trust) {
38
+ this.shell = shell;
39
+ this.onLoad = onLoad;
40
+ this.worked = worked;
41
+ this.trust = trust;
42
+ }
43
+ /** Attach the registration-scoped invalidation capability. */
44
+ attach(control) {
45
+ this.control = control;
46
+ }
47
+ /** Add roots and refresh the catalog. */
48
+ addRoots(roots, origin = {}) {
49
+ let changed = false;
50
+ for (const root of roots) {
51
+ if (!this.roots.has(root)) {
52
+ this.roots.set(root, origin);
53
+ changed = true;
54
+ }
55
+ }
56
+ if (changed)
57
+ this.control?.invalidate();
58
+ }
59
+ /** Remove roots and refresh the catalog. */
60
+ removeRoots(roots) {
61
+ let changed = false;
62
+ for (const root of roots) {
63
+ if (this.roots.delete(root))
64
+ changed = true;
65
+ }
66
+ if (changed)
67
+ this.control?.invalidate();
68
+ }
69
+ /**
70
+ * Serve one skill by its body path (`<dir>/SKILL.md` or a flat `<name>.md`).
71
+ * Returns its withdrawal; a body mounted twice stays until both withdraw.
72
+ */
73
+ addSkill(bodyPath, origin = {}) {
74
+ const held = this.skills.get(bodyPath);
75
+ if (held === undefined)
76
+ this.skills.set(bodyPath, { origin, users: 1 });
77
+ else
78
+ held.users += 1;
79
+ if (held === undefined)
80
+ this.control?.invalidate();
81
+ let released = false;
82
+ return () => {
83
+ if (released)
84
+ return;
85
+ released = true;
86
+ const current = this.skills.get(bodyPath);
87
+ if (current === undefined)
88
+ return;
89
+ current.users -= 1;
90
+ if (current.users > 0)
91
+ return;
92
+ this.skills.delete(bodyPath);
93
+ this.control?.invalidate();
94
+ };
95
+ }
96
+ /** The body paths of the skills mounted one by one, for diagnostics. */
97
+ listSkills() {
98
+ return [...this.skills.keys()].sort((a, b) => a.localeCompare(b, 'en'));
99
+ }
100
+ /** Re-read every root (a hook installed new skills). */
101
+ refresh() {
102
+ this.control?.invalidate();
103
+ }
104
+ /** The configured roots, for diagnostics. */
105
+ listRoots() {
106
+ return [...this.roots.keys()].sort((a, b) => a.localeCompare(b, 'en'));
107
+ }
108
+ async list(options) {
109
+ const candidates = [];
110
+ const names = new Set();
111
+ // The person's own and the project's skills sit nearer than plugins in DSH's catalog and win a shared
112
+ // name outright; Claude Code keeps both by naming plugin skills `plugin:skill`. A plugin skill such a
113
+ // skill would hide is listed as `<plugin>-<skill>`, as `/plugin:command` is `/plugin-command`.
114
+ const native = nativeSkillNames(options.cwd);
115
+ const add = (candidate, bodyPath, origin) => {
116
+ if (candidate === undefined)
117
+ return;
118
+ // The same skill installed in both places: DSH's own copy serves it.
119
+ if (native.get(candidate.name)?.has(contentHash(bodyPath) ?? '') === true)
120
+ return;
121
+ const prefixed = origin.pluginName !== undefined && native.has(candidate.name) ? `${kebab(origin.pluginName)}-${candidate.name}` : candidate.name;
122
+ // Two plugins may ship a skill with the same name; the later one stays
123
+ // reachable under a stable suffix instead of breaking the catalog.
124
+ const name = names.has(prefixed) || native.has(prefixed) ? `${prefixed}-${shortHash(bodyPath, 6)}` : prefixed;
125
+ names.add(name);
126
+ candidates.push(name === candidate.name ? candidate : { ...candidate, name });
127
+ };
128
+ const sessionId = options.scope?.session?.header?.id;
129
+ const worked = typeof sessionId === 'string' ? this.worked?.(sessionId) : undefined;
130
+ const seen = new Set();
131
+ const visible = (origin) => origin.projectRoot === undefined || (options.cwd !== undefined && isInside(origin.projectRoot, options.cwd));
132
+ const gate = (candidate) => {
133
+ // A skill with `paths` is offered to the model once the session works with a matching file.
134
+ const paths = candidate?.locator?.paths;
135
+ if (candidate === undefined || paths === undefined || !candidate.invocation.modelInvocable)
136
+ return candidate;
137
+ const cwd = options.cwd ?? process.cwd();
138
+ const matched = [...worked ?? []].some(file => paths.some(pattern => pathPatternMatches(pattern, file, cwd)));
139
+ return matched ? candidate : { ...candidate, invocation: { ...candidate.invocation, modelInvocable: false } };
140
+ };
141
+ const offer = (bodyPath, fallbackName, origin) => {
142
+ if (seen.has(bodyPath))
143
+ return;
144
+ seen.add(bodyPath);
145
+ add(gate(this.candidate(bodyPath, fallbackName, origin)), bodyPath, origin);
146
+ };
147
+ for (const [root, origin] of this.roots) {
148
+ if (!visible(origin))
149
+ continue;
150
+ for (const child of childDirectories(root)) {
151
+ const bodyPath = join(root, child, 'SKILL.md');
152
+ if (isFile(bodyPath))
153
+ offer(bodyPath, child, origin);
154
+ }
155
+ for (const entry of safeEntries(root)) {
156
+ if (!entry.isFile() || !entry.name.toLowerCase().endsWith('.md'))
157
+ continue;
158
+ offer(join(root, entry.name), stem(entry.name), origin);
159
+ }
160
+ }
161
+ for (const [bodyPath, { origin }] of this.skills) {
162
+ if (visible(origin) && isFile(bodyPath))
163
+ offer(bodyPath, fallbackNameOf(bodyPath), origin);
164
+ }
165
+ return candidates;
166
+ }
167
+ /**
168
+ * Render a skill body for one invocation: `/name args` gives it the
169
+ * arguments a model-loaded skill never has.
170
+ */
171
+ async renderFor(bodyPath, rawArguments, cwd, sessionId, signal) {
172
+ const asset = readMarkdownAsset(bodyPath);
173
+ if (asset === undefined)
174
+ return undefined;
175
+ const origin = this.originOf(bodyPath);
176
+ if (this.shell === undefined)
177
+ return asset.body;
178
+ return (await renderBody(asset.body, {
179
+ ...this.renderContext(bodyPath, origin ?? {}, asset.data, cwd, this.shell),
180
+ rawArguments,
181
+ ...(sessionId !== undefined ? { sessionId } : {}),
182
+ ...(signal !== undefined ? { signal } : {}),
183
+ })).text;
184
+ }
185
+ /**
186
+ * What a body renders with. The body is the one just read, so whether its
187
+ * shell lines may run is decided now, for this content: a project's skill
188
+ * in a workspace that is not trusted (any more) runs none.
189
+ */
190
+ renderContext(bodyPath, origin, data, cwd, shell) {
191
+ const scope = origin.scope ?? (origin.projectRoot !== undefined ? 'project' : origin.pluginRoot === undefined ? 'user' : 'plugin');
192
+ const trust = origin.projectRoot !== undefined && this.trust !== undefined ? this.trust(origin.projectRoot) : undefined;
193
+ return {
194
+ rawArguments: '',
195
+ argumentNames: toolList(data['arguments']) ?? [],
196
+ cwd,
197
+ skillDir: dirname(bodyPath),
198
+ shell,
199
+ scope,
200
+ ...(origin.pluginRoot !== undefined ? { pluginRoot: origin.pluginRoot } : {}),
201
+ ...(origin.dataDir !== undefined ? { dataDir: origin.dataDir } : {}),
202
+ ...(typeof data['shell'] === 'string' ? { shellKind: data['shell'] } : {}),
203
+ ...(trust !== undefined && !trust.trusted ? { refuseShell: untrustedShell(trust.workspace) } : {}),
204
+ };
205
+ }
206
+ originOf(bodyPath) {
207
+ const mounted = this.skills.get(bodyPath);
208
+ if (mounted !== undefined)
209
+ return mounted.origin;
210
+ for (const [root, origin] of this.roots)
211
+ if (isInside(root, bodyPath))
212
+ return origin;
213
+ return undefined;
214
+ }
215
+ async get(candidate, options) {
216
+ const locator = candidate.locator;
217
+ if (locator === undefined || !isFile(locator.bodyPath))
218
+ return undefined;
219
+ const asset = readMarkdownAsset(locator.bodyPath);
220
+ if (asset === undefined)
221
+ return undefined;
222
+ const frontmatter = parseSkillFrontmatter(asset.data, locator.fallbackName).frontmatter;
223
+ const description = frontmatter.description.length > 0 ? frontmatter.description : firstLine(asset.body);
224
+ if (description === undefined)
225
+ return undefined;
226
+ const sessionId = options.scope?.session?.header?.id;
227
+ const content = this.shell === undefined
228
+ ? asset.body
229
+ : (await renderBody(asset.body, {
230
+ ...this.renderContext(locator.bodyPath, locator.origin, asset.data, options.cwd ?? process.cwd(), this.shell),
231
+ ...(typeof sessionId === 'string' ? { sessionId } : {}),
232
+ ...(options.signal !== undefined ? { signal: options.signal } : {}),
233
+ })).text;
234
+ this.onLoad?.(locator.bodyPath);
235
+ return {
236
+ name: candidate.name,
237
+ description,
238
+ ...(frontmatter.whenToUse !== undefined ? { whenToUse: frontmatter.whenToUse } : {}),
239
+ content,
240
+ invocation: {
241
+ modelInvocable: frontmatter.modelInvocable,
242
+ userInvocable: frontmatter.userInvocable,
243
+ },
244
+ source: 'custom',
245
+ provider: this.name,
246
+ path: locator.bodyPath,
247
+ resourceBase: { kind: 'directory', path: dirname(locator.bodyPath) },
248
+ ...(frontmatter.metadata !== undefined ? { metadata: frontmatter.metadata } : {}),
249
+ };
250
+ }
251
+ candidate(bodyPath, fallbackName, origin) {
252
+ const asset = readMarkdownAsset(bodyPath);
253
+ if (asset === undefined)
254
+ return undefined;
255
+ const frontmatter = parseSkillFrontmatter(asset.data, fallbackName).frontmatter;
256
+ // Without a description, Claude Code uses the first non-empty line of the content.
257
+ const description = frontmatter.description.length > 0 ? frontmatter.description : firstLine(asset.body);
258
+ if (description === undefined)
259
+ return undefined;
260
+ const paths = toolList(asset.data['paths']);
261
+ return {
262
+ name: frontmatter.name,
263
+ description,
264
+ ...(frontmatter.whenToUse !== undefined ? { whenToUse: frontmatter.whenToUse } : {}),
265
+ invocation: {
266
+ modelInvocable: frontmatter.modelInvocable,
267
+ userInvocable: frontmatter.userInvocable,
268
+ },
269
+ source: 'custom',
270
+ provider: this.name,
271
+ rank: RANK,
272
+ locator: { bodyPath, fallbackName, origin, ...(paths !== undefined ? { paths } : {}) },
273
+ path: bodyPath,
274
+ resourceBase: { kind: 'directory', path: dirname(bodyPath) },
275
+ ...(frontmatter.metadata !== undefined ? { metadata: frontmatter.metadata } : {}),
276
+ };
277
+ }
278
+ }
279
+ /** The name a skill body falls back to: its directory for `SKILL.md`, else the file's stem. */
280
+ function fallbackNameOf(bodyPath) {
281
+ return /^SKILL\.md$/iu.test(basename(bodyPath)) ? basename(dirname(bodyPath)) : stem(basename(bodyPath));
282
+ }
283
+ /**
284
+ * Names of the skills DSH itself lists from the person's and the project's
285
+ * roots: `~/.dsh/skills`, `$DSH_AGENTS_HOME` (else `~/.agents`) `/skills`,
286
+ * and `.dsh/skills`, `.agents/skills` of the project: the session directory and
287
+ * its parents up to the repository root, below the home directory.
288
+ * @returns each name with the content hashes of its copies.
289
+ */
290
+ function nativeSkillNames(cwd) {
291
+ const home = resolve(homedir());
292
+ const roots = [
293
+ join(process.env['DSH_HOME'] ?? join(home, '.dsh'), 'skills'),
294
+ join(process.env['DSH_AGENTS_HOME'] ?? join(home, '.agents'), 'skills'),
295
+ ];
296
+ for (let dir = cwd === undefined ? undefined : resolve(cwd); dir !== undefined && dir.toLowerCase() !== home.toLowerCase();) {
297
+ roots.push(join(dir, '.dsh', 'skills'), join(dir, '.agents', 'skills'));
298
+ const parent = dirname(dir);
299
+ dir = parent === dir || isFile(join(dir, '.git')) || existsSync(join(dir, '.git')) ? undefined : parent;
300
+ }
301
+ const out = new Map();
302
+ for (const root of roots) {
303
+ for (const child of childDirectories(root)) {
304
+ const bodyPath = join(root, child, 'SKILL.md');
305
+ if (!isFile(bodyPath))
306
+ continue;
307
+ const asset = readMarkdownAsset(bodyPath);
308
+ const name = typeof asset?.data['name'] === 'string' ? asset.data['name'] : child;
309
+ const hashes = out.get(name) ?? new Set();
310
+ hashes.add(contentHash(bodyPath) ?? '');
311
+ out.set(name, hashes);
312
+ }
313
+ }
314
+ return out;
315
+ }
316
+ /** sha256 of a file with line endings normalised, or undefined when unreadable. */
317
+ function contentHash(path) {
318
+ try {
319
+ return createHash('sha256').update(readFileSync(path, 'utf8').replace(/\r\n/gu, '\n')).digest('hex');
320
+ }
321
+ catch {
322
+ return undefined;
323
+ }
324
+ }
325
+ function kebab(value) {
326
+ return value.toLowerCase().replace(/[^a-z0-9]+/gu, '-').replace(/^-+|-+$/gu, '');
327
+ }
328
+ /** The first non-empty line of Markdown content, without heading marks. */
329
+ function firstLine(body) {
330
+ const line = body.split(/\r?\n/u).map(text => text.replace(/^#+\s*/u, '').trim()).find(text => text.length > 0);
331
+ return line === undefined ? undefined : line.slice(0, 1536);
332
+ }
333
+ function safeEntries(root) {
334
+ try {
335
+ return readdirSync(root, { withFileTypes: true });
336
+ }
337
+ catch {
338
+ return [];
339
+ }
340
+ }
@@ -0,0 +1,22 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ import z from '@deepseek-ai/schemastery';
3
+ import type { Disposer } from '../forge/contract.js';
4
+ import { type HarnessForge } from '../forge/service.js';
5
+ /** The skills row's configuration. */
6
+ export interface Config {
7
+ /**
8
+ * Directories the person names: every foreign `SKILL.md` bundle in them is
9
+ * served, without import or review. An imported plugin's skills are served
10
+ * one by one instead, only those mounted.
11
+ */
12
+ skillRoots?: string[];
13
+ }
14
+ export declare const Config: z<Config>;
15
+ export declare const name = "harness-forge-skills";
16
+ export declare const inject: string[];
17
+ /** The skills row. */
18
+ export declare function apply(ctx: Context, config?: Config): void;
19
+ /** The arguments after a `/name` gesture in what the user typed. */
20
+ export declare function gestureArguments(typed: string, name: string): string;
21
+ /** Start the skills row on the shared service. Returns its teardown. */
22
+ export declare function startSkills(ctx: Context, forge: HarnessForge, config: Config): Disposer;