@deslop/workbench 0.0.390 → 0.0.391
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.
- package/dist/server.js +48 -5
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -252616,7 +252616,11 @@ var Portless = class Portless extends Service()("@deslop/portless/service/Portle
|
|
|
252616
252616
|
});
|
|
252617
252617
|
};
|
|
252618
252618
|
//#endregion
|
|
252619
|
-
//#region ../../packages/usage/src/
|
|
252619
|
+
//#region ../../packages/usage/src/system.ts
|
|
252620
|
+
function percentage(input) {
|
|
252621
|
+
if (input.total <= 0) return 0;
|
|
252622
|
+
return Math.max(0, Math.min(100, input.used / input.total * 100));
|
|
252623
|
+
}
|
|
252620
252624
|
function cpuTimes() {
|
|
252621
252625
|
return reduce(cpus(), {
|
|
252622
252626
|
idle: 0,
|
|
@@ -252626,6 +252630,40 @@ function cpuTimes() {
|
|
|
252626
252630
|
total: total.total + cpu.times.idle + cpu.times.irq + cpu.times.nice + cpu.times.sys + cpu.times.user
|
|
252627
252631
|
}));
|
|
252628
252632
|
}
|
|
252633
|
+
function cpuUtilization(input) {
|
|
252634
|
+
const total = input.after.total - input.before.total;
|
|
252635
|
+
return percentage({
|
|
252636
|
+
total,
|
|
252637
|
+
used: total - (input.after.idle - input.before.idle)
|
|
252638
|
+
});
|
|
252639
|
+
}
|
|
252640
|
+
function nodeMemoryUtilization() {
|
|
252641
|
+
return percentage({
|
|
252642
|
+
total: totalmem(),
|
|
252643
|
+
used: totalmem() - freemem()
|
|
252644
|
+
});
|
|
252645
|
+
}
|
|
252646
|
+
function darwinPageCount(input) {
|
|
252647
|
+
return Number(new RegExp(`${input.label}:\\s+(\\d+)\\.`, "u").exec(input.vmStatOutput)?.[1] ?? 0);
|
|
252648
|
+
}
|
|
252649
|
+
function darwinMemoryUtilization(input) {
|
|
252650
|
+
const pageSize = Number(/page size of (\d+) bytes/u.exec(input.vmStatOutput)?.[1] ?? 0);
|
|
252651
|
+
return percentage({
|
|
252652
|
+
total: Number(/(\d+)/u.exec(input.memsizeOutput)?.[1] ?? 0),
|
|
252653
|
+
used: (darwinPageCount({
|
|
252654
|
+
label: "Pages active",
|
|
252655
|
+
vmStatOutput: input.vmStatOutput
|
|
252656
|
+
}) + darwinPageCount({
|
|
252657
|
+
label: "Pages wired down",
|
|
252658
|
+
vmStatOutput: input.vmStatOutput
|
|
252659
|
+
}) + darwinPageCount({
|
|
252660
|
+
label: "Pages occupied by compressor",
|
|
252661
|
+
vmStatOutput: input.vmStatOutput
|
|
252662
|
+
})) * pageSize
|
|
252663
|
+
});
|
|
252664
|
+
}
|
|
252665
|
+
//#endregion
|
|
252666
|
+
//#region ../../packages/usage/src/service.ts
|
|
252629
252667
|
var Usage = class extends Service()("@deslop/usage/service/Usage", { make: gen(function* () {
|
|
252630
252668
|
const client = yield* HttpClient;
|
|
252631
252669
|
const fs = yield* FileSystem;
|
|
@@ -252654,15 +252692,20 @@ var Usage = class extends Service()("@deslop/usage/service/Usage", { make: gen(f
|
|
|
252654
252692
|
const claudeCredentialsFile = fs.readFileString(`${home}/.claude/.credentials.json`);
|
|
252655
252693
|
const claudeToken = pipe(process.platform === "darwin" ? pipe(claudeCredentialsFile, catch_$2(() => keychainCredentials)) : claudeCredentialsFile, flatMap$2(decodeEffect(ClaudeCredentials)), map$4((credentials) => credentials.claudeAiOauth.accessToken), catch_$2(() => new UsageError({ message: "not signed in" })));
|
|
252656
252694
|
const codexToken = pipe(fs.readFileString(`${codexHome}/auth.json`), flatMap$2(decodeEffect(CodexCredentials)), map$4((credentials) => credentials.tokens.access_token), catch_$2(() => new UsageError({ message: "not signed in" })));
|
|
252695
|
+
const memoryUtilization = process.platform === "darwin" ? pipe(all({
|
|
252696
|
+
memsizeOutput: commandOutput("sysctl", ["-n", "hw.memsize"]),
|
|
252697
|
+
vmStatOutput: commandOutput("vm_stat", [])
|
|
252698
|
+
}, { concurrency: 2 }), map$4((output) => darwinMemoryUtilization(output)), catch_$2(() => sync(nodeMemoryUtilization))) : sync(nodeMemoryUtilization);
|
|
252657
252699
|
const system = pipe(gen(function* () {
|
|
252658
252700
|
const before = cpuTimes();
|
|
252659
252701
|
yield* sleep$1("250 millis");
|
|
252660
252702
|
const after = cpuTimes();
|
|
252661
|
-
const total = after.total - before.total;
|
|
252662
|
-
const idle = after.idle - before.idle;
|
|
252663
252703
|
return SystemUsage.make({
|
|
252664
|
-
cpuUtilization:
|
|
252665
|
-
|
|
252704
|
+
cpuUtilization: cpuUtilization({
|
|
252705
|
+
after,
|
|
252706
|
+
before
|
|
252707
|
+
}),
|
|
252708
|
+
memoryUtilization: yield* memoryUtilization
|
|
252666
252709
|
});
|
|
252667
252710
|
}), withSpan("Usage.system"));
|
|
252668
252711
|
return {
|