@safetech/inheriti-cli 0.0.19-dev.0 → 0.0.20-dev.0

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/main.js CHANGED
@@ -77921,6 +77921,7 @@ function generateAutomationRuntimeBundle(input) {
77921
77921
  const script = [
77922
77922
  "#!/bin/sh",
77923
77923
  "set -eu",
77924
+ ...Object.entries(policy.environment).map(([name2, value2]) => `export ${name2}=${shellQuote(value2)}`),
77924
77925
  `[ "$#" -gt 0 ] || { echo 'Application command required' >&2; exit 2; }`,
77925
77926
  `exec ${cli.map(shellQuote).join(" ")} "$@"`,
77926
77927
  ""
@@ -77976,16 +77977,27 @@ var init_automation_field_mappings = __esm({
77976
77977
  });
77977
77978
 
77978
77979
  // ../../packages/core/dist/provider-cli-error.js
77979
- function providerCliError(binary, error2, fallback2) {
77980
+ function providerCliError(binary, error2, fallback2, showStderr = false) {
77980
77981
  const failure = error2;
77981
- if (failure?.code === "ENOENT")
77982
- return new Error(`${binary}_cli_required`);
77983
77982
  const stderr = typeof failure?.stderr === "string" ? failure.stderr : "";
77983
+ const aws = binary === "aws" && stderr.match(/An error occurred \(([A-Za-z][A-Za-z0-9]{0,63})\) when calling the ([A-Za-z][A-Za-z0-9]{0,63}) operation:/u);
77984
+ const gcloud = binary === "gcloud" && stderr.match(/ERROR: \((gcloud[.a-z0-9_-]{1,100})\) ([A-Z][A-Z0-9_]{1,63}):/u);
77985
+ const diagnostic = showStderr && stderr.trim() ? stderr.trim().replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/gu, "") : aws ? `${aws[1]} in ${aws[2]}` : gcloud ? `${gcloud[2]} in ${gcloud[1]}` : typeof failure?.code === "number" ? `Exit code ${failure.code}` : typeof failure?.code === "string" && /^[A-Z][A-Z0-9_]+$/u.test(failure.code) ? `Process error ${failure.code}` : void 0;
77986
+ const result = (code) => {
77987
+ const result2 = new Error(code);
77988
+ if (diagnostic)
77989
+ Object.defineProperty(result2, "providerDiagnostic", {
77990
+ value: `${binary === "aws" ? "AWS" : "gcloud"} CLI: ${diagnostic}`
77991
+ });
77992
+ return result2;
77993
+ };
77994
+ if (failure?.code === "ENOENT")
77995
+ return result(`${binary}_cli_required`);
77984
77996
  if (binary === "aws" && /Unable to locate credentials|ExpiredToken|InvalidClientTokenId|UnrecognizedClientException|security token included in the request is invalid|SSO session[^\n]*expired/i.test(stderr))
77985
- return new Error("aws_authentication_required");
77997
+ return result("aws_authentication_required");
77986
77998
  if (binary === "gcloud" && /You do not currently have an active account selected|Please run:\s*gcloud auth login|does not have any valid credentials|invalid_grant/i.test(stderr))
77987
- return new Error("gcloud_authentication_required");
77988
- return new Error(fallback2);
77999
+ return result("gcloud_authentication_required");
78000
+ return result(fallback2);
77989
78001
  }
77990
78002
  var init_provider_cli_error = __esm({
77991
78003
  "../../packages/core/dist/provider-cli-error.js"() {
@@ -78072,7 +78084,7 @@ var init_automation_image = __esm({
78072
78084
  const { stdout } = await execFileAsync(binary, args, { timeout: 12e4, maxBuffer: 1024 * 1024, windowsHide: true, signal });
78073
78085
  return stdout;
78074
78086
  } catch (error2) {
78075
- throw providerCliError(binary, error2, "automation_image_lookup_failed");
78087
+ throw providerCliError(binary, error2, "automation_image_lookup_failed", true);
78076
78088
  }
78077
78089
  };
78078
78090
  }
@@ -78159,6 +78171,8 @@ async function describeCloudTarget(target2, run4, requireStartup) {
78159
78171
  "json"
78160
78172
  ]));
78161
78173
  const definition = record3(response.taskDefinition);
78174
+ if (!definition.taskRoleArn)
78175
+ throw new Error("automation_ecs_task_role_missing");
78162
78176
  const container = selectContainer(definition.containerDefinitions, target2.container);
78163
78177
  const entryPoint = command2(container.entryPoint ?? []);
78164
78178
  if (requireStartup && !entryPoint.length)
@@ -78272,7 +78286,7 @@ var init_automation_cloud_target = __esm({
78272
78286
  const { stdout } = await execFileAsync2(binary, args, { maxBuffer: 1024 * 1024, windowsHide: true, timeout: 2e4 });
78273
78287
  return stdout;
78274
78288
  } catch (error2) {
78275
- throw providerCliError(binary, error2, "automation_cloud_inspection_failed");
78289
+ throw providerCliError(binary, error2, "automation_cloud_inspection_failed", true);
78276
78290
  }
78277
78291
  };
78278
78292
  record3 = (value2) => {
@@ -79042,6 +79056,7 @@ async function pairEcsAutomation(input, run4 = runAws3) {
79042
79056
  throw new Error("automation_ecs_pair_input_invalid");
79043
79057
  const { target: target2 } = input;
79044
79058
  input.signal?.throwIfAborted();
79059
+ input.onProgress?.("checking");
79045
79060
  const region = ["--region", target2.region, "--output", "json"];
79046
79061
  const call = async (args, signal) => parsed2(await run4(["ecs", ...args, ...region], signal));
79047
79062
  const response = await call(["describe-services", "--cluster", target2.cluster, "--services", target2.service], input.signal);
@@ -79104,6 +79119,7 @@ async function pairEcsAutomation(input, run4 = runAws3) {
79104
79119
  const requestFile = join5(directory, "run-task.json");
79105
79120
  try {
79106
79121
  await writeFile5(registrationFile, JSON.stringify(registration), { mode: 384, flag: "wx" });
79122
+ input.onProgress?.("registering");
79107
79123
  const registered = await call(["register-task-definition", "--cli-input-json", `file://${registrationFile}`]);
79108
79124
  const taskDefinitionArn = record5(registered.taskDefinition).taskDefinitionArn;
79109
79125
  if (!name(taskDefinitionArn))
@@ -79111,12 +79127,14 @@ async function pairEcsAutomation(input, run4 = runAws3) {
79111
79127
  try {
79112
79128
  await writeFile5(requestFile, JSON.stringify({ ...request, taskDefinition: taskDefinitionArn }), { mode: 384, flag: "wx" });
79113
79129
  input.signal?.throwIfAborted();
79130
+ input.onProgress?.("opening");
79114
79131
  try {
79115
79132
  await input.startPairing();
79116
79133
  } catch {
79117
79134
  throw new Error("automation_ecs_pair_window_failed");
79118
79135
  }
79119
79136
  input.signal?.throwIfAborted();
79137
+ input.onProgress?.("starting");
79120
79138
  const started = await call(["run-task", "--cli-input-json", `file://${requestFile}`], void 0);
79121
79139
  const tasks = items(started.tasks).map(record5);
79122
79140
  if (items(started.failures ?? []).length || tasks.length !== 1 || !name(tasks[0].taskArn))
@@ -79124,6 +79142,7 @@ async function pairEcsAutomation(input, run4 = runAws3) {
79124
79142
  const taskArn = tasks[0].taskArn;
79125
79143
  try {
79126
79144
  input.signal?.throwIfAborted();
79145
+ input.onProgress?.("waiting");
79127
79146
  await run4(["ecs", "wait", "tasks-stopped", "--cluster", target2.cluster, "--tasks", taskArn, "--region", target2.region], input.signal);
79128
79147
  } catch {
79129
79148
  try {
@@ -79133,6 +79152,7 @@ async function pairEcsAutomation(input, run4 = runAws3) {
79133
79152
  }
79134
79153
  throw new Error("automation_ecs_pair_wait_failed");
79135
79154
  }
79155
+ input.onProgress?.("verifying");
79136
79156
  const finished7 = await call(["describe-tasks", "--cluster", target2.cluster, "--tasks", taskArn], input.signal);
79137
79157
  const completed = items(finished7.tasks).map(record5);
79138
79158
  const finalContainers = completed.length === 1 ? items(completed[0].containers).map(record5) : [];
@@ -79140,6 +79160,7 @@ async function pairEcsAutomation(input, run4 = runAws3) {
79140
79160
  throw new Error("automation_ecs_pair_failed");
79141
79161
  return { taskArn, taskDefinitionArn, status: "paired" };
79142
79162
  } finally {
79163
+ input.onProgress?.("cleaning");
79143
79164
  await call(["deregister-task-definition", "--task-definition", taskDefinitionArn], void 0);
79144
79165
  }
79145
79166
  } finally {
@@ -106438,7 +106459,7 @@ var require_dist_cjs11 = __commonJS({
106438
106459
  var { createHash: createHash11, createPrivateKey: createPrivateKey2, createPublicKey, sign: sign3 } = __require("node:crypto");
106439
106460
  var { promises } = __require("node:fs");
106440
106461
  var { homedir: homedir7 } = __require("node:os");
106441
- var { dirname: dirname7, join: join15 } = __require("node:path");
106462
+ var { dirname: dirname7, join: join16 } = __require("node:path");
106442
106463
  var LoginCredentialsFetcher = class _LoginCredentialsFetcher {
106443
106464
  profileData;
106444
106465
  init;
@@ -106602,10 +106623,10 @@ var require_dist_cjs11 = __commonJS({
106602
106623
  await promises.writeFile(tokenFilePath, JSON.stringify(token, null, 2), "utf8");
106603
106624
  }
106604
106625
  getTokenFilePath() {
106605
- const directory = process.env.AWS_LOGIN_CACHE_DIRECTORY ?? join15(homedir7(), ".aws", "login", "cache");
106626
+ const directory = process.env.AWS_LOGIN_CACHE_DIRECTORY ?? join16(homedir7(), ".aws", "login", "cache");
106606
106627
  const loginSessionBytes = Buffer.from(this.loginSession, "utf8");
106607
106628
  const loginSessionSha256 = createHash11("sha256").update(loginSessionBytes).digest("hex");
106608
- return join15(directory, `${loginSessionSha256}.json`);
106629
+ return join16(directory, `${loginSessionSha256}.json`);
106609
106630
  }
106610
106631
  derToRawSignature(derSignature) {
106611
106632
  let offset = 2;
@@ -160529,7 +160550,7 @@ async function promptText(title2) {
160529
160550
  });
160530
160551
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Box_default, { borderStyle: "round", borderColor: "cyan", paddingX: 1, flexDirection: "column", width: 72, children: [
160531
160552
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { bold: true, color: "cyan", children: title2 }),
160532
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { children: value2 || "Type a path, then press enter \xB7 esc to cancel" })
160553
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { children: value2 || "Existing folder or .sh filename \xB7 Enter uses default \xB7 Esc cancels" })
160533
160554
  ] });
160534
160555
  }
160535
160556
  const instance = render_default(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Input, {}), { exitOnCtrlC: false });
@@ -160665,15 +160686,15 @@ var require_windows = __commonJS({
160665
160686
  }
160666
160687
  return false;
160667
160688
  }
160668
- function checkStat(stat6, path9, options) {
160669
- if (!stat6.isSymbolicLink() && !stat6.isFile()) {
160689
+ function checkStat(stat7, path9, options) {
160690
+ if (!stat7.isSymbolicLink() && !stat7.isFile()) {
160670
160691
  return false;
160671
160692
  }
160672
160693
  return checkPathExt(path9, options);
160673
160694
  }
160674
160695
  function isexe(path9, options, cb2) {
160675
- fs13.stat(path9, function(er5, stat6) {
160676
- cb2(er5, er5 ? false : checkStat(stat6, path9, options));
160696
+ fs13.stat(path9, function(er5, stat7) {
160697
+ cb2(er5, er5 ? false : checkStat(stat7, path9, options));
160677
160698
  });
160678
160699
  }
160679
160700
  function sync(path9, options) {
@@ -160689,20 +160710,20 @@ var require_mode = __commonJS({
160689
160710
  isexe.sync = sync;
160690
160711
  var fs13 = __require("fs");
160691
160712
  function isexe(path9, options, cb2) {
160692
- fs13.stat(path9, function(er5, stat6) {
160693
- cb2(er5, er5 ? false : checkStat(stat6, options));
160713
+ fs13.stat(path9, function(er5, stat7) {
160714
+ cb2(er5, er5 ? false : checkStat(stat7, options));
160694
160715
  });
160695
160716
  }
160696
160717
  function sync(path9, options) {
160697
160718
  return checkStat(fs13.statSync(path9), options);
160698
160719
  }
160699
- function checkStat(stat6, options) {
160700
- return stat6.isFile() && checkMode(stat6, options);
160720
+ function checkStat(stat7, options) {
160721
+ return stat7.isFile() && checkMode(stat7, options);
160701
160722
  }
160702
- function checkMode(stat6, options) {
160703
- var mod = stat6.mode;
160704
- var uid = stat6.uid;
160705
- var gid = stat6.gid;
160723
+ function checkMode(stat7, options) {
160724
+ var mod = stat7.mode;
160725
+ var uid = stat7.uid;
160726
+ var gid = stat7.gid;
160706
160727
  var myUid = options.uid !== void 0 ? options.uid : process.getuid && process.getuid();
160707
160728
  var myGid = options.gid !== void 0 ? options.gid : process.getgid && process.getgid();
160708
160729
  var u10 = parseInt("100", 8);
@@ -174306,7 +174327,7 @@ function isExplicitAutomationDenial(error2) {
174306
174327
  const value2 = error2;
174307
174328
  return ["governance_denied", "reveal_denied"].includes(String(value2?.code ?? value2?.message ?? ""));
174308
174329
  }
174309
- function messageFor(error2, business = false) {
174330
+ function messageFor(error2, business = false, automationCommand) {
174310
174331
  if (error2 instanceof OrganizationChoiceRequired) return error2.message;
174311
174332
  if (error2 instanceof CliConfigurationInvalid) return error2.message;
174312
174333
  if (error2 instanceof UsePlanInvalid) return error2.message;
@@ -174332,11 +174353,29 @@ function messageFor(error2, business = false) {
174332
174353
  if (code === "plan_share_reconstruction_failed" && typeof reason === "string") {
174333
174354
  return RECONSTRUCTION_MESSAGES[reason] ?? MESSAGES.plan_share_reconstruction_failed;
174334
174355
  }
174335
- if (typeof code === "string") return MESSAGES[code] ?? code;
174356
+ if (typeof code === "string") return MESSAGES[code] ?? (automationCommand ? `Automations ${automationCommand} failed (${/^automation_[a-z0-9_]+$/u.test(code) ? code : "unrecognized error code"}). Check the command inputs and provider access.` : code);
174336
174357
  const message2 = error2?.message;
174337
174358
  if (typeof message2 === "string" && Object.hasOwn(MESSAGES, message2)) return MESSAGES[message2];
174359
+ if (automationCommand) {
174360
+ if (typeof message2 === "string" && /^Docker (?:build|image|run|push) failed\. Check Docker access, the Dockerfile, and registry sign-in\.$/u.test(message2)) return message2;
174361
+ if (typeof message2 === "string" && /^Could not add Inheriti CLI to the image\. Its final stage needs npm, Node\.js and a shell(?:; this CLI version must also be published on npm)?\.$/u.test(message2)) return message2;
174362
+ const known = {
174363
+ "Authentication required": "Sign in again before managing automation.",
174364
+ "Invalid Business API response": "Business returned an invalid automation response. Check the service status before retrying.",
174365
+ "Invalid CLI version": "The CLI version is invalid. Install a published channel version and retry.",
174366
+ "Invalid verified GitHub release": "Business returned invalid verified release metadata. Check the integration release.",
174367
+ "Invalid GitHub workflow input": "The GitHub workflow reference or release input is invalid. Check the repository, file and branch.",
174368
+ "Docker CLI is required. Install Docker and start it before building the image.": "Docker CLI is required. Install Docker and start it before building the image."
174369
+ };
174370
+ return typeof message2 === "string" && known[message2] ? known[message2] : `Automations ${automationCommand} failed unexpectedly. Check the selected organisation, provider access and workload status before retrying.`;
174371
+ }
174338
174372
  return typeof name2 === "string" && name2 !== "Error" ? MESSAGES[name2] ?? name2 : "The command failed.";
174339
174373
  }
174374
+ function providerDiagnosticFor(error2) {
174375
+ const descriptor = error2 && typeof error2 === "object" ? Object.getOwnPropertyDescriptor(error2, "providerDiagnostic") : void 0;
174376
+ const value2 = descriptor?.value;
174377
+ return descriptor?.enumerable === false && typeof value2 === "string" && /^(?:AWS|gcloud) CLI: \S/u.test(value2) ? value2 : void 0;
174378
+ }
174340
174379
  function planCreationFailureMessage(stage, error2) {
174341
174380
  const status = error2?.status;
174342
174381
  if (status === 401) return MESSAGES.operator_reauthentication_required;
@@ -174394,6 +174433,48 @@ var MESSAGES = {
174394
174433
  automation_setup_authentication_required: "Sign in again to manage automation.",
174395
174434
  automation_setup_permission_denied: "You cannot manage automation for this organisation or plan.",
174396
174435
  automation_setup_request_failed: "Business did not accept this automation request. Check your access and entries.",
174436
+ automation_cloud_target_invalid: "The cloud workload or its configuration could not be read. Check the region, project or cluster, workload name and access.",
174437
+ automation_cloud_container_ambiguous: "The workload has multiple containers. Select the application container with --container.",
174438
+ automation_cloud_identity_invalid: "The workload identity is missing or invalid. Check its service account or ECS task role.",
174439
+ automation_cloud_inspection_failed: "The cloud CLI could not inspect the workload. Check local provider access and the target identifiers.",
174440
+ automation_cloud_preview_invalid: "The runtime preview is invalid. Check the launcher path and environment variable names.",
174441
+ automation_cloud_apply_target_changed: "The Cloud Run workload changed since preview. Inspect it and preview again.",
174442
+ automation_cloud_apply_input_invalid: "The Cloud Run deployment inputs are invalid. Check the image, service and launcher.",
174443
+ automation_cloud_apply_environment_conflict: "A Cloud Run environment variable conflicts with an existing value. Review the mappings before applying.",
174444
+ automation_cloud_apply_existing_wrapper_conflict: "Cloud Run already has a different startup wrapper. Review its command before applying.",
174445
+ automation_ecs_input_invalid: "The ECS deployment inputs are invalid. Check the service, image, launcher and mappings.",
174446
+ automation_ecs_response_invalid: "AWS returned an unexpected ECS response. Inspect the service before retrying.",
174447
+ automation_ecs_service_invalid: "The ECS service is unavailable or is not using the expected task definition. Check the cluster, service and region.",
174448
+ automation_ecs_identity_changed: "The ECS task role changed since verification. Inspect the connection and service before retrying.",
174449
+ automation_ecs_revision_changed: "The ECS task definition changed since preview. Preview the current revision before applying.",
174450
+ automation_ecs_container_ambiguous: "The ECS task has multiple containers. Select the application container with --container.",
174451
+ automation_ecs_registration_invalid: "AWS did not return a usable ECS task definition revision. Inspect the service before retrying.",
174452
+ automation_ecs_environment_conflict: "An ECS environment variable conflicts with an existing value. Review the mappings before applying.",
174453
+ automation_ecs_existing_setup_conflict: "The ECS task already has a different automation launcher. Review its entry point before applying.",
174454
+ automation_ecs_deployment_unstable: "The ECS deployment did not become stable. Inspect the service events and task health before retrying.",
174455
+ automation_ecs_provider_failed: "AWS CLI could not complete the ECS operation. Check local AWS access, ECS permissions and service events.",
174456
+ automation_ecs_pair_source_invalid: "The ECS task definition cannot be copied for pairing. Check its task role and container configuration.",
174457
+ automation_ec2_pair_invocation_pending: "The EC2 pairing command is still running in Systems Manager. Check its command status before retrying.",
174458
+ automation_provider_invalid: "Choose a supported automation provider.",
174459
+ automation_provider_trust_invalid: "The provider trust details are invalid. Check the workload identity and connection settings.",
174460
+ automation_runtime_provider_invalid: "The runtime provider does not match the selected connection.",
174461
+ automation_runtime_provider_unsupported: "This automation provider does not support runtime setup.",
174462
+ automation_runtime_trust_invalid: "The runtime identity does not match the verified connection.",
174463
+ automation_runtime_input_invalid: "The runtime setup inputs are invalid. Check the plan, image and target.",
174464
+ automation_mapping_selection_invalid: "Choose valid plan fields and unique environment variable names for the mapping.",
174465
+ automation_aws_account_mismatch: "The AWS account does not match the selected publication target. Check your AWS CLI identity and account ID.",
174466
+ automation_aws_parameter_key_unknown: "An AWS parameter key is not part of the selected field mapping. Preview the mappings again.",
174467
+ automation_aws_parameter_type_invalid: "The AWS parameter type is unsupported for this publication. Check the destination.",
174468
+ automation_aws_provider_failed: "AWS CLI could not publish the values. Check local AWS access and target permissions.",
174469
+ automation_aws_publication_canceled: "AWS publication was canceled before completion. Inspect the destination before retrying.",
174470
+ automation_aws_publisher_input_invalid: "The AWS publication inputs are invalid. Check the target, account and field mappings.",
174471
+ automation_aws_secret_format_invalid: "The existing AWS secret has an incompatible format. Choose a compatible target.",
174472
+ automation_aws_secret_promotion_failed: "AWS could not promote the new secret version. Inspect versions before retrying.",
174473
+ automation_aws_secret_replica: "The selected AWS secret is a replica. Publish to its primary secret.",
174474
+ automation_aws_secret_rotation_enabled: "The selected AWS secret has rotation enabled. Review its rotation policy before publishing.",
174475
+ automation_aws_secret_service_managed: "The selected AWS secret is managed by another service. Choose a secret you control.",
174476
+ automation_aws_secret_version_changed: "The AWS secret version changed since preview. Preview again before publishing.",
174477
+ automation_aws_secret_version_unknown: "The AWS secret version could not be confirmed. Inspect versions before retrying.",
174397
174478
  aws_cli_required: "AWS CLI is required for this command. Install it and make sure aws is on your PATH.",
174398
174479
  aws_authentication_required: "AWS CLI has no valid credentials. Authenticate locally, then retry this command.",
174399
174480
  gcloud_cli_required: "Google Cloud CLI is required for this command. Install it and make sure gcloud is on your PATH.",
@@ -174452,6 +174533,7 @@ var MESSAGES = {
174452
174533
  automation_ecs_running_image_unavailable: "No matching running ECS task has a single confirmed image digest. Wait for the service deployment to finish, or pass --image IMAGE@sha256:DIGEST.",
174453
174534
  automation_ecs_pair_service_invalid: "The ECS service is unavailable or its task definition changed. Inspect it again.",
174454
174535
  automation_ecs_pair_identity_changed: "The ECS task role changed. Inspect the service and connection before retrying.",
174536
+ automation_ecs_task_role_missing: "The ECS task definition has no task role (taskRoleArn). Add a task role and update the service; the execution role alone is not enough.",
174455
174537
  automation_ecs_pair_placement_unknown: "The ECS service launch type or capacity provider could not be copied safely.",
174456
174538
  automation_ecs_pair_network_unknown: "The ECS service network settings could not be copied safely.",
174457
174539
  automation_ecs_pair_container_ambiguous: "Select the ECS application container with --container.",
@@ -175154,7 +175236,7 @@ ${tarball ? "The local package is ready as inheriti-cli.tgz in this Docker build
175154
175236
  terminal.write(`
175155
175237
  ECS / Cloud Run container
175156
175238
 
175157
- 1. Add this instruction to your application's final Dockerfile stage (with npm and Node.js):
175239
+ 1. The final Dockerfile stage needs Node.js 22 or later and npm. If it lacks them, use a Node.js base image for that stage, for example FROM node:22-bookworm-slim, while preserving your application's setup. Then add:
175158
175240
  ` + (local || tarball ? `${tarball ? "For this test, use the copied inheriti-cli.tgz; do not commit it." : "Copy the locally built .tgz into your application's Docker build context as inheriti-cli.tgz for this test only; do not commit it."}
175159
175241
  COPY inheriti-cli.tgz /tmp/inheriti-cli.tgz
175160
175242
  RUN npm install --engine-strict --global --prefix /usr/local /tmp/inheriti-cli.tgz \\
@@ -175444,7 +175526,7 @@ async function automationManage(context, configuration, terminal, signal, argv)
175444
175526
  return 1;
175445
175527
  }
175446
175528
  await operations.createConnection({ id: id2, name: options["--name"], provider: provider.value, environment, trust: details });
175447
- terminal.write(`Connection created: ${id2}`);
175529
+ terminal.write(`Connection created: ${options["--name"]} (${id2})`);
175448
175530
  const expectedAudience = AutomationProviderValue.from(provider.value).expectedAudience(id2, details);
175449
175531
  if (expectedAudience) terminal.write(`Expected audience: ${expectedAudience}`);
175450
175532
  return 0;
@@ -175748,8 +175830,8 @@ ${user ? `USER ${user}
175748
175830
  init_node_base2();
175749
175831
  await init_select();
175750
175832
  await init_select();
175751
- import { chmod as chmod4, realpath, writeFile as writeFile13 } from "node:fs/promises";
175752
- import { isAbsolute as isAbsolute3, relative, resolve as resolve11, sep as sep2 } from "node:path";
175833
+ import { chmod as chmod4, realpath, stat as stat6, writeFile as writeFile13 } from "node:fs/promises";
175834
+ import { extname as extname3, isAbsolute as isAbsolute3, join as join15, relative, resolve as resolve11, sep as sep2 } from "node:path";
175753
175835
  var usage2 = [
175754
175836
  "Usage: inheriti automations setup --plan PLAN_ID [--connection CONNECTION_ID]",
175755
175837
  " (--map-all [--except ASSET.FIELD ...] | --only ASSET.FIELD ... | --map NAME=ASSET.FIELD ... | --field ASSET.FIELD --env-name NAME)",
@@ -175893,6 +175975,14 @@ async function automationSetup(context, configuration, terminal, argv) {
175893
175975
  connection,
175894
175976
  mappings
175895
175977
  });
175978
+ const printManualSummary = () => terminal.write(`
175979
+ Prepare ${bundle.provider} startup script
175980
+ Plan: ${options["--plan"]}
175981
+ Connection: ${connection.name} (${connection.id})
175982
+ Plan fields:
175983
+ ${mappings.map((item) => ` ${item.envName} \u2190 ${item.selector}`).join("\n")}
175984
+ Runtime needs: ${bundle.requiredEnvironment.join(", ") || "no additional variables"}
175985
+ The script sets the connection ID and provider. It does not deploy the image or reveal plan values.`);
175896
175986
  if (connection.provider === "PORTABLE") {
175897
175987
  if ([
175898
175988
  "--project",
@@ -175914,16 +176004,11 @@ async function automationSetup(context, configuration, terminal, argv) {
175914
176004
  terminal.writeError(usage2);
175915
176005
  return 1;
175916
176006
  }
175917
- renderJson(terminal, {
175918
- status: "manual_setup_required",
175919
- provider: bundle.provider,
175920
- environment: bundle.environment,
175921
- mappings,
175922
- requiredEnvironment: bundle.requiredEnvironment,
175923
- instructions: bundle.instructions
175924
- });
176007
+ printManualSummary();
175925
176008
  terminal.write("--- Launcher script (save as an executable file) ---");
175926
176009
  terminal.write(bundle.script);
176010
+ terminal.write(`Before deploying:
176011
+ ${bundle.instructions.map((item) => `\u2022 ${item}`).join("\n")}`);
175927
176012
  return 0;
175928
176013
  }
175929
176014
  if (options["--instance"]) {
@@ -175996,32 +176081,36 @@ async function automationSetup(context, configuration, terminal, argv) {
175996
176081
  return 1;
175997
176082
  }
175998
176083
  if (!["--project", "--region", "--job", "--cluster", "--service", "--task-definition", "--container"].some((key) => options[key]) && !applying && !options["--image"] && !options["--expect-revision"]) {
175999
- renderJson(terminal, {
176000
- status: "manual_setup_required",
176001
- provider: bundle.provider,
176002
- environment: bundle.environment,
176003
- mappings,
176004
- requiredEnvironment: bundle.requiredEnvironment,
176005
- instructions: bundle.instructions
176006
- });
176084
+ printManualSummary();
176007
176085
  const choice = options["--save"] ? "save" : terminal.interactive ? await promptSelect("How should the launcher be delivered?", [
176008
- { value: "print", description: "Print script" },
176009
- { value: "save", description: "Save as a file in this app project" }
176086
+ { value: "save", description: "Save startup script in this app project" },
176087
+ { value: "print", description: "Print startup script in terminal" }
176010
176088
  ]) : "print";
176011
176089
  if (!choice) return 1;
176012
176090
  if (choice === "print") {
176013
176091
  terminal.write("--- Launcher script (save as an executable file) ---");
176014
176092
  terminal.write(bundle.script);
176093
+ terminal.write(`Before deploying:
176094
+ ${bundle.instructions.map((item) => `\u2022 ${item}`).join("\n")}`);
176015
176095
  return 0;
176016
176096
  }
176017
- const source = options["--save"] ?? await promptText("Save launcher as (relative to this Docker build context):");
176018
- if (!source || isAbsolute3(source) || source === "." || source === ".." || /[\0\[\]*?]/u.test(source)) {
176019
- terminal.writeError("Choose a relative file path inside the current Docker build context without Docker COPY wildcard characters.");
176097
+ const answer = options["--save"] ?? await promptText("Save in project: folder or .sh file \xB7 Enter uses inheriti-start.sh");
176098
+ if (answer === void 0) return 1;
176099
+ const source = answer.trim() || "inheriti-start.sh";
176100
+ if (isAbsolute3(source) || source === ".." || /[\0\[\]*?]/u.test(source)) {
176101
+ terminal.writeError("Choose a relative folder or .sh file inside the current Docker build context.");
176020
176102
  return 1;
176021
176103
  }
176022
176104
  try {
176023
176105
  const base = await realpath(process.cwd());
176024
- const destination = resolve11(base, source);
176106
+ const selected = resolve11(base, source);
176107
+ const existing = await stat6(selected).catch(() => void 0);
176108
+ const folder = source === "." || source.endsWith("/") || !extname3(source) || existing?.isDirectory();
176109
+ if (folder && !existing?.isDirectory()) {
176110
+ terminal.writeError("That folder does not exist. Create it first, or enter a .sh filename in this project.");
176111
+ return 1;
176112
+ }
176113
+ const destination = folder ? join15(selected, "inheriti-start.sh") : selected;
176025
176114
  const inside = relative(base, destination);
176026
176115
  const parent = relative(base, await realpath(resolve11(destination, "..")));
176027
176116
  if (!inside || inside.startsWith(`..${sep2}`) || inside === ".." || isAbsolute3(inside) || parent.startsWith(`..${sep2}`) || parent === ".." || isAbsolute3(parent)) {
@@ -176032,14 +176121,20 @@ async function automationSetup(context, configuration, terminal, argv) {
176032
176121
  `, { flag: "wx", mode: 493 });
176033
176122
  await chmod4(destination, 493);
176034
176123
  const dockerSource = `./${inside.split(sep2).join("/")}`;
176035
- terminal.write(`Saved launcher: ${inside}`);
176036
- terminal.write("Add to your Dockerfile:");
176124
+ terminal.write(`
176125
+ Saved startup script: ${inside}
176126
+ This shell script (.sh) starts your app through Inheriti; keep it in your Docker build context.
176127
+
176128
+ 1. Add these lines to your Dockerfile:`);
176037
176129
  terminal.write(`COPY ${JSON.stringify([dockerSource, "/usr/local/bin/inheriti-automation"])}`);
176038
176130
  terminal.write("RUN chmod +x /usr/local/bin/inheriti-automation");
176039
176131
  terminal.write('ENTRYPOINT ["/usr/local/bin/inheriti-automation"]');
176040
- terminal.write("Keep the complete application executable and arguments in image CMD, ECS command, or Cloud Run args. Remove any ECS entryPoint or Cloud Run command override that bypasses this launcher (or set it to the launcher). Then deploy with your usual pipeline.");
176132
+ terminal.write("\n2. Keep your app executable and arguments in image CMD, ECS command, or Cloud Run args. Remove any ECS entryPoint or Cloud Run command override that bypasses this script.\n3. Build and deploy the updated image with your usual pipeline.");
176133
+ terminal.write(`
176134
+ Before deploying:
176135
+ ${bundle.instructions.map((item) => `\u2022 ${item}`).join("\n")}`);
176041
176136
  } catch (error2) {
176042
- terminal.writeError(`Could not save launcher: ${error2 instanceof Error ? error2.message : String(error2)}`);
176137
+ terminal.writeError(error2.code === "EEXIST" ? "The startup script already exists. Choose a different filename or folder; no file was replaced." : `Could not save startup script: ${error2 instanceof Error ? error2.message : String(error2)}`);
176043
176138
  return 1;
176044
176139
  }
176045
176140
  return 0;
@@ -176165,23 +176260,53 @@ async function pairAwsAutomationService(context, configuration, terminal, argv,
176165
176260
  ], signal);
176166
176261
  if (choice !== "run") return 1;
176167
176262
  }
176168
- const result = await pairEcsAutomation({
176169
- target: target2,
176170
- expectedRevision: inspected.revision,
176171
- expectedRoleArn: connection.trust.roleArn,
176172
- image: image2,
176173
- cliPath: options["--cli-path"] ?? "/usr/local/bin/inheriti",
176174
- environment: {
176175
- INHERITI_AUTOMATION_PROVIDER: "AWS",
176176
- INHERITI_AUTOMATION_CONNECTION_ID: connection.id,
176177
- AWS_REGION: target2.region
176178
- },
176179
- startPairing: async () => {
176180
- await operations.startPairing(connection.id);
176181
- },
176182
- ...signal ? { signal } : {}
176183
- });
176184
- const verified = await operations.getConnection(connection.id);
176263
+ const region = terminal.createLiveRegion?.();
176264
+ const started = Date.now();
176265
+ let phase = "Checking ECS service";
176266
+ let tick = 0;
176267
+ const draw = () => region?.update(`${["\u280B", "\u2819", "\u2839", "\u2838"][tick++ % 4]} ${phase} \xB7 ${Math.floor((Date.now() - started) / 1e3)}s`);
176268
+ const report = (next) => {
176269
+ phase = next;
176270
+ draw();
176271
+ };
176272
+ const timer = region ? setInterval(draw, 180) : void 0;
176273
+ timer?.unref();
176274
+ draw();
176275
+ let result;
176276
+ let verified;
176277
+ try {
176278
+ result = await pairEcsAutomation({
176279
+ target: target2,
176280
+ expectedRevision: inspected.revision,
176281
+ expectedRoleArn: connection.trust.roleArn,
176282
+ image: image2,
176283
+ cliPath: options["--cli-path"] ?? "/usr/local/bin/inheriti",
176284
+ environment: {
176285
+ INHERITI_AUTOMATION_PROVIDER: "AWS",
176286
+ INHERITI_AUTOMATION_CONNECTION_ID: connection.id,
176287
+ AWS_REGION: target2.region
176288
+ },
176289
+ startPairing: async () => {
176290
+ await operations.startPairing(connection.id);
176291
+ },
176292
+ onProgress: (value2) => report({
176293
+ checking: "Checking ECS service",
176294
+ registering: "Registering temporary task",
176295
+ opening: "Opening pairing window",
176296
+ starting: "Starting temporary task",
176297
+ waiting: "Waiting for ECS task to stop",
176298
+ verifying: "Verifying task result",
176299
+ cleaning: "Removing temporary task definition"
176300
+ }[value2]),
176301
+ ...signal ? { signal } : {}
176302
+ });
176303
+ report("Confirming connection in Business");
176304
+ verified = await operations.getConnection(connection.id);
176305
+ } finally {
176306
+ if (timer) clearInterval(timer);
176307
+ region?.update("");
176308
+ region?.close();
176309
+ }
176185
176310
  if (verified.status !== "VERIFIED") {
176186
176311
  terminal.writeError("The ECS task finished, but Business has not confirmed the connection. Check its status before proceeding.");
176187
176312
  return 1;
@@ -176889,8 +177014,8 @@ var PortableIdentity = class extends AutomationIdentity {
176889
177014
  const file2 = await open3(path9, constants7.O_RDONLY | constants7.O_NOFOLLOW);
176890
177015
  let bytes;
176891
177016
  try {
176892
- const stat6 = await file2.stat();
176893
- if (!stat6.isFile() || stat6.nlink !== 1 || stat6.size > 4096 || (stat6.mode & 63) !== 0 || stat6.uid !== process.getuid?.())
177017
+ const stat7 = await file2.stat();
177018
+ if (!stat7.isFile() || stat7.nlink !== 1 || stat7.size > 4096 || (stat7.mode & 63) !== 0 || stat7.uid !== process.getuid?.())
176894
177019
  throw new Error("automation_portable_key_permissions_invalid");
176895
177020
  bytes = await file2.readFile();
176896
177021
  const key = createPrivateKey(bytes);
@@ -177219,7 +177344,7 @@ Preview target metadata by default. --apply reveals selected text fields and pub
177219
177344
  Preview one Google Cloud Secret Manager target per selected field. --apply publishes new versions only to new or Inheriti-managed secrets. Requires Application Default Credentials and Secret Manager permissions. Subsequent reads use Google Cloud IAM; plan changes or revocation do not update or delete these copies. No automatic synchronization or rotation.`,
177220
177345
  "automations setup": `Usage: inheriti automations setup --plan PLAN_ID [--connection CONNECTION_ID] (--map-all [--except ASSET.FIELD ...] | --only ASSET.FIELD ... | --map NAME=ASSET.FIELD ... | --field ASSET.FIELD --env-name NAME) [--project PROJECT --region REGION (--job JOB | --service SERVICE) | --region REGION --cluster CLUSTER (--service SERVICE | --task-definition ARN) | --region REGION --instance INSTANCE_ID --service-name NAME --run-as-user USER [--install [--replace]] -- APP_COMMAND [ARGS...]] [--container NAME] [--script-path ABSOLUTE_PATH] [--cli-path ABSOLUTE_PATH] [--save RELATIVE_PATH] [--apply --image IMAGE_TAG_OR_DIGEST [--expect-revision REVISION]]
177221
177346
 
177222
- Prepare a Cloud Run, ECS, EC2, or custom runner launch script for a verified connection and active plan grant. Use --map-all or repeatable --only for generated names; --except omits fields from --map-all. Repeat --map to rename a generated variable or map fields explicitly. Review mappings before applying. Without a managed target, choose Print or Save as. --save writes a new executable launcher in the current Docker build context and prints matching Dockerfile COPY and ENTRYPOINT lines. Managed cloud targets require an exact target. The CLI path inside the image defaults to /usr/local/bin/inheriti; use --cli-path for a different absolute path. By default this prints a safe preview and script. For EC2, --install writes the launcher and systemd unit via SSM after confirmation, without starting the service. Use --install --replace to update a stopped, matching installation; it also upgrades the previous generated unit. To update an existing Cloud Run job, service, or ECS service, first build and publish an image containing the CLI, then use --apply with its ECR or Artifact Registry tag or immutable digest and the revision from the preview. In an interactive terminal, review the safe preview and confirm instead of passing a revision. It does not build or publish images. Mount any private key only on the custom runner. Never pass secret values as flags.`,
177347
+ Prepare a Cloud Run, ECS, EC2, or custom runner launch script for a verified connection and active plan grant. Use --map-all or repeatable --only for generated names; --except omits fields from --map-all. Repeat --map to rename a generated variable or map fields explicitly. Review mappings before applying. Without a managed target, choose Print or Save as. Enter accepts the default inheriti-start.sh filename; an existing folder saves that file inside it. --save writes a new executable launcher in the current Docker build context and prints matching Dockerfile COPY and ENTRYPOINT lines. Managed cloud targets require an exact target. The CLI path inside the image defaults to /usr/local/bin/inheriti; use --cli-path for a different absolute path. By default this prints a safe preview and script. For EC2, --install writes the launcher and systemd unit via SSM after confirmation, without starting the service. Use --install --replace to update a stopped, matching installation; it also upgrades the previous generated unit. To update an existing Cloud Run job, service, or ECS service, first build and publish an image containing the CLI, then use --apply with its ECR or Artifact Registry tag or immutable digest and the revision from the preview. In an interactive terminal, review the safe preview and confirm instead of passing a revision. It does not build or publish images. Mount any private key only on the custom runner. Never pass secret values as flags.`,
177223
177348
  "automations grant": `Usage: inheriti automations grant create|activate|member|revoke [--plan PLAN_ID] [--id GRANT_ID] [--grant GRANT_ID] [--connection CONNECTION_ID] [--member MEMBER_ID]
177224
177349
 
177225
177350
  Create accepts --id and requires connection and responsible member; activate/revoke require grant; member also requires a new responsible member. Missing IDs can be selected in a terminal.`,
@@ -177983,7 +178108,10 @@ async function run3(argv, environmentVariables, terminal) {
177983
178108
  return 1;
177984
178109
  } catch (error2) {
177985
178110
  if (command7 === "__complete") return 0;
177986
- terminal.writeError(messageFor(error2, routing.business));
178111
+ const automationCommand = command7 === "secrets" && rest[0] === "publish" ? "publish" : command7 === "automations" ? ["create", "setup", "pair", "grant", "runtime", "list", "grants", "usage", "verify", "trust", "disable"].includes(rest[0] ?? "") ? rest[0] : "command" : void 0;
178112
+ const providerDiagnostic = automationCommand && providerDiagnosticFor(error2);
178113
+ terminal.writeError(messageFor(error2, routing.business, automationCommand) + (providerDiagnostic ? `
178114
+ ${providerDiagnostic}` : ""));
177987
178115
  return automationSecretDelivery && isExplicitAutomationDenial(error2) ? 77 : 1;
177988
178116
  }
177989
178117
  }