@shardworks/nexus-core 0.1.100 → 0.1.102

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.
Files changed (166) hide show
  1. package/README.md +95 -166
  2. package/dist/guild-config.d.ts +14 -52
  3. package/dist/guild-config.d.ts.map +1 -1
  4. package/dist/guild-config.js +7 -10
  5. package/dist/guild-config.js.map +1 -1
  6. package/dist/guild.d.ts +83 -0
  7. package/dist/guild.d.ts.map +1 -0
  8. package/dist/guild.js +45 -0
  9. package/dist/guild.js.map +1 -0
  10. package/dist/id.d.ts +14 -0
  11. package/dist/id.d.ts.map +1 -0
  12. package/dist/id.js +19 -0
  13. package/dist/id.js.map +1 -0
  14. package/dist/index.d.ts +6 -30
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +7 -32
  17. package/dist/index.js.map +1 -1
  18. package/dist/nexus-home.d.ts +0 -4
  19. package/dist/nexus-home.d.ts.map +1 -1
  20. package/dist/nexus-home.js +1 -9
  21. package/dist/nexus-home.js.map +1 -1
  22. package/dist/plugin.d.ts +115 -0
  23. package/dist/plugin.d.ts.map +1 -0
  24. package/dist/plugin.js +39 -0
  25. package/dist/plugin.js.map +1 -0
  26. package/dist/resolve-package.d.ts +58 -0
  27. package/dist/resolve-package.d.ts.map +1 -0
  28. package/dist/resolve-package.js +123 -0
  29. package/dist/resolve-package.js.map +1 -0
  30. package/package.json +5 -14
  31. package/dist/book.d.ts +0 -110
  32. package/dist/book.d.ts.map +0 -1
  33. package/dist/book.js +0 -16
  34. package/dist/book.js.map +0 -1
  35. package/dist/legacy/1/anima.d.ts +0 -79
  36. package/dist/legacy/1/anima.d.ts.map +0 -1
  37. package/dist/legacy/1/anima.js +0 -285
  38. package/dist/legacy/1/anima.js.map +0 -1
  39. package/dist/legacy/1/audit.d.ts +0 -23
  40. package/dist/legacy/1/audit.d.ts.map +0 -1
  41. package/dist/legacy/1/audit.js +0 -61
  42. package/dist/legacy/1/audit.js.map +0 -1
  43. package/dist/legacy/1/bundle.d.ts +0 -111
  44. package/dist/legacy/1/bundle.d.ts.map +0 -1
  45. package/dist/legacy/1/bundle.js +0 -452
  46. package/dist/legacy/1/bundle.js.map +0 -1
  47. package/dist/legacy/1/clock-daemon.d.ts +0 -2
  48. package/dist/legacy/1/clock-daemon.d.ts.map +0 -1
  49. package/dist/legacy/1/clock-daemon.js +0 -72
  50. package/dist/legacy/1/clock-daemon.js.map +0 -1
  51. package/dist/legacy/1/clockworks.d.ts +0 -98
  52. package/dist/legacy/1/clockworks.d.ts.map +0 -1
  53. package/dist/legacy/1/clockworks.js +0 -359
  54. package/dist/legacy/1/clockworks.js.map +0 -1
  55. package/dist/legacy/1/conversation.d.ts +0 -165
  56. package/dist/legacy/1/conversation.d.ts.map +0 -1
  57. package/dist/legacy/1/conversation.js +0 -457
  58. package/dist/legacy/1/conversation.js.map +0 -1
  59. package/dist/legacy/1/engine.d.ts +0 -90
  60. package/dist/legacy/1/engine.d.ts.map +0 -1
  61. package/dist/legacy/1/engine.js +0 -89
  62. package/dist/legacy/1/engine.js.map +0 -1
  63. package/dist/legacy/1/events.d.ts +0 -88
  64. package/dist/legacy/1/events.d.ts.map +0 -1
  65. package/dist/legacy/1/events.js +0 -239
  66. package/dist/legacy/1/events.js.map +0 -1
  67. package/dist/legacy/1/guild-config.d.ts +0 -74
  68. package/dist/legacy/1/guild-config.d.ts.map +0 -1
  69. package/dist/legacy/1/guild-config.js +0 -51
  70. package/dist/legacy/1/guild-config.js.map +0 -1
  71. package/dist/legacy/1/id.d.ts +0 -8
  72. package/dist/legacy/1/id.d.ts.map +0 -1
  73. package/dist/legacy/1/id.js +0 -27
  74. package/dist/legacy/1/id.js.map +0 -1
  75. package/dist/legacy/1/index.d.ts +0 -28
  76. package/dist/legacy/1/index.d.ts.map +0 -1
  77. package/dist/legacy/1/index.js +0 -32
  78. package/dist/legacy/1/index.js.map +0 -1
  79. package/dist/legacy/1/init-guild.d.ts +0 -24
  80. package/dist/legacy/1/init-guild.d.ts.map +0 -1
  81. package/dist/legacy/1/init-guild.js +0 -230
  82. package/dist/legacy/1/init-guild.js.map +0 -1
  83. package/dist/legacy/1/install-tool.d.ts +0 -73
  84. package/dist/legacy/1/install-tool.d.ts.map +0 -1
  85. package/dist/legacy/1/install-tool.js +0 -436
  86. package/dist/legacy/1/install-tool.js.map +0 -1
  87. package/dist/legacy/1/instantiate.d.ts +0 -33
  88. package/dist/legacy/1/instantiate.d.ts.map +0 -1
  89. package/dist/legacy/1/instantiate.js +0 -137
  90. package/dist/legacy/1/instantiate.js.map +0 -1
  91. package/dist/legacy/1/manifest.d.ts +0 -132
  92. package/dist/legacy/1/manifest.d.ts.map +0 -1
  93. package/dist/legacy/1/manifest.js +0 -321
  94. package/dist/legacy/1/manifest.js.map +0 -1
  95. package/dist/legacy/1/migrate.d.ts +0 -84
  96. package/dist/legacy/1/migrate.d.ts.map +0 -1
  97. package/dist/legacy/1/migrate.js +0 -228
  98. package/dist/legacy/1/migrate.js.map +0 -1
  99. package/dist/legacy/1/nexus-home.d.ts +0 -11
  100. package/dist/legacy/1/nexus-home.d.ts.map +0 -1
  101. package/dist/legacy/1/nexus-home.js +0 -16
  102. package/dist/legacy/1/nexus-home.js.map +0 -1
  103. package/dist/legacy/1/plugin-descriptor.d.ts +0 -3
  104. package/dist/legacy/1/plugin-descriptor.d.ts.map +0 -1
  105. package/dist/legacy/1/plugin-descriptor.js +0 -2
  106. package/dist/legacy/1/plugin-descriptor.js.map +0 -1
  107. package/dist/legacy/1/preconditions.d.ts +0 -100
  108. package/dist/legacy/1/preconditions.d.ts.map +0 -1
  109. package/dist/legacy/1/preconditions.js +0 -189
  110. package/dist/legacy/1/preconditions.js.map +0 -1
  111. package/dist/legacy/1/rehydrate.d.ts +0 -22
  112. package/dist/legacy/1/rehydrate.d.ts.map +0 -1
  113. package/dist/legacy/1/rehydrate.js +0 -109
  114. package/dist/legacy/1/rehydrate.js.map +0 -1
  115. package/dist/legacy/1/remove-tool.d.ts +0 -19
  116. package/dist/legacy/1/remove-tool.d.ts.map +0 -1
  117. package/dist/legacy/1/remove-tool.js +0 -105
  118. package/dist/legacy/1/remove-tool.js.map +0 -1
  119. package/dist/legacy/1/session.d.ts +0 -343
  120. package/dist/legacy/1/session.d.ts.map +0 -1
  121. package/dist/legacy/1/session.js +0 -499
  122. package/dist/legacy/1/session.js.map +0 -1
  123. package/dist/legacy/1/tool-registry.d.ts +0 -12
  124. package/dist/legacy/1/tool-registry.d.ts.map +0 -1
  125. package/dist/legacy/1/tool-registry.js +0 -28
  126. package/dist/legacy/1/tool-registry.js.map +0 -1
  127. package/dist/legacy/1/tool.d.ts +0 -10
  128. package/dist/legacy/1/tool.d.ts.map +0 -1
  129. package/dist/legacy/1/tool.js +0 -2
  130. package/dist/legacy/1/tool.js.map +0 -1
  131. package/dist/legacy/1/upgrade.d.ts +0 -129
  132. package/dist/legacy/1/upgrade.d.ts.map +0 -1
  133. package/dist/legacy/1/upgrade.js +0 -355
  134. package/dist/legacy/1/upgrade.js.map +0 -1
  135. package/dist/legacy/1/workshop.d.ts +0 -95
  136. package/dist/legacy/1/workshop.d.ts.map +0 -1
  137. package/dist/legacy/1/workshop.js +0 -229
  138. package/dist/legacy/1/workshop.js.map +0 -1
  139. package/dist/legacy/1/worktree.d.ts +0 -67
  140. package/dist/legacy/1/worktree.d.ts.map +0 -1
  141. package/dist/legacy/1/worktree.js +0 -117
  142. package/dist/legacy/1/worktree.js.map +0 -1
  143. package/dist/legacy/1/writ.d.ts +0 -130
  144. package/dist/legacy/1/writ.d.ts.map +0 -1
  145. package/dist/legacy/1/writ.js +0 -599
  146. package/dist/legacy/1/writ.js.map +0 -1
  147. package/dist/rig-context.d.ts +0 -47
  148. package/dist/rig-context.d.ts.map +0 -1
  149. package/dist/rig-context.js +0 -11
  150. package/dist/rig-context.js.map +0 -1
  151. package/dist/rig-descriptor.d.ts +0 -39
  152. package/dist/rig-descriptor.d.ts.map +0 -1
  153. package/dist/rig-descriptor.js +0 -12
  154. package/dist/rig-descriptor.js.map +0 -1
  155. package/dist/rig.d.ts +0 -70
  156. package/dist/rig.d.ts.map +0 -1
  157. package/dist/rig.js +0 -14
  158. package/dist/rig.js.map +0 -1
  159. package/dist/tool.d.ts +0 -136
  160. package/dist/tool.d.ts.map +0 -1
  161. package/dist/tool.js +0 -135
  162. package/dist/tool.js.map +0 -1
  163. package/migrations/001-schema.sql +0 -177
  164. package/migrations/002-writs.sql +0 -44
  165. package/migrations/003-conversations.sql +0 -43
  166. package/migrations/004-remove-commissions.sql +0 -24
package/README.md CHANGED
@@ -1,243 +1,172 @@
1
1
  # `@shardworks/nexus-core`
2
2
 
3
- The public SDK for Nexus Mk 2.1. Rig authors import from this package to define tools, declare books, and read guild configuration.
3
+ The public SDK surface for Nexus Mk 2.1. Every plugin kit or apparatus — depends on this package for the guild singleton, plugin lifecycle types, guild configuration, and package resolution utilities.
4
4
 
5
- This package is a dependency of every rig. It does not depend on mainspring or the CLI — the dependency graph runs one way: rigs → core.
5
+ This package has zero runtime dependencies. The dependency graph runs one way: plugins → core.
6
6
 
7
7
  ---
8
8
 
9
- ## `tool()` — Tool SDK
9
+ ## `Guild` — Process-Level Singleton
10
10
 
11
- Define a Nexus tool. This is the primary authoring entry point for rig packages.
11
+ The central access point for guild infrastructure at runtime. All plugin code (apparatus `start()`, tool handlers, engine handlers) imports `guild()` to access apparatus APIs, plugin config, and the guild root path.
12
12
 
13
13
  ```typescript
14
- import { tool } from '@shardworks/nexus-core';
15
- import { z } from 'zod';
16
-
17
- export default tool({
18
- name: 'greet',
19
- description: 'Greet an anima by name',
20
- params: {
21
- name: z.string().describe('Anima name'),
22
- },
23
- handler: async ({ name }, ctx) => {
24
- return `Hello, ${name}! Guild root: ${ctx.home}`;
25
- },
26
- });
27
- ```
28
-
29
- A rig package exports a `Rig` object, a single tool, or an array of tools as its default export. Mainspring discovers them automatically at install time.
30
-
31
- ### `ToolDefinition`
32
-
33
- The return type of `tool()`. MCP, CLI, and engines all consume this shape.
34
-
35
- ### `ToolCaller`
36
-
37
- `'cli' | 'mcp'` — controls which surfaces a tool appears on. Set via `callableFrom`:
14
+ import { guild } from '@shardworks/nexus-core';
38
15
 
39
- ```typescript
40
- tool({
41
- name: 'rig-install',
42
- callableFrom: ['cli'], // CLI only — not exposed to animas via MCP
43
- ...
44
- });
16
+ const home = guild().home;
17
+ const stacks = guild().apparatus<StacksApi>('stacks');
18
+ const config = guild().config<MyConfig>('my-plugin');
45
19
  ```
46
20
 
47
- Defaults to all callers if omitted.
48
-
49
- ### Resolution helpers
50
-
51
- ```typescript
52
- // Find one tool from a module's default export
53
- resolveToolFromExport(moduleDefault, toolName?)
21
+ | Member | Returns | Description |
22
+ |---|---|---|
23
+ | `home` | `string` | Absolute path to the guild root |
24
+ | `apparatus<T>(name)` | `T` | Retrieve a started apparatus's `provides` object by plugin id |
25
+ | `config<T>(pluginId)` | `T` | Read a plugin's configuration section from guild.json |
26
+ | `writeConfig<T>(pluginId, value)` | `void` | Write a plugin's configuration section to guild.json (updates in-memory + disk) |
27
+ | `guildConfig()` | `GuildConfig` | Read the full parsed guild.json |
28
+ | `kits()` | `LoadedKit[]` | Snapshot of all loaded kits (including apparatus supportKits) |
29
+ | `apparatuses()` | `LoadedApparatus[]` | Snapshot of all started apparatuses |
54
30
 
55
- // Find all tools from a module's default export
56
- resolveAllToolsFromExport(moduleDefault)
31
+ Framework functions (not for plugin use):
57
32
 
58
- // Type guard
59
- isToolDefinition(obj)
60
- ```
33
+ | Function | Description |
34
+ |---|---|
35
+ | `setGuild(g)` | Register the guild instance — called by Arbor at startup |
36
+ | `clearGuild()` | Clear the guild instance — called by Arbor at shutdown or in tests |
61
37
 
62
38
  ---
63
39
 
64
- ## `Rig`Rig Export Type
40
+ ## Plugin System `Kit`, `Apparatus`, `Plugin`
41
+
42
+ Core types for the Kit/Apparatus model. Plugins come in two kinds:
65
43
 
66
- The author-facing export type for a rig package. Rig packages export this as their default export. Mainspring reads it at load time to discover the rig's contributions.
44
+ - **Kit** passive package contributing capabilities. No lifecycle, no running state. Read at load time.
45
+ - **Apparatus** — package contributing persistent infrastructure. Has a `start`/`stop` lifecycle.
67
46
 
68
47
  ```typescript
69
- import { type Rig, tool } from '@shardworks/nexus-core';
48
+ import type { Kit, Apparatus, Plugin } from '@shardworks/nexus-core';
70
49
 
71
- const myTool = tool({ ... });
50
+ // Kit example
51
+ export default { kit: { tools: [myTool] } } satisfies Plugin;
72
52
 
53
+ // Apparatus example
73
54
  export default {
74
- tools: [myTool],
75
- books: {
76
- writs: { indexes: ['status', 'createdAt', 'parent.id'] },
55
+ apparatus: {
56
+ requires: ['stacks'],
57
+ provides: myApi,
58
+ start: async (ctx) => { /* ... */ },
77
59
  },
78
- } satisfies Rig;
79
- ```
80
-
81
- | Field | Type | Description |
82
- |---|---|---|
83
- | `tools?` | `ToolDefinition[]` | Tools this rig contributes to the guild |
84
- | `books?` | `Record<string, BookOptions>` | Named document collections — mainspring creates SQLite tables and indexes at startup |
85
-
86
- Backward-compatible: rigs may still export a bare `ToolDefinition` or `ToolDefinition[]` directly.
87
-
88
- ### `BookOptions`
89
-
90
- Schema declaration for a single book:
91
-
92
- ```typescript
93
- interface BookOptions {
94
- indexes?: string[]; // field names to index (plain or dot-notation)
95
- }
96
- ```
97
-
98
- ### `isRig(obj)`
99
-
100
- Type guard distinguishing a `Rig` export from a bare tool or array.
101
-
102
- ---
103
-
104
- ## `RigContext` — Handler Context
105
-
106
- Injected into every tool and engine handler. Scoped to the rig that owns the handler.
107
-
108
- ```typescript
109
- interface RigContext {
110
- home: string;
111
-
112
- book<T extends { id: string }>(name: string): Book<T>;
113
- rigBook<T extends { id: string }>(rigId: string, name: string): ReadOnlyBook<T>;
114
- }
60
+ } satisfies Plugin;
115
61
  ```
116
62
 
117
- | Member | Returns | Description |
118
- |---|---|---|
119
- | `home` | `string` | Absolute path to the guild root |
120
- | `book(name)` | `Book<T>` | Read-write handle to one of this rig's declared books |
121
- | `rigBook(rigId, name)` | `ReadOnlyBook<T>` | Read-only handle to another rig's book |
122
-
123
- `ToolContext` is a deprecated alias for `RigContext`, re-exported from legacy for backward compatibility.
124
-
125
- ---
126
-
127
- ## `Book<T>` — Document Store
63
+ ### Types
128
64
 
129
- The NoSQL document store primitive for rig authors. `T` must extend `{ id: string }` — rig authors own ID generation.
130
-
131
- | Method | Description |
65
+ | Type | Description |
132
66
  |---|---|
133
- | `put(content)` | Upsert a document (creates or replaces entirely by `content.id`) |
134
- | `get(id)` | Retrieve by id, or `null` |
135
- | `delete(id)` | Remove by id (silent no-op if absent) |
136
- | `find(query)` | Query with `where`, `orderBy`, `order`, `limit`, `offset` |
137
- | `list(options?)` | List all documents, optionally paginated and sorted |
138
- | `count(where?)` | Count documents matching an optional filter |
139
-
140
- ### `BookQuery`
141
-
142
- ```typescript
143
- type BookQuery = {
144
- where?: Record<string, unknown>; // field equality filters, ANDed
145
- orderBy?: string; // plain name or dot-notation
146
- order?: 'asc' | 'desc';
147
- limit?: number;
148
- offset?: number; // requires limit
149
- }
150
- ```
67
+ | `Kit` | Open record with optional `requires` and `recommends` arrays. Contribution fields are defined by consuming apparatuses. |
68
+ | `Apparatus` | Record with `start(ctx)`, optional `stop()`, optional `provides`, `requires`, `supportKit`, `consumes`. |
69
+ | `Plugin` | Discriminated union: `{ kit: Kit }` or `{ apparatus: Apparatus }` |
70
+ | `LoadedKit` | A kit as tracked by Arbor: `packageName`, `id`, `version`, `kit` |
71
+ | `LoadedApparatus` | An apparatus as tracked by Arbor: `packageName`, `id`, `version`, `apparatus` |
72
+ | `LoadedPlugin` | Union of `LoadedKit` and `LoadedApparatus` |
73
+ | `StartupContext` | Passed to `apparatus.start()`. Provides `on(event, handler)` for lifecycle subscriptions. |
151
74
 
152
- ### `ReadOnlyBook<T>`
75
+ ### Type Guards
153
76
 
154
- Returned by `rigBook()` for cross-rig access. Same as `Book<T>` minus `put` and `delete`.
77
+ | Function | Description |
78
+ |---|---|
79
+ | `isKit(obj)` | Narrows to `{ kit: Kit }` |
80
+ | `isApparatus(obj)` | Narrows to `{ apparatus: Apparatus }` |
81
+ | `isLoadedKit(p)` | Narrows `LoadedPlugin` to `LoadedKit` |
82
+ | `isLoadedApparatus(p)` | Narrows `LoadedPlugin` to `LoadedApparatus` |
155
83
 
156
84
  ---
157
85
 
158
- ## `guild-config` — Guild Configuration
86
+ ## Guild Configuration
159
87
 
160
88
  Read and write `guild.json`, the guild's central configuration file.
161
89
 
162
90
  ```typescript
163
- import { readGuildConfigV2, writeGuildConfigV2 } from '@shardworks/nexus-core';
91
+ import { readGuildConfig, writeGuildConfig } from '@shardworks/nexus-core';
164
92
 
165
- const config = readGuildConfigV2(home);
166
- config.baseTools.push('my-tool');
167
- writeGuildConfigV2(home, config);
93
+ const config = readGuildConfig(home);
94
+ writeGuildConfig(home, config);
168
95
  ```
169
96
 
170
- ### `GuildConfigV2`
171
-
172
- The shape of `guild.json` for V2 guilds:
97
+ ### `GuildConfig`
173
98
 
174
99
  | Field | Type | Description |
175
100
  |---|---|---|
176
101
  | `name` | `string` | Guild name |
177
102
  | `nexus` | `string` | Framework version at last init/upgrade |
178
- | `rigs` | `string[]` | Installed rig keys (derived from npm package names) |
179
- | `baseTools` | `string[]` | Tools available to all animas |
180
- | `roles` | `Record<string, RoleDefinition>` | Guild roles with seats, tools, instructions |
181
- | `workshops` | `Record<string, WorkshopEntry>` | Registered workshops |
103
+ | `plugins` | `string[]` | Installed plugin ids |
104
+ | `clockworks?` | `ClockworksConfig` | Events and standing orders |
105
+ | `writTypes?` | `Record<string, WritTypeDeclaration>` | Guild-declared writ types |
182
106
  | `settings?` | `GuildSettings` | Operational flags including default `model` |
183
- | `clockworks?` | `ClockworksConfig` | Standing orders and custom events |
184
- | `writTypes?` | `Record<string, WritTypeDeclaration>` | Custom writ type declarations |
185
107
 
186
- ### Other exports
108
+ All other top-level keys are plugin configuration sections, keyed by derived plugin id.
187
109
 
188
- ```typescript
189
- guildConfigPath(home) // path to guild.json
190
- createInitialGuildConfigV2(...) // default config for nsg init
191
- ```
110
+ ### Other Exports
111
+
112
+ | Function / Type | Description |
113
+ |---|---|
114
+ | `createInitialGuildConfig(name, version, model)` | Default config for `nsg init` |
115
+ | `guildConfigPath(home)` | Resolve path to `guild.json` |
116
+ | `EventDeclaration` | Custom event: `description`, optional `schema` |
117
+ | `StandingOrder` | Event → action mapping (run / summon / brief) |
118
+ | `ClockworksConfig` | Container for events and standing orders |
119
+ | `WritTypeDeclaration` | Writ type: `description` |
120
+ | `GuildSettings` | Settings: `model`, `autoMigrate` |
192
121
 
193
122
  ---
194
123
 
195
- ## `nexus-home` — Path Resolution
124
+ ## Path Resolution — `nexus-home`
196
125
 
197
126
  Resolve standard paths within a guild's `.nexus/` directory.
198
127
 
199
128
  ```typescript
200
129
  import { findGuildRoot, nexusDir } from '@shardworks/nexus-core';
201
130
 
202
- const home = findGuildRoot(); // walks up from cwd to find guild.json
203
- const dir = nexusDir(home); // .nexus/
131
+ const home = findGuildRoot(); // walks up from cwd to find guild.json
132
+ const dir = nexusDir(home); // .nexus/
204
133
  ```
205
134
 
206
- ### All path helpers
207
-
208
135
  | Function | Returns |
209
136
  |---|---|
210
137
  | `findGuildRoot(startDir?)` | Guild root (walks up from cwd, throws if not found) |
211
138
  | `nexusDir(home)` | `.nexus/` |
212
139
  | `worktreesPath(home)` | `.nexus/worktrees/` |
213
- | `workshopsPath(home)` | `.nexus/workshops/` |
214
- | `workshopBarePath(home, name)` | `.nexus/workshops/<name>.git` |
215
140
  | `clockPidPath(home)` | `.nexus/clock.pid` |
216
141
  | `clockLogPath(home)` | `.nexus/clock.log` |
217
142
 
218
143
  ---
219
144
 
220
- ## `rig-descriptor` — Rig Descriptor Types
145
+ ## Package Resolution
221
146
 
222
- Types for `rig.json`, the optional descriptor a rig package can include at its root to declare dependencies on other rigs.
147
+ Utilities for resolving guild-installed npm packages and deriving plugin ids.
223
148
 
224
149
  ```typescript
225
- import type { RigDescriptor } from '@shardworks/nexus-core';
150
+ import { derivePluginId, resolveGuildPackageEntry } from '@shardworks/nexus-core';
151
+
152
+ derivePluginId('@shardworks/books-apparatus'); // → 'books'
153
+ derivePluginId('@acme/my-plugin'); // → 'acme/my-plugin'
154
+ derivePluginId('my-relay-kit'); // → 'my-relay'
226
155
  ```
227
156
 
228
- ### `RigDescriptor`
157
+ | Function | Description |
158
+ |---|---|
159
+ | `derivePluginId(packageName)` | Canonical npm package name → plugin id. Strips `@shardworks/` scope and `-plugin`/`-apparatus`/`-kit` suffixes. |
160
+ | `readGuildPackageJson(guildRoot, pkgName)` | Read a package's `package.json` from the guild's `node_modules` |
161
+ | `resolvePackageNameForPluginId(guildRoot, pluginId)` | Reverse lookup: find the npm package name for a plugin id |
162
+ | `resolveGuildPackageEntry(guildRoot, pkgName)` | Resolve the ESM entry point for a guild-installed package |
229
163
 
230
- ```typescript
231
- interface RigDescriptor {
232
- description?: string;
233
- dependencies?: RigDependency[];
234
- }
235
-
236
- interface RigDependency {
237
- rig: string; // rig key, e.g. 'nexus-stdlib'
238
- }
239
- ```
164
+ ---
165
+
166
+ ## `VERSION`
240
167
 
241
- Mainspring reads `rig.json` at install time. If declared dependencies aren't installed, `nsg rig install` fails with a clear error.
168
+ The package version, read from `package.json` at runtime.
242
169
 
243
- A rig with no dependencies needs no `rig.json` at all.
170
+ ```typescript
171
+ import { VERSION } from '@shardworks/nexus-core';
172
+ ```
@@ -1,18 +1,3 @@
1
- /** Definition of a guild role — a structural position in the guild. */
2
- export interface RoleDefinition {
3
- /**
4
- * Maximum number of animas that can hold this role simultaneously.
5
- * `null` means unbounded.
6
- */
7
- seats: number | null;
8
- /** Tools available to animas in this role (additive with baseTools). */
9
- tools: string[];
10
- /**
11
- * Path to role-specific instructions markdown, relative to guild root.
12
- * Read fresh at manifest time and delivered to animas holding this role.
13
- */
14
- instructions?: string;
15
- }
16
1
  /** A custom event declaration in guild.json clockworks.events. */
17
2
  export interface EventDeclaration {
18
3
  /** Human-readable description of what this event means. */
@@ -20,11 +5,6 @@ export interface EventDeclaration {
20
5
  /** Optional payload schema hint (not enforced in Phase 1). */
21
6
  schema?: Record<string, string>;
22
7
  }
23
- /** A writ type declaration in guild.json. */
24
- export interface WritTypeDeclaration {
25
- /** Human-readable description of this writ type. */
26
- description: string;
27
- }
28
8
  /** A standing order — a registered response to an event. */
29
9
  export type StandingOrder = {
30
10
  on: string;
@@ -44,13 +24,6 @@ export interface ClockworksConfig {
44
24
  /** Standing orders — event → action mappings. */
45
25
  standingOrders?: StandingOrder[];
46
26
  }
47
- /** A registered workshop — a repository where the guild does its work. */
48
- export interface WorkshopEntry {
49
- /** Git remote URL (the clone source). */
50
- remoteUrl: string;
51
- /** ISO-8601 timestamp of when the workshop was added. */
52
- addedAt: string;
53
- }
54
27
  /** Guild-level settings — operational flags and preferences. */
55
28
  export interface GuildSettings {
56
29
  /**
@@ -66,45 +39,34 @@ export interface GuildSettings {
66
39
  autoMigrate?: boolean;
67
40
  }
68
41
  /**
69
- * Guild configuration — V2.
70
- *
71
- * The rig-centric model: rigs are npm packages; capabilities (tools, engines,
72
- * training content) are declared by rigs and discovered dynamically at runtime.
73
- * No per-capability registries — `config.rigs` + `node_modules` is the source
74
- * of truth. The default model moves into `settings`.
42
+ * Guild configuration.
75
43
  *
76
- * Breaking change from GuildConfig (V1): drops `tools`, `engines`, `curricula`,
77
- * `temperaments`, and top-level `model`. Requires `rigs` (was optional).
44
+ * The plugin-centric model: plugins are npm packages; capabilities (tools, engines,
45
+ * training content) are declared by plugins and discovered dynamically at runtime.
46
+ * Framework-level keys (`name`, `nexus`, `plugins`, `settings`) are defined here;
47
+ * all other top-level keys are plugin configuration sections, keyed by plugin id.
78
48
  */
79
- export interface GuildConfigV2 {
49
+ export interface GuildConfig {
80
50
  /** Guild name — used as the guildhall npm package name. */
81
51
  name: string;
82
52
  /** Installed Nexus framework version. */
83
53
  nexus: string;
84
- /** Registered workshops indexed by name. */
85
- workshops: Record<string, WorkshopEntry>;
86
- /** Guild roles — structural positions that animas fill. */
87
- roles: Record<string, RoleDefinition>;
88
- /** Tool names available to all animas regardless of role. */
89
- baseTools: string[];
90
- /** Installed rig keys (derived from npm package names). Always present; starts empty. */
91
- rigs: string[];
54
+ /** Installed plugin ids (derived from npm package names). Always present; starts empty. */
55
+ plugins: string[];
92
56
  /** Clockworks configuration — events, standing orders. */
93
57
  clockworks?: ClockworksConfig;
94
- /** Writ types declared by this guild. Built-in types (mandate, summon) are implicit. */
95
- writTypes?: Record<string, WritTypeDeclaration>;
96
58
  /** Guild-level settings — operational flags and preferences. Includes default model. */
97
59
  settings?: GuildSettings;
98
60
  }
99
61
  /**
100
- * Create the default guild.json content for a new V2 guild.
62
+ * Create the default guild.json content for a new guild.
101
63
  * All collections start empty. The default model is stored in settings.
102
64
  */
103
- export declare function createInitialGuildConfigV2(name: string, nexusVersion: string, model: string): GuildConfigV2;
104
- /** Read and parse a V2 guild.json from the guild root. */
105
- export declare function readGuildConfigV2(home: string): GuildConfigV2;
106
- /** Write a V2 guild.json to the guild root. */
107
- export declare function writeGuildConfigV2(home: string, config: GuildConfigV2): void;
65
+ export declare function createInitialGuildConfig(name: string, nexusVersion: string, model: string): GuildConfig;
66
+ /** Read and parse guild.json from the guild root. */
67
+ export declare function readGuildConfig(home: string): GuildConfig;
68
+ /** Write guild.json to the guild root. */
69
+ export declare function writeGuildConfig(home: string, config: GuildConfig): void;
108
70
  /** Resolve the path to guild.json in the guild root. */
109
71
  export declare function guildConfigPath(home: string): string;
110
72
  //# sourceMappingURL=guild-config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"guild-config.d.ts","sourceRoot":"","sources":["../src/guild-config.ts"],"names":[],"mappings":"AAGA,uEAAuE;AACvE,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,wEAAwE;IACxE,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,kEAAkE;AA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A;CAAE,GAC/C;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAElC,wDAAwD;AACxD,MAAM,WAAW,gBAAgB;IAC/B,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC1C,iDAAiD;IACjD,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;CAClC;AAED,gEAAgE;AAChE,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,2DAA2D;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,2FAA2F;IAC3F,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,0DAA0D;IAC1D,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,wFAAwF;IACxF,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,CAOvG;AAED,qDAAqD;AACrD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAGzD;AAED,0CAA0C;AAC1C,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAGxE;AAED,wDAAwD;AACxD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD"}
@@ -1,27 +1,24 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  /**
4
- * Create the default guild.json content for a new V2 guild.
4
+ * Create the default guild.json content for a new guild.
5
5
  * All collections start empty. The default model is stored in settings.
6
6
  */
7
- export function createInitialGuildConfigV2(name, nexusVersion, model) {
7
+ export function createInitialGuildConfig(name, nexusVersion, model) {
8
8
  return {
9
9
  name,
10
10
  nexus: nexusVersion,
11
- workshops: {},
12
- roles: {},
13
- baseTools: [],
14
- rigs: [],
11
+ plugins: [],
15
12
  settings: { model },
16
13
  };
17
14
  }
18
- /** Read and parse a V2 guild.json from the guild root. */
19
- export function readGuildConfigV2(home) {
15
+ /** Read and parse guild.json from the guild root. */
16
+ export function readGuildConfig(home) {
20
17
  const configFile = guildConfigPath(home);
21
18
  return JSON.parse(fs.readFileSync(configFile, 'utf-8'));
22
19
  }
23
- /** Write a V2 guild.json to the guild root. */
24
- export function writeGuildConfigV2(home, config) {
20
+ /** Write guild.json to the guild root. */
21
+ export function writeGuildConfig(home, config) {
25
22
  const configFile = guildConfigPath(home);
26
23
  fs.writeFileSync(configFile, JSON.stringify(config, null, 2) + '\n');
27
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"guild-config.js","sourceRoot":"","sources":["../src/guild-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAqG7B;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CAAC,IAAY,EAAE,YAAoB,EAAE,KAAa;IAC1F,OAAO;QACL,IAAI;QACJ,KAAK,EAAE,YAAY;QACnB,SAAS,EAAE,EAAE;QACb,KAAK,EAAE,EAAE;QACT,SAAS,EAAE,EAAE;QACb,IAAI,EAAE,EAAE;QACR,QAAQ,EAAE,EAAE,KAAK,EAAE;KACpB,CAAC;AACJ,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,MAAM,UAAU,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACzC,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAkB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C;AAED,wDAAwD;AACxD,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;AACvC,CAAC"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Guild — the process-level singleton for accessing guild infrastructure.
3
+ *
4
+ * All plugin code — apparatus start(), tool handlers, engine handlers,
5
+ * relay handlers, CDC handlers — imports `guild()` to access apparatus APIs,
6
+ * plugin config, the guild root path, and the loaded plugin graph.
7
+ *
8
+ * Arbor creates the Guild instance before starting apparatus and registers
9
+ * it via `setGuild()`. The instance is backed by live data structures
10
+ * (e.g. the provides Map) that are populated progressively as apparatus start.
11
+ *
12
+ * See: docs/architecture/plugins.md
13
+ */
14
+ import type { GuildConfig } from './guild-config.ts';
15
+ import type { LoadedKit, LoadedApparatus } from './plugin.ts';
16
+ /**
17
+ * Runtime access to guild infrastructure.
18
+ *
19
+ * Available after Arbor creates the instance (before apparatus start).
20
+ * One instance per process.
21
+ */
22
+ export interface Guild {
23
+ /** Absolute path to the guild root (contains guild.json). */
24
+ readonly home: string;
25
+ /**
26
+ * Retrieve a started apparatus's provides object by plugin id.
27
+ *
28
+ * Throws if the apparatus is not installed or has no `provides`.
29
+ * During startup, only apparatus that have already started are visible
30
+ * (dependency ordering guarantees declared deps are started first).
31
+ */
32
+ apparatus<T>(name: string): T;
33
+ /**
34
+ * Read a plugin's configuration section from guild.json.
35
+ *
36
+ * Returns `guild.json[pluginId]` cast to `T`. Returns `{}` if no
37
+ * section exists. The generic parameter is a cast — the framework
38
+ * does not validate config shape.
39
+ */
40
+ config<T = Record<string, unknown>>(pluginId: string): T;
41
+ /**
42
+ * Write a plugin's configuration section to guild.json.
43
+ *
44
+ * Updates `guild.json[pluginId]` with `value` and writes the file
45
+ * to disk. Also updates the in-memory config so subsequent reads
46
+ * reflect the change.
47
+ *
48
+ * For framework-level keys (name, nexus, plugins, settings), use
49
+ * the standalone `writeGuildConfig()` function instead.
50
+ */
51
+ writeConfig<T = Record<string, unknown>>(pluginId: string, value: T): void;
52
+ /**
53
+ * Read the full parsed guild.json.
54
+ *
55
+ * Escape hatch for framework-level fields (name, nexus, plugins,
56
+ * settings) that don't belong to any specific plugin.
57
+ */
58
+ guildConfig(): GuildConfig;
59
+ /** Snapshot of all loaded kits (including apparatus supportKits). */
60
+ kits(): LoadedKit[];
61
+ /** Snapshot of all started apparatuses. */
62
+ apparatuses(): LoadedApparatus[];
63
+ }
64
+ /**
65
+ * Get the active guild instance.
66
+ *
67
+ * Throws with a clear message if called before Arbor has initialized
68
+ * the guild (e.g. at module import time, before startup begins).
69
+ */
70
+ export declare function guild(): Guild;
71
+ /**
72
+ * Set the guild instance. Called by Arbor before starting apparatus.
73
+ *
74
+ * Not for plugin use — this is framework infrastructure.
75
+ */
76
+ export declare function setGuild(g: Guild): void;
77
+ /**
78
+ * Clear the guild instance. Called by Arbor at shutdown or in tests.
79
+ *
80
+ * Not for plugin use — this is framework infrastructure.
81
+ */
82
+ export declare function clearGuild(): void;
83
+ //# sourceMappingURL=guild.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guild.d.ts","sourceRoot":"","sources":["../src/guild.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAI9D;;;;;GAKG;AACH,MAAM,WAAW,KAAK;IACpB,6DAA6D;IAC7D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB;;;;;;OAMG;IACH,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CAAA;IAE7B;;;;;;OAMG;IACH,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,CAAA;IAExD;;;;;;;;;OASG;IACH,WAAW,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAA;IAE1E;;;;;OAKG;IACH,WAAW,IAAI,WAAW,CAAA;IAE1B,qEAAqE;IACrE,IAAI,IAAI,SAAS,EAAE,CAAA;IAEnB,2CAA2C;IAC3C,WAAW,IAAI,eAAe,EAAE,CAAA;CACjC;AAMD;;;;;GAKG;AACH,wBAAgB,KAAK,IAAI,KAAK,CAQ7B;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI,CAEvC;AAED;;;;GAIG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAEjC"}
package/dist/guild.js ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Guild — the process-level singleton for accessing guild infrastructure.
3
+ *
4
+ * All plugin code — apparatus start(), tool handlers, engine handlers,
5
+ * relay handlers, CDC handlers — imports `guild()` to access apparatus APIs,
6
+ * plugin config, the guild root path, and the loaded plugin graph.
7
+ *
8
+ * Arbor creates the Guild instance before starting apparatus and registers
9
+ * it via `setGuild()`. The instance is backed by live data structures
10
+ * (e.g. the provides Map) that are populated progressively as apparatus start.
11
+ *
12
+ * See: docs/architecture/plugins.md
13
+ */
14
+ // ── Singleton ──────────────────────────────────────────────────────────
15
+ let _guild = null;
16
+ /**
17
+ * Get the active guild instance.
18
+ *
19
+ * Throws with a clear message if called before Arbor has initialized
20
+ * the guild (e.g. at module import time, before startup begins).
21
+ */
22
+ export function guild() {
23
+ if (!_guild) {
24
+ throw new Error('Guild not initialized — guild() called before Arbor startup. ' +
25
+ 'Ensure guild() is called inside a handler or start(), not at module scope.');
26
+ }
27
+ return _guild;
28
+ }
29
+ /**
30
+ * Set the guild instance. Called by Arbor before starting apparatus.
31
+ *
32
+ * Not for plugin use — this is framework infrastructure.
33
+ */
34
+ export function setGuild(g) {
35
+ _guild = g;
36
+ }
37
+ /**
38
+ * Clear the guild instance. Called by Arbor at shutdown or in tests.
39
+ *
40
+ * Not for plugin use — this is framework infrastructure.
41
+ */
42
+ export function clearGuild() {
43
+ _guild = null;
44
+ }
45
+ //# sourceMappingURL=guild.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guild.js","sourceRoot":"","sources":["../src/guild.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA8DH,0EAA0E;AAE1E,IAAI,MAAM,GAAiB,IAAI,CAAC;AAEhC;;;;;GAKG;AACH,MAAM,UAAU,KAAK;IACnB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,+DAA+D;YAC/D,4EAA4E,CAC7E,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,CAAQ;IAC/B,MAAM,GAAG,CAAC,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU;IACxB,MAAM,GAAG,IAAI,CAAC;AAChB,CAAC"}
package/dist/id.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Generate a sortable, prefixed ID.
3
+ *
4
+ * Format: `{prefix}-{base36_timestamp}-{hex_random}`
5
+ *
6
+ * The timestamp component (Date.now() in base36) gives lexicographic sort
7
+ * order by creation time. The random suffix prevents collisions without
8
+ * coordination.
9
+ *
10
+ * @param prefix Short, type-identifying string (e.g. `w`, `ses`, `turn`)
11
+ * @param randomByteCount Number of random bytes; produces 2× hex digits (default 6 → 12 hex chars)
12
+ */
13
+ export declare function generateId(prefix: string, randomByteCount?: number): string;
14
+ //# sourceMappingURL=id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../src/id.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,GAAE,MAAU,GAAG,MAAM,CAI9E"}