@synopackageland/cli 0.48.13 → 0.48.14

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/CHANGELOG.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## 0.48.14
4
4
 
5
+ - status, install, uninstall and deploy no longer request the unsupported installing_target package-list field, so DSM versions that reject it work again
6
+ - --json prints one final object on stdout; progress goes to stderr once per change
7
+ - Closing the output pipe no longer abandons stop and uninstall; an interrupted uninstall resumes or reports the package as removed
5
8
  - Reject daemon.nofile in check, build and inspect until package-safe activation is supported
6
9
  - Stop daemons through the non-root SDK controller during migration and teardown; continue executor cleanup after a daemon stop failure
7
10
 
package/README.md CHANGED
@@ -502,7 +502,7 @@ variables also work in `.env`; timeout/interval values accept integer seconds fr
502
502
  | `DSM_OPERATION_TIMEOUT_SECONDS` | 600 | One SPK upload, install/upgrade compound, or package start/stop request |
503
503
  | `DSM_INSTALL_MAX_POLLS` | 10000 | Per-package polling attempts across initial checks, pre-pull and install/start verification |
504
504
  | `DSM_UNINSTALL_TIMEOUT_SECONDS` | 1800 | State check, stop and uninstall together |
505
- | `DSM_POLL_INTERVAL_SECONDS` | 5 | Package-state polling and progress interval |
505
+ | `DSM_POLL_INTERVAL_SECONDS` | 5 | Package-state polling interval |
506
506
  | `DSM_IMAGE_PULL_STALL_TIMEOUT_SECONDS` | 1200 | No increase in NAS pull bytes; status heartbeats do not reset this budget |
507
507
 
508
508
  Install/upgrade waiting has no default elapsed-time deadline. Slow successful work
@@ -519,6 +519,11 @@ pinned image. Pinning alone does not download layers onto the NAS. Pull tasks
519
519
  are not cancelled or replayed when their response is lost or a budget expires.
520
520
  Broken packages skip stop during uninstall; their existing install error does not
521
521
  block removal, while new uninstall errors still fail clearly.
522
+ Uninstall resumes a stopped or stopping package, waits for an existing uninstall,
523
+ and succeeds when DSM already verifies the package is absent.
524
+ Polling progress goes to stderr only when it changes, in both text and JSON modes.
525
+ `--json` stdout contains one final JSON object. A closed stdout or stderr pipe does
526
+ not interrupt DSM writes; the command finishes and reports its result through its exit code.
522
527
 
523
528
  `logs --json` emits the usual single JSON envelope, including DSM `worker_msg`,
524
529
  status details and the last reported Compose error. A locally retained pre-pull
@@ -528,6 +533,7 @@ unknown; a generic `install_corruption` does not prove a registry failure.
528
533
 
529
534
  `status <package-id> --json` reports `state: "upgrading"`, `"installing"` or
530
535
  `"starting"` during replacement/startup, with `fromVersion`/`toVersion` when known.
536
+ Stopping/removal reports `state: "stopping"` or `"uninstalling"` until DSM verifies completion.
531
537
  It never reports `installed:false` for those transitions: an upgrade retains
532
538
  `installed:true`; a fresh install without a verified payload uses `installed:null`.
533
539
  `status` carries the effective DSM/CLI status. The result contract is
package/dist/cli.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { nasFlags, withNasOptions } from './nas/options.js';
2
+ import { installOutputGuards } from './terminal-output.js';
2
3
  import { upstreamRepository, upstreamMaintainer } from './upstream-attribution.js';
3
4
  import { Command, CommanderError } from "commander";
4
5
  import { CLI_VERSION } from "./cli-version.js";
@@ -298,6 +299,7 @@ async function containerBuild(project, arches, options) {
298
299
  }
299
300
  /** Resolves after dispatch; commands may set process.exitCode. Rejections are failures. */
300
301
  export async function runCli(argv) {
302
+ installOutputGuards();
301
303
  if (argv[2] === 'ctl' && argv[3] === 'external') {
302
304
  const { runCtl } = await import('./ctl/cli.js');
303
305
  return runCtl(argv.slice(3));
@@ -13,7 +13,7 @@ interface CatalogPackageEntry {
13
13
  export interface InstalledPackageState {
14
14
  /** null means DSM cannot currently verify an installed payload. */
15
15
  installed: boolean | null;
16
- state?: 'installing' | 'upgrading' | 'starting' | 'unknown';
16
+ state?: 'installing' | 'upgrading' | 'starting' | 'stopping' | 'uninstalling' | 'unknown';
17
17
  fromVersion?: string;
18
18
  toVersion?: string;
19
19
  version?: string;
@@ -1,6 +1,6 @@
1
1
  import { CtlError } from '../ctl/errors.js';
2
2
  import { readFileSync } from "node:fs";
3
- import { terminalSafe } from '../terminal-text.js';
3
+ import { progressReporter } from '../terminal-output.js';
4
4
  import { pullContainerImages } from './container-pull.js';
5
5
  import { savePullFailure } from './package-diagnostics.js';
6
6
  import { readPackageOperation, operationOwnerAlive, savePackageOperation, clearPackageOperation, releasePackageOperation } from './package-operation.js';
@@ -83,7 +83,8 @@ export function packageStateFromRecord(value) {
83
83
  installed: Boolean(installedPath) || match.installed === true,
84
84
  };
85
85
  const transition = status?.toLowerCase();
86
- if (transition === 'installing' || transition === 'upgrading' || transition === 'starting') {
86
+ if (transition === 'installing' || transition === 'upgrading' || transition === 'starting' ||
87
+ transition === 'stopping' || transition === 'uninstalling') {
87
88
  state.state = transition;
88
89
  // DSM can remove installed_info while replacing the payload.
89
90
  state.installed = state.installed || transition === 'upgrading' ? true : null;
@@ -133,7 +134,10 @@ export async function fetchInstalledPackageState(dsmOrigin, cookieHeader, packag
133
134
  api: "SYNO.Core.Package",
134
135
  version: "2",
135
136
  method: "list",
136
- additional: JSON.stringify(["status", "installed_info", "installing_target"]),
137
+ // installing_target is not a supported additional field on some DSM 7.x
138
+ // versions (error 120). Transitions come from status/list_status and the
139
+ // retained installation task; only report a target version with evidence.
140
+ additional: JSON.stringify(["status", "installed_info"]),
137
141
  ignore_hidden: "false",
138
142
  }, { timeoutMs, signal: context.signal });
139
143
  if (!Array.isArray(record(body.data).packages))
@@ -213,17 +217,19 @@ export async function waitForInstalledVersion(readState, options) {
213
217
  const deadline = options.deadlineMs === undefined ? Infinity : Date.now() + options.deadlineMs;
214
218
  const consumePoll = options.consumePoll ?? installWorkload(options.packageId, options.maxPolls);
215
219
  const pollMs = options.pollMs ?? dsmPollIntervalMs();
220
+ const progress = progressReporter(options.onProgress);
216
221
  let transitioned = !options.requireTransition;
217
222
  while (Date.now() < deadline) {
218
223
  consumePoll();
219
224
  let state;
225
+ let timedOut = false;
220
226
  try {
221
227
  state = await cancelableInstall(() => Promise.resolve(readState(Math.min(dsmRequestTimeoutMs(), Math.max(1, deadline - Date.now())))), options.signal);
222
228
  }
223
229
  catch (error) {
224
230
  if (!isHostTimeout(error))
225
231
  throw error;
226
- options.onProgress?.(`${options.packageId}: status request timed out; still installing/starting…`);
232
+ timedOut = true;
227
233
  }
228
234
  if (state && !installInProgress(state) && packageFailure(state)) {
229
235
  throw new CtlError('DSM_INSTALL_FAILED', `DSM reports package ${options.packageId} install did not complete (Package Center status ${state.status ?? 'unknown'}): ${failureDetail(state)}`.trim(), 'Check the DSM Package Center install/start log');
@@ -238,7 +244,8 @@ export async function waitForInstalledVersion(readState, options) {
238
244
  (!options.expectedVersion || state.version === options.expectedVersion) &&
239
245
  (!options.requireRunning || running) && transitioned)
240
246
  return state;
241
- options.onProgress?.(`${options.packageId}: installing/starting… (DSM status ${state?.status ?? 'unavailable'})`);
247
+ progress(timedOut ? `${options.packageId}: status request timed out; still installing/starting…` :
248
+ `${options.packageId}: installing/starting… (DSM status ${state?.status ?? 'unavailable'})`);
242
249
  await installDelay(Math.min(pollMs, Math.max(0, deadline - Date.now())), options.signal);
243
250
  }
244
251
  throw installBudgetExpired(options);
@@ -259,7 +266,7 @@ export async function uninstallPackageFromDsm(options) {
259
266
  const deadline = Date.now() + (options.deadlineMs ?? dsmUninstallTimeoutMs());
260
267
  const requestMs = dsmRequestTimeoutMs(), operationMs = dsmOperationTimeoutMs();
261
268
  const pollMs = options.pollMs ?? dsmPollIntervalMs();
262
- const progress = options.onProgress ?? (message => process.stderr.write(`${terminalSafe(message)}\n`));
269
+ const progress = progressReporter(options.onProgress);
263
270
  let phase = 'checking package state';
264
271
  let previousFailure;
265
272
  const expired = () => new CtlError('DSM_UNINSTALL_TIMEOUT', `Package ${options.packageId}: overall uninstall budget exhausted while ${phase}; DSM may still be stopping/uninstalling.`, 'Check Package Center before retrying; stop/uninstall requests were not replayed');
@@ -268,19 +275,19 @@ export async function uninstallPackageFromDsm(options) {
268
275
  throw expired();
269
276
  return Math.min(limit, deadline - Date.now());
270
277
  };
271
- const heartbeat = setInterval(() => progress(`${options.packageId}: ${phase}…`), pollMs);
272
278
  try {
273
279
  const sid = extractSid(options.cookieHeader);
274
280
  const wait = async (done) => {
275
281
  while (Date.now() < deadline) {
276
282
  let state;
283
+ let timedOut = false;
277
284
  try {
278
285
  state = await fetchInstalledPackageState(options.dsmOrigin, options.cookieHeader, options.packageId, remaining(requestMs));
279
286
  }
280
287
  catch (error) {
281
288
  if (!isHostTimeout(error))
282
289
  throw error;
283
- progress(`${options.packageId}: status request timed out; ${phase}…`);
290
+ timedOut = true;
284
291
  }
285
292
  if (state && Date.now() < deadline) {
286
293
  if (done(state))
@@ -288,7 +295,8 @@ export async function uninstallPackageFromDsm(options) {
288
295
  if (packageFailure(state) && !(phase === 'uninstalling' && previousFailure === failureDetail(state)))
289
296
  throw new CtlError('DSM_UNINSTALL_FAILED', `DSM reports ${options.packageId} failed while ${phase}: ${failureDetail(state) || state.status}`, 'Check the DSM Package Center stop/uninstall log');
290
297
  }
291
- progress(`${options.packageId}: ${phase}… (DSM status ${state?.status ?? 'unavailable'})`);
298
+ progress(timedOut ? `${options.packageId}: status request timed out; ${phase}…` :
299
+ `${options.packageId}: ${phase}…${state?.status === phase ? '' : ` (DSM status ${state?.status ?? 'unavailable'})`}`);
292
300
  await new Promise(resolve => setTimeout(resolve, Math.min(pollMs, Math.max(0, deadline - Date.now()))));
293
301
  }
294
302
  throw expired();
@@ -307,7 +315,18 @@ export async function uninstallPackageFromDsm(options) {
307
315
  progress(`${options.packageId}: ${method} request timed out; checking DSM state without replay…`);
308
316
  }
309
317
  };
310
- const before = await wait(() => true);
318
+ let before = await wait(() => true);
319
+ if (before.state === 'uninstalling') {
320
+ phase = 'uninstalling';
321
+ progress(`${options.packageId}: ${phase}…`);
322
+ await wait(state => state.installed === false);
323
+ return;
324
+ }
325
+ if (before.state === 'stopping') {
326
+ phase = 'stopping';
327
+ progress(`${options.packageId}: ${phase}…`);
328
+ before = await wait(state => state.installed === false || packageStatusIsStopped(state));
329
+ }
311
330
  if (before.state || before.installed === null)
312
331
  throw new CtlError('PACKAGE_BUSY', `Package ${options.packageId} has an unresolved operation`, 'Wait for DSM to finish before uninstalling');
313
332
  if (before.installed === false)
@@ -331,9 +350,6 @@ export async function uninstallPackageFromDsm(options) {
331
350
  catch (error) {
332
351
  throw uninstallFailure(options.packageId, error);
333
352
  }
334
- finally {
335
- clearInterval(heartbeat);
336
- }
337
353
  }
338
354
  export function catalogInstallationRequests(entry, installed, sid, volumePath) {
339
355
  const install = {
@@ -446,7 +462,7 @@ export async function installPackageFromLocalSpk(options) {
446
462
  let verified = false;
447
463
  const requestMs = dsmRequestTimeoutMs(), operationMs = dsmOperationTimeoutMs();
448
464
  const pollMs = options.pollMs ?? dsmPollIntervalMs();
449
- const progress = options.onProgress ?? (message => process.stderr.write(`${terminalSafe(message)}\n`));
465
+ const progress = progressReporter(options.onProgress);
450
466
  let phase = 'checking package state';
451
467
  const remaining = (limit) => {
452
468
  if (signal.aborted)
@@ -455,7 +471,6 @@ export async function installPackageFromLocalSpk(options) {
455
471
  throw installBudgetExpired(options);
456
472
  return Math.min(limit, deadline - Date.now());
457
473
  };
458
- const heartbeat = setInterval(() => progress(`${options.packageId}: ${phase}…`), pollMs);
459
474
  process.once('SIGINT', cancel);
460
475
  process.once('SIGTERM', cancel);
461
476
  try {
@@ -531,7 +546,6 @@ export async function installPackageFromLocalSpk(options) {
531
546
  throw error;
532
547
  }
533
548
  finally {
534
- clearInterval(heartbeat);
535
549
  process.removeListener('SIGINT', cancel);
536
550
  process.removeListener('SIGTERM', cancel);
537
551
  if (operation) {
@@ -1,7 +1,7 @@
1
1
  import { CtlError } from '../ctl/errors.js';
2
2
  import { parseImageReference } from '../images/pin.js';
3
3
  import { registryBaseUrl } from '../compose/registry-mirrors.js';
4
- import { terminalSafe } from '../terminal-text.js';
4
+ import { progressReporter } from '../terminal-output.js';
5
5
  import { maskDiagnostic } from './package-diagnostics.js';
6
6
  import { installWorkload, installCanceled, installDelay } from './install-control.js';
7
7
  import { dsmFetch } from './dsm-http.js';
@@ -23,7 +23,7 @@ export async function pullContainerImages(options) {
23
23
  const consumePoll = options.consumePoll ?? installWorkload('container image pull');
24
24
  const stallMs = options.stallMs ?? dsmPullStallTimeoutMs();
25
25
  const pollMs = options.pollMs ?? dsmPollIntervalMs();
26
- const progress = options.onProgress ?? (line => process.stderr.write(`${terminalSafe(line)}\n`));
26
+ const progress = progressReporter(options.onProgress);
27
27
  for (const image of new Set(options.images)) {
28
28
  const parsed = parseImageReference(image);
29
29
  if (!parsed)
@@ -56,8 +56,6 @@ export async function pullContainerImages(options) {
56
56
  return body.data;
57
57
  };
58
58
  progress(`${context}: starting NAS image pull…`);
59
- // Even while a NAS request is pending, keep stderr alive.
60
- const heartbeat = setInterval(() => progress(`${context}: pulling… (${Math.max(0, downloaded)} bytes)`), pollMs);
61
59
  try {
62
60
  if (parsed.digest) {
63
61
  const inventory = await call('list', { offset: '0', limit: '-1' });
@@ -119,8 +117,5 @@ export async function pullContainerImages(options) {
119
117
  throw error;
120
118
  throw fail('CONTAINER_PULL_FAILED', `NAS image pull failed: ${error instanceof Error ? error.message : 'unknown transport error'}`);
121
119
  }
122
- finally {
123
- clearInterval(heartbeat);
124
- }
125
120
  }
126
121
  }
@@ -58,21 +58,20 @@ export declare function uninstallPackage(id: string, options?: {
58
58
  yes?: boolean;
59
59
  dryRun?: boolean;
60
60
  }): Promise<{
61
- dryRun: boolean;
61
+ dryRun?: boolean | undefined;
62
62
  host: string;
63
63
  package: string;
64
- action: string;
65
- installed?: undefined;
64
+ installed: boolean;
65
+ action?: undefined;
66
66
  } | {
67
+ dryRun: boolean;
67
68
  host: string;
68
69
  package: string;
69
- installed: boolean;
70
- dryRun?: undefined;
71
- action?: undefined;
70
+ action: string;
72
71
  }>;
73
72
  export declare function packageStatus(id: string, host?: string): Promise<{
74
73
  installed: boolean | null;
75
- state?: "installing" | "upgrading" | "starting" | "unknown";
74
+ state?: "installing" | "upgrading" | "starting" | "stopping" | "uninstalling" | "unknown";
76
75
  fromVersion?: string;
77
76
  toVersion?: string;
78
77
  version?: string;
@@ -201,10 +201,13 @@ export async function uninstallPackage(id, options = {}) {
201
201
  packageId(id);
202
202
  const nas = await connectNas(options.host);
203
203
  const state = await fetchInstalledPackageState(nas.session.origin, nas.session.cookie, id);
204
- if (state?.state || state?.installed === null)
204
+ if (!state)
205
+ throw fail('PACKAGE_STATUS_UNKNOWN', 'DSM did not return a verifiable package state');
206
+ if (state.installed === false && !state.state)
207
+ return { host: nas.name, package: id, installed: false, ...(options.dryRun ? { dryRun: true } : {}) };
208
+ const resuming = state.state === 'stopping' || state.state === 'uninstalling';
209
+ if (!resuming && (state.state || state.installed === null))
205
210
  throw fail('PACKAGE_BUSY', `Package ${id} has an unresolved operation`);
206
- if (!state?.installed)
207
- throw fail("PACKAGE_NOT_INSTALLED", `Package ${id} is not installed`);
208
211
  if (options.dryRun)
209
212
  return { dryRun: true, host: nas.name, package: id, action: "uninstall" };
210
213
  await requireAdministrator(nas);
@@ -0,0 +1,4 @@
1
+ /** A disconnected output consumer must not abandon a dispatched DSM mutation. */
2
+ export declare function installOutputGuards(): void;
3
+ /** Report changes, keeping machine-readable command results on stdout. */
4
+ export declare function progressReporter(output?: (message: string) => void): (message: string) => void;
@@ -0,0 +1,36 @@
1
+ import { terminalSafe } from './terminal-text.js';
2
+ const guarded = new WeakSet();
3
+ let signalGuarded = false;
4
+ const brokenPipe = (error) => error?.code === 'EPIPE';
5
+ /** A disconnected output consumer must not abandon a dispatched DSM mutation. */
6
+ export function installOutputGuards() {
7
+ for (const stream of [process.stdout, process.stderr]) {
8
+ if (guarded.has(stream))
9
+ continue;
10
+ guarded.add(stream);
11
+ stream.on('error', error => { if (!brokenPipe(error))
12
+ throw error; });
13
+ }
14
+ if (!signalGuarded) {
15
+ signalGuarded = true;
16
+ process.on('SIGPIPE', () => { });
17
+ }
18
+ }
19
+ /** Report changes, keeping machine-readable command results on stdout. */
20
+ export function progressReporter(output = message => {
21
+ process.stderr.write(`${terminalSafe(message)}\n`);
22
+ }) {
23
+ let previous;
24
+ return message => {
25
+ if (message === previous)
26
+ return;
27
+ previous = message;
28
+ try {
29
+ output(message);
30
+ }
31
+ catch (error) {
32
+ if (!brokenPipe(error))
33
+ throw error;
34
+ }
35
+ };
36
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synopackageland/cli",
3
- "version": "0.48.13",
3
+ "version": "0.48.14",
4
4
  "description": "Syno Package Land Developer Kit CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -19,6 +19,8 @@
19
19
  "installing",
20
20
  "upgrading",
21
21
  "starting",
22
+ "stopping",
23
+ "uninstalling",
22
24
  "unknown"
23
25
  ]
24
26
  },
@@ -65,7 +67,9 @@
65
67
  "enum": [
66
68
  "installing",
67
69
  "upgrading",
68
- "starting"
70
+ "starting",
71
+ "stopping",
72
+ "uninstalling"
69
73
  ]
70
74
  }
71
75
  }