@rivus/gateway 0.21.0 → 0.21.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.
@@ -2250,7 +2250,7 @@ function parseLockOwner(value) {
2250
2250
  //#endregion
2251
2251
  //#region src/platform/project/setup/release-descriptor.ts
2252
2252
  const RIVUS_RELEASE_DESCRIPTOR = Object.freeze({
2253
- version: "0.21.0",
2253
+ version: "0.21.1",
2254
2254
  dependencies: Object.freeze({
2255
2255
  "@earendil-works/pi-coding-agent": "0.84.4",
2256
2256
  "@larksuiteoapi/node-sdk": "1.74.0",
@@ -4099,6 +4099,7 @@ function createLaunchdServiceManager(context) {
4099
4099
  ];
4100
4100
  const pendingStates = [
4101
4101
  "running",
4102
+ "xpcproxy",
4102
4103
  "spawn scheduled",
4103
4104
  "spawning",
4104
4105
  "throttled"
@@ -4257,7 +4258,7 @@ function createSystemdServiceManager(context) {
4257
4258
  bus,
4258
4259
  managerPath,
4259
4260
  `${bus}.Manager`,
4260
- "GetUnit",
4261
+ "LoadUnit",
4261
4262
  "s",
4262
4263
  id
4263
4264
  ], unitPathSchema);
@@ -5140,19 +5141,33 @@ finally { image.free(); }
5140
5141
  `;
5141
5142
  //#endregion
5142
5143
  //#region src/adapters/deployment/upgrade/home-backup.ts
5144
+ const isMissingFile = Schema.is(Schema.Struct({ code: Schema.Literal("ENOENT") }));
5143
5145
  async function backUpUpgradeHome(input) {
5144
5146
  await mkdir(input.directory, {
5145
5147
  recursive: true,
5146
5148
  mode: 448
5147
5149
  });
5148
- const archive = join(input.directory, "home.tar");
5149
- const temporary = `${archive}.partial`;
5150
+ const archive = {
5151
+ path: join(input.directory, "home.tar.gz"),
5152
+ format: "gzip"
5153
+ };
5154
+ const temporary = {
5155
+ ...archive,
5156
+ path: `${archive.path}.partial`
5157
+ };
5150
5158
  try {
5151
- if ((await input.run({
5159
+ await rm(join(input.directory, "home.tar.partial"), { force: true });
5160
+ const existing = await retainedArchive(input.directory);
5161
+ if (existing) {
5162
+ await verifyArchive(existing, input);
5163
+ return existing.path;
5164
+ }
5165
+ const created = await input.run({
5152
5166
  command: "/usr/bin/tar",
5153
5167
  args: [
5168
+ "--use-compress-program=/usr/bin/gzip -1",
5154
5169
  "-cpf",
5155
- temporary,
5170
+ temporary.path,
5156
5171
  "--exclude=./.rivus-upgrade",
5157
5172
  "-C",
5158
5173
  input.home,
@@ -5163,29 +5178,74 @@ async function backUpUpgradeHome(input) {
5163
5178
  timeoutMs: 18e5,
5164
5179
  ...input.signal ? { signal: input.signal } : {},
5165
5180
  discardStdout: true
5166
- })).exitCode !== 0) throw new Error("Home backup failed; the service remains stopped and the previous release is retained");
5167
- await chmod(temporary, 384);
5168
- await verifyArchive(temporary, input);
5169
- await rename(temporary, archive);
5170
- return archive;
5181
+ });
5182
+ if (created.exitCode !== 0) {
5183
+ await rm(temporary.path, { force: true });
5184
+ await throwArchiveFailure("create", archive.path, created);
5185
+ }
5186
+ await chmod(temporary.path, 384);
5187
+ await verifyArchive(temporary, input, true);
5188
+ await rename(temporary.path, archive.path);
5189
+ return archive.path;
5171
5190
  } finally {
5172
- await rm(temporary, { force: true });
5191
+ await rm(temporary.path, { force: true });
5173
5192
  }
5174
5193
  }
5175
5194
  async function verifyUpgradeBackup(input) {
5176
- await verifyArchive(join(input.directory, "home.tar"), input);
5195
+ const archive = await retainedArchive(input.directory);
5196
+ if (!archive) throw new Error("Home backup is missing");
5197
+ await verifyArchive(archive, input);
5198
+ }
5199
+ async function retainedArchive(directory) {
5200
+ const archives = [];
5201
+ for (const [name, format] of [["home.tar.gz", "gzip"], ["home.tar", "tar"]]) {
5202
+ const path = join(directory, name);
5203
+ if (await lstat(path).catch((error) => {
5204
+ if (!isMissingFile(error)) throw error;
5205
+ })) archives.push({
5206
+ path,
5207
+ format
5208
+ });
5209
+ }
5210
+ if (archives.length > 1) throw new Error("Both home.tar and home.tar.gz exist; preserve both backups and resolve the ambiguity before resuming");
5211
+ return archives[0];
5177
5212
  }
5178
- async function verifyArchive(path, input) {
5179
- const metadata = await stat(path);
5180
- if (!metadata.isFile() || metadata.size === 0) throw new Error("Home backup is missing or empty");
5181
- if ((await input.run({
5213
+ async function verifyArchive(archive, input, removeFailedPartial = false) {
5214
+ const metadata = await lstat(archive.path);
5215
+ if (!metadata.isFile() || metadata.size === 0) throw new Error("Home backup is missing, empty or not a regular file");
5216
+ const listed = await input.run({
5182
5217
  command: "/usr/bin/tar",
5183
- args: ["-tf", path],
5218
+ args: [
5219
+ ...archive.format === "gzip" ? ["--use-compress-program=/usr/bin/gzip -d"] : [],
5220
+ "-tf",
5221
+ archive.path
5222
+ ],
5184
5223
  cwd: input.home,
5185
5224
  env: input.env,
5186
5225
  timeoutMs: 18e5,
5187
5226
  discardStdout: true
5188
- })).exitCode !== 0) throw new Error("Home backup could not be read; refusing to switch the service");
5227
+ });
5228
+ if (listed.exitCode !== 0) {
5229
+ if (removeFailedPartial) await rm(archive.path, { force: true });
5230
+ await throwArchiveFailure("verify", archive.path, listed);
5231
+ }
5232
+ }
5233
+ async function throwArchiveFailure(phase, archive, result) {
5234
+ const diagnostics = join(dirname(archive), `tar-${phase}-failure-${randomUUID()}.json`);
5235
+ const summary = phase === "create" ? "Home backup failed; the service remains stopped and the previous release is retained" : "Home backup could not be read; refusing to switch the service";
5236
+ try {
5237
+ await writeAtomicTextFile(diagnostics, `${JSON.stringify({
5238
+ archive,
5239
+ exitCode: result.exitCode,
5240
+ stderr: result.stderr
5241
+ }, null, 2)}\n`, {
5242
+ mode: 384,
5243
+ durable: true
5244
+ });
5245
+ } catch {
5246
+ throw new Error(`${summary} (tar exit ${result.exitCode}); private diagnostics could not be saved to ${diagnostics}`);
5247
+ }
5248
+ throw new Error(`${summary} (tar exit ${result.exitCode}); private diagnostics: ${diagnostics}`);
5189
5249
  }
5190
5250
  //#endregion
5191
5251
  //#region src/bootstrap/upgrade/upgrade-home.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivus/gateway",
3
- "version": "0.21.0",
3
+ "version": "0.21.1",
4
4
  "description": "Message gateway, channels, host binding, automation, and daemon assembly for Rivus.",
5
5
  "type": "module",
6
6
  "license": "GPL-3.0-only",
@@ -57,8 +57,8 @@
57
57
  "@agentclientprotocol/sdk": "1.5.1",
58
58
  "@larksuiteoapi/node-sdk": "1.74.0",
59
59
  "@resvg/resvg-js": "2.6.2",
60
- "@rivus/platform": "0.21.0",
61
- "@rivus/runtime": "0.21.0",
60
+ "@rivus/platform": "0.21.1",
61
+ "@rivus/runtime": "0.21.1",
62
62
  "axios": "1.20.0",
63
63
  "effect": "^4.0.0",
64
64
  "get-east-asian-width": "1.6.0",