@rolexjs/core 0.2.0 → 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.
package/dist/index.d.ts CHANGED
@@ -1,178 +1,197 @@
1
- import { RXR } from "resourcexjs";
2
- /**
3
- * RoleX Core Types
4
- * @rolexjs/core
5
- */
6
- /**
7
- * Rendered Role object
8
- */
9
- interface RenderedRole {
10
- /** Final rendered complete prompt */
11
- readonly prompt: string;
12
- /** Personality section */
13
- readonly personality: string;
14
- /** Principle section */
15
- readonly principle: string;
16
- /** Knowledge section */
17
- readonly knowledge: string;
1
+ import { Scenario as Scenario$1, Feature as Feature$1 } from '@cucumber/messages';
2
+
3
+ /**
4
+ * Scenario — A unit of behavior within a Feature.
5
+ *
6
+ * Extends Gherkin's Scenario with verifiability marking.
7
+ * Verifiable scenarios become persistent test cases.
8
+ * Non-verifiable scenarios are one-time acceptance criteria.
9
+ */
10
+
11
+ /**
12
+ * A Gherkin Scenario enriched with verification metadata.
13
+ */
14
+ interface Scenario extends Scenario$1 {
15
+ readonly verifiable: boolean;
18
16
  }
19
- /**
20
- * Thought sub-tag types
21
- */
22
- type ThoughtSubTag = "exploration" | "reasoning" | "challenge" | "plan";
23
- /**
24
- * Execution sub-tag types
25
- */
26
- type ExecutionSubTag = "process" | "constraint" | "rule" | "guideline" | "criteria";
27
- /**
28
- * Parsed Thought content
29
- */
30
- interface ParsedThought {
31
- readonly exploration?: string;
32
- readonly reasoning?: string;
33
- readonly challenge?: string;
34
- readonly plan?: string;
17
+
18
+ /**
19
+ * Feature — The atomic unit in the RDD model.
20
+ *
21
+ * Extends Gherkin's Feature with RDD dimension classification
22
+ * and explicit Scenario relationship.
23
+ */
24
+
25
+ /**
26
+ * A Gherkin Feature enriched with RDD semantics.
27
+ */
28
+ interface Feature extends Feature$1 {
29
+ readonly type: "persona" | "knowledge" | "experience" | "voice" | "goal" | "plan" | "task";
30
+ readonly scenarios: Scenario[];
35
31
  }
36
- /**
37
- * Parsed Execution content
38
- */
39
- interface ParsedExecution {
40
- readonly process?: string;
41
- readonly constraint?: string;
42
- readonly rule?: string;
43
- readonly guideline?: string;
44
- readonly criteria?: string;
32
+
33
+ /**
34
+ * Identity — The role's complete self.
35
+ *
36
+ * NOT a Feature itself — it is a container that wraps
37
+ * multiple Features (*.identity.feature files).
38
+ * Always loaded, independent of any goal.
39
+ */
40
+
41
+ /**
42
+ * The identity foundation of a role. Wraps many Features.
43
+ */
44
+ interface Identity {
45
+ readonly features: Feature[];
45
46
  }
46
- /**
47
- * Resource resolver function type
48
- */
49
- type ResourceResolver = (src: string) => Promise<string>;
50
- /**
51
- * Load and render a Role from RXR
52
- *
53
- * @param rxr - Role resource (RXL + RXM + RXA)
54
- * @returns Rendered Role object
55
- *
56
- * @example
57
- * ```typescript
58
- * const rx = createResourceX();
59
- * const executable = await rx.use('nuwa.role@1.0.0');
60
- * // Or use loadRole directly with RXR
61
- * const role = await loadRole(rxr);
62
- * console.log(role.prompt);
63
- * ```
64
- */
65
- declare function loadRole(rxr: RXR): Promise<RenderedRole>;
66
- import { BundledType } from "resourcexjs";
67
- /**
68
- * AI Agent Role
69
- */
70
- declare const roleType: BundledType;
71
- /**
72
- * RoleX Error Classes
73
- * @rolexjs/core
74
- */
75
- /**
76
- * Base error class for all RoleX errors
77
- */
78
- declare class RoleXError extends Error {
79
- constructor(message: string, options?: ErrorOptions);
47
+
48
+ /**
49
+ * Goal — The driver of action.
50
+ *
51
+ * A Goal IS-A Feature with type='goal'.
52
+ * Dynamic and phase-specific. What the role wants to achieve.
53
+ * Expressed as *.goal.feature files.
54
+ */
55
+
56
+ /**
57
+ * A goal that a role wants to achieve in a given phase.
58
+ */
59
+ interface Goal extends Feature {
60
+ readonly type: "goal";
80
61
  }
81
- /**
82
- * Error thrown when role loading fails
83
- */
84
- declare class RoleLoadError extends RoleXError {
85
- readonly locator?: string;
86
- constructor(message: string, locator?: string);
62
+
63
+ /**
64
+ * Role — The primary organizing unit in RDD.
65
+ *
66
+ * Every role operates through dimensions:
67
+ * Identity → Goal → Plan → Task/Skill
68
+ *
69
+ * Identity is static (always present).
70
+ * Goals are dynamic (change per phase).
71
+ */
72
+
73
+ /**
74
+ * A role in the RDD (Role-Driven Development) model.
75
+ */
76
+ interface Role {
77
+ readonly name: string;
78
+ readonly identity: Identity;
79
+ readonly goals: Goal[];
87
80
  }
88
- /**
89
- * Error thrown when resource resolution fails
90
- */
91
- declare class ResourceResolveError extends RoleXError {
92
- readonly src?: string;
93
- constructor(message: string, src?: string);
81
+
82
+ /**
83
+ * Plan — The bridge between goal and execution.
84
+ *
85
+ * A Plan IS-A Feature with type='plan'.
86
+ * Expressed as *.plan.feature files.
87
+ */
88
+
89
+ /**
90
+ * A plan that decomposes a goal into executable tasks.
91
+ */
92
+ interface Plan extends Feature {
93
+ readonly type: "plan";
94
94
  }
95
- /**
96
- * Error thrown when DPML parsing fails
97
- */
98
- declare class DPMLParseError extends RoleXError {
99
- constructor(message: string);
95
+
96
+ /**
97
+ * Task — Concrete unit of work within a plan.
98
+ *
99
+ * A Task IS-A Feature with type='task'.
100
+ * Expressed as *.task.feature files.
101
+ */
102
+
103
+ /**
104
+ * A concrete unit of work.
105
+ */
106
+ interface Task extends Feature {
107
+ readonly type: "task";
108
+ }
109
+
110
+ /**
111
+ * Skill — Execution capability for a task.
112
+ *
113
+ * Compatible with existing skill systems:
114
+ * Claude Code skills, ResourceX resources, MCP tools, etc.
115
+ */
116
+ /**
117
+ * A capability that a role uses to execute a task.
118
+ */
119
+ interface Skill {
120
+ /** Skill identifier, e.g. "commit", "bdd", "dev-flow" */
121
+ readonly name: string;
122
+ /** Reference to the concrete implementation: skill path, resource locator, tool URI */
123
+ readonly reference: string;
100
124
  }
101
- import { Schema } from "dpml";
102
- /**
103
- * RoleX schema collection
104
- */
105
- interface RoleSchemas {
106
- readonly role: Schema;
107
- readonly thought: Schema;
108
- readonly execution: Schema;
109
- readonly knowledge: Schema;
125
+
126
+ /**
127
+ * Platform The abstraction layer for role storage.
128
+ *
129
+ * Defines how roles are loaded and persisted.
130
+ * LocalPlatform uses the filesystem (.rolex/ directories).
131
+ * Future platforms could use databases, cloud storage, etc.
132
+ *
133
+ * All methods are stateless — role name is passed per call.
134
+ */
135
+
136
+ /**
137
+ * Role entry in the organization.
138
+ */
139
+ interface RoleEntry {
140
+ readonly name: string;
141
+ readonly team: string;
110
142
  }
111
- import { Schema as Schema2 } from "dpml";
112
- /**
113
- * Create all RoleX schemas
114
- *
115
- * Role structure:
116
- * <role>
117
- * <personality>...</personality>
118
- * <principle>...</principle>
119
- * <knowledge>...</knowledge>
120
- * </role>
121
- */
122
- declare function defineRoleSchemas(): RoleSchemas;
123
- declare const roleSchema: Schema2;
124
- declare const thoughtSchema: Schema2;
125
- declare const executionSchema: Schema2;
126
- declare const knowledgeSchema: Schema2;
127
- /**
128
- * Transformer input interface (compatible with dpml 0.3.0)
129
- */
130
- interface TransformInput {
131
- document: {
132
- rootNode: unknown
133
- nodesById?: Map<string, unknown>
134
- metadata?: Record<string, unknown>
135
- };
136
- isValid?: boolean;
137
- validation?: {
138
- isValid: boolean
139
- errors: unknown[]
140
- warnings: unknown[]
141
- };
142
- resources?: unknown[];
143
+ /**
144
+ * Organization structure.
145
+ */
146
+ interface Organization {
147
+ readonly name: string;
148
+ readonly roles: RoleEntry[];
149
+ }
150
+ /**
151
+ * Society directory — all known roles and organizations.
152
+ */
153
+ interface Directory {
154
+ readonly roles: readonly RoleEntry[];
155
+ readonly organizations: readonly {
156
+ readonly name: string;
157
+ }[];
143
158
  }
144
159
  /**
145
- * Role transformer type
146
- */
147
- interface RoleTransformer {
148
- name: string;
149
- description?: string;
150
- transform(input: TransformInput): RenderedRole;
160
+ * Platform interface — abstracts role storage and retrieval.
161
+ * All methods are stateless — role name identifies the target role.
162
+ */
163
+ interface Platform {
164
+ /** Found an organization */
165
+ found(name: string): void;
166
+ /** Get the organization structure (teams + roles) */
167
+ organization(): Organization;
168
+ /** Create a new role with its persona */
169
+ born(name: string, source: string): Feature;
170
+ /** Hire a role into the organization — establish CAS link */
171
+ hire(name: string): void;
172
+ /** Fire a role from the organization — remove CAS link */
173
+ fire(name: string): void;
174
+ /** Load all identity features for a role */
175
+ identity(roleId: string): Feature[];
176
+ /** Add a growth dimension to a role's identity */
177
+ growup(roleId: string, type: "knowledge" | "experience" | "voice", name: string, source: string): Feature;
178
+ /** Find the current active goal for a role (with plan + tasks context) */
179
+ activeGoal(roleId: string): (Goal & {
180
+ plan: Plan | null;
181
+ tasks: Task[];
182
+ }) | null;
183
+ /** Create a new goal from Gherkin source */
184
+ createGoal(roleId: string, name: string, source: string, testable?: boolean): Goal;
185
+ /** Create a plan for the current active goal */
186
+ createPlan(roleId: string, source: string): Plan;
187
+ /** Create a task for the current active goal */
188
+ createTask(roleId: string, name: string, source: string, testable?: boolean): Task;
189
+ /** Mark the current active goal as done, optionally with experience reflection */
190
+ completeGoal(roleId: string, experience?: string): void;
191
+ /** Abandon the current active goal, optionally with experience reflection */
192
+ abandonGoal(roleId: string, experience?: string): void;
193
+ /** Mark a task as done */
194
+ completeTask(roleId: string, name: string): void;
151
195
  }
152
- import { Transformer } from "dpml";
153
- /**
154
- * Role Transformer
155
- * Transforms DPML role document into RenderedRole
156
- */
157
- declare const roleTransformer: Transformer<{
158
- document: {
159
- rootNode: unknown
160
- }
161
- }, RenderedRole>;
162
- /**
163
- * Create a resource resolver function
164
- *
165
- * Uses ARP with RxrTransport to resolve resource references.
166
- * RxrTransport automatically accesses local/cached resources.
167
- *
168
- * @returns Resource resolver function that accepts ARP URLs
169
- *
170
- * @example
171
- * ```typescript
172
- * const resolver = createResourceResolver();
173
- * const content = await resolver('arp:text:rxr://localhost/my.role@1.0.0/thought/first.thought.md');
174
- * ```
175
- */
176
- declare function createResourceResolver(): ResourceResolver;
177
- declare const VERSION: string;
178
- export { thoughtSchema, roleType, roleTransformer, roleSchema, loadRole, knowledgeSchema, executionSchema, defineRoleSchemas, createResourceResolver, VERSION, ThoughtSubTag, RoleXError, RoleTransformer, RoleSchemas, RoleLoadError, ResourceResolver, ResourceResolveError, RenderedRole, ParsedThought, ParsedExecution, ExecutionSubTag, DPMLParseError };
196
+
197
+ export type { Directory, Feature, Goal, Identity, Organization, Plan, Platform, Role, RoleEntry, Scenario, Skill, Task };
package/dist/index.js CHANGED
@@ -1,425 +1 @@
1
- // src/loader/loadRole.ts
2
- import { createDPML } from "dpml";
3
- import { extract, format } from "resourcexjs";
4
-
5
- // src/schema/defineSchemas.ts
6
- import { defineSchema } from "dpml";
7
- function defineRoleSchemas() {
8
- const role = defineSchema({
9
- element: "role",
10
- children: {
11
- elements: [{ element: "personality" }, { element: "principle" }, { element: "knowledge" }]
12
- }
13
- });
14
- const thought = defineSchema({
15
- element: "thought",
16
- children: {
17
- elements: [
18
- { element: "exploration" },
19
- { element: "reasoning" },
20
- { element: "challenge" },
21
- { element: "plan" }
22
- ]
23
- }
24
- });
25
- const execution = defineSchema({
26
- element: "execution",
27
- children: {
28
- elements: [
29
- { element: "process" },
30
- { element: "constraint" },
31
- { element: "rule" },
32
- { element: "guideline" },
33
- { element: "criteria" }
34
- ]
35
- }
36
- });
37
- const knowledge = defineSchema({
38
- element: "knowledge",
39
- content: { type: "text" }
40
- });
41
- return { role, thought, execution, knowledge };
42
- }
43
- var schemas = defineRoleSchemas();
44
- var roleSchema = schemas.role;
45
- var thoughtSchema = schemas.thought;
46
- var executionSchema = schemas.execution;
47
- var knowledgeSchema = schemas.knowledge;
48
- // src/transformer/roleTransformer.ts
49
- import { defineTransformer } from "dpml";
50
- function extractTextContent(node) {
51
- const parts = [];
52
- if (node.content) {
53
- parts.push(node.content);
54
- }
55
- if (node.children && node.children.length > 0) {
56
- for (const child of node.children) {
57
- if (typeof child === "string") {
58
- parts.push(child);
59
- } else if (child.tagName) {
60
- parts.push(extractTextContent(child));
61
- } else if (child.content) {
62
- parts.push(child.content);
63
- }
64
- }
65
- }
66
- return parts.join(`
67
- `).trim();
68
- }
69
- function findChildByTagName(node, tagName) {
70
- if (!node.children)
71
- return;
72
- for (const child of node.children) {
73
- if (typeof child !== "string" && child.tagName === tagName) {
74
- return child;
75
- }
76
- }
77
- return;
78
- }
79
- function findAllChildrenByTagName(node, tagName) {
80
- if (!node.children)
81
- return [];
82
- const results = [];
83
- for (const child of node.children) {
84
- if (typeof child !== "string" && child.tagName === tagName) {
85
- results.push(child);
86
- }
87
- }
88
- return results;
89
- }
90
- function parseThought(node) {
91
- return {
92
- exploration: findChildByTagName(node, "exploration") ? extractTextContent(findChildByTagName(node, "exploration")) : undefined,
93
- reasoning: findChildByTagName(node, "reasoning") ? extractTextContent(findChildByTagName(node, "reasoning")) : undefined,
94
- challenge: findChildByTagName(node, "challenge") ? extractTextContent(findChildByTagName(node, "challenge")) : undefined,
95
- plan: findChildByTagName(node, "plan") ? extractTextContent(findChildByTagName(node, "plan")) : undefined
96
- };
97
- }
98
- function parseExecution(node) {
99
- return {
100
- process: findChildByTagName(node, "process") ? extractTextContent(findChildByTagName(node, "process")) : undefined,
101
- constraint: findChildByTagName(node, "constraint") ? extractTextContent(findChildByTagName(node, "constraint")) : undefined,
102
- rule: findChildByTagName(node, "rule") ? extractTextContent(findChildByTagName(node, "rule")) : undefined,
103
- guideline: findChildByTagName(node, "guideline") ? extractTextContent(findChildByTagName(node, "guideline")) : undefined,
104
- criteria: findChildByTagName(node, "criteria") ? extractTextContent(findChildByTagName(node, "criteria")) : undefined
105
- };
106
- }
107
- function renderThought(thought) {
108
- const parts = [];
109
- if (thought.exploration)
110
- parts.push(thought.exploration);
111
- if (thought.reasoning)
112
- parts.push(thought.reasoning);
113
- if (thought.challenge)
114
- parts.push(thought.challenge);
115
- if (thought.plan)
116
- parts.push(thought.plan);
117
- return parts.join(`
118
-
119
- `);
120
- }
121
- function renderExecution(execution) {
122
- const parts = [];
123
- if (execution.process)
124
- parts.push(execution.process);
125
- if (execution.constraint)
126
- parts.push(execution.constraint);
127
- if (execution.rule)
128
- parts.push(execution.rule);
129
- if (execution.guideline)
130
- parts.push(execution.guideline);
131
- if (execution.criteria)
132
- parts.push(execution.criteria);
133
- return parts.join(`
134
-
135
- `);
136
- }
137
- var roleTransformer = defineTransformer({
138
- name: "role-transformer",
139
- description: "Transform DPML role document to RenderedRole",
140
- transform(input) {
141
- const doc = input.document;
142
- const rootNode = doc.rootNode;
143
- if (!rootNode || rootNode.tagName !== "role") {
144
- throw new Error("Invalid role document: root element must be <role>");
145
- }
146
- const personalityNode = findChildByTagName(rootNode, "personality");
147
- let personalityContent = "";
148
- const thoughts = [];
149
- if (personalityNode) {
150
- personalityContent = extractTextContent(personalityNode);
151
- const thoughtNodes = findAllChildrenByTagName(personalityNode, "thought");
152
- for (const thoughtNode of thoughtNodes) {
153
- thoughts.push(parseThought(thoughtNode));
154
- }
155
- }
156
- const principleNode = findChildByTagName(rootNode, "principle");
157
- let principleContent = "";
158
- const executions = [];
159
- if (principleNode) {
160
- principleContent = extractTextContent(principleNode);
161
- const executionNodes = findAllChildrenByTagName(principleNode, "execution");
162
- for (const executionNode of executionNodes) {
163
- executions.push(parseExecution(executionNode));
164
- }
165
- }
166
- const knowledgeNode = findChildByTagName(rootNode, "knowledge");
167
- const knowledgeContent = knowledgeNode ? extractTextContent(knowledgeNode) : "";
168
- const personalityParts = [personalityContent];
169
- for (const thought of thoughts) {
170
- const rendered = renderThought(thought);
171
- if (rendered)
172
- personalityParts.push(rendered);
173
- }
174
- const personality = personalityParts.filter(Boolean).join(`
175
-
176
- `);
177
- const principleParts = [principleContent];
178
- for (const execution of executions) {
179
- const rendered = renderExecution(execution);
180
- if (rendered)
181
- principleParts.push(rendered);
182
- }
183
- const principle = principleParts.filter(Boolean).join(`
184
-
185
- `);
186
- const knowledge = knowledgeContent;
187
- const promptParts = [];
188
- if (personality)
189
- promptParts.push(personality);
190
- if (principle)
191
- promptParts.push(principle);
192
- if (knowledge)
193
- promptParts.push(knowledge);
194
- const prompt = promptParts.join(`
195
-
196
- ---
197
-
198
- `);
199
- return { prompt, personality, principle, knowledge };
200
- }
201
- });
202
- // src/resolver/createResourceResolver.ts
203
- import { createARP } from "resourcexjs/arp";
204
-
205
- // src/errors.ts
206
- class RoleXError extends Error {
207
- constructor(message, options) {
208
- super(message, options);
209
- this.name = "RoleXError";
210
- }
211
- }
212
-
213
- class RoleLoadError extends RoleXError {
214
- locator;
215
- constructor(message, locator) {
216
- super(message);
217
- this.locator = locator;
218
- this.name = "RoleLoadError";
219
- }
220
- }
221
-
222
- class ResourceResolveError extends RoleXError {
223
- src;
224
- constructor(message, src) {
225
- super(message);
226
- this.src = src;
227
- this.name = "ResourceResolveError";
228
- }
229
- }
230
-
231
- class DPMLParseError extends RoleXError {
232
- constructor(message) {
233
- super(message);
234
- this.name = "DPMLParseError";
235
- }
236
- }
237
-
238
- // src/resolver/createResourceResolver.ts
239
- function createResourceResolver() {
240
- return async (src) => {
241
- if (!src.startsWith("arp:")) {
242
- throw new ResourceResolveError(`Resource must use ARP format. Expected: arp:semantic:transport://location, got: ${src}`, src);
243
- }
244
- const arp = createARP();
245
- try {
246
- const arl = arp.parse(src);
247
- const resource = await arl.resolve();
248
- if (typeof resource.content === "string") {
249
- return resource.content;
250
- }
251
- if (Buffer.isBuffer(resource.content)) {
252
- return resource.content.toString("utf-8");
253
- }
254
- throw new ResourceResolveError(`Unexpected resource content type for: ${src}`, src);
255
- } catch (error) {
256
- if (error instanceof ResourceResolveError) {
257
- throw error;
258
- }
259
- const message = error instanceof Error ? error.message : String(error);
260
- throw new ResourceResolveError(`Failed to resolve resource: ${message}`, src);
261
- }
262
- };
263
- }
264
- // src/loader/loadRole.ts
265
- async function processResourceTags(content, resolver) {
266
- const resourceTagPattern = /<resource\s+src=["']([^"']+)["']\s*(?:\/>|><\/resource>)/g;
267
- const matches = [];
268
- let match;
269
- while ((match = resourceTagPattern.exec(content)) !== null) {
270
- matches.push({ match: match[0], src: match[1] });
271
- }
272
- if (matches.length === 0) {
273
- return content;
274
- }
275
- const resolutions = await Promise.all(matches.map(async ({ match: match2, src }) => {
276
- const resolvedContent = await resolver(src);
277
- return { match: match2, resolvedContent };
278
- }));
279
- let result = content;
280
- for (const { match: match2, resolvedContent } of resolutions) {
281
- result = result.replace(match2, resolvedContent);
282
- }
283
- return result;
284
- }
285
- async function loadRole(rxr) {
286
- const files = await extract(rxr.archive);
287
- const fileNames = Object.keys(files);
288
- let mainFileName = fileNames.find((f) => f.endsWith(".role.pml"));
289
- if (!mainFileName) {
290
- mainFileName = fileNames.find((f) => f.endsWith(".role.md"));
291
- }
292
- if (!mainFileName) {
293
- throw new RoleLoadError("No .role.pml or .role.md file found in role resource", format(rxr.locator));
294
- }
295
- const mainFileBuffer = files[mainFileName];
296
- if (!mainFileBuffer) {
297
- throw new RoleLoadError(`Failed to read main file: ${mainFileName}`, format(rxr.locator));
298
- }
299
- const mainContent = mainFileBuffer.toString("utf-8");
300
- const resourceResolver = createResourceResolver();
301
- const processedContent = await processResourceTags(mainContent, resourceResolver);
302
- const dpml = createDPML({
303
- schema: roleSchema,
304
- transformers: [roleTransformer]
305
- });
306
- const role = await dpml.compile(processedContent);
307
- return role;
308
- }
309
- // src/loader/simpleRoleLoader.ts
310
- import { extract as extract2, format as format2 } from "resourcexjs";
311
- // src/roleType.ts
312
- var roleType = {
313
- name: "role",
314
- aliases: ["ai-role", "agent-role"],
315
- description: "AI Agent Role",
316
- code: `// @resolver: role_type_default
317
- // src/builtins/role.type.ts
318
- function extractSection(content, tag) {
319
- const regex = new RegExp(\`<\${tag}>([\\\\s\\\\S]*?)</\${tag}>\`, "i");
320
- const match = content.match(regex);
321
- return match ? match[1].trim() : "";
322
- }
323
- function getFile(files, path) {
324
- let buffer = files[path];
325
- if (buffer)
326
- return buffer;
327
- buffer = files[\`./\${path}\`];
328
- if (buffer)
329
- return buffer;
330
- if (path.startsWith("./")) {
331
- buffer = files[path.slice(2)];
332
- if (buffer)
333
- return buffer;
334
- }
335
- return;
336
- }
337
- function resolveReferences(content, files) {
338
- let resolved = content;
339
- const oldStyleRegex = /@!([a-z]+):\\/\\/([a-zA-Z0-9_-]+)/g;
340
- resolved = resolved.replace(oldStyleRegex, (_match, protocol, name) => {
341
- const pmlPath = \`\${protocol}/\${name}.\${protocol}.pml\`;
342
- let fileBuffer = getFile(files, pmlPath);
343
- if (fileBuffer) {
344
- return new TextDecoder().decode(fileBuffer);
345
- }
346
- const mdPath = \`\${protocol}/\${name}.\${protocol}.md\`;
347
- fileBuffer = getFile(files, mdPath);
348
- if (fileBuffer) {
349
- return new TextDecoder().decode(fileBuffer);
350
- }
351
- return "";
352
- });
353
- const resourceRegex = /<resource\\s+src="arp:text:rxr:\\/\\/[^/]+\\/[^/]+@[^/]+\\/([^"]+)"\\s*\\/>/g;
354
- resolved = resolved.replace(resourceRegex, (_match, filePath) => {
355
- const fileBuffer = getFile(files, filePath);
356
- if (!fileBuffer) {
357
- return "";
358
- }
359
- return new TextDecoder().decode(fileBuffer);
360
- });
361
- return resolved.trim();
362
- }
363
- var role_type_default = {
364
- name: "role",
365
- aliases: ["ai-role", "agent-role"],
366
- description: "AI Agent Role",
367
- async resolve(ctx) {
368
- const files = ctx.files;
369
- const fileNames = Object.keys(files);
370
- let mainFileName = fileNames.find((f) => f.endsWith(".role.pml"));
371
- if (!mainFileName) {
372
- mainFileName = fileNames.find((f) => f.endsWith(".role.md"));
373
- }
374
- if (!mainFileName) {
375
- throw new Error("No .role.pml or .role.md file found in role resource");
376
- }
377
- const mainFileBuffer = files[mainFileName];
378
- if (!mainFileBuffer) {
379
- throw new Error(\`Failed to read main file: \${mainFileName}\`);
380
- }
381
- const mainContent = new TextDecoder().decode(mainFileBuffer);
382
- const personality = extractSection(mainContent, "personality");
383
- const principle = extractSection(mainContent, "principle");
384
- const knowledge = extractSection(mainContent, "knowledge");
385
- const resolvedPersonality = resolveReferences(personality, files);
386
- const resolvedPrinciple = resolveReferences(principle, files);
387
- const resolvedKnowledge = resolveReferences(knowledge, files);
388
- const prompt = \`Personality:
389
- \${resolvedPersonality}
390
-
391
- Principle:
392
- \${resolvedPrinciple}
393
-
394
- Knowledge:
395
- \${resolvedKnowledge}\`;
396
- return {
397
- personality: resolvedPersonality,
398
- principle: resolvedPrinciple,
399
- knowledge: resolvedKnowledge,
400
- prompt
401
- };
402
- }
403
- };`
404
- };
405
-
406
- // src/index.ts
407
- var VERSION = "__VERSION__";
408
- export {
409
- thoughtSchema,
410
- roleType,
411
- roleTransformer,
412
- roleSchema,
413
- loadRole,
414
- knowledgeSchema,
415
- executionSchema,
416
- defineRoleSchemas,
417
- createResourceResolver,
418
- VERSION,
419
- RoleXError,
420
- RoleLoadError,
421
- ResourceResolveError,
422
- DPMLParseError
423
- };
424
-
425
- //# debugId=AD50F14DD3C6F7A764756E2164756E21
1
+ //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,17 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/loader/loadRole.ts", "../src/schema/defineSchemas.ts", "../src/transformer/roleTransformer.ts", "../src/resolver/createResourceResolver.ts", "../src/errors.ts", "../src/loader/simpleRoleLoader.ts", "../src/roleType.ts", "../src/index.ts"],
4
- "sourcesContent": [
5
- "/**\n * Load Role\n * Load and render Role resources\n * @rolexjs/core\n */\n\nimport { createDPML } from \"dpml\";\nimport type { RXR } from \"resourcexjs\";\nimport { extract, format } from \"resourcexjs\";\nimport { roleSchema } from \"~/schema/index.js\";\nimport { roleTransformer } from \"~/transformer/index.js\";\nimport { createResourceResolver } from \"~/resolver/index.js\";\nimport { RoleLoadError } from \"~/errors.js\";\nimport type { RenderedRole, ResourceResolver } from \"~/types.js\";\n\n/**\n * Process <resource> tags in content\n * Replace <resource src=\"arp:...\"/> with resolved content\n */\nasync function processResourceTags(content: string, resolver: ResourceResolver): Promise<string> {\n // Match <resource src=\"...\"/> or <resource src=\"...\"></resource>\n const resourceTagPattern = /<resource\\s+src=[\"']([^\"']+)[\"']\\s*(?:\\/>|><\\/resource>)/g;\n\n const matches: Array<{ match: string; src: string }> = [];\n let match;\n\n while ((match = resourceTagPattern.exec(content)) !== null) {\n matches.push({ match: match[0], src: match[1] });\n }\n\n if (matches.length === 0) {\n return content;\n }\n\n // Resolve all resources in parallel\n const resolutions = await Promise.all(\n matches.map(async ({ match, src }) => {\n const resolvedContent = await resolver(src);\n return { match, resolvedContent };\n })\n );\n\n // Replace all resource tags\n let result = content;\n for (const { match, resolvedContent } of resolutions) {\n result = result.replace(match, resolvedContent);\n }\n\n return result;\n}\n\n/**\n * Load and render a Role from RXR\n *\n * @param rxr - Role resource (RXL + RXM + RXA)\n * @returns Rendered Role object\n *\n * @example\n * ```typescript\n * const rx = createResourceX();\n * const executable = await rx.use('nuwa.role@1.0.0');\n * // Or use loadRole directly with RXR\n * const role = await loadRole(rxr);\n * console.log(role.prompt);\n * ```\n */\nexport async function loadRole(rxr: RXR): Promise<RenderedRole> {\n const files = await extract(rxr.archive);\n const fileNames = Object.keys(files);\n\n // 1. Find main file (*.role.pml or *.role.md for backward compatibility)\n let mainFileName = fileNames.find((f) => f.endsWith(\".role.pml\"));\n if (!mainFileName) {\n mainFileName = fileNames.find((f) => f.endsWith(\".role.md\"));\n }\n\n if (!mainFileName) {\n throw new RoleLoadError(\n \"No .role.pml or .role.md file found in role resource\",\n format(rxr.locator)\n );\n }\n\n const mainFileBuffer = files[mainFileName];\n if (!mainFileBuffer) {\n throw new RoleLoadError(`Failed to read main file: ${mainFileName}`, format(rxr.locator));\n }\n\n const mainContent = mainFileBuffer.toString(\"utf-8\");\n\n // 2. Create resource resolver (uses ARP with auto-registered RxrTransport)\n const resourceResolver = createResourceResolver();\n\n // 3. Process resource tags\n const processedContent = await processResourceTags(mainContent, resourceResolver);\n\n // 4. Create DPML and compile\n const dpml = createDPML({\n schema: roleSchema,\n transformers: [roleTransformer],\n });\n\n const role = (await dpml.compile(processedContent)) as RenderedRole;\n\n return role;\n}\n",
6
- "/**\n * Define DPML Schemas for Role\n * @rolexjs/core\n */\n\nimport { defineSchema, type Schema } from \"dpml\";\nimport type { RoleSchemas } from \"./types.js\";\n\n/**\n * Create all RoleX schemas\n *\n * Role structure:\n * <role>\n * <personality>...</personality>\n * <principle>...</principle>\n * <knowledge>...</knowledge>\n * </role>\n */\nexport function defineRoleSchemas(): RoleSchemas {\n const role = defineSchema({\n element: \"role\",\n children: {\n elements: [{ element: \"personality\" }, { element: \"principle\" }, { element: \"knowledge\" }],\n },\n });\n\n const thought = defineSchema({\n element: \"thought\",\n children: {\n elements: [\n { element: \"exploration\" },\n { element: \"reasoning\" },\n { element: \"challenge\" },\n { element: \"plan\" },\n ],\n },\n });\n\n const execution = defineSchema({\n element: \"execution\",\n children: {\n elements: [\n { element: \"process\" },\n { element: \"constraint\" },\n { element: \"rule\" },\n { element: \"guideline\" },\n { element: \"criteria\" },\n ],\n },\n });\n\n const knowledge = defineSchema({\n element: \"knowledge\",\n content: { type: \"text\" },\n });\n\n return { role, thought, execution, knowledge };\n}\n\n// Default schemas instance\nconst schemas: RoleSchemas = defineRoleSchemas();\n\nexport const roleSchema: Schema = schemas.role;\nexport const thoughtSchema: Schema = schemas.thought;\nexport const executionSchema: Schema = schemas.execution;\nexport const knowledgeSchema: Schema = schemas.knowledge;\n",
7
- "/**\n * Role Transformer\n * Transform DPML document to RenderedRole\n * @rolexjs/core\n */\n\nimport { defineTransformer, type Transformer } from \"dpml\";\nimport type { RenderedRole, ParsedThought, ParsedExecution } from \"~/types.js\";\n\n/**\n * DPML Node interface (compatible with dpml 0.3.0)\n */\ninterface DPMLNode {\n tagName?: string;\n attributes?: Record<string, string>;\n children?: Array<DPMLNode | string>;\n content?: string;\n}\n\n/**\n * Extract text content from a node\n * DPML 0.3.0: text content is in node.content, child elements are in node.children\n */\nfunction extractTextContent(node: DPMLNode): string {\n const parts: string[] = [];\n\n // Add node's own text content first\n if (node.content) {\n parts.push(node.content);\n }\n\n // Then add children's content\n if (node.children && node.children.length > 0) {\n for (const child of node.children) {\n if (typeof child === \"string\") {\n parts.push(child);\n } else if (child.tagName) {\n // Element node - recursively extract\n parts.push(extractTextContent(child));\n } else if (child.content) {\n // Text node with content\n parts.push(child.content);\n }\n }\n }\n\n return parts.join(\"\\n\").trim();\n}\n\n/**\n * Find child node by tag name\n */\nfunction findChildByTagName(node: DPMLNode, tagName: string): DPMLNode | undefined {\n if (!node.children) return undefined;\n\n for (const child of node.children) {\n if (typeof child !== \"string\" && child.tagName === tagName) {\n return child;\n }\n }\n\n return undefined;\n}\n\n/**\n * Find all children by tag name\n */\nfunction findAllChildrenByTagName(node: DPMLNode, tagName: string): DPMLNode[] {\n if (!node.children) return [];\n\n const results: DPMLNode[] = [];\n\n for (const child of node.children) {\n if (typeof child !== \"string\" && child.tagName === tagName) {\n results.push(child);\n }\n }\n\n return results;\n}\n\n/**\n * Parse thought node into ParsedThought\n */\nfunction parseThought(node: DPMLNode): ParsedThought {\n return {\n exploration: findChildByTagName(node, \"exploration\")\n ? extractTextContent(findChildByTagName(node, \"exploration\")!)\n : undefined,\n reasoning: findChildByTagName(node, \"reasoning\")\n ? extractTextContent(findChildByTagName(node, \"reasoning\")!)\n : undefined,\n challenge: findChildByTagName(node, \"challenge\")\n ? extractTextContent(findChildByTagName(node, \"challenge\")!)\n : undefined,\n plan: findChildByTagName(node, \"plan\")\n ? extractTextContent(findChildByTagName(node, \"plan\")!)\n : undefined,\n };\n}\n\n/**\n * Parse execution node into ParsedExecution\n */\nfunction parseExecution(node: DPMLNode): ParsedExecution {\n return {\n process: findChildByTagName(node, \"process\")\n ? extractTextContent(findChildByTagName(node, \"process\")!)\n : undefined,\n constraint: findChildByTagName(node, \"constraint\")\n ? extractTextContent(findChildByTagName(node, \"constraint\")!)\n : undefined,\n rule: findChildByTagName(node, \"rule\")\n ? extractTextContent(findChildByTagName(node, \"rule\")!)\n : undefined,\n guideline: findChildByTagName(node, \"guideline\")\n ? extractTextContent(findChildByTagName(node, \"guideline\")!)\n : undefined,\n criteria: findChildByTagName(node, \"criteria\")\n ? extractTextContent(findChildByTagName(node, \"criteria\")!)\n : undefined,\n };\n}\n\n/**\n * Render thought to text\n */\nfunction renderThought(thought: ParsedThought): string {\n const parts: string[] = [];\n\n if (thought.exploration) parts.push(thought.exploration);\n if (thought.reasoning) parts.push(thought.reasoning);\n if (thought.challenge) parts.push(thought.challenge);\n if (thought.plan) parts.push(thought.plan);\n\n return parts.join(\"\\n\\n\");\n}\n\n/**\n * Render execution to text\n */\nfunction renderExecution(execution: ParsedExecution): string {\n const parts: string[] = [];\n\n if (execution.process) parts.push(execution.process);\n if (execution.constraint) parts.push(execution.constraint);\n if (execution.rule) parts.push(execution.rule);\n if (execution.guideline) parts.push(execution.guideline);\n if (execution.criteria) parts.push(execution.criteria);\n\n return parts.join(\"\\n\\n\");\n}\n\n/**\n * Role Transformer\n * Transforms DPML role document into RenderedRole\n */\nexport const roleTransformer: Transformer<{ document: { rootNode: unknown } }, RenderedRole> =\n defineTransformer({\n name: \"role-transformer\",\n description: \"Transform DPML role document to RenderedRole\",\n\n transform(input: { document: { rootNode: unknown } }): RenderedRole {\n const doc = input.document;\n const rootNode = doc.rootNode as DPMLNode;\n\n if (!rootNode || rootNode.tagName !== \"role\") {\n throw new Error(\"Invalid role document: root element must be <role>\");\n }\n\n // 1. Parse personality section\n const personalityNode = findChildByTagName(rootNode, \"personality\");\n let personalityContent = \"\";\n const thoughts: ParsedThought[] = [];\n\n if (personalityNode) {\n personalityContent = extractTextContent(personalityNode);\n const thoughtNodes = findAllChildrenByTagName(personalityNode, \"thought\");\n for (const thoughtNode of thoughtNodes) {\n thoughts.push(parseThought(thoughtNode));\n }\n }\n\n // 2. Parse principle section\n const principleNode = findChildByTagName(rootNode, \"principle\");\n let principleContent = \"\";\n const executions: ParsedExecution[] = [];\n\n if (principleNode) {\n principleContent = extractTextContent(principleNode);\n const executionNodes = findAllChildrenByTagName(principleNode, \"execution\");\n for (const executionNode of executionNodes) {\n executions.push(parseExecution(executionNode));\n }\n }\n\n // 3. Parse knowledge section\n const knowledgeNode = findChildByTagName(rootNode, \"knowledge\");\n const knowledgeContent = knowledgeNode ? extractTextContent(knowledgeNode) : \"\";\n\n // 4. Render each section\n const personalityParts = [personalityContent];\n for (const thought of thoughts) {\n const rendered = renderThought(thought);\n if (rendered) personalityParts.push(rendered);\n }\n const personality = personalityParts.filter(Boolean).join(\"\\n\\n\");\n\n const principleParts = [principleContent];\n for (const execution of executions) {\n const rendered = renderExecution(execution);\n if (rendered) principleParts.push(rendered);\n }\n const principle = principleParts.filter(Boolean).join(\"\\n\\n\");\n\n const knowledge = knowledgeContent;\n\n // 5. Assemble final prompt\n const promptParts: string[] = [];\n if (personality) promptParts.push(personality);\n if (principle) promptParts.push(principle);\n if (knowledge) promptParts.push(knowledge);\n\n const prompt = promptParts.join(\"\\n\\n---\\n\\n\");\n\n return { prompt, personality, principle, knowledge };\n },\n });\n",
8
- "/**\n * Create Resource Resolver\n * Resolve resource references via ARP protocol\n * @rolexjs/core\n */\n\nimport { createARP } from \"resourcexjs/arp\";\nimport type { ResourceResolver } from \"~/types.js\";\nimport { ResourceResolveError } from \"~/errors.js\";\n\n/**\n * Create a resource resolver function\n *\n * Uses ARP with RxrTransport to resolve resource references.\n * RxrTransport automatically accesses local/cached resources.\n *\n * @returns Resource resolver function that accepts ARP URLs\n *\n * @example\n * ```typescript\n * const resolver = createResourceResolver();\n * const content = await resolver('arp:text:rxr://localhost/my.role@1.0.0/thought/first.thought.md');\n * ```\n */\nexport function createResourceResolver(): ResourceResolver {\n return async (src: string): Promise<string> => {\n // 1. Validate ARP format\n if (!src.startsWith(\"arp:\")) {\n throw new ResourceResolveError(\n `Resource must use ARP format. Expected: arp:semantic:transport://location, got: ${src}`,\n src\n );\n }\n\n // 2. Create ARP instance (RxrTransport is auto-registered)\n const arp = createARP();\n\n // 3. Parse and resolve\n try {\n const arl = arp.parse(src);\n const resource = await arl.resolve();\n\n // 4. Convert to string\n if (typeof resource.content === \"string\") {\n return resource.content;\n }\n\n if (Buffer.isBuffer(resource.content)) {\n return resource.content.toString(\"utf-8\");\n }\n\n throw new ResourceResolveError(`Unexpected resource content type for: ${src}`, src);\n } catch (error) {\n if (error instanceof ResourceResolveError) {\n throw error;\n }\n const message = error instanceof Error ? error.message : String(error);\n throw new ResourceResolveError(`Failed to resolve resource: ${message}`, src);\n }\n };\n}\n",
9
- "/**\n * RoleX Error Classes\n * @rolexjs/core\n */\n\n/**\n * Base error class for all RoleX errors\n */\nexport class RoleXError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = \"RoleXError\";\n }\n}\n\n/**\n * Error thrown when role loading fails\n */\nexport class RoleLoadError extends RoleXError {\n constructor(\n message: string,\n public readonly locator?: string\n ) {\n super(message);\n this.name = \"RoleLoadError\";\n }\n}\n\n/**\n * Error thrown when resource resolution fails\n */\nexport class ResourceResolveError extends RoleXError {\n constructor(\n message: string,\n public readonly src?: string\n ) {\n super(message);\n this.name = \"ResourceResolveError\";\n }\n}\n\n/**\n * Error thrown when DPML parsing fails\n */\nexport class DPMLParseError extends RoleXError {\n constructor(message: string) {\n super(message);\n this.name = \"DPMLParseError\";\n }\n}\n",
10
- "/**\n * Simple Role Loader\n * Simple role loader without DPML, uses direct text replacement\n * Uses ARP stateless resource reference resolution\n */\n\nimport type { RXR } from \"resourcexjs\";\nimport { extract, format } from \"resourcexjs\";\nimport type { RenderedRole } from \"~/types.js\";\nimport { RoleLoadError } from \"~/errors.js\";\n\n/**\n * Simple role loading (without DPML)\n * 1. Read files from RXR\n * 2. Parse @!protocol://path references (from internal files)\n * 3. Simple text concatenation\n */\nexport async function loadRoleSimple(rxr: RXR): Promise<RenderedRole> {\n const files = await extract(rxr.archive);\n const fileNames = Object.keys(files);\n\n // 1. Find main file\n let mainFileName = fileNames.find((f) => f.endsWith(\".role.pml\"));\n if (!mainFileName) {\n mainFileName = fileNames.find((f) => f.endsWith(\".role.md\"));\n }\n\n if (!mainFileName) {\n throw new RoleLoadError(\"No .role.pml or .role.md file found\", format(rxr.locator));\n }\n\n const mainFileBuffer = files[mainFileName];\n if (!mainFileBuffer) {\n throw new RoleLoadError(`Failed to read main file: ${mainFileName}`, format(rxr.locator));\n }\n\n const mainContent = mainFileBuffer.toString(\"utf-8\");\n\n // 2. Extract three sections\n const personality = extractSection(mainContent, \"personality\");\n const principle = extractSection(mainContent, \"principle\");\n const knowledge = extractSection(mainContent, \"knowledge\");\n\n // 3. Resolve references (from internal files)\n const resolvedPersonality = resolveReferences(personality, files);\n const resolvedPrinciple = resolveReferences(principle, files);\n const resolvedKnowledge = resolveReferences(knowledge, files);\n\n // 4. Build final prompt\n const prompt = `Personality:\\n${resolvedPersonality}\\n\\nPrinciple:\\n${resolvedPrinciple}\\n\\nKnowledge:\\n${resolvedKnowledge}`;\n\n return {\n personality: resolvedPersonality,\n principle: resolvedPrinciple,\n knowledge: resolvedKnowledge,\n prompt,\n };\n}\n\n/**\n * Extract section content\n */\nfunction extractSection(content: string, tag: string): string {\n const regex = new RegExp(`<${tag}>([\\\\s\\\\S]*?)</${tag}>`, \"i\");\n const match = content.match(regex);\n return match ? match[1].trim() : \"\";\n}\n\n/**\n * Get file from files, supporting with/without ./ prefix\n */\nfunction getFile(files: Record<string, Buffer>, path: string): Buffer | undefined {\n // Try original path\n let buffer = files[path];\n if (buffer) return buffer;\n\n // Try with ./ prefix\n buffer = files[`./${path}`];\n if (buffer) return buffer;\n\n // Try without ./ prefix\n if (path.startsWith(\"./\")) {\n buffer = files[path.slice(2)];\n if (buffer) return buffer;\n }\n\n return undefined;\n}\n\n/**\n * Resolve references and replace\n * Supports:\n * - @!thought://xxx\n * - <resource src=\"arp:text:rxr://domain/name@version/path/file.pml\"/>\n */\nfunction resolveReferences(content: string, files: Record<string, Buffer>): string {\n let resolved = content;\n\n // 1. Handle @!protocol://path format\n const oldStyleRegex = /@!([a-z]+):\\/\\/([a-zA-Z0-9_-]+)/g;\n resolved = resolved.replace(oldStyleRegex, (_match, protocol, name) => {\n // Try .pml suffix\n const pmlPath = `${protocol}/${name}.${protocol}.pml`;\n let fileBuffer = getFile(files, pmlPath);\n if (fileBuffer) {\n return fileBuffer.toString(\"utf-8\");\n }\n\n // Try .md suffix\n const mdPath = `${protocol}/${name}.${protocol}.md`;\n fileBuffer = getFile(files, mdPath);\n if (fileBuffer) {\n return fileBuffer.toString(\"utf-8\");\n }\n\n console.warn(`Referenced file not found: ${pmlPath} or ${mdPath}`);\n return \"\";\n });\n\n // 2. Handle <resource src=\"...\"/> format\n const resourceRegex = /<resource\\s+src=\"arp:text:rxr:\\/\\/[^/]+\\/[^/]+@[^/]+\\/([^\"]+)\"\\s*\\/>/g;\n resolved = resolved.replace(resourceRegex, (_match, filePath) => {\n const fileBuffer = getFile(files, filePath);\n if (!fileBuffer) {\n console.warn(`Referenced file not found: ${filePath}`);\n return \"\";\n }\n return fileBuffer.toString(\"utf-8\");\n });\n\n return resolved.trim();\n}\n",
11
- "/**\n * Role Resource Type (pre-bundled)\n * Auto-generated by build.ts - DO NOT EDIT\n *\n * Resolver code receives ResolveContext (ctx) with:\n * - ctx.manifest: { registry?, path?, name, type, version }\n * - ctx.files: Record<string, Uint8Array>\n */\n\nimport type { BundledType } from \"resourcexjs\";\n\n/**\n * AI Agent Role\n */\nexport const roleType: BundledType = {\n name: \"role\",\n aliases: [\"ai-role\",\"agent-role\"],\n description: \"AI Agent Role\",\n code: `// @resolver: role_type_default\n// src/builtins/role.type.ts\nfunction extractSection(content, tag) {\n const regex = new RegExp(\\`<\\${tag}>([\\\\\\\\s\\\\\\\\S]*?)</\\${tag}>\\`, \"i\");\n const match = content.match(regex);\n return match ? match[1].trim() : \"\";\n}\nfunction getFile(files, path) {\n let buffer = files[path];\n if (buffer)\n return buffer;\n buffer = files[\\`./\\${path}\\`];\n if (buffer)\n return buffer;\n if (path.startsWith(\"./\")) {\n buffer = files[path.slice(2)];\n if (buffer)\n return buffer;\n }\n return;\n}\nfunction resolveReferences(content, files) {\n let resolved = content;\n const oldStyleRegex = /@!([a-z]+):\\\\/\\\\/([a-zA-Z0-9_-]+)/g;\n resolved = resolved.replace(oldStyleRegex, (_match, protocol, name) => {\n const pmlPath = \\`\\${protocol}/\\${name}.\\${protocol}.pml\\`;\n let fileBuffer = getFile(files, pmlPath);\n if (fileBuffer) {\n return new TextDecoder().decode(fileBuffer);\n }\n const mdPath = \\`\\${protocol}/\\${name}.\\${protocol}.md\\`;\n fileBuffer = getFile(files, mdPath);\n if (fileBuffer) {\n return new TextDecoder().decode(fileBuffer);\n }\n return \"\";\n });\n const resourceRegex = /<resource\\\\s+src=\"arp:text:rxr:\\\\/\\\\/[^/]+\\\\/[^/]+@[^/]+\\\\/([^\"]+)\"\\\\s*\\\\/>/g;\n resolved = resolved.replace(resourceRegex, (_match, filePath) => {\n const fileBuffer = getFile(files, filePath);\n if (!fileBuffer) {\n return \"\";\n }\n return new TextDecoder().decode(fileBuffer);\n });\n return resolved.trim();\n}\nvar role_type_default = {\n name: \"role\",\n aliases: [\"ai-role\", \"agent-role\"],\n description: \"AI Agent Role\",\n async resolve(ctx) {\n const files = ctx.files;\n const fileNames = Object.keys(files);\n let mainFileName = fileNames.find((f) => f.endsWith(\".role.pml\"));\n if (!mainFileName) {\n mainFileName = fileNames.find((f) => f.endsWith(\".role.md\"));\n }\n if (!mainFileName) {\n throw new Error(\"No .role.pml or .role.md file found in role resource\");\n }\n const mainFileBuffer = files[mainFileName];\n if (!mainFileBuffer) {\n throw new Error(\\`Failed to read main file: \\${mainFileName}\\`);\n }\n const mainContent = new TextDecoder().decode(mainFileBuffer);\n const personality = extractSection(mainContent, \"personality\");\n const principle = extractSection(mainContent, \"principle\");\n const knowledge = extractSection(mainContent, \"knowledge\");\n const resolvedPersonality = resolveReferences(personality, files);\n const resolvedPrinciple = resolveReferences(principle, files);\n const resolvedKnowledge = resolveReferences(knowledge, files);\n const prompt = \\`Personality:\n\\${resolvedPersonality}\n\nPrinciple:\n\\${resolvedPrinciple}\n\nKnowledge:\n\\${resolvedKnowledge}\\`;\n return {\n personality: resolvedPersonality,\n principle: resolvedPrinciple,\n knowledge: resolvedKnowledge,\n prompt\n };\n }\n};`,\n};\n",
12
- "/**\n * @rolexjs/core\n * RoleX Core - AI Agent Role Management Framework\n *\n * RoleX is a DPML domain implementation for AI Agent Role resources.\n * It provides parsing, rendering, and ResourceX integration.\n */\n\n// ========== Core API ==========\n\nexport { loadRole } from \"./loader/index.js\";\n\n// BundledType for ResourceX integration (auto-generated)\nexport { roleType } from \"./roleType.js\";\n\n// ========== Types ==========\n\nexport type {\n RenderedRole,\n ParsedThought,\n ParsedExecution,\n ThoughtSubTag,\n ExecutionSubTag,\n ResourceResolver,\n} from \"./types.js\";\n\n// ========== Errors ==========\n\nexport { RoleXError, RoleLoadError, ResourceResolveError, DPMLParseError } from \"./errors.js\";\n\n// ========== Schema ==========\n\nexport type { RoleSchemas } from \"./schema/index.js\";\nexport {\n defineRoleSchemas,\n roleSchema,\n thoughtSchema,\n executionSchema,\n knowledgeSchema,\n} from \"./schema/index.js\";\n\n// ========== Transformer ==========\n\nexport type { RoleTransformer } from \"./transformer/index.js\";\nexport { roleTransformer } from \"./transformer/index.js\";\n\n// ========== Resolver ==========\n\nexport { createResourceResolver } from \"./resolver/index.js\";\n\n// ========== Version ==========\n\nexport const VERSION: string = \"__VERSION__\";\n"
13
- ],
14
- "mappings": ";AAMA;AAEA;;;ACHA;AAaO,SAAS,iBAAiB,GAAgB;AAAA,EAC/C,MAAM,OAAO,aAAa;AAAA,IACxB,SAAS;AAAA,IACT,UAAU;AAAA,MACR,UAAU,CAAC,EAAE,SAAS,cAAc,GAAG,EAAE,SAAS,YAAY,GAAG,EAAE,SAAS,YAAY,CAAC;AAAA,IAC3F;AAAA,EACF,CAAC;AAAA,EAED,MAAM,UAAU,aAAa;AAAA,IAC3B,SAAS;AAAA,IACT,UAAU;AAAA,MACR,UAAU;AAAA,QACR,EAAE,SAAS,cAAc;AAAA,QACzB,EAAE,SAAS,YAAY;AAAA,QACvB,EAAE,SAAS,YAAY;AAAA,QACvB,EAAE,SAAS,OAAO;AAAA,MACpB;AAAA,IACF;AAAA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AAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwFR;;;ACtDO,IAAM,UAAkB;",
15
- "debugId": "AD50F14DD3C6F7A764756E2164756E21",
16
- "names": []
17
- }
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rolexjs/core",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "RoleX Core - AI Agent Role Management Framework",
5
5
  "keywords": [
6
6
  "rolex",
@@ -31,17 +31,16 @@
31
31
  "README.md"
32
32
  ],
33
33
  "scripts": {
34
- "build": "bun run build.ts",
34
+ "build": "tsup",
35
35
  "test": "bun test || true",
36
36
  "lint": "eslint .",
37
37
  "typecheck": "tsc --noEmit",
38
38
  "clean": "rm -rf dist"
39
39
  },
40
- "dependencies": {
41
- "dpml": "^0.3.0",
42
- "resourcexjs": "^2.5.3"
40
+ "dependencies": {},
41
+ "devDependencies": {
42
+ "@cucumber/messages": "^32.0.1"
43
43
  },
44
- "devDependencies": {},
45
44
  "publishConfig": {
46
45
  "access": "public"
47
46
  }