@indigoai-us/hq-cloud 6.15.100 → 6.15.101

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/cli/share.js CHANGED
@@ -23,7 +23,7 @@ import { hasRemoteChanged, isAccessDenied, resolveActiveCompany, resolveTransfer
23
23
  import { buildConflictId, buildConflictPath, readShortMachineId, } from "../lib/conflict-file.js";
24
24
  import { appendConflictEntry } from "../lib/conflict-index.js";
25
25
  import { isCloudAuthoritative } from "../lib/cloud-authoritative.js";
26
- import { VaultAuthError, VaultClient, VaultPermissionDeniedError } from "../vault-client.js";
26
+ import { VaultAuthError, VaultClient, VaultClientError, VaultPermissionDeniedError, } from "../vault-client.js";
27
27
  import { describeError } from "../lib/describe-error.js";
28
28
  import { isRetryableIdentityRefusal, isTerminalIdentityRefusal, } from "../cognito-auth.js";
29
29
  import { readlinkOrNull } from "../lib/readlink-safe.js";
@@ -951,12 +951,25 @@ async function registerOneCompanySkill(run, entry, registrar) {
951
951
  if (currentUid)
952
952
  return;
953
953
  run.options.onHeartbeat?.();
954
- const result = await registrar({
955
- companySlug: run.ctx.slug,
956
- path: entry.relativePath,
957
- content,
958
- });
959
- assertValidSkillRegistration(result, entry.relativePath);
954
+ let result;
955
+ try {
956
+ result = await registrar({
957
+ companySlug: run.ctx.slug,
958
+ path: entry.relativePath,
959
+ content,
960
+ });
961
+ assertValidSkillRegistration(result, entry.relativePath);
962
+ }
963
+ catch (err) {
964
+ if (!isPermanentSkillRegistrationValidationError(err))
965
+ throw err;
966
+ const current = fs.readFileSync(entry.absolutePath, "utf8");
967
+ if (current !== content) {
968
+ content = current;
969
+ continue;
970
+ }
971
+ throw err;
972
+ }
960
973
  const current = fs.readFileSync(entry.absolutePath, "utf8");
961
974
  if (current !== content) {
962
975
  content = current;
@@ -967,13 +980,18 @@ async function registerOneCompanySkill(run, entry, registrar) {
967
980
  }
968
981
  throw new Error(`Company skill '${entry.relativePath}' kept changing while HQ registered it; retry after the current edit finishes.`);
969
982
  }
983
+ function isPermanentSkillRegistrationValidationError(err) {
984
+ return (err instanceof VaultClientError &&
985
+ (err.statusCode === 400 || err.statusCode === 422));
986
+ }
970
987
  /**
971
988
  * Durable creation backstop. Hooks improve the authoring experience, but sync
972
989
  * is the invariant boundary: no unstamped canonical company skill reaches S3.
973
990
  */
974
991
  async function preflightCompanySkillIdentities(run, entries) {
975
- if (run.options.personalMode === true || run.ctx.uid.startsWith("prs_"))
976
- return new Set();
992
+ if (run.options.personalMode === true || run.ctx.uid.startsWith("prs_")) {
993
+ return { registrationDenied: new Set(), registrationInvalid: new Set() };
994
+ }
977
995
  const canonical = entries.filter((entry) => entry.kind === "file" &&
978
996
  CANONICAL_COMPANY_SKILL_RE.test(entry.relativePath));
979
997
  const unstamped = canonical.filter((entry) => !parseRegisteredCompanySkillUid(fs.readFileSync(entry.absolutePath, "utf8")));
@@ -982,24 +1000,39 @@ async function preflightCompanySkillIdentities(run, entries) {
982
1000
  return (journalEntry?.skillMetadataPending === true &&
983
1001
  journalEntry.hash === hashFile(entry.absolutePath));
984
1002
  });
985
- if (unstamped.length === 0 && pending.length === 0)
986
- return new Set();
1003
+ if (unstamped.length === 0 && pending.length === 0) {
1004
+ return { registrationDenied: new Set(), registrationInvalid: new Set() };
1005
+ }
987
1006
  const registrar = skillRegistrarForRun(run);
988
1007
  if (!registrar) {
989
1008
  if (unstamped.length > 0) {
990
1009
  throw new UnregisteredCompanySkillError(unstamped.map((entry) => entry.relativePath));
991
1010
  }
992
- return new Set();
1011
+ return { registrationDenied: new Set(), registrationInvalid: new Set() };
993
1012
  }
994
1013
  const registrationDenied = new Set();
1014
+ const registrationInvalid = new Set();
1015
+ const registrationInvalidMessages = new Map();
995
1016
  for (const entry of unstamped) {
996
1017
  try {
997
1018
  await registerOneCompanySkill(run, entry, registrar);
998
1019
  }
999
1020
  catch (err) {
1000
- if (!(err instanceof VaultPermissionDeniedError))
1021
+ // A 403 has its existing permissions-specific report. Keep its priority
1022
+ // even for a caller-supplied generic VaultClientError rather than folding
1023
+ // it into the validation bucket below.
1024
+ if (err instanceof VaultPermissionDeniedError ||
1025
+ (err instanceof VaultClientError && err.statusCode === 403)) {
1026
+ registrationDenied.add(entry.relativePath);
1027
+ }
1028
+ else if (isPermanentSkillRegistrationValidationError(err)) {
1029
+ registrationInvalid.add(entry.relativePath);
1030
+ if (err.message)
1031
+ registrationInvalidMessages.set(entry.relativePath, err.message);
1032
+ }
1033
+ else {
1001
1034
  throw err;
1002
- registrationDenied.add(entry.relativePath);
1035
+ }
1003
1036
  }
1004
1037
  }
1005
1038
  if (registrationDenied.size > 0) {
@@ -1010,6 +1043,19 @@ async function preflightCompanySkillIdentities(run, entries) {
1010
1043
  samplePaths: [...registrationDenied].slice(0, 10),
1011
1044
  });
1012
1045
  }
1046
+ if (registrationInvalid.size > 0) {
1047
+ const samplePaths = [...registrationInvalid].slice(0, 10);
1048
+ const message = samplePaths
1049
+ .map((relativePath) => registrationInvalidMessages.get(relativePath))
1050
+ .find((candidate) => candidate !== undefined);
1051
+ run.emit({
1052
+ type: "not-shipped",
1053
+ reason: "skill-registration-invalid",
1054
+ count: registrationInvalid.size,
1055
+ samplePaths,
1056
+ ...(message ? { message } : {}),
1057
+ });
1058
+ }
1013
1059
  for (const entry of pending) {
1014
1060
  const journalEntry = run.journal.files[entry.relativePath];
1015
1061
  run.options.onHeartbeat?.();
@@ -1059,7 +1105,7 @@ async function preflightCompanySkillIdentities(run, entries) {
1059
1105
  delete run.journal.files[entry.relativePath]?.skillMetadataPending;
1060
1106
  checkpointShareJournal(run);
1061
1107
  }
1062
- return registrationDenied;
1108
+ return { registrationDenied, registrationInvalid };
1063
1109
  }
1064
1110
  /**
1065
1111
  * Reconcile metadata only after the canonical bytes have landed. Identity
@@ -1176,9 +1222,10 @@ async function buildSharePlans(run) {
1176
1222
  return false;
1177
1223
  })
1178
1224
  : controlCharFiltered;
1179
- const registrationDenied = await preflightCompanySkillIdentities(run, filesToShare);
1180
- const uploadableFiles = registrationDenied.size > 0
1181
- ? filesToShare.filter((entry) => !registrationDenied.has(entry.relativePath))
1225
+ const { registrationDenied, registrationInvalid } = await preflightCompanySkillIdentities(run, filesToShare);
1226
+ const registrationSkipped = new Set([...registrationDenied, ...registrationInvalid]);
1227
+ const uploadableFiles = registrationSkipped.size > 0
1228
+ ? filesToShare.filter((entry) => !registrationSkipped.has(entry.relativePath))
1182
1229
  : filesToShare;
1183
1230
  const pushPlan = computePushPlan(uploadableFiles, run.journal, run.skipUnchanged === true, run.options.onHeartbeat);
1184
1231
  const deletePlan = run.propagateDeletes === true
@@ -2594,12 +2641,18 @@ function defaultConsoleLogger(event) {
2594
2641
  else if (event.reason === "skill-registration-denied") {
2595
2642
  console.warn(` ! ${event.count} unstamped company skill${event.count === 1 ? "" : "s"} could NOT be registered with this machine's permissions and was NOT uploaded:`);
2596
2643
  }
2644
+ else if (event.reason === "skill-registration-invalid") {
2645
+ console.warn(` ! ${event.count} unstamped company skill${event.count === 1 ? "" : "s"} was rejected as invalid and was NOT uploaded:`);
2646
+ }
2597
2647
  else {
2598
2648
  console.warn(` ! ${event.count} linked subtree${event.count === 1 ? "" : "s"} recorded but NOT uploaded — contents sync via their own repo, not the vault:`);
2599
2649
  }
2600
2650
  for (const p of event.samplePaths) {
2601
2651
  console.warn(` · ${p}`);
2602
2652
  }
2653
+ if (event.message) {
2654
+ console.warn(` Reason: ${event.message}`);
2655
+ }
2603
2656
  if (event.count > event.samplePaths.length) {
2604
2657
  console.warn(` ... and ${event.count - event.samplePaths.length} more`);
2605
2658
  }