dsh-ops 0.0.0-stage → 0.2.2

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 (140) hide show
  1. package/CHANGELOG.md +202 -0
  2. package/LICENSE +30 -0
  3. package/NOTICE +106 -0
  4. package/PROVENANCE.md +435 -0
  5. package/README.en.md +126 -0
  6. package/README.md +115 -2
  7. package/README.zh.md +116 -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/release-0.2.1.md +72 -0
  12. package/docs/schema-baseline.json +64 -0
  13. package/docs/schema-current.json +84 -0
  14. package/docs/schema-measurement.md +17 -0
  15. package/dsh-plugin.json +88 -0
  16. package/icon.svg +12 -0
  17. package/lib/binary.js +409 -0
  18. package/lib/config.js +198 -0
  19. package/lib/handshake.js +252 -0
  20. package/lib/index.js +108 -0
  21. package/lib/jobs.js +42 -0
  22. package/lib/policy.js +64 -0
  23. package/lib/presentation.js +63 -0
  24. package/lib/profile-install.js +61 -0
  25. package/lib/rust.js +194 -0
  26. package/lib/session-shells.js +78 -0
  27. package/lib/shells.js +998 -0
  28. package/lib/tools.js +657 -0
  29. package/locale/en.json +6 -0
  30. package/locale/zh.json +6 -0
  31. package/package.json +114 -4
  32. package/vendor/fastctx/Cargo.lock +3210 -0
  33. package/vendor/fastctx/Cargo.toml +94 -0
  34. package/vendor/fastctx/FORK.md +119 -0
  35. package/vendor/fastctx/LICENSE-APACHE +201 -0
  36. package/vendor/fastctx/NOTICE +40 -0
  37. package/vendor/fastctx/README.md +439 -0
  38. package/vendor/fastctx/THIRD_PARTY_LICENSES.md +17 -0
  39. package/vendor/fastctx/THIRD_PARTY_LICENSES_RUST.md +7914 -0
  40. package/vendor/fastctx/UPSTREAM.md +49 -0
  41. package/vendor/fastctx/build.rs +413 -0
  42. package/vendor/fastctx/src/background_status.rs +403 -0
  43. package/vendor/fastctx/src/binary.rs +75 -0
  44. package/vendor/fastctx/src/bounded_sort.rs +500 -0
  45. package/vendor/fastctx/src/budget.rs +781 -0
  46. package/vendor/fastctx/src/cli/mod.rs +110 -0
  47. package/vendor/fastctx/src/context_guard.rs +289 -0
  48. package/vendor/fastctx/src/control/mod.rs +6 -0
  49. package/vendor/fastctx/src/control/paths.rs +49 -0
  50. package/vendor/fastctx/src/control/settings.rs +753 -0
  51. package/vendor/fastctx/src/control/transaction.rs +531 -0
  52. package/vendor/fastctx/src/edit/document.rs +535 -0
  53. package/vendor/fastctx/src/edit/locks.rs +371 -0
  54. package/vendor/fastctx/src/edit/mod.rs +213 -0
  55. package/vendor/fastctx/src/edit/private_storage/unix.rs +315 -0
  56. package/vendor/fastctx/src/edit/private_storage/windows.rs +793 -0
  57. package/vendor/fastctx/src/edit/private_storage.rs +234 -0
  58. package/vendor/fastctx/src/edit/replace.rs +1030 -0
  59. package/vendor/fastctx/src/edit_server.rs +53 -0
  60. package/vendor/fastctx/src/encoding/reference_v011.rs +587 -0
  61. package/vendor/fastctx/src/encoding/snapshot_pipeline.rs +1678 -0
  62. package/vendor/fastctx/src/encoding.rs +1118 -0
  63. package/vendor/fastctx/src/file_executor.rs +1151 -0
  64. package/vendor/fastctx/src/file_snapshot.rs +1491 -0
  65. package/vendor/fastctx/src/glob_filter.rs +98 -0
  66. package/vendor/fastctx/src/glob_tool.rs +653 -0
  67. package/vendor/fastctx/src/grep_sink.rs +1162 -0
  68. package/vendor/fastctx/src/grep_tool.rs +2449 -0
  69. package/vendor/fastctx/src/lib.rs +45 -0
  70. package/vendor/fastctx/src/main.rs +15 -0
  71. package/vendor/fastctx/src/model.rs +51 -0
  72. package/vendor/fastctx/src/model_guidance.rs +62 -0
  73. package/vendor/fastctx/src/operation.rs +356 -0
  74. package/vendor/fastctx/src/ordered_window.rs +1235 -0
  75. package/vendor/fastctx/src/os_environment.rs +414 -0
  76. package/vendor/fastctx/src/path_codec.rs +850 -0
  77. package/vendor/fastctx/src/paths.rs +244 -0
  78. package/vendor/fastctx/src/process_identity.rs +763 -0
  79. package/vendor/fastctx/src/process_policy.rs +74 -0
  80. package/vendor/fastctx/src/read_tool/batch.rs +496 -0
  81. package/vendor/fastctx/src/read_tool/hex_file.rs +141 -0
  82. package/vendor/fastctx/src/read_tool/image_file.rs +88 -0
  83. package/vendor/fastctx/src/read_tool/mod.rs +245 -0
  84. package/vendor/fastctx/src/read_tool/pdf.rs +470 -0
  85. package/vendor/fastctx/src/read_tool/pdf_disabled.rs +47 -0
  86. package/vendor/fastctx/src/read_tool/pdf_engine.rs +664 -0
  87. package/vendor/fastctx/src/read_tool/text_file.rs +351 -0
  88. package/vendor/fastctx/src/render_plan.rs +468 -0
  89. package/vendor/fastctx/src/runtime/activity.rs +159 -0
  90. package/vendor/fastctx/src/runtime/hosts.rs +99 -0
  91. package/vendor/fastctx/src/runtime/journal.rs +556 -0
  92. package/vendor/fastctx/src/runtime/local_ipc.rs +186 -0
  93. package/vendor/fastctx/src/runtime/mod.rs +746 -0
  94. package/vendor/fastctx/src/runtime/protocol.rs +296 -0
  95. package/vendor/fastctx/src/runtime/session.rs +536 -0
  96. package/vendor/fastctx/src/runtime/windows_process.rs +66 -0
  97. package/vendor/fastctx/src/search_parallelism.rs +106 -0
  98. package/vendor/fastctx/src/search_text.rs +227 -0
  99. package/vendor/fastctx/src/server.rs +359 -0
  100. package/vendor/fastctx/src/server_manifest.rs +468 -0
  101. package/vendor/fastctx/src/server_support.rs +826 -0
  102. package/vendor/fastctx/src/session.rs +629 -0
  103. package/vendor/fastctx/src/shell/apply_patch_hint.rs +41 -0
  104. package/vendor/fastctx/src/shell/bash.rs +263 -0
  105. package/vendor/fastctx/src/shell/buffer.rs +108 -0
  106. package/vendor/fastctx/src/shell/encoding.rs +403 -0
  107. package/vendor/fastctx/src/shell/foreground.rs +115 -0
  108. package/vendor/fastctx/src/shell/jobs/admission.rs +91 -0
  109. package/vendor/fastctx/src/shell/jobs/background.rs +146 -0
  110. package/vendor/fastctx/src/shell/jobs/host.rs +830 -0
  111. package/vendor/fastctx/src/shell/jobs/identity.rs +29 -0
  112. package/vendor/fastctx/src/shell/jobs/mod.rs +1513 -0
  113. package/vendor/fastctx/src/shell/jobs/model.rs +244 -0
  114. package/vendor/fastctx/src/shell/jobs/output_log.rs +1148 -0
  115. package/vendor/fastctx/src/shell/jobs/store.rs +1300 -0
  116. package/vendor/fastctx/src/shell/mod.rs +345 -0
  117. package/vendor/fastctx/src/shell/normalize.rs +389 -0
  118. package/vendor/fastctx/src/shell/output.rs +406 -0
  119. package/vendor/fastctx/src/shell/process.rs +493 -0
  120. package/vendor/fastctx/src/shell_server.rs +156 -0
  121. package/vendor/fastctx/src/skip_report.rs +83 -0
  122. package/vendor/fastctx/src/stdio_transport.rs +177 -0
  123. package/vendor/fastctx/src/tool_schema.rs +204 -0
  124. package/vendor/fastctx/src/traversal.rs +846 -0
  125. package/vendor/fastctx/third-party/pdfium-7763/LICENSE +9 -0
  126. package/vendor/fastctx/third-party/pdfium-7763/licenses/abseil.txt +202 -0
  127. package/vendor/fastctx/third-party/pdfium-7763/licenses/agg23.txt +14 -0
  128. package/vendor/fastctx/third-party/pdfium-7763/licenses/fast_float.txt +27 -0
  129. package/vendor/fastctx/third-party/pdfium-7763/licenses/freetype.txt +169 -0
  130. package/vendor/fastctx/third-party/pdfium-7763/licenses/icu.txt +542 -0
  131. package/vendor/fastctx/third-party/pdfium-7763/licenses/lcms.txt +27 -0
  132. package/vendor/fastctx/third-party/pdfium-7763/licenses/libjpeg_turbo.ijg +260 -0
  133. package/vendor/fastctx/third-party/pdfium-7763/licenses/libjpeg_turbo.md +135 -0
  134. package/vendor/fastctx/third-party/pdfium-7763/licenses/libopenjpeg.txt +32 -0
  135. package/vendor/fastctx/third-party/pdfium-7763/licenses/libpng.txt +134 -0
  136. package/vendor/fastctx/third-party/pdfium-7763/licenses/libtiff.txt +21 -0
  137. package/vendor/fastctx/third-party/pdfium-7763/licenses/llvm-libc.txt +278 -0
  138. package/vendor/fastctx/third-party/pdfium-7763/licenses/pdfium.txt +230 -0
  139. package/vendor/fastctx/third-party/pdfium-7763/licenses/simdutf.txt +18 -0
  140. package/vendor/fastctx/third-party/pdfium-7763/licenses/zlib.txt +29 -0
@@ -0,0 +1,146 @@
1
+ //! In-memory per-server tracking for background status lines.
2
+
3
+ use super::model::{JobRecord, JobStatus};
4
+ use super::store;
5
+ use crate::background_status::{BackgroundEntry, BackgroundState, BackgroundStatus};
6
+ use crate::control::paths::ControlPaths;
7
+ use std::collections::HashMap;
8
+ use std::sync::{Arc, Mutex};
9
+ use std::time::{Duration, SystemTime, UNIX_EPOCH};
10
+ use time::OffsetDateTime;
11
+ use time::format_description::well_known::Rfc3339;
12
+
13
+ #[derive(Clone, Copy, Debug)]
14
+ struct TrackedJob {
15
+ started_at: SystemTime,
16
+ started_sort_key: u64,
17
+ }
18
+
19
+ /// Jobs explicitly known to one MCP session; clones share that session state.
20
+ #[derive(Clone, Debug, Default)]
21
+ pub(super) struct BackgroundTracker {
22
+ jobs: Arc<Mutex<HashMap<String, TrackedJob>>>,
23
+ }
24
+
25
+ impl BackgroundTracker {
26
+ pub(super) fn track_id(&self, job_id: &str, now: SystemTime) {
27
+ let started_sort_key = system_time_nanos(now);
28
+ self.jobs
29
+ .lock()
30
+ .unwrap()
31
+ .entry(job_id.to_string())
32
+ .or_insert(TrackedJob {
33
+ started_at: now,
34
+ started_sort_key,
35
+ });
36
+ }
37
+
38
+ pub(super) fn track_record(&self, record: &JobRecord, now: SystemTime) {
39
+ let tracked = tracked_start(record, now);
40
+ self.jobs.lock().unwrap().insert(record.id.clone(), tracked);
41
+ }
42
+
43
+ pub(super) fn remove(&self, job_id: &str) {
44
+ self.jobs.lock().unwrap().remove(job_id);
45
+ }
46
+
47
+ pub(super) fn has_candidates(&self, exclude: Option<&str>) -> bool {
48
+ self.jobs
49
+ .lock()
50
+ .unwrap()
51
+ .keys()
52
+ .any(|job_id| exclude != Some(job_id.as_str()))
53
+ }
54
+
55
+ pub(super) fn snapshot(
56
+ &self,
57
+ paths: &ControlPaths,
58
+ exclude: Option<&str>,
59
+ now: SystemTime,
60
+ ) -> Option<BackgroundStatus> {
61
+ self.snapshot_with_probe(exclude, now, |job_id| {
62
+ store::find_record(&paths.jobs_dir, job_id)
63
+ })
64
+ }
65
+
66
+ fn snapshot_with_probe(
67
+ &self,
68
+ exclude: Option<&str>,
69
+ now: SystemTime,
70
+ mut probe: impl FnMut(&str) -> Result<Option<JobRecord>, String>,
71
+ ) -> Option<BackgroundStatus> {
72
+ let tracked = self
73
+ .jobs
74
+ .lock()
75
+ .unwrap()
76
+ .iter()
77
+ .filter(|(job_id, _)| exclude != Some(job_id.as_str()))
78
+ .map(|(job_id, tracked)| (job_id.clone(), *tracked))
79
+ .collect::<Vec<_>>();
80
+ if tracked.is_empty() {
81
+ return None;
82
+ }
83
+
84
+ let mut entries = Vec::with_capacity(tracked.len());
85
+ let mut missing = Vec::new();
86
+ for (job_id, fallback) in tracked {
87
+ match probe(&job_id) {
88
+ Ok(Some(record)) => {
89
+ let start = tracked_start(&record, fallback.started_at);
90
+ self.jobs.lock().unwrap().insert(job_id.clone(), start);
91
+ let state = match &record.status {
92
+ JobStatus::Running => BackgroundState::Running,
93
+ JobStatus::Exited(exit) if exit.was_killed() => BackgroundState::Killed,
94
+ JobStatus::Exited(exit) => BackgroundState::Exited(exit.exit_code),
95
+ JobStatus::Interrupted => BackgroundState::Interrupted,
96
+ };
97
+ entries.push(BackgroundEntry {
98
+ job_id,
99
+ started_at: start.started_at,
100
+ started_sort_key: start.started_sort_key,
101
+ state,
102
+ });
103
+ }
104
+ Ok(None) => missing.push(job_id),
105
+ Err(_) => {}
106
+ }
107
+ }
108
+ if !missing.is_empty() {
109
+ let mut jobs = self.jobs.lock().unwrap();
110
+ for job_id in missing {
111
+ jobs.remove(&job_id);
112
+ }
113
+ }
114
+ BackgroundStatus::render(entries, now)
115
+ }
116
+ }
117
+
118
+ fn tracked_start(record: &JobRecord, fallback: SystemTime) -> TrackedJob {
119
+ let nanos = if record.meta.started_at_unix_nanos > 0 {
120
+ Some(record.meta.started_at_unix_nanos)
121
+ } else {
122
+ OffsetDateTime::parse(&record.meta.started_at, &Rfc3339)
123
+ .ok()
124
+ .and_then(|value| u64::try_from(value.unix_timestamp_nanos()).ok())
125
+ };
126
+ let Some(started_sort_key) = nanos else {
127
+ return TrackedJob {
128
+ started_at: fallback,
129
+ started_sort_key: system_time_nanos(fallback),
130
+ };
131
+ };
132
+ TrackedJob {
133
+ started_at: UNIX_EPOCH
134
+ .checked_add(Duration::from_nanos(started_sort_key))
135
+ .unwrap_or(fallback),
136
+ started_sort_key,
137
+ }
138
+ }
139
+
140
+ fn system_time_nanos(value: SystemTime) -> u64 {
141
+ value
142
+ .duration_since(UNIX_EPOCH)
143
+ .ok()
144
+ .and_then(|duration| u64::try_from(duration.as_nanos()).ok())
145
+ .unwrap_or(0)
146
+ }