@clawmasons/shared 0.1.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/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/role/adapter.d.ts +29 -0
- package/dist/role/adapter.d.ts.map +1 -0
- package/dist/role/adapter.js +149 -0
- package/dist/role/adapter.js.map +1 -0
- package/dist/role/discovery.d.ts +38 -0
- package/dist/role/discovery.d.ts.map +1 -0
- package/dist/role/discovery.js +209 -0
- package/dist/role/discovery.js.map +1 -0
- package/dist/role/index.d.ts.map +1 -0
- package/dist/role/index.js +13 -0
- package/dist/role/index.js.map +1 -0
- package/dist/role/package-reader.d.ts +30 -0
- package/dist/role/package-reader.d.ts.map +1 -0
- package/dist/role/package-reader.js +223 -0
- package/dist/role/package-reader.js.map +1 -0
- package/dist/role/parser.d.ts +45 -0
- package/dist/role/parser.d.ts.map +1 -0
- package/dist/role/parser.js +241 -0
- package/dist/role/parser.js.map +1 -0
- package/dist/role/resource-scanner.d.ts +16 -0
- package/dist/role/resource-scanner.d.ts.map +1 -0
- package/dist/role/resource-scanner.js +43 -0
- package/dist/role/resource-scanner.js.map +1 -0
- package/dist/schemas/index.d.ts +7 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/index.js +8 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/schemas/role-types.d.ts +564 -0
- package/dist/schemas/role-types.d.ts.map +1 -0
- package/dist/schemas/role-types.js +93 -0
- package/dist/schemas/role-types.js.map +1 -0
- package/dist/toolfilter.d.ts.map +1 -0
- package/dist/toolfilter.js +55 -0
- package/dist/toolfilter.js.map +1 -0
- package/dist/types/role.d.ts +14 -0
- package/dist/types/role.d.ts.map +1 -0
- package/dist/types/role.js +2 -0
- package/dist/types/role.js.map +1 -0
- package/dist/types.d.ts +106 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +29 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { appChapterFieldSchema, type AppChapterField, skillChapterFieldSchema, type SkillChapterField, taskChapterFieldSchema, type TaskChapterField, roleChapterFieldSchema, type RoleChapterField, parseChapterField, type ChapterField, } from "./schemas/index.js";
|
|
2
|
+
export { toolPermissionsSchema, roleMetadataSchema, taskRefSchema, skillRefSchema, appConfigSchema, mountConfigSchema, containerRequirementsSchema, governanceConfigSchema, resourceFileSchema, roleSourceSchema, roleSchema, } from "./schemas/index.js";
|
|
3
|
+
export type { Role, RoleMetadata, TaskRef, AppConfig, SkillRef, ContainerRequirements, GovernanceConfig, ResourceFile, RoleSource, MountConfig, ToolPermissions, } from "./types/role.js";
|
|
4
|
+
export type { DiscoveredPackage, ResolvedAgent, ResolvedApp, ResolvedRole, ResolvedSkill, ResolvedTask, } from "./types.js";
|
|
5
|
+
export { computeToolFilters, getAppShortName, type ToolFilter, } from "./toolfilter.js";
|
|
6
|
+
export { registerDialect, getDialect, getDialectByDirectory, getAllDialects, getKnownDirectories, type DialectEntry, type DialectFieldMapping, readMaterializedRole, parseFrontmatter, detectDialect, RoleParseError, scanBundledResources, readPackagedRole, PackageReadError, adaptRoleToResolvedAgent, AdapterError, discoverRoles, resolveRole, RoleDiscoveryError, } from "./role/index.js";
|
|
7
|
+
export { scanProject, type ScanResult, type DiscoveredSkill, type DiscoveredCommand, type DiscoveredMcpServer, proposeRoleMd, type ProposeOptions, } from "./mason/index.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,KAAK,eAAe,EACpB,uBAAuB,EACvB,KAAK,iBAAiB,EACtB,sBAAsB,EACtB,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,KAAK,gBAAgB,EACrB,iBAAiB,EACjB,KAAK,YAAY,GAClB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,2BAA2B,EAC3B,sBAAsB,EACtB,kBAAkB,EAClB,gBAAgB,EAChB,UAAU,GACX,MAAM,oBAAoB,CAAC;AAG5B,YAAY,EACV,IAAI,EACJ,YAAY,EACZ,OAAO,EACP,SAAS,EACT,QAAQ,EACR,qBAAqB,EACrB,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,WAAW,EACX,eAAe,GAChB,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,YAAY,EACZ,aAAa,EACb,YAAY,GACb,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,KAAK,UAAU,GAChB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,eAAe,EACf,UAAU,EACV,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,oBAAoB,EACpB,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,wBAAwB,EACxB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,WAAW,EACX,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,aAAa,EACb,KAAK,cAAc,GACpB,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Schemas
|
|
2
|
+
export { appChapterFieldSchema, skillChapterFieldSchema, taskChapterFieldSchema, roleChapterFieldSchema, parseChapterField, } from "./schemas/index.js";
|
|
3
|
+
// ROLE_TYPES schemas
|
|
4
|
+
export { toolPermissionsSchema, roleMetadataSchema, taskRefSchema, skillRefSchema, appConfigSchema, mountConfigSchema, containerRequirementsSchema, governanceConfigSchema, resourceFileSchema, roleSourceSchema, roleSchema, } from "./schemas/index.js";
|
|
5
|
+
// Tool filtering
|
|
6
|
+
export { computeToolFilters, getAppShortName, } from "./toolfilter.js";
|
|
7
|
+
// Role module (dialect registry, parser, resource scanner)
|
|
8
|
+
export { registerDialect, getDialect, getDialectByDirectory, getAllDialects, getKnownDirectories, readMaterializedRole, parseFrontmatter, detectDialect, RoleParseError, scanBundledResources, readPackagedRole, PackageReadError, adaptRoleToResolvedAgent, AdapterError, discoverRoles, resolveRole, RoleDiscoveryError, } from "./role/index.js";
|
|
9
|
+
// Mason module (project scanner, ROLE.md proposer)
|
|
10
|
+
export { scanProject, proposeRoleMd, } from "./mason/index.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,OAAO,EACL,qBAAqB,EAErB,uBAAuB,EAEvB,sBAAsB,EAEtB,sBAAsB,EAEtB,iBAAiB,GAElB,MAAM,oBAAoB,CAAC;AAE5B,qBAAqB;AACrB,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,2BAA2B,EAC3B,sBAAsB,EACtB,kBAAkB,EAClB,gBAAgB,EAChB,UAAU,GACX,MAAM,oBAAoB,CAAC;AA2B5B,iBAAiB;AACjB,OAAO,EACL,kBAAkB,EAClB,eAAe,GAEhB,MAAM,iBAAiB,CAAC;AAEzB,2DAA2D;AAC3D,OAAO,EACL,eAAe,EACf,UAAU,EACV,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EAGnB,oBAAoB,EACpB,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,wBAAwB,EACxB,YAAY,EACZ,aAAa,EACb,WAAW,EACX,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAEzB,mDAAmD;AACnD,OAAO,EACL,WAAW,EAKX,aAAa,GAEd,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Role-to-ResolvedAgent Adapter
|
|
3
|
+
*
|
|
4
|
+
* Converts a Role (ROLE_TYPES pipeline) into the existing ResolvedAgent
|
|
5
|
+
* shape that materializers already accept. This is the key migration bridge:
|
|
6
|
+
* it lets the new role-based pipeline feed into existing materializers without
|
|
7
|
+
* rewriting them.
|
|
8
|
+
*
|
|
9
|
+
* The adapter is stateless — it performs a pure data transformation with no
|
|
10
|
+
* side effects or I/O.
|
|
11
|
+
*/
|
|
12
|
+
import type { Role } from "../types/role.js";
|
|
13
|
+
import type { ResolvedAgent } from "../types.js";
|
|
14
|
+
/**
|
|
15
|
+
* Error thrown when the adapter cannot convert a Role.
|
|
16
|
+
*/
|
|
17
|
+
export declare class AdapterError extends Error {
|
|
18
|
+
constructor(message: string);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Convert a Role into a ResolvedAgent that existing materializers accept.
|
|
22
|
+
*
|
|
23
|
+
* @param role - A validated Role from the ROLE_TYPES pipeline
|
|
24
|
+
* @param agentType - The target agent dialect name (e.g., "claude-code", "codex", "aider")
|
|
25
|
+
* @returns A ResolvedAgent suitable for passing to any RuntimeMaterializer
|
|
26
|
+
* @throws AdapterError if agentType does not match a registered dialect
|
|
27
|
+
*/
|
|
28
|
+
export declare function adaptRoleToResolvedAgent(role: Role, agentType: string): ResolvedAgent;
|
|
29
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/role/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,IAAI,EAIL,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,aAAa,EAKd,MAAM,aAAa,CAAC;AAGrB;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,MAAM,GAChB,aAAa,CAgCf"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Role-to-ResolvedAgent Adapter
|
|
3
|
+
*
|
|
4
|
+
* Converts a Role (ROLE_TYPES pipeline) into the existing ResolvedAgent
|
|
5
|
+
* shape that materializers already accept. This is the key migration bridge:
|
|
6
|
+
* it lets the new role-based pipeline feed into existing materializers without
|
|
7
|
+
* rewriting them.
|
|
8
|
+
*
|
|
9
|
+
* The adapter is stateless — it performs a pure data transformation with no
|
|
10
|
+
* side effects or I/O.
|
|
11
|
+
*/
|
|
12
|
+
import { getDialect } from "./dialect-registry.js";
|
|
13
|
+
/**
|
|
14
|
+
* Error thrown when the adapter cannot convert a Role.
|
|
15
|
+
*/
|
|
16
|
+
export class AdapterError extends Error {
|
|
17
|
+
constructor(message) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = "AdapterError";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Convert a Role into a ResolvedAgent that existing materializers accept.
|
|
24
|
+
*
|
|
25
|
+
* @param role - A validated Role from the ROLE_TYPES pipeline
|
|
26
|
+
* @param agentType - The target agent dialect name (e.g., "claude-code", "codex", "aider")
|
|
27
|
+
* @returns A ResolvedAgent suitable for passing to any RuntimeMaterializer
|
|
28
|
+
* @throws AdapterError if agentType does not match a registered dialect
|
|
29
|
+
*/
|
|
30
|
+
export function adaptRoleToResolvedAgent(role, agentType) {
|
|
31
|
+
// Validate agent type against dialect registry
|
|
32
|
+
const dialect = getDialect(agentType);
|
|
33
|
+
if (!dialect) {
|
|
34
|
+
throw new AdapterError(`Unknown agent type "${agentType}". Must be a registered dialect (e.g., "claude-code", "codex", "aider", "mcp-agent").`);
|
|
35
|
+
}
|
|
36
|
+
const name = role.metadata.name;
|
|
37
|
+
const version = role.metadata.version ?? "0.0.0";
|
|
38
|
+
// Build the single ResolvedRole from the Role
|
|
39
|
+
const resolvedRole = buildResolvedRole(role, version);
|
|
40
|
+
// Build the top-level ResolvedAgent
|
|
41
|
+
const agent = {
|
|
42
|
+
name,
|
|
43
|
+
version,
|
|
44
|
+
agentName: name,
|
|
45
|
+
slug: name,
|
|
46
|
+
description: role.metadata.description,
|
|
47
|
+
runtimes: [agentType],
|
|
48
|
+
credentials: [...(role.governance.credentials ?? [])],
|
|
49
|
+
roles: [resolvedRole],
|
|
50
|
+
proxy: {
|
|
51
|
+
port: 9090,
|
|
52
|
+
type: "streamable-http",
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
return agent;
|
|
56
|
+
}
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
// Internal mapping functions
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
function buildResolvedRole(role, version) {
|
|
61
|
+
const permissions = aggregatePermissions(role.apps);
|
|
62
|
+
const tasks = role.tasks.map((t) => adaptTask(t, role.instructions));
|
|
63
|
+
const apps = role.apps.map(adaptApp);
|
|
64
|
+
const skills = role.skills.map(adaptSkill);
|
|
65
|
+
const resolvedRole = {
|
|
66
|
+
name: role.metadata.name,
|
|
67
|
+
version,
|
|
68
|
+
description: role.metadata.description,
|
|
69
|
+
instructions: role.instructions,
|
|
70
|
+
risk: role.governance.risk ?? "LOW",
|
|
71
|
+
permissions,
|
|
72
|
+
tasks,
|
|
73
|
+
apps,
|
|
74
|
+
skills,
|
|
75
|
+
};
|
|
76
|
+
// Container requirements → ResolvedRole fields
|
|
77
|
+
if (role.container) {
|
|
78
|
+
const aptPackages = role.container.packages?.apt;
|
|
79
|
+
if (aptPackages && aptPackages.length > 0) {
|
|
80
|
+
resolvedRole.aptPackages = aptPackages;
|
|
81
|
+
}
|
|
82
|
+
if (role.container.baseImage) {
|
|
83
|
+
resolvedRole.baseImage = role.container.baseImage;
|
|
84
|
+
}
|
|
85
|
+
const mounts = role.container.mounts;
|
|
86
|
+
if (mounts && mounts.length > 0) {
|
|
87
|
+
resolvedRole.mounts = mounts.map((m) => ({
|
|
88
|
+
source: m.source,
|
|
89
|
+
target: m.target,
|
|
90
|
+
readonly: m.readonly ?? false,
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Governance constraints
|
|
95
|
+
if (role.governance.constraints) {
|
|
96
|
+
resolvedRole.constraints = {
|
|
97
|
+
...role.governance.constraints,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
return resolvedRole;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Aggregate tool permissions from all apps into the permissions map
|
|
104
|
+
* that ResolvedRole expects: { [appName]: { allow: string[], deny: string[] } }
|
|
105
|
+
*/
|
|
106
|
+
function aggregatePermissions(apps) {
|
|
107
|
+
const permissions = {};
|
|
108
|
+
for (const app of apps) {
|
|
109
|
+
permissions[app.name] = {
|
|
110
|
+
allow: [...(app.tools?.allow ?? [])],
|
|
111
|
+
deny: [...(app.tools?.deny ?? [])],
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return permissions;
|
|
115
|
+
}
|
|
116
|
+
function adaptTask(task, instructions) {
|
|
117
|
+
return {
|
|
118
|
+
name: task.name,
|
|
119
|
+
version: "0.0.0",
|
|
120
|
+
taskType: "subagent",
|
|
121
|
+
prompt: instructions,
|
|
122
|
+
apps: [],
|
|
123
|
+
skills: [],
|
|
124
|
+
subTasks: [],
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function adaptApp(app) {
|
|
128
|
+
return {
|
|
129
|
+
name: app.name,
|
|
130
|
+
version: "0.0.0",
|
|
131
|
+
transport: app.transport ?? "stdio",
|
|
132
|
+
command: app.command,
|
|
133
|
+
args: app.args,
|
|
134
|
+
url: app.url,
|
|
135
|
+
env: app.env ? { ...app.env } : undefined,
|
|
136
|
+
tools: [...(app.tools?.allow ?? [])],
|
|
137
|
+
capabilities: [],
|
|
138
|
+
credentials: [...(app.credentials ?? [])],
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function adaptSkill(skill) {
|
|
142
|
+
return {
|
|
143
|
+
name: skill.name,
|
|
144
|
+
version: "0.0.0",
|
|
145
|
+
artifacts: [],
|
|
146
|
+
description: skill.name,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/role/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAeH,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CACtC,IAAU,EACV,SAAiB;IAEjB,+CAA+C;IAC/C,MAAM,OAAO,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;IACtC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,YAAY,CACpB,uBAAuB,SAAS,uFAAuF,CACxH,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAChC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC;IAEjD,8CAA8C;IAC9C,MAAM,YAAY,GAAG,iBAAiB,CAAC,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
|
2
|
+
* Unified Role Discovery — finds roles from all sources, merges with
|
|
3
|
+
* precedence rules, and presents a unified list.
|
|
4
|
+
*
|
|
5
|
+
* Discovery sources (in precedence order):
|
|
6
|
+
* 1. Local roles: <projectDir>/.<agent>/roles/* /ROLE.md
|
|
7
|
+
* 2. Packaged roles: node_modules packages with chapter.type === "role"
|
|
8
|
+
*
|
|
9
|
+
* Local roles shadow packaged roles with the same name, enabling the
|
|
10
|
+
* "eject and customize" workflow (PRD §6.3).
|
|
11
|
+
*/
|
|
12
|
+
import type { Role } from "../types/role.js";
|
|
13
|
+
/**
|
|
14
|
+
* Error thrown when role discovery or resolution fails.
|
|
15
|
+
*/
|
|
16
|
+
export declare class RoleDiscoveryError extends Error {
|
|
17
|
+
constructor(message: string);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Discover all available roles from local agent directories and installed
|
|
21
|
+
* NPM packages. Local roles take precedence over packaged roles with the
|
|
22
|
+
* same name.
|
|
23
|
+
*
|
|
24
|
+
* @param projectDir - Absolute path to the project root
|
|
25
|
+
* @returns Array of validated Role objects (deduplicated by name)
|
|
26
|
+
*/
|
|
27
|
+
export declare function discoverRoles(projectDir: string): Promise<Role[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Resolve a single role by name using the same precedence rules as
|
|
30
|
+
* discoverRoles. Checks local roles first, then packaged roles.
|
|
31
|
+
*
|
|
32
|
+
* @param name - Role name to resolve
|
|
33
|
+
* @param projectDir - Absolute path to the project root
|
|
34
|
+
* @returns Validated Role
|
|
35
|
+
* @throws RoleDiscoveryError if the role is not found
|
|
36
|
+
*/
|
|
37
|
+
export declare function resolveRole(name: string, projectDir: string): Promise<Role>;
|
|
38
|
+
//# sourceMappingURL=discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../src/role/discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAkBvE;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAYf"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified Role Discovery — finds roles from all sources, merges with
|
|
3
|
+
* precedence rules, and presents a unified list.
|
|
4
|
+
*
|
|
5
|
+
* Discovery sources (in precedence order):
|
|
6
|
+
* 1. Local roles: <projectDir>/.<agent>/roles/* /ROLE.md
|
|
7
|
+
* 2. Packaged roles: node_modules packages with chapter.type === "role"
|
|
8
|
+
*
|
|
9
|
+
* Local roles shadow packaged roles with the same name, enabling the
|
|
10
|
+
* "eject and customize" workflow (PRD §6.3).
|
|
11
|
+
*/
|
|
12
|
+
import { readdir, readFile, stat } from "node:fs/promises";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { readMaterializedRole } from "./parser.js";
|
|
15
|
+
import { readPackagedRole } from "./package-reader.js";
|
|
16
|
+
/**
|
|
17
|
+
* Error thrown when role discovery or resolution fails.
|
|
18
|
+
*/
|
|
19
|
+
export class RoleDiscoveryError extends Error {
|
|
20
|
+
constructor(message) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = "RoleDiscoveryError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Discover all available roles from local agent directories and installed
|
|
27
|
+
* NPM packages. Local roles take precedence over packaged roles with the
|
|
28
|
+
* same name.
|
|
29
|
+
*
|
|
30
|
+
* @param projectDir - Absolute path to the project root
|
|
31
|
+
* @returns Array of validated Role objects (deduplicated by name)
|
|
32
|
+
*/
|
|
33
|
+
export async function discoverRoles(projectDir) {
|
|
34
|
+
const localRoles = await discoverLocalRoles(projectDir);
|
|
35
|
+
const packagedRoles = await discoverPackagedRoles(projectDir);
|
|
36
|
+
// Merge: local roles take precedence over packaged roles with the same name
|
|
37
|
+
const merged = new Map();
|
|
38
|
+
// Add packaged roles first (lower precedence)
|
|
39
|
+
for (const role of packagedRoles) {
|
|
40
|
+
merged.set(role.metadata.name, role);
|
|
41
|
+
}
|
|
42
|
+
// Add local roles second (higher precedence — overwrites packaged)
|
|
43
|
+
for (const role of localRoles) {
|
|
44
|
+
merged.set(role.metadata.name, role);
|
|
45
|
+
}
|
|
46
|
+
return [...merged.values()];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Resolve a single role by name using the same precedence rules as
|
|
50
|
+
* discoverRoles. Checks local roles first, then packaged roles.
|
|
51
|
+
*
|
|
52
|
+
* @param name - Role name to resolve
|
|
53
|
+
* @param projectDir - Absolute path to the project root
|
|
54
|
+
* @returns Validated Role
|
|
55
|
+
* @throws RoleDiscoveryError if the role is not found
|
|
56
|
+
*/
|
|
57
|
+
export async function resolveRole(name, projectDir) {
|
|
58
|
+
// 1. Check local roles first (higher precedence)
|
|
59
|
+
const localRole = await findLocalRole(name, projectDir);
|
|
60
|
+
if (localRole)
|
|
61
|
+
return localRole;
|
|
62
|
+
// 2. Check packaged roles
|
|
63
|
+
const packagedRole = await findPackagedRole(name, projectDir);
|
|
64
|
+
if (packagedRole)
|
|
65
|
+
return packagedRole;
|
|
66
|
+
throw new RoleDiscoveryError(`Role "${name}" not found. It is not a local role and is not installed as a package.`);
|
|
67
|
+
}
|
|
68
|
+
// ---------------------------------------------------------------------------
|
|
69
|
+
// Local role discovery
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
/**
|
|
72
|
+
* Scan .mason/roles/ for local ROLE.md files.
|
|
73
|
+
* Silently skips the directory if it doesn't exist.
|
|
74
|
+
*/
|
|
75
|
+
async function discoverLocalRoles(projectDir) {
|
|
76
|
+
const roles = [];
|
|
77
|
+
const rolesDir = join(projectDir, ".mason", "roles");
|
|
78
|
+
let entries;
|
|
79
|
+
try {
|
|
80
|
+
entries = await readdir(rolesDir);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
// .mason/roles/ doesn't exist — no local roles
|
|
84
|
+
return roles;
|
|
85
|
+
}
|
|
86
|
+
for (const entry of entries) {
|
|
87
|
+
const roleMdPath = join(rolesDir, entry, "ROLE.md");
|
|
88
|
+
try {
|
|
89
|
+
const s = await stat(roleMdPath);
|
|
90
|
+
if (!s.isFile())
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// No ROLE.md in this subdirectory — skip
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const role = await readMaterializedRole(roleMdPath);
|
|
99
|
+
roles.push(role);
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
103
|
+
console.warn(`[mason] Skipping invalid ROLE.md at ${roleMdPath}: ${msg}`);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return roles;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Find a specific local role by name in .mason/roles/.
|
|
111
|
+
*/
|
|
112
|
+
async function findLocalRole(name, projectDir) {
|
|
113
|
+
const roleMdPath = join(projectDir, ".mason", "roles", name, "ROLE.md");
|
|
114
|
+
try {
|
|
115
|
+
const s = await stat(roleMdPath);
|
|
116
|
+
if (!s.isFile())
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
return await readMaterializedRole(roleMdPath);
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
127
|
+
console.warn(`[mason] Invalid ROLE.md at ${roleMdPath}: ${msg}`);
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
// Packaged role discovery
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
/**
|
|
135
|
+
* Scan node_modules for packages with chapter.type === "role".
|
|
136
|
+
* Checks both top-level and scoped package directories.
|
|
137
|
+
*/
|
|
138
|
+
async function discoverPackagedRoles(projectDir) {
|
|
139
|
+
const roles = [];
|
|
140
|
+
const nodeModulesDir = join(projectDir, "node_modules");
|
|
141
|
+
let topLevel;
|
|
142
|
+
try {
|
|
143
|
+
topLevel = await readdir(nodeModulesDir);
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
// No node_modules — no packaged roles
|
|
147
|
+
return roles;
|
|
148
|
+
}
|
|
149
|
+
const packageDirs = [];
|
|
150
|
+
for (const entry of topLevel) {
|
|
151
|
+
if (entry.startsWith("."))
|
|
152
|
+
continue;
|
|
153
|
+
const entryPath = join(nodeModulesDir, entry);
|
|
154
|
+
if (entry.startsWith("@")) {
|
|
155
|
+
// Scoped packages: read the scope directory
|
|
156
|
+
let scopedEntries;
|
|
157
|
+
try {
|
|
158
|
+
scopedEntries = await readdir(entryPath);
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
for (const scopedEntry of scopedEntries) {
|
|
164
|
+
if (!scopedEntry.startsWith(".")) {
|
|
165
|
+
packageDirs.push(join(entryPath, scopedEntry));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
packageDirs.push(entryPath);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
for (const pkgDir of packageDirs) {
|
|
174
|
+
if (await isRolePackage(pkgDir)) {
|
|
175
|
+
try {
|
|
176
|
+
const role = await readPackagedRole(pkgDir);
|
|
177
|
+
roles.push(role);
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
// Malformed package — skip during discovery
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return roles;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Find a specific packaged role by name.
|
|
189
|
+
*/
|
|
190
|
+
async function findPackagedRole(name, projectDir) {
|
|
191
|
+
// First, try to find it among all packaged roles
|
|
192
|
+
const packagedRoles = await discoverPackagedRoles(projectDir);
|
|
193
|
+
return packagedRoles.find((r) => r.metadata.name === name);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Check if a directory is an NPM package with chapter.type === "role".
|
|
197
|
+
*/
|
|
198
|
+
async function isRolePackage(pkgDir) {
|
|
199
|
+
const pkgJsonPath = join(pkgDir, "package.json");
|
|
200
|
+
try {
|
|
201
|
+
const raw = await readFile(pkgJsonPath, "utf-8");
|
|
202
|
+
const pkg = JSON.parse(raw);
|
|
203
|
+
return pkg.chapter?.type === "role";
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=discovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/role/discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAe;QACzB,KAAK,CAAC,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AAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QACjD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAEzB,CAAC;QACF,OAAO,GAAG,CAAC,OAAO,EAAE,IAAI,KAAK,MAAM,CAAC;IACtC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/role/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,eAAe,EACf,UAAU,EACV,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,KAAK,YAAY,EACjB,KAAK,mBAAmB,GACzB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,aAAa,EACb,cAAc,GACf,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAG7D,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGzE,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGtE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Dialect Registry
|
|
2
|
+
export { registerDialect, getDialect, getDialectByDirectory, getAllDialects, getKnownDirectories, } from "./dialect-registry.js";
|
|
3
|
+
// Parser
|
|
4
|
+
export { readMaterializedRole, parseFrontmatter, detectDialect, RoleParseError, } from "./parser.js";
|
|
5
|
+
// Resource Scanner
|
|
6
|
+
export { scanBundledResources } from "./resource-scanner.js";
|
|
7
|
+
// Package Reader
|
|
8
|
+
export { readPackagedRole, PackageReadError } from "./package-reader.js";
|
|
9
|
+
// Adapter
|
|
10
|
+
export { adaptRoleToResolvedAgent, AdapterError } from "./adapter.js";
|
|
11
|
+
// Discovery
|
|
12
|
+
export { discoverRoles, resolveRole, RoleDiscoveryError } from "./discovery.js";
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/role/index.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,EACL,eAAe,EACf,UAAU,EACV,qBAAqB,EACrB,cAAc,EACd,mBAAmB,GAGpB,MAAM,uBAAuB,CAAC;AAE/B,SAAS;AACT,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,aAAa,EACb,cAAc,GACf,MAAM,aAAa,CAAC;AAErB,mBAAmB;AACnB,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE7D,iBAAiB;AACjB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEzE,UAAU;AACV,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEtE,YAAY;AACZ,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package Reader — reads an NPM role package and produces a Role object.
|
|
3
|
+
*
|
|
4
|
+
* Steps:
|
|
5
|
+
* 1. Read package.json and verify chapter.type === "role"
|
|
6
|
+
* 2. Read the bundled ROLE.md from the package directory
|
|
7
|
+
* 3. Parse frontmatter and body (reuses parseFrontmatter from parser.ts)
|
|
8
|
+
* 4. Normalize fields using dialect mapping if chapter.dialect is specified,
|
|
9
|
+
* otherwise use generic ROLE_TYPES field names directly
|
|
10
|
+
* 5. Resolve all paths relative to the package directory
|
|
11
|
+
* 6. Set source.type = 'package' and source.packageName
|
|
12
|
+
* 7. Validate through roleSchema
|
|
13
|
+
*/
|
|
14
|
+
import type { Role } from "../types/role.js";
|
|
15
|
+
/**
|
|
16
|
+
* Error thrown when a role NPM package cannot be read.
|
|
17
|
+
*/
|
|
18
|
+
export declare class PackageReadError extends Error {
|
|
19
|
+
readonly packagePath: string;
|
|
20
|
+
constructor(message: string, packagePath: string);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Read an NPM role package and produce a validated Role object.
|
|
24
|
+
*
|
|
25
|
+
* @param packagePath - Absolute path to the package directory (e.g., node_modules/@acme/role-create-prd)
|
|
26
|
+
* @returns Validated Role with source.type = 'package'
|
|
27
|
+
* @throws PackageReadError if the package is missing required files or has wrong chapter.type
|
|
28
|
+
*/
|
|
29
|
+
export declare function readPackagedRole(packagePath: string): Promise<Role>;
|
|
30
|
+
//# sourceMappingURL=package-reader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-reader.d.ts","sourceRoot":"","sources":["../../src/role/package-reader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAK7C;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;aAGvB,WAAW,EAAE,MAAM;gBADnC,OAAO,EAAE,MAAM,EACC,WAAW,EAAE,MAAM;CAKtC;AA2BD;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAwFzE"}
|