@shardworks/loom-apparatus 0.1.117 → 0.1.118
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/README.md +16 -11
- package/dist/loom.d.ts +8 -4
- package/dist/loom.d.ts.map +1 -1
- package/dist/loom.js +68 -2
- package/dist/loom.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
# `@shardworks/loom-apparatus`
|
|
2
2
|
|
|
3
|
-
The Loom — the guild's session context composer. This apparatus owns system prompt assembly: given a role name, it weaves charter,
|
|
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.
|
|
3
|
+
The Loom — the guild's session context composer. This apparatus owns system prompt assembly: given a role name, it weaves charter, tool instructions, 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.
|
|
6
4
|
|
|
7
5
|
```
|
|
8
6
|
caller (Animator.summon) → weave({ role })
|
|
9
|
-
@shardworks/loom-apparatus → AnimaWeave { systemPrompt? }
|
|
7
|
+
@shardworks/loom-apparatus → AnimaWeave { systemPrompt?, tools?, environment? }
|
|
10
8
|
The Animator → launches session with weave + work prompt
|
|
11
9
|
```
|
|
12
10
|
|
|
@@ -44,8 +42,8 @@ interface LoomApi {
|
|
|
44
42
|
/**
|
|
45
43
|
* Weave an anima's session context.
|
|
46
44
|
*
|
|
47
|
-
* Given a role name, produces an AnimaWeave
|
|
48
|
-
*
|
|
45
|
+
* Given a role name, produces an AnimaWeave with a composed system prompt,
|
|
46
|
+
* resolved tool set, and git identity environment variables.
|
|
49
47
|
*/
|
|
50
48
|
weave(request: WeaveRequest): Promise<AnimaWeave>;
|
|
51
49
|
}
|
|
@@ -57,8 +55,8 @@ interface LoomApi {
|
|
|
57
55
|
interface WeaveRequest {
|
|
58
56
|
/**
|
|
59
57
|
* The role to weave context for (e.g. 'artificer', 'scribe').
|
|
60
|
-
*
|
|
61
|
-
*
|
|
58
|
+
* Determines tool resolution and role instructions. When omitted,
|
|
59
|
+
* only charter content is included in the system prompt.
|
|
62
60
|
*/
|
|
63
61
|
role?: string;
|
|
64
62
|
}
|
|
@@ -68,8 +66,14 @@ interface WeaveRequest {
|
|
|
68
66
|
|
|
69
67
|
```typescript
|
|
70
68
|
interface AnimaWeave {
|
|
71
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* The system prompt for the AI process. Composed from guild charter,
|
|
71
|
+
* tool instructions, and role instructions. Undefined when no
|
|
72
|
+
* composition layers produce content.
|
|
73
|
+
*/
|
|
72
74
|
systemPrompt?: string;
|
|
75
|
+
/** The resolved tool set for this role. Undefined when no role is specified or no tools match. */
|
|
76
|
+
tools?: ResolvedTool[];
|
|
73
77
|
/**
|
|
74
78
|
* Environment variables for the session process.
|
|
75
79
|
* Default: git identity derived from role name.
|
|
@@ -88,7 +92,8 @@ const loom = guild().apparatus<LoomApi>('loom');
|
|
|
88
92
|
|
|
89
93
|
const weave = await loom.weave({ role: 'artificer' });
|
|
90
94
|
// → {
|
|
91
|
-
// systemPrompt:
|
|
95
|
+
// systemPrompt: '...charter...\n\n## Tool: ...\n\n...role instructions...',
|
|
96
|
+
// tools: [...],
|
|
92
97
|
// environment: {
|
|
93
98
|
// GIT_AUTHOR_NAME: 'Artificer',
|
|
94
99
|
// GIT_AUTHOR_EMAIL: 'artificer@nexus.local',
|
|
@@ -115,7 +120,7 @@ const result = await animator.summon({
|
|
|
115
120
|
|
|
116
121
|
The Loom reads role definitions from `guild.json["loom"]["roles"]`. See the [architecture spec](../../docs/architecture/apparatus/loom.md) for role configuration format.
|
|
117
122
|
|
|
118
|
-
|
|
123
|
+
Role configuration is used for tool resolution (permissions), environment variables (git identity), and role instruction file lookup (`roles/{role}.md`). Future: curricula and temperament composition.
|
|
119
124
|
|
|
120
125
|
---
|
|
121
126
|
|
package/dist/loom.d.ts
CHANGED
|
@@ -36,7 +36,11 @@ export interface WeaveRequest {
|
|
|
36
36
|
* prompt is not part of the weave — it goes directly to the Animator.
|
|
37
37
|
*/
|
|
38
38
|
export interface AnimaWeave {
|
|
39
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* The system prompt for the AI process. Composed from guild charter,
|
|
41
|
+
* tool instructions, and role instructions. Undefined when no
|
|
42
|
+
* composition layers produce content.
|
|
43
|
+
*/
|
|
40
44
|
systemPrompt?: string;
|
|
41
45
|
/** The resolved tool set for this role. Undefined when no role is specified or no tools match. */
|
|
42
46
|
tools?: ResolvedTool[];
|
|
@@ -49,9 +53,9 @@ export interface LoomApi {
|
|
|
49
53
|
* Weave an anima's session context.
|
|
50
54
|
*
|
|
51
55
|
* Given a role name, produces an AnimaWeave containing the composed
|
|
52
|
-
* system prompt and the resolved tool set.
|
|
53
|
-
*
|
|
54
|
-
*
|
|
56
|
+
* system prompt and the resolved tool set. The system prompt is assembled
|
|
57
|
+
* from the guild charter, tool instructions (for the resolved tool set),
|
|
58
|
+
* and role instructions — in that order.
|
|
55
59
|
*
|
|
56
60
|
* Tool resolution is active: if a role is provided and the Instrumentarium
|
|
57
61
|
* is installed, the Loom resolves role → permissions → tools.
|
package/dist/loom.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
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;AAMpF,MAAM,WAAW,YAAY;IAC3B;;;;;;;;OAQG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kGAAkG;IAClG,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;IACvB,oFAAoF;IACpF,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC;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,CAuHnC"}
|
package/dist/loom.js
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
* See: docs/specification.md (loom)
|
|
16
16
|
*/
|
|
17
17
|
import { guild } from '@shardworks/nexus-core';
|
|
18
|
+
import fs from 'node:fs';
|
|
19
|
+
import path from 'node:path';
|
|
18
20
|
// ── Apparatus factory ─────────────────────────────────────────────────
|
|
19
21
|
/**
|
|
20
22
|
* Create the Loom apparatus plugin.
|
|
@@ -25,6 +27,8 @@ import { guild } from '@shardworks/nexus-core';
|
|
|
25
27
|
*/
|
|
26
28
|
export function createLoom() {
|
|
27
29
|
let config = {};
|
|
30
|
+
let charterContent;
|
|
31
|
+
let roleInstructions = new Map();
|
|
28
32
|
const api = {
|
|
29
33
|
async weave(request) {
|
|
30
34
|
const weave = {};
|
|
@@ -55,8 +59,25 @@ export function createLoom() {
|
|
|
55
59
|
GIT_AUTHOR_EMAIL: `${request.role}@nexus.local`,
|
|
56
60
|
};
|
|
57
61
|
}
|
|
58
|
-
//
|
|
59
|
-
|
|
62
|
+
// Compose system prompt from available layers: charter → tool instructions → role instructions.
|
|
63
|
+
const layers = [];
|
|
64
|
+
if (charterContent) {
|
|
65
|
+
layers.push(charterContent);
|
|
66
|
+
}
|
|
67
|
+
if (weave.tools && weave.tools.length > 0) {
|
|
68
|
+
for (const resolvedTool of weave.tools) {
|
|
69
|
+
const instructions = resolvedTool.definition.instructions;
|
|
70
|
+
if (instructions) {
|
|
71
|
+
layers.push(`## Tool: ${resolvedTool.definition.name}\n\n${instructions}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (request.role && roleInstructions.has(request.role)) {
|
|
76
|
+
layers.push(roleInstructions.get(request.role));
|
|
77
|
+
}
|
|
78
|
+
if (layers.length > 0) {
|
|
79
|
+
weave.systemPrompt = layers.join('\n\n');
|
|
80
|
+
}
|
|
60
81
|
return weave;
|
|
61
82
|
},
|
|
62
83
|
};
|
|
@@ -67,6 +88,51 @@ export function createLoom() {
|
|
|
67
88
|
start(_ctx) {
|
|
68
89
|
const g = guild();
|
|
69
90
|
config = g.guildConfig().loom ?? {};
|
|
91
|
+
const home = g.home;
|
|
92
|
+
// Read charter content at startup and cache it.
|
|
93
|
+
charterContent = undefined;
|
|
94
|
+
const charterFilePath = path.join(home, 'charter.md');
|
|
95
|
+
try {
|
|
96
|
+
charterContent = fs.readFileSync(charterFilePath, 'utf-8');
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
if (err.code !== 'ENOENT')
|
|
100
|
+
throw err;
|
|
101
|
+
// No charter.md — check for charter/ directory.
|
|
102
|
+
const charterDir = path.join(home, 'charter');
|
|
103
|
+
try {
|
|
104
|
+
const stat = fs.statSync(charterDir);
|
|
105
|
+
if (stat.isDirectory()) {
|
|
106
|
+
const mdFiles = fs.readdirSync(charterDir)
|
|
107
|
+
.filter(f => f.endsWith('.md'))
|
|
108
|
+
.sort();
|
|
109
|
+
if (mdFiles.length > 0) {
|
|
110
|
+
charterContent = mdFiles
|
|
111
|
+
.map(f => fs.readFileSync(path.join(charterDir, f), 'utf-8'))
|
|
112
|
+
.join('\n\n');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// No charter/ directory either — silently omit.
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Read role instruction files at startup for all configured roles.
|
|
121
|
+
roleInstructions = new Map();
|
|
122
|
+
if (config.roles) {
|
|
123
|
+
for (const roleName of Object.keys(config.roles)) {
|
|
124
|
+
const rolePath = path.join(home, 'roles', `${roleName}.md`);
|
|
125
|
+
try {
|
|
126
|
+
const content = fs.readFileSync(rolePath, 'utf-8');
|
|
127
|
+
if (content) {
|
|
128
|
+
roleInstructions.set(roleName, content);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
// File doesn't exist — silently omit.
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
70
136
|
},
|
|
71
137
|
},
|
|
72
138
|
};
|
package/dist/loom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loom.js","sourceRoot":"","sources":["../src/loom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"loom.js","sourceRoot":"","sources":["../src/loom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAE/C,OAAO,EAAE,MAAM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,CAAC,KAAK,CAAC,EAAE,CAAC;wBACjD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,QAAQ,KAAK,CAAC,CAAC;wBAC5D,IAAI,CAAC;4BACH,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;4BACnD,IAAI,OAAO,EAAE,CAAC;gCACZ,gBAAgB,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;4BAC1C,CAAC;wBACH,CAAC;wBAAC,MAAM,CAAC;4BACP,sCAAsC;wBACxC,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shardworks/loom-apparatus",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.118",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"zod": "4.3.6",
|
|
20
|
-
"@shardworks/nexus-core": "0.1.
|
|
21
|
-
"@shardworks/tools-apparatus": "0.1.
|
|
20
|
+
"@shardworks/nexus-core": "0.1.118",
|
|
21
|
+
"@shardworks/tools-apparatus": "0.1.118"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/node": "25.5.0"
|