@modootoday/pmcp 0.26.1 → 0.27.0

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 (82) hide show
  1. package/.agents/plugins/marketplace.json +1 -1
  2. package/.claude-plugin/marketplace.json +1 -1
  3. package/.claude-plugin/plugin.json +1 -1
  4. package/.mcp.json +1 -1
  5. package/dist/{apply-7HWNHSQB.js → apply-YNBY2GPK.js} +7 -7
  6. package/dist/{chunk-BSG74PTY.js → chunk-5TT7YAEP.js} +3 -3
  7. package/dist/chunk-674APJDK.js +128 -0
  8. package/dist/chunk-6TM7PLXG.js +154 -0
  9. package/dist/{chunk-5ZP3ABPI.js → chunk-6U6MLIS2.js} +2 -2
  10. package/dist/{chunk-GYL2C2Y5.js → chunk-ENFF7ZBC.js} +2 -2
  11. package/dist/{chunk-XPLT6DJC.js → chunk-GVKVMSWX.js} +25 -23
  12. package/dist/{chunk-T52AGUO7.js → chunk-JTKGDT2K.js} +2 -2
  13. package/dist/{chunk-UHKHXS3E.js → chunk-L5EJK24I.js} +2 -2
  14. package/dist/{chunk-3T7CJS4A.js → chunk-LKH57HLV.js} +2 -2
  15. package/dist/chunk-LXJTABBQ.js +1148 -0
  16. package/dist/{chunk-OHCUPXU4.js → chunk-LXWAU7AX.js} +65 -2
  17. package/dist/{chunk-ZT75ACJ2.js → chunk-M5GNZSOJ.js} +2 -2
  18. package/dist/chunk-MXVP3ICV.js +7 -0
  19. package/dist/{chunk-2VL3C52Y.js → chunk-OY7XYKVL.js} +2 -2
  20. package/dist/{chunk-M2XABD33.js → chunk-OZTEMCCM.js} +3 -3
  21. package/dist/{chunk-CJD2HFXF.js → chunk-PH3P5WEY.js} +3 -3
  22. package/dist/{chunk-MFQAQ4IJ.js → chunk-Q3XLIRIJ.js} +4 -4
  23. package/dist/{chunk-E7BPELYH.js → chunk-TVA2IN6H.js} +5 -5
  24. package/dist/chunk-TYXJBXZQ.js +441 -0
  25. package/dist/chunk-WG7KH46S.js +71 -0
  26. package/dist/{chunk-GIK4TROM.js → chunk-X2WDR3UK.js} +2 -2
  27. package/dist/{chunk-A7MF7RMO.js → chunk-X3LNF5KJ.js} +5 -5
  28. package/dist/{chunk-KWEW5EBE.js → chunk-XCIFD7G5.js} +2 -2
  29. package/dist/{chunk-JDVDA5HW.js → chunk-Y5WIIEG2.js} +2 -2
  30. package/dist/{chunk-RGTWJWQ7.js → chunk-ZO5CRS2T.js} +2 -2
  31. package/dist/cli.js +10 -10
  32. package/dist/{completion-O3KRUSJG.js → completion-WKIMMLNF.js} +6 -6
  33. package/dist/{diagnostics-PB5TKIAL.js → diagnostics-LCNF5NRK.js} +5 -5
  34. package/dist/doctor-NKFZNSRD.js +106 -0
  35. package/dist/{doctor-JVWINJT5.js → doctor-PSMPNQXS.js} +9 -9
  36. package/dist/{entry-CY74PLN3.js → entry-LMAWTZM2.js} +11 -11
  37. package/dist/{exec-mcp-HAKUGQZM.js → exec-mcp-VAP46MKO.js} +5 -5
  38. package/dist/{harness-N234LNM7.js → harness-ZCMU5MJD.js} +3 -3
  39. package/dist/harness-launch-gate.js +3 -3
  40. package/dist/harness-worker.js +5 -5
  41. package/dist/heavy-VBC4AGL6.js +1063 -0
  42. package/dist/{hooks-7K624JQC.js → hooks-AWAO7CQO.js} +3 -3
  43. package/dist/{host-CCJFOCZJ.js → host-4GFQQJUS.js} +7 -7
  44. package/dist/{host-PT7NRWG6.js → host-I4XIJTXR.js} +6 -6
  45. package/dist/host-OBTC2PGQ.js +32 -0
  46. package/dist/{host-run-RRBFTVYW.js → host-run-T3FC7L6I.js} +4 -4
  47. package/dist/http.js +1 -1
  48. package/dist/{import-mcp-GCNNSLWH.js → import-mcp-5JSGA5IS.js} +4 -4
  49. package/dist/index.d.ts +1 -1
  50. package/dist/index.js +8 -8
  51. package/dist/{init-A4NLTERR.js → init-PZYWBDZS.js} +2 -2
  52. package/dist/{invoke-G4LNWPTL.js → invoke-DCKJCMRB.js} +7 -7
  53. package/dist/jobs-FLHB3WER.js +26 -0
  54. package/dist/{list-EZYULVDW.js → list-ZEU7T3XK.js} +6 -6
  55. package/dist/{logout-BYO3UJUH.js → logout-CUSOVMKL.js} +5 -5
  56. package/dist/{mcp-CZNYDYTJ.js → mcp-ZHOPOFXI.js} +2 -2
  57. package/dist/measure-AUBPYT6L.js +129 -0
  58. package/dist/plan-46BTJQIV.js +98 -0
  59. package/dist/{project-GLT3SO7Y.js → project-T36TRAWT.js} +4 -4
  60. package/dist/{run-OBQBKBPV.js → run-37PVE74I.js} +4 -4
  61. package/dist/{run-J5O2V3MB.js → run-LMSHQJPQ.js} +4 -4
  62. package/dist/{serve-QCG4PCVS.js → serve-E4FD6PAL.js} +3 -3
  63. package/dist/{start-login-LRO3RTHD.js → start-login-JSKFXSLY.js} +5 -5
  64. package/dist/{status-BQLT7JRE.js → status-ZNWF4362.js} +5 -5
  65. package/dist/{status-EZTFSD5S.js → status-ZSK3PNM2.js} +6 -6
  66. package/dist/stdio.js +2 -2
  67. package/dist/{test-O7TN5SBA.js → test-OCTC2DSZ.js} +5 -5
  68. package/dist/{tui-ODLF6QWC.js → tui-LE2KPUMI.js} +4 -4
  69. package/dist/{worker-AK4GLGPZ.js → worker-6U67LWIP.js} +9 -9
  70. package/docs/commands.md +24 -8
  71. package/docs/project-configuration.md +1 -1
  72. package/gemini-extension.json +2 -2
  73. package/mcp.json +1 -1
  74. package/package.json +5 -5
  75. package/plugin.json +1 -1
  76. package/plugins/pmcp/.claude-plugin/plugin.json +1 -1
  77. package/plugins/pmcp/.mcp.json +1 -1
  78. package/plugins/pmcp/gemini-extension.json +2 -2
  79. package/plugins/pmcp/mcp.json +1 -1
  80. package/plugins/pmcp/plugin.json +1 -1
  81. package/dist/chunk-EIBKHS74.js +0 -7
  82. package/dist/heavy-X3KZ7WBU.js +0 -2211
@@ -145,8 +145,71 @@ var heavySpec = {
145
145
  }
146
146
  ]
147
147
  };
148
+ var hostSpec = {
149
+ name: "host",
150
+ examples: [
151
+ "pmcp host io measure",
152
+ "pmcp host io plan",
153
+ "pmcp host io doctor --weights"
154
+ ],
155
+ subcommands: [
156
+ {
157
+ name: "io measure",
158
+ describe: "Probe the disk under the host lease and record its io.cost model",
159
+ usage: "pmcp host io measure [--dir <path>] [--seconds <n>] [--json]",
160
+ options: ["dir", "seconds", "config", "json"],
161
+ examples: ["pmcp host io measure --dir /var/tmp"]
162
+ },
163
+ {
164
+ name: "io plan",
165
+ describe: "Print the io.cost lines and a systemd unit to install as root",
166
+ usage: "pmcp host io plan [--unit <name>] [--json]",
167
+ options: ["unit", "config", "json"],
168
+ examples: ["pmcp host io plan --unit iocost.service"]
169
+ },
170
+ {
171
+ name: "io doctor",
172
+ describe: "Compare the live io.cost model and qos with the record",
173
+ usage: "pmcp host io doctor [--weights [--seconds <n>]] [--json]",
174
+ options: ["weights", "seconds", "config", "json"],
175
+ examples: ["pmcp host io doctor", "pmcp host io doctor --weights"]
176
+ }
177
+ ],
178
+ describe: "Measure the disk and check the io.cost model the lease's io weights rely on",
179
+ usage: "pmcp host io <measure|plan|doctor> [options]",
180
+ options: [
181
+ nearestConfigOption,
182
+ jsonOption,
183
+ {
184
+ name: "dir",
185
+ describe: "measure: make the probe file on this directory's filesystem (default: the lease directory).",
186
+ placeholder: "<path>"
187
+ },
188
+ {
189
+ name: "seconds",
190
+ describe: "measure: seconds per probe pattern (default 8); doctor --weights: seconds the readers run (default 20).",
191
+ placeholder: "<n>"
192
+ },
193
+ {
194
+ name: "unit",
195
+ describe: "plan: print a drop-in for this oneshot unit instead of a unit of its own.",
196
+ placeholder: "<name>"
197
+ },
198
+ {
199
+ name: "weights",
200
+ describe: "doctor: also run two readers at io.weight 25 and 100 under the host lease and compare them.",
201
+ boolean: true
202
+ },
203
+ {
204
+ name: "probe",
205
+ describe: "Internal: the probe job a leased run executes.",
206
+ placeholder: "<job>"
207
+ }
208
+ ]
209
+ };
148
210
 
149
211
  export {
150
- heavySpec
212
+ heavySpec,
213
+ hostSpec
151
214
  };
152
- //# sourceMappingURL=chunk-OHCUPXU4.js.map
215
+ //# sourceMappingURL=chunk-LXWAU7AX.js.map
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-7CHUMF3E.js";
4
4
  import {
5
5
  readSpec
6
- } from "./chunk-JDVDA5HW.js";
6
+ } from "./chunk-Y5WIIEG2.js";
7
7
  import {
8
8
  ArgumentError
9
9
  } from "./chunk-Y6NFETNG.js";
@@ -25,4 +25,4 @@ function serverFrom(context) {
25
25
  export {
26
26
  serverFrom
27
27
  };
28
- //# sourceMappingURL=chunk-ZT75ACJ2.js.map
28
+ //# sourceMappingURL=chunk-M5GNZSOJ.js.map
@@ -0,0 +1,7 @@
1
+ // src/commands/version.ts
2
+ var VERSION = "0.27.0";
3
+
4
+ export {
5
+ VERSION
6
+ };
7
+ //# sourceMappingURL=chunk-MXVP3ICV.js.map
@@ -12,7 +12,7 @@ import {
12
12
  } from "./chunk-XWLMZKH2.js";
13
13
  import {
14
14
  VERSION
15
- } from "./chunk-EIBKHS74.js";
15
+ } from "./chunk-MXVP3ICV.js";
16
16
  import {
17
17
  ConfigError
18
18
  } from "./chunk-GJXOFDJT.js";
@@ -610,4 +610,4 @@ export {
610
610
  hostEnvDoctor,
611
611
  hostDoctor
612
612
  };
613
- //# sourceMappingURL=chunk-2VL3C52Y.js.map
613
+ //# sourceMappingURL=chunk-OY7XYKVL.js.map
@@ -3,13 +3,13 @@ import {
3
3
  } from "./chunk-5ZABTVSW.js";
4
4
  import {
5
5
  dependencies
6
- } from "./chunk-5ZP3ABPI.js";
6
+ } from "./chunk-6U6MLIS2.js";
7
7
  import {
8
8
  interactiveEntry
9
9
  } from "./chunk-LMT3PPXJ.js";
10
10
  import {
11
11
  assertNativeHost
12
- } from "./chunk-3T7CJS4A.js";
12
+ } from "./chunk-LKH57HLV.js";
13
13
 
14
14
  // src/tui/startup/host.ts
15
15
  function terminalSupport() {
@@ -42,4 +42,4 @@ export {
42
42
  terminalSupport,
43
43
  requireTerminal
44
44
  };
45
- //# sourceMappingURL=chunk-M2XABD33.js.map
45
+ //# sourceMappingURL=chunk-OZTEMCCM.js.map
@@ -19,12 +19,12 @@ import {
19
19
  splitKeyed,
20
20
  versionMatches,
21
21
  withoutBlock
22
- } from "./chunk-JDVDA5HW.js";
22
+ } from "./chunk-Y5WIIEG2.js";
23
23
  import {
24
24
  lockVersionProblem,
25
25
  readLock,
26
26
  replaceFile
27
- } from "./chunk-2VL3C52Y.js";
27
+ } from "./chunk-OY7XYKVL.js";
28
28
  import {
29
29
  ProjectError,
30
30
  RULES_DIR,
@@ -273,4 +273,4 @@ export {
273
273
  prepare,
274
274
  checkProject
275
275
  };
276
- //# sourceMappingURL=chunk-CJD2HFXF.js.map
276
+ //# sourceMappingURL=chunk-PH3P5WEY.js.map
@@ -7,7 +7,7 @@ import {
7
7
  prepare,
8
8
  present,
9
9
  writeNative
10
- } from "./chunk-CJD2HFXF.js";
10
+ } from "./chunk-PH3P5WEY.js";
11
11
  import {
12
12
  ANTIGRAVITY_MCP_PLUGIN,
13
13
  BUNDLE_NATIVE_FILES,
@@ -21,7 +21,7 @@ import {
21
21
  same,
22
22
  splitKeyed,
23
23
  withoutBlock
24
- } from "./chunk-JDVDA5HW.js";
24
+ } from "./chunk-Y5WIIEG2.js";
25
25
  import {
26
26
  HOOK_DIRECTORY
27
27
  } from "./chunk-GQRDEIQA.js";
@@ -30,7 +30,7 @@ import {
30
30
  replaceFile,
31
31
  replaceLink,
32
32
  writeLock
33
- } from "./chunk-2VL3C52Y.js";
33
+ } from "./chunk-OY7XYKVL.js";
34
34
  import {
35
35
  RULES_DIR,
36
36
  legacyLinks
@@ -400,4 +400,4 @@ export {
400
400
  unmanagedHooks,
401
401
  describeHookProblem
402
402
  };
403
- //# sourceMappingURL=chunk-MFQAQ4IJ.js.map
403
+ //# sourceMappingURL=chunk-Q3XLIRIJ.js.map
@@ -7,20 +7,20 @@ import {
7
7
  observeSession,
8
8
  openGroup,
9
9
  runOperation
10
- } from "./chunk-BSG74PTY.js";
10
+ } from "./chunk-5TT7YAEP.js";
11
11
  import {
12
12
  nativeHostTools
13
- } from "./chunk-3T7CJS4A.js";
13
+ } from "./chunk-LKH57HLV.js";
14
14
  import {
15
15
  locateExecutable
16
16
  } from "./chunk-R2GPCZUX.js";
17
17
  import {
18
18
  artifact,
19
19
  stateDirectory
20
- } from "./chunk-T52AGUO7.js";
20
+ } from "./chunk-JTKGDT2K.js";
21
21
  import {
22
22
  ptyBinary
23
- } from "./chunk-2VL3C52Y.js";
23
+ } from "./chunk-OY7XYKVL.js";
24
24
  import {
25
25
  GroupStore,
26
26
  privateJson
@@ -249,4 +249,4 @@ async function invoke(operation) {
249
249
  export {
250
250
  invoke
251
251
  };
252
- //# sourceMappingURL=chunk-E7BPELYH.js.map
252
+ //# sourceMappingURL=chunk-TVA2IN6H.js.map
@@ -0,0 +1,441 @@
1
+ import {
2
+ applyIo,
3
+ cgroupHost
4
+ } from "./chunk-WG7KH46S.js";
5
+
6
+ // src/host/io/jobs.ts
7
+ import { spawn } from "child_process";
8
+ import { mkdirSync, readFileSync as readFileSync2, writeFileSync } from "fs";
9
+ import { join as join2 } from "path";
10
+
11
+ // src/host/io/probe.ts
12
+ import { randomFillSync } from "crypto";
13
+ import {
14
+ closeSync,
15
+ constants,
16
+ fstatSync,
17
+ fsyncSync,
18
+ openSync,
19
+ read,
20
+ write,
21
+ writeSync
22
+ } from "fs";
23
+ import { performance } from "perf_hooks";
24
+ var BLOCK = 4096;
25
+ var MIB = 1 << 20;
26
+ var WASM_PAGE = 65536;
27
+ function alignedBuffer(size) {
28
+ const { Memory } = globalThis.WebAssembly;
29
+ const memory = new Memory({ initial: Math.ceil(size / WASM_PAGE) });
30
+ return Buffer.from(memory.buffer, 0, size);
31
+ }
32
+ function direct() {
33
+ const flag = constants["O_DIRECT"];
34
+ if (flag === void 0) throw new Error("O_DIRECT is not available here");
35
+ return flag;
36
+ }
37
+ function openDirect(path, flags, mode) {
38
+ try {
39
+ return openSync(path, flags | direct(), mode);
40
+ } catch (error) {
41
+ if (error.code === "EINVAL")
42
+ throw new Error(
43
+ `${path}: this filesystem refuses O_DIRECT; give --dir on a disk-backed filesystem`
44
+ );
45
+ throw error;
46
+ }
47
+ }
48
+ function makeFile(path, sizeMb) {
49
+ const fd = openDirect(
50
+ path,
51
+ constants.O_WRONLY | constants.O_CREAT | constants.O_TRUNC,
52
+ 384
53
+ );
54
+ try {
55
+ const buffer = alignedBuffer(MIB);
56
+ randomFillSync(buffer);
57
+ const begun = performance.now();
58
+ for (let at = 0; at < sizeMb; at += 1) writeSync(fd, buffer, 0, MIB);
59
+ fsyncSync(fd);
60
+ const seconds = (performance.now() - begun) / 1e3;
61
+ return rate(sizeMb, MIB, seconds);
62
+ } finally {
63
+ closeSync(fd);
64
+ }
65
+ }
66
+ function rate(ops, size, seconds) {
67
+ return {
68
+ ops,
69
+ seconds: Math.round(seconds * 100) / 100,
70
+ iops: Math.floor(ops / seconds),
71
+ bps: Math.floor(ops * size / seconds)
72
+ };
73
+ }
74
+ function io(fd, buffer, offset, writing) {
75
+ return new Promise((resolve, reject) => {
76
+ const done = (error, bytes) => {
77
+ if (error) return reject(error);
78
+ if (bytes !== buffer.length)
79
+ return reject(new Error(`short ${writing ? "write" : "read"}`));
80
+ resolve();
81
+ };
82
+ if (writing) write(fd, buffer, 0, buffer.length, offset, done);
83
+ else read(fd, buffer, 0, buffer.length, offset, done);
84
+ });
85
+ }
86
+ async function runPattern(path, seconds, pattern) {
87
+ const flags = pattern.write ? constants.O_RDWR : constants.O_RDONLY;
88
+ const fd = openDirect(path, flags);
89
+ try {
90
+ const blocks = Math.floor(fstatSync(fd).size / pattern.size);
91
+ const per = Math.floor(blocks / pattern.depth);
92
+ if (per < 1) throw new Error(`${path} is too small for the probe`);
93
+ const memory = alignedBuffer(pattern.size * pattern.depth);
94
+ if (pattern.write) randomFillSync(memory);
95
+ const deadline = performance.now() + seconds * 1e3;
96
+ let ops = 0;
97
+ const loop = async (lane) => {
98
+ const buffer = memory.subarray(
99
+ lane * pattern.size,
100
+ (lane + 1) * pattern.size
101
+ );
102
+ let position = lane * per;
103
+ while (performance.now() < deadline) {
104
+ let block;
105
+ if (pattern.sequential) {
106
+ block = position;
107
+ position = position + 1 >= (lane + 1) * per ? lane * per : position + 1;
108
+ } else block = Math.floor(Math.random() * blocks);
109
+ await io(fd, buffer, block * pattern.size, pattern.write);
110
+ ops += 1;
111
+ }
112
+ };
113
+ const begun = performance.now();
114
+ await Promise.all(
115
+ Array.from({ length: pattern.depth }, (_, lane) => loop(lane))
116
+ );
117
+ const elapsed = (performance.now() - begun) / 1e3;
118
+ if (pattern.write) fsyncSync(fd);
119
+ return rate(ops, pattern.size, elapsed);
120
+ } finally {
121
+ closeSync(fd);
122
+ }
123
+ }
124
+ var DEPTH = 16;
125
+ var PATTERNS = {
126
+ rseq_1m_qd4: { depth: 4, size: MIB, write: false, sequential: true },
127
+ rseq_4k_qd16: { depth: DEPTH, size: BLOCK, write: false, sequential: true },
128
+ rrand_4k_qd16: { depth: DEPTH, size: BLOCK, write: false, sequential: false },
129
+ wseq_4k_qd16: { depth: DEPTH, size: BLOCK, write: true, sequential: true },
130
+ wrand_4k_qd16: { depth: DEPTH, size: BLOCK, write: true, sequential: false }
131
+ };
132
+ async function probeAll(path, sizeMb, seconds) {
133
+ const made = makeFile(path, sizeMb);
134
+ const found = { wseq_1m_file: made };
135
+ for (const [name, pattern] of Object.entries(PATTERNS))
136
+ found[name] = await runPattern(path, seconds, pattern);
137
+ return found;
138
+ }
139
+ function modelOf(probes) {
140
+ const take = (name, key) => {
141
+ const value = probes[name]?.[key];
142
+ if (value === void 0 || value < 1)
143
+ throw new Error(`the ${name} probe gave no ${key}`);
144
+ return value;
145
+ };
146
+ return {
147
+ rbps: take("rseq_1m_qd4", "bps"),
148
+ rseqiops: take("rseq_4k_qd16", "iops"),
149
+ rrandiops: take("rrand_4k_qd16", "iops"),
150
+ wbps: take("wseq_1m_file", "bps"),
151
+ wseqiops: take("wseq_4k_qd16", "iops"),
152
+ wrandiops: take("wrand_4k_qd16", "iops")
153
+ };
154
+ }
155
+
156
+ // src/host/io/sysfs.ts
157
+ import { existsSync, readFileSync, realpathSync, statSync } from "fs";
158
+ import { dirname, join } from "path";
159
+
160
+ // src/host/io/model.ts
161
+ var MODEL_KEYS = [
162
+ "rbps",
163
+ "rseqiops",
164
+ "rrandiops",
165
+ "wbps",
166
+ "wseqiops",
167
+ "wrandiops"
168
+ ];
169
+ var QOS = "enable=1 ctrl=user rpct=0 rlat=0 wpct=0 wlat=0 min=50 max=100";
170
+ function modelLine(device, model) {
171
+ const fields = MODEL_KEYS.map((key) => `${key}=${model[key]}`).join(" ");
172
+ return `${device} ctrl=user model=linear ${fields}`;
173
+ }
174
+ function qosLine(device) {
175
+ return `${device} ${QOS}`;
176
+ }
177
+ function parseCostLines(text) {
178
+ return text.split("\n").map((line) => line.trim()).filter((line) => line !== "").map((line) => {
179
+ const [device = "", ...pairs] = line.split(/\s+/u);
180
+ const fields = {};
181
+ for (const pair of pairs) {
182
+ const at = pair.indexOf("=");
183
+ if (at > 0) fields[pair.slice(0, at)] = pair.slice(at + 1);
184
+ }
185
+ return { device, fields };
186
+ });
187
+ }
188
+ var SYSTEMD_UNIT = "pmcp-io-cost.service";
189
+ function execLines(device, model) {
190
+ const write2 = (line, file) => `ExecStart=/bin/sh -c "echo '${line}' > /sys/fs/cgroup/${file}"`;
191
+ return [
192
+ write2(modelLine(device, model), "io.cost.model"),
193
+ write2(qosLine(device), "io.cost.qos")
194
+ ];
195
+ }
196
+ function systemdUnit(devices, dropInFor) {
197
+ const exec = devices.flatMap(({ device, model }) => execLines(device, model));
198
+ if (dropInFor !== void 0)
199
+ return {
200
+ path: `/etc/systemd/system/${dropInFor}.d/pmcp-io-model.conf`,
201
+ text: ["[Service]", ...exec, ""].join("\n")
202
+ };
203
+ return {
204
+ path: `/etc/systemd/system/${SYSTEMD_UNIT}`,
205
+ text: [
206
+ "[Unit]",
207
+ "Description=io.cost model measured by pmcp host io measure",
208
+ "After=local-fs.target",
209
+ "",
210
+ "[Service]",
211
+ "Type=oneshot",
212
+ "RemainAfterExit=yes",
213
+ ...exec,
214
+ "",
215
+ "[Install]",
216
+ "WantedBy=multi-user.target",
217
+ ""
218
+ ].join("\n")
219
+ };
220
+ }
221
+
222
+ // src/host/io/sysfs.ts
223
+ var SYSFS = "/sys";
224
+ function cgroupRoot(sys) {
225
+ return join(sys, "fs", "cgroup");
226
+ }
227
+ function read2(path) {
228
+ try {
229
+ return readFileSync(path, "utf8");
230
+ } catch {
231
+ return null;
232
+ }
233
+ }
234
+ function liveCost(sys) {
235
+ const model = read2(join(cgroupRoot(sys), "io.cost.model"));
236
+ const qos = read2(join(cgroupRoot(sys), "io.cost.qos"));
237
+ return {
238
+ model: model === null ? null : parseCostLines(model),
239
+ qos: qos === null ? null : parseCostLines(qos)
240
+ };
241
+ }
242
+ function deviceOf(path) {
243
+ const dev = BigInt(statSync(path, { bigint: true }).dev);
244
+ const major = dev >> 8n & 0xfffn | dev >> 32n & ~0xfffn;
245
+ const minor = dev & 0xffn | dev >> 12n & ~0xffn;
246
+ return `${major}:${minor}`;
247
+ }
248
+ function wholeDisk(sys, device) {
249
+ const node = join(sys, "dev", "block", device);
250
+ if (!existsSync(join(node, "partition"))) return device;
251
+ try {
252
+ const parent = read2(join(dirname(realpathSync(node)), "dev"))?.trim();
253
+ return parent || device;
254
+ } catch {
255
+ return device;
256
+ }
257
+ }
258
+ function ioGaps(root, scope) {
259
+ const parts = scope.split("/").filter(Boolean);
260
+ const gaps = [];
261
+ for (let at = 0; at < parts.length; at += 1) {
262
+ const rel = parts.slice(0, at);
263
+ const text = read2(join(root, ...rel, "cgroup.subtree_control")) ?? "";
264
+ if (!text.split(/\s+/u).includes("io")) gaps.push(`/${rel.join("/")}`);
265
+ }
266
+ return gaps;
267
+ }
268
+
269
+ // src/host/io/jobs.ts
270
+ var PROBE_SLICE = "pmcp-io.slice";
271
+ var RESULT = "result.json";
272
+ var THREADS = String(DEPTH);
273
+ function selfArgv() {
274
+ return [process.execPath, ...process.execArgv, process.argv[1] ?? ""];
275
+ }
276
+ function jobArgv(self, verb, job) {
277
+ return [...self, "host", "io", verb, "--probe", JSON.stringify(job)];
278
+ }
279
+ function inScope(argv, unit) {
280
+ return [
281
+ "systemd-run",
282
+ "--user",
283
+ "--scope",
284
+ "-q",
285
+ `--slice=${PROBE_SLICE}`,
286
+ `--unit=${unit}`,
287
+ "--",
288
+ ...argv
289
+ ];
290
+ }
291
+ function writeJson(path, value) {
292
+ writeFileSync(path, `${JSON.stringify(value)}
293
+ `, { mode: 384 });
294
+ }
295
+ function readJson(path) {
296
+ return JSON.parse(readFileSync2(path, "utf8"));
297
+ }
298
+ function ownCgroup() {
299
+ const line = readFileSync2("/proc/self/cgroup", "utf8").split("\n").find((entry) => entry.startsWith("0::"));
300
+ return line?.slice(3).trim() ?? "";
301
+ }
302
+ async function reader(job) {
303
+ const host = cgroupHost();
304
+ const scope = ownCgroup();
305
+ const applied = applyIo(host, scope, job.weight, void 0);
306
+ let weightSet = false;
307
+ try {
308
+ const text = readFileSync2(join2(host.root, scope, "io.weight"), "utf8");
309
+ weightSet = text.includes(`default ${job.weight}`);
310
+ } catch {
311
+ weightSet = false;
312
+ }
313
+ const gaps = ioGaps(host.root, scope);
314
+ const base = { weight: job.weight, cgroup: scope, gaps, weightSet };
315
+ const out = join2(job.dir, RESULT);
316
+ if (gaps.length > 0 || !applied.weight || !weightSet) {
317
+ writeJson(out, { ...base, rate: null });
318
+ return;
319
+ }
320
+ await new Promise(
321
+ (resolve) => setTimeout(resolve, Math.max(0, job.startAt - Date.now()))
322
+ );
323
+ const rate2 = await runPattern(
324
+ join2(job.dir, "probe.bin"),
325
+ job.seconds,
326
+ PATTERNS["rrand_4k_qd16"]
327
+ );
328
+ writeJson(out, { ...base, rate: rate2 });
329
+ }
330
+ function waitFor(argv) {
331
+ const [bin, ...rest] = argv;
332
+ return new Promise((resolve) => {
333
+ const child = spawn(bin, rest, {
334
+ stdio: ["ignore", "inherit", "inherit"],
335
+ env: { ...process.env, UV_THREADPOOL_SIZE: THREADS }
336
+ });
337
+ child.on("error", () => resolve(127));
338
+ child.on("exit", (code) => resolve(code ?? 1));
339
+ });
340
+ }
341
+ var WEIGHTS = [25, 100];
342
+ async function compare(job) {
343
+ const dirs = WEIGHTS.map((weight) => join2(job.dir, `w${weight}`));
344
+ for (const dir of dirs) {
345
+ mkdirSync(dir, { mode: 448 });
346
+ makeFile(join2(dir, "probe.bin"), job.sizeMb);
347
+ }
348
+ const startAt = Date.now() + 3e3;
349
+ const codes = await Promise.all(
350
+ WEIGHTS.map((weight, at) => {
351
+ const unit = `pmcp-io-check-w${weight}-${process.pid}-${Date.now()}`;
352
+ const reading = {
353
+ kind: "reader",
354
+ dir: dirs[at],
355
+ weight,
356
+ startAt,
357
+ seconds: job.seconds
358
+ };
359
+ return waitFor(inScope(jobArgv(job.self, "doctor", reading), unit));
360
+ })
361
+ );
362
+ writeJson(join2(job.dir, RESULT), compareOf(dirs, codes));
363
+ }
364
+ function compareOf(dirs, codes) {
365
+ if (codes.some((code) => code !== 0))
366
+ return {
367
+ valid: false,
368
+ readers: [],
369
+ ratio: null,
370
+ problem: `a test scope exited ${codes.join(" and ")}`
371
+ };
372
+ return judgeCompare(
373
+ dirs.map((dir) => readJson(join2(dir, RESULT)))
374
+ );
375
+ }
376
+ function judgeCompare(readers) {
377
+ const gaps = [...new Set(readers.flatMap((entry) => entry.gaps))];
378
+ if (gaps.length > 0)
379
+ return {
380
+ valid: false,
381
+ readers,
382
+ ratio: null,
383
+ problem: `io is not enabled in cgroup.subtree_control of ${gaps.join(", ")}`
384
+ };
385
+ const unset = readers.filter((entry) => !entry.weightSet);
386
+ if (unset.length > 0)
387
+ return {
388
+ valid: false,
389
+ readers,
390
+ ratio: null,
391
+ problem: `io.weight could not be written in ${unset.map((entry) => entry.cgroup).join(", ")}`
392
+ };
393
+ const low = readers.find((entry) => entry.weight === 25)?.rate?.iops ?? 0;
394
+ const high = readers.find((entry) => entry.weight === 100)?.rate?.iops ?? 0;
395
+ return {
396
+ valid: true,
397
+ readers,
398
+ ratio: Math.round(high / Math.max(low, 1) * 100) / 100
399
+ };
400
+ }
401
+ async function runJob(text) {
402
+ const job = JSON.parse(text);
403
+ if (job.kind !== "reader") mkdirSync(job.dir, { mode: 448 });
404
+ if (job.kind === "measure") {
405
+ process.stderr.write(
406
+ `pmcp host io: probing ${job.dir} (${job.sizeMb} MiB, ${job.seconds}s per pattern)
407
+ `
408
+ );
409
+ const probes = await probeAll(
410
+ join2(job.dir, "probe.bin"),
411
+ job.sizeMb,
412
+ job.seconds
413
+ );
414
+ writeJson(join2(job.dir, RESULT), probes);
415
+ } else if (job.kind === "reader") await reader(job);
416
+ else await compare(job);
417
+ return 0;
418
+ }
419
+
420
+ export {
421
+ modelOf,
422
+ MODEL_KEYS,
423
+ modelLine,
424
+ qosLine,
425
+ systemdUnit,
426
+ SYSFS,
427
+ liveCost,
428
+ deviceOf,
429
+ wholeDisk,
430
+ PROBE_SLICE,
431
+ RESULT,
432
+ THREADS,
433
+ selfArgv,
434
+ jobArgv,
435
+ inScope,
436
+ readJson,
437
+ WEIGHTS,
438
+ judgeCompare,
439
+ runJob
440
+ };
441
+ //# sourceMappingURL=chunk-TYXJBXZQ.js.map