@indigoai-us/hq-cli 5.47.15 → 5.47.17
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/.github/workflows/publish.yml +2 -2
- package/dist/commands/feedback.d.ts +2 -0
- package/dist/commands/feedback.js +24 -2
- package/dist/commands/files.d.ts +19 -0
- package/dist/commands/files.js +37 -3
- package/dist/commands/people.d.ts +22 -0
- package/dist/commands/people.js +187 -0
- package/dist/commands/secrets.js +25 -2
- package/dist/index.js +6 -2
- package/dist/run/hq-plugin.js +9 -2
- package/dist/sentry-dsn.generated.d.ts +1 -1
- package/dist/sentry-dsn.generated.js +1 -1
- package/dist/utils/feedback-diagnostics.d.ts +7 -0
- package/dist/utils/feedback-diagnostics.js +4 -2
- package/dist/utils/feedback-screenshots.d.ts +23 -0
- package/dist/utils/feedback-screenshots.js +98 -0
- package/dist/utils/feedback-versions.d.ts +34 -0
- package/dist/utils/feedback-versions.js +50 -0
- package/dist/utils/people.d.ts +99 -0
- package/dist/utils/people.js +168 -0
- package/package.json +1 -1
- package/src/commands/feedback.test.ts +44 -0
- package/src/commands/feedback.ts +46 -13
- package/src/commands/files-delete.test.ts +132 -0
- package/src/commands/files.ts +42 -1
- package/src/commands/people.test.ts +426 -0
- package/src/commands/people.ts +240 -0
- package/src/commands/secrets.test.ts +80 -0
- package/src/commands/secrets.ts +35 -0
- package/src/index.ts +4 -0
- package/src/run/hq-plugin.test.ts +39 -0
- package/src/run/hq-plugin.ts +7 -0
- package/src/utils/feedback-diagnostics.test.ts +11 -0
- package/src/utils/feedback-diagnostics.ts +8 -0
- package/src/utils/feedback-screenshots.test.ts +134 -0
- package/src/utils/feedback-screenshots.ts +124 -0
- package/src/utils/feedback-versions.test.ts +98 -0
- package/src/utils/feedback-versions.ts +68 -0
- package/src/utils/people.ts +222 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { vaultApiFetch } from "./vault-api.js";
|
|
4
|
+
|
|
5
|
+
export const MAX_SCREENSHOTS = 5;
|
|
6
|
+
// Per-image ceiling. Screenshots are PNG/JPEG captures; 10 MB is generous.
|
|
7
|
+
export const MAX_SCREENSHOT_BYTES = 10 * 1024 * 1024;
|
|
8
|
+
|
|
9
|
+
// Extension → content type. Must stay in sync with the server's allowed set
|
|
10
|
+
// (hq-pro feedback-screenshots.ts ALLOWED_CONTENT_TYPES).
|
|
11
|
+
const EXT_CONTENT_TYPE: Record<string, string> = {
|
|
12
|
+
".png": "image/png",
|
|
13
|
+
".jpg": "image/jpeg",
|
|
14
|
+
".jpeg": "image/jpeg",
|
|
15
|
+
".webp": "image/webp",
|
|
16
|
+
".gif": "image/gif",
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function contentTypeForPath(filePath: string): string {
|
|
20
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
21
|
+
const contentType = EXT_CONTENT_TYPE[ext];
|
|
22
|
+
if (!contentType) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
`unsupported screenshot type: ${filePath} (allowed: ${Object.keys(EXT_CONTENT_TYPE).join(", ")})`,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return contentType;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ScreenshotInput {
|
|
31
|
+
path: string;
|
|
32
|
+
contentType: string;
|
|
33
|
+
bytes: Buffer;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Validate + read the given screenshot paths (count, type, existence, size). */
|
|
37
|
+
export function loadScreenshots(paths: string[]): ScreenshotInput[] {
|
|
38
|
+
if (paths.length > MAX_SCREENSHOTS) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`at most ${MAX_SCREENSHOTS} screenshots are allowed (got ${paths.length})`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return paths.map((filePath) => {
|
|
44
|
+
const contentType = contentTypeForPath(filePath);
|
|
45
|
+
let bytes: Buffer;
|
|
46
|
+
try {
|
|
47
|
+
bytes = fs.readFileSync(filePath);
|
|
48
|
+
} catch {
|
|
49
|
+
throw new Error(`cannot read screenshot: ${filePath}`);
|
|
50
|
+
}
|
|
51
|
+
if (bytes.byteLength === 0) {
|
|
52
|
+
throw new Error(`screenshot is empty: ${filePath}`);
|
|
53
|
+
}
|
|
54
|
+
if (bytes.byteLength > MAX_SCREENSHOT_BYTES) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`screenshot too large: ${filePath} (${bytes.byteLength} bytes, max ${MAX_SCREENSHOT_BYTES})`,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return { path: filePath, contentType, bytes };
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface PresignResponse {
|
|
64
|
+
screenshots: Array<{ key: string; url: string; contentType: string }>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Validate the screenshot paths, request presigned PUT URLs from the feedback
|
|
69
|
+
* endpoint, upload each image direct to S3, and return the object keys to
|
|
70
|
+
* attach to the feedback submission. Returns [] for no screenshots.
|
|
71
|
+
*
|
|
72
|
+
* `fetchImpl` is injectable for tests; defaults to the global fetch.
|
|
73
|
+
*/
|
|
74
|
+
export async function uploadScreenshots(opts: {
|
|
75
|
+
paths: string[];
|
|
76
|
+
token: string;
|
|
77
|
+
fetchImpl?: typeof fetch;
|
|
78
|
+
}): Promise<string[]> {
|
|
79
|
+
if (opts.paths.length === 0) return [];
|
|
80
|
+
const inputs = loadScreenshots(opts.paths);
|
|
81
|
+
|
|
82
|
+
const res = await vaultApiFetch({
|
|
83
|
+
token: opts.token,
|
|
84
|
+
path: "/v1/feedback/screenshots/presign",
|
|
85
|
+
method: "POST",
|
|
86
|
+
body: { contentTypes: inputs.map((i) => i.contentType) },
|
|
87
|
+
});
|
|
88
|
+
if (!res.ok) {
|
|
89
|
+
const data = await res.json().catch(() => ({}));
|
|
90
|
+
const msg =
|
|
91
|
+
data &&
|
|
92
|
+
typeof data === "object" &&
|
|
93
|
+
typeof (data as { error?: unknown }).error === "string"
|
|
94
|
+
? (data as { error: string }).error
|
|
95
|
+
: res.statusText;
|
|
96
|
+
throw new Error(`Failed to presign screenshots: ${msg}`);
|
|
97
|
+
}
|
|
98
|
+
const parsed = (await res.json()) as PresignResponse;
|
|
99
|
+
if (
|
|
100
|
+
!parsed ||
|
|
101
|
+
!Array.isArray(parsed.screenshots) ||
|
|
102
|
+
parsed.screenshots.length !== inputs.length
|
|
103
|
+
) {
|
|
104
|
+
throw new Error("Presign response did not match the requested screenshots");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const doFetch = opts.fetchImpl ?? fetch;
|
|
108
|
+
const keys: string[] = [];
|
|
109
|
+
for (let i = 0; i < inputs.length; i++) {
|
|
110
|
+
const slot = parsed.screenshots[i]!;
|
|
111
|
+
const put = await doFetch(slot.url, {
|
|
112
|
+
method: "PUT",
|
|
113
|
+
headers: { "Content-Type": slot.contentType },
|
|
114
|
+
body: inputs[i]!.bytes,
|
|
115
|
+
});
|
|
116
|
+
if (!put.ok) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
`Failed to upload screenshot ${inputs[i]!.path}: HTTP ${put.status}`,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
keys.push(slot.key);
|
|
122
|
+
}
|
|
123
|
+
return keys;
|
|
124
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as os from "node:os";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
|
|
6
|
+
vi.mock("./manifest.js", () => ({
|
|
7
|
+
findHqRoot: vi.fn(() => "/fake/hq"),
|
|
8
|
+
}));
|
|
9
|
+
vi.mock("./pack-contributions.js", () => ({
|
|
10
|
+
readHqVersion: vi.fn(() => "15.0.20"),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
import { findHqRoot } from "./manifest.js";
|
|
14
|
+
import { readHqVersion } from "./pack-contributions.js";
|
|
15
|
+
import { CLI_VERSION } from "../cli-version.js";
|
|
16
|
+
import {
|
|
17
|
+
collectVersions,
|
|
18
|
+
readCoreVersion,
|
|
19
|
+
readSyncVersion,
|
|
20
|
+
} from "./feedback-versions.js";
|
|
21
|
+
|
|
22
|
+
describe("readSyncVersion", () => {
|
|
23
|
+
let tmpHome: string;
|
|
24
|
+
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), "hqsync-"));
|
|
27
|
+
fs.mkdirSync(path.join(tmpHome, ".hq"), { recursive: true });
|
|
28
|
+
});
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
fs.rmSync(tmpHome, { recursive: true, force: true });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
function writeMarker(contents: string): void {
|
|
34
|
+
fs.writeFileSync(path.join(tmpHome, ".hq", "sync-version.json"), contents);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
it("reads the version the hq-sync app records", () => {
|
|
38
|
+
writeMarker(JSON.stringify({ version: "0.8.22-beta.1", updatedAt: "x" }));
|
|
39
|
+
expect(readSyncVersion(tmpHome)).toBe("0.8.22-beta.1");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("returns null when the marker file is absent (hq-sync not installed)", () => {
|
|
43
|
+
expect(readSyncVersion(tmpHome)).toBeNull();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("returns null on malformed JSON rather than throwing", () => {
|
|
47
|
+
writeMarker("{ not json");
|
|
48
|
+
expect(readSyncVersion(tmpHome)).toBeNull();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("returns null when version is missing or not a non-empty string", () => {
|
|
52
|
+
writeMarker(JSON.stringify({ updatedAt: "x" }));
|
|
53
|
+
expect(readSyncVersion(tmpHome)).toBeNull();
|
|
54
|
+
writeMarker(JSON.stringify({ version: "" }));
|
|
55
|
+
expect(readSyncVersion(tmpHome)).toBeNull();
|
|
56
|
+
writeMarker(JSON.stringify({ version: 123 }));
|
|
57
|
+
expect(readSyncVersion(tmpHome)).toBeNull();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("readCoreVersion", () => {
|
|
62
|
+
beforeEach(() => {
|
|
63
|
+
vi.mocked(findHqRoot).mockReset().mockReturnValue("/fake/hq");
|
|
64
|
+
vi.mocked(readHqVersion).mockReset().mockReturnValue("15.0.20");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("reads hqVersion from the resolved HQ root", () => {
|
|
68
|
+
expect(readCoreVersion()).toBe("15.0.20");
|
|
69
|
+
expect(readHqVersion).toHaveBeenCalledWith("/fake/hq");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("returns null (never throws) when resolution fails", () => {
|
|
73
|
+
vi.mocked(findHqRoot).mockImplementation(() => {
|
|
74
|
+
throw new Error("no hq root");
|
|
75
|
+
});
|
|
76
|
+
expect(readCoreVersion()).toBeNull();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("returns null when core.yaml has no hqVersion", () => {
|
|
80
|
+
vi.mocked(readHqVersion).mockReturnValue(null);
|
|
81
|
+
expect(readCoreVersion()).toBeNull();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe("collectVersions", () => {
|
|
86
|
+
beforeEach(() => {
|
|
87
|
+
vi.mocked(findHqRoot).mockReset().mockReturnValue("/fake/hq");
|
|
88
|
+
vi.mocked(readHqVersion).mockReset().mockReturnValue("15.0.20");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("always reports the cli version and best-effort core/sync", () => {
|
|
92
|
+
const versions = collectVersions();
|
|
93
|
+
expect(versions.cli).toBe(CLI_VERSION);
|
|
94
|
+
expect(versions.core).toBe("15.0.20");
|
|
95
|
+
// sync reads the real homedir marker, which won't exist in CI → null.
|
|
96
|
+
expect(["string", "object"]).toContain(typeof versions.sync); // string | null
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as os from "node:os";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { CLI_VERSION } from "../cli-version.js";
|
|
5
|
+
import { findHqRoot } from "./manifest.js";
|
|
6
|
+
import { readHqVersion } from "./pack-contributions.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The three HQ component versions captured from the submitter's environment
|
|
10
|
+
* and attached to a feedback submission so triage can see exactly which
|
|
11
|
+
* versions a report came from.
|
|
12
|
+
*
|
|
13
|
+
* - `cli` — this hq-cli build (always known).
|
|
14
|
+
* - `core` — the HQ scaffold version from `core/core.yaml` (`hqVersion`);
|
|
15
|
+
* null when the command runs outside an HQ tree.
|
|
16
|
+
* - `sync` — the installed hq-sync menubar app version, which the app
|
|
17
|
+
* records at `~/.hq/sync-version.json` on startup; null when
|
|
18
|
+
* hq-sync is not installed (e.g. CLI-only / CI environments).
|
|
19
|
+
*/
|
|
20
|
+
export interface VersionInfo {
|
|
21
|
+
cli: string;
|
|
22
|
+
core: string | null;
|
|
23
|
+
sync: string | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Best-effort read of the hq-core scaffold version (`core/core.yaml`
|
|
28
|
+
* `hqVersion`). Resolves the HQ root from the working directory; returns
|
|
29
|
+
* null when no HQ root / core.yaml is found rather than throwing — version
|
|
30
|
+
* capture must never break a feedback submission.
|
|
31
|
+
*/
|
|
32
|
+
export function readCoreVersion(): string | null {
|
|
33
|
+
try {
|
|
34
|
+
return readHqVersion(findHqRoot());
|
|
35
|
+
} catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Best-effort read of the hq-sync menubar app version. The app writes
|
|
42
|
+
* `{ version, updatedAt }` to `~/.hq/sync-version.json` on startup; the CLI
|
|
43
|
+
* reads it here. Returns null when the file is absent or malformed (hq-sync
|
|
44
|
+
* not installed, or an older build that predates the marker).
|
|
45
|
+
*/
|
|
46
|
+
export function readSyncVersion(homeDir: string = os.homedir()): string | null {
|
|
47
|
+
try {
|
|
48
|
+
const raw = fs.readFileSync(
|
|
49
|
+
path.join(homeDir, ".hq", "sync-version.json"),
|
|
50
|
+
"utf-8",
|
|
51
|
+
);
|
|
52
|
+
const parsed = JSON.parse(raw) as { version?: unknown };
|
|
53
|
+
return typeof parsed.version === "string" && parsed.version.length > 0
|
|
54
|
+
? parsed.version
|
|
55
|
+
: null;
|
|
56
|
+
} catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Collect all three component versions, each independently best-effort. */
|
|
62
|
+
export function collectVersions(): VersionInfo {
|
|
63
|
+
return {
|
|
64
|
+
cli: CLI_VERSION,
|
|
65
|
+
core: readCoreVersion(),
|
|
66
|
+
sync: readSyncVersion(),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Company people (membership) directory reader + search.
|
|
3
|
+
*
|
|
4
|
+
* The local source of truth for "who belongs to a company" is the per-company
|
|
5
|
+
* people store on disk:
|
|
6
|
+
*
|
|
7
|
+
* companies/<company-slug>/people/<person-slug>/meta.yaml
|
|
8
|
+
*
|
|
9
|
+
* Each `meta.yaml` carries at least `name` and `type` ("internal" | "external")
|
|
10
|
+
* plus optional `email`, `role`, `organization`, `tags`, etc. (see
|
|
11
|
+
* `companies/_template/people/_example/meta.yaml` for the canonical schema).
|
|
12
|
+
*
|
|
13
|
+
* Everything here is scoped to ONE company directory. Callers resolve a single
|
|
14
|
+
* company slug up front; nothing in this module ever enumerates or reads across
|
|
15
|
+
* company boundaries — HQ tenancy rules forbid cross-company member lookups.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import * as fs from "fs";
|
|
19
|
+
import * as path from "path";
|
|
20
|
+
import * as yaml from "js-yaml";
|
|
21
|
+
|
|
22
|
+
/** A single person/member record parsed from a `people/<slug>/meta.yaml`. */
|
|
23
|
+
export interface PersonRecord {
|
|
24
|
+
/** Folder slug under `companies/<company>/people/<slug>/`. */
|
|
25
|
+
slug: string;
|
|
26
|
+
/** Display name (required field in `meta.yaml`). */
|
|
27
|
+
name: string;
|
|
28
|
+
/** Contact email, when recorded. */
|
|
29
|
+
email?: string;
|
|
30
|
+
/** "internal" (team member) | "external" (client, vendor, …). */
|
|
31
|
+
type?: string;
|
|
32
|
+
/** Role/title inside (or relative to) the company. */
|
|
33
|
+
role?: string;
|
|
34
|
+
/** External-only: the person's own organization. */
|
|
35
|
+
organization?: string;
|
|
36
|
+
/** Freeform tags for filtering. */
|
|
37
|
+
tags?: string[];
|
|
38
|
+
/** Absolute path to the `meta.yaml` this record was parsed from. */
|
|
39
|
+
source: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Company slugs map directly onto a filesystem path segment, so we validate
|
|
44
|
+
* them before joining to keep a malicious or fat-fingered `--company` value
|
|
45
|
+
* from escaping the `companies/` tree. Mirrors the slug rules used by
|
|
46
|
+
* cloud-provision.
|
|
47
|
+
*/
|
|
48
|
+
const COMPANY_SLUG_REGEX = /^[A-Za-z0-9._-]+$/;
|
|
49
|
+
const FORBIDDEN_COMPANY_SLUGS = new Set(["personal", ".", ".."]);
|
|
50
|
+
|
|
51
|
+
export function assertSafeCompanySlug(slug: string): void {
|
|
52
|
+
if (!slug || !COMPANY_SLUG_REGEX.test(slug)) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`Invalid company slug "${slug}" — must match ${COMPANY_SLUG_REGEX.source}`,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
if (FORBIDDEN_COMPANY_SLUGS.has(slug)) {
|
|
58
|
+
throw new Error(`Company slug "${slug}" is reserved and cannot be used here`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Absolute path to a company's `people/` directory. */
|
|
63
|
+
export function companyPeopleDir(hqRoot: string, companySlug: string): string {
|
|
64
|
+
assertSafeCompanySlug(companySlug);
|
|
65
|
+
return path.join(hqRoot, "companies", companySlug, "people");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Parse a single `meta.yaml` body into a `PersonRecord`. Returns `null` when the
|
|
70
|
+
* file is empty, unparseable, or has no usable `name` — a person record without
|
|
71
|
+
* a name can't be listed, searched, or resolved, so it's skipped rather than
|
|
72
|
+
* surfaced as a half-row. Exported for unit testing.
|
|
73
|
+
*/
|
|
74
|
+
export function parsePersonMeta(
|
|
75
|
+
raw: string,
|
|
76
|
+
slug: string,
|
|
77
|
+
source: string,
|
|
78
|
+
): PersonRecord | null {
|
|
79
|
+
let doc: unknown;
|
|
80
|
+
try {
|
|
81
|
+
doc = yaml.load(raw);
|
|
82
|
+
} catch (err) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`Failed to parse ${source}: ${err instanceof Error ? err.message : String(err)}`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
if (!doc || typeof doc !== "object") return null;
|
|
88
|
+
const d = doc as Record<string, unknown>;
|
|
89
|
+
|
|
90
|
+
const name = typeof d.name === "string" ? d.name.trim() : "";
|
|
91
|
+
if (!name) return null;
|
|
92
|
+
|
|
93
|
+
const str = (v: unknown): string | undefined =>
|
|
94
|
+
typeof v === "string" && v.trim() ? v.trim() : undefined;
|
|
95
|
+
|
|
96
|
+
const tags = Array.isArray(d.tags)
|
|
97
|
+
? d.tags.filter((t): t is string => typeof t === "string")
|
|
98
|
+
: undefined;
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
slug,
|
|
102
|
+
name,
|
|
103
|
+
email: str(d.email),
|
|
104
|
+
type: str(d.type),
|
|
105
|
+
role: str(d.role),
|
|
106
|
+
organization: str(d.organization),
|
|
107
|
+
...(tags && tags.length > 0 ? { tags } : {}),
|
|
108
|
+
source,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* List every person recorded for ONE company. Reads
|
|
114
|
+
* `companies/<companySlug>/people/<personSlug>/meta.yaml` for each person
|
|
115
|
+
* folder.
|
|
116
|
+
*
|
|
117
|
+
* - Folders whose name starts with `_` are skipped (e.g. the `_example`
|
|
118
|
+
* template that ships in `companies/_template/people/`).
|
|
119
|
+
* - Folders without a `meta.yaml`, or whose `meta.yaml` has no `name`, are
|
|
120
|
+
* skipped silently — they aren't members yet.
|
|
121
|
+
* - Returns `[]` when the company has no `people/` directory at all.
|
|
122
|
+
*
|
|
123
|
+
* Results are sorted by name (case-insensitive) for stable output.
|
|
124
|
+
*/
|
|
125
|
+
export function listCompanyPeople(
|
|
126
|
+
hqRoot: string,
|
|
127
|
+
companySlug: string,
|
|
128
|
+
): PersonRecord[] {
|
|
129
|
+
const dir = companyPeopleDir(hqRoot, companySlug);
|
|
130
|
+
if (!fs.existsSync(dir)) return [];
|
|
131
|
+
|
|
132
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
133
|
+
const people: PersonRecord[] = [];
|
|
134
|
+
|
|
135
|
+
for (const entry of entries) {
|
|
136
|
+
if (!entry.isDirectory()) continue;
|
|
137
|
+
if (entry.name.startsWith("_")) continue; // _example and other scaffolding
|
|
138
|
+
|
|
139
|
+
const metaPath = path.join(dir, entry.name, "meta.yaml");
|
|
140
|
+
if (!fs.existsSync(metaPath)) continue;
|
|
141
|
+
|
|
142
|
+
const raw = fs.readFileSync(metaPath, "utf-8");
|
|
143
|
+
const record = parsePersonMeta(raw, entry.name, metaPath);
|
|
144
|
+
if (record) people.push(record);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
people.sort((a, b) =>
|
|
148
|
+
a.name.localeCompare(b.name, undefined, { sensitivity: "base" }),
|
|
149
|
+
);
|
|
150
|
+
return people;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Case-insensitive keyword search over a person's NAME and EMAIL (plus the
|
|
155
|
+
* folder slug, which is a normalized alias of the name). Pure — operates on an
|
|
156
|
+
* already-loaded list so it's trivially testable and reusable.
|
|
157
|
+
*
|
|
158
|
+
* An empty/whitespace keyword matches nothing (callers should treat that as a
|
|
159
|
+
* usage error rather than "return everyone").
|
|
160
|
+
*/
|
|
161
|
+
export function searchPeople(
|
|
162
|
+
people: PersonRecord[],
|
|
163
|
+
keyword: string,
|
|
164
|
+
): PersonRecord[] {
|
|
165
|
+
const needle = keyword.trim().toLowerCase();
|
|
166
|
+
if (!needle) return [];
|
|
167
|
+
return people.filter((p) => {
|
|
168
|
+
const haystacks = [p.name, p.email, p.slug].filter(
|
|
169
|
+
(v): v is string => typeof v === "string",
|
|
170
|
+
);
|
|
171
|
+
return haystacks.some((h) => h.toLowerCase().includes(needle));
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Outcome of resolving a name to an email address. */
|
|
176
|
+
export type ResolveResult =
|
|
177
|
+
| { status: "found"; email: string; person: PersonRecord }
|
|
178
|
+
| { status: "no_email"; person: PersonRecord }
|
|
179
|
+
| { status: "ambiguous"; matches: PersonRecord[] }
|
|
180
|
+
| { status: "not_found" };
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Resolve a person NAME to their email, built on top of {@link searchPeople}.
|
|
184
|
+
*
|
|
185
|
+
* Match precedence (narrowest first) so a precise query isn't drowned out by
|
|
186
|
+
* looser substring hits:
|
|
187
|
+
* 1. exact name match (case-insensitive, trimmed)
|
|
188
|
+
* 2. exact folder-slug match
|
|
189
|
+
* 3. substring search over name/email/slug
|
|
190
|
+
*
|
|
191
|
+
* The first tier that yields any match decides the result:
|
|
192
|
+
* - exactly one match with an email → `found`
|
|
193
|
+
* - exactly one match, no email → `no_email`
|
|
194
|
+
* - more than one match → `ambiguous` (caller disambiguates)
|
|
195
|
+
* - no match in any tier → `not_found`
|
|
196
|
+
*/
|
|
197
|
+
export function resolveNameToEmail(
|
|
198
|
+
people: PersonRecord[],
|
|
199
|
+
name: string,
|
|
200
|
+
): ResolveResult {
|
|
201
|
+
const query = name.trim();
|
|
202
|
+
if (!query) return { status: "not_found" };
|
|
203
|
+
const lowered = query.toLowerCase();
|
|
204
|
+
|
|
205
|
+
const exactName = people.filter((p) => p.name.toLowerCase() === lowered);
|
|
206
|
+
const exactSlug = people.filter((p) => p.slug.toLowerCase() === lowered);
|
|
207
|
+
const substring = searchPeople(people, query);
|
|
208
|
+
|
|
209
|
+
const matches =
|
|
210
|
+
exactName.length > 0
|
|
211
|
+
? exactName
|
|
212
|
+
: exactSlug.length > 0
|
|
213
|
+
? exactSlug
|
|
214
|
+
: substring;
|
|
215
|
+
|
|
216
|
+
if (matches.length === 0) return { status: "not_found" };
|
|
217
|
+
if (matches.length > 1) return { status: "ambiguous", matches };
|
|
218
|
+
|
|
219
|
+
const person = matches[0];
|
|
220
|
+
if (!person.email) return { status: "no_email", person };
|
|
221
|
+
return { status: "found", email: person.email, person };
|
|
222
|
+
}
|