@synopackageland/cli 0.49.1 → 0.50.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.
Files changed (96) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +10 -0
  3. package/dist/build-spk/generator.js +3 -3
  4. package/dist/build-spk/reproducible-archive.js +3 -1
  5. package/dist/ctl/ai-tools.d.ts +11 -1
  6. package/dist/ctl/ai-tools.js +4 -4
  7. package/dist/ctl/cli.d.ts +8 -1
  8. package/dist/ctl/cli.js +54 -5
  9. package/dist/ctl/descriptor.d.ts +15 -2
  10. package/dist/ctl/descriptor.js +9 -4
  11. package/dist/ctl/diagnostics.d.ts +16 -0
  12. package/dist/ctl/diagnostics.js +11 -0
  13. package/dist/ctl/flows.js +2 -0
  14. package/dist/ctl/input.d.ts +5 -3
  15. package/dist/ctl/input.js +3 -3
  16. package/dist/ctl/native-auth-command.d.ts +9 -0
  17. package/dist/ctl/native-auth-command.js +103 -0
  18. package/dist/ctl/native-executor.d.ts +16 -0
  19. package/dist/ctl/native-executor.js +187 -0
  20. package/dist/ctl/native-file-types.d.ts +16 -0
  21. package/dist/ctl/native-file-types.js +57 -0
  22. package/dist/ctl/native-files.d.ts +13 -0
  23. package/dist/ctl/native-files.js +115 -0
  24. package/dist/ctl/native-metadata.d.ts +10 -0
  25. package/dist/ctl/native-metadata.js +50 -0
  26. package/dist/ctl/native-paths.d.ts +4 -0
  27. package/dist/ctl/native-paths.js +65 -0
  28. package/dist/ctl/native-protocol.d.ts +21 -0
  29. package/dist/ctl/native-protocol.js +150 -0
  30. package/dist/ctl/native-registry.d.ts +8 -0
  31. package/dist/ctl/native-registry.js +182 -0
  32. package/dist/ctl/native-schemas.d.ts +7 -0
  33. package/dist/ctl/native-schemas.js +25 -0
  34. package/dist/ctl/native-store.d.ts +67 -0
  35. package/dist/ctl/native-store.js +342 -0
  36. package/dist/ctl/native-transfers.d.ts +13 -0
  37. package/dist/ctl/native-transfers.js +331 -0
  38. package/dist/ctl/native-transport.d.ts +30 -0
  39. package/dist/ctl/native-transport.js +148 -0
  40. package/dist/ctl/native-types.d.ts +15 -0
  41. package/dist/ctl/native-types.js +1 -0
  42. package/dist/ctl/registry.d.ts +5 -4
  43. package/dist/ctl/registry.js +12 -1
  44. package/dist/ctl/service.d.ts +34 -1
  45. package/dist/ctl/service.js +122 -1
  46. package/dist/ctl/windows-acl.d.ts +39 -0
  47. package/dist/ctl/windows-acl.js +80 -0
  48. package/dist/ctl/windows-prompt.d.ts +5 -0
  49. package/dist/ctl/windows-prompt.js +119 -0
  50. package/dist/ctl/windows-sddl.d.ts +20 -0
  51. package/dist/ctl/windows-sddl.js +162 -0
  52. package/dist/ctl/windows-security-helper.d.ts +7 -0
  53. package/dist/ctl/windows-security-helper.js +88 -0
  54. package/dist/ctl/windows-security.d.ts +10 -0
  55. package/dist/ctl/windows-security.js +95 -0
  56. package/dist/ctl/windows-tools.d.ts +11 -0
  57. package/dist/ctl/windows-tools.js +23 -0
  58. package/dist/error-registry.js +15 -0
  59. package/dist/generated/native-http.d.ts +189 -0
  60. package/dist/generated/native-http.js +1 -0
  61. package/dist/nas/store.d.ts +3 -1
  62. package/dist/nas/store.js +6 -3
  63. package/dist/nas/transport.d.ts +1 -0
  64. package/dist/native-http-schema/descriptor.schema.json +242 -0
  65. package/dist/native-http-schema/inventory.schema.json +121 -0
  66. package/dist/native-http-schema/registry.schema.json +872 -0
  67. package/dist/native-http-schema/source.json +1 -0
  68. package/dist/runtime/sdk-source.d.ts +1 -1
  69. package/dist/runtime/sdk-source.js +1 -1
  70. package/dist/spk/extract.d.ts +6 -0
  71. package/dist/spk/extract.js +39 -0
  72. package/dist/standalone/api-description.d.ts +2 -5
  73. package/dist/standalone/build.js +5 -1
  74. package/dist/standalone/compose-errors.js +5 -0
  75. package/dist/standalone/daemon.js +1 -0
  76. package/dist/standalone/inspect-spk.js +23 -37
  77. package/dist/standalone/install-ports.js +2 -1
  78. package/dist/standalone/lifecycle.js +9 -2
  79. package/dist/standalone/manifest.d.ts +1 -0
  80. package/dist/standalone/manifest.js +22 -5
  81. package/dist/standalone/native-http-inspect.d.ts +9 -0
  82. package/dist/standalone/native-http-inspect.js +43 -0
  83. package/dist/standalone/native-http.d.ts +31 -0
  84. package/dist/standalone/native-http.js +120 -0
  85. package/dist/standalone/native-layout.js +2 -0
  86. package/dist/standalone/operation-registry.d.ts +2 -7
  87. package/dist/standalone/operation-registry.js +3 -0
  88. package/dist/standalone/spk.d.ts +1 -0
  89. package/dist/standalone/spk.js +15 -1
  90. package/package.json +3 -2
  91. package/schema/dsm-api-contract.json +8 -7
  92. package/skills/SKILL.md +2 -2
  93. package/skills/reference/compose.md +21 -0
  94. package/skills/reference/ctl.md +229 -0
  95. package/skills/reference/daemon-mode.md +1 -1
  96. package/skills/reference/upstream-fork.md +5 -2
@@ -0,0 +1 @@
1
+ {"module":"github.com/synopackageland/syno-pkg-land-sdk","version":"0.52.0","local":false}
@@ -1,7 +1,7 @@
1
1
  export { goPrivateCovers } from './go-env.js';
2
2
  import { type ExecutorManifest } from './sdk-executor-manifest.js';
3
3
  /** Pinned SDK for CLI-owned controllers and Compose planning; App pins take precedence. */
4
- export declare const DEFAULT_SDK_VERSION = "0.49.5";
4
+ export declare const DEFAULT_SDK_VERSION = "0.52.0";
5
5
  export declare const SDK_PACKAGE = "@synopackageland/sdk";
6
6
  export declare const SDK_MODULE = "github.com/synopackageland/syno-pkg-land-sdk";
7
7
  export declare const EXECUTOR_MODULE = "github.com/synopackageland/syno-pkg-land-sdk/executor";
@@ -5,7 +5,7 @@ import { tmpdir } from 'node:os';
5
5
  import { join } from 'node:path';
6
6
  import { readExecutorManifest, predatesExecutorManifest } from './sdk-executor-manifest.js';
7
7
  /** Pinned SDK for CLI-owned controllers and Compose planning; App pins take precedence. */
8
- export const DEFAULT_SDK_VERSION = '0.49.5';
8
+ export const DEFAULT_SDK_VERSION = '0.52.0';
9
9
  export const SDK_PACKAGE = '@synopackageland/sdk';
10
10
  export const SDK_MODULE = 'github.com/synopackageland/syno-pkg-land-sdk';
11
11
  export const EXECUTOR_MODULE = `${SDK_MODULE}/executor`;
@@ -0,0 +1,6 @@
1
+ /** Extract an inventoried SPK archive into a private directory, preserving safe header modes. */
2
+ export declare function extractSpkArchive(options: {
3
+ file: string;
4
+ cwd: string;
5
+ filter?: (path: string) => boolean;
6
+ }): Promise<string[]>;
@@ -0,0 +1,39 @@
1
+ import { chmodSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import * as tar from "tar";
4
+ /** Extract an inventoried SPK archive into a private directory, preserving safe header modes. */
5
+ export async function extractSpkArchive(options) {
6
+ const modes = new Map();
7
+ const findings = [];
8
+ await tar.x({
9
+ ...options,
10
+ preserveOwner: false,
11
+ filter: (path, entry) => {
12
+ if (options.filter && !options.filter(path))
13
+ return false;
14
+ const mode = entry.mode ?? 0;
15
+ if (mode & 0o6000)
16
+ findings.push(`archive contains a setuid/setgid file: ${path}`);
17
+ if (mode & 0o002)
18
+ findings.push(`archive contains a world-writable file: ${path}`);
19
+ const relative = path.replace(/^\.\//, "").replace(/\/$/, "");
20
+ if (!relative || relative === ".")
21
+ return false; // Keep the private extraction root private.
22
+ if (path.startsWith("/") || /^[A-Za-z]:/.test(path) || relative.includes("\\") ||
23
+ relative.split("/").some(part => !part || part === "." || part === "..") ||
24
+ !("type" in entry) || !["File", "Directory"].includes(entry.type)) {
25
+ findings.push(`archive contains an unsafe path or type: ${path}`);
26
+ return false;
27
+ }
28
+ // Sanitize before tar creates anything; validation still reads the original headers.
29
+ entry.mode = mode & 0o777 & ~0o002;
30
+ modes.set(relative, entry.mode);
31
+ return true;
32
+ },
33
+ });
34
+ // chmod after all writes; restore children before potentially read-only parents.
35
+ for (const [path, mode] of [...modes].sort(([a], [b]) => b.split("/").length - a.split("/").length)) {
36
+ chmodSync(join(options.cwd, path), mode);
37
+ }
38
+ return findings;
39
+ }
@@ -1,10 +1,7 @@
1
- import type { Descriptor } from '../ctl/descriptor.js';
2
1
  import { type StandaloneManifest } from './manifest.js';
3
2
  import type { CommandRunner } from './build.js';
4
- export declare function buildApiDescription(m: StandaloneManifest, bridgeMethods: string[] | undefined, run: CommandRunner): Promise<{
5
- description: Descriptor;
6
- registry: Record<string, string>;
7
- } | undefined>;
3
+ import type { NativeArtifacts } from './native-http.js';
4
+ export declare function buildApiDescription(m: StandaloneManifest, bridgeMethods: string[] | undefined, run: CommandRunner): Promise<NativeArtifacts | undefined>;
8
5
  export declare function describeApiRoutes(m: StandaloneManifest, bridgeMethods: string[] | undefined, run: CommandRunner): Promise<{
9
6
  method: string;
10
7
  permission: string;
@@ -4,6 +4,7 @@ import { buildAppBackup } from './hyper-backup.js';
4
4
  import { auditGoRoutes, httpRoutesDigest } from './route-audit.js';
5
5
  import { PORTAL_REQUIRES_EXECUTOR } from "../portal/alias.js";
6
6
  import { buildApiDescription } from "./api-description.js";
7
+ import { buildNativeMetadataCgi } from './native-http.js';
7
8
  import { goChildEnv } from "../runtime/go-env.js";
8
9
  import { spawn } from "node:child_process";
9
10
  import { goModulePath, privateSdkHint, SDK_MODULE, sdkSource, } from "../runtime/sdk-source.js";
@@ -154,7 +155,9 @@ export async function buildStandalone(options) {
154
155
  const executor = await buildExecutor(manifest, arch, archWork, run);
155
156
  executor?.warnings.forEach((warning) => warnings.add(warning));
156
157
  const builtManifest = executor ? { ...manifest, executor } : manifest;
157
- const { cgi: cgiPath, worker: backgroundWorker, app, } = await backendFor(builtManifest, arch, archWork, run, bridge);
158
+ const { cgi: cgiPath, worker: backgroundWorker, app, } = builtManifest.ctl?.enabled && builtManifest.ctl.transport === 'native-http'
159
+ ? { cgi: await buildNativeMetadataCgi(builtManifest, arch, archWork, run, apiDescription) }
160
+ : await backendFor(builtManifest, arch, archWork, run, bridge);
158
161
  const outputPath = join(stage, `${manifest.package}-${manifest.spkVersion}-${arch}.spk`);
159
162
  const daemonControl = await buildDaemonControl(manifest, arch, archWork, run);
160
163
  const identityGateway = await buildIdentityGateway(manifest, arch, archWork, run);
@@ -183,6 +186,7 @@ export async function buildStandalone(options) {
183
186
  portalText,
184
187
  apiDescription,
185
188
  apiRegistry: apiArtifact?.registry,
189
+ httpInventory: apiArtifact?.inventory,
186
190
  });
187
191
  return outputPath;
188
192
  }));
@@ -1,5 +1,10 @@
1
1
  /** SDK planner errors accepted at this versioned tool boundary. */
2
2
  export const COMPOSE_ERRORS = {
3
+ COMPOSE_STOP_UNCONFIRMED: {
4
+ code: "COMPOSE_STOP_UNCONFIRMED",
5
+ description: "The App's local stop operation failed.",
6
+ suggestion: "Inspect the failed App hook or local service cleanup, resolve that failure and retry Stop. Missing Container Manager profiles after Stop are normal; do not recreate or modify them.",
7
+ },
3
8
  COMPOSE_HOST_UDP_INVALID: {
4
9
  code: "COMPOSE_HOST_UDP_INVALID",
5
10
  description: "The host UDP listener declaration is invalid.",
@@ -293,6 +293,7 @@ export function copyDaemonPayload(manifest, arch, target, controller) {
293
293
  writeFileSync(join(target, "config.json"), daemonConfig(manifest), {
294
294
  mode: 0o644,
295
295
  });
296
+ chmodSync(join(target, "config.json"), 0o644);
296
297
  }
297
298
  function writeNodeLauncher(source, target, node) {
298
299
  if (source && existsSync(join(source, NODE_LAUNCHER.split("/")[0])))
@@ -10,7 +10,7 @@ import { nativePortal } from "./portal.js";
10
10
  import { nativeGatewaySupported, renderNativeGatewayConfig, renderNativeGatewayDiagnostic, renderNativeGatewayPrepare, NATIVE_GATEWAY_CONFIG, gatewayEntryPath } from './native-gateway.js';
11
11
  import { inspectPortalInfo } from "../portal/info.js";
12
12
  import { isDeepStrictEqual } from "node:util";
13
- import { inspectApiDescription } from "./api-description-inspect.js";
13
+ import { inspectCtlArtifacts } from './native-http-inspect.js';
14
14
  import { dsmLauncherType } from "../contract/app-launch.js";
15
15
  import { isWebLaunchMode, resolvedWebLaunch, trustedAppEntryPath, usesAuthGateway, } from "../contract/web-launch.js";
16
16
  import { loadContract } from "../contract/load.js";
@@ -27,6 +27,7 @@ import { inspectHyperBackup } from "./hyper-backup.js";
27
27
  import { tmpdir } from "node:os";
28
28
  import { join } from "node:path";
29
29
  import * as tar from "tar";
30
+ import { extractSpkArchive } from "../spk/extract.js";
30
31
  import { familyOfArchToken, NATIVE_ARCH_FAMILIES, } from "../build-spk/dsm-arch.js";
31
32
  import { CONTAINER_MIN_DSM, isDsmAtLeast, PORTAL_EXECUTOR_MIN_DSM, PORTAL_MIN_DSM, PORTAL_MIN_DSM_REASON, } from "../build-spk/dsm-version.js";
32
33
  import { ELF_MACHINE } from "./binary.js";
@@ -74,7 +75,7 @@ export async function inspectSpk(spkPath, expectedKind) {
74
75
  const findings = (await archiveInventory(spkPath, true)).map(formatArchiveIssue);
75
76
  if (findings.length)
76
77
  return { signed: false, payload: [], findings, capabilities: [] };
77
- await tar.x({ file: spkPath, cwd: dir });
78
+ findings.push(...await extractSpkArchive({ file: spkPath, cwd: dir }));
78
79
  if (existsSync(join(dir, 'package.tgz'))) {
79
80
  findings.push(...(await archiveInventory(join(dir, 'package.tgz'))).map(formatArchiveIssue));
80
81
  if (findings.length)
@@ -90,7 +91,7 @@ export async function inspectSpk(spkPath, expectedKind) {
90
91
  const payload = await listPayload(join(dir, "package.tgz"), findings);
91
92
  const target = join(dir, "layout-inspection");
92
93
  mkdirSync(target);
93
- await tar.x({ file: join(dir, "package.tgz"), cwd: target });
94
+ await extractSpkArchive({ file: join(dir, "package.tgz"), cwd: target });
94
95
  findings.push(...inspectNativeLayout(dir, target, info));
95
96
  for (const key of [
96
97
  "package",
@@ -177,11 +178,12 @@ export async function inspectSpk(spkPath, expectedKind) {
177
178
  const root = join(dir, "backup-inspection");
178
179
  if (!existsSync(root)) {
179
180
  mkdirSync(root);
180
- await tar.x({ file: join(dir, "package.tgz"), cwd: root });
181
+ await extractSpkArchive({ file: join(dir, "package.tgz"), cwd: root });
181
182
  }
182
183
  return root;
183
184
  }, payload, metadata.hyperBackup, /^package="([^"]*)"$/m.exec(readOptional(join(dir, "INFO")) ?? "")?.[1] ?? "", familyOfArchToken(/^arch="([^"]*)"$/m.exec(readOptional(join(dir, "INFO")) ?? "")?.[1]?.split(/\s+/)[0] ?? "") ?? "x86_64", findings);
184
185
  const integrations = metadata.integrations ?? [];
186
+ await inspectCtlArtifacts(dir, paths, metadata.ctl, metadata.entry, findings);
185
187
  if (metadata.compose !== undefined) {
186
188
  const result = await inspectUnifiedCompose(dir, payload, { ...metadata, installSettings }, findings);
187
189
  if (dependencies) {
@@ -249,22 +251,6 @@ export async function inspectSpk(spkPath, expectedKind) {
249
251
  checkUninstall(dir, findings);
250
252
  if (kind === "container")
251
253
  await checkContainerExposure(dir, join(dir, "package.tgz"), findings);
252
- if (metadata.ctl || paths.has("synopkgland-api.json")) {
253
- if (!metadata.ctl ||
254
- !paths.has("synopkgland-api.json") ||
255
- [...paths].some((path) => path.startsWith("ui/") && path.endsWith("synopkgland-api.json")))
256
- findings.push("CTL_DESCRIPTOR_LAYOUT_INVALID API description must be private and match its build record.");
257
- else {
258
- const apiDir = join(dir, "api-description-inspection");
259
- mkdirSync(apiDir);
260
- await tar.x({
261
- file: join(dir, "package.tgz"),
262
- cwd: apiDir,
263
- filter: (path) => path.replace(/^\.\//, "") === "synopkgland-api.json",
264
- });
265
- findings.push(...inspectApiDescription(readFileSync(join(apiDir, "synopkgland-api.json"), "utf8"), { id: info.package, version: info.version }, metadata.ctl.hash, metadata.ctl.registry));
266
- }
267
- }
268
254
  const bridge = compiledKind && kind !== "native-go"
269
255
  ? await checkBridgeApp(dir, metadata.backend, info, payload, findings, metadata.entry)
270
256
  : undefined;
@@ -283,7 +269,7 @@ export async function inspectSpk(spkPath, expectedKind) {
283
269
  paths.has("executor/executor")) {
284
270
  const executorDir = join(dir, "executor-inspection");
285
271
  mkdirSync(executorDir);
286
- await tar.x({ file: join(dir, "package.tgz"), cwd: executorDir });
272
+ await extractSpkArchive({ file: join(dir, "package.tgz"), cwd: executorDir });
287
273
  const inspected = inspectExecutor(executorDir, info.package, info.arch);
288
274
  findings.push(...inspected.findings);
289
275
  executor = inspected.executor;
@@ -421,7 +407,7 @@ async function inspectModuleUi(dir, paths, version, findings, mobile) {
421
407
  throw new Error("module UI assets must all belong to the recorded tree");
422
408
  const root = join(dir, "module-ui-inspection");
423
409
  mkdirSync(root);
424
- await tar.x({ file: join(dir, "package.tgz"), cwd: root, filter: path => path.replace(/^\.\//, "").startsWith(prefix) });
410
+ await extractSpkArchive({ file: join(dir, "package.tgz"), cwd: root, filter: path => path.replace(/^\.\//, "").startsWith(prefix) });
425
411
  if (uiTreeDigest(join(root, "ui/app", version), true) !== version)
426
412
  throw new Error("UI assets differ from their recorded digest");
427
413
  }
@@ -435,7 +421,7 @@ const LAUNCHER_PORTAL_MISMATCH = "LAUNCHER_PORTAL_MISMATCH";
435
421
  async function checkLaunchConfiguration(dir, info, native, declared, alias, findings, console = false, windowless = false) {
436
422
  const target = join(dir, "launch-inspection");
437
423
  mkdirSync(target);
438
- await tar.x({
424
+ await extractSpkArchive({
439
425
  file: join(dir, "package.tgz"),
440
426
  cwd: target,
441
427
  filter: (path) => ["ui/config", "synology-app.yaml"].includes(path.replace(/^\.\//, "")),
@@ -573,7 +559,7 @@ function checkGatewayOnlyLauncher(target, info, native, findings) {
573
559
  async function checkEntryLauncher(dir, pkg, entry, findings) {
574
560
  const target = join(dir, "entry-inspection");
575
561
  mkdirSync(target);
576
- await tar.x({
562
+ await extractSpkArchive({
577
563
  file: join(dir, "package.tgz"),
578
564
  cwd: target,
579
565
  filter: (path) => path.replace(/^\.\//, "") === "ui/config",
@@ -606,7 +592,7 @@ const LOGIN_STYLE_FILES = [
606
592
  async function inspectLoginStyle(dir, pkg, portal, findings) {
607
593
  const target = join(dir, "login-style-inspection");
608
594
  mkdirSync(target);
609
- await tar.x({
595
+ await extractSpkArchive({
610
596
  file: join(dir, "package.tgz"),
611
597
  cwd: target,
612
598
  filter: (path) => path.replace(/^\.\//, "").startsWith("ui/"),
@@ -716,7 +702,7 @@ async function checkArch(dir, info, kind, hasCgi, findings) {
716
702
  const cgi = join(dir, "cgi-inspection");
717
703
  mkdirSync(cgi);
718
704
  // Only the header is read; the CGI is never run.
719
- await tar.x({
705
+ await extractSpkArchive({
720
706
  file: join(dir, "package.tgz"),
721
707
  cwd: cgi,
722
708
  filter: (path) => path.replace(/^\.\//, "") === CGI_PAYLOAD_PATH,
@@ -750,7 +736,7 @@ async function inspectUnifiedCompose(dir, payload, metadata, findings) {
750
736
  const appScripts = unwrapAppScripts(join(dir, "scripts"), findings);
751
737
  const root = join(dir, "unified-compose-inspection");
752
738
  mkdirSync(root);
753
- await tar.x({ file: join(dir, "package.tgz"), cwd: root });
739
+ await extractSpkArchive({ file: join(dir, "package.tgz"), cwd: root });
754
740
  try {
755
741
  if (metadata.capabilities?.some((c) => c !== "composeMounts"))
756
742
  throw new Error("Compose cannot claim an undeclared executor capability");
@@ -942,7 +928,7 @@ async function recoverCompose(dir, value, findings) {
942
928
  throw new Error("invalid compose inventory");
943
929
  const root = join(dir, "compose-inspection");
944
930
  mkdirSync(root);
945
- await tar.x({
931
+ await extractSpkArchive({
946
932
  file: join(dir, "package.tgz"),
947
933
  cwd: root,
948
934
  filter: (p) => ["compose/docker-compose.yml", "sso/gateway.json"].includes(p.replace(/^\.\//, "")),
@@ -989,7 +975,7 @@ async function checkDaemon(dir, info, paths, payload, findings, executor, backgr
989
975
  // Extract only the bounded config; the payload executable is never run.
990
976
  const { mkdirSync } = await import("node:fs");
991
977
  mkdirSync(unpacked);
992
- await tar.x({
978
+ await extractSpkArchive({
993
979
  file: join(dir, "package.tgz"),
994
980
  cwd: unpacked,
995
981
  filter: (path) => ["daemon/config.json", `daemon/payload/${NODE_LAUNCHER}`].includes(path.replace(/^\.\//, "")),
@@ -1181,7 +1167,7 @@ function readInfo(path, findings, kind, compose = false, daemonNode, dependencie
1181
1167
  async function checkContainerExposure(dir, packageTgz, findings) {
1182
1168
  const extracted = join(dir, "payload");
1183
1169
  mkdirSync(extracted);
1184
- await tar.x({
1170
+ await extractSpkArchive({
1185
1171
  file: packageTgz,
1186
1172
  cwd: extracted,
1187
1173
  filter: (path) => path.replace(/^\.\//, "") === "compose.yaml",
@@ -1213,7 +1199,7 @@ async function inspectGatewayAdmission(dir, paths, saved, findings) {
1213
1199
  }
1214
1200
  const root = join(dir, "gateway-admission-inspection");
1215
1201
  mkdirSync(root);
1216
- await tar.x({ file: join(dir, "package.tgz"), cwd: root, filter: p => p.replace(/^\.\//, "") === "sso/gateway.json" });
1202
+ await extractSpkArchive({ file: join(dir, "package.tgz"), cwd: root, filter: p => p.replace(/^\.\//, "") === "sso/gateway.json" });
1217
1203
  const cfg = JSON.parse(readFileSync(join(root, "sso/gateway.json"), "utf8"));
1218
1204
  const gateway = gatewayReviewReport(cfg);
1219
1205
  if (cfg.upstream_access !== undefined && !["public", "protected"].includes(cfg.upstream_access))
@@ -1248,7 +1234,7 @@ async function inspectExternalGateway(dir, paths, payload, saved, findings) {
1248
1234
  const root = join(dir, "external-gateway-inspection");
1249
1235
  mkdirSync(root);
1250
1236
  const entries = ["sso/gateway.json", GATEWAY_SETTINGS_CGI_PATH, "ui/sso/open.cgi"];
1251
- await tar.x({ file: join(dir, "package.tgz"), cwd: root, filter: p => entries.includes(p.replace(/^\.\//, "")) });
1237
+ await extractSpkArchive({ file: join(dir, "package.tgz"), cwd: root, filter: p => entries.includes(p.replace(/^\.\//, "")) });
1252
1238
  const cfg = JSON.parse(readFileSync(join(root, "sso/gateway.json"), "utf8"));
1253
1239
  if (saved === undefined && cfg.external === undefined && !paths.has(GATEWAY_SETTINGS_CGI_PATH))
1254
1240
  return;
@@ -1291,7 +1277,7 @@ async function recoverNativeGateway(dir, value, info, findings) {
1291
1277
  throw new Error('unsupported native gateway SDK/DSM floor');
1292
1278
  const root = join(dir, 'native-gateway-inspection');
1293
1279
  mkdirSync(root);
1294
- await tar.x({ file: join(dir, 'package.tgz'), cwd: root, filter: path => ['sso/gateway.json', 'ui/sso/open.cgi', NATIVE_GATEWAY_CONFIG].includes(path.replace(/^\.\//, '')) });
1280
+ await extractSpkArchive({ file: join(dir, 'package.tgz'), cwd: root, filter: path => ['sso/gateway.json', 'ui/sso/open.cgi', NATIVE_GATEWAY_CONFIG].includes(path.replace(/^\.\//, '')) });
1295
1281
  const config = JSON.parse(readFileSync(join(root, 'sso/gateway.json'), 'utf8'));
1296
1282
  if (config.native_ingress !== true || config.package !== info.package || !isDeepStrictEqual(config.listen, plan.listen) || config.ingress_path !== plan.ingress?.path
1297
1283
  || config.state_dir !== `/var/packages/${info.package}/var/sso`)
@@ -1343,7 +1329,7 @@ async function recoverDaemonIngress(dir, value, info, paths, findings) {
1343
1329
  throw new Error("ingress needs the package daemon");
1344
1330
  const root = join(dir, "daemon-ingress-inspection");
1345
1331
  mkdirSync(root);
1346
- await tar.x({ file: join(dir, "package.tgz"), cwd: root, filter: (path) => path.replace(/^\.\//, "") === DAEMON_INGRESS_CONFIG });
1332
+ await extractSpkArchive({ file: join(dir, "package.tgz"), cwd: root, filter: (path) => path.replace(/^\.\//, "") === DAEMON_INGRESS_CONFIG });
1347
1333
  if (readOptional(join(root, DAEMON_INGRESS_CONFIG)) !== renderDaemonIngressConfig(info.package, ingress))
1348
1334
  throw new Error("ingress location differs from its fixed proxy");
1349
1335
  for (const key of ["instuninst_restart_services", "startstop_restart_services"])
@@ -1559,7 +1545,7 @@ async function inspectInstallSettings(dir, payload, metadata, findings) {
1559
1545
  }
1560
1546
  const root = join(dir, 'install-settings-inspection');
1561
1547
  mkdirSync(root);
1562
- await tar.x({ file: join(dir, 'package.tgz'), cwd: root });
1548
+ await extractSpkArchive({ file: join(dir, 'package.tgz'), cwd: root });
1563
1549
  const info = readInfo(join(dir, 'INFO'), findings, 'binary', Boolean(metadata.compose), undefined, inspectPackageDependencies(metadata.dependencies, findings));
1564
1550
  const gateway = metadata.compose?.gateway ?? metadata.native_gateway;
1565
1551
  const m = { package: info.package, os_min_ver: info.os_min_ver, capabilities: {}, installSettings: settings, identityGateway: gateway, ...(ports ? { installPorts: true } : {}) };
@@ -1636,7 +1622,7 @@ async function recoverPortal(dir, info, appId, paths, payload, findings, nativeG
1636
1622
  return;
1637
1623
  const unpacked = join(dir, "portal-inspection");
1638
1624
  mkdirSync(unpacked);
1639
- await tar.x({
1625
+ await extractSpkArchive({
1640
1626
  file: join(dir, "package.tgz"),
1641
1627
  cwd: unpacked,
1642
1628
  filter: (path) => files.includes(path.replace(/^\.\//, "")),
@@ -1842,7 +1828,7 @@ async function inspectMobile(dir, paths, record, info, findings) {
1842
1828
  throw new Error('registration package or version differs from INFO');
1843
1829
  const target = join(dir, 'mobile-inspection');
1844
1830
  mkdirSync(target);
1845
- await tar.x({ file: join(dir, 'package.tgz'), cwd: target, filter: path => path.replace(/^\.\//, '').startsWith('ui/app/') });
1831
+ await extractSpkArchive({ file: join(dir, 'package.tgz'), cwd: target, filter: path => path.replace(/^\.\//, '').startsWith('ui/app/') });
1846
1832
  const problem = inspectMobileFiles(join(target, 'ui/app'), record);
1847
1833
  if (problem)
1848
1834
  throw new Error(problem);
@@ -1,4 +1,4 @@
1
- import { mkdirSync, writeFileSync, readFileSync, existsSync } from 'node:fs';
1
+ import { chmodSync, mkdirSync, writeFileSync, readFileSync, existsSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  export function portDefaults(m) {
4
4
  if (!m.installPorts || !m.identityGateway)
@@ -125,4 +125,5 @@ export function writePortPayload(m, root, render) {
125
125
  mkdirSync(join(root, 'install'), { recursive: true });
126
126
  writeFileSync(join(root, 'install/ports.json'), JSON.stringify({ schema: 1, package: m.package, ports, files }, null, 2) + '\n', { mode: 0o600 });
127
127
  writeFileSync(join(root, `install/${m.package}.sc`), Object.entries(ports).map(([key, p]) => `[synopkgland.${m.package.replaceAll('_', '-')}.${key.replaceAll('_', '-')}]\ntitle="${m.package}"\ndesc="${m.package}"\nport_forward="no"\ndst.ports="${p.default}/${p.protocol}"\n`).join('\n'), { mode: 0o644 });
128
+ chmodSync(join(root, `install/${m.package}.sc`), 0o644);
128
129
  }
@@ -63,13 +63,20 @@ function renderStandaloneScriptInternal(name, manifest) {
63
63
  compose: undefined,
64
64
  daemon: manifest.identityGateway ? composeDaemon(manifest) : undefined,
65
65
  };
66
- const body = name === "preinst"
66
+ let body = name === "preinst"
67
67
  ? renderComposeInstall(manifest.package).replace("#!/bin/sh\n", () => "#!/bin/sh\n" + renderSharedFolderPreparation(manifest.sharedFolder))
68
68
  : renderStandaloneScriptInternal(name, { ...native, appScripts: undefined });
69
+ if (name === "start-stop-status" && !manifest.identityGateway) {
70
+ // Report real local teardown failures. Container Manager may remove
71
+ // profiles on STOP and recreate them in its START worker; neither
72
+ // action may require those profiles to exist.
73
+ body = `#!/bin/sh\nsynopkgland_compose_lifecycle() (\n${body.slice("#!/bin/sh\n".length)})\nsynopkgland_compose_result=0\nsynopkgland_compose_lifecycle "$@" || synopkgland_compose_result=$?\nif [ "$1" = stop ] && [ "$synopkgland_compose_result" != 0 ]; then\n echo "[COMPOSE_STOP_UNCONFIRMED] Local service teardown failed; inspect App hooks and local services, then retry Stop" >&2\nfi\nexit "$synopkgland_compose_result"\n`;
74
+ }
69
75
  const control = `"/var/packages/${manifest.package}/target/daemon/control"`;
70
76
  const paths = `"\${SYNOPKG_PKGDEST:-/var/packages/${manifest.package}/target}" "\${SYNOPKG_PKGVAR:-/var/packages/${manifest.package}/var}"`;
71
77
  const preflight = name === "start-stop-status"
72
- ? `case "$1" in prestart|start|restart)\n "\${SYNOPKG_PKGDEST:-/var/packages/${manifest.package}/target}/compose/control" preflight || exit $? ;;\nesac\n` +
78
+ ? (!manifest.identityGateway ? `if [ "$1" = restart ]; then\n "$0" stop || exit $?\n exec "$0" start\nfi\n` : "") +
79
+ `case "$1" in prestart|start|restart)\n "\${SYNOPKG_PKGDEST:-/var/packages/${manifest.package}/target}/compose/control" preflight || exit $? ;;\nesac\n` +
73
80
  (!manifest.identityGateway ? `case "$1" in prestart|prestop) exit 0 ;; esac\n` : "")
74
81
  : "";
75
82
  const remember = name === "postinst" &&
@@ -50,6 +50,7 @@ export interface StandaloneManifest {
50
50
  allowSecretFiles?: string[];
51
51
  ctl?: {
52
52
  enabled: boolean;
53
+ transport?: 'native-http';
53
54
  registry?: string;
54
55
  aliases?: string[];
55
56
  developedBy?: string;
@@ -1,3 +1,4 @@
1
+ import { validateNativeManifest } from './native-http.js';
1
2
  import { readMobile, mobileIconPath } from './mobile.js';
2
3
  import { daemonNoFileSdkProblem, daemonNoFileIdentityProblem, DAEMON_NOFILE_MIN_DSM, DAEMON_NOFILE_UNSUPPORTED, DAEMON_NOFILE_ACTIVATION_PROBLEM } from './daemon-nofile.js';
3
4
  import { readAllowedSecretFiles } from "../secret-files.js";
@@ -226,7 +227,7 @@ function readManifest(raw, c) {
226
227
  : undefined;
227
228
  if (binaryProblem)
228
229
  c.fail("STANDALONE_ROOT_PROGRAMS_INVALID", binaryProblem);
229
- const backend = raw.compose !== undefined && raw.backend === undefined
230
+ const backend = (raw.compose !== undefined || isRecord(raw.ctl) && raw.ctl.transport === 'native-http') && raw.backend === undefined
230
231
  ? { kind: "binary", files: {} }
231
232
  : arches && readBackend(raw.backend, arches, c);
232
233
  if (backend && backend.kind !== "binary" && rootOps) {
@@ -248,7 +249,7 @@ function readManifest(raw, c) {
248
249
  }
249
250
  let permissions;
250
251
  let integrations;
251
- if (backend && backend.kind !== "binary") {
252
+ if (backend && backend.kind !== "binary" && !(isRecord(raw.ctl) && raw.ctl.transport === 'native-http')) {
252
253
  try {
253
254
  const source = isRecord(raw.ctl) && typeof raw.ctl.registry === 'string' ? readRegistry(registryFile(c.root, raw.ctl.registry)) : undefined;
254
255
  permissions = readApiPermissions(backend, capabilities, source?.operations);
@@ -283,7 +284,7 @@ function readManifest(raw, c) {
283
284
  c.fail(problem.code, problem.message);
284
285
  }
285
286
  const gatewayRaw = isRecord(raw.identity_gateway) ? raw.identity_gateway : {};
286
- if (raw.compose !== undefined && isRecord(raw.ctl) && raw.ctl.enabled === true)
287
+ if (raw.compose !== undefined && isRecord(raw.ctl) && raw.ctl.enabled === true && raw.ctl.transport !== 'native-http')
287
288
  c.fail("CTL_UNSUPPORTED_BACKEND", "Compose does not support automatic ctl descriptions; disable ctl.");
288
289
  if (isRecord(raw.compose) && isRecord(raw.compose.web) && !isRecord(raw.compose.web.health))
289
290
  c.fail("COMPOSE_HEALTH_REQUIRED", "Select compose.web.health.path and expected 2xx status for the actual App. Readiness does not follow redirects; check is static and does not probe HTTP.");
@@ -420,7 +421,7 @@ function readManifest(raw, c) {
420
421
  }
421
422
  const entry = raw.entry === undefined
422
423
  ? undefined
423
- : raw.compose !== undefined &&
424
+ : (raw.compose !== undefined || isRecord(raw.ctl) && raw.ctl.transport === 'native-http') &&
424
425
  (raw.entry === "admin-only" || raw.entry === "app-privilege")
425
426
  ? raw.entry
426
427
  : readEntry(raw.entry, backend, permissions?.policy, c);
@@ -589,6 +590,8 @@ function readManifest(raw, c) {
589
590
  if (typeof raw.ctl.registry !== 'string' || raw.ctl.commands !== undefined)
590
591
  throw Error('Use ctl.registry without ctl.commands.');
591
592
  const registry = readRegistry(registryFile(c.root, raw.ctl.registry));
593
+ if (raw.ctl.transport !== undefined && raw.ctl.transport !== 'native-http' || (registry.version === 3) !== (raw.ctl.transport === 'native-http') || raw.ctl.transport === 'native-http' && (raw.ctl.external !== undefined || !identityGateway?.ingress || capabilities.identity))
594
+ throw Error('Native HTTP requires a v3 registry, protected same-origin ingress and no ctl.external or standalone identity.');
592
595
  raw.ctl.commands = Object.fromEntries(Object.entries(registry.operations).filter(([, op]) => op.ai !== 'hidden'));
593
596
  }
594
597
  catch (error) {
@@ -596,6 +599,10 @@ function readManifest(raw, c) {
596
599
  return undefined;
597
600
  }
598
601
  }
602
+ if (isRecord(raw.ctl) && raw.ctl.transport !== undefined && (raw.ctl.transport !== 'native-http' || typeof raw.ctl.registry !== 'string')) {
603
+ c.fail('CTL_DECLARATION_INVALID', 'Explicit native-http transport requires a v3 operation registry.');
604
+ return undefined;
605
+ }
599
606
  if (isRecord(raw.ctl) && raw.ctl.external !== undefined) {
600
607
  const external = raw.ctl.external;
601
608
  if (!isRecord(external) || Object.keys(external).length < 1 || Object.keys(external).length > 16 ||
@@ -606,7 +613,7 @@ function readManifest(raw, c) {
606
613
  return undefined;
607
614
  }
608
615
  }
609
- return {
616
+ const manifest = {
610
617
  ...(raw.ctl ? { ctl: raw.ctl } : {}),
611
618
  ...(allowSecretFiles ? { allowSecretFiles } : {}),
612
619
  root: c.root,
@@ -655,6 +662,16 @@ function readManifest(raw, c) {
655
662
  ...(loginStyle ? { loginStyle } : {}),
656
663
  ...(appScripts ? { appScripts } : {}),
657
664
  };
665
+ if (manifest.ctl?.transport === 'native-http') {
666
+ try {
667
+ validateNativeManifest(manifest);
668
+ }
669
+ catch (error) {
670
+ c.fail('CTL_NATIVE_REGISTRY_INVALID', error.message);
671
+ return undefined;
672
+ }
673
+ }
674
+ return manifest;
658
675
  }
659
676
  function checkBridgeMethods(backend, permissions, c) {
660
677
  for (const problem of bridgeMethodProblems(backend.methods, permissions, `${relative(c.root, backend.dir)}/permissions.json`))
@@ -0,0 +1,9 @@
1
+ export interface CtlBuildRecord {
2
+ hash: string;
3
+ registry?: Record<string, string>;
4
+ transport?: string;
5
+ inventorySha256?: string;
6
+ sdk?: string;
7
+ }
8
+ /** Runs before Compose's early inspect return as well as on native packages. */
9
+ export declare function inspectCtlArtifacts(dir: string, paths: Set<string>, record: CtlBuildRecord | undefined, entry: string | undefined, findings: string[]): Promise<void>;
@@ -0,0 +1,43 @@
1
+ import { readFileSync, mkdirSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import * as tar from 'tar';
4
+ import { validateNativeArtifacts, digest, HTTP_INVENTORY_FILE } from '../ctl/native-metadata.js';
5
+ import { gatewayEntryPolicyDigest } from './identity-gateway.js';
6
+ import { CGI_PAYLOAD_PATH } from './dsm-window.js';
7
+ import { inspectApiDescription } from './api-description-inspect.js';
8
+ import { strictJson } from '../ctl/json.js';
9
+ /** Runs before Compose's early inspect return as well as on native packages. */
10
+ export async function inspectCtlArtifacts(dir, paths, record, entry, findings) {
11
+ if (!record && !paths.has('synopkgland-api.json') && !paths.has(HTTP_INVENTORY_FILE))
12
+ return;
13
+ if (!record || !paths.has('synopkgland-api.json') || [...paths].some(path => path.startsWith('ui/') && (path.endsWith('synopkgland-api.json') || path.endsWith(HTTP_INVENTORY_FILE)))) {
14
+ findings.push('CTL_DESCRIPTOR_LAYOUT_INVALID metadata must be private and match its build record.');
15
+ return;
16
+ }
17
+ const root = join(dir, 'api-description-inspection');
18
+ mkdirSync(root, { recursive: true });
19
+ const wanted = new Set(['synopkgland-api.json', HTTP_INVENTORY_FILE, 'sso/gateway.json', CGI_PAYLOAD_PATH]);
20
+ await tar.x({ file: join(dir, 'package.tgz'), cwd: root, filter: path => wanted.has(path.replace(/^\.\//, '')) });
21
+ const raw = readFileSync(join(root, 'synopkgland-api.json'), 'utf8'), info = readFileSync(join(dir, 'INFO'), 'utf8'), id = /^package="([^"]+)"$/m.exec(info)?.[1] ?? '', version = /^version="([^"]+)"$/m.exec(info)?.[1] ?? '';
22
+ try {
23
+ const description = strictJson(raw);
24
+ if (description.version !== 3) {
25
+ if (record.transport || paths.has(HTTP_INVENTORY_FILE))
26
+ throw Error();
27
+ findings.push(...inspectApiDescription(raw, { id, version }, record.hash, record.registry));
28
+ return;
29
+ }
30
+ if (record.transport !== 'native-http' || !record.sdk || !paths.has(HTTP_INVENTORY_FILE) || !paths.has('sso/gateway.json') || !paths.has(CGI_PAYLOAD_PATH))
31
+ throw Error();
32
+ const { descriptor: d, inventory: i } = validateNativeArtifacts(description, strictJson(readFileSync(join(root, HTTP_INVENTORY_FILE))));
33
+ const p = d.payload;
34
+ const gateway = strictJson(readFileSync(join(root, 'sso/gateway.json')));
35
+ const permissions = Object.fromEntries(Object.entries(i.bindings).map(([name, b]) => [name, b.permission]));
36
+ const cgi = readFileSync(join(root, CGI_PAYLOAD_PATH));
37
+ if (p.package.id !== id || p.package.version !== version || p.entry !== (entry ?? 'policy') || d.sha256 !== record.hash || p.inventorySha256 !== record.inventorySha256 || digest(permissions) !== digest(record.registry) || p.entryPolicyDigest !== gatewayEntryPolicyDigest(gateway) || p.execution.basePath !== gateway.ingress_path || digest(i.upstreamAuthPaths) !== digest(gateway.upstream_auth_paths) || !cgi.includes(Buffer.from(d.sha256)) || !cgi.includes(Buffer.from('api/nativehttp.NewDescriptionHandler')))
38
+ throw Error();
39
+ }
40
+ catch {
41
+ findings.push('CTL_NATIVE_METADATA_MISMATCH descriptor, HTTP inventory, gateway policy, CGI pin or final INFO differs.');
42
+ }
43
+ }
@@ -0,0 +1,31 @@
1
+ import { type NativeArchFamily } from '../build-spk/dsm-arch.js';
2
+ import type { NativeInventory } from '../ctl/native-types.js';
3
+ import type { Descriptor } from '../ctl/descriptor.js';
4
+ import type { StandaloneManifest } from './manifest.js';
5
+ import type { CommandRunner } from './build.js';
6
+ export interface NativeArtifacts {
7
+ description: Descriptor;
8
+ registry: Record<string, string>;
9
+ inventory?: NativeInventory;
10
+ }
11
+ export declare function nativeSdk(m: StandaloneManifest): import("../runtime/sdk-source.js").SdkSource;
12
+ export declare function nativeBuildConfig(m: StandaloneManifest): {
13
+ package: {
14
+ id: string;
15
+ version: string;
16
+ displayName: string;
17
+ };
18
+ aliases: string[];
19
+ provenance: {
20
+ developedBy: string;
21
+ generator: string;
22
+ };
23
+ backend: string;
24
+ transport: string;
25
+ gateway: any;
26
+ };
27
+ export declare function validateNativeManifest(m: StandaloneManifest): void;
28
+ export declare function generateNativeOperations(m: StandaloneManifest, run: CommandRunner, check?: boolean): Promise<NativeArtifacts>;
29
+ /** Fixed SDK metadata-only CGI; no App business routes are linked. */
30
+ export declare function metadataCgiSource(pkg: string, entry: string, sha256: string): string;
31
+ export declare function buildNativeMetadataCgi(m: StandaloneManifest, arch: NativeArchFamily, work: string, run: CommandRunner, description: Descriptor): Promise<string>;