stitchkit 0.110.1 → 0.110.3

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 (86) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/agent-runtime/archive-projection.d.ts +10 -0
  3. package/dist/agent-runtime/archive-projection.d.ts.map +1 -0
  4. package/dist/agent-runtime/archive-spill.d.ts +61 -0
  5. package/dist/agent-runtime/archive-spill.d.ts.map +1 -0
  6. package/dist/agent-runtime/branch-contract.d.ts +102 -0
  7. package/dist/agent-runtime/branch-contract.d.ts.map +1 -0
  8. package/dist/agent-runtime/branch-events.d.ts +18 -0
  9. package/dist/agent-runtime/branch-events.d.ts.map +1 -0
  10. package/dist/agent-runtime/branch-identities.d.ts +20 -0
  11. package/dist/agent-runtime/branch-identities.d.ts.map +1 -0
  12. package/dist/agent-runtime/branch-messages.d.ts +32 -0
  13. package/dist/agent-runtime/branch-messages.d.ts.map +1 -0
  14. package/dist/agent-runtime/branch-observations.d.ts +104 -0
  15. package/dist/agent-runtime/branch-observations.d.ts.map +1 -0
  16. package/dist/agent-runtime/branch-provider.d.ts +130 -0
  17. package/dist/agent-runtime/branch-provider.d.ts.map +1 -0
  18. package/dist/agent-runtime/branch-replay.d.ts +426 -0
  19. package/dist/agent-runtime/branch-replay.d.ts.map +1 -0
  20. package/dist/agent-runtime/branch-source.d.ts +16 -0
  21. package/dist/agent-runtime/branch-source.d.ts.map +1 -0
  22. package/dist/agent-runtime/branch-transitions.d.ts +6 -0
  23. package/dist/agent-runtime/branch-transitions.d.ts.map +1 -0
  24. package/dist/agent-runtime/sqlite-events.d.ts.map +1 -1
  25. package/dist/agent-runtime/sqlite-history.d.ts.map +1 -1
  26. package/dist/agent-runtime/sqlite-purge.d.ts.map +1 -1
  27. package/dist/agent-runtime/store-archive.d.ts +1 -0
  28. package/dist/agent-runtime/store-archive.d.ts.map +1 -1
  29. package/dist/agent-runtime/store-branch.d.ts +5 -0
  30. package/dist/agent-runtime/store-branch.d.ts.map +1 -0
  31. package/dist/agent-runtime/store-conformance-branch.d.ts +4 -0
  32. package/dist/agent-runtime/store-conformance-branch.d.ts.map +1 -0
  33. package/dist/agent-runtime/store-conformance-support.d.ts +5 -5
  34. package/dist/agent-runtime/store-conformance.d.ts.map +1 -1
  35. package/dist/agent-runtime/store-create.d.ts +1 -1
  36. package/dist/agent-runtime/store-create.d.ts.map +1 -1
  37. package/dist/agent-runtime/store-driver-contract.d.ts +6 -0
  38. package/dist/agent-runtime/store-driver-contract.d.ts.map +1 -1
  39. package/dist/agent-runtime/store-events.d.ts +1131 -0
  40. package/dist/agent-runtime/store-events.d.ts.map +1 -1
  41. package/dist/agent-runtime/store-memory-archive.d.ts +8 -0
  42. package/dist/agent-runtime/store-memory-archive.d.ts.map +1 -0
  43. package/dist/agent-runtime/store-memory-events.d.ts +7 -0
  44. package/dist/agent-runtime/store-memory-events.d.ts.map +1 -0
  45. package/dist/agent-runtime/store-memory.d.ts +1 -1
  46. package/dist/agent-runtime/store-memory.d.ts.map +1 -1
  47. package/dist/agent-runtime/store-purge.d.ts +2 -0
  48. package/dist/agent-runtime/store-purge.d.ts.map +1 -1
  49. package/dist/agent-runtime/store-reduce-run.d.ts +2 -2
  50. package/dist/agent-runtime/store-reduce-run.d.ts.map +1 -1
  51. package/dist/agent-runtime/store-reduce-shared.d.ts +1 -0
  52. package/dist/agent-runtime/store-reduce-shared.d.ts.map +1 -1
  53. package/dist/agent-runtime/store-reducer.d.ts +2 -2
  54. package/dist/agent-runtime/store-reducer.d.ts.map +1 -1
  55. package/dist/agent-runtime/store-replay.d.ts +4 -0
  56. package/dist/agent-runtime/store-replay.d.ts.map +1 -0
  57. package/dist/agent-runtime/store.d.ts +3 -0
  58. package/dist/agent-runtime/store.d.ts.map +1 -1
  59. package/dist/durability/events.d.ts +4 -0
  60. package/dist/durability/events.d.ts.map +1 -1
  61. package/dist/entrypoints/agent-runtime/coding-tools.js +1 -2
  62. package/dist/entrypoints/agent-runtime/harness.js +4 -3
  63. package/dist/entrypoints/agent-runtime/sandbox.js +3 -5
  64. package/dist/entrypoints/agent-runtime/sqlite/bun.js +13 -3
  65. package/dist/entrypoints/agent-runtime/sqlite/node.js +13 -3
  66. package/dist/entrypoints/agent-runtime/testing.js +89 -5
  67. package/dist/entrypoints/agent-runtime.d.ts +2 -1
  68. package/dist/entrypoints/agent-runtime.d.ts.map +1 -1
  69. package/dist/entrypoints/agent-runtime.js +27 -15
  70. package/dist/entrypoints/tools.js +5 -3
  71. package/dist/{index-0gs4ymfj.js → index-4fgg1507.js} +31 -2
  72. package/dist/{index-c17xcx4k.js → index-56yx8dxp.js} +19 -96
  73. package/dist/{index-8rstkvcf.js → index-7c046kxr.js} +1 -1
  74. package/dist/{index-tjdsyrys.js → index-bm180f2d.js} +203 -83
  75. package/dist/{index-924500c3.js → index-ddkwkcvn.js} +2 -2
  76. package/dist/{index-c0hffcmj.js → index-dgfah0g8.js} +21 -9
  77. package/dist/index-j1cwtyk1.js +2269 -0
  78. package/dist/index-snef22zr.js +94 -0
  79. package/dist/{index-5p55xreg.js → index-w619fqvv.js} +67 -29
  80. package/llms/agent-runtime.3.txt +4 -0
  81. package/llms/agent-runtime.txt +75 -0
  82. package/llms-full.txt +79 -0
  83. package/llms.txt +1 -1
  84. package/package.json +1 -1
  85. package/dist/index-8ks9b85e.js +0 -129
  86. package/dist/index-d2h99n7d.js +0 -1071
@@ -4,13 +4,6 @@ import {
4
4
  import {
5
5
  NativeCommandError2
6
6
  } from "./index-84bf5spd.js";
7
- import {
8
- probeAgentProcessSandboxOutcome,
9
- missingSandboxRestrictions2,
10
- codingRefusal,
11
- codingPathRefusal,
12
- refuseMissingCodingPath
13
- } from "./index-8ks9b85e.js";
14
7
  import {
15
8
  CommandStopped,
16
9
  startNativeCommand
@@ -36,8 +29,10 @@ import {
36
29
  defineRuntimeTool2
37
30
  } from "./index-636mggad.js";
38
31
  import {
32
+ AppError2,
39
33
  forbidden2,
40
- conflict2
34
+ conflict2,
35
+ STITCH_ERROR_STATUS2
41
36
  } from "./index-j9gxbztg.js";
42
37
 
43
38
  // src/agent-runtime/coding-tool-contract.ts
@@ -183,9 +178,80 @@ function resolveCodingToolLimits(input) {
183
178
  return AgentCodingToolLimitsSchema2.parse({ ...DEFAULT_LIMITS, ...input });
184
179
  }
185
180
 
181
+ // src/agent-runtime/sandbox.ts
182
+ import { z as z2 } from "zod";
183
+ var AgentSandboxRestrictionSchema2 = z2.enum([
184
+ "network-denied",
185
+ "write-contained",
186
+ "secrets-hidden",
187
+ "process-contained"
188
+ ]);
189
+ var AgentSandboxGradeSchema2 = z2.discriminatedUnion("grade", [
190
+ z2.object({ grade: z2.literal("full"), restrictions: z2.array(AgentSandboxRestrictionSchema2) }).strict(),
191
+ z2.object({
192
+ grade: z2.literal("partial"),
193
+ restrictions: z2.array(AgentSandboxRestrictionSchema2),
194
+ gaps: z2.array(AgentSandboxRestrictionSchema2)
195
+ }).strict(),
196
+ z2.object({ grade: z2.literal("unavailable"), reason: z2.string().min(1) }).strict()
197
+ ]);
198
+ var probes = new WeakMap;
199
+ var PROBE_FAILED = "sandbox probe failed";
200
+ var PROBE_INVALID = "sandbox probe returned no valid grade";
201
+ async function runProbe(sandbox) {
202
+ let value;
203
+ try {
204
+ value = await sandbox.probe();
205
+ } catch (cause) {
206
+ return { grade: { grade: "unavailable", reason: PROBE_FAILED }, cause };
207
+ }
208
+ const parsed = AgentSandboxGradeSchema2.safeParse(value);
209
+ if (parsed.success)
210
+ return { grade: parsed.data };
211
+ return { grade: { grade: "unavailable", reason: PROBE_INVALID }, cause: parsed.error };
212
+ }
213
+ function probeAgentProcessSandboxOutcome(sandbox, options = {}) {
214
+ if (options.refresh)
215
+ probes.delete(sandbox);
216
+ const present = probes.get(sandbox);
217
+ if (present)
218
+ return present;
219
+ const pending = runProbe(sandbox);
220
+ probes.set(sandbox, pending);
221
+ return pending;
222
+ }
223
+ async function probeAgentProcessSandbox2(sandbox, options = {}) {
224
+ const fresh = options.refresh === true || !probes.has(sandbox);
225
+ const outcome = await probeAgentProcessSandboxOutcome(sandbox, options);
226
+ if (fresh && outcome.cause !== undefined) {
227
+ process.emitWarning(new Error("Sandbox probe failed", { cause: outcome.cause }));
228
+ }
229
+ return outcome.grade;
230
+ }
231
+ function missingSandboxRestrictions2(grade, required) {
232
+ if (grade.grade === "unavailable")
233
+ return required;
234
+ const present = new Set(grade.restrictions);
235
+ return required.filter((restriction) => !present.has(restriction));
236
+ }
237
+ async function recordAgentSandboxProbe2(input) {
238
+ const grade = await probeAgentProcessSandbox2(input.sandbox);
239
+ const missing = missingSandboxRestrictions2(grade, input.required);
240
+ await input.store.appendEvent({
241
+ conversationId: input.conversationId,
242
+ kind: "sandbox/probed",
243
+ payload: {
244
+ result: grade,
245
+ required: [...input.required],
246
+ missing: [...missing]
247
+ }
248
+ });
249
+ return grade;
250
+ }
251
+
186
252
  // src/agent-runtime/coding-tools.ts
187
253
  import path5 from "node:path";
188
- import { z as z4 } from "zod";
254
+ import { z as z5 } from "zod";
189
255
 
190
256
  // src/agent-runtime/coding-tool-files.ts
191
257
  import { createHash } from "node:crypto";
@@ -194,6 +260,60 @@ import { realpath as realpath2 } from "node:fs/promises";
194
260
  // src/agent-runtime/coding-tool-paths.ts
195
261
  import { lstat, realpath } from "node:fs/promises";
196
262
  import path from "node:path";
263
+
264
+ // src/agent-runtime/coding-tool-refusals.ts
265
+ function codingRefusal(code, message, options = {}) {
266
+ throw new AppError2(code, {
267
+ message,
268
+ status: STITCH_ERROR_STATUS2[code],
269
+ details: { message, ...options.details },
270
+ hint: options.hint,
271
+ ..."cause" in options && { cause: options.cause }
272
+ });
273
+ }
274
+ function codingPathRefusal(code, message, path, options = {}) {
275
+ codingRefusal(code, message, {
276
+ details: { path, ...options.details },
277
+ ...options.hint && { hint: options.hint }
278
+ });
279
+ }
280
+ function refuseMissingCodingPath(error, relative) {
281
+ const code = error?.code;
282
+ if (error instanceof Error && error.message.includes("is not a regular file")) {
283
+ codingPathRefusal("BAD_REQUEST", "This path is not a regular file", relative, {
284
+ hint: "Use list_directory to see what is here."
285
+ });
286
+ }
287
+ if (code === "ENOENT") {
288
+ codingPathRefusal("NOT_FOUND", "This path does not exist", relative, {
289
+ hint: "Use list_directory or glob to find the right path."
290
+ });
291
+ }
292
+ if (code === "ENOTDIR") {
293
+ codingPathRefusal("BAD_REQUEST", "A segment of this path is not a directory", relative, {
294
+ hint: "Check the path with list_directory."
295
+ });
296
+ }
297
+ if (code === "ELOOP") {
298
+ codingPathRefusal("FORBIDDEN", "This path is a symlink, which is not followed", relative, {
299
+ hint: "Read or write the target directly, by its own workspace-relative path."
300
+ });
301
+ }
302
+ if (code === "EISDIR") {
303
+ codingPathRefusal("BAD_REQUEST", "This path is not a regular file", relative, {
304
+ hint: "Use list_directory to see what is here."
305
+ });
306
+ }
307
+ throw error;
308
+ }
309
+ function refuseUnknownSpillReference(reference) {
310
+ codingRefusal("SPILL_REFERENCE_UNKNOWN", `No spilled output is held under \`${reference}\``, {
311
+ details: { reference },
312
+ hint: "Use the reference returned by the command that spilled its output, not a session or call id."
313
+ });
314
+ }
315
+
316
+ // src/agent-runtime/coding-tool-paths.ts
197
317
  function within(root, target) {
198
318
  const relative = path.relative(root, target);
199
319
  return relative === "" || !relative.startsWith(`..${path.sep}`) && relative !== ".." && !path.isAbsolute(relative);
@@ -579,7 +699,7 @@ function createFileCodingTools(config, limits) {
579
699
  // src/agent-runtime/coding-tool-listing.ts
580
700
  import { realpath as realpath3 } from "node:fs/promises";
581
701
  import path3 from "node:path";
582
- import { z as z2 } from "zod";
702
+ import { z as z3 } from "zod";
583
703
  var DEFAULT_EXCLUDED_DIRECTORIES = [
584
704
  ".git",
585
705
  ".next",
@@ -589,28 +709,28 @@ var DEFAULT_EXCLUDED_DIRECTORIES = [
589
709
  "dist",
590
710
  "node_modules"
591
711
  ];
592
- var ListInputSchema = z2.object({ path: z2.string().min(1).default(".") }).strict();
593
- var ListOutputSchema = z2.object({
594
- path: z2.string().min(1),
595
- entries: z2.array(z2.object({
596
- name: z2.string().min(1),
597
- kind: z2.enum(["file", "directory", "symlink", "other"]),
598
- bytes: z2.int().nonnegative().optional(),
599
- excluded: z2.boolean().optional()
712
+ var ListInputSchema = z3.object({ path: z3.string().min(1).default(".") }).strict();
713
+ var ListOutputSchema = z3.object({
714
+ path: z3.string().min(1),
715
+ entries: z3.array(z3.object({
716
+ name: z3.string().min(1),
717
+ kind: z3.enum(["file", "directory", "symlink", "other"]),
718
+ bytes: z3.int().nonnegative().optional(),
719
+ excluded: z3.boolean().optional()
600
720
  }).strict()),
601
- truncated: z2.boolean(),
602
- denied: z2.array(CodingDeniedEntrySchema).optional(),
603
- deniedTruncated: z2.boolean().optional()
721
+ truncated: z3.boolean(),
722
+ denied: z3.array(CodingDeniedEntrySchema).optional(),
723
+ deniedTruncated: z3.boolean().optional()
604
724
  }).strict();
605
- var GlobInputSchema = z2.object({ pattern: z2.string().min(1), path: z2.string().min(1).default(".") }).strict();
606
- var GlobOutputSchema = z2.object({
607
- paths: z2.array(z2.string().min(1)),
608
- truncated: z2.boolean(),
609
- resultTruncated: z2.boolean(),
610
- skippedDirectories: z2.int().nonnegative(),
611
- scannedFiles: z2.int().nonnegative(),
612
- denied: z2.array(CodingDeniedEntrySchema).optional(),
613
- deniedTruncated: z2.boolean().optional()
725
+ var GlobInputSchema = z3.object({ pattern: z3.string().min(1), path: z3.string().min(1).default(".") }).strict();
726
+ var GlobOutputSchema = z3.object({
727
+ paths: z3.array(z3.string().min(1)),
728
+ truncated: z3.boolean(),
729
+ resultTruncated: z3.boolean(),
730
+ skippedDirectories: z3.int().nonnegative(),
731
+ scannedFiles: z3.int().nonnegative(),
732
+ denied: z3.array(CodingDeniedEntrySchema).optional(),
733
+ deniedTruncated: z3.boolean().optional()
614
734
  }).strict();
615
735
  function compileWorkspaceGlob(pattern) {
616
736
  let source = "";
@@ -743,29 +863,29 @@ function createListingCodingTools(config, limits) {
743
863
  import { createHash as createHash2 } from "node:crypto";
744
864
  import { realpath as realpath4 } from "node:fs/promises";
745
865
  import path4 from "node:path";
746
- import { z as z3 } from "zod";
747
- var SearchInputSchema = z3.object({
748
- query: z3.string().min(1),
749
- mode: z3.enum(["path", "content"]).default("content"),
750
- regex: z3.boolean().default(false),
751
- context: z3.int().nonnegative().max(10).default(0),
752
- include: z3.string().min(1).describe("Anchored `**`/`*`/`?` pattern matched against the whole workspace-relative path. `*` does not cross `/`; use `**/` to include matching files in subdirectories.").optional()
866
+ import { z as z4 } from "zod";
867
+ var SearchInputSchema = z4.object({
868
+ query: z4.string().min(1),
869
+ mode: z4.enum(["path", "content"]).default("content"),
870
+ regex: z4.boolean().default(false),
871
+ context: z4.int().nonnegative().max(10).default(0),
872
+ include: z4.string().min(1).describe("Anchored `**`/`*`/`?` pattern matched against the whole workspace-relative path. `*` does not cross `/`; use `**/` to include matching files in subdirectories.").optional()
753
873
  }).strict();
754
- var SearchOutputSchema = z3.object({
755
- matches: z3.array(z3.object({
756
- path: z3.string().min(1),
757
- line: z3.int().positive().optional(),
758
- text: z3.string().optional(),
759
- before: z3.array(z3.string()).optional(),
760
- after: z3.array(z3.string()).optional()
874
+ var SearchOutputSchema = z4.object({
875
+ matches: z4.array(z4.object({
876
+ path: z4.string().min(1),
877
+ line: z4.int().positive().optional(),
878
+ text: z4.string().optional(),
879
+ before: z4.array(z4.string()).optional(),
880
+ after: z4.array(z4.string()).optional()
761
881
  }).strict()),
762
- truncated: z3.boolean(),
763
- scannedFiles: z3.int().nonnegative().describe("Files admitted by include and host authorization that reached path or content comparison."),
764
- skippedDirectories: z3.int().nonnegative(),
765
- skippedSymlinks: z3.int().nonnegative(),
766
- denied: z3.array(CodingDeniedEntrySchema).optional(),
767
- deniedTruncated: z3.boolean().optional(),
768
- hint: z3.string().min(1).optional()
882
+ truncated: z4.boolean(),
883
+ scannedFiles: z4.int().nonnegative().describe("Files admitted by include and host authorization that reached path or content comparison."),
884
+ skippedDirectories: z4.int().nonnegative(),
885
+ skippedSymlinks: z4.int().nonnegative(),
886
+ denied: z4.array(CodingDeniedEntrySchema).optional(),
887
+ deniedTruncated: z4.boolean().optional(),
888
+ hint: z4.string().min(1).optional()
769
889
  }).strict();
770
890
  function compileSearchRegex(pattern) {
771
891
  if (/\\[1-9]/.test(pattern) || /\(\?<?[=!]/.test(pattern)) {
@@ -784,21 +904,21 @@ function compileSearchRegex(pattern) {
784
904
  }
785
905
  }
786
906
  var MAX_SEARCHED_LINE_BYTES = 8192;
787
- var EditInputSchema = z3.object({
788
- path: z3.string().min(1),
789
- oldText: z3.string().min(1),
790
- newText: z3.string(),
791
- replaceAll: z3.boolean().default(false),
792
- expectedSha256: z3.string().length(64).optional(),
793
- dryRun: z3.boolean().default(false)
907
+ var EditInputSchema = z4.object({
908
+ path: z4.string().min(1),
909
+ oldText: z4.string().min(1),
910
+ newText: z4.string(),
911
+ replaceAll: z4.boolean().default(false),
912
+ expectedSha256: z4.string().length(64).optional(),
913
+ dryRun: z4.boolean().default(false)
794
914
  }).strict();
795
- var EditOutputSchema = z3.object({
796
- path: z3.string().min(1),
797
- baseSha256: z3.string().length(64),
798
- sha256: z3.string().length(64),
799
- replacements: z3.int().positive(),
800
- bytes: z3.int().nonnegative(),
801
- applied: z3.boolean()
915
+ var EditOutputSchema = z4.object({
916
+ path: z4.string().min(1),
917
+ baseSha256: z4.string().length(64),
918
+ sha256: z4.string().length(64),
919
+ replacements: z4.int().positive(),
920
+ bytes: z4.int().nonnegative(),
921
+ applied: z4.boolean()
802
922
  }).strict();
803
923
  function sha256(value) {
804
924
  return createHash2("sha256").update(value).digest("hex");
@@ -1278,17 +1398,17 @@ function createAgentCodingTools2(config) {
1278
1398
  name: AGENT_CODING_TOOL_NAMES.readOutput,
1279
1399
  description: "Read a bounded byte slice from one opaque coding output artifact.",
1280
1400
  identity: { serviceName: "coding", action: "read-artifact", method: "POST" },
1281
- input: z4.object({
1282
- reference: z4.string().min(1),
1283
- offset: z4.int().nonnegative().default(0),
1284
- maxBytes: z4.int().positive().optional()
1401
+ input: z5.object({
1402
+ reference: z5.string().min(1),
1403
+ offset: z5.int().nonnegative().default(0),
1404
+ maxBytes: z5.int().positive().optional()
1285
1405
  }).strict(),
1286
- output: z4.object({
1287
- reference: z4.string().min(1),
1288
- offset: z4.int().nonnegative(),
1289
- text: z4.string(),
1290
- bytes: z4.int().nonnegative(),
1291
- totalBytes: z4.int().nonnegative().optional()
1406
+ output: z5.object({
1407
+ reference: z5.string().min(1),
1408
+ offset: z5.int().nonnegative(),
1409
+ text: z5.string(),
1410
+ bytes: z5.int().nonnegative(),
1411
+ totalBytes: z5.int().nonnegative().optional()
1292
1412
  }).strict(),
1293
1413
  transports: ["AGENT"],
1294
1414
  handler: async ({ input }) => {
@@ -1327,14 +1447,14 @@ function createAgentCodingTools2(config) {
1327
1447
  name: AGENT_CODING_TOOL_NAMES.searchOutput,
1328
1448
  description: "Search a durable spilled output without loading it into context.",
1329
1449
  identity: { serviceName: "coding", action: "search-artifact", method: "POST" },
1330
- input: z4.object({
1331
- reference: z4.string().min(1),
1332
- query: z4.string().min(1),
1333
- maxMatches: z4.int().positive().max(limits.maxSearchResults).default(20)
1450
+ input: z5.object({
1451
+ reference: z5.string().min(1),
1452
+ query: z5.string().min(1),
1453
+ maxMatches: z5.int().positive().max(limits.maxSearchResults).default(20)
1334
1454
  }).strict(),
1335
- output: z4.object({
1336
- reference: z4.string(),
1337
- matches: z4.array(z4.object({ line: z4.int().positive(), text: z4.string() }))
1455
+ output: z5.object({
1456
+ reference: z5.string(),
1457
+ matches: z5.array(z5.object({ line: z5.int().positive(), text: z5.string() }))
1338
1458
  }).strict(),
1339
1459
  transports: ["AGENT"],
1340
1460
  handler: async ({ input }) => {
@@ -1371,4 +1491,4 @@ function createAgentCodingTools2(config) {
1371
1491
  ];
1372
1492
  }
1373
1493
 
1374
- export { AgentCodingToolLimitsSchema2, AgentCodingToolAuthorizationSchema2, AgentCodingToolPathAuthorizationSchema2, createAgentCodingTools2 };
1494
+ export { AgentCodingToolLimitsSchema2, AgentCodingToolAuthorizationSchema2, AgentCodingToolPathAuthorizationSchema2, ShellOutputSchema, AgentSandboxRestrictionSchema2, AgentSandboxGradeSchema2, probeAgentProcessSandbox2, missingSandboxRestrictions2, recordAgentSandboxProbe2, codingRefusal, refuseUnknownSpillReference, AGENT_CODING_TOOL_NAMES, createAgentCodingTools2 };
@@ -22,7 +22,7 @@ import {
22
22
  createLocalStepDurability2,
23
23
  isAgentToolError2,
24
24
  createToolDurabilityContext
25
- } from "./index-c17xcx4k.js";
25
+ } from "./index-56yx8dxp.js";
26
26
  import {
27
27
  canonicalAgentJson2,
28
28
  createToolChronology,
@@ -31,7 +31,7 @@ import {
31
31
  isAssistantHistoryEvidence2,
32
32
  isCompleteAgentHistoryTurn,
33
33
  assistantStatus
34
- } from "./index-0gs4ymfj.js";
34
+ } from "./index-4fgg1507.js";
35
35
  import {
36
36
  messageOf
37
37
  } from "./index-g149e9pk.js";
@@ -5,7 +5,7 @@ import {
5
5
  AgentRecoverableDescriptorSchema2,
6
6
  AgentRecoverablePageSchema2,
7
7
  canonicalAgentJson2
8
- } from "./index-0gs4ymfj.js";
8
+ } from "./index-4fgg1507.js";
9
9
  import {
10
10
  AgentMessageSchema2,
11
11
  AgentRunSchema2
@@ -17,8 +17,9 @@ import {
17
17
  AgentSeedReceiptSchema2,
18
18
  AgentHistoryMutationSchema2,
19
19
  appendEventIn,
20
+ ArchiveProjectionSchema,
20
21
  createAgentRuntimeStore2
21
- } from "./index-d2h99n7d.js";
22
+ } from "./index-j1cwtyk1.js";
22
23
  import {
23
24
  AgentConversationPageSchema2,
24
25
  AgentConversationMessagePageSchema2
@@ -63,6 +64,14 @@ function sqliteConversationPurge(database) {
63
64
  if (table === null || table === undefined)
64
65
  return;
65
66
  return {
67
+ async isEmpty(transaction, conversationId) {
68
+ for (const table of OWNED_TABLES) {
69
+ const row = transaction.prepare(`SELECT 1 FROM ${table} WHERE conversation_id = ? LIMIT 1`).get(conversationId);
70
+ if (row !== null && row !== undefined)
71
+ return false;
72
+ }
73
+ return transaction.prepare("SELECT 1 FROM stitchkit_agent_runtime_children WHERE parent_conversation_id = ? OR child_conversation_id = ? LIMIT 1").get(conversationId, conversationId) == null;
74
+ },
66
75
  async isPurged(transaction, conversationId) {
67
76
  const row = transaction.prepare("SELECT conversation_id FROM stitchkit_agent_runtime_purged WHERE conversation_id = ?").get(conversationId);
68
77
  return row !== null && row !== undefined;
@@ -584,13 +593,7 @@ var sqliteArchive = {
584
593
  if (typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.archiveType === "runtime-snapshot") {
585
594
  continue;
586
595
  }
587
- const projection = z4.object({
588
- name: z4.string(),
589
- version: z4.int().positive(),
590
- uptoSeq: z4.int().nonnegative(),
591
- value: z4.json(),
592
- updatedAt: z4.string()
593
- }).strict().parse(raw);
596
+ const projection = ArchiveProjectionSchema.parse(raw);
594
597
  transaction.prepare(`
595
598
  INSERT INTO stitchkit_agent_runtime_projections
596
599
  (conversation_id, name, version, upto_seq, payload, updated_at)
@@ -629,6 +632,15 @@ var sqliteArchive = {
629
632
 
630
633
  // src/agent-runtime/sqlite-history.ts
631
634
  var sqliteHistory = {
635
+ async restore(transaction, input) {
636
+ const compacted = new Set(input.compactedMessageIds);
637
+ for (const [position, message] of input.messages.entries()) {
638
+ if (message.conversationId !== input.conversationId)
639
+ throw new TypeError("Restored history has a foreign conversation");
640
+ transaction.prepare(`INSERT INTO stitchkit_agent_runtime_messages
641
+ (conversation_id, id, position, active, payload) VALUES (?, ?, ?, ?, ?)`).run(input.conversationId, message.id, position, compacted.has(message.id) ? 0 : 1, encodeJson(message));
642
+ }
643
+ },
632
644
  async load(transaction, conversationId) {
633
645
  return transaction.prepare(`
634
646
  SELECT payload FROM stitchkit_agent_runtime_messages