@indigoai-us/hq-cli 5.345.215 → 5.345.218

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 (161) hide show
  1. package/CHANGELOG.md +168 -0
  2. package/README.md +46 -1
  3. package/assets/bot-workers/setup/skills/add-a-pack.md +3 -3
  4. package/assets/scaffold/core/scripts/hq-session.sh +4 -0
  5. package/assets/scaffold/core/scripts/lib/epochrealtime.sh +30 -0
  6. package/assets/scaffold/core/scripts/lib/work-mesh-enqueue.sh +12 -5
  7. package/dist/command-catalog.generated.d.ts +59 -4
  8. package/dist/command-catalog.generated.js +74 -4
  9. package/dist/command-help.js +3 -1
  10. package/dist/command-registration-plan.d.ts +6 -0
  11. package/dist/command-registration-plan.js +1 -0
  12. package/dist/commands/auth.d.ts +1 -1
  13. package/dist/commands/auth.js +11 -52
  14. package/dist/commands/bot.js +11 -4
  15. package/dist/commands/cloud-demote.d.ts +19 -4
  16. package/dist/commands/cloud-demote.js +85 -12
  17. package/dist/commands/cloud-provision.d.ts +5 -1
  18. package/dist/commands/cloud-provision.js +6 -2
  19. package/dist/commands/cloud.d.ts +37 -1
  20. package/dist/commands/cloud.js +110 -27
  21. package/dist/commands/core-hq-session-native.js +3 -0
  22. package/dist/commands/core.js +1 -0
  23. package/dist/commands/daemon.js +4 -1
  24. package/dist/commands/dm.js +7 -0
  25. package/dist/commands/doctor-usage.d.ts +8 -0
  26. package/dist/commands/doctor-usage.js +20 -0
  27. package/dist/commands/doctor.js +7 -1
  28. package/dist/commands/env.d.ts +18 -0
  29. package/dist/commands/env.js +82 -0
  30. package/dist/commands/install-global.js +3 -3
  31. package/dist/commands/lanes.js +100 -24
  32. package/dist/commands/logout.d.ts +7 -0
  33. package/dist/commands/logout.js +41 -34
  34. package/dist/commands/members.js +1 -1
  35. package/dist/commands/pack-start-bot.d.ts +1 -1
  36. package/dist/commands/pack-start-bot.js +2 -2
  37. package/dist/commands/pkg-update.js +1 -1
  38. package/dist/commands/sources.d.ts +8 -2
  39. package/dist/commands/sources.js +65 -9
  40. package/dist/commands/sync-narrow.js +1 -1
  41. package/dist/commands/team-sync.js +1 -1
  42. package/dist/commands/whoami.js +26 -1
  43. package/dist/data/command-states.json +22 -0
  44. package/dist/index.js +52 -4
  45. package/dist/lazy-commands.js +2 -1
  46. package/dist/lib/anywhere-person-setting.d.ts +2 -0
  47. package/dist/lib/anywhere-person-setting.js +6 -3
  48. package/dist/lib/billing/usage-card.d.ts +25 -4
  49. package/dist/lib/billing/usage-card.js +76 -9
  50. package/dist/lib/billing/usage-cost.d.ts +3 -3
  51. package/dist/lib/billing/usage-cost.js +40 -15
  52. package/dist/lib/billing/usage-only.js +4 -2
  53. package/dist/lib/billing/usage-rate-card.d.ts +2 -2
  54. package/dist/lib/billing/usage-rate-card.js +3 -0
  55. package/dist/lib/bot/fleet-cron.js +93 -6
  56. package/dist/lib/bot/inflight.d.ts +9 -0
  57. package/dist/lib/bot/inflight.js +10 -0
  58. package/dist/lib/bot/jobs/hot-signal-sync.js +12 -1
  59. package/dist/lib/bot/pack-link.d.ts +2 -2
  60. package/dist/lib/bot/pack-link.js +2 -2
  61. package/dist/lib/bot/runtime/grok-acp.d.ts +1 -0
  62. package/dist/lib/bot/runtime/grok-acp.js +26 -11
  63. package/dist/lib/bot/runtime/grok.js +1 -1
  64. package/dist/lib/daemon/flag-monitor.d.ts +8 -0
  65. package/dist/lib/daemon/flag-monitor.js +17 -6
  66. package/dist/lib/daemon/flag.d.ts +65 -1
  67. package/dist/lib/daemon/flag.js +190 -40
  68. package/dist/lib/daemon/hook-env.d.ts +32 -0
  69. package/dist/lib/daemon/hook-env.js +51 -0
  70. package/dist/lib/daemon/ops/policy.js +67 -8
  71. package/dist/lib/daemon/paths.d.ts +72 -2
  72. package/dist/lib/daemon/paths.js +154 -3
  73. package/dist/lib/daemon/run.js +32 -21
  74. package/dist/lib/daemon/selfcheck.d.ts +22 -0
  75. package/dist/lib/daemon/selfcheck.js +40 -1
  76. package/dist/lib/daemon/server.d.ts +3 -1
  77. package/dist/lib/daemon/server.js +7 -22
  78. package/dist/lib/daemon/state-file-switch.d.ts +57 -0
  79. package/dist/lib/daemon/state-file-switch.js +88 -0
  80. package/dist/lib/daemon/state-file.d.ts +198 -0
  81. package/dist/lib/daemon/state-file.js +419 -0
  82. package/dist/lib/daemon/timed-flag-monitors.d.ts +47 -0
  83. package/dist/lib/daemon/timed-flag-monitors.js +75 -0
  84. package/dist/lib/doctor/checks/host-core.d.ts +52 -0
  85. package/dist/lib/doctor/checks/host-core.js +337 -0
  86. package/dist/lib/doctor/checks/replay-recorder.d.ts +39 -0
  87. package/dist/lib/doctor/checks/replay-recorder.js +261 -0
  88. package/dist/lib/doctor/checks/sync-runtime.js +3 -3
  89. package/dist/lib/doctor/registry.js +4 -0
  90. package/dist/lib/environment/credential-shapes.d.ts +61 -0
  91. package/dist/lib/environment/credential-shapes.js +333 -0
  92. package/dist/lib/environment/profile.d.ts +239 -0
  93. package/dist/lib/environment/profile.js +239 -0
  94. package/dist/lib/hook-engine/coverage.d.ts +13 -0
  95. package/dist/lib/hook-engine/coverage.js +124 -0
  96. package/dist/lib/hook-engine/reconcile.js +300 -94
  97. package/dist/lib/hook-engine/registration.d.ts +17 -1
  98. package/dist/lib/hook-engine/registration.js +62 -7
  99. package/dist/lib/hot-channels/adapters/slack.d.ts +21 -5
  100. package/dist/lib/hot-channels/adapters/slack.js +64 -21
  101. package/dist/lib/hot-channels/alert.d.ts +2 -0
  102. package/dist/lib/hot-channels/alert.js +8 -1
  103. package/dist/lib/hot-channels/contract.d.ts +12 -0
  104. package/dist/lib/hot-channels/contract.js +7 -0
  105. package/dist/lib/hot-channels/loop.js +1 -0
  106. package/dist/lib/hot-channels/run.d.ts +6 -0
  107. package/dist/lib/hot-channels/run.js +4 -0
  108. package/dist/lib/hot-channels/signals-pass.d.ts +64 -1
  109. package/dist/lib/hot-channels/signals-pass.js +21 -49
  110. package/dist/lib/install/claude-targets.d.ts +12 -1
  111. package/dist/lib/install/claude-targets.js +70 -5
  112. package/dist/lib/install/codex-pack-contributions.js +1 -1
  113. package/dist/lib/install/codex-targets.d.ts +2 -2
  114. package/dist/lib/install/codex-targets.js +48 -5
  115. package/dist/lib/install/hook-target.d.ts +4 -1
  116. package/dist/lib/install/hook-target.js +14 -1
  117. package/dist/lib/lanes/canonical-host.d.ts +35 -0
  118. package/dist/lib/lanes/canonical-host.js +65 -0
  119. package/dist/lib/lanes/host-capacity.d.ts +30 -0
  120. package/dist/lib/lanes/host-capacity.js +29 -3
  121. package/dist/lib/mesh/live/daemon/run.d.ts +2 -0
  122. package/dist/lib/mesh/live/daemon/run.js +5 -2
  123. package/dist/lib/mesh/live/flush.d.ts +5 -1
  124. package/dist/lib/mesh/live/flush.js +12 -6
  125. package/dist/lib/mesh/live/reporting-privacy.d.ts +32 -0
  126. package/dist/lib/mesh/live/reporting-privacy.js +56 -1
  127. package/dist/lib/mesh/live/spool.d.ts +7 -0
  128. package/dist/lib/mesh/live/spool.js +25 -0
  129. package/dist/lib/packages/setup-block.d.ts +2 -2
  130. package/dist/lib/packages/setup-block.js +2 -2
  131. package/dist/lib/packages/start-bot.d.ts +1 -1
  132. package/dist/lib/packages/start-bot.js +1 -1
  133. package/dist/lib/person-setting-cache.d.ts +38 -0
  134. package/dist/lib/person-setting-cache.js +98 -0
  135. package/dist/lib/safe-store.d.ts +245 -0
  136. package/dist/lib/safe-store.js +777 -0
  137. package/dist/lib/signals/engine.d.ts +29 -2
  138. package/dist/lib/signals/engine.js +103 -4
  139. package/dist/lib/signals/reply.js +73 -18
  140. package/dist/lib/signals/steps/adapters.js +7 -2
  141. package/dist/lib/signals/steps/extract.d.ts +13 -0
  142. package/dist/lib/signals/steps/extract.js +84 -4
  143. package/dist/main.js +47 -4
  144. package/dist/schemas/hq-environment-profile.v1.schema.json +438 -0
  145. package/dist/types.d.ts +1 -1
  146. package/dist/utils/auth-expiry.d.ts +8 -0
  147. package/dist/utils/auth-expiry.js +53 -0
  148. package/dist/utils/callback-port-busy.d.ts +1 -1
  149. package/dist/utils/callback-port-busy.js +4 -4
  150. package/dist/utils/cli-telemetry.d.ts +21 -0
  151. package/dist/utils/cli-telemetry.js +34 -0
  152. package/dist/utils/command-usage.d.ts +275 -0
  153. package/dist/utils/command-usage.js +797 -0
  154. package/dist/utils/hook-trust.d.ts +7 -0
  155. package/dist/utils/hook-trust.js +34 -4
  156. package/dist/utils/host-registration.d.ts +179 -0
  157. package/dist/utils/host-registration.js +505 -0
  158. package/dist/utils/resident-package-preload.js +2 -0
  159. package/package.json +10 -8
  160. package/scripts/bench-core.mjs +1096 -0
  161. package/scripts/check-function-manifest.mjs +702 -0
@@ -22,11 +22,19 @@ export const FIRST_SYNC_TELEMETRY_DISCLOSURE_LINE = "HQ sends a usage event when
22
22
  export const CLI_INVITE_NUDGE_TELEMETRY_DISCLOSURE_LINE = "HQ sends a usage event when it shows the teammate invite prompt (your company UID and whether you saw, clicked, or dismissed the prompt; no invitee details, command names, file contents, or secrets). Set HQ_TELEMETRY=0 to turn this off.";
23
23
  export const CLI_FEATURE_USED_TELEMETRY_FLAG = "cli.feature-used-telemetry-v1";
24
24
  export const CLI_FEATURE_USED_TELEMETRY_DISCLOSURE_LINE = "HQ sends a feature-use event when you run a supported CLI feature (feature kind and outcome, plus your company UID when available; never command names, file contents, or secrets). The hq-flags key cli.feature-used-telemetry-v1 controls these events. Set HQ_TELEMETRY=0 to turn this off.";
25
+ /**
26
+ * What HQ stores on this computer and never sends: the local command count
27
+ * (utils/command-usage.ts). Printed once on stderr on the first interactive
28
+ * run that is not `--json`, signed in or not. It is separate from the notices
29
+ * above because nothing is sent, so `HQ_TELEMETRY=0` does not turn it off.
30
+ */
31
+ export const LOCAL_COMMAND_USAGE_DISCLOSURE_LINE = "HQ keeps a count of the commands you run in ~/.hq/command-usage on this computer (the command name and the date of each run, never arguments, file contents, or secrets). It is never sent anywhere, so HQ_TELEMETRY=0 does not turn it off. Run `hq doctor usage` to see it; delete that folder to clear it.";
25
32
  const TELEMETRY_DISABLED_VALUES = new Set(["0", "false", "off"]);
26
33
  const DISCLOSURE_MARKER = "cli-telemetry-disclosed";
27
34
  const FIRST_SYNC_DISCLOSURE_MARKER = "cli-telemetry-disclosed-first-sync-v1";
28
35
  const INVITE_NUDGE_DISCLOSURE_MARKER = "cli-telemetry-disclosed-invite-nudge-v1";
29
36
  const FEATURE_USED_DISCLOSURE_MARKER = "cli-telemetry-disclosed-feature-used-v1";
37
+ const LOCAL_COMMAND_USAGE_DISCLOSURE_MARKER = "cli-command-usage-disclosed-v1";
30
38
  const SESSION_STARTED_BUDGET_FILE = "cli-session-started-budget.json";
31
39
  const SESSION_STARTED_BUDGET_LOCK_STALE_MS = 10_000;
32
40
  let cliSessionStartedPromise;
@@ -237,6 +245,8 @@ export async function withCliFeatureUsed(kind, action, companyUid) {
237
245
  /**
238
246
  * `HQ_TELEMETRY=0` (also `false` and `off`, case-insensitive) disables every
239
247
  * CLI POST to `/v1/telemetry/events`. `HQ_TELEMETRY_TIMEOUT_MS` is unchanged.
248
+ * It does not turn off the local command count (utils/command-usage.ts): that
249
+ * count is a file on this computer and sends nothing.
240
250
  */
241
251
  export function isCliTelemetryDisabled(env = process.env) {
242
252
  const raw = env.HQ_TELEMETRY?.trim().toLowerCase();
@@ -376,6 +386,30 @@ function recordDisclosureShown(markerPath) {
376
386
  export function maybeDiscloseCliTelemetry(stderr = process.stderr, stdout = process.stdout, argv = process.argv) {
377
387
  return maybeDiscloseTelemetry(TELEMETRY_DISCLOSURE_LINE, telemetryDisclosureMarkerPath(), stderr, stdout, argv);
378
388
  }
389
+ export function localCommandUsageDisclosureMarkerPath() {
390
+ return path.join(hqConfigDir(), LOCAL_COMMAND_USAGE_DISCLOSURE_MARKER);
391
+ }
392
+ /**
393
+ * Print the local command count notice at most once per machine. It does not
394
+ * depend on sign-in or on `HQ_TELEMETRY`, because the count does not either.
395
+ * Nothing is printed while `~/.hq` does not exist: no count is kept then, and
396
+ * the marker could not be recorded.
397
+ */
398
+ export function maybeDiscloseLocalCommandUsage(stderr = process.stderr, stdout = process.stdout, argv = process.argv) {
399
+ const markerPath = localCommandUsageDisclosureMarkerPath();
400
+ if (hasShownDisclosure(markerPath))
401
+ return true;
402
+ if (!canPrintDisclosure(stdout, argv))
403
+ return false;
404
+ try {
405
+ if (!fs.existsSync(hqConfigDir()))
406
+ return false;
407
+ }
408
+ catch {
409
+ return false;
410
+ }
411
+ return maybeDiscloseTelemetry(LOCAL_COMMAND_USAGE_DISCLOSURE_LINE, markerPath, stderr, stdout, argv);
412
+ }
379
413
  function maybeDiscloseFirstSyncTelemetry() {
380
414
  return maybeDiscloseTelemetry(FIRST_SYNC_TELEMETRY_DISCLOSURE_LINE, firstSyncTelemetryDisclosureMarkerPath());
381
415
  }
@@ -0,0 +1,275 @@
1
+ /**
2
+ * Local command usage count, and the retiring-command gate, which ships
3
+ * switched off ({@link RETIRING_GATE_ENABLED}): no command is refused and no
4
+ * retiring notice is printed. The gate code is kept for when it is turned on.
5
+ *
6
+ * Every `hq` run appends one line to a file under `~/.hq/command-usage/`:
7
+ * the UTC date, a kind, a count, and the command path (`secrets env`,
8
+ * `doctor usage`). The command path is built only from command names the CLI
9
+ * itself declares, so an argument, a flag value, a company slug, a file path,
10
+ * the working directory, or an environment value can never be part of it.
11
+ *
12
+ * The file stays on this computer. Nothing here opens a socket, and the file
13
+ * sits outside every folder that sync, vault upload, telemetry, or `hq
14
+ * feedback` reads (see command-usage.test.ts for the checks). `HQ_TELEMETRY=0`
15
+ * therefore does not turn the count off.
16
+ *
17
+ * `src/index.ts` imports this module on every route, including the hook fast
18
+ * routes, so it imports Node builtins and the store helper only (which imports
19
+ * Node builtins only), and the per-run work is one small
20
+ * append: no read of the usage file, no directory listing. A write error is
21
+ * swallowed; counting must never fail or slow a command.
22
+ *
23
+ * Size: the file is compacted to one line per date, kind and command once it
24
+ * passes COMMAND_USAGE_COMPACT_AT_BYTES. Compaction drops dates older than the
25
+ * 30-day window, and then the oldest dates until the result fits
26
+ * COMMAND_USAGE_MAX_COMPACTED_BYTES. The file from before the last compaction
27
+ * is kept until the next one, so the folder holds about twice the compaction
28
+ * threshold at most (about 512 KiB).
29
+ *
30
+ * Every read and write of the usage folder goes through the shared store
31
+ * helper (`src/lib/safe-store.ts`): the folder is held open and checked by its
32
+ * descriptor, files are opened without following a link and without blocking,
33
+ * and only a regular single-link file of this user is written or read. A named
34
+ * pipe, a link (symbolic or hard), or a folder at the usage path means no count
35
+ * is kept; so does a usage folder that is a link, belongs to another user, or
36
+ * is writable by the group or others, and a folder swapped for another while
37
+ * a write runs. The command runs as it would otherwise.
38
+ *
39
+ * When the gate is switched on, it matches the whole command path. An entry
40
+ * for a command group (`core job`) does not gate the commands under it
41
+ * (`core job run`); each command to retire is listed by its own path. While it
42
+ * is off, the `refused` count stays 0 and `hq doctor usage` does not show it.
43
+ */
44
+ import { type OpenStoreDirOptions } from "../lib/safe-store.js";
45
+ /**
46
+ * The switch for the retiring-command gate. Off: no command is refused and no
47
+ * retiring notice is printed, whatever `src/data/command-states.json` marks.
48
+ *
49
+ * Owner decision (Corey, 2026-11-13): "let's not retire commands right now.
50
+ * just evolve towards new platform". Every command runs as it did in
51
+ * v5.345.215. The marking data and the local usage count stay, so the gate can
52
+ * be switched back on later by setting this to true.
53
+ */
54
+ export declare const RETIRING_GATE_ENABLED: boolean;
55
+ /**
56
+ * Global flag that, with the gate on, runs a command whose state is
57
+ * `retiring`. With the gate off it is still accepted and taken out of argv
58
+ * where hq reads it; it only marks the run of a marked command as a
59
+ * `still-use` run in the local count.
60
+ */
61
+ export declare const STILL_USE_FLAG = "--i-still-use-this";
62
+ /** Help text for the flag on the root program (main.ts and command-help.ts). */
63
+ export declare const STILL_USE_FLAG_DESCRIPTION: string;
64
+ /** `hq doctor usage` reports this many days, and compaction keeps the same. */
65
+ export declare const COMMAND_USAGE_WINDOW_DAYS = 30;
66
+ /** The usage file is compacted once an append takes it past this size. */
67
+ export declare const COMMAND_USAGE_COMPACT_AT_BYTES: number;
68
+ /** A compacted file is cut to this size by dropping its oldest dates. */
69
+ export declare const COMMAND_USAGE_MAX_COMPACTED_BYTES: number;
70
+ /**
71
+ * Appends stop at this size. It is reached only when compaction keeps failing
72
+ * (for example a lock that cannot be taken); normal use stays near the
73
+ * compaction threshold.
74
+ */
75
+ export declare const COMMAND_USAGE_HARD_MAX_BYTES: number;
76
+ /** Folder under `~/.hq`. Not `logs/`, `locks/` or `jobs/`: `hq feedback` reads those. */
77
+ export declare const COMMAND_USAGE_DIRNAME = "command-usage";
78
+ export declare const COMMAND_USAGE_FILENAME = "usage.tsv";
79
+ export type CommandUseKind = "run" | "still-use" | "refused";
80
+ export interface CommandStateEntry {
81
+ state: string;
82
+ replacedBy?: string;
83
+ }
84
+ /** `commands` of `src/data/command-states.json`: only commands that are not `live`. */
85
+ export type CommandStates = Readonly<Record<string, CommandStateEntry>>;
86
+ export interface CommandUsageOptions {
87
+ /** Usage folder. Defaults to {@link commandUsageDir}. */
88
+ dir?: string | null;
89
+ /** Clock, in epoch milliseconds. */
90
+ now?: number;
91
+ env?: NodeJS.ProcessEnv;
92
+ /** Test seam: passed to the store helper, which calls it between the steps of each operation. */
93
+ at?: OpenStoreDirOptions["at"];
94
+ }
95
+ /**
96
+ * Where the count is kept, or null when this run keeps none.
97
+ *
98
+ * A test run never writes to the real home: it counts only into the folder a
99
+ * test names with HQ_TEST_COMMAND_USAGE_DIR. That variable is ignored outside
100
+ * a test run, so it is not a way to move or switch off the count.
101
+ *
102
+ * A test run is `NODE_ENV=test` or `VITEST=true`. A person who has
103
+ * `NODE_ENV=test` set in their shell therefore keeps no count (the README says
104
+ * so). The retiring gate does not depend on it: see {@link loadCommandStates}.
105
+ */
106
+ export declare function commandUsageDir(env?: NodeJS.ProcessEnv): string | null;
107
+ /** Test seam: forget the cached state table and the once-per-process mark. */
108
+ export declare function _resetCommandUsageForTests(): void;
109
+ /**
110
+ * Read the command states that ship inside the CLI. The file lists only
111
+ * commands whose state is not `live`; a command absent from it is `live`.
112
+ * A missing or damaged file gates nothing: a broken table must not stop
113
+ * every command from running.
114
+ *
115
+ * HQ_TEST_COMMAND_STATES_FILE names another table for this repository's own
116
+ * tests. It is read only in a test run of a source checkout. An installed CLI
117
+ * never reads it, whatever the environment holds, so a person's environment
118
+ * cannot switch the gate off or point it at another table.
119
+ */
120
+ export declare function loadCommandStates(env?: NodeJS.ProcessEnv, sourceCheckout?: () => boolean): CommandStates;
121
+ /**
122
+ * True when the flag appears anywhere before a `--` terminator. `src/index.ts`
123
+ * uses this to send such a run to the full command graph, which knows the
124
+ * command names and decides whether the flag is hq's ({@link takeStillUseFlag}).
125
+ */
126
+ export declare function hasStillUseFlag(argv: readonly string[]): boolean;
127
+ /** The parts of a Commander command {@link takeStillUseFlag} reads. */
128
+ export interface CommandTreeNode {
129
+ name(): string;
130
+ aliases(): string[];
131
+ commands: readonly CommandTreeNode[];
132
+ }
133
+ /**
134
+ * Take the flag out of `argv` in place where hq reads it, and say whether it
135
+ * was there.
136
+ *
137
+ * hq reads the flag only before the command's own arguments begin: before the
138
+ * command name, between the names of a command path, or directly after the
139
+ * last name (`hq --i-still-use-this whoami`, `hq core --i-still-use-this job
140
+ * run`, `hq whoami --i-still-use-this`). The first operand or option of the
141
+ * command ends that span, and so does `--`. A flag after that point stays in
142
+ * `argv` and belongs to the command: `hq run tool --i-still-use-this` hands it
143
+ * to `tool`.
144
+ *
145
+ * `root` is the command graph, so a name is told from an operand by the
146
+ * commands the CLI declares. This runs before Commander parses `argv`, which
147
+ * therefore never sees a flag hq took, and neither does a command that reads
148
+ * its arguments straight from `process.argv`.
149
+ */
150
+ export declare function takeStillUseFlag(argv: string[], root: CommandTreeNode): boolean;
151
+ /** The parts of a Commander command this module reads. */
152
+ export interface CommandNode {
153
+ name(): string;
154
+ aliases(): string[];
155
+ /** Operands and unparsed arguments Commander left for this command. */
156
+ args: string[];
157
+ parent: CommandNode | null;
158
+ }
159
+ /**
160
+ * The command path of the command Commander is about to run.
161
+ *
162
+ * `canonical` joins the declared command names from the root down. `typed`
163
+ * is the same path with each name replaced by the alias the person typed,
164
+ * when they typed one.
165
+ *
166
+ * Nothing is read from argv. Commander dispatches a subcommand on the first
167
+ * operand its parent was left with (`parent.args[0]`), after the parent's
168
+ * own options and their values are taken out. That word is used only when it
169
+ * is a declared name or alias of the dispatched command, so a positional
170
+ * value or an option value cannot become part of the path.
171
+ */
172
+ export declare function commandPathOf(actionCommand: CommandNode): {
173
+ typed: string;
174
+ canonical: string;
175
+ };
176
+ /**
177
+ * Append one use of `commandPath`. Never throws. Creates the usage folder but
178
+ * never `~/.hq` itself: a computer with no HQ state keeps no count.
179
+ */
180
+ export declare function recordCommandUse(commandPath: string, kind: CommandUseKind, options?: CommandUsageOptions): void;
181
+ /**
182
+ * Whether `dir` is a usage folder this module works in (see
183
+ * {@link openUsageStore}). With `create`, a missing leaf folder is made first.
184
+ */
185
+ export declare function usageDirIsSafe(dir: string, create?: boolean): boolean;
186
+ /** The one message a refused command prints. */
187
+ export declare function retiringRefusalMessage(commandPath: string, entry: CommandStateEntry): string;
188
+ export interface CommandRun {
189
+ /** Command path as typed (aliases kept). This is what the count records. */
190
+ typed: string;
191
+ /** Command path by declared names, when it differs from `typed`. */
192
+ canonical?: string;
193
+ /** Whether the run carries {@link STILL_USE_FLAG}. */
194
+ stillUse: boolean;
195
+ }
196
+ /**
197
+ * Count one command run and apply the retiring gate.
198
+ *
199
+ * The gate is off ({@link RETIRING_GATE_ENABLED}): this then always returns
200
+ * null and only counts the run. A run of a command marked `retiring` that
201
+ * carries the flag is still counted as `still-use`; nothing is counted as
202
+ * `refused`.
203
+ *
204
+ * With the gate on, returns null when the command may run, or the refusal
205
+ * message when its state is `retiring` and the run does not carry the flag. A refused attempt
206
+ * is counted as `refused`, and a run that used the flag on a retiring command
207
+ * as `still-use`, both apart from ordinary runs. Other states are not gated.
208
+ *
209
+ * The table is matched on the whole command path, as typed and by declared
210
+ * names. An entry for a group does not gate the commands under it, and an
211
+ * entry for a command does not gate the group above it. Retiring a group
212
+ * means listing each of its commands, so a command is never refused without
213
+ * its own entry.
214
+ *
215
+ * One process counts one run: a fast route that hands the command on to the
216
+ * full command graph is not counted a second time there.
217
+ */
218
+ export declare function admitCommandRun(run: CommandRun, options?: CommandUsageOptions & {
219
+ states?: CommandStates;
220
+ /** Defaults to {@link RETIRING_GATE_ENABLED}. Tests of the dormant gate pass true. */
221
+ gateEnabled?: boolean;
222
+ }): string | null;
223
+ /** Take the compaction lock of `dir`. Returns the token, or null. */
224
+ export declare function acquireCompactLock(dir: string, now?: number): string | null;
225
+ /** Take over the lock of `dir` judged stale with content `judged`. Returns the token, or null. */
226
+ export declare function claimStaleCompactLock(dir: string, judged: string, now?: number): string | null;
227
+ /** Give the lock of `dir` back. Does nothing when another process has taken it over. */
228
+ export declare function releaseCompactLock(dir: string, token: string): void;
229
+ /**
230
+ * Fold the usage file into one line per date, kind and command.
231
+ *
232
+ * One process at a time, behind a lock that a later run takes over after a
233
+ * minute (see {@link acquireHeldLock}). The live file is renamed first, so
234
+ * other hq processes keep appending to a fresh file. The folded lines are
235
+ * then appended to that fresh file with a marker that names the renamed file
236
+ * and how many of its bytes were folded.
237
+ *
238
+ * The renamed file is kept until the next compaction. A process that opened
239
+ * it just before the rename can still write its line there; the next
240
+ * compaction (or `hq doctor usage`) reads what lies past the marked length,
241
+ * and only then is the file removed. A renamed file left by a crash is
242
+ * handled the same way: folded once, by its marker.
243
+ *
244
+ * Every rename, append and removal goes through the store helper, so each
245
+ * runs only while the folder's path still leads to the held folder, and the
246
+ * lock is checked again before the rename and before the append.
247
+ * Returns whether this call compacted.
248
+ */
249
+ export declare function compactCommandUsage(dir: string, now?: number): boolean;
250
+ export interface CommandUsageRow {
251
+ command: string;
252
+ /** Runs without {@link STILL_USE_FLAG}. */
253
+ runs: number;
254
+ /** Runs of a retiring command that carried the flag. */
255
+ stillUseRuns: number;
256
+ /** Attempts on a retiring command that were refused. */
257
+ refused: number;
258
+ }
259
+ export interface CommandUsageReport {
260
+ schema: 1;
261
+ windowDays: number;
262
+ /** First and last UTC date of the window, inclusive. */
263
+ from: string;
264
+ to: string;
265
+ /** The usage file, or null when this run keeps no count. */
266
+ file: string | null;
267
+ bytes: number;
268
+ leavesThisComputer: false;
269
+ commands: CommandUsageRow[];
270
+ }
271
+ /** Counts per command for the last {@link COMMAND_USAGE_WINDOW_DAYS} days. */
272
+ export declare function readCommandUsage(options?: CommandUsageOptions): CommandUsageReport;
273
+ /** Plain-text report for `hq doctor usage`. */
274
+ export declare function renderCommandUsageText(report: CommandUsageReport): string;
275
+ //# sourceMappingURL=command-usage.d.ts.map