@shardworks/loom-apparatus 0.1.101

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/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2026 Sean Boots
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # `@shardworks/loom-apparatus`
2
+
3
+ The Loom — the guild's session context composer. This apparatus owns system prompt assembly: given a role name, it weaves charter, curricula, temperament, and role instructions into an `AnimaWeave` that The Animator consumes to launch AI sessions. The work prompt (what the anima should do) bypasses The Loom — it is not a composition concern.
4
+
5
+ MVP: system prompt composition is not yet implemented — `weave()` returns an empty `AnimaWeave` (systemPrompt undefined). The role is accepted but not yet used. The seam exists now so the contract is stable as composition logic is built out.
6
+
7
+ ```
8
+ caller (Animator.summon) → weave({ role })
9
+ @shardworks/loom-apparatus → AnimaWeave { systemPrompt? }
10
+ The Animator → launches session with weave + work prompt
11
+ ```
12
+
13
+ ---
14
+
15
+ ## Installation
16
+
17
+ ```json
18
+ {
19
+ "dependencies": {
20
+ "@shardworks/loom-apparatus": "workspace:*"
21
+ }
22
+ }
23
+ ```
24
+
25
+ Plugin id: `loom`
26
+
27
+ ---
28
+
29
+ ## API
30
+
31
+ The Loom exposes `LoomApi` via `provides`, accessed by other plugins as:
32
+
33
+ ```typescript
34
+ import { guild } from '@shardworks/nexus-core';
35
+ import type { LoomApi } from '@shardworks/loom-apparatus';
36
+
37
+ const loom = guild().apparatus<LoomApi>('loom');
38
+ ```
39
+
40
+ ### `LoomApi`
41
+
42
+ ```typescript
43
+ interface LoomApi {
44
+ /**
45
+ * Weave an anima's session context.
46
+ *
47
+ * Given a role name, produces an AnimaWeave containing the composed
48
+ * system prompt. MVP: returns undefined for systemPrompt.
49
+ */
50
+ weave(request: WeaveRequest): Promise<AnimaWeave>;
51
+ }
52
+ ```
53
+
54
+ ### `WeaveRequest`
55
+
56
+ ```typescript
57
+ interface WeaveRequest {
58
+ /**
59
+ * The role to weave context for (e.g. 'artificer', 'scribe').
60
+ * MVP: accepted but not used. Future: resolves role instructions,
61
+ * curriculum, temperament, and composes the system prompt.
62
+ */
63
+ role?: string;
64
+ }
65
+ ```
66
+
67
+ ### `AnimaWeave`
68
+
69
+ ```typescript
70
+ interface AnimaWeave {
71
+ /** The system prompt for the AI process. Undefined until composition is implemented. */
72
+ systemPrompt?: string;
73
+ }
74
+ ```
75
+
76
+ ### Usage Examples
77
+
78
+ **Weave a context for a role:**
79
+
80
+ ```typescript
81
+ const loom = guild().apparatus<LoomApi>('loom');
82
+
83
+ const weave = await loom.weave({ role: 'artificer' });
84
+ // MVP → { systemPrompt: undefined }
85
+ // Future → { systemPrompt: '<woven from charter + curricula + ...>' }
86
+ ```
87
+
88
+ **Via The Animator (typical path):**
89
+
90
+ ```typescript
91
+ const animator = guild().apparatus<AnimatorApi>('animator');
92
+
93
+ // summon() calls loom.weave() internally — you don't need to call it directly
94
+ const result = await animator.summon({
95
+ role: 'artificer',
96
+ prompt: 'Build the frobnicator module with tests',
97
+ cwd: '/path/to/workdir',
98
+ });
99
+ ```
100
+
101
+ ---
102
+
103
+ ## Configuration
104
+
105
+ MVP: none. The Loom reads no guild configuration.
106
+
107
+ Future versions will read role definitions, anima identity records, charter content, and curricula from guild config and The Stacks.
108
+
109
+ ---
110
+
111
+ ## Exports
112
+
113
+ ```typescript
114
+ // Loom API types
115
+ import {
116
+ type LoomApi,
117
+ type WeaveRequest,
118
+ type AnimaWeave,
119
+ createLoom,
120
+ } from '@shardworks/loom-apparatus';
121
+ ```
122
+
123
+ The default export is the apparatus plugin instance, ready for use in `guild.json`:
124
+
125
+ ```typescript
126
+ import loom from '@shardworks/loom-apparatus';
127
+ // → Plugin with apparatus.provides = LoomApi
128
+ ```
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @shardworks/loom-apparatus — The Loom.
3
+ *
4
+ * Session context composition: weaves role instructions, curricula, and
5
+ * temperaments into an AnimaWeave that The Animator can consume to
6
+ * launch AI sessions.
7
+ *
8
+ * See: docs/specification.md (loom)
9
+ */
10
+ export { type LoomApi, type WeaveRequest, type AnimaWeave, type LoomConfig, type RoleDefinition, createLoom, } from './loom.ts';
11
+ import type { LoomConfig } from './loom.ts';
12
+ declare module '@shardworks/nexus-core' {
13
+ interface GuildConfig {
14
+ loom?: LoomConfig;
15
+ }
16
+ }
17
+ declare const _default: import("@shardworks/nexus-core").Plugin;
18
+ export default _default;
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,UAAU,GACX,MAAM,WAAW,CAAC;AAMnB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,QAAQ,wBAAwB,CAAC;IACtC,UAAU,WAAW;QACnB,IAAI,CAAC,EAAE,UAAU,CAAC;KACnB;CACF;;AAID,wBAA4B"}
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @shardworks/loom-apparatus — The Loom.
3
+ *
4
+ * Session context composition: weaves role instructions, curricula, and
5
+ * temperaments into an AnimaWeave that The Animator can consume to
6
+ * launch AI sessions.
7
+ *
8
+ * See: docs/specification.md (loom)
9
+ */
10
+ import { createLoom } from "./loom.js";
11
+ // ── Loom API ─────────────────────────────────────────────────────────
12
+ export { createLoom, } from "./loom.js";
13
+ // ── Default export: the apparatus plugin ──────────────────────────────
14
+ export default createLoom();
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,wEAAwE;AAExE,OAAO,EAML,UAAU,GACX,MAAM,WAAW,CAAC;AAanB,yEAAyE;AAEzE,eAAe,UAAU,EAAE,CAAC"}
package/dist/loom.d.ts ADDED
@@ -0,0 +1,82 @@
1
+ /**
2
+ * The Loom — session context composition apparatus.
3
+ *
4
+ * The Loom owns system prompt assembly. Given a role name, it produces
5
+ * an AnimaWeave — the composed identity context that The Animator uses
6
+ * to launch a session. The work prompt (what the anima should do) is
7
+ * not the Loom's concern; it bypasses the Loom and goes directly to
8
+ * the Animator.
9
+ *
10
+ * The Loom resolves the role's permission grants from guild.json, then
11
+ * calls the Instrumentarium to resolve the permission-gated tool set.
12
+ * Tools are returned on the AnimaWeave so the Animator can pass them
13
+ * to the session provider for MCP server configuration.
14
+ *
15
+ * See: docs/specification.md (loom)
16
+ */
17
+ import type { Plugin } from '@shardworks/nexus-core';
18
+ import type { ResolvedTool } from '@shardworks/tools-apparatus';
19
+ export interface WeaveRequest {
20
+ /**
21
+ * The role to weave context for (e.g. 'artificer', 'scribe').
22
+ *
23
+ * When provided, the Loom resolves role → permissions from guild.json,
24
+ * then calls the Instrumentarium to resolve the permission-gated tool set.
25
+ * Tools are returned on the AnimaWeave.
26
+ *
27
+ * When omitted, no tool resolution occurs — the AnimaWeave has no tools.
28
+ */
29
+ role?: string;
30
+ }
31
+ /**
32
+ * The output of The Loom's weave() — the composed anima identity context.
33
+ *
34
+ * Contains the system prompt (produced by the Loom from the anima's
35
+ * identity layers) and the resolved tool set for the role. The work
36
+ * prompt is not part of the weave — it goes directly to the Animator.
37
+ */
38
+ export interface AnimaWeave {
39
+ /** The system prompt for the AI process. Undefined until composition is implemented. */
40
+ systemPrompt?: string;
41
+ /** The resolved tool set for this role. Undefined when no role is specified or no tools match. */
42
+ tools?: ResolvedTool[];
43
+ }
44
+ /** The Loom's public API, exposed via `provides`. */
45
+ export interface LoomApi {
46
+ /**
47
+ * Weave an anima's session context.
48
+ *
49
+ * Given a role name, produces an AnimaWeave containing the composed
50
+ * system prompt and the resolved tool set. System prompt composition
51
+ * (charter, curricula, temperament, role instructions) is future work —
52
+ * systemPrompt remains undefined until then.
53
+ *
54
+ * Tool resolution is active: if a role is provided and the Instrumentarium
55
+ * is installed, the Loom resolves role → permissions → tools.
56
+ */
57
+ weave(request: WeaveRequest): Promise<AnimaWeave>;
58
+ }
59
+ /** Role definition in guild.json under the Loom's plugin section. */
60
+ export interface RoleDefinition {
61
+ /** Permission grants in `plugin:level` format. */
62
+ permissions: string[];
63
+ /**
64
+ * When true, permissionless tools are excluded unless the role grants
65
+ * `plugin:*` or `*:*` for the tool's plugin. Default: false.
66
+ */
67
+ strict?: boolean;
68
+ }
69
+ /** Loom configuration from guild.json. */
70
+ export interface LoomConfig {
71
+ /** Role definitions keyed by role name. */
72
+ roles?: Record<string, RoleDefinition>;
73
+ }
74
+ /**
75
+ * Create the Loom apparatus plugin.
76
+ *
77
+ * Returns a Plugin with:
78
+ * - `requires: ['tools']` — needs the Instrumentarium for tool resolution
79
+ * - `provides: LoomApi` — the context composition API
80
+ */
81
+ export declare function createLoom(): Plugin;
82
+ //# sourceMappingURL=loom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loom.d.ts","sourceRoot":"","sources":["../src/loom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,wBAAwB,CAAC;AAErE,OAAO,KAAK,EAAsB,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAIpF,MAAM,WAAW,YAAY;IAC3B;;;;;;;;OAQG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,wFAAwF;IACxF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kGAAkG;IAClG,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;CACxB;AAED,qDAAqD;AACrD,MAAM,WAAW,OAAO;IACtB;;;;;;;;;;OAUG;IACH,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACnD;AAID,qEAAqE;AACrE,MAAM,WAAW,cAAc;IAC7B,kDAAkD;IAClD,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,0CAA0C;AAC1C,MAAM,WAAW,UAAU;IACzB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CACxC;AAID;;;;;;GAMG;AACH,wBAAgB,UAAU,IAAI,MAAM,CA2CnC"}
package/dist/loom.js ADDED
@@ -0,0 +1,66 @@
1
+ /**
2
+ * The Loom — session context composition apparatus.
3
+ *
4
+ * The Loom owns system prompt assembly. Given a role name, it produces
5
+ * an AnimaWeave — the composed identity context that The Animator uses
6
+ * to launch a session. The work prompt (what the anima should do) is
7
+ * not the Loom's concern; it bypasses the Loom and goes directly to
8
+ * the Animator.
9
+ *
10
+ * The Loom resolves the role's permission grants from guild.json, then
11
+ * calls the Instrumentarium to resolve the permission-gated tool set.
12
+ * Tools are returned on the AnimaWeave so the Animator can pass them
13
+ * to the session provider for MCP server configuration.
14
+ *
15
+ * See: docs/specification.md (loom)
16
+ */
17
+ import { guild } from '@shardworks/nexus-core';
18
+ // ── Apparatus factory ─────────────────────────────────────────────────
19
+ /**
20
+ * Create the Loom apparatus plugin.
21
+ *
22
+ * Returns a Plugin with:
23
+ * - `requires: ['tools']` — needs the Instrumentarium for tool resolution
24
+ * - `provides: LoomApi` — the context composition API
25
+ */
26
+ export function createLoom() {
27
+ let config = {};
28
+ const api = {
29
+ async weave(request) {
30
+ const weave = {};
31
+ // Resolve tools if a role is provided and has a definition.
32
+ if (request.role && config.roles) {
33
+ const roleDef = config.roles[request.role];
34
+ if (roleDef) {
35
+ try {
36
+ const instrumentarium = guild().apparatus('tools');
37
+ weave.tools = instrumentarium.resolve({
38
+ permissions: roleDef.permissions,
39
+ strict: roleDef.strict,
40
+ caller: 'anima',
41
+ });
42
+ }
43
+ catch {
44
+ // Instrumentarium not installed — no tools.
45
+ // This shouldn't happen since we require 'tools', but
46
+ // fail gracefully rather than crash the session.
47
+ }
48
+ }
49
+ }
50
+ // Future: compose system prompt from charter + curriculum +
51
+ // temperament + role instructions + tool instructions.
52
+ return weave;
53
+ },
54
+ };
55
+ return {
56
+ apparatus: {
57
+ requires: ['tools'],
58
+ provides: api,
59
+ start(_ctx) {
60
+ const g = guild();
61
+ config = g.guildConfig().loom ?? {};
62
+ },
63
+ },
64
+ };
65
+ }
66
+ //# sourceMappingURL=loom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loom.js","sourceRoot":"","sources":["../src/loom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAmE/C,yEAAyE;AAEzE;;;;;;GAMG;AACH,MAAM,UAAU,UAAU;IACxB,IAAI,MAAM,GAAe,EAAE,CAAC;IAE5B,MAAM,GAAG,GAAY;QACnB,KAAK,CAAC,KAAK,CAAC,OAAqB;YAC/B,MAAM,KAAK,GAAe,EAAE,CAAC;YAE7B,4DAA4D;YAC5D,IAAI,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;gBACjC,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBAC3C,IAAI,OAAO,EAAE,CAAC;oBACZ,IAAI,CAAC;wBACH,MAAM,eAAe,GAAG,KAAK,EAAE,CAAC,SAAS,CAAqB,OAAO,CAAC,CAAC;wBACvE,KAAK,CAAC,KAAK,GAAG,eAAe,CAAC,OAAO,CAAC;4BACpC,WAAW,EAAE,OAAO,CAAC,WAAW;4BAChC,MAAM,EAAE,OAAO,CAAC,MAAM;4BACtB,MAAM,EAAE,OAAO;yBAChB,CAAC,CAAC;oBACL,CAAC;oBAAC,MAAM,CAAC;wBACP,4CAA4C;wBAC5C,sDAAsD;wBACtD,iDAAiD;oBACnD,CAAC;gBACH,CAAC;YACH,CAAC;YAED,4DAA4D;YAC5D,uDAAuD;YACvD,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;IAEF,OAAO;QACL,SAAS,EAAE;YACT,QAAQ,EAAE,CAAC,OAAO,CAAC;YACnB,QAAQ,EAAE,GAAG;YAEb,KAAK,CAAC,IAAoB;gBACxB,MAAM,CAAC,GAAG,KAAK,EAAE,CAAC;gBAClB,MAAM,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC;YACtC,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@shardworks/loom-apparatus",
3
+ "version": "0.1.101",
4
+ "license": "ISC",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/shardworks/nexus",
8
+ "directory": "packages/plugins/loom"
9
+ },
10
+ "description": "The Loom — session context composition apparatus",
11
+ "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ }
17
+ },
18
+ "dependencies": {
19
+ "zod": "4.3.6",
20
+ "@shardworks/tools-apparatus": "0.1.101",
21
+ "@shardworks/nexus-core": "0.1.101"
22
+ },
23
+ "devDependencies": {
24
+ "@types/node": "25.5.0"
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "scripts": {
30
+ "build": "tsc",
31
+ "test": "node --disable-warning=ExperimentalWarning --experimental-transform-types --test 'src/**/*.test.ts'",
32
+ "typecheck": "tsc --noEmit"
33
+ }
34
+ }