@dsh-agentic-roleplay/core 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/{access-CXtaZNbx.js → access-DAw54-NI.js} +6 -15
- package/lib/{authoring-tools--6V1pIIL.js → authoring-tools-4NgDhIJV.js} +116 -13
- package/lib/authoring.js +38 -8
- package/lib/{child-C9nPIy9j.js → child-D3QUNb3m.js} +121 -2
- package/lib/client.js +1389 -475
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +3 -3
- package/lib/doctor.js +3 -3
- package/lib/{gallery-CtG-bDzz.js → gallery-Ct6nm4UQ.js} +3 -3
- package/lib/{generator-nLoPM5MF.js → generator-CI8fOnXy.js} +9 -3
- package/lib/helper.js +22 -1
- package/lib/{hooks-DORky4KT.js → hooks-BNeoGMHZ.js} +1342 -293
- package/lib/images.js +4 -4
- package/lib/index.js +444 -24
- package/lib/jail-BIF79PJO.js +107 -0
- package/lib/{library-CH-ahlm0.js → library-BF9ZMSFz.js} +3 -3
- package/lib/{lorebook-author-tools-BrVde1N-.js → lorebook-author-tools-DBk-V0hp.js} +7 -7
- package/lib/lorebook-authoring.js +4 -4
- package/lib/{narration-B0hConSw.js → narration-xvErE2yp.js} +34 -3
- package/lib/orchestration.js +915 -59
- package/lib/{pack-jail-Bk82pX9t.js → pack-jail-C8EyX9Ix.js} +18 -14
- package/lib/{packs-ELfh8yh1.js → packs-S0SzrVv-.js} +2 -2
- package/lib/{presenter-agent-UKbKYXMO.js → presenter-agent-Bc478nTA.js} +11 -8
- package/lib/{preset-D9Sfc8sf.js → preset-SJZyw0kt.js} +4 -4
- package/lib/{preset-author-tools-B3pFL1-e.js → preset-author-tools-CzogjK42.js} +7 -7
- package/lib/preset-authoring.js +5 -5
- package/lib/{presets-BRt4Xsy4.js → presets-DQ5rioMh.js} +251 -49
- package/lib/{reflection-CHiHsY4Y.js → reflection-buQiSdvq.js} +17 -609
- package/lib/service-mRKwpWjX.js +140 -0
- package/lib/{text-CzqhC8sT.js → text-Dfv8S8eq.js} +36 -2
- package/lib/{turn-guard-B53qOWEU.js → turn-guard-BSAba8sp.js} +3 -3
- package/package.json +3 -3
- package/prompts/en/import/finish-ok.md +1 -1
- package/prompts/en/import/generator.md +1 -1
- package/prompts/en/import/style.md +1 -1
- package/prompts/en/import/variables.md +3 -1
- package/prompts/en/roleplay/character-decide.md +1 -1
- package/prompts/en/roleplay/character-lookup.md +1 -1
- package/prompts/en/roleplay/decide-errand.md +1 -0
- package/prompts/en/roleplay/decide-message.md +1 -0
- package/prompts/en/roleplay/decide-reuse.md +3 -0
- package/prompts/en/roleplay/decide-variable.md +1 -0
- package/prompts/en/roleplay/dream.md +1 -0
- package/prompts/en/roleplay/gate-repeat.md +1 -0
- package/prompts/en/roleplay/image-presenter.md +1 -0
- package/prompts/en/roleplay/track-values.md +1 -0
- package/prompts/en/roleplay/track-variables.md +1 -0
- package/prompts/zh/import/finish-ok.md +1 -1
- package/prompts/zh/import/generator.md +1 -1
- package/prompts/zh/import/style.md +1 -1
- package/prompts/zh/import/variables.md +3 -1
- package/prompts/zh/roleplay/character-decide.md +1 -1
- package/prompts/zh/roleplay/character-lookup.md +1 -1
- package/prompts/zh/roleplay/decide-errand.md +1 -0
- package/prompts/zh/roleplay/decide-message.md +1 -0
- package/prompts/zh/roleplay/decide-reuse.md +3 -0
- package/prompts/zh/roleplay/decide-variable.md +1 -0
- package/prompts/zh/roleplay/dream.md +1 -0
- package/prompts/zh/roleplay/gate-repeat.md +1 -0
- package/prompts/zh/roleplay/image-presenter.md +1 -0
- package/prompts/zh/roleplay/track-values.md +1 -0
- package/prompts/zh/roleplay/track-variables.md +1 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { j as roleplaySessionOf } from "./child-D3QUNb3m.js";
|
|
2
|
+
import { i as isInside } from "./service-mRKwpWjX.js";
|
|
3
|
+
import { dirname, isAbsolute, resolve } from "node:path";
|
|
4
|
+
import { readdirSync, realpathSync, statSync } from "node:fs";
|
|
5
|
+
// src/host/workspace/jail.ts
|
|
6
|
+
/** DSH's file tools whose path is a `file_path` argument, and those that search under a `path`. */
|
|
7
|
+
const FILE_TOOLS = [
|
|
8
|
+
"read",
|
|
9
|
+
"read_image",
|
|
10
|
+
"write",
|
|
11
|
+
"edit"
|
|
12
|
+
];
|
|
13
|
+
const SEARCH_TOOLS = ["glob", "grep"];
|
|
14
|
+
const WRITING = ["write", "edit"];
|
|
15
|
+
const PATCHING = "apply_patch";
|
|
16
|
+
const PATCH_FILES = /^\*\*\* (?:Add|Update|Delete) File: (.+)$|^\*\*\* Move to: (.+)$/gmu;
|
|
17
|
+
/** The real path of a file that may not exist yet: the nearest folder above it that does, followed through links, with the rest put back. */
|
|
18
|
+
function realPathOf(path) {
|
|
19
|
+
const rest = [];
|
|
20
|
+
let current = resolve(path);
|
|
21
|
+
for (;;) try {
|
|
22
|
+
return rest.reduceRight((made, part) => resolve(made, part), realpathSync(current));
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (error.code !== "ENOENT" && error.code !== "ENOTDIR") throw error;
|
|
25
|
+
const up = dirname(current);
|
|
26
|
+
if (up === current) return resolve(path);
|
|
27
|
+
rest.push(current.slice(up.length + 1));
|
|
28
|
+
current = up;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const MOST_LISTED = 30;
|
|
32
|
+
/** Where a model that tried to read a folder is sent: what the folder holds. A bare "not a regular file" made helpers try the same folder twenty times. */
|
|
33
|
+
function folderListing(path) {
|
|
34
|
+
try {
|
|
35
|
+
if (!statSync(path).isDirectory()) return void 0;
|
|
36
|
+
const names = readdirSync(path, { withFileTypes: true }).map((entry) => entry.isDirectory() ? `${entry.name}/` : entry.name).sort();
|
|
37
|
+
const shown = names.slice(0, MOST_LISTED).join(", ");
|
|
38
|
+
return `${path} is a folder, not a file, so it cannot be read. It holds: ${names.length === 0 ? "nothing" : shown}${names.length > MOST_LISTED ? ` and ${names.length - MOST_LISTED} more` : ""}. Read one of those files by its whole path (${path}/<name>)`;
|
|
39
|
+
} catch {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Why a path is out of reach for a story, or nothing when it is inside a folder the story may use (and may write, when it writes). */
|
|
44
|
+
function folderProblem(path, writing, roots, workspace) {
|
|
45
|
+
if (!isAbsolute(path)) return `give the whole path (it is not relative to anything the tools know): the story's workspace is ${workspace}`;
|
|
46
|
+
const real = realPathOf(path);
|
|
47
|
+
const found = roots.filter((root) => isInside(root.path, real));
|
|
48
|
+
if (found.length === 0) return `${path} is outside the folders this story's tools may use: its workspace ${workspace}${roots.length > 1 ? ` and ${roots.filter((root) => root.path !== workspace).map((root) => `${root.path} (${root.write ? "read and write" : "read only"})`).join(", ")}` : ""}. Nothing, not another path and not sandbox_permissions, lifts that: tell the person if it is needed`;
|
|
49
|
+
if (writing && !found.some((root) => root.write)) return `${path} is in a folder this story may only read: tell the person if it should be changed`;
|
|
50
|
+
}
|
|
51
|
+
function patchPaths(patch) {
|
|
52
|
+
return [...patch.matchAll(PATCH_FILES)].map((match) => (match[1] ?? match[2] ?? "").trim()).filter((path) => path !== "");
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Keeps DSH's file tools of a story's agents (the game master and its helpers) inside the story's workspace and the folders the person gave the story.
|
|
56
|
+
* It stands first in the chain, so that what it refuses cannot be let through by a listener after it. Shell and terminal tools are not held to folders:
|
|
57
|
+
* they stay off unless the person turns them on.
|
|
58
|
+
*/
|
|
59
|
+
async function foldersJail(exec, next, deps) {
|
|
60
|
+
const header = exec.agent?.session.header;
|
|
61
|
+
const chat = header?.origin === "subagent" ? header.parentSession : exec.agent?.session.id;
|
|
62
|
+
const session = chat === void 0 ? void 0 : roleplaySessionOf(chat);
|
|
63
|
+
if (session === void 0) return await next();
|
|
64
|
+
const files = FILE_TOOLS.includes(exec.name);
|
|
65
|
+
const search = SEARCH_TOOLS.includes(exec.name);
|
|
66
|
+
if (!files && !search && exec.name !== PATCHING) return await next();
|
|
67
|
+
const roots = await deps.roots(session);
|
|
68
|
+
if (roots === void 0) return await next();
|
|
69
|
+
const args = exec.arguments;
|
|
70
|
+
const check = (paths, writing) => {
|
|
71
|
+
for (const path of paths) {
|
|
72
|
+
if (typeof path !== "string" || path === "" || path.startsWith("~")) return {
|
|
73
|
+
kind: "deny",
|
|
74
|
+
reason: `the path must be a whole path inside the story's workspace ${deps.workspace()} or a folder it was given`
|
|
75
|
+
};
|
|
76
|
+
const problem = folderProblem(path, writing, roots, deps.workspace());
|
|
77
|
+
if (problem !== void 0) return {
|
|
78
|
+
kind: "deny",
|
|
79
|
+
reason: problem
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
if (files) {
|
|
84
|
+
const refused = check([args["file_path"]], WRITING.includes(exec.name));
|
|
85
|
+
if (refused !== void 0) return refused;
|
|
86
|
+
const listing = exec.name === "read" || exec.name === "read_image" ? folderListing(args["file_path"]) : void 0;
|
|
87
|
+
return listing === void 0 ? await next() : {
|
|
88
|
+
kind: "deny",
|
|
89
|
+
reason: listing
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (search) return check([args["path"] ?? deps.workspace()], false) ?? await next();
|
|
93
|
+
const patch = args["patch"] ?? args["input"];
|
|
94
|
+
const paths = typeof patch === "string" ? patchPaths(patch) : [];
|
|
95
|
+
if (paths.length === 0) return {
|
|
96
|
+
kind: "deny",
|
|
97
|
+
reason: "apply_patch must name its files: write them as whole paths inside the story's folders"
|
|
98
|
+
};
|
|
99
|
+
return check(paths, true) ?? await next();
|
|
100
|
+
}
|
|
101
|
+
/** Puts the jail first in the chain of `tools/pre-execute`. */
|
|
102
|
+
function registerFoldersJail(ctx, deps) {
|
|
103
|
+
ctx.on("tools/pre-execute", (exec, next) => foldersJail(exec, next, deps), { prepend: true });
|
|
104
|
+
}
|
|
105
|
+
export { registerFoldersJail as t };
|
|
106
|
+
|
|
107
|
+
//# sourceMappingURL=jail-BIF79PJO.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as atomicWrite } from "./access-
|
|
2
|
-
import { i as translator, n as withoutExtension, r as languageOf, t as trimCharacters } from "./text-
|
|
1
|
+
import { n as atomicWrite } from "./access-DAw54-NI.js";
|
|
2
|
+
import { i as translator, n as withoutExtension, r as languageOf, t as trimCharacters } from "./text-Dfv8S8eq.js";
|
|
3
3
|
import { dirname, extname, join } from "node:path";
|
|
4
4
|
import { existsSync } from "node:fs";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
@@ -374,4 +374,4 @@ async function addToLibrary(sessionFolder, bytes, originalName) {
|
|
|
374
374
|
}
|
|
375
375
|
export { slug as C, norm as S, uniqueKey as T, writeImageFileMetadata as _, LIBRARY_FOLDER as a, NoEmbeddingService as b, nextSceneSerial as c, sceneImagePath as d, writeImage as f, sidecarOf as g, readImageFileMetadata as h, libraryHashes as i, readImageMetadata as l, mediaTypeOf as m, addToLibraryOnce as n, entityImageDirectory as o, MEDIA_TYPES as p, imageExtensionOf as r, inheritImages as s, addToLibrary as t, referenceImagePath as u, readPngMetadata as v, trOf as w, mapLimit as x, withPngMetadata as y };
|
|
376
376
|
|
|
377
|
-
//# sourceMappingURL=library-
|
|
377
|
+
//# sourceMappingURL=library-BF9ZMSFz.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import "./access-
|
|
2
|
-
import { _t as writeLorebookEntry, ct as deleteLorebookEntry, ft as loadLorebook, gt as updateLorebookInfo, i as contextOf, lt as entriesOf, mt as readLorebook$1, pt as lorebookDirectory, r as MAX_PREVIEW_TEXT, tn as ImportCardError } from "./authoring-tools
|
|
3
|
-
import { $ as IMPORT_FOLDER,
|
|
4
|
-
import { C as slug, T as uniqueKey, w as trOf, x as mapLimit } from "./library-
|
|
5
|
-
import { i as translator, r as languageOf } from "./text-
|
|
6
|
-
import {
|
|
1
|
+
import "./access-DAw54-NI.js";
|
|
2
|
+
import { _t as writeLorebookEntry, ct as deleteLorebookEntry, ft as loadLorebook, gt as updateLorebookInfo, i as contextOf, lt as entriesOf, mt as readLorebook$1, pt as lorebookDirectory, r as MAX_PREVIEW_TEXT, tn as ImportCardError } from "./authoring-tools-4NgDhIJV.js";
|
|
3
|
+
import { $ as IMPORT_FOLDER, Bt as LORE_KINDS, Q as withPlayer, Vt as LORE_SCOPES, Y as cleanText, Z as partsOf, n as createPresetFromGuidance } from "./presets-DQ5rioMh.js";
|
|
4
|
+
import { C as slug, T as uniqueKey, w as trOf, x as mapLimit } from "./library-BF9ZMSFz.js";
|
|
5
|
+
import { i as translator, r as languageOf } from "./text-Dfv8S8eq.js";
|
|
6
|
+
import { it as shippedPromptsDirectory } from "./hooks-BNeoGMHZ.js";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { existsSync, readFileSync } from "node:fs";
|
|
9
9
|
import { readFile, rm, writeFile } from "node:fs/promises";
|
|
@@ -696,4 +696,4 @@ async function lorebookApproval(exec, next, state) {
|
|
|
696
696
|
}
|
|
697
697
|
export { lorebookImportMessage as a, readLorebook as c, lorebookOfChat as d, lorebookAuthorTools as i, selectEntries as l, LorebookReader as n, pendingTargets as o, lorebookApproval as r, previewLorebook as s, LOREBOOK_UPLOAD as t, lorebookChatSessionId as u };
|
|
698
698
|
|
|
699
|
-
//# sourceMappingURL=lorebook-author-tools-
|
|
699
|
+
//# sourceMappingURL=lorebook-author-tools-DBk-V0hp.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { n as limitAuthoringAgents, pt as lorebookDirectory } from "./authoring-tools
|
|
2
|
-
import { t as guardAuthoringTurns } from "./turn-guard-
|
|
3
|
-
import { d as lorebookOfChat, i as lorebookAuthorTools, n as LorebookReader, o as pendingTargets, r as lorebookApproval } from "./lorebook-author-tools-
|
|
4
|
-
import "./hooks-
|
|
1
|
+
import { n as limitAuthoringAgents, pt as lorebookDirectory } from "./authoring-tools-4NgDhIJV.js";
|
|
2
|
+
import { t as guardAuthoringTurns } from "./turn-guard-BSAba8sp.js";
|
|
3
|
+
import { d as lorebookOfChat, i as lorebookAuthorTools, n as LorebookReader, o as pendingTargets, r as lorebookApproval } from "./lorebook-author-tools-DBk-V0hp.js";
|
|
4
|
+
import "./hooks-BNeoGMHZ.js";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { existsSync, readdirSync } from "node:fs";
|
|
7
7
|
// src/lorebook-authoring.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as atomicWriteSync } from "./access-
|
|
1
|
+
import { i as atomicWriteSync } from "./access-DAw54-NI.js";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
4
4
|
// ../dsh-roleplay-model/src/clock.ts
|
|
@@ -14,8 +14,13 @@ const DECISION_SITES = [
|
|
|
14
14
|
"reflection",
|
|
15
15
|
"agency",
|
|
16
16
|
"refusal",
|
|
17
|
+
"repeats",
|
|
17
18
|
"rules",
|
|
18
|
-
"secrets"
|
|
19
|
+
"secrets",
|
|
20
|
+
"messages",
|
|
21
|
+
"errands",
|
|
22
|
+
"variables",
|
|
23
|
+
"reuse"
|
|
19
24
|
];
|
|
20
25
|
/** The sites that check what the game master delivers to the player. They are off unless a chat turns one on: a check costs a request, or at least a call, in every turn. */
|
|
21
26
|
const GATE_SITES = ["agency", "refusal"];
|
|
@@ -35,6 +40,12 @@ const DECISION_MODES = [
|
|
|
35
40
|
];
|
|
36
41
|
/** What a gate can be set to: the modes of any site, or off. */
|
|
37
42
|
const GATE_MODES = ["off", ...DECISION_MODES];
|
|
43
|
+
/** What the repeat check can be set to: a gate's modes, or `strict`, which refuses every repeated sentence by code alone, with no model, and so may refuse a repeat that was meant. */
|
|
44
|
+
const REPEAT_MODES = [
|
|
45
|
+
"off",
|
|
46
|
+
"strict",
|
|
47
|
+
...DECISION_MODES
|
|
48
|
+
];
|
|
38
49
|
const emptySiteStats = () => ({
|
|
39
50
|
runs: 0,
|
|
40
51
|
items: 0,
|
|
@@ -134,6 +145,18 @@ const SETTINGS_SPEC = {
|
|
|
134
145
|
joint: flag(true),
|
|
135
146
|
summary: flag(true)
|
|
136
147
|
},
|
|
148
|
+
schedule: { enabled: flag(true) },
|
|
149
|
+
autonomy: {
|
|
150
|
+
enabled: flag(false),
|
|
151
|
+
messages: flag(true),
|
|
152
|
+
maxUnanswered: integer(1, 20, 3),
|
|
153
|
+
idleMinutes: integer(1, 10080, 15),
|
|
154
|
+
awayHours: integer(1, 720, 12),
|
|
155
|
+
chance: ratio(0, 1, .05),
|
|
156
|
+
decay: ratio(0, 1, .5),
|
|
157
|
+
transitionChance: ratio(0, 1, .4),
|
|
158
|
+
messageGapMinutes: integer(5, 10080, 180)
|
|
159
|
+
},
|
|
137
160
|
sampling: {
|
|
138
161
|
master: ratio(0, 2, .7),
|
|
139
162
|
characters: ratio(0, 2, .8),
|
|
@@ -186,9 +209,17 @@ const SETTINGS_SPEC = {
|
|
|
186
209
|
reflection: choice(DECISION_MODES, "llm"),
|
|
187
210
|
agency: choice(GATE_MODES, "off"),
|
|
188
211
|
refusal: choice(GATE_MODES, "off"),
|
|
212
|
+
repeats: choice(REPEAT_MODES, "off"),
|
|
213
|
+
repeatTurns: integer(1, 30, 6),
|
|
214
|
+
repeatChars: integer(6, 60, 12),
|
|
189
215
|
rules: choice(EXTRA_MODES, "off"),
|
|
190
216
|
secrets: choice(EXTRA_MODES, "off"),
|
|
217
|
+
messages: choice(EXTRA_MODES, "off"),
|
|
218
|
+
errands: choice(EXTRA_MODES, "on"),
|
|
219
|
+
variables: choice(GATE_MODES, "llm"),
|
|
220
|
+
reuse: choice(EXTRA_MODES, "off"),
|
|
191
221
|
gateThreshold: ratio(.1, .95, .5),
|
|
222
|
+
reuseThreshold: ratio(.1, .95, .85),
|
|
192
223
|
confidence: ratio(0, 1, .7)
|
|
193
224
|
},
|
|
194
225
|
interface: { pack: text(60, "") },
|
|
@@ -454,4 +485,4 @@ function decodeOutput(text) {
|
|
|
454
485
|
}
|
|
455
486
|
export { emptyStats as _, liveSettings as a, writeSettings as c, parseSettings as d, parseSwitchboard as f, GATE_SITES as g, DECISION_SITES as h, InvalidSettingsError as i, DEFAULT_SETTINGS as l, rulesOf as m, encodeOutput as n, readSettings as o, WORLD_RULES_KEY as p, encodePreview as r, useChildReasoning as s, decodeOutput as t, SETTINGS_SPEC as u };
|
|
456
487
|
|
|
457
|
-
//# sourceMappingURL=narration-
|
|
488
|
+
//# sourceMappingURL=narration-xvErE2yp.js.map
|