@indigoai-us/hq-cloud 6.18.107 → 6.18.109

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 (118) hide show
  1. package/dist/bin/sync-runner-company.d.ts +1 -0
  2. package/dist/bin/sync-runner-company.d.ts.map +1 -1
  3. package/dist/bin/sync-runner-company.js +29 -8
  4. package/dist/bin/sync-runner-company.js.map +1 -1
  5. package/dist/bin/sync-runner-manifest.d.ts +27 -0
  6. package/dist/bin/sync-runner-manifest.d.ts.map +1 -1
  7. package/dist/bin/sync-runner-manifest.js +104 -0
  8. package/dist/bin/sync-runner-manifest.js.map +1 -1
  9. package/dist/bin/sync-runner-planning.d.ts +48 -0
  10. package/dist/bin/sync-runner-planning.d.ts.map +1 -1
  11. package/dist/bin/sync-runner-planning.js +140 -0
  12. package/dist/bin/sync-runner-planning.js.map +1 -1
  13. package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
  14. package/dist/bin/sync-runner-watch-loop.js +8 -2
  15. package/dist/bin/sync-runner-watch-loop.js.map +1 -1
  16. package/dist/bin/sync-runner.d.ts +1 -0
  17. package/dist/bin/sync-runner.d.ts.map +1 -1
  18. package/dist/bin/sync-runner.js +24 -1
  19. package/dist/bin/sync-runner.js.map +1 -1
  20. package/dist/cli/rescue-core.d.ts +64 -1
  21. package/dist/cli/rescue-core.d.ts.map +1 -1
  22. package/dist/cli/rescue-core.js +272 -125
  23. package/dist/cli/rescue-core.js.map +1 -1
  24. package/dist/cli/rescue-git.d.ts +47 -0
  25. package/dist/cli/rescue-git.d.ts.map +1 -0
  26. package/dist/cli/rescue-git.js +126 -0
  27. package/dist/cli/rescue-git.js.map +1 -0
  28. package/dist/cli/rescue-native-copy.d.ts +88 -0
  29. package/dist/cli/rescue-native-copy.d.ts.map +1 -0
  30. package/dist/cli/rescue-native-copy.js +823 -0
  31. package/dist/cli/rescue-native-copy.js.map +1 -0
  32. package/dist/cli/rescue-snapshot.d.ts +22 -0
  33. package/dist/cli/rescue-snapshot.d.ts.map +1 -1
  34. package/dist/cli/rescue-snapshot.js +27 -0
  35. package/dist/cli/rescue-snapshot.js.map +1 -1
  36. package/dist/cli/rescue.d.ts +21 -1
  37. package/dist/cli/rescue.d.ts.map +1 -1
  38. package/dist/cli/rescue.js +68 -2
  39. package/dist/cli/rescue.js.map +1 -1
  40. package/dist/cli/share.d.ts +14 -0
  41. package/dist/cli/share.d.ts.map +1 -1
  42. package/dist/cli/share.js +19 -8
  43. package/dist/cli/share.js.map +1 -1
  44. package/dist/cli/sync.d.ts +8 -0
  45. package/dist/cli/sync.d.ts.map +1 -1
  46. package/dist/cli/sync.js +5 -5
  47. package/dist/cli/sync.js.map +1 -1
  48. package/dist/cognito-auth.d.ts +57 -0
  49. package/dist/cognito-auth.d.ts.map +1 -1
  50. package/dist/cognito-auth.js +182 -3
  51. package/dist/cognito-auth.js.map +1 -1
  52. package/dist/ignore.d.ts +5 -1
  53. package/dist/ignore.d.ts.map +1 -1
  54. package/dist/ignore.js +32 -2
  55. package/dist/ignore.js.map +1 -1
  56. package/dist/index.d.ts +3 -2
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +6 -1
  59. package/dist/index.js.map +1 -1
  60. package/dist/manifest/leg-skip-store.d.ts +59 -0
  61. package/dist/manifest/leg-skip-store.d.ts.map +1 -0
  62. package/dist/manifest/leg-skip-store.js +140 -0
  63. package/dist/manifest/leg-skip-store.js.map +1 -0
  64. package/dist/manifest/upload-manifest.d.ts +11 -0
  65. package/dist/manifest/upload-manifest.d.ts.map +1 -1
  66. package/dist/manifest/upload-manifest.js +30 -1
  67. package/dist/manifest/upload-manifest.js.map +1 -1
  68. package/dist/manifest-folder-alias.d.ts +70 -0
  69. package/dist/manifest-folder-alias.d.ts.map +1 -0
  70. package/dist/manifest-folder-alias.js +139 -0
  71. package/dist/manifest-folder-alias.js.map +1 -0
  72. package/dist/manifest-reconcile.d.ts +5 -0
  73. package/dist/manifest-reconcile.d.ts.map +1 -1
  74. package/dist/manifest-reconcile.js +14 -2
  75. package/dist/manifest-reconcile.js.map +1 -1
  76. package/dist/outposts/billing.d.ts +0 -2
  77. package/dist/outposts/billing.d.ts.map +1 -1
  78. package/dist/outposts/billing.js +0 -2
  79. package/dist/outposts/billing.js.map +1 -1
  80. package/dist/outposts/cli-billing.d.ts +8 -2
  81. package/dist/outposts/cli-billing.d.ts.map +1 -1
  82. package/dist/outposts/cli-billing.js +13 -8
  83. package/dist/outposts/cli-billing.js.map +1 -1
  84. package/dist/outposts/client.d.ts +6 -3
  85. package/dist/outposts/client.d.ts.map +1 -1
  86. package/dist/outposts/client.js +12 -8
  87. package/dist/outposts/client.js.map +1 -1
  88. package/dist/outposts/command.d.ts +30 -0
  89. package/dist/outposts/command.d.ts.map +1 -1
  90. package/dist/outposts/command.js +79 -13
  91. package/dist/outposts/command.js.map +1 -1
  92. package/dist/outposts/company-outposts.d.ts +2 -2
  93. package/dist/outposts/company-outposts.d.ts.map +1 -1
  94. package/dist/outposts/company-outposts.js +5 -4
  95. package/dist/outposts/company-outposts.js.map +1 -1
  96. package/dist/outposts/hq-pro-routes.d.ts +15 -0
  97. package/dist/outposts/hq-pro-routes.d.ts.map +1 -0
  98. package/dist/outposts/hq-pro-routes.js +21 -0
  99. package/dist/outposts/hq-pro-routes.js.map +1 -0
  100. package/dist/outposts/index.d.ts +3 -1
  101. package/dist/outposts/index.d.ts.map +1 -1
  102. package/dist/outposts/index.js +2 -1
  103. package/dist/outposts/index.js.map +1 -1
  104. package/dist/outposts/sizes.d.ts +56 -0
  105. package/dist/outposts/sizes.d.ts.map +1 -0
  106. package/dist/outposts/sizes.js +120 -0
  107. package/dist/outposts/sizes.js.map +1 -0
  108. package/dist/outposts/types.d.ts +3 -0
  109. package/dist/outposts/types.d.ts.map +1 -1
  110. package/dist/outposts/types.js +0 -11
  111. package/dist/outposts/types.js.map +1 -1
  112. package/dist/sync/pull-scope.d.ts +1 -1
  113. package/dist/sync/pull-scope.d.ts.map +1 -1
  114. package/dist/sync/pull-scope.js +8 -3
  115. package/dist/sync/pull-scope.js.map +1 -1
  116. package/dist/types.d.ts +7 -0
  117. package/dist/types.d.ts.map +1 -1
  118. package/package.json +1 -1
@@ -261,15 +261,72 @@ export interface MachineCreds {
261
261
  hostKeyPath?: string;
262
262
  /** hq-pro control-plane origin an external agent mints through. */
263
263
  apiBaseUrl?: string;
264
+ /**
265
+ * True when this identity comes from a delegated session file
266
+ * (`HQ_MACHINE_SESSION_FILE`) rather than a credentials file. `secret` is
267
+ * empty: the process holds tokens a trusted parent minted, never the
268
+ * long-lived machine secret, and it can never mint on its own.
269
+ */
270
+ delegated?: true;
264
271
  }
265
272
  export type MachineRuntime = "hosted" | "external";
266
273
  /** Default hq-pro control plane (HQ_VAULT_API_URL overrides). */
267
274
  export declare const DEFAULT_MACHINE_API_BASE_URL = "https://hqapi.hq.computer";
268
275
  /** Resolve the machine-creds file path (HQ_MACHINE_CREDS_FILE overrides). */
269
276
  export declare function machineCredsFilePath(): string;
277
+ /**
278
+ * Env var naming a delegated machine session file.
279
+ *
280
+ * A trusted parent that holds the machine credentials (the company Outpost
281
+ * job runner, root) mints tokens and writes them here for a child that must
282
+ * act as the same machine identity without ever holding the long-lived
283
+ * secret. The child re-reads the file on every token request, so the parent
284
+ * can refresh it in place while the child runs. The file is a JSON document
285
+ * from {@link delegatedMachineSessionDocument}.
286
+ *
287
+ * While this env is set it is the whole identity decision: no credentials
288
+ * file is consulted, so an unusable session file means no machine identity
289
+ * (and, in required-machine mode, no person fallback either). Set it only
290
+ * for the child that should hold this session.
291
+ */
292
+ export declare const DELEGATED_MACHINE_SESSION_ENV = "HQ_MACHINE_SESSION_FILE";
293
+ export declare const DELEGATED_MACHINE_SESSION_VERSION = 1;
294
+ export interface DelegatedMachineSession {
295
+ version: 1;
296
+ entityType: "company-outpost";
297
+ entityUid: string;
298
+ username: string;
299
+ clientId: string;
300
+ region: string;
301
+ idToken: string;
302
+ accessToken: string;
303
+ /** Epoch milliseconds when the tokens expire. */
304
+ expiresAt: number;
305
+ /** Epoch milliseconds when the parent wrote this document. */
306
+ issuedAt: number;
307
+ }
308
+ /** Path of the delegated session file, or null when none is configured. */
309
+ export declare function delegatedMachineSessionFilePath(): string | null;
310
+ /**
311
+ * Build the document a parent writes to the delegated session file. Only
312
+ * tokens and identity bindings go in; the machine secret never does.
313
+ */
314
+ export declare function delegatedMachineSessionDocument(creds: Pick<MachineCreds, "username" | "clientId" | "region" | "entityType" | "entityUid">, tokens: Pick<CognitoTokens, "idToken" | "accessToken" | "expiresAt">, now?: number): DelegatedMachineSession;
315
+ /**
316
+ * Read and validate the delegated session file, or null when none is
317
+ * configured or the file is unreadable, malformed, or inconsistent with
318
+ * itself. Expiry is not checked here: an expired session is still this
319
+ * identity (so required-machine mode never falls back to a person), and
320
+ * {@link getValidMachineTokens} reports the expiry with the file path.
321
+ */
322
+ export declare function loadDelegatedMachineSession(): DelegatedMachineSession | null;
270
323
  /**
271
324
  * Load machine credentials, or null when this process is not running as a
272
325
  * machine identity (no creds file / unreadable / malformed).
326
+ *
327
+ * A delegated session file (`HQ_MACHINE_SESSION_FILE`) takes precedence over
328
+ * a credentials file: the parent that set it chose this identity for the
329
+ * child explicitly.
273
330
  */
274
331
  export declare function loadMachineCreds(): MachineCreds | null;
275
332
  /** True when the creds describe an external (host-key signed) agent. */
@@ -1 +1 @@
1
- {"version":3,"file":"cognito-auth.d.ts","sourceRoot":"","sources":["../src/cognito-auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAcH,MAAM,WAAW,iBAAiB;IAChC,4DAA4D;IAC5D,MAAM,EAAE,MAAM,CAAC;IACf,oEAAoE;IACpE,cAAc,EAAE,MAAM,CAAC;IACvB,yDAAyD;IACzD,QAAQ,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IA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cAAc,CAAC;IAC7B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,MAAM,mBAAmB,GAC3B,KAAK,GACL,MAAM,GACN,QAAQ,GACR,gBAAgB,GAChB,yBAAyB,GACzB,UAAU,CAAC;AAkBf,qFAAqF;AACrF,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAAG,IAAI,GAAG,IAAI,CAG9F;AAMD,wBAAgB,wBAAwB,CAAC,IAAI,GAAE,mBAAwB,GAAG,OAAO,CAShF;AAED,wBAAgB,uBAAuB,CAAC,IAAI,GAAE,MAAqB,GAAG,MAAM,CAE3E;AAED,wBAAgB,uBAAuB,CAAC,IAAI,GAAE,MAAqB,GAAG,mBAAmB,CAOxF;AAyBD;;;;GAIG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,GAAE,mBAAwB,GAC7B;IAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,OAAO,EAAE,mBAAmB,CAAA;CAAE,CA0CvD;AAED,wBAAgB,qBAAqB,CAAC,IAAI,GAAE,mBAAwB,GAAG,MAAM,GAAG,IAAI,CAEnF;AAED,UAAU,eAAe;IACvB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7B;AAYD,oEAAoE;AACpE,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,eAAe,EAAE,YAAY,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,IAAI,CAI7G"}
@@ -926,11 +926,180 @@ export function machineCredsFilePath() {
926
926
  return (process.env.HQ_MACHINE_CREDS_FILE ??
927
927
  path.join(os.homedir(), ".hq-agent", "machine-creds.json"));
928
928
  }
929
+ // ---------------------------------------------------------------------------
930
+ // Delegated machine session (HQ_MACHINE_SESSION_FILE)
931
+ // ---------------------------------------------------------------------------
932
+ /**
933
+ * Env var naming a delegated machine session file.
934
+ *
935
+ * A trusted parent that holds the machine credentials (the company Outpost
936
+ * job runner, root) mints tokens and writes them here for a child that must
937
+ * act as the same machine identity without ever holding the long-lived
938
+ * secret. The child re-reads the file on every token request, so the parent
939
+ * can refresh it in place while the child runs. The file is a JSON document
940
+ * from {@link delegatedMachineSessionDocument}.
941
+ *
942
+ * While this env is set it is the whole identity decision: no credentials
943
+ * file is consulted, so an unusable session file means no machine identity
944
+ * (and, in required-machine mode, no person fallback either). Set it only
945
+ * for the child that should hold this session.
946
+ */
947
+ export const DELEGATED_MACHINE_SESSION_ENV = "HQ_MACHINE_SESSION_FILE";
948
+ export const DELEGATED_MACHINE_SESSION_VERSION = 1;
949
+ /** Path of the delegated session file, or null when none is configured. */
950
+ export function delegatedMachineSessionFilePath() {
951
+ const raw = process.env[DELEGATED_MACHINE_SESSION_ENV]?.trim();
952
+ return raw !== undefined && raw.length > 0 ? raw : null;
953
+ }
954
+ const OUTPOST_UID_PATTERN = /^out_[0-9A-HJKMNP-TV-Z]{26}$/;
955
+ /**
956
+ * Build the document a parent writes to the delegated session file. Only
957
+ * tokens and identity bindings go in; the machine secret never does.
958
+ */
959
+ export function delegatedMachineSessionDocument(creds, tokens, now = Date.now()) {
960
+ if (creds.entityType !== "company-outpost" || typeof creds.entityUid !== "string" || !OUTPOST_UID_PATTERN.test(creds.entityUid)) {
961
+ throw new CognitoAuthError("Delegated machine sessions are issued for company-outpost identities only");
962
+ }
963
+ if (typeof creds.clientId !== "string" || creds.clientId.length === 0 || typeof creds.region !== "string" || creds.region.length === 0) {
964
+ throw new CognitoAuthError("Delegated machine session needs the credentials' clientId and region");
965
+ }
966
+ const expiresAt = parseExpiresAtMs(tokens.expiresAt);
967
+ if (expiresAt === null)
968
+ throw new CognitoAuthError("Delegated machine session needs a numeric expiresAt");
969
+ return {
970
+ version: DELEGATED_MACHINE_SESSION_VERSION,
971
+ entityType: "company-outpost",
972
+ entityUid: creds.entityUid,
973
+ username: creds.username,
974
+ clientId: creds.clientId,
975
+ region: creds.region,
976
+ idToken: tokens.idToken,
977
+ accessToken: tokens.accessToken,
978
+ expiresAt,
979
+ issuedAt: now,
980
+ };
981
+ }
982
+ /**
983
+ * Read and validate the delegated session file, or null when none is
984
+ * configured or the file is unreadable, malformed, or inconsistent with
985
+ * itself. Expiry is not checked here: an expired session is still this
986
+ * identity (so required-machine mode never falls back to a person), and
987
+ * {@link getValidMachineTokens} reports the expiry with the file path.
988
+ */
989
+ export function loadDelegatedMachineSession() {
990
+ const file = delegatedMachineSessionFilePath();
991
+ if (file === null)
992
+ return null;
993
+ try {
994
+ const raw = JSON.parse(fs.readFileSync(file, "utf-8"));
995
+ if (!raw || typeof raw !== "object" || Array.isArray(raw))
996
+ return null;
997
+ if (raw.version !== DELEGATED_MACHINE_SESSION_VERSION)
998
+ return null;
999
+ if (raw.entityType !== "company-outpost")
1000
+ return null;
1001
+ if (typeof raw.entityUid !== "string" || !OUTPOST_UID_PATTERN.test(raw.entityUid))
1002
+ return null;
1003
+ for (const key of ["username", "clientId", "region", "idToken", "accessToken"]) {
1004
+ const value = raw[key];
1005
+ if (typeof value !== "string" || value.trim().length === 0)
1006
+ return null;
1007
+ }
1008
+ const expiresAt = parseExpiresAtMs(raw.expiresAt);
1009
+ if (expiresAt === null)
1010
+ return null;
1011
+ if (typeof raw.issuedAt !== "number" || !Number.isFinite(raw.issuedAt))
1012
+ return null;
1013
+ const issuedAt = raw.issuedAt;
1014
+ // The ID token must describe the identity the document claims. Anything
1015
+ // else is a planted or mixed-up file, not a session for this machine.
1016
+ const idClaims = decodeJwtClaims(raw.idToken);
1017
+ if (!idClaims || idClaims["custom:entityType"] !== "company-outpost" || idClaims["custom:entityUid"] !== raw.entityUid)
1018
+ return null;
1019
+ const accessClaims = decodeJwtClaims(raw.accessToken);
1020
+ if (!accessClaims)
1021
+ return null;
1022
+ // The session expires when either the document or the ID token says so.
1023
+ const idExp = typeof idClaims.exp === "number" ? idClaims.exp * 1000 : expiresAt;
1024
+ const effectiveExpiresAt = Math.min(expiresAt, idExp);
1025
+ const live = effectiveExpiresAt > Date.now();
1026
+ // While the session is live it must pass exactly the binding a minted or
1027
+ // cached pair must pass (company, outpost id, client, sub shape, no
1028
+ // delegation markers, HQ_COMPANY_UID / HQ_COMPANY_OUTPOST_ID). An expired
1029
+ // session stays this identity so required-machine mode never drifts to a
1030
+ // person, and the token getter reports the expiry with the path.
1031
+ if (live && !machineTokenPairMatchesIdentity({ accessToken: raw.accessToken, idToken: raw.idToken, refreshToken: "", expiresAt, tokenType: "Bearer" }, { username: raw.username, secret: "", clientId: raw.clientId, region: raw.region, entityType: "company-outpost", entityUid: raw.entityUid }, raw.clientId))
1032
+ return null;
1033
+ return {
1034
+ version: DELEGATED_MACHINE_SESSION_VERSION,
1035
+ entityType: "company-outpost",
1036
+ entityUid: raw.entityUid,
1037
+ username: raw.username,
1038
+ clientId: raw.clientId,
1039
+ region: raw.region,
1040
+ idToken: raw.idToken,
1041
+ accessToken: raw.accessToken,
1042
+ expiresAt: effectiveExpiresAt,
1043
+ issuedAt,
1044
+ };
1045
+ }
1046
+ catch {
1047
+ return null;
1048
+ }
1049
+ }
1050
+ function noMachineIdentityMessage() {
1051
+ const sessionFile = delegatedMachineSessionFilePath();
1052
+ if (sessionFile !== null) {
1053
+ return `${DELEGATED_MACHINE_SESSION_ENV} names ${sessionFile}, but that file is not a usable delegated machine session (missing, unreadable, malformed, or its tokens do not describe the identity it claims); no credentials file is consulted while it is set`;
1054
+ }
1055
+ return `No machine credentials found at ${machineCredsFilePath()}`;
1056
+ }
1057
+ function machineCredsFromDelegatedSession(session) {
1058
+ return {
1059
+ username: session.username,
1060
+ secret: "",
1061
+ clientId: session.clientId,
1062
+ region: session.region,
1063
+ entityType: "company-outpost",
1064
+ entityUid: session.entityUid,
1065
+ runtime: "hosted",
1066
+ delegated: true,
1067
+ };
1068
+ }
1069
+ /** Tokens from the delegated session file, re-read on every call. */
1070
+ function delegatedSessionTokens(expected) {
1071
+ const file = delegatedMachineSessionFilePath() ?? "(unset)";
1072
+ const session = loadDelegatedMachineSession();
1073
+ if (!session || session.entityUid !== expected.entityUid) {
1074
+ throw new CognitoAuthError(`Delegated machine session at ${file} (from ${DELEGATED_MACHINE_SESSION_ENV}) is missing or no longer describes ${expected.entityUid}`);
1075
+ }
1076
+ if (session.expiresAt <= Date.now()) {
1077
+ throw new CognitoAuthError(`Delegated machine session at ${file} expired at ${new Date(session.expiresAt).toISOString()}; the parent that issued it did not refresh it`);
1078
+ }
1079
+ return {
1080
+ accessToken: session.accessToken,
1081
+ idToken: session.idToken,
1082
+ refreshToken: "",
1083
+ expiresAt: session.expiresAt,
1084
+ tokenType: "Bearer",
1085
+ };
1086
+ }
929
1087
  /**
930
1088
  * Load machine credentials, or null when this process is not running as a
931
1089
  * machine identity (no creds file / unreadable / malformed).
1090
+ *
1091
+ * A delegated session file (`HQ_MACHINE_SESSION_FILE`) takes precedence over
1092
+ * a credentials file: the parent that set it chose this identity for the
1093
+ * child explicitly.
932
1094
  */
933
1095
  export function loadMachineCreds() {
1096
+ if (delegatedMachineSessionFilePath() !== null) {
1097
+ // The parent that set the session env chose this identity. A torn,
1098
+ // missing or planted session file must not fall through to a creds file
1099
+ // (which in a job's run home would be the job user's own) or to a person.
1100
+ const delegated = loadDelegatedMachineSession();
1101
+ return delegated ? machineCredsFromDelegatedSession(delegated) : null;
1102
+ }
934
1103
  const file = machineCredsFilePath();
935
1104
  try {
936
1105
  if (!fs.existsSync(file))
@@ -1083,6 +1252,9 @@ function assertHumanAuthenticationAllowed() {
1083
1252
  export function assertMachineIdentityWhenRequired() {
1084
1253
  if (!machineIdentityRequired() || isMachineIdentity())
1085
1254
  return;
1255
+ if (delegatedMachineSessionFilePath() !== null) {
1256
+ throw new CognitoAuthError(`HQ_REQUIRE_MACHINE_IDENTITY or HQ_MACHINE_AUTH_REQUIRED is set and ${noMachineIdentityMessage()}. Refusing to fall back to an interactive human session.`);
1257
+ }
1086
1258
  const explicit = process.env.HQ_MACHINE_CREDS_FILE?.trim();
1087
1259
  const source = explicit !== undefined && explicit.length > 0
1088
1260
  ? "HQ_MACHINE_CREDS_FILE"
@@ -1189,7 +1361,10 @@ async function mintMachineTokensUnlocked(config, creds, retry, assertCurrent = (
1189
1361
  assertCurrent();
1190
1362
  const machineCreds = creds ?? loadMachineCreds();
1191
1363
  if (!machineCreds) {
1192
- throw new CognitoAuthError(`No machine credentials found at ${machineCredsFilePath()}`);
1364
+ throw new CognitoAuthError(noMachineIdentityMessage());
1365
+ }
1366
+ if (machineCreds.delegated) {
1367
+ throw new CognitoAuthError("A delegated machine session holds no machine secret and cannot mint tokens; the parent that issued it refreshes them");
1193
1368
  }
1194
1369
  if (companyMachineRequired() && machineCreds.entityType !== "company-outpost") {
1195
1370
  throw new CognitoAuthError("Company machine authentication requires company-outpost credentials");
@@ -1381,7 +1556,7 @@ async function mintExternalMachineTokens(creds, clientId, retryOpts, signal) {
1381
1556
  export async function mintMachineTokens(config, creds, retry) {
1382
1557
  const selected = creds ?? loadMachineCreds();
1383
1558
  if (!selected)
1384
- throw new CognitoAuthError("No usable machine credentials found");
1559
+ throw new CognitoAuthError(noMachineIdentityMessage());
1385
1560
  const identityKey = machineIdentityKey(config, selected);
1386
1561
  const companyContext = companyMachineRequired() || selected.entityType === "company-outpost";
1387
1562
  const fileBound = !creds || loadMachineCreds() !== null || machineIdentityRequired();
@@ -1441,8 +1616,12 @@ export async function getValidMachineTokens(config, options = {}) {
1441
1616
  }
1442
1617
  const machineCreds = loadMachineCreds();
1443
1618
  if (!machineCreds) {
1444
- throw new CognitoAuthError(`No machine credentials found at ${machineCredsFilePath()}`);
1619
+ throw new CognitoAuthError(noMachineIdentityMessage());
1445
1620
  }
1621
+ // A delegated session never caches, memoizes or mints: the file is the
1622
+ // session, and the parent refreshes it in place.
1623
+ if (machineCreds.delegated)
1624
+ return delegatedSessionTokens(machineCreds);
1446
1625
  const expectedClientId = machineCreds.clientId ?? config.clientId;
1447
1626
  const identityKey = machineIdentityKey(config, machineCreds);
1448
1627
  const companyContext = companyMachineRequired() || machineCreds.entityType === "company-outpost";