@nativestudio/cli 0.3.0-rc.2 → 0.3.0-rc.21

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 (283) hide show
  1. package/COMPATIBILITY.json +37 -8
  2. package/LICENSE +201 -21
  3. package/components/runtime.json +33 -4
  4. package/components/runtime.tgz +0 -0
  5. package/dist/_chunks/chunk-27KI24GK.js +1 -0
  6. package/dist/_chunks/chunk-2S7FI3HF.js +1 -0
  7. package/dist/_chunks/chunk-3RNDOAQI.js +1 -0
  8. package/dist/_chunks/{chunk-C33A2DW4.js → chunk-3TOXIJ7K.js} +1 -1
  9. package/dist/_chunks/chunk-4AD4PNUX.js +1 -0
  10. package/dist/_chunks/chunk-5Y7J2OYL.js +45 -0
  11. package/dist/_chunks/chunk-76E5R3OC.js +1 -0
  12. package/dist/_chunks/chunk-7I7ARCY7.js +1 -0
  13. package/dist/_chunks/chunk-7IVAYDU3.js +1 -0
  14. package/dist/_chunks/chunk-7P2NA6TH.js +1 -0
  15. package/dist/_chunks/chunk-DLW42PJ6.js +1 -0
  16. package/dist/_chunks/chunk-DMA53YVU.js +1 -0
  17. package/dist/_chunks/chunk-ETK7GYCB.js +1 -0
  18. package/dist/_chunks/chunk-FFXSXE3G.js +1 -0
  19. package/dist/_chunks/chunk-H4FH6STZ.js +1 -0
  20. package/dist/_chunks/chunk-KOCUZ3AE.js +1 -0
  21. package/dist/_chunks/chunk-LDBXGRCQ.js +1 -0
  22. package/dist/_chunks/chunk-LTNJ45JP.js +1 -0
  23. package/dist/_chunks/chunk-MZWEFYHE.js +1 -0
  24. package/dist/_chunks/{chunk-VDNNFVTZ.js → chunk-OW6R4MAQ.js} +1 -1
  25. package/dist/_chunks/chunk-PQCA4X5H.js +1 -0
  26. package/dist/_chunks/chunk-QGK6G6YS.js +1 -0
  27. package/dist/_chunks/chunk-SM2I7TJ3.js +1 -0
  28. package/dist/_chunks/chunk-TT7IA5HB.js +1 -0
  29. package/dist/_chunks/chunk-VXYZCCCQ.js +1 -0
  30. package/dist/_chunks/chunk-VYCNG6TR.js +1 -0
  31. package/dist/_chunks/chunk-WLQMICJN.js +1 -0
  32. package/dist/_chunks/chunk-WTJVS2VS.js +1 -0
  33. package/dist/_chunks/chunk-X5MVC46N.js +1 -0
  34. package/dist/_chunks/chunk-X5PBZTKX.js +1 -0
  35. package/dist/_chunks/chunk-ZMJYBUS3.js +1 -0
  36. package/dist/_chunks/chunk-ZYXHPTT2.js +1 -0
  37. package/dist/_chunks/component-contract-2JHTRTOB.js +1 -0
  38. package/dist/_chunks/component-preflight-6OWDQAZT.js +1 -0
  39. package/dist/_chunks/connect-7TJDWXV4.js +1 -0
  40. package/dist/_chunks/device-management-JPS4HG34.js +1 -0
  41. package/dist/_chunks/device-preflight-GTQ67H7C.js +1 -0
  42. package/dist/_chunks/devices-inventory-E6ZLXCVR.js +1 -0
  43. package/dist/_chunks/devices-main-2BMCANKU.js +1 -0
  44. package/dist/_chunks/files-JJ6YOULB.js +1 -0
  45. package/dist/_chunks/host-component-ZYQ5ETVL.js +1 -0
  46. package/dist/_chunks/host-help-VNLA3YOV.js +1 -0
  47. package/dist/_chunks/host-main-KLWW7R47.js +1 -0
  48. package/dist/_chunks/http-profile-3VVSWYA5.js +1 -0
  49. package/dist/_chunks/library-main-3WWH7UYV.js +1 -0
  50. package/dist/_chunks/local-main-5BW63USP.js +1 -0
  51. package/dist/_chunks/local-mcp-AARKBDU5.js +1 -0
  52. package/dist/_chunks/main-LGYJ3ZCN.js +2 -0
  53. package/dist/_chunks/mcp-BLSK636Q.js +1 -0
  54. package/dist/_chunks/oauth-RPME2XYB.js +1 -0
  55. package/dist/_chunks/observe-entry-JVZAMB7N.js +1 -0
  56. package/dist/_chunks/remote-client-25Z65VJU.js +1 -0
  57. package/dist/_chunks/render-main-6Z3DKCWL.js +1 -0
  58. package/dist/_chunks/series-main-FBERVYWG.js +1 -0
  59. package/dist/_chunks/source-import-PNMCMTK7.js +1 -0
  60. package/dist/_chunks/src-7HSJFRVQ.js +1 -0
  61. package/dist/_chunks/stdio-main-HNLJCG45.js +1 -0
  62. package/dist/_chunks/workspace-main-QX5JGEMR.js +1 -0
  63. package/dist/_types/cli/local/desktop-contract.d.ts +1981 -22
  64. package/dist/_types/cli/local/desktop-device-contract.d.ts +807 -0
  65. package/dist/_types/cli/local/desktop-device-navigation.d.ts +3 -0
  66. package/dist/_types/cli/local/desktop-device-owner.d.ts +273 -0
  67. package/dist/_types/cli/local/desktop-device-state.d.ts +455 -0
  68. package/dist/_types/cli/local/desktop-library.d.ts +853 -0
  69. package/dist/_types/cli/local/desktop-owner.d.ts +787 -4
  70. package/dist/_types/cli/local/ledger.d.ts +76 -20
  71. package/dist/_types/cli/local/manager.d.ts +1233 -49
  72. package/dist/_types/cli/local/mcp-tools.d.ts +313 -54
  73. package/dist/_types/cli/local/releases.d.ts +30 -7
  74. package/dist/_types/cli/local-management.d.ts +9 -2
  75. package/dist/_types/cli/local-navigation.d.ts +1 -0
  76. package/dist/_types/contracts/agent-execution-lifecycle.d.ts +55 -43
  77. package/dist/_types/contracts/agent-execution-oauth.d.ts +2 -2
  78. package/dist/_types/contracts/agent-execution-registration.d.ts +59 -15
  79. package/dist/_types/contracts/agent-execution-selection.d.ts +7 -7
  80. package/dist/_types/contracts/agent-host-contract.d.ts +189 -0
  81. package/dist/_types/contracts/agent-host-execution.d.ts +92 -61
  82. package/dist/_types/contracts/agent-host-generic-transport.d.ts +4 -4
  83. package/dist/_types/contracts/agent-host-legacy-release.d.ts +31 -0
  84. package/dist/_types/contracts/agent-host-protocol.d.ts +71 -0
  85. package/dist/_types/contracts/agent-host-wire.d.ts +263 -0
  86. package/dist/_types/contracts/agent-host.d.ts +126 -65
  87. package/dist/_types/contracts/artifact-discovery.d.ts +143 -11
  88. package/dist/_types/contracts/audio.d.ts +166 -0
  89. package/dist/_types/contracts/component-status.d.ts +241 -0
  90. package/dist/_types/contracts/composition-authoring.d.ts +8 -8
  91. package/dist/_types/contracts/composition-frame-render.d.ts +4 -4
  92. package/dist/_types/contracts/composition-observation.d.ts +1 -1
  93. package/dist/_types/contracts/composition-render-base.d.ts +5 -4
  94. package/dist/_types/contracts/composition-render.d.ts +8 -8
  95. package/dist/_types/contracts/composition-repair.d.ts +10 -10
  96. package/dist/_types/contracts/composition-source-review.d.ts +13 -13
  97. package/dist/_types/contracts/consistency-profile.d.ts +102 -6
  98. package/dist/_types/contracts/continuity-evaluation.d.ts +1 -1
  99. package/dist/_types/contracts/delivery-completion.d.ts +1 -1
  100. package/dist/_types/contracts/delivery-manifest.d.ts +25 -11729
  101. package/dist/_types/contracts/delivery-operations.d.ts +207 -3915
  102. package/dist/_types/contracts/delivery-summary.d.ts +4 -4
  103. package/dist/_types/contracts/delivery-validation.d.ts +25 -2
  104. package/dist/_types/contracts/device-onboarding.d.ts +35 -0
  105. package/dist/_types/contracts/device-render.d.ts +113 -0
  106. package/dist/_types/contracts/editor-intelligence.d.ts +392 -2531
  107. package/dist/_types/contracts/enterprise-brand.d.ts +302 -0
  108. package/dist/_types/contracts/exploration-recommendation.d.ts +263 -11607
  109. package/dist/_types/contracts/external-agent-access.d.ts +4 -6
  110. package/dist/_types/contracts/federation-event-link-receiver.d.ts +200 -0
  111. package/dist/_types/contracts/federation-event-link.d.ts +485 -0
  112. package/dist/_types/contracts/federation-result.d.ts +239 -0
  113. package/dist/_types/contracts/final-ready.d.ts +24 -24
  114. package/dist/_types/contracts/final-render.d.ts +1742 -6949
  115. package/dist/_types/contracts/human-identity.d.ts +13 -0
  116. package/dist/_types/contracts/human-links.d.ts +58 -0
  117. package/dist/_types/contracts/index.d.ts +26 -0
  118. package/dist/_types/contracts/interface/common.d.ts +18 -0
  119. package/dist/_types/contracts/interface/execution-output.d.ts +9 -6
  120. package/dist/_types/contracts/interface/media-output.d.ts +118 -0
  121. package/dist/_types/contracts/interface/operation.d.ts +89 -0
  122. package/dist/_types/contracts/interface/production-snapshot.d.ts +106 -199
  123. package/dist/_types/contracts/interface/query.d.ts +85 -0
  124. package/dist/_types/contracts/keyframe-generation.d.ts +31 -2
  125. package/dist/_types/contracts/keyframe-review.d.ts +7 -7
  126. package/dist/_types/contracts/lifecycle-event-projections.d.ts +19 -4
  127. package/dist/_types/contracts/lifecycle-events.d.ts +54 -2
  128. package/dist/_types/contracts/local-execution/agent-component-status.d.ts +109 -0
  129. package/dist/_types/contracts/local-execution/agent-context.d.ts +385 -0
  130. package/dist/_types/contracts/local-execution/agent-evidence.d.ts +79 -0
  131. package/dist/_types/contracts/local-execution/agent-grant.d.ts +31 -0
  132. package/dist/_types/contracts/local-execution/agent-review.d.ts +529 -71
  133. package/dist/_types/contracts/local-execution/audio-profile.d.ts +6 -0
  134. package/dist/_types/contracts/local-execution/common.d.ts +12 -11
  135. package/dist/_types/contracts/local-execution/completion.d.ts +41 -45
  136. package/dist/_types/contracts/local-execution/components.d.ts +45 -0
  137. package/dist/_types/contracts/local-execution/cpu-preparation.d.ts +46 -0
  138. package/dist/_types/contracts/local-execution/cpu-resources.d.ts +55 -0
  139. package/dist/_types/contracts/local-execution/cpu-speech-job.d.ts +70 -0
  140. package/dist/_types/contracts/local-execution/cpu-speech.d.ts +161 -0
  141. package/dist/_types/contracts/local-execution/descriptor.d.ts +38 -0
  142. package/dist/_types/contracts/local-execution/device-authority.d.ts +31 -0
  143. package/dist/_types/contracts/local-execution/device-inventory.d.ts +108 -0
  144. package/dist/_types/contracts/local-execution/device-workspace.d.ts +11 -0
  145. package/dist/_types/contracts/local-execution/device.d.ts +24 -55
  146. package/dist/_types/contracts/local-execution/enrollment-credential.d.ts +141 -0
  147. package/dist/_types/contracts/local-execution/enrollment-handoff.d.ts +44 -0
  148. package/dist/_types/contracts/local-execution/external-generation.d.ts +199 -0
  149. package/dist/_types/contracts/local-execution/index.d.ts +36 -0
  150. package/dist/_types/contracts/local-execution/ipc.d.ts +2809 -231
  151. package/dist/_types/contracts/local-execution/library-command.d.ts +620 -0
  152. package/dist/_types/contracts/local-execution/library-result.d.ts +428 -0
  153. package/dist/_types/contracts/local-execution/library.d.ts +873 -0
  154. package/dist/_types/contracts/local-execution/lifecycle.d.ts +262 -48
  155. package/dist/_types/contracts/local-execution/local-navigation.d.ts +304 -67
  156. package/dist/_types/contracts/local-execution/management.d.ts +407 -0
  157. package/dist/_types/contracts/local-execution/media-recipe.d.ts +207 -0
  158. package/dist/_types/contracts/local-execution/media-validation-request.d.ts +232 -0
  159. package/dist/_types/contracts/local-execution/media-validation.d.ts +262 -0
  160. package/dist/_types/contracts/local-execution/object-transfer.d.ts +155 -0
  161. package/dist/_types/contracts/local-execution/offline.d.ts +59 -0
  162. package/dist/_types/contracts/local-execution/preview.d.ts +177 -3561
  163. package/dist/_types/contracts/local-execution/processor-capability.d.ts +49 -0
  164. package/dist/_types/contracts/local-execution/processor-direct.d.ts +290 -0
  165. package/dist/_types/contracts/local-execution/processor-recipes.d.ts +1194 -0
  166. package/dist/_types/contracts/local-execution/processor-toolchain.d.ts +47 -0
  167. package/dist/_types/contracts/local-execution/processor.d.ts +6424 -0
  168. package/dist/_types/contracts/local-execution/project-source-direct.d.ts +201 -0
  169. package/dist/_types/contracts/local-execution/qwen-tts.d.ts +31 -0
  170. package/dist/_types/contracts/local-execution/recognition.d.ts +170 -0
  171. package/dist/_types/contracts/local-execution/speech.d.ts +95 -0
  172. package/dist/_types/contracts/local-execution/tool-selection.d.ts +71 -5
  173. package/dist/_types/contracts/local-execution/whisper.d.ts +24 -0
  174. package/dist/_types/contracts/local-execution/work.d.ts +124 -3402
  175. package/dist/_types/contracts/local-execution/workspace.d.ts +141 -0
  176. package/dist/_types/contracts/mcp-capabilities.d.ts +16 -0
  177. package/dist/_types/contracts/media-category.d.ts +11 -0
  178. package/dist/_types/contracts/media-observation.d.ts +930 -9
  179. package/dist/_types/contracts/native-speech-model.d.ts +53 -0
  180. package/dist/_types/contracts/native-speech-options.d.ts +25 -0
  181. package/dist/_types/contracts/native-tool-authority.d.ts +25 -21
  182. package/dist/_types/contracts/native-tool-execution.d.ts +60 -39
  183. package/dist/_types/contracts/navigation-context.d.ts +76 -8
  184. package/dist/_types/contracts/navigation-groups.d.ts +2 -2
  185. package/dist/_types/contracts/navigation.d.ts +79 -26
  186. package/dist/_types/contracts/observation-profile.d.ts +3 -3
  187. package/dist/_types/contracts/production-creation.d.ts +30 -0
  188. package/dist/_types/contracts/production-feedback.d.ts +452 -0
  189. package/dist/_types/contracts/production.d.ts +30 -0
  190. package/dist/_types/contracts/programmatic-composition.d.ts +24 -24
  191. package/dist/_types/contracts/programmatic-exploration.d.ts +362 -5999
  192. package/dist/_types/contracts/programmatic-video-review.d.ts +5 -5
  193. package/dist/_types/contracts/project-library.d.ts +30 -0
  194. package/dist/_types/contracts/project.d.ts +30 -0
  195. package/dist/_types/contracts/provider-catalog.d.ts +3 -3
  196. package/dist/_types/contracts/provider-models.d.ts +209 -8
  197. package/dist/_types/contracts/provider.d.ts +66 -1
  198. package/dist/_types/contracts/reference-preview.d.ts +20 -0
  199. package/dist/_types/contracts/render-readiness.d.ts +175 -0
  200. package/dist/_types/contracts/repair-lifecycle.d.ts +64 -396
  201. package/dist/_types/contracts/repair-plan.d.ts +18 -100
  202. package/dist/_types/contracts/repair-strategy.d.ts +163 -4478
  203. package/dist/_types/contracts/review-intelligence-final-output.d.ts +418 -8150
  204. package/dist/_types/contracts/review-intelligence.d.ts +455 -11423
  205. package/dist/_types/contracts/review1-repair-source.d.ts +6 -6
  206. package/dist/_types/contracts/review1-repair-strategy.d.ts +4 -4
  207. package/dist/_types/contracts/rough-cut-manifest.d.ts +27 -7
  208. package/dist/_types/contracts/rough-cut-profile.d.ts +12 -3
  209. package/dist/_types/contracts/rough-cut-review.d.ts +144 -12495
  210. package/dist/_types/contracts/rough-cut.d.ts +1170 -5673
  211. package/dist/_types/contracts/series-canon.d.ts +97 -0
  212. package/dist/_types/contracts/series-character.d.ts +23 -0
  213. package/dist/_types/contracts/series-improvement.d.ts +1639 -0
  214. package/dist/_types/contracts/series-standard.d.ts +1641 -0
  215. package/dist/_types/contracts/shares.d.ts +135 -0
  216. package/dist/_types/contracts/shot-preparation-basis.d.ts +2 -2
  217. package/dist/_types/contracts/shot-preparation.d.ts +4 -4
  218. package/dist/_types/contracts/sound-making-plan.d.ts +210 -2
  219. package/dist/_types/contracts/speech-cost.d.ts +96 -0
  220. package/dist/_types/contracts/speech-parameters.d.ts +39 -0
  221. package/dist/_types/contracts/speech.d.ts +603 -23
  222. package/dist/_types/contracts/temporal-evidence-operation.d.ts +2 -1
  223. package/dist/_types/contracts/timeline-audio.d.ts +20 -4
  224. package/dist/_types/contracts/timeline-manifest.d.ts +40 -8
  225. package/dist/_types/contracts/timeline-source-sound.d.ts +42 -4
  226. package/dist/_types/contracts/timeline-v2.d.ts +124 -16
  227. package/dist/_types/contracts/timeline-version-reader.d.ts +288 -40
  228. package/dist/_types/contracts/timeline-visual-layers.d.ts +124 -16
  229. package/dist/_types/contracts/timeline.d.ts +50 -4850
  230. package/dist/_types/contracts/transcription.d.ts +1 -1
  231. package/dist/_types/contracts/video-generation.d.ts +35 -2
  232. package/dist/_types/contracts/video-review.d.ts +7 -7
  233. package/dist/_types/contracts/visual-exploration.d.ts +3 -3
  234. package/dist/_types/contracts/visual-layer-render.d.ts +298 -47
  235. package/dist/_types/contracts/visual-sequence.d.ts +22 -0
  236. package/dist/_types/contracts/voice-consistency.d.ts +183 -0
  237. package/dist/_types/contracts/voice-profile/contracts.d.ts +821 -0
  238. package/dist/_types/contracts/voice-profile/identity.d.ts +27 -0
  239. package/dist/_types/contracts/voice-profile/interface.d.ts +89 -0
  240. package/dist/_types/contracts/voice-profile/reference.d.ts +106 -0
  241. package/dist/_types/contracts/voice-review.d.ts +1194 -0
  242. package/dist/_types/contracts/workspace.d.ts +83 -0
  243. package/dist/_types/sdk/errors.d.ts +9 -3
  244. package/dist/_types/sdk/local-runtime/components.d.ts +2 -0
  245. package/dist/_types/sdk/local-runtime/device-client.d.ts +181 -19
  246. package/dist/_types/sdk/local-runtime/library.d.ts +268 -0
  247. package/dist/_types/sdk/local-runtime/workspace.d.ts +186 -0
  248. package/dist/_types/sdk/local-runtime-client.d.ts +1934 -96
  249. package/dist/entry.js +1 -1
  250. package/dist/local-management.js +1 -1
  251. package/dist/local-navigation.js +1 -1
  252. package/dist/native/helper.exe +0 -0
  253. package/dist/native/helper.json +1 -0
  254. package/package.json +2 -8
  255. package/README.md +0 -95
  256. package/dist/_chunks/chunk-66CUOZVI.js +0 -1
  257. package/dist/_chunks/chunk-6NVIN2NI.js +0 -1
  258. package/dist/_chunks/chunk-7S3DJ2QE.js +0 -1
  259. package/dist/_chunks/chunk-BVSTJQJI.js +0 -1
  260. package/dist/_chunks/chunk-C753RRRA.js +0 -1
  261. package/dist/_chunks/chunk-E57YVMQ4.js +0 -1
  262. package/dist/_chunks/chunk-GJ7BZJLW.js +0 -1
  263. package/dist/_chunks/chunk-HLKERZIE.js +0 -1
  264. package/dist/_chunks/chunk-K6LVS2IN.js +0 -1
  265. package/dist/_chunks/chunk-KHKUJXQX.js +0 -1
  266. package/dist/_chunks/chunk-PUNG4ND7.js +0 -1
  267. package/dist/_chunks/chunk-VC3ODN3M.js +0 -1
  268. package/dist/_chunks/chunk-VPYAXWXY.js +0 -1
  269. package/dist/_chunks/files-FZEK2ZZJ.js +0 -1
  270. package/dist/_chunks/local-main-NLFS74Q4.js +0 -1
  271. package/dist/_chunks/local-mcp-OLHBBVNN.js +0 -1
  272. package/dist/_chunks/main-VRIQTI6R.js +0 -2
  273. package/dist/_chunks/mcp-EIMXNRH3.js +0 -1
  274. package/dist/_chunks/oauth-F7EZGVME.js +0 -1
  275. package/dist/_chunks/project-connect-MXM7IY55.js +0 -1
  276. package/dist/_chunks/src-7F6ZEU3U.js +0 -1
  277. package/dist/_chunks/stdio-main-KOGQ5OWF.js +0 -1
  278. package/dist/native/Bootstrap.ps1 +0 -90
  279. package/dist/native/JobNative.cs +0 -127
  280. package/dist/native/JobRunner.cs +0 -360
  281. package/dist/native/NativeMain.cs +0 -146
  282. package/dist/native/PipeBridge.cs +0 -260
  283. package/dist/native/PrivateAccess.cs +0 -152
@@ -1,360 +0,0 @@
1
- using System;
2
- using System.IO;
3
- using System.Text;
4
- using System.Linq;
5
- using System.Collections;
6
- using System.Collections.Generic;
7
- using System.Diagnostics;
8
- using System.Runtime.InteropServices;
9
- using System.Threading;
10
- using Microsoft.Win32.SafeHandles;
11
- namespace NativeStudio.Platform
12
- {
13
- public static class JobRunner
14
- {
15
- static readonly object Sync = new object();
16
- static readonly Dictionary<string, IntPtr> Jobs = new Dictionary<string, IntPtr>();
17
- static readonly HashSet<string> Cancelled = new HashSet<string>();
18
- static IntPtr aggregate;
19
- static Process parent;
20
- static bool closed;
21
- public static void Parent(int id)
22
- {
23
- parent = Process.GetProcessById(id);
24
- if (parent.Handle == IntPtr.Zero)
25
- throw new Exception("PARENT");
26
- }
27
- public static bool Reserve(string id)
28
- {
29
- lock (Sync)
30
- {
31
- if (closed || Jobs.Count >= 16 || Jobs.ContainsKey(id))
32
- return false;
33
- Jobs.Add(id, IntPtr.Zero);
34
- return true;
35
- }
36
- }
37
- public static void Release(string id)
38
- {
39
- lock (Sync)
40
- {
41
- Jobs.Remove(id);
42
- Cancelled.Remove(id);
43
- }
44
- }
45
- public static void Cancel(string id)
46
- {
47
- lock (Sync)
48
- {
49
- IntPtr job;
50
- if (!Jobs.TryGetValue(id, out job))
51
- return;
52
- Cancelled.Add(id);
53
- if (job != IntPtr.Zero)
54
- JobNative.TerminateJobObject(job, 1); // Handle disposal uses the same lock.
55
- }
56
- }
57
- public static void Close()
58
- {
59
- lock (Sync)
60
- {
61
- closed = true;
62
- if (aggregate != IntPtr.Zero)
63
- {
64
- JobNative.CloseHandle(aggregate);
65
- aggregate = IntPtr.Zero;
66
- }
67
- }
68
- }
69
- static IntPtr Aggregate()
70
- {
71
- lock (Sync)
72
- {
73
- if (closed)
74
- throw new Exception("CLOSED");
75
- if (aggregate == IntPtr.Zero)
76
- {
77
- aggregate = JobNative.Job(true);
78
- var monitor = new Thread(delegate ()
79
- {
80
- try
81
- {
82
- while (!closed)
83
- {
84
- lock (Sync)
85
- {
86
- if (closed)
87
- return;
88
- long rss = Process.GetCurrentProcess().WorkingSet64;
89
- if (parent != null)
90
- {
91
- if (parent.HasExited)
92
- {
93
- Close();
94
- return;
95
- }
96
- parent.Refresh();
97
- rss += parent.WorkingSet64;
98
- }
99
- foreach (uint id in JobNative.Processes(aggregate))
100
- {
101
- try
102
- {
103
- using (var p = Process.GetProcessById((int)id))
104
- rss += p.WorkingSet64;
105
- }
106
- catch (ArgumentException) { } // A command already exited.
107
- }
108
- if (rss > 4294967296L)
109
- {
110
- Close();
111
- return;
112
- }
113
- }
114
- Thread.Sleep(100);
115
- }
116
- }
117
- catch { Close(); }
118
- });
119
- monitor.IsBackground = true;
120
- monitor.Start();
121
- }
122
- return aggregate;
123
- }
124
- }
125
- public static string Quote(string value)
126
- {
127
- if (value.IndexOf('\0') >= 0)
128
- throw new Exception("ARGUMENT");
129
- var b = new StringBuilder("\"");
130
- int slashes = 0;
131
- foreach (char c in value)
132
- {
133
- if (c == '\\')
134
- {
135
- slashes++;
136
- continue;
137
- }
138
- if (c == '\"')
139
- {
140
- b.Append('\\', slashes * 2 + 1);
141
- b.Append(c);
142
- }
143
- else
144
- {
145
- b.Append('\\', slashes);
146
- b.Append(c);
147
- }
148
- slashes = 0;
149
- }
150
- b.Append('\\', slashes * 2);
151
- b.Append('"');
152
- return b.ToString();
153
- }
154
- static IntPtr EnvironmentBlock(IDictionary<string, object> r)
155
- {
156
- var values = new SortedDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
157
- values["SystemRoot"] = Environment.GetEnvironmentVariable("SystemRoot");
158
- object supplied;
159
- if (r.TryGetValue("environment", out supplied) && supplied != null)
160
- {
161
- var env = (IDictionary<string, object>)supplied;
162
- if (env.Count > 24)
163
- throw new Exception("ENVIRONMENT");
164
- foreach (var entry in env)
165
- {
166
- string key = entry.Key.ToUpperInvariant(), value = entry.Value as string;
167
- if (value == null || value.Length > 4096 || value.IndexOf('\0') >= 0 || !System.Text.RegularExpressions.Regex.IsMatch(key, @"^[A-Z][A-Z0-9_]{0,60}$") || key == "NODE_OPTIONS" || key.StartsWith("LD_") || key.StartsWith("DYLD_"))
168
- throw new Exception("ENVIRONMENT");
169
- if (key != "SYSTEMROOT")
170
- values[key] = value;
171
- }
172
- }
173
- return Marshal.StringToHGlobalUni(String.Join("\0", values.Select(v => v.Key + "=" + v.Value).ToArray()) + "\0\0");
174
- }
175
- static FileStream Stream(IntPtr handle, FileAccess access)
176
- {
177
- return new FileStream(new SafeFileHandle(handle, true), access, 4096, false);
178
- }
179
- public static object Execute(string id, IDictionary<string, object> r)
180
- {
181
- string binary = PrivateAccess.PathOf(NativeMain.Text(r, "binary"));
182
- if (!binary.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
183
- throw new Exception("EXECUTABLE");
184
- PrivateAccess.Check(binary, "file", false);
185
- var args = (IList)r["args"];
186
- if (args.Count > 512)
187
- throw new Exception("ARGUMENT");
188
- var command = new StringBuilder(Quote(binary));
189
- foreach (object arg in args)
190
- {
191
- if (!(arg is string))
192
- throw new Exception("ARGUMENT");
193
- command.Append(' ').Append(Quote((string)arg));
194
- }
195
- if (command.Length > 30000)
196
- throw new Exception("ARGUMENT_LIMIT");
197
- string input = r.ContainsKey("input") ? NativeMain.Text(r, "input") : "";
198
- if (Encoding.UTF8.GetByteCount(input) > 65536)
199
- throw new Exception("INPUT_LIMIT");
200
- int maximum = Convert.ToInt32(r["maxOutputBytes"]);
201
- long expires = Convert.ToInt64(r["expiresAt"]);
202
- if (maximum < 1 || maximum > 524288 || expires <= DateTimeOffset.UtcNow.ToUnixTimeMilliseconds())
203
- throw new Exception("LIMIT");
204
- string cwd = r.ContainsKey("cwd") && r["cwd"] != null ? PrivateAccess.PathOf(NativeMain.Text(r, "cwd")) : null;
205
- IntPtr job = IntPtr.Zero, environment = IntPtr.Zero, inRead = IntPtr.Zero, inWrite = IntPtr.Zero, outRead = IntPtr.Zero, outWrite = IntPtr.Zero, errRead = IntPtr.Zero, errWrite = IntPtr.Zero;
206
- SafeFileHandle ownedJob = null;
207
- var info = new JobNative.ProcessInfo();
208
- bool assigned = false;
209
- try
210
- {
211
- var root = Aggregate();
212
- job = JobNative.Job(false);
213
- ownedJob = new SafeFileHandle(job, true);
214
- lock (Sync)
215
- {
216
- Jobs[id] = job;
217
- if (Cancelled.Contains(id) || closed)
218
- throw new Exception("CANCELLED");
219
- }
220
- var sa = new JobNative.SecurityAttributes { size = Marshal.SizeOf(typeof(JobNative.SecurityAttributes)), inherit = 1 };
221
- if (!JobNative.CreatePipe(out inRead, out inWrite, ref sa, 0) || !JobNative.CreatePipe(out outRead, out outWrite, ref sa, 0) || !JobNative.CreatePipe(out errRead, out errWrite, ref sa, 0))
222
- throw new Exception("PIPE");
223
- if (!JobNative.SetHandleInformation(inWrite, 1, 0) || !JobNative.SetHandleInformation(outRead, 1, 0) || !JobNative.SetHandleInformation(errRead, 1, 0))
224
- throw new Exception("HANDLE");
225
- var startup = new JobNative.StartupInfo { size = Marshal.SizeOf(typeof(JobNative.StartupInfo)), flags = 0x100, input = inRead, output = outWrite, error = errWrite };
226
- environment = EnvironmentBlock(r);
227
- if (!JobNative.CreateProcess(binary, command, IntPtr.Zero, IntPtr.Zero, true, 4 | 0x400 | 0x8000000, environment, cwd, ref startup, out info))
228
- throw new Exception("SPAWN");
229
- lock (Sync)
230
- {
231
- if (closed || Cancelled.Contains(id))
232
- throw new Exception("CANCELLED");
233
- if (!JobNative.AssignProcessToJobObject(root, info.process) || !JobNative.AssignProcessToJobObject(job, info.process))
234
- throw new Exception("JOB_ASSIGN");
235
- assigned = true;
236
- }
237
- JobNative.CloseHandle(inRead);
238
- inRead = IntPtr.Zero;
239
- JobNative.CloseHandle(outWrite);
240
- outWrite = IntPtr.Zero;
241
- JobNative.CloseHandle(errWrite);
242
- errWrite = IntPtr.Zero;
243
- using (var output = Stream(outRead, FileAccess.Read))
244
- using (var errors = Stream(errRead, FileAccess.Read))
245
- using (var stdin = Stream(inWrite, FileAccess.Write))
246
- using (var bytes = new MemoryStream())
247
- {
248
- outRead = errRead = inWrite = IntPtr.Zero;
249
- int failed = 0;
250
- var reader = new Thread(delegate ()
251
- {
252
- try
253
- {
254
- var buffer = new byte[4096];
255
- int count;
256
- while ((count = output.Read(buffer, 0, buffer.Length)) > 0)
257
- {
258
- if (bytes.Length + count > maximum)
259
- throw new Exception();
260
- bytes.Write(buffer, 0, count);
261
- }
262
- }
263
- catch { Interlocked.Exchange(ref failed, 1); JobNative.Kill(ownedJob); }
264
- });
265
- var diagnostics = new Thread(delegate ()
266
- {
267
- try
268
- {
269
- var buffer = new byte[4096];
270
- int count, total = 0;
271
- while ((count = errors.Read(buffer, 0, buffer.Length)) > 0)
272
- {
273
- total += count;
274
- if (total > 65536)
275
- throw new Exception();
276
- }
277
- }
278
- catch { Interlocked.Exchange(ref failed, 1); JobNative.Kill(ownedJob); }
279
- });
280
- var writer = new Thread(delegate ()
281
- {
282
- try
283
- {
284
- var b = Encoding.UTF8.GetBytes(input);
285
- stdin.Write(b, 0, b.Length);
286
- stdin.Dispose();
287
- }
288
- catch { Interlocked.Exchange(ref failed, 1); JobNative.Kill(ownedJob); }
289
- });
290
- try
291
- {
292
- reader.IsBackground = diagnostics.IsBackground = writer.IsBackground = true;
293
- reader.Start();
294
- diagnostics.Start();
295
- writer.Start();
296
- lock (Sync)
297
- {
298
- if (closed || Cancelled.Contains(id) || JobNative.ResumeThread(info.thread) == 0xffffffff)
299
- throw new Exception("CANCELLED");
300
- }
301
- while (JobNative.WaitForSingleObject(info.process, 50) == 258)
302
- {
303
- lock (Sync)
304
- {
305
- if (closed || Cancelled.Contains(id) || failed != 0 || expires <= DateTimeOffset.UtcNow.ToUnixTimeMilliseconds())
306
- throw new Exception("CANCELLED");
307
- }
308
- }
309
- uint code;
310
- if (!JobNative.GetExitCodeProcess(info.process, out code))
311
- throw new Exception("EXIT");
312
- JobNative.Kill(ownedJob); // Dispose every descendant even if it closed its streams.
313
- if (!reader.Join(2000) || !diagnostics.Join(2000) || !writer.Join(2000) || failed != 0 || code != 0)
314
- throw new Exception("EXECUTION");
315
- lock (Sync)
316
- {
317
- if (closed || Cancelled.Contains(id))
318
- throw new Exception("CANCELLED");
319
- }
320
- return new
321
- {
322
- output = Convert.ToBase64String(bytes.ToArray())
323
- };
324
- }
325
- finally
326
- {
327
- JobNative.Kill(ownedJob);
328
- foreach (var worker in new[] { reader, diagnostics, writer })
329
- if (worker.IsAlive)
330
- worker.Join(2000);
331
- }
332
- }
333
- }
334
- finally
335
- {
336
- if (info.process != IntPtr.Zero)
337
- {
338
- if (!assigned)
339
- JobNative.TerminateProcess(info.process, 1);
340
- JobNative.CloseHandle(info.process);
341
- }
342
- if (info.thread != IntPtr.Zero)
343
- JobNative.CloseHandle(info.thread);
344
- lock (Sync)
345
- {
346
- Jobs[id] = IntPtr.Zero;
347
- if (ownedJob != null)
348
- ownedJob.Dispose();
349
- else if (job != IntPtr.Zero)
350
- JobNative.CloseHandle(job);
351
- }
352
- foreach (var handle in new[] { inRead, inWrite, outRead, outWrite, errRead, errWrite })
353
- if (handle != IntPtr.Zero)
354
- JobNative.CloseHandle(handle);
355
- if (environment != IntPtr.Zero)
356
- Marshal.FreeHGlobal(environment);
357
- }
358
- }
359
- }
360
- }
@@ -1,146 +0,0 @@
1
- using System;
2
- using System.Collections.Generic;
3
- using System.Text;
4
- using System.Threading;
5
- using System.Web.Script.Serialization;
6
- namespace NativeStudio.Platform
7
- {
8
- public static class NativeMain
9
- {
10
- static readonly object Output = new object();
11
- public static readonly JavaScriptSerializer Json = new JavaScriptSerializer { MaxJsonLength = 2097152, RecursionLimit = 32 };
12
- public static string Text(IDictionary<string, object> r, string key)
13
- {
14
- object value;
15
- if (!r.TryGetValue(key, out value) || !(value is string) || ((string)value).Length > 1048576)
16
- throw new Exception("INPUT");
17
- return (string)value;
18
- }
19
- public static string Line(int limit)
20
- {
21
- var value = new StringBuilder();
22
- for (; ; )
23
- {
24
- int c = Console.In.Read();
25
- if (c < 0)
26
- return value.Length == 0 ? null : value.ToString();
27
- if (c == 10)
28
- return value.ToString();
29
- if (c != 13)
30
- value.Append((char)c);
31
- if (value.Length > limit)
32
- throw new Exception("INPUT_LIMIT");
33
- }
34
- }
35
- public static void Send(object value)
36
- {
37
- string line;
38
- lock (Json)
39
- line = Json.Serialize(value);
40
- lock (Output)
41
- {
42
- Console.WriteLine(line);
43
- Console.Out.Flush();
44
- }
45
- }
46
- static void Handle(IDictionary<string, object> r)
47
- {
48
- string id = Text(r, "id");
49
- try
50
- {
51
- var operation = Text(r, "operation");
52
- if (operation == "directory")
53
- PrivateAccess.Directory(Text(r, "path"));
54
- else if (operation == "check")
55
- PrivateAccess.Check(Text(r, "path"), Text(r, "kind"), true);
56
- else if (operation == "executable")
57
- PrivateAccess.Check(Text(r, "path"), "file", false);
58
- else if (operation == "move")
59
- PrivateAccess.Move(Text(r, "source"), Text(r, "target"), r.ContainsKey("exclusive") && (bool)r["exclusive"]);
60
- else if (operation == "execute")
61
- {
62
- Send(new
63
- {
64
- id = id,
65
- ok = true,
66
- data = JobRunner.Execute(id, r)
67
- });
68
- return;
69
- }
70
- else
71
- throw new Exception("OPERATION");
72
- Send(new
73
- {
74
- id = id,
75
- ok = true,
76
- data = true
77
- });
78
- }
79
- catch (Exception e)
80
- {
81
- Send(new
82
- {
83
- id = id,
84
- ok = false,
85
- error = e.Message == "EXISTS" ? "EXISTS" : "DENIED"
86
- });
87
- }
88
- }
89
- public static int Main(string[] args)
90
- {
91
- Console.InputEncoding = new UTF8Encoding(false);
92
- Console.OutputEncoding = new UTF8Encoding(false);
93
- try
94
- {
95
- if (args.Length == 2 && args[0] == "pipe")
96
- {
97
- PipeBridge.Run(args[1]);
98
- return 0;
99
- }
100
- if (args.Length != 2 || args[0] != "service")
101
- return 1;
102
- JobRunner.Parent(Int32.Parse(args[1]));
103
- for (; ; )
104
- {
105
- var line = Line(1048576);
106
- if (line == null)
107
- break;
108
- IDictionary<string, object> request;
109
- lock (Json)
110
- request = Json.Deserialize<Dictionary<string, object>>(line);
111
- if (Text(request, "operation") == "cancel")
112
- {
113
- JobRunner.Cancel(Text(request, "target"));
114
- continue;
115
- }
116
- if (Text(request, "operation") == "execute")
117
- {
118
- if (!JobRunner.Reserve(Text(request, "id")))
119
- {
120
- Send(new
121
- {
122
- id = Text(request, "id"),
123
- ok = false,
124
- error = "BUSY"
125
- });
126
- continue;
127
- }
128
- ThreadPool.QueueUserWorkItem(delegate
129
- {
130
- try
131
- {
132
- Handle(request);
133
- }
134
- finally { JobRunner.Release(Text(request, "id")); }
135
- });
136
- }
137
- else
138
- Handle(request);
139
- }
140
- return 0;
141
- }
142
- catch { return 1; }
143
- finally { JobRunner.Close(); }
144
- }
145
- }
146
- }