dsh-ops 0.0.0-stage → 0.2.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 (139) hide show
  1. package/CHANGELOG.md +189 -0
  2. package/LICENSE +30 -0
  3. package/NOTICE +106 -0
  4. package/PROVENANCE.md +417 -0
  5. package/README.en.md +121 -0
  6. package/README.md +113 -2
  7. package/README.zh.md +114 -0
  8. package/bin/dsh-ops.mjs +1216 -0
  9. package/cordis.patch.yml +160 -0
  10. package/docs/manual-validation.md +53 -0
  11. package/docs/schema-baseline.json +64 -0
  12. package/docs/schema-current.json +84 -0
  13. package/docs/schema-measurement.md +17 -0
  14. package/dsh-plugin.json +88 -0
  15. package/icon.svg +12 -0
  16. package/lib/binary.js +409 -0
  17. package/lib/config.js +198 -0
  18. package/lib/handshake.js +252 -0
  19. package/lib/index.js +108 -0
  20. package/lib/jobs.js +42 -0
  21. package/lib/policy.js +64 -0
  22. package/lib/presentation.js +63 -0
  23. package/lib/profile-install.js +61 -0
  24. package/lib/rust.js +194 -0
  25. package/lib/session-shells.js +78 -0
  26. package/lib/shells.js +993 -0
  27. package/lib/tools.js +657 -0
  28. package/locale/en.json +6 -0
  29. package/locale/zh.json +6 -0
  30. package/package.json +114 -4
  31. package/vendor/fastctx/Cargo.lock +3210 -0
  32. package/vendor/fastctx/Cargo.toml +94 -0
  33. package/vendor/fastctx/FORK.md +119 -0
  34. package/vendor/fastctx/LICENSE-APACHE +201 -0
  35. package/vendor/fastctx/NOTICE +40 -0
  36. package/vendor/fastctx/README.md +439 -0
  37. package/vendor/fastctx/THIRD_PARTY_LICENSES.md +17 -0
  38. package/vendor/fastctx/THIRD_PARTY_LICENSES_RUST.md +7914 -0
  39. package/vendor/fastctx/UPSTREAM.md +49 -0
  40. package/vendor/fastctx/build.rs +413 -0
  41. package/vendor/fastctx/src/background_status.rs +403 -0
  42. package/vendor/fastctx/src/binary.rs +75 -0
  43. package/vendor/fastctx/src/bounded_sort.rs +500 -0
  44. package/vendor/fastctx/src/budget.rs +781 -0
  45. package/vendor/fastctx/src/cli/mod.rs +110 -0
  46. package/vendor/fastctx/src/context_guard.rs +289 -0
  47. package/vendor/fastctx/src/control/mod.rs +6 -0
  48. package/vendor/fastctx/src/control/paths.rs +49 -0
  49. package/vendor/fastctx/src/control/settings.rs +753 -0
  50. package/vendor/fastctx/src/control/transaction.rs +531 -0
  51. package/vendor/fastctx/src/edit/document.rs +535 -0
  52. package/vendor/fastctx/src/edit/locks.rs +371 -0
  53. package/vendor/fastctx/src/edit/mod.rs +213 -0
  54. package/vendor/fastctx/src/edit/private_storage/unix.rs +315 -0
  55. package/vendor/fastctx/src/edit/private_storage/windows.rs +793 -0
  56. package/vendor/fastctx/src/edit/private_storage.rs +234 -0
  57. package/vendor/fastctx/src/edit/replace.rs +1030 -0
  58. package/vendor/fastctx/src/edit_server.rs +53 -0
  59. package/vendor/fastctx/src/encoding/reference_v011.rs +587 -0
  60. package/vendor/fastctx/src/encoding/snapshot_pipeline.rs +1678 -0
  61. package/vendor/fastctx/src/encoding.rs +1118 -0
  62. package/vendor/fastctx/src/file_executor.rs +1151 -0
  63. package/vendor/fastctx/src/file_snapshot.rs +1491 -0
  64. package/vendor/fastctx/src/glob_filter.rs +98 -0
  65. package/vendor/fastctx/src/glob_tool.rs +653 -0
  66. package/vendor/fastctx/src/grep_sink.rs +1162 -0
  67. package/vendor/fastctx/src/grep_tool.rs +2449 -0
  68. package/vendor/fastctx/src/lib.rs +45 -0
  69. package/vendor/fastctx/src/main.rs +15 -0
  70. package/vendor/fastctx/src/model.rs +51 -0
  71. package/vendor/fastctx/src/model_guidance.rs +62 -0
  72. package/vendor/fastctx/src/operation.rs +356 -0
  73. package/vendor/fastctx/src/ordered_window.rs +1235 -0
  74. package/vendor/fastctx/src/os_environment.rs +414 -0
  75. package/vendor/fastctx/src/path_codec.rs +850 -0
  76. package/vendor/fastctx/src/paths.rs +244 -0
  77. package/vendor/fastctx/src/process_identity.rs +763 -0
  78. package/vendor/fastctx/src/process_policy.rs +74 -0
  79. package/vendor/fastctx/src/read_tool/batch.rs +496 -0
  80. package/vendor/fastctx/src/read_tool/hex_file.rs +141 -0
  81. package/vendor/fastctx/src/read_tool/image_file.rs +88 -0
  82. package/vendor/fastctx/src/read_tool/mod.rs +245 -0
  83. package/vendor/fastctx/src/read_tool/pdf.rs +470 -0
  84. package/vendor/fastctx/src/read_tool/pdf_disabled.rs +47 -0
  85. package/vendor/fastctx/src/read_tool/pdf_engine.rs +664 -0
  86. package/vendor/fastctx/src/read_tool/text_file.rs +351 -0
  87. package/vendor/fastctx/src/render_plan.rs +468 -0
  88. package/vendor/fastctx/src/runtime/activity.rs +159 -0
  89. package/vendor/fastctx/src/runtime/hosts.rs +99 -0
  90. package/vendor/fastctx/src/runtime/journal.rs +556 -0
  91. package/vendor/fastctx/src/runtime/local_ipc.rs +186 -0
  92. package/vendor/fastctx/src/runtime/mod.rs +746 -0
  93. package/vendor/fastctx/src/runtime/protocol.rs +296 -0
  94. package/vendor/fastctx/src/runtime/session.rs +536 -0
  95. package/vendor/fastctx/src/runtime/windows_process.rs +66 -0
  96. package/vendor/fastctx/src/search_parallelism.rs +106 -0
  97. package/vendor/fastctx/src/search_text.rs +227 -0
  98. package/vendor/fastctx/src/server.rs +359 -0
  99. package/vendor/fastctx/src/server_manifest.rs +468 -0
  100. package/vendor/fastctx/src/server_support.rs +826 -0
  101. package/vendor/fastctx/src/session.rs +629 -0
  102. package/vendor/fastctx/src/shell/apply_patch_hint.rs +41 -0
  103. package/vendor/fastctx/src/shell/bash.rs +263 -0
  104. package/vendor/fastctx/src/shell/buffer.rs +108 -0
  105. package/vendor/fastctx/src/shell/encoding.rs +403 -0
  106. package/vendor/fastctx/src/shell/foreground.rs +115 -0
  107. package/vendor/fastctx/src/shell/jobs/admission.rs +91 -0
  108. package/vendor/fastctx/src/shell/jobs/background.rs +146 -0
  109. package/vendor/fastctx/src/shell/jobs/host.rs +830 -0
  110. package/vendor/fastctx/src/shell/jobs/identity.rs +29 -0
  111. package/vendor/fastctx/src/shell/jobs/mod.rs +1513 -0
  112. package/vendor/fastctx/src/shell/jobs/model.rs +244 -0
  113. package/vendor/fastctx/src/shell/jobs/output_log.rs +1148 -0
  114. package/vendor/fastctx/src/shell/jobs/store.rs +1300 -0
  115. package/vendor/fastctx/src/shell/mod.rs +345 -0
  116. package/vendor/fastctx/src/shell/normalize.rs +389 -0
  117. package/vendor/fastctx/src/shell/output.rs +406 -0
  118. package/vendor/fastctx/src/shell/process.rs +493 -0
  119. package/vendor/fastctx/src/shell_server.rs +156 -0
  120. package/vendor/fastctx/src/skip_report.rs +83 -0
  121. package/vendor/fastctx/src/stdio_transport.rs +177 -0
  122. package/vendor/fastctx/src/tool_schema.rs +204 -0
  123. package/vendor/fastctx/src/traversal.rs +846 -0
  124. package/vendor/fastctx/third-party/pdfium-7763/LICENSE +9 -0
  125. package/vendor/fastctx/third-party/pdfium-7763/licenses/abseil.txt +202 -0
  126. package/vendor/fastctx/third-party/pdfium-7763/licenses/agg23.txt +14 -0
  127. package/vendor/fastctx/third-party/pdfium-7763/licenses/fast_float.txt +27 -0
  128. package/vendor/fastctx/third-party/pdfium-7763/licenses/freetype.txt +169 -0
  129. package/vendor/fastctx/third-party/pdfium-7763/licenses/icu.txt +542 -0
  130. package/vendor/fastctx/third-party/pdfium-7763/licenses/lcms.txt +27 -0
  131. package/vendor/fastctx/third-party/pdfium-7763/licenses/libjpeg_turbo.ijg +260 -0
  132. package/vendor/fastctx/third-party/pdfium-7763/licenses/libjpeg_turbo.md +135 -0
  133. package/vendor/fastctx/third-party/pdfium-7763/licenses/libopenjpeg.txt +32 -0
  134. package/vendor/fastctx/third-party/pdfium-7763/licenses/libpng.txt +134 -0
  135. package/vendor/fastctx/third-party/pdfium-7763/licenses/libtiff.txt +21 -0
  136. package/vendor/fastctx/third-party/pdfium-7763/licenses/llvm-libc.txt +278 -0
  137. package/vendor/fastctx/third-party/pdfium-7763/licenses/pdfium.txt +230 -0
  138. package/vendor/fastctx/third-party/pdfium-7763/licenses/simdutf.txt +18 -0
  139. package/vendor/fastctx/third-party/pdfium-7763/licenses/zlib.txt +29 -0
@@ -0,0 +1,234 @@
1
+ // Modified by dsh-ops (https://github.com/T-Auto/dsh-ops): removed update_check_directory, whose only caller was the deleted src/update/ cache.
2
+ //! User-private storage for edit locks and other process-shared runtime state.
3
+
4
+ use std::fs::{self, File, OpenOptions};
5
+ use std::path::{Component, Path, PathBuf};
6
+
7
+ #[cfg(unix)]
8
+ mod unix;
9
+ #[cfg(windows)]
10
+ mod windows;
11
+
12
+ pub(crate) fn edit_lock_directory() -> PathBuf {
13
+ runtime_component("edit-locks")
14
+ }
15
+
16
+ pub(crate) fn job_control_directory() -> PathBuf {
17
+ runtime_component("job-control")
18
+ }
19
+
20
+ pub(crate) fn control_center_directory() -> PathBuf {
21
+ runtime_component("engine")
22
+ }
23
+
24
+ #[cfg(unix)]
25
+ pub(crate) fn short_control_center_directory() -> PathBuf {
26
+ unix::short_control_center_directory()
27
+ }
28
+
29
+ #[cfg(windows)]
30
+ pub(crate) use windows::PrivateSecurityDescriptor;
31
+
32
+ pub(crate) fn ensure_private_directory(path: &Path, label: &str) -> Result<(), String> {
33
+ validate_private_directory_path(path, label)?;
34
+ #[cfg(unix)]
35
+ {
36
+ unix::ensure_private_directory(path, label)
37
+ }
38
+ #[cfg(windows)]
39
+ {
40
+ windows::ensure_private_directory(path, label)
41
+ }
42
+ #[cfg(not(any(unix, windows)))]
43
+ {
44
+ ensure_private_directory_portable(path, label)
45
+ }
46
+ }
47
+
48
+ fn validate_private_directory_path(path: &Path, label: &str) -> Result<(), String> {
49
+ if !path.is_absolute()
50
+ || path
51
+ .components()
52
+ .any(|component| matches!(component, Component::ParentDir | Component::CurDir))
53
+ {
54
+ return Err(format!(
55
+ "Cannot use the {label} directory {} because its path is not an absolute, normalized path.",
56
+ crate::paths::display_path(path)
57
+ ));
58
+ }
59
+ Ok(())
60
+ }
61
+
62
+ #[cfg(not(any(unix, windows)))]
63
+ fn ensure_private_directory_portable(path: &Path, label: &str) -> Result<(), String> {
64
+ fs::create_dir_all(path).map_err(|error| {
65
+ format!(
66
+ "Cannot create the {label} directory {}: {error}",
67
+ crate::paths::display_path(path)
68
+ )
69
+ })?;
70
+ verify_directory(path, label)
71
+ }
72
+
73
+ fn inspect_regular_file(path: &Path, label: &str) -> Result<Option<fs::Metadata>, String> {
74
+ match fs::symlink_metadata(path) {
75
+ Ok(metadata) => {
76
+ if is_reparse_or_symlink(&metadata) || !metadata.is_file() {
77
+ Err(format!(
78
+ "Cannot use the {label} path {} because it is not a private regular file. Remove it and retry.",
79
+ crate::paths::display_path(path)
80
+ ))
81
+ } else {
82
+ Ok(Some(metadata))
83
+ }
84
+ }
85
+ Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(None),
86
+ Err(error) => Err(format!(
87
+ "Cannot inspect the {label} path {}: {error}",
88
+ crate::paths::display_path(path)
89
+ )),
90
+ }
91
+ }
92
+
93
+ pub(crate) fn open_lock_file(path: &Path, label: &str) -> Result<File, String> {
94
+ inspect_regular_file(path, label)?;
95
+ let mut options = OpenOptions::new();
96
+ options.create(true).truncate(false).read(true).write(true);
97
+ configure_no_follow(&mut options);
98
+ let file = options.open(path).map_err(|error| {
99
+ format!(
100
+ "Cannot open the {label} {}: {error}",
101
+ crate::paths::display_path(path)
102
+ )
103
+ })?;
104
+ verify_open_file(&file, path, label)?;
105
+ Ok(file)
106
+ }
107
+
108
+ fn runtime_component(component: &str) -> PathBuf {
109
+ #[cfg(unix)]
110
+ {
111
+ unix::runtime_component(component)
112
+ }
113
+ #[cfg(windows)]
114
+ {
115
+ windows::runtime_component(component)
116
+ }
117
+ #[cfg(not(any(unix, windows)))]
118
+ {
119
+ std::env::temp_dir().join(format!("fastctx-{component}"))
120
+ }
121
+ }
122
+
123
+ pub(super) fn verify_directory(path: &Path, label: &str) -> Result<(), String> {
124
+ let metadata = fs::symlink_metadata(path).map_err(|error| {
125
+ format!(
126
+ "Cannot inspect the {label} directory {}: {error}",
127
+ crate::paths::display_path(path)
128
+ )
129
+ })?;
130
+ validate_directory_metadata(path, label, &metadata)
131
+ }
132
+
133
+ pub(super) fn validate_directory_metadata(
134
+ path: &Path,
135
+ label: &str,
136
+ metadata: &fs::Metadata,
137
+ ) -> Result<(), String> {
138
+ if is_reparse_or_symlink(metadata) || !metadata.is_dir() {
139
+ return Err(format!(
140
+ "Cannot use the {label} path {} because it is not a private directory. Remove it and retry.",
141
+ crate::paths::display_path(path)
142
+ ));
143
+ }
144
+ Ok(())
145
+ }
146
+
147
+ fn verify_open_file(file: &File, path: &Path, label: &str) -> Result<(), String> {
148
+ let metadata = file.metadata().map_err(|error| {
149
+ format!(
150
+ "Cannot inspect the open {label} {}: {error}",
151
+ crate::paths::display_path(path)
152
+ )
153
+ })?;
154
+ if is_reparse_or_symlink(&metadata) || !metadata.is_file() {
155
+ return Err(format!(
156
+ "Cannot use the {label} path {} because it is not a private regular file. Remove it and retry.",
157
+ crate::paths::display_path(path)
158
+ ));
159
+ }
160
+ Ok(())
161
+ }
162
+
163
+ #[cfg(unix)]
164
+ fn configure_no_follow(options: &mut OpenOptions) {
165
+ unix::configure_no_follow(options);
166
+ }
167
+
168
+ #[cfg(windows)]
169
+ fn configure_no_follow(options: &mut OpenOptions) {
170
+ windows::configure_no_follow(options);
171
+ }
172
+
173
+ #[cfg(not(any(unix, windows)))]
174
+ fn configure_no_follow(_options: &mut OpenOptions) {}
175
+
176
+ #[cfg(windows)]
177
+ fn is_reparse_or_symlink(metadata: &fs::Metadata) -> bool {
178
+ windows::is_reparse_or_symlink(metadata)
179
+ }
180
+
181
+ #[cfg(unix)]
182
+ fn is_reparse_or_symlink(metadata: &fs::Metadata) -> bool {
183
+ unix::is_reparse_or_symlink(metadata)
184
+ }
185
+
186
+ #[cfg(not(any(unix, windows)))]
187
+ fn is_reparse_or_symlink(metadata: &fs::Metadata) -> bool {
188
+ metadata.file_type().is_symlink()
189
+ }
190
+
191
+ #[cfg(test)]
192
+ mod tests {
193
+ use super::{ensure_private_directory, open_lock_file};
194
+ use std::path::Path;
195
+
196
+ #[test]
197
+ fn private_directories_and_lock_files_are_regular_and_usable() {
198
+ let temp = tempfile::tempdir().unwrap();
199
+ let directory = temp.path().join("fastctx/runtime/edit-locks");
200
+ ensure_private_directory(&directory, "edit-lock").unwrap();
201
+ let lock = directory.join("test.lock");
202
+ let file = open_lock_file(&lock, "edit lock").unwrap();
203
+ assert!(file.metadata().unwrap().is_file());
204
+ }
205
+
206
+ #[test]
207
+ fn relative_or_lexically_escaping_private_directory_paths_are_rejected() {
208
+ let relative =
209
+ ensure_private_directory(Path::new("relative/edit-locks"), "edit-lock").unwrap_err();
210
+ assert!(relative.contains("absolute, normalized path"), "{relative}");
211
+
212
+ let temp = tempfile::tempdir().unwrap();
213
+ let escaping = temp.path().join("inside/../outside");
214
+ let error = ensure_private_directory(&escaping, "edit-lock").unwrap_err();
215
+ assert!(error.contains("absolute, normalized path"), "{error}");
216
+ assert!(!temp.path().join("outside").exists());
217
+ }
218
+
219
+ #[cfg(unix)]
220
+ #[test]
221
+ fn symlink_entries_are_rejected_instead_of_followed() {
222
+ use std::os::unix::fs::symlink;
223
+
224
+ let temp = tempfile::tempdir().unwrap();
225
+ let directory = temp.path().join("edit-locks");
226
+ ensure_private_directory(&directory, "edit-lock").unwrap();
227
+ let target = temp.path().join("outside");
228
+ std::fs::write(&target, b"outside").unwrap();
229
+ let entry = directory.join("escape.lock");
230
+ symlink(target, &entry).unwrap();
231
+ let error = open_lock_file(&entry, "edit lock").unwrap_err();
232
+ assert!(error.contains("not a private regular file"), "{error}");
233
+ }
234
+ }