@indigoai-us/hq-cli 5.345.237 → 5.345.241

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 (115) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/assets/scaffold/core/scripts/hq-delegate-repo.sh +7 -1
  3. package/assets/scaffold/core/scripts/hq-delegate-secrets.sh +95 -20
  4. package/assets/scaffold/core/scripts/hq-delegate-transfer.sh +57 -9
  5. package/dist/command-catalog.generated.d.ts +185 -3
  6. package/dist/command-catalog.generated.js +228 -3
  7. package/dist/command-registration-plan.d.ts +6 -0
  8. package/dist/command-registration-plan.js +1 -0
  9. package/dist/commands/bot.d.ts +2 -0
  10. package/dist/commands/bot.js +23 -0
  11. package/dist/commands/cloud-off-gate.d.ts +2 -1
  12. package/dist/commands/cloud-off-gate.js +17 -4
  13. package/dist/commands/cloud.d.ts +17 -2
  14. package/dist/commands/cloud.js +126 -24
  15. package/dist/commands/core-delegate-w1b.js +35 -10
  16. package/dist/commands/core-delegate.d.ts +2 -1
  17. package/dist/commands/core-delegate.js +207 -48
  18. package/dist/commands/deploy-comments.js +8 -2
  19. package/dist/commands/deploy-events.d.ts +40 -0
  20. package/dist/commands/deploy-events.js +300 -0
  21. package/dist/commands/doctor.d.ts +4 -4
  22. package/dist/commands/doctor.js +2 -2
  23. package/dist/commands/feedback.js +2 -3
  24. package/dist/commands/keyed-sync-pull.d.ts +12 -0
  25. package/dist/commands/keyed-sync-pull.js +151 -0
  26. package/dist/commands/library-add.d.ts +5 -2
  27. package/dist/commands/library-add.js +22 -9
  28. package/dist/commands/mcp-registration.d.ts +4 -18
  29. package/dist/commands/mcp-registration.js +9 -29
  30. package/dist/commands/mesh.d.ts +4 -0
  31. package/dist/commands/mesh.js +25 -5
  32. package/dist/commands/pack-install.d.ts +2 -3
  33. package/dist/commands/pack-install.js +6 -8
  34. package/dist/commands/secrets.d.ts +3 -4
  35. package/dist/commands/secrets.js +3 -20
  36. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +307 -232
  37. package/dist/hq-cloud-sync-runner/package.json +1 -1
  38. package/dist/lib/agent-kit/inbox-state.d.ts +2 -1
  39. package/dist/lib/agent-kit/inbox-state.js +27 -3
  40. package/dist/lib/bot/api.d.ts +2 -1
  41. package/dist/lib/bot/api.js +2 -15
  42. package/dist/lib/bot/promote.d.ts +23 -0
  43. package/dist/lib/bot/promote.js +73 -0
  44. package/dist/lib/bot/promotion-hold-reconcile.d.ts +56 -0
  45. package/dist/lib/bot/promotion-hold-reconcile.js +155 -0
  46. package/dist/lib/capacity/collectors/claude-oauth.d.ts +0 -2
  47. package/dist/lib/capacity/collectors/claude-oauth.js +0 -5
  48. package/dist/lib/core-utils/delegate-helper-paths.d.ts +26 -0
  49. package/dist/lib/core-utils/delegate-helper-paths.js +33 -0
  50. package/dist/lib/daemon/jq-provision.d.ts +63 -0
  51. package/dist/lib/daemon/jq-provision.js +155 -0
  52. package/dist/lib/daemon/lanes-reconcile-guard.d.ts +4 -3
  53. package/dist/lib/daemon/lanes-reconcile-guard.js +4 -4
  54. package/dist/lib/daemon/mesh-owner.d.ts +4 -0
  55. package/dist/lib/daemon/mesh-owner.js +20 -0
  56. package/dist/lib/daemon/ops/policy.d.ts +3 -0
  57. package/dist/lib/daemon/ops/policy.js +32 -4
  58. package/dist/lib/daemon/run.d.ts +17 -1
  59. package/dist/lib/daemon/run.js +24 -3
  60. package/dist/lib/daemon/server.d.ts +6 -0
  61. package/dist/lib/daemon/server.js +5 -0
  62. package/dist/lib/daemon/verified-jq.d.ts +96 -0
  63. package/dist/lib/daemon/verified-jq.js +337 -0
  64. package/dist/lib/doctor/checks/jq.js +16 -0
  65. package/dist/lib/doctor/deep/executor.d.ts +7 -0
  66. package/dist/lib/doctor/deep/executor.js +1 -1
  67. package/dist/lib/doctor/deep/parity.js +1 -27
  68. package/dist/lib/doctor/deep/sandbox.d.ts +2 -2
  69. package/dist/lib/doctor/deep/sandbox.js +3 -19
  70. package/dist/lib/doctor/fix/refresh-sync-handoff.js +52 -21
  71. package/dist/lib/doctor/fixtures/discover.d.ts +2 -0
  72. package/dist/lib/doctor/fixtures/discover.js +1 -1
  73. package/dist/lib/doctor/json-output.d.ts +1 -1
  74. package/dist/lib/doctor/registry.d.ts +6 -7
  75. package/dist/lib/doctor/registry.js +6 -7
  76. package/dist/lib/doctor/report.d.ts +9 -10
  77. package/dist/lib/doctor/report.js +4 -4
  78. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  79. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  80. package/dist/lib/jq/install.d.ts +27 -0
  81. package/dist/lib/jq/install.js +156 -0
  82. package/dist/lib/lanes/outpost-dispatch.d.ts +1 -1
  83. package/dist/lib/lanes/outpost-dispatch.js +13 -13
  84. package/dist/lib/lanes/outpost-pruner-install.js +1 -1
  85. package/dist/lib/mesh/live/daemon/doctor.js +7 -1
  86. package/dist/lib/mesh/live/daemon/install.d.ts +4 -0
  87. package/dist/lib/mesh/live/daemon/install.js +10 -0
  88. package/dist/lib/mesh/live/daemon/run.js +17 -0
  89. package/dist/lib/mesh/live/emit-retry.d.ts +20 -2
  90. package/dist/lib/mesh/live/emit-retry.js +57 -4
  91. package/dist/lib/mesh/live/emit.js +25 -4
  92. package/dist/lib/mesh/live/flush.d.ts +2 -0
  93. package/dist/lib/mesh/live/flush.js +21 -8
  94. package/dist/lib/mesh/live/spool.d.ts +9 -1
  95. package/dist/lib/mesh/live/spool.js +41 -29
  96. package/dist/lib/sync-core/rollout-state.d.ts +9 -1
  97. package/dist/lib/sync-core/rollout-state.js +34 -4
  98. package/dist/lib/windows/jq.d.ts +4 -0
  99. package/dist/lib/windows/jq.js +10 -39
  100. package/dist/lib/workers-registry/index.js +7 -11
  101. package/dist/utils/callback-port-busy.d.ts +2 -2
  102. package/dist/utils/callback-port-busy.js +2 -2
  103. package/dist/utils/cli-network-lifecycle.js +1 -0
  104. package/dist/utils/client-health-contract.d.ts +2 -0
  105. package/dist/utils/client-health-contract.js +1 -1
  106. package/dist/utils/client-health.js +1 -9
  107. package/dist/utils/cognito-config.js +5 -0
  108. package/dist/utils/cognito-session.d.ts +4 -6
  109. package/dist/utils/cognito-session.js +4 -24
  110. package/dist/utils/incomplete-install-error.js +1 -11
  111. package/dist/utils/install-tree-torn.d.ts +11 -0
  112. package/dist/utils/install-tree-torn.js +1 -1
  113. package/dist/utils/resident-package-preload.js +2 -1
  114. package/docs/anywhere-runtime.md +8 -0
  115. package/package.json +9 -9
@@ -20,8 +20,9 @@ import { SERVER_OWNED_FOLDERS, findServerOwnedLocalOnly, } from "../lib/sync/ser
20
20
  import chalk from "chalk";
21
21
  import * as fs from "fs";
22
22
  import * as path from "path";
23
- import { share, getStateDir, listJournals, createIgnoreFilter, VaultClient, computePersonalVaultPaths, PERSONAL_VAULT_JOURNAL_SLUG, resolvePullScope, readSyncProgress, syncDoctor, } from "@indigoai-us/hq-cloud";
24
- import { syncLeg } from "../utils/sync-operation-lock.js";
23
+ import { share, getStateDir, listJournals, createIgnoreFilter, VaultClient, computePersonalVaultPaths, PERSONAL_VAULT_JOURNAL_SLUG, resolvePullScope, readSyncProgress, syncDoctor, isTerminalIdentityRefusal, scopeLookupSkipMessage, SyncScopeLookupError, } from "@indigoai-us/hq-cloud";
24
+ import { syncLeg, syncUnderOperationLock } from "../utils/sync-operation-lock.js";
25
+ import { keyedSyncPull } from "./keyed-sync-pull.js";
25
26
  import { SYNC_WATCHDOG_EXIT_CODE, SYNC_WATCHDOG_REPORT_GRACE_MS, SyncWatchdogTimeoutError, createSnapshotProgressProbe, resolveSyncWatchdogLimits, withSyncWatchdog, } from "../utils/sync-watchdog.js";
26
27
  import { DEFAULT_HQ_ROOT, ensureCognitoToken, buildVaultConfig, IdentitySwapRefusal, cognitoCachePrincipalUid, isDefinitivePersonAuthRejection, isIdentitySwapRefusal, loadCachedTokens, refreshCachedSession, } from "../utils/cognito-session.js";
27
28
  import { resolveUploadAuthor } from "../utils/upload-author.js";
@@ -258,6 +259,15 @@ export function formatSyncFailure(err, ctx = {}) {
258
259
  isIdentitySwapRefusal(err)) {
259
260
  return err.message;
260
261
  }
262
+ if (err instanceof SyncScopeLookupError) {
263
+ // A session refusal on the lookup's first request reaches us wrapped and
264
+ // without its cause; the run's vault config recorded the refusal, which
265
+ // carries the sign-in fix. Otherwise the bounded skip line stands.
266
+ const recorded = SCOPE_LOOKUP_SESSION_REFUSAL_CLASSES.has(err.errorClass)
267
+ ? syncAuthFailureFor(ctx.vaultConfig)
268
+ : null;
269
+ return recorded ? recorded.message : err.message;
270
+ }
261
271
  if (isVaultAuthRejection(err)) {
262
272
  // hq-cloud's 401 retry swallowed the token-function error; report it.
263
273
  const recorded = syncAuthFailureFor(ctx.vaultConfig);
@@ -822,6 +832,49 @@ function isSkippedCompany(skip, slug, companyUid) {
822
832
  return false;
823
833
  return skip.has(slug.toLowerCase()) || skip.has(companyUid.toLowerCase());
824
834
  }
835
+ // The skip message and error class come from hq-cloud (>= 6.18.117), whose
836
+ // resolvePullScope throws SyncScopeLookupError when a lookup fails. Re-exported
837
+ // so callers and tests match on the one class hq-cloud throws.
838
+ export { scopeLookupSkipMessage, SyncScopeLookupError };
839
+ /** An error's class name, or "UnknownError". hq-cloud bounds it further. */
840
+ function errorClassOf(err) {
841
+ return err instanceof Error ? err.name : "UnknownError";
842
+ }
843
+ /**
844
+ * Auth refusals during a scope lookup. hq-cloud rethrows VaultAuthError and a
845
+ * terminal Cognito refusal unchanged; the CLI's own token getter throws the
846
+ * session and identity-swap refusals. These keep their sign-in message.
847
+ */
848
+ function isScopeLookupAuthRefusal(err) {
849
+ return (err instanceof SyncSessionExpiredError ||
850
+ err instanceof SyncSessionRejectedError ||
851
+ isIdentitySwapRefusal(err) ||
852
+ isVaultAuthRejection(err) ||
853
+ isTerminalIdentityRefusal(err));
854
+ }
855
+ /**
856
+ * Session refusals from the CLI's token getter. When one is thrown on the
857
+ * lookup's first request, hq-cloud's resolver wraps it in a
858
+ * SyncScopeLookupError with no cause; the run's vault config still records
859
+ * the refusal itself.
860
+ */
861
+ const SCOPE_LOOKUP_SESSION_REFUSAL_CLASSES = new Set([
862
+ "SyncSessionExpiredError",
863
+ "SyncSessionRejectedError",
864
+ "IdentitySwapRefusal",
865
+ ]);
866
+ /**
867
+ * The per-company line for a failed scope lookup in `--all` runs. The company
868
+ * is skipped either way. A SyncScopeLookupError or an auth refusal goes
869
+ * through the run's failure formatter (the bounded skip line, or the sign-in
870
+ * fix); anything else gets the bounded skip line built here.
871
+ */
872
+ function scopeLookupFailureMessage(company, err, formatFailure = formatSyncFailure) {
873
+ if (err instanceof SyncScopeLookupError || isScopeLookupAuthRefusal(err)) {
874
+ return formatFailure(err);
875
+ }
876
+ return scopeLookupSkipMessage(company, errorClassOf(err));
877
+ }
825
878
  export async function pullAll(options, deps) {
826
879
  const memberships = await deps.vaultClient.listMyMemberships();
827
880
  const persons = await deps.vaultClient.listPersonEntities();
@@ -884,8 +937,10 @@ export async function pullAll(options, deps) {
884
937
  // old code resolved the mode for the banner and then called sync() with NO
885
938
  // scope, so every CLI pull ran `syncMode: "all"` and stamped an all-mode
886
939
  // PullRecord that wedged the next menubar sync (all→shared scope-shrink).
887
- // The shared `resolvePullScope` (via deps.resolveScope) degrades to `all`
888
- // on any failure, so a transient blip never narrows scope.
940
+ // The shared `resolvePullScope` (via deps.resolveScope) fails closed since
941
+ // hq-cloud 6.18.117: a failed or denied lookup throws (SyncScopeLookupError,
942
+ // or the auth refusal itself) instead of answering `all`. The company is
943
+ // then skipped (audit item 4): its leg never runs without a scope.
889
944
  let resolvedMode;
890
945
  if (entry.companyUid && deps.resolveScope) {
891
946
  try {
@@ -902,8 +957,11 @@ export async function pullAll(options, deps) {
902
957
  entry.syncOptions.excludePrefixes = excludePrefixes;
903
958
  }
904
959
  }
905
- catch {
906
- resolvedMode = undefined;
960
+ catch (err) {
961
+ const message = scopeLookupFailureMessage(entry.slug, err, deps.formatFailure);
962
+ result.errors.push({ company: entry.slug, message });
963
+ result.perCompany.push({ slug: entry.slug, error: message });
964
+ continue;
907
965
  }
908
966
  }
909
967
  else if (entry.membershipKey && getSyncConfig) {
@@ -1048,8 +1106,13 @@ export async function pushAll(options, deps) {
1048
1106
  entry.shareOptions.prefixSet = scope.prefixSet;
1049
1107
  }
1050
1108
  }
1051
- catch {
1052
- // Degrade to no explicit scope filter — share() treats undefined as full access.
1109
+ catch (err) {
1110
+ // Audit item 4: skip this company. share() treats a missing prefixSet
1111
+ // as full access, so pushing on would widen the upload.
1112
+ const message = scopeLookupFailureMessage(entry.slug, err, deps.formatFailure);
1113
+ result.errors.push({ company: entry.slug, message });
1114
+ result.perCompany.push({ slug: entry.slug, error: message });
1115
+ continue;
1053
1116
  }
1054
1117
  }
1055
1118
  try {
@@ -1237,11 +1300,14 @@ function readActiveCompany(hqRoot) {
1237
1300
  * "all"` and stamped an all-mode PullRecord that wedged the next menubar sync.
1238
1301
  *
1239
1302
  * Delegates to the shared `resolvePullScope` (same resolver the runner uses),
1240
- * which degrades to `all` on any failure — so a transient blip never narrows
1241
- * scope. Returns `undefined` only when no company can be resolved at all (then
1242
- * `sync()` resolves the active company itself and pulls `all`, as before).
1303
+ * which fails closed since hq-cloud 6.18.117. Returns `undefined` only when no
1304
+ * company is named or active (then `sync()` resolves the active company itself
1305
+ * and pulls `all`, as before). When the lookup fails it throws (audit item 4):
1306
+ * an auth refusal is rethrown as-is so the sign-in message survives, and any
1307
+ * other failure is a bounded {@link SyncScopeLookupError}. The command then
1308
+ * stops for this company rather than syncing unscoped. Exported for tests.
1243
1309
  */
1244
- async function resolveCliPullScope(client, companyRef, hqRoot, onResolvedCompanyUid) {
1310
+ export async function resolveCliPullScope(client, companyRef, hqRoot, onResolvedCompanyUid) {
1245
1311
  const ref = companyRef ?? readActiveCompany(hqRoot);
1246
1312
  if (!ref)
1247
1313
  return undefined;
@@ -1271,11 +1337,29 @@ async function resolveCliPullScope(client, companyRef, hqRoot, onResolvedCompany
1271
1337
  }
1272
1338
  }
1273
1339
  }
1274
- catch {
1275
- // Can't resolve the membership set — degrade to no explicit scope.
1276
- return undefined;
1340
+ catch (err) {
1341
+ throw scopeLookupFailure(ref, err);
1342
+ }
1343
+ try {
1344
+ return await resolvePullScope(client, companyUid, slug, hqRoot);
1345
+ }
1346
+ catch (err) {
1347
+ throw scopeLookupFailure(slug, err);
1277
1348
  }
1278
- return resolvePullScope(client, companyUid, slug, hqRoot);
1349
+ }
1350
+ /**
1351
+ * The error a failed single-company scope lookup throws. Auth refusals keep
1352
+ * their own curated message (formatSyncFailure renders the sign-in fix);
1353
+ * everything else becomes a bounded SyncScopeLookupError.
1354
+ */
1355
+ function scopeLookupFailure(company, err) {
1356
+ if (err instanceof SyncScopeLookupError)
1357
+ return err;
1358
+ if (isScopeLookupAuthRefusal(err))
1359
+ return err;
1360
+ // `retryable` only drives the sync runner's transient-blip reporting, which
1361
+ // the CLI does not use.
1362
+ return new SyncScopeLookupError(company, errorClassOf(err), false);
1279
1363
  }
1280
1364
  /**
1281
1365
  * The progress-snapshot label share()'s default recorder would use: the
@@ -1304,6 +1388,11 @@ function printPlanLimitRefusal(summary, indent = " ") {
1304
1388
  }
1305
1389
  }
1306
1390
  export function registerCloudCommands(program) {
1391
+ program.hook("preAction", (_group, action) => {
1392
+ if (process.env.HQ_API_KEY !== undefined && ["push", "now"].includes(action.name())) {
1393
+ throw Object.assign(new Error("HQ_API_KEY sync is read-only; push and now are refused. Use sync pull with an explicit company UID and --company-slug."), { expected: true });
1394
+ }
1395
+ });
1307
1396
  program
1308
1397
  .command("push")
1309
1398
  .description("Push local file(s) to the company vault on S3")
@@ -1740,6 +1829,7 @@ export function registerCloudCommands(program) {
1740
1829
  program
1741
1830
  .command("pull")
1742
1831
  .description("Pull permitted files from the company vault to local HQ")
1832
+ .option("--company-slug <slug>", "Trusted local layout slug; required with HQ_API_KEY and --company cmp_…")
1743
1833
  .option("--hq-root <path>", `Local HQ tree root (default: ${DEFAULT_HQ_ROOT})`, DEFAULT_HQ_ROOT)
1744
1834
  .option("--company <slug>", "Company slug or UID (defaults to active company in .hq/config.json)")
1745
1835
  .option("--lock-timeout <seconds>", "Maximum wait for another active HQ operation (default: 300; 0 = refuse immediately)")
@@ -1765,6 +1855,20 @@ export function registerCloudCommands(program) {
1765
1855
  "disk and only un-tracked from sync; clean out-of-scope files are " +
1766
1856
  "quarantined under .hq/scope-quarantine/ (recoverable).")
1767
1857
  .action(async (options) => {
1858
+ if (process.env.HQ_API_KEY !== undefined) {
1859
+ if (options.all || options.personal !== undefined || options.forceScopeShrink || options.onConflict || options.modeAll) {
1860
+ throw Object.assign(new Error("Keyed pull requires one company; fanout, personal, scope-shrink and conflict options are unsupported."), { expected: true });
1861
+ }
1862
+ configureSyncLockTimeout(options.lockTimeout);
1863
+ const result = await syncUnderOperationLock({
1864
+ hqRoot: options.hqRoot,
1865
+ company: options.company,
1866
+ companySlug: options.companySlug,
1867
+ token: process.env.HQ_API_KEY.trim(),
1868
+ }, { sync: keyedSyncPull });
1869
+ console.log(`Keyed pull: ${result.filesDownloaded} files downloaded; unlisted local files preserved.`);
1870
+ return;
1871
+ }
1768
1872
  const skips = refuseSyncForOffVaults("pull", {
1769
1873
  all: options.all,
1770
1874
  personal: options.personal,
@@ -1814,8 +1918,9 @@ export function registerCloudCommands(program) {
1814
1918
  const pullClient = new VaultClient(vaultConfig);
1815
1919
  const { resolvedCompanyUid, resolvedMode } = await resolvePerCompanyPullPlan(pullClient, options.company);
1816
1920
  // DEV-1768: resolve the REAL effective scope (mode + prefixSet) and
1817
- // thread it into the pull below — not just the banner. Best-effort;
1818
- // degrades to "all" inside the resolver on any failure.
1921
+ // thread it into the pull below — not just the banner. A failed
1922
+ // lookup throws and stops the pull (audit item 4); it never falls
1923
+ // back to an unscoped "all" pull.
1819
1924
  const pullScope = await resolveCliPullScope(pullClient, options.company, options.hqRoot);
1820
1925
  // Size gate: only a large local folder is nudged / strict-refused.
1821
1926
  const nudgeExceedsSize = resolvedMode === "all" &&
@@ -2627,14 +2732,11 @@ async function runNowSingle(hqRoot, company, personal, message, onConflict, mode
2627
2732
  // DEV-1768: resolve the membership's real scope and thread it into the
2628
2733
  // pull leg, so `hq sync now` stops seeding all-mode PullRecords. Personal
2629
2734
  // targets have no membership scope — they stay full ("all").
2735
+ // A failed lookup throws (audit item 4) and stops this run through the
2736
+ // outer catch; it never falls back to an unscoped pull.
2630
2737
  let pullScope;
2631
2738
  if (!personalMode) {
2632
- try {
2633
- pullScope = await resolveCliPullScope(new VaultClient(vaultConfig), targetCompany, hqRoot);
2634
- }
2635
- catch {
2636
- pullScope = undefined;
2637
- }
2739
+ pullScope = await resolveCliPullScope(new VaultClient(vaultConfig), targetCompany, hqRoot);
2638
2740
  }
2639
2741
  console.log(chalk.dim(" → pull leg"));
2640
2742
  const excludePrefixes = readScopeExcludePrefixes(pullScope);
@@ -704,18 +704,43 @@ function runGrant(args, context) {
704
704
  return fail("grant", `share timed out for ${prefix}; retain this manifest and resume`);
705
705
  if (shareRc !== 0)
706
706
  err(`hq-delegate-grant: share reported an error on ${prefix}; checking exact grant\n`);
707
- let landed = false;
708
- for (const delay of [0, 1, 2]) {
709
- if (delay)
710
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, delay * 1000);
711
- const after = readAcl(aclPattern);
712
- if (after.ok && after.value?.exists === true && list(after.value.direct).some((row) => isRecord(row) && row.granteeType === expectedType && row.granteeId === expectedId && row.permission === permission)) {
713
- landed = true;
714
- break;
707
+ const grantLanded = (pattern) => {
708
+ for (const delay of [0, 1, 2]) {
709
+ if (delay)
710
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, delay * 1000);
711
+ const after = readAcl(pattern);
712
+ if (after.ok && after.value?.exists === true && list(after.value.direct).some((row) => isRecord(row) && row.granteeType === expectedType && row.granteeId === expectedId && row.permission === permission)) {
713
+ return after.value;
714
+ }
715
715
  }
716
- }
717
- if (!landed)
716
+ return undefined;
717
+ };
718
+ const landedAcl = grantLanded(aclPattern);
719
+ if (!landedAcl)
718
720
  return fail("grant", `grant outcome unconfirmed for ${principal} on ${prefix}; retain this manifest and resume`);
721
+ // Full-transfer mode: a more specific rule under the project prefix (for
722
+ // example projects/<name>/design/*) outranks the root grant, so the
723
+ // recipient would keep the narrower permission there. Grant the same
724
+ // permission on every such rule and verify each one. A rule outside the
725
+ // project stops the grant.
726
+ if (jqRawPath(manifest, "mode") === "transfer" && prefix.startsWith(`projects/${project}/`)) {
727
+ const children = [...new Set(list(landedAcl.children)
728
+ .map((child) => isRecord(child) ? child.sourcePrefix : undefined)
729
+ .filter((source) => typeof source === "string"
730
+ && source.startsWith(prefix) && source.endsWith("/*") && source !== aclPattern))].sort();
731
+ for (const child of children) {
732
+ if (!child.startsWith(`projects/${project}/`))
733
+ return fail("grant", `more specific rule ${child} is outside projects/${project}/`);
734
+ const childShare = grantHq(["files", "share", child, "--with", grantPrincipal, "--permission", permission, "--company", company], context, "inherit");
735
+ if (childShare.timedOut)
736
+ return fail("grant", `share timed out for more specific rule ${child}; retain this manifest and resume`);
737
+ if (childShare.code !== 0)
738
+ err(`hq-delegate-grant: share reported an error on ${child}; checking exact grant\n`);
739
+ if (!grantLanded(child))
740
+ return fail("grant", `grant outcome unconfirmed for ${principal} on more specific rule ${child}; retain this manifest and resume`);
741
+ out(`hq-delegate-grant: verified ${permission} on more specific rule ${child} for ${principal}\n`);
742
+ }
743
+ }
719
744
  const current = list(manifest.vaultPrefixes)[i];
720
745
  if (!isRecord(current))
721
746
  return fail("grant", "manifest has an invalid vaultPrefixes entry");
@@ -2,6 +2,7 @@
2
2
  import * as fs from "node:fs";
3
3
  import { Command } from "commander";
4
4
  import { type SpawnPlan } from "../utils/windows-spawn.js";
5
+ import { delegateBoardPath, delegateRepoDirectory, secretsSourcePaths } from "../lib/core-utils/delegate-helper-paths.js";
5
6
  export declare const CORE_NATIVE_DELEGATE_FLAG = "core-native-delegate";
6
7
  type DelegateName = "resolve" | "pickup" | "repo" | "secrets" | "transfer";
7
8
  export type DelegateContext = {
@@ -55,6 +56,7 @@ export declare function moveFile(source: string, target: string, fileSystem?: Pi
55
56
  export declare function writeJsonAtomically(target: string, value: unknown, siblingTemp?: boolean, fileSystem?: DelegateAtomicWriteFileSystem): void;
56
57
  export declare function delegateDiagnosticPath(argument: string): string;
57
58
  export declare function scanSecretFiles(file: string): string[] | undefined;
59
+ export { delegateBoardPath, delegateRepoDirectory, secretsSourcePaths };
58
60
  export declare function runNative(name: DelegateName, args: string[], context: DelegateContext): number;
59
61
  /** Fast-entry adapter; family gating and shell fallback happen before import. */
60
62
  export declare function runDelegateFast(args: readonly string[], _stdin: string, cwd: string, hqRoot: string | undefined, commandName: string): number;
@@ -74,5 +76,4 @@ export type DelegateRunOptions = {
74
76
  export declare function runDelegateFlow(options: DelegateRunOptions, context: DelegateContext): Promise<number>;
75
77
  /** Register the Wave 1a delegate commands and preserve the shell rollback path. */
76
78
  export declare function registerCoreDelegateCommand(core: Command, registerWave1b?: (delegate: Command, core: Command) => void): void;
77
- export {};
78
79
  //# sourceMappingURL=core-delegate.d.ts.map