rolexjs 1.5.0 → 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 CHANGED
@@ -1,22 +1,118 @@
1
- import { Platform, Renderer, RoleXBuilder } from '@rolexjs/core';
1
+ import { Platform } from '@rolexjs/core';
2
2
  export * from '@rolexjs/core';
3
- import { State } from '@rolexjs/system';
3
+ import { State, Structure } from '@rolexjs/system';
4
+ import { Comment, Issue } from 'issuexjs';
5
+ import { Ops } from '@rolexjs/prototype';
6
+ export { world } from '@rolexjs/prototype';
4
7
 
5
8
  /**
6
- * Product Render format product state as readable text.
9
+ * RoleContextstateful session context for role operations.
7
10
  *
8
- * Renders product operations into human-readable summaries.
9
- * Ownership links show owner names only (not full individual trees).
10
- * Specs show behavior contract titles for quick overview.
11
+ * Tracks execution state from the individual's perspective:
12
+ * - roleId (who I am)
13
+ * - focusedGoalId / focusedPlanId (what I'm working on)
14
+ * - encounter / experience id sets (what I have for cognition)
15
+ *
16
+ * Created by activate, updated by subsequent role operations.
17
+ * Consumers (MCP, CLI) hold a reference and pass it through.
11
18
  */
12
19
 
13
- type ProductAction = "produce" | "strategy" | "spec" | "release" | "channel" | "own" | "disown" | "deprecate";
14
- declare function renderProduct(state: State): string;
20
+ declare class RoleContext {
21
+ roleId: string;
22
+ focusedGoalId: string | null;
23
+ focusedPlanId: string | null;
24
+ readonly encounterIds: Set<string>;
25
+ readonly experienceIds: Set<string>;
26
+ constructor(roleId: string);
27
+ requireGoalId(): string;
28
+ requirePlanId(): string;
29
+ addEncounter(id: string): void;
30
+ requireEncounterIds(ids: string[]): void;
31
+ consumeEncounters(ids: string[]): void;
32
+ addExperience(id: string): void;
33
+ requireExperienceIds(ids: string[]): void;
34
+ consumeExperiences(ids: string[]): void;
35
+ /** Walk the state tree and populate registries. */
36
+ rehydrate(state: State): void;
37
+ private walk;
38
+ /** First-person, state-aware hint for the AI after an operation. */
39
+ cognitiveHint(process: string): string | null;
40
+ }
41
+
15
42
  /**
16
- * Render a product operation result as readable text.
17
- * Returns status + hint + product overview.
43
+ * Feature the information format for the RoleX concept world.
44
+ *
45
+ * Every node's information is a Gherkin Feature.
46
+ * This is our own type — decoupled from @cucumber/messages.
47
+ */
48
+ interface Feature {
49
+ readonly name: string;
50
+ readonly description?: string;
51
+ readonly tags?: readonly string[];
52
+ readonly scenarios: readonly Scenario[];
53
+ }
54
+ interface Scenario {
55
+ readonly name: string;
56
+ readonly description?: string;
57
+ readonly tags?: readonly string[];
58
+ readonly steps: readonly Step[];
59
+ }
60
+ interface Step {
61
+ readonly keyword: string;
62
+ readonly text: string;
63
+ readonly dataTable?: readonly DataTableRow[];
64
+ }
65
+ interface DataTableRow {
66
+ readonly cells: readonly string[];
67
+ }
68
+ /** Parse a Gherkin source string into a Feature. */
69
+ declare function parse(source: string): Feature;
70
+ /** Serialize a Feature back to Gherkin source string. */
71
+ declare function serialize(feature: Feature): string;
72
+
73
+ /**
74
+ * Find — unified node lookup with priority-based disambiguation.
75
+ *
76
+ * When multiple nodes share the same id (allowed after relaxing
77
+ * global uniqueness), prefer "addressable" nodes over internal metadata.
78
+ *
79
+ * Priority (lower = preferred):
80
+ * 0: individual, organization, position — top-level entities
81
+ * 1: goal — execution roots
82
+ * 2: plan, task — execution nodes
83
+ * 3: procedure, principle — individual knowledge
84
+ * 4: encounter, experience — cognition artifacts
85
+ * 5: identity, charter — structural definitions
86
+ * 6: duty, requirement, background, etc. — internal metadata
18
87
  */
19
- declare function renderProductResult(action: ProductAction, state: State): string;
88
+
89
+ /**
90
+ * Find a node by id or alias in a state tree.
91
+ *
92
+ * When multiple nodes match, returns the one with the highest priority
93
+ * (top-level entities > execution nodes > knowledge > metadata).
94
+ */
95
+ declare function findInState(state: State, target: string): Structure | null;
96
+
97
+ /**
98
+ * Issue Render — format IssueX data as readable text.
99
+ *
100
+ * Lightweight rendering for issue operations.
101
+ * Unlike the core render layer (which projects State trees),
102
+ * this module formats flat IssueX objects into human-readable strings.
103
+ */
104
+
105
+ type IssueAction = "publish" | "get" | "list" | "close" | "reopen" | "update" | "assign" | "comment" | "comments" | "label" | "unlabel";
106
+ type LabelResolver = (ids: string[]) => Promise<string[]>;
107
+ declare function renderIssue(issue: Issue, labelNames?: string[]): string;
108
+ declare function renderIssueList(issues: Issue[]): string;
109
+ declare function renderComment(comment: Comment): string;
110
+ declare function renderCommentList(comments: Comment[]): string;
111
+ /**
112
+ * Render an issue operation result as readable text.
113
+ * Dispatches to the right renderer based on action.
114
+ */
115
+ declare function renderIssueResult(action: IssueAction, result: unknown, resolveLabels?: LabelResolver): Promise<string>;
20
116
 
21
117
  /**
22
118
  * Project Render — format project state as readable text.
@@ -26,7 +122,8 @@ declare function renderProductResult(action: ProductAction, state: State): strin
26
122
  * Milestones show progress status (#done or pending).
27
123
  */
28
124
 
29
- type ProjectAction = "launch" | "scope" | "milestone" | "achieve" | "enroll" | "remove" | "deliver" | "wiki" | "archive" | "produce";
125
+ type ProjectAction = "launch" | "scope" | "milestone" | "achieve" | "enroll" | "remove" | "deliver" | "wiki" | "archive";
126
+ declare function renderProject(state: State): string;
30
127
  /**
31
128
  * Render a project operation result as readable text.
32
129
  * Returns status + hint + project overview.
@@ -34,21 +131,170 @@ type ProjectAction = "launch" | "scope" | "milestone" | "achieve" | "enroll" | "
34
131
  declare function renderProjectResult(action: ProjectAction, state: State): string;
35
132
 
36
133
  /**
37
- * RoleXbuilder entry point.
134
+ * Render3-layer output for all Rolex operations.
135
+ *
136
+ * Layer 1: Status — what just happened (describe)
137
+ * Layer 2: Hint — what to do next (hint + cognitive hint)
138
+ * Layer 3: Projection — full state tree as markdown (renderState)
139
+ *
140
+ * render() composes the 3 layers. MCP and CLI are pure pass-through.
141
+ */
142
+
143
+ declare function describe(process: string, name: string, state: State): string;
144
+ declare function hint(process: string): string;
145
+
146
+ /** Full Gherkin feature content for a process — sourced from .feature files. */
147
+ declare function detail(process: string): string;
148
+
149
+ /** Get a directive by topic and scenario. Returns empty string if not found. */
150
+ declare function directive(topic: string, scenario: string): string;
151
+ /**
152
+ * renderState — markdown renderer for State trees.
153
+ *
154
+ * Rules:
155
+ * - Heading: "#" repeated to depth + " [name]"
156
+ * - Body: raw information field as-is (full Gherkin preserved)
157
+ * - Links: "> → relation [target.name]" with target feature name
158
+ * - Children: sorted by concept hierarchy, then rendered at depth+1
159
+ * - Fold: when fold(node) returns true, render heading only (no body/links/children)
160
+ *
161
+ * Markdown heading depth caps at 6 (######).
162
+ */
163
+ interface RenderStateOptions {
164
+ /** When returns true, render only the heading — skip body, links, and children. */
165
+ fold?: (node: State) => boolean;
166
+ }
167
+ declare function renderState(state: State, depth?: number, options?: RenderStateOptions): string;
168
+ interface RenderOptions {
169
+ /** The process that was executed. */
170
+ process: string;
171
+ /** Display name for the primary node. */
172
+ name: string;
173
+ /** State projection of the affected node. */
174
+ state: State;
175
+ /** AI cognitive hint — first-person, state-aware self-direction cue. */
176
+ cognitiveHint?: string | null;
177
+ /** Fold predicate — folded nodes render heading only. */
178
+ fold?: RenderStateOptions["fold"];
179
+ }
180
+ /** Render a full 3-layer output string. */
181
+ declare function render(opts: RenderOptions): string;
182
+
183
+ /**
184
+ * Role — stateful handle returned by Rolex.activate().
185
+ *
186
+ * Holds roleId + RoleContext internally.
187
+ * All operations return rendered 3-layer text (status + hint + projection).
188
+ * MCP and CLI are pure pass-through — no render logic needed.
38
189
  *
39
190
  * Usage:
40
- * import { createRoleX } from "rolexjs";
191
+ * const role = await rolex.activate("sean");
192
+ * await role.want("Feature: Ship v1", "ship-v1"); // → rendered string
193
+ * await role.plan("Feature: Phase 1", "phase-1"); // → rendered string
194
+ * await role.finish("write-tests", "Feature: Tests written");
195
+ */
196
+
197
+ /**
198
+ * Internal API surface that Role delegates to.
199
+ * Constructed by Rolex.activate() — not part of public API.
200
+ */
201
+ interface RolexInternal {
202
+ ops: Ops;
203
+ saveCtx(ctx: RoleContext): void | Promise<void>;
204
+ direct<T>(locator: string, args?: Record<string, unknown>): Promise<T>;
205
+ resolveLabels?: LabelResolver;
206
+ }
207
+ declare class Role {
208
+ readonly roleId: string;
209
+ readonly ctx: RoleContext;
210
+ private api;
211
+ constructor(roleId: string, ctx: RoleContext, api: RolexInternal);
212
+ /** Project the individual's full state tree (used after activate). */
213
+ project(): Promise<string>;
214
+ /** Render an OpResult into a 3-layer output string. */
215
+ private fmt;
216
+ private save;
217
+ /** Focus: view or switch focused goal. Only accepts goal ids. */
218
+ focus(goal?: string): Promise<string>;
219
+ /** Want: declare a goal. */
220
+ want(goal?: string, id?: string, alias?: readonly string[]): Promise<string>;
221
+ /** Plan: create a plan for the focused goal. */
222
+ plan(plan?: string, id?: string, after?: string, fallback?: string): Promise<string>;
223
+ /** Todo: add a task to the focused plan. */
224
+ todo(task?: string, id?: string, alias?: readonly string[]): Promise<string>;
225
+ /** Finish: complete a task, optionally record an encounter. */
226
+ finish(task: string, encounter?: string): Promise<string>;
227
+ /** Complete: close a plan as done, record encounter. */
228
+ complete(plan?: string, encounter?: string): Promise<string>;
229
+ /** Abandon: drop a plan, record encounter. */
230
+ abandon(plan?: string, encounter?: string): Promise<string>;
231
+ /** Reflect: consume encounters → experience. Empty encounters = direct creation. */
232
+ reflect(encounters: string[], experience?: string, id?: string): Promise<string>;
233
+ /** Realize: consume experiences → principle. Empty experiences = direct creation. */
234
+ realize(experiences: string[], principle?: string, id?: string): Promise<string>;
235
+ /** Master: create procedure, optionally consuming experiences. */
236
+ master(procedure: string, id?: string, experiences?: string[]): Promise<string>;
237
+ /** Forget: remove any node under the individual by id. */
238
+ forget(nodeId: string): Promise<string>;
239
+ /** Skill: load full skill content by locator. */
240
+ skill(locator: string): Promise<string>;
241
+ /** Use: subjective execution — `!ns.method` or ResourceX locator. */
242
+ use<T = unknown>(locator: string, args?: Record<string, unknown>): Promise<T>;
243
+ }
244
+
245
+ /**
246
+ * Rolex — thin API shell.
247
+ *
248
+ * Public API:
249
+ * genesis() — create the world on first run
250
+ * activate(id) — returns a stateful Role handle
251
+ * direct(loc, args) — direct the world to execute an instruction
41
252
  *
42
- * const rx = createRoleX({ platform });
43
- * const role = await rx.individual.activate({ individual: "sean" });
44
- * await rx.society.born({ id: "alice", content: "Feature: Alice" });
253
+ * All operation implementations live in @rolexjs/prototype (createOps).
254
+ * Rolex just wires Platform ops and manages Role lifecycle.
45
255
  */
46
256
 
47
- interface RoleXConfig {
48
- platform: Platform;
49
- renderer?: Renderer;
257
+ /** Summary entry returned by census.list. */
258
+ interface CensusEntry {
259
+ id?: string;
260
+ name: string;
261
+ tag?: string;
262
+ }
263
+ declare class Rolex {
264
+ private rt;
265
+ private ops;
266
+ private resourcex?;
267
+ private issuex?;
268
+ private repo;
269
+ private readonly initializer?;
270
+ private readonly bootstrap;
271
+ private society;
272
+ private past;
273
+ private constructor();
274
+ /** Create a Rolex instance from a Platform (async due to Runtime initialization). */
275
+ static create(platform: Platform): Promise<Rolex>;
276
+ /** Async initialization — called by Rolex.create(). */
277
+ private init;
278
+ /** Genesis — create the world on first run. Settles built-in prototypes. */
279
+ genesis(): Promise<void>;
280
+ /**
281
+ * Activate a role — returns a stateful Role handle.
282
+ *
283
+ * If the individual does not exist in runtime but a prototype is registered,
284
+ * auto-born the individual first.
285
+ */
286
+ activate(individual: string): Promise<Role>;
287
+ /** Find a node by id or alias across the entire society tree. Internal use only. */
288
+ private find;
289
+ /**
290
+ * Direct the world to execute an instruction.
291
+ *
292
+ * - `!namespace.method` — dispatch to ops
293
+ * - anything else — delegate to ResourceX `ingest`
294
+ */
295
+ direct<T = unknown>(locator: string, args?: Record<string, unknown>): Promise<T>;
50
296
  }
51
- /** Create a RoleX builder. Synchronous initialization is lazy. Genesis is built-in. */
52
- declare function createRoleX(config: RoleXConfig): RoleXBuilder;
297
+ /** Create a Rolex instance from a Platform. */
298
+ declare function createRoleX(platform: Platform): Promise<Rolex>;
53
299
 
54
- export { type ProductAction, type ProjectAction, type RoleXConfig, createRoleX, renderProduct, renderProductResult, renderProjectResult };
300
+ export { type CensusEntry, type DataTableRow, type Feature, type IssueAction, type LabelResolver, type ProjectAction, type RenderOptions, type RenderStateOptions, Role, RoleContext, Rolex, type Scenario, type Step, createRoleX, describe, detail, directive, findInState, hint, parse, render, renderComment, renderCommentList, renderIssue, renderIssueList, renderIssueResult, renderProject, renderProjectResult, renderState, serialize };