mu-harness 0.17.2 → 0.17.3
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/esm/agents/index.d.ts +1 -0
- package/esm/agents/index.js +1 -0
- package/esm/agents/registry.d.ts +7 -0
- package/esm/agents/registry.js +7 -0
- package/esm/agents/writer.d.ts +14 -0
- package/esm/agents/writer.js +81 -0
- package/esm/common/index.d.ts +1 -0
- package/esm/common/scope.d.ts +8 -0
- package/esm/common/scope.js +1 -0
- package/esm/harness/create.js +12 -4
- package/esm/harness/types.d.ts +16 -2
- package/esm/skills/index.d.ts +1 -1
- package/esm/skills/writer.d.ts +3 -3
- package/package.json +3 -3
- package/script/agents/index.d.ts +1 -0
- package/script/agents/index.js +3 -1
- package/script/agents/registry.d.ts +7 -0
- package/script/agents/registry.js +7 -0
- package/script/agents/writer.d.ts +14 -0
- package/script/agents/writer.js +85 -0
- package/script/common/index.d.ts +1 -0
- package/script/common/scope.d.ts +8 -0
- package/script/common/scope.js +2 -0
- package/script/harness/create.js +11 -3
- package/script/harness/types.d.ts +16 -2
- package/script/skills/index.d.ts +1 -1
- package/script/skills/writer.d.ts +3 -3
package/esm/agents/index.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export type { Agent, GrantValue, ToolDecision, ToolGrants } from './types.js';
|
|
|
2
2
|
export { type AgentRegistry, createAgentRegistry, grantArg, toolDecision, toolNames } from './registry.js';
|
|
3
3
|
export { parseAgent } from './parser.js';
|
|
4
4
|
export { loadAgents } from './loader.js';
|
|
5
|
+
export { createAgentWriterTool } from './writer.js';
|
package/esm/agents/index.js
CHANGED
package/esm/agents/registry.d.ts
CHANGED
|
@@ -2,6 +2,13 @@ import type { Agent, ToolDecision } from './types.js';
|
|
|
2
2
|
export interface AgentRegistry {
|
|
3
3
|
list(): Agent[];
|
|
4
4
|
get(name: string): Agent | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Register (or replace) an agent at runtime — mirrors {@link SkillRegistry.add}.
|
|
7
|
+
* Lets tools like `create_agent` make a freshly-authored agent immediately
|
|
8
|
+
* delegatable without a restart. Agents that `extends` the added one are
|
|
9
|
+
* re-resolved so they pick up the change.
|
|
10
|
+
*/
|
|
11
|
+
add(agent: Agent): void;
|
|
5
12
|
}
|
|
6
13
|
export declare const grantArg: (tool: string, input: unknown) => string | undefined;
|
|
7
14
|
export declare const toolDecision: (agent: Agent, tool: string, arg?: string) => ToolDecision;
|
package/esm/agents/registry.js
CHANGED
|
@@ -84,5 +84,12 @@ export const createAgentRegistry = (agents = []) => {
|
|
|
84
84
|
return {
|
|
85
85
|
list: () => [...byName.values()],
|
|
86
86
|
get: (name) => byName.get(name),
|
|
87
|
+
add: (agent) => {
|
|
88
|
+
raw.set(agent.name, agent);
|
|
89
|
+
byName.set(agent.name, resolve(agent.name, new Set()));
|
|
90
|
+
for (const [name, a] of raw)
|
|
91
|
+
if (a.extends === agent.name)
|
|
92
|
+
byName.set(name, resolve(name, new Set()));
|
|
93
|
+
},
|
|
87
94
|
};
|
|
88
95
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Tool } from 'mu-core';
|
|
2
|
+
import type { Scope } from '../common/index.js';
|
|
3
|
+
import type { AgentRegistry } from './registry.js';
|
|
4
|
+
/**
|
|
5
|
+
* `create_agent` — authors a reusable agent definition (`.md` with frontmatter)
|
|
6
|
+
* and registers it live via {@link AgentRegistry.add}, so it can be delegated to
|
|
7
|
+
* through `subagent` without a restart. Mirrors {@link createSkillWriterTool}:
|
|
8
|
+
* the `scope` selects the save location, or a configured `forceScope` pins it.
|
|
9
|
+
*/
|
|
10
|
+
export declare const createAgentWriterTool: (deps: {
|
|
11
|
+
dirs: Record<Scope, string>;
|
|
12
|
+
registry: AgentRegistry;
|
|
13
|
+
forceScope?: Scope;
|
|
14
|
+
}) => Tool;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { stringify as stringifyYaml } from '../deps/jsr.io/@std/yaml/1.1.0/mod.js';
|
|
5
|
+
import { parseAgent } from './parser.js';
|
|
6
|
+
const slug = (name) => name.trim().toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
7
|
+
/**
|
|
8
|
+
* `create_agent` — authors a reusable agent definition (`.md` with frontmatter)
|
|
9
|
+
* and registers it live via {@link AgentRegistry.add}, so it can be delegated to
|
|
10
|
+
* through `subagent` without a restart. Mirrors {@link createSkillWriterTool}:
|
|
11
|
+
* the `scope` selects the save location, or a configured `forceScope` pins it.
|
|
12
|
+
*/
|
|
13
|
+
export const createAgentWriterTool = (deps) => {
|
|
14
|
+
const { forceScope } = deps;
|
|
15
|
+
const scopeProp = forceScope ? {} : {
|
|
16
|
+
scope: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
enum: ['local', 'config'],
|
|
19
|
+
description: 'Where to save it: "local" = this project (repo-first), "config" = global config dir. Defaults to "local".',
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
name: 'create_agent',
|
|
24
|
+
description: forceScope
|
|
25
|
+
? `Define a reusable agent (name, description, system prompt, optional per-tool grants) that can be delegated to via \`subagent\`. Always saved to the "${forceScope}" agents directory.`
|
|
26
|
+
: 'Define a reusable agent (name, description, system prompt, optional per-tool grants) that can be delegated to via `subagent`. `scope: "local"` saves it to this project, `scope: "config"` makes it available across all projects.',
|
|
27
|
+
parameters: {
|
|
28
|
+
type: 'object',
|
|
29
|
+
properties: {
|
|
30
|
+
name: { type: 'string', description: 'Short agent name (kebab-case); also the filename.' },
|
|
31
|
+
description: { type: 'string', description: 'One line describing what this agent is for.' },
|
|
32
|
+
prompt: { type: 'string', description: 'The system prompt that defines the agent.' },
|
|
33
|
+
tools: {
|
|
34
|
+
type: 'object',
|
|
35
|
+
description: 'Optional per-tool grants: map a tool name to "allow" | "ask" | "deny" (or a nested {glob: decision} map). Omitted tools are denied — be explicit about what it may use.',
|
|
36
|
+
additionalProperties: true,
|
|
37
|
+
},
|
|
38
|
+
model: { type: 'string', description: 'Optional model ref override.' },
|
|
39
|
+
color: { type: 'string', description: 'Optional hex color for the UI.' },
|
|
40
|
+
...scopeProp,
|
|
41
|
+
},
|
|
42
|
+
required: ['name', 'description', 'prompt'],
|
|
43
|
+
additionalProperties: false,
|
|
44
|
+
},
|
|
45
|
+
run: async (input) => {
|
|
46
|
+
const { name, description, prompt, tools, model, color, scope } = (input ?? {});
|
|
47
|
+
if (!name || !description || !prompt) {
|
|
48
|
+
return [{ type: 'text', text: 'Error: create_agent requires `name`, `description`, and `prompt`.' }];
|
|
49
|
+
}
|
|
50
|
+
// A configured forceScope wins over whatever the model passed.
|
|
51
|
+
const resolved = forceScope ?? scope ?? 'local';
|
|
52
|
+
const base = deps.dirs[resolved];
|
|
53
|
+
if (!base)
|
|
54
|
+
return [{ type: 'text', text: `Error: unknown scope "${scope}".` }];
|
|
55
|
+
const id = slug(name);
|
|
56
|
+
if (!id)
|
|
57
|
+
return [{ type: 'text', text: `Error: invalid agent name "${name}".` }];
|
|
58
|
+
if (deps.registry.get(id)) {
|
|
59
|
+
return [{ type: 'text', text: `Error: an agent named "${id}" already exists.` }];
|
|
60
|
+
}
|
|
61
|
+
const file = join(base, `${id}.md`);
|
|
62
|
+
if (existsSync(file))
|
|
63
|
+
return [{ type: 'text', text: `Error: ${file} already exists.` }];
|
|
64
|
+
const frontmatter = { name: id, description };
|
|
65
|
+
if (model)
|
|
66
|
+
frontmatter.model = model;
|
|
67
|
+
if (color)
|
|
68
|
+
frontmatter.color = color;
|
|
69
|
+
if (tools && typeof tools === 'object')
|
|
70
|
+
frontmatter.tools = tools;
|
|
71
|
+
const source = `---\n${stringifyYaml(frontmatter).trimEnd()}\n---\n\n${prompt.trim()}\n`;
|
|
72
|
+
await mkdir(base, { recursive: true });
|
|
73
|
+
await writeFile(file, source, 'utf-8');
|
|
74
|
+
deps.registry.add(parseAgent(source, id));
|
|
75
|
+
return [{
|
|
76
|
+
type: 'text',
|
|
77
|
+
text: `Created agent "${id}" at ${file}. It can now be delegated to via the \`subagent\` tool.`,
|
|
78
|
+
}];
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
};
|
package/esm/common/index.d.ts
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a host saves agent-authored definitions (skills, sub-agents, …):
|
|
3
|
+
* - `local` → the current project (repo-first, e.g. `<cwd>/skills`).
|
|
4
|
+
* - `config` → the global config dir, shared across every project.
|
|
5
|
+
*
|
|
6
|
+
* Generic across definition kinds so every writer tool speaks the same vocabulary.
|
|
7
|
+
*/
|
|
8
|
+
export type Scope = 'local' | 'config';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/harness/create.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import os from 'node:os';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import process from 'node:process';
|
|
4
|
-
import { createAgentRegistry, grantArg, loadAgents, toolDecision, toolNames } from '../agents/index.js';
|
|
4
|
+
import { createAgentRegistry, createAgentWriterTool, grantArg, loadAgents, toolDecision, toolNames } from '../agents/index.js';
|
|
5
5
|
import { createAgentsCommand, createCommandRegistry, createHelpCommand, createSessionsCommand, createSkillsCommand, } from '../commands/index.js';
|
|
6
6
|
import { createHarnessConfig } from '../config/index.js';
|
|
7
7
|
import { mergeHooks } from '../hooks/index.js';
|
|
@@ -20,17 +20,19 @@ const TITLE_AGENT = {
|
|
|
20
20
|
tools: [],
|
|
21
21
|
};
|
|
22
22
|
export const createHarness = async (options) => {
|
|
23
|
-
const { hostName, xdg, providers, model, agents: hostAgents = [], skills: hostSkills = [], skillScope, title, titleModel, scheduler: enableScheduler = false, approvals, ...sessionDefaults } = options;
|
|
23
|
+
const { hostName, xdg, providers, model, agents: hostAgents = [], skills: hostSkills = [], skillScope, agentScope, agentDirs, title, titleModel, scheduler: enableScheduler = false, approvals, ...sessionDefaults } = options;
|
|
24
24
|
const cwd = options.cwd ?? process.cwd();
|
|
25
25
|
const config = createHarnessConfig({ hostName, xdg });
|
|
26
26
|
const models = createModelRegistry({ providers, default: model });
|
|
27
27
|
const pluginsDir = join(config.configDir, 'plugins');
|
|
28
|
-
const agentsDir = join(config.configDir, 'agents');
|
|
28
|
+
const agentsDir = agentDirs?.config ?? join(config.configDir, 'agents');
|
|
29
|
+
const localAgentsDir = agentDirs?.local ?? join(cwd, 'agents');
|
|
29
30
|
const plugins = createPluginStore({ dir: pluginsDir });
|
|
30
31
|
const newId = () => crypto.randomUUID();
|
|
31
32
|
const pluginAgents = (sessionDefaults.plugins ?? []).flatMap((plugin) => plugin.agents ?? []);
|
|
33
|
+
const localAgents = await loadAgents(localAgentsDir);
|
|
32
34
|
const diskAgents = await loadAgents(agentsDir);
|
|
33
|
-
const agents = createAgentRegistry([...hostAgents, ...pluginAgents, ...diskAgents]);
|
|
35
|
+
const agents = createAgentRegistry([...hostAgents, ...pluginAgents, ...localAgents, ...diskAgents]);
|
|
34
36
|
const skillsDir = join(config.configDir, 'skills');
|
|
35
37
|
const cwdSkillsDir = join(cwd, 'skills');
|
|
36
38
|
const envBlock = environmentBlock({
|
|
@@ -54,6 +56,11 @@ export const createHarness = async (options) => {
|
|
|
54
56
|
registry: skills,
|
|
55
57
|
forceScope: skillScope,
|
|
56
58
|
});
|
|
59
|
+
const agentWriterTool = createAgentWriterTool({
|
|
60
|
+
dirs: { local: localAgentsDir, config: agentsDir },
|
|
61
|
+
registry: agents,
|
|
62
|
+
forceScope: agentScope,
|
|
63
|
+
});
|
|
57
64
|
const scopeSkills = (agent) => {
|
|
58
65
|
if (!agent)
|
|
59
66
|
return skills;
|
|
@@ -68,6 +75,7 @@ export const createHarness = async (options) => {
|
|
|
68
75
|
...extra,
|
|
69
76
|
createSkillTool(scopeSkills(agent)),
|
|
70
77
|
skillWriterTool,
|
|
78
|
+
agentWriterTool,
|
|
71
79
|
...schedulerTools,
|
|
72
80
|
];
|
|
73
81
|
const approvalHook = (getAgent) => approvals
|
package/esm/harness/types.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { Provider } from 'mu-core';
|
|
2
2
|
import type { Agent, AgentRegistry, ToolDecision } from '../agents/index.js';
|
|
3
3
|
import type { CommandRegistry } from '../commands/index.js';
|
|
4
|
+
import type { Scope } from '../common/index.js';
|
|
4
5
|
import type { HarnessConfig, HarnessConfigOptions } from '../config/index.js';
|
|
5
6
|
import type { ApprovalManager } from '../permissions/index.js';
|
|
6
7
|
import type { PluginStore } from '../plugin/index.js';
|
|
7
8
|
import type { Scheduler, TaskStore } from '../scheduler/index.js';
|
|
8
9
|
import type { AgentSessionConfig, SessionManager } from '../session/index.js';
|
|
9
|
-
import type { Skill, SkillRegistry
|
|
10
|
+
import type { Skill, SkillRegistry } from '../skills/index.js';
|
|
10
11
|
import type { SubAgentRegistry, SubAgentResult } from '../subAgents/index.js';
|
|
11
12
|
import type { ModelRegistry } from './models.js';
|
|
12
13
|
export type HarnessOptions = HarnessConfigOptions & Omit<AgentSessionConfig, 'provider' | 'model' | 'id' | 'messages'> & {
|
|
@@ -19,7 +20,20 @@ export type HarnessOptions = HarnessConfigOptions & Omit<AgentSessionConfig, 'pr
|
|
|
19
20
|
* argument is overridden (and dropped from the tool schema). Unset → the
|
|
20
21
|
* model chooses, defaulting to 'local'.
|
|
21
22
|
*/
|
|
22
|
-
skillScope?:
|
|
23
|
+
skillScope?: Scope;
|
|
24
|
+
/**
|
|
25
|
+
* Forces the save location of `create_agent`. Same semantics as
|
|
26
|
+
* {@link skillScope}: set to pin the scope, leave unset to let the model choose.
|
|
27
|
+
*/
|
|
28
|
+
agentScope?: Scope;
|
|
29
|
+
/**
|
|
30
|
+
* Overrides where `create_agent` writes (and which dirs are loaded at boot).
|
|
31
|
+
* Defaults to `{ local: <cwd>/agents, config: <configDir>/agents }`.
|
|
32
|
+
*/
|
|
33
|
+
agentDirs?: {
|
|
34
|
+
local?: string;
|
|
35
|
+
config?: string;
|
|
36
|
+
};
|
|
23
37
|
title?: boolean;
|
|
24
38
|
titleModel?: string;
|
|
25
39
|
cwd?: string;
|
package/esm/skills/index.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export { parseSkill } from './parser.js';
|
|
|
4
4
|
export { loadSkills } from './loader.js';
|
|
5
5
|
export { skillMatchesPlatform } from './platform.js';
|
|
6
6
|
export { createSkillTool } from './tool.js';
|
|
7
|
-
export { createSkillWriterTool
|
|
7
|
+
export { createSkillWriterTool } from './writer.js';
|
|
8
8
|
export { createRunSkillTool, runSkill, type RunSkillDeps } from './run.js';
|
package/esm/skills/writer.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Tool } from 'mu-core';
|
|
2
|
+
import type { Scope } from '../common/index.js';
|
|
2
3
|
import type { SkillRegistry } from './registry.js';
|
|
3
|
-
export type SkillScope = 'local' | 'config';
|
|
4
4
|
export declare const createSkillWriterTool: (deps: {
|
|
5
|
-
dirs: Record<
|
|
5
|
+
dirs: Record<Scope, string>;
|
|
6
6
|
registry: SkillRegistry;
|
|
7
|
-
forceScope?:
|
|
7
|
+
forceScope?: Scope;
|
|
8
8
|
}) => Tool;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mu-harness",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.3",
|
|
4
4
|
"description": "Agent harness: createHarness wires mu-core into a host — XDG paths, model registry, plugins, disk-loaded agents & skills, sub-agents, sessions (JSONL + SQLite catalog), slash commands, permission/approval hooks, an optional scheduler, and a composable TUI chat app",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./script/index.js",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"@swc/wasm-typescript": "^1.15.0",
|
|
24
24
|
"cli-highlight": "^2.1.11",
|
|
25
25
|
"croner": "^9.0.0",
|
|
26
|
-
"mu-core": "^0.17.
|
|
27
|
-
"mu-tui": "^0.17.
|
|
26
|
+
"mu-core": "^0.17.3",
|
|
27
|
+
"mu-tui": "^0.17.3"
|
|
28
28
|
},
|
|
29
29
|
"_generatedBy": "dnt@dev",
|
|
30
30
|
"types": "./esm/index.d.ts"
|
package/script/agents/index.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export type { Agent, GrantValue, ToolDecision, ToolGrants } from './types.js';
|
|
|
2
2
|
export { type AgentRegistry, createAgentRegistry, grantArg, toolDecision, toolNames } from './registry.js';
|
|
3
3
|
export { parseAgent } from './parser.js';
|
|
4
4
|
export { loadAgents } from './loader.js';
|
|
5
|
+
export { createAgentWriterTool } from './writer.js';
|
package/script/agents/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadAgents = exports.parseAgent = exports.toolNames = exports.toolDecision = exports.grantArg = exports.createAgentRegistry = void 0;
|
|
3
|
+
exports.createAgentWriterTool = exports.loadAgents = exports.parseAgent = exports.toolNames = exports.toolDecision = exports.grantArg = exports.createAgentRegistry = void 0;
|
|
4
4
|
var registry_js_1 = require("./registry.js");
|
|
5
5
|
Object.defineProperty(exports, "createAgentRegistry", { enumerable: true, get: function () { return registry_js_1.createAgentRegistry; } });
|
|
6
6
|
Object.defineProperty(exports, "grantArg", { enumerable: true, get: function () { return registry_js_1.grantArg; } });
|
|
@@ -10,3 +10,5 @@ var parser_js_1 = require("./parser.js");
|
|
|
10
10
|
Object.defineProperty(exports, "parseAgent", { enumerable: true, get: function () { return parser_js_1.parseAgent; } });
|
|
11
11
|
var loader_js_1 = require("./loader.js");
|
|
12
12
|
Object.defineProperty(exports, "loadAgents", { enumerable: true, get: function () { return loader_js_1.loadAgents; } });
|
|
13
|
+
var writer_js_1 = require("./writer.js");
|
|
14
|
+
Object.defineProperty(exports, "createAgentWriterTool", { enumerable: true, get: function () { return writer_js_1.createAgentWriterTool; } });
|
|
@@ -2,6 +2,13 @@ import type { Agent, ToolDecision } from './types.js';
|
|
|
2
2
|
export interface AgentRegistry {
|
|
3
3
|
list(): Agent[];
|
|
4
4
|
get(name: string): Agent | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Register (or replace) an agent at runtime — mirrors {@link SkillRegistry.add}.
|
|
7
|
+
* Lets tools like `create_agent` make a freshly-authored agent immediately
|
|
8
|
+
* delegatable without a restart. Agents that `extends` the added one are
|
|
9
|
+
* re-resolved so they pick up the change.
|
|
10
|
+
*/
|
|
11
|
+
add(agent: Agent): void;
|
|
5
12
|
}
|
|
6
13
|
export declare const grantArg: (tool: string, input: unknown) => string | undefined;
|
|
7
14
|
export declare const toolDecision: (agent: Agent, tool: string, arg?: string) => ToolDecision;
|
|
@@ -90,6 +90,13 @@ const createAgentRegistry = (agents = []) => {
|
|
|
90
90
|
return {
|
|
91
91
|
list: () => [...byName.values()],
|
|
92
92
|
get: (name) => byName.get(name),
|
|
93
|
+
add: (agent) => {
|
|
94
|
+
raw.set(agent.name, agent);
|
|
95
|
+
byName.set(agent.name, resolve(agent.name, new Set()));
|
|
96
|
+
for (const [name, a] of raw)
|
|
97
|
+
if (a.extends === agent.name)
|
|
98
|
+
byName.set(name, resolve(name, new Set()));
|
|
99
|
+
},
|
|
93
100
|
};
|
|
94
101
|
};
|
|
95
102
|
exports.createAgentRegistry = createAgentRegistry;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Tool } from 'mu-core';
|
|
2
|
+
import type { Scope } from '../common/index.js';
|
|
3
|
+
import type { AgentRegistry } from './registry.js';
|
|
4
|
+
/**
|
|
5
|
+
* `create_agent` — authors a reusable agent definition (`.md` with frontmatter)
|
|
6
|
+
* and registers it live via {@link AgentRegistry.add}, so it can be delegated to
|
|
7
|
+
* through `subagent` without a restart. Mirrors {@link createSkillWriterTool}:
|
|
8
|
+
* the `scope` selects the save location, or a configured `forceScope` pins it.
|
|
9
|
+
*/
|
|
10
|
+
export declare const createAgentWriterTool: (deps: {
|
|
11
|
+
dirs: Record<Scope, string>;
|
|
12
|
+
registry: AgentRegistry;
|
|
13
|
+
forceScope?: Scope;
|
|
14
|
+
}) => Tool;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAgentWriterTool = void 0;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const promises_1 = require("node:fs/promises");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const mod_js_1 = require("../deps/jsr.io/@std/yaml/1.1.0/mod.js");
|
|
8
|
+
const parser_js_1 = require("./parser.js");
|
|
9
|
+
const slug = (name) => name.trim().toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
10
|
+
/**
|
|
11
|
+
* `create_agent` — authors a reusable agent definition (`.md` with frontmatter)
|
|
12
|
+
* and registers it live via {@link AgentRegistry.add}, so it can be delegated to
|
|
13
|
+
* through `subagent` without a restart. Mirrors {@link createSkillWriterTool}:
|
|
14
|
+
* the `scope` selects the save location, or a configured `forceScope` pins it.
|
|
15
|
+
*/
|
|
16
|
+
const createAgentWriterTool = (deps) => {
|
|
17
|
+
const { forceScope } = deps;
|
|
18
|
+
const scopeProp = forceScope ? {} : {
|
|
19
|
+
scope: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
enum: ['local', 'config'],
|
|
22
|
+
description: 'Where to save it: "local" = this project (repo-first), "config" = global config dir. Defaults to "local".',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
name: 'create_agent',
|
|
27
|
+
description: forceScope
|
|
28
|
+
? `Define a reusable agent (name, description, system prompt, optional per-tool grants) that can be delegated to via \`subagent\`. Always saved to the "${forceScope}" agents directory.`
|
|
29
|
+
: 'Define a reusable agent (name, description, system prompt, optional per-tool grants) that can be delegated to via `subagent`. `scope: "local"` saves it to this project, `scope: "config"` makes it available across all projects.',
|
|
30
|
+
parameters: {
|
|
31
|
+
type: 'object',
|
|
32
|
+
properties: {
|
|
33
|
+
name: { type: 'string', description: 'Short agent name (kebab-case); also the filename.' },
|
|
34
|
+
description: { type: 'string', description: 'One line describing what this agent is for.' },
|
|
35
|
+
prompt: { type: 'string', description: 'The system prompt that defines the agent.' },
|
|
36
|
+
tools: {
|
|
37
|
+
type: 'object',
|
|
38
|
+
description: 'Optional per-tool grants: map a tool name to "allow" | "ask" | "deny" (or a nested {glob: decision} map). Omitted tools are denied — be explicit about what it may use.',
|
|
39
|
+
additionalProperties: true,
|
|
40
|
+
},
|
|
41
|
+
model: { type: 'string', description: 'Optional model ref override.' },
|
|
42
|
+
color: { type: 'string', description: 'Optional hex color for the UI.' },
|
|
43
|
+
...scopeProp,
|
|
44
|
+
},
|
|
45
|
+
required: ['name', 'description', 'prompt'],
|
|
46
|
+
additionalProperties: false,
|
|
47
|
+
},
|
|
48
|
+
run: async (input) => {
|
|
49
|
+
const { name, description, prompt, tools, model, color, scope } = (input ?? {});
|
|
50
|
+
if (!name || !description || !prompt) {
|
|
51
|
+
return [{ type: 'text', text: 'Error: create_agent requires `name`, `description`, and `prompt`.' }];
|
|
52
|
+
}
|
|
53
|
+
// A configured forceScope wins over whatever the model passed.
|
|
54
|
+
const resolved = forceScope ?? scope ?? 'local';
|
|
55
|
+
const base = deps.dirs[resolved];
|
|
56
|
+
if (!base)
|
|
57
|
+
return [{ type: 'text', text: `Error: unknown scope "${scope}".` }];
|
|
58
|
+
const id = slug(name);
|
|
59
|
+
if (!id)
|
|
60
|
+
return [{ type: 'text', text: `Error: invalid agent name "${name}".` }];
|
|
61
|
+
if (deps.registry.get(id)) {
|
|
62
|
+
return [{ type: 'text', text: `Error: an agent named "${id}" already exists.` }];
|
|
63
|
+
}
|
|
64
|
+
const file = (0, node_path_1.join)(base, `${id}.md`);
|
|
65
|
+
if ((0, node_fs_1.existsSync)(file))
|
|
66
|
+
return [{ type: 'text', text: `Error: ${file} already exists.` }];
|
|
67
|
+
const frontmatter = { name: id, description };
|
|
68
|
+
if (model)
|
|
69
|
+
frontmatter.model = model;
|
|
70
|
+
if (color)
|
|
71
|
+
frontmatter.color = color;
|
|
72
|
+
if (tools && typeof tools === 'object')
|
|
73
|
+
frontmatter.tools = tools;
|
|
74
|
+
const source = `---\n${(0, mod_js_1.stringify)(frontmatter).trimEnd()}\n---\n\n${prompt.trim()}\n`;
|
|
75
|
+
await (0, promises_1.mkdir)(base, { recursive: true });
|
|
76
|
+
await (0, promises_1.writeFile)(file, source, 'utf-8');
|
|
77
|
+
deps.registry.add((0, parser_js_1.parseAgent)(source, id));
|
|
78
|
+
return [{
|
|
79
|
+
type: 'text',
|
|
80
|
+
text: `Created agent "${id}" at ${file}. It can now be delegated to via the \`subagent\` tool.`,
|
|
81
|
+
}];
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
exports.createAgentWriterTool = createAgentWriterTool;
|
package/script/common/index.d.ts
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a host saves agent-authored definitions (skills, sub-agents, …):
|
|
3
|
+
* - `local` → the current project (repo-first, e.g. `<cwd>/skills`).
|
|
4
|
+
* - `config` → the global config dir, shared across every project.
|
|
5
|
+
*
|
|
6
|
+
* Generic across definition kinds so every writer tool speaks the same vocabulary.
|
|
7
|
+
*/
|
|
8
|
+
export type Scope = 'local' | 'config';
|
package/script/harness/create.js
CHANGED
|
@@ -26,17 +26,19 @@ const TITLE_AGENT = {
|
|
|
26
26
|
tools: [],
|
|
27
27
|
};
|
|
28
28
|
const createHarness = async (options) => {
|
|
29
|
-
const { hostName, xdg, providers, model, agents: hostAgents = [], skills: hostSkills = [], skillScope, title, titleModel, scheduler: enableScheduler = false, approvals, ...sessionDefaults } = options;
|
|
29
|
+
const { hostName, xdg, providers, model, agents: hostAgents = [], skills: hostSkills = [], skillScope, agentScope, agentDirs, title, titleModel, scheduler: enableScheduler = false, approvals, ...sessionDefaults } = options;
|
|
30
30
|
const cwd = options.cwd ?? node_process_1.default.cwd();
|
|
31
31
|
const config = (0, index_js_3.createHarnessConfig)({ hostName, xdg });
|
|
32
32
|
const models = (0, models_js_1.createModelRegistry)({ providers, default: model });
|
|
33
33
|
const pluginsDir = (0, node_path_1.join)(config.configDir, 'plugins');
|
|
34
|
-
const agentsDir = (0, node_path_1.join)(config.configDir, 'agents');
|
|
34
|
+
const agentsDir = agentDirs?.config ?? (0, node_path_1.join)(config.configDir, 'agents');
|
|
35
|
+
const localAgentsDir = agentDirs?.local ?? (0, node_path_1.join)(cwd, 'agents');
|
|
35
36
|
const plugins = (0, index_js_6.createPluginStore)({ dir: pluginsDir });
|
|
36
37
|
const newId = () => crypto.randomUUID();
|
|
37
38
|
const pluginAgents = (sessionDefaults.plugins ?? []).flatMap((plugin) => plugin.agents ?? []);
|
|
39
|
+
const localAgents = await (0, index_js_1.loadAgents)(localAgentsDir);
|
|
38
40
|
const diskAgents = await (0, index_js_1.loadAgents)(agentsDir);
|
|
39
|
-
const agents = (0, index_js_1.createAgentRegistry)([...hostAgents, ...pluginAgents, ...diskAgents]);
|
|
41
|
+
const agents = (0, index_js_1.createAgentRegistry)([...hostAgents, ...pluginAgents, ...localAgents, ...diskAgents]);
|
|
40
42
|
const skillsDir = (0, node_path_1.join)(config.configDir, 'skills');
|
|
41
43
|
const cwdSkillsDir = (0, node_path_1.join)(cwd, 'skills');
|
|
42
44
|
const envBlock = (0, environment_js_1.environmentBlock)({
|
|
@@ -60,6 +62,11 @@ const createHarness = async (options) => {
|
|
|
60
62
|
registry: skills,
|
|
61
63
|
forceScope: skillScope,
|
|
62
64
|
});
|
|
65
|
+
const agentWriterTool = (0, index_js_1.createAgentWriterTool)({
|
|
66
|
+
dirs: { local: localAgentsDir, config: agentsDir },
|
|
67
|
+
registry: agents,
|
|
68
|
+
forceScope: agentScope,
|
|
69
|
+
});
|
|
63
70
|
const scopeSkills = (agent) => {
|
|
64
71
|
if (!agent)
|
|
65
72
|
return skills;
|
|
@@ -74,6 +81,7 @@ const createHarness = async (options) => {
|
|
|
74
81
|
...extra,
|
|
75
82
|
(0, index_js_9.createSkillTool)(scopeSkills(agent)),
|
|
76
83
|
skillWriterTool,
|
|
84
|
+
agentWriterTool,
|
|
77
85
|
...schedulerTools,
|
|
78
86
|
];
|
|
79
87
|
const approvalHook = (getAgent) => approvals
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { Provider } from 'mu-core';
|
|
2
2
|
import type { Agent, AgentRegistry, ToolDecision } from '../agents/index.js';
|
|
3
3
|
import type { CommandRegistry } from '../commands/index.js';
|
|
4
|
+
import type { Scope } from '../common/index.js';
|
|
4
5
|
import type { HarnessConfig, HarnessConfigOptions } from '../config/index.js';
|
|
5
6
|
import type { ApprovalManager } from '../permissions/index.js';
|
|
6
7
|
import type { PluginStore } from '../plugin/index.js';
|
|
7
8
|
import type { Scheduler, TaskStore } from '../scheduler/index.js';
|
|
8
9
|
import type { AgentSessionConfig, SessionManager } from '../session/index.js';
|
|
9
|
-
import type { Skill, SkillRegistry
|
|
10
|
+
import type { Skill, SkillRegistry } from '../skills/index.js';
|
|
10
11
|
import type { SubAgentRegistry, SubAgentResult } from '../subAgents/index.js';
|
|
11
12
|
import type { ModelRegistry } from './models.js';
|
|
12
13
|
export type HarnessOptions = HarnessConfigOptions & Omit<AgentSessionConfig, 'provider' | 'model' | 'id' | 'messages'> & {
|
|
@@ -19,7 +20,20 @@ export type HarnessOptions = HarnessConfigOptions & Omit<AgentSessionConfig, 'pr
|
|
|
19
20
|
* argument is overridden (and dropped from the tool schema). Unset → the
|
|
20
21
|
* model chooses, defaulting to 'local'.
|
|
21
22
|
*/
|
|
22
|
-
skillScope?:
|
|
23
|
+
skillScope?: Scope;
|
|
24
|
+
/**
|
|
25
|
+
* Forces the save location of `create_agent`. Same semantics as
|
|
26
|
+
* {@link skillScope}: set to pin the scope, leave unset to let the model choose.
|
|
27
|
+
*/
|
|
28
|
+
agentScope?: Scope;
|
|
29
|
+
/**
|
|
30
|
+
* Overrides where `create_agent` writes (and which dirs are loaded at boot).
|
|
31
|
+
* Defaults to `{ local: <cwd>/agents, config: <configDir>/agents }`.
|
|
32
|
+
*/
|
|
33
|
+
agentDirs?: {
|
|
34
|
+
local?: string;
|
|
35
|
+
config?: string;
|
|
36
|
+
};
|
|
23
37
|
title?: boolean;
|
|
24
38
|
titleModel?: string;
|
|
25
39
|
cwd?: string;
|
package/script/skills/index.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export { parseSkill } from './parser.js';
|
|
|
4
4
|
export { loadSkills } from './loader.js';
|
|
5
5
|
export { skillMatchesPlatform } from './platform.js';
|
|
6
6
|
export { createSkillTool } from './tool.js';
|
|
7
|
-
export { createSkillWriterTool
|
|
7
|
+
export { createSkillWriterTool } from './writer.js';
|
|
8
8
|
export { createRunSkillTool, runSkill, type RunSkillDeps } from './run.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Tool } from 'mu-core';
|
|
2
|
+
import type { Scope } from '../common/index.js';
|
|
2
3
|
import type { SkillRegistry } from './registry.js';
|
|
3
|
-
export type SkillScope = 'local' | 'config';
|
|
4
4
|
export declare const createSkillWriterTool: (deps: {
|
|
5
|
-
dirs: Record<
|
|
5
|
+
dirs: Record<Scope, string>;
|
|
6
6
|
registry: SkillRegistry;
|
|
7
|
-
forceScope?:
|
|
7
|
+
forceScope?: Scope;
|
|
8
8
|
}) => Tool;
|