@rolexjs/core 1.5.0-dev-20260310044915 → 1.5.0-dev-20260312083443

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 CHANGED
@@ -683,13 +683,13 @@ function findInState(state, target) {
683
683
  }
684
684
  function createHelpers(ctx) {
685
685
  const { rt, project: project2, resourcex, issuex } = ctx;
686
- async function ok(node, process8) {
686
+ async function ok2(node, process8) {
687
687
  return { state: await project2(node), process: process8 };
688
688
  }
689
689
  async function archive2(node, process8) {
690
690
  const target = structure2(node.name, node.description ?? "", past);
691
691
  const archived = await rt.transform(node, target);
692
- return ok(archived, process8);
692
+ return ok2(archived, process8);
693
693
  }
694
694
  function validateGherkin(source) {
695
695
  if (!source) return;
@@ -712,7 +712,7 @@ function createHelpers(ctx) {
712
712
  if (!issuex) throw new Error("IssueX is not available.");
713
713
  return issuex;
714
714
  }
715
- return { ok, archive: archive2, validateGherkin, removeExisting, requireResourceX, requireIssueX };
715
+ return { ok: ok2, archive: archive2, validateGherkin, removeExisting, requireResourceX, requireIssueX };
716
716
  }
717
717
 
718
718
  // src/commands/issue.ts
@@ -800,30 +800,30 @@ function issueCommands(_ctx, helpers) {
800
800
  // src/commands/position.ts
801
801
  function positionCommands(ctx, helpers) {
802
802
  const { rt, resolve } = ctx;
803
- const { ok, validateGherkin, removeExisting } = helpers;
803
+ const { ok: ok2, validateGherkin, removeExisting } = helpers;
804
804
  return {
805
805
  async "position.charge"(position2, duty2, id) {
806
806
  validateGherkin(duty2);
807
807
  const node = await rt.create(await resolve(position2), duty, duty2, id);
808
- return ok(node, "charge");
808
+ return ok2(node, "charge");
809
809
  },
810
810
  async "position.require"(position2, procedure2, id) {
811
811
  validateGherkin(procedure2);
812
812
  const parent = await resolve(position2);
813
813
  if (id) await removeExisting(parent, id);
814
814
  const node = await rt.create(parent, requirement, procedure2, id);
815
- return ok(node, "require");
815
+ return ok2(node, "require");
816
816
  },
817
817
  async "position.appoint"(position2, individual2) {
818
818
  const posNode = await resolve(position2);
819
819
  const indNode = await resolve(individual2);
820
820
  await rt.link(posNode, indNode, "appointment", "serve");
821
- return ok(posNode, "appoint");
821
+ return ok2(posNode, "appoint");
822
822
  },
823
823
  async "position.dismiss"(position2, individual2) {
824
824
  const posNode = await resolve(position2);
825
825
  await rt.unlink(posNode, await resolve(individual2), "appointment", "serve");
826
- return ok(posNode, "dismiss");
826
+ return ok2(posNode, "dismiss");
827
827
  }
828
828
  };
829
829
  }
@@ -831,37 +831,37 @@ function positionCommands(ctx, helpers) {
831
831
  // src/commands/product.ts
832
832
  function productCommands(ctx, helpers) {
833
833
  const { rt, resolve } = ctx;
834
- const { ok, archive: archive2, validateGherkin } = helpers;
834
+ const { ok: ok2, archive: archive2, validateGherkin } = helpers;
835
835
  return {
836
836
  async "product.strategy"(product2, strategy2, id) {
837
837
  validateGherkin(strategy2);
838
838
  const node = await rt.create(await resolve(product2), strategy, strategy2, id);
839
- return ok(node, "strategy");
839
+ return ok2(node, "strategy");
840
840
  },
841
841
  async "product.spec"(product2, spec2, id) {
842
842
  validateGherkin(spec2);
843
843
  const node = await rt.create(await resolve(product2), spec, spec2, id);
844
- return ok(node, "spec");
844
+ return ok2(node, "spec");
845
845
  },
846
846
  async "product.release"(product2, release2, id) {
847
847
  validateGherkin(release2);
848
848
  const node = await rt.create(await resolve(product2), release, release2, id);
849
- return ok(node, "release");
849
+ return ok2(node, "release");
850
850
  },
851
851
  async "product.channel"(product2, channel2, id) {
852
852
  validateGherkin(channel2);
853
853
  const node = await rt.create(await resolve(product2), channel, channel2, id);
854
- return ok(node, "channel");
854
+ return ok2(node, "channel");
855
855
  },
856
856
  async "product.own"(product2, individual2) {
857
857
  const prodNode = await resolve(product2);
858
858
  await rt.link(prodNode, await resolve(individual2), "ownership", "own");
859
- return ok(prodNode, "own");
859
+ return ok2(prodNode, "own");
860
860
  },
861
861
  async "product.disown"(product2, individual2) {
862
862
  const prodNode = await resolve(product2);
863
863
  await rt.unlink(prodNode, await resolve(individual2), "ownership", "own");
864
- return ok(prodNode, "disown");
864
+ return ok2(prodNode, "disown");
865
865
  },
866
866
  async "product.deprecate"(product2) {
867
867
  return archive2(await resolve(product2), "deprecate");
@@ -872,42 +872,42 @@ function productCommands(ctx, helpers) {
872
872
  // src/commands/project.ts
873
873
  function projectCommands(ctx, helpers) {
874
874
  const { rt, society: society2, resolve } = ctx;
875
- const { ok, validateGherkin } = helpers;
875
+ const { ok: ok2, validateGherkin } = helpers;
876
876
  return {
877
877
  async "project.scope"(project2, scope2, id) {
878
878
  validateGherkin(scope2);
879
879
  const node = await rt.create(await resolve(project2), scope, scope2, id);
880
- return ok(node, "scope");
880
+ return ok2(node, "scope");
881
881
  },
882
882
  async "project.milestone"(project2, milestone2, id) {
883
883
  validateGherkin(milestone2);
884
884
  const node = await rt.create(await resolve(project2), milestone, milestone2, id);
885
- return ok(node, "milestone");
885
+ return ok2(node, "milestone");
886
886
  },
887
887
  async "project.achieve"(milestone2) {
888
888
  const node = await resolve(milestone2);
889
889
  await rt.tag(node, "done");
890
- return ok(node, "achieve");
890
+ return ok2(node, "achieve");
891
891
  },
892
892
  async "project.enroll"(project2, individual2) {
893
893
  const projNode = await resolve(project2);
894
894
  await rt.link(projNode, await resolve(individual2), "participation", "participate");
895
- return ok(projNode, "enroll");
895
+ return ok2(projNode, "enroll");
896
896
  },
897
897
  async "project.remove"(project2, individual2) {
898
898
  const projNode = await resolve(project2);
899
899
  await rt.unlink(projNode, await resolve(individual2), "participation", "participate");
900
- return ok(projNode, "remove");
900
+ return ok2(projNode, "remove");
901
901
  },
902
902
  async "project.deliver"(project2, deliverable2, id) {
903
903
  validateGherkin(deliverable2);
904
904
  const node = await rt.create(await resolve(project2), deliverable, deliverable2, id);
905
- return ok(node, "deliver");
905
+ return ok2(node, "deliver");
906
906
  },
907
907
  async "project.wiki"(project2, wiki2, id) {
908
908
  validateGherkin(wiki2);
909
909
  const node = await rt.create(await resolve(project2), wiki, wiki2, id);
910
- return ok(node, "wiki");
910
+ return ok2(node, "wiki");
911
911
  },
912
912
  async "project.produce"(project2, content, id, alias, owner) {
913
913
  validateGherkin(content);
@@ -916,17 +916,17 @@ function projectCommands(ctx, helpers) {
916
916
  await rt.link(projNode, node, "production", "produce");
917
917
  await rt.link(node, projNode, "origin", "produced-by");
918
918
  if (owner) await rt.link(node, await resolve(owner), "ownership", "own");
919
- return ok(node, "produce");
919
+ return ok2(node, "produce");
920
920
  },
921
921
  async "project.maintain"(project2, individual2) {
922
922
  const projNode = await resolve(project2);
923
923
  await rt.link(projNode, await resolve(individual2), "maintain", "maintained-by");
924
- return ok(projNode, "maintain");
924
+ return ok2(projNode, "maintain");
925
925
  },
926
926
  async "project.unmaintain"(project2, individual2) {
927
927
  const projNode = await resolve(project2);
928
928
  await rt.unlink(projNode, await resolve(individual2), "maintain", "maintained-by");
929
- return ok(projNode, "unmaintain");
929
+ return ok2(projNode, "unmaintain");
930
930
  }
931
931
  };
932
932
  }
@@ -993,29 +993,29 @@ function renderFileTree(files, indent = "") {
993
993
  }
994
994
  function roleCommands(ctx, helpers) {
995
995
  const { rt, resolve } = ctx;
996
- const { ok, validateGherkin, removeExisting, requireResourceX } = helpers;
996
+ const { ok: ok2, validateGherkin, removeExisting, requireResourceX } = helpers;
997
997
  return {
998
998
  // ---- Role: focus ----
999
999
  async "role.focus"(goal2) {
1000
- return ok(await resolve(goal2), "focus");
1000
+ return ok2(await resolve(goal2), "focus");
1001
1001
  },
1002
1002
  // ---- Role: execution ----
1003
1003
  async "role.want"(individual2, goal2, id, alias) {
1004
1004
  validateGherkin(goal2);
1005
1005
  const node = await rt.create(await resolve(individual2), goal, goal2, id, alias);
1006
- return ok(node, "want");
1006
+ return ok2(node, "want");
1007
1007
  },
1008
1008
  async "role.plan"(goal2, plan2, id, after, fallback) {
1009
1009
  validateGherkin(plan2);
1010
1010
  const node = await rt.create(await resolve(goal2), plan, plan2, id);
1011
1011
  if (after) await rt.link(node, await resolve(after), "after", "before");
1012
1012
  if (fallback) await rt.link(node, await resolve(fallback), "fallback-for", "fallback");
1013
- return ok(node, "plan");
1013
+ return ok2(node, "plan");
1014
1014
  },
1015
1015
  async "role.todo"(plan2, task2, id, alias) {
1016
1016
  validateGherkin(task2);
1017
1017
  const node = await rt.create(await resolve(plan2), task, task2, id, alias);
1018
- return ok(node, "todo");
1018
+ return ok2(node, "todo");
1019
1019
  },
1020
1020
  async "role.finish"(task2, individual2, encounter2) {
1021
1021
  validateGherkin(encounter2);
@@ -1024,9 +1024,9 @@ function roleCommands(ctx, helpers) {
1024
1024
  if (encounter2) {
1025
1025
  const encId = taskNode.id ? `${taskNode.id}-finished` : void 0;
1026
1026
  const enc = await rt.create(await resolve(individual2), encounter, encounter2, encId);
1027
- return ok(enc, "finish");
1027
+ return ok2(enc, "finish");
1028
1028
  }
1029
- return ok(taskNode, "finish");
1029
+ return ok2(taskNode, "finish");
1030
1030
  },
1031
1031
  async "role.complete"(plan2, individual2, encounter2) {
1032
1032
  validateGherkin(encounter2);
@@ -1034,7 +1034,7 @@ function roleCommands(ctx, helpers) {
1034
1034
  await rt.tag(planNode, "done");
1035
1035
  const encId = planNode.id ? `${planNode.id}-completed` : void 0;
1036
1036
  const enc = await rt.create(await resolve(individual2), encounter, encounter2, encId);
1037
- return ok(enc, "complete");
1037
+ return ok2(enc, "complete");
1038
1038
  },
1039
1039
  async "role.abandon"(plan2, individual2, encounter2) {
1040
1040
  validateGherkin(encounter2);
@@ -1042,7 +1042,7 @@ function roleCommands(ctx, helpers) {
1042
1042
  await rt.tag(planNode, "abandoned");
1043
1043
  const encId = planNode.id ? `${planNode.id}-abandoned` : void 0;
1044
1044
  const enc = await rt.create(await resolve(individual2), encounter, encounter2, encId);
1045
- return ok(enc, "abandon");
1045
+ return ok2(enc, "abandon");
1046
1046
  },
1047
1047
  // ---- Role: cognition ----
1048
1048
  async "role.reflect"(encounter2, individual2, experience2, id) {
@@ -1056,10 +1056,10 @@ function roleCommands(ctx, helpers) {
1056
1056
  id
1057
1057
  );
1058
1058
  await rt.remove(encNode);
1059
- return ok(exp2, "reflect");
1059
+ return ok2(exp2, "reflect");
1060
1060
  }
1061
1061
  const exp = await rt.create(await resolve(individual2), experience, experience2, id);
1062
- return ok(exp, "reflect");
1062
+ return ok2(exp, "reflect");
1063
1063
  },
1064
1064
  async "role.realize"(experience2, individual2, principle2, id) {
1065
1065
  validateGherkin(principle2);
@@ -1072,10 +1072,10 @@ function roleCommands(ctx, helpers) {
1072
1072
  id
1073
1073
  );
1074
1074
  await rt.remove(expNode);
1075
- return ok(prin2, "realize");
1075
+ return ok2(prin2, "realize");
1076
1076
  }
1077
1077
  const prin = await rt.create(await resolve(individual2), principle, principle2, id);
1078
- return ok(prin, "realize");
1078
+ return ok2(prin, "realize");
1079
1079
  },
1080
1080
  async "role.master"(individual2, procedure2, id, experience2) {
1081
1081
  validateGherkin(procedure2);
@@ -1083,7 +1083,7 @@ function roleCommands(ctx, helpers) {
1083
1083
  if (id) await removeExisting(parent, id);
1084
1084
  const proc = await rt.create(parent, procedure, procedure2, id);
1085
1085
  if (experience2) await rt.remove(await resolve(experience2));
1086
- return ok(proc, "master");
1086
+ return ok2(proc, "master");
1087
1087
  },
1088
1088
  // ---- Role: knowledge management ----
1089
1089
  async "role.forget"(nodeId) {
@@ -1111,14 +1111,14 @@ ${text}`;
1111
1111
  // src/commands/society.ts
1112
1112
  function societyCommands(ctx, helpers) {
1113
1113
  const { rt, society: society2, resolve } = ctx;
1114
- const { ok, archive: archive2, validateGherkin, removeExisting } = helpers;
1114
+ const { ok: ok2, archive: archive2, validateGherkin, removeExisting } = helpers;
1115
1115
  return {
1116
1116
  // ---- Society: individual lifecycle ----
1117
1117
  async "society.born"(content, id, alias) {
1118
1118
  validateGherkin(content);
1119
1119
  const node = await rt.create(society2, individual, content, id, alias);
1120
1120
  await rt.create(node, identity, void 0, `${id}-identity`);
1121
- return ok(node, "born");
1121
+ return ok2(node, "born");
1122
1122
  },
1123
1123
  async "society.retire"(individual2) {
1124
1124
  return archive2(await resolve(individual2), "retire");
@@ -1129,7 +1129,7 @@ function societyCommands(ctx, helpers) {
1129
1129
  async "society.rehire"(pastNode) {
1130
1130
  const node = await resolve(pastNode);
1131
1131
  const ind = await rt.transform(node, individual);
1132
- return ok(ind, "rehire");
1132
+ return ok2(ind, "rehire");
1133
1133
  },
1134
1134
  // ---- Society: external injection ----
1135
1135
  async "society.teach"(individual2, principle2, id) {
@@ -1137,21 +1137,21 @@ function societyCommands(ctx, helpers) {
1137
1137
  const parent = await resolve(individual2);
1138
1138
  if (id) await removeExisting(parent, id);
1139
1139
  const node = await rt.create(parent, principle, principle2, id);
1140
- return ok(node, "teach");
1140
+ return ok2(node, "teach");
1141
1141
  },
1142
1142
  async "society.train"(individual2, procedure2, id) {
1143
1143
  validateGherkin(procedure2);
1144
1144
  const parent = await resolve(individual2);
1145
1145
  if (id) await removeExisting(parent, id);
1146
1146
  const node = await rt.create(parent, procedure, procedure2, id);
1147
- return ok(node, "train");
1147
+ return ok2(node, "train");
1148
1148
  },
1149
1149
  // ---- Society: organization lifecycle ----
1150
1150
  async "society.found"(content, id, alias, admin) {
1151
1151
  validateGherkin(content);
1152
1152
  const node = await rt.create(society2, organization, content, id, alias);
1153
1153
  if (admin) await rt.link(node, await resolve(admin), "admin", "administer");
1154
- return ok(node, "found");
1154
+ return ok2(node, "found");
1155
1155
  },
1156
1156
  async "society.dissolve"(org) {
1157
1157
  return archive2(await resolve(org), "dissolve");
@@ -1160,38 +1160,38 @@ function societyCommands(ctx, helpers) {
1160
1160
  async "society.crown"(individual2) {
1161
1161
  const indNode = await resolve(individual2);
1162
1162
  await rt.link(society2, indNode, "crown", "crowned");
1163
- return ok(indNode, "crown");
1163
+ return ok2(indNode, "crown");
1164
1164
  },
1165
1165
  async "society.uncrown"(individual2) {
1166
1166
  const indNode = await resolve(individual2);
1167
1167
  await rt.unlink(society2, indNode, "crown", "crowned");
1168
- return ok(indNode, "uncrown");
1168
+ return ok2(indNode, "uncrown");
1169
1169
  },
1170
1170
  // ---- Org ----
1171
1171
  async "org.charter"(org, charter2, id) {
1172
1172
  validateGherkin(charter2);
1173
1173
  const node = await rt.create(await resolve(org), charter, charter2, id);
1174
- return ok(node, "charter");
1174
+ return ok2(node, "charter");
1175
1175
  },
1176
1176
  async "org.hire"(org, individual2) {
1177
1177
  const orgNode = await resolve(org);
1178
1178
  await rt.link(orgNode, await resolve(individual2), "membership", "belong");
1179
- return ok(orgNode, "hire");
1179
+ return ok2(orgNode, "hire");
1180
1180
  },
1181
1181
  async "org.fire"(org, individual2) {
1182
1182
  const orgNode = await resolve(org);
1183
1183
  await rt.unlink(orgNode, await resolve(individual2), "membership", "belong");
1184
- return ok(orgNode, "fire");
1184
+ return ok2(orgNode, "fire");
1185
1185
  },
1186
1186
  async "org.admin"(org, individual2) {
1187
1187
  const orgNode = await resolve(org);
1188
1188
  await rt.link(orgNode, await resolve(individual2), "admin", "administer");
1189
- return ok(orgNode, "admin");
1189
+ return ok2(orgNode, "admin");
1190
1190
  },
1191
1191
  async "org.unadmin"(org, individual2) {
1192
1192
  const orgNode = await resolve(org);
1193
1193
  await rt.unlink(orgNode, await resolve(individual2), "admin", "administer");
1194
- return ok(orgNode, "unadmin");
1194
+ return ok2(orgNode, "unadmin");
1195
1195
  },
1196
1196
  // ---- Org: project lifecycle ----
1197
1197
  async "org.launch"(content, id, alias, org, maintainer) {
@@ -1199,7 +1199,7 @@ function societyCommands(ctx, helpers) {
1199
1199
  const node = await rt.create(society2, project, content, id, alias);
1200
1200
  if (org) await rt.link(node, await resolve(org), "ownership", "project");
1201
1201
  if (maintainer) await rt.link(node, await resolve(maintainer), "maintain", "maintained-by");
1202
- return ok(node, "launch");
1202
+ return ok2(node, "launch");
1203
1203
  },
1204
1204
  async "org.archive"(project2) {
1205
1205
  return archive2(await resolve(project2), "archive");
@@ -1208,7 +1208,7 @@ function societyCommands(ctx, helpers) {
1208
1208
  async "org.establish"(content, id, alias) {
1209
1209
  validateGherkin(content);
1210
1210
  const node = await rt.create(society2, position, content, id, alias);
1211
- return ok(node, "establish");
1211
+ return ok2(node, "establish");
1212
1212
  },
1213
1213
  async "org.abolish"(position2) {
1214
1214
  return archive2(await resolve(position2), "abolish");
@@ -2996,13 +2996,17 @@ var RoleXService = class _RoleXService {
2996
2996
  past;
2997
2997
  /** Cached Role instances — one per individual. */
2998
2998
  roles = /* @__PURE__ */ new Map();
2999
+ /** Expose commands for the RPC handler. */
3000
+ get commandMap() {
3001
+ return this.commands;
3002
+ }
2999
3003
  /** Permission registry — maps relation names to permissions. */
3000
3004
  permissions = new PermissionRegistry().register("crowned", sovereignPermissions).register("administer", orgAdminPermissions).register("maintained-by", projectMaintainerPermissions).register("own", productOwnerPermissions);
3001
- constructor(platform, renderer) {
3005
+ constructor(platform, renderer, prototypes) {
3002
3006
  this.repo = platform.repository;
3003
3007
  this.rt = this.repo.runtime;
3004
3008
  this.initializer = platform.initializer;
3005
- this.prototypes = platform.prototypes ?? [];
3009
+ this.prototypes = prototypes ?? [];
3006
3010
  this.renderer = renderer;
3007
3011
  if (platform.resourcexProvider) {
3008
3012
  setProvider(platform.resourcexProvider);
@@ -3014,8 +3018,8 @@ var RoleXService = class _RoleXService {
3014
3018
  this.issuex = createIssueX({ provider: platform.issuexProvider });
3015
3019
  }
3016
3020
  }
3017
- static async create(platform, renderer) {
3018
- const service = new _RoleXService(platform, renderer);
3021
+ static async create(platform, renderer, prototypes) {
3022
+ const service = new _RoleXService(platform, renderer, prototypes);
3019
3023
  await service.init();
3020
3024
  return service;
3021
3025
  }
@@ -3171,45 +3175,167 @@ function isCommandResult(value) {
3171
3175
  return typeof value === "object" && value !== null && "state" in value && "process" in value;
3172
3176
  }
3173
3177
 
3174
- // src/renderer.ts
3175
- var RendererRouter = class {
3176
- renderers = /* @__PURE__ */ new Map();
3177
- /** Register a renderer for a command namespace. */
3178
- register(namespace, renderer) {
3179
- this.renderers.set(namespace, renderer);
3180
- return this;
3178
+ // src/rpc.ts
3179
+ var RPC_METHOD_NOT_FOUND = -32601;
3180
+ var RPC_INTERNAL_ERROR = -32603;
3181
+ var RpcHandler = class {
3182
+ commands;
3183
+ methods;
3184
+ constructor(deps) {
3185
+ this.commands = deps.commands;
3186
+ this.methods = deps.methods ?? {};
3181
3187
  }
3182
- /** Route a command to the appropriate renderer. */
3183
- render(command, result) {
3184
- const dot = command.indexOf(".");
3185
- const namespace = dot >= 0 ? command.slice(0, dot) : command;
3186
- const renderer = this.renderers.get(namespace);
3187
- if (renderer) return renderer.render(command, result);
3188
- return defaultRender(command, result);
3188
+ async handle(request) {
3189
+ const { method, params = {}, id = null } = request;
3190
+ try {
3191
+ const custom = this.methods[method];
3192
+ if (custom) {
3193
+ const result2 = await custom(params);
3194
+ return ok(id, result2);
3195
+ }
3196
+ const fn = this.commands[method];
3197
+ if (!fn) {
3198
+ return error(id, RPC_METHOD_NOT_FOUND, `Unknown method "${method}".`);
3199
+ }
3200
+ const positionalArgs = toArgs(method, params);
3201
+ const result = await fn(...positionalArgs);
3202
+ return ok(id, result);
3203
+ } catch (err) {
3204
+ const message = err instanceof Error ? err.message : String(err);
3205
+ return error(id, RPC_INTERNAL_ERROR, message);
3206
+ }
3189
3207
  }
3190
3208
  };
3191
- function defaultRender(_command, result) {
3192
- return JSON.stringify(result, null, 2);
3209
+ function ok(id, result) {
3210
+ return { jsonrpc: "2.0", id, result };
3211
+ }
3212
+ function error(id, code, message, data) {
3213
+ return { jsonrpc: "2.0", id, error: { code, message, data } };
3214
+ }
3215
+
3216
+ // src/namespaces.ts
3217
+ function createSocietyNamespace(call) {
3218
+ return {
3219
+ born: (p5) => call("society.born", p5),
3220
+ retire: (p5) => call("society.retire", p5),
3221
+ die: (p5) => call("society.die", p5),
3222
+ rehire: (p5) => call("society.rehire", p5),
3223
+ teach: (p5) => call("society.teach", p5),
3224
+ train: (p5) => call("society.train", p5),
3225
+ found: (p5) => call("society.found", p5),
3226
+ dissolve: (p5) => call("society.dissolve", p5),
3227
+ crown: (p5) => call("society.crown", p5),
3228
+ uncrown: (p5) => call("society.uncrown", p5)
3229
+ };
3230
+ }
3231
+ function createRoleNamespace(call) {
3232
+ return {
3233
+ activate: (p5) => call("role.activate", p5),
3234
+ inspect: (p5) => call("inspect", p5),
3235
+ survey: (p5) => call("survey", p5)
3236
+ };
3237
+ }
3238
+ function createOrgNamespace(call) {
3239
+ return {
3240
+ charter: (p5) => call("org.charter", p5),
3241
+ hire: (p5) => call("org.hire", p5),
3242
+ fire: (p5) => call("org.fire", p5),
3243
+ admin: (p5) => call("org.admin", p5),
3244
+ unadmin: (p5) => call("org.unadmin", p5),
3245
+ launch: (p5) => call("org.launch", p5),
3246
+ archive: (p5) => call("org.archive", p5),
3247
+ establish: (p5) => call("org.establish", p5),
3248
+ abolish: (p5) => call("org.abolish", p5)
3249
+ };
3250
+ }
3251
+ function createPositionNamespace(call) {
3252
+ return {
3253
+ charge: (p5) => call("position.charge", p5),
3254
+ require: (p5) => call("position.require", p5),
3255
+ appoint: (p5) => call("position.appoint", p5),
3256
+ dismiss: (p5) => call("position.dismiss", p5)
3257
+ };
3258
+ }
3259
+ function createProjectNamespace(call) {
3260
+ return {
3261
+ scope: (p5) => call("project.scope", p5),
3262
+ milestone: (p5) => call("project.milestone", p5),
3263
+ achieve: (p5) => call("project.achieve", p5),
3264
+ enroll: (p5) => call("project.enroll", p5),
3265
+ remove: (p5) => call("project.remove", p5),
3266
+ deliver: (p5) => call("project.deliver", p5),
3267
+ wiki: (p5) => call("project.wiki", p5),
3268
+ produce: (p5) => call("project.produce", p5),
3269
+ maintain: (p5) => call("project.maintain", p5),
3270
+ unmaintain: (p5) => call("project.unmaintain", p5)
3271
+ };
3272
+ }
3273
+ function createProductNamespace(call) {
3274
+ return {
3275
+ strategy: (p5) => call("product.strategy", p5),
3276
+ spec: (p5) => call("product.spec", p5),
3277
+ release: (p5) => call("product.release", p5),
3278
+ channel: (p5) => call("product.channel", p5),
3279
+ own: (p5) => call("product.own", p5),
3280
+ disown: (p5) => call("product.disown", p5),
3281
+ deprecate: (p5) => call("product.deprecate", p5)
3282
+ };
3283
+ }
3284
+ function createCensusNamespace(call) {
3285
+ return {
3286
+ list: (p5) => call("census.list", p5)
3287
+ };
3288
+ }
3289
+ function createIssueNamespace(call) {
3290
+ return {
3291
+ publish: (p5) => call("issue.publish", p5),
3292
+ get: (p5) => call("issue.get", p5),
3293
+ list: (p5) => call("issue.list", p5),
3294
+ update: (p5) => call("issue.update", p5),
3295
+ close: (p5) => call("issue.close", p5),
3296
+ reopen: (p5) => call("issue.reopen", p5),
3297
+ assign: (p5) => call("issue.assign", p5),
3298
+ comment: (p5) => call("issue.comment", p5),
3299
+ comments: (p5) => call("issue.comments", p5),
3300
+ label: (p5) => call("issue.label", p5),
3301
+ unlabel: (p5) => call("issue.unlabel", p5)
3302
+ };
3303
+ }
3304
+ function createResourceNamespace(call) {
3305
+ return {
3306
+ add: (p5) => call("resource.add", p5),
3307
+ search: (p5) => call("resource.search", p5),
3308
+ has: (p5) => call("resource.has", p5),
3309
+ info: (p5) => call("resource.info", p5),
3310
+ remove: (p5) => call("resource.remove", p5),
3311
+ push: (p5) => call("resource.push", p5),
3312
+ pull: (p5) => call("resource.pull", p5),
3313
+ clearCache: (p5) => call("resource.clearCache", p5)
3314
+ };
3193
3315
  }
3194
3316
 
3195
3317
  // src/tools.ts
3196
3318
  var worldInstructions = Object.values(world).join("\n\n");
3319
+ var d = (name) => processes[name] ?? "";
3197
3320
  var tools = [
3198
3321
  // --- Top-level perception ---
3199
3322
  {
3200
3323
  name: "activate",
3324
+ description: d("activate"),
3201
3325
  params: {
3202
3326
  roleId: { type: "string", required: true, description: "Role name to activate" }
3203
3327
  }
3204
3328
  },
3205
3329
  {
3206
3330
  name: "inspect",
3331
+ description: d("inspect"),
3207
3332
  params: {
3208
3333
  id: { type: "string", required: true, description: "Node id to inspect (any node type)" }
3209
3334
  }
3210
3335
  },
3211
3336
  {
3212
3337
  name: "survey",
3338
+ description: d("survey"),
3213
3339
  params: {
3214
3340
  type: {
3215
3341
  type: "string",
@@ -3220,6 +3346,7 @@ var tools = [
3220
3346
  },
3221
3347
  {
3222
3348
  name: "focus",
3349
+ description: d("focus"),
3223
3350
  params: {
3224
3351
  id: {
3225
3352
  type: "string",
@@ -3231,6 +3358,7 @@ var tools = [
3231
3358
  // --- Execution ---
3232
3359
  {
3233
3360
  name: "want",
3361
+ description: d("want"),
3234
3362
  params: {
3235
3363
  id: { type: "string", required: true, description: "Goal id (used for focus/reference)" },
3236
3364
  goal: {
@@ -3242,6 +3370,7 @@ var tools = [
3242
3370
  },
3243
3371
  {
3244
3372
  name: "plan",
3373
+ description: d("plan"),
3245
3374
  params: {
3246
3375
  id: {
3247
3376
  type: "string",
@@ -3267,6 +3396,7 @@ var tools = [
3267
3396
  },
3268
3397
  {
3269
3398
  name: "todo",
3399
+ description: d("todo"),
3270
3400
  params: {
3271
3401
  id: { type: "string", required: true, description: "Task id (used for finish/reference)" },
3272
3402
  task: {
@@ -3278,6 +3408,7 @@ var tools = [
3278
3408
  },
3279
3409
  {
3280
3410
  name: "finish",
3411
+ description: d("finish"),
3281
3412
  params: {
3282
3413
  id: { type: "string", required: true, description: "Task id to finish" },
3283
3414
  encounter: {
@@ -3289,6 +3420,7 @@ var tools = [
3289
3420
  },
3290
3421
  {
3291
3422
  name: "complete",
3423
+ description: d("complete"),
3292
3424
  params: {
3293
3425
  id: {
3294
3426
  type: "string",
@@ -3304,6 +3436,7 @@ var tools = [
3304
3436
  },
3305
3437
  {
3306
3438
  name: "abandon",
3439
+ description: d("abandon"),
3307
3440
  params: {
3308
3441
  id: {
3309
3442
  type: "string",
@@ -3320,6 +3453,7 @@ var tools = [
3320
3453
  // --- Cognition ---
3321
3454
  {
3322
3455
  name: "reflect",
3456
+ description: d("reflect"),
3323
3457
  params: {
3324
3458
  ids: {
3325
3459
  type: "string[]",
@@ -3340,6 +3474,7 @@ var tools = [
3340
3474
  },
3341
3475
  {
3342
3476
  name: "realize",
3477
+ description: d("realize"),
3343
3478
  params: {
3344
3479
  ids: {
3345
3480
  type: "string[]",
@@ -3360,6 +3495,7 @@ var tools = [
3360
3495
  },
3361
3496
  {
3362
3497
  name: "master",
3498
+ description: d("master"),
3363
3499
  params: {
3364
3500
  ids: {
3365
3501
  type: "string[]",
@@ -3381,6 +3517,7 @@ var tools = [
3381
3517
  // --- Knowledge ---
3382
3518
  {
3383
3519
  name: "forget",
3520
+ description: d("forget"),
3384
3521
  params: {
3385
3522
  id: {
3386
3523
  type: "string",
@@ -3391,6 +3528,7 @@ var tools = [
3391
3528
  },
3392
3529
  {
3393
3530
  name: "skill",
3531
+ description: d("skill"),
3394
3532
  params: {
3395
3533
  locator: {
3396
3534
  type: "string",
@@ -3402,6 +3540,7 @@ var tools = [
3402
3540
  // --- Use / Direct ---
3403
3541
  {
3404
3542
  name: "use",
3543
+ description: d("use"),
3405
3544
  params: {
3406
3545
  command: {
3407
3546
  type: "string",
@@ -3417,6 +3556,7 @@ var tools = [
3417
3556
  },
3418
3557
  {
3419
3558
  name: "direct",
3559
+ description: d("direct"),
3420
3560
  params: {
3421
3561
  command: {
3422
3562
  type: "string",
@@ -3432,10 +3572,124 @@ var tools = [
3432
3572
  }
3433
3573
  ];
3434
3574
  var protocol = { tools, instructions: worldInstructions };
3575
+
3576
+ // src/builder.ts
3577
+ function createBuilder(config) {
3578
+ let initPromise = null;
3579
+ function ensureInit() {
3580
+ if (!initPromise) {
3581
+ initPromise = (async () => {
3582
+ const service = await RoleXService.create(
3583
+ config.platform,
3584
+ config.renderer,
3585
+ config.prototypes
3586
+ );
3587
+ const handler = new RpcHandler({
3588
+ commands: service.commandMap,
3589
+ methods: {
3590
+ "role.activate": async (params) => {
3591
+ return service.activate(params.individual);
3592
+ },
3593
+ inspect: async (params) => {
3594
+ return service.inspect(params.id);
3595
+ },
3596
+ survey: async (params) => {
3597
+ return service.survey(params.type);
3598
+ }
3599
+ }
3600
+ });
3601
+ return { handler, service };
3602
+ })();
3603
+ }
3604
+ return initPromise;
3605
+ }
3606
+ const call = async (method, params) => {
3607
+ const { handler } = await ensureInit();
3608
+ const response = await handler.handle({
3609
+ jsonrpc: "2.0",
3610
+ method,
3611
+ params,
3612
+ id: null
3613
+ });
3614
+ if (response.error) {
3615
+ throw new Error(response.error.message);
3616
+ }
3617
+ return response.result;
3618
+ };
3619
+ const _society = createSocietyNamespace(call);
3620
+ const _role = createRoleNamespace(call);
3621
+ const _org = createOrgNamespace(call);
3622
+ const _position = createPositionNamespace(call);
3623
+ const _project = createProjectNamespace(call);
3624
+ const _product = createProductNamespace(call);
3625
+ const _census = createCensusNamespace(call);
3626
+ const _issue = createIssueNamespace(call);
3627
+ const _resource = createResourceNamespace(call);
3628
+ return {
3629
+ get society() {
3630
+ return _society;
3631
+ },
3632
+ get role() {
3633
+ return _role;
3634
+ },
3635
+ get org() {
3636
+ return _org;
3637
+ },
3638
+ get position() {
3639
+ return _position;
3640
+ },
3641
+ get project() {
3642
+ return _project;
3643
+ },
3644
+ get product() {
3645
+ return _product;
3646
+ },
3647
+ get census() {
3648
+ return _census;
3649
+ },
3650
+ get issue() {
3651
+ return _issue;
3652
+ },
3653
+ get resource() {
3654
+ return _resource;
3655
+ },
3656
+ protocol,
3657
+ async rpc(request) {
3658
+ const { handler } = await ensureInit();
3659
+ return handler.handle(request);
3660
+ },
3661
+ async _internal() {
3662
+ const { service } = await ensureInit();
3663
+ return { service };
3664
+ }
3665
+ };
3666
+ }
3667
+
3668
+ // src/renderer.ts
3669
+ var RendererRouter = class {
3670
+ renderers = /* @__PURE__ */ new Map();
3671
+ /** Register a renderer for a command namespace. */
3672
+ register(namespace, renderer) {
3673
+ this.renderers.set(namespace, renderer);
3674
+ return this;
3675
+ }
3676
+ /** Route a command to the appropriate renderer. */
3677
+ render(command, result) {
3678
+ const dot = command.indexOf(".");
3679
+ const namespace = dot >= 0 ? command.slice(0, dot) : command;
3680
+ const renderer = this.renderers.get(namespace);
3681
+ if (renderer) return renderer.render(command, result);
3682
+ return defaultRender(command, result);
3683
+ }
3684
+ };
3685
+ function defaultRender(_command, result) {
3686
+ return JSON.stringify(result, null, 2);
3687
+ }
3435
3688
  export {
3436
3689
  RendererRouter,
3437
3690
  Role,
3438
3691
  RoleXService,
3692
+ RpcHandler,
3439
3693
  abandon,
3440
3694
  abolish,
3441
3695
  activate,
@@ -3451,6 +3705,7 @@ export {
3451
3705
  charterOrg,
3452
3706
  complete,
3453
3707
  create6 as create,
3708
+ createBuilder,
3454
3709
  createCommands,
3455
3710
  createRuntime,
3456
3711
  deliverProject,