@shardworks/nexus-core 0.1.99 → 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/README.md +95 -166
- package/dist/guild-config.d.ts +14 -52
- package/dist/guild-config.d.ts.map +1 -1
- package/dist/guild-config.js +7 -10
- package/dist/guild-config.js.map +1 -1
- package/dist/guild.d.ts +83 -0
- package/dist/guild.d.ts.map +1 -0
- package/dist/guild.js +45 -0
- package/dist/guild.js.map +1 -0
- package/dist/id.d.ts +14 -0
- package/dist/id.d.ts.map +1 -0
- package/dist/id.js +19 -0
- package/dist/id.js.map +1 -0
- package/dist/index.d.ts +6 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -32
- package/dist/index.js.map +1 -1
- package/dist/nexus-home.d.ts +0 -4
- package/dist/nexus-home.d.ts.map +1 -1
- package/dist/nexus-home.js +1 -9
- package/dist/nexus-home.js.map +1 -1
- package/dist/plugin.d.ts +115 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +39 -0
- package/dist/plugin.js.map +1 -0
- package/dist/resolve-package.d.ts +58 -0
- package/dist/resolve-package.d.ts.map +1 -0
- package/dist/resolve-package.js +123 -0
- package/dist/resolve-package.js.map +1 -0
- package/package.json +5 -14
- package/dist/book.d.ts +0 -110
- package/dist/book.d.ts.map +0 -1
- package/dist/book.js +0 -16
- package/dist/book.js.map +0 -1
- package/dist/legacy/1/anima.d.ts +0 -79
- package/dist/legacy/1/anima.d.ts.map +0 -1
- package/dist/legacy/1/anima.js +0 -285
- package/dist/legacy/1/anima.js.map +0 -1
- package/dist/legacy/1/audit.d.ts +0 -23
- package/dist/legacy/1/audit.d.ts.map +0 -1
- package/dist/legacy/1/audit.js +0 -61
- package/dist/legacy/1/audit.js.map +0 -1
- package/dist/legacy/1/bundle.d.ts +0 -111
- package/dist/legacy/1/bundle.d.ts.map +0 -1
- package/dist/legacy/1/bundle.js +0 -452
- package/dist/legacy/1/bundle.js.map +0 -1
- package/dist/legacy/1/clock-daemon.d.ts +0 -2
- package/dist/legacy/1/clock-daemon.d.ts.map +0 -1
- package/dist/legacy/1/clock-daemon.js +0 -72
- package/dist/legacy/1/clock-daemon.js.map +0 -1
- package/dist/legacy/1/clockworks.d.ts +0 -98
- package/dist/legacy/1/clockworks.d.ts.map +0 -1
- package/dist/legacy/1/clockworks.js +0 -359
- package/dist/legacy/1/clockworks.js.map +0 -1
- package/dist/legacy/1/conversation.d.ts +0 -165
- package/dist/legacy/1/conversation.d.ts.map +0 -1
- package/dist/legacy/1/conversation.js +0 -457
- package/dist/legacy/1/conversation.js.map +0 -1
- package/dist/legacy/1/engine.d.ts +0 -90
- package/dist/legacy/1/engine.d.ts.map +0 -1
- package/dist/legacy/1/engine.js +0 -89
- package/dist/legacy/1/engine.js.map +0 -1
- package/dist/legacy/1/events.d.ts +0 -88
- package/dist/legacy/1/events.d.ts.map +0 -1
- package/dist/legacy/1/events.js +0 -239
- package/dist/legacy/1/events.js.map +0 -1
- package/dist/legacy/1/guild-config.d.ts +0 -74
- package/dist/legacy/1/guild-config.d.ts.map +0 -1
- package/dist/legacy/1/guild-config.js +0 -51
- package/dist/legacy/1/guild-config.js.map +0 -1
- package/dist/legacy/1/id.d.ts +0 -8
- package/dist/legacy/1/id.d.ts.map +0 -1
- package/dist/legacy/1/id.js +0 -27
- package/dist/legacy/1/id.js.map +0 -1
- package/dist/legacy/1/index.d.ts +0 -28
- package/dist/legacy/1/index.d.ts.map +0 -1
- package/dist/legacy/1/index.js +0 -32
- package/dist/legacy/1/index.js.map +0 -1
- package/dist/legacy/1/init-guild.d.ts +0 -24
- package/dist/legacy/1/init-guild.d.ts.map +0 -1
- package/dist/legacy/1/init-guild.js +0 -230
- package/dist/legacy/1/init-guild.js.map +0 -1
- package/dist/legacy/1/install-tool.d.ts +0 -73
- package/dist/legacy/1/install-tool.d.ts.map +0 -1
- package/dist/legacy/1/install-tool.js +0 -436
- package/dist/legacy/1/install-tool.js.map +0 -1
- package/dist/legacy/1/instantiate.d.ts +0 -33
- package/dist/legacy/1/instantiate.d.ts.map +0 -1
- package/dist/legacy/1/instantiate.js +0 -137
- package/dist/legacy/1/instantiate.js.map +0 -1
- package/dist/legacy/1/manifest.d.ts +0 -132
- package/dist/legacy/1/manifest.d.ts.map +0 -1
- package/dist/legacy/1/manifest.js +0 -321
- package/dist/legacy/1/manifest.js.map +0 -1
- package/dist/legacy/1/migrate.d.ts +0 -84
- package/dist/legacy/1/migrate.d.ts.map +0 -1
- package/dist/legacy/1/migrate.js +0 -228
- package/dist/legacy/1/migrate.js.map +0 -1
- package/dist/legacy/1/nexus-home.d.ts +0 -11
- package/dist/legacy/1/nexus-home.d.ts.map +0 -1
- package/dist/legacy/1/nexus-home.js +0 -16
- package/dist/legacy/1/nexus-home.js.map +0 -1
- package/dist/legacy/1/plugin-descriptor.d.ts +0 -3
- package/dist/legacy/1/plugin-descriptor.d.ts.map +0 -1
- package/dist/legacy/1/plugin-descriptor.js +0 -2
- package/dist/legacy/1/plugin-descriptor.js.map +0 -1
- package/dist/legacy/1/preconditions.d.ts +0 -100
- package/dist/legacy/1/preconditions.d.ts.map +0 -1
- package/dist/legacy/1/preconditions.js +0 -189
- package/dist/legacy/1/preconditions.js.map +0 -1
- package/dist/legacy/1/rehydrate.d.ts +0 -22
- package/dist/legacy/1/rehydrate.d.ts.map +0 -1
- package/dist/legacy/1/rehydrate.js +0 -109
- package/dist/legacy/1/rehydrate.js.map +0 -1
- package/dist/legacy/1/remove-tool.d.ts +0 -19
- package/dist/legacy/1/remove-tool.d.ts.map +0 -1
- package/dist/legacy/1/remove-tool.js +0 -105
- package/dist/legacy/1/remove-tool.js.map +0 -1
- package/dist/legacy/1/session.d.ts +0 -343
- package/dist/legacy/1/session.d.ts.map +0 -1
- package/dist/legacy/1/session.js +0 -499
- package/dist/legacy/1/session.js.map +0 -1
- package/dist/legacy/1/tool-registry.d.ts +0 -12
- package/dist/legacy/1/tool-registry.d.ts.map +0 -1
- package/dist/legacy/1/tool-registry.js +0 -28
- package/dist/legacy/1/tool-registry.js.map +0 -1
- package/dist/legacy/1/tool.d.ts +0 -10
- package/dist/legacy/1/tool.d.ts.map +0 -1
- package/dist/legacy/1/tool.js +0 -2
- package/dist/legacy/1/tool.js.map +0 -1
- package/dist/legacy/1/upgrade.d.ts +0 -129
- package/dist/legacy/1/upgrade.d.ts.map +0 -1
- package/dist/legacy/1/upgrade.js +0 -355
- package/dist/legacy/1/upgrade.js.map +0 -1
- package/dist/legacy/1/workshop.d.ts +0 -95
- package/dist/legacy/1/workshop.d.ts.map +0 -1
- package/dist/legacy/1/workshop.js +0 -229
- package/dist/legacy/1/workshop.js.map +0 -1
- package/dist/legacy/1/worktree.d.ts +0 -67
- package/dist/legacy/1/worktree.d.ts.map +0 -1
- package/dist/legacy/1/worktree.js +0 -117
- package/dist/legacy/1/worktree.js.map +0 -1
- package/dist/legacy/1/writ.d.ts +0 -130
- package/dist/legacy/1/writ.d.ts.map +0 -1
- package/dist/legacy/1/writ.js +0 -599
- package/dist/legacy/1/writ.js.map +0 -1
- package/dist/rig-context.d.ts +0 -47
- package/dist/rig-context.d.ts.map +0 -1
- package/dist/rig-context.js +0 -11
- package/dist/rig-context.js.map +0 -1
- package/dist/rig-descriptor.d.ts +0 -39
- package/dist/rig-descriptor.d.ts.map +0 -1
- package/dist/rig-descriptor.js +0 -12
- package/dist/rig-descriptor.js.map +0 -1
- package/dist/rig.d.ts +0 -70
- package/dist/rig.d.ts.map +0 -1
- package/dist/rig.js +0 -14
- package/dist/rig.js.map +0 -1
- package/dist/tool.d.ts +0 -136
- package/dist/tool.d.ts.map +0 -1
- package/dist/tool.js +0 -135
- package/dist/tool.js.map +0 -1
- package/migrations/001-schema.sql +0 -177
- package/migrations/002-writs.sql +0 -44
- package/migrations/003-conversations.sql +0 -43
- package/migrations/004-remove-commissions.sql +0 -24
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Manifest — assembles an anima's identity for a session.
|
|
3
|
-
*
|
|
4
|
-
* Reads the anima's composition from the Register (roles, curricula, temperament),
|
|
5
|
-
* resolves tools by role gating and precondition checks, reads all prompt
|
|
6
|
-
* ingredients from disk, and assembles the composed system prompt.
|
|
7
|
-
*
|
|
8
|
-
* The manifest is the anima's *identity*: who are you, what can you do.
|
|
9
|
-
* The *user prompt* (commission spec, brief, conversation topic) is NOT part
|
|
10
|
-
* of the manifest — it comes from the caller.
|
|
11
|
-
*
|
|
12
|
-
* Absorbed from the former `engine-manifest` package. MCP config generation
|
|
13
|
-
* is NOT here — that's a transport detail owned by session providers.
|
|
14
|
-
*/
|
|
15
|
-
import type { GuildConfig } from './guild-config.ts';
|
|
16
|
-
/** An anima's record from the Register, including composition metadata. */
|
|
17
|
-
export interface AnimaRecord {
|
|
18
|
-
id: string;
|
|
19
|
-
name: string;
|
|
20
|
-
status: string;
|
|
21
|
-
roles: string[];
|
|
22
|
-
curriculumName: string;
|
|
23
|
-
curriculumVersion: string;
|
|
24
|
-
curriculumSnapshot: string;
|
|
25
|
-
temperamentName: string;
|
|
26
|
-
temperamentVersion: string;
|
|
27
|
-
temperamentSnapshot: string;
|
|
28
|
-
}
|
|
29
|
-
/** A resolved tool that the anima has access to. */
|
|
30
|
-
export interface ResolvedTool {
|
|
31
|
-
/** Tool name — how the anima sees it. */
|
|
32
|
-
name: string;
|
|
33
|
-
/** Absolute path to the tool's directory on disk. */
|
|
34
|
-
path: string;
|
|
35
|
-
/** Instructions content (if instructions.md exists). */
|
|
36
|
-
instructions: string | null;
|
|
37
|
-
/** npm package name for runtime resolution, or null for file-path resolution. */
|
|
38
|
-
package: string | null;
|
|
39
|
-
}
|
|
40
|
-
/** A tool that was resolved by role but failed precondition checks. */
|
|
41
|
-
export interface UnavailableTool {
|
|
42
|
-
/** Tool name. */
|
|
43
|
-
name: string;
|
|
44
|
-
/** Human-readable reasons why the tool is unavailable. */
|
|
45
|
-
reasons: string[];
|
|
46
|
-
}
|
|
47
|
-
/** The fully-resolved manifest for an anima session. */
|
|
48
|
-
export interface ManifestResult {
|
|
49
|
-
/** The anima record from the Register. */
|
|
50
|
-
anima: AnimaRecord;
|
|
51
|
-
/** The composed system prompt for the anima. */
|
|
52
|
-
systemPrompt: string;
|
|
53
|
-
/** The individual ingredients that produced the system prompt. */
|
|
54
|
-
composition: {
|
|
55
|
-
codex: string;
|
|
56
|
-
roleInstructions: string;
|
|
57
|
-
curriculum: {
|
|
58
|
-
name: string;
|
|
59
|
-
version: string;
|
|
60
|
-
content: string;
|
|
61
|
-
} | null;
|
|
62
|
-
temperament: {
|
|
63
|
-
name: string;
|
|
64
|
-
version: string;
|
|
65
|
-
content: string;
|
|
66
|
-
} | null;
|
|
67
|
-
toolInstructions: Array<{
|
|
68
|
-
toolName: string;
|
|
69
|
-
instructions: string;
|
|
70
|
-
}>;
|
|
71
|
-
};
|
|
72
|
-
/** Resolved tools the anima has access to. */
|
|
73
|
-
tools: ResolvedTool[];
|
|
74
|
-
/** Tools that matched the anima's roles but failed precondition checks. */
|
|
75
|
-
unavailable: UnavailableTool[];
|
|
76
|
-
/** Warnings generated during manifest (e.g. undefined roles). */
|
|
77
|
-
warnings: string[];
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Read an anima's full record from the Register, including roles and composition.
|
|
81
|
-
*/
|
|
82
|
-
export declare function readAnima(home: string, animaName: string): AnimaRecord;
|
|
83
|
-
/**
|
|
84
|
-
* Resolve the set of tools an anima has access to, based on role
|
|
85
|
-
* definitions and precondition checks.
|
|
86
|
-
*
|
|
87
|
-
* 1. Start with baseTools (available to all animas)
|
|
88
|
-
* 2. For each anima role, look up the role in guild.json.roles
|
|
89
|
-
* - If defined: union in that role's tools
|
|
90
|
-
* - If undefined: warn and skip (no tools, no instructions from that role)
|
|
91
|
-
* 3. Deduplicate tool names
|
|
92
|
-
* 4. Resolve each tool from guild.json.tools catalog
|
|
93
|
-
* 5. Run precondition checks — split into available and unavailable
|
|
94
|
-
*
|
|
95
|
-
* Returns available tools, unavailable tools, and any warnings.
|
|
96
|
-
*/
|
|
97
|
-
export declare function resolveTools(home: string, config: GuildConfig, animaRoles: string[]): Promise<{
|
|
98
|
-
available: ResolvedTool[];
|
|
99
|
-
unavailable: UnavailableTool[];
|
|
100
|
-
warnings: string[];
|
|
101
|
-
}>;
|
|
102
|
-
/**
|
|
103
|
-
* Read codex documents from the guildhall — guild-wide policy for all animas.
|
|
104
|
-
*
|
|
105
|
-
* Reads all .md files in the codex/ directory (non-recursive top level).
|
|
106
|
-
*/
|
|
107
|
-
export declare function readCodex(home: string): string;
|
|
108
|
-
/**
|
|
109
|
-
* Read role-specific instructions for an anima's roles.
|
|
110
|
-
*
|
|
111
|
-
* For each role the anima holds, reads the instructions file pointed to by
|
|
112
|
-
* the role definition in guild.json. Skips undefined roles (warning already
|
|
113
|
-
* emitted by resolveTools). Skips roles without instructions.
|
|
114
|
-
*/
|
|
115
|
-
export declare function readRoleInstructions(home: string, config: GuildConfig, animaRoles: string[]): string;
|
|
116
|
-
/**
|
|
117
|
-
* Assemble the composed system prompt for an anima session.
|
|
118
|
-
*
|
|
119
|
-
* Sections are included in order: codex → role instructions → curricula →
|
|
120
|
-
* temperament → tool instructions → unavailable tools notice.
|
|
121
|
-
* Empty sections are omitted.
|
|
122
|
-
*/
|
|
123
|
-
export declare function assembleSystemPrompt(codex: string, roleInstructions: string, anima: AnimaRecord, tools: ResolvedTool[], unavailable?: UnavailableTool[]): string;
|
|
124
|
-
/**
|
|
125
|
-
* Manifest an anima for a session.
|
|
126
|
-
*
|
|
127
|
-
* This is the main entry point. Reads the anima's composition, resolves
|
|
128
|
-
* tools by role, assembles the system prompt, and returns the full
|
|
129
|
-
* manifest with composition provenance.
|
|
130
|
-
*/
|
|
131
|
-
export declare function manifest(home: string, animaName: string): Promise<ManifestResult>;
|
|
132
|
-
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.d.ts","sourceR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AAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAiDvF"}
|
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Manifest — assembles an anima's identity for a session.
|
|
3
|
-
*
|
|
4
|
-
* Reads the anima's composition from the Register (roles, curricula, temperament),
|
|
5
|
-
* resolves tools by role gating and precondition checks, reads all prompt
|
|
6
|
-
* ingredients from disk, and assembles the composed system prompt.
|
|
7
|
-
*
|
|
8
|
-
* The manifest is the anima's *identity*: who are you, what can you do.
|
|
9
|
-
* The *user prompt* (commission spec, brief, conversation topic) is NOT part
|
|
10
|
-
* of the manifest — it comes from the caller.
|
|
11
|
-
*
|
|
12
|
-
* Absorbed from the former `engine-manifest` package. MCP config generation
|
|
13
|
-
* is NOT here — that's a transport detail owned by session providers.
|
|
14
|
-
*/
|
|
15
|
-
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
16
|
-
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
17
|
-
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
18
|
-
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
return path;
|
|
22
|
-
};
|
|
23
|
-
import fs from 'node:fs';
|
|
24
|
-
import path from 'node:path';
|
|
25
|
-
import Database from 'better-sqlite3';
|
|
26
|
-
import { booksPath } from "./nexus-home.js";
|
|
27
|
-
import { readGuildConfig } from "./guild-config.js";
|
|
28
|
-
import { readPreconditions, checkPreconditions } from "./preconditions.js";
|
|
29
|
-
import { resolveToolFromExport } from "./tool.js";
|
|
30
|
-
/** Extract the npm package name from a package specifier that may include a subpath. */
|
|
31
|
-
function basePackageName(pkg) {
|
|
32
|
-
// Scoped: @scope/name/subpath → @scope/name
|
|
33
|
-
if (pkg.startsWith('@')) {
|
|
34
|
-
const parts = pkg.split('/');
|
|
35
|
-
return parts.slice(0, 2).join('/');
|
|
36
|
-
}
|
|
37
|
-
// Unscoped: name/subpath → name
|
|
38
|
-
return pkg.split('/')[0];
|
|
39
|
-
}
|
|
40
|
-
// ── Core Functions ─────────────────────────────────────────────────────
|
|
41
|
-
/**
|
|
42
|
-
* Read an anima's full record from the Register, including roles and composition.
|
|
43
|
-
*/
|
|
44
|
-
export function readAnima(home, animaName) {
|
|
45
|
-
const db = new Database(booksPath(home));
|
|
46
|
-
db.pragma('foreign_keys = ON');
|
|
47
|
-
try {
|
|
48
|
-
// Get anima
|
|
49
|
-
const anima = db.prepare(`SELECT id, name, status FROM animas WHERE name = ?`).get(animaName);
|
|
50
|
-
if (!anima) {
|
|
51
|
-
throw new Error(`Anima "${animaName}" not found in the Register.`);
|
|
52
|
-
}
|
|
53
|
-
// Get roles
|
|
54
|
-
const roleRows = db.prepare(`SELECT role FROM roster WHERE anima_id = ? ORDER BY role`).all(anima.id);
|
|
55
|
-
const roles = roleRows.map(r => r.role);
|
|
56
|
-
// Get composition — now includes name/version metadata
|
|
57
|
-
const composition = db.prepare(`SELECT curriculum_name, curriculum_version, curriculum_snapshot,
|
|
58
|
-
temperament_name, temperament_version, temperament_snapshot
|
|
59
|
-
FROM anima_compositions WHERE anima_id = ?`).get(anima.id);
|
|
60
|
-
return {
|
|
61
|
-
id: anima.id,
|
|
62
|
-
name: anima.name,
|
|
63
|
-
status: anima.status,
|
|
64
|
-
roles,
|
|
65
|
-
curriculumName: composition?.curriculum_name ?? '',
|
|
66
|
-
curriculumVersion: composition?.curriculum_version ?? '',
|
|
67
|
-
curriculumSnapshot: composition?.curriculum_snapshot ?? '',
|
|
68
|
-
temperamentName: composition?.temperament_name ?? '',
|
|
69
|
-
temperamentVersion: composition?.temperament_version ?? '',
|
|
70
|
-
temperamentSnapshot: composition?.temperament_snapshot ?? '',
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
finally {
|
|
74
|
-
db.close();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Resolve the set of tools an anima has access to, based on role
|
|
79
|
-
* definitions and precondition checks.
|
|
80
|
-
*
|
|
81
|
-
* 1. Start with baseTools (available to all animas)
|
|
82
|
-
* 2. For each anima role, look up the role in guild.json.roles
|
|
83
|
-
* - If defined: union in that role's tools
|
|
84
|
-
* - If undefined: warn and skip (no tools, no instructions from that role)
|
|
85
|
-
* 3. Deduplicate tool names
|
|
86
|
-
* 4. Resolve each tool from guild.json.tools catalog
|
|
87
|
-
* 5. Run precondition checks — split into available and unavailable
|
|
88
|
-
*
|
|
89
|
-
* Returns available tools, unavailable tools, and any warnings.
|
|
90
|
-
*/
|
|
91
|
-
export async function resolveTools(home, config, animaRoles) {
|
|
92
|
-
const warnings = [];
|
|
93
|
-
// Collect tool names: start with base, union in role-specific
|
|
94
|
-
const toolNames = new Set(config.baseTools ?? []);
|
|
95
|
-
for (const role of animaRoles) {
|
|
96
|
-
const roleDef = config.roles[role];
|
|
97
|
-
if (!roleDef) {
|
|
98
|
-
warnings.push(`Role "${role}" is assigned to this anima but not defined in guild.json. ` +
|
|
99
|
-
`No tools or instructions from this role will be available.`);
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
for (const toolName of roleDef.tools) {
|
|
103
|
-
toolNames.add(toolName);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
// Resolve each tool from the catalog
|
|
107
|
-
const available = [];
|
|
108
|
-
const unavailable = [];
|
|
109
|
-
for (const name of toolNames) {
|
|
110
|
-
const entry = config.tools[name];
|
|
111
|
-
if (!entry) {
|
|
112
|
-
warnings.push(`Tool "${name}" is referenced by a role or baseTools but not found in guild.json.tools. Skipping.`);
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
// Resolve on-disk path
|
|
116
|
-
const toolPath = path.join(home, 'tools', name);
|
|
117
|
-
const descriptorPath = path.join(toolPath, 'nexus-tool.json');
|
|
118
|
-
// Check preconditions before including in the available set
|
|
119
|
-
const preconditions = readPreconditions(descriptorPath);
|
|
120
|
-
if (preconditions.length > 0) {
|
|
121
|
-
const results = checkPreconditions(preconditions);
|
|
122
|
-
const failures = results.filter(r => !r.passed).map(r => r.message);
|
|
123
|
-
if (failures.length > 0) {
|
|
124
|
-
unavailable.push({ name, reasons: failures });
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
// Read instructions from multiple sources, in priority order:
|
|
129
|
-
// 1. Descriptor file on disk (nexus-tool.json → instructions field)
|
|
130
|
-
// 2. Tool definition (import module → instructions or instructionsFile)
|
|
131
|
-
let instructions = null;
|
|
132
|
-
// Source 1: descriptor file on disk
|
|
133
|
-
if (fs.existsSync(descriptorPath)) {
|
|
134
|
-
try {
|
|
135
|
-
const descriptor = JSON.parse(fs.readFileSync(descriptorPath, 'utf-8'));
|
|
136
|
-
if (descriptor.instructions) {
|
|
137
|
-
const instructionsPath = path.join(toolPath, descriptor.instructions);
|
|
138
|
-
if (fs.existsSync(instructionsPath)) {
|
|
139
|
-
instructions = fs.readFileSync(instructionsPath, 'utf-8');
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
catch {
|
|
144
|
-
// If descriptor is unreadable, skip instructions from descriptor
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
// Source 2: tool definition (for collection packages or tools with
|
|
148
|
-
// inline instructions / instructionsFile in the tool() definition)
|
|
149
|
-
if (!instructions && entry.package) {
|
|
150
|
-
try {
|
|
151
|
-
const mod = await import(__rewriteRelativeImportExtension(entry.package));
|
|
152
|
-
const toolDef = resolveToolFromExport(mod.default, name);
|
|
153
|
-
if (toolDef) {
|
|
154
|
-
if (toolDef.instructions) {
|
|
155
|
-
// Inline instructions text
|
|
156
|
-
instructions = toolDef.instructions;
|
|
157
|
-
}
|
|
158
|
-
else if (toolDef.instructionsFile) {
|
|
159
|
-
// File path relative to the package root in node_modules.
|
|
160
|
-
const instrPath = path.join(home, 'node_modules', basePackageName(entry.package), toolDef.instructionsFile);
|
|
161
|
-
if (fs.existsSync(instrPath)) {
|
|
162
|
-
instructions = fs.readFileSync(instrPath, 'utf-8');
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
catch {
|
|
168
|
-
// If import fails, skip — instructions are optional
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
available.push({
|
|
172
|
-
name,
|
|
173
|
-
path: toolPath,
|
|
174
|
-
instructions,
|
|
175
|
-
package: entry.package ?? null,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
return { available, unavailable, warnings };
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Read codex documents from the guildhall — guild-wide policy for all animas.
|
|
182
|
-
*
|
|
183
|
-
* Reads all .md files in the codex/ directory (non-recursive top level).
|
|
184
|
-
*/
|
|
185
|
-
export function readCodex(home) {
|
|
186
|
-
const codexDir = path.join(home, 'codex');
|
|
187
|
-
if (!fs.existsSync(codexDir))
|
|
188
|
-
return '';
|
|
189
|
-
const sections = [];
|
|
190
|
-
// Read top-level .md files (included for all animas)
|
|
191
|
-
for (const entry of fs.readdirSync(codexDir, { withFileTypes: true })) {
|
|
192
|
-
if (entry.isFile() && entry.name.endsWith('.md')) {
|
|
193
|
-
const content = fs.readFileSync(path.join(codexDir, entry.name), 'utf-8').trim();
|
|
194
|
-
if (content)
|
|
195
|
-
sections.push(content);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return sections.join('\n\n---\n\n');
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Read role-specific instructions for an anima's roles.
|
|
202
|
-
*
|
|
203
|
-
* For each role the anima holds, reads the instructions file pointed to by
|
|
204
|
-
* the role definition in guild.json. Skips undefined roles (warning already
|
|
205
|
-
* emitted by resolveTools). Skips roles without instructions.
|
|
206
|
-
*/
|
|
207
|
-
export function readRoleInstructions(home, config, animaRoles) {
|
|
208
|
-
const sections = [];
|
|
209
|
-
for (const role of animaRoles) {
|
|
210
|
-
const roleDef = config.roles[role];
|
|
211
|
-
if (!roleDef || !roleDef.instructions)
|
|
212
|
-
continue;
|
|
213
|
-
const instructionsPath = path.join(home, roleDef.instructions);
|
|
214
|
-
if (!fs.existsSync(instructionsPath))
|
|
215
|
-
continue;
|
|
216
|
-
try {
|
|
217
|
-
const content = fs.readFileSync(instructionsPath, 'utf-8').trim();
|
|
218
|
-
if (content) {
|
|
219
|
-
sections.push(content);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
catch {
|
|
223
|
-
// If unreadable, skip
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return sections.join('\n\n---\n\n');
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Assemble the composed system prompt for an anima session.
|
|
230
|
-
*
|
|
231
|
-
* Sections are included in order: codex → role instructions → curricula →
|
|
232
|
-
* temperament → tool instructions → unavailable tools notice.
|
|
233
|
-
* Empty sections are omitted.
|
|
234
|
-
*/
|
|
235
|
-
export function assembleSystemPrompt(codex, roleInstructions, anima, tools, unavailable = []) {
|
|
236
|
-
const sections = [];
|
|
237
|
-
// Codex — guild-wide policies and procedures
|
|
238
|
-
if (codex.trim()) {
|
|
239
|
-
sections.push(`# Codex\n\n${codex}`);
|
|
240
|
-
}
|
|
241
|
-
// Role instructions — role-specific operational guidance
|
|
242
|
-
if (roleInstructions.trim()) {
|
|
243
|
-
sections.push(`# Role Instructions\n\n${roleInstructions}`);
|
|
244
|
-
}
|
|
245
|
-
// Curricula — the anima's training content
|
|
246
|
-
if (anima.curriculumSnapshot.trim()) {
|
|
247
|
-
sections.push(`# Training\n\n${anima.curriculumSnapshot}`);
|
|
248
|
-
}
|
|
249
|
-
// Temperament — the anima's personality
|
|
250
|
-
if (anima.temperamentSnapshot.trim()) {
|
|
251
|
-
sections.push(`# Temperament\n\n${anima.temperamentSnapshot}`);
|
|
252
|
-
}
|
|
253
|
-
// Tool instructions — guidance for each tool the anima has access to
|
|
254
|
-
const toolInstructions = tools
|
|
255
|
-
.filter(t => t.instructions)
|
|
256
|
-
.map(t => t.instructions);
|
|
257
|
-
if (toolInstructions.length > 0) {
|
|
258
|
-
sections.push(`# Tool Instructions\n\n${toolInstructions.join('\n\n---\n\n')}`);
|
|
259
|
-
}
|
|
260
|
-
// Unavailable tools notice — tell the anima what's broken and why
|
|
261
|
-
if (unavailable.length > 0) {
|
|
262
|
-
const notices = unavailable.map(u => {
|
|
263
|
-
const reasons = u.reasons.map(r => ` - ${r}`).join('\n');
|
|
264
|
-
return `**${u.name}** — unavailable:\n${reasons}`;
|
|
265
|
-
});
|
|
266
|
-
sections.push(`# Unavailable Tools\n\n` +
|
|
267
|
-
`The following tools are registered for your roles but are currently ` +
|
|
268
|
-
`unavailable due to unmet environment requirements. Do not attempt to use them. ` +
|
|
269
|
-
`If a patron or operator asks you to perform work that requires these tools, ` +
|
|
270
|
-
`explain what is needed to make them available.\n\n` +
|
|
271
|
-
notices.join('\n\n'));
|
|
272
|
-
}
|
|
273
|
-
return sections.join('\n\n---\n\n');
|
|
274
|
-
}
|
|
275
|
-
/**
|
|
276
|
-
* Manifest an anima for a session.
|
|
277
|
-
*
|
|
278
|
-
* This is the main entry point. Reads the anima's composition, resolves
|
|
279
|
-
* tools by role, assembles the system prompt, and returns the full
|
|
280
|
-
* manifest with composition provenance.
|
|
281
|
-
*/
|
|
282
|
-
export async function manifest(home, animaName) {
|
|
283
|
-
const config = readGuildConfig(home);
|
|
284
|
-
const anima = readAnima(home, animaName);
|
|
285
|
-
if (anima.status !== 'active') {
|
|
286
|
-
throw new Error(`Anima "${animaName}" is not active (status: ${anima.status}). Cannot manifest.`);
|
|
287
|
-
}
|
|
288
|
-
// Resolve tools based on role definitions + precondition checks
|
|
289
|
-
const { available, unavailable, warnings } = await resolveTools(home, config, anima.roles);
|
|
290
|
-
// Read codex (guild-wide, no role filtering)
|
|
291
|
-
const codex = readCodex(home);
|
|
292
|
-
// Read role-specific instructions
|
|
293
|
-
const roleInstructions = readRoleInstructions(home, config, anima.roles);
|
|
294
|
-
// Assemble system prompt (includes role instructions and unavailability notices)
|
|
295
|
-
const systemPrompt = assembleSystemPrompt(codex, roleInstructions, anima, available, unavailable);
|
|
296
|
-
// Build composition provenance
|
|
297
|
-
const curriculum = anima.curriculumName
|
|
298
|
-
? { name: anima.curriculumName, version: anima.curriculumVersion, content: anima.curriculumSnapshot }
|
|
299
|
-
: null;
|
|
300
|
-
const temperament = anima.temperamentName
|
|
301
|
-
? { name: anima.temperamentName, version: anima.temperamentVersion, content: anima.temperamentSnapshot }
|
|
302
|
-
: null;
|
|
303
|
-
const toolInstructions = available
|
|
304
|
-
.filter(t => t.instructions)
|
|
305
|
-
.map(t => ({ toolName: t.name, instructions: t.instructions }));
|
|
306
|
-
return {
|
|
307
|
-
anima,
|
|
308
|
-
systemPrompt,
|
|
309
|
-
composition: {
|
|
310
|
-
codex,
|
|
311
|
-
roleInstructions,
|
|
312
|
-
curriculum,
|
|
313
|
-
temperament,
|
|
314
|
-
toolInstructions,
|
|
315
|
-
},
|
|
316
|
-
tools: available,
|
|
317
|
-
unavailable,
|
|
318
|
-
warnings,
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
//# sourceMappingURL=manifest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../../src/legacy/1/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;;;;;;;;;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,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,gBAAgB,GAAG,SAAS;SAC/B,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC;SAC3B,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC,YAAa,EAAE,CAAC,CAAC,CAAC;IAEnE,OAAO;QACL,KAAK;QACL,YAAY;QACZ,WAAW,EAAE;YACX,KAAK;YACL,gBAAgB;YAChB,UAAU;YACV,WAAW;YACX,gBAAgB;SACjB;QACD,KAAK,EAAE,SAAS;QAChB,WAAW;QACX,QAAQ;KACT,CAAC;AACJ,CAAC"}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Database migration — applies pending SQL migrations to the guild's Books.
|
|
3
|
-
*
|
|
4
|
-
* Core framework migrations ship with the `@shardworks/nexus-core` package
|
|
5
|
-
* and are applied automatically when the Books are opened (unless the guild
|
|
6
|
-
* opts out via `settings.autoMigrate: false` in guild.json).
|
|
7
|
-
*
|
|
8
|
-
* Migrations are numbered sequentially (001-schema.sql, etc.) and applied in
|
|
9
|
-
* order. The module tracks which migrations have been applied in a
|
|
10
|
-
* `_migrations` table and only runs new ones.
|
|
11
|
-
*
|
|
12
|
-
* ## Migration sources
|
|
13
|
-
*
|
|
14
|
-
* 1. **Core migrations** — bundled with nexus-core, define the framework schema.
|
|
15
|
-
* 2. **Guild migrations** — in the guild's `nexus/migrations/` directory, for
|
|
16
|
-
* guild-specific schema extensions delivered by bundles.
|
|
17
|
-
*
|
|
18
|
-
* ## Migration file naming
|
|
19
|
-
*
|
|
20
|
-
* Files must match the pattern: NNN-description.sql
|
|
21
|
-
* where NNN is a zero-padded sequence number.
|
|
22
|
-
*/
|
|
23
|
-
/** A migration file discovered on disk. */
|
|
24
|
-
export interface MigrationFile {
|
|
25
|
-
/** Sequence number (e.g. 1, 2, 3). */
|
|
26
|
-
sequence: number;
|
|
27
|
-
/** Full filename (e.g. '001-initial-schema.sql'). */
|
|
28
|
-
filename: string;
|
|
29
|
-
/** Absolute path to the file. */
|
|
30
|
-
path: string;
|
|
31
|
-
}
|
|
32
|
-
/** Provenance metadata for migrations installed via bundles. */
|
|
33
|
-
export interface MigrationProvenance {
|
|
34
|
-
/** Bundle that delivered this migration (e.g. "@shardworks/guild-starter-kit@0.1.5"). */
|
|
35
|
-
bundle: string;
|
|
36
|
-
/** Original filename in the bundle before renumbering (e.g. "001-initial-schema.sql"). */
|
|
37
|
-
originalName: string;
|
|
38
|
-
}
|
|
39
|
-
/** Result of applying migrations. */
|
|
40
|
-
export interface MigrateResult {
|
|
41
|
-
/** Migrations that were applied in this run. */
|
|
42
|
-
applied: string[];
|
|
43
|
-
/** Migrations that were already applied (skipped). */
|
|
44
|
-
skipped: string[];
|
|
45
|
-
/** Total number of migrations on disk. */
|
|
46
|
-
total: number;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Discover migration files in a directory, sorted by sequence.
|
|
50
|
-
*/
|
|
51
|
-
export declare function discoverMigrations(migrationsDir: string): MigrationFile[];
|
|
52
|
-
/**
|
|
53
|
-
* Apply pending core framework migrations to the guild's Books.
|
|
54
|
-
*
|
|
55
|
-
* Core migrations are bundled with the nexus-core package and define
|
|
56
|
-
* the framework's required schema (sessions, writs, events, etc.).
|
|
57
|
-
*
|
|
58
|
-
* @param home - Absolute path to the guild root.
|
|
59
|
-
* @returns Summary of what was applied and skipped.
|
|
60
|
-
*/
|
|
61
|
-
export declare function applyCoreMigrations(home: string): MigrateResult;
|
|
62
|
-
/**
|
|
63
|
-
* Apply pending guild-local migrations to the guild's Books.
|
|
64
|
-
*
|
|
65
|
-
* Guild-local migrations live in `nexus/migrations/` within the guild
|
|
66
|
-
* directory and are delivered by bundles for guild-specific schema extensions.
|
|
67
|
-
*
|
|
68
|
-
* @param home - Absolute path to the guild root.
|
|
69
|
-
* @param provenance - Optional map of guild filename → bundle provenance.
|
|
70
|
-
* @returns Summary of what was applied and skipped.
|
|
71
|
-
*/
|
|
72
|
-
export declare function applyMigrations(home: string, provenance?: Record<string, MigrationProvenance>): MigrateResult;
|
|
73
|
-
/**
|
|
74
|
-
* Ensure the guild's Books database has all pending core migrations applied.
|
|
75
|
-
*
|
|
76
|
-
* Called automatically before database access. Reads `settings.autoMigrate`
|
|
77
|
-
* from guild.json (defaults to `true`). Skips if auto-migration is disabled
|
|
78
|
-
* or if this guild was already migrated in the current process.
|
|
79
|
-
*
|
|
80
|
-
* @param home - Absolute path to the guild root.
|
|
81
|
-
* @returns The migrations that were applied, or null if skipped.
|
|
82
|
-
*/
|
|
83
|
-
export declare function ensureBooks(home: string): MigrateResult | null;
|
|
84
|
-
//# sourceMappingURL=migrate.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../../src/legacy/1/migrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AASH,2CAA2C;AAC3C,MAAM,WAAW,aAAa;IAC5B,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,QAAQ,EAAE,MAAM,CAAC;IACjB,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,gEAAgE;AAChE,MAAM,WAAW,mBAAmB;IAClC,yFAAyF;IACzF,MAAM,EAAE,MAAM,CAAC;IACf,0FAA0F;IAC1F,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,qCAAqC;AACrC,MAAM,WAAW,aAAa;IAC5B,gDAAgD;IAChD,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,sDAAsD;IACtD,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;CACf;AAuDD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,GAAG,aAAa,EAAE,CAoBzE;AAmED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAmB/D;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,GAC/C,aAAa,CAqBf;AAOD;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAsB9D"}
|