stitchkit 0.98.2 → 0.100.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 (143) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/dist/agent-runtime/contained-darwin.d.ts +0 -17
  3. package/dist/agent-runtime/contained-darwin.d.ts.map +1 -1
  4. package/dist/agent-runtime/contained-write.d.ts.map +1 -1
  5. package/dist/agent-runtime/invocation-attempt.d.ts +22 -0
  6. package/dist/agent-runtime/invocation-attempt.d.ts.map +1 -0
  7. package/dist/agent-runtime/invocation-failure.d.ts +6 -0
  8. package/dist/agent-runtime/invocation-failure.d.ts.map +1 -0
  9. package/dist/agent-runtime/invocation-payload.d.ts +18 -0
  10. package/dist/agent-runtime/invocation-payload.d.ts.map +1 -0
  11. package/dist/agent-runtime/invocation-read.d.ts +131 -0
  12. package/dist/agent-runtime/invocation-read.d.ts.map +1 -0
  13. package/dist/agent-runtime/invocation-schema.d.ts +378 -0
  14. package/dist/agent-runtime/invocation-schema.d.ts.map +1 -0
  15. package/dist/agent-runtime/invocations.d.ts +46 -0
  16. package/dist/agent-runtime/invocations.d.ts.map +1 -0
  17. package/dist/agent-runtime/run-acquisition.d.ts.map +1 -1
  18. package/dist/agent-runtime/run-execution-state.d.ts +4 -2
  19. package/dist/agent-runtime/run-execution-state.d.ts.map +1 -1
  20. package/dist/agent-runtime/run-execution.d.ts.map +1 -1
  21. package/dist/agent-runtime/run-failure.d.ts.map +1 -1
  22. package/dist/agent-runtime/run-model-attempts.d.ts.map +1 -1
  23. package/dist/agent-runtime/run-operation-lifecycle.d.ts +2 -2
  24. package/dist/agent-runtime/run-operation-lifecycle.d.ts.map +1 -1
  25. package/dist/agent-runtime/run-provider-ledger.d.ts +1 -0
  26. package/dist/agent-runtime/run-provider-ledger.d.ts.map +1 -1
  27. package/dist/agent-runtime/runtime.d.ts +11 -0
  28. package/dist/agent-runtime/runtime.d.ts.map +1 -1
  29. package/dist/agent-runtime/store-create.d.ts.map +1 -1
  30. package/dist/agent-runtime/store-event-once.d.ts +29 -0
  31. package/dist/agent-runtime/store-event-once.d.ts.map +1 -0
  32. package/dist/agent-runtime/store.d.ts +5 -0
  33. package/dist/agent-runtime/store.d.ts.map +1 -1
  34. package/dist/application/change-subscription.d.ts +36 -0
  35. package/dist/application/change-subscription.d.ts.map +1 -0
  36. package/dist/application/diagnostic-journal-contract.d.ts +3 -6
  37. package/dist/application/diagnostic-journal-contract.d.ts.map +1 -1
  38. package/dist/application/notification-delivery.d.ts +32 -0
  39. package/dist/application/notification-delivery.d.ts.map +1 -0
  40. package/dist/application/notification-outbox-state.d.ts +37 -0
  41. package/dist/application/notification-outbox-state.d.ts.map +1 -0
  42. package/dist/application/notification-outbox.d.ts +7 -1
  43. package/dist/application/notification-outbox.d.ts.map +1 -1
  44. package/dist/application/watch-hub-core.d.ts +10 -15
  45. package/dist/application/watch-hub-core.d.ts.map +1 -1
  46. package/dist/application/watch-hub.d.ts +10 -2
  47. package/dist/application/watch-hub.d.ts.map +1 -1
  48. package/dist/browser/session-credentials.d.ts +20 -0
  49. package/dist/browser/session-credentials.d.ts.map +1 -0
  50. package/dist/browser/session.d.ts +31 -0
  51. package/dist/browser/session.d.ts.map +1 -0
  52. package/dist/durability/events.d.ts +6 -0
  53. package/dist/durability/events.d.ts.map +1 -1
  54. package/dist/entrypoints/agent-runtime/coding-tools.js +5 -4
  55. package/dist/entrypoints/agent-runtime/harness.js +8 -6
  56. package/dist/entrypoints/agent-runtime/sandbox.js +5 -4
  57. package/dist/entrypoints/agent-runtime/sqlite/bun.js +3 -3
  58. package/dist/entrypoints/agent-runtime/sqlite/node.js +3 -3
  59. package/dist/entrypoints/agent-runtime/testing.js +3 -3
  60. package/dist/entrypoints/agent-runtime.d.ts +3 -0
  61. package/dist/entrypoints/agent-runtime.d.ts.map +1 -1
  62. package/dist/entrypoints/agent-runtime.js +21 -10
  63. package/dist/entrypoints/application/diagnostic-journal.js +2 -1
  64. package/dist/entrypoints/application.d.ts +3 -1
  65. package/dist/entrypoints/application.d.ts.map +1 -1
  66. package/dist/entrypoints/application.js +629 -189
  67. package/dist/entrypoints/cli.js +6 -6
  68. package/dist/entrypoints/files.js +2 -1
  69. package/dist/entrypoints/index.d.ts +2 -0
  70. package/dist/entrypoints/index.d.ts.map +1 -1
  71. package/dist/entrypoints/index.js +172 -0
  72. package/dist/entrypoints/live.js +68 -13
  73. package/dist/entrypoints/react.d.ts +1 -1
  74. package/dist/entrypoints/react.d.ts.map +1 -1
  75. package/dist/entrypoints/react.js +59 -16
  76. package/dist/entrypoints/testing.js +1 -1
  77. package/dist/entrypoints/tools/connections.js +2 -2
  78. package/dist/entrypoints/tools/invoker.js +4 -4
  79. package/dist/entrypoints/tools.js +8 -8
  80. package/dist/{index-wsm5w4ee.js → index-0b1cnze2.js} +35 -3
  81. package/dist/{index-np4m8hd3.js → index-0r0fbk7z.js} +9 -7
  82. package/dist/{index-p9sh0xx4.js → index-5p2m7we1.js} +3 -3
  83. package/dist/{index-55hkhm67.js → index-8qt2m66q.js} +1 -1
  84. package/dist/{index-hmp4800j.js → index-9t3dffv2.js} +3 -3
  85. package/dist/{index-khtgb21r.js → index-bm5rx7n6.js} +2 -2
  86. package/dist/{index-gxrt5h6v.js → index-cyktc4bp.js} +3 -0
  87. package/dist/{index-xw3s75nj.js → index-d8m8zpd8.js} +1 -1
  88. package/dist/{index-px2gm2jp.js → index-fhwqwxe0.js} +17 -55
  89. package/dist/{index-het2he5g.js → index-gw8bmyaj.js} +5 -3
  90. package/dist/{index-8p52kd5p.js → index-js7gqrb1.js} +96 -14
  91. package/dist/{index-wt743f7f.js → index-k6gpggb9.js} +2 -1
  92. package/dist/index-q3pyb9n0.js +22 -0
  93. package/dist/{index-f1nb70ae.js → index-r066jx76.js} +4 -4
  94. package/dist/{index-sp1tzwnb.js → index-s84he4v7.js} +2 -2
  95. package/dist/{index-863ea9jb.js → index-sh3s86na.js} +3 -3
  96. package/dist/{index-nts4a2br.js → index-xwhjjw2x.js} +879 -280
  97. package/dist/{index-1m2thnq0.js → index-y9qn426m.js} +2 -2
  98. package/dist/index-zjjyynm3.js +42 -0
  99. package/dist/internal/coalesced-task.d.ts +15 -0
  100. package/dist/internal/coalesced-task.d.ts.map +1 -0
  101. package/dist/internal/darwin-binding.d.ts +19 -0
  102. package/dist/internal/darwin-binding.d.ts.map +1 -0
  103. package/dist/internal/exclusive-lock.d.ts +20 -7
  104. package/dist/internal/exclusive-lock.d.ts.map +1 -1
  105. package/dist/internal/mutation-queue.d.ts +4 -0
  106. package/dist/internal/mutation-queue.d.ts.map +1 -0
  107. package/dist/internal/process-identity.d.ts +1 -1
  108. package/dist/internal/process-identity.d.ts.map +1 -1
  109. package/dist/internal/process-instance.d.ts +26 -0
  110. package/dist/internal/process-instance.d.ts.map +1 -0
  111. package/dist/live/watch-client-state.d.ts +71 -0
  112. package/dist/live/watch-client-state.d.ts.map +1 -0
  113. package/dist/live/watch-client.d.ts +5 -1
  114. package/dist/live/watch-client.d.ts.map +1 -1
  115. package/dist/live/watch-contract.d.ts +12 -0
  116. package/dist/live/watch-contract.d.ts.map +1 -1
  117. package/dist/react/cache-bridge.d.ts +10 -0
  118. package/dist/react/cache-bridge.d.ts.map +1 -1
  119. package/dist/tools/schema/flatten-join.d.ts.map +1 -1
  120. package/llms/agent-runtime.2.txt +94 -0
  121. package/llms/agent-runtime.3.txt +24 -0
  122. package/llms/application.2.txt +68 -2
  123. package/llms/application.txt +32 -2
  124. package/llms/files.txt +1 -1
  125. package/llms/live.txt +7 -0
  126. package/llms/react.txt +8 -0
  127. package/llms/server.3.txt +35 -0
  128. package/llms/stitchkit.2.txt +41 -0
  129. package/llms/stitchkit.3.txt +22 -0
  130. package/llms/stitchkit.txt +3 -3
  131. package/llms/tools.txt +9 -8
  132. package/llms/upgrading-0.37.0.txt +176 -0
  133. package/llms/{upgrading-0.37.0-0.58.0.txt → upgrading-0.44.0-0.60.0.txt} +229 -169
  134. package/llms/{upgrading-0.59.0-0.71.0.txt → upgrading-0.61.0-0.73.0.txt} +122 -229
  135. package/llms/{upgrading-0.72.0-0.98.0.txt → upgrading-0.74.0-0.100.0.txt} +96 -122
  136. package/llms/upgrading.txt +4 -3
  137. package/llms-full.txt +431 -14
  138. package/llms.txt +11 -10
  139. package/native/darwin-arm64.node +0 -0
  140. package/native/darwin-x64.node +0 -0
  141. package/package.json +1 -1
  142. package/dist/agent-runtime/run-mutation-queue.d.ts +0 -21
  143. package/dist/agent-runtime/run-mutation-queue.d.ts.map +0 -1
@@ -19,7 +19,7 @@ import {
19
19
  canonicalAgentJson,
20
20
  decodeAgentConversationArchive,
21
21
  encodeAgentConversationArchive
22
- } from "./index-gxrt5h6v.js";
22
+ } from "./index-cyktc4bp.js";
23
23
  import {
24
24
  AgentMessageSchema,
25
25
  AgentRecordIdSchema,
@@ -427,6 +427,37 @@ async function importConversation(driver, bytes) {
427
427
  });
428
428
  }
429
429
 
430
+ // src/agent-runtime/store-event-once.ts
431
+ import { createHash } from "node:crypto";
432
+ function appendEventOnce(driver, input, key) {
433
+ const parsed = AppendAgentStoreEventSchema.parse(input);
434
+ if (!key)
435
+ throw new TypeError("Event admission key must not be empty");
436
+ const eventId = createHash("sha256").update(JSON.stringify([parsed.conversationId, parsed.kind, key])).digest("hex");
437
+ return driver.transaction(async (transaction) => {
438
+ if (await driver.conversations?.isPurged(transaction, parsed.conversationId)) {
439
+ throw new AgentConversationPurgedError;
440
+ }
441
+ let fromSeq;
442
+ do {
443
+ const page = await driver.events.list(transaction, {
444
+ conversationId: parsed.conversationId,
445
+ fromSeq,
446
+ limit: 1e4
447
+ });
448
+ const previous = page.items.find((event2) => event2.eventId === eventId);
449
+ if (previous)
450
+ return { outcome: "duplicate", event: previous };
451
+ fromSeq = page.nextSeq;
452
+ } while (fromSeq !== undefined);
453
+ const event = await driver.events.append(transaction, {
454
+ ...agentStoreEventDraft(parsed),
455
+ eventId
456
+ });
457
+ return { outcome: "applied", event };
458
+ });
459
+ }
460
+
430
461
  // src/agent-runtime/store-mutate.ts
431
462
  import { z as z4 } from "zod";
432
463
 
@@ -453,7 +484,7 @@ function applied(current, input, effects) {
453
484
  }
454
485
 
455
486
  // src/agent-runtime/store-reducer.ts
456
- import { createHash } from "node:crypto";
487
+ import { createHash as createHash2 } from "node:crypto";
457
488
 
458
489
  // src/agent-runtime/store-reduce-history.ts
459
490
  function reduceAccept(current, input) {
@@ -737,7 +768,7 @@ function transitionRecord(operation) {
737
768
  assistant: {
738
769
  id: assistant.id,
739
770
  status: assistant.status,
740
- sha256: createHash("sha256").update(body).digest("hex"),
771
+ sha256: createHash2("sha256").update(body).digest("hex"),
741
772
  parts: assistant.parts.length,
742
773
  bytes: Buffer.byteLength(body)
743
774
  }
@@ -979,6 +1010,7 @@ function createAgentRuntimeStore(driver) {
979
1010
  loadSnapshot: (conversationId) => loadSnapshot(driver, conversationId),
980
1011
  loadRun: (input) => loadRun(driver, input),
981
1012
  listActiveRuns: (conversationId) => listActiveRuns(driver, conversationId),
1013
+ appendEventOnce: (input, key) => appendEventOnce(driver, input, key),
982
1014
  appendEvent: (input) => appendEvent(driver, input),
983
1015
  readEvents: (input) => readEvents(driver, input),
984
1016
  exportConversation: (conversationId) => exportConversation(driver, conversationId),
@@ -271,12 +271,7 @@ function typeNames(schema) {
271
271
  return combinedBranchTypes(schema);
272
272
  }
273
273
  function typeSchema(type, nullable) {
274
- const schema = { type: nullable ? [type, "null"] : type };
275
- if (type === "array")
276
- schema.items = {};
277
- if (type === "object")
278
- schema.additionalProperties = {};
279
- return schema;
274
+ return { type: nullable ? [type, "null"] : type };
280
275
  }
281
276
  function commonBaseType(schemas) {
282
277
  const names = schemas.map(typeNames);
@@ -296,6 +291,13 @@ function commonBaseType(schemas) {
296
291
  }
297
292
  if (bases.size === 0)
298
293
  return nullable ? { type: "null" } : {};
294
+ if (bases.has("array") || bases.has("object")) {
295
+ const alternatives = new Map;
296
+ for (const schema of schemas)
297
+ alternatives.set(serializeCanonicalJson(schema), schema);
298
+ const ordered = [...alternatives].sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0).map(([, schema]) => schema);
299
+ return { anyOf: structuredClone(ordered) };
300
+ }
299
301
  if (bases.size === 1) {
300
302
  const [only] = bases;
301
303
  return only ? typeSchema(only, nullable) : {};
@@ -316,7 +318,7 @@ function mergePropertySchemas(properties) {
316
318
  } else {
317
319
  const values = schemas.map(stringValues);
318
320
  const allStrings = values.every((value) => value !== null);
319
- merged = allStrings ? { type: "string", enum: [...new Set(values.flatMap((value) => value ?? []))] } : commonBaseType(schemas);
321
+ merged = allStrings ? { type: "string", enum: [...new Set(values.flatMap((value) => value ?? []))] } : commonBaseType(structural);
320
322
  }
321
323
  const descriptions = [
322
324
  ...new Set(schemas.map((schema) => schema.description).filter((value) => typeof value === "string"))
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  collectTools,
3
3
  createToolRunner
4
- } from "./index-khtgb21r.js";
4
+ } from "./index-bm5rx7n6.js";
5
5
  import {
6
6
  toolErrorFromResult
7
- } from "./index-55hkhm67.js";
7
+ } from "./index-8qt2m66q.js";
8
8
  import {
9
9
  assertUniqueToolName
10
- } from "./index-np4m8hd3.js";
10
+ } from "./index-0r0fbk7z.js";
11
11
  import {
12
12
  AppError
13
13
  } from "./index-2vtcmrj9.js";
@@ -9,7 +9,7 @@ import {
9
9
  applyToolViewDefaults,
10
10
  objectShapeKeys,
11
11
  projectToolView
12
- } from "./index-np4m8hd3.js";
12
+ } from "./index-0r0fbk7z.js";
13
13
  import {
14
14
  normalizeError,
15
15
  validateDeclaredOutput
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  contractToolMountable
3
- } from "./index-khtgb21r.js";
3
+ } from "./index-bm5rx7n6.js";
4
4
  import {
5
5
  runtimeToolMountable
6
- } from "./index-xw3s75nj.js";
6
+ } from "./index-d8m8zpd8.js";
7
7
  import {
8
8
  projectToolSurface
9
- } from "./index-np4m8hd3.js";
9
+ } from "./index-0r0fbk7z.js";
10
10
 
11
11
  // src/tools/surface.ts
12
12
  function collectToolSurface({
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  executeToolMethod,
3
3
  toolErrorFromResult
4
- } from "./index-55hkhm67.js";
4
+ } from "./index-8qt2m66q.js";
5
5
  import {
6
6
  assertToolExtensionCompatible,
7
7
  mergeSchemas,
8
8
  projectToolSurface,
9
9
  rebuildObject
10
- } from "./index-np4m8hd3.js";
10
+ } from "./index-0r0fbk7z.js";
11
11
  import {
12
12
  isRetryableStatus
13
13
  } from "./index-2vtcmrj9.js";
@@ -17,6 +17,9 @@ import { z } from "zod";
17
17
  var AgentStoreEventKindSchema = z.enum([
18
18
  "runtime/baseline",
19
19
  "runtime/transition",
20
+ "invocation/started",
21
+ "invocation/finished",
22
+ "provider/payload",
20
23
  "provider/request",
21
24
  "provider/response",
22
25
  "provider/message",
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  projectRuntimeTool
3
- } from "./index-np4m8hd3.js";
3
+ } from "./index-0r0fbk7z.js";
4
4
 
5
5
  // src/tools/runtime-tool.ts
6
6
  function defineRuntimeTool(definition) {
@@ -1,21 +1,17 @@
1
+ import {
2
+ loadDarwinBinding
3
+ } from "./index-zjjyynm3.js";
4
+
1
5
  // src/agent-runtime/contained-scan.ts
2
- import path3 from "node:path";
6
+ import path2 from "node:path";
3
7
 
4
8
  // src/agent-runtime/contained-files.ts
5
9
  import { constants } from "node:fs";
6
10
  import { lstat, mkdir, open, readdir, realpath } from "node:fs/promises";
7
- import path2 from "node:path";
11
+ import path from "node:path";
8
12
 
9
13
  // src/agent-runtime/contained-darwin.ts
10
- import {
11
- close as closeDescriptor,
12
- existsSync,
13
- fstat,
14
- read as readDescriptor
15
- } from "node:fs";
16
- import { createRequire } from "node:module";
17
- import path from "node:path";
18
- import { fileURLToPath } from "node:url";
14
+ import { close as closeDescriptor, fstat, read as readDescriptor } from "node:fs";
19
15
  var FILE_TYPE_MASK = 61440;
20
16
  var FILE_TYPE_DIRECTORY = 16384;
21
17
  var FILE_TYPE_REGULAR = 32768;
@@ -23,40 +19,6 @@ var FILE_TYPE_SYMLINK = 40960;
23
19
  function modeIs(mode, type) {
24
20
  return (mode & FILE_TYPE_MASK) === type;
25
21
  }
26
- function hasFunctions(value, names) {
27
- return typeof value === "object" && value !== null && names.every((name) => typeof Reflect.get(value, name) === "function");
28
- }
29
- var darwinBinding;
30
- function loadDarwinBinding() {
31
- if (darwinBinding)
32
- return darwinBinding;
33
- const directory = path.dirname(fileURLToPath(import.meta.url));
34
- const binary = `darwin-${process.arch}.node`;
35
- const candidates = [
36
- path.resolve(directory, "../native", binary),
37
- path.resolve(directory, "../../native", binary)
38
- ];
39
- const selected = candidates.find((candidate) => existsSync(candidate));
40
- if (!selected) {
41
- throw new Error(`Contained filesystem operations need the packaged Darwin ${process.arch} backend`);
42
- }
43
- const loaded = createRequire(import.meta.url)(selected);
44
- const methods = [
45
- "openDirectoryAt",
46
- "openFileAt",
47
- "createFileAt",
48
- "createDirectoryAt",
49
- "statAt",
50
- "listAt",
51
- "renameAt",
52
- "unlinkAt"
53
- ];
54
- if (!hasFunctions(loaded, methods)) {
55
- throw new Error("The packaged Darwin contained-files backend has an invalid surface");
56
- }
57
- darwinBinding = loaded;
58
- return darwinBinding;
59
- }
60
22
 
61
23
  class NumericFileHandle {
62
24
  fd;
@@ -110,7 +72,7 @@ async function openPinnedDirectory(absolute) {
110
72
  }
111
73
  }
112
74
  function safeSegments(relative) {
113
- if (path2.isAbsolute(relative))
75
+ if (path.isAbsolute(relative))
114
76
  throw new Error("Contained paths must be relative");
115
77
  const segments = relative.split(/[\\/]/u);
116
78
  if (segments.length === 0 || segments.some((segment) => segment === "" || segment === "." || segment === "..")) {
@@ -122,13 +84,13 @@ async function openDirectoryAt(directory, name) {
122
84
  if (process.platform === "darwin") {
123
85
  return new NumericFileHandle(loadDarwinBinding().openDirectoryAt(directory.fd, name));
124
86
  }
125
- return open(path2.join(descriptorPath(directory), name), constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
87
+ return open(path.join(descriptorPath(directory), name), constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
126
88
  }
127
89
  async function openFileAt(directory, name) {
128
90
  if (process.platform === "darwin") {
129
91
  return new NumericFileHandle(loadDarwinBinding().openFileAt(directory.fd, name));
130
92
  }
131
- return open(path2.join(descriptorPath(directory), name), constants.O_RDONLY | constants.O_NOFOLLOW);
93
+ return open(path.join(descriptorPath(directory), name), constants.O_RDONLY | constants.O_NOFOLLOW);
132
94
  }
133
95
  function entryMetadata(mode, size) {
134
96
  return {
@@ -144,7 +106,7 @@ async function statAt(directory, name) {
144
106
  const metadata = loadDarwinBinding().statAt(directory.fd, name);
145
107
  return metadata ? entryMetadata(metadata.mode, metadata.size) : null;
146
108
  }
147
- return lstat(path2.join(descriptorPath(directory), name)).catch((error) => {
109
+ return lstat(path.join(descriptorPath(directory), name)).catch((error) => {
148
110
  if (error.code === "ENOENT")
149
111
  return null;
150
112
  throw error;
@@ -176,7 +138,7 @@ async function listContainedDirectory(root, relative, maxEntries, authorizePath)
176
138
  const admitted = [];
177
139
  const denied = [];
178
140
  for (const entry of raw) {
179
- const entryPath = relative === "." ? entry.name : path2.join(relative, entry.name);
141
+ const entryPath = relative === "." ? entry.name : path.join(relative, entry.name);
180
142
  if (authorizePath && !await authorizePath(entryPath)) {
181
143
  denied.push({ name: entry.name, kind: containedEntryKind(entry) });
182
144
  continue;
@@ -217,7 +179,7 @@ async function createDirectoryAt(directory, name) {
217
179
  return loadDarwinBinding().createDirectoryAt(directory.fd, name, 511);
218
180
  }
219
181
  try {
220
- await mkdir(path2.join(descriptorPath(directory), name));
182
+ await mkdir(path.join(descriptorPath(directory), name));
221
183
  return true;
222
184
  } catch (error) {
223
185
  if (error.code === "EEXIST")
@@ -235,7 +197,7 @@ async function missingContainedDirectories(root, relative) {
235
197
  for (const segment of segments) {
236
198
  walked = [...walked, segment];
237
199
  if (missing.length > 0) {
238
- missing.push(walked.join(path2.sep));
200
+ missing.push(walked.join(path.sep));
239
201
  continue;
240
202
  }
241
203
  const next = await openDirectoryAt(current, segment).catch((error) => {
@@ -244,7 +206,7 @@ async function missingContainedDirectories(root, relative) {
244
206
  throw error;
245
207
  });
246
208
  if (!next) {
247
- missing.push(walked.join(path2.sep));
209
+ missing.push(walked.join(path.sep));
248
210
  continue;
249
211
  }
250
212
  await current.close();
@@ -373,7 +335,7 @@ async function scanContainedFiles(input) {
373
335
  const entries = [...await listAt(directory)];
374
336
  entries.sort((left, right) => left.name.localeCompare(right.name));
375
337
  for (const entry of entries) {
376
- const relative = relativeDirectory ? path3.join(relativeDirectory, entry.name) : entry.name;
338
+ const relative = relativeDirectory ? path2.join(relativeDirectory, entry.name) : entry.name;
377
339
  const kind = entry.isDirectory() ? "directory" : entry.isSymbolicLink() ? "symlink" : entry.isFile() ? "file" : "other";
378
340
  if (kind === "file" && input.includeFile && !input.includeFile(relative))
379
341
  continue;
@@ -445,4 +407,4 @@ async function scanContainedFiles(input) {
445
407
  return { files, truncated, skippedDirectories, skippedSymlinks, denied, deniedTruncated };
446
408
  }
447
409
 
448
- export { loadDarwinBinding, NumericFileHandle, descriptorPath, listContainedDirectory, missingContainedDirectories, openContainedParent, openContainedFile, assertContainedFileCurrent, assertContainedParentCurrent, containedEntryMetadata, openContainedParentFile, readContainedUtf8Handle, walkContainedFiles, scanContainedFiles };
410
+ export { NumericFileHandle, descriptorPath, listContainedDirectory, missingContainedDirectories, openContainedParent, openContainedFile, assertContainedFileCurrent, assertContainedParentCurrent, containedEntryMetadata, openContainedParentFile, readContainedUtf8Handle, walkContainedFiles, scanContainedFiles };
@@ -5,14 +5,16 @@ import {
5
5
  containedEntryMetadata,
6
6
  descriptorPath,
7
7
  listContainedDirectory,
8
- loadDarwinBinding,
9
8
  missingContainedDirectories,
10
9
  openContainedFile,
11
10
  openContainedParent,
12
11
  openContainedParentFile,
13
12
  readContainedUtf8Handle,
14
13
  scanContainedFiles
15
- } from "./index-px2gm2jp.js";
14
+ } from "./index-fhwqwxe0.js";
15
+ import {
16
+ loadDarwinBinding
17
+ } from "./index-zjjyynm3.js";
16
18
  import {
17
19
  codingPathRefusal,
18
20
  codingRefusal,
@@ -22,7 +24,7 @@ import {
22
24
  } from "./index-qmy6zq75.js";
23
25
  import {
24
26
  defineRuntimeTool
25
- } from "./index-xw3s75nj.js";
27
+ } from "./index-d8m8zpd8.js";
26
28
  import {
27
29
  conflict,
28
30
  forbidden
@@ -1,3 +1,6 @@
1
+ import {
2
+ loadDarwinBinding
3
+ } from "./index-zjjyynm3.js";
1
4
  import {
2
5
  isRecord
3
6
  } from "./index-hffjpmq9.js";
@@ -6,6 +9,7 @@ import {
6
9
  import { constants } from "node:fs";
7
10
  import { lstat, open, unlink } from "node:fs/promises";
8
11
  import { hostname } from "node:os";
12
+ import { z as z2 } from "zod";
9
13
 
10
14
  // src/internal/process-identity.ts
11
15
  import { execFile } from "node:child_process";
@@ -47,9 +51,9 @@ async function machineIdentity(declared) {
47
51
  detectedIdentity = platform() === "darwin" ? await readDarwinPlatformUuid() : await firstReadableLine(["/etc/machine-id", "/var/lib/dbus/machine-id"]);
48
52
  return detectedIdentity;
49
53
  }
50
- async function probeLiveness(pid) {
54
+ async function probeLiveness(pid, reach = (target) => process.kill(target, 0)) {
51
55
  try {
52
- process.kill(pid, 0);
56
+ reach(pid);
53
57
  } catch (error) {
54
58
  return isRecord(error) && error.code === "ESRCH" ? "gone" : "alive";
55
59
  }
@@ -73,7 +77,92 @@ async function isZombieProcess(pid, seam = {}) {
73
77
  }
74
78
  }
75
79
 
80
+ // src/internal/process-instance.ts
81
+ import { readFile as readFile2, readlink } from "node:fs/promises";
82
+ import { platform as platform2 } from "node:os";
83
+ import { z } from "zod";
84
+ var ProcessInstanceSchema = z.object({
85
+ platform: z.enum(["linux", "darwin"]),
86
+ bootId: z.string().min(1),
87
+ namespace: z.string().min(1),
88
+ startId: z.string().regex(/^\d+$/)
89
+ }).strict();
90
+ function linuxProcessStart(stat, pid) {
91
+ if (!stat.startsWith(`${pid} (`))
92
+ return null;
93
+ const end = stat.lastIndexOf(")");
94
+ if (end < 0)
95
+ return null;
96
+ const start = stat.slice(end + 1).trim().split(/\s+/)[19];
97
+ return start !== undefined && /^\d+$/.test(start) ? start : null;
98
+ }
99
+ async function readProcessInstance(pid, procRoot = "/proc") {
100
+ try {
101
+ if (platform2() === "darwin") {
102
+ const result = ProcessInstanceSchema.safeParse(loadDarwinBinding().processIdentity(pid));
103
+ return result.success ? result.data : null;
104
+ }
105
+ if (platform2() !== "linux")
106
+ return null;
107
+ const [bootId, namespace, ownStatus, timeNamespace, ownStat, stat] = await Promise.all([
108
+ readFile2(`${procRoot}/sys/kernel/random/boot_id`, "utf8"),
109
+ readlink(`${procRoot}/self/ns/pid`),
110
+ readFile2(`${procRoot}/self/status`, "utf8"),
111
+ readlink(`${procRoot}/self/ns/time`),
112
+ readFile2(`${procRoot}/self/stat`, "utf8"),
113
+ readFile2(`${procRoot}/${pid}/stat`, "utf8")
114
+ ]);
115
+ const namespacePids = ownStatus.match(/^NStgid:[ \t]*(.*)$/m)?.[1]?.trim().split(/\s+/);
116
+ if (namespacePids?.length !== 1 || namespacePids[0] !== String(process.pid) || linuxProcessStart(ownStat, process.pid) === null)
117
+ return null;
118
+ const startId = linuxProcessStart(stat, pid);
119
+ if (startId === null || !bootId.trim())
120
+ return null;
121
+ return {
122
+ platform: "linux",
123
+ bootId: bootId.trim(),
124
+ namespace: `${namespace};${timeNamespace}`,
125
+ startId
126
+ };
127
+ } catch {
128
+ return null;
129
+ }
130
+ }
131
+ async function probeProcessOwner(pid, recorded, probes = { read: readProcessInstance, liveness: probeLiveness }) {
132
+ if (recorded === undefined)
133
+ return { liveness: await probes.liveness(pid), identity: "legacy" };
134
+ const unavailable = {
135
+ liveness: "not-probed",
136
+ identity: "unavailable"
137
+ };
138
+ if (recorded === null)
139
+ return unavailable;
140
+ const current = await probes.read(process.pid);
141
+ if (!current || recorded.platform !== current.platform)
142
+ return unavailable;
143
+ if (recorded.bootId !== current.bootId)
144
+ return { liveness: "gone", identity: "different-boot" };
145
+ if (recorded.namespace !== current.namespace)
146
+ return unavailable;
147
+ const liveness = await probes.liveness(pid);
148
+ if (liveness === "gone")
149
+ return { liveness, identity: "pid-gone" };
150
+ const observed = await probes.read(pid);
151
+ if (!observed || observed.bootId !== current.bootId || observed.namespace !== current.namespace)
152
+ return unavailable;
153
+ if (recorded.startId !== observed.startId)
154
+ return { liveness: "gone", identity: "reused-pid" };
155
+ return { liveness: "alive", identity: "matched" };
156
+ }
157
+
76
158
  // src/internal/exclusive-lock.ts
159
+ var ExclusiveLockOwnerSchema = z2.object({
160
+ pid: z2.number().int().positive().max(Number.MAX_SAFE_INTEGER),
161
+ host: z2.string().min(1),
162
+ acquiredAt: z2.string(),
163
+ machine: z2.string().min(1).optional().catch(undefined),
164
+ process: ProcessInstanceSchema.nullable().optional().catch(null)
165
+ });
77
166
  function isCode(error, code) {
78
167
  return isRecord(error) && error.code === code;
79
168
  }
@@ -84,17 +173,8 @@ function readOwner(text) {
84
173
  } catch {
85
174
  return;
86
175
  }
87
- if (!isRecord(parsed))
88
- return;
89
- const { pid, host, acquiredAt, machine } = parsed;
90
- if (typeof pid !== "number" || !Number.isSafeInteger(pid) || pid <= 0)
91
- return;
92
- if (typeof host !== "string" || host.length === 0)
93
- return;
94
- if (typeof acquiredAt !== "string")
95
- return;
96
- const identified = typeof machine === "string" && machine.length > 0 ? { machine } : {};
97
- return { pid, host, acquiredAt, ...identified };
176
+ const owner = ExclusiveLockOwnerSchema.safeParse(parsed);
177
+ return owner.success ? owner.data : undefined;
98
178
  }
99
179
  function attribute(owner, identity) {
100
180
  if (identity !== null && owner.machine !== undefined) {
@@ -108,7 +188,7 @@ async function diagnose(owner, declaredIdentity) {
108
188
  const attribution = attribute(owner, await machineIdentity(declaredIdentity));
109
189
  if (attribution !== "this-machine")
110
190
  return { attribution, liveness: "not-probed", owner };
111
- return { attribution, liveness: await probeLiveness(owner.pid), owner };
191
+ return { attribution, ...await probeProcessOwner(owner.pid, owner.process), owner };
112
192
  }
113
193
  async function readLockFile(path) {
114
194
  let handle;
@@ -140,9 +220,11 @@ async function unlinkIfSame(path, ino) {
140
220
  }
141
221
  async function createOwned(path, options, reclaimed) {
142
222
  const identity = await machineIdentity(options.machineIdentity);
223
+ const instance = await readProcessInstance(process.pid);
143
224
  const handle = await open(path, "wx", options.mode);
144
225
  const owner = {
145
226
  pid: process.pid,
227
+ process: instance,
146
228
  host: hostname(),
147
229
  acquiredAt: new Date().toISOString(),
148
230
  ...identity !== null && { machine: identity }
@@ -175,6 +175,7 @@ function deltaWins(delta, value) {
175
175
  import { z as z2 } from "zod";
176
176
  var WatchKeySchema = z2.object({
177
177
  service: z2.string().min(1),
178
+ instance: z2.string().min(1).max(128).optional(),
178
179
  action: z2.string().min(1),
179
180
  digest: z2.string().min(1)
180
181
  }).strict().readonly();
@@ -221,7 +222,7 @@ var watchContract = {
221
222
  }
222
223
  };
223
224
  function watchKeyString(key) {
224
- return `${key.service}/${key.action}/${key.digest}`;
225
+ return `${key.service}/${key.action}/${key.digest}${key.instance === undefined ? "" : `/${encodeURIComponent(key.instance)}`}`;
225
226
  }
226
227
 
227
228
  export { WatchDeltaSchema, WatchArrayOpSchema, diff, apply, deltaWins, WatchKeySchema, WatchHaveSchema, WatchValueSchema, WatchStateSchema, WATCH_OPEN, WATCH_CLOSE, WATCH_VALUE, WATCH_STATE, watchContract, watchKeyString };
@@ -0,0 +1,22 @@
1
+ // src/internal/mutation-queue.ts
2
+ function createMutationQueue(maxPending = Number.POSITIVE_INFINITY) {
3
+ if (maxPending !== Number.POSITIVE_INFINITY && (!Number.isInteger(maxPending) || maxPending < 1)) {
4
+ throw new RangeError("maxPending must be a positive integer");
5
+ }
6
+ let tail = Promise.resolve();
7
+ let pending = 0;
8
+ return (mutation) => {
9
+ if (pending >= maxPending)
10
+ return Promise.reject(new Error("Mutation queue capacity exceeded"));
11
+ pending += 1;
12
+ const result = tail.then(mutation, mutation);
13
+ tail = result.then(() => {
14
+ pending -= 1;
15
+ }, () => {
16
+ pending -= 1;
17
+ });
18
+ return result;
19
+ };
20
+ }
21
+
22
+ export { createMutationQueue };
@@ -3,15 +3,15 @@ import {
3
3
  } from "./index-sbdmyz75.js";
4
4
  import {
5
5
  collectToolSurface
6
- } from "./index-hmp4800j.js";
6
+ } from "./index-9t3dffv2.js";
7
7
  import {
8
8
  createToolRunner,
9
9
  formatToolError
10
- } from "./index-khtgb21r.js";
10
+ } from "./index-bm5rx7n6.js";
11
11
  import {
12
12
  toolErrorFromResult,
13
13
  toolResultFromError
14
- } from "./index-55hkhm67.js";
14
+ } from "./index-8qt2m66q.js";
15
15
  import {
16
16
  coerceJsonArgs
17
17
  } from "./index-1zbbzgfh.js";
@@ -19,7 +19,7 @@ import {
19
19
  assertUniqueToolName,
20
20
  buildToolPresentationSchema,
21
21
  objectShapeKeys
22
- } from "./index-np4m8hd3.js";
22
+ } from "./index-0r0fbk7z.js";
23
23
  import {
24
24
  jsonSchemaFields
25
25
  } from "./index-eqqvgdb3.js";
@@ -7,12 +7,12 @@ import {
7
7
  createAgentRuntimeStore,
8
8
  isActiveRunState,
9
9
  replaceMessage
10
- } from "./index-wsm5w4ee.js";
10
+ } from "./index-0b1cnze2.js";
11
11
  import {
12
12
  AgentRecoverablePageSchema,
13
13
  AgentStoreEventEnvelopeSchema,
14
14
  AgentStoreEventPageSchema
15
- } from "./index-gxrt5h6v.js";
15
+ } from "./index-cyktc4bp.js";
16
16
  import {
17
17
  AgentMessageSchema,
18
18
  AgentRecordIdSchema
@@ -4,16 +4,16 @@ import {
4
4
  } from "./index-79z7m7dt.js";
5
5
  import {
6
6
  collectToolSurface
7
- } from "./index-hmp4800j.js";
7
+ } from "./index-9t3dffv2.js";
8
8
  import {
9
9
  createToolRunner,
10
10
  formatToolError
11
- } from "./index-khtgb21r.js";
11
+ } from "./index-bm5rx7n6.js";
12
12
  import {
13
13
  isToolExecutionControlError,
14
14
  toolCauseFromResult,
15
15
  toolResultFromError
16
- } from "./index-55hkhm67.js";
16
+ } from "./index-8qt2m66q.js";
17
17
  import {
18
18
  isRecord
19
19
  } from "./index-hffjpmq9.js";