@dsh-agentic-roleplay/core 0.12.7 → 0.13.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 (38) hide show
  1. package/lib/{authoring-tools-Bi9YQ9QH.js → authoring-tools-CKV1UnN7.js} +1089 -129
  2. package/lib/authoring.js +130 -37
  3. package/lib/client.js +1251 -662
  4. package/lib/client.js.map +1 -1
  5. package/lib/doctor.js +1 -1
  6. package/lib/{gallery-BT5lf-T5.js → gallery-CT5uj50b.js} +2 -2
  7. package/lib/{hooks-DR-HqE50.js → hooks-CnxV2uEh.js} +43 -16
  8. package/lib/images.js +3 -3
  9. package/lib/index.js +336 -15
  10. package/lib/{interpreter-BYNrjYZo.js → interpreter-Cz5qsuXk.js} +3 -3
  11. package/lib/{lorebook-author-tools-BI-r8fEt.js → lorebook-author-tools-p3Nfpuxh.js} +6 -6
  12. package/lib/lorebook-authoring.js +5 -5
  13. package/lib/orchestration.js +15 -10
  14. package/lib/{pack-jail-Y1XPbqHw.js → pack-jail-KyZen_gy.js} +9 -9
  15. package/lib/{packs-DD-v-Epl.js → packs-DU171pDX.js} +2 -2
  16. package/lib/{presenter-agent-00sOVGI9.js → presenter-agent-CwDg0WE8.js} +2 -2
  17. package/lib/{preset-Bnx3jhUv.js → preset-BO8iWQ-n.js} +3 -3
  18. package/lib/{preset-author-tools-DYrBcieA.js → preset-author-tools-C83shASm.js} +6 -6
  19. package/lib/preset-authoring.js +5 -5
  20. package/lib/{reflection-DqxoV9xE.js → reflection-CXS87Di3.js} +6 -6
  21. package/lib/{serial-CS46qAvI.js → serial-xcAG57p_.js} +148 -38
  22. package/lib/{text-B-HsLdb-.js → text-KnqhN_Zv.js} +4 -1
  23. package/lib/{turn-guard-bZkxzRXJ.js → turn-guard-CfsGepCg.js} +2 -2
  24. package/package.json +2 -2
  25. package/prompts/en/import/next-stage-go.md +1 -0
  26. package/prompts/en/import/next-stage-paused.md +1 -0
  27. package/prompts/en/import/next-survey-paused.md +1 -0
  28. package/prompts/en/import/notice-staged.md +5 -0
  29. package/prompts/en/import/pause-stages.md +1 -0
  30. package/prompts/en/import/pause-survey.md +1 -0
  31. package/prompts/en/world/procedure.md +3 -0
  32. package/prompts/zh/import/next-stage-go.md +1 -0
  33. package/prompts/zh/import/next-stage-paused.md +1 -0
  34. package/prompts/zh/import/next-survey-paused.md +1 -0
  35. package/prompts/zh/import/notice-staged.md +5 -0
  36. package/prompts/zh/import/pause-stages.md +1 -0
  37. package/prompts/zh/import/pause-survey.md +1 -0
  38. package/prompts/zh/world/procedure.md +3 -0
package/lib/authoring.js CHANGED
@@ -1,15 +1,15 @@
1
- import { $ as checkWorld, $t as authoredWorldOf, A as loadWorldParts, At as lettersOf, C as cardChanges, D as worldFieldChanges, E as pictureChange, F as editsSince, Ft as cardTools, It as entitiesByPiece, M as CHECK_COMMANDS, Mt as UPDATE_FOLDER, N as CHECK_COMMAND_DESCRIPTIONS, O as editWorldInfo, Rt as readSource, S as addressChanges, St as DICE_FILE_NAME, T as matchPieces, Tt as CALENDAR_FILE_NAME, b as CHECKS, j as loadCardEvidence, jt as shapeOpening, k as readWorldInfo, kt as loadCharacters, l as importTools, n as limitAuthoringAgents, o as contextOf, p as isReviewing, s as importHooks, u as worldOf, v as checkImported, w as diffText, x as runChecks, y as presentReport, zt as COMMANDS_FILE_NAME } from "./authoring-tools-Bi9YQ9QH.js";
2
- import { t as guardAuthoringTurns } from "./turn-guard-bZkxzRXJ.js";
1
+ import { $ as checkWorld, $t as authoredWorldOf, A as loadWorldParts, At as lettersOf, C as cardChanges, D as worldFieldChanges, E as pictureChange, F as editsSince, Ft as cardTools, It as entitiesByPiece, M as CHECK_COMMANDS, Mt as UPDATE_FOLDER, N as CHECK_COMMAND_DESCRIPTIONS, O as editWorldInfo, Rt as readSource, S as addressChanges, St as DICE_FILE_NAME, T as matchPieces, Tt as CALENDAR_FILE_NAME, b as CHECKS, j as loadCardEvidence, jt as shapeOpening, k as readWorldInfo, kt as loadCharacters, l as importTools, n as limitAuthoringAgents, o as contextOf, p as isReviewing, s as importHooks, u as worldOf, v as checkImported, w as diffText, x as runChecks, y as presentReport, zt as COMMANDS_FILE_NAME } from "./authoring-tools-CKV1UnN7.js";
2
+ import { t as guardAuthoringTurns } from "./turn-guard-CfsGepCg.js";
3
3
  import { n as silenceRuntimeContext, t as silenceHarnessDevContext } from "./dev-context-Cgv_wZbG.js";
4
- import { B as deleteTriggerDocument, D as editWorldPlots, G as parseVariablesEdit, H as writeTriggerDocument, K as parseDiceEdit, M as readWorldEditor, O as editWorldRelation, Q as translateTools, U as parseCalendarEdit, V as readTriggerDocuments, X as presetTools, a as deleteWorldPackFile, c as createAuthoredEntity, d as replaceAuthoredEntity, f as editCalendar, g as editVariables, i as checkWorldPack, l as deleteAuthoredEntity, m as editDice, nt as finishUpdate, o as listWorldPacks, p as editCommands, q as parseCommandsEdit, r as registerPackJail, rt as pendingUpdate, s as AUTHORED_ENTITY_KINDS, u as readAuthoredEntityDocument } from "./pack-jail-Y1XPbqHw.js";
5
- import { Et as IMPORT_FOLDER, F as parseWorldInfoEdit, I as hasSpeech, Pt as InvalidEditProblems, R as partsText, at as writeWorldPrompt, it as readWorldPrompt, kt as PICTURE_FILE, nt as deleteWorldPrompt, qt as VARIABLES_FILE_NAME, rt as listWorldPrompts, tt as PROSE_PROMPTS, zt as parseRelationEdit } from "./serial-CS46qAvI.js";
6
- import { B as parsePlotsFile, at as shippedPromptsDirectory, ht as registerCommands, q as formatIssue } from "./hooks-DR-HqE50.js";
7
- import { i as translator, r as languageOf } from "./text-B-HsLdb-.js";
8
- import { g as SURFACE_NAMES, m as PACK_LIMITS, p as PACK_ACTIONS } from "./packs-DD-v-Epl.js";
4
+ import { B as deleteTriggerDocument, D as editWorldPlots, G as parseVariablesEdit, H as writeTriggerDocument, K as parseDiceEdit, M as readWorldEditor, O as editWorldRelation, Q as translateTools, U as parseCalendarEdit, V as readTriggerDocuments, X as presetTools, a as deleteWorldPackFile, c as createAuthoredEntity, d as replaceAuthoredEntity, f as editCalendar, g as editVariables, i as checkWorldPack, l as deleteAuthoredEntity, m as editDice, nt as finishUpdate, o as listWorldPacks, p as editCommands, q as parseCommandsEdit, r as registerPackJail, rt as pendingUpdate, s as AUTHORED_ENTITY_KINDS, u as readAuthoredEntityDocument } from "./pack-jail-KyZen_gy.js";
5
+ import { Ft as IMPORT_FOLDER, G as hasSpeech, Jt as parseRelationEdit, Rt as PICTURE_FILE, Ut as InvalidEditProblems, W as parseWorldInfoEdit, dt as deleteWorldPrompt, ft as listWorldPrompts, mt as writeWorldPrompt, pt as readWorldPrompt, q as partsText, rn as VARIABLES_FILE_NAME, ut as PROSE_PROMPTS } from "./serial-xcAG57p_.js";
6
+ import { B as parsePlotsFile, J as formatIssue, at as shippedPromptsDirectory, ht as registerCommands } from "./hooks-CnxV2uEh.js";
7
+ import { i as translator, r as languageOf } from "./text-KnqhN_Zv.js";
8
+ import { g as SURFACE_NAMES, m as PACK_LIMITS, p as PACK_ACTIONS } from "./packs-DU171pDX.js";
9
9
  import { u as DEFAULT_SETTINGS } from "./narration-CUZIXzab.js";
10
- import { r as childSampling } from "./child-Bfj7-Iuo.js";
11
- import { a as updateImage, i as listGallery, n as describeGalleryImage } from "./gallery-BT5lf-T5.js";
12
- import { n as interpretImage } from "./interpreter-BYNrjYZo.js";
10
+ import { T as currentTurn, r as childSampling } from "./child-Bfj7-Iuo.js";
11
+ import { a as updateImage, i as listGallery, n as describeGalleryImage } from "./gallery-CT5uj50b.js";
12
+ import { n as interpretImage } from "./interpreter-Cz5qsuXk.js";
13
13
  import "./access-5vtPAT3O.js";
14
14
  import { join, relative } from "node:path";
15
15
  import { createHash } from "node:crypto";
@@ -70,20 +70,20 @@ async function writeWorldFile(world, kind, document, options = {}) {
70
70
  await FILES[kind].write(world, document, options);
71
71
  }
72
72
  // src/host/authoring/read-tools.ts
73
- const output$6 = (value) => [{
73
+ const output$7 = (value) => [{
74
74
  type: "text",
75
75
  text: JSON.stringify(value, null, 2)
76
76
  }];
77
77
  const jsonOutput$4 = {
78
78
  schema: { type: "json" },
79
- render: (_args, value) => output$6(value)
79
+ render: (_args, value) => output$7(value)
80
80
  };
81
81
  const keyParameter$1 = {
82
82
  type: "string",
83
83
  required: true,
84
84
  description: "Stable key shown by the corresponding list tool."
85
85
  };
86
- const json$1 = (value) => JSON.parse(JSON.stringify(value));
86
+ const json$2 = (value) => JSON.parse(JSON.stringify(value));
87
87
  /** Resolves every call from its authoring chat identity, then reads the files afresh. */
88
88
  var AuthoredWorldReader = class {
89
89
  worlds;
@@ -117,7 +117,7 @@ function listTool(reader, name, description, select, summarize) {
117
117
  output: jsonOutput$4,
118
118
  isConcurrencySafe: () => true,
119
119
  async execute(_args, exec) {
120
- return json$1(select((await reader.read(exec)).state).map(summarize));
120
+ return json$2(select((await reader.read(exec)).state).map(summarize));
121
121
  }
122
122
  });
123
123
  }
@@ -131,7 +131,7 @@ function getTool(reader, name, description, select) {
131
131
  async execute(args, exec) {
132
132
  const found = select((await reader.read(exec)).state).find((entry) => entry.key === args.key);
133
133
  if (found === void 0) throw new Error(`there is no ${name.slice(4).replaceAll("_", " ")} with key "${args.key}"`);
134
- return json$1(found);
134
+ return json$2(found);
135
135
  }
136
136
  });
137
137
  }
@@ -147,7 +147,7 @@ function authoredWorldReadTools(reader) {
147
147
  async execute(_args, exec) {
148
148
  const { record, state } = await reader.read(exec);
149
149
  const document = JSON.parse(await readFile(join(record.directory, "world.json"), "utf8"));
150
- return json$1({
150
+ return json$2({
151
151
  id: record.summary.id,
152
152
  name: record.summary.name,
153
153
  description: record.summary.description,
@@ -174,7 +174,7 @@ function authoredWorldReadTools(reader) {
174
174
  output: jsonOutput$4,
175
175
  isConcurrencySafe: () => true,
176
176
  async execute(_args, exec) {
177
- return json$1(await readWorldInfo((await reader.read(exec)).record.directory));
177
+ return json$2(await readWorldInfo((await reader.read(exec)).record.directory));
178
178
  }
179
179
  }),
180
180
  listTool(reader, "list_characters", "List authored characters with stable keys and concise identifying information.", (world) => world.characters, (entry) => ({
@@ -236,7 +236,7 @@ function authoredWorldReadTools(reader) {
236
236
  isConcurrencySafe: () => true,
237
237
  async execute(args, exec) {
238
238
  const { record } = await reader.read(exec);
239
- return json$1(await readAuthoredEntityDocument({
239
+ return json$2(await readAuthoredEntityDocument({
240
240
  id: record.summary.id,
241
241
  directory: record.directory
242
242
  }, args.kind, args.key));
@@ -275,7 +275,7 @@ function authoredWorldReadTools(reader) {
275
275
  const { record } = await reader.read(exec);
276
276
  const found = (await readTriggerDocuments(record.directory)).find((entry) => entry["key"] === args.key);
277
277
  if (found === void 0) throw new Error(`there is no trigger with key "${args.key}"`);
278
- return json$1(found);
278
+ return json$2(found);
279
279
  }
280
280
  }),
281
281
  defineTool({
@@ -291,7 +291,7 @@ function authoredWorldReadTools(reader) {
291
291
  async execute(args, exec) {
292
292
  const { record } = await reader.read(exec);
293
293
  if (!isWorldFileKind(args.kind)) throw new Error(`kind must be one of ${WORLD_FILE_KINDS.join(", ")}`);
294
- return json$1(await readWorldFile(record.directory, args.kind));
294
+ return json$2(await readWorldFile(record.directory, args.kind));
295
295
  }
296
296
  }),
297
297
  defineTool({
@@ -320,7 +320,7 @@ function authoredWorldReadTools(reader) {
320
320
  output: jsonOutput$4,
321
321
  isConcurrencySafe: () => true,
322
322
  async execute(args, exec) {
323
- return json$1((await reader.read(exec)).state.relations.filter((relation) => (args.kind === void 0 || relation.kind === args.kind) && (args.from === void 0 || relation.from.key === args.from) && (args.to === void 0 || relation.to.key === args.to)));
323
+ return json$2((await reader.read(exec)).state.relations.filter((relation) => (args.kind === void 0 || relation.kind === args.kind) && (args.from === void 0 || relation.from.key === args.from) && (args.to === void 0 || relation.to.key === args.to)));
324
324
  }
325
325
  })
326
326
  ];
@@ -347,13 +347,13 @@ async function checkOpeningSpeakers(directory, edit) {
347
347
  }
348
348
  // src/host/authoring/pack-tools.ts
349
349
  const PACK_MUTATION_TOOLS = ["delete_world_pack_file"];
350
- const output$5 = (value) => [{
350
+ const output$6 = (value) => [{
351
351
  type: "text",
352
352
  text: JSON.stringify(value, null, 2)
353
353
  }];
354
354
  const jsonOutput$3 = {
355
355
  schema: { type: "json" },
356
- render: (_args, value) => output$5(value)
356
+ render: (_args, value) => output$6(value)
357
357
  };
358
358
  /** 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. */
359
359
  function relativeTo(exec, path) {
@@ -455,13 +455,13 @@ function worldPackTools(reader) {
455
455
  }
456
456
  // src/host/authoring/prompt-tools.ts
457
457
  const PROMPT_MUTATION_TOOLS = ["write_world_prompt", "delete_world_prompt"];
458
- const output$4 = (value) => [{
458
+ const output$5 = (value) => [{
459
459
  type: "text",
460
460
  text: JSON.stringify(value, null, 2)
461
461
  }];
462
462
  const jsonOutput$2 = {
463
463
  schema: { type: "json" },
464
- render: (_args, value) => output$4(value)
464
+ render: (_args, value) => output$5(value)
465
465
  };
466
466
  const idParameter = {
467
467
  type: "string",
@@ -550,13 +550,13 @@ function worldPromptTools(reader, shipped = shippedPromptsDirectory()) {
550
550
  }
551
551
  // src/host/authoring/image-tools.ts
552
552
  const IMAGE_MUTATION_TOOLS = ["edit_world_image", "describe_world_image"];
553
- const output$3 = (value) => [{
553
+ const output$4 = (value) => [{
554
554
  type: "text",
555
555
  text: JSON.stringify(value, null, 2)
556
556
  }];
557
557
  const jsonOutput$1 = {
558
558
  schema: { type: "json" },
559
- render: (_args, value) => output$3(value)
559
+ render: (_args, value) => output$4(value)
560
560
  };
561
561
  const pathParameter = {
562
562
  type: "string",
@@ -788,13 +788,13 @@ function plain$1(value, max = 220) {
788
788
  };
789
789
  }
790
790
  // src/host/authoring/write-tools.ts
791
- const output$2 = (value) => [{
791
+ const output$3 = (value) => [{
792
792
  type: "text",
793
793
  text: JSON.stringify(value, null, 2)
794
794
  }];
795
795
  const jsonOutput = {
796
796
  schema: { type: "json" },
797
- render: (_args, value) => output$2(value)
797
+ render: (_args, value) => output$3(value)
798
798
  };
799
799
  const kindParameter = {
800
800
  type: "string",
@@ -1318,14 +1318,14 @@ const hashOf = async (file) => await readFile(file).then((bytes) => createHash("
1318
1318
  if (error.code === "ENOENT") return void 0;
1319
1319
  throw error;
1320
1320
  });
1321
- const output$1 = {
1321
+ const output$2 = {
1322
1322
  schema: { type: "json" },
1323
1323
  render: (_args, value) => [{
1324
1324
  type: "text",
1325
1325
  text: JSON.stringify(value, null, 1)
1326
1326
  }]
1327
1327
  };
1328
- const json = (value) => JSON.parse(JSON.stringify(value));
1328
+ const json$1 = (value) => JSON.parse(JSON.stringify(value));
1329
1329
  /**
1330
1330
  * The tools that bring a world up to date with a newer version of the card it was made from. `card_diff` is the starting point: what the card changed, worked out by code,
1331
1331
  * with the import's records of what each piece made and the files the person has edited since; the assistant then edits with its ordinary tools and asks for those edits like any others.
@@ -1343,7 +1343,7 @@ function updateTools(worlds) {
1343
1343
  name: "card_diff",
1344
1344
  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).",
1345
1345
  parameters: {},
1346
- output: output$1,
1346
+ output: output$2,
1347
1347
  isConcurrencySafe: () => true,
1348
1348
  async execute(_args, exec) {
1349
1349
  const directory = await worldOf(exec);
@@ -1383,7 +1383,7 @@ function updateTools(worlds) {
1383
1383
  });
1384
1384
  const edits = await editsSince(directory);
1385
1385
  const picture = pictureChange(await hashOf(join(directory, IMPORT_FOLDER, PICTURE_FILE)), await hashOf(join(directory, IMPORT_FOLDER, UPDATE_FOLDER, PICTURE_FILE)));
1386
- return json({
1386
+ return json$1({
1387
1387
  card: cardChanges(before.card, after.card),
1388
1388
  images: {
1389
1389
  cardPicture: picture,
@@ -1419,12 +1419,12 @@ function updateTools(worlds) {
1419
1419
  name: "card_update_finish",
1420
1420
  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.`,
1421
1421
  parameters: {},
1422
- output: output$1,
1422
+ output: output$2,
1423
1423
  async execute(_args, exec) {
1424
1424
  const directory = await worldOf(exec);
1425
1425
  const outcome = await finishUpdate(directory, exec.signal === void 0 ? {} : { signal: exec.signal });
1426
1426
  const checks = await checkImported(directory, (await readWorldInfo(directory)).name);
1427
- return json({
1427
+ return json$1({
1428
1428
  done: true,
1429
1429
  checks,
1430
1430
  card: `${IMPORT_FOLDER}/card.json`,
@@ -1449,7 +1449,7 @@ const isUpdateRequest = (text) => text.includes("card_diff") && text.includes("c
1449
1449
  * An update turn that stops with the update still waiting is sent back once: models end such a turn on a change they found no place for, and the person then has neither the
1450
1450
  * rest of the update nor a report. A turn that stops again is let go, so a question to the person can still end it.
1451
1451
  */
1452
- function updateHooks(ctx, worlds, languageOf$1) {
1452
+ function updateHooks(ctx, worlds, languageOf$2) {
1453
1453
  const updating = /* @__PURE__ */ new Map();
1454
1454
  const nudges = /* @__PURE__ */ new Map();
1455
1455
  const authoring = (agent) => {
@@ -1484,7 +1484,7 @@ function updateHooks(ctx, worlds, languageOf$1) {
1484
1484
  return;
1485
1485
  }
1486
1486
  nudges.set(here.chat, told + 1);
1487
- const tr = translator(languageOf(languageOf$1(here.world)));
1487
+ const tr = translator(languageOf(languageOf$2(here.world)));
1488
1488
  agent.steer(createUserMessage({
1489
1489
  content: [{
1490
1490
  type: "text",
@@ -1604,6 +1604,97 @@ function openingTools(worlds, settings, prompting) {
1604
1604
  }
1605
1605
  })];
1606
1606
  }
1607
+ // src/host/authoring/checkpoint-tools.ts
1608
+ const output$1 = {
1609
+ schema: { type: "json" },
1610
+ render: (_args, value) => [{
1611
+ type: "text",
1612
+ text: JSON.stringify(value, null, 1)
1613
+ }]
1614
+ };
1615
+ const json = (value) => JSON.parse(JSON.stringify(value));
1616
+ const checkpointParameter = {
1617
+ type: "string",
1618
+ required: true,
1619
+ description: "A checkpoint id from list_world_checkpoints."
1620
+ };
1621
+ /**
1622
+ * Read-only access to the checkpoints of the world being authored: when each was made, what has changed in the world since, and a file as the checkpoint has it. Putting a file back is
1623
+ * done with the ordinary editing tools from what is read here; restoring the whole world is the person's.
1624
+ */
1625
+ function checkpointTools(worlds, checkpoints) {
1626
+ return [
1627
+ defineTool({
1628
+ name: "list_world_checkpoints",
1629
+ description: "The checkpoints of this world, newest first: a copy of its files taken before the edits of a turn, or on the person's request. Use one to see what a turn changed or to take back part of it.",
1630
+ parameters: {},
1631
+ output: output$1,
1632
+ isConcurrencySafe: () => true,
1633
+ async execute(_args, exec) {
1634
+ return json({ checkpoints: await checkpoints().list((await worldOf(worlds, exec)).id) });
1635
+ }
1636
+ }),
1637
+ defineTool({
1638
+ name: "diff_world_checkpoint",
1639
+ description: "Which files of the world differ from a checkpoint: changed, added since and removed since. Paths only; read a file with read_world_checkpoint_file.",
1640
+ parameters: { checkpoint: checkpointParameter },
1641
+ output: output$1,
1642
+ isConcurrencySafe: () => true,
1643
+ async execute(args, exec) {
1644
+ return json(await checkpoints().diff((await worldOf(worlds, exec)).id, args.checkpoint));
1645
+ }
1646
+ }),
1647
+ defineTool({
1648
+ name: "read_world_checkpoint_file",
1649
+ description: "One file of the world as a checkpoint has it (a path from diff_world_checkpoint, such as characters/<id>/character.json). Long files are cut and say so. To take a change back, write what you read here with the editing tools.",
1650
+ parameters: {
1651
+ checkpoint: checkpointParameter,
1652
+ path: {
1653
+ type: "string",
1654
+ required: true,
1655
+ description: "The file's path in the world."
1656
+ }
1657
+ },
1658
+ output: output$1,
1659
+ isConcurrencySafe: () => true,
1660
+ async execute(args, exec) {
1661
+ return json(await checkpoints().read((await worldOf(worlds, exec)).id, args.checkpoint, args.path));
1662
+ }
1663
+ })
1664
+ ];
1665
+ }
1666
+ /** A checkpoint at the first edit of each authoring turn, and a word to the chat when the person restored the world since it last looked. */
1667
+ function checkpointHooks(ctx, checkpoints, languageOf$1) {
1668
+ ctx.on("tools/pre-execute", async (exec, next) => {
1669
+ if (AUTHORING_MUTATION_TOOLS.has(exec.name) && exec.agent !== void 0 && authoredWorldOf(exec.agent.session.id) !== void 0 && exec.agent.session.header.origin !== "subagent") await checkpoints().beforeEdit(exec.agent.session.id, currentTurn(exec.agent), exec.name);
1670
+ return await next();
1671
+ }, { prepend: true });
1672
+ ctx.on("agent/pre-step", async (payload, next) => {
1673
+ const decision = await next();
1674
+ if (decision.kind !== "enter" || payload.step !== 1 || payload.agent.session.header.origin === "subagent") return decision;
1675
+ const restored = await checkpoints().unannouncedRestore(payload.agent.session.id);
1676
+ if (restored === void 0) return decision;
1677
+ const text = translator(languageOf(languageOf$1(payload.agent.session.id)))("The person restored this world to the checkpoint \"{label}\" ({at}): every file is as it was then, and what you edited since is gone. Read the world again before you edit, and do not rely on what you remember of it.", restored);
1678
+ return {
1679
+ ...decision,
1680
+ messages: [...decision.messages, createUserMessage({
1681
+ content: [{
1682
+ type: "text",
1683
+ text
1684
+ }],
1685
+ source: { kind: "roleplay" }
1686
+ })]
1687
+ };
1688
+ });
1689
+ }
1690
+ /** The checkpoint tools and hooks, registered on the scope of the preset that authors a world. */
1691
+ function registerCheckpointTools(ctx) {
1692
+ for (const tool of checkpointTools(ctx.roleplayWorlds, () => ctx.roleplayCheckpoints)) ctx.tools.register(tool);
1693
+ checkpointHooks(ctx, () => ctx.roleplayCheckpoints, (chat) => {
1694
+ const world = authoredWorldOf(chat);
1695
+ return world === void 0 ? void 0 : ctx.roleplayAuthoringLanguages.get(world);
1696
+ });
1697
+ }
1607
1698
  // src/host/checks/tools.ts
1608
1699
  const output = {
1609
1700
  schema: { type: "json" },
@@ -1729,6 +1820,7 @@ const inject = [
1729
1820
  "roleplayPrompts",
1730
1821
  "roleplayAuthoringLanguages",
1731
1822
  "roleplayAuthoringTools",
1823
+ "roleplayCheckpoints",
1732
1824
  "tools",
1733
1825
  "systemPrompt"
1734
1826
  ];
@@ -1763,6 +1855,7 @@ function apply(ctx) {
1763
1855
  settings: () => ctx.roleplayImport.settings,
1764
1856
  prompting
1765
1857
  })) ctx.tools.register(tool);
1858
+ registerCheckpointTools(ctx);
1766
1859
  importHooks(ctx, ctx.roleplayWorlds, prompting, ctx.roleplayImport.state);
1767
1860
  checkCommands(ctx, prompting);
1768
1861
  updateHooks(ctx, ctx.roleplayWorlds, (world) => ctx.roleplayAuthoringLanguages.get(world));