@indigoai-us/hq-cli 5.345.264 → 5.345.267
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 +61 -0
- package/assets/scaffold/core/scripts/hq-delegate-grant.sh +4 -48
- package/assets/scaffold/core/scripts/hq-delegate-secrets.sh +16 -10
- package/assets/scaffold/core/scripts/hq-delegate-send.sh +17 -1
- package/contracts/host-canary-release.json +7 -7
- package/dist/command-catalog.generated.d.ts +30 -1
- package/dist/command-catalog.generated.js +37 -1
- package/dist/commands/core-delegate-w1b.js +21 -40
- package/dist/commands/core-delegate.js +11 -8
- package/dist/commands/files-browse.d.ts +83 -4
- package/dist/commands/files-browse.js +404 -54
- package/dist/commands/groups.js +2 -2
- package/dist/commands/skill.js +15 -0
- package/dist/lib/agent-kit/mcp/tools.js +2 -2
- package/dist/lib/agent-kit/skills.js +12 -6
- package/dist/lib/daemon/merge-sections.d.ts +44 -9
- package/dist/lib/daemon/merge-sections.js +234 -37
- package/dist/lib/daemon/run.js +1 -0
- package/dist/lib/doctor/checks/antigravity-wiring.js +20 -4
- package/dist/lib/doctor/checks/host-core.js +9 -4
- package/dist/lib/doctor/fix/process-identity.d.ts +2 -0
- package/dist/lib/doctor/fix/process-identity.js +5 -2
- package/dist/lib/hook-engine/coverage.js +13 -1
- package/dist/lib/hook-engine/native-precompact-compatibility.json +1 -0
- package/dist/lib/hook-engine/reconcile.js +13 -3
- package/dist/lib/signals/reply.js +25 -5
- package/dist/lib/signals/steps/extract.d.ts +28 -4
- package/dist/lib/signals/steps/extract.js +124 -10
- package/dist/lib/sync-core/release.d.ts +1 -1
- package/dist/lib/sync-core/release.js +2 -2
- package/package.json +7 -7
|
@@ -41,11 +41,11 @@ import { Readable } from "node:stream";
|
|
|
41
41
|
import { pipeline } from "node:stream/promises";
|
|
42
42
|
import { raiseAccessRefresh } from "../lib/sync-core/access-refresh.js";
|
|
43
43
|
import { S3Client, ListObjectsV2Command, GetObjectCommand, } from "@aws-sdk/client-s3";
|
|
44
|
-
import { VaultClient, } from "@indigoai-us/hq-cloud";
|
|
44
|
+
import { VaultClient, createIgnoreFilter, SYNC_MAX_FILE_BYTES, } from "@indigoai-us/hq-cloud";
|
|
45
45
|
import { isPrivateFolderPattern } from "./_patterns.js";
|
|
46
46
|
import { displayAclSource, } from "../utils/files-browse-acl.js";
|
|
47
47
|
export { ACL_SOURCE_DISPLAY_LABELS, displayAclSource } from "../utils/files-browse-acl.js";
|
|
48
|
-
import { DEFAULT_HQ_ROOT, DEFAULT_COGNITO, buildVaultConfig, } from "../utils/cognito-session.js";
|
|
48
|
+
import { DEFAULT_HQ_ROOT, DEFAULT_COGNITO, buildVaultConfig, describeCognitoTokenSource, } from "../utils/cognito-session.js";
|
|
49
49
|
import { resolveVaultCredential } from "../utils/resolve-vault-credential.js";
|
|
50
50
|
import { maxLength } from "../utils/table-width.js";
|
|
51
51
|
import { getCompanyUid, looksLikeCompanyUid, looksLikePersonVaultUid, vaultApiFetch, } from "../utils/vault-api.js";
|
|
@@ -193,13 +193,14 @@ export function formatBrowseTable(rows) {
|
|
|
193
193
|
if (rows.length === 0) {
|
|
194
194
|
return "No objects under that prefix.";
|
|
195
195
|
}
|
|
196
|
-
|
|
197
|
-
const data = rows.map((r) => [
|
|
196
|
+
return renderTable(["KEY", "SIZE", "MODIFIED", "ACL"], rows.map((r) => [
|
|
198
197
|
r.key,
|
|
199
198
|
String(r.size),
|
|
200
199
|
r.lastModified ? r.lastModified.toISOString() : "—",
|
|
201
200
|
displayAclSource(r.aclSource),
|
|
202
|
-
]);
|
|
201
|
+
]));
|
|
202
|
+
}
|
|
203
|
+
function renderTable(cols, data) {
|
|
203
204
|
const widths = cols.map((c, i) => maxLength(data, (row) => row[i].length, c.length));
|
|
204
205
|
const renderRow = (row) => row.map((cell, i) => cell.padEnd(widths[i])).join(" ");
|
|
205
206
|
const lines = [
|
|
@@ -210,11 +211,28 @@ export function formatBrowseTable(rows) {
|
|
|
210
211
|
lines.push(renderRow(row));
|
|
211
212
|
return lines.join("\n");
|
|
212
213
|
}
|
|
213
|
-
function
|
|
214
|
+
export function formatSearchTable(rows, acl) {
|
|
215
|
+
if (acl) {
|
|
216
|
+
return formatBrowseTable(rows.map((r) => ({ ...r, aclSource: r.aclSource ?? "role-bypass" })));
|
|
217
|
+
}
|
|
218
|
+
return renderTable(["KEY", "SIZE", "MODIFIED"], rows.map((r) => [
|
|
219
|
+
r.key,
|
|
220
|
+
String(r.size),
|
|
221
|
+
r.lastModified ? r.lastModified.toISOString() : "—",
|
|
222
|
+
]));
|
|
223
|
+
}
|
|
224
|
+
export function formatSearchResults(rows, query, acl = false) {
|
|
214
225
|
if (rows.length === 0) {
|
|
215
226
|
return `No files found for search ${JSON.stringify(query)}.`;
|
|
216
227
|
}
|
|
217
|
-
return
|
|
228
|
+
return formatSearchTable(rows, acl);
|
|
229
|
+
}
|
|
230
|
+
export function formatLocalSearchResults(found, query) {
|
|
231
|
+
const title = chalk.bold(`Local matches (synced copy under ${found.root}):`);
|
|
232
|
+
const body = found.rows.length === 0
|
|
233
|
+
? `Nothing in the synced copy matches ${JSON.stringify(query)}.`
|
|
234
|
+
: formatSearchTable(found.rows, false);
|
|
235
|
+
return [title, body].join("\n");
|
|
218
236
|
}
|
|
219
237
|
function normalizeCompanySearchPath(value) {
|
|
220
238
|
return value
|
|
@@ -236,20 +254,7 @@ function requireCompanyClient(f) {
|
|
|
236
254
|
}
|
|
237
255
|
return f;
|
|
238
256
|
}
|
|
239
|
-
|
|
240
|
-
* `hq files browse <path>` orchestrator.
|
|
241
|
-
*
|
|
242
|
-
* 1. Parse slug from prefix (or use override).
|
|
243
|
-
* 2. Resolve companyUid + bucketName via VaultClient.entity.
|
|
244
|
-
* 3. Vend read creds via the multi-tenant STS route (`/sts/vend` company,
|
|
245
|
-
* `/sts/vend-self` personal) — resolves the per-entity bucket + role/ACL.
|
|
246
|
-
* 4. Construct S3Client from vended creds, paginate ListObjectsV2 over the
|
|
247
|
-
* company-relative key space.
|
|
248
|
-
* 5. Fetch explicit grants once, classify each key.
|
|
249
|
-
*
|
|
250
|
-
* Pure-ish: no console output, no process.exit — caller renders + exits.
|
|
251
|
-
*/
|
|
252
|
-
export async function runBrowse(input) {
|
|
257
|
+
async function resolveListTarget(input) {
|
|
253
258
|
const { pathPrefix, vaultClient, region, personalMode } = input;
|
|
254
259
|
// Branch by mode. Company mode parses slug from path and looks up by
|
|
255
260
|
// namespace; personal mode resolves the entity directly by the supplied
|
|
@@ -311,6 +316,24 @@ export async function runBrowse(input) {
|
|
|
311
316
|
const listPrefix = !personalMode && (bucketPrefix === "/" || bucketPrefix === ".")
|
|
312
317
|
? ""
|
|
313
318
|
: bucketPrefix;
|
|
319
|
+
return { bucket, entityUid, slug, vend, s3, listPrefix };
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* `hq files browse <path>` orchestrator.
|
|
323
|
+
*
|
|
324
|
+
* 1. Parse slug from prefix (or use override).
|
|
325
|
+
* 2. Resolve companyUid + bucketName via VaultClient.entity.
|
|
326
|
+
* 3. Vend read creds via the multi-tenant STS route (`/sts/vend` company,
|
|
327
|
+
* `/sts/vend-self` personal) — resolves the per-entity bucket + role/ACL.
|
|
328
|
+
* 4. Construct S3Client from vended creds, paginate ListObjectsV2 over the
|
|
329
|
+
* company-relative key space.
|
|
330
|
+
* 5. Fetch explicit grants once, classify each key.
|
|
331
|
+
*
|
|
332
|
+
* Pure-ish: no console output, no process.exit — caller renders + exits.
|
|
333
|
+
*/
|
|
334
|
+
export async function runBrowse(input) {
|
|
335
|
+
const { vaultClient, personalMode } = input;
|
|
336
|
+
const { bucket, entityUid, slug, vend, s3, listPrefix } = await resolveListTarget(input);
|
|
314
337
|
// Pull the caller's explicit-grant graph once so per-key classification is
|
|
315
338
|
// O(grants) without N round-trips. Retain the raw pattern after stripping
|
|
316
339
|
// only the redundant company anchor: `foo/` and `foo/*` have different
|
|
@@ -546,18 +569,27 @@ export function formatSharedWithMeTable(rows) {
|
|
|
546
569
|
}
|
|
547
570
|
return lines.join("\n");
|
|
548
571
|
}
|
|
572
|
+
export function createSearchMatcher(query) {
|
|
573
|
+
const q = query.toLowerCase();
|
|
574
|
+
const normalizedQuery = /^company\/[^/]+/.test(q)
|
|
575
|
+
? normalizeCompanySearchPath(q)
|
|
576
|
+
: q;
|
|
577
|
+
return (key) => key.includes(q) ||
|
|
578
|
+
(key.includes("company") ? normalizeCompanySearchPath(key) : key).includes(normalizedQuery);
|
|
579
|
+
}
|
|
549
580
|
/**
|
|
550
581
|
* `hq files search <query>` orchestrator. Lists the company (or personal)
|
|
551
|
-
* vault under its root
|
|
582
|
+
* vault under its root, then filters to keys containing the
|
|
552
583
|
* query (case-insensitive). v1 is a name/path search over the listing — no
|
|
553
|
-
* content search.
|
|
584
|
+
* content search.
|
|
554
585
|
*
|
|
555
|
-
* Pure-ish: no console output. The caller renders with `
|
|
586
|
+
* Pure-ish: no console output. The caller renders with `formatSearchResults`.
|
|
556
587
|
*/
|
|
557
588
|
export async function runSearch(input) {
|
|
558
|
-
const
|
|
559
|
-
|
|
560
|
-
|
|
589
|
+
const target = await resolveListTarget({
|
|
590
|
+
pathPrefix: input.personalMode
|
|
591
|
+
? ""
|
|
592
|
+
: toCompanyAnchored(input.prefix ?? "", input.companySlug),
|
|
561
593
|
companySlug: input.companySlug,
|
|
562
594
|
personalMode: input.personalMode,
|
|
563
595
|
personalUid: input.personalUid,
|
|
@@ -566,18 +598,296 @@ export async function runSearch(input) {
|
|
|
566
598
|
companyClient: input.companyClient,
|
|
567
599
|
region: input.region,
|
|
568
600
|
});
|
|
569
|
-
const
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
const
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
601
|
+
const { slug } = target;
|
|
602
|
+
const anchor = input.personalMode || slug === undefined ? "" : toCompanyAnchored("", slug);
|
|
603
|
+
const matches = createSearchMatcher(input.query);
|
|
604
|
+
const now = input.now ?? Date.now;
|
|
605
|
+
const startedAt = now();
|
|
606
|
+
let grantPatterns;
|
|
607
|
+
const loadGrantPatterns = async () => {
|
|
608
|
+
if (slug === undefined)
|
|
609
|
+
return [];
|
|
610
|
+
grantPatterns ??= (await input.vaultClient.listMyExplicitGrants(target.entityUid)).map((g) => ({
|
|
611
|
+
pattern: toBrowseGrantPattern(g.path, slug),
|
|
612
|
+
source: g.source,
|
|
613
|
+
}));
|
|
614
|
+
return grantPatterns;
|
|
615
|
+
};
|
|
616
|
+
const rows = [];
|
|
617
|
+
let pages = 0;
|
|
618
|
+
let objects = 0;
|
|
619
|
+
let continuationToken;
|
|
620
|
+
do {
|
|
621
|
+
const resp = (await target.s3.send(new ListObjectsV2Command({
|
|
622
|
+
Bucket: target.bucket,
|
|
623
|
+
Prefix: target.listPrefix,
|
|
624
|
+
ContinuationToken: continuationToken,
|
|
625
|
+
})));
|
|
626
|
+
pages += 1;
|
|
627
|
+
for (const obj of resp.Contents ?? []) {
|
|
628
|
+
if (!obj.Key)
|
|
629
|
+
continue;
|
|
630
|
+
objects += 1;
|
|
631
|
+
const key = anchor + obj.Key;
|
|
632
|
+
if (!matches(key.toLowerCase()))
|
|
633
|
+
continue;
|
|
634
|
+
const marker = obj.Key.endsWith("/") && (obj.Size ?? 0) === 0;
|
|
635
|
+
let aclSource;
|
|
636
|
+
if (input.personalMode) {
|
|
637
|
+
aclSource = "personal-vault";
|
|
638
|
+
}
|
|
639
|
+
else if (marker || input.includeAcl) {
|
|
640
|
+
aclSource = classifyAclSource(obj.Key, await loadGrantPatterns());
|
|
641
|
+
}
|
|
642
|
+
if (marker && aclSource !== "private-folder")
|
|
643
|
+
continue;
|
|
644
|
+
rows.push({
|
|
645
|
+
key,
|
|
646
|
+
size: obj.Size ?? 0,
|
|
647
|
+
lastModified: obj.LastModified,
|
|
648
|
+
...(input.includeAcl ? { aclSource } : {}),
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
input.onPage?.({
|
|
652
|
+
pages,
|
|
653
|
+
objects,
|
|
654
|
+
matches: rows.length,
|
|
655
|
+
elapsedMs: now() - startedAt,
|
|
656
|
+
});
|
|
657
|
+
continuationToken = resp.NextContinuationToken ?? undefined;
|
|
658
|
+
} while (continuationToken);
|
|
659
|
+
return rows;
|
|
660
|
+
}
|
|
661
|
+
const SAFE_COMPANY_SLUG = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
662
|
+
export function assertSafeCompanySlug(slug) {
|
|
663
|
+
if (!SAFE_COMPANY_SLUG.test(slug) || slug.includes("..")) {
|
|
664
|
+
throw new Error(`Invalid company slug '${slug}'.`);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
export function resolveSearchPrefix(raw, companySlug) {
|
|
668
|
+
if (raw === undefined)
|
|
669
|
+
return "";
|
|
670
|
+
const scope = toCompanyAnchored("", companySlug);
|
|
671
|
+
const unsafe = Array.from(raw).some((c) => {
|
|
672
|
+
const code = c.charCodeAt(0);
|
|
673
|
+
return code < 0x20 || code === 0x7f || c === "\\";
|
|
580
674
|
});
|
|
675
|
+
if (unsafe) {
|
|
676
|
+
throw new Error(`--prefix '${raw}' contains a backslash or control character; use a forward-slash path inside ${scope}.`);
|
|
677
|
+
}
|
|
678
|
+
const segments = raw.split("/").filter((s) => s !== "" && s !== ".");
|
|
679
|
+
if (segments.includes("..")) {
|
|
680
|
+
throw new Error(`--prefix '${raw}' must not contain '..'; it must stay inside ${scope}.`);
|
|
681
|
+
}
|
|
682
|
+
if (segments[0] === "companies") {
|
|
683
|
+
if (segments[1] !== companySlug) {
|
|
684
|
+
throw new Error(`--prefix '${raw}' is outside ${scope}.`);
|
|
685
|
+
}
|
|
686
|
+
segments.splice(0, 2);
|
|
687
|
+
}
|
|
688
|
+
return segments.length === 0 ? "" : `${segments.join("/")}/`;
|
|
689
|
+
}
|
|
690
|
+
export function searchLocalCompanyFiles(input) {
|
|
691
|
+
assertSafeCompanySlug(input.companySlug);
|
|
692
|
+
const companyRoot = path.join(input.hqRoot, "companies", input.companySlug);
|
|
693
|
+
const segments = input.prefix.split("/").filter((s) => s.length > 0);
|
|
694
|
+
const root = path.join(companyRoot, ...segments);
|
|
695
|
+
const unavailable = { root, available: false, rows: [] };
|
|
696
|
+
const empty = { root, available: true, rows: [] };
|
|
697
|
+
let companyStat;
|
|
698
|
+
try {
|
|
699
|
+
companyStat = fs.lstatSync(companyRoot);
|
|
700
|
+
}
|
|
701
|
+
catch {
|
|
702
|
+
return unavailable;
|
|
703
|
+
}
|
|
704
|
+
if (!companyStat.isDirectory())
|
|
705
|
+
return unavailable;
|
|
706
|
+
let walkRoot;
|
|
707
|
+
try {
|
|
708
|
+
const realCompany = fs.realpathSync(companyRoot);
|
|
709
|
+
walkRoot = fs.realpathSync(root);
|
|
710
|
+
if (walkRoot !== realCompany && !walkRoot.startsWith(realCompany + path.sep)) {
|
|
711
|
+
return empty;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
catch {
|
|
715
|
+
return empty;
|
|
716
|
+
}
|
|
717
|
+
let shouldSync = input.shouldSync;
|
|
718
|
+
if (!shouldSync) {
|
|
719
|
+
try {
|
|
720
|
+
shouldSync = createIgnoreFilter(input.hqRoot);
|
|
721
|
+
}
|
|
722
|
+
catch (err) {
|
|
723
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
724
|
+
return {
|
|
725
|
+
...unavailable,
|
|
726
|
+
warning: `Skipped the local search: could not read the sync ignore rules under ${input.hqRoot} (${reason}).`,
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
const matches = createSearchMatcher(input.query);
|
|
731
|
+
const keyPrefix = segments.length > 0 ? `${segments.join("/")}/` : "";
|
|
732
|
+
const rows = [];
|
|
733
|
+
const stack = [root];
|
|
734
|
+
while (stack.length > 0) {
|
|
735
|
+
const dir = stack.pop();
|
|
736
|
+
let entries;
|
|
737
|
+
try {
|
|
738
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
739
|
+
}
|
|
740
|
+
catch {
|
|
741
|
+
continue;
|
|
742
|
+
}
|
|
743
|
+
for (const entry of entries) {
|
|
744
|
+
const abs = path.join(dir, entry.name);
|
|
745
|
+
if (entry.isDirectory()) {
|
|
746
|
+
if (entry.name === ".git" || entry.name === "node_modules")
|
|
747
|
+
continue;
|
|
748
|
+
if (!shouldSync(abs, true))
|
|
749
|
+
continue;
|
|
750
|
+
stack.push(abs);
|
|
751
|
+
continue;
|
|
752
|
+
}
|
|
753
|
+
if (!entry.isFile())
|
|
754
|
+
continue;
|
|
755
|
+
const rel = path.relative(root, abs).split(path.sep).join("/");
|
|
756
|
+
const key = toCompanyAnchored(keyPrefix + rel, input.companySlug);
|
|
757
|
+
if (!matches(key.toLowerCase()))
|
|
758
|
+
continue;
|
|
759
|
+
if (!shouldSync(abs, false))
|
|
760
|
+
continue;
|
|
761
|
+
let st;
|
|
762
|
+
try {
|
|
763
|
+
st = fs.statSync(abs);
|
|
764
|
+
}
|
|
765
|
+
catch {
|
|
766
|
+
continue;
|
|
767
|
+
}
|
|
768
|
+
if (st.size > SYNC_MAX_FILE_BYTES)
|
|
769
|
+
continue;
|
|
770
|
+
rows.push({ key, size: st.size, lastModified: st.mtime });
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
rows.sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
|
|
774
|
+
return { root, available: true, rows };
|
|
775
|
+
}
|
|
776
|
+
export function createSearchProgressReporter(input) {
|
|
777
|
+
const { stream } = input;
|
|
778
|
+
const tty = stream.isTTY === true;
|
|
779
|
+
const show = tty || input.force === true;
|
|
780
|
+
let drawn = false;
|
|
781
|
+
return {
|
|
782
|
+
start(scope) {
|
|
783
|
+
if (tty || input.quiet === true)
|
|
784
|
+
return;
|
|
785
|
+
stream.write(`hq files search: listing every vault object under ${scope}; large vaults can take minutes. Narrow with --prefix <path>, or use --local-only for synced files.\n`);
|
|
786
|
+
},
|
|
787
|
+
page(p) {
|
|
788
|
+
if (!show)
|
|
789
|
+
return;
|
|
790
|
+
const line = `Scanned ${p.pages} page(s), ${p.objects} object(s), ${p.matches} match(es), ${(p.elapsedMs / 1000).toFixed(1)}s`;
|
|
791
|
+
if (tty) {
|
|
792
|
+
stream.write(`\r\x1b[2K${line}`);
|
|
793
|
+
drawn = true;
|
|
794
|
+
}
|
|
795
|
+
else {
|
|
796
|
+
stream.write(`${line}\n`);
|
|
797
|
+
}
|
|
798
|
+
},
|
|
799
|
+
done() {
|
|
800
|
+
if (!drawn)
|
|
801
|
+
return;
|
|
802
|
+
stream.write("\r\x1b[2K");
|
|
803
|
+
drawn = false;
|
|
804
|
+
},
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
const TRUTHY_ENV = new Set(["1", "true", "yes"]);
|
|
808
|
+
function envFlagSet(value) {
|
|
809
|
+
return TRUTHY_ENV.has(value?.trim().toLowerCase() ?? "");
|
|
810
|
+
}
|
|
811
|
+
export function personLocalSearchAllowed(input) {
|
|
812
|
+
const vars = input.vars ?? process.env;
|
|
813
|
+
if (input.credentialKind !== "cognito")
|
|
814
|
+
return false;
|
|
815
|
+
if ((vars.HQ_API_KEY ?? "").trim().length > 0)
|
|
816
|
+
return false;
|
|
817
|
+
if (envFlagSet(vars.HQ_REQUIRE_MACHINE_IDENTITY))
|
|
818
|
+
return false;
|
|
819
|
+
if (envFlagSet(vars.HQ_MACHINE_AUTH_REQUIRED))
|
|
820
|
+
return false;
|
|
821
|
+
const describe = input.describeIdentity ?? ((e) => describeCognitoTokenSource({ env: e }));
|
|
822
|
+
const who = describe(vars);
|
|
823
|
+
return who.tokenSource === "person" && who.actorKind === "human";
|
|
824
|
+
}
|
|
825
|
+
export async function runCompanySearchCommand(input) {
|
|
826
|
+
const slug = input.companySlug;
|
|
827
|
+
assertSafeCompanySlug(slug);
|
|
828
|
+
const prefix = resolveSearchPrefix(input.prefix, slug);
|
|
829
|
+
const scope = toCompanyAnchored(prefix, slug);
|
|
830
|
+
if (input.localOnly && input.local === false) {
|
|
831
|
+
throw new Error("--local-only and --no-local cannot be combined.");
|
|
832
|
+
}
|
|
833
|
+
const { vaultClient, companyClient, localAllowed } = await input.connect();
|
|
834
|
+
const wantLocal = input.local !== false;
|
|
835
|
+
if (input.localOnly && !localAllowed) {
|
|
836
|
+
throw new Error("--local-only searches your own synced files, so it needs your own signed-in HQ session (not an API key, machine or agent identity).");
|
|
837
|
+
}
|
|
838
|
+
let local;
|
|
839
|
+
if (wantLocal && localAllowed) {
|
|
840
|
+
const membership = await vaultClient.entity.findInMyNamespace("company", slug);
|
|
841
|
+
if (!membership) {
|
|
842
|
+
throw new Error(`No company found for slug '${slug}' in your namespace. Confirm you have an active membership.`);
|
|
843
|
+
}
|
|
844
|
+
local = searchLocalCompanyFiles({
|
|
845
|
+
hqRoot: input.hqRoot,
|
|
846
|
+
companySlug: slug,
|
|
847
|
+
prefix,
|
|
848
|
+
query: input.query,
|
|
849
|
+
shouldSync: input.shouldSync,
|
|
850
|
+
});
|
|
851
|
+
if (local.warning)
|
|
852
|
+
input.stderr.write(`${local.warning}\n`);
|
|
853
|
+
if (local.available) {
|
|
854
|
+
input.stdout(formatLocalSearchResults(local, input.query));
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
if (input.localOnly) {
|
|
858
|
+
if (!local?.available && !local?.warning) {
|
|
859
|
+
input.stdout(`No synced copy of ${scope} under ${input.hqRoot}.`);
|
|
860
|
+
}
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
const reporter = createSearchProgressReporter({
|
|
864
|
+
stream: input.stderr,
|
|
865
|
+
force: input.progress,
|
|
866
|
+
quiet: input.quiet,
|
|
867
|
+
});
|
|
868
|
+
reporter.start(prefix ? scope : `${scope} (the whole company vault)`);
|
|
869
|
+
let rows;
|
|
870
|
+
try {
|
|
871
|
+
rows = await runSearch({
|
|
872
|
+
query: input.query,
|
|
873
|
+
companySlug: slug,
|
|
874
|
+
prefix,
|
|
875
|
+
includeAcl: input.acl === true,
|
|
876
|
+
vaultClient,
|
|
877
|
+
companyClient,
|
|
878
|
+
region: input.region,
|
|
879
|
+
onPage: (p) => reporter.page(p),
|
|
880
|
+
now: input.now,
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
finally {
|
|
884
|
+
reporter.done();
|
|
885
|
+
}
|
|
886
|
+
if (local?.available) {
|
|
887
|
+
input.stdout("");
|
|
888
|
+
input.stdout(chalk.bold("Vault matches:"));
|
|
889
|
+
}
|
|
890
|
+
input.stdout(formatSearchResults(rows, input.query, input.acl === true));
|
|
581
891
|
}
|
|
582
892
|
/** Per-machine pin set path: `<hqRoot>/.hq/pins.json`. */
|
|
583
893
|
export function pinFilePath(hqRoot) {
|
|
@@ -1326,9 +1636,16 @@ export function registerFilesBrowseCommands(filesCmd, deps = {}) {
|
|
|
1326
1636
|
});
|
|
1327
1637
|
filesCmd
|
|
1328
1638
|
.command("search <query>")
|
|
1329
|
-
.description("Search vault object keys (case-insensitive path/name match) under a company without downloading. Requires --company (or --personal). Content search is not supported in v1.")
|
|
1639
|
+
.description("Search vault object keys (case-insensitive path/name match) under a company without downloading. Requires --company (or --personal). When you run it with your own HQ login, prints matches from your synced local copy first (labelled), then lists the vault, which pages through every object under the company (or --prefix) and can take minutes on large vaults. Content search is not supported in v1.")
|
|
1330
1640
|
.option("--company <slug>", "Company slug to search.")
|
|
1331
1641
|
.option("--personal", "Search the caller's canonical personal vault. Mutually exclusive with --company.")
|
|
1642
|
+
.option("--prefix <path>", "Only list the vault under this folder inside companies/<slug>/ (e.g. knowledge/ or companies/<slug>/knowledge/).")
|
|
1643
|
+
.option("--local-only", "Search only your synced local copy under <hq-root>/companies/<slug>/; skip the vault listing. Needs your own HQ login.")
|
|
1644
|
+
.option("--no-local", "Skip the synced local copy; list the vault only.")
|
|
1645
|
+
.option("--quiet", "Do not print the slow-listing note to stderr when stderr is not a terminal.")
|
|
1646
|
+
.option("--acl", "Add the ACL column (fetches your explicit grants, like hq files browse).")
|
|
1647
|
+
.option("--progress", "Print paging progress to stderr even when stderr is not a terminal.")
|
|
1648
|
+
.option("--hq-root <path>", `Local HQ tree root (default: ${DEFAULT_HQ_ROOT})`, DEFAULT_HQ_ROOT)
|
|
1332
1649
|
.action(async (query, options, command) => {
|
|
1333
1650
|
try {
|
|
1334
1651
|
// `--company` is declared on the parent `files` group too, so commander
|
|
@@ -1337,8 +1654,11 @@ export function registerFilesBrowseCommands(filesCmd, deps = {}) {
|
|
|
1337
1654
|
if (options.personal && company) {
|
|
1338
1655
|
throw new Error("--personal and --company are mutually exclusive. Pick one.");
|
|
1339
1656
|
}
|
|
1340
|
-
const { token: accessToken, client, cognito } = await resolveBrowseSession();
|
|
1341
1657
|
if (options.personal) {
|
|
1658
|
+
if (options.prefix !== undefined || options.localOnly || options.local === false) {
|
|
1659
|
+
throw new Error("--prefix, --local-only and --no-local apply to company search only; remove them or pass --company <slug>.");
|
|
1660
|
+
}
|
|
1661
|
+
const { cognito } = await resolveBrowseSession();
|
|
1342
1662
|
if (!cognito)
|
|
1343
1663
|
throw personalVaultNeedsCognito();
|
|
1344
1664
|
const personalUid = await resolveCanonicalPersonUid({
|
|
@@ -1346,30 +1666,60 @@ export function registerFilesBrowseCommands(filesCmd, deps = {}) {
|
|
|
1346
1666
|
listPersonEntities: () => cognito.entity.listByType("person"),
|
|
1347
1667
|
getEntity: async () => null,
|
|
1348
1668
|
});
|
|
1349
|
-
const
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
personalUid,
|
|
1354
|
-
vaultClient: cognito,
|
|
1355
|
-
s3Factory: personalS3Factory,
|
|
1356
|
-
region: DEFAULT_COGNITO.region,
|
|
1669
|
+
const reporter = createSearchProgressReporter({
|
|
1670
|
+
stream: process.stderr,
|
|
1671
|
+
force: options.progress,
|
|
1672
|
+
quiet: options.quiet,
|
|
1357
1673
|
});
|
|
1358
|
-
|
|
1674
|
+
reporter.start("your personal vault");
|
|
1675
|
+
let rows;
|
|
1676
|
+
try {
|
|
1677
|
+
rows = await runSearch({
|
|
1678
|
+
query,
|
|
1679
|
+
companySlug: "personal",
|
|
1680
|
+
personalMode: true,
|
|
1681
|
+
personalUid,
|
|
1682
|
+
vaultClient: cognito,
|
|
1683
|
+
s3Factory: personalS3Factory,
|
|
1684
|
+
region: DEFAULT_COGNITO.region,
|
|
1685
|
+
includeAcl: options.acl === true,
|
|
1686
|
+
onPage: (p) => reporter.page(p),
|
|
1687
|
+
});
|
|
1688
|
+
}
|
|
1689
|
+
finally {
|
|
1690
|
+
reporter.done();
|
|
1691
|
+
}
|
|
1692
|
+
console.log(formatSearchResults(rows, query, options.acl === true));
|
|
1359
1693
|
return;
|
|
1360
1694
|
}
|
|
1361
1695
|
if (!company) {
|
|
1362
1696
|
throw new Error("search: --company <slug> is required (or --personal to search your personal vault).");
|
|
1363
1697
|
}
|
|
1364
|
-
await
|
|
1365
|
-
const rows = await runSearch({
|
|
1698
|
+
await runCompanySearchCommand({
|
|
1366
1699
|
query,
|
|
1367
1700
|
companySlug: company,
|
|
1368
|
-
|
|
1369
|
-
|
|
1701
|
+
hqRoot: options.hqRoot,
|
|
1702
|
+
prefix: options.prefix,
|
|
1703
|
+
localOnly: options.localOnly,
|
|
1704
|
+
local: options.local,
|
|
1705
|
+
quiet: options.quiet,
|
|
1706
|
+
acl: options.acl,
|
|
1707
|
+
progress: options.progress,
|
|
1370
1708
|
region: DEFAULT_COGNITO.region,
|
|
1709
|
+
connect: async () => {
|
|
1710
|
+
const { token: accessToken, client, cognito } = await resolveBrowseSession();
|
|
1711
|
+
await getCompanyUid(accessToken, company);
|
|
1712
|
+
return {
|
|
1713
|
+
vaultClient: client,
|
|
1714
|
+
companyClient: makeCompanyPresignFactory(accessToken, company),
|
|
1715
|
+
localAllowed: personLocalSearchAllowed({
|
|
1716
|
+
credentialKind: cognito ? "cognito" : "api-key",
|
|
1717
|
+
}),
|
|
1718
|
+
};
|
|
1719
|
+
},
|
|
1720
|
+
stdout: (text) => console.log(text),
|
|
1721
|
+
stderr: process.stderr,
|
|
1371
1722
|
});
|
|
1372
|
-
console.log(formatSearchResults(rows, query));
|
|
1373
1723
|
}
|
|
1374
1724
|
catch (err) {
|
|
1375
1725
|
const message = err instanceof Error ? err.message : String(err);
|
package/dist/commands/groups.js
CHANGED
|
@@ -65,7 +65,7 @@ export function registerGroupsCommand(program) {
|
|
|
65
65
|
console.error(chalk.red("Not authenticated — please run `hq login`"));
|
|
66
66
|
}
|
|
67
67
|
else if (res.status === 403) {
|
|
68
|
-
console.error(chalk.red("Not authorized —
|
|
68
|
+
console.error(chalk.red(err.error ?? "Not authorized — manage-groups permission required"));
|
|
69
69
|
}
|
|
70
70
|
else if (res.status === 409) {
|
|
71
71
|
console.error(chalk.red(`Group already exists: ${groupId}`));
|
|
@@ -109,7 +109,7 @@ export function registerGroupsCommand(program) {
|
|
|
109
109
|
console.error(chalk.red("Not authenticated — please run `hq login`"));
|
|
110
110
|
}
|
|
111
111
|
else if (res.status === 403) {
|
|
112
|
-
console.error(chalk.red("Not authorized —
|
|
112
|
+
console.error(chalk.red(err.error ?? "Not authorized — manage-groups permission required"));
|
|
113
113
|
}
|
|
114
114
|
else if (res.status === 404) {
|
|
115
115
|
console.error(chalk.red(`Group not found: ${groupId}`));
|
package/dist/commands/skill.js
CHANGED
|
@@ -68,6 +68,15 @@ function skillUploadRefused(skillUid, filePath, companySlug, refused) {
|
|
|
68
68
|
...(refused.upgradeUrl ? { upgradeUrl: refused.upgradeUrl } : {}),
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* share() returned without aborting or a plan-limit, but uploaded nothing.
|
|
73
|
+
* Printing "Sync: complete" here is how a registered skill showed up in the
|
|
74
|
+
* company list with no vault SKILL.md (feedback_9ad15468).
|
|
75
|
+
*/
|
|
76
|
+
function skillUploadDidNotReachVault(skillUid, filePath, companySlug) {
|
|
77
|
+
console.warn(chalk.yellow(`⚠ Skill ${skillUid} is stamped locally at '${filePath}', but the file was not uploaded.`));
|
|
78
|
+
return localSkillError(`The skill file was not uploaded. Upload it with: hq sync push --company ${companySlug} '${filePath}'`);
|
|
79
|
+
}
|
|
71
80
|
export function parseSkillUid(markdown) {
|
|
72
81
|
const match = markdown.match(FRONTMATTER_RE);
|
|
73
82
|
if (!match)
|
|
@@ -605,6 +614,9 @@ export function registerSkillCommand(program, deps = {}) {
|
|
|
605
614
|
if (syncResult.planLimit) {
|
|
606
615
|
throw skillUploadRefused(registered.skillUid, filePath, companySlug, syncResult.planLimit);
|
|
607
616
|
}
|
|
617
|
+
if (syncResult.filesUploaded === 0) {
|
|
618
|
+
throw skillUploadDidNotReachVault(registered.skillUid, filePath, companySlug);
|
|
619
|
+
}
|
|
608
620
|
}
|
|
609
621
|
console.log(chalk.green(`Skill ready: ${registered.skillUid}`));
|
|
610
622
|
console.log(` File: ${filePath}`);
|
|
@@ -772,6 +784,9 @@ export function registerSkillCommand(program, deps = {}) {
|
|
|
772
784
|
if (syncResult.planLimit) {
|
|
773
785
|
throw skillUploadRefused(skillUid, canonicalPath, companySlug, syncResult.planLimit);
|
|
774
786
|
}
|
|
787
|
+
if (syncResult.filesUploaded === 0) {
|
|
788
|
+
throw skillUploadDidNotReachVault(skillUid, canonicalPath, companySlug);
|
|
789
|
+
}
|
|
775
790
|
}
|
|
776
791
|
console.log(chalk.green(`Skill promoted: ${skillUid}`));
|
|
777
792
|
console.log(` File: ${canonicalPath}`);
|
|
@@ -131,7 +131,7 @@ export function buildAgentMcpTools(clients) {
|
|
|
131
131
|
name: "hq_search",
|
|
132
132
|
description: clients.syncFiles
|
|
133
133
|
? "Search the synced company vault (local qmd index). Modes: keyword (default), semantic, hybrid."
|
|
134
|
-
: "Search the company vault by file name and path
|
|
134
|
+
: "Search the company vault by file name and path (no local copy is kept). Slow on large companies: it lists the entire company vault, which can take minutes. If you know the path, use hq_files_read; to look inside a folder, use hq_files_list with a narrow path. Content and semantic search need a kit installed with --sync-files.",
|
|
135
135
|
inputSchema: {
|
|
136
136
|
type: "object",
|
|
137
137
|
properties: {
|
|
@@ -155,7 +155,7 @@ export function buildAgentMcpTools(clients) {
|
|
|
155
155
|
if (mode && mode !== "keyword") {
|
|
156
156
|
throw new McpToolInputError(`"${mode}" search needs a local copy of the vault; this agent reads files on demand. Use keyword, or reinstall the kit with \`hq agent kit install --sync-files\`.`);
|
|
157
157
|
}
|
|
158
|
-
return fromRun(await clients.runHq(["files", "search", query, "--company", company]), "hq files search");
|
|
158
|
+
return fromRun(await clients.runHq(["files", "search", query, "--company", company, "--no-local", "--quiet"]), "hq files search");
|
|
159
159
|
}
|
|
160
160
|
const hqArgs = ["search", query, "--mode", mode ?? "keyword", "-n", String(count), "--json"];
|
|
161
161
|
return fromRun(await clients.runHq(hqArgs), "hq search");
|
|
@@ -62,17 +62,23 @@ mark each item done.
|
|
|
62
62
|
description: "Find things in the company vault (documents, knowledge, meeting notes) with the hq CLI.",
|
|
63
63
|
body: `# HQ search
|
|
64
64
|
|
|
65
|
-
By default this agent keeps no local copy of the vault,
|
|
66
|
-
|
|
65
|
+
By default this agent keeps no local copy of the vault. Without it, search
|
|
66
|
+
matches file NAMES and paths, not file contents:
|
|
67
67
|
|
|
68
68
|
\`\`\`bash
|
|
69
|
-
hq files
|
|
70
|
-
hq files browse companies/<slug>/<folder> # list a folder
|
|
69
|
+
hq files get companies/<slug>/<file> # fetch one file when you know its path
|
|
71
70
|
hq files cat companies/<slug>/<file> # read one file
|
|
71
|
+
hq files browse companies/<slug>/<folder> # list one folder
|
|
72
|
+
hq files search "<query>" --company <slug> # find files by name/path (slow)
|
|
72
73
|
\`\`\`
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
\`hq files search\` lists the entire company vault and filters it locally, so
|
|
76
|
+
on a large company it can take several minutes. If you know the path, use
|
|
77
|
+
\`hq files get\` or \`hq files cat\`. To look inside a folder, use \`hq files browse\`
|
|
78
|
+
with a narrow prefix. Search only when you know neither.
|
|
79
|
+
|
|
80
|
+
A good pattern for a question you cannot answer from names alone: browse a
|
|
81
|
+
narrow folder to find a few likely files, then read them with \`hq files cat\`.
|
|
76
82
|
|
|
77
83
|
Content and semantic search need a local copy and its index, which only exists
|
|
78
84
|
if the kit was installed with \`--sync-files\`. In that case (check
|