@indigoai-us/hq-cli 5.345.214 → 5.345.215

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 (200) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/assets/scaffold/core/scripts/hq-delegate-verify.sh +5 -2
  3. package/dist/command-catalog.generated.d.ts +180 -13
  4. package/dist/command-catalog.generated.js +221 -13
  5. package/dist/commands/agents.d.ts +51 -1
  6. package/dist/commands/agents.js +154 -2
  7. package/dist/commands/bot-jobs.d.ts +2 -15
  8. package/dist/commands/bot-jobs.js +2 -94
  9. package/dist/commands/bot-runtime.d.ts +46 -5
  10. package/dist/commands/bot-runtime.js +228 -18
  11. package/dist/commands/bot.d.ts +16 -9
  12. package/dist/commands/bot.js +231 -55
  13. package/dist/commands/capacity.d.ts +4 -1
  14. package/dist/commands/capacity.js +46 -10
  15. package/dist/commands/cloud.d.ts +66 -13
  16. package/dist/commands/cloud.js +121 -40
  17. package/dist/commands/company-restore.d.ts +23 -0
  18. package/dist/commands/company-restore.js +128 -0
  19. package/dist/commands/company.js +2 -0
  20. package/dist/commands/core-delegate-w1b.js +15 -1
  21. package/dist/commands/core-policy.js +67 -8
  22. package/dist/commands/daemon.js +5 -0
  23. package/dist/commands/files-browse.d.ts +11 -4
  24. package/dist/commands/files-browse.js +21 -4
  25. package/dist/commands/files.d.ts +1 -1
  26. package/dist/commands/files.js +25 -11
  27. package/dist/commands/integrations-auth-rules.d.ts +27 -0
  28. package/dist/commands/integrations-auth-rules.js +79 -0
  29. package/dist/commands/integrations-connect.d.ts +10 -3
  30. package/dist/commands/integrations-connect.js +87 -13
  31. package/dist/commands/integrations-import.js +124 -12
  32. package/dist/commands/lanes.js +28 -11
  33. package/dist/commands/mesh.d.ts +2 -0
  34. package/dist/commands/mesh.js +60 -35
  35. package/dist/commands/sources.js +6 -0
  36. package/dist/commands/storage-offload.d.ts +12 -0
  37. package/dist/commands/storage-offload.js +41 -3
  38. package/dist/commands/sync-held.js +5 -2
  39. package/dist/commands/sync-mode.js +5 -0
  40. package/dist/commands/whoami.js +4 -0
  41. package/dist/lazy-commands.js +3 -5
  42. package/dist/lib/bot/config.d.ts +1 -0
  43. package/dist/lib/bot/config.js +10 -0
  44. package/dist/lib/bot/eventbridge-cron.d.ts +22 -0
  45. package/dist/lib/bot/eventbridge-cron.js +104 -0
  46. package/dist/lib/bot/fleet-cron.d.ts +8 -0
  47. package/dist/lib/bot/fleet-cron.js +35 -3
  48. package/dist/lib/bot/fleet-daemon.d.ts +46 -0
  49. package/dist/lib/bot/fleet-daemon.js +99 -1
  50. package/dist/lib/bot/fleet-local.d.ts +33 -1
  51. package/dist/lib/bot/fleet-local.js +215 -31
  52. package/dist/lib/bot/fleet-python.d.ts +3 -0
  53. package/dist/lib/bot/fleet-python.js +34 -4
  54. package/dist/lib/bot/fleet-runtime-sources.d.ts +15 -0
  55. package/dist/lib/bot/fleet-runtime-sources.js +30 -0
  56. package/dist/lib/bot/legacy-provider-login.d.ts +8 -0
  57. package/dist/lib/bot/legacy-provider-login.js +19 -2
  58. package/dist/lib/bot/probe.js +7 -1
  59. package/dist/lib/bot/prompt.js +1 -1
  60. package/dist/lib/bot/readiness.d.ts +8 -0
  61. package/dist/lib/bot/readiness.js +17 -3
  62. package/dist/lib/bot/run.js +20 -1
  63. package/dist/lib/bot/runtime/codex.js +1 -1
  64. package/dist/lib/bot/runtime/grok-acp.d.ts +5 -1
  65. package/dist/lib/bot/runtime/grok-acp.js +6 -3
  66. package/dist/lib/bot/runtime/index.js +19 -9
  67. package/dist/lib/bot/runtime/messages-stream.js +2 -2
  68. package/dist/lib/bot/runtime/types.d.ts +15 -0
  69. package/dist/lib/bot/runtime/types.js +9 -0
  70. package/dist/lib/bot/runtime-auth.d.ts +30 -0
  71. package/dist/lib/bot/runtime-auth.js +94 -3
  72. package/dist/lib/bot/runtime-failure.d.ts +23 -0
  73. package/dist/lib/bot/runtime-failure.js +43 -1
  74. package/dist/lib/bot/status.d.ts +2 -0
  75. package/dist/lib/capacity/accounts.d.ts +8 -0
  76. package/dist/lib/capacity/accounts.js +19 -0
  77. package/dist/lib/capacity/available.d.ts +154 -0
  78. package/dist/lib/capacity/available.js +905 -0
  79. package/dist/lib/capacity/codex-availability.d.ts +14 -1
  80. package/dist/lib/capacity/codex-availability.js +26 -1
  81. package/dist/lib/capacity/collectors/claude-oauth.d.ts +29 -2
  82. package/dist/lib/capacity/collectors/claude-oauth.js +104 -7
  83. package/dist/lib/capacity/collectors/codex.js +10 -7
  84. package/dist/lib/capacity/collectors/grok-refresh.d.ts +80 -0
  85. package/dist/lib/capacity/collectors/grok-refresh.js +189 -0
  86. package/dist/lib/capacity/collectors/grok.d.ts +5 -0
  87. package/dist/lib/capacity/collectors/grok.js +56 -5
  88. package/dist/lib/capacity/ledger.d.ts +37 -1
  89. package/dist/lib/capacity/ledger.js +207 -30
  90. package/dist/lib/capacity/project.d.ts +26 -0
  91. package/dist/lib/capacity/project.js +137 -8
  92. package/dist/lib/capacity/refusal-rows.d.ts +31 -0
  93. package/dist/lib/capacity/refusal-rows.js +61 -0
  94. package/dist/lib/capacity/refusal.d.ts +53 -2
  95. package/dist/lib/capacity/refusal.js +284 -65
  96. package/dist/lib/capacity/route.js +46 -11
  97. package/dist/lib/capacity/widget.d.ts +12 -1
  98. package/dist/lib/capacity/widget.js +91 -3
  99. package/dist/lib/daemon/catalog.js +11 -1
  100. package/dist/lib/daemon/resolver.d.ts +2 -0
  101. package/dist/lib/daemon/resolver.js +3 -0
  102. package/dist/lib/daemon/run.d.ts +9 -0
  103. package/dist/lib/daemon/run.js +54 -1
  104. package/dist/lib/daemon/server.d.ts +2 -0
  105. package/dist/lib/daemon/server.js +10 -1
  106. package/dist/lib/daemon/tcc-eperm.d.ts +153 -0
  107. package/dist/lib/daemon/tcc-eperm.js +310 -0
  108. package/dist/lib/db/sqlite-binding.d.ts +1 -0
  109. package/dist/lib/db/sqlite-binding.js +1 -1
  110. package/dist/lib/delivery/admission.d.ts +86 -0
  111. package/dist/lib/delivery/admission.js +148 -0
  112. package/dist/lib/delivery/artifacts.d.ts +105 -0
  113. package/dist/lib/delivery/artifacts.js +567 -0
  114. package/dist/lib/delivery/attempt-id.d.ts +13 -0
  115. package/dist/lib/delivery/attempt-id.js +16 -0
  116. package/dist/lib/delivery/backup.d.ts +78 -0
  117. package/dist/lib/delivery/backup.js +343 -0
  118. package/dist/lib/delivery/cache.d.ts +29 -0
  119. package/dist/lib/delivery/cache.js +33 -0
  120. package/dist/lib/delivery/contracts.d.ts +142 -0
  121. package/dist/lib/delivery/contracts.js +289 -0
  122. package/dist/lib/delivery/credentials.d.ts +54 -0
  123. package/dist/lib/delivery/credentials.js +119 -0
  124. package/dist/lib/delivery/disposable-target.d.ts +42 -0
  125. package/dist/lib/delivery/disposable-target.js +111 -0
  126. package/dist/lib/delivery/effects.d.ts +136 -0
  127. package/dist/lib/delivery/effects.js +541 -0
  128. package/dist/lib/delivery/enrollment.d.ts +146 -0
  129. package/dist/lib/delivery/enrollment.js +460 -0
  130. package/dist/lib/delivery/escalations.d.ts +51 -0
  131. package/dist/lib/delivery/escalations.js +60 -0
  132. package/dist/lib/delivery/identity.d.ts +25 -0
  133. package/dist/lib/delivery/identity.js +82 -0
  134. package/dist/lib/delivery/inbox.d.ts +116 -0
  135. package/dist/lib/delivery/inbox.js +260 -0
  136. package/dist/lib/delivery/lease.d.ts +80 -0
  137. package/dist/lib/delivery/lease.js +134 -0
  138. package/dist/lib/delivery/migrations.d.ts +255 -0
  139. package/dist/lib/delivery/migrations.js +823 -0
  140. package/dist/lib/delivery/mqtt-adapter.d.ts +50 -0
  141. package/dist/lib/delivery/mqtt-adapter.js +242 -0
  142. package/dist/lib/delivery/mqtt.d.ts +63 -0
  143. package/dist/lib/delivery/mqtt.js +119 -0
  144. package/dist/lib/delivery/outbox.d.ts +95 -0
  145. package/dist/lib/delivery/outbox.js +187 -0
  146. package/dist/lib/delivery/provenance.d.ts +129 -0
  147. package/dist/lib/delivery/provenance.js +93 -0
  148. package/dist/lib/delivery/reconciler.d.ts +215 -0
  149. package/dist/lib/delivery/reconciler.js +703 -0
  150. package/dist/lib/delivery/restore.d.ts +35 -0
  151. package/dist/lib/delivery/restore.js +134 -0
  152. package/dist/lib/delivery/rpc/client.d.ts +22 -0
  153. package/dist/lib/delivery/rpc/client.js +159 -0
  154. package/dist/lib/delivery/rpc/port.d.ts +40 -0
  155. package/dist/lib/delivery/rpc/port.js +16 -0
  156. package/dist/lib/delivery/rpc/server.d.ts +30 -0
  157. package/dist/lib/delivery/rpc/server.js +205 -0
  158. package/dist/lib/delivery/rpc/wire.d.ts +85 -0
  159. package/dist/lib/delivery/rpc/wire.js +143 -0
  160. package/dist/lib/delivery/store.d.ts +163 -0
  161. package/dist/lib/delivery/store.js +944 -0
  162. package/dist/lib/delivery/windows-service-install.d.ts +262 -0
  163. package/dist/lib/delivery/windows-service-install.js +892 -0
  164. package/dist/lib/delivery/workers/macos-job-helper.d.ts +103 -0
  165. package/dist/lib/delivery/workers/macos-job-helper.js +927 -0
  166. package/dist/lib/delivery/workers/macos.d.ts +191 -0
  167. package/dist/lib/delivery/workers/macos.js +943 -0
  168. package/dist/lib/delivery/workers/windows-job-helper.d.ts +35 -0
  169. package/dist/lib/delivery/workers/windows-job-helper.js +264 -0
  170. package/dist/lib/delivery/workers/windows-service-live.d.ts +121 -0
  171. package/dist/lib/delivery/workers/windows-service-live.js +711 -0
  172. package/dist/lib/delivery/workers/windows-service-runner.d.ts +33 -0
  173. package/dist/lib/delivery/workers/windows-service-runner.js +82 -0
  174. package/dist/lib/delivery/workers/windows-service.d.ts +140 -0
  175. package/dist/lib/delivery/workers/windows-service.js +584 -0
  176. package/dist/lib/delivery/workers/windows.d.ts +251 -0
  177. package/dist/lib/delivery/workers/windows.js +594 -0
  178. package/dist/lib/hot-channels/adapters/meetings.d.ts +15 -0
  179. package/dist/lib/hot-channels/adapters/meetings.js +36 -3
  180. package/dist/lib/hot-channels/signals-pass.d.ts +10 -0
  181. package/dist/lib/hot-channels/signals-pass.js +71 -2
  182. package/dist/lib/hot-channels/signals-redo.js +10 -2
  183. package/dist/lib/install/provider-wrappers.d.ts +2 -0
  184. package/dist/lib/install/provider-wrappers.js +68 -3
  185. package/dist/lib/lanes/watcher.js +35 -0
  186. package/dist/lib/signals/steps/extract.js +40 -4
  187. package/dist/schemas/hq-available-ai.v1.schema.json +76 -0
  188. package/dist/utils/catalog-runtime-paths.d.ts +34 -0
  189. package/dist/utils/catalog-runtime-paths.js +53 -0
  190. package/dist/utils/cognito-callback-port.d.ts +14 -0
  191. package/dist/utils/cognito-callback-port.js +24 -0
  192. package/dist/utils/cognito-session.js +3 -3
  193. package/dist/utils/deleted-company-notice.d.ts +59 -0
  194. package/dist/utils/deleted-company-notice.js +156 -0
  195. package/dist/utils/files-browse-acl.js +1 -1
  196. package/dist/utils/login-browser.d.ts +1 -1
  197. package/dist/utils/login-browser.js +7 -5
  198. package/dist/utils/resident-package-preload.js +30 -15
  199. package/dist/utils/vault-api.js +7 -0
  200. package/package.json +7 -7
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The native Windows Job Object supervisor (US-006), as C# source.
3
+ *
4
+ * Node cannot create a Job Object or start a process suspended, so the worker
5
+ * compiles this source once with the csc.exe that ships with the .NET
6
+ * Framework 4 in every supported Windows install, and runs the result as a
7
+ * small supervisor per job. No package or system software is installed.
8
+ *
9
+ * Protocol. The worker writes the spec to the helper's stdin as
10
+ * "key<TAB>base64(utf8 value)" lines ended by "end". Keys: app, cmd, cwd,
11
+ * log, env (one line per KEY=VALUE), mem (bytes), procs, cpu (ms). The helper
12
+ * writes one event per stdout line:
13
+ * started <pid> the root process is in the job and resumed
14
+ * process <pid> a process joined the job
15
+ * exit <reason> <code> the job is empty; reason is exited, cancelled,
16
+ * memory_limit, process_limit or cpu_limit
17
+ * error <stage> <win32> the job could not be set up; nothing was resumed
18
+ * After "end", a stdin line "cancel", or stdin closing, terminates the job.
19
+ *
20
+ * Containment. One job per run with KILL_ON_JOB_CLOSE, a job memory limit, an
21
+ * active process limit, a per-job user CPU time limit and
22
+ * DIE_ON_UNHANDLED_EXCEPTION. Breakaway is not allowed, so
23
+ * CREATE_BREAKAWAY_FROM_JOB fails for a process directly in the job. A process
24
+ * in a nested job that allows breakaway (node puts its children in one) may
25
+ * leave that inner job, but it stays in this one. The root process is created
26
+ * suspended, assigned to the job, and only then resumed, so it never runs
27
+ * outside the job. The helper holds the only job handle: if the helper dies
28
+ * for any reason the handle closes and Windows kills the whole tree. When the
29
+ * root process exits, the rest of the tree is terminated with it.
30
+ *
31
+ * "--selftest" builds a job with the same limits, reads them back and prints
32
+ * "selftest ok"; the worker runs it after every build.
33
+ */
34
+ export declare const HELPER_SOURCE: string;
35
+ //# sourceMappingURL=windows-job-helper.d.ts.map
@@ -0,0 +1,264 @@
1
+ /**
2
+ * The native Windows Job Object supervisor (US-006), as C# source.
3
+ *
4
+ * Node cannot create a Job Object or start a process suspended, so the worker
5
+ * compiles this source once with the csc.exe that ships with the .NET
6
+ * Framework 4 in every supported Windows install, and runs the result as a
7
+ * small supervisor per job. No package or system software is installed.
8
+ *
9
+ * Protocol. The worker writes the spec to the helper's stdin as
10
+ * "key<TAB>base64(utf8 value)" lines ended by "end". Keys: app, cmd, cwd,
11
+ * log, env (one line per KEY=VALUE), mem (bytes), procs, cpu (ms). The helper
12
+ * writes one event per stdout line:
13
+ * started <pid> the root process is in the job and resumed
14
+ * process <pid> a process joined the job
15
+ * exit <reason> <code> the job is empty; reason is exited, cancelled,
16
+ * memory_limit, process_limit or cpu_limit
17
+ * error <stage> <win32> the job could not be set up; nothing was resumed
18
+ * After "end", a stdin line "cancel", or stdin closing, terminates the job.
19
+ *
20
+ * Containment. One job per run with KILL_ON_JOB_CLOSE, a job memory limit, an
21
+ * active process limit, a per-job user CPU time limit and
22
+ * DIE_ON_UNHANDLED_EXCEPTION. Breakaway is not allowed, so
23
+ * CREATE_BREAKAWAY_FROM_JOB fails for a process directly in the job. A process
24
+ * in a nested job that allows breakaway (node puts its children in one) may
25
+ * leave that inner job, but it stays in this one. The root process is created
26
+ * suspended, assigned to the job, and only then resumed, so it never runs
27
+ * outside the job. The helper holds the only job handle: if the helper dies
28
+ * for any reason the handle closes and Windows kills the whole tree. When the
29
+ * root process exits, the rest of the tree is terminated with it.
30
+ *
31
+ * "--selftest" builds a job with the same limits, reads them back and prints
32
+ * "selftest ok"; the worker runs it after every build.
33
+ */
34
+ export const HELPER_SOURCE = String.raw `
35
+ using System;
36
+ using System.Collections.Generic;
37
+ using System.IO;
38
+ using System.Runtime.InteropServices;
39
+ using System.Text;
40
+ using System.Threading;
41
+
42
+ static class HqJob {
43
+ const uint CREATE_SUSPENDED = 0x4, CREATE_UNICODE_ENVIRONMENT = 0x400, CREATE_NO_WINDOW = 0x08000000;
44
+ const uint LIMIT_JOB_TIME = 0x4, LIMIT_ACTIVE_PROCESS = 0x8, LIMIT_JOB_MEMORY = 0x200;
45
+ const uint LIMIT_DIE_ON_UNHANDLED_EXCEPTION = 0x400, LIMIT_KILL_ON_JOB_CLOSE = 0x2000;
46
+ const int BasicAccounting = 1, BasicProcessIdList = 3, PortAssociation = 7, ExtendedLimit = 9;
47
+ const uint MSG_END_OF_JOB_TIME = 1, MSG_ACTIVE_PROCESS_LIMIT = 3, MSG_ACTIVE_PROCESS_ZERO = 4, MSG_NEW_PROCESS = 6;
48
+ const uint MSG_PROCESS_MEMORY_LIMIT = 9, MSG_JOB_MEMORY_LIMIT = 10;
49
+
50
+ [StructLayout(LayoutKind.Sequential)]
51
+ struct BASIC_LIMIT { public long PerProcessUserTimeLimit, PerJobUserTimeLimit; public uint LimitFlags; public UIntPtr MinimumWorkingSetSize, MaximumWorkingSetSize; public uint ActiveProcessLimit; public UIntPtr Affinity; public uint PriorityClass, SchedulingClass; }
52
+ [StructLayout(LayoutKind.Sequential)]
53
+ struct IO_COUNTERS { public ulong ReadOps, WriteOps, OtherOps, ReadBytes, WriteBytes, OtherBytes; }
54
+ [StructLayout(LayoutKind.Sequential)]
55
+ struct EXT_LIMIT { public BASIC_LIMIT Basic; public IO_COUNTERS Io; public UIntPtr ProcessMemoryLimit, JobMemoryLimit, PeakProcessMemoryUsed, PeakJobMemoryUsed; }
56
+ [StructLayout(LayoutKind.Sequential)]
57
+ struct PORT_ASSOC { public IntPtr CompletionKey, CompletionPort; }
58
+ [StructLayout(LayoutKind.Sequential)]
59
+ struct BASIC_ACCOUNTING { public long TotalUserTime, TotalKernelTime, ThisPeriodTotalUserTime, ThisPeriodTotalKernelTime; public uint TotalPageFaultCount, TotalProcesses, ActiveProcesses, TotalTerminatedProcesses; }
60
+ [StructLayout(LayoutKind.Sequential)]
61
+ struct SECURITY_ATTRIBUTES { public int nLength; public IntPtr lpSecurityDescriptor; public bool bInheritHandle; }
62
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
63
+ struct STARTUPINFO { public int cb; public string lpReserved, lpDesktop, lpTitle; public int dwX, dwY, dwXSize, dwYSize, dwXCountChars, dwYCountChars, dwFillAttribute, dwFlags; public short wShowWindow, cbReserved2; public IntPtr lpReserved2, hStdInput, hStdOutput, hStdError; }
64
+ [StructLayout(LayoutKind.Sequential)]
65
+ struct PROCESS_INFORMATION { public IntPtr hProcess, hThread; public int dwProcessId, dwThreadId; }
66
+
67
+ [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] static extern IntPtr CreateJobObjectW(IntPtr sa, string name);
68
+ [DllImport("kernel32.dll", SetLastError = true)] static extern bool SetInformationJobObject(IntPtr job, int cls, ref EXT_LIMIT info, int size);
69
+ [DllImport("kernel32.dll", SetLastError = true)] static extern bool SetInformationJobObject(IntPtr job, int cls, ref PORT_ASSOC info, int size);
70
+ [DllImport("kernel32.dll", SetLastError = true)] static extern bool QueryInformationJobObject(IntPtr job, int cls, ref EXT_LIMIT info, int size, IntPtr ret);
71
+ [DllImport("kernel32.dll", SetLastError = true)] static extern bool QueryInformationJobObject(IntPtr job, int cls, ref BASIC_ACCOUNTING info, int size, IntPtr ret);
72
+ [DllImport("kernel32.dll", SetLastError = true)] static extern bool QueryInformationJobObject(IntPtr job, int cls, IntPtr info, int size, IntPtr ret);
73
+ [DllImport("kernel32.dll", SetLastError = true)] static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process);
74
+ [DllImport("kernel32.dll", SetLastError = true)] static extern bool TerminateJobObject(IntPtr job, uint code);
75
+ [DllImport("kernel32.dll", SetLastError = true)] static extern IntPtr CreateIoCompletionPort(IntPtr file, IntPtr port, UIntPtr key, uint threads);
76
+ [DllImport("kernel32.dll", SetLastError = true)] static extern bool GetQueuedCompletionStatus(IntPtr port, out uint bytes, out IntPtr key, out IntPtr overlapped, uint ms);
77
+ [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] static extern IntPtr CreateFileW(string name, uint access, uint share, ref SECURITY_ATTRIBUTES sa, uint disposition, uint flags, IntPtr template);
78
+ [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] static extern bool CreateProcessW(string app, StringBuilder cmd, IntPtr pa, IntPtr ta, bool inherit, uint flags, IntPtr env, string cwd, ref STARTUPINFO si, out PROCESS_INFORMATION pi);
79
+ [DllImport("kernel32.dll", SetLastError = true)] static extern uint ResumeThread(IntPtr thread);
80
+ [DllImport("kernel32.dll", SetLastError = true)] static extern bool TerminateProcess(IntPtr process, uint code);
81
+ [DllImport("kernel32.dll", SetLastError = true)] static extern uint WaitForSingleObject(IntPtr handle, uint ms);
82
+ [DllImport("kernel32.dll", SetLastError = true)] static extern bool GetExitCodeProcess(IntPtr process, out uint code);
83
+ [DllImport("kernel32.dll", SetLastError = true)] static extern bool CloseHandle(IntPtr handle);
84
+ [DllImport("kernel32.dll", SetLastError = true)] static extern IntPtr GetStdHandle(int which);
85
+ [DllImport("kernel32.dll", SetLastError = true)] static extern bool SetHandleInformation(IntPtr handle, uint mask, uint flags);
86
+
87
+ static readonly object outLock = new object();
88
+ static StreamWriter stdout;
89
+ static IntPtr job;
90
+ static readonly HashSet<long> seen = new HashSet<long>();
91
+ static string reason;
92
+ static uint reasonCode;
93
+
94
+ static void Emit(string line) { lock (outLock) { stdout.Write(line + "\n"); stdout.Flush(); } }
95
+
96
+ static void Seen(long pid) {
97
+ bool added;
98
+ lock (seen) added = seen.Add(pid);
99
+ if (added) Emit("process " + pid);
100
+ }
101
+
102
+ /** The first reason wins. A limit or a cancel terminates the job at once. */
103
+ static void Stop(string why, uint code) {
104
+ lock (outLock) {
105
+ if (reason != null) return;
106
+ reason = why;
107
+ reasonCode = code;
108
+ }
109
+ TerminateJobObject(job, code);
110
+ }
111
+
112
+ static EXT_LIMIT Limits(long mem, uint procs, long cpuMs) {
113
+ var ext = new EXT_LIMIT();
114
+ ext.Basic.LimitFlags = LIMIT_KILL_ON_JOB_CLOSE | LIMIT_JOB_MEMORY | LIMIT_ACTIVE_PROCESS | LIMIT_JOB_TIME | LIMIT_DIE_ON_UNHANDLED_EXCEPTION;
115
+ ext.Basic.PerJobUserTimeLimit = cpuMs * 10000;
116
+ ext.Basic.ActiveProcessLimit = procs;
117
+ ext.JobMemoryLimit = new UIntPtr((ulong)mem);
118
+ return ext;
119
+ }
120
+
121
+ static int SelfTest() {
122
+ IntPtr j = CreateJobObjectW(IntPtr.Zero, null);
123
+ if (j == IntPtr.Zero) { Emit("error create " + Marshal.GetLastWin32Error()); return 3; }
124
+ var ext = Limits(64L << 20, 4, 1000);
125
+ if (!SetInformationJobObject(j, ExtendedLimit, ref ext, Marshal.SizeOf(typeof(EXT_LIMIT)))) { Emit("error limits " + Marshal.GetLastWin32Error()); return 3; }
126
+ var back = new EXT_LIMIT();
127
+ if (!QueryInformationJobObject(j, ExtendedLimit, ref back, Marshal.SizeOf(typeof(EXT_LIMIT)), IntPtr.Zero)) { Emit("error query " + Marshal.GetLastWin32Error()); return 3; }
128
+ bool ok = back.Basic.LimitFlags == ext.Basic.LimitFlags && back.Basic.ActiveProcessLimit == 4 && back.JobMemoryLimit.ToUInt64() == (64UL << 20) && back.Basic.PerJobUserTimeLimit == 1000L * 10000;
129
+ CloseHandle(j);
130
+ Emit(ok ? "selftest ok" : "selftest mismatch");
131
+ return ok ? 0 : 3;
132
+ }
133
+
134
+ static string EnvBlock(List<string> pairs) {
135
+ pairs.Sort((a, b) => string.Compare(a.Substring(0, a.IndexOf('=')), b.Substring(0, b.IndexOf('=')), StringComparison.OrdinalIgnoreCase));
136
+ var sb = new StringBuilder();
137
+ foreach (var p in pairs) { sb.Append(p); sb.Append('\0'); }
138
+ sb.Append('\0');
139
+ return sb.ToString();
140
+ }
141
+
142
+ static void PollList() {
143
+ int size = 8 + IntPtr.Size * 1024;
144
+ IntPtr buf = Marshal.AllocHGlobal(size);
145
+ try {
146
+ if (!QueryInformationJobObject(job, BasicProcessIdList, buf, size, IntPtr.Zero)) return;
147
+ int n = Marshal.ReadInt32(buf, 4);
148
+ for (int i = 0; i < n; i++) Seen(Marshal.ReadIntPtr(buf, 8 + i * IntPtr.Size).ToInt64());
149
+ } finally { Marshal.FreeHGlobal(buf); }
150
+ }
151
+
152
+ /** Returns true when the job has no processes left. */
153
+ static bool Handle(uint msg, IntPtr ov) {
154
+ if (msg == MSG_NEW_PROCESS) Seen(ov.ToInt64());
155
+ else if (msg == MSG_JOB_MEMORY_LIMIT || msg == MSG_PROCESS_MEMORY_LIMIT) Stop("memory_limit", 0xE0000001);
156
+ else if (msg == MSG_ACTIVE_PROCESS_LIMIT) Stop("process_limit", 0xE0000002);
157
+ else if (msg == MSG_END_OF_JOB_TIME) Stop("cpu_limit", 0xE0000003);
158
+ else if (msg == MSG_ACTIVE_PROCESS_ZERO) return true;
159
+ return false;
160
+ }
161
+
162
+ static int Main(string[] args) {
163
+ stdout = new StreamWriter(Console.OpenStandardOutput(), new UTF8Encoding(false));
164
+ if (args.Length == 1 && args[0] == "--selftest") return SelfTest();
165
+
166
+ // The helper's own pipes to the worker must not leak into the job.
167
+ for (int i = -10; i >= -12; i--) SetHandleInformation(GetStdHandle(i), 1, 0);
168
+
169
+ var input = new StreamReader(Console.OpenStandardInput(), new UTF8Encoding(false));
170
+ var spec = new Dictionary<string, string>();
171
+ var env = new List<string>();
172
+ for (string line; (line = input.ReadLine()) != null && line != "end";) {
173
+ int tab = line.IndexOf('\t');
174
+ if (tab < 0) continue;
175
+ string key = line.Substring(0, tab), val = Encoding.UTF8.GetString(Convert.FromBase64String(line.Substring(tab + 1)));
176
+ if (key == "env") env.Add(val); else spec[key] = val;
177
+ }
178
+
179
+ job = CreateJobObjectW(IntPtr.Zero, null);
180
+ if (job == IntPtr.Zero) { Emit("error create " + Marshal.GetLastWin32Error()); return 3; }
181
+ var ext = Limits(long.Parse(spec["mem"]), uint.Parse(spec["procs"]), long.Parse(spec["cpu"]));
182
+ if (!SetInformationJobObject(job, ExtendedLimit, ref ext, Marshal.SizeOf(typeof(EXT_LIMIT)))) { Emit("error limits " + Marshal.GetLastWin32Error()); return 3; }
183
+ IntPtr port = CreateIoCompletionPort(new IntPtr(-1), IntPtr.Zero, UIntPtr.Zero, 1);
184
+ var assoc = new PORT_ASSOC { CompletionKey = job, CompletionPort = port };
185
+ if (port == IntPtr.Zero || !SetInformationJobObject(job, PortAssociation, ref assoc, Marshal.SizeOf(typeof(PORT_ASSOC)))) { Emit("error port " + Marshal.GetLastWin32Error()); return 3; }
186
+
187
+ var sa = new SECURITY_ATTRIBUTES { nLength = Marshal.SizeOf(typeof(SECURITY_ATTRIBUTES)), bInheritHandle = true };
188
+ IntPtr log = CreateFileW(spec["log"], 0x40000000, 7, ref sa, 2, 0x80, IntPtr.Zero);
189
+ IntPtr nul = CreateFileW("NUL", 0x80000000, 3, ref sa, 3, 0, IntPtr.Zero);
190
+ if (log == new IntPtr(-1) || nul == new IntPtr(-1)) { Emit("error log " + Marshal.GetLastWin32Error()); return 3; }
191
+
192
+ var si = new STARTUPINFO { cb = Marshal.SizeOf(typeof(STARTUPINFO)), dwFlags = 0x100, hStdInput = nul, hStdOutput = log, hStdError = log };
193
+ IntPtr block = Marshal.StringToHGlobalUni(EnvBlock(env));
194
+ PROCESS_INFORMATION pi;
195
+ bool created = CreateProcessW(spec["app"], new StringBuilder(spec["cmd"]), IntPtr.Zero, IntPtr.Zero, true,
196
+ CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT | CREATE_NO_WINDOW, block, spec["cwd"], ref si, out pi);
197
+ int createErr = Marshal.GetLastWin32Error();
198
+ Marshal.FreeHGlobal(block);
199
+ CloseHandle(log);
200
+ CloseHandle(nul);
201
+ if (!created) { Emit("error create_process " + createErr); return 3; }
202
+ if (!AssignProcessToJobObject(job, pi.hProcess)) {
203
+ int err = Marshal.GetLastWin32Error();
204
+ TerminateProcess(pi.hProcess, 1);
205
+ Emit("error assign " + err);
206
+ return 3;
207
+ }
208
+ // The root is in the job but still suspended. If it cannot be resumed it
209
+ // never runs: terminate the job so nothing is left behind, and report it.
210
+ if (ResumeThread(pi.hThread) == 0xFFFFFFFF) {
211
+ int err = Marshal.GetLastWin32Error();
212
+ TerminateJobObject(job, 1);
213
+ CloseHandle(pi.hThread);
214
+ Emit("error resume " + err);
215
+ return 3;
216
+ }
217
+ CloseHandle(pi.hThread);
218
+ Emit("started " + pi.dwProcessId);
219
+ Seen(pi.dwProcessId);
220
+
221
+ var reader = new Thread(() => {
222
+ try {
223
+ for (string line; (line = input.ReadLine()) != null;) if (line == "cancel") break;
224
+ } catch (Exception) { }
225
+ Stop("cancelled", 0xE0000000);
226
+ });
227
+ reader.IsBackground = true;
228
+ reader.Start();
229
+
230
+ bool rootDone = false;
231
+ uint rootCode = 0;
232
+ long cpuLimit = long.Parse(spec["cpu"]) * 10000;
233
+ for (;;) {
234
+ uint msg; IntPtr key, ov;
235
+ if (GetQueuedCompletionStatus(port, out msg, out key, out ov, 200)) {
236
+ if (Handle(msg, ov)) break;
237
+ } else {
238
+ PollList();
239
+ var acct = new BASIC_ACCOUNTING();
240
+ if (QueryInformationJobObject(job, BasicAccounting, ref acct, Marshal.SizeOf(typeof(BASIC_ACCOUNTING)), IntPtr.Zero)) {
241
+ if (acct.TotalUserTime >= cpuLimit) Stop("cpu_limit", 0xE0000003);
242
+ if (acct.ActiveProcesses == 0) break;
243
+ }
244
+ }
245
+ if (!rootDone && WaitForSingleObject(pi.hProcess, 0) == 0) {
246
+ rootDone = true;
247
+ GetExitCodeProcess(pi.hProcess, out rootCode);
248
+ // A limit message posted before the root exited is still queued; read it first.
249
+ bool empty = false;
250
+ while (GetQueuedCompletionStatus(port, out msg, out key, out ov, 0)) if (Handle(msg, ov)) { empty = true; break; }
251
+ Stop("exited", rootCode);
252
+ if (empty) break;
253
+ }
254
+ }
255
+ if (!rootDone) GetExitCodeProcess(pi.hProcess, out rootCode);
256
+ string why;
257
+ uint code;
258
+ lock (outLock) { why = reason ?? "exited"; code = reason == null ? rootCode : (reason == "exited" ? rootCode : reasonCode); }
259
+ Emit("exit " + why + " " + code);
260
+ return 0;
261
+ }
262
+ }
263
+ `;
264
+ //# sourceMappingURL=windows-job-helper.js.map
@@ -0,0 +1,121 @@
1
+ export interface LiveHost {
2
+ run(file: string, args: string[]): {
3
+ status: number | null;
4
+ stdout: string;
5
+ stderr: string;
6
+ };
7
+ }
8
+ export declare const realLiveHost: LiveHost;
9
+ export interface LiveOptions {
10
+ root: string;
11
+ service: string;
12
+ host: LiveHost;
13
+ out: (line: string) => void;
14
+ systemRoot?: string;
15
+ /** The node the fixture jobs run under. Defaults to the installed runtime\node.exe. */
16
+ node?: string;
17
+ /** PIDs of live processes whose command line holds the token. Defaults to a Win32_Process query. */
18
+ tokenPids?: (token: string) => number[];
19
+ /** Every PID in an OS process listing. Defaults to tasklist. */
20
+ listedPids?: () => Set<number>;
21
+ /** How long a job may take to reach a terminal outcome. */
22
+ outcomeTimeoutMs?: number;
23
+ /** Tests only: where ServiceProfiles is. Defaults to <SystemRoot>\\ServiceProfiles. */
24
+ serviceProfilesDir?: string;
25
+ /** How long to wait for Windows to create the profile after the first start. Capped at 10 s. */
26
+ postStartWaitMs?: number;
27
+ /** Tests only: the pause between polls. */
28
+ sleepMs?: (ms: number) => Promise<void>;
29
+ }
30
+ /**
31
+ * Review C4: Windows creates the service profile at the first start. If ServiceProfiles\<service> (any type) or
32
+ * ProfileList\<SID> exists before that, it was left by an earlier run or planted, and must be cleared by rollback
33
+ * first. "Never started" is the absence of config\first-start.json, which only Administrators can write. The marker
34
+ * is written only after the post-start check passes (checkAfterFirstStart). Returns the refusal, or null.
35
+ */
36
+ export declare function checkBeforeFirstStart(o: LiveOptions): string | null;
37
+ /**
38
+ * Review R8: right after the first start, the profile Windows created must pass the same folder checks rollback
39
+ * uses (profileFolderCheck: exact path, no link, owner SYSTEM/Administrators/service SID, protected DACL, no other
40
+ * writer, explicit allow ACE for the service SID, ProfileList path matches). Windows may create it lazily, so it is
41
+ * polled for at most 10 s; still absent is a failure. On any failure the service is stopped and no marker is
42
+ * written, so the next run repeats the pre-start check (and refuses, because the folder now exists). On success
43
+ * config\first-start.json is written. Returns the failure, or null.
44
+ */
45
+ export declare function checkAfterFirstStart(o: LiveOptions): Promise<string | null>;
46
+ /** The image names these checks start, directly or through the service. Nothing else may be ended on their account. */
47
+ export declare const LIVE_PROCESS_NAMES: readonly ["node.exe", "hqjob.exe", "whoami.exe", "HQNDUS006040.exe", "sc.exe", "reg.exe", "tasklist.exe", "taskkill.exe", "schtasks.exe", "powershell.exe"];
48
+ export interface WhoamiVerdict {
49
+ pass: boolean;
50
+ reasons: string[];
51
+ privileges: string[];
52
+ /** Privileges in the token that are not in ALWAYS_GRANTED_PRIVILEGES. Any entry fails N1. */
53
+ extraPrivileges: string[];
54
+ }
55
+ /**
56
+ * Privileges Windows leaves in a service token whatever the service's
57
+ * required-privileges list says. The installer trims the service to
58
+ * SeChangeNotifyPrivilege, which is also the one privilege the service
59
+ * manager never removes, so that is the whole list. Anything else in a job's
60
+ * token means the trim did not take effect.
61
+ */
62
+ export declare const ALWAYS_GRANTED_PRIVILEGES: readonly string[];
63
+ /**
64
+ * Judge "whoami /all" output by SID, which does not depend on the display
65
+ * language: the user is the service's virtual account, the token carries the
66
+ * SERVICE logon group, and it carries neither Administrators (in any form,
67
+ * deny-only included) nor an interactive or remote-interactive logon.
68
+ */
69
+ export declare function evaluateWhoami(text: string, service: string): WhoamiVerdict;
70
+ /** The node script the N2 jobs run: argv is mode pidDir token role; every process writes <role>.pid. */
71
+ export declare const LIVE_FIXTURE_SOURCE: string;
72
+ interface CaseResult {
73
+ name: string;
74
+ pass: boolean;
75
+ detail: string;
76
+ }
77
+ /** Cancel a four-process tree, one of them detached, through the service. */
78
+ export declare function cancelCase(o: LiveOptions, dir: string): Promise<CaseResult>;
79
+ /**
80
+ * True when the text is exactly one "tasklist /V /FO CSV /NH" row for a
81
+ * node.exe with this pid whose User Name column is the service account. Only
82
+ * that column is compared: the window title is set by the process itself.
83
+ */
84
+ export declare function isRunnerRow(text: string, pid: number, service: string): boolean;
85
+ /**
86
+ * Runs as the job. argv: root decoyQueueEntry decoyStateFile tag. It tries
87
+ * each access once and prints one JSON line. A write that is allowed is
88
+ * undone at once; the two open-for-write probes change no bytes.
89
+ */
90
+ export declare const ACL_PROBE_SOURCE: string;
91
+ export interface AclProbeRow {
92
+ op: string;
93
+ result: "denied" | "allowed" | "error";
94
+ code: string;
95
+ }
96
+ /** The probe line from a job log, or nothing. */
97
+ export declare function parseAclProbe(log: string): AclProbeRow[];
98
+ export declare function evaluateAclProbe(rows: AclProbeRow[]): {
99
+ pass: boolean;
100
+ lines: string[];
101
+ };
102
+ export declare function n1(o: LiveOptions): Promise<boolean>;
103
+ export declare function n2(o: LiveOptions): Promise<boolean>;
104
+ /** After rollback: every place the pilot could have left something. Read-only. */
105
+ /** True only for N3 PASS. */
106
+ export declare function n3(o: LiveOptions): boolean;
107
+ /**
108
+ * After rollback: every place the pilot could have left something. Read-only. "pending" (exit 3) only when the
109
+ * service profile held by Windows (its folder, ProfileList key and loaded hives) is all that is left and at least
110
+ * one hive is loaded: the two-phase uninstall's state before restart. It is not a pass.
111
+ */
112
+ export declare function n3Status(o: LiveOptions): "pass" | "pending" | "fail";
113
+ export declare function liveMain(argv: string[], host?: LiveHost, platform?: NodeJS.Platform, out?: (s: string) => void,
114
+ /** The only names the checks may act on. Tests pass a scratch root; the command line cannot. */
115
+ allowed?: {
116
+ service: string;
117
+ root: string;
118
+ serviceProfilesDir?: string;
119
+ }): Promise<number>;
120
+ export {};
121
+ //# sourceMappingURL=windows-service-live.d.ts.map