@dsh-agentic-roleplay/core 0.9.0 → 0.10.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 (47) hide show
  1. package/lib/{access-CfQWbNZP.js → access-CXtaZNbx.js} +50 -2
  2. package/lib/{authoring-tools-CdHlvx32.js → authoring-tools-B4mEdKp_.js} +1349 -604
  3. package/lib/authoring.js +23 -19
  4. package/lib/{child-lYYeOwl2.js → child-Dtv76jNx.js} +116 -11
  5. package/lib/client.js +2810 -795
  6. package/lib/client.js.map +1 -1
  7. package/lib/compaction.js +3 -3
  8. package/lib/doctor.js +3 -3
  9. package/lib/{gallery-BKh7eu80.js → gallery-BZJleAeH.js} +5 -9
  10. package/lib/{generator-DdZ1-sgv.js → generator-Cg6CQc5S.js} +2 -2
  11. package/lib/helper.js +1 -1
  12. package/lib/{hooks-CcQj_dJo.js → hooks-DTjHWTfx.js} +168 -28
  13. package/lib/images.js +4 -4
  14. package/lib/index.js +362 -33
  15. package/lib/{library-QFL6Z_Nr.js → library-GIlrkOim.js} +9 -14
  16. package/lib/{lorebook-author-tools-DWBnYo1E.js → lorebook-author-tools-BCFFJSle.js} +6 -6
  17. package/lib/lorebook-authoring.js +4 -4
  18. package/lib/{narration-CjB_KwwY.js → narration-BVzew4-K.js} +7 -52
  19. package/lib/orchestration.js +155 -10
  20. package/lib/{pack-jail-BMy6NcCY.js → pack-jail-hsNQNTOf.js} +25 -15
  21. package/lib/{packs-BREPSfHy.js → packs-UpK_cvI4.js} +2 -2
  22. package/lib/{presenter-agent-B49-_iUm.js → presenter-agent-DZOgBOR9.js} +12 -17
  23. package/lib/{preset-BqgY1Tz4.js → preset-Cyoj1ZWa.js} +4 -4
  24. package/lib/{preset-author-tools-BB_Dcv2o.js → preset-author-tools-RSta6pHK.js} +6 -6
  25. package/lib/preset-authoring.js +5 -5
  26. package/lib/{presets-Bwnrx7p0.js → presets-CvpsW_10.js} +17 -9
  27. package/lib/{reflection-CUWG-6Qg.js → reflection-0qTvw2It.js} +53 -26
  28. package/lib/{turn-guard-Bb8Ew-1z.js → turn-guard-BzNeGNnc.js} +3 -3
  29. package/package.json +2 -2
  30. package/prompts/en/checks/conflict.md +1 -0
  31. package/prompts/en/checks/decide-conflict.md +1 -0
  32. package/prompts/en/checks/decide-covered.md +1 -0
  33. package/prompts/en/checks/decide-opening.md +1 -0
  34. package/prompts/en/checks/decide-same-thing.md +1 -0
  35. package/prompts/en/checks/decide-same-value.md +1 -0
  36. package/prompts/en/checks/decide-sheet.md +1 -1
  37. package/prompts/en/checks/fidelity.md +1 -0
  38. package/prompts/en/checks/notice.md +2 -2
  39. package/prompts/zh/checks/conflict.md +1 -0
  40. package/prompts/zh/checks/decide-conflict.md +1 -0
  41. package/prompts/zh/checks/decide-covered.md +1 -0
  42. package/prompts/zh/checks/decide-opening.md +1 -0
  43. package/prompts/zh/checks/decide-same-thing.md +1 -0
  44. package/prompts/zh/checks/decide-same-value.md +1 -0
  45. package/prompts/zh/checks/decide-sheet.md +1 -1
  46. package/prompts/zh/checks/fidelity.md +1 -0
  47. package/prompts/zh/checks/notice.md +2 -2
@@ -1,3 +1,7 @@
1
+ import { basename, dirname, join } from "node:path";
2
+ import { chmodSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
3
+ import { randomUUID } from "node:crypto";
4
+ import { chmod, mkdir, rename, rm, stat, writeFile } from "node:fs/promises";
1
5
  // src/shared/chat.ts
2
6
  const CHAT_PREFIX = "session-";
3
7
  const UUID_V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
@@ -135,6 +139,50 @@ const VARIABLE_VISIBILITIES = [
135
139
  always: false,
136
140
  builtin: true
137
141
  }));
142
+ // src/host/atomic-write.ts
143
+ /**
144
+ * Replaces a file in one step: the data goes to a temporary file in the same folder and is renamed over the file, so an interruption leaves the old file or the new one,
145
+ * never half of either. Every writer of a file someone else may read at the same time goes through here.
146
+ */
147
+ async function atomicWrite(file, data, options = {}) {
148
+ if (options.createDirectory === true) await mkdir(dirname(file), { recursive: true });
149
+ const temporary = join(dirname(file), `.${basename(file)}.${process.pid}.${randomUUID()}.tmp`);
150
+ try {
151
+ const mode = options.mode ?? await stat(file).then((value) => value.mode & 511, (error) => {
152
+ if (error.code === "ENOENT") return 420;
153
+ throw error;
154
+ });
155
+ await writeFile(temporary, data, { mode });
156
+ await chmod(temporary, mode);
157
+ await rename(temporary, file);
158
+ } catch (error) {
159
+ await rm(temporary, { force: true });
160
+ throw error;
161
+ }
162
+ }
163
+ /** A JSON file written the same way, with the indentation given (none by default) and a final newline when it is indented. */
164
+ async function atomicWriteJson(file, value, options = {}) {
165
+ const { indent, ...rest } = options;
166
+ await atomicWrite(file, indent === void 0 ? JSON.stringify(value) : `${JSON.stringify(value, null, indent)}\n`, rest);
167
+ }
168
+ /** The synchronous form, for the few writers that cannot wait (the chat settings, read at every step). */
169
+ function atomicWriteSync(file, data) {
170
+ const temporary = join(dirname(file), `.${basename(file)}.${process.pid}.${randomUUID()}.tmp`);
171
+ try {
172
+ let mode = 420;
173
+ try {
174
+ mode = statSync(file).mode & 511;
175
+ } catch (error) {
176
+ if (error.code !== "ENOENT") throw error;
177
+ }
178
+ writeFileSync(temporary, data, { mode });
179
+ chmodSync(temporary, mode);
180
+ renameSync(temporary, file);
181
+ } catch (error) {
182
+ rmSync(temporary, { force: true });
183
+ throw error;
184
+ }
185
+ }
138
186
  // src/host/prompts/access.ts
139
187
  /** The prompt `id` in `language`, from the library of the agent's own context. */
140
188
  function promptFor(agent, id, language, variables) {
@@ -142,6 +190,6 @@ function promptFor(agent, id, language, variables) {
142
190
  if (library === void 0) throw new Error("the prompt library is not running");
143
191
  return library.text(id, language, variables, roleplaySessionOf(agent.session.id));
144
192
  }
145
- export { chatSessionId as a, VARIABLE_VISIBILITIES as i, VARIABLE_KINDS as n, roleplaySessionOf as o, VARIABLE_SUBJECTS as r, promptFor as t };
193
+ export { VARIABLE_KINDS as a, chatSessionId as c, atomicWriteSync as i, roleplaySessionOf as l, atomicWrite as n, VARIABLE_SUBJECTS as o, atomicWriteJson as r, VARIABLE_VISIBILITIES as s, promptFor as t };
146
194
 
147
- //# sourceMappingURL=access-CfQWbNZP.js.map
195
+ //# sourceMappingURL=access-CXtaZNbx.js.map