@indigoai-us/hq-cli 5.345.250 → 5.345.252

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 (186) hide show
  1. package/CHANGELOG.md +214 -0
  2. package/assets/scaffold/core/scripts/hq-session.sh +9 -0
  3. package/contracts/host-canary-release.json +9 -3
  4. package/dist/command-catalog.generated.d.ts +316 -2
  5. package/dist/command-catalog.generated.js +389 -2
  6. package/dist/commands/bot.js +12 -3
  7. package/dist/commands/core-bucket-c-work-mesh-offer-native.js +1 -1
  8. package/dist/commands/core-hq-session-binding.d.ts +140 -0
  9. package/dist/commands/core-hq-session-binding.js +363 -0
  10. package/dist/commands/core-hq-session-native.d.ts +23 -0
  11. package/dist/commands/core-hq-session-native.js +59 -9
  12. package/dist/commands/core-stop-autosave.js +1 -1
  13. package/dist/commands/core.js +10 -0
  14. package/dist/commands/doctor.d.ts +5 -1
  15. package/dist/commands/doctor.js +42 -5
  16. package/dist/commands/files.js +1 -1
  17. package/dist/commands/install-global.js +4 -2
  18. package/dist/commands/lanes.d.ts +2 -0
  19. package/dist/commands/lanes.js +9 -4
  20. package/dist/commands/logout.js +4 -0
  21. package/dist/commands/ontology-graph.d.ts +11 -2
  22. package/dist/commands/ontology-graph.js +130 -4
  23. package/dist/commands/report.js +35 -2
  24. package/dist/commands/sources.js +26 -8
  25. package/dist/commands/storage-gate.js +1 -1
  26. package/dist/commands/vault-retention-flag.js +2 -1
  27. package/dist/commands/whoami.js +1 -1
  28. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +238 -221
  29. package/dist/hq-cloud-sync-runner/package.json +1 -1
  30. package/dist/index.js +3 -1
  31. package/dist/lib/agent-kit/inbox-poll-backoff-flag.js +1 -1
  32. package/dist/lib/agent-kit/mcp/tools.js +48 -0
  33. package/dist/lib/bot/fleet-bots-update-pass.js +1 -1
  34. package/dist/lib/bot/fleet-cron.d.ts +37 -0
  35. package/dist/lib/bot/fleet-cron.js +59 -12
  36. package/dist/lib/bot/fleet-local.d.ts +18 -0
  37. package/dist/lib/bot/fleet-local.js +51 -5
  38. package/dist/lib/bot/inbox-poll-backoff-flag.js +1 -1
  39. package/dist/lib/bot/signals-engine-flag.d.ts +1 -1
  40. package/dist/lib/bot/signals-engine-flag.js +1 -1
  41. package/dist/lib/cli-invite-nudge.js +1 -1
  42. package/dist/lib/client-version.d.ts +2 -0
  43. package/dist/lib/client-version.js +24 -0
  44. package/dist/lib/company-flag-gate.d.ts +30 -0
  45. package/dist/lib/company-flag-gate.js +104 -0
  46. package/dist/lib/core-utils/hook-timeout-debug-context-flag.js +1 -1
  47. package/dist/lib/daemon/flag.js +2 -1
  48. package/dist/lib/daemon/legacy-journal-gate.js +3 -1
  49. package/dist/lib/daemon/shared-flag-reads.js +1 -1
  50. package/dist/lib/doctor/checks/host-core.js +22 -4
  51. package/dist/lib/doctor/checks/jq.d.ts +27 -6
  52. package/dist/lib/doctor/checks/jq.js +46 -8
  53. package/dist/lib/doctor/client-health-reason-codes-flag.js +1 -1
  54. package/dist/lib/doctor/fix/refresh-sync-handoff.d.ts +1 -1
  55. package/dist/lib/doctor/fix/refresh-sync-handoff.js +1 -1
  56. package/dist/lib/flag-client-gate-headers.d.ts +38 -0
  57. package/dist/lib/flag-client-gate-headers.js +62 -0
  58. package/dist/lib/flag-client-headers.d.ts +15 -0
  59. package/dist/lib/flag-client-headers.js +25 -0
  60. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  61. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  62. package/dist/lib/flag-registry-worker.js +35 -0
  63. package/dist/lib/flag-registry.d.ts +1 -20
  64. package/dist/lib/flag-registry.js +5 -81
  65. package/dist/lib/hook-engine/adapter-core-pin.d.ts +29 -0
  66. package/dist/lib/hook-engine/adapter-core-pin.js +29 -0
  67. package/dist/lib/hook-engine/coverage.d.ts +68 -8
  68. package/dist/lib/hook-engine/coverage.js +167 -25
  69. package/dist/lib/hook-engine/native-stop-compatibility.json +9 -4
  70. package/dist/lib/hook-engine/reconcile.js +3 -2
  71. package/dist/lib/hot-channels/graph-context.d.ts +26 -1
  72. package/dist/lib/hot-channels/graph-context.js +76 -9
  73. package/dist/lib/hot-channels/prompts/signals-pass.md +20 -0
  74. package/dist/lib/hot-channels/run.d.ts +1 -0
  75. package/dist/lib/hot-channels/signal-changes.d.ts +228 -0
  76. package/dist/lib/hot-channels/signal-changes.js +683 -0
  77. package/dist/lib/hot-channels/signals-pass.d.ts +24 -0
  78. package/dist/lib/hot-channels/signals-pass.js +240 -15
  79. package/dist/lib/lanes/outpost-worktree-pruner-flag.d.ts +1 -1
  80. package/dist/lib/lanes/outpost-worktree-pruner-flag.js +1 -1
  81. package/dist/lib/lanes/registry-flag.js +2 -1
  82. package/dist/lib/lanes/spawn.js +11 -1
  83. package/dist/lib/mesh/live/binding-intent.d.ts +61 -0
  84. package/dist/lib/mesh/live/binding-intent.js +201 -0
  85. package/dist/lib/mesh/live/binding-receipt.d.ts +157 -0
  86. package/dist/lib/mesh/live/binding-receipt.js +365 -0
  87. package/dist/lib/mesh/live/company-flag-refresh.js +1 -1
  88. package/dist/lib/mesh/live/daemon/doctor-telemetry.d.ts +39 -0
  89. package/dist/lib/mesh/live/daemon/doctor-telemetry.js +58 -0
  90. package/dist/lib/mesh/live/daemon/install.js +2 -1
  91. package/dist/lib/mesh/live/daemon/presence.js +9 -0
  92. package/dist/lib/mesh/live/daemon/run.d.ts +3 -0
  93. package/dist/lib/mesh/live/daemon/run.js +33 -1
  94. package/dist/lib/ontology-graph/lineage/index.d.ts +401 -0
  95. package/dist/lib/ontology-graph/lineage/index.js +1027 -0
  96. package/dist/lib/ontology-graph/model/files.d.ts +4 -0
  97. package/dist/lib/ontology-graph/model/files.js +23 -0
  98. package/dist/lib/ontology-graph/model/index.d.ts +65 -1
  99. package/dist/lib/ontology-graph/model/index.js +154 -18
  100. package/dist/lib/ontology-graph/model/pass-tasks.d.ts +84 -1
  101. package/dist/lib/ontology-graph/model/pass-tasks.js +173 -4
  102. package/dist/lib/ontology-graph/model/pass.d.ts +11 -0
  103. package/dist/lib/ontology-graph/model/pass.js +17 -10
  104. package/dist/lib/ontology-graph/model/pending-items.d.ts +39 -0
  105. package/dist/lib/ontology-graph/model/pending-items.js +136 -0
  106. package/dist/lib/ontology-graph/model/step.d.ts +47 -2
  107. package/dist/lib/ontology-graph/model/step.js +202 -36
  108. package/dist/lib/ontology-graph/model/tasks.d.ts +28 -4
  109. package/dist/lib/ontology-graph/model/tasks.js +48 -15
  110. package/dist/lib/ontology-graph/pages/render.d.ts +1 -1
  111. package/dist/lib/ontology-graph/pages/render.js +4 -3
  112. package/dist/lib/ontology-graph/read/brief.d.ts +13 -3
  113. package/dist/lib/ontology-graph/read/brief.js +349 -67
  114. package/dist/lib/ontology-graph/read/index.d.ts +5 -1
  115. package/dist/lib/ontology-graph/read/index.js +174 -30
  116. package/dist/lib/ontology-graph/read/lineage.d.ts +101 -0
  117. package/dist/lib/ontology-graph/read/lineage.js +262 -0
  118. package/dist/lib/ontology-graph/read/reader-setting.d.ts +2 -0
  119. package/dist/lib/ontology-graph/read/reader-setting.js +4 -1
  120. package/dist/lib/ontology-graph/remodel/index.d.ts +174 -0
  121. package/dist/lib/ontology-graph/remodel/index.js +450 -0
  122. package/dist/lib/ontology-graph/replay/buffered-store.js +17 -0
  123. package/dist/lib/ontology-graph/replay/engine.d.ts +32 -1
  124. package/dist/lib/ontology-graph/replay/engine.js +213 -8
  125. package/dist/lib/ontology-graph/replay/extractors.d.ts +26 -0
  126. package/dist/lib/ontology-graph/replay/extractors.js +25 -1
  127. package/dist/lib/ontology-graph/replay/index.d.ts +2 -0
  128. package/dist/lib/ontology-graph/replay/index.js +120 -8
  129. package/dist/lib/ontology-graph/replay/signal-changes.d.ts +118 -0
  130. package/dist/lib/ontology-graph/replay/signal-changes.js +687 -0
  131. package/dist/lib/ontology-graph/schema/authority.d.ts +14 -5
  132. package/dist/lib/ontology-graph/schema/authority.js +13 -3
  133. package/dist/lib/ontology-graph/schema/decision-status.d.ts +18 -0
  134. package/dist/lib/ontology-graph/schema/decision-status.js +20 -0
  135. package/dist/lib/ontology-graph/schema/index.d.ts +2 -1
  136. package/dist/lib/ontology-graph/schema/index.js +2 -1
  137. package/dist/lib/ontology-graph/setup/index.d.ts +88 -0
  138. package/dist/lib/ontology-graph/setup/index.js +499 -0
  139. package/dist/lib/ontology-graph/types.d.ts +21 -0
  140. package/dist/lib/ontology-graph/types.js +5 -0
  141. package/dist/lib/search-index/index.d.ts +33 -1
  142. package/dist/lib/search-index/index.js +180 -25
  143. package/dist/lib/search-index/qmd-exit-diagnostics.d.ts +7 -0
  144. package/dist/lib/search-index/qmd-exit-diagnostics.js +25 -1
  145. package/dist/lib/signals/adapters-catalog.js +1 -1
  146. package/dist/lib/signals/failure-alert.js +4 -5
  147. package/dist/lib/signals/steps/adapters.js +3 -0
  148. package/dist/lib/sync-core/engine-holds.d.ts +1 -0
  149. package/dist/lib/sync-core/engine-holds.js +26 -0
  150. package/dist/lib/sync-core/engine-home.d.ts +3 -0
  151. package/dist/lib/sync-core/engine-home.js +41 -1
  152. package/dist/lib/sync-core/flag.js +2 -1
  153. package/dist/lib/sync-core/legacy-journal-export-child.js +5 -3
  154. package/dist/lib/sync-core/legacy-journal-export.d.ts +23 -4
  155. package/dist/lib/sync-core/legacy-journal-export.js +120 -55
  156. package/dist/lib/sync-core/reconcile.d.ts +2 -1
  157. package/dist/lib/sync-core/reconcile.js +30 -5
  158. package/dist/lib/sync-invalid-entity-warning.js +2 -1
  159. package/dist/lib/windows/install-followup.d.ts +41 -0
  160. package/dist/lib/windows/install-followup.js +87 -0
  161. package/dist/lib/windows/jq.d.ts +59 -0
  162. package/dist/lib/windows/jq.js +154 -3
  163. package/dist/lib/windows/user-path.d.ts +5 -0
  164. package/dist/lib/windows/user-path.js +1 -1
  165. package/dist/lib/work-context/auto-bind.d.ts +12 -0
  166. package/dist/lib/work-context/auto-bind.js +49 -3
  167. package/dist/lib/work-context/organize.d.ts +4 -2
  168. package/dist/lib/work-context/organize.js +18 -8
  169. package/dist/lib/work-context/reconcile.js +16 -1
  170. package/dist/main.js +12 -1
  171. package/dist/utils/client-health-contract.d.ts +30 -0
  172. package/dist/utils/client-health-contract.js +111 -0
  173. package/dist/utils/client-health.d.ts +5 -2
  174. package/dist/utils/client-health.js +74 -5
  175. package/dist/utils/exclusive-lock.d.ts +5 -1
  176. package/dist/utils/exclusive-lock.js +9 -2
  177. package/dist/utils/host-registration.d.ts +7 -0
  178. package/dist/utils/host-registration.js +10 -1
  179. package/dist/utils/pid.d.ts +31 -0
  180. package/dist/utils/pid.js +65 -0
  181. package/dist/utils/resident-package-preload.js +12 -4
  182. package/dist/utils/sentry-fingerprint.js +3 -0
  183. package/dist/utils/sync-person.d.ts +15 -0
  184. package/dist/utils/sync-person.js +74 -0
  185. package/package.json +8 -8
  186. package/scripts/install-hook-engine.mjs +5 -3
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Bind intents: the hook's confirmation that a session is binding itself.
3
+ *
4
+ * `hq core hq-session` cannot tell a session's own id from one a child
5
+ * process inherited from its parent, because both arrive as the same
6
+ * environment variable. The hook host can: a PreToolUse payload carries the
7
+ * real `session_id` and `tool_use_id`, set by the host and not by the shell.
8
+ * The native scope guard (crates/hq-hook/src/scope, the port of
9
+ * mandatory-scope-authorizer.sh) writes one intent file when it allows a
10
+ * Bash call that runs `hq-session.sh set company_slug`, `add company` or
11
+ * `remove company` for the payload's own session:
12
+ *
13
+ * <work mesh root>/bindings/intents/<session>.<tool_use_id>
14
+ * {"v":1,"session":"…","call":"…","action":"bind","company":"acme","at":"<ISO>"}
15
+ *
16
+ * The CLI consumes a matching intent once (atomic rename, then delete) and
17
+ * only then writes a receipt for an id the environment names. Nothing here
18
+ * writes intents: until the hook does, no intent exists and nothing changes.
19
+ *
20
+ * A plain shell export cannot produce an intent. A process running as the
21
+ * member can write the file, as it can write a receipt line; neither is
22
+ * tamper-evident. The guard here is against crediting the wrong session by
23
+ * accident, not against the member.
24
+ */
25
+ import * as fs from "node:fs";
26
+ import * as path from "node:path";
27
+ import { BINDINGS_DIRNAME } from "./binding-receipt.js";
28
+ import { workMeshRoot } from "./paths.js";
29
+ import * as os from "node:os";
30
+ export const INTENTS_DIRNAME = "intents";
31
+ /** An intent older than this does not confirm a change. */
32
+ export const BIND_INTENT_MAX_AGE_MS = 120_000;
33
+ /** An intent timed this far after the change does not confirm it (clock skew between two processes). */
34
+ const BIND_INTENT_FUTURE_SKEW_MS = 5_000;
35
+ /** Intents and claimed leftovers older than this are removed. */
36
+ export const BIND_INTENT_PRUNE_AGE_MS = 10 * 60_000;
37
+ const MAX_BYTES = 4096;
38
+ const SESSION_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,255}$/;
39
+ const CALL_RE = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
40
+ const SLUG_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
41
+ const ACTIONS = new Set(["bind", "unbind", "add", "remove"]);
42
+ export function bindIntentsDir(options = {}) {
43
+ const env = options.env ?? process.env;
44
+ const root = options.workMeshRoot ?? workMeshRoot(options.home ?? (env.HOME?.trim() || os.homedir()), env);
45
+ return path.join(root, BINDINGS_DIRNAME, INTENTS_DIRNAME);
46
+ }
47
+ /** The file name the hook writes for a session and call, or null for ids it may not use. */
48
+ export function bindIntentFileName(sessionId, call) {
49
+ if (!SESSION_RE.test(sessionId) || !CALL_RE.test(call))
50
+ return null;
51
+ return `${sessionId}.${call}`;
52
+ }
53
+ function parseIntent(raw) {
54
+ let value;
55
+ try {
56
+ value = JSON.parse(raw);
57
+ }
58
+ catch {
59
+ return null;
60
+ }
61
+ if (!value || typeof value !== "object" || Array.isArray(value))
62
+ return null;
63
+ const rec = value;
64
+ if (rec.v !== 1)
65
+ return null;
66
+ if (typeof rec.session !== "string" || !SESSION_RE.test(rec.session))
67
+ return null;
68
+ if (typeof rec.call !== "string" || !CALL_RE.test(rec.call))
69
+ return null;
70
+ if (typeof rec.action !== "string" || !ACTIONS.has(rec.action))
71
+ return null;
72
+ if (typeof rec.company !== "string" || (rec.company !== "" && !SLUG_RE.test(rec.company)))
73
+ return null;
74
+ if (typeof rec.at !== "string" || !Number.isFinite(Date.parse(rec.at)))
75
+ return null;
76
+ return {
77
+ v: 1, session: rec.session, call: rec.call, action: rec.action, company: rec.company, at: rec.at,
78
+ };
79
+ }
80
+ /**
81
+ * The folder or file belongs to this user and no one else can write it. On
82
+ * a platform without user ids (Windows) only the kind of entry is checked.
83
+ */
84
+ function privateEntry(stat) {
85
+ const uid = typeof process.getuid === "function" ? process.getuid() : undefined;
86
+ if (uid !== undefined && stat.uid !== uid)
87
+ return false;
88
+ if (process.platform !== "win32" && (stat.mode & 0o022) !== 0)
89
+ return false;
90
+ return true;
91
+ }
92
+ /** An intent file's content, when it is a plain private file under the size limit. */
93
+ function readIntent(file) {
94
+ try {
95
+ const stat = fs.lstatSync(file);
96
+ if (!stat.isFile() || stat.size > MAX_BYTES || !privateEntry(stat))
97
+ return null;
98
+ return parseIntent(fs.readFileSync(file, "utf8"));
99
+ }
100
+ catch {
101
+ return null;
102
+ }
103
+ }
104
+ function sameSlug(a, b) {
105
+ return a.toLowerCase() === b.toLowerCase();
106
+ }
107
+ /**
108
+ * Consume one intent that confirms this change: same session, action and
109
+ * company, timed at most {@link BIND_INTENT_MAX_AGE_MS} before `at` and not
110
+ * after it (beyond a small skew), a plain file whose name matches its
111
+ * content, owned by this user and writable by no one else, in a folder that
112
+ * is the same. A candidate is picked by reading it, claimed by an atomic
113
+ * rename (so two commands cannot both use it), and the claimed file is read
114
+ * and checked again: what counts is what was claimed. The claimed file is
115
+ * deleted either way. Returns the intent, or null.
116
+ */
117
+ export function consumeBindIntent(change, options = {}) {
118
+ if (!SESSION_RE.test(change.sessionId))
119
+ return null;
120
+ const moment = change.at.getTime();
121
+ if (!Number.isFinite(moment))
122
+ return null;
123
+ const dir = bindIntentsDir(options);
124
+ let names;
125
+ try {
126
+ const stat = fs.lstatSync(dir);
127
+ if (!stat.isDirectory() || !privateEntry(stat))
128
+ return null;
129
+ names = fs.readdirSync(dir);
130
+ }
131
+ catch {
132
+ return null;
133
+ }
134
+ const matches = (intent, call) => {
135
+ if (!intent || intent.session !== change.sessionId || intent.call !== call)
136
+ return false;
137
+ if (intent.action !== change.action)
138
+ return false;
139
+ if (change.action === "unbind"
140
+ ? intent.company !== "" && intent.company.toLowerCase() !== "personal"
141
+ : !sameSlug(intent.company, change.company))
142
+ return false;
143
+ const at = Date.parse(intent.at);
144
+ return at >= moment - BIND_INTENT_MAX_AGE_MS && at <= moment + BIND_INTENT_FUTURE_SKEW_MS;
145
+ };
146
+ const prefix = `${change.sessionId}.`;
147
+ for (const name of names.sort()) {
148
+ if (!name.startsWith(prefix))
149
+ continue;
150
+ const call = name.slice(prefix.length);
151
+ if (!CALL_RE.test(call))
152
+ continue;
153
+ const file = path.join(dir, name);
154
+ // Pick a candidate without taking it, so another change's intent is left alone.
155
+ if (!matches(readIntent(file), call))
156
+ continue;
157
+ // Claim it: only one rename of the same path can succeed.
158
+ const claimed = `${file}.used-${process.pid}`;
159
+ try {
160
+ fs.renameSync(file, claimed);
161
+ }
162
+ catch {
163
+ continue;
164
+ }
165
+ // Decide on the bytes that were claimed, not the ones read before.
166
+ const intent = readIntent(claimed);
167
+ try {
168
+ fs.rmSync(claimed, { force: true });
169
+ }
170
+ catch {
171
+ // A leftover claimed file is pruned later and never matches again.
172
+ }
173
+ if (matches(intent, call))
174
+ return intent;
175
+ }
176
+ return null;
177
+ }
178
+ /** Remove intents and claimed leftovers older than {@link BIND_INTENT_PRUNE_AGE_MS}. Never throws. */
179
+ export function pruneBindIntents(options = {}) {
180
+ const now = (options.now?.() ?? new Date()).getTime();
181
+ const dir = bindIntentsDir(options);
182
+ try {
183
+ if (!fs.lstatSync(dir).isDirectory())
184
+ return;
185
+ for (const name of fs.readdirSync(dir)) {
186
+ const file = path.join(dir, name);
187
+ try {
188
+ const stat = fs.lstatSync(file);
189
+ if (now - stat.mtimeMs > BIND_INTENT_PRUNE_AGE_MS)
190
+ fs.rmSync(file, { force: true });
191
+ }
192
+ catch {
193
+ // Gone already.
194
+ }
195
+ }
196
+ }
197
+ catch {
198
+ // No intents.
199
+ }
200
+ }
201
+ //# sourceMappingURL=binding-intent.js.map
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Binding receipts: a dated record, written by `hq`, of each time a session's
3
+ * company lock set was changed with `hq-session set company_slug`,
4
+ * `add company` or `remove company`.
5
+ *
6
+ * A session's meta.yaml holds its current company only, with no time and a
7
+ * `company_source` line anyone can write. The receipt adds what meta cannot
8
+ * say: when the change happened, that it went through `hq` and not a hook,
9
+ * and the source of the change itself. Bound-session attribution (plan:
10
+ * companies/indigo/projects/telemetry-required-for-company-work) will count a
11
+ * bind as company work only when a receipt covers the moment of the work and
12
+ * its source is on {@link CHOSEN_SOURCES}. Nothing reads the receipt to decide
13
+ * reporting yet; this module only writes and reads it.
14
+ *
15
+ * One append-only file per session, `<work mesh root>/bindings/<sid>.jsonl`.
16
+ * Each line is the session's lock set after one change:
17
+ *
18
+ * {"v":2,"at":"<ISO time>","action":"bind","companies":["acme"],
19
+ * "source":"explicit","root":"<16 hex>","writer":"hq-cli"}
20
+ *
21
+ * Version 2 made `root` required. A version 1 line (written by unreleased
22
+ * builds before `root` existed) reads like any other unusable line: the whole
23
+ * file is no receipt.
24
+ *
25
+ * `root` names the HQ tree whose meta.yaml the change was read from (the
26
+ * first 16 hex digits of the sha256 of its real path). The file is per user,
27
+ * not per tree, so a reader matches `root` against the tree it judges: a bind
28
+ * made in a second HQ is never credited to the first. A reader that names no
29
+ * tree matches no line. `actor`, when present, is the caller's own session
30
+ * when the change named another session with `--session-id` (a parent
31
+ * binding a child, for example); it does not change whether the line counts.
32
+ *
33
+ * A file that is not a plain file, is over the size limit, has a line that
34
+ * does not parse, or has times that go backwards is read as no receipt at
35
+ * all. The file is not tamper-evident: a well-formed line written by any
36
+ * process running as the member reads like one `hq` wrote.
37
+ */
38
+ export declare const BINDINGS_DIRNAME = "bindings";
39
+ /** The receipt line schema. 2: `root` is required. */
40
+ export declare const BINDING_RECEIPT_VERSION = 2;
41
+ /** How many parents a `parent` bind is followed up. */
42
+ export declare const BINDING_PARENT_WALK_MAX = 8;
43
+ /**
44
+ * `source` is reserved for a later writer that records a source change on its
45
+ * own (the native spawn handoff); `hq core hq-session` never writes it, and
46
+ * `set company_source` writes no receipt.
47
+ */
48
+ export type BindingAction = "bind" | "unbind" | "add" | "remove" | "source";
49
+ /**
50
+ * The allowlist: sources a person, an agent or a dispatching parent chose.
51
+ * Everything else is a default or a guess and never counts:
52
+ * `device_default`, `manifest_single_company`, `session`, `prompt_mention`,
53
+ * `scheduled_task`, a missing source, and any word not on this list.
54
+ * `parent` counts only through {@link bindingSourceCounts}.
55
+ */
56
+ export declare const CHOSEN_SOURCES: ReadonlySet<string>;
57
+ export declare const PARENT_SOURCE = "parent";
58
+ export interface BindingLine {
59
+ v: typeof BINDING_RECEIPT_VERSION;
60
+ at: string;
61
+ action: BindingAction;
62
+ /** The session's lock set after this change. Empty: not bound. */
63
+ companies: string[];
64
+ source: string;
65
+ /** The parent session a `parent` bind was inherited from. */
66
+ parent?: string;
67
+ /** The HQ tree the change was made in: {@link treeKeyOf}. */
68
+ root: string;
69
+ /** The caller's own session, when the change named another one. */
70
+ actor?: string;
71
+ /**
72
+ * `hook`: the session bound itself and the hook host confirmed the real
73
+ * session id for the tool call that ran the change (binding-intent.ts).
74
+ */
75
+ confirmed?: "hook";
76
+ /** The confirming tool call (`tool_use_id`), with `confirmed`. */
77
+ call?: string;
78
+ writer: "hq-cli";
79
+ }
80
+ export interface BindingPaths {
81
+ env?: NodeJS.ProcessEnv;
82
+ home?: string;
83
+ /** Overrides the Work Mesh root (tests). */
84
+ workMeshRoot?: string;
85
+ now?: () => Date;
86
+ /**
87
+ * The HQ tree a reader judges. Lines from another tree, and every line when
88
+ * this is not given, are not part of the binding.
89
+ */
90
+ hqRoot?: string;
91
+ }
92
+ /** The tree key a receipt line carries: sha256 of the tree's real path, first 16 hex digits. */
93
+ export declare function treeKeyOf(hqRoot: string): string;
94
+ export declare function bindingReceiptPath(sessionId: string, options?: BindingPaths): string | null;
95
+ /**
96
+ * Every line of a session's receipt, oldest first. Null when there is no
97
+ * usable receipt: no file, a link or a folder at its path, a file over the
98
+ * size limit, a line that does not parse, or times that go backwards.
99
+ */
100
+ export declare function readBindingReceipt(sessionId: string, options?: BindingPaths): BindingLine[] | null;
101
+ /** Append one line. Never throws: a receipt that cannot be written is no receipt. */
102
+ export declare function appendBindingReceipt(sessionId: string, entry: {
103
+ action: BindingAction;
104
+ companies: readonly string[];
105
+ source: string;
106
+ parent?: string;
107
+ hqRoot?: string;
108
+ actor?: string;
109
+ /** The tool call the hook confirmed, for a session binding itself. */
110
+ confirmedCall?: string;
111
+ }, options?: BindingPaths): BindingLine | null;
112
+ /**
113
+ * The session's lock set and source at `at` in the tree `options.hqRoot`
114
+ * names: the last change on or before it.
115
+ */
116
+ export declare function bindingAt(sessionId: string, at: Date, options?: BindingPaths): BindingLine | null;
117
+ /**
118
+ * Does the session's bind to `company` at `at` come from a choice? True for
119
+ * the sources on {@link CHOSEN_SOURCES}. A `parent` bind counts only when the
120
+ * parent's own receipt, at that moment, binds the same company and counts by
121
+ * the same rule, at most {@link BINDING_PARENT_WALK_MAX} parents up.
122
+ */
123
+ export declare function bindingSourceCounts(sessionId: string, company: string, at: Date, options?: BindingPaths): boolean;
124
+ /**
125
+ * Since when has the session held `company` without a break, as of `at`?
126
+ * The time of the first line of the unbroken run of lines, ending at the one
127
+ * in force at `at`, whose lock set includes the company. Null when the
128
+ * session does not hold it at `at`.
129
+ */
130
+ export declare function bindingBoundSince(sessionId: string, company: string, at: Date, options?: BindingPaths): Date | null;
131
+ /** An unattended run: the job runner and the Outpost export this before they start anything. */
132
+ export declare function unattendedRun(env?: NodeJS.ProcessEnv): boolean;
133
+ /**
134
+ * What the member is told when a session is bound to a company that requires
135
+ * reporting. It names the session by its first 12 characters, and says whether it is the caller's own
136
+ * (`own`), another session the caller bound (`other`), or unknown because the
137
+ * caller's environment names no session (`unknown`).
138
+ */
139
+ export declare function sessionReportingRequiredNotice(company: string, sessionId: string, relation: "own" | "unknown" | "other"): string;
140
+ /** Forget every receipt: the person signed out. */
141
+ export declare function clearBindingReceipts(options?: BindingPaths): void;
142
+ export interface SessionMeta {
143
+ /** The primary company, as written. */
144
+ companySlug: string;
145
+ /** The lock set: the primary company and every added one. Never `personal`. */
146
+ companies: string[];
147
+ companySource: string;
148
+ foreignCwd: string;
149
+ }
150
+ /**
151
+ * The company lines of `<HQ root>/workspace/sessions/<sid>/meta.yaml`, read
152
+ * line by line as the session scripts write them. Null when the file is
153
+ * missing, is not a plain file, cannot be read, or names a company that is
154
+ * not a plain slug.
155
+ */
156
+ export declare function readSessionMeta(hqRoot: string | undefined, sessionId: string): SessionMeta | null;
157
+ //# sourceMappingURL=binding-receipt.d.ts.map