@rolexjs/core 1.5.0-dev-20260317103808 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +19 -833
- package/dist/index.js +26 -3335
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as _rolexjs_system from '@rolexjs/system';
|
|
2
|
-
import { Runtime, Initializer
|
|
2
|
+
import { Runtime, Initializer } from '@rolexjs/system';
|
|
3
3
|
export { Create, GraphOp, Link, Process, Relation, Remove, Runtime, State, Structure, Transform, Unlink, create, createRuntime, link, process, relation, remove, structure, transform, unlink } from '@rolexjs/system';
|
|
4
|
+
import { IssueXProvider } from '@issuexjs/core';
|
|
5
|
+
import { ResourceXProvider, CustomExecutor } from '@resourcexjs/core';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Platform — external integration point for RoleX.
|
|
@@ -20,41 +22,11 @@ interface ContextData {
|
|
|
20
22
|
focusedGoalId: string | null;
|
|
21
23
|
focusedPlanId: string | null;
|
|
22
24
|
}
|
|
23
|
-
/**
|
|
24
|
-
interface
|
|
25
|
-
|
|
26
|
-
id: string;
|
|
27
|
-
|
|
28
|
-
instructions: Array<{
|
|
29
|
-
op: string;
|
|
30
|
-
args: Record<string, unknown>;
|
|
31
|
-
}>;
|
|
32
|
-
}
|
|
33
|
-
/** The unified prototype data structure. */
|
|
34
|
-
interface PrototypeData {
|
|
35
|
-
id: string;
|
|
36
|
-
source: string;
|
|
37
|
-
migrations: Migration[];
|
|
38
|
-
}
|
|
39
|
-
/** Migration history entry — records a single executed migration. */
|
|
40
|
-
interface MigrationRecord {
|
|
41
|
-
prototypeId: string;
|
|
42
|
-
migrationId: string;
|
|
43
|
-
version: number;
|
|
44
|
-
checksum: string;
|
|
45
|
-
executedAt: string;
|
|
46
|
-
}
|
|
47
|
-
/** Prototype registry — tracks which prototypes are settled and their migration history. */
|
|
48
|
-
interface PrototypeRepository {
|
|
49
|
-
settle(id: string, source: string): Promise<void>;
|
|
50
|
-
evict(id: string): Promise<void>;
|
|
51
|
-
list(): Promise<Record<string, string>>;
|
|
52
|
-
/** Record a migration as executed. */
|
|
53
|
-
recordMigration(prototypeId: string, migrationId: string, version: number, checksum: string): Promise<void>;
|
|
54
|
-
/** Get all executed migrations for a prototype, ordered by execution time. */
|
|
55
|
-
getMigrationHistory(prototypeId: string): Promise<MigrationRecord[]>;
|
|
56
|
-
/** Check if a specific migration has been executed. */
|
|
57
|
-
hasMigration(prototypeId: string, migrationId: string): Promise<boolean>;
|
|
25
|
+
/** Prototype registry — tracks which prototypes are settled. */
|
|
26
|
+
interface PrototypeRegistry {
|
|
27
|
+
settle(id: string, source: string): void;
|
|
28
|
+
evict(id: string): void;
|
|
29
|
+
list(): Record<string, string>;
|
|
58
30
|
}
|
|
59
31
|
/**
|
|
60
32
|
* RoleXRepository — unified data access layer.
|
|
@@ -66,7 +38,7 @@ interface RoleXRepository {
|
|
|
66
38
|
/** Graph operation engine. */
|
|
67
39
|
readonly runtime: Runtime;
|
|
68
40
|
/** Prototype registry — tracks which prototypes are settled. */
|
|
69
|
-
readonly prototype:
|
|
41
|
+
readonly prototype: PrototypeRegistry;
|
|
70
42
|
/** Save role context to persistent storage. */
|
|
71
43
|
saveContext(roleId: string, data: ContextData): Promise<void>;
|
|
72
44
|
/** Load role context from persistent storage. Returns null if none exists. */
|
|
@@ -75,8 +47,16 @@ interface RoleXRepository {
|
|
|
75
47
|
interface Platform {
|
|
76
48
|
/** Unified data access layer — graph, prototypes, contexts. */
|
|
77
49
|
readonly repository: RoleXRepository;
|
|
50
|
+
/** ResourceX provider — injected storage backend for resource management. */
|
|
51
|
+
readonly resourcexProvider?: ResourceXProvider;
|
|
52
|
+
/** Custom executor for ResourceX resolver execution (e.g., QuickJS Wasm for Workers). */
|
|
53
|
+
readonly resourcexExecutor?: CustomExecutor;
|
|
54
|
+
/** IssueX provider — injected storage backend for issue tracking. */
|
|
55
|
+
readonly issuexProvider?: IssueXProvider;
|
|
78
56
|
/** Initializer — bootstrap the world on first run. */
|
|
79
57
|
readonly initializer?: Initializer;
|
|
58
|
+
/** Prototype sources to settle on genesis (local paths or ResourceX locators). */
|
|
59
|
+
readonly bootstrap?: readonly string[];
|
|
80
60
|
}
|
|
81
61
|
|
|
82
62
|
declare const society: _rolexjs_system.Structure;
|
|
@@ -103,15 +83,7 @@ declare const scope: _rolexjs_system.Structure;
|
|
|
103
83
|
declare const milestone: _rolexjs_system.Structure;
|
|
104
84
|
declare const deliverable: _rolexjs_system.Structure;
|
|
105
85
|
declare const wiki: _rolexjs_system.Structure;
|
|
106
|
-
declare const product: _rolexjs_system.Structure;
|
|
107
|
-
declare const strategy: _rolexjs_system.Structure;
|
|
108
|
-
declare const spec: _rolexjs_system.Structure;
|
|
109
|
-
declare const release: _rolexjs_system.Structure;
|
|
110
|
-
declare const channel: _rolexjs_system.Structure;
|
|
111
|
-
declare const issue: _rolexjs_system.Structure;
|
|
112
|
-
declare const comment: _rolexjs_system.Structure;
|
|
113
86
|
|
|
114
|
-
declare const activate: _rolexjs_system.Process;
|
|
115
87
|
declare const want: _rolexjs_system.Process;
|
|
116
88
|
declare const planGoal: _rolexjs_system.Process;
|
|
117
89
|
declare const todo: _rolexjs_system.Process;
|
|
@@ -136,14 +108,6 @@ declare const scopeProject: _rolexjs_system.Process;
|
|
|
136
108
|
declare const milestoneProject: _rolexjs_system.Process;
|
|
137
109
|
declare const deliverProject: _rolexjs_system.Process;
|
|
138
110
|
declare const wikiProject: _rolexjs_system.Process;
|
|
139
|
-
declare const produceProject: _rolexjs_system.Process;
|
|
140
|
-
|
|
141
|
-
declare const ownProduct: _rolexjs_system.Process;
|
|
142
|
-
declare const disownProduct: _rolexjs_system.Process;
|
|
143
|
-
declare const strategyProduct: _rolexjs_system.Process;
|
|
144
|
-
declare const specProduct: _rolexjs_system.Process;
|
|
145
|
-
declare const releaseProduct: _rolexjs_system.Process;
|
|
146
|
-
declare const channelProduct: _rolexjs_system.Process;
|
|
147
111
|
|
|
148
112
|
declare const born: _rolexjs_system.Process;
|
|
149
113
|
declare const found: _rolexjs_system.Process;
|
|
@@ -152,788 +116,10 @@ declare const launch: _rolexjs_system.Process;
|
|
|
152
116
|
declare const retire: _rolexjs_system.Process;
|
|
153
117
|
declare const die: _rolexjs_system.Process;
|
|
154
118
|
declare const archive: _rolexjs_system.Process;
|
|
155
|
-
declare const deprecate: _rolexjs_system.Process;
|
|
156
119
|
declare const dissolve: _rolexjs_system.Process;
|
|
157
120
|
declare const abolish: _rolexjs_system.Process;
|
|
158
121
|
declare const rehire: _rolexjs_system.Process;
|
|
159
122
|
|
|
160
|
-
|
|
161
|
-
* Projection — the single projection pipeline for RoleX.
|
|
162
|
-
*
|
|
163
|
-
* Pipeline: raw project → compact(depth) → enrich permissions.
|
|
164
|
-
*
|
|
165
|
-
* All projections go through this pipeline. No special cases.
|
|
166
|
-
* Control behavior via ProjectionContext.
|
|
167
|
-
*
|
|
168
|
-
* Rules:
|
|
169
|
-
* - Root (depth 0): full
|
|
170
|
-
* - Level 1 children: full (with content)
|
|
171
|
-
* - Level 2+ grandchildren: compact (name/id/tag only, no subtree)
|
|
172
|
-
* - All link targets: compact (name/id/tag only, no subtree)
|
|
173
|
-
*/
|
|
174
|
-
|
|
175
|
-
interface ProjectionContext {
|
|
176
|
-
/** Children expansion depth. Default 1: one level fully expanded, then compact. */
|
|
177
|
-
depth?: number;
|
|
178
|
-
}
|
|
179
|
-
interface Projection {
|
|
180
|
-
/** Project a node through the full pipeline: raw → compact → enrich. */
|
|
181
|
-
(node: Structure, ctx?: ProjectionContext): Promise<State>;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Commands — shared type definitions.
|
|
186
|
-
*/
|
|
187
|
-
|
|
188
|
-
interface CommandResult {
|
|
189
|
-
state: State;
|
|
190
|
-
process: string;
|
|
191
|
-
}
|
|
192
|
-
interface CommandContext {
|
|
193
|
-
rt: Runtime;
|
|
194
|
-
society: Structure;
|
|
195
|
-
past: Structure;
|
|
196
|
-
resolve(id: string): Structure | Promise<Structure>;
|
|
197
|
-
find(id: string): (Structure | null) | Promise<Structure | null>;
|
|
198
|
-
project: Projection;
|
|
199
|
-
prototype?: PrototypeRepository;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* CommandResultMap — typed return type for every command.
|
|
203
|
-
*
|
|
204
|
-
* This is the source of truth for what each command returns.
|
|
205
|
-
* Renderer and consumers use this to know the shape of each result.
|
|
206
|
-
*/
|
|
207
|
-
interface CommandResultMap {
|
|
208
|
-
"society.born": CommandResult;
|
|
209
|
-
"society.retire": CommandResult;
|
|
210
|
-
"society.die": CommandResult;
|
|
211
|
-
"society.rehire": CommandResult;
|
|
212
|
-
"society.teach": CommandResult;
|
|
213
|
-
"society.train": CommandResult;
|
|
214
|
-
"role.focus": CommandResult;
|
|
215
|
-
"role.want": CommandResult;
|
|
216
|
-
"role.plan": CommandResult;
|
|
217
|
-
"role.todo": CommandResult;
|
|
218
|
-
"role.finish": CommandResult;
|
|
219
|
-
"role.complete": CommandResult;
|
|
220
|
-
"role.abandon": CommandResult;
|
|
221
|
-
"role.reflect": CommandResult;
|
|
222
|
-
"role.realize": CommandResult;
|
|
223
|
-
"role.master": CommandResult;
|
|
224
|
-
"role.forget": CommandResult;
|
|
225
|
-
"project.scope": CommandResult;
|
|
226
|
-
"project.milestone": CommandResult;
|
|
227
|
-
"project.achieve": CommandResult;
|
|
228
|
-
"project.enroll": CommandResult;
|
|
229
|
-
"project.remove": CommandResult;
|
|
230
|
-
"project.deliver": CommandResult;
|
|
231
|
-
"project.wiki": CommandResult;
|
|
232
|
-
"project.produce": CommandResult;
|
|
233
|
-
"project.maintain": CommandResult;
|
|
234
|
-
"project.unmaintain": CommandResult;
|
|
235
|
-
"product.strategy": CommandResult;
|
|
236
|
-
"product.spec": CommandResult;
|
|
237
|
-
"product.release": CommandResult;
|
|
238
|
-
"product.channel": CommandResult;
|
|
239
|
-
"product.own": CommandResult;
|
|
240
|
-
"product.disown": CommandResult;
|
|
241
|
-
"product.deprecate": CommandResult;
|
|
242
|
-
"society.found": CommandResult;
|
|
243
|
-
"org.charter": CommandResult;
|
|
244
|
-
"society.dissolve": CommandResult;
|
|
245
|
-
"org.hire": CommandResult;
|
|
246
|
-
"org.fire": CommandResult;
|
|
247
|
-
"org.admin": CommandResult;
|
|
248
|
-
"org.unadmin": CommandResult;
|
|
249
|
-
"org.launch": CommandResult;
|
|
250
|
-
"org.archive": CommandResult;
|
|
251
|
-
"org.establish": CommandResult;
|
|
252
|
-
"org.abolish": CommandResult;
|
|
253
|
-
"position.charge": CommandResult;
|
|
254
|
-
"position.require": CommandResult;
|
|
255
|
-
"position.appoint": CommandResult;
|
|
256
|
-
"position.dismiss": CommandResult;
|
|
257
|
-
"society.crown": CommandResult;
|
|
258
|
-
"society.uncrown": CommandResult;
|
|
259
|
-
"survey.list": CommandResult;
|
|
260
|
-
"issue.publish": CommandResult;
|
|
261
|
-
"issue.get": CommandResult;
|
|
262
|
-
"issue.list": CommandResult;
|
|
263
|
-
"issue.update": CommandResult;
|
|
264
|
-
"issue.close": CommandResult;
|
|
265
|
-
"issue.reopen": CommandResult;
|
|
266
|
-
"issue.assign": CommandResult;
|
|
267
|
-
"issue.comment": CommandResult;
|
|
268
|
-
"issue.comments": CommandResult;
|
|
269
|
-
"issue.label": CommandResult;
|
|
270
|
-
"issue.unlabel": CommandResult;
|
|
271
|
-
}
|
|
272
|
-
type Commands = Record<string, (...args: any[]) => any>;
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Commands — platform-agnostic command implementations.
|
|
276
|
-
*
|
|
277
|
-
* Every RoleX command is a pure function of (Runtime, args) -> CommandResult.
|
|
278
|
-
* No platform-specific code — all I/O goes through injected interfaces.
|
|
279
|
-
*
|
|
280
|
-
* Usage:
|
|
281
|
-
* const commands = createCommands({ rt, society, past, resolve, find, resourcex });
|
|
282
|
-
* const result = commands["society.born"]("Feature: Sean", "sean");
|
|
283
|
-
*/
|
|
284
|
-
|
|
285
|
-
declare function createCommands(ctx: CommandContext): Commands;
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Renderer — framework for rendering command results.
|
|
289
|
-
*
|
|
290
|
-
* Renderer interface and RendererRouter live here in prototype
|
|
291
|
-
* because this layer owns all command types and structures.
|
|
292
|
-
* Concrete renderers are registered by the upper layer (rolexjs).
|
|
293
|
-
*/
|
|
294
|
-
|
|
295
|
-
/** Renders a command result into a string (typically Markdown). */
|
|
296
|
-
interface Renderer {
|
|
297
|
-
render(command: string, result: CommandResult): string;
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* RendererRouter — routes commands to namespace-specific renderers.
|
|
301
|
-
*
|
|
302
|
-
* Registered renderers handle their namespace (e.g. "role" handles "role.want").
|
|
303
|
-
* Unregistered commands fall through to the default renderer (JSON serialization).
|
|
304
|
-
*/
|
|
305
|
-
declare class RendererRouter implements Renderer {
|
|
306
|
-
private readonly renderers;
|
|
307
|
-
/** Register a renderer for a command namespace. */
|
|
308
|
-
register(namespace: string, renderer: Renderer): this;
|
|
309
|
-
/** Route a command to the appropriate renderer. */
|
|
310
|
-
render(command: string, result: CommandResult): string;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Role — rich domain model (充血模型) for an individual.
|
|
315
|
-
*
|
|
316
|
-
* Role is a self-contained operation domain that holds:
|
|
317
|
-
* - State projection (read cache from graph)
|
|
318
|
-
* - Cursors (focusedGoalId, focusedPlanId)
|
|
319
|
-
* - Cognitive registries (encounters, experiences)
|
|
320
|
-
* - Domain behaviors (focus, want, plan, todo, finish, etc.)
|
|
321
|
-
*
|
|
322
|
-
* Design:
|
|
323
|
-
* - Role = Actor State, RoleX = ActorSystem
|
|
324
|
-
* - Ownership validation: hasNode() ensures isolation
|
|
325
|
-
* - KV-serializable: snapshot() / restore()
|
|
326
|
-
* - Single instance per individual
|
|
327
|
-
*/
|
|
328
|
-
|
|
329
|
-
/** Serializable role state for KV persistence. */
|
|
330
|
-
interface RoleSnapshot {
|
|
331
|
-
id: string;
|
|
332
|
-
focusedGoalId: string | null;
|
|
333
|
-
focusedPlanId: string | null;
|
|
334
|
-
encounterIds: string[];
|
|
335
|
-
experienceIds: string[];
|
|
336
|
-
}
|
|
337
|
-
/** Internal dependencies injected by RoleX at activate time. */
|
|
338
|
-
interface RoleDeps {
|
|
339
|
-
commands: Commands;
|
|
340
|
-
renderer: Renderer;
|
|
341
|
-
onSave(snapshot: RoleSnapshot): void | Promise<void>;
|
|
342
|
-
}
|
|
343
|
-
declare class Role {
|
|
344
|
-
readonly id: string;
|
|
345
|
-
private focusedGoalId;
|
|
346
|
-
private focusedPlanId;
|
|
347
|
-
private readonly encounterIds;
|
|
348
|
-
private readonly experienceIds;
|
|
349
|
-
/** Set of all node ids under this individual — for ownership validation. */
|
|
350
|
-
private readonly nodeIds;
|
|
351
|
-
private deps;
|
|
352
|
-
constructor(id: string, deps: RoleDeps);
|
|
353
|
-
/** Populate from state projection. Builds nodeIds set + cognitive registries. */
|
|
354
|
-
hydrate(state: State): void;
|
|
355
|
-
private walkState;
|
|
356
|
-
private hasNode;
|
|
357
|
-
private requireOwnership;
|
|
358
|
-
private requireGoalId;
|
|
359
|
-
private requirePlanId;
|
|
360
|
-
private fmt;
|
|
361
|
-
private save;
|
|
362
|
-
/** Serialize to KV-compatible snapshot. */
|
|
363
|
-
snapshot(): RoleSnapshot;
|
|
364
|
-
/** Restore cursors and cognitive state from a snapshot. */
|
|
365
|
-
restore(snap: RoleSnapshot): void;
|
|
366
|
-
/** Project the individual's state tree (used after activate). */
|
|
367
|
-
project(): Promise<string>;
|
|
368
|
-
/** Focus: view or switch focused goal. Validates ownership. */
|
|
369
|
-
focus(goal?: string): Promise<string>;
|
|
370
|
-
/** Want: declare a goal under this individual. */
|
|
371
|
-
want(goal?: string, id?: string, alias?: readonly string[]): Promise<string>;
|
|
372
|
-
/** Plan: create a plan for the focused goal. */
|
|
373
|
-
plan(plan?: string, id?: string, after?: string, fallback?: string): Promise<string>;
|
|
374
|
-
/** Todo: add a task to the focused plan. */
|
|
375
|
-
todo(task?: string, id?: string, alias?: readonly string[]): Promise<string>;
|
|
376
|
-
/** Finish: complete a task, optionally record an encounter. */
|
|
377
|
-
finish(task: string, encounter?: string): Promise<string>;
|
|
378
|
-
/** Complete: close a plan as done, record encounter. */
|
|
379
|
-
complete(plan?: string, encounter?: string): Promise<string>;
|
|
380
|
-
/** Abandon: drop a plan, record encounter. */
|
|
381
|
-
abandon(plan?: string, encounter?: string): Promise<string>;
|
|
382
|
-
/** Reflect: consume encounters → experience. */
|
|
383
|
-
reflect(encounters: string[], experience?: string, id?: string): Promise<string>;
|
|
384
|
-
/** Realize: consume experiences → principle. */
|
|
385
|
-
realize(experiences: string[], principle?: string, id?: string): Promise<string>;
|
|
386
|
-
/** Master: create procedure, optionally consuming experiences. */
|
|
387
|
-
master(procedure: string, id?: string, experiences?: string[]): Promise<string>;
|
|
388
|
-
/** Forget: remove any node under this individual by id. */
|
|
389
|
-
forget(nodeId: string): Promise<string>;
|
|
390
|
-
private cognitiveHint;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* RoleXService — runtime orchestrator (internal).
|
|
395
|
-
*
|
|
396
|
-
* Wires Platform → Commands, manages Role lifecycle, handles ResourceX/IssueX.
|
|
397
|
-
* Not exposed publicly — consumed by the RoleX entry point.
|
|
398
|
-
*
|
|
399
|
-
* Key responsibilities:
|
|
400
|
-
* - Initialize world roots (society, past)
|
|
401
|
-
* - Create and cache Role instances (one per individual)
|
|
402
|
-
* - Apply prototypes on first run
|
|
403
|
-
* - Dispatch direct commands
|
|
404
|
-
*/
|
|
405
|
-
|
|
406
|
-
interface RoleX {
|
|
407
|
-
activate(individual: string): Promise<Role>;
|
|
408
|
-
inspect(id: string, options?: {
|
|
409
|
-
raw?: boolean;
|
|
410
|
-
}): Promise<string | State>;
|
|
411
|
-
survey(type?: string, options?: {
|
|
412
|
-
raw?: boolean;
|
|
413
|
-
}): Promise<string | readonly State[]>;
|
|
414
|
-
direct<T = unknown>(locator: string, args?: Record<string, unknown>, options?: {
|
|
415
|
-
raw?: boolean;
|
|
416
|
-
}): Promise<T>;
|
|
417
|
-
}
|
|
418
|
-
declare class RoleXService implements RoleX {
|
|
419
|
-
private rt;
|
|
420
|
-
private commands;
|
|
421
|
-
private project;
|
|
422
|
-
private repo;
|
|
423
|
-
private readonly initializer?;
|
|
424
|
-
private readonly renderer;
|
|
425
|
-
private readonly prototypes;
|
|
426
|
-
private society;
|
|
427
|
-
private past;
|
|
428
|
-
/** Cached Role instances — one per individual. */
|
|
429
|
-
private readonly roles;
|
|
430
|
-
/** Expose commands for the RPC handler. */
|
|
431
|
-
get commandMap(): Commands;
|
|
432
|
-
/** Permission registry — maps relation names to permissions. */
|
|
433
|
-
private readonly permissions;
|
|
434
|
-
private constructor();
|
|
435
|
-
static create(platform: Platform, renderer: Renderer, prototypes?: readonly PrototypeData[]): Promise<RoleXService>;
|
|
436
|
-
private init;
|
|
437
|
-
activate(individual: string): Promise<Role>;
|
|
438
|
-
private findOrAutoBorn;
|
|
439
|
-
private saveSnapshot;
|
|
440
|
-
private restoreSnapshot;
|
|
441
|
-
inspect(id: string, options?: {
|
|
442
|
-
raw?: boolean;
|
|
443
|
-
}): Promise<string | State>;
|
|
444
|
-
survey(type?: string, options?: {
|
|
445
|
-
raw?: boolean;
|
|
446
|
-
}): Promise<string | readonly State[]>;
|
|
447
|
-
direct<T = unknown>(locator: string, args?: Record<string, unknown>, options?: {
|
|
448
|
-
raw?: boolean;
|
|
449
|
-
}): Promise<T>;
|
|
450
|
-
/** Find a node by id across the entire society tree (raw, no pipeline). */
|
|
451
|
-
private find;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* JSON-RPC 2.0 types and handler for RoleX.
|
|
456
|
-
*
|
|
457
|
-
* The RpcHandler is the single dispatch point for all RoleX operations.
|
|
458
|
-
* It accepts JSON-RPC 2.0 requests and delegates to the command layer
|
|
459
|
-
* via toArgs() for named-to-positional argument conversion.
|
|
460
|
-
*/
|
|
461
|
-
|
|
462
|
-
interface JsonRpcRequest {
|
|
463
|
-
jsonrpc: "2.0";
|
|
464
|
-
method: string;
|
|
465
|
-
params?: Record<string, unknown>;
|
|
466
|
-
id?: string | number | null;
|
|
467
|
-
}
|
|
468
|
-
interface JsonRpcResponse<T = unknown> {
|
|
469
|
-
jsonrpc: "2.0";
|
|
470
|
-
id: string | number | null;
|
|
471
|
-
result?: T;
|
|
472
|
-
error?: JsonRpcError;
|
|
473
|
-
}
|
|
474
|
-
interface JsonRpcError {
|
|
475
|
-
code: number;
|
|
476
|
-
message: string;
|
|
477
|
-
data?: unknown;
|
|
478
|
-
}
|
|
479
|
-
interface RpcHandlerDeps {
|
|
480
|
-
commands: Commands;
|
|
481
|
-
/** Custom method handlers for methods not in the commands map (e.g. activate, inspect, survey). */
|
|
482
|
-
methods?: Record<string, (params: Record<string, unknown>) => Promise<unknown>>;
|
|
483
|
-
}
|
|
484
|
-
declare class RpcHandler {
|
|
485
|
-
private commands;
|
|
486
|
-
private methods;
|
|
487
|
-
constructor(deps: RpcHandlerDeps);
|
|
488
|
-
handle<T = unknown>(request: JsonRpcRequest): Promise<JsonRpcResponse<T>>;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
/**
|
|
492
|
-
* Namespace interfaces and factories for RoleX builder API.
|
|
493
|
-
*
|
|
494
|
-
* Each namespace is a typed wrapper over the JSON-RPC caller function.
|
|
495
|
-
* Methods accept named parameter objects (matching JSON-RPC params)
|
|
496
|
-
* and return typed results.
|
|
497
|
-
*/
|
|
498
|
-
|
|
499
|
-
type Caller = (method: string, params?: Record<string, unknown>) => Promise<any>;
|
|
500
|
-
interface SocietyNamespace {
|
|
501
|
-
born(params: {
|
|
502
|
-
content?: string;
|
|
503
|
-
id: string;
|
|
504
|
-
alias?: string[];
|
|
505
|
-
}): Promise<CommandResult>;
|
|
506
|
-
retire(params: {
|
|
507
|
-
individual: string;
|
|
508
|
-
}): Promise<CommandResult>;
|
|
509
|
-
die(params: {
|
|
510
|
-
individual: string;
|
|
511
|
-
}): Promise<CommandResult>;
|
|
512
|
-
rehire(params: {
|
|
513
|
-
individual: string;
|
|
514
|
-
}): Promise<CommandResult>;
|
|
515
|
-
teach(params: {
|
|
516
|
-
individual: string;
|
|
517
|
-
content: string;
|
|
518
|
-
id: string;
|
|
519
|
-
}): Promise<CommandResult>;
|
|
520
|
-
train(params: {
|
|
521
|
-
individual: string;
|
|
522
|
-
content: string;
|
|
523
|
-
id: string;
|
|
524
|
-
}): Promise<CommandResult>;
|
|
525
|
-
found(params: {
|
|
526
|
-
content?: string;
|
|
527
|
-
id: string;
|
|
528
|
-
alias?: string[];
|
|
529
|
-
admin?: string;
|
|
530
|
-
}): Promise<CommandResult>;
|
|
531
|
-
dissolve(params: {
|
|
532
|
-
org: string;
|
|
533
|
-
}): Promise<CommandResult>;
|
|
534
|
-
crown(params: {
|
|
535
|
-
individual: string;
|
|
536
|
-
}): Promise<CommandResult>;
|
|
537
|
-
uncrown(params: {
|
|
538
|
-
individual: string;
|
|
539
|
-
}): Promise<CommandResult>;
|
|
540
|
-
}
|
|
541
|
-
interface IndividualNamespace {
|
|
542
|
-
activate(params: {
|
|
543
|
-
individual: string;
|
|
544
|
-
}): Promise<Role>;
|
|
545
|
-
}
|
|
546
|
-
interface OrgNamespace {
|
|
547
|
-
charter(params: {
|
|
548
|
-
org: string;
|
|
549
|
-
content: string;
|
|
550
|
-
id: string;
|
|
551
|
-
}): Promise<CommandResult>;
|
|
552
|
-
hire(params: {
|
|
553
|
-
org: string;
|
|
554
|
-
individual: string;
|
|
555
|
-
}): Promise<CommandResult>;
|
|
556
|
-
fire(params: {
|
|
557
|
-
org: string;
|
|
558
|
-
individual: string;
|
|
559
|
-
}): Promise<CommandResult>;
|
|
560
|
-
admin(params: {
|
|
561
|
-
org: string;
|
|
562
|
-
individual: string;
|
|
563
|
-
}): Promise<CommandResult>;
|
|
564
|
-
unadmin(params: {
|
|
565
|
-
org: string;
|
|
566
|
-
individual: string;
|
|
567
|
-
}): Promise<CommandResult>;
|
|
568
|
-
launch(params: {
|
|
569
|
-
content?: string;
|
|
570
|
-
id: string;
|
|
571
|
-
alias?: string[];
|
|
572
|
-
org?: string;
|
|
573
|
-
maintainer?: string;
|
|
574
|
-
}): Promise<CommandResult>;
|
|
575
|
-
archive(params: {
|
|
576
|
-
project: string;
|
|
577
|
-
}): Promise<CommandResult>;
|
|
578
|
-
establish(params: {
|
|
579
|
-
content?: string;
|
|
580
|
-
id: string;
|
|
581
|
-
alias?: string[];
|
|
582
|
-
}): Promise<CommandResult>;
|
|
583
|
-
abolish(params: {
|
|
584
|
-
position: string;
|
|
585
|
-
}): Promise<CommandResult>;
|
|
586
|
-
}
|
|
587
|
-
interface PositionNamespace {
|
|
588
|
-
charge(params: {
|
|
589
|
-
position: string;
|
|
590
|
-
content: string;
|
|
591
|
-
id: string;
|
|
592
|
-
}): Promise<CommandResult>;
|
|
593
|
-
require(params: {
|
|
594
|
-
position: string;
|
|
595
|
-
content: string;
|
|
596
|
-
id: string;
|
|
597
|
-
}): Promise<CommandResult>;
|
|
598
|
-
appoint(params: {
|
|
599
|
-
position: string;
|
|
600
|
-
individual: string;
|
|
601
|
-
}): Promise<CommandResult>;
|
|
602
|
-
dismiss(params: {
|
|
603
|
-
position: string;
|
|
604
|
-
individual: string;
|
|
605
|
-
}): Promise<CommandResult>;
|
|
606
|
-
}
|
|
607
|
-
interface ProjectNamespace {
|
|
608
|
-
scope(params: {
|
|
609
|
-
project: string;
|
|
610
|
-
content: string;
|
|
611
|
-
id: string;
|
|
612
|
-
}): Promise<CommandResult>;
|
|
613
|
-
milestone(params: {
|
|
614
|
-
project: string;
|
|
615
|
-
content: string;
|
|
616
|
-
id: string;
|
|
617
|
-
}): Promise<CommandResult>;
|
|
618
|
-
achieve(params: {
|
|
619
|
-
milestone: string;
|
|
620
|
-
}): Promise<CommandResult>;
|
|
621
|
-
enroll(params: {
|
|
622
|
-
project: string;
|
|
623
|
-
individual: string;
|
|
624
|
-
}): Promise<CommandResult>;
|
|
625
|
-
remove(params: {
|
|
626
|
-
project: string;
|
|
627
|
-
individual: string;
|
|
628
|
-
}): Promise<CommandResult>;
|
|
629
|
-
deliver(params: {
|
|
630
|
-
project: string;
|
|
631
|
-
content: string;
|
|
632
|
-
id: string;
|
|
633
|
-
}): Promise<CommandResult>;
|
|
634
|
-
wiki(params: {
|
|
635
|
-
project: string;
|
|
636
|
-
content: string;
|
|
637
|
-
id: string;
|
|
638
|
-
}): Promise<CommandResult>;
|
|
639
|
-
produce(params: {
|
|
640
|
-
project: string;
|
|
641
|
-
content?: string;
|
|
642
|
-
id: string;
|
|
643
|
-
alias?: string[];
|
|
644
|
-
owner?: string;
|
|
645
|
-
}): Promise<CommandResult>;
|
|
646
|
-
maintain(params: {
|
|
647
|
-
project: string;
|
|
648
|
-
individual: string;
|
|
649
|
-
}): Promise<CommandResult>;
|
|
650
|
-
unmaintain(params: {
|
|
651
|
-
project: string;
|
|
652
|
-
individual: string;
|
|
653
|
-
}): Promise<CommandResult>;
|
|
654
|
-
}
|
|
655
|
-
interface ProductNamespace {
|
|
656
|
-
strategy(params: {
|
|
657
|
-
product: string;
|
|
658
|
-
content: string;
|
|
659
|
-
id: string;
|
|
660
|
-
}): Promise<CommandResult>;
|
|
661
|
-
spec(params: {
|
|
662
|
-
product: string;
|
|
663
|
-
content: string;
|
|
664
|
-
id: string;
|
|
665
|
-
}): Promise<CommandResult>;
|
|
666
|
-
release(params: {
|
|
667
|
-
product: string;
|
|
668
|
-
content: string;
|
|
669
|
-
id: string;
|
|
670
|
-
}): Promise<CommandResult>;
|
|
671
|
-
channel(params: {
|
|
672
|
-
product: string;
|
|
673
|
-
content: string;
|
|
674
|
-
id: string;
|
|
675
|
-
}): Promise<CommandResult>;
|
|
676
|
-
own(params: {
|
|
677
|
-
product: string;
|
|
678
|
-
individual: string;
|
|
679
|
-
}): Promise<CommandResult>;
|
|
680
|
-
disown(params: {
|
|
681
|
-
product: string;
|
|
682
|
-
individual: string;
|
|
683
|
-
}): Promise<CommandResult>;
|
|
684
|
-
deprecate(params: {
|
|
685
|
-
product: string;
|
|
686
|
-
}): Promise<CommandResult>;
|
|
687
|
-
}
|
|
688
|
-
interface IssueNamespace {
|
|
689
|
-
publish(params: {
|
|
690
|
-
title: string;
|
|
691
|
-
body: string;
|
|
692
|
-
author: string;
|
|
693
|
-
assignee?: string;
|
|
694
|
-
}): Promise<CommandResult>;
|
|
695
|
-
get(params: {
|
|
696
|
-
number: number;
|
|
697
|
-
}): Promise<CommandResult>;
|
|
698
|
-
list(params?: {
|
|
699
|
-
status?: string;
|
|
700
|
-
author?: string;
|
|
701
|
-
assignee?: string;
|
|
702
|
-
label?: string;
|
|
703
|
-
}): Promise<CommandResult>;
|
|
704
|
-
update(params: {
|
|
705
|
-
number: number;
|
|
706
|
-
title?: string;
|
|
707
|
-
body?: string;
|
|
708
|
-
assignee?: string;
|
|
709
|
-
}): Promise<CommandResult>;
|
|
710
|
-
close(params: {
|
|
711
|
-
number: number;
|
|
712
|
-
}): Promise<CommandResult>;
|
|
713
|
-
reopen(params: {
|
|
714
|
-
number: number;
|
|
715
|
-
}): Promise<CommandResult>;
|
|
716
|
-
assign(params: {
|
|
717
|
-
number: number;
|
|
718
|
-
assignee: string;
|
|
719
|
-
}): Promise<CommandResult>;
|
|
720
|
-
comment(params: {
|
|
721
|
-
number: number;
|
|
722
|
-
body: string;
|
|
723
|
-
author: string;
|
|
724
|
-
}): Promise<CommandResult>;
|
|
725
|
-
comments(params: {
|
|
726
|
-
number: number;
|
|
727
|
-
}): Promise<CommandResult>;
|
|
728
|
-
label(params: {
|
|
729
|
-
number: number;
|
|
730
|
-
label: string;
|
|
731
|
-
}): Promise<CommandResult>;
|
|
732
|
-
unlabel(params: {
|
|
733
|
-
number: number;
|
|
734
|
-
label: string;
|
|
735
|
-
}): Promise<CommandResult>;
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
/**
|
|
739
|
-
* Schema types for RoleX instruction definitions.
|
|
740
|
-
*
|
|
741
|
-
* These types define the structure of every RoleX operation:
|
|
742
|
-
* parameter types, descriptions, and positional arg ordering.
|
|
743
|
-
*/
|
|
744
|
-
/** Supported parameter types for instruction definitions. */
|
|
745
|
-
type ParamType = "string" | "number" | "gherkin" | "string[]" | "record";
|
|
746
|
-
/** Definition of a single parameter in an instruction. */
|
|
747
|
-
interface ParamDef {
|
|
748
|
-
type: ParamType;
|
|
749
|
-
required: boolean;
|
|
750
|
-
description: string;
|
|
751
|
-
}
|
|
752
|
-
/**
|
|
753
|
-
* A single positional argument entry.
|
|
754
|
-
*
|
|
755
|
-
* - `string` — simple lookup: `args[name]`
|
|
756
|
-
* - `{ pack: [...] }` — collect named args into an options object;
|
|
757
|
-
* returns `undefined` if all values are absent.
|
|
758
|
-
*/
|
|
759
|
-
type ArgEntry = string | {
|
|
760
|
-
pack: readonly string[];
|
|
761
|
-
};
|
|
762
|
-
/** Full definition of a RoleX instruction (one namespace.method). */
|
|
763
|
-
interface InstructionDef {
|
|
764
|
-
namespace: string;
|
|
765
|
-
method: string;
|
|
766
|
-
/** Parameter definitions — keyed by param name, used for MCP/CLI schema generation. */
|
|
767
|
-
params: Record<string, ParamDef>;
|
|
768
|
-
/** Positional argument order — maps named args to method call positions. */
|
|
769
|
-
args: readonly ArgEntry[];
|
|
770
|
-
}
|
|
771
|
-
/** RoleX tool definition — schema for a top-level tool (activate, want, use, etc.). */
|
|
772
|
-
interface ToolDef {
|
|
773
|
-
/** Tool name (e.g. "activate", "use"). */
|
|
774
|
-
name: string;
|
|
775
|
-
/** Full Gherkin description of the tool's behavior. */
|
|
776
|
-
description: string;
|
|
777
|
-
/** Parameter definitions — keyed by param name. */
|
|
778
|
-
params: Record<string, ParamDef>;
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
/**
|
|
782
|
-
* RoleX tool definitions — the single source of truth for all tool schemas.
|
|
783
|
-
*
|
|
784
|
-
* Channel-agnostic: MCP, CLI, REST, A2A each convert to their own format.
|
|
785
|
-
* Each ToolDef is self-contained: name + description + params.
|
|
786
|
-
*/
|
|
787
|
-
|
|
788
|
-
/**
|
|
789
|
-
* Protocol — the complete interface contract for channel adapters.
|
|
790
|
-
*
|
|
791
|
-
* Any adapter (MCP, CLI, REST, A2A) only needs this object
|
|
792
|
-
* to know what tools exist and what instructions to present.
|
|
793
|
-
*/
|
|
794
|
-
interface Protocol {
|
|
795
|
-
/** All tool definitions — self-contained with description + parameter schemas. */
|
|
796
|
-
tools: ToolDef[];
|
|
797
|
-
/** World-level instructions — the cognitive framework for AI roles. */
|
|
798
|
-
instructions: string;
|
|
799
|
-
}
|
|
800
|
-
/** The protocol instance — single source of truth for all channel adapters. */
|
|
801
|
-
declare const protocol: Protocol;
|
|
802
|
-
|
|
803
|
-
/**
|
|
804
|
-
* RoleX Builder — synchronous factory with lazy initialization.
|
|
805
|
-
*
|
|
806
|
-
* Usage:
|
|
807
|
-
* const rx = createBuilder({ platform, renderer });
|
|
808
|
-
* const role = await rx.individual.activate({ individual: "sean" });
|
|
809
|
-
* await rx.society.born({ id: "alice", content: "Feature: Alice" });
|
|
810
|
-
*/
|
|
811
|
-
|
|
812
|
-
interface RoleXInternal {
|
|
813
|
-
service: RoleXService;
|
|
814
|
-
}
|
|
815
|
-
interface RoleXBuilder {
|
|
816
|
-
/** Society-level operations — born, retire, crown, teach, train, found, dissolve. */
|
|
817
|
-
readonly society: SocietyNamespace;
|
|
818
|
-
/** Individual operations — activate. */
|
|
819
|
-
readonly individual: IndividualNamespace;
|
|
820
|
-
/** Organization operations — charter, hire, fire, admin, launch, establish. */
|
|
821
|
-
readonly org: OrgNamespace;
|
|
822
|
-
/** Position operations — charge, require, appoint, dismiss. */
|
|
823
|
-
readonly position: PositionNamespace;
|
|
824
|
-
/** Project operations — scope, milestone, enroll, deliver, produce. */
|
|
825
|
-
readonly project: ProjectNamespace;
|
|
826
|
-
/** Product operations — strategy, spec, release, channel, own. */
|
|
827
|
-
readonly product: ProductNamespace;
|
|
828
|
-
/** Issue tracking integration. */
|
|
829
|
-
readonly issue: IssueNamespace;
|
|
830
|
-
/** Inspect any node's full state — world-level observation. */
|
|
831
|
-
inspect(params: {
|
|
832
|
-
id: string;
|
|
833
|
-
raw?: boolean;
|
|
834
|
-
}): Promise<string | State>;
|
|
835
|
-
/** Survey the world — list individuals, organizations, positions. */
|
|
836
|
-
survey(params?: {
|
|
837
|
-
type?: string;
|
|
838
|
-
raw?: boolean;
|
|
839
|
-
}): Promise<string | readonly State[]>;
|
|
840
|
-
/** Tool schemas + world instructions — the unified contract for any channel adapter. */
|
|
841
|
-
readonly protocol: Protocol;
|
|
842
|
-
/** Universal JSON-RPC 2.0 dispatch. */
|
|
843
|
-
rpc<T = unknown>(request: JsonRpcRequest): Promise<JsonRpcResponse<T>>;
|
|
844
|
-
/** Internal access for testing — not part of the public contract. */
|
|
845
|
-
_internal(): Promise<RoleXInternal>;
|
|
846
|
-
}
|
|
847
|
-
interface BuilderConfig {
|
|
848
|
-
platform: Platform;
|
|
849
|
-
renderer: Renderer;
|
|
850
|
-
/** Built-in prototypes to apply on initialization (e.g. genesis). */
|
|
851
|
-
prototypes?: readonly PrototypeData[];
|
|
852
|
-
}
|
|
853
|
-
declare function createBuilder(config: BuilderConfig): RoleXBuilder;
|
|
854
|
-
|
|
855
|
-
/**
|
|
856
|
-
* Find — unified node lookup with priority-based disambiguation.
|
|
857
|
-
*
|
|
858
|
-
* When multiple nodes share the same id (allowed after relaxing
|
|
859
|
-
* global uniqueness), prefer "addressable" nodes over internal metadata.
|
|
860
|
-
*
|
|
861
|
-
* Priority (lower = preferred):
|
|
862
|
-
* 0: individual, organization, position — top-level entities
|
|
863
|
-
* 1: goal — execution roots
|
|
864
|
-
* 2: plan, task — execution nodes
|
|
865
|
-
* 3: procedure, principle — individual knowledge
|
|
866
|
-
* 4: encounter, experience — cognition artifacts
|
|
867
|
-
* 5: identity, charter — structural definitions
|
|
868
|
-
* 6: duty, requirement, background, etc. — internal metadata
|
|
869
|
-
*/
|
|
870
|
-
|
|
871
|
-
/**
|
|
872
|
-
* Find a node by id or alias in a state tree.
|
|
873
|
-
*
|
|
874
|
-
* When multiple nodes match, returns the one with the highest priority
|
|
875
|
-
* (top-level entities > execution nodes > knowledge > metadata).
|
|
876
|
-
*/
|
|
877
|
-
declare function findInState(state: State, target: string): Structure | null;
|
|
878
|
-
|
|
879
|
-
/**
|
|
880
|
-
* applyPrototype — apply a prototype's migrations incrementally.
|
|
881
|
-
*
|
|
882
|
-
* Pure function: receives data + storage + executor, no framework coupling.
|
|
883
|
-
* Checks migration history, executes only unapplied migrations, records each.
|
|
884
|
-
*/
|
|
885
|
-
|
|
886
|
-
/** Result of applying a prototype. */
|
|
887
|
-
interface ApplyResult {
|
|
888
|
-
prototypeId: string;
|
|
889
|
-
applied: number;
|
|
890
|
-
skipped: number;
|
|
891
|
-
upToDate: boolean;
|
|
892
|
-
}
|
|
893
|
-
/**
|
|
894
|
-
* Apply a prototype — execute unapplied migrations in version order.
|
|
895
|
-
*
|
|
896
|
-
* @param data - The prototype data structure with migrations
|
|
897
|
-
* @param repo - Storage layer for migration history
|
|
898
|
-
* @param direct - Executor for prototype instructions
|
|
899
|
-
*/
|
|
900
|
-
declare function applyPrototype(data: PrototypeData, repo: PrototypeRepository, direct: (op: string, args: Record<string, unknown>) => Promise<unknown>): Promise<ApplyResult>;
|
|
901
|
-
|
|
902
|
-
/**
|
|
903
|
-
* descriptions — AUTO-GENERATED by scripts/gen-descriptions.ts
|
|
904
|
-
*
|
|
905
|
-
* DO NOT EDIT MANUALLY. Run `bun run gen:desc` to regenerate.
|
|
906
|
-
*
|
|
907
|
-
* Source: descriptions/{system}/{process}.feature (69 files)
|
|
908
|
-
*/
|
|
909
|
-
declare const WORLD_TOPICS: readonly ["cognition", "cognitive-priority", "command-system", "communication", "execution", "gherkin", "identity-ethics", "inspect", "issue", "memory", "role-identity", "skill-system", "state-origin", "survey", "use-protocol"];
|
|
910
|
-
type WorldTopic = (typeof WORLD_TOPICS)[number];
|
|
911
|
-
declare const world: Record<WorldTopic, string>;
|
|
912
|
-
declare const processes: Record<string, string>;
|
|
913
|
-
|
|
914
|
-
declare const directives: Record<string, Record<string, string>>;
|
|
915
|
-
|
|
916
|
-
/**
|
|
917
|
-
* Dispatch — schema-driven argument mapping.
|
|
918
|
-
*
|
|
919
|
-
* Replaces the hand-written toArgs switch in rolex.ts with a single
|
|
920
|
-
* lookup against the instruction registry.
|
|
921
|
-
*/
|
|
922
|
-
/**
|
|
923
|
-
* Map named arguments to positional arguments for a given operation.
|
|
924
|
-
*
|
|
925
|
-
* @param op - Operation key in "namespace.method" format (e.g. "society.born")
|
|
926
|
-
* @param args - Named arguments from the caller
|
|
927
|
-
* @returns Positional argument array matching the method signature
|
|
928
|
-
*/
|
|
929
|
-
declare function toArgs(op: string, args: Record<string, unknown>): unknown[];
|
|
930
|
-
|
|
931
|
-
/**
|
|
932
|
-
* Instruction set — schema definitions for all RoleX operations.
|
|
933
|
-
*
|
|
934
|
-
* Covers every namespace.method that can be dispatched through `use()`.
|
|
935
|
-
*/
|
|
936
|
-
|
|
937
|
-
declare const instructions: Record<string, InstructionDef>;
|
|
123
|
+
declare const activate: _rolexjs_system.Process;
|
|
938
124
|
|
|
939
|
-
export { type
|
|
125
|
+
export { type ContextData, type Platform, type PrototypeRegistry, type RoleXRepository, abandon, abolish, activate, appoint, archive, background, born, charge, charter, charterOrg, complete, deliverProject, deliverable, die, dismiss, dissolve, duty, encounter, enroll, establish, experience, finish, fire, found, goal, hire, identity, individual, launch, master, milestone, milestoneProject, mindset, organization, past, plan, planGoal, position, principle, procedure, project, realize, reflect, rehire, removeParticipant, requirement, retire, scope, scopeProject, society, task, todo, tone, want, wiki, wikiProject };
|