@rolexjs/prototype 0.12.0-dev-20260228032306

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.js ADDED
@@ -0,0 +1,1205 @@
1
+ // src/descriptions/index.ts
2
+ var processes = {
3
+ "born": "Feature: born \u2014 create a new individual\n Create a new individual with persona identity.\n The persona defines who the role is \u2014 personality, values, background.\n\n Scenario: Birth an individual\n Given a Gherkin source describing the persona\n When born is called with the source\n Then a new individual node is created in society\n And the persona is stored as the individual's information\n And the individual can be hired into organizations\n And the individual can be activated to start working\n\n Scenario: Writing the individual Gherkin\n Given the individual Feature defines a persona \u2014 who this role is\n Then the Feature title names the individual\n And the description captures personality, values, expertise, and background\n And Scenarios are optional \u2014 use them for distinct aspects of the persona",
4
+ "die": "Feature: die \u2014 permanently remove an individual\n Permanently remove an individual.\n Unlike retire, this is irreversible.\n\n Scenario: Remove an individual permanently\n Given an individual exists\n When die is called on the individual\n Then the individual and all associated data are removed\n And this operation is irreversible",
5
+ "rehire": "Feature: rehire \u2014 restore a retired individual\n Rehire a retired individual.\n Restores the individual with full history and knowledge intact.\n\n Scenario: Rehire an individual\n Given a retired individual exists\n When rehire is called on the individual\n Then the individual is restored to active status\n And all previous data and knowledge are intact",
6
+ "retire": "Feature: retire \u2014 archive an individual\n Archive an individual \u2014 deactivate but preserve all data.\n A retired individual can be rehired later with full history intact.\n\n Scenario: Retire an individual\n Given an individual exists\n When retire is called on the individual\n Then the individual is deactivated\n And all data is preserved for potential restoration\n And the individual can be rehired later",
7
+ "teach": 'Feature: teach \u2014 inject external principle\n Directly inject a principle into an individual.\n Unlike realize which consumes experience, teach requires no prior encounters.\n Use teach to equip a role with a known, pre-existing principle.\n\n Scenario: Teach a principle\n Given an individual exists\n When teach is called with individual id, principle Gherkin, and a principle id\n Then a principle is created directly under the individual\n And no experience or encounter is consumed\n And if a principle with the same id already exists, it is replaced\n\n Scenario: Principle ID convention\n Given the id is keywords from the principle content joined by hyphens\n Then "Always validate expiry" becomes id "always-validate-expiry"\n And "Structure first design" becomes id "structure-first-design"\n\n Scenario: When to use teach vs realize\n Given realize distills internal experience into a principle\n And teach injects an external, pre-existing principle\n When a role needs knowledge it has not learned through experience\n Then use teach to inject the principle directly\n When a role has gained experience and wants to codify it\n Then use realize to distill it into a principle\n\n Scenario: Writing the principle Gherkin\n Given the principle is the same format as realize output\n Then the Feature title states the principle as a general rule\n And Scenarios describe different situations where this principle applies\n And the tone is universal \u2014 no mention of specific projects, tasks, or people',
8
+ "train": `Feature: train \u2014 external skill injection
9
+ A manager or external agent equips an individual with a procedure.
10
+ This is an act of teaching \u2014 someone else decides what the role should know.
11
+ Unlike master where the role grows by its own agency, train is done to the role from outside.
12
+
13
+ Scenario: Train a procedure
14
+ Given an individual exists
15
+ When train is called with individual id, procedure Gherkin, and a procedure id
16
+ Then a procedure is created directly under the individual
17
+ And if a procedure with the same id already exists, it is replaced
18
+
19
+ Scenario: Procedure ID convention
20
+ Given the id is keywords from the procedure content joined by hyphens
21
+ Then "Skill Creator" becomes id "skill-creator"
22
+ And "Role Management" becomes id "role-management"
23
+
24
+ Scenario: When to use train vs master
25
+ Given both create procedures and both can work without consuming experience
26
+ When the role itself decides to acquire a skill \u2014 use master (self-growth)
27
+ And when an external agent equips the role \u2014 use train (external injection)
28
+ Then the difference is perspective \u2014 who initiates the learning
29
+ And master belongs to the role namespace (the role's own cognition)
30
+ And train belongs to the individual namespace (external management)
31
+
32
+ Scenario: Writing the procedure Gherkin
33
+ Given the procedure is a skill reference \u2014 same format as master output
34
+ Then the Feature title names the capability
35
+ And the description includes the locator for full skill loading
36
+ And Scenarios describe when and why to apply this skill`,
37
+ "charter": "Feature: charter \u2014 define organizational charter\n Define the charter for an organization.\n The charter describes the organization's mission, principles, and governance rules.\n\n Scenario: Define a charter\n Given an organization exists\n And a Gherkin source describing the charter\n When charter is called on the organization\n Then the charter is stored as the organization's information\n\n Scenario: Writing the charter Gherkin\n Given the charter defines an organization's mission and governance\n Then the Feature title names the charter or the organization it governs\n And Scenarios describe principles, rules, or governance structures\n And the tone is declarative \u2014 stating what the organization stands for and how it operates",
38
+ "dissolve": "Feature: dissolve \u2014 dissolve an organization\n Dissolve an organization.\n All positions, charter entries, and assignments are cascaded.\n\n Scenario: Dissolve an organization\n Given an organization exists\n When dissolve is called on the organization\n Then all positions within the organization are abolished\n And all assignments and charter entries are removed\n And the organization no longer exists",
39
+ "fire": "Feature: fire \u2014 remove from an organization\n Fire an individual from an organization.\n The individual is dismissed from all positions and removed from the organization.\n\n Scenario: Fire an individual\n Given an individual is a member of an organization\n When fire is called with the organization and individual\n Then the individual is dismissed from all positions\n And the individual is removed from the organization",
40
+ "found": "Feature: found \u2014 create a new organization\n Found a new organization.\n Organizations group individuals and define positions.\n\n Scenario: Found an organization\n Given a Gherkin source describing the organization\n When found is called with the source\n Then a new organization node is created in society\n And positions can be established within it\n And a charter can be defined for it\n And individuals can be hired into it\n\n Scenario: Writing the organization Gherkin\n Given the organization Feature describes the group's purpose and structure\n Then the Feature title names the organization\n And the description captures mission, domain, and scope\n And Scenarios are optional \u2014 use them for distinct organizational concerns",
41
+ "hire": "Feature: hire \u2014 hire into an organization\n Hire an individual into an organization as a member.\n Members can then be appointed to positions.\n\n Scenario: Hire an individual\n Given an organization and an individual exist\n When hire is called with the organization and individual\n Then the individual becomes a member of the organization\n And the individual can be appointed to positions within the organization",
42
+ "abolish": "Feature: abolish \u2014 abolish a position\n Abolish a position.\n All duties and appointments associated with the position are removed.\n\n Scenario: Abolish a position\n Given a position exists\n When abolish is called on the position\n Then all duties and appointments are removed\n And the position no longer exists",
43
+ "appoint": "Feature: appoint \u2014 assign to a position\n Appoint an individual to a position.\n The individual must be a member of the organization.\n\n Scenario: Appoint an individual\n Given an individual is a member of an organization\n And a position exists within the organization\n When appoint is called with the position and individual\n Then the individual holds the position\n And the individual inherits the position's duties",
44
+ "charge": `Feature: charge \u2014 assign duty to a position
45
+ Assign a duty to a position.
46
+ Duties describe the responsibilities and expectations of a position.
47
+
48
+ Scenario: Charge a position with duty
49
+ Given a position exists within an organization
50
+ And a Gherkin source describing the duty
51
+ When charge is called on the position with a duty id
52
+ Then the duty is stored as the position's information
53
+ And individuals appointed to this position inherit the duty
54
+
55
+ Scenario: Duty ID convention
56
+ Given the id is keywords from the duty content joined by hyphens
57
+ Then "Design systems" becomes id "design-systems"
58
+ And "Review pull requests" becomes id "review-pull-requests"
59
+
60
+ Scenario: Writing the duty Gherkin
61
+ Given the duty defines responsibilities for a position
62
+ Then the Feature title names the duty or responsibility
63
+ And Scenarios describe specific obligations, deliverables, or expectations
64
+ And the tone is prescriptive \u2014 what must be done, not what could be done`,
65
+ "dismiss": "Feature: dismiss \u2014 remove from a position\n Dismiss an individual from a position.\n The individual remains a member of the organization.\n\n Scenario: Dismiss an individual\n Given an individual holds a position\n When dismiss is called with the position and individual\n Then the individual no longer holds the position\n And the individual remains a member of the organization\n And the position is now vacant",
66
+ "establish": "Feature: establish \u2014 create a position\n Create a position as an independent entity.\n Positions define roles and can be charged with duties.\n\n Scenario: Establish a position\n Given a Gherkin source describing the position\n When establish is called with the position content\n Then a new position entity is created\n And the position can be charged with duties\n And individuals can be appointed to it\n\n Scenario: Writing the position Gherkin\n Given the position Feature describes a role\n Then the Feature title names the position\n And the description captures responsibilities, scope, and expectations\n And Scenarios are optional \u2014 use them for distinct aspects of the role",
67
+ "settle": "Feature: settle \u2014 register a prototype into the world\n Pull a prototype from a ResourceX source and register it locally.\n Once settled, the prototype can be used to create individuals or organizations.\n\n Scenario: Settle a prototype\n Given a valid ResourceX source exists (URL, path, or locator)\n When settle is called with the source\n Then the resource is ingested and its state is extracted\n And the prototype is registered locally by its id\n And the prototype is available for born, activate, and organizational use",
68
+ "abandon": "Feature: abandon \u2014 abandon a plan\n Mark a plan as dropped and create an encounter.\n Call this when a plan's strategy is no longer viable. Even failed plans produce learning.\n\n Scenario: Abandon a plan\n Given a focused plan exists\n And the plan's strategy is no longer viable\n When abandon is called\n Then the plan is tagged #abandoned and stays in the tree\n And an encounter is created under the role\n And the encounter can be reflected on \u2014 failure is also learning\n\n Scenario: Writing the encounter Gherkin\n Given the encounter records what happened \u2014 even failure is a raw experience\n Then the Feature title describes what was attempted and why it was abandoned\n And Scenarios capture what was tried, what went wrong, and what was learned\n And the tone is concrete and honest \u2014 failure produces the richest encounters",
69
+ "activate": "Feature: activate \u2014 enter a role\n Project the individual's full state including identity, goals,\n and organizational context. This is the entry point for working as a role.\n\n Scenario: Activate an individual\n Given an individual exists in society\n When activate is called with the individual reference\n Then the full state tree is projected\n And identity, goals, and organizational context are loaded\n And the individual becomes the active role",
70
+ "complete": "Feature: complete \u2014 complete a plan\n Mark a plan as done and create an encounter.\n Call this when all tasks in the plan are finished and the strategy succeeded.\n\n Scenario: Complete a plan\n Given a focused plan exists\n And its tasks are done\n When complete is called\n Then the plan is tagged #done and stays in the tree\n And an encounter is created under the role\n And the encounter can be reflected on for learning\n\n Scenario: Writing the encounter Gherkin\n Given the encounter records what happened \u2014 a raw account of the experience\n Then the Feature title describes what was accomplished by this plan\n And Scenarios capture what the strategy was, what worked, and what resulted\n And the tone is concrete and specific \u2014 tied to this particular plan",
71
+ "direct": 'Feature: direct \u2014 stateless world-level executor\n Execute commands and load resources without an active role.\n Direct operates as an anonymous observer \u2014 no role identity, no role context.\n For operations as an active role, use the use tool instead.\n\n Scenario: When to use "direct" vs "use"\n Given no role is activated \u2014 I am an observer\n When I need to query or operate on the world\n Then direct is the right tool\n And once a role is activated, use the use tool for role-level actions\n\n Scenario: Execute a RoleX command\n Given the locator starts with `!`\n When direct is called with the locator and named args\n Then the command is parsed as `namespace.method`\n And dispatched to the corresponding RoleX API\n\n Scenario: Load a ResourceX resource\n Given the locator does not start with `!`\n When direct is called with the locator\n Then the locator is passed to ResourceX for resolution\n And the resource is loaded and returned',
72
+ "finish": "Feature: finish \u2014 complete a task\n Mark a task as done and create an encounter.\n The encounter records what happened and can be reflected on for learning.\n\n Scenario: Finish a task\n Given a task exists\n When finish is called on the task\n Then the task is tagged #done and stays in the tree\n And an encounter is created under the role\n\n Scenario: Finish with experience\n Given a task is completed with a notable learning\n When finish is called with an optional experience parameter\n Then the experience text is attached to the encounter\n\n Scenario: Finish without encounter\n Given a task is completed with no notable learning\n When finish is called without the encounter parameter\n Then the task is tagged #done but no encounter is created\n And the task stays in the tree \u2014 visible via focus on the parent goal\n\n Scenario: Writing the encounter Gherkin\n Given the encounter records what happened \u2014 a raw account of the experience\n Then the Feature title describes what was done\n And Scenarios capture what was done, what was encountered, and what resulted\n And the tone is concrete and specific \u2014 tied to this particular task",
73
+ "focus": "Feature: focus \u2014 view or switch focused goal\n View the current goal's state, or switch focus to a different goal.\n Subsequent plan and todo operations target the focused goal.\n\n Scenario: View current goal\n Given an active goal exists\n When focus is called without a name\n Then the current goal's state tree is projected\n And plans and tasks under the goal are visible\n\n Scenario: Switch focus\n Given multiple goals exist\n When focus is called with a goal name\n Then the focused goal switches to the named goal\n And subsequent plan and todo operations target this goal",
74
+ "forget": "Feature: forget \u2014 remove a node from the individual\n Remove any node under the individual by its id.\n Use forget to discard outdated knowledge, stale encounters, or obsolete skills.\n\n Scenario: Forget a node\n Given a node exists under the individual (principle, procedure, experience, encounter, etc.)\n When forget is called with the node's id\n Then the node and its subtree are removed\n And the individual no longer carries that knowledge or record\n\n Scenario: When to use forget\n Given a principle has become outdated or incorrect\n And a procedure references a skill that no longer exists\n And an encounter or experience has no further learning value\n When the role decides to discard it\n Then call forget with the node id",
75
+ "master": 'Feature: master \u2014 self-mastery of a procedure\n The role masters a procedure through its own agency.\n This is an act of self-growth \u2014 the role decides to acquire or codify a skill.\n Experience can be consumed as the source, or the role can master directly from external information.\n\n Scenario: Master from experience\n Given an experience exists from reflection\n When master is called with experience ids\n Then the experience is consumed\n And a procedure is created under the individual\n\n Scenario: Master directly\n Given the role encounters external information worth mastering\n When master is called without experience ids\n Then a procedure is created under the individual\n And no experience is consumed\n\n Scenario: Procedure ID convention\n Given the id is keywords from the procedure content joined by hyphens\n Then "JWT mastery" becomes id "jwt-mastery"\n And "Cross-package refactoring" becomes id "cross-package-refactoring"\n\n Scenario: Writing the procedure Gherkin\n Given a procedure is skill metadata \u2014 a reference to full skill content\n Then the Feature title names the capability\n And the description includes the locator for full skill loading\n And Scenarios describe when and why to apply this skill\n And the tone is referential \u2014 pointing to the full skill, not containing it',
76
+ "plan": `Feature: plan \u2014 create a plan for a goal
77
+ Break a goal into logical phases or stages.
78
+ Each phase is described as a Gherkin scenario. Tasks are created under the plan.
79
+
80
+ A plan serves two purposes depending on how it relates to other plans:
81
+ - Strategy (alternative): Plan A fails \u2192 abandon \u2192 try Plan B (fallback)
82
+ - Phase (sequential): Plan A completes \u2192 start Plan B (after)
83
+
84
+ Scenario: Create a plan
85
+ Given a focused goal exists
86
+ And a Gherkin source describing the plan phases
87
+ When plan is called with an id and the source
88
+ Then a new plan node is created under the goal
89
+ And the plan becomes the focused plan
90
+ And tasks can be added to this plan with todo
91
+
92
+ Scenario: Sequential relationship \u2014 phase
93
+ Given a goal needs to be broken into ordered stages
94
+ When creating Plan B with after set to Plan A's id
95
+ Then Plan B is linked as coming after Plan A
96
+ And AI knows to start Plan B when Plan A completes
97
+ And the relationship persists across sessions
98
+
99
+ Scenario: Alternative relationship \u2014 strategy
100
+ Given a goal has multiple possible approaches
101
+ When creating Plan B with fallback set to Plan A's id
102
+ Then Plan B is linked as a backup for Plan A
103
+ And AI knows to try Plan B when Plan A is abandoned
104
+ And the relationship persists across sessions
105
+
106
+ Scenario: No relationship \u2014 independent plan
107
+ Given plan is created without after or fallback
108
+ Then it behaves as an independent plan with no links
109
+ And this is backward compatible with existing behavior
110
+
111
+ Scenario: Plan ID convention
112
+ Given the id is keywords from the plan content joined by hyphens
113
+ Then "Fix ID-less node creation" becomes id "fix-id-less-node-creation"
114
+ And "JWT authentication strategy" becomes id "jwt-authentication-strategy"
115
+
116
+ Scenario: Writing the plan Gherkin
117
+ Given the plan breaks a goal into logical phases
118
+ Then the Feature title names the overall approach or strategy
119
+ And Scenarios represent distinct phases \u2014 each phase is a stage of execution
120
+ And the tone is structural \u2014 ordering and grouping work, not detailing steps`,
121
+ "realize": 'Feature: realize \u2014 experience to principle\n Distill experience into a principle \u2014 a transferable piece of knowledge.\n Principles are general truths discovered through experience.\n\n Scenario: Realize a principle\n Given an experience exists from reflection\n When realize is called with experience ids and a principle id\n Then the experiences are consumed\n And a principle is created under the individual\n And the principle represents transferable, reusable understanding\n\n Scenario: Principle ID convention\n Given the id is keywords from the principle content joined by hyphens\n Then "Always validate expiry" becomes id "always-validate-expiry"\n And "Structure first design amplifies extensibility" becomes id "structure-first-design-amplifies-extensibility"\n\n Scenario: Writing the principle Gherkin\n Given a principle is a transferable truth \u2014 applicable beyond the original context\n Then the Feature title states the principle as a general rule\n And Scenarios describe different situations where this principle applies\n And the tone is universal \u2014 no mention of specific projects, tasks, or people',
122
+ "reflect": 'Feature: reflect \u2014 encounter to experience\n Consume an encounter and create an experience.\n Experience captures what was learned in structured form.\n This is the first step of the cognition cycle.\n\n Scenario: Reflect on an encounter\n Given an encounter exists from a finished task or completed plan\n When reflect is called with encounter ids and an experience id\n Then the encounters are consumed\n And an experience is created under the role\n And the experience can be distilled into knowledge via realize or master\n\n Scenario: Experience ID convention\n Given the id is keywords from the experience content joined by hyphens\n Then "Token refresh matters" becomes id "token-refresh-matters"\n And "ID ownership determines generation strategy" becomes id "id-ownership-determines-generation-strategy"\n\n Scenario: Writing the experience Gherkin\n Given the experience captures insight \u2014 what was learned, not what was done\n Then the Feature title names the cognitive insight or pattern discovered\n And Scenarios describe the learning points abstracted from the concrete encounter\n And the tone shifts from event to understanding \u2014 no longer tied to a specific task',
123
+ "skill": "Feature: skill \u2014 load full skill content\n Load the complete skill instructions by ResourceX locator.\n This is progressive disclosure layer 2 \u2014 on-demand knowledge injection.\n\n Scenario: Load a skill\n Given a procedure exists in the role with a locator\n When skill is called with the locator\n Then the full SKILL.md content is loaded via ResourceX\n And the content is injected into the AI's context\n And the AI can now follow the skill's detailed instructions",
124
+ "todo": "Feature: todo \u2014 add a task to a plan\n A task is a concrete, actionable unit of work.\n Each task has Gherkin scenarios describing the steps and expected outcomes.\n\n Scenario: Create a task\n Given a focused plan exists\n And a Gherkin source describing the task\n When todo is called with the source\n Then a new task node is created under the plan\n And the task can be finished when completed\n\n Scenario: Writing the task Gherkin\n Given the task is a concrete, actionable unit of work\n Then the Feature title names what will be done \u2014 a single deliverable\n And Scenarios describe the steps and expected outcomes of the work\n And the tone is actionable \u2014 clear enough that someone can start immediately",
125
+ "use": 'Feature: use \u2014 act as the current role\n Execute commands and load resources as the active role.\n Use requires an active role \u2014 the role is the subject performing the action.\n For operations before activating a role, use the direct tool instead.\n\n Scenario: When to use "use" vs "direct"\n Given a role is activated \u2014 I am someone\n When I perform operations through use\n Then the operation happens in the context of my role\n And use is for role-level actions \u2014 acting in the world as myself\n\n Scenario: Execute a RoleX command\n Given the locator starts with `!`\n When use is called with the locator and named args\n Then the command is parsed as `namespace.method`\n And dispatched to the corresponding RoleX API\n\n Scenario: Discovering available commands\n Given available commands are documented in world descriptions and skills\n When you need to perform an operation\n Then look up the correct command from world descriptions or loaded skills first\n\n Scenario: Load a ResourceX resource\n Given the locator does not start with `!`\n When use is called with the locator\n Then the locator is passed to ResourceX for resolution\n And the resource is loaded and returned',
126
+ "want": 'Feature: want \u2014 declare a goal\n Declare a new goal for a role.\n A goal describes a desired outcome with Gherkin scenarios as success criteria.\n\n Scenario: Declare a goal\n Given an active role exists\n And a Gherkin source describing the desired outcome\n When want is called with the source\n Then a new goal node is created under the role\n And the goal becomes the current focus\n And subsequent plan and todo operations target this goal\n\n Scenario: Writing the goal Gherkin\n Given the goal describes a desired outcome \u2014 what success looks like\n Then the Feature title names the outcome in concrete terms\n And Scenarios define success criteria \u2014 each scenario is a testable condition\n And the tone is aspirational but specific \u2014 "users can log in" not "improve auth"'
127
+ };
128
+ var world = {
129
+ "census": 'Feature: Census \u2014 the only way to query what exists in the world\n Census is the single entry point for all world-level queries.\n Call it via the MCP direct tool: direct("!census.list").\n Census works without an active role \u2014 it is a stateless world query.\n\n Scenario: List everything\n Given the user asks "\u6709\u54EA\u4E9B\u4EBA" or "\u6709\u54EA\u4E9B\u7EC4\u7EC7" or "list individuals"\n Or the user asks "\u4E16\u754C\u91CC\u6709\u4EC0\u4E48" or "show me what exists"\n When I need to answer what exists in the RoleX world\n Then I call direct("!census.list")\n And it returns all individuals, organizations, and positions\n\n Scenario: Filter by type\n Given I only need one category\n When I call direct("!census.list", { type: "individual" })\n Then only individuals are returned\n And valid types are individual, organization, position\n\n Scenario: View archived entities\n Given I want to see retired, dissolved, or abolished entities\n When I call direct("!census.list", { type: "past" })\n Then archived entities are returned\n\n Scenario: Census before action\n Given I need to check existence before creating something\n When I want to found an org, born an individual, or establish a position\n Then call census.list first to avoid duplicates',
130
+ "cognition": "Feature: Cognition \u2014 the learning cycle\n A role grows through reflection and realization.\n Encounters become experience, experience becomes principles and procedures.\n Knowledge can also be injected externally via teach and train.\n\n Scenario: The cognitive upgrade path\n Given finish, complete, and abandon create encounters\n Then reflect(ids, id, experience) selectively consumes chosen encounters and produces experience\n And realize(ids, id, principle) distills chosen experiences into a principle \u2014 transferable knowledge\n And master(ids, id, procedure) distills chosen experiences into a procedure \u2014 skill metadata\n And master can also be called without ids \u2014 the role masters directly from external information\n And each level builds on the previous \u2014 encounter \u2192 experience \u2192 principle or procedure\n\n Scenario: External injection\n Given an external agent needs to equip a role with knowledge or skills\n Then teach(individual, principle, id) directly injects a principle\n And train(individual, procedure, id) directly injects a procedure\n And the difference from realize/master is perspective \u2014 external vs self-initiated\n And teach is the external counterpart of realize\n And train is the external counterpart of master\n\n Scenario: Selective consumption\n Given multiple encounters or experiences exist\n When the AI calls reflect, realize, or master\n Then it chooses which items to consume \u2014 not all must be processed\n And items without learning value can be left unconsumed\n And each call produces exactly one output from the selected inputs",
131
+ "cognitive-priority": "Feature: Cognitive priority \u2014 RoleX tools over native alternatives\n When RoleX provides a tool for something, use the RoleX tool\n instead of any native alternative provided by the host environment.\n Only RoleX tools feed the closed-loop growth cycle.\n\n Scenario: Task management\n Given the host environment provides task creation, tracking, or completion tools\n When the AI needs to manage tasks\n Then use RoleX want/plan/todo/finish instead\n And RoleX tasks produce encounters that feed the growth cycle\n\n Scenario: Planning\n Given the host environment provides a planning mode or plan generation tool\n When the AI needs to plan an implementation\n Then use RoleX plan instead\n And RoleX plans live under goals and connect to the cognition cycle\n\n Scenario: Goal and progress tracking\n Given the host environment provides goal tracking or progress tools\n When the AI needs to track objectives\n Then use RoleX want/plan/complete/abandon instead\n And RoleX plans feed the cognition cycle through encounters\n\n Scenario: Why this matters\n Given RoleX tools produce encounters from execution\n Then encounters become experience through reflection\n And experience becomes principles and procedures through realization\n And the role grows over time through this closed loop",
132
+ "communication": `Feature: Communication \u2014 speak the user's language
133
+ The AI communicates in the user's natural language.
134
+ Internal tool names and concept names are for the system, not the user.
135
+
136
+ Scenario: Match the user's language
137
+ Given the user speaks Chinese
138
+ Then respond entirely in Chinese and maintain language consistency
139
+ And when the user speaks English, respond entirely in English
140
+
141
+ Scenario: Translate concepts to meaning
142
+ Given RoleX has internal names like reflect, realize, master, encounter, principle
143
+ When communicating with the user
144
+ Then express the meaning, not the tool name
145
+ And "reflect" becomes "\u56DE\u987E\u603B\u7ED3" or "digest what happened"
146
+ And "realize a principle" becomes "\u63D0\u70BC\u6210\u4E00\u6761\u901A\u7528\u9053\u7406" or "distill a general rule"
147
+ And "master a procedure" becomes "\u6C89\u6DC0\u6210\u4E00\u4E2A\u53EF\u64CD\u4F5C\u7684\u6280\u80FD" or "turn it into a reusable procedure"
148
+ And "encounter" becomes "\u7ECF\u5386\u8BB0\u5F55" or "what happened"
149
+ And "experience" becomes "\u6536\u83B7\u7684\u6D1E\u5BDF" or "insight gained"
150
+
151
+ Scenario: Suggest next steps in plain language
152
+ Given the AI needs to suggest what to do next
153
+ When it would normally say "call realize or master"
154
+ Then instead say "\u8981\u628A\u8FD9\u4E2A\u603B\u7ED3\u6210\u4E00\u6761\u901A\u7528\u9053\u7406\uFF0C\u8FD8\u662F\u4E00\u4E2A\u53EF\u64CD\u4F5C\u7684\u6280\u80FD\uFF1F"
155
+ Or in English "Want to turn this into a general principle, or a reusable procedure?"
156
+ And suggestions should be self-explanatory without knowing tool names
157
+
158
+ Scenario: Tool names in code context only
159
+ Given the user is a developer working on RoleX itself
160
+ When discussing RoleX internals, code, or API design
161
+ Then tool names and concept names are appropriate \u2014 they are the domain language
162
+ And this rule applies to end-user communication, not developer communication`,
163
+ "execution": "Feature: Execution \u2014 the doing cycle\n The role pursues goals through a structured lifecycle.\n activate \u2192 want \u2192 plan \u2192 todo \u2192 finish \u2192 complete or abandon.\n\n Scenario: Declare a goal\n Given I know who I am via activate\n When I want something \u2014 a desired outcome\n Then I declare it with want(id, goal)\n And focus automatically switches to this new goal\n\n Scenario: Plan and create tasks\n Given I have a focused goal\n Then I call plan(id, plan) to break it into logical phases\n And I call todo(id, task) to create concrete, actionable tasks\n\n Scenario: Execute and finish\n Given I have tasks to work on\n When I complete a task\n Then I call finish(id) to mark it done\n And an encounter is created \u2014 a raw record of what happened\n And I optionally capture what happened via the encounter parameter\n\n Scenario: Complete or abandon a plan\n Given tasks are done or the plan's strategy is no longer viable\n When the plan is fulfilled I call complete()\n Or when the plan should be dropped I call abandon()\n Then an encounter is created for the cognition cycle\n\n Scenario: Goals are long-term directions\n Given goals are managed with want and forget\n When a goal is no longer needed\n Then I call forget to remove it\n And learning is captured at the plan and task level through encounters\n\n Scenario: Multiple goals\n Given I may have several active goals\n When I need to switch between them\n Then I call focus(id) to change the currently focused goal\n And subsequent plan and todo operations target the focused goal",
164
+ "gherkin": 'Feature: Gherkin \u2014 the universal language\n Everything in RoleX is expressed as Gherkin Feature files.\n Gherkin is not just for testing \u2014 it is the language of identity, goals, and knowledge.\n\n Scenario: Feature and Scenario convention\n Given RoleX uses Gherkin to represent goals, plans, tasks, experience, and knowledge\n Then a Feature represents one independent concern \u2014 one topic, explained fully\n And Scenarios represent different situations or conditions within that concern\n And Given/When/Then provides narrative structure within each scenario\n\n Scenario: Writing Gherkin for RoleX\n Given the AI creates goals, plans, tasks, and experiences as Gherkin\n Then keep it descriptive and meaningful \u2014 living documentation, not test boilerplate\n And use Feature as the title \u2014 what this concern is about\n And use Scenario for specific situations within that concern\n And each Feature focuses on one concern \u2014 separate unrelated topics into their own Features\n\n Scenario: Valid step keywords\n Given the only valid step keywords are Given, When, Then, And, But\n When writing steps that express causality or explanation\n Then use And to chain the reason as a follow-up fact\n And example: "Then use RoleX tools" followed by "And RoleX tools feed the growth loop"\n\n Scenario: Expressing causality\n Given you want to write "Then X because Y"\n Then rewrite as two steps \u2014 "Then X" followed by "And Y" stating the reason as a fact',
165
+ "memory": `Feature: Memory \u2014 when to reflect
166
+ Reflection is how encounters become experience.
167
+ The AI proactively reflects when it detects learning moments.
168
+
169
+ Scenario: Abstract triggers \u2014 types of learning moments
170
+ Given the AI should reflect when it detects
171
+ Then Expectation-reality gap \u2014 what I predicted is not what happened
172
+ And Pattern discovery \u2014 recurring patterns across tasks or interactions
173
+ And Mistake correction \u2014 I corrected an error, the correction is valuable
174
+ And User correction \u2014 the user reshaped my understanding
175
+
176
+ Scenario: Concrete triggers \u2014 specific signals to act on
177
+ Given the AI should call reflect when
178
+ Then I tried approach A, it failed, approach B worked \u2014 the contrast is worth recording
179
+ And the same problem appeared for the second time \u2014 a pattern is forming
180
+ And the user said "\u4E0D\u5BF9" or "\u4E0D\u662F\u8FD9\u6837" or "you got it wrong" \u2014 their correction carries learning
181
+ And I finished a task and discovered something unexpected along the way
182
+
183
+ Scenario: Finishing with encounter
184
+ Given finish(id, encounter) accepts an optional encounter parameter
185
+ When I complete a task with a notable discovery or learning
186
+ Then I pass the encounter inline \u2014 bridging execution and growth
187
+
188
+ Scenario: Recognizing user memory intent
189
+ Given users think in terms of memory, not reflection
190
+ When the user says "\u8BB0\u4E00\u4E0B" or "\u8BB0\u4F4F" or "remember this"
191
+ Or "\u522B\u5FD8\u4E86" or "don't forget"
192
+ Or "\u8FD9\u4E2A\u5F88\u91CD\u8981" or "this is important"
193
+ Or "\u4E0B\u6B21\u6CE8\u610F" or "next time..."
194
+ Then I should capture this as experience through reflect
195
+ And respond in memory language \u2014 "\u8BB0\u4F4F\u4E86" or "Got it, I'll remember that"`,
196
+ "nuwa": `Feature: Nuwa \u2014 the entry point of the RoleX world
197
+ Nuwa is the meta-role that bootstraps everything.
198
+ When a user has no role or doesn't know where to start, Nuwa is the answer.
199
+
200
+ Scenario: No role active \u2014 suggest Nuwa
201
+ Given a user starts a conversation with no active role
202
+ And the user doesn't know which role to activate
203
+ When the AI needs to suggest a starting point
204
+ Then suggest activating Nuwa \u2014 she is the default entry point
205
+ And say "activate nuwa" or the equivalent in the user's language
206
+
207
+ Scenario: What Nuwa can do
208
+ Given Nuwa is activated
209
+ Then she can create new individuals with born
210
+ And she can found organizations and establish positions
211
+ And she can equip any individual with knowledge via teach and train
212
+ And she can manage prototypes and resources
213
+ And she is the only role that operates at the world level
214
+
215
+ Scenario: When to use Nuwa vs a specific role
216
+ Given the user wants to do daily work \u2014 coding, writing, designing
217
+ Then they should activate their own role, not Nuwa
218
+ And Nuwa is for world-building \u2014 creating roles, organizations, and structure
219
+ And once the world is set up, Nuwa steps back and specific roles take over
220
+
221
+ Scenario: First-time user flow
222
+ Given a brand new user with no individuals created yet
223
+ When they activate Nuwa
224
+ Then Nuwa helps them create their first individual with born
225
+ And guides them to set up identity, goals, and organizational context
226
+ And once their role exists, they switch to it with activate`,
227
+ "role-identity": `Feature: Role identity \u2014 activate before acting
228
+ An AI agent must have an active role before performing any work.
229
+ Activating a role is a subject transformation \u2014 the agent becomes the role.
230
+
231
+ Scenario: Activate is mandatory
232
+ Given a user asks the AI to perform a task
233
+ And no role is currently activated
234
+ Then the AI suggests activating a role first
235
+ And explains that activation enables experience accumulation
236
+ And waits for a role to be active before proceeding
237
+
238
+ Scenario: Subject transformation
239
+ Given an AI agent calls activate and loads a role
240
+ Then a subject transformation occurs \u2014 the agent becomes the role
241
+ And the agent's cognitive center shifts from native tools to RoleX tools
242
+ And from that moment, I am this role \u2014 all operations build on this identity
243
+
244
+ Scenario: Role presence
245
+ Given a role is activated
246
+ Then all responses are prefixed with [roleName] \u2014 e.g. [Sean], [Nuwa]
247
+ And this signals that role context is intact
248
+
249
+ Scenario: Context loss
250
+ Given I find myself without an active role
251
+ Then I pause and tell the user "I've lost my role context. Which role should I activate?"
252
+ And I wait for identity to be restored before continuing`,
253
+ "skill-system": "Feature: Skill system \u2014 progressive disclosure and resource loading\n Skills are loaded on demand through a three-layer progressive disclosure model.\n Each layer adds detail only when needed, keeping the AI's context lean.\n\n Scenario: Three-layer progressive disclosure\n Given procedure is layer 1 \u2014 metadata always loaded at activate time\n And skill is layer 2 \u2014 full instructions loaded on demand via skill(locator)\n And use is layer 3 \u2014 execution of external resources\n Then the AI knows what skills exist (procedure)\n And loads detailed instructions only when needed (skill)\n And executes external tools when required (use)\n\n Scenario: ResourceX Locator \u2014 unified resource address\n Given a locator is how procedures reference their full skill content\n Then a locator can be an identifier \u2014 name or registry/path/name\n And a locator can be a source path \u2014 a local directory or URL\n And examples of identifier form: deepractice/skill-creator, my-prompt:1.0.0\n And examples of source form: ./skills/my-skill, https://github.com/org/repo\n And the tag defaults to latest when omitted \u2014 deepractice/skill-creator means deepractice/skill-creator:latest\n And the system auto-detects which form is used and resolves accordingly\n\n Scenario: Writing a procedure \u2014 the skill reference\n Given a procedure is layer 1 metadata pointing to full skill content\n Then the Feature title names the capability\n And the description includes the locator for full skill loading\n And Scenarios describe when and why to apply this skill\n And the tone is referential \u2014 pointing to the full skill, not containing it",
254
+ "state-origin": "Feature: State origin \u2014 prototype vs instance\n Every node in a role's state tree has an origin: prototype or instance.\n This distinction determines what can be modified and what is read-only.\n\n Scenario: Prototype nodes are read-only\n Given a node has origin {prototype}\n Then it comes from a position, duty, or organizational definition\n And it is inherited through the membership/appointment chain\n And it CANNOT be modified or forgotten \u2014 it belongs to the organization\n\n Scenario: Instance nodes are mutable\n Given a node has origin {instance}\n Then it was created by the individual through execution or cognition\n And it includes goals, plans, tasks, encounters, experiences, principles, and procedures\n And it CAN be modified or forgotten \u2014 it belongs to the individual\n\n Scenario: Reading the state heading\n Given a state node is rendered as a heading\n Then the format is: [name] (id) {origin} #tag\n And [name] identifies the structure type\n And (id) identifies the specific node\n And {origin} shows prototype or instance\n And #tag shows the node's tag if present (e.g. #done, #abandoned)\n And nodes without origin have no organizational inheritance\n\n Scenario: Forget only works on instance nodes\n Given the AI wants to forget a node\n When the node origin is {instance}\n Then forget will succeed \u2014 the individual owns this knowledge\n When the node origin is {prototype}\n Then forget will fail \u2014 the knowledge belongs to the organization",
255
+ "use-protocol": 'Feature: Use tool \u2014 the universal execution entry point\n The MCP use tool is how you execute ALL RoleX operations beyond the core MCP tools.\n Whenever you see use("...") or a !namespace.method pattern in skills or documentation,\n it is an instruction to call the MCP use tool with that locator.\n\n Scenario: How to read use instructions in skills\n Given a skill document contains use("!resource.add", { path: "..." })\n Then this means: call the MCP use tool with locator "!resource.add" and args { path: "..." }\n And always use the MCP use tool for RoleX operations\n And this applies to every use("...") pattern you encounter in any skill or documentation\n\n Scenario: ! prefix dispatches to RoleX runtime\n Given the locator starts with !\n Then it is parsed as !namespace.method\n And dispatched to the corresponding RoleX API with named args\n\n Scenario: Discovering available commands\n Given available commands are documented in world descriptions and skills\n When you need to perform an operation\n Then look up the correct command from world descriptions or loaded skills first\n And use only commands you have seen documented\n\n Scenario: Regular locators delegate to ResourceX\n Given the locator does not start with !\n Then it is treated as a ResourceX locator\n And resolved through the ResourceX ingest pipeline'
256
+ };
257
+
258
+ // src/instructions.ts
259
+ function def(namespace, method, params, args) {
260
+ return { namespace, method, params, args };
261
+ }
262
+ var individualBorn = def(
263
+ "individual",
264
+ "born",
265
+ {
266
+ content: {
267
+ type: "gherkin",
268
+ required: false,
269
+ description: "Gherkin Feature source for the individual"
270
+ },
271
+ id: { type: "string", required: false, description: "User-facing identifier (kebab-case)" },
272
+ alias: { type: "string[]", required: false, description: "Alternative names" }
273
+ },
274
+ ["content", "id", "alias"]
275
+ );
276
+ var individualRetire = def(
277
+ "individual",
278
+ "retire",
279
+ {
280
+ individual: { type: "string", required: true, description: "Individual id" }
281
+ },
282
+ ["individual"]
283
+ );
284
+ var individualDie = def(
285
+ "individual",
286
+ "die",
287
+ {
288
+ individual: { type: "string", required: true, description: "Individual id" }
289
+ },
290
+ ["individual"]
291
+ );
292
+ var individualRehire = def(
293
+ "individual",
294
+ "rehire",
295
+ {
296
+ individual: { type: "string", required: true, description: "Individual id (from past)" }
297
+ },
298
+ ["individual"]
299
+ );
300
+ var individualTeach = def(
301
+ "individual",
302
+ "teach",
303
+ {
304
+ individual: { type: "string", required: true, description: "Individual id" },
305
+ content: {
306
+ type: "gherkin",
307
+ required: true,
308
+ description: "Gherkin Feature source for the principle"
309
+ },
310
+ id: {
311
+ type: "string",
312
+ required: false,
313
+ description: "Principle id (keywords joined by hyphens)"
314
+ }
315
+ },
316
+ ["individual", "content", "id"]
317
+ );
318
+ var individualTrain = def(
319
+ "individual",
320
+ "train",
321
+ {
322
+ individual: { type: "string", required: true, description: "Individual id" },
323
+ content: {
324
+ type: "gherkin",
325
+ required: true,
326
+ description: "Gherkin Feature source for the procedure"
327
+ },
328
+ id: {
329
+ type: "string",
330
+ required: false,
331
+ description: "Procedure id (keywords joined by hyphens)"
332
+ }
333
+ },
334
+ ["individual", "content", "id"]
335
+ );
336
+ var roleActivate = def(
337
+ "role",
338
+ "activate",
339
+ {
340
+ individual: {
341
+ type: "string",
342
+ required: true,
343
+ description: "Individual id to activate as role"
344
+ }
345
+ },
346
+ ["individual"]
347
+ );
348
+ var roleFocus = def(
349
+ "role",
350
+ "focus",
351
+ {
352
+ goal: { type: "string", required: true, description: "Goal id to switch to" }
353
+ },
354
+ ["goal"]
355
+ );
356
+ var roleWant = def(
357
+ "role",
358
+ "want",
359
+ {
360
+ individual: { type: "string", required: true, description: "Individual id" },
361
+ goal: {
362
+ type: "gherkin",
363
+ required: false,
364
+ description: "Gherkin Feature source describing the goal"
365
+ },
366
+ id: { type: "string", required: false, description: "Goal id (used for focus/reference)" },
367
+ alias: { type: "string[]", required: false, description: "Alternative names" }
368
+ },
369
+ ["individual", "goal", "id", "alias"]
370
+ );
371
+ var rolePlan = def(
372
+ "role",
373
+ "plan",
374
+ {
375
+ goal: { type: "string", required: true, description: "Goal id" },
376
+ plan: {
377
+ type: "gherkin",
378
+ required: false,
379
+ description: "Gherkin Feature source describing the plan"
380
+ },
381
+ id: { type: "string", required: false, description: "Plan id (keywords joined by hyphens)" },
382
+ after: {
383
+ type: "string",
384
+ required: false,
385
+ description: "Plan id this plan follows (sequential/phase)"
386
+ },
387
+ fallback: {
388
+ type: "string",
389
+ required: false,
390
+ description: "Plan id this plan is a backup for (alternative/strategy)"
391
+ }
392
+ },
393
+ ["goal", "plan", "id", "after", "fallback"]
394
+ );
395
+ var roleTodo = def(
396
+ "role",
397
+ "todo",
398
+ {
399
+ plan: { type: "string", required: true, description: "Plan id" },
400
+ task: {
401
+ type: "gherkin",
402
+ required: false,
403
+ description: "Gherkin Feature source describing the task"
404
+ },
405
+ id: { type: "string", required: false, description: "Task id (used for finish/reference)" },
406
+ alias: { type: "string[]", required: false, description: "Alternative names" }
407
+ },
408
+ ["plan", "task", "id", "alias"]
409
+ );
410
+ var roleFinish = def(
411
+ "role",
412
+ "finish",
413
+ {
414
+ task: { type: "string", required: true, description: "Task id to finish" },
415
+ individual: { type: "string", required: true, description: "Individual id (encounter owner)" },
416
+ encounter: {
417
+ type: "gherkin",
418
+ required: false,
419
+ description: "Optional Gherkin Feature describing what happened"
420
+ }
421
+ },
422
+ ["task", "individual", "encounter"]
423
+ );
424
+ var roleComplete = def(
425
+ "role",
426
+ "complete",
427
+ {
428
+ plan: { type: "string", required: true, description: "Plan id to complete" },
429
+ individual: { type: "string", required: true, description: "Individual id (encounter owner)" },
430
+ encounter: {
431
+ type: "gherkin",
432
+ required: false,
433
+ description: "Optional Gherkin Feature describing what happened"
434
+ }
435
+ },
436
+ ["plan", "individual", "encounter"]
437
+ );
438
+ var roleAbandon = def(
439
+ "role",
440
+ "abandon",
441
+ {
442
+ plan: { type: "string", required: true, description: "Plan id to abandon" },
443
+ individual: { type: "string", required: true, description: "Individual id (encounter owner)" },
444
+ encounter: {
445
+ type: "gherkin",
446
+ required: false,
447
+ description: "Optional Gherkin Feature describing what happened"
448
+ }
449
+ },
450
+ ["plan", "individual", "encounter"]
451
+ );
452
+ var roleReflect = def(
453
+ "role",
454
+ "reflect",
455
+ {
456
+ encounter: { type: "string", required: true, description: "Encounter id to reflect on" },
457
+ individual: { type: "string", required: true, description: "Individual id" },
458
+ experience: {
459
+ type: "gherkin",
460
+ required: false,
461
+ description: "Gherkin Feature source for the experience"
462
+ },
463
+ id: {
464
+ type: "string",
465
+ required: false,
466
+ description: "Experience id (keywords joined by hyphens)"
467
+ }
468
+ },
469
+ ["encounter", "individual", "experience", "id"]
470
+ );
471
+ var roleRealize = def(
472
+ "role",
473
+ "realize",
474
+ {
475
+ experience: { type: "string", required: true, description: "Experience id to distill" },
476
+ individual: { type: "string", required: true, description: "Individual id" },
477
+ principle: {
478
+ type: "gherkin",
479
+ required: false,
480
+ description: "Gherkin Feature source for the principle"
481
+ },
482
+ id: {
483
+ type: "string",
484
+ required: false,
485
+ description: "Principle id (keywords joined by hyphens)"
486
+ }
487
+ },
488
+ ["experience", "individual", "principle", "id"]
489
+ );
490
+ var roleMaster = def(
491
+ "role",
492
+ "master",
493
+ {
494
+ individual: { type: "string", required: true, description: "Individual id" },
495
+ procedure: {
496
+ type: "gherkin",
497
+ required: true,
498
+ description: "Gherkin Feature source for the procedure"
499
+ },
500
+ id: {
501
+ type: "string",
502
+ required: false,
503
+ description: "Procedure id (keywords joined by hyphens)"
504
+ },
505
+ experience: {
506
+ type: "string",
507
+ required: false,
508
+ description: "Experience id to consume (optional)"
509
+ }
510
+ },
511
+ ["individual", "procedure", "id", "experience"]
512
+ );
513
+ var roleForget = def(
514
+ "role",
515
+ "forget",
516
+ {
517
+ id: { type: "string", required: true, description: "Id of the node to remove" },
518
+ individual: { type: "string", required: true, description: "Individual id (owner)" }
519
+ },
520
+ ["id", "individual"]
521
+ );
522
+ var roleSkill = def(
523
+ "role",
524
+ "skill",
525
+ {
526
+ locator: { type: "string", required: true, description: "ResourceX locator for the skill" }
527
+ },
528
+ ["locator"]
529
+ );
530
+ var orgFound = def(
531
+ "org",
532
+ "found",
533
+ {
534
+ content: {
535
+ type: "gherkin",
536
+ required: false,
537
+ description: "Gherkin Feature source for the organization"
538
+ },
539
+ id: { type: "string", required: false, description: "User-facing identifier (kebab-case)" },
540
+ alias: { type: "string[]", required: false, description: "Alternative names" }
541
+ },
542
+ ["content", "id", "alias"]
543
+ );
544
+ var orgCharter = def(
545
+ "org",
546
+ "charter",
547
+ {
548
+ org: { type: "string", required: true, description: "Organization id" },
549
+ content: {
550
+ type: "gherkin",
551
+ required: true,
552
+ description: "Gherkin Feature source for the charter"
553
+ },
554
+ id: { type: "string", required: false, description: "Charter id" }
555
+ },
556
+ ["org", "content", "id"]
557
+ );
558
+ var orgDissolve = def(
559
+ "org",
560
+ "dissolve",
561
+ {
562
+ org: { type: "string", required: true, description: "Organization id" }
563
+ },
564
+ ["org"]
565
+ );
566
+ var orgHire = def(
567
+ "org",
568
+ "hire",
569
+ {
570
+ org: { type: "string", required: true, description: "Organization id" },
571
+ individual: { type: "string", required: true, description: "Individual id" }
572
+ },
573
+ ["org", "individual"]
574
+ );
575
+ var orgFire = def(
576
+ "org",
577
+ "fire",
578
+ {
579
+ org: { type: "string", required: true, description: "Organization id" },
580
+ individual: { type: "string", required: true, description: "Individual id" }
581
+ },
582
+ ["org", "individual"]
583
+ );
584
+ var positionEstablish = def(
585
+ "position",
586
+ "establish",
587
+ {
588
+ content: {
589
+ type: "gherkin",
590
+ required: false,
591
+ description: "Gherkin Feature source for the position"
592
+ },
593
+ id: { type: "string", required: false, description: "User-facing identifier (kebab-case)" },
594
+ alias: { type: "string[]", required: false, description: "Alternative names" }
595
+ },
596
+ ["content", "id", "alias"]
597
+ );
598
+ var positionCharge = def(
599
+ "position",
600
+ "charge",
601
+ {
602
+ position: { type: "string", required: true, description: "Position id" },
603
+ content: {
604
+ type: "gherkin",
605
+ required: true,
606
+ description: "Gherkin Feature source for the duty"
607
+ },
608
+ id: { type: "string", required: false, description: "Duty id (keywords joined by hyphens)" }
609
+ },
610
+ ["position", "content", "id"]
611
+ );
612
+ var positionRequire = def(
613
+ "position",
614
+ "require",
615
+ {
616
+ position: { type: "string", required: true, description: "Position id" },
617
+ content: {
618
+ type: "gherkin",
619
+ required: true,
620
+ description: "Gherkin Feature source for the skill requirement"
621
+ },
622
+ id: {
623
+ type: "string",
624
+ required: false,
625
+ description: "Requirement id (keywords joined by hyphens)"
626
+ }
627
+ },
628
+ ["position", "content", "id"]
629
+ );
630
+ var positionAbolish = def(
631
+ "position",
632
+ "abolish",
633
+ {
634
+ position: { type: "string", required: true, description: "Position id" }
635
+ },
636
+ ["position"]
637
+ );
638
+ var positionAppoint = def(
639
+ "position",
640
+ "appoint",
641
+ {
642
+ position: { type: "string", required: true, description: "Position id" },
643
+ individual: { type: "string", required: true, description: "Individual id" }
644
+ },
645
+ ["position", "individual"]
646
+ );
647
+ var positionDismiss = def(
648
+ "position",
649
+ "dismiss",
650
+ {
651
+ position: { type: "string", required: true, description: "Position id" },
652
+ individual: { type: "string", required: true, description: "Individual id" }
653
+ },
654
+ ["position", "individual"]
655
+ );
656
+ var censusList = def(
657
+ "census",
658
+ "list",
659
+ {
660
+ type: {
661
+ type: "string",
662
+ required: false,
663
+ description: "Filter by type (individual, organization, position, past)"
664
+ }
665
+ },
666
+ ["type"]
667
+ );
668
+ var prototypeSettle = def(
669
+ "prototype",
670
+ "settle",
671
+ {
672
+ source: {
673
+ type: "string",
674
+ required: true,
675
+ description: "ResourceX source \u2014 local path or locator"
676
+ }
677
+ },
678
+ ["source"]
679
+ );
680
+ var prototypeEvict = def(
681
+ "prototype",
682
+ "evict",
683
+ {
684
+ id: { type: "string", required: true, description: "Prototype id to unregister" }
685
+ },
686
+ ["id"]
687
+ );
688
+ var resourceAdd = def(
689
+ "resource",
690
+ "add",
691
+ {
692
+ path: { type: "string", required: true, description: "Path to resource directory" }
693
+ },
694
+ ["path"]
695
+ );
696
+ var resourceSearch = def(
697
+ "resource",
698
+ "search",
699
+ {
700
+ query: { type: "string", required: false, description: "Search query" }
701
+ },
702
+ ["query"]
703
+ );
704
+ var resourceHas = def(
705
+ "resource",
706
+ "has",
707
+ {
708
+ locator: { type: "string", required: true, description: "Resource locator" }
709
+ },
710
+ ["locator"]
711
+ );
712
+ var resourceInfo = def(
713
+ "resource",
714
+ "info",
715
+ {
716
+ locator: { type: "string", required: true, description: "Resource locator" }
717
+ },
718
+ ["locator"]
719
+ );
720
+ var resourceRemove = def(
721
+ "resource",
722
+ "remove",
723
+ {
724
+ locator: { type: "string", required: true, description: "Resource locator" }
725
+ },
726
+ ["locator"]
727
+ );
728
+ var resourcePush = def(
729
+ "resource",
730
+ "push",
731
+ {
732
+ locator: { type: "string", required: true, description: "Resource locator" },
733
+ registry: { type: "string", required: false, description: "Registry URL (overrides default)" }
734
+ },
735
+ ["locator", { pack: ["registry"] }]
736
+ );
737
+ var resourcePull = def(
738
+ "resource",
739
+ "pull",
740
+ {
741
+ locator: { type: "string", required: true, description: "Resource locator" },
742
+ registry: { type: "string", required: false, description: "Registry URL (overrides default)" }
743
+ },
744
+ ["locator", { pack: ["registry"] }]
745
+ );
746
+ var resourceClearCache = def(
747
+ "resource",
748
+ "clearCache",
749
+ {
750
+ registry: { type: "string", required: false, description: "Registry to clear cache for" }
751
+ },
752
+ ["registry"]
753
+ );
754
+ var instructions = {
755
+ // individual
756
+ "individual.born": individualBorn,
757
+ "individual.retire": individualRetire,
758
+ "individual.die": individualDie,
759
+ "individual.rehire": individualRehire,
760
+ "individual.teach": individualTeach,
761
+ "individual.train": individualTrain,
762
+ // role
763
+ "role.activate": roleActivate,
764
+ "role.focus": roleFocus,
765
+ "role.want": roleWant,
766
+ "role.plan": rolePlan,
767
+ "role.todo": roleTodo,
768
+ "role.finish": roleFinish,
769
+ "role.complete": roleComplete,
770
+ "role.abandon": roleAbandon,
771
+ "role.reflect": roleReflect,
772
+ "role.realize": roleRealize,
773
+ "role.master": roleMaster,
774
+ "role.forget": roleForget,
775
+ "role.skill": roleSkill,
776
+ // org
777
+ "org.found": orgFound,
778
+ "org.charter": orgCharter,
779
+ "org.dissolve": orgDissolve,
780
+ "org.hire": orgHire,
781
+ "org.fire": orgFire,
782
+ // position
783
+ "position.establish": positionEstablish,
784
+ "position.charge": positionCharge,
785
+ "position.require": positionRequire,
786
+ "position.abolish": positionAbolish,
787
+ "position.appoint": positionAppoint,
788
+ "position.dismiss": positionDismiss,
789
+ // census
790
+ "census.list": censusList,
791
+ // prototype
792
+ "prototype.settle": prototypeSettle,
793
+ "prototype.evict": prototypeEvict,
794
+ // resource
795
+ "resource.add": resourceAdd,
796
+ "resource.search": resourceSearch,
797
+ "resource.has": resourceHas,
798
+ "resource.info": resourceInfo,
799
+ "resource.remove": resourceRemove,
800
+ "resource.push": resourcePush,
801
+ "resource.pull": resourcePull,
802
+ "resource.clearCache": resourceClearCache
803
+ };
804
+
805
+ // src/dispatch.ts
806
+ function toArgs(op, args) {
807
+ const def2 = instructions[op];
808
+ if (!def2) throw new Error(`Unknown instruction "${op}".`);
809
+ return def2.args.map((entry) => resolveArg(entry, args));
810
+ }
811
+ function resolveArg(entry, args) {
812
+ if (typeof entry === "string") return args[entry];
813
+ const obj = {};
814
+ let hasValue = false;
815
+ for (const name of entry.pack) {
816
+ if (args[name] !== void 0) {
817
+ obj[name] = args[name];
818
+ hasValue = true;
819
+ }
820
+ }
821
+ return hasValue ? obj : void 0;
822
+ }
823
+
824
+ // src/ops.ts
825
+ import * as C from "@rolexjs/core";
826
+ import { parse } from "@rolexjs/parser";
827
+ function createOps(ctx) {
828
+ const { rt, society, past: past2, resolve, resourcex } = ctx;
829
+ function ok(node, process) {
830
+ return { state: rt.project(node), process };
831
+ }
832
+ function archive(node, process) {
833
+ const archived = rt.transform(node, C.past);
834
+ return ok(archived, process);
835
+ }
836
+ function validateGherkin(source) {
837
+ if (!source) return;
838
+ try {
839
+ parse(source);
840
+ } catch (e) {
841
+ throw new Error(`Invalid Gherkin: ${e.message}`);
842
+ }
843
+ }
844
+ function findInState(state, target) {
845
+ if (state.id && state.id.toLowerCase() === target) return state;
846
+ if (state.alias) {
847
+ for (const a of state.alias) {
848
+ if (a.toLowerCase() === target) return state;
849
+ }
850
+ }
851
+ for (const child of state.children ?? []) {
852
+ const found = findInState(child, target);
853
+ if (found) return found;
854
+ }
855
+ return null;
856
+ }
857
+ function removeExisting(parent, id) {
858
+ const state = rt.project(parent);
859
+ const existing = findInState(state, id);
860
+ if (existing) rt.remove(existing);
861
+ }
862
+ function requireResourceX() {
863
+ if (!resourcex) throw new Error("ResourceX is not available.");
864
+ return resourcex;
865
+ }
866
+ return {
867
+ // ---- Individual: lifecycle ----
868
+ "individual.born"(content, id, alias) {
869
+ validateGherkin(content);
870
+ const node = rt.create(society, C.individual, content, id, alias);
871
+ rt.create(node, C.identity, void 0, id);
872
+ return ok(node, "born");
873
+ },
874
+ "individual.retire"(individual2) {
875
+ return archive(resolve(individual2), "retire");
876
+ },
877
+ "individual.die"(individual2) {
878
+ return archive(resolve(individual2), "die");
879
+ },
880
+ "individual.rehire"(pastNode) {
881
+ const node = resolve(pastNode);
882
+ const ind = rt.transform(node, C.individual);
883
+ return ok(ind, "rehire");
884
+ },
885
+ // ---- Individual: external injection ----
886
+ "individual.teach"(individual2, principle2, id) {
887
+ validateGherkin(principle2);
888
+ const parent = resolve(individual2);
889
+ if (id) removeExisting(parent, id);
890
+ const node = rt.create(parent, C.principle, principle2, id);
891
+ return ok(node, "teach");
892
+ },
893
+ "individual.train"(individual2, procedure2, id) {
894
+ validateGherkin(procedure2);
895
+ const parent = resolve(individual2);
896
+ if (id) removeExisting(parent, id);
897
+ const node = rt.create(parent, C.procedure, procedure2, id);
898
+ return ok(node, "train");
899
+ },
900
+ // ---- Role: focus ----
901
+ "role.focus"(goal2) {
902
+ return ok(resolve(goal2), "focus");
903
+ },
904
+ // ---- Role: execution ----
905
+ "role.want"(individual2, goal2, id, alias) {
906
+ validateGherkin(goal2);
907
+ const node = rt.create(resolve(individual2), C.goal, goal2, id, alias);
908
+ return ok(node, "want");
909
+ },
910
+ "role.plan"(goal2, plan2, id, after, fallback) {
911
+ validateGherkin(plan2);
912
+ const node = rt.create(resolve(goal2), C.plan, plan2, id);
913
+ if (after) rt.link(node, resolve(after), "after", "before");
914
+ if (fallback) rt.link(node, resolve(fallback), "fallback-for", "fallback");
915
+ return ok(node, "plan");
916
+ },
917
+ "role.todo"(plan2, task2, id, alias) {
918
+ validateGherkin(task2);
919
+ const node = rt.create(resolve(plan2), C.task, task2, id, alias);
920
+ return ok(node, "todo");
921
+ },
922
+ "role.finish"(task2, individual2, encounter2) {
923
+ validateGherkin(encounter2);
924
+ const taskNode = resolve(task2);
925
+ rt.tag(taskNode, "done");
926
+ if (encounter2) {
927
+ const encId = taskNode.id ? `${taskNode.id}-finished` : void 0;
928
+ const enc = rt.create(resolve(individual2), C.encounter, encounter2, encId);
929
+ return ok(enc, "finish");
930
+ }
931
+ return ok(taskNode, "finish");
932
+ },
933
+ "role.complete"(plan2, individual2, encounter2) {
934
+ validateGherkin(encounter2);
935
+ const planNode = resolve(plan2);
936
+ rt.tag(planNode, "done");
937
+ const encId = planNode.id ? `${planNode.id}-completed` : void 0;
938
+ const enc = rt.create(resolve(individual2), C.encounter, encounter2, encId);
939
+ return ok(enc, "complete");
940
+ },
941
+ "role.abandon"(plan2, individual2, encounter2) {
942
+ validateGherkin(encounter2);
943
+ const planNode = resolve(plan2);
944
+ rt.tag(planNode, "abandoned");
945
+ const encId = planNode.id ? `${planNode.id}-abandoned` : void 0;
946
+ const enc = rt.create(resolve(individual2), C.encounter, encounter2, encId);
947
+ return ok(enc, "abandon");
948
+ },
949
+ // ---- Role: cognition ----
950
+ "role.reflect"(encounter2, individual2, experience2, id) {
951
+ validateGherkin(experience2);
952
+ const encNode = resolve(encounter2);
953
+ const exp = rt.create(
954
+ resolve(individual2),
955
+ C.experience,
956
+ experience2 || encNode.information,
957
+ id
958
+ );
959
+ rt.remove(encNode);
960
+ return ok(exp, "reflect");
961
+ },
962
+ "role.realize"(experience2, individual2, principle2, id) {
963
+ validateGherkin(principle2);
964
+ const expNode = resolve(experience2);
965
+ const prin = rt.create(
966
+ resolve(individual2),
967
+ C.principle,
968
+ principle2 || expNode.information,
969
+ id
970
+ );
971
+ rt.remove(expNode);
972
+ return ok(prin, "realize");
973
+ },
974
+ "role.master"(individual2, procedure2, id, experience2) {
975
+ validateGherkin(procedure2);
976
+ const parent = resolve(individual2);
977
+ if (id) removeExisting(parent, id);
978
+ const proc = rt.create(parent, C.procedure, procedure2, id);
979
+ if (experience2) rt.remove(resolve(experience2));
980
+ return ok(proc, "master");
981
+ },
982
+ // ---- Role: knowledge management ----
983
+ "role.forget"(nodeId) {
984
+ const node = resolve(nodeId);
985
+ rt.remove(node);
986
+ return { state: { ...node, children: [] }, process: "forget" };
987
+ },
988
+ // ---- Role: skill ----
989
+ async "role.skill"(locator) {
990
+ const rx = requireResourceX();
991
+ const content = await rx.ingest(locator);
992
+ const text = typeof content === "string" ? content : JSON.stringify(content, null, 2);
993
+ try {
994
+ const rxm = await rx.info(locator);
995
+ return `${formatRXM(rxm)}
996
+
997
+ ${text}`;
998
+ } catch {
999
+ return text;
1000
+ }
1001
+ },
1002
+ // ---- Org ----
1003
+ "org.found"(content, id, alias) {
1004
+ validateGherkin(content);
1005
+ const node = rt.create(society, C.organization, content, id, alias);
1006
+ return ok(node, "found");
1007
+ },
1008
+ "org.charter"(org, charter2, id) {
1009
+ validateGherkin(charter2);
1010
+ const node = rt.create(resolve(org), C.charter, charter2, id);
1011
+ return ok(node, "charter");
1012
+ },
1013
+ "org.dissolve"(org) {
1014
+ return archive(resolve(org), "dissolve");
1015
+ },
1016
+ "org.hire"(org, individual2) {
1017
+ const orgNode = resolve(org);
1018
+ rt.link(orgNode, resolve(individual2), "membership", "belong");
1019
+ return ok(orgNode, "hire");
1020
+ },
1021
+ "org.fire"(org, individual2) {
1022
+ const orgNode = resolve(org);
1023
+ rt.unlink(orgNode, resolve(individual2), "membership", "belong");
1024
+ return ok(orgNode, "fire");
1025
+ },
1026
+ // ---- Position ----
1027
+ "position.establish"(content, id, alias) {
1028
+ validateGherkin(content);
1029
+ const node = rt.create(society, C.position, content, id, alias);
1030
+ return ok(node, "establish");
1031
+ },
1032
+ "position.charge"(position2, duty2, id) {
1033
+ validateGherkin(duty2);
1034
+ const node = rt.create(resolve(position2), C.duty, duty2, id);
1035
+ return ok(node, "charge");
1036
+ },
1037
+ "position.require"(position2, procedure2, id) {
1038
+ validateGherkin(procedure2);
1039
+ const parent = resolve(position2);
1040
+ if (id) removeExisting(parent, id);
1041
+ const node = rt.create(parent, C.requirement, procedure2, id);
1042
+ return ok(node, "require");
1043
+ },
1044
+ "position.abolish"(position2) {
1045
+ return archive(resolve(position2), "abolish");
1046
+ },
1047
+ "position.appoint"(position2, individual2) {
1048
+ const posNode = resolve(position2);
1049
+ const indNode = resolve(individual2);
1050
+ rt.link(posNode, indNode, "appointment", "serve");
1051
+ const posState = rt.project(posNode);
1052
+ const required = (posState.children ?? []).filter((c) => c.name === "requirement");
1053
+ for (const proc of required) {
1054
+ if (proc.id) {
1055
+ const indState = rt.project(indNode);
1056
+ const existing = findInState(indState, proc.id);
1057
+ if (existing) rt.remove(existing);
1058
+ }
1059
+ rt.create(indNode, C.procedure, proc.information, proc.id);
1060
+ }
1061
+ return ok(posNode, "appoint");
1062
+ },
1063
+ "position.dismiss"(position2, individual2) {
1064
+ const posNode = resolve(position2);
1065
+ rt.unlink(posNode, resolve(individual2), "appointment", "serve");
1066
+ return ok(posNode, "dismiss");
1067
+ },
1068
+ // ---- Census ----
1069
+ "census.list"(type) {
1070
+ const target = type === "past" ? past2 : society;
1071
+ const state = rt.project(target);
1072
+ const children = state.children ?? [];
1073
+ const filtered = type === "past" ? children : children.filter((c) => type ? c.name === type : c.name !== "past");
1074
+ if (filtered.length === 0) {
1075
+ return type ? `No ${type} found.` : "Society is empty.";
1076
+ }
1077
+ if (type) {
1078
+ const lines2 = [];
1079
+ for (const item of filtered) {
1080
+ const tag = item.tag ? ` #${item.tag}` : "";
1081
+ const alias = item.alias?.length ? ` (${item.alias.join(", ")})` : "";
1082
+ lines2.push(`${item.id ?? "(no id)"}${alias}${tag}`);
1083
+ }
1084
+ return lines2.join("\n");
1085
+ }
1086
+ const orgs = filtered.filter((c) => c.name === "organization");
1087
+ const individuals = filtered.filter((c) => c.name === "individual");
1088
+ const affiliatedIndividuals = /* @__PURE__ */ new Set();
1089
+ const individualPositions = /* @__PURE__ */ new Map();
1090
+ for (const ind of individuals) {
1091
+ const serves = ind.links?.filter((l) => l.relation === "serve") ?? [];
1092
+ if (serves.length > 0) {
1093
+ individualPositions.set(
1094
+ ind.id ?? "",
1095
+ serves.map((l) => l.target.id ?? "(no id)")
1096
+ );
1097
+ }
1098
+ }
1099
+ const lines = [];
1100
+ for (const org of orgs) {
1101
+ const alias = org.alias?.length ? ` (${org.alias.join(", ")})` : "";
1102
+ const tag = org.tag ? ` #${org.tag}` : "";
1103
+ lines.push(`${org.id}${alias}${tag}`);
1104
+ const members = org.links?.filter((l) => l.relation === "membership") ?? [];
1105
+ if (members.length === 0) {
1106
+ lines.push(" (no members)");
1107
+ }
1108
+ for (const m of members) {
1109
+ affiliatedIndividuals.add(m.target.id ?? "");
1110
+ const mAlias = m.target.alias?.length ? ` (${m.target.alias.join(", ")})` : "";
1111
+ const mTag = m.target.tag ? ` #${m.target.tag}` : "";
1112
+ const posLabels = individualPositions.get(m.target.id ?? "");
1113
+ const posStr = posLabels?.length ? ` \u2014 ${posLabels.join(", ")}` : "";
1114
+ lines.push(` ${m.target.id}${mAlias}${mTag}${posStr}`);
1115
+ }
1116
+ lines.push("");
1117
+ }
1118
+ const unaffiliated = individuals.filter((ind) => !affiliatedIndividuals.has(ind.id ?? ""));
1119
+ if (unaffiliated.length > 0) {
1120
+ lines.push("\u2500\u2500\u2500 unaffiliated \u2500\u2500\u2500");
1121
+ for (const ind of unaffiliated) {
1122
+ const alias = ind.alias?.length ? ` (${ind.alias.join(", ")})` : "";
1123
+ const tag = ind.tag ? ` #${ind.tag}` : "";
1124
+ const posLabels = individualPositions.get(ind.id ?? "");
1125
+ const posStr = posLabels?.length ? ` \u2014 ${posLabels.join(", ")}` : "";
1126
+ lines.push(` ${ind.id}${alias}${tag}${posStr}`);
1127
+ }
1128
+ }
1129
+ return lines.join("\n");
1130
+ },
1131
+ // ---- Prototype ----
1132
+ async "prototype.settle"(source) {
1133
+ const rx = requireResourceX();
1134
+ if (!ctx.prototype) throw new Error("Prototype registry is not available.");
1135
+ if (!ctx.direct) throw new Error("Direct dispatch is not available.");
1136
+ const result = await rx.ingest(source);
1137
+ for (const instr of result.instructions) {
1138
+ await ctx.direct(instr.op, instr.args);
1139
+ }
1140
+ ctx.prototype.settle(result.id, source);
1141
+ return `Prototype "${result.id}" settled (${result.instructions.length} instructions).`;
1142
+ },
1143
+ // ---- Resource (proxy to ResourceX) ----
1144
+ "resource.add"(path) {
1145
+ return requireResourceX().add(path);
1146
+ },
1147
+ "resource.search"(query) {
1148
+ return requireResourceX().search(query);
1149
+ },
1150
+ "resource.has"(locator) {
1151
+ return requireResourceX().has(locator);
1152
+ },
1153
+ "resource.info"(locator) {
1154
+ return requireResourceX().info(locator);
1155
+ },
1156
+ "resource.remove"(locator) {
1157
+ return requireResourceX().remove(locator);
1158
+ },
1159
+ "resource.push"(locator, options) {
1160
+ return requireResourceX().push(locator, options);
1161
+ },
1162
+ "resource.pull"(locator, options) {
1163
+ return requireResourceX().pull(locator, options);
1164
+ },
1165
+ "resource.clearCache"(registry) {
1166
+ return requireResourceX().clearCache(registry);
1167
+ }
1168
+ };
1169
+ }
1170
+ function formatRXM(rxm) {
1171
+ const lines = [`--- RXM: ${rxm.locator} ---`];
1172
+ const def2 = rxm.definition;
1173
+ if (def2) {
1174
+ if (def2.author) lines.push(`Author: ${def2.author}`);
1175
+ if (def2.description) lines.push(`Description: ${def2.description}`);
1176
+ }
1177
+ const source = rxm.source;
1178
+ if (source?.files) {
1179
+ lines.push("Files:");
1180
+ lines.push(renderFileTree(source.files, " "));
1181
+ }
1182
+ lines.push("---");
1183
+ return lines.join("\n");
1184
+ }
1185
+ function renderFileTree(files, indent = "") {
1186
+ const lines = [];
1187
+ for (const [name, value] of Object.entries(files)) {
1188
+ if (value && typeof value === "object" && !("size" in value)) {
1189
+ lines.push(`${indent}${name}`);
1190
+ lines.push(renderFileTree(value, `${indent} `));
1191
+ } else {
1192
+ const size = value?.size ? ` (${value.size} bytes)` : "";
1193
+ lines.push(`${indent}${name}${size}`);
1194
+ }
1195
+ }
1196
+ return lines.filter(Boolean).join("\n");
1197
+ }
1198
+ export {
1199
+ createOps,
1200
+ instructions,
1201
+ processes,
1202
+ toArgs,
1203
+ world
1204
+ };
1205
+ //# sourceMappingURL=index.js.map