dsh-remote 0.8.94 → 1.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 (196) hide show
  1. package/LICENSE +21 -21
  2. package/README.en.md +128 -370
  3. package/README.md +129 -355
  4. package/cordis.patch.yml +9 -9
  5. package/lib/audit.js +45 -45
  6. package/lib/auto-update.js +70 -0
  7. package/lib/binding.js +174 -172
  8. package/lib/boot.js +42 -42
  9. package/lib/client.js +6381 -4662
  10. package/lib/credential.js +277 -270
  11. package/lib/errors.js +141 -141
  12. package/lib/exec-job.js +245 -242
  13. package/lib/file-changes.js +57 -0
  14. package/lib/file-reference.js +457 -457
  15. package/lib/forwards.js +258 -258
  16. package/lib/host-api.js +822 -822
  17. package/lib/hostkey.js +108 -108
  18. package/lib/http-transport.js +201 -201
  19. package/lib/ignore.js +202 -202
  20. package/lib/index.js +4555 -4488
  21. package/lib/instructions-dynamic.js +415 -415
  22. package/lib/instructions.js +288 -288
  23. package/lib/open-folder.js +56 -56
  24. package/lib/openssh.js +950 -940
  25. package/lib/paths.js +292 -292
  26. package/lib/pool.js +1029 -1029
  27. package/lib/posix-shell.cjs +34 -34
  28. package/lib/registry.js +296 -296
  29. package/lib/remote-fs.js +179 -173
  30. package/lib/remote-git.js +127 -0
  31. package/lib/remote-sandbox.js +183 -183
  32. package/lib/remote-shell-child.cjs +460 -397
  33. package/lib/remote-shell.js +697 -697
  34. package/lib/remote-skills.js +312 -312
  35. package/lib/remote-write.js +51 -0
  36. package/lib/routes-audit.js +58 -58
  37. package/lib/routes-forwards.js +72 -72
  38. package/lib/routes-fs.js +299 -251
  39. package/lib/routes-machines.js +217 -186
  40. package/lib/routes-misc.js +187 -187
  41. package/lib/routes-term.js +169 -169
  42. package/lib/routes-update.js +147 -143
  43. package/lib/routes-web-attach.js +121 -112
  44. package/lib/routes-workspace.js +325 -312
  45. package/lib/search.js +235 -235
  46. package/lib/self-heal.js +130 -130
  47. package/lib/sftp-surface.js +119 -119
  48. package/lib/sshconfig.js +779 -779
  49. package/lib/sync-status.js +31 -0
  50. package/lib/sync.js +350 -350
  51. package/lib/tasks.js +95 -95
  52. package/lib/telemetry.js +247 -247
  53. package/lib/terminal.js +205 -205
  54. package/lib/tui/flow.js +130 -130
  55. package/lib/tui/format.js +380 -380
  56. package/lib/tui/i18n.js +350 -350
  57. package/lib/tui/index.js +531 -531
  58. package/lib/tui/provider.js +344 -344
  59. package/lib/tui/scene.js +986 -986
  60. package/lib/update.js +497 -490
  61. package/lib/vendor/jsdiff/LICENSE +29 -0
  62. package/lib/vendor/jsdiff/SOURCE.md +4 -0
  63. package/lib/vendor/jsdiff/diff/base.js +254 -0
  64. package/lib/vendor/jsdiff/diff/line.js +66 -0
  65. package/lib/vendor/jsdiff/patch/create.js +229 -0
  66. package/lib/vendor/jsdiff/util/params.js +15 -0
  67. package/lib/web-attach.js +1081 -860
  68. package/lib/workspace-cleanup.js +337 -337
  69. package/lib/workspace-search.js +219 -0
  70. package/node_modules/buildcheck/.eslintrc.js +5 -0
  71. package/node_modules/buildcheck/.github/workflows/ci.yml +88 -0
  72. package/node_modules/buildcheck/.github/workflows/lint.yml +27 -0
  73. package/node_modules/buildcheck/.npmignore +3 -0
  74. package/node_modules/buildcheck/LICENSE +19 -0
  75. package/node_modules/buildcheck/README.md +106 -0
  76. package/node_modules/buildcheck/deps/Find-VisualStudio.cs +250 -0
  77. package/node_modules/buildcheck/lib/findvs.js +361 -0
  78. package/node_modules/buildcheck/lib/index.js +738 -0
  79. package/node_modules/buildcheck/package.json +36 -0
  80. package/node_modules/buildcheck/test/test.js +8 -0
  81. package/node_modules/cpu-features/.eslintrc.js +5 -0
  82. package/node_modules/cpu-features/.github/workflows/ci.yml +74 -0
  83. package/node_modules/cpu-features/.github/workflows/lint.yml +27 -0
  84. package/node_modules/cpu-features/LICENSE +19 -0
  85. package/node_modules/cpu-features/README.md +59 -0
  86. package/node_modules/cpu-features/binding.gyp +16 -0
  87. package/node_modules/cpu-features/buildcheck.js +32 -0
  88. package/node_modules/cpu-features/deps/cpu_features/.clang-format +4 -0
  89. package/node_modules/cpu-features/deps/cpu_features/.dockerignore +31 -0
  90. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/Dockerfile +5 -0
  91. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/aarch64_linux_cmake.yml +30 -0
  92. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_freebsd_cmake.yml +22 -0
  93. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_linux_bazel.yml +26 -0
  94. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_linux_cmake.yml +31 -0
  95. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_macos_cmake.yml +43 -0
  96. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_windows_cmake.yml +25 -0
  97. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/arm_linux_cmake.yml +31 -0
  98. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/clang_format.yml +24 -0
  99. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/mips_linux_cmake.yml +30 -0
  100. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/power_linux_cmake.yml +29 -0
  101. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/riscv_linux_cmake.yml +28 -0
  102. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/s390x_linux_cmake.yml +27 -0
  103. package/node_modules/cpu-features/deps/cpu_features/.grenrc.yml +21 -0
  104. package/node_modules/cpu-features/deps/cpu_features/BUILD.bazel +329 -0
  105. package/node_modules/cpu-features/deps/cpu_features/CMakeLists.txt +261 -0
  106. package/node_modules/cpu-features/deps/cpu_features/CONTRIBUTING.md +23 -0
  107. package/node_modules/cpu-features/deps/cpu_features/LICENSE +230 -0
  108. package/node_modules/cpu-features/deps/cpu_features/README.md +272 -0
  109. package/node_modules/cpu-features/deps/cpu_features/WORKSPACE +19 -0
  110. package/node_modules/cpu-features/deps/cpu_features/bazel/ci/README.md +5 -0
  111. package/node_modules/cpu-features/deps/cpu_features/bazel/platforms.bzl +11 -0
  112. package/node_modules/cpu-features/deps/cpu_features/cmake/CpuFeaturesConfig.cmake.in +3 -0
  113. package/node_modules/cpu-features/deps/cpu_features/cmake/CpuFeaturesNdkCompatConfig.cmake.in +3 -0
  114. package/node_modules/cpu-features/deps/cpu_features/cmake/README.md +30 -0
  115. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/Makefile +252 -0
  116. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/README.md +40 -0
  117. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/docker.dot +64 -0
  118. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/docker.svg +312 -0
  119. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/generate_image.sh +7 -0
  120. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/docker/amd64/Dockerfile +48 -0
  121. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/docker/toolchain/Dockerfile +34 -0
  122. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/sample/CMakeLists.txt +22 -0
  123. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/sample/main.cpp +11 -0
  124. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/vagrant/freebsd/Vagrantfile +107 -0
  125. package/node_modules/cpu-features/deps/cpu_features/cmake/googletest.CMakeLists.txt.in +15 -0
  126. package/node_modules/cpu-features/deps/cpu_features/cpu_features.gyp +105 -0
  127. package/node_modules/cpu-features/deps/cpu_features/include/cpu_features_cache_info.h +54 -0
  128. package/node_modules/cpu-features/deps/cpu_features/include/cpu_features_macros.h +384 -0
  129. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_aarch64.h +259 -0
  130. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_arm.h +121 -0
  131. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_mips.h +74 -0
  132. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_ppc.h +149 -0
  133. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_riscv.h +72 -0
  134. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_s390x.h +108 -0
  135. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_x86.h +288 -0
  136. package/node_modules/cpu-features/deps/cpu_features/include/internal/bit_utils.h +40 -0
  137. package/node_modules/cpu-features/deps/cpu_features/include/internal/cpuid_x86.h +37 -0
  138. package/node_modules/cpu-features/deps/cpu_features/include/internal/filesystem.h +39 -0
  139. package/node_modules/cpu-features/deps/cpu_features/include/internal/hwcaps.h +240 -0
  140. package/node_modules/cpu-features/deps/cpu_features/include/internal/stack_line_reader.h +49 -0
  141. package/node_modules/cpu-features/deps/cpu_features/include/internal/string_view.h +110 -0
  142. package/node_modules/cpu-features/deps/cpu_features/include/internal/windows_utils.h +70 -0
  143. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/CMakeLists.txt +60 -0
  144. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/README.md +4 -0
  145. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/cpu-features.c +205 -0
  146. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/cpu-features.h +320 -0
  147. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/ndk-compat-test.c +12 -0
  148. package/node_modules/cpu-features/deps/cpu_features/patches/0001-Add-Apple-Silicon-Support.patch +456 -0
  149. package/node_modules/cpu-features/deps/cpu_features/scripts/generate_badges.d +165 -0
  150. package/node_modules/cpu-features/deps/cpu_features/scripts/make_release.sh +75 -0
  151. package/node_modules/cpu-features/deps/cpu_features/scripts/run_integration.sh +490 -0
  152. package/node_modules/cpu-features/deps/cpu_features/scripts/test_integration.sh +79 -0
  153. package/node_modules/cpu-features/deps/cpu_features/src/copy.inl +19 -0
  154. package/node_modules/cpu-features/deps/cpu_features/src/define_introspection.inl +86 -0
  155. package/node_modules/cpu-features/deps/cpu_features/src/define_introspection_and_hwcaps.inl +26 -0
  156. package/node_modules/cpu-features/deps/cpu_features/src/equals.inl +22 -0
  157. package/node_modules/cpu-features/deps/cpu_features/src/filesystem.c +62 -0
  158. package/node_modules/cpu-features/deps/cpu_features/src/hwcaps.c +169 -0
  159. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64__base_implementation.inl +88 -0
  160. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_linux_or_android.c +79 -0
  161. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_macos_or_iphone.c +82 -0
  162. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_windows.c +138 -0
  163. package/node_modules/cpu-features/deps/cpu_features/src/impl_arm_linux_or_android.c +212 -0
  164. package/node_modules/cpu-features/deps/cpu_features/src/impl_mips_linux_or_android.c +93 -0
  165. package/node_modules/cpu-features/deps/cpu_features/src/impl_ppc_linux.c +163 -0
  166. package/node_modules/cpu-features/deps/cpu_features/src/impl_riscv_linux.c +111 -0
  167. package/node_modules/cpu-features/deps/cpu_features/src/impl_s390x_linux.c +120 -0
  168. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86__base_implementation.inl +2055 -0
  169. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_freebsd.c +68 -0
  170. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_linux_or_android.c +58 -0
  171. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_macos.c +57 -0
  172. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_windows.c +58 -0
  173. package/node_modules/cpu-features/deps/cpu_features/src/stack_line_reader.c +132 -0
  174. package/node_modules/cpu-features/deps/cpu_features/src/string_view.c +192 -0
  175. package/node_modules/cpu-features/deps/cpu_features/src/utils/list_cpu_features.c +461 -0
  176. package/node_modules/cpu-features/deps/cpu_features/test/CMakeLists.txt +114 -0
  177. package/node_modules/cpu-features/deps/cpu_features/test/bit_utils_test.cc +53 -0
  178. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_aarch64_test.cc +396 -0
  179. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_arm_test.cc +384 -0
  180. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_mips_test.cc +176 -0
  181. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_ppc_test.cc +131 -0
  182. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_riscv_test.cc +180 -0
  183. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_s390x_test.cc +82 -0
  184. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_x86_test.cc +1729 -0
  185. package/node_modules/cpu-features/deps/cpu_features/test/filesystem_for_testing.cc +103 -0
  186. package/node_modules/cpu-features/deps/cpu_features/test/filesystem_for_testing.h +61 -0
  187. package/node_modules/cpu-features/deps/cpu_features/test/hwcaps_for_testing.cc +52 -0
  188. package/node_modules/cpu-features/deps/cpu_features/test/hwcaps_for_testing.h +31 -0
  189. package/node_modules/cpu-features/deps/cpu_features/test/stack_line_reader_test.cc +132 -0
  190. package/node_modules/cpu-features/deps/cpu_features/test/string_view_test.cc +202 -0
  191. package/node_modules/cpu-features/lib/index.js +5 -0
  192. package/node_modules/cpu-features/package.json +40 -0
  193. package/node_modules/cpu-features/src/binding.cc +151 -0
  194. package/node_modules/cpu-features/test/test.js +12 -0
  195. package/node_modules/nan/tools/1to2.js +0 -0
  196. package/package.json +107 -103
@@ -0,0 +1,219 @@
1
+ // Incremental remote workspace search. A job is owned by one session binding;
2
+ // cancelling it never closes the SSH pool used by other sessions or terminals.
3
+ import { randomUUID } from 'node:crypto'
4
+ import { joinRemotePath } from './paths.js'
5
+ import { requestSessionHint } from './binding.js'
6
+ import { matchGlob } from './search.js'
7
+
8
+ function interrupted(signal) { return Object.assign(new Error(signal.reason === 'timeout' ? 'Search time budget reached' : 'Search cancelled'), { name: 'AbortError' }) }
9
+ // A cancelled caller must stop waiting immediately, but an SSH request already
10
+ // sent still owns capacity until its actual promise settles. Otherwise rapid
11
+ // typing can leave unlimited abandoned reads on the shared SFTP channel.
12
+ class SearchOperations {
13
+ constructor(limit = 6) { this.limit = limit; this.active = 0; this.waiting = [] }
14
+ run(operation, signal) {
15
+ if (signal.aborted) return Promise.reject(interrupted(signal))
16
+ return new Promise((resolve, reject) => {
17
+ const entry = { operation, signal, resolve, reject, started: false }
18
+ entry.abort = () => {
19
+ if (!entry.started) {
20
+ const index = this.waiting.indexOf(entry)
21
+ if (index >= 0) this.waiting.splice(index, 1)
22
+ signal.removeEventListener('abort', entry.abort)
23
+ }
24
+ reject(interrupted(signal))
25
+ }
26
+ signal.addEventListener('abort', entry.abort, { once: true })
27
+ this.waiting.push(entry)
28
+ this.pump()
29
+ })
30
+ }
31
+ pump() {
32
+ while (this.active < this.limit && this.waiting.length) {
33
+ const entry = this.waiting.shift()
34
+ if (entry.signal.aborted) { entry.abort(); continue }
35
+ entry.started = true
36
+ this.active++
37
+ Promise.resolve().then(() => {
38
+ if (entry.signal.aborted) throw interrupted(entry.signal)
39
+ return entry.operation()
40
+ }).then(entry.resolve, entry.reject).finally(() => {
41
+ entry.signal.removeEventListener('abort', entry.abort)
42
+ this.active--
43
+ this.pump()
44
+ })
45
+ }
46
+ }
47
+ }
48
+
49
+ function matchingSnippet(line, normalizedIndex, queryLength, normalizedLength) {
50
+ let startMatch = normalizedIndex, endMatch = normalizedIndex + queryLength
51
+ if (normalizedLength !== line.length) {
52
+ // Lowercasing can expand a character (e.g. Turkish dotted capital I). Map
53
+ // folded offsets back before centering the original, case-preserving text.
54
+ let folded = 0, raw = 0, foundStart = false
55
+ for (const character of line) {
56
+ const next = folded + character.toLowerCase().length
57
+ if (!foundStart && next > normalizedIndex) { startMatch = raw; foundStart = true }
58
+ raw += character.length
59
+ if (next >= normalizedIndex + queryLength) { endMatch = raw; break }
60
+ folded = next
61
+ }
62
+ }
63
+ let from = Math.max(0, startMatch - 100)
64
+ let to = Math.min(line.length, Math.max(from + 500, endMatch))
65
+ if (from > 0 && /[\uDC00-\uDFFF]/.test(line[from])) from--
66
+ if (to < line.length && /[\uDC00-\uDFFF]/.test(line[to])) to++
67
+ return (from > 0 ? '…' : '') + line.slice(from, to) + (to < line.length ? '…' : '')
68
+ }
69
+ const terminal = status => ['completed','partial','cancelled','failed'].includes(status)
70
+
71
+ export class WorkspaceSearches {
72
+ constructor({ maxEntries = 50000, maxResults = 300, timeoutMs = 30000, maxReadBytes = 256 * 1024, maxDepth = 30, decodeBuf = b => b.toString('utf8'), encoding = 'utf-8', now = Date.now } = {}) {
73
+ Object.assign(this, { maxEntries, maxResults, timeoutMs, maxReadBytes, maxDepth, decodeBuf, encoding, now })
74
+ this.jobs = new Map()
75
+ this.operations = new WeakMap()
76
+ }
77
+ owner(binding, hint) { return JSON.stringify([hint.sessionId || hint.local, binding.host, binding.port, binding.username, binding.ws]) }
78
+ snapshot(job) {
79
+ return { id: job.id, query: job.query, mode: job.mode, status: job.status, phase: job.phase,
80
+ results: job.results.slice(), scannedFiles: job.scannedFiles, scannedDirs: job.scannedDirs, scannedEntries: job.scannedEntries,
81
+ skipped: job.skipped, errors: job.errors, currentPath: job.currentPath, elapsedMs: (job.finishedAt ?? this.now()) - job.startedAt,
82
+ truncated: job.truncated, reason: job.reason || '', error: job.error || '' }
83
+ }
84
+ get(owner, id) { const job = this.jobs.get(id); return job?.owner === owner ? this.snapshot(job) : null }
85
+ cancel(owner, id) {
86
+ const job = this.jobs.get(id)
87
+ if (!job || job.owner !== owner) return null
88
+ if (!terminal(job.status)) { job.controller.abort('cancelled'); job.status = 'cancelled'; job.finishedAt = this.now() }
89
+ return this.snapshot(job)
90
+ }
91
+ start(owner, binding, { query, mode = 'names', includeIgnored = false, caseSensitive = false, isIgnored = () => false } = {}) {
92
+ query = typeof query === 'string' ? query.trim() : ''
93
+ if (!query || query.length > 256 || !['names','files','directories','content'].includes(mode)) throw Object.assign(new Error('query (1–256 characters) and a valid search mode are required'), { httpStatus: 400 })
94
+ if (!binding.bound || !binding.ws) throw Object.assign(new Error('Search requires a session bound to a remote workspace'), { httpStatus: 403 })
95
+ for (const job of this.jobs.values()) {
96
+ if (!terminal(job.status) && job.owner === owner) this.cancel(owner, job.id)
97
+ if (terminal(job.status) && this.now() - job.finishedAt > 5 * 60000) this.jobs.delete(job.id)
98
+ }
99
+ if ([...this.jobs.values()].filter(j => !terminal(j.status)).length >= 4) throw Object.assign(new Error('Too many active searches; stop a search and retry'), { httpStatus: 429 })
100
+ while (this.jobs.size >= 40) {
101
+ const old = [...this.jobs.values()].find(j => terminal(j.status))
102
+ if (!old) break
103
+ this.jobs.delete(old.id)
104
+ }
105
+ const job = { id: randomUUID(), owner, query, mode, status: 'running', phase: 'connecting', results: [], scannedFiles: 0, scannedDirs: 0, scannedEntries: 0,
106
+ skipped: 0, errors: 0, currentPath: '', truncated: false, startedAt: this.now(), finishedAt: null, controller: new AbortController() }
107
+ this.jobs.set(job.id, job)
108
+ job.promise = this.run(job, binding, { includeIgnored, caseSensitive, isIgnored })
109
+ return this.snapshot(job)
110
+ }
111
+ async run(job, binding, { includeIgnored, caseSensitive, isIgnored }) {
112
+ const signal = job.controller.signal
113
+ let operations = this.operations.get(binding.pool)
114
+ if (!operations) { operations = new SearchOperations(); this.operations.set(binding.pool, operations) }
115
+ const timer = setTimeout(() => job.controller.abort('timeout'), this.timeoutMs)
116
+ timer.unref?.()
117
+ const stop = () => signal.aborted || job.truncated
118
+ const normalize = value => caseSensitive ? value : value.toLowerCase()
119
+ const query = normalize(job.query)
120
+ const nameMatches = (name, relative) => /[*?]/.test(query)
121
+ ? matchGlob(normalize(job.query.includes('/') ? relative : name), query)
122
+ : normalize(relative).includes(query)
123
+ const add = result => {
124
+ if (stop()) return
125
+ if (job.results.length >= this.maxResults) { job.truncated = true; job.reason = 'results'; return }
126
+ job.results.push(result)
127
+ }
128
+ try {
129
+ const sftp = await operations.run(() => binding.pool.sftp(), signal)
130
+ const queue = [{ path: binding.ws, relative: '', depth: 0 }]
131
+ job.phase = 'scanning'
132
+ const visit = async directory => {
133
+ if (stop()) return
134
+ job.currentPath = directory.relative || '.'
135
+ let entries
136
+ try { entries = await operations.run(() => sftp.readdir(directory.path), signal) }
137
+ catch (error) {
138
+ if (signal.aborted) throw error
139
+ if (!directory.relative) throw error
140
+ job.errors++; return
141
+ }
142
+ if (stop()) return
143
+ job.scannedDirs++
144
+ const files = []
145
+ for (const entry of entries || []) {
146
+ if (stop()) break
147
+ const name = String(entry.filename || '')
148
+ if (!name || name === '.' || name === '..' || /[\/\\\0]/.test(name) || /^[a-z]:/i.test(name)) continue
149
+ if (++job.scannedEntries > this.maxEntries) { job.truncated = true; job.reason = 'entries'; break }
150
+ const attrs = entry.attrs || {}, link = !!attrs.isSymbolicLink?.(), dir = !link && !!attrs.isDirectory?.()
151
+ const relative = directory.relative ? directory.relative + '/' + name : name
152
+ if (!includeIgnored && isIgnored(relative, dir)) { job.skipped++; continue }
153
+ const path = joinRemotePath(directory.path, name)
154
+ if (!dir) job.scannedFiles++
155
+ if (job.mode !== 'content' && (job.mode === 'names' || job.mode === 'directories' && dir || job.mode === 'files' && !dir) && nameMatches(name, relative)) add({ path, relative, name, type: dir ? 'directory' : link ? 'symlink' : 'file' })
156
+ if (dir) {
157
+ if (directory.depth < this.maxDepth) queue.push({ path, relative, depth: directory.depth + 1 })
158
+ else { job.skipped++; job.truncated = true; job.reason = 'depth' }
159
+ } else if (job.mode === 'content') {
160
+ if (link || attrs.size > this.maxReadBytes) job.skipped++
161
+ else files.push({ path, relative, name, attrs })
162
+ }
163
+ }
164
+ // Bounded pipelining keeps high-RTT SFTP usable without unbounded reads.
165
+ for (let offset = 0; offset < files.length && !stop(); offset += 3) {
166
+ await Promise.all(files.slice(offset, offset + 3).map(async file => {
167
+ if (stop()) return
168
+ try {
169
+ let stat = file.attrs
170
+ if (!Number.isFinite(stat.size)) stat = await operations.run(() => sftp.stat(file.path), signal)
171
+ if (stat.size > this.maxReadBytes) { job.skipped++; return }
172
+ const bytes = await operations.run(() => typeof sftp.readPartial === 'function' ? sftp.readPartial(file.path, 0, this.maxReadBytes + 1) : sftp.readFile(file.path), signal)
173
+ if (stop()) return
174
+ if (bytes.length > this.maxReadBytes || bytes.subarray(0, 8192).includes(0)) { job.skipped++; return }
175
+ const lines = this.decodeBuf(bytes, this.encoding).replace(/\r\n/g, '\n').split('\n')
176
+ for (let i = 0; i < lines.length && !stop(); i++) {
177
+ const normalized = normalize(lines[i]), match = normalized.indexOf(query)
178
+ if (match >= 0) add({ path: file.path, relative: file.relative, name: file.name, type: 'file', line: i + 1,
179
+ text: matchingSnippet(lines[i], match, query.length, normalized.length) })
180
+ }
181
+ } catch (error) { if (signal.aborted) throw error; job.errors++ }
182
+ }))
183
+ }
184
+ }
185
+ while (queue.length && !stop()) await Promise.all(queue.splice(0, 2).map(visit))
186
+ if (signal.aborted) throw interrupted(signal)
187
+ if (!terminal(job.status)) job.status = job.truncated || job.errors ? 'partial' : 'completed'
188
+ } catch (error) {
189
+ if (signal.aborted) {
190
+ job.status = signal.reason === 'timeout' ? 'partial' : 'cancelled'
191
+ if (signal.reason === 'timeout') { job.truncated = true; job.reason = 'timeout' }
192
+ } else { job.status = 'failed'; job.error = error.message || String(error) }
193
+ } finally { clearTimeout(timer); job.finishedAt ??= this.now(); job.currentPath = '' }
194
+ }
195
+ dispose() { for (const job of this.jobs.values()) if (!terminal(job.status)) job.controller.abort('disposed'); this.jobs.clear() }
196
+ }
197
+
198
+ export function createSearchRoutes({ searches, sendJson, readBody, resolveRequestBinding, isIgnoredFor = () => () => false }) {
199
+ return [{ kind: 'exact', path: '/dsh-remote/search', async handler(req, res) {
200
+ if (!['GET','POST'].includes(req.method)) return sendJson(res, 405, { ok: false, error: 'method not allowed' })
201
+ try {
202
+ const q = new URL(req.url, 'http://localhost').searchParams
203
+ const body = req.method === 'POST' ? JSON.parse((await readBody(req)) || '{}') : {}
204
+ const hint = requestSessionHint(req, body)
205
+ if (!hint.sessionId && !hint.local) return sendJson(res, 400, { ok: false, error: 'sessionId or local remote workspace context is required' })
206
+ const binding = await resolveRequestBinding(req, body)
207
+ if (!binding.bound) return sendJson(res, 403, { ok: false, error: 'Search requires a remote workspace' })
208
+ const owner = searches.owner(binding, hint), id = String(body.id || q.get('id') || '')
209
+ if (req.method === 'GET' || body.action === 'cancel') {
210
+ if (!id) return sendJson(res, 400, { ok: false, error: 'search id is required' })
211
+ const search = body.action === 'cancel' ? searches.cancel(owner, id) : searches.get(owner, id)
212
+ return sendJson(res, search ? 200 : 404, search ? { ok: true, search } : { ok: false, error: 'Search not found in this workspace' })
213
+ }
214
+ if (body.action && body.action !== 'start') return sendJson(res, 400, { ok: false, error: 'action must be start or cancel' })
215
+ const search = searches.start(owner, binding, { query: body.query, mode: body.mode, caseSensitive: body.caseSensitive === true, includeIgnored: body.includeIgnored === true, isIgnored: isIgnoredFor(binding.ws) })
216
+ return sendJson(res, 200, { ok: true, search })
217
+ } catch (error) { return sendJson(res, error.httpStatus || 500, { ok: false, error: error.message || String(error) }) }
218
+ } }]
219
+ }
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ extends: '@mscdex/eslint-config',
5
+ };
@@ -0,0 +1,88 @@
1
+ name: CI
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches: [ master ]
7
+
8
+ jobs:
9
+ tests-linux:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ node-version: [10.x, 12.x, 14.x, 16.x, 18.x, 20.x, 22.x, 24.x]
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ with:
18
+ persist-credentials: false
19
+ - name: Use Node.js ${{ matrix.node-version }}
20
+ uses: actions/setup-node@v4
21
+ with:
22
+ node-version: ${{ matrix.node-version }}
23
+ - name: Check Node.js version
24
+ run: node -pe process.versions
25
+ - name: Install module
26
+ run: npm install
27
+ - name: Run tests
28
+ run: npm test
29
+ tests-macos-intel:
30
+ runs-on: macos-15-intel
31
+ strategy:
32
+ fail-fast: false
33
+ matrix:
34
+ node-version: [10.x, 12.x, 14.x, 16.x, 18.x, 20.x, 22.x, 24.x]
35
+ steps:
36
+ - uses: actions/checkout@v4
37
+ with:
38
+ persist-credentials: false
39
+ - name: Use Node.js ${{ matrix.node-version }}
40
+ uses: actions/setup-node@v4
41
+ with:
42
+ node-version: ${{ matrix.node-version }}
43
+ - name: Check Node.js version
44
+ run: node -pe process.versions
45
+ - name: Install module
46
+ run: npm install
47
+ - name: Run tests
48
+ run: npm test
49
+ tests-macos-arm:
50
+ runs-on: macos-latest
51
+ strategy:
52
+ fail-fast: false
53
+ matrix:
54
+ node-version: [16.x, 18.x, 20.x, 22.x, 24.x]
55
+ steps:
56
+ - uses: actions/checkout@v4
57
+ with:
58
+ persist-credentials: false
59
+ - name: Use Node.js ${{ matrix.node-version }}
60
+ uses: actions/setup-node@v4
61
+ with:
62
+ node-version: ${{ matrix.node-version }}
63
+ - name: Check Node.js version
64
+ run: node -pe process.versions
65
+ - name: Install module
66
+ run: npm install
67
+ - name: Run tests
68
+ run: npm test
69
+ tests-windows-2022:
70
+ runs-on: windows-2022
71
+ strategy:
72
+ fail-fast: false
73
+ matrix:
74
+ node-version: [24.x]
75
+ steps:
76
+ - uses: actions/checkout@v4
77
+ with:
78
+ persist-credentials: false
79
+ - name: Use Node.js ${{ matrix.node-version }}
80
+ uses: actions/setup-node@v4
81
+ with:
82
+ node-version: ${{ matrix.node-version }}
83
+ - name: Check Node.js version
84
+ run: node -pe process.versions
85
+ - name: Install module
86
+ run: npm install
87
+ - name: Run tests
88
+ run: npm test
@@ -0,0 +1,27 @@
1
+ name: lint
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches: [ master ]
7
+
8
+ env:
9
+ NODE_VERSION: 22.x
10
+
11
+ jobs:
12
+ lint-js:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ with:
17
+ persist-credentials: false
18
+ - name: Use Node.js ${{ env.NODE_VERSION }}
19
+ uses: actions/setup-node@v4
20
+ with:
21
+ node-version: ${{ env.NODE_VERSION }}
22
+ - name: Check Node.js version
23
+ run: node -pe process.versions
24
+ - name: Install ESLint + ESLint configs/plugins
25
+ run: npm install --only=dev
26
+ - name: Lint files
27
+ run: npm run lint
@@ -0,0 +1,3 @@
1
+ .eslintcache
2
+ **/node_modules/**
3
+ /package-lock.json
@@ -0,0 +1,19 @@
1
+ Copyright Brian White. All rights reserved.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
+ IN THE SOFTWARE.
@@ -0,0 +1,106 @@
1
+ # Description
2
+
3
+ Build environment checking for [node.js](http://nodejs.org/).
4
+
5
+ This allows for autoconf-like functionality for node addons/build scripts.
6
+
7
+ **Note:** Obsolete and/or exotic build environments or platforms not supported
8
+ by node.js are not supported.
9
+
10
+ ## Requirements
11
+
12
+ * [node.js](http://nodejs.org/) -- v10.0.0 or newer
13
+ * Supported compilers:
14
+ * gcc
15
+ * clang
16
+ * MSVC 2013+ and Windows SDK 8.1+
17
+
18
+ ## Installation
19
+
20
+ npm install buildcheck
21
+
22
+ ## Examples
23
+
24
+ ### Check if a C function exists
25
+
26
+ ```js
27
+ 'use strict';
28
+
29
+ const BuildEnvironment = require('buildcheck');
30
+
31
+ const buildEnv = new BuildEnvironment();
32
+
33
+ console.log(buildEnv.checkFunction('c', 'preadv2'));
34
+ ```
35
+
36
+ ### Check if a C header is usable
37
+
38
+ ```js
39
+ 'use strict';
40
+
41
+ const BuildEnvironment = require('buildcheck');
42
+
43
+ const buildEnv = new BuildEnvironment();
44
+
45
+ console.log(buildEnv.checkHeader('c', 'linux/io_uring.h'));
46
+ ```
47
+
48
+ ### Try to compile some C code
49
+
50
+ ```js
51
+ 'use strict';
52
+
53
+ const BuildEnvironment = require('buildcheck');
54
+
55
+ const buildEnv = new BuildEnvironment();
56
+
57
+ // Should be a successful compile
58
+ console.log(buildEnv.tryCompile('c', 'int main() { return 0; }'));
59
+
60
+ // Should be a failed compile
61
+ console.log(buildEnv.tryCompile('c', 'int main() { return z; }'));
62
+ ```
63
+
64
+ ## API
65
+
66
+ ### Exports
67
+
68
+ The exported value is `BuildEnvironment`, the main class for dealing with a build environment.
69
+
70
+ ### BuildEnvironment
71
+
72
+ #### Methods
73
+
74
+ * **(constructor)**([< _object_ >config]) - Creates and returns a new BuildEnvironment instance. `config` may contain:
75
+
76
+ * **compilerC** - _string_ - C compiler command to use. *Note: this is ignored on Windows.* **Default:** `process.env.CC` or `'cc'`
77
+
78
+ * **compilerCXX** - _string_ - C++ compiler command to use. *Note: this is ignored on Windows.* **Default:** `process.env.CXX` or `'c++'`
79
+
80
+ * **msvs_version** - _mixed_ - A string or number containing the year of the Visual Studio compiler to use. *Note: this is for Windows only.* **Default:** newest version installed
81
+
82
+ * **checkDeclared**(< _string_ >lang, < _string_ >symbolName[, < _object_ >options]) - _boolean_ - Checks if a symbol `symbolName` is declared where `lang` is either `'c'` or `'c++'`. Returns `true` if symbol exists, `false` otherwise. `options` may contain:
83
+
84
+ * **headers** - _array_ - A list of headers to try when checking if the symbol is declared. `checkFunction()` will always first try without a library. If not supplied, a default list of common (platform-specific) headers will be used.
85
+
86
+ * **searchLibs** - _array_ - A list of library names (without the `'-l'` prefix) to try when checking if the symbol is declared. `checkDeclared()` will always first try without a library.
87
+
88
+ * **checkFunction**(< _string_ >lang, < _string_ >functionName[, < _object_ >options]) - _boolean_ - Checks if a function `functionName` exists and is linkable where `lang` is either `'c'` or `'c++'`. Returns `true` if function exists, `false` otherwise. `options` may contain:
89
+
90
+ * **searchLibs** - _array_ - A list of library names (without the `'-l'` prefix) to try when checking for this function. `checkFunction()` will always first try without a library.
91
+
92
+ * **checkFeature**(< _string_ >featureName) - _mixed_ - Executes a special test for a "feature" and returns the result. Supported values for `featureName`:
93
+
94
+ * `'strerror_r'` - Returns an object containing:
95
+
96
+ * `declared` - _boolean_ - Whether `strerror_r()` is declared
97
+
98
+ * `returnsCharPtr` - _boolean_ - If `strerror_r()` is declared, whether it returns `char*` (a GNU extension) or not.
99
+
100
+ * **checkHeader**(< _string_ >lang, < _string_ >headerName) - _boolean_ - Checks if the header `headerName` exists and is usable where `lang` is either `'c'` or `'c++'`. Returns `true` if the header exists and is usable, `false` otherwise.
101
+
102
+ * **defines**([< _string_ >lang[, < _boolean_ >rendered]]) - _array_ - Returns a list of features, functions, headers, and symbols known to be defined by this build environment instance. `lang` is either `'c'` or `'c++'` If `lang` is not set, defines for both `'c'` and `'c++'` will be returned. If `rendered` is `true` (defaults to `false`), autoconf-style defines (e.g. "HAVE_FOO=1") will be returned instead. Defines coming from features utilize base strings/names from autoconf for better compatibility.
103
+
104
+ * **libs**([< _string_ >lang]) - _array_ - Returns a list of (`'-l'`-prefixed) libraries known to be required for features and functions defined by this build environment instance. `lang` is either `'c'` or `'c++'` If `lang` is not set, defines for both `'c'` and `'c++'` will be returned.
105
+
106
+ * **tryCompile**(< _string_ >lang, < _string_ >code[, < _array_ >compilerParams]) - _mixed_ - Attempts to compile `code` where `lang` is either `'c'` or `'c++'`. `compilerParams` is an optional array of compiler/linker flags to include. Returns `true` on successful compilation, or an _Error_ instance with an `output` property containing the compiler error output.