@indigoai-us/hq-cli 5.108.26 → 5.109.1

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.
@@ -0,0 +1,53 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ export function accessOutcomesPath(hqRoot) {
4
+ return path.join(hqRoot, ".hq", "access-outcomes.jsonl");
5
+ }
6
+ /**
7
+ * Append one JSONL line. Best-effort by contract: callers are expected to
8
+ * catch and downgrade any failure, since telemetry must never change an
9
+ * `hq access` outcome or exit code.
10
+ */
11
+ export function recordAccessOutcome(hqRoot, rec) {
12
+ const file = accessOutcomesPath(hqRoot);
13
+ fs.mkdirSync(path.dirname(file), { recursive: true });
14
+ const line = JSON.stringify({ outcome: rec.outcome, company: rec.company, ts: rec.ts });
15
+ fs.appendFileSync(file, `${line}\n`, "utf-8");
16
+ }
17
+ /**
18
+ * Read the ledger. A missing file is the empty ledger; malformed lines are
19
+ * skipped so one bad append never hides the rest of the history.
20
+ */
21
+ export function readAccessOutcomes(hqRoot) {
22
+ const file = accessOutcomesPath(hqRoot);
23
+ let raw;
24
+ try {
25
+ raw = fs.readFileSync(file, "utf-8");
26
+ }
27
+ catch (err) {
28
+ if (err.code === "ENOENT")
29
+ return [];
30
+ throw err;
31
+ }
32
+ const out = [];
33
+ for (const line of raw.split("\n")) {
34
+ const trimmed = line.trim();
35
+ if (!trimmed)
36
+ continue;
37
+ try {
38
+ const parsed = JSON.parse(trimmed);
39
+ if (parsed &&
40
+ typeof parsed === "object" &&
41
+ typeof parsed.outcome === "string" &&
42
+ typeof parsed.company === "string" &&
43
+ typeof parsed.ts === "string") {
44
+ out.push(parsed);
45
+ }
46
+ }
47
+ catch {
48
+ // malformed line: skip
49
+ }
50
+ }
51
+ return out;
52
+ }
53
+ //# sourceMappingURL=access-outcomes.js.map
@@ -0,0 +1,28 @@
1
+ export declare const ACCESS_REQUEST_DEDUPE_MS: number;
2
+ export interface AccessRequestRecord {
3
+ requester: string;
4
+ prefix: string;
5
+ company: string;
6
+ grantor: string;
7
+ sentAt: string;
8
+ eventId?: string;
9
+ }
10
+ export declare function accessRequestsPath(hqRoot: string): string;
11
+ /**
12
+ * Read the ledger. A missing file is the empty ledger; any other failure
13
+ * (unreadable, corrupt JSON, non-array shape) is rethrown with the ledger path
14
+ * so a corrupt file is never silently replaced by the next write.
15
+ */
16
+ export declare function readAccessRequests(hqRoot: string): AccessRequestRecord[];
17
+ export declare function recordAccessRequest(hqRoot: string, rec: AccessRequestRecord): void;
18
+ export declare function findRecentAccessRequest(hqRoot: string, args: {
19
+ requester: string;
20
+ prefix: string;
21
+ /** Company slug — `prefix` is company-relative, so it is only unique per company. */
22
+ company: string;
23
+ grantor: string;
24
+ now: number;
25
+ windowMs?: number;
26
+ }): AccessRequestRecord | null;
27
+ export declare function formatTimeAgo(iso: string, nowMs: number): string;
28
+ //# sourceMappingURL=access-requests.d.ts.map
@@ -0,0 +1,98 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ export const ACCESS_REQUEST_DEDUPE_MS = 24 * 60 * 60 * 1000;
4
+ export function accessRequestsPath(hqRoot) {
5
+ return path.join(hqRoot, ".hq", "access-requests.json");
6
+ }
7
+ /**
8
+ * Read the ledger. A missing file is the empty ledger; any other failure
9
+ * (unreadable, corrupt JSON, non-array shape) is rethrown with the ledger path
10
+ * so a corrupt file is never silently replaced by the next write.
11
+ */
12
+ export function readAccessRequests(hqRoot) {
13
+ const file = accessRequestsPath(hqRoot);
14
+ let raw;
15
+ try {
16
+ raw = fs.readFileSync(file, "utf-8");
17
+ }
18
+ catch (err) {
19
+ if (err.code === "ENOENT")
20
+ return [];
21
+ const message = err instanceof Error ? err.message : String(err);
22
+ throw new Error(`Cannot read access-request ledger at ${file}: ${message}`);
23
+ }
24
+ let parsed;
25
+ try {
26
+ parsed = JSON.parse(raw);
27
+ }
28
+ catch (err) {
29
+ const message = err instanceof Error ? err.message : String(err);
30
+ throw new Error(`Corrupt access-request ledger at ${file}: ${message}. Repair or remove the file; it was not overwritten.`);
31
+ }
32
+ if (!Array.isArray(parsed)) {
33
+ throw new Error(`Corrupt access-request ledger at ${file}: expected a JSON array. Repair or remove the file; it was not overwritten.`);
34
+ }
35
+ return parsed;
36
+ }
37
+ export function recordAccessRequest(hqRoot, rec) {
38
+ // Read first: a corrupt ledger throws here, before anything is written.
39
+ const existing = readAccessRequests(hqRoot);
40
+ existing.push(rec);
41
+ const file = accessRequestsPath(hqRoot);
42
+ fs.mkdirSync(path.dirname(file), { recursive: true });
43
+ // Atomic replace: write a sibling tmp file, then rename over the ledger so a
44
+ // crash mid-write can never leave a truncated file behind.
45
+ const tmp = `${file}.${process.pid}.${Date.now()}.tmp`;
46
+ try {
47
+ fs.writeFileSync(tmp, JSON.stringify(existing, null, 2), "utf-8");
48
+ fs.renameSync(tmp, file);
49
+ }
50
+ finally {
51
+ // A failed rename must not strand the tmp file next to the ledger.
52
+ if (fs.existsSync(tmp))
53
+ fs.unlinkSync(tmp);
54
+ }
55
+ }
56
+ export function findRecentAccessRequest(hqRoot, args) {
57
+ const windowMs = args.windowMs ?? ACCESS_REQUEST_DEDUPE_MS;
58
+ const rows = readAccessRequests(hqRoot);
59
+ let latest = null;
60
+ for (const row of rows) {
61
+ if (row.requester !== args.requester ||
62
+ row.prefix !== args.prefix ||
63
+ row.company !== args.company ||
64
+ row.grantor !== args.grantor) {
65
+ continue;
66
+ }
67
+ const t = Date.parse(row.sentAt);
68
+ if (!Number.isFinite(t))
69
+ continue;
70
+ if (args.now - t > windowMs)
71
+ continue;
72
+ if (!latest || Date.parse(latest.sentAt) < t)
73
+ latest = row;
74
+ }
75
+ return latest;
76
+ }
77
+ export function formatTimeAgo(iso, nowMs) {
78
+ const t = Date.parse(iso);
79
+ if (!Number.isFinite(t))
80
+ return "just now";
81
+ const delta = Math.max(0, nowMs - t);
82
+ const minute = 60 * 1000;
83
+ const hour = 60 * minute;
84
+ const day = 24 * hour;
85
+ if (delta < minute)
86
+ return "just now";
87
+ if (delta < hour) {
88
+ const n = Math.floor(delta / minute);
89
+ return `${n} minute${n === 1 ? "" : "s"} ago`;
90
+ }
91
+ if (delta < day) {
92
+ const n = Math.floor(delta / hour);
93
+ return `${n} hour${n === 1 ? "" : "s"} ago`;
94
+ }
95
+ const n = Math.floor(delta / day);
96
+ return `${n} day${n === 1 ? "" : "s"} ago`;
97
+ }
98
+ //# sourceMappingURL=access-requests.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigoai-us/hq-cli",
3
- "version": "5.108.26",
3
+ "version": "5.109.1",
4
4
  "description": "HQ by Indigo management CLI — modules and cloud sync",
5
5
  "main": "dist/index.js",
6
6
  "bin": {