@indigoai-us/hq-cloud 6.18.6 → 6.18.8

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 (64) hide show
  1. package/dist/bin/sync-runner-company.d.ts +2 -0
  2. package/dist/bin/sync-runner-company.d.ts.map +1 -1
  3. package/dist/bin/sync-runner-company.js +14 -0
  4. package/dist/bin/sync-runner-company.js.map +1 -1
  5. package/dist/bin/sync-runner-company.test.js +45 -1
  6. package/dist/bin/sync-runner-company.test.js.map +1 -1
  7. package/dist/bin/sync-runner-publish-expansion.test.d.ts +2 -0
  8. package/dist/bin/sync-runner-publish-expansion.test.d.ts.map +1 -0
  9. package/dist/bin/sync-runner-publish-expansion.test.js +54 -0
  10. package/dist/bin/sync-runner-publish-expansion.test.js.map +1 -0
  11. package/dist/bin/sync-runner-watch-loop.d.ts +11 -0
  12. package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
  13. package/dist/bin/sync-runner-watch-loop.js +58 -1
  14. package/dist/bin/sync-runner-watch-loop.js.map +1 -1
  15. package/dist/bin/sync-runner.d.ts +4 -0
  16. package/dist/bin/sync-runner.d.ts.map +1 -1
  17. package/dist/bin/sync-runner.js +1 -0
  18. package/dist/bin/sync-runner.js.map +1 -1
  19. package/dist/cli/share.d.ts +26 -2
  20. package/dist/cli/share.d.ts.map +1 -1
  21. package/dist/cli/share.js +113 -23
  22. package/dist/cli/share.js.map +1 -1
  23. package/dist/cli/share.test.js +320 -9
  24. package/dist/cli/share.test.js.map +1 -1
  25. package/dist/lib/ontology-entity-meta.d.ts +21 -0
  26. package/dist/lib/ontology-entity-meta.d.ts.map +1 -0
  27. package/dist/lib/ontology-entity-meta.js +51 -0
  28. package/dist/lib/ontology-entity-meta.js.map +1 -0
  29. package/dist/lib/ontology-entity-meta.test.d.ts +2 -0
  30. package/dist/lib/ontology-entity-meta.test.d.ts.map +1 -0
  31. package/dist/lib/ontology-entity-meta.test.js +79 -0
  32. package/dist/lib/ontology-entity-meta.test.js.map +1 -0
  33. package/dist/lib/ontology-entity-push.d.ts +9 -4
  34. package/dist/lib/ontology-entity-push.d.ts.map +1 -1
  35. package/dist/lib/ontology-entity-push.js +19 -20
  36. package/dist/lib/ontology-entity-push.js.map +1 -1
  37. package/dist/lib/ontology-entity-push.test.js +7 -0
  38. package/dist/lib/ontology-entity-push.test.js.map +1 -1
  39. package/dist/lib/ontology-outbox.d.ts +52 -0
  40. package/dist/lib/ontology-outbox.d.ts.map +1 -0
  41. package/dist/lib/ontology-outbox.js +118 -0
  42. package/dist/lib/ontology-outbox.js.map +1 -0
  43. package/dist/lib/skill-register-landed-bytes.d.ts +16 -0
  44. package/dist/lib/skill-register-landed-bytes.d.ts.map +1 -0
  45. package/dist/lib/skill-register-landed-bytes.js +78 -0
  46. package/dist/lib/skill-register-landed-bytes.js.map +1 -0
  47. package/dist/lib/skill-register-landed-bytes.test.d.ts +2 -0
  48. package/dist/lib/skill-register-landed-bytes.test.d.ts.map +1 -0
  49. package/dist/lib/skill-register-landed-bytes.test.js +83 -0
  50. package/dist/lib/skill-register-landed-bytes.test.js.map +1 -0
  51. package/dist/private-folder-transport.d.ts.map +1 -1
  52. package/dist/private-folder-transport.js +16 -1
  53. package/dist/private-folder-transport.js.map +1 -1
  54. package/dist/private-folder-transport.test.d.ts +2 -0
  55. package/dist/private-folder-transport.test.d.ts.map +1 -0
  56. package/dist/private-folder-transport.test.js +33 -0
  57. package/dist/private-folder-transport.test.js.map +1 -0
  58. package/dist/s3.d.ts +1 -1
  59. package/dist/s3.d.ts.map +1 -1
  60. package/dist/s3.js +34 -4
  61. package/dist/s3.js.map +1 -1
  62. package/dist/s3.test.js +51 -0
  63. package/dist/s3.test.js.map +1 -1
  64. package/package.json +2 -1
package/dist/cli/share.js CHANGED
@@ -27,7 +27,9 @@ import { hasRemoteChanged, isAccessDenied, resolveActiveCompany, resolveTransfer
27
27
  import { buildConflictBackupPath, buildConflictId, buildConflictProbePath, readShortMachineId, } from "../lib/conflict-file.js";
28
28
  import { appendConflictEntry } from "../lib/conflict-index.js";
29
29
  import { isCloudAuthoritative } from "../lib/cloud-authoritative.js";
30
- import { isOntologyEntityKey, resolveOntologyEntityPush } from "../lib/ontology-entity-push.js";
30
+ import { isOntologyEntityKey, ONTOLOGY_MULTI_WRITER_FLAG, resolveOntologyEntityPush, } from "../lib/ontology-entity-push.js";
31
+ import { entityIsFreshForCreate, outboxAllowsEntityPush, readOntologyOutbox, } from "../lib/ontology-outbox.js";
32
+ import { resolveSkillRegisterLandedBytes } from "../lib/skill-register-landed-bytes.js";
31
33
  import { VaultAuthError, VaultClient, VaultClientError, VaultConflictError, VaultPermissionDeniedError, } from "../vault-client.js";
32
34
  import { describeError } from "../lib/describe-error.js";
33
35
  import { isTransientHttpStatusError } from "../lib/net-errors.js";
@@ -376,13 +378,19 @@ async function yieldToCooperativeCheckpoint(work, cooperativeCheckpoint, force =
376
378
  * Push-side refusal for server-owned paths. board.json is the documented
377
379
  * exception; checkpoint-written ontology entity files are the second one, only
378
380
  * while the company's `checkpoint.ontology` flag is on (see
379
- * ../lib/ontology-entity-push.ts).
381
+ * ../lib/ontology-entity-push.ts). With the multi-writer flag on as well, an
382
+ * entity file is pushed only when its local bytes match its outbox entry;
383
+ * anything else (a pulled copy, a copy another writer has since merged away)
384
+ * stays cloud-authoritative (see ../lib/ontology-outbox.ts).
380
385
  */
381
- function refusesServerOwnedPush(relativePath, ontologyEntityPush) {
386
+ function refusesServerOwnedPush(relativePath, ontologyEntityPush, absolutePath, plannedHash) {
382
387
  if (relativePath === "board.json")
383
388
  return false;
384
- if (ontologyEntityPush && isOntologyEntityKey(relativePath))
385
- return false;
389
+ if (ontologyEntityPush !== false && isOntologyEntityKey(relativePath)) {
390
+ if (ontologyEntityPush === true)
391
+ return false;
392
+ return !outboxAllowsEntityPush(ontologyEntityPush, relativePath, absolutePath, plannedHash);
393
+ }
386
394
  return isCloudAuthoritative(relativePath);
387
395
  }
388
396
  function computePushPlan(filesToShare, journal, skipUnchanged, onHeartbeat, ontologyEntityPush = false) {
@@ -398,7 +406,7 @@ function computePushPlan(filesToShare, journal, skipUnchanged, onHeartbeat, onto
398
406
  // them before hashing or skip-unchanged so local-only files and files with
399
407
  // a divergent remote baseline both surface the same honest refusal. The
400
408
  // board and flag-gated ontology entities are the push-side exceptions.
401
- if (refusesServerOwnedPush(relativePath, ontologyEntityPush)) {
409
+ if (refusesServerOwnedPush(relativePath, ontologyEntityPush, absolutePath)) {
402
410
  items.push({ action: "refuse-server-owned", absolutePath, relativePath });
403
411
  continue;
404
412
  }
@@ -703,6 +711,8 @@ function emitServerOwnedRefusalSummary(run, refusals) {
703
711
  .map((item) => item.relativePath),
704
712
  });
705
713
  }
714
+ /** Most uploaded paths a push reports back (the watcher announces these). */
715
+ export const SHARE_UPLOADED_PATHS_CAP = 1_000;
706
716
  /**
707
717
  * A conditional-write fence rejection — the SDK's 412 (`name:
708
718
  * "PreconditionFailed"`) or the presigned transport's mirror of it. Means
@@ -1030,6 +1040,8 @@ async function createPushRunContext(options) {
1030
1040
  return {
1031
1041
  options,
1032
1042
  ontologyEntityPush: false,
1043
+ skillRegisterLandedBytes: false,
1044
+ skillRegistrationFallbacks: 0,
1033
1045
  paths,
1034
1046
  message,
1035
1047
  onConflict,
@@ -1071,11 +1083,47 @@ async function createPushRunContext(options) {
1071
1083
  async function resolveRunOntologyEntityPush(run) {
1072
1084
  if (run.options.personalMode === true)
1073
1085
  return false;
1074
- if (run.options.ontologyEntityPush !== undefined)
1075
- return run.options.ontologyEntityPush;
1076
1086
  const vaultConfig = run.vaultConfig;
1077
1087
  const authToken = vaultConfig?.authToken;
1078
- return resolveOntologyEntityPush({
1088
+ const flagInput = {
1089
+ companyUid: run.ctx.uid,
1090
+ companySlug: run.ctx.slug,
1091
+ endpoint: vaultConfig?.apiUrl,
1092
+ getToken: authToken === undefined
1093
+ ? undefined
1094
+ : typeof authToken === "function"
1095
+ ? authToken
1096
+ : () => authToken,
1097
+ };
1098
+ const entityPush = run.options.ontologyEntityPush ?? await resolveOntologyEntityPush(flagInput);
1099
+ if (!entityPush)
1100
+ return false;
1101
+ // A failed read of the multi-writer flag must not fall back to the unguarded
1102
+ // push: entity files stay pull-only for this pass instead.
1103
+ let multiWriterReadFailed = false;
1104
+ const multiWriter = run.options.ontologyMultiWriter ?? await resolveOntologyEntityPush({
1105
+ ...flagInput,
1106
+ flag: ONTOLOGY_MULTI_WRITER_FLAG,
1107
+ onError: (error) => {
1108
+ multiWriterReadFailed = true;
1109
+ const detail = error instanceof Error ? error.message : String(error);
1110
+ process.stderr.write(`hq-cloud: could not read ${ONTOLOGY_MULTI_WRITER_FLAG}; ontology entities stay pull-only this pass (${detail.slice(0, 200)})\n`);
1111
+ },
1112
+ });
1113
+ if (multiWriterReadFailed)
1114
+ return false;
1115
+ if (!multiWriter)
1116
+ return true;
1117
+ return readOntologyOutbox(run.hqRoot, run.ctx.slug, (error) => {
1118
+ process.stderr.write(`hq-cloud: could not read the ontology outbox for ${run.ctx.slug}; no entity file is pushed this pass (${error.message.slice(0, 200)})\n`);
1119
+ });
1120
+ }
1121
+ async function resolveRunSkillRegisterLandedBytes(run) {
1122
+ if (run.options.personalMode === true || !run.ctx.uid.startsWith("cmp_"))
1123
+ return false;
1124
+ const vaultConfig = run.vaultConfig;
1125
+ const authToken = vaultConfig?.authToken;
1126
+ return resolveSkillRegisterLandedBytes({
1079
1127
  companyUid: run.ctx.uid,
1080
1128
  companySlug: run.ctx.slug,
1081
1129
  endpoint: vaultConfig?.apiUrl,
@@ -1095,6 +1143,7 @@ function createShareCounters() {
1095
1143
  filesTombstoned: 0,
1096
1144
  filesRefusedStale: 0,
1097
1145
  filesSuppressedByTombstone: 0,
1146
+ uploadedPaths: [],
1098
1147
  };
1099
1148
  }
1100
1149
  const CANONICAL_COMPANY_SKILL_RE = /^skills\/([a-z0-9][a-z0-9-]*)\/SKILL\.md$/;
@@ -1530,6 +1579,8 @@ async function recoverLandedSkillConflict(run, relativePath, content, absolutePa
1530
1579
  let fallback;
1531
1580
  try {
1532
1581
  run.options.onHeartbeat?.();
1582
+ if (run.skillRegisterLandedBytes)
1583
+ run.skillRegistrationFallbacks += 1;
1533
1584
  fallback = await registrar({
1534
1585
  companySlug: run.ctx.slug,
1535
1586
  path: relativePath,
@@ -1750,6 +1801,9 @@ async function buildSharePlans(run) {
1750
1801
  return false;
1751
1802
  })
1752
1803
  : controlCharFiltered;
1804
+ if (filesToShare.some((entry) => CANONICAL_COMPANY_SKILL_RE.test(entry.relativePath))) {
1805
+ run.skillRegisterLandedBytes = await resolveRunSkillRegisterLandedBytes(run);
1806
+ }
1753
1807
  const { registrationDenied, registrationInvalid, registrationFailed } = await preflightCompanySkillIdentities(run, filesToShare);
1754
1808
  const registrationSkipped = new Set([
1755
1809
  ...registrationDenied,
@@ -2003,7 +2057,7 @@ async function executeUploads(run, pushPlan, counters, conflictPaths) {
2003
2057
  // legitimate, but must flow through the conditional PUT fence below. It
2004
2058
  // remains cloud-authoritative on pull so server automation still wins a
2005
2059
  // pull conflict.
2006
- if (refusesServerOwnedPush(relativePath, run.ontologyEntityPush)) {
2060
+ if (refusesServerOwnedPush(relativePath, run.ontologyEntityPush, absolutePath, localHash)) {
2007
2061
  if (run.options.serverOwnedPathPolicy !== "skip") {
2008
2062
  emitServerOwnedRefusal(run, relativePath);
2009
2063
  }
@@ -2065,9 +2119,19 @@ async function executeUploads(run, pushPlan, counters, conflictPaths) {
2065
2119
  // bodies that match the baseline), so settle it here: the cloud deletion
2066
2120
  // wins, the local body is parked under `.hq/conflict-backups/`, and the
2067
2121
  // journal row goes, leaving nothing for the next pass to re-report.
2068
- if (cloudWinsEntity && !remoteMeta && journalEntry) {
2122
+ //
2123
+ // With the multi-writer rules on, a create with no journal row is allowed
2124
+ // only for a body whose `last_updated` is within 24 hours: an older body
2125
+ // over an absent remote is a key the vault no longer has, not a new
2126
+ // entity, so it is set aside the same way.
2127
+ const staleEntityCreate = cloudWinsEntity &&
2128
+ !remoteMeta &&
2129
+ !journalEntry &&
2130
+ typeof run.ontologyEntityPush === "object" &&
2131
+ !entityIsFreshForCreate(fs.readFileSync(absolutePath, "utf8"), Date.now());
2132
+ if ((cloudWinsEntity && !remoteMeta && journalEntry) || staleEntityCreate) {
2069
2133
  counters.filesSkipped++;
2070
- if (journalEntry.hash === localHash)
2134
+ if (journalEntry && journalEntry.hash === localHash)
2071
2135
  return;
2072
2136
  conflictPaths.push(relativePath);
2073
2137
  if (!isMaterializationPathStillContained(run.syncRoot, item.absolutePath)) {
@@ -2376,8 +2440,21 @@ async function executeUploads(run, pushPlan, counters, conflictPaths) {
2376
2440
  // own synchronous read. If an editor saves while the network request is
2377
2441
  // in flight, the comparison below suppresses reconciliation; that newer
2378
2442
  // version will upload and reconcile on the next pass.
2379
- const skillContentAtPut = !isSymlinkUpload && CANONICAL_COMPANY_SKILL_RE.test(relativePath)
2380
- ? fs.readFileSync(absolutePath, "utf8")
2443
+ const isCompanySkillUpload = !isSymlinkUpload && CANONICAL_COMPANY_SKILL_RE.test(relativePath);
2444
+ const skillUploadBytes = isCompanySkillUpload && run.skillRegisterLandedBytes
2445
+ ? fs.readFileSync(absolutePath)
2446
+ : undefined;
2447
+ if (skillUploadBytes) {
2448
+ const capturedHash = crypto.createHash("sha256").update(skillUploadBytes).digest("hex");
2449
+ if (capturedHash !== localHash) {
2450
+ const refreshed = refreshUploadItem();
2451
+ if (refreshed !== null)
2452
+ await restartForChangedBody(refreshed);
2453
+ return;
2454
+ }
2455
+ }
2456
+ const skillContentAtPut = isCompanySkillUpload
2457
+ ? skillUploadBytes?.toString("utf8") ?? fs.readFileSync(absolutePath, "utf8")
2381
2458
  : undefined;
2382
2459
  if (!isSymlinkUpload)
2383
2460
  setUploadContentHash(absolutePath, localHash);
@@ -2390,19 +2467,25 @@ async function executeUploads(run, pushPlan, counters, conflictPaths) {
2390
2467
  ? { bypassBandwidthGovernor: true }
2391
2468
  : undefined;
2392
2469
  const sendUpload = async (transport) => {
2470
+ if (isSymlinkUpload) {
2471
+ if (transport) {
2472
+ return uploadSymlink(run.ctx, item.target, relativePath, run.options.author, pc, transferOptions, transport);
2473
+ }
2474
+ if (transferOptions) {
2475
+ return uploadSymlink(run.ctx, item.target, relativePath, run.options.author, pc, transferOptions);
2476
+ }
2477
+ return uploadSymlink(run.ctx, item.target, relativePath, run.options.author, pc);
2478
+ }
2479
+ if (skillUploadBytes) {
2480
+ return uploadFile(run.ctx, absolutePath, relativePath, run.options.author, pc, transferOptions, skillUploadBytes, transport);
2481
+ }
2393
2482
  if (transport) {
2394
- return isSymlinkUpload
2395
- ? uploadSymlink(run.ctx, item.target, relativePath, run.options.author, pc, transferOptions, transport)
2396
- : uploadFile(run.ctx, absolutePath, relativePath, run.options.author, pc, transferOptions, transport);
2483
+ return uploadFile(run.ctx, absolutePath, relativePath, run.options.author, pc, transferOptions, undefined, transport);
2397
2484
  }
2398
2485
  if (transferOptions) {
2399
- return isSymlinkUpload
2400
- ? uploadSymlink(run.ctx, item.target, relativePath, run.options.author, pc, transferOptions)
2401
- : uploadFile(run.ctx, absolutePath, relativePath, run.options.author, pc, transferOptions);
2486
+ return uploadFile(run.ctx, absolutePath, relativePath, run.options.author, pc, transferOptions);
2402
2487
  }
2403
- return isSymlinkUpload
2404
- ? uploadSymlink(run.ctx, item.target, relativePath, run.options.author, pc)
2405
- : uploadFile(run.ctx, absolutePath, relativePath, run.options.author, pc);
2488
+ return uploadFile(run.ctx, absolutePath, relativePath, run.options.author, pc);
2406
2489
  };
2407
2490
  const primePrivateFolder = (io) => primePrivateFolderUpload({
2408
2491
  io,
@@ -2466,6 +2549,9 @@ async function executeUploads(run, pushPlan, counters, conflictPaths) {
2466
2549
  }
2467
2550
  counters.filesUploaded++;
2468
2551
  counters.bytesUploaded += size;
2552
+ if (counters.uploadedPaths.length < SHARE_UPLOADED_PATHS_CAP) {
2553
+ counters.uploadedPaths.push(relativePath);
2554
+ }
2469
2555
  // A landed company skill needs a durable retry marker before the registry
2470
2556
  // call. The ordinary cadence is intentionally sparse for large vaults,
2471
2557
  // but losing this row can strand tags after a crash between PUT and
@@ -3656,6 +3742,10 @@ function buildShareResult(run, counters, filesRefusedStalePaths, conflictPaths,
3656
3742
  filesRefusedStale: counters.filesRefusedStale,
3657
3743
  filesRefusedStalePaths,
3658
3744
  filesSuppressedByTombstone: counters.filesSuppressedByTombstone,
3745
+ ...(run.skillRegisterLandedBytes
3746
+ ? { skillRegistrationFallbacks: run.skillRegistrationFallbacks }
3747
+ : {}),
3748
+ uploadedPaths: counters.uploadedPaths,
3659
3749
  filesExcludedByPolicy: run.excludedSet.size,
3660
3750
  filesExcludedByScope: run.scopeExcludedSet.size,
3661
3751
  filesExcludedByIgnore: run.ignoreExcludedSet.size,