@indigoai-us/hq-cli 5.345.156 → 5.345.159

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/CHANGELOG.md +231 -0
  2. package/assets/scaffold/core/scripts/rebuild-company-knowledge-index.sh +110 -2
  3. package/assets/scaffold/core/scripts/rebuild-projects-index.sh +101 -5
  4. package/assets/scaffold/core/scripts/worktree.sh +4 -0
  5. package/dist/command-catalog.generated.d.ts +531 -6
  6. package/dist/command-catalog.generated.js +674 -27
  7. package/dist/command-registration-plan.d.ts +18 -0
  8. package/dist/command-registration-plan.js +4 -0
  9. package/dist/commands/_patterns.d.ts +17 -0
  10. package/dist/commands/_patterns.js +22 -0
  11. package/dist/commands/agent-kit.js +8 -6
  12. package/dist/commands/bot.js +7 -4
  13. package/dist/commands/channel-suggest.d.ts +56 -0
  14. package/dist/commands/channel-suggest.js +170 -0
  15. package/dist/commands/channels.js +7 -1
  16. package/dist/commands/cloud.d.ts +45 -0
  17. package/dist/commands/cloud.js +150 -10
  18. package/dist/commands/company.js +4 -3
  19. package/dist/commands/core-checkpoint-native.d.ts +18 -0
  20. package/dist/commands/core-checkpoint-native.js +67 -2
  21. package/dist/commands/core-pipeline-driver-native.d.ts +12 -1
  22. package/dist/commands/core-pipeline-driver-native.js +131 -5
  23. package/dist/commands/core.js +12 -0
  24. package/dist/commands/crm.js +83 -6
  25. package/dist/commands/deploy-access.d.ts +33 -0
  26. package/dist/commands/deploy-access.js +322 -0
  27. package/dist/commands/dm-attach.d.ts +106 -0
  28. package/dist/commands/dm-attach.js +184 -0
  29. package/dist/commands/dm.d.ts +37 -0
  30. package/dist/commands/dm.js +172 -10
  31. package/dist/commands/feedback-show.d.ts +40 -0
  32. package/dist/commands/feedback-show.js +261 -0
  33. package/dist/commands/feedback.d.ts +21 -0
  34. package/dist/commands/feedback.js +152 -2
  35. package/dist/commands/files.d.ts +24 -0
  36. package/dist/commands/files.js +52 -1
  37. package/dist/commands/integrations-connect.js +7 -3
  38. package/dist/commands/lanes-accounts.js +16 -1
  39. package/dist/commands/lanes-loop.js +14 -4
  40. package/dist/commands/lanes-message.js +6 -4
  41. package/dist/commands/lanes-resume.js +36 -13
  42. package/dist/commands/lanes-shared.d.ts +5 -0
  43. package/dist/commands/lanes-shared.js +13 -3
  44. package/dist/commands/lanes-watch.js +1 -0
  45. package/dist/commands/lanes.d.ts +20 -1
  46. package/dist/commands/lanes.js +201 -51
  47. package/dist/commands/mesh.js +149 -1
  48. package/dist/commands/monitor.d.ts +1 -0
  49. package/dist/commands/monitor.js +4 -1
  50. package/dist/commands/repo.d.ts +41 -0
  51. package/dist/commands/repo.js +331 -0
  52. package/dist/commands/scan.d.ts +3 -1
  53. package/dist/commands/scan.js +7 -3
  54. package/dist/commands/secrets.d.ts +21 -0
  55. package/dist/commands/secrets.js +114 -14
  56. package/dist/commands/signals.js +17 -5
  57. package/dist/commands/staff/listings.d.ts +41 -0
  58. package/dist/commands/staff/listings.js +160 -0
  59. package/dist/commands/staff/reset-test-account.d.ts +3 -2
  60. package/dist/commands/staff/reset-test-account.js +4 -3
  61. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +2629 -1036
  62. package/dist/hq-cloud-sync-runner/package.json +1 -1
  63. package/dist/lib/agent-kit/run/inbox.js +2 -1
  64. package/dist/lib/agent-kit/wake-secrets.d.ts +7 -0
  65. package/dist/lib/agent-kit/wake-secrets.js +32 -0
  66. package/dist/lib/agent-kit/wake.d.ts +4 -0
  67. package/dist/lib/agent-kit/wake.js +49 -3
  68. package/dist/lib/bot/inflight.d.ts +7 -1
  69. package/dist/lib/bot/inflight.js +10 -2
  70. package/dist/lib/bot/prompt.js +3 -0
  71. package/dist/lib/bot/run.js +72 -20
  72. package/dist/lib/bot/session.d.ts +14 -0
  73. package/dist/lib/bot/session.js +70 -0
  74. package/dist/lib/capacity/collectors/claude-oauth.d.ts +6 -0
  75. package/dist/lib/capacity/collectors/claude-oauth.js +12 -0
  76. package/dist/lib/capacity/lane-login.d.ts +6 -0
  77. package/dist/lib/capacity/lane-login.js +5 -0
  78. package/dist/lib/core-utils/worktree.js +2 -0
  79. package/dist/lib/daemon/exit-cause.d.ts +43 -0
  80. package/dist/lib/daemon/exit-cause.js +88 -0
  81. package/dist/lib/daemon/handoff.d.ts +2 -0
  82. package/dist/lib/daemon/handoff.js +6 -1
  83. package/dist/lib/daemon/hq-child-bootstrap.mjs +20 -3
  84. package/dist/lib/daemon/paths.d.ts +2 -0
  85. package/dist/lib/daemon/paths.js +1 -0
  86. package/dist/lib/daemon/run.js +13 -0
  87. package/dist/lib/daemon/supervisor.d.ts +54 -1
  88. package/dist/lib/daemon/supervisor.js +297 -21
  89. package/dist/lib/daemon/unit-holds.d.ts +22 -0
  90. package/dist/lib/daemon/unit-holds.js +86 -0
  91. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  92. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  93. package/dist/lib/index-render/company-knowledge.js +1 -3
  94. package/dist/lib/index-render/projects.js +1 -3
  95. package/dist/lib/lanes/account-company.d.ts +28 -0
  96. package/dist/lib/lanes/account-company.js +53 -0
  97. package/dist/lib/lanes/accounts.d.ts +22 -3
  98. package/dist/lib/lanes/accounts.js +38 -2
  99. package/dist/lib/lanes/claude-balance.d.ts +6 -1
  100. package/dist/lib/lanes/claude-balance.js +6 -1
  101. package/dist/lib/lanes/claude-credential.d.ts +78 -0
  102. package/dist/lib/lanes/claude-credential.js +163 -0
  103. package/dist/lib/lanes/compaction.d.ts +2 -0
  104. package/dist/lib/lanes/compaction.js +9 -0
  105. package/dist/lib/lanes/config.js +6 -0
  106. package/dist/lib/lanes/envelope-repair-dispatch.js +2 -1
  107. package/dist/lib/lanes/hooks-install.js +2 -1
  108. package/dist/lib/lanes/host-capacity.d.ts +2 -0
  109. package/dist/lib/lanes/host-capacity.js +1 -0
  110. package/dist/lib/lanes/keep-alive.d.ts +1 -1
  111. package/dist/lib/lanes/keep-alive.js +3 -1
  112. package/dist/lib/lanes/links.js +10 -4
  113. package/dist/lib/lanes/loop.js +16 -1
  114. package/dist/lib/lanes/node-binary.d.ts +17 -0
  115. package/dist/lib/lanes/node-binary.js +30 -0
  116. package/dist/lib/lanes/outpost-dispatch.d.ts +2 -1
  117. package/dist/lib/lanes/outpost-dispatch.js +1 -0
  118. package/dist/lib/lanes/reconcile.js +4 -0
  119. package/dist/lib/lanes/remote-control-lane.js +2 -0
  120. package/dist/lib/lanes/spawn.d.ts +3 -0
  121. package/dist/lib/lanes/spawn.js +119 -9
  122. package/dist/lib/lanes/store.d.ts +6 -0
  123. package/dist/lib/lanes/store.js +107 -18
  124. package/dist/lib/lanes/types.d.ts +2 -0
  125. package/dist/lib/lanes/watch.js +28 -5
  126. package/dist/lib/lanes/watcher-main.js +4 -3
  127. package/dist/lib/lanes/watcher.d.ts +4 -0
  128. package/dist/lib/lanes/watcher.js +110 -21
  129. package/dist/lib/mesh/api.d.ts +32 -0
  130. package/dist/lib/mesh/api.js +75 -0
  131. package/dist/lib/secret-scan/detect.js +9 -0
  132. package/dist/lib/secret-scan/repo-config.d.ts +41 -0
  133. package/dist/lib/secret-scan/repo-config.js +237 -0
  134. package/dist/lib/secret-scan/rules.d.ts +7 -1
  135. package/dist/lib/secret-scan/rules.js +3 -1
  136. package/dist/lib/secret-scan/staged.d.ts +5 -0
  137. package/dist/lib/secret-scan/staged.js +19 -2
  138. package/dist/lib/secret-scan/types.d.ts +2 -0
  139. package/dist/lib/sync/server-owned-local-only.d.ts +29 -0
  140. package/dist/lib/sync/server-owned-local-only.js +75 -0
  141. package/dist/utils/package-use-lease.js +27 -9
  142. package/dist/utils/version-gate.d.ts +7 -0
  143. package/dist/utils/version-gate.js +66 -0
  144. package/package.json +8 -8
@@ -515,6 +515,81 @@ export async function registerMeshProject(token, companyUid, projectId, channelI
515
515
  channelCreated: result?.channelCreated === true,
516
516
  };
517
517
  }
518
+ // ---------------------------------------------------------------------------
519
+ // Project lifecycle (active | completed | archived)
520
+ // ---------------------------------------------------------------------------
521
+ export const PROJECT_LIFECYCLE_STATUSES = ["active", "completed", "archived"];
522
+ function lifecycleFromRow(row) {
523
+ const rec = asRecord(row);
524
+ const projectId = String(rec?.projectId || "").trim();
525
+ const status = String(rec?.status || "").trim();
526
+ const version = Number(rec?.version);
527
+ if (!projectId || !Number.isSafeInteger(version) || version < 0)
528
+ return null;
529
+ if (!PROJECT_LIFECYCLE_STATUSES.includes(status))
530
+ return null;
531
+ return {
532
+ projectId,
533
+ status: status,
534
+ version,
535
+ updatedAt: String(rec?.updatedAt || ""),
536
+ updatedBy: String(rec?.updatedBy || ""),
537
+ };
538
+ }
539
+ /**
540
+ * List every lifecycle row for a company (follows the 25-row server pages).
541
+ * A project with no row has never left `active` and is not listed.
542
+ */
543
+ export async function listProjectLifecycles(token, companyUid) {
544
+ const rows = [];
545
+ let cursor;
546
+ // Bounded so a server that keeps returning the same cursor cannot loop forever.
547
+ for (let page = 0; page < 200; page += 1) {
548
+ const data = asRecord(await meshJson(token, "/v1/work-mesh/project-lifecycle", {
549
+ query: { companyUid, ...(cursor ? { cursor } : {}) },
550
+ }));
551
+ const projects = Array.isArray(data?.projects) ? data.projects : [];
552
+ for (const row of projects) {
553
+ const parsed = lifecycleFromRow(row);
554
+ if (parsed)
555
+ rows.push(parsed);
556
+ }
557
+ const next = typeof data?.nextCursor === "string" ? data.nextCursor.trim() : "";
558
+ if (!next || next === cursor)
559
+ break;
560
+ cursor = next;
561
+ }
562
+ return rows;
563
+ }
564
+ /** The lifecycle row for one project, or null when it has never been changed. */
565
+ export async function getProjectLifecycle(token, companyUid, projectId) {
566
+ const rows = await listProjectLifecycles(token, companyUid);
567
+ return rows.find((row) => row.projectId === projectId) ?? null;
568
+ }
569
+ /**
570
+ * PATCH /v1/work-mesh/projects/{id}/lifecycle. `expectedVersion` is the
571
+ * current lifecycle row version (0 when the project has no row yet). The
572
+ * server answers 409 BOARD_NONEMPTY when archiving a Board that still has
573
+ * stories unless `confirmNonempty` is set, and a plain 409 on a version
574
+ * mismatch. Nothing is deleted: stories, folder, channel, members and
575
+ * history stay; the project only leaves the active list and the organize
576
+ * candidates.
577
+ */
578
+ export async function setProjectLifecycle(token, companyUid, projectId, change) {
579
+ const data = await meshJson(token, `/v1/work-mesh/projects/${encodeURIComponent(projectId)}/lifecycle`, {
580
+ method: "PATCH",
581
+ query: { companyUid },
582
+ body: {
583
+ status: change.status,
584
+ expectedVersion: change.expectedVersion,
585
+ ...(change.confirmNonempty ? { confirmNonempty: true } : {}),
586
+ },
587
+ });
588
+ const parsed = lifecycleFromRow(data);
589
+ if (!parsed)
590
+ throw new Error("Work mesh returned an invalid project lifecycle row");
591
+ return parsed;
592
+ }
518
593
  export function pairDmUidsFromInbox(inbox) {
519
594
  const rec = asRecord(inbox);
520
595
  const ids = new Set();
@@ -36,6 +36,8 @@ function allowed(al, c) {
36
36
  const lower = c.secret.toLowerCase();
37
37
  checks.push(al.stopwords.some((s) => lower.includes(s)));
38
38
  }
39
+ if (al.commits.length)
40
+ checks.push(c.commit !== undefined && al.commits.includes(c.commit.toLowerCase()));
39
41
  if (!checks.length)
40
42
  return false;
41
43
  return al.condition === "AND" ? checks.every(Boolean) : checks.some(Boolean);
@@ -50,6 +52,10 @@ function lineBounds(text, start, end) {
50
52
  offset++;
51
53
  return { line: text.slice(from, to), offset };
52
54
  }
55
+ /** A repo allowlist applies to this rule (no targetRules means every rule). */
56
+ function repoAllowed(rules, ruleId, c) {
57
+ return (rules.repo ?? []).some((al) => (!al.targetRules.length || al.targetRules.includes(ruleId)) && allowed(al, c));
58
+ }
53
59
  /** True when the global allowlist excludes this path from scanning. */
54
60
  export function pathIgnored(file, rules = compiledRules()) {
55
61
  return rules.global.paths.some((p) => p.test(file));
@@ -60,6 +66,7 @@ export function scanPath(file, rules = compiledRules()) {
60
66
  return [];
61
67
  return rules.rules
62
68
  .filter((r) => !r.regex && r.path?.test(file))
69
+ .filter((r) => !repoAllowed(rules, r.id, { file, secret: "", match: "", line: "" }))
63
70
  .map((r) => ({ ruleId: r.id, description: r.description, file, line: 1 }));
64
71
  }
65
72
  export function scanFragment(frag, rules = compiledRules()) {
@@ -103,6 +110,8 @@ export function scanFragment(frag, rules = compiledRules()) {
103
110
  continue;
104
111
  if (rule.allowlists.some((al) => allowed(al, cand)))
105
112
  continue;
113
+ if (repoAllowed(rules, rule.id, cand))
114
+ continue;
106
115
  const lineNo = startLine + offset;
107
116
  const key = `${rule.id}:${lineNo}`;
108
117
  if (seen.has(key))
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Repo-level allowlists: `[[allowlists]]` (and the legacy `[allowlist]`) from
3
+ * the scanned repo's own `.gitleaks.toml`, with gitleaks semantics for
4
+ * `paths`, `regexes`, `regexTarget`, `stopwords`, `commits`, `targetRules` and
5
+ * `condition`. They apply on top of the built-in rules and allowlists, to that
6
+ * repo only. Repo `[[rules]]`, `[extend]` and the rest of the file are ignored:
7
+ * a repo can allow known false positives, not change what is detected.
8
+ *
9
+ * The file is read from git, never the working tree:
10
+ * - The staged (index) copy applies only when it is identical to the copy
11
+ * already committed at HEAD (or at MERGE_HEAD during a merge). A commit
12
+ * that changes the allowlist is scanned with the HEAD allowlist, so
13
+ * widening the allowlist and adding the secret cannot happen in one commit.
14
+ * - A changed staged copy is still validated, so a broken file fails now.
15
+ * - A symlinked .gitleaks.toml is rejected.
16
+ *
17
+ * Narrow by construction: every allowlist needs `paths`, each anchored with a
18
+ * literal prefix (`^golden/...`); `regexes` and `stopwords` need
19
+ * `condition = "AND"`, so they never reach files outside those paths.
20
+ *
21
+ * Fails closed: anything not acceptable is a ScanConfigError, and the scan
22
+ * exits 2 rather than running with a guess.
23
+ */
24
+ import { type CompiledAllowlist } from "./rules.js";
25
+ export declare class ScanConfigError extends Error {
26
+ }
27
+ export declare const REPO_CONFIG_FILE = ".gitleaks.toml";
28
+ /**
29
+ * Length of the literal text right after a leading `^`: letters, digits,
30
+ * `/ _ - @ ~` and backslash-escaped punctuation. A quantifier on the last
31
+ * literal makes it optional, so it does not count.
32
+ */
33
+ export declare function literalPathPrefix(src: string): number;
34
+ /** Validated allowlists from the text of a .gitleaks.toml. */
35
+ export declare function parseRepoAllowlists(text: string, file?: string): CompiledAllowlist[];
36
+ /**
37
+ * Compiled allowlists for a staged scan of the repo at `repoRoot`, read from
38
+ * git as described at the top of this file. [] when the repo has none.
39
+ */
40
+ export declare function loadRepoAllowlists(repoRoot: string): CompiledAllowlist[];
41
+ //# sourceMappingURL=repo-config.d.ts.map
@@ -0,0 +1,237 @@
1
+ /**
2
+ * Repo-level allowlists: `[[allowlists]]` (and the legacy `[allowlist]`) from
3
+ * the scanned repo's own `.gitleaks.toml`, with gitleaks semantics for
4
+ * `paths`, `regexes`, `regexTarget`, `stopwords`, `commits`, `targetRules` and
5
+ * `condition`. They apply on top of the built-in rules and allowlists, to that
6
+ * repo only. Repo `[[rules]]`, `[extend]` and the rest of the file are ignored:
7
+ * a repo can allow known false positives, not change what is detected.
8
+ *
9
+ * The file is read from git, never the working tree:
10
+ * - The staged (index) copy applies only when it is identical to the copy
11
+ * already committed at HEAD (or at MERGE_HEAD during a merge). A commit
12
+ * that changes the allowlist is scanned with the HEAD allowlist, so
13
+ * widening the allowlist and adding the secret cannot happen in one commit.
14
+ * - A changed staged copy is still validated, so a broken file fails now.
15
+ * - A symlinked .gitleaks.toml is rejected.
16
+ *
17
+ * Narrow by construction: every allowlist needs `paths`, each anchored with a
18
+ * literal prefix (`^golden/...`); `regexes` and `stopwords` need
19
+ * `condition = "AND"`, so they never reach files outside those paths.
20
+ *
21
+ * Fails closed: anything not acceptable is a ScanConfigError, and the scan
22
+ * exits 2 rather than running with a guess.
23
+ */
24
+ import { execFileSync } from "node:child_process";
25
+ import { parse } from "smol-toml";
26
+ import { compileGoRegex } from "./go-regex.js";
27
+ import { compileAllowlist } from "./rules.js";
28
+ export class ScanConfigError extends Error {
29
+ }
30
+ export const REPO_CONFIG_FILE = ".gitleaks.toml";
31
+ const KEYS = new Set(["description", "condition", "regexTarget", "paths", "regexes", "stopwords", "commits", "targetRules"]);
32
+ const MIN_PATH_PREFIX = 3;
33
+ const MIN_STOPWORD = 3;
34
+ /** User regexes run on JavaScript's backtracking engine, not RE2. */
35
+ const MAX_REGEX_LENGTH = 256;
36
+ /** A quantified group that itself contains a quantifier, e.g. (a+)+ or (?:x*y)*. */
37
+ const NESTED_QUANTIFIER = /\((?:[^()\\]|\\.)*[*+}](?:[^()\\]|\\.)*\)[*+{]/;
38
+ /** Paths no real allowlist path should match all of. */
39
+ const PROBE_PATHS = ["a", ".env", "src/index.ts", "config/credentials.yml", "deep/nested/dir/file.json"];
40
+ function fail(file, where, msg) {
41
+ throw new ScanConfigError(`${file}: ${where}: ${msg}`);
42
+ }
43
+ function stringList(file, where, key, v) {
44
+ if (v === undefined)
45
+ return undefined;
46
+ if (!Array.isArray(v) || v.some((x) => typeof x !== "string"))
47
+ fail(file, where, `${key} must be a list of strings`);
48
+ return v;
49
+ }
50
+ /**
51
+ * Length of the literal text right after a leading `^`: letters, digits,
52
+ * `/ _ - @ ~` and backslash-escaped punctuation. A quantifier on the last
53
+ * literal makes it optional, so it does not count.
54
+ */
55
+ export function literalPathPrefix(src) {
56
+ if (!src.startsWith("^"))
57
+ return 0;
58
+ let n = 0;
59
+ let i = 1;
60
+ while (i < src.length) {
61
+ const ch = src[i];
62
+ if (/[A-Za-z0-9/_\-@~]/.test(ch)) {
63
+ n++;
64
+ i++;
65
+ }
66
+ else if (ch === "\\" && i + 1 < src.length && /[^A-Za-z0-9]/.test(src[i + 1])) {
67
+ n++;
68
+ i += 2;
69
+ }
70
+ else {
71
+ break;
72
+ }
73
+ }
74
+ if (n > 0 && /^[*?{]/.test(src.slice(i)))
75
+ n--;
76
+ return n;
77
+ }
78
+ /** True when `src` has a `|` outside any group, which would bypass the `^` prefix. */
79
+ function topLevelAlternation(src) {
80
+ let depth = 0;
81
+ let inClass = false;
82
+ for (let i = 0; i < src.length; i++) {
83
+ const ch = src[i];
84
+ if (ch === "\\")
85
+ i++;
86
+ else if (inClass)
87
+ inClass = ch !== "]";
88
+ else if (ch === "[")
89
+ inClass = true;
90
+ else if (ch === "(")
91
+ depth++;
92
+ else if (ch === ")")
93
+ depth--;
94
+ else if (ch === "|" && depth === 0)
95
+ return true;
96
+ }
97
+ return false;
98
+ }
99
+ function compileChecked(file, where, key, src) {
100
+ if (src.length > MAX_REGEX_LENGTH)
101
+ fail(file, where, `${key} entry is longer than ${MAX_REGEX_LENGTH} characters`);
102
+ if (NESTED_QUANTIFIER.test(src))
103
+ fail(file, where, `${key} entry ${JSON.stringify(src)} has a nested quantifier; simplify it`);
104
+ try {
105
+ return compileGoRegex(src);
106
+ }
107
+ catch (err) {
108
+ fail(file, where, `${key} entry ${JSON.stringify(src)} is not a supported regex (${err instanceof Error ? err.message : String(err)})`);
109
+ }
110
+ }
111
+ function validate(file, where, raw) {
112
+ if (!raw || typeof raw !== "object" || Array.isArray(raw))
113
+ fail(file, where, "must be a table");
114
+ const t = raw;
115
+ for (const k of Object.keys(t))
116
+ if (!KEYS.has(k))
117
+ fail(file, where, `unknown key "${k}"`);
118
+ if (t.description !== undefined && typeof t.description !== "string")
119
+ fail(file, where, "description must be a string");
120
+ let condition;
121
+ if (t.condition !== undefined) {
122
+ const c = typeof t.condition === "string" ? t.condition.trim().toUpperCase() : "";
123
+ if (c !== "OR" && c !== "AND")
124
+ fail(file, where, 'condition must be "AND" or "OR"');
125
+ condition = c;
126
+ }
127
+ if (t.regexTarget !== undefined && t.regexTarget !== "secret" && t.regexTarget !== "match" && t.regexTarget !== "line") {
128
+ fail(file, where, 'regexTarget must be "secret", "match" or "line"');
129
+ }
130
+ const al = {
131
+ condition,
132
+ regexTarget: t.regexTarget,
133
+ paths: stringList(file, where, "paths", t.paths),
134
+ regexes: stringList(file, where, "regexes", t.regexes),
135
+ stopwords: stringList(file, where, "stopwords", t.stopwords),
136
+ commits: stringList(file, where, "commits", t.commits),
137
+ targetRules: stringList(file, where, "targetRules", t.targetRules),
138
+ };
139
+ // A repo may narrow what is reported, never switch the scanner off: every
140
+ // allowlist is scoped to files named by an anchored literal prefix.
141
+ if (!al.paths?.length) {
142
+ fail(file, where, "needs paths, each starting with ^ and a literal directory or file name (e.g. '^fixtures/')");
143
+ }
144
+ for (const src of al.paths) {
145
+ const re = compileChecked(file, where, "paths", src);
146
+ if (literalPathPrefix(src) < MIN_PATH_PREFIX || topLevelAlternation(src)) {
147
+ fail(file, where, `paths entry ${JSON.stringify(src)} must start with ^ and at least ${MIN_PATH_PREFIX} literal characters (e.g. '^fixtures/')`);
148
+ }
149
+ if (re.test("") || PROBE_PATHS.every((p) => re.test(p))) {
150
+ fail(file, where, `paths entry ${JSON.stringify(src)} matches everything; allowlist specific files`);
151
+ }
152
+ }
153
+ if ((al.regexes?.length || al.stopwords?.length) && al.condition !== "AND") {
154
+ fail(file, where, 'regexes and stopwords need condition = "AND", so they only apply inside paths');
155
+ }
156
+ for (const src of al.regexes ?? []) {
157
+ if (compileChecked(file, where, "regexes", src).test(""))
158
+ fail(file, where, `regexes entry ${JSON.stringify(src)} matches everything`);
159
+ }
160
+ for (const s of al.stopwords ?? []) {
161
+ if (s.trim().length < MIN_STOPWORD)
162
+ fail(file, where, `stopword ${JSON.stringify(s)} is shorter than ${MIN_STOPWORD} characters`);
163
+ }
164
+ return al;
165
+ }
166
+ /** Validated allowlists from the text of a .gitleaks.toml. */
167
+ export function parseRepoAllowlists(text, file = REPO_CONFIG_FILE) {
168
+ let doc;
169
+ try {
170
+ doc = parse(text);
171
+ }
172
+ catch (err) {
173
+ throw new ScanConfigError(`${file}: could not be parsed: ${err instanceof Error ? err.message.split("\n")[0] : String(err)}`);
174
+ }
175
+ const out = [];
176
+ if (doc.allowlist !== undefined)
177
+ out.push(validate(file, "[allowlist]", doc.allowlist));
178
+ if (doc.allowlists !== undefined) {
179
+ if (!Array.isArray(doc.allowlists))
180
+ fail(file, "allowlists", "must be an array of tables ([[allowlists]])");
181
+ doc.allowlists.forEach((a, i) => out.push(validate(file, `[[allowlists]] #${i + 1}`, a)));
182
+ }
183
+ return out.map(compileAllowlist);
184
+ }
185
+ function git(repoRoot, args) {
186
+ try {
187
+ return execFileSync("git", args, { cwd: repoRoot, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] });
188
+ }
189
+ catch {
190
+ return null;
191
+ }
192
+ }
193
+ /** `<mode> <type> <blob>\t<path>` (ls-tree, blobField 2) or `<mode> <blob> <stage>\t<path>` (ls-files -s, blobField 1). */
194
+ function entry(out, blobField) {
195
+ const line = out?.split("\n").find(Boolean);
196
+ if (!line)
197
+ return null;
198
+ const f = line.split("\t")[0].split(" ");
199
+ return { mode: f[0], blob: f[blobField] };
200
+ }
201
+ function readEntry(repoRoot, e, where) {
202
+ if (e.mode === "120000")
203
+ throw new ScanConfigError(`${REPO_CONFIG_FILE} (${where}) is a symlink; commit a regular file`);
204
+ const text = git(repoRoot, ["cat-file", "blob", e.blob]);
205
+ if (text === null)
206
+ throw new ScanConfigError(`${REPO_CONFIG_FILE} (${where}) could not be read from git`);
207
+ return text;
208
+ }
209
+ /**
210
+ * Compiled allowlists for a staged scan of the repo at `repoRoot`, read from
211
+ * git as described at the top of this file. [] when the repo has none.
212
+ */
213
+ export function loadRepoAllowlists(repoRoot) {
214
+ const lsFiles = git(repoRoot, ["ls-files", "-s", "--", REPO_CONFIG_FILE]);
215
+ // Only a resolved (stage 0) index entry counts. A conflicted .gitleaks.toml
216
+ // has stages 1-3 and no stage 0; it is not trusted and the HEAD copy is used.
217
+ const stage0 = lsFiles?.split("\n").find((l) => l.split("\t")[0].split(" ")[2] === "0") ?? null;
218
+ const staged = entry(stage0, 1);
219
+ if (!staged)
220
+ return lsFiles?.trim() ? headAllowlists(repoRoot) : [];
221
+ const stagedLists = parseRepoAllowlists(readEntry(repoRoot, staged, "staged"));
222
+ const committed = ["HEAD", "MERGE_HEAD"]
223
+ .filter((rev) => git(repoRoot, ["rev-parse", "--verify", "-q", `${rev}^{commit}`]) !== null)
224
+ .map((rev) => ({ rev, e: entry(git(repoRoot, ["ls-tree", rev, "--", REPO_CONFIG_FILE]), 2) }))
225
+ .filter((c) => c.e !== null);
226
+ if (committed.some((c) => c.e.blob === staged.blob && c.e.mode === staged.mode))
227
+ return stagedLists;
228
+ // Changed in this commit: scan with the version already committed at HEAD.
229
+ return headAllowlists(repoRoot);
230
+ }
231
+ function headAllowlists(repoRoot) {
232
+ if (git(repoRoot, ["rev-parse", "--verify", "-q", "HEAD^{commit}"]) === null)
233
+ return [];
234
+ const head = entry(git(repoRoot, ["ls-tree", "HEAD", "--", REPO_CONFIG_FILE]), 2);
235
+ return head ? parseRepoAllowlists(readEntry(repoRoot, head, "HEAD"), `${REPO_CONFIG_FILE} (HEAD)`) : [];
236
+ }
237
+ //# sourceMappingURL=repo-config.js.map
@@ -2,13 +2,16 @@
2
2
  * Compiled rule set: the vendored gitleaks default rules plus HQ's own token
3
3
  * patterns (src/lib/core-utils/secret-patterns.ts). Compiled once per process.
4
4
  */
5
- import type { GitleaksRule } from "./types.js";
5
+ import type { GitleaksAllowlist, GitleaksRule } from "./types.js";
6
6
  export interface CompiledAllowlist {
7
7
  condition: "OR" | "AND";
8
8
  target: "secret" | "match" | "line";
9
9
  paths: RegExp[];
10
10
  regexes: RegExp[];
11
11
  stopwords: string[];
12
+ commits: string[];
13
+ /** Empty: applies to every rule. */
14
+ targetRules: string[];
12
15
  }
13
16
  export interface CompiledRule {
14
17
  id: string;
@@ -24,7 +27,10 @@ export interface CompiledRule {
24
27
  export interface CompiledRuleSet {
25
28
  global: CompiledAllowlist;
26
29
  rules: CompiledRule[];
30
+ /** Allowlists from the scanned repo's own .gitleaks.toml (see repo-config.ts). */
31
+ repo?: CompiledAllowlist[];
27
32
  }
33
+ export declare function compileAllowlist(a: GitleaksAllowlist): CompiledAllowlist;
28
34
  /** HQ's own patterns, expressed as gitleaks-shaped rules. */
29
35
  export declare function hqRules(): GitleaksRule[];
30
36
  export declare function compiledRules(): CompiledRuleSet;
@@ -5,13 +5,15 @@
5
5
  import { SECRET_PATTERNS } from "../core-utils/secret-patterns.js";
6
6
  import { GITLEAKS_CONFIG } from "./gitleaks-rules.generated.js";
7
7
  import { compileGoRegex } from "./go-regex.js";
8
- function compileAllowlist(a) {
8
+ export function compileAllowlist(a) {
9
9
  return {
10
10
  condition: a.condition === "AND" ? "AND" : "OR",
11
11
  target: a.regexTarget ?? "secret",
12
12
  paths: (a.paths ?? []).map((p) => compileGoRegex(p)),
13
13
  regexes: (a.regexes ?? []).map((r) => compileGoRegex(r)),
14
14
  stopwords: (a.stopwords ?? []).map((s) => s.toLowerCase()),
15
+ commits: (a.commits ?? []).map((c) => c.toLowerCase()),
16
+ targetRules: a.targetRules ?? [],
15
17
  };
16
18
  }
17
19
  function compileRule(r) {
@@ -12,6 +12,11 @@ export interface ParsedDiff {
12
12
  /** Parse `git diff --unified=0` output into one fragment of added lines per hunk. */
13
13
  export declare function parseUnifiedDiff(diff: string): ParsedDiff;
14
14
  export declare function stagedDiff(cwd: string): string;
15
+ export declare function repoRoot(cwd: string): string;
16
+ /**
17
+ * Built-in rules plus the repo's own .gitleaks.toml allowlists. Diff paths are
18
+ * relative to the repo root, as gitleaks' allowlist paths are.
19
+ */
15
20
  export declare function scanStaged(cwd: string): SecretFinding[];
16
21
  export declare function scanFiles(paths: string[]): SecretFinding[];
17
22
  //# sourceMappingURL=staged.d.ts.map
@@ -4,6 +4,8 @@
4
4
  import { execFileSync } from "node:child_process";
5
5
  import { readFileSync, statSync } from "node:fs";
6
6
  import { scanFragment, scanPath } from "./detect.js";
7
+ import { loadRepoAllowlists } from "./repo-config.js";
8
+ import { compiledRules } from "./rules.js";
7
9
  export class ScanInputError extends Error {
8
10
  }
9
11
  const DIFF_ARGS = [
@@ -89,9 +91,24 @@ export function stagedDiff(cwd) {
89
91
  throw new ScanInputError(`could not read the staged changes: ${detail || "git diff failed"}`);
90
92
  }
91
93
  }
94
+ export function repoRoot(cwd) {
95
+ try {
96
+ return execFileSync("git", ["rev-parse", "--show-toplevel"], { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
97
+ }
98
+ catch (err) {
99
+ const detail = err instanceof Error && "stderr" in err ? String(err.stderr).trim() : String(err);
100
+ throw new ScanInputError(`could not find the repo root: ${detail || "git rev-parse failed"}`);
101
+ }
102
+ }
103
+ /**
104
+ * Built-in rules plus the repo's own .gitleaks.toml allowlists. Diff paths are
105
+ * relative to the repo root, as gitleaks' allowlist paths are.
106
+ */
92
107
  export function scanStaged(cwd) {
93
- const { fragments, binaryFiles } = parseUnifiedDiff(stagedDiff(cwd));
94
- return [...fragments.flatMap((f) => scanFragment(f)), ...binaryFiles.flatMap((f) => scanPath(f))];
108
+ const diff = stagedDiff(cwd);
109
+ const rules = { ...compiledRules(), repo: loadRepoAllowlists(repoRoot(cwd)) };
110
+ const { fragments, binaryFiles } = parseUnifiedDiff(diff);
111
+ return [...fragments.flatMap((f) => scanFragment(f, rules)), ...binaryFiles.flatMap((f) => scanPath(f, rules))];
95
112
  }
96
113
  export function scanFiles(paths) {
97
114
  const out = [];
@@ -9,6 +9,8 @@ export interface GitleaksAllowlist {
9
9
  regexes?: string[];
10
10
  stopwords?: string[];
11
11
  commits?: string[];
12
+ /** Repo allowlists only: limit the allowlist to these rule ids. */
13
+ targetRules?: string[];
12
14
  }
13
15
  export interface GitleaksRule {
14
16
  id: string;
@@ -0,0 +1,29 @@
1
+ /** Company-relative folders the server owns and a client push never uploads. */
2
+ export declare const SERVER_OWNED_FOLDERS: readonly string[];
3
+ /**
4
+ * True for a company-relative path a client push refuses as server-owned.
5
+ * Mirrors hq-cloud's `isLocallyIneligibleForPush` with the entity exception:
6
+ * `ontology/entities/` can be client-owned, so it is not reported here.
7
+ */
8
+ export declare function isServerOwnedNeverPushed(rel: string): boolean;
9
+ export type ServerOwnedLocalOnlyResult = {
10
+ files: string[];
11
+ total: number;
12
+ };
13
+ export type FindServerOwnedLocalOnlyOptions = {
14
+ hqRoot: string;
15
+ slug: string;
16
+ /** Company-relative keys already in the sync journal (live or tombstoned). */
17
+ journalKeys: ReadonlySet<string>;
18
+ /** Engine ignore filter over absolute paths; true = would sync. */
19
+ shouldSync?: (absPath: string, isDir?: boolean) => boolean;
20
+ /** Max paths returned; `total` still counts every match. */
21
+ limit?: number;
22
+ };
23
+ /**
24
+ * Walk the server-owned folders under `companies/<slug>/` and return files
25
+ * that are not in the journal. A journaled file arrived by pull and is in
26
+ * sync; anything else was written locally and will never upload.
27
+ */
28
+ export declare function findServerOwnedLocalOnly(opts: FindServerOwnedLocalOnlyOptions): ServerOwnedLocalOnlyResult;
29
+ //# sourceMappingURL=server-owned-local-only.d.ts.map
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Local-only files under server-owned vault folders (feedback_0414d71c).
3
+ *
4
+ * The sync engine treats `sources/`, `signals/` and the non-entity part of
5
+ * `ontology/` as cloud-authoritative: the server pipeline writes them and a
6
+ * client push refuses them (`refuse-server-owned` in hq-cloud's share plan,
7
+ * see hq-cloud `src/lib/cloud-authoritative.ts`). The recurring runner skips
8
+ * them quietly, so a file written locally into one of these folders never
9
+ * reaches the vault and nothing reports it as pending. `hq sync status` lists
10
+ * them so the gap is visible.
11
+ *
12
+ * Read-only and network-free: the walk covers only the server-owned folders
13
+ * and the "already synced" set is the company's sync journal the caller
14
+ * already has.
15
+ */
16
+ import * as fs from "node:fs";
17
+ import * as path from "node:path";
18
+ /** Company-relative folders the server owns and a client push never uploads. */
19
+ export const SERVER_OWNED_FOLDERS = ["sources", "signals", "ontology"];
20
+ /**
21
+ * True for a company-relative path a client push refuses as server-owned.
22
+ * Mirrors hq-cloud's `isLocallyIneligibleForPush` with the entity exception:
23
+ * `ontology/entities/` can be client-owned, so it is not reported here.
24
+ */
25
+ export function isServerOwnedNeverPushed(rel) {
26
+ const vaultRel = rel.split("\\").join("/").replace(/^\.?\//, "");
27
+ if (vaultRel.startsWith("ontology/entities/"))
28
+ return false;
29
+ return SERVER_OWNED_FOLDERS.some((folder) => vaultRel.startsWith(`${folder}/`));
30
+ }
31
+ /**
32
+ * Walk the server-owned folders under `companies/<slug>/` and return files
33
+ * that are not in the journal. A journaled file arrived by pull and is in
34
+ * sync; anything else was written locally and will never upload.
35
+ */
36
+ export function findServerOwnedLocalOnly(opts) {
37
+ const root = path.join(opts.hqRoot, "companies", opts.slug);
38
+ const limit = opts.limit ?? 20;
39
+ const found = [];
40
+ const stack = SERVER_OWNED_FOLDERS.map((folder) => path.join(root, folder));
41
+ while (stack.length > 0) {
42
+ const dir = stack.pop();
43
+ let entries;
44
+ try {
45
+ entries = fs.readdirSync(dir, { withFileTypes: true });
46
+ }
47
+ catch {
48
+ continue;
49
+ }
50
+ for (const entry of entries) {
51
+ const abs = path.join(dir, entry.name);
52
+ if (entry.isDirectory()) {
53
+ if (entry.name === ".git" || entry.name === "node_modules")
54
+ continue;
55
+ if (opts.shouldSync && !opts.shouldSync(abs, true))
56
+ continue;
57
+ stack.push(abs);
58
+ continue;
59
+ }
60
+ if (!entry.isFile())
61
+ continue;
62
+ if (opts.shouldSync && !opts.shouldSync(abs, false))
63
+ continue;
64
+ const rel = path.relative(root, abs).split(path.sep).join("/");
65
+ if (!isServerOwnedNeverPushed(rel))
66
+ continue;
67
+ if (opts.journalKeys.has(rel))
68
+ continue;
69
+ found.push(rel);
70
+ }
71
+ }
72
+ found.sort((a, b) => a.localeCompare(b));
73
+ return { files: found.slice(0, limit), total: found.length };
74
+ }
75
+ //# sourceMappingURL=server-owned-local-only.js.map
@@ -1,5 +1,5 @@
1
1
  import { createHash, randomBytes } from "node:crypto";
2
- import { mkdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync, } from "node:fs";
2
+ import { mkdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, } from "node:fs";
3
3
  import { utimes } from "node:fs/promises";
4
4
  import os from "node:os";
5
5
  import path from "node:path";
@@ -152,6 +152,29 @@ export function packageUseLeaseDirectory(prefix, stateDirectory = packageUseStat
152
152
  function packageUseUpdateRequestPath(prefix, stateDirectory) {
153
153
  return path.join(packageUseLeaseDirectory(prefix, stateDirectory), UPDATE_REQUEST);
154
154
  }
155
+ // os.uptime() has whole-second resolution, so allow a small margin before
156
+ // calling a request older than the current boot.
157
+ const BOOT_TIME_MARGIN_MS = 5_000;
158
+ /**
159
+ * An update request is stale when it was written before the current boot (its
160
+ * pid may have been reused by an unrelated process since), or when its pid is
161
+ * gone (ESRCH) or belongs to another user (EPERM). The updater always runs as
162
+ * the same user as the CLI, so a pid we may not signal is not our updater.
163
+ */
164
+ function updateRequestIsStale(requestPath, pid) {
165
+ const bootTimeMs = Date.now() - os.uptime() * 1000;
166
+ if (statSync(requestPath).mtimeMs < bootTimeMs - BOOT_TIME_MARGIN_MS)
167
+ return true;
168
+ try {
169
+ process.kill(pid, 0);
170
+ }
171
+ catch (error) {
172
+ const code = error.code;
173
+ if (code === "ESRCH" || code === "EPERM")
174
+ return true;
175
+ }
176
+ return false;
177
+ }
155
178
  function waitForUpdateRequest(requestPath, timeoutMs, notify = null) {
156
179
  const started = Date.now();
157
180
  let notified = false;
@@ -163,14 +186,9 @@ function waitForUpdateRequest(requestPath, timeoutMs, notify = null) {
163
186
  if (typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0) {
164
187
  throw new Error("invalid update request");
165
188
  }
166
- try {
167
- process.kill(pid, 0);
168
- }
169
- catch (error) {
170
- if (error.code === "ESRCH") {
171
- rmSync(requestPath, { force: true });
172
- return;
173
- }
189
+ if (updateRequestIsStale(requestPath, pid)) {
190
+ rmSync(requestPath, { force: true });
191
+ return;
174
192
  }
175
193
  }
176
194
  catch (error) {