@rolexjs/core 1.4.0-dev-20260305032702 → 1.4.0-dev-20260305092016

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import * as _rolexjs_system from '@rolexjs/system';
2
- import { Runtime, Initializer } from '@rolexjs/system';
2
+ import { Runtime, Initializer, Structure, State } 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
4
  import { IssueXProvider } from '@issuexjs/core';
5
5
  import { ResourceXProvider, CustomExecutor } from '@resourcexjs/core';
6
+ import { IssueX, Issue, Comment } from 'issuexjs';
7
+ import { ResourceX, Resource, RXM } from 'resourcexjs';
6
8
 
7
9
  /**
8
10
  * Platform — external integration point for RoleX.
@@ -114,6 +116,7 @@ declare const milestone: _rolexjs_system.Structure;
114
116
  declare const deliverable: _rolexjs_system.Structure;
115
117
  declare const wiki: _rolexjs_system.Structure;
116
118
 
119
+ declare const activate: _rolexjs_system.Process;
117
120
  declare const want: _rolexjs_system.Process;
118
121
  declare const planGoal: _rolexjs_system.Process;
119
122
  declare const todo: _rolexjs_system.Process;
@@ -150,6 +153,397 @@ declare const dissolve: _rolexjs_system.Process;
150
153
  declare const abolish: _rolexjs_system.Process;
151
154
  declare const rehire: _rolexjs_system.Process;
152
155
 
153
- declare const activate: _rolexjs_system.Process;
156
+ /**
157
+ * Commands — platform-agnostic command implementations.
158
+ *
159
+ * Every RoleX command is a pure function of (Runtime, args) → CommandResult.
160
+ * No platform-specific code — all I/O goes through injected interfaces.
161
+ *
162
+ * Usage:
163
+ * const commands = createCommands({ rt, society, past, resolve, find, resourcex });
164
+ * const result = commands["individual.born"]("Feature: Sean", "sean");
165
+ */
166
+
167
+ interface CommandResult {
168
+ state: State;
169
+ process: string;
170
+ }
171
+ interface CommandContext {
172
+ rt: Runtime;
173
+ society: Structure;
174
+ past: Structure;
175
+ resolve(id: string): Structure | Promise<Structure>;
176
+ find(id: string): (Structure | null) | Promise<Structure | null>;
177
+ resourcex?: ResourceX;
178
+ issuex?: IssueX;
179
+ prototype?: PrototypeRepository;
180
+ direct?(locator: string, args?: Record<string, unknown>): Promise<unknown>;
181
+ }
182
+ /**
183
+ * CommandResultMap — typed return type for every command.
184
+ *
185
+ * This is the source of truth for what each command returns.
186
+ * Renderer and consumers use this to know the shape of each result.
187
+ */
188
+ interface CommandResultMap {
189
+ "individual.born": CommandResult;
190
+ "individual.retire": CommandResult;
191
+ "individual.die": CommandResult;
192
+ "individual.rehire": CommandResult;
193
+ "individual.teach": CommandResult;
194
+ "individual.train": CommandResult;
195
+ "role.focus": CommandResult;
196
+ "role.want": CommandResult;
197
+ "role.plan": CommandResult;
198
+ "role.todo": CommandResult;
199
+ "role.finish": CommandResult;
200
+ "role.complete": CommandResult;
201
+ "role.abandon": CommandResult;
202
+ "role.reflect": CommandResult;
203
+ "role.realize": CommandResult;
204
+ "role.master": CommandResult;
205
+ "role.forget": CommandResult;
206
+ "role.skill": string;
207
+ "project.launch": CommandResult;
208
+ "project.scope": CommandResult;
209
+ "project.milestone": CommandResult;
210
+ "project.achieve": CommandResult;
211
+ "project.enroll": CommandResult;
212
+ "project.remove": CommandResult;
213
+ "project.deliver": CommandResult;
214
+ "project.wiki": CommandResult;
215
+ "project.archive": CommandResult;
216
+ "org.found": CommandResult;
217
+ "org.charter": CommandResult;
218
+ "org.dissolve": CommandResult;
219
+ "org.hire": CommandResult;
220
+ "org.fire": CommandResult;
221
+ "position.establish": CommandResult;
222
+ "position.charge": CommandResult;
223
+ "position.require": CommandResult;
224
+ "position.abolish": CommandResult;
225
+ "position.appoint": CommandResult;
226
+ "position.dismiss": CommandResult;
227
+ "census.list": CommandResult;
228
+ "issue.publish": Issue;
229
+ "issue.get": Issue | null;
230
+ "issue.list": Issue[];
231
+ "issue.update": Issue;
232
+ "issue.close": Issue;
233
+ "issue.reopen": Issue;
234
+ "issue.assign": Issue;
235
+ "issue.comment": Comment;
236
+ "issue.comments": Comment[];
237
+ "issue.label": Issue | null;
238
+ "issue.unlabel": Issue | null;
239
+ "resource.add": Resource;
240
+ "resource.search": string[];
241
+ "resource.has": boolean;
242
+ "resource.info": Resource;
243
+ "resource.remove": undefined;
244
+ "resource.push": RXM;
245
+ "resource.pull": undefined;
246
+ "resource.clearCache": undefined;
247
+ }
248
+ type Commands = Record<string, (...args: any[]) => any>;
249
+ declare function createCommands(ctx: CommandContext): Commands;
250
+
251
+ /**
252
+ * Renderer — framework for rendering command results.
253
+ *
254
+ * Renderer interface and RendererRouter live here in prototype
255
+ * because this layer owns all command types and structures.
256
+ * Concrete renderers are registered by the upper layer (rolexjs).
257
+ */
258
+
259
+ /** Renders a command result into a string (typically Markdown). */
260
+ interface Renderer {
261
+ render(command: string, result: CommandResult): string;
262
+ }
263
+ /**
264
+ * RendererRouter — routes commands to namespace-specific renderers.
265
+ *
266
+ * Registered renderers handle their namespace (e.g. "role" handles "role.want").
267
+ * Unregistered commands fall through to the default renderer (JSON serialization).
268
+ */
269
+ declare class RendererRouter implements Renderer {
270
+ private readonly renderers;
271
+ /** Register a renderer for a command namespace. */
272
+ register(namespace: string, renderer: Renderer): this;
273
+ /** Route a command to the appropriate renderer. */
274
+ render(command: string, result: CommandResult): string;
275
+ }
276
+
277
+ /**
278
+ * Role — rich domain model (充血模型) for an individual.
279
+ *
280
+ * Role is a self-contained operation domain that holds:
281
+ * - State projection (read cache from graph)
282
+ * - Cursors (focusedGoalId, focusedPlanId)
283
+ * - Cognitive registries (encounters, experiences)
284
+ * - Domain behaviors (focus, want, plan, todo, finish, etc.)
285
+ *
286
+ * Design:
287
+ * - Role = Actor State, RoleX = ActorSystem
288
+ * - Ownership validation: hasNode() ensures isolation
289
+ * - KV-serializable: snapshot() / restore()
290
+ * - Single instance per individual
291
+ */
292
+
293
+ /** Serializable role state for KV persistence. */
294
+ interface RoleSnapshot {
295
+ id: string;
296
+ focusedGoalId: string | null;
297
+ focusedPlanId: string | null;
298
+ encounterIds: string[];
299
+ experienceIds: string[];
300
+ }
301
+ /** Internal dependencies injected by RoleX at activate time. */
302
+ interface RoleDeps {
303
+ commands: Commands;
304
+ renderer: Renderer;
305
+ onSave(snapshot: RoleSnapshot): void | Promise<void>;
306
+ /** Direct execution — for `use` method. Provided by RoleXService. */
307
+ direct?<T>(locator: string, args?: Record<string, unknown>): Promise<T>;
308
+ /** Post-process `use` results (e.g., issue rendering). Provided by upper layer. */
309
+ transformUseResult?<T>(locator: string, result: T): Promise<T>;
310
+ }
311
+ declare class Role {
312
+ readonly id: string;
313
+ private focusedGoalId;
314
+ private focusedPlanId;
315
+ private readonly encounterIds;
316
+ private readonly experienceIds;
317
+ /** Set of all node ids under this individual — for ownership validation. */
318
+ private readonly nodeIds;
319
+ private deps;
320
+ constructor(id: string, deps: RoleDeps);
321
+ /** Populate from state projection. Builds nodeIds set + cognitive registries. */
322
+ hydrate(state: State): void;
323
+ private walkState;
324
+ private hasNode;
325
+ private requireOwnership;
326
+ private requireGoalId;
327
+ private requirePlanId;
328
+ private fmt;
329
+ private save;
330
+ /** Serialize to KV-compatible snapshot. */
331
+ snapshot(): RoleSnapshot;
332
+ /** Restore cursors and cognitive state from a snapshot. */
333
+ restore(snap: RoleSnapshot): void;
334
+ /** Project the individual's state tree (used after activate). */
335
+ project(): Promise<string>;
336
+ /** Focus: view or switch focused goal. Validates ownership. */
337
+ focus(goal?: string): Promise<string>;
338
+ /** Want: declare a goal under this individual. */
339
+ want(goal?: string, id?: string, alias?: readonly string[]): Promise<string>;
340
+ /** Plan: create a plan for the focused goal. */
341
+ plan(plan?: string, id?: string, after?: string, fallback?: string): Promise<string>;
342
+ /** Todo: add a task to the focused plan. */
343
+ todo(task?: string, id?: string, alias?: readonly string[]): Promise<string>;
344
+ /** Finish: complete a task, optionally record an encounter. */
345
+ finish(task: string, encounter?: string): Promise<string>;
346
+ /** Complete: close a plan as done, record encounter. */
347
+ complete(plan?: string, encounter?: string): Promise<string>;
348
+ /** Abandon: drop a plan, record encounter. */
349
+ abandon(plan?: string, encounter?: string): Promise<string>;
350
+ /** Reflect: consume encounters → experience. */
351
+ reflect(encounters: string[], experience?: string, id?: string): Promise<string>;
352
+ /** Realize: consume experiences → principle. */
353
+ realize(experiences: string[], principle?: string, id?: string): Promise<string>;
354
+ /** Master: create procedure, optionally consuming experiences. */
355
+ master(procedure: string, id?: string, experiences?: string[]): Promise<string>;
356
+ /** Forget: remove any node under this individual by id. */
357
+ forget(nodeId: string): Promise<string>;
358
+ /** Skill: load full skill content by locator. */
359
+ skill(locator: string): Promise<string>;
360
+ /** Use: subjective execution — `!ns.method` or ResourceX locator. */
361
+ use<T = unknown>(locator: string, args?: Record<string, unknown>): Promise<T>;
362
+ private cognitiveHint;
363
+ }
364
+
365
+ /**
366
+ * RoleXService — runtime orchestrator (internal).
367
+ *
368
+ * Wires Platform → Commands, manages Role lifecycle, handles ResourceX/IssueX.
369
+ * Not exposed publicly — consumed by the RoleX entry point.
370
+ *
371
+ * Key responsibilities:
372
+ * - Initialize world roots (society, past)
373
+ * - Create and cache Role instances (one per individual)
374
+ * - Apply prototypes on first run
375
+ * - Dispatch direct commands
376
+ */
377
+
378
+ interface RoleX {
379
+ activate(individual: string): Promise<Role>;
380
+ direct<T = unknown>(locator: string, args?: Record<string, unknown>, options?: {
381
+ raw?: boolean;
382
+ }): Promise<T>;
383
+ }
384
+ declare class RoleXService implements RoleX {
385
+ private rt;
386
+ private commands;
387
+ private resourcex?;
388
+ private issuex?;
389
+ private repo;
390
+ private readonly initializer?;
391
+ private readonly renderer;
392
+ private readonly prototypes;
393
+ private society;
394
+ private past;
395
+ /** Cached Role instances — one per individual. */
396
+ private readonly roles;
397
+ private constructor();
398
+ static create(platform: Platform, renderer: Renderer): Promise<RoleXService>;
399
+ private init;
400
+ activate(individual: string): Promise<Role>;
401
+ private findOrAutoBorn;
402
+ private saveSnapshot;
403
+ private restoreSnapshot;
404
+ direct<T = unknown>(locator: string, args?: Record<string, unknown>, options?: {
405
+ raw?: boolean;
406
+ }): Promise<T>;
407
+ private find;
408
+ }
409
+
410
+ /**
411
+ * Find — unified node lookup with priority-based disambiguation.
412
+ *
413
+ * When multiple nodes share the same id (allowed after relaxing
414
+ * global uniqueness), prefer "addressable" nodes over internal metadata.
415
+ *
416
+ * Priority (lower = preferred):
417
+ * 0: individual, organization, position — top-level entities
418
+ * 1: goal — execution roots
419
+ * 2: plan, task — execution nodes
420
+ * 3: procedure, principle — individual knowledge
421
+ * 4: encounter, experience — cognition artifacts
422
+ * 5: identity, charter — structural definitions
423
+ * 6: duty, requirement, background, etc. — internal metadata
424
+ */
425
+
426
+ /**
427
+ * Find a node by id or alias in a state tree.
428
+ *
429
+ * When multiple nodes match, returns the one with the highest priority
430
+ * (top-level entities > execution nodes > knowledge > metadata).
431
+ */
432
+ declare function findInState(state: State, target: string): Structure | null;
433
+
434
+ /**
435
+ * applyPrototype — apply a prototype's migrations incrementally.
436
+ *
437
+ * Pure function: receives data + storage + executor, no framework coupling.
438
+ * Checks migration history, executes only unapplied migrations, records each.
439
+ */
440
+
441
+ /** Result of applying a prototype. */
442
+ interface ApplyResult {
443
+ prototypeId: string;
444
+ applied: number;
445
+ skipped: number;
446
+ upToDate: boolean;
447
+ }
448
+ /**
449
+ * Apply a prototype — execute unapplied migrations in version order.
450
+ *
451
+ * @param data - The prototype data structure with migrations
452
+ * @param repo - Storage layer for migration history
453
+ * @param direct - Executor for prototype instructions
454
+ */
455
+ declare function applyPrototype(data: PrototypeData, repo: PrototypeRepository, direct: (op: string, args: Record<string, unknown>) => Promise<unknown>): Promise<ApplyResult>;
456
+
457
+ declare const processes: Record<string, string>;
458
+ declare const world: Record<string, string>;
459
+
460
+ declare const directives: Record<string, Record<string, string>>;
461
+
462
+ /**
463
+ * Dispatch — schema-driven argument mapping.
464
+ *
465
+ * Replaces the hand-written toArgs switch in rolex.ts with a single
466
+ * lookup against the instruction registry.
467
+ */
468
+ /**
469
+ * Map named arguments to positional arguments for a given operation.
470
+ *
471
+ * @param op - Operation key in "namespace.method" format (e.g. "individual.born")
472
+ * @param args - Named arguments from the caller
473
+ * @returns Positional argument array matching the method signature
474
+ */
475
+ declare function toArgs(op: string, args: Record<string, unknown>): unknown[];
476
+
477
+ /**
478
+ * Schema types for RoleX instruction definitions.
479
+ *
480
+ * These types define the structure of every RoleX operation:
481
+ * parameter types, descriptions, and positional arg ordering.
482
+ */
483
+ /** Supported parameter types for instruction definitions. */
484
+ type ParamType = "string" | "number" | "gherkin" | "string[]" | "record";
485
+ /** Definition of a single parameter in an instruction. */
486
+ interface ParamDef {
487
+ type: ParamType;
488
+ required: boolean;
489
+ description: string;
490
+ }
491
+ /**
492
+ * A single positional argument entry.
493
+ *
494
+ * - `string` — simple lookup: `args[name]`
495
+ * - `{ pack: [...] }` — collect named args into an options object;
496
+ * returns `undefined` if all values are absent.
497
+ */
498
+ type ArgEntry = string | {
499
+ pack: readonly string[];
500
+ };
501
+ /** Full definition of a RoleX instruction (one namespace.method). */
502
+ interface InstructionDef {
503
+ namespace: string;
504
+ method: string;
505
+ /** Parameter definitions — keyed by param name, used for MCP/CLI schema generation. */
506
+ params: Record<string, ParamDef>;
507
+ /** Positional argument order — maps named args to method call positions. */
508
+ args: readonly ArgEntry[];
509
+ }
510
+ /** RoleX tool definition — schema for a top-level tool (activate, want, use, etc.). */
511
+ interface ToolDef {
512
+ /** Tool name (e.g. "activate", "use"). */
513
+ name: string;
514
+ /** Parameter definitions — keyed by param name. */
515
+ params: Record<string, ParamDef>;
516
+ }
517
+
518
+ /**
519
+ * Instruction set — schema definitions for all RoleX operations.
520
+ *
521
+ * Covers every namespace.method that can be dispatched through `use()`.
522
+ */
523
+
524
+ declare const instructions: Record<string, InstructionDef>;
525
+
526
+ /**
527
+ * RoleX tool definitions — the single source of truth for all tool schemas.
528
+ *
529
+ * Channel-agnostic: MCP, CLI, REST, A2A each convert to their own format.
530
+ * Description for each tool comes from descriptions/processes via detail().
531
+ * This file only defines the parameter schema.
532
+ */
533
+
534
+ /**
535
+ * Protocol — the complete interface contract for channel adapters.
536
+ *
537
+ * Any adapter (MCP, CLI, REST, A2A) only needs this object
538
+ * to know what tools exist and what instructions to present.
539
+ */
540
+ interface Protocol {
541
+ /** All tool definitions with parameter schemas. */
542
+ tools: ToolDef[];
543
+ /** World-level instructions — the cognitive framework for AI roles. */
544
+ instructions: string;
545
+ }
546
+ /** The protocol instance — single source of truth for all channel adapters. */
547
+ declare const protocol: Protocol;
154
548
 
155
- export { type ContextData, type Migration, type MigrationRecord, type Platform, type PrototypeData, type PrototypeRepository, 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 };
549
+ export { type ApplyResult, type ArgEntry, type CommandContext, type CommandResult, type CommandResultMap, type Commands, type ContextData, type InstructionDef, type Migration, type MigrationRecord, type ParamDef, type ParamType, type Platform, type Protocol, type PrototypeData, type PrototypeRepository, type Renderer, RendererRouter, Role, type RoleDeps, type RoleSnapshot, type RoleX, type RoleXRepository, RoleXService, type ToolDef, abandon, abolish, activate, applyPrototype, appoint, archive, background, born, charge, charter, charterOrg, complete, createCommands, deliverProject, deliverable, die, directives, dismiss, dissolve, duty, encounter, enroll, establish, experience, findInState, finish, fire, found, goal, hire, identity, individual, instructions, launch, master, milestone, milestoneProject, mindset, organization, past, plan, planGoal, position, principle, procedure, processes, project, protocol, realize, reflect, rehire, removeParticipant, requirement, retire, scope, scopeProject, society, task, toArgs, todo, tone, want, wiki, wikiProject, world };