pi-amq 0.1.1

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 (264) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/LICENSE +21 -0
  3. package/README.md +92 -0
  4. package/THIRD_PARTY_NOTICES.md +33 -0
  5. package/dist/extension/guidance.d.ts +25 -0
  6. package/dist/extension/guidance.d.ts.map +1 -0
  7. package/dist/extension/guidance.js +121 -0
  8. package/dist/extension/guidance.js.map +1 -0
  9. package/dist/extension/guide.d.ts +30 -0
  10. package/dist/extension/guide.d.ts.map +1 -0
  11. package/dist/extension/guide.js +128 -0
  12. package/dist/extension/guide.js.map +1 -0
  13. package/dist/extension/index.d.ts +4 -0
  14. package/dist/extension/index.d.ts.map +1 -0
  15. package/dist/extension/index.js +6 -0
  16. package/dist/extension/index.js.map +1 -0
  17. package/dist/extension/runtime.d.ts +48 -0
  18. package/dist/extension/runtime.d.ts.map +1 -0
  19. package/dist/extension/runtime.js +1095 -0
  20. package/dist/extension/runtime.js.map +1 -0
  21. package/dist/extension/tools.d.ts +12 -0
  22. package/dist/extension/tools.d.ts.map +1 -0
  23. package/dist/extension/tools.js +198 -0
  24. package/dist/extension/tools.js.map +1 -0
  25. package/dist/extension/worker-runtime.d.ts +34 -0
  26. package/dist/extension/worker-runtime.d.ts.map +1 -0
  27. package/dist/extension/worker-runtime.js +974 -0
  28. package/dist/extension/worker-runtime.js.map +1 -0
  29. package/dist/extension/worker-tools.d.ts +140 -0
  30. package/dist/extension/worker-tools.d.ts.map +1 -0
  31. package/dist/extension/worker-tools.js +217 -0
  32. package/dist/extension/worker-tools.js.map +1 -0
  33. package/dist/integration/confirmed-bind-onboarding.d.ts +44 -0
  34. package/dist/integration/confirmed-bind-onboarding.d.ts.map +1 -0
  35. package/dist/integration/confirmed-bind-onboarding.js +199 -0
  36. package/dist/integration/confirmed-bind-onboarding.js.map +1 -0
  37. package/dist/integration/fleet-view.d.ts +66 -0
  38. package/dist/integration/fleet-view.d.ts.map +1 -0
  39. package/dist/integration/fleet-view.js +238 -0
  40. package/dist/integration/fleet-view.js.map +1 -0
  41. package/dist/integration/fresh-session-dispatcher.d.ts +66 -0
  42. package/dist/integration/fresh-session-dispatcher.d.ts.map +1 -0
  43. package/dist/integration/fresh-session-dispatcher.js +103 -0
  44. package/dist/integration/fresh-session-dispatcher.js.map +1 -0
  45. package/dist/integration/launch-preview.d.ts +31 -0
  46. package/dist/integration/launch-preview.d.ts.map +1 -0
  47. package/dist/integration/launch-preview.js +325 -0
  48. package/dist/integration/launch-preview.js.map +1 -0
  49. package/dist/integration/transport-port.d.ts +39 -0
  50. package/dist/integration/transport-port.d.ts.map +1 -0
  51. package/dist/integration/transport-port.js +2 -0
  52. package/dist/integration/transport-port.js.map +1 -0
  53. package/dist/integration/worker-completion-notifier.d.ts +22 -0
  54. package/dist/integration/worker-completion-notifier.d.ts.map +1 -0
  55. package/dist/integration/worker-completion-notifier.js +81 -0
  56. package/dist/integration/worker-completion-notifier.js.map +1 -0
  57. package/dist/transport/amq-cli-adapter.d.ts +41 -0
  58. package/dist/transport/amq-cli-adapter.d.ts.map +1 -0
  59. package/dist/transport/amq-cli-adapter.js +291 -0
  60. package/dist/transport/amq-cli-adapter.js.map +1 -0
  61. package/dist/transport/amq-message.d.ts +47 -0
  62. package/dist/transport/amq-message.d.ts.map +1 -0
  63. package/dist/transport/amq-message.js +173 -0
  64. package/dist/transport/amq-message.js.map +1 -0
  65. package/dist/transport/amq-operations.d.ts +105 -0
  66. package/dist/transport/amq-operations.d.ts.map +1 -0
  67. package/dist/transport/amq-operations.js +320 -0
  68. package/dist/transport/amq-operations.js.map +1 -0
  69. package/dist/transport/atomic-json.d.ts +18 -0
  70. package/dist/transport/atomic-json.d.ts.map +1 -0
  71. package/dist/transport/atomic-json.js +90 -0
  72. package/dist/transport/atomic-json.js.map +1 -0
  73. package/dist/transport/binding-resolver.d.ts +46 -0
  74. package/dist/transport/binding-resolver.d.ts.map +1 -0
  75. package/dist/transport/binding-resolver.js +389 -0
  76. package/dist/transport/binding-resolver.js.map +1 -0
  77. package/dist/transport/bridge-journal.d.ts +100 -0
  78. package/dist/transport/bridge-journal.d.ts.map +1 -0
  79. package/dist/transport/bridge-journal.js +459 -0
  80. package/dist/transport/bridge-journal.js.map +1 -0
  81. package/dist/transport/dlq-retry-audit.d.ts +28 -0
  82. package/dist/transport/dlq-retry-audit.d.ts.map +1 -0
  83. package/dist/transport/dlq-retry-audit.js +66 -0
  84. package/dist/transport/dlq-retry-audit.js.map +1 -0
  85. package/dist/transport/inbox-pump.d.ts +81 -0
  86. package/dist/transport/inbox-pump.d.ts.map +1 -0
  87. package/dist/transport/inbox-pump.js +558 -0
  88. package/dist/transport/inbox-pump.js.map +1 -0
  89. package/dist/transport/index.d.ts +12 -0
  90. package/dist/transport/index.d.ts.map +1 -0
  91. package/dist/transport/index.js +12 -0
  92. package/dist/transport/index.js.map +1 -0
  93. package/dist/transport/presence-projector.d.ts +29 -0
  94. package/dist/transport/presence-projector.d.ts.map +1 -0
  95. package/dist/transport/presence-projector.js +73 -0
  96. package/dist/transport/presence-projector.js.map +1 -0
  97. package/dist/transport/priority-delivery-scheduler.d.ts +85 -0
  98. package/dist/transport/priority-delivery-scheduler.d.ts.map +1 -0
  99. package/dist/transport/priority-delivery-scheduler.js +210 -0
  100. package/dist/transport/priority-delivery-scheduler.js.map +1 -0
  101. package/dist/transport/receiver-lease.d.ts +102 -0
  102. package/dist/transport/receiver-lease.d.ts.map +1 -0
  103. package/dist/transport/receiver-lease.js +778 -0
  104. package/dist/transport/receiver-lease.js.map +1 -0
  105. package/dist/transport/runtime-status.d.ts +48 -0
  106. package/dist/transport/runtime-status.d.ts.map +1 -0
  107. package/dist/transport/runtime-status.js +71 -0
  108. package/dist/transport/runtime-status.js.map +1 -0
  109. package/dist/workflow/atomic-storage.d.ts +12 -0
  110. package/dist/workflow/atomic-storage.d.ts.map +1 -0
  111. package/dist/workflow/atomic-storage.js +104 -0
  112. package/dist/workflow/atomic-storage.js.map +1 -0
  113. package/dist/workflow/budget.d.ts +18 -0
  114. package/dist/workflow/budget.d.ts.map +1 -0
  115. package/dist/workflow/budget.js +74 -0
  116. package/dist/workflow/budget.js.map +1 -0
  117. package/dist/workflow/index.d.ts +17 -0
  118. package/dist/workflow/index.d.ts.map +1 -0
  119. package/dist/workflow/index.js +17 -0
  120. package/dist/workflow/index.js.map +1 -0
  121. package/dist/workflow/lifecycle-projection.d.ts +18 -0
  122. package/dist/workflow/lifecycle-projection.d.ts.map +1 -0
  123. package/dist/workflow/lifecycle-projection.js +22 -0
  124. package/dist/workflow/lifecycle-projection.js.map +1 -0
  125. package/dist/workflow/model-fallback.d.ts +2 -0
  126. package/dist/workflow/model-fallback.d.ts.map +1 -0
  127. package/dist/workflow/model-fallback.js +17 -0
  128. package/dist/workflow/model-fallback.js.map +1 -0
  129. package/dist/workflow/pi-session-fork.d.ts +18 -0
  130. package/dist/workflow/pi-session-fork.d.ts.map +1 -0
  131. package/dist/workflow/pi-session-fork.js +80 -0
  132. package/dist/workflow/pi-session-fork.js.map +1 -0
  133. package/dist/workflow/run-artifacts.d.ts +5 -0
  134. package/dist/workflow/run-artifacts.d.ts.map +1 -0
  135. package/dist/workflow/run-artifacts.js +25 -0
  136. package/dist/workflow/run-artifacts.js.map +1 -0
  137. package/dist/workflow/run-cleanup.d.ts +70 -0
  138. package/dist/workflow/run-cleanup.d.ts.map +1 -0
  139. package/dist/workflow/run-cleanup.js +222 -0
  140. package/dist/workflow/run-cleanup.js.map +1 -0
  141. package/dist/workflow/run-gate.d.ts +43 -0
  142. package/dist/workflow/run-gate.d.ts.map +1 -0
  143. package/dist/workflow/run-gate.js +70 -0
  144. package/dist/workflow/run-gate.js.map +1 -0
  145. package/dist/workflow/run-store.d.ts +208 -0
  146. package/dist/workflow/run-store.d.ts.map +1 -0
  147. package/dist/workflow/run-store.js +2965 -0
  148. package/dist/workflow/run-store.js.map +1 -0
  149. package/dist/workflow/spawn-confirmation.d.ts +44 -0
  150. package/dist/workflow/spawn-confirmation.d.ts.map +1 -0
  151. package/dist/workflow/spawn-confirmation.js +228 -0
  152. package/dist/workflow/spawn-confirmation.js.map +1 -0
  153. package/dist/workflow/system-process-inspector.d.ts +9 -0
  154. package/dist/workflow/system-process-inspector.d.ts.map +1 -0
  155. package/dist/workflow/system-process-inspector.js +129 -0
  156. package/dist/workflow/system-process-inspector.js.map +1 -0
  157. package/dist/workflow/worker-child-extension.d.ts +3 -0
  158. package/dist/workflow/worker-child-extension.d.ts.map +1 -0
  159. package/dist/workflow/worker-child-extension.js +182 -0
  160. package/dist/workflow/worker-child-extension.js.map +1 -0
  161. package/dist/workflow/worker-gate.d.ts +74 -0
  162. package/dist/workflow/worker-gate.d.ts.map +1 -0
  163. package/dist/workflow/worker-gate.js +165 -0
  164. package/dist/workflow/worker-gate.js.map +1 -0
  165. package/dist/workflow/worker-launch.d.ts +65 -0
  166. package/dist/workflow/worker-launch.d.ts.map +1 -0
  167. package/dist/workflow/worker-launch.js +338 -0
  168. package/dist/workflow/worker-launch.js.map +1 -0
  169. package/dist/workflow/worker-model-catalog.d.ts +36 -0
  170. package/dist/workflow/worker-model-catalog.d.ts.map +1 -0
  171. package/dist/workflow/worker-model-catalog.js +105 -0
  172. package/dist/workflow/worker-model-catalog.js.map +1 -0
  173. package/dist/workflow/worker-process-supervisor.d.ts +110 -0
  174. package/dist/workflow/worker-process-supervisor.d.ts.map +1 -0
  175. package/dist/workflow/worker-process-supervisor.js +1188 -0
  176. package/dist/workflow/worker-process-supervisor.js.map +1 -0
  177. package/dist/workflow/worker-prompt-capsule.d.ts +32 -0
  178. package/dist/workflow/worker-prompt-capsule.d.ts.map +1 -0
  179. package/dist/workflow/worker-prompt-capsule.js +52 -0
  180. package/dist/workflow/worker-prompt-capsule.js.map +1 -0
  181. package/dist/workflow/worker-role-presets.d.ts +38 -0
  182. package/dist/workflow/worker-role-presets.d.ts.map +1 -0
  183. package/dist/workflow/worker-role-presets.js +201 -0
  184. package/dist/workflow/worker-role-presets.js.map +1 -0
  185. package/dist/workflow/workflow-doctor.d.ts +57 -0
  186. package/dist/workflow/workflow-doctor.d.ts.map +1 -0
  187. package/dist/workflow/workflow-doctor.js +289 -0
  188. package/dist/workflow/workflow-doctor.js.map +1 -0
  189. package/dist/workflow/workflow-lease.d.ts +125 -0
  190. package/dist/workflow/workflow-lease.d.ts.map +1 -0
  191. package/dist/workflow/workflow-lease.js +689 -0
  192. package/dist/workflow/workflow-lease.js.map +1 -0
  193. package/dist/workflow/workflow-types.d.ts +335 -0
  194. package/dist/workflow/workflow-types.d.ts.map +1 -0
  195. package/dist/workflow/workflow-types.js +11 -0
  196. package/dist/workflow/workflow-types.js.map +1 -0
  197. package/dist/workflow/workspace-paths.d.ts +4 -0
  198. package/dist/workflow/workspace-paths.d.ts.map +1 -0
  199. package/dist/workflow/workspace-paths.js +22 -0
  200. package/dist/workflow/workspace-paths.js.map +1 -0
  201. package/docs/conformance.md +116 -0
  202. package/docs/demo-transcript.md +34 -0
  203. package/docs/design.md +1481 -0
  204. package/docs/operator-guide.md +100 -0
  205. package/extension/guidance.ts +162 -0
  206. package/extension/guide.ts +155 -0
  207. package/extension/index.ts +8 -0
  208. package/extension/runtime.ts +1224 -0
  209. package/extension/tools.ts +221 -0
  210. package/extension/worker-runtime.ts +1150 -0
  211. package/extension/worker-tools.ts +276 -0
  212. package/integration/confirmed-bind-onboarding.ts +296 -0
  213. package/integration/fleet-view.ts +286 -0
  214. package/integration/fresh-session-dispatcher.ts +166 -0
  215. package/integration/launch-preview.ts +396 -0
  216. package/integration/transport-port.ts +29 -0
  217. package/integration/worker-completion-notifier.ts +98 -0
  218. package/package.json +55 -0
  219. package/roles/oracle.md +9 -0
  220. package/roles/researcher.md +8 -0
  221. package/roles/reviewer.md +9 -0
  222. package/roles/scout.md +8 -0
  223. package/roles/worker.md +10 -0
  224. package/scripts/demo-two-terminal.sh +59 -0
  225. package/skills/coordination-patterns/SKILL.md +41 -0
  226. package/skills/coordination-patterns/references/supervised-worker-fan-out.md +12 -0
  227. package/skills/coordination-patterns/references/today-mail-team.md +36 -0
  228. package/transport/amq-cli-adapter.ts +381 -0
  229. package/transport/amq-message.ts +218 -0
  230. package/transport/amq-operations.ts +482 -0
  231. package/transport/atomic-json.ts +115 -0
  232. package/transport/binding-resolver.ts +565 -0
  233. package/transport/bridge-journal.ts +588 -0
  234. package/transport/dlq-retry-audit.ts +97 -0
  235. package/transport/inbox-pump.ts +729 -0
  236. package/transport/index.ts +11 -0
  237. package/transport/presence-projector.ts +104 -0
  238. package/transport/priority-delivery-scheduler.ts +328 -0
  239. package/transport/receiver-lease.ts +945 -0
  240. package/transport/runtime-status.ts +112 -0
  241. package/workflow/.gitkeep +1 -0
  242. package/workflow/atomic-storage.ts +120 -0
  243. package/workflow/budget.ts +90 -0
  244. package/workflow/index.ts +16 -0
  245. package/workflow/lifecycle-projection.ts +37 -0
  246. package/workflow/model-fallback.ts +17 -0
  247. package/workflow/pi-session-fork.ts +96 -0
  248. package/workflow/run-artifacts.ts +36 -0
  249. package/workflow/run-cleanup.ts +315 -0
  250. package/workflow/run-gate.ts +122 -0
  251. package/workflow/run-store.ts +3890 -0
  252. package/workflow/spawn-confirmation.ts +305 -0
  253. package/workflow/system-process-inspector.ts +142 -0
  254. package/workflow/worker-child-extension.ts +193 -0
  255. package/workflow/worker-gate.ts +238 -0
  256. package/workflow/worker-launch.ts +485 -0
  257. package/workflow/worker-model-catalog.ts +165 -0
  258. package/workflow/worker-process-supervisor.ts +1504 -0
  259. package/workflow/worker-prompt-capsule.ts +81 -0
  260. package/workflow/worker-role-presets.ts +241 -0
  261. package/workflow/workflow-doctor.ts +400 -0
  262. package/workflow/workflow-lease.ts +905 -0
  263. package/workflow/workflow-types.ts +367 -0
  264. package/workflow/workspace-paths.ts +32 -0
@@ -0,0 +1,129 @@
1
+ import { execFile } from "node:child_process";
2
+ import { readFile, readlink } from "node:fs/promises";
3
+ import { hostname } from "node:os";
4
+ import { isAbsolute, normalize } from "node:path";
5
+ import { promisify } from "node:util";
6
+ const execFileAsync = promisify(execFile);
7
+ /** Reads PID-reuse-resistant identity evidence without treating age or timeout as death proof. */
8
+ export class SystemProcessIdentityInspector {
9
+ async current() {
10
+ const inspection = await this.inspect(process.pid);
11
+ if (inspection.kind !== "live") {
12
+ throw new Error(inspection.kind === "unknown"
13
+ ? `Current process identity is unavailable: ${inspection.diagnostic}`
14
+ : "Current process disappeared during identity inspection");
15
+ }
16
+ return inspection.identity;
17
+ }
18
+ async inspect(pid) {
19
+ if (!Number.isSafeInteger(pid) || pid <= 0) {
20
+ return { kind: "unknown", diagnostic: "PID must be a positive integer" };
21
+ }
22
+ if (process.platform === "linux")
23
+ return inspectLinux(pid);
24
+ if (process.platform === "darwin")
25
+ return inspectDarwin(pid);
26
+ return {
27
+ kind: "unknown",
28
+ diagnostic: `Process start identity is unsupported on ${process.platform}`,
29
+ };
30
+ }
31
+ }
32
+ async function inspectLinux(pid) {
33
+ try {
34
+ const [stat, executable, bootIdentity] = await Promise.all([
35
+ readFile(`/proc/${pid}/stat`, "utf8"),
36
+ readlink(`/proc/${pid}/exe`),
37
+ readFile("/proc/sys/kernel/random/boot_id", "utf8"),
38
+ ]);
39
+ const closing = stat.lastIndexOf(")");
40
+ if (closing < 0)
41
+ return { kind: "unknown", diagnostic: "Linux process stat is malformed" };
42
+ const fields = stat.slice(closing + 2).trim().split(/\s+/);
43
+ const startTicks = fields[19];
44
+ if (!startTicks)
45
+ return { kind: "unknown", diagnostic: "Linux process start ticks are missing" };
46
+ return {
47
+ kind: "live",
48
+ identity: {
49
+ pid,
50
+ processStartIdentity: `linux-start-ticks:${startTicks}`,
51
+ bootIdentity: bootIdentity.trim() || null,
52
+ executable: normalize(executable),
53
+ hostname: hostname(),
54
+ },
55
+ };
56
+ }
57
+ catch (error) {
58
+ return classifyInspectionFailure(error, pid);
59
+ }
60
+ }
61
+ async function inspectDarwin(pid) {
62
+ try {
63
+ const [{ stdout }, boot] = await Promise.all([
64
+ execFileAsync("ps", ["-p", String(pid), "-o", "lstart=", "-o", "comm="], {
65
+ encoding: "utf8",
66
+ maxBuffer: 8_192,
67
+ timeout: 2_000,
68
+ }),
69
+ execFileAsync("sysctl", ["-n", "kern.boottime"], {
70
+ encoding: "utf8",
71
+ maxBuffer: 8_192,
72
+ timeout: 2_000,
73
+ }),
74
+ ]);
75
+ const line = stdout.trim();
76
+ if (line.length === 0)
77
+ return { kind: "absent" };
78
+ const start = line.slice(0, 24).trim();
79
+ const psExecutable = line.slice(24).trim();
80
+ if (start.length === 0) {
81
+ return { kind: "unknown", diagnostic: "Darwin ps start identity is incomplete" };
82
+ }
83
+ const executable = selectDarwinExecutable(psExecutable, pid === process.pid ? process.execPath : null);
84
+ if (executable === null) {
85
+ return { kind: "unknown", diagnostic: "Darwin process executable is unavailable" };
86
+ }
87
+ return {
88
+ kind: "live",
89
+ identity: {
90
+ pid,
91
+ processStartIdentity: `darwin-lstart:${start}`,
92
+ bootIdentity: boot.stdout.trim() || null,
93
+ executable,
94
+ hostname: hostname(),
95
+ },
96
+ };
97
+ }
98
+ catch (error) {
99
+ return classifyInspectionFailure(error, pid);
100
+ }
101
+ }
102
+ /** Uses current-process evidence only when ps reports a relative argv[0]. */
103
+ export function selectDarwinExecutable(psExecutable, currentExecutable) {
104
+ const reported = psExecutable.trim();
105
+ if (isAbsolute(reported))
106
+ return normalize(reported);
107
+ if (currentExecutable !== null && isAbsolute(currentExecutable)) {
108
+ return normalize(currentExecutable);
109
+ }
110
+ return null;
111
+ }
112
+ function classifyInspectionFailure(error, pid) {
113
+ if (isNodeError(error) && (error.code === "ENOENT" || error.code === "ESRCH")) {
114
+ return { kind: "absent" };
115
+ }
116
+ if (isExecFailure(error) && error.code === 1)
117
+ return { kind: "absent" };
118
+ return {
119
+ kind: "unknown",
120
+ diagnostic: `Could not inspect PID ${pid}: ${error instanceof Error ? error.message : String(error)}`,
121
+ };
122
+ }
123
+ function isNodeError(error) {
124
+ return error instanceof Error && "code" in error;
125
+ }
126
+ function isExecFailure(error) {
127
+ return error instanceof Error && "code" in error && typeof error.code === "number";
128
+ }
129
+ //# sourceMappingURL=system-process-inspector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-process-inspector.js","sourceRoot":"","sources":["../../workflow/system-process-inspector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAQtC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C,kGAAkG;AAClG,MAAM,OAAO,8BAA8B;IACzC,KAAK,CAAC,OAAO;QACX,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACnD,IAAI,UAAU,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CACb,UAAU,CAAC,IAAI,KAAK,SAAS;gBAC3B,CAAC,CAAC,4CAA4C,UAAU,CAAC,UAAU,EAAE;gBACrE,CAAC,CAAC,wDAAwD,CAC7D,CAAC;QACJ,CAAC;QACD,OAAO,UAAU,CAAC,QAAQ,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAW;QACvB,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC;YAC3C,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,gCAAgC,EAAE,CAAC;QAC3E,CAAC;QACD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;YAAE,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AK,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IACxE,OAAO;QACL,IAAI,EAAE,SAAS;QACf,UAAU,EAAE,yBAAyB,GAAG,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;KACtG,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC;AACnD,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;AACrF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ export default function workerChildExtension(pi: ExtensionAPI): void;
3
+ //# sourceMappingURL=worker-child-extension.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-child-extension.d.ts","sourceRoot":"","sources":["../../workflow/worker-child-extension.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,iCAAiC,CAAC;AAWtF,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CA2HnE"}
@@ -0,0 +1,182 @@
1
+ import { createReadStream, readFileSync } from "node:fs";
2
+ import { Type } from "typebox";
3
+ import { parseWorkerLaunchContractV1, validateWorkerChildContext, } from "./worker-launch.js";
4
+ import { classifyProviderFallbackFailure } from "./model-fallback.js";
5
+ export default function workerChildExtension(pi) {
6
+ const loaded = loadLaunchContract();
7
+ if (!loaded.ok) {
8
+ pi.on("session_start", (_event, ctx) => refuse(loaded.error, ctx));
9
+ pi.on("before_agent_start", (_event, ctx) => refuse(loaded.error, ctx));
10
+ return;
11
+ }
12
+ const contract = loaded.contract;
13
+ let ready = false;
14
+ pi.registerTool({
15
+ name: "message_worker",
16
+ label: "Message Worker",
17
+ description: "Request one directionally granted peer message through the parent supervisor.",
18
+ parameters: Type.Object({
19
+ target: Type.String({ minLength: 1, maxLength: 256 }),
20
+ message: Type.String({ minLength: 1, maxLength: 32_768 }),
21
+ correlation: Type.String({ minLength: 1, maxLength: 256 }),
22
+ }),
23
+ async execute(_id, params) {
24
+ writeProtocolLine({
25
+ type: "pi_amq_worker_peer_message",
26
+ runId: contract.runId,
27
+ workerId: contract.workerId,
28
+ attemptId: contract.attemptId,
29
+ workerAttemptGeneration: contract.workerAttemptGeneration,
30
+ supervisorGeneration: contract.supervisorGeneration,
31
+ target: params.target,
32
+ message: params.message,
33
+ correlation: params.correlation,
34
+ });
35
+ const details = { status: "requested", target: params.target, correlation: params.correlation };
36
+ return { content: [{ type: "text", text: JSON.stringify(details) }], details };
37
+ },
38
+ });
39
+ pi.registerTool({
40
+ name: "wait_for_input",
41
+ label: "Wait for Input",
42
+ description: "Declare a typed correlated wait without inferring waiting from prose or silence.",
43
+ parameters: Type.Object({
44
+ reason: Type.String({ minLength: 1, maxLength: 2_048 }),
45
+ correlation: Type.String({ minLength: 1, maxLength: 256 }),
46
+ }),
47
+ async execute(_id, params) {
48
+ writeProtocolLine({
49
+ type: "pi_amq_worker_wait",
50
+ runId: contract.runId,
51
+ workerId: contract.workerId,
52
+ attemptId: contract.attemptId,
53
+ workerAttemptGeneration: contract.workerAttemptGeneration,
54
+ supervisorGeneration: contract.supervisorGeneration,
55
+ reason: params.reason,
56
+ correlation: params.correlation,
57
+ });
58
+ const details = {
59
+ status: "declared",
60
+ reason: params.reason,
61
+ correlation: params.correlation,
62
+ };
63
+ return { content: [{ type: "text", text: JSON.stringify(details) }], details };
64
+ },
65
+ });
66
+ pi.on("session_start", (_event, ctx) => {
67
+ try {
68
+ validateWorkerChildContext(contract, childContext(ctx));
69
+ attachParentLiveness(contract, ctx);
70
+ const sessionFile = ctx.sessionManager.getSessionFile();
71
+ if (!sessionFile)
72
+ throw new Error("Pi worker session file is unavailable");
73
+ writeProtocolLine({
74
+ type: "pi_amq_worker_ready",
75
+ runId: contract.runId,
76
+ workerId: contract.workerId,
77
+ attemptId: contract.attemptId,
78
+ workerAttemptGeneration: contract.workerAttemptGeneration,
79
+ supervisorGeneration: contract.supervisorGeneration,
80
+ sessionFile,
81
+ });
82
+ ready = true;
83
+ }
84
+ catch (error) {
85
+ refuse(error, ctx);
86
+ }
87
+ });
88
+ pi.on("before_agent_start", (event, ctx) => {
89
+ try {
90
+ if (!ready)
91
+ throw new Error("Worker launch parity was not established");
92
+ validateWorkerChildContext(contract, childContext(ctx, event.systemPromptOptions.selectedTools));
93
+ }
94
+ catch (error) {
95
+ refuse(error, ctx);
96
+ }
97
+ });
98
+ pi.on("model_select", (_event, ctx) => revalidateOrRefuse(contract, ctx));
99
+ pi.on("thinking_level_select", (_event, ctx) => revalidateOrRefuse(contract, ctx));
100
+ pi.on("agent_settled", () => {
101
+ if (!ready)
102
+ return;
103
+ writeProtocolLine({
104
+ type: "pi_amq_worker_settled",
105
+ runId: contract.runId,
106
+ workerId: contract.workerId,
107
+ attemptId: contract.attemptId,
108
+ workerAttemptGeneration: contract.workerAttemptGeneration,
109
+ supervisorGeneration: contract.supervisorGeneration,
110
+ });
111
+ });
112
+ pi.on("message_end", (event, ctx) => {
113
+ const message = event.message;
114
+ if (message.role !== "assistant")
115
+ return;
116
+ const reason = classifyProviderFallbackFailure(message.stopReason, message.errorMessage);
117
+ if (!reason)
118
+ return;
119
+ writeProtocolLine({
120
+ type: "pi_amq_worker_provider_failure",
121
+ runId: contract.runId,
122
+ workerId: contract.workerId,
123
+ attemptId: contract.attemptId,
124
+ workerAttemptGeneration: contract.workerAttemptGeneration,
125
+ supervisorGeneration: contract.supervisorGeneration,
126
+ reason,
127
+ });
128
+ ctx.shutdown();
129
+ });
130
+ }
131
+ function loadLaunchContract() {
132
+ try {
133
+ const path = process.env["PI_AMQ_WORKER_LAUNCH_CONTRACT"];
134
+ if (!path)
135
+ throw new Error("PI_AMQ_WORKER_LAUNCH_CONTRACT is required");
136
+ const value = JSON.parse(readFileSync(path, "utf8"));
137
+ return { ok: true, contract: parseWorkerLaunchContractV1(value) };
138
+ }
139
+ catch (error) {
140
+ return { ok: false, error: error instanceof Error ? error : new Error(String(error)) };
141
+ }
142
+ }
143
+ function childContext(ctx, tools) {
144
+ return {
145
+ mode: ctx.mode,
146
+ cwd: ctx.cwd,
147
+ model: ctx.model ? { provider: ctx.model.provider, id: ctx.model.id } : undefined,
148
+ thinkingLevel: ctx.thinkingLevel,
149
+ projectTrusted: ctx.isProjectTrusted(),
150
+ ...(tools === undefined ? {} : { tools }),
151
+ environmentKeys: Object.keys(process.env),
152
+ };
153
+ }
154
+ function revalidateOrRefuse(contract, ctx) {
155
+ try {
156
+ validateWorkerChildContext(contract, childContext(ctx));
157
+ }
158
+ catch (error) {
159
+ refuse(error, ctx);
160
+ }
161
+ }
162
+ function attachParentLiveness(contract, ctx) {
163
+ const configured = Number(process.env["PI_AMQ_PARENT_LIVENESS_FD"]);
164
+ if (configured !== contract.parentLivenessFd) {
165
+ throw new Error("Parent-liveness descriptor does not match the launch contract");
166
+ }
167
+ const stream = createReadStream("", { fd: configured, autoClose: false });
168
+ stream.on("end", () => ctx.shutdown());
169
+ stream.on("error", () => ctx.shutdown());
170
+ stream.resume();
171
+ }
172
+ function refuse(error, ctx) {
173
+ writeProtocolLine({
174
+ type: "pi_amq_worker_refused",
175
+ error: error instanceof Error ? error.message : String(error),
176
+ });
177
+ ctx.shutdown();
178
+ }
179
+ function writeProtocolLine(value) {
180
+ process.stdout.write(`${JSON.stringify(value)}\n`);
181
+ }
182
+ //# sourceMappingURL=worker-child-extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-child-extension.js","sourceRoot":"","sources":["../../workflow/worker-child-extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,M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AAE,GAAG,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IACvC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IACzC,MAAM,CAAC,MAAM,EAAE,CAAC;AAClB,CAAC;AAED,SAAS,MAAM,CAAC,KAAc,EAAE,GAAqB;IACnD,iBAAiB,CAAC;QAChB,IAAI,EAAE,uBAAuB;QAC7B,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;KAC9D,CAAC,CAAC;IACH,GAAG,CAAC,QAAQ,EAAE,CAAC;AACjB,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAc;IACvC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACrD,CAAC"}
@@ -0,0 +1,74 @@
1
+ import type { ReportSchemaV1 } from "./workflow-types.js";
2
+ export declare const WORKER_ATTEMPT_STATES: readonly ["pending", "running", "blocked", "ambiguous", "done", "failed", "cancelled"];
3
+ export type WorkerAttemptState = (typeof WORKER_ATTEMPT_STATES)[number];
4
+ export declare function normalizeWorkerAttemptState(value: unknown): WorkerAttemptState;
5
+ export interface WorkerGateFacts {
6
+ readonly evidence: {
7
+ readonly exists: boolean;
8
+ };
9
+ readonly report: {
10
+ readonly schemaDeclared: boolean;
11
+ readonly matches: boolean;
12
+ };
13
+ readonly acceptanceCheck: {
14
+ readonly declared: boolean;
15
+ readonly exitCode: number | null;
16
+ };
17
+ readonly human: {
18
+ readonly approvalRequired: boolean;
19
+ readonly approved: boolean;
20
+ };
21
+ readonly budget: {
22
+ readonly exceeded: boolean;
23
+ };
24
+ readonly runtime: {
25
+ readonly supervisorLost: boolean;
26
+ readonly effectsUncertain: boolean;
27
+ readonly certain?: boolean;
28
+ };
29
+ readonly failure?: {
30
+ readonly observed: boolean;
31
+ };
32
+ readonly termination?: {
33
+ readonly observed: boolean;
34
+ };
35
+ readonly wait?: {
36
+ readonly declared: boolean;
37
+ };
38
+ readonly reconcile: {
39
+ readonly decisionExists: boolean;
40
+ readonly uncertaintyCleared?: boolean;
41
+ };
42
+ readonly input: {
43
+ readonly kind: "revise_contract" | "steer" | "peer_message" | null;
44
+ readonly correlationMatches: boolean;
45
+ };
46
+ readonly cancel: {
47
+ readonly verbReceived: boolean;
48
+ };
49
+ }
50
+ export type WorkerGateGuard = "evidence.exists" | "report.matches(report_schema)" | "acceptance_check.exit == 0" | "human.approved" | "budget.not_exceeded" | "runtime.uncertain" | "runtime.certain" | "failure.observed" | "termination.observed" | "wait.declared" | "reconcile.decision.exists" | "reconcile.uncertainty.cleared" | "input.is_new" | "input.correlation_matches" | "cancel.verb";
51
+ export interface WorkerAttemptTransitionRule {
52
+ readonly from: WorkerAttemptState;
53
+ readonly to: WorkerAttemptState;
54
+ readonly guards: readonly WorkerGateGuard[];
55
+ }
56
+ export declare const WORKER_ATTEMPT_LEGALITY_TABLE: readonly WorkerAttemptTransitionRule[];
57
+ export type WorkerAttemptTransitionResult = {
58
+ readonly allowed: true;
59
+ } | {
60
+ readonly allowed: false;
61
+ readonly reason: "undeclared-transition" | "guard-failed";
62
+ readonly blockers: readonly WorkerGateGuard[];
63
+ };
64
+ export declare function evaluateWorkerAttemptTransition(from: WorkerAttemptState, to: WorkerAttemptState, facts: WorkerGateFacts): WorkerAttemptTransitionResult;
65
+ export declare const TERMINAL_ATTEMPT_PRIORITY: readonly ["ambiguous", "cancelled", "failed", "running"];
66
+ export declare function classifyObservedTermination(input: {
67
+ readonly runtimeCertain: boolean;
68
+ readonly effectsUncertain: boolean;
69
+ readonly cancellationRequested: boolean;
70
+ readonly terminationObserved: boolean;
71
+ readonly failureObserved: boolean;
72
+ }): WorkerAttemptState;
73
+ export declare function reportMatchesSchema(schema: ReportSchemaV1, report: unkn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AE,KAAK,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,uBAAuB,GAAG,cAAc,CAAC;IAC1D,QAAQ,CAAC,QAAQ,EAAE,SAAS,eAAe,EAAE,CAAC;CAC/C,CAAC;AAEN,wBAAgB,+BAA+B,CAC7C,IAAI,EAAE,kBAAkB,EACxB,EAAE,EAAE,kBAAkB,EACtB,KAAK,EAAE,eAAe,GACrB,6BAA6B,CAY/B;AAwCD,eAAO,MAAM,yBAAyB,0DAA2D,CAAC;AAElG,wBAAgB,2BAA2B,CAAC,KAAK,EAAE;IACjD,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;IACnC,QAAQ,CAAC,qBAAqB,EAAE,OAAO,CAAC;IACxC,QAAQ,CAAC,mBAAmB,EAAE,OAAO,CAAC;IACtC,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;CACnC,GAAG,kBAAkB,CAKrB;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAUpF"}
@@ -0,0 +1,165 @@
1
+ export const WORKER_ATTEMPT_STATES = [
2
+ "pending",
3
+ "running",
4
+ "blocked",
5
+ "ambiguous",
6
+ "done",
7
+ "failed",
8
+ "cancelled",
9
+ ];
10
+ export function normalizeWorkerAttemptState(value) {
11
+ switch (value) {
12
+ case "spawn-intent":
13
+ return "pending";
14
+ case "exited":
15
+ return "running";
16
+ case "pending":
17
+ case "running":
18
+ case "blocked":
19
+ case "ambiguous":
20
+ case "done":
21
+ case "failed":
22
+ case "cancelled":
23
+ return value;
24
+ default:
25
+ throw new TypeError("worker attempt state is invalid");
26
+ }
27
+ }
28
+ const DONE_GUARDS = [
29
+ "runtime.certain",
30
+ "evidence.exists",
31
+ "report.matches(report_schema)",
32
+ "acceptance_check.exit == 0",
33
+ "human.approved",
34
+ "budget.not_exceeded",
35
+ ];
36
+ const RECONCILE_GUARDS = [
37
+ "reconcile.decision.exists",
38
+ "reconcile.uncertainty.cleared",
39
+ ];
40
+ const CANCELLED_GUARDS = [
41
+ "cancel.verb",
42
+ "termination.observed",
43
+ "runtime.certain",
44
+ ];
45
+ export const WORKER_ATTEMPT_LEGALITY_TABLE = [
46
+ { from: "pending", to: "running", guards: [] },
47
+ { from: "pending", to: "failed", guards: ["failure.observed"] },
48
+ { from: "pending", to: "ambiguous", guards: ["runtime.uncertain"] },
49
+ { from: "pending", to: "cancelled", guards: CANCELLED_GUARDS },
50
+ { from: "running", to: "blocked", guards: ["wait.declared"] },
51
+ { from: "running", to: "done", guards: DONE_GUARDS },
52
+ { from: "running", to: "failed", guards: ["failure.observed"] },
53
+ { from: "running", to: "ambiguous", guards: ["runtime.uncertain"] },
54
+ { from: "running", to: "cancelled", guards: CANCELLED_GUARDS },
55
+ {
56
+ from: "blocked",
57
+ to: "running",
58
+ guards: ["input.is_new", "input.correlation_matches"],
59
+ },
60
+ { from: "blocked", to: "failed", guards: ["failure.observed"] },
61
+ { from: "blocked", to: "ambiguous", guards: ["runtime.uncertain"] },
62
+ { from: "blocked", to: "cancelled", guards: CANCELLED_GUARDS },
63
+ { from: "ambiguous", to: "pending", guards: RECONCILE_GUARDS },
64
+ { from: "ambiguous", to: "running", guards: RECONCILE_GUARDS },
65
+ { from: "ambiguous", to: "blocked", guards: [...RECONCILE_GUARDS, "wait.declared"] },
66
+ { from: "ambiguous", to: "done", guards: [...RECONCILE_GUARDS, ...DONE_GUARDS] },
67
+ { from: "ambiguous", to: "failed", guards: [...RECONCILE_GUARDS, "failure.observed"] },
68
+ {
69
+ from: "ambiguous",
70
+ to: "cancelled",
71
+ guards: [...RECONCILE_GUARDS, ...CANCELLED_GUARDS],
72
+ },
73
+ ];
74
+ export function evaluateWorkerAttemptTransition(from, to, facts) {
75
+ const rule = WORKER_ATTEMPT_LEGALITY_TABLE.find((candidate) => candidate.from === from && candidate.to === to);
76
+ if (!rule) {
77
+ return { allowed: false, reason: "undeclared-transition", blockers: [] };
78
+ }
79
+ const blockers = rule.guards.filter((guard) => !guardSatisfied(guard, facts));
80
+ return blockers.length === 0
81
+ ? { allowed: true }
82
+ : { allowed: false, reason: "guard-failed", blockers };
83
+ }
84
+ function guardSatisfied(guard, facts) {
85
+ switch (guard) {
86
+ case "evidence.exists":
87
+ return facts.evidence.exists;
88
+ case "report.matches(report_schema)":
89
+ return !facts.report.schemaDeclared || facts.report.matches;
90
+ case "acceptance_check.exit == 0":
91
+ return !facts.acceptanceCheck.declared || facts.acceptanceCheck.exitCode === 0;
92
+ case "human.approved":
93
+ return !facts.human.approvalRequired || facts.human.approved;
94
+ case "budget.not_exceeded":
95
+ return !facts.budget.exceeded;
96
+ case "runtime.uncertain":
97
+ return facts.runtime.supervisorLost || facts.runtime.effectsUncertain;
98
+ case "runtime.certain":
99
+ return facts.runtime.certain === true
100
+ || (!facts.runtime.supervisorLost && !facts.runtime.effectsUncertain);
101
+ case "failure.observed":
102
+ return facts.failure?.observed === true;
103
+ case "termination.observed":
104
+ return facts.termination?.observed === true;
105
+ case "wait.declared":
106
+ return facts.wait?.declared === true;
107
+ case "reconcile.decision.exists":
108
+ return facts.reconcile.decisionExists;
109
+ case "reconcile.uncertainty.cleared":
110
+ return facts.reconcile.uncertaintyCleared === true;
111
+ case "input.is_new":
112
+ return facts.input.kind === "revise_contract"
113
+ || facts.input.kind === "steer"
114
+ || facts.input.kind === "peer_message";
115
+ case "input.correlation_matches":
116
+ return facts.input.correlationMatches;
117
+ case "cancel.verb":
118
+ return facts.cancel.verbReceived;
119
+ }
120
+ }
121
+ export const TERMINAL_ATTEMPT_PRIORITY = ["ambiguous", "cancelled", "failed", "running"];
122
+ export function classifyObservedTermination(input) {
123
+ if (!input.runtimeCertain || input.effectsUncertain)
124
+ return "ambiguous";
125
+ if (input.cancellationRequested && input.terminationObserved)
126
+ return "cancelled";
127
+ if (input.failureObserved)
128
+ return "failed";
129
+ return "running";
130
+ }
131
+ export function reportMatchesSchema(schema, report) {
132
+ if (!isRecord(report))
133
+ return false;
134
+ for (const required of schema.required) {
135
+ if (!Object.prototype.hasOwnProperty.call(report, required))
136
+ return false;
137
+ }
138
+ for (const [name, field] of Object.entries(schema.properties)) {
139
+ if (!Object.prototype.hasOwnProperty.call(report, name))
140
+ continue;
141
+ if (!matchesFieldType(field, report[name]))
142
+ return false;
143
+ }
144
+ return true;
145
+ }
146
+ function matchesFieldType(field, value) {
147
+ switch (field.type) {
148
+ case "string":
149
+ return typeof value === "string";
150
+ case "number":
151
+ return typeof value === "number" && Number.isFinite(value);
152
+ case "boolean":
153
+ return typeof value === "boolean";
154
+ case "object":
155
+ return isRecord(value);
156
+ case "array":
157
+ return Array.isArray(value);
158
+ case "null":
159
+ return value === null;
160
+ }
161
+ }
162
+ function isRecord(value) {
163
+ return typeof value === "object" && value !== null && !Array.isArray(value);
164
+ }
165
+ //# sourceMappingURL=worker-gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-gate.js","sourceRoot":"","sources":["../../workflow/worker-gate.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,SAAS;IACT,SAAS;IACT,SAAS;IACT,WAAW;IACX,MAAM;IACN,QAAQ;IACR,WAAW;CACH,CAAC;AAIX,MAAM,UAAU,2BAA2B,CAAC,KAAc;IACxD,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,cAAc;YACjB,OAAO,SAAS,CAAC;QACnB,KAAK,QAAQ;YACX,OAAO,SAAS,CAAC;QACnB,KAAK,SAAS,CAAC;QACf,KAAK,SAAS,CAAC;QACf,KAAK,SAAS,CAAC;QACf,KAAK,WAAW,CAAC;QACjB,KAAK,MAAM,CAAC;QACZ,KAAK,QAAQ,CAAC;QACd,KAAK,WAAW;YACd,OAAO,KAAK,CAAC;QACf;YACE,MAAM,IAAI,SAAS,CAAC,iCAAiC,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC;AA+CD,MAAM,WAAW,GAA+B;IAC9C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