@dsh-agentic-roleplay/core 0.8.2 → 0.9.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.
Files changed (40) hide show
  1. package/lib/{authoring-tools-BgmC2oqU.js → authoring-tools-CdHlvx32.js} +1909 -53
  2. package/lib/authoring.js +135 -32
  3. package/lib/client.js +347 -347
  4. package/lib/doctor.js +1 -1
  5. package/lib/{gallery-D1V4h8vh.js → gallery-BKh7eu80.js} +2 -2
  6. package/lib/{generator-CLPosooC.js → generator-DdZ1-sgv.js} +2 -2
  7. package/lib/{hooks-rQTTeOC4.js → hooks-CcQj_dJo.js} +2 -2
  8. package/lib/images.js +4 -4
  9. package/lib/index.js +14 -14
  10. package/lib/{library-Dfu0dgRj.js → library-QFL6Z_Nr.js} +2 -2
  11. package/lib/{lorebook-author-tools-BAaAqZZm.js → lorebook-author-tools-DWBnYo1E.js} +6 -6
  12. package/lib/lorebook-authoring.js +4 -4
  13. package/lib/orchestration.js +8 -8
  14. package/lib/{pack-jail-CN-314ln.js → pack-jail-BMy6NcCY.js} +21 -723
  15. package/lib/{packs-DIj5BEfq.js → packs-BREPSfHy.js} +2 -2
  16. package/lib/{presenter-agent-DR0KvLE0.js → presenter-agent-B49-_iUm.js} +4 -4
  17. package/lib/{preset-CscHj1-Y.js → preset-BqgY1Tz4.js} +3 -3
  18. package/lib/{preset-author-tools-CxluF8qc.js → preset-author-tools-BB_Dcv2o.js} +6 -6
  19. package/lib/preset-authoring.js +5 -5
  20. package/lib/{presets-HB8kJTaE.js → presets-Bwnrx7p0.js} +22 -11
  21. package/lib/{reflection-Dg1xtOTW.js → reflection-CUWG-6Qg.js} +6 -6
  22. package/lib/{text-DyRN4nDP.js → text-CbGQhK1-.js} +4 -3
  23. package/lib/{turn-guard-g_hDn0jR.js → turn-guard-Bb8Ew-1z.js} +2 -2
  24. package/package.json +2 -2
  25. package/prompts/en/checks/decide-sheet.md +1 -0
  26. package/prompts/en/checks/fidelity.md +7 -0
  27. package/prompts/en/checks/gaps.md +4 -0
  28. package/prompts/en/checks/notice.md +3 -0
  29. package/prompts/en/import/finish-draft.md +1 -1
  30. package/prompts/en/import/finish-ok.md +3 -1
  31. package/prompts/en/import/notice-repair.md +2 -2
  32. package/prompts/en/import/repair-again.md +2 -2
  33. package/prompts/zh/checks/decide-sheet.md +1 -0
  34. package/prompts/zh/checks/fidelity.md +7 -0
  35. package/prompts/zh/checks/gaps.md +4 -0
  36. package/prompts/zh/checks/notice.md +3 -0
  37. package/prompts/zh/import/finish-draft.md +1 -1
  38. package/prompts/zh/import/finish-ok.md +3 -1
  39. package/prompts/zh/import/notice-repair.md +2 -2
  40. package/prompts/zh/import/repair-again.md +2 -2
package/lib/authoring.js CHANGED
@@ -1,10 +1,10 @@
1
- import { Q as checkWorld, R as parseWorldInfoEdit, Vt as authoredWorldOf, a as importHooks, h as editsSince, l as isReviewing, n as limitAuthoringAgents, o as importTools } from "./authoring-tools-BgmC2oqU.js";
2
- import { t as guardAuthoringTurns } from "./turn-guard-g_hDn0jR.js";
3
- import { $ as matchPieces, B as readWorldInfo, C as readWorldEditor, F as loadWorldParts, H as translateTools, K as finishUpdate, M as deleteTriggerDocument, N as readTriggerDocuments, P as writeTriggerDocument, Q as diffText, R as presetTools, Z as cardChanges, _ as editWorldPlots, a as deleteWorldPackFile, c as createAuthoredEntity, d as replaceAuthoredEntity, et as worldFieldChanges, i as checkWorldPack, l as deleteAuthoredEntity, nt as entitiesByPiece, o as listWorldPacks, q as pendingUpdate, r as registerPackJail, rt as readSource, s as AUTHORED_ENTITY_KINDS, tt as cardTools, u as readAuthoredEntityDocument, v as editWorldRelation, z as editWorldInfo } from "./pack-jail-CN-314ln.js";
4
- import { Et as InvalidEditProblems, G as listWorldPrompts, K as readWorldPrompt, Q as IMPORT_FOLDER, U as PROSE_PROMPTS, W as deleteWorldPrompt, jt as parseRelationEdit, q as writeWorldPrompt } from "./presets-HB8kJTaE.js";
5
- import { i as translator, r as languageOf } from "./text-DyRN4nDP.js";
6
- import { J as formatIssue, V as parsePlotsFile, at as shippedPromptsDirectory } from "./hooks-rQTTeOC4.js";
7
- import { g as SURFACE_NAMES, m as PACK_LIMITS, p as PACK_ACTIONS } from "./packs-DIj5BEfq.js";
1
+ import { A as cardTools, C as worldFieldChanges, E as loadCardEvidence, F as editsSince, M as readSource, N as CHECK_COMMANDS, S as matchPieces, T as loadWorldParts, _ as runChecks, a as importHooks, b as cardChanges, g as CHECKS, h as presentReport, ht as checkWorld, i as contextOf, in as authoredWorldOf, j as entitiesByPiece, l as isReviewing, m as checkImported, n as limitAuthoringAgents, o as importTools, tt as parseWorldInfoEdit, v as editWorldInfo, x as diffText, y as readWorldInfo } from "./authoring-tools-CdHlvx32.js";
2
+ import { t as guardAuthoringTurns } from "./turn-guard-Bb8Ew-1z.js";
3
+ import { C as readWorldEditor, L as presetTools, M as deleteTriggerDocument, N as readTriggerDocuments, P as writeTriggerDocument, U as finishUpdate, W as pendingUpdate, _ as editWorldPlots, a as deleteWorldPackFile, c as createAuthoredEntity, d as replaceAuthoredEntity, i as checkWorldPack, l as deleteAuthoredEntity, o as listWorldPacks, r as registerPackJail, s as AUTHORED_ENTITY_KINDS, u as readAuthoredEntityDocument, v as editWorldRelation, z as translateTools } from "./pack-jail-BMy6NcCY.js";
4
+ import { Dt as InvalidEditProblems, G as listWorldPrompts, K as readWorldPrompt, Mt as parseRelationEdit, Q as IMPORT_FOLDER, U as PROSE_PROMPTS, W as deleteWorldPrompt, ct as parseAuthoringCommand, q as writeWorldPrompt } from "./presets-Bwnrx7p0.js";
5
+ import { i as translator, r as languageOf } from "./text-CbGQhK1-.js";
6
+ import { J as formatIssue, V as parsePlotsFile, at as shippedPromptsDirectory } from "./hooks-CcQj_dJo.js";
7
+ import { g as SURFACE_NAMES, m as PACK_LIMITS, p as PACK_ACTIONS } from "./packs-BREPSfHy.js";
8
8
  import "./access-CfQWbNZP.js";
9
9
  import { join, relative } from "node:path";
10
10
  import { readFile, readdir } from "node:fs/promises";
@@ -12,13 +12,13 @@ import { createUserMessage } from "@deepseek-ai/dsh-llm";
12
12
  import { defineTool } from "@deepseek-ai/dsh-tools";
13
13
  import { isDeepStrictEqual } from "node:util";
14
14
  // src/host/authoring/read-tools.ts
15
- const output$4 = (value) => [{
15
+ const output$5 = (value) => [{
16
16
  type: "text",
17
17
  text: JSON.stringify(value, null, 2)
18
18
  }];
19
19
  const jsonOutput$3 = {
20
20
  schema: { type: "json" },
21
- render: (_args, value) => output$4(value)
21
+ render: (_args, value) => output$5(value)
22
22
  };
23
23
  const keyParameter$1 = {
24
24
  type: "string",
@@ -119,16 +119,6 @@ function authoredWorldReadTools(reader) {
119
119
  return json$1(await readWorldInfo((await reader.read(exec)).record.directory));
120
120
  }
121
121
  }),
122
- defineTool({
123
- name: "world_check",
124
- description: "Check the world as starting a story from it would: every file reads and everything that refers to something refers to something that is there. It names the problems of the first part of the world that has any (characters, factions, places, calendar, dice, items, lore, tracked values, triggers, plots), so run it again after fixing them to see whether another part has some. Run it before you say a world is done.",
125
- parameters: {},
126
- output: jsonOutput$3,
127
- isConcurrencySafe: () => true,
128
- async execute(_args, exec) {
129
- return json$1(await checkWorld((await reader.read(exec)).record));
130
- }
131
- }),
132
122
  listTool(reader, "list_characters", "List authored characters with stable keys and concise identifying information.", (world) => world.characters, (entry) => ({
133
123
  key: entry.key,
134
124
  name: entry.name,
@@ -263,13 +253,13 @@ function authoredWorldReadTools(reader) {
263
253
  }
264
254
  // src/host/authoring/pack-tools.ts
265
255
  const PACK_MUTATION_TOOLS = ["delete_world_pack_file"];
266
- const output$3 = (value) => [{
256
+ const output$4 = (value) => [{
267
257
  type: "text",
268
258
  text: JSON.stringify(value, null, 2)
269
259
  }];
270
260
  const jsonOutput$2 = {
271
261
  schema: { type: "json" },
272
- render: (_args, value) => output$3(value)
262
+ render: (_args, value) => output$4(value)
273
263
  };
274
264
  /** A path as the file tools take it: relative to the chat's folder when it has one, which is short and hard to mistype. */
275
265
  function relativeTo(exec, path) {
@@ -371,13 +361,13 @@ function worldPackTools(reader) {
371
361
  }
372
362
  // src/host/authoring/prompt-tools.ts
373
363
  const PROMPT_MUTATION_TOOLS = ["write_world_prompt", "delete_world_prompt"];
374
- const output$2 = (value) => [{
364
+ const output$3 = (value) => [{
375
365
  type: "text",
376
366
  text: JSON.stringify(value, null, 2)
377
367
  }];
378
368
  const jsonOutput$1 = {
379
369
  schema: { type: "json" },
380
- render: (_args, value) => output$2(value)
370
+ render: (_args, value) => output$3(value)
381
371
  };
382
372
  const idParameter = {
383
373
  type: "string",
@@ -532,13 +522,13 @@ function plain(value, max = 220) {
532
522
  };
533
523
  }
534
524
  // src/host/authoring/write-tools.ts
535
- const output$1 = (value) => [{
525
+ const output$2 = (value) => [{
536
526
  type: "text",
537
527
  text: JSON.stringify(value, null, 2)
538
528
  }];
539
529
  const jsonOutput = {
540
530
  schema: { type: "json" },
541
- render: (_args, value) => output$1(value)
531
+ render: (_args, value) => output$2(value)
542
532
  };
543
533
  const kindParameter = {
544
534
  type: "string",
@@ -598,7 +588,7 @@ function plotDocument(value) {
598
588
  if (!parsed.ok) throw new InvalidEditProblems(parsed.issues.map(formatIssue));
599
589
  return parsed.value[0];
600
590
  }
601
- /** The most problems a write reports back; `world_check` lists the rest. */
591
+ /** The most problems a write reports back; `check_world` lists the rest. */
602
592
  const REPORTED_PROBLEMS = 8;
603
593
  /**
604
594
  * A write is allowed to leave the world unfinished (a character first, its place next), so the check is advice, not a refusal: the assistant sees at once what its edit
@@ -615,16 +605,16 @@ function withWorldCheck(reader, tool) {
615
605
  const check = await checkWorld(record);
616
606
  if (check.ok) return {
617
607
  ...done,
618
- world_check: "ok: a story could start from this world"
608
+ check_world: "ok: a story could start from this world"
619
609
  };
620
610
  const shown = check.problems.slice(0, REPORTED_PROBLEMS).map((problem) => `${problem.where}: ${problem.message}`);
621
611
  return {
622
612
  ...done,
623
- world_check: {
613
+ check_world: {
624
614
  ok: false,
625
615
  still_open: shown,
626
616
  more: check.problems.length - shown.length + check.more,
627
- note: "Not an error of this edit; fix what the world still needs before the end of the turn (world_check lists all)."
617
+ note: "Not an error of this edit; fix what the world still needs before the end of the turn (check_world lists all)."
628
618
  }
629
619
  };
630
620
  }
@@ -931,7 +921,7 @@ async function loreTitles(directory) {
931
921
  }
932
922
  return titles;
933
923
  }
934
- const output = {
924
+ const output$1 = {
935
925
  schema: { type: "json" },
936
926
  render: (_args, value) => [{
937
927
  type: "text",
@@ -956,7 +946,7 @@ function updateTools(worlds) {
956
946
  name: "card_diff",
957
947
  description: "What a newer version of the card this world was imported from changes. For each piece (field, greeting, lorebook entry) that changed, was added or was dropped: the sentences that differ, and the characters, places and things the import made from it, which are what may need to change. Also the files of the world that were edited since the import, and what the newer version changes about the card itself. Start here when asked to update the world from its card; read whole pieces with card_read (version current or new).",
958
948
  parameters: {},
959
- output,
949
+ output: output$1,
960
950
  isConcurrencySafe: () => true,
961
951
  async execute(_args, exec) {
962
952
  const directory = await worldOf(exec);
@@ -1026,12 +1016,14 @@ function updateTools(worlds) {
1026
1016
  name: "card_update_finish",
1027
1017
  description: `Makes the newer card the card this world was made from, once the world has been brought up to date with it: the old card is kept in ${IMPORT_FOLDER}/previous, and what the world holds now is what later edits are measured against. Run it after your edits, and only then.`,
1028
1018
  parameters: {},
1029
- output,
1019
+ output: output$1,
1030
1020
  async execute(_args, exec) {
1031
1021
  const directory = await worldOf(exec);
1032
1022
  const outcome = await finishUpdate(directory, exec.signal === void 0 ? {} : { signal: exec.signal });
1023
+ const checks = await checkImported(directory, (await readWorldInfo(directory)).name);
1033
1024
  return json({
1034
1025
  done: true,
1026
+ checks,
1035
1027
  card: `${IMPORT_FOLDER}/card.json`,
1036
1028
  previous: join(IMPORT_FOLDER, "previous"),
1037
1029
  forgottenRecords: outcome.forgotten,
@@ -1099,6 +1091,112 @@ function updateHooks(ctx, worlds, languageOf$1) {
1099
1091
  }));
1100
1092
  });
1101
1093
  }
1094
+ // src/host/checks/tools.ts
1095
+ const output = {
1096
+ schema: { type: "json" },
1097
+ render: (_args, value) => [{
1098
+ type: "text",
1099
+ text: JSON.stringify(value, null, 2)
1100
+ }]
1101
+ };
1102
+ const deepParameter = {
1103
+ type: "boolean",
1104
+ description: "Also run the checks a model judges (slower, one or more model requests each). Leave it off for a quick look; turn it on when the quick checks leave the world looking thin, when the person asks for a thorough check, or before you say an import is done."
1105
+ };
1106
+ function kitTool(reader, judging, name, kit, description, card = false) {
1107
+ return defineTool({
1108
+ name,
1109
+ description,
1110
+ parameters: {
1111
+ ...card ? { version: {
1112
+ type: "string",
1113
+ enum: ["current", "new"],
1114
+ description: "current (the default) is the card the world was made from; new is the newer version waiting to update it."
1115
+ } } : {},
1116
+ deep: deepParameter
1117
+ },
1118
+ output,
1119
+ isConcurrencySafe: () => false,
1120
+ async execute(args, exec) {
1121
+ const { record } = await reader.read(exec);
1122
+ const version = args.version === "new" ? "new" : "current";
1123
+ const evidence = card ? await loadCardEvidence(record.directory, version) : void 0;
1124
+ if (card && evidence === void 0) throw new Error(version === "new" ? "no newer version of the card is waiting to update this world" : "this world has no source card: it was not imported from one, or its .import folder was removed");
1125
+ const language = judging.prompting.languages().get(record.summary.id);
1126
+ const text = (id, variables) => judging.prompting.prompts().text(id, language, variables);
1127
+ const model = args.deep === true ? contextOf(exec, judging.settings(), text, language) : void 0;
1128
+ const report = await runChecks({
1129
+ world: record,
1130
+ ...evidence === void 0 ? {} : { card: evidence },
1131
+ ...model === void 0 ? {} : { model }
1132
+ }, {
1133
+ kits: [kit],
1134
+ deep: args.deep === true
1135
+ });
1136
+ return JSON.parse(JSON.stringify(presentReport(report)));
1137
+ }
1138
+ });
1139
+ }
1140
+ /** The checks of the suite as tools of a world authoring chat; each kit is one call, and what it finds is stored with the world for the next run to compare with. */
1141
+ function checkTools(reader, judging) {
1142
+ return [
1143
+ kitTool(reader, judging, "check_world", "consistency", "Check the world for inconsistencies: whether a story could start from it (every file reads and everything that refers to something refers to something that is there; it names the problems of the first part of the world that has any, so run it again after fixing them), places no one can reach, names that clash, tracked values that are the same thing twice, and prompts the story could not use. Run it before you say a world is done. It reads only; each finding says where it is and, when clear, what would fix it."),
1144
+ kitTool(reader, judging, "check_card", "fidelity", "Compare the world with the card it was imported from, which is kept: whether every piece of the card the import read is in the world, whether every name in the world occurs in the card, whether the numbers the card gives were kept, and, with version new, what a newer card waiting to update the world changed that the world does not say yet. With deep, a model also compares each document with the pieces it was made from and quotes the facts that were lost or made up. A finding is a pointer: read the piece with card_read before you change anything. It reads only.", true),
1145
+ kitTool(reader, judging, "check_quality", "quality", "Check the authoring quality of the world: whether someone can be played, whether the characters that matter have sheets to play from, places with nothing in them, what the world says about itself. With deep, a model also judges whether each sheet is enough to play and what the world is missing to play well. It reads only; a finding is a gap to fill from what the card or the person says, never from invention."),
1146
+ defineTool({
1147
+ name: "check_list",
1148
+ description: "List the checks of the suite: which kit each belongs to, whether the program or a model decides it, and what it needs.",
1149
+ parameters: {},
1150
+ output,
1151
+ isConcurrencySafe: () => true,
1152
+ async execute() {
1153
+ return JSON.parse(JSON.stringify(CHECKS.map((check) => ({
1154
+ id: check.id,
1155
+ kit: check.kit,
1156
+ mode: check.mode,
1157
+ needs: check.needs,
1158
+ description: check.description
1159
+ }))));
1160
+ }
1161
+ })
1162
+ ];
1163
+ }
1164
+ // src/host/checks/hooks.ts
1165
+ /** The tool each kit is run with, for the notice of a check command. */
1166
+ const KIT_TOOLS = {
1167
+ consistency: "check_world",
1168
+ fidelity: "check_card",
1169
+ quality: "check_quality"
1170
+ };
1171
+ /** Hears the check commands (`/check`, `/check-world`) in an authoring chat and tells the assistant to run those kits and what to do with what they find. */
1172
+ function checkHooks(ctx, prompting) {
1173
+ const authoring = (agent) => agent.session.header.origin === "subagent" || authoredWorldOf(agent.session.id) === void 0 ? void 0 : agent.session.id;
1174
+ ctx.on("agent/pre-step", async (payload, next) => {
1175
+ const decision = await next();
1176
+ const chat = authoring(payload.agent);
1177
+ if (decision.kind !== "enter" || payload.step !== 1 || chat === void 0) return decision;
1178
+ const text = payload.messages.filter((message) => message.source.kind === "user").flatMap((message) => message.content.flatMap((block) => block.type === "text" ? [block.text] : [])).join("\n");
1179
+ const command = parseAuthoringCommand(text, Object.keys(CHECK_COMMANDS));
1180
+ if (command === void 0) return decision;
1181
+ const world = authoredWorldOf(chat);
1182
+ const tools = CHECK_COMMANDS[command.name].map((kit) => KIT_TOOLS[kit]).join(", ");
1183
+ const notice = prompting.prompts().text("checks/notice", world === void 0 ? void 0 : prompting.languages().get(world), {
1184
+ command: `/${command.name}`,
1185
+ tools,
1186
+ request: command.rest === "" ? "-" : command.rest
1187
+ });
1188
+ return {
1189
+ ...decision,
1190
+ messages: [...decision.messages, createUserMessage({
1191
+ content: [{
1192
+ type: "text",
1193
+ text: notice
1194
+ }],
1195
+ source: { kind: "roleplay" }
1196
+ })]
1197
+ };
1198
+ });
1199
+ }
1102
1200
  // src/authoring.ts
1103
1201
  const name = "@dsh-agentic-roleplay/core/authoring";
1104
1202
  const inject = [
@@ -1130,7 +1228,12 @@ function apply(ctx) {
1130
1228
  for (const tool of updateTools(ctx.roleplayWorlds)) ctx.tools.register(tool);
1131
1229
  for (const tool of presetTools(ctx.roleplayWorlds, () => ctx.roleplayImport.settings, prompting)) ctx.tools.register(tool);
1132
1230
  for (const tool of translateTools(ctx.roleplayWorlds, () => ctx.roleplayImport.settings, prompting)) ctx.tools.register(tool);
1231
+ for (const tool of checkTools(reader, {
1232
+ settings: () => ctx.roleplayImport.settings,
1233
+ prompting
1234
+ })) ctx.tools.register(tool);
1133
1235
  importHooks(ctx, ctx.roleplayWorlds, prompting);
1236
+ checkHooks(ctx, prompting);
1134
1237
  updateHooks(ctx, ctx.roleplayWorlds, (world) => ctx.roleplayAuthoringLanguages.get(world));
1135
1238
  const reviewing = async (chat) => {
1136
1239
  const id = authoredWorldOf(chat);