omniharness-cli 0.1.77 → 0.1.78

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.
@@ -5,7 +5,8 @@ import { attachmentBlock, kindFromName } from '../attachments.js';
5
5
  import { OmniRouteClient } from '../config/omniRoute.js';
6
6
  import { saveActiveCombo } from '../config/settings.js';
7
7
  import { createSystemTools } from '../tools/systemTools.js';
8
- import { loadSkills, renderSkillCommand, skillSchema } from '../skills.js';
8
+ import { loadSkills, renderSkillCommand, skillKind, skillSchema } from '../skills.js';
9
+ import { loadPluginSkills, renderCommandBody } from '../plugins.js';
9
10
  import { chunkText, cosineSimilarity } from '../search.js';
10
11
  import { loadSemanticIndex, saveSemanticIndex } from '../semanticStore.js';
11
12
  import { loadSession, saveSession, clearSession } from '../sessionStore.js';
@@ -122,7 +123,14 @@ export async function createMastraEngine(config) {
122
123
  };
123
124
  const emit = (event) => { for (const listener of listeners)
124
125
  listener(event); };
125
- const skills = await loadSkills(config.workspaceRoot);
126
+ // OMNIHARNESS.md skills first: a workspace's own definition wins a name
127
+ // collision with a plugin's.
128
+ const ownSkills = await loadSkills(config.workspaceRoot);
129
+ const taken = new Set(ownSkills.map((skill) => skill.name));
130
+ const skills = [
131
+ ...ownSkills,
132
+ ...(await loadPluginSkills(config.workspaceRoot)).filter((skill) => !taken.has(skill.name)),
133
+ ];
126
134
  const systemTools = {
127
135
  read_file: {
128
136
  name: 'read_file', description: tools.readFile.description, highRisk: false, parameters: { type: 'object', properties: { path: { type: 'string' } }, required: ['path'] },
@@ -228,9 +236,19 @@ export async function createMastraEngine(config) {
228
236
  }
229
237
  };
230
238
  for (const skill of skills) {
239
+ const prompt = skillKind(skill) === 'prompt';
231
240
  systemTools[skill.name] = {
232
- name: skill.name, description: skill.description, highRisk: true, parameters: skillSchema(skill).parameters ?? { type: 'object', properties: {} },
241
+ name: skill.name,
242
+ description: skill.description,
243
+ // A prompt skill returns instructions. It runs nothing itself, so it
244
+ // does not need the shell and does not carry the shell's risk — the
245
+ // tools it then asks for are gated on their own terms.
246
+ highRisk: !prompt,
247
+ parameters: skillSchema(skill).parameters ?? { type: 'object', properties: {} },
233
248
  execute: async (input) => {
249
+ if (prompt) {
250
+ return renderCommandBody(skill.prompt ?? '', String(input.arguments ?? ''));
251
+ }
234
252
  if (!config.shellAllowed)
235
253
  throw new Error('shell execution is disabled; custom skills need shell access');
236
254
  const script = renderSkillCommand(skill.command, skill.parameters, input);
@@ -0,0 +1,235 @@
1
+ import { promises as fs } from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ /**
5
+ * Split leading `---` delimited frontmatter from a markdown body.
6
+ *
7
+ * Deliberately a small key/value reader rather than a YAML parser: command
8
+ * frontmatter in practice is flat scalars, and a dependency that can evaluate
9
+ * arbitrary YAML is a poor thing to point at files the user downloaded. A file
10
+ * with no frontmatter is not an error — it is a prompt with no metadata.
11
+ */
12
+ export function parseFrontmatter(text) {
13
+ const normalized = text.replace(/^/, '');
14
+ const match = /^---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/.exec(normalized);
15
+ if (!match)
16
+ return { fields: {}, body: normalized.trim() };
17
+ const fields = {};
18
+ for (const line of match[1].split(/\r?\n/)) {
19
+ const kv = /^([A-Za-z0-9_-]+)[ \t]*:[ \t]*(.*)$/.exec(line);
20
+ if (!kv)
21
+ continue;
22
+ let value = kv[2].trim();
23
+ // Strip one layer of matching quotes, the only quoting seen in practice.
24
+ if ((value.startsWith('"') && value.endsWith('"') && value.length > 1)
25
+ || (value.startsWith("'") && value.endsWith("'") && value.length > 1)) {
26
+ value = value.slice(1, -1);
27
+ }
28
+ fields[kv[1].toLowerCase()] = value;
29
+ }
30
+ return { fields, body: normalized.slice(match[0].length).trim() };
31
+ }
32
+ function splitList(value) {
33
+ if (!value)
34
+ return [];
35
+ const inner = value.trim().replace(/^\[/, '').replace(/\]$/, '');
36
+ // Split on commas that are not inside the parentheses of Bash(gh pr view:*).
37
+ const out = [];
38
+ let depth = 0;
39
+ let current = '';
40
+ for (const ch of inner) {
41
+ if (ch === '(')
42
+ depth += 1;
43
+ if (ch === ')')
44
+ depth = Math.max(0, depth - 1);
45
+ if (ch === ',' && depth === 0) {
46
+ out.push(current);
47
+ current = '';
48
+ continue;
49
+ }
50
+ current += ch;
51
+ }
52
+ out.push(current);
53
+ return out.map((entry) => entry.trim().replace(/^["']|["']$/g, '')).filter((entry) => entry !== '');
54
+ }
55
+ async function readJSON(file) {
56
+ try {
57
+ return JSON.parse(await fs.readFile(file, 'utf8'));
58
+ }
59
+ catch {
60
+ return null;
61
+ }
62
+ }
63
+ async function readCommands(root, pluginName, dir) {
64
+ const base = path.join(root, dir);
65
+ let entries;
66
+ try {
67
+ entries = await fs.readdir(base);
68
+ }
69
+ catch {
70
+ return [];
71
+ }
72
+ const commands = [];
73
+ for (const entry of entries.sort()) {
74
+ if (!entry.toLowerCase().endsWith('.md'))
75
+ continue;
76
+ const file = path.join(base, entry);
77
+ let raw;
78
+ try {
79
+ raw = await fs.readFile(file, 'utf8');
80
+ }
81
+ catch {
82
+ continue;
83
+ }
84
+ const { fields, body } = parseFrontmatter(raw);
85
+ if (body === '')
86
+ continue; // nothing to instruct with
87
+ commands.push({
88
+ name: entry.replace(/\.md$/i, ''),
89
+ description: fields.description ?? `${dir.replace(/s$/, '')} from ${pluginName}`,
90
+ body,
91
+ allowedTools: splitList(fields['allowed-tools']),
92
+ plugin: pluginName,
93
+ path: file,
94
+ });
95
+ }
96
+ return commands;
97
+ }
98
+ /** Read one plugin directory. Returns null if it is not a plugin. */
99
+ export async function loadPlugin(root) {
100
+ const manifest = await readJSON(path.join(root, '.claude-plugin', 'plugin.json'));
101
+ if (!manifest || typeof manifest.name !== 'string' || manifest.name === '')
102
+ return null;
103
+ const name = manifest.name;
104
+ const author = manifest.author;
105
+ const commands = [
106
+ ...await readCommands(root, name, 'commands'),
107
+ ...await readCommands(root, name, 'agents'),
108
+ ];
109
+ return {
110
+ name,
111
+ description: typeof manifest.description === 'string' ? manifest.description : '',
112
+ version: typeof manifest.version === 'string' ? manifest.version : '0.0.0',
113
+ author: typeof author === 'string' ? author : (author?.name ?? ''),
114
+ root,
115
+ commands,
116
+ };
117
+ }
118
+ async function subdirectories(dir) {
119
+ try {
120
+ const entries = await fs.readdir(dir, { withFileTypes: true });
121
+ return entries.filter((e) => e.isDirectory()).map((e) => path.join(dir, e.name)).sort();
122
+ }
123
+ catch {
124
+ return [];
125
+ }
126
+ }
127
+ /**
128
+ * Read a directory as either a single plugin or a marketplace of them. A
129
+ * marketplace's `source` entries are relative to the marketplace root; a
130
+ * source pointing outside it is ignored rather than followed.
131
+ */
132
+ export async function loadFrom(dir, depth = 2) {
133
+ const single = await loadPlugin(dir);
134
+ if (single)
135
+ return [single];
136
+ const market = await readJSON(path.join(dir, '.claude-plugin', 'marketplace.json'));
137
+ const out = [];
138
+ if (market && Array.isArray(market.plugins)) {
139
+ for (const entry of market.plugins) {
140
+ const source = typeof entry.source === 'string' ? entry.source : '';
141
+ if (source === '')
142
+ continue;
143
+ const resolved = path.resolve(dir, source);
144
+ const rel = path.relative(dir, resolved);
145
+ if (rel === '' || rel.startsWith('..') || path.isAbsolute(rel))
146
+ continue;
147
+ const plugin = await loadPlugin(resolved);
148
+ if (plugin)
149
+ out.push(plugin);
150
+ }
151
+ return out;
152
+ }
153
+ // A directory of plugin directories — and a child may itself be a
154
+ // marketplace rather than a plugin, which is what cloning a plugin
155
+ // repository into the plugins directory gives you. Descending only one
156
+ // level found nothing in that very ordinary case. Bounded, so a plugins
157
+ // directory holding a deep source tree is not walked to the bottom.
158
+ if (depth <= 0)
159
+ return out;
160
+ for (const child of await subdirectories(dir)) {
161
+ out.push(...await loadFrom(child, depth - 1));
162
+ }
163
+ return out;
164
+ }
165
+ /**
166
+ * The directories searched for plugins, nearest first.
167
+ *
168
+ * OMNIHARNESS_PLUGIN_PATH replaces the list entirely, delimited like PATH.
169
+ * Setting it empty disables discovery. It exists because the default reaches
170
+ * into the user's home directory: without an override, what the agent can do
171
+ * depends on what happens to be installed on the machine, which makes a test
172
+ * or a CI run read differently from one box to the next.
173
+ */
174
+ export function pluginSearchPath(workspaceRoot) {
175
+ const override = process.env.OMNIHARNESS_PLUGIN_PATH;
176
+ if (override !== undefined) {
177
+ return override.split(path.delimiter).map((entry) => entry.trim()).filter((entry) => entry !== '');
178
+ }
179
+ const home = os.homedir();
180
+ return [
181
+ path.join(workspaceRoot, '.claude', 'plugins'),
182
+ path.join(workspaceRoot, '.omniharness', 'plugins'),
183
+ ...(home ? [path.join(home, '.claude', 'plugins')] : []),
184
+ ];
185
+ }
186
+ /**
187
+ * Discover every plugin on the search path. A workspace plugin wins a name
188
+ * collision with a user-level one, because the nearer definition is the more
189
+ * specific.
190
+ */
191
+ export async function discoverPlugins(workspaceRoot, roots = pluginSearchPath(workspaceRoot)) {
192
+ const seen = new Set();
193
+ const out = [];
194
+ for (const root of roots) {
195
+ for (const plugin of await loadFrom(root)) {
196
+ if (seen.has(plugin.name))
197
+ continue;
198
+ seen.add(plugin.name);
199
+ out.push(plugin);
200
+ }
201
+ }
202
+ return out;
203
+ }
204
+ /** Substitute the argument tokens a command body may use. */
205
+ export function renderCommandBody(body, args) {
206
+ const words = args.trim() === '' ? [] : args.trim().split(/\s+/);
207
+ let out = body.split('$ARGUMENTS').join(args.trim());
208
+ // $1..$9 take one word each, matching the shell convention the format borrows.
209
+ out = out.replace(/\$([1-9])/g, (_, digit) => words[Number(digit) - 1] ?? '');
210
+ return out;
211
+ }
212
+ const ARGUMENTS_PARAM = [{ name: 'arguments', type: 'string' }];
213
+ /**
214
+ * Present a plugin command as a Skill so the rest of the engine does not have
215
+ * to know where it came from. Names are prefixed with the plugin so two
216
+ * plugins can both ship a "review" command.
217
+ */
218
+ export function commandToSkill(command) {
219
+ return {
220
+ name: `${command.plugin}:${command.name}`.replace(/[^A-Za-z0-9_:.-]/g, '-'),
221
+ description: command.description,
222
+ command: '',
223
+ parameters: ARGUMENTS_PARAM,
224
+ kind: 'prompt',
225
+ prompt: command.body,
226
+ source: command.plugin,
227
+ allowedTools: command.allowedTools,
228
+ };
229
+ }
230
+ /** Every command from every discovered plugin, as Skills. */
231
+ export async function loadPluginSkills(workspaceRoot) {
232
+ const plugins = await discoverPlugins(workspaceRoot);
233
+ return plugins.flatMap((plugin) => plugin.commands.map(commandToSkill));
234
+ }
235
+ //# sourceMappingURL=plugins.js.map
package/dist/skills.js CHANGED
@@ -1,5 +1,9 @@
1
1
  import { promises as fs } from 'node:fs';
2
2
  import path from 'node:path';
3
+ /** Whether a skill runs a command or supplies instructions. */
4
+ export function skillKind(skill) {
5
+ return skill.kind ?? 'shell';
6
+ }
3
7
  /**
4
8
  * Parse an OMNIHARNESS.md skills definition. Blocks start with `## <name>`
5
9
  * and contain `description:`, `command:`, and `param: <name> <type>` fields.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omniharness-cli",
3
- "version": "0.1.77",
3
+ "version": "0.1.78",
4
4
  "description": "OmniHarness — local-first agent orchestration harness for OmniRoute.",
5
5
  "license": "MIT",
6
6
  "type": "module",