Repository navigation
Expand file tree
/
Copy pathHostEnvironment.cs
More file actions
145 lines (134 loc) · 5.72 KB
/
Copy pathHostEnvironment.cs
File metadata and controls
145 lines (134 loc) · 5.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System.Globalization;
using System.Runtime.InteropServices;
using OpenClaw.Launcher.Mxc;
namespace OpenClaw.Launcher;
/// <summary>
/// The Windows build and the version of every component in this
/// installation's execution chain.
/// </summary>
/// <remarks>
/// Recorded when the host starts and in each diagnostics bundle, so a report
/// names the build and dependency chain that produced it without the reporter
/// collecting them by hand. Every fact is best-effort: one that cannot be read
/// is described as unavailable instead of failing the command being diagnosed.
/// Reading them costs no process launch, which is why the MXC backend probe is
/// recorded where it already runs rather than here.
/// </remarks>
internal sealed record HostEnvironment(
string Windows,
string Package,
string Mxc,
string NodeJs,
string DotNet)
{
public static HostEnvironment Read(
string baseDirectory,
string? nodeArchivePath) =>
new(
DescribeWindows(
Environment.OSVersion.Version,
WindowsHostBuild.TryRead(),
RuntimeInformation.OSArchitecture,
RuntimeInformation.ProcessArchitecture),
DescribeInstalledPackage(),
DescribeMxc(baseDirectory),
DescribeNodeJs(nodeArchivePath, RuntimeInformation.ProcessArchitecture),
RuntimeInformation.FrameworkDescription);
public string Describe() =>
$"Windows {Windows}; package {Package}, build " +
$"{ClawCtlBuildMetadata.PackageVersion} (commit {ClawCtlBuildMetadata.PackageCommit}); " +
$"OpenClaw payload {ClawCtlBuildMetadata.PayloadVersion} " +
$"(commit {ClawCtlBuildMetadata.PayloadCommit}); MXC {Mxc}; Node.js {NodeJs}; {DotNet}";
internal static string DescribeWindows(
Version osVersion,
MxcHostBuild? hostBuild,
Architecture osArchitecture,
Architecture processArchitecture)
{
string version = hostBuild is null
? string.Create(
CultureInfo.InvariantCulture,
$"{osVersion.Major}.{osVersion.Minor}.{osVersion.Build} (update revision unavailable)")
: string.Create(
CultureInfo.InvariantCulture,
$"{osVersion.Major}.{osVersion.Minor}.{hostBuild.Build}.{hostBuild.UpdateBuildRevision}");
// They differ under emulation, and the process architecture is the one
// that selects the staged MXC runtime and Node.js archive.
return $"{version} ({osArchitecture} OS, {processArchitecture} process)";
}
internal static string DescribeMxc(string baseDirectory)
{
MxcRuntimeLocation location = MxcRuntimeLocator.Locate(baseDirectory);
string runtime = location.Provenance is { } provenance
? $"{provenance.Package} {provenance.Version} {provenance.Architecture}"
: "runtime of unknown provenance";
return $"{runtime}, SDK {ClawCtlBuildMetadata.MxcSdkPackageVersion}, " +
$"contract {Microsoft.Mxc.Sdk.V1.MxcLifecycle.SdkContractVersion}";
}
internal static string DescribeNodeJs(string? archivePath, Architecture architecture)
{
if (archivePath is null)
{
return "archive missing";
}
try
{
return NodeRuntimeInstaller.GetArchiveVersion(archivePath, architecture).ToString();
}
catch (Exception exception) when (
exception is InvalidDataException or PlatformNotSupportedException)
{
return $"archive {Path.GetFileName(archivePath)} unrecognized";
}
}
/// <summary>
/// Names how the package was installed: a loose layout registered in
/// Developer Mode, a Store-signed install, or a sideloaded MSIX and the
/// kind of signature Windows accepted it with.
/// </summary>
internal static string DescribePackage(PackageProvenance? provenance)
{
if (provenance is null)
{
return "unpackaged";
}
// Development mode is checked first: a loose registration is unsigned
// whatever the certificate its checkout would sign with.
string kind = provenance.DevelopmentMode == true
? "Developer Mode loose-layout registration"
: provenance.Origin switch
{
PackageOrigin.Store => "Store-signed",
PackageOrigin.DeveloperSigned => "developer-signed MSIX",
PackageOrigin.LineOfBusiness => "line-of-business MSIX",
PackageOrigin.Unsigned => "unsigned MSIX",
PackageOrigin.DeveloperUnsigned => "unsigned developer registration",
PackageOrigin.Inbox => "inbox package",
null => "origin unreadable",
_ => "unknown origin"
};
string origin = provenance.Origin is { } value ? $", origin {value}" : string.Empty;
string developmentMode = provenance.DevelopmentMode is null
? ", development mode unreadable"
: string.Empty;
string location = provenance.InstallPath is { } path
? $" at {path}"
: " at an unreadable location";
return $"{provenance.FullName} ({kind}{origin}{developmentMode}){location}";
}
private static string DescribeInstalledPackage()
{
try
{
return DescribePackage(PackageIdentity.TryReadProvenance());
}
catch (Exception exception) when (
exception is InvalidOperationException or
EntryPointNotFoundException or
DllNotFoundException)
{
// A diagnostic read must never fail the command it describes.
return $"identity unreadable ({exception.Message})";
}
}
}