@indigoai-us/hq-cli 5.345.222 → 5.345.223
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/CHANGELOG.md +23 -0
- package/dist/command-catalog.generated.d.ts +1 -1
- package/dist/command-catalog.generated.js +1 -1
- package/dist/commands/bot.d.ts +1 -1
- package/dist/commands/bot.js +34 -33
- package/dist/commands/core-delegate-w1b.js +207 -187
- package/dist/commands/packs.js +13 -2
- package/dist/commands/sync-core.js +31 -12
- package/dist/lib/bot/fleet-cron.d.ts +26 -3
- package/dist/lib/bot/fleet-cron.js +44 -4
- package/dist/lib/bot/run.d.ts +4 -4
- package/dist/lib/bot/run.js +5 -3
- package/dist/lib/bot/signals-engine-flag.d.ts +53 -13
- package/dist/lib/bot/signals-engine-flag.js +202 -9
- package/dist/lib/daemon/machine-checks.d.ts +45 -0
- package/dist/lib/daemon/machine-checks.js +95 -11
- package/dist/lib/daemon/native-notice-ledger.d.ts +9 -0
- package/dist/lib/daemon/native-notice-ledger.js +43 -0
- package/dist/lib/daemon/run.js +3 -2
- package/dist/lib/daemon/supervisor.d.ts +10 -0
- package/dist/lib/daemon/supervisor.js +86 -0
- package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
- package/dist/lib/flag-registry-worker-source.generated.js +1 -1
- package/dist/lib/flag-registry-worker.js +33 -3
- package/dist/lib/flag-registry.js +13 -0
- package/dist/lib/scan-packages/index.js +8 -9
- package/dist/lib/signals/engine.d.ts +8 -0
- package/dist/lib/signals/engine.js +15 -5
- package/dist/lib/sync-core/flag.d.ts +18 -0
- package/dist/lib/sync-core/flag.js +66 -0
- package/dist/lib/sync-core/reconcile.d.ts +6 -0
- package/dist/lib/sync-core/reconcile.js +15 -0
- package/dist/lib/sync-core/rollout-state.d.ts +2 -0
- package/dist/lib/sync-core/rollout-state.js +7 -0
- package/dist/lib/sync-core/vault-settings.d.ts +12 -1
- package/dist/lib/sync-core/vault-settings.js +23 -7
- package/dist/utils/pack-contributions.d.ts +14 -2
- package/dist/utils/pack-contributions.js +31 -5
- package/package.json +7 -7
- package/scripts/bench-core.mjs +34 -3
|
@@ -518,200 +518,219 @@ function runGrant(args, context) {
|
|
|
518
518
|
return fail("grant", "--manifest is required");
|
|
519
519
|
if (!fs.existsSync(manifestPath) || !fs.statSync(manifestPath).isFile())
|
|
520
520
|
return fail("grant", `manifest not found: ${delegateDiagnosticPath(manifestPath)}`);
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
catch {
|
|
526
|
-
return fail("grant", `manifest is not valid JSON: ${delegateDiagnosticPath(manifestPath)}`);
|
|
527
|
-
}
|
|
528
|
-
if (manifest === null || manifest === false)
|
|
529
|
-
return fail("grant", `manifest is not valid JSON: ${delegateDiagnosticPath(manifestPath)}`);
|
|
530
|
-
if (!isRecord(manifest))
|
|
531
|
-
return fail("grant", "manifest has no company");
|
|
532
|
-
const company = jqRawPath(manifest, "company");
|
|
533
|
-
const project = jqRawPath(manifest, "project.name");
|
|
534
|
-
const principal = jqRawPath(manifest, "to.principal");
|
|
535
|
-
const display = jqRawPaths(manifest, ["to.displayName", "to.principal"]);
|
|
536
|
-
const status = jqRawPath(manifest, "status");
|
|
537
|
-
if (!company)
|
|
538
|
-
return fail("grant", "manifest has no company");
|
|
539
|
-
if (!project)
|
|
540
|
-
return fail("grant", "manifest has no project.name");
|
|
541
|
-
if (!principal)
|
|
542
|
-
return fail("grant", "manifest has no to.principal");
|
|
543
|
-
let grantPrincipal = principal;
|
|
544
|
-
if (principal.startsWith("agt_")) {
|
|
545
|
-
const legacyGroup = "grp_dlg-" + principal.slice(-9).toLowerCase();
|
|
546
|
-
const nextGroup = delegationGroupId(principal);
|
|
547
|
-
const recordedGroup = text(getPath(manifest, "grantPrincipal"));
|
|
548
|
-
grantPrincipal = recordedGroup === legacyGroup || recordedGroup === nextGroup ? recordedGroup : nextGroup;
|
|
549
|
-
}
|
|
550
|
-
if (status !== "building" && status !== "granted")
|
|
551
|
-
return fail("grant", `manifest status is '${status}' — grants run from 'building' (or re-run from 'granted'), not from there`);
|
|
552
|
-
const prefixes = list(getPath(manifest, "vaultPrefixes"));
|
|
553
|
-
if (prefixes.length === 0)
|
|
554
|
-
return fail("grant", "manifest has no vaultPrefixes");
|
|
555
|
-
const badPrefixes = prefixes.filter((entry) => {
|
|
556
|
-
const prefix = jqRawPath(entry, "prefix");
|
|
557
|
-
return !prefix.endsWith("/") || prefix.startsWith("companies/") || prefix.startsWith("/");
|
|
558
|
-
}).map((entry) => jqRawPath(entry, "prefix"));
|
|
559
|
-
if (badPrefixes.length)
|
|
560
|
-
return fail("grant", `prefix violates the hq-files prefix conventions (must be company-relative folder form ending in '/'): ${badPrefixes.join("\n")}`);
|
|
561
|
-
out(`Delegation grant plan — company '${company}', recipient '${principal}':\n`);
|
|
562
|
-
if (grantPrincipal !== principal)
|
|
563
|
-
out(` 0. Agent recipient: grants flow through group ${grantPrincipal} (created if absent, containing exactly ${display})\n`);
|
|
564
|
-
out(` 1. Push companies/${company}/projects/${project}/ to the vault (on-conflict keep)\n`);
|
|
565
|
-
for (const entry of prefixes)
|
|
566
|
-
out(` 2. Grant ${jqRawPath(entry, "permission")} on ${jqRawPath(entry, "prefix")} — ${jqRawPath(entry, "reason")}\n`);
|
|
567
|
-
const writePrefixes = prefixes.map((entry) => jqRawPath(entry, "permission") === "write" ? jqRawPath(entry, "prefix") : "").filter(Boolean);
|
|
568
|
-
if (writePrefixes.length) {
|
|
569
|
-
out(`\nNOTE: granting 'write' is a privilege escalation. The recipient will be able\nto upload, overwrite, and delete under: ${writePrefixes.map((prefix) => `${prefix} `).join("")}\n`);
|
|
570
|
-
}
|
|
571
|
-
if (!yes) {
|
|
572
|
-
out("\n");
|
|
573
|
-
err("hq-delegate-grant: confirmation required — re-run with --yes after the user approves\n");
|
|
574
|
-
return 2;
|
|
575
|
-
}
|
|
576
|
-
let result = runHq(["sync", "push", `companies/${company}/projects/${project}/`, "--company", company, "--on-conflict", "keep"], context, "inherit");
|
|
577
|
-
if (result.code !== 0)
|
|
578
|
-
return fail("grant", `vault push failed for companies/${company}/projects/${project}/`);
|
|
579
|
-
const referencePaths = [
|
|
580
|
-
...list(getPath(manifest, "knowledge", [])),
|
|
581
|
-
...list(getPath(manifest, "policies", [])),
|
|
582
|
-
].filter((entry) => typeof entry === "string" && entry.startsWith(`companies/${company}/`));
|
|
583
|
-
for (const reference of referencePaths) {
|
|
584
|
-
if (fs.existsSync(path.join(context.root ?? context.cwd, reference))) {
|
|
585
|
-
result = runHq(["sync", "push", reference, "--company", company, "--on-conflict", "keep"], context, "inherit");
|
|
586
|
-
if (result.code !== 0)
|
|
587
|
-
return fail("grant", `vault push failed for referenced knowledge: ${reference}`);
|
|
588
|
-
}
|
|
589
|
-
else {
|
|
590
|
-
err(`hq-delegate-grant: referenced path missing locally (cannot push): ${reference} — the verify probe will fail if it is not already in the vault\n`);
|
|
521
|
+
const lock = `${manifestPath}.send-lock`;
|
|
522
|
+
if (yes) {
|
|
523
|
+
try {
|
|
524
|
+
fs.mkdirSync(lock);
|
|
591
525
|
}
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
result = runHq(["groups", "create", grantPrincipal, "--name", `Delegation: ${display}`, "--company", company], context, "inherit");
|
|
595
|
-
if (result.code !== 0)
|
|
596
|
-
err("hq-delegate-grant: group create reported an error (may already exist) — continuing\n");
|
|
597
|
-
result = runHq(["groups", "add", grantPrincipal, principal, "--company", company], context, "inherit");
|
|
598
|
-
if (result.code !== 0)
|
|
599
|
-
err("hq-delegate-grant: group add reported an error (may already be a member) — continuing\n");
|
|
600
|
-
const members = subprocess("hq", ["groups", "members", grantPrincipal, "--company", company], context.cwd, { env: { NO_COLOR: "1", FORCE_COLOR: "0" } });
|
|
601
|
-
if (members.code !== 0)
|
|
602
|
-
return fail("grant", "could not verify delegation group membership");
|
|
603
|
-
const memberIds = groupMemberIds(members.stdout ?? "");
|
|
604
|
-
if (memberIds === null || memberIds.length !== 1 || memberIds[0] !== principal) {
|
|
605
|
-
return fail("grant", "delegation group membership does not exactly match recipient");
|
|
526
|
+
catch {
|
|
527
|
+
return fail("grant", "verification or delivery is active; retry after it finishes");
|
|
606
528
|
}
|
|
607
529
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
let expectedCompany = "";
|
|
611
|
-
if (grantPrincipal.startsWith("grp_")) {
|
|
612
|
-
expectedType = "group";
|
|
613
|
-
expectedId = grantPrincipal;
|
|
614
|
-
}
|
|
615
|
-
else if (grantPrincipal === "@all") {
|
|
616
|
-
expectedType = "company-wide";
|
|
617
|
-
}
|
|
618
|
-
else {
|
|
619
|
-
const resolved = runHq(["people", "resolve", principal, "--company", company, "--json", "--membership-only"], context);
|
|
620
|
-
let response;
|
|
530
|
+
try {
|
|
531
|
+
let manifest;
|
|
621
532
|
try {
|
|
622
|
-
|
|
533
|
+
manifest = readJsonFile(manifestPath);
|
|
623
534
|
}
|
|
624
|
-
catch
|
|
625
|
-
|
|
626
|
-
const input = commandSubstitutionBytes(resolved);
|
|
627
|
-
emitJqParseDiagnostic(input, ["-e", RESOLVE_FOUND_FILTER], context);
|
|
628
|
-
emitJqParseDiagnostic(input, ["-e", RESOLVE_NOT_FOUND_FILTER], context);
|
|
629
|
-
}
|
|
630
|
-
response = undefined;
|
|
535
|
+
catch {
|
|
536
|
+
return fail("grant", `manifest is not valid JSON: ${delegateDiagnosticPath(manifestPath)}`);
|
|
631
537
|
}
|
|
632
|
-
if (
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
538
|
+
if (manifest === null || manifest === false)
|
|
539
|
+
return fail("grant", `manifest is not valid JSON: ${delegateDiagnosticPath(manifestPath)}`);
|
|
540
|
+
if (!isRecord(manifest))
|
|
541
|
+
return fail("grant", "manifest has no company");
|
|
542
|
+
const company = jqRawPath(manifest, "company");
|
|
543
|
+
const project = jqRawPath(manifest, "project.name");
|
|
544
|
+
const principal = jqRawPath(manifest, "to.principal");
|
|
545
|
+
const display = jqRawPaths(manifest, ["to.displayName", "to.principal"]);
|
|
546
|
+
const status = jqRawPath(manifest, "status");
|
|
547
|
+
if (!company)
|
|
548
|
+
return fail("grant", "manifest has no company");
|
|
549
|
+
if (!project)
|
|
550
|
+
return fail("grant", "manifest has no project.name");
|
|
551
|
+
if (!principal)
|
|
552
|
+
return fail("grant", "manifest has no to.principal");
|
|
553
|
+
let grantPrincipal = principal;
|
|
554
|
+
if (principal.startsWith("agt_")) {
|
|
555
|
+
const legacyGroup = "grp_dlg-" + principal.slice(-9).toLowerCase();
|
|
556
|
+
const nextGroup = delegationGroupId(principal);
|
|
557
|
+
const recordedGroup = text(getPath(manifest, "grantPrincipal"));
|
|
558
|
+
grantPrincipal = recordedGroup === legacyGroup || recordedGroup === nextGroup ? recordedGroup : nextGroup;
|
|
638
559
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
560
|
+
if (status !== "building" && status !== "granted")
|
|
561
|
+
return fail("grant", `manifest status is '${status}' — grants run from 'building' (or re-run from 'granted'), not from there`);
|
|
562
|
+
const prefixes = list(getPath(manifest, "vaultPrefixes"));
|
|
563
|
+
if (prefixes.length === 0)
|
|
564
|
+
return fail("grant", "manifest has no vaultPrefixes");
|
|
565
|
+
const badPrefixes = prefixes.filter((entry) => {
|
|
566
|
+
const prefix = jqRawPath(entry, "prefix");
|
|
567
|
+
return !prefix.endsWith("/") || prefix.startsWith("companies/") || prefix.startsWith("/");
|
|
568
|
+
}).map((entry) => jqRawPath(entry, "prefix"));
|
|
569
|
+
if (badPrefixes.length)
|
|
570
|
+
return fail("grant", `prefix violates the hq-files prefix conventions (must be company-relative folder form ending in '/'): ${badPrefixes.join("\n")}`);
|
|
571
|
+
out(`Delegation grant plan — company '${company}', recipient '${principal}':\n`);
|
|
572
|
+
if (grantPrincipal !== principal)
|
|
573
|
+
out(` 0. Agent recipient: grants flow through group ${grantPrincipal} (created if absent, containing exactly ${display})\n`);
|
|
574
|
+
out(` 1. Push companies/${company}/projects/${project}/ to the vault (on-conflict keep)\n`);
|
|
575
|
+
for (const entry of prefixes)
|
|
576
|
+
out(` 2. Grant ${jqRawPath(entry, "permission")} on ${jqRawPath(entry, "prefix")} — ${jqRawPath(entry, "reason")}\n`);
|
|
577
|
+
const writePrefixes = prefixes.map((entry) => jqRawPath(entry, "permission") === "write" ? jqRawPath(entry, "prefix") : "").filter(Boolean);
|
|
578
|
+
if (writePrefixes.length) {
|
|
579
|
+
out(`\nNOTE: granting 'write' is a privilege escalation. The recipient will be able\nto upload, overwrite, and delete under: ${writePrefixes.map((prefix) => `${prefix} `).join("")}\n`);
|
|
646
580
|
}
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
const response = runHq(["files", "acl", prefix, "--company", company, "--json"], context);
|
|
652
|
-
if (response.code !== 0)
|
|
653
|
-
return { ok: false };
|
|
654
|
-
let value;
|
|
655
|
-
try {
|
|
656
|
-
value = JSON.parse(response.stdout ?? "");
|
|
581
|
+
if (!yes) {
|
|
582
|
+
out("\n");
|
|
583
|
+
err("hq-delegate-grant: confirmation required — re-run with --yes after the user approves\n");
|
|
584
|
+
return 2;
|
|
657
585
|
}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
586
|
+
let result = runHq(["sync", "push", `companies/${company}/projects/${project}/`, "--company", company, "--on-conflict", "keep"], context, "inherit");
|
|
587
|
+
if (result.code !== 0)
|
|
588
|
+
return fail("grant", `vault push failed for companies/${company}/projects/${project}/`);
|
|
589
|
+
const referencePaths = [
|
|
590
|
+
...list(getPath(manifest, "knowledge", [])),
|
|
591
|
+
...list(getPath(manifest, "policies", [])),
|
|
592
|
+
].filter((entry) => typeof entry === "string" && entry.startsWith(`companies/${company}/`));
|
|
593
|
+
for (const reference of referencePaths) {
|
|
594
|
+
if (fs.existsSync(path.join(context.root ?? context.cwd, reference))) {
|
|
595
|
+
result = runHq(["sync", "push", reference, "--company", company, "--on-conflict", "keep"], context, "inherit");
|
|
596
|
+
if (result.code !== 0)
|
|
597
|
+
return fail("grant", `vault push failed for referenced knowledge: ${reference}`);
|
|
598
|
+
}
|
|
599
|
+
else {
|
|
600
|
+
err(`hq-delegate-grant: referenced path missing locally (cannot push): ${reference} — the verify probe will fail if it is not already in the vault\n`);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
if (grantPrincipal !== principal) {
|
|
604
|
+
result = runHq(["groups", "create", grantPrincipal, "--name", `Delegation: ${display}`, "--company", company], context, "inherit");
|
|
605
|
+
if (result.code !== 0)
|
|
606
|
+
err("hq-delegate-grant: group create reported an error (may already exist) — continuing\n");
|
|
607
|
+
result = runHq(["groups", "add", grantPrincipal, principal, "--company", company], context, "inherit");
|
|
608
|
+
if (result.code !== 0)
|
|
609
|
+
err("hq-delegate-grant: group add reported an error (may already be a member) — continuing\n");
|
|
610
|
+
const members = subprocess("hq", ["groups", "members", grantPrincipal, "--company", company], context.cwd, { env: { NO_COLOR: "1", FORCE_COLOR: "0" } });
|
|
611
|
+
if (members.code !== 0)
|
|
612
|
+
return fail("grant", "could not verify delegation group membership");
|
|
613
|
+
const memberIds = groupMemberIds(members.stdout ?? "");
|
|
614
|
+
if (memberIds === null || memberIds.length !== 1 || memberIds[0] !== principal) {
|
|
615
|
+
return fail("grant", "delegation group membership does not exactly match recipient");
|
|
662
616
|
}
|
|
663
|
-
value = undefined;
|
|
664
617
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
618
|
+
let expectedType = "";
|
|
619
|
+
let expectedId = "";
|
|
620
|
+
let expectedCompany = "";
|
|
621
|
+
if (grantPrincipal.startsWith("grp_")) {
|
|
622
|
+
expectedType = "group";
|
|
623
|
+
expectedId = grantPrincipal;
|
|
670
624
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
if (after.ok && after.value?.exists === true && list(after.value.direct).some((row) => isRecord(row) && row.granteeType === expectedType && row.granteeId === expectedId && row.permission === permission)) {
|
|
695
|
-
landed = true;
|
|
696
|
-
break;
|
|
625
|
+
else if (grantPrincipal === "@all") {
|
|
626
|
+
expectedType = "company-wide";
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
const resolved = runHq(["people", "resolve", principal, "--company", company, "--json", "--membership-only"], context);
|
|
630
|
+
let response;
|
|
631
|
+
try {
|
|
632
|
+
response = JSON.parse(resolved.stdout ?? "");
|
|
633
|
+
}
|
|
634
|
+
catch (error) {
|
|
635
|
+
if (error instanceof SyntaxError) {
|
|
636
|
+
const input = commandSubstitutionBytes(resolved);
|
|
637
|
+
emitJqParseDiagnostic(input, ["-e", RESOLVE_FOUND_FILTER], context);
|
|
638
|
+
emitJqParseDiagnostic(input, ["-e", RESOLVE_NOT_FOUND_FILTER], context);
|
|
639
|
+
}
|
|
640
|
+
response = undefined;
|
|
641
|
+
}
|
|
642
|
+
if (isRecord(response) && response.status === "found" && isRecord(response.person) && typeof response.person.personUid === "string" && typeof response.person.companyUid === "string") {
|
|
643
|
+
if (resolved.code !== 0)
|
|
644
|
+
return fail("grant", "recipient resolution failed");
|
|
645
|
+
expectedType = "person";
|
|
646
|
+
expectedId = response.person.personUid;
|
|
647
|
+
expectedCompany = response.person.companyUid;
|
|
697
648
|
}
|
|
649
|
+
else if (isRecord(response) && response.status === "not_found") {
|
|
650
|
+
if (principal.includes("@")) {
|
|
651
|
+
expectedType = "email";
|
|
652
|
+
expectedId = principal.toLowerCase().trim();
|
|
653
|
+
}
|
|
654
|
+
else
|
|
655
|
+
return fail("grant", "unresolved recipient");
|
|
656
|
+
}
|
|
657
|
+
else
|
|
658
|
+
return fail("grant", "authoritative recipient lookup failed; update hq-cli if --membership-only is unsupported");
|
|
698
659
|
}
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
660
|
+
const readAcl = (prefix) => {
|
|
661
|
+
const response = runHq(["files", "acl", prefix, "--company", company, "--json"], context);
|
|
662
|
+
if (response.code !== 0)
|
|
663
|
+
return { ok: false };
|
|
664
|
+
let value;
|
|
665
|
+
try {
|
|
666
|
+
value = JSON.parse(response.stdout ?? "");
|
|
667
|
+
}
|
|
668
|
+
catch (error) {
|
|
669
|
+
if (error instanceof SyntaxError) {
|
|
670
|
+
const input = commandSubstitutionBytes(response);
|
|
671
|
+
emitJqParseDiagnostic(input, ["-e", "--arg", "prefix", prefix, "--arg", "company", expectedCompany, ACL_FILTER], context);
|
|
672
|
+
}
|
|
673
|
+
value = undefined;
|
|
674
|
+
}
|
|
675
|
+
const rawPrefix = isRecord(value) ? value.prefix : undefined;
|
|
676
|
+
const expectedPrefix = prefix.endsWith("/*") ? prefix.slice(0, -1) : prefix;
|
|
677
|
+
if (!isRecord(value) || value.schemaVersion !== 1 || (rawPrefix !== prefix && rawPrefix !== expectedPrefix) || typeof value.companyUid !== "string" || (expectedCompany !== "" && value.companyUid !== expectedCompany) || !Array.isArray(value.direct) || typeof value.exists !== "boolean") {
|
|
678
|
+
err(`hq-delegate-grant: invalid structured ACL response for ${prefix}\n`);
|
|
679
|
+
return { ok: false };
|
|
680
|
+
}
|
|
681
|
+
return { value, ok: true };
|
|
682
|
+
};
|
|
683
|
+
const now = currentTime();
|
|
684
|
+
for (let i = 0; i < prefixes.length; i += 1) {
|
|
685
|
+
const entry = prefixes[i];
|
|
686
|
+
if (!isRecord(entry) || !isRecord(manifest))
|
|
687
|
+
return fail("grant", "manifest has an invalid vaultPrefixes entry");
|
|
688
|
+
const prefix = jqRawPath(entry, "prefix");
|
|
689
|
+
const permission = jqRawPath(entry, "permission");
|
|
690
|
+
const aclPattern = `${prefix}*`;
|
|
691
|
+
const before = readAcl(aclPattern);
|
|
692
|
+
if (!before.ok || !before.value)
|
|
693
|
+
return fail("grant", `ACL preflight failed; no share attempted for ${prefix}`);
|
|
694
|
+
expectedCompany = text(before.value.companyUid);
|
|
695
|
+
const share = runHq(["files", "share", aclPattern, "--with", grantPrincipal, "--permission", permission, "--company", company], context, "inherit");
|
|
696
|
+
const shareRc = share.code;
|
|
697
|
+
if (shareRc !== 0)
|
|
698
|
+
err(`hq-delegate-grant: share reported an error on ${prefix}; checking exact grant\n`);
|
|
699
|
+
let landed = false;
|
|
700
|
+
for (const delay of [0, 1, 2]) {
|
|
701
|
+
if (delay)
|
|
702
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, delay * 1000);
|
|
703
|
+
const after = readAcl(aclPattern);
|
|
704
|
+
if (after.ok && after.value?.exists === true && list(after.value.direct).some((row) => isRecord(row) && row.granteeType === expectedType && row.granteeId === expectedId && row.permission === permission)) {
|
|
705
|
+
landed = true;
|
|
706
|
+
break;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
if (!landed)
|
|
710
|
+
return fail("grant", `grant outcome unconfirmed for ${principal} on ${prefix}; retain this manifest and resume`);
|
|
711
|
+
const current = list(manifest.vaultPrefixes)[i];
|
|
712
|
+
if (!isRecord(current))
|
|
713
|
+
return fail("grant", "manifest has an invalid vaultPrefixes entry");
|
|
714
|
+
current.verifiedAt = now;
|
|
715
|
+
current.grantReceipt = { companyUid: expectedCompany, granteeType: expectedType, granteeId: expectedId, shareExitCode: shareRc, verifiedAt: now };
|
|
716
|
+
writeJsonAtomically(manifestPath, manifest, true);
|
|
717
|
+
out(`hq-delegate-grant: verified ${permission} on ${prefix} for ${principal}\n`);
|
|
718
|
+
}
|
|
719
|
+
manifest.status = "granted";
|
|
720
|
+
manifest.grantPrincipal = grantPrincipal;
|
|
721
|
+
manifest.vaultPrefixes = list(manifest.vaultPrefixes).map((entry) => isRecord(entry) ? { ...entry, verifiedAt: now } : entry);
|
|
706
722
|
writeJsonAtomically(manifestPath, manifest, true);
|
|
707
|
-
out(`hq-delegate-grant:
|
|
723
|
+
out(`hq-delegate-grant: all ${prefixes.length} grants verified — manifest status advanced to 'granted'\n`);
|
|
724
|
+
return 0;
|
|
725
|
+
}
|
|
726
|
+
finally {
|
|
727
|
+
if (yes) {
|
|
728
|
+
try {
|
|
729
|
+
fs.rmdirSync(lock);
|
|
730
|
+
}
|
|
731
|
+
catch { /* Preserve the grant result. */ }
|
|
732
|
+
}
|
|
708
733
|
}
|
|
709
|
-
manifest.status = "granted";
|
|
710
|
-
manifest.grantPrincipal = grantPrincipal;
|
|
711
|
-
manifest.vaultPrefixes = list(manifest.vaultPrefixes).map((entry) => isRecord(entry) ? { ...entry, verifiedAt: now } : entry);
|
|
712
|
-
writeJsonAtomically(manifestPath, manifest, true);
|
|
713
|
-
out(`hq-delegate-grant: all ${prefixes.length} grants verified — manifest status advanced to 'granted'\n`);
|
|
714
|
-
return 0;
|
|
715
734
|
}
|
|
716
735
|
function atomicCopy(source, target, mode) {
|
|
717
736
|
const temporary = `${target}.tmp.${process.pid}.${Math.random().toString(16).slice(2)}`;
|
|
@@ -931,15 +950,6 @@ function runSend(args, context) {
|
|
|
931
950
|
return fail("send", "--manifest is required");
|
|
932
951
|
if (!fs.existsSync(manifestPath) || !fs.statSync(manifestPath).isFile())
|
|
933
952
|
return fail("send", `manifest not found: ${delegateDiagnosticPath(manifestPath)}`);
|
|
934
|
-
const manifest = jsonFile(manifestPath);
|
|
935
|
-
if (!manifest)
|
|
936
|
-
return fail("send", `manifest is not valid JSON: ${delegateDiagnosticPath(manifestPath)}`);
|
|
937
|
-
if (send) {
|
|
938
|
-
const publishedPath = path.join(context.root ?? context.cwd, jqRawPath(manifest, "publication.manifestPath"));
|
|
939
|
-
if (malformedJsonFile(publishedPath)) {
|
|
940
|
-
return runShellFallback("send", args, context);
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
953
|
const lock = `${manifestPath}.send-lock`;
|
|
944
954
|
if (send) {
|
|
945
955
|
try {
|
|
@@ -960,6 +970,16 @@ function runSend(args, context) {
|
|
|
960
970
|
catch { /* Preserve the command result if a concurrent process removed it. */ }
|
|
961
971
|
};
|
|
962
972
|
try {
|
|
973
|
+
const manifest = jsonFile(manifestPath);
|
|
974
|
+
if (!manifest)
|
|
975
|
+
return fail("send", `manifest is not valid JSON: ${delegateDiagnosticPath(manifestPath)}`);
|
|
976
|
+
if (send) {
|
|
977
|
+
const publishedPath = path.join(context.root ?? context.cwd, jqRawPath(manifest, "publication.manifestPath"));
|
|
978
|
+
if (malformedJsonFile(publishedPath)) {
|
|
979
|
+
removeLock();
|
|
980
|
+
return runShellFallback("send", args, context);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
963
983
|
const bundleDir = path.dirname(path.resolve(manifestPath));
|
|
964
984
|
const brief = path.join(bundleDir, "BRIEF.md");
|
|
965
985
|
const prompt = path.join(bundleDir, "PICKUP-PROMPT.md");
|
package/dist/commands/packs.js
CHANGED
|
@@ -29,7 +29,7 @@ import { findHqRoot } from '../utils/manifest.js';
|
|
|
29
29
|
import { resolveHqRoot as resolveDetectedHqRoot } from './doctor.js';
|
|
30
30
|
import { anywhereRuntimeAllowed } from '../lib/anywhere-person-setting.js';
|
|
31
31
|
import { classify, PINNED_HQ_ANYWHERE_SOURCE, resolveLatest, parseMarketplaceSource, resolveLatestMarketplace, runScanPackages, installPack, } from './pack-install.js';
|
|
32
|
-
import { contributionLinks, linkStatus, listInstalledPacks, findDependentPacks, readPackManifest, unwirePack, unwirePackMcp, readHqVersion, readRecommendedPackages, packagesDir, } from '../utils/pack-contributions.js';
|
|
32
|
+
import { contributionLinks, linkStatus, listInstalledPacks, findDependentPacks, readPackManifest, unwirePack, unwireNamespacedSkills, unwirePackMcp, readHqVersion, readRecommendedPackages, packagesDir, } from '../utils/pack-contributions.js';
|
|
33
33
|
import { readInstalledPackSetup } from '../lib/packages/setup-block.js';
|
|
34
34
|
import { syncCodexPackHooks, syncCodexPackSkills } from '../lib/install/codex-pack-contributions.js';
|
|
35
35
|
function resolveRoot(opts) {
|
|
@@ -275,7 +275,11 @@ export async function runUpdate(name, opts, deps = {}) {
|
|
|
275
275
|
syncCodexPackSkills(pack.dir, pname, m.contributes?.skills ?? [], true);
|
|
276
276
|
// Un-wire old contributions first so a contribution dropped by the new
|
|
277
277
|
// version doesn't leave a dangling host symlink. installPack re-wires.
|
|
278
|
-
|
|
278
|
+
// The namespaced `<pack>:<skill>` hosts stay: the pack directory is
|
|
279
|
+
// replaced in place, so they keep resolving, and removing them would
|
|
280
|
+
// hide `/<pack>:<skill>` until the next reindex. Hosts of skills the new
|
|
281
|
+
// version dropped are removed after the install below.
|
|
282
|
+
unwirePack(hqRoot, pack.dir, m.contributes ?? {}, { keepNamespacedSkills: true });
|
|
279
283
|
const prevCwd = process.cwd();
|
|
280
284
|
if (opts.hqRoot)
|
|
281
285
|
process.chdir(hqRoot); // installPack resolves via findHqRoot()
|
|
@@ -294,6 +298,13 @@ export async function runUpdate(name, opts, deps = {}) {
|
|
|
294
298
|
if (opts.hqRoot)
|
|
295
299
|
process.chdir(prevCwd);
|
|
296
300
|
}
|
|
301
|
+
// An unreadable new manifest says nothing about which skills were
|
|
302
|
+
// dropped, so leave the namespaced hosts for reindex to reconcile.
|
|
303
|
+
const newManifest = readPackManifest(pack.dir).manifest;
|
|
304
|
+
if (newManifest) {
|
|
305
|
+
const newSkills = new Set(newManifest.contributes?.skills ?? []);
|
|
306
|
+
unwireNamespacedSkills(hqRoot, pack.dir, (m.contributes?.skills ?? []).filter((item) => !newSkills.has(item)));
|
|
307
|
+
}
|
|
297
308
|
results.push({ ...base, applied: true });
|
|
298
309
|
}
|
|
299
310
|
catch (e) {
|
|
@@ -3,13 +3,13 @@ import * as os from "node:os";
|
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import { ensureSyncCoreBinary, readSyncCorePin } from "../lib/sync-core/release.js";
|
|
5
5
|
import { readEngineStatus } from "../lib/sync-core/engine-home.js";
|
|
6
|
-
import { readCompanyRolloutFlag } from "../lib/sync-core/flag.js";
|
|
6
|
+
import { readCompanyDownloadStreams, readCompanyRolloutFlag } from "../lib/sync-core/flag.js";
|
|
7
7
|
import { reconcileSyncCore } from "../lib/sync-core/reconcile.js";
|
|
8
8
|
import { engineOwnedManifestScopes, manifestScopeArg } from "../lib/sync-core/manifest-scopes.js";
|
|
9
9
|
import { readSyncCoreRolloutState, syncCoreRolloutStatePath } from "../lib/sync-core/rollout-state.js";
|
|
10
10
|
import { readVaultSyncSwitches } from "../lib/vault-sync-switches.js";
|
|
11
11
|
import { isSyncCoreVaultUid } from "../lib/sync-core/vault-uid.js";
|
|
12
|
-
import { readSyncCoreVaultSettings, setSyncCoreVaultSetting, SyncCoreVaultSettingError, } from "../lib/sync-core/vault-settings.js";
|
|
12
|
+
import { effectiveEngineSettings, readSyncCoreVaultSettings, setSyncCoreVaultSetting, SyncCoreVaultSettingError, } from "../lib/sync-core/vault-settings.js";
|
|
13
13
|
function defaultDeps() {
|
|
14
14
|
return {
|
|
15
15
|
home: os.homedir(),
|
|
@@ -61,6 +61,7 @@ export async function runSyncCoreReconcile(opts, d = defaultDeps()) {
|
|
|
61
61
|
getEntity: async () => null,
|
|
62
62
|
}),
|
|
63
63
|
readRolloutFlag: (companyUid) => readCompanyRolloutFlag(companyUid, token, { env: d.env }),
|
|
64
|
+
readDownloadStreams: (companyUid) => readCompanyDownloadStreams(companyUid, token, { env: d.env }),
|
|
64
65
|
ensureBinary: (release) => ensureSyncCoreBinary({ home: d.home, platform: d.platform, arch: d.arch, release, env: d.env }),
|
|
65
66
|
platform: d.platform,
|
|
66
67
|
env: d.env,
|
|
@@ -231,29 +232,47 @@ export function resolveSyncCoreVault(home, name, opts = {}) {
|
|
|
231
232
|
return match[0].uid;
|
|
232
233
|
throw new SyncCoreVaultSettingError(`No vault named ${JSON.stringify(wanted)} is on the new sync engine on this machine. Pass a company slug from hq sync-core status, personal, or a vault uid.`);
|
|
233
234
|
}
|
|
234
|
-
function describeSettings(settings) {
|
|
235
|
-
if (!settings?.parallelDownloads)
|
|
236
|
-
return "parallel-downloads off (default)";
|
|
237
|
-
|
|
235
|
+
function describeSettings(settings, source) {
|
|
236
|
+
if (!settings?.parallelDownloads) {
|
|
237
|
+
return source === "computer" ? "parallel-downloads off (this computer)" : "parallel-downloads off (default)";
|
|
238
|
+
}
|
|
239
|
+
const text = `parallel-downloads on, download-streams ${settings.downloadStreams ?? "default"}`;
|
|
240
|
+
return source === "company" ? `${text} (company setting)` : text;
|
|
238
241
|
}
|
|
239
242
|
export function runSyncCoreConfig(vault, key, value, opts, d = defaultDeps()) {
|
|
240
243
|
try {
|
|
241
244
|
const clearing = key !== undefined && (value === "off" || value === "default");
|
|
242
245
|
const uid = resolveSyncCoreVault(d.home, vault, { clearing });
|
|
243
|
-
|
|
246
|
+
const onEngine = readSyncCoreRolloutState(d.home)?.vaults.find((entry) => entry.uid === uid);
|
|
247
|
+
let local;
|
|
244
248
|
if (key === undefined) {
|
|
245
|
-
|
|
249
|
+
local = readSyncCoreVaultSettings(d.home).get(uid);
|
|
246
250
|
}
|
|
247
251
|
else {
|
|
248
252
|
if (value === undefined)
|
|
249
253
|
throw new SyncCoreVaultSettingError(`Give a value for ${key}`);
|
|
250
|
-
|
|
254
|
+
// A vault no longer on the engine here has no company value to opt out
|
|
255
|
+
// of, so turning it off just removes the stale entry.
|
|
256
|
+
const stored = !onEngine && key === "parallel-downloads" && value === "off" ? "default" : value;
|
|
257
|
+
local = setSyncCoreVaultSetting(d.home, uid, key, stored);
|
|
251
258
|
}
|
|
259
|
+
const companyStreams = onEngine?.downloadStreams;
|
|
260
|
+
const settings = effectiveEngineSettings(local, companyStreams);
|
|
261
|
+
const source = local?.parallelDownloads !== undefined ? "computer" : settings ? "company" : "default";
|
|
252
262
|
if (opts.json) {
|
|
253
|
-
d.out(JSON.stringify({
|
|
263
|
+
d.out(JSON.stringify({
|
|
264
|
+
vault: uid,
|
|
265
|
+
parallelDownloads: settings?.parallelDownloads === true,
|
|
266
|
+
downloadStreams: settings?.downloadStreams ?? null,
|
|
267
|
+
source,
|
|
268
|
+
companyDownloadStreams: companyStreams ?? null,
|
|
269
|
+
}));
|
|
254
270
|
return;
|
|
255
271
|
}
|
|
256
|
-
d.out(`${uid}: ${describeSettings(settings)}`);
|
|
272
|
+
d.out(`${uid}: ${describeSettings(settings, source)}`);
|
|
273
|
+
if (source === "computer" && companyStreams !== undefined) {
|
|
274
|
+
d.out(`The company setting (${companyStreams} download streams) applies again after: hq sync-core config ${vault} parallel-downloads default`);
|
|
275
|
+
}
|
|
257
276
|
if (key !== undefined) {
|
|
258
277
|
d.out("Only this computer is changed. hq daemon restarts this vault's sync engine within about 15 seconds. Engine releases without parallel downloads ignore the setting.");
|
|
259
278
|
}
|
|
@@ -287,7 +306,7 @@ export function registerSyncCoreCommand(program, over = {}) {
|
|
|
287
306
|
});
|
|
288
307
|
syncCore
|
|
289
308
|
.command("config <vault> [key] [value]")
|
|
290
|
-
.description("Show or change this computer's new sync engine settings for one vault: parallel-downloads on|off, download-streams 1-32|default")
|
|
309
|
+
.description("Show or change this computer's new sync engine settings for one vault: parallel-downloads on|off|default (default follows the company setting), download-streams 1-32|default")
|
|
291
310
|
.option("--json", "Print JSON")
|
|
292
311
|
.action((vault, key, value, opts) => runSyncCoreConfig(vault, key, value, opts, deps()));
|
|
293
312
|
syncCore
|
|
@@ -108,10 +108,15 @@ export interface EnsureFleetHotSignalSyncInput {
|
|
|
108
108
|
* cli.bot-signals-engine-job (default off). Every company still gets the
|
|
109
109
|
* daily 06:30 hot-signal-sync job; the flag picks what its script runs: the
|
|
110
110
|
* signals engine when true, the plain hot-channel sync when false. The script
|
|
111
|
-
* is rewritten on every call, so flipping the flag
|
|
112
|
-
* bot start without re-registering the
|
|
111
|
+
* is rewritten on every call, so flipping the flag (or turning a capture
|
|
112
|
+
* setting on) takes effect on the next bot start without re-registering the
|
|
113
|
+
* job.
|
|
114
|
+
*
|
|
115
|
+
* The flag is a company flag, so pass a function to answer per company (a
|
|
116
|
+
* personal bot has one job per company and each can differ). A boolean is
|
|
117
|
+
* the same answer for every company.
|
|
113
118
|
*/
|
|
114
|
-
signalsJobEnabled: boolean;
|
|
119
|
+
signalsJobEnabled: boolean | ((company: string) => boolean);
|
|
115
120
|
/**
|
|
116
121
|
* Whether this bot is the Executive bot (lib/bot/executive.ts). Other personal bots
|
|
117
122
|
* hand over only companies with a confirmed replacement job. Default true.
|
|
@@ -132,5 +137,23 @@ export interface EnsureFleetHotSignalSyncResult {
|
|
|
132
137
|
removed: string[];
|
|
133
138
|
}
|
|
134
139
|
export declare function fleetHotSignalSyncCompanies(config: EnsureFleetHotSignalSyncInput["config"], activeCompany: string | null, ownerCompanies?: readonly string[]): string[];
|
|
140
|
+
/**
|
|
141
|
+
* cli.bot-signals-engine-job, read for each company the bot has a
|
|
142
|
+
* hot-signal-sync job for: the answer for `signalsJobEnabled`. Only a company
|
|
143
|
+
* whose flag is on, and which the engine would not skip as prefs-off on this
|
|
144
|
+
* computer (signals_capture and ontology_capture both off), gets the engine
|
|
145
|
+
* script; the others keep the plain hot-channel sync. A company has one job
|
|
146
|
+
* and one script, so it is never run by both in a morning. Never throws: when
|
|
147
|
+
* the read itself throws, every company keeps the plain sync and `log` gets
|
|
148
|
+
* one line.
|
|
149
|
+
*
|
|
150
|
+
* The answer is taken when the script is written: each time `hq bot` syncs
|
|
151
|
+
* the bot's Fleet jobs (`hq bot start` and `restart` among them). A
|
|
152
|
+
* capture setting (or the flag) changed afterwards, in either direction,
|
|
153
|
+
* reaches the script the next time it is written. Until then a company whose
|
|
154
|
+
* capture was turned on keeps the plain sync, and a company whose capture was
|
|
155
|
+
* turned off keeps the engine script, which skips it as prefs-off.
|
|
156
|
+
*/
|
|
157
|
+
export declare function fleetHotSignalSyncEngineCompanies(input: Pick<EnsureFleetHotSignalSyncInput, "config" | "activeCompany" | "ownerCompanies" | "executive" | "executiveCompanies">, read?: (companies: readonly string[]) => Promise<ReadonlySet<string>>, log?: (message: string) => void): Promise<(company: string) => boolean>;
|
|
135
158
|
export declare function ensureFleetHotSignalSync(input: EnsureFleetHotSignalSyncInput): EnsureFleetHotSignalSyncResult;
|
|
136
159
|
//# sourceMappingURL=fleet-cron.d.ts.map
|