@telora/daemon 0.21.134 → 0.21.146

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 (276) hide show
  1. package/build-info.json +2 -2
  2. package/dist/audit/audit-hooks.d.ts +15 -6
  3. package/dist/audit/audit-hooks.d.ts.map +1 -1
  4. package/dist/audit/audit-hooks.js +56 -28
  5. package/dist/audit/audit-hooks.js.map +1 -1
  6. package/dist/ci/ci-escalation.js +1 -1
  7. package/dist/ci/ci-escalation.js.map +1 -1
  8. package/dist/ci/ci-sensor-loop.d.ts +24 -0
  9. package/dist/ci/ci-sensor-loop.d.ts.map +1 -1
  10. package/dist/ci/ci-sensor-loop.js +35 -9
  11. package/dist/ci/ci-sensor-loop.js.map +1 -1
  12. package/dist/cli/connect/config-write.d.ts +87 -0
  13. package/dist/cli/connect/config-write.d.ts.map +1 -0
  14. package/dist/cli/connect/config-write.js +255 -0
  15. package/dist/cli/connect/config-write.js.map +1 -0
  16. package/dist/cli/connect/registration.d.ts +76 -0
  17. package/dist/cli/connect/registration.d.ts.map +1 -0
  18. package/dist/cli/connect/registration.js +207 -0
  19. package/dist/cli/connect/registration.js.map +1 -0
  20. package/dist/cli/connect.d.ts +3 -141
  21. package/dist/cli/connect.d.ts.map +1 -1
  22. package/dist/cli/connect.js +9 -441
  23. package/dist/cli/connect.js.map +1 -1
  24. package/dist/completion/coverage-stabilized.d.ts +1 -1
  25. package/dist/completion/coverage-stabilized.d.ts.map +1 -1
  26. package/dist/completion/coverage-stabilized.js +1 -1
  27. package/dist/completion/coverage-stabilized.js.map +1 -1
  28. package/dist/completion/escalation-provenance.d.ts +2 -1
  29. package/dist/completion/escalation-provenance.d.ts.map +1 -1
  30. package/dist/completion/escalation-provenance.js +2 -1
  31. package/dist/completion/escalation-provenance.js.map +1 -1
  32. package/dist/completion/escalations.js +1 -1
  33. package/dist/completion/escalations.js.map +1 -1
  34. package/dist/completion/event-escalations.d.ts +1 -1
  35. package/dist/completion/event-escalations.d.ts.map +1 -1
  36. package/dist/completion/event-escalations.js +1 -1
  37. package/dist/completion/event-escalations.js.map +1 -1
  38. package/dist/completion/event.d.ts +1 -1
  39. package/dist/completion/event.d.ts.map +1 -1
  40. package/dist/completion/event.js +2 -2
  41. package/dist/completion/event.js.map +1 -1
  42. package/dist/completion/machine-remediable-demotion.d.ts +1 -1
  43. package/dist/completion/machine-remediable-demotion.d.ts.map +1 -1
  44. package/dist/completion/machine-remediable-demotion.js +2 -1
  45. package/dist/completion/machine-remediable-demotion.js.map +1 -1
  46. package/dist/completion/read-only-pristine.d.ts +1 -1
  47. package/dist/completion/read-only-pristine.d.ts.map +1 -1
  48. package/dist/completion/read-only-pristine.js +1 -1
  49. package/dist/completion/read-only-pristine.js.map +1 -1
  50. package/dist/completion/review-exit-escalations.d.ts +1 -1
  51. package/dist/completion/review-exit-escalations.d.ts.map +1 -1
  52. package/dist/completion/review-exit-phase.d.ts +5 -2
  53. package/dist/completion/review-exit-phase.d.ts.map +1 -1
  54. package/dist/completion/review-exit-phase.js +5 -2
  55. package/dist/completion/review-exit-phase.js.map +1 -1
  56. package/dist/completion/settle-injection-sweep.d.ts +9 -7
  57. package/dist/completion/settle-injection-sweep.d.ts.map +1 -1
  58. package/dist/completion/settle-injection-sweep.js +17 -15
  59. package/dist/completion/settle-injection-sweep.js.map +1 -1
  60. package/dist/completion/state-cascade.js +2 -2
  61. package/dist/completion/state-cascade.js.map +1 -1
  62. package/dist/completion/status-advance-phase.d.ts.map +1 -1
  63. package/dist/completion/status-advance-phase.js +2 -1
  64. package/dist/completion/status-advance-phase.js.map +1 -1
  65. package/dist/completion/team-lifecycle.d.ts.map +1 -1
  66. package/dist/completion/team-lifecycle.js +2 -1
  67. package/dist/completion/team-lifecycle.js.map +1 -1
  68. package/dist/delivery/delivery-advance-block.d.ts +1 -1
  69. package/dist/delivery/delivery-advance-block.d.ts.map +1 -1
  70. package/dist/delivery/delivery-advance-block.js +1 -1
  71. package/dist/delivery/delivery-advance-block.js.map +1 -1
  72. package/dist/delivery/delivery-lifecycle.js +1 -1
  73. package/dist/delivery/delivery-lifecycle.js.map +1 -1
  74. package/dist/delivery/delivery-merge-ops.js +1 -1
  75. package/dist/delivery/delivery-merge-ops.js.map +1 -1
  76. package/dist/delivery/delivery-reconciler-shadow.d.ts +1 -1
  77. package/dist/delivery/delivery-reconciler-shadow.d.ts.map +1 -1
  78. package/dist/delivery/delivery-reconciler-shadow.js +1 -1
  79. package/dist/delivery/delivery-reconciler-shadow.js.map +1 -1
  80. package/dist/delivery/operator-hold.d.ts +1 -1
  81. package/dist/delivery/operator-hold.d.ts.map +1 -1
  82. package/dist/delivery/paused-revival.d.ts.map +1 -1
  83. package/dist/delivery/paused-revival.js +2 -1
  84. package/dist/delivery/paused-revival.js.map +1 -1
  85. package/dist/directive/close-loop-dispatcher.d.ts +35 -12
  86. package/dist/directive/close-loop-dispatcher.d.ts.map +1 -1
  87. package/dist/directive/close-loop-dispatcher.js +31 -11
  88. package/dist/directive/close-loop-dispatcher.js.map +1 -1
  89. package/dist/directive/directive-dispatch.d.ts +1 -1
  90. package/dist/directive/directive-dispatch.d.ts.map +1 -1
  91. package/dist/directive/directive-dispatch.js +1 -1
  92. package/dist/directive/directive-dispatch.js.map +1 -1
  93. package/dist/directive/directive-executor.js +1 -1
  94. package/dist/directive/directive-executor.js.map +1 -1
  95. package/dist/drift/staleness-sensor.js +1 -1
  96. package/dist/drift/staleness-sensor.js.map +1 -1
  97. package/dist/focus/focus-engine.js +3 -2
  98. package/dist/focus/focus-engine.js.map +1 -1
  99. package/dist/focus/focus-lifecycle.d.ts.map +1 -1
  100. package/dist/focus/focus-lifecycle.js +2 -1
  101. package/dist/focus/focus-lifecycle.js.map +1 -1
  102. package/dist/focus/focus-respawn-guard.d.ts +1 -1
  103. package/dist/focus/focus-respawn-guard.d.ts.map +1 -1
  104. package/dist/focus/focus-respawn-guard.js +1 -1
  105. package/dist/focus/focus-respawn-guard.js.map +1 -1
  106. package/dist/focus/listener-auto-advance.d.ts +4 -45
  107. package/dist/focus/listener-auto-advance.d.ts.map +1 -1
  108. package/dist/focus/listener-auto-advance.js +5 -238
  109. package/dist/focus/listener-auto-advance.js.map +1 -1
  110. package/dist/focus/listener-spawn.d.ts +62 -0
  111. package/dist/focus/listener-spawn.d.ts.map +1 -0
  112. package/dist/focus/listener-spawn.js +418 -0
  113. package/dist/focus/listener-spawn.js.map +1 -0
  114. package/dist/focus/listener-state.d.ts +57 -0
  115. package/dist/focus/listener-state.d.ts.map +1 -0
  116. package/dist/focus/listener-state.js +63 -0
  117. package/dist/focus/listener-state.js.map +1 -0
  118. package/dist/focus/listener.d.ts +0 -58
  119. package/dist/focus/listener.d.ts.map +1 -1
  120. package/dist/focus/listener.js +25 -453
  121. package/dist/focus/listener.js.map +1 -1
  122. package/dist/focus/verify-open-issues.d.ts +62 -0
  123. package/dist/focus/verify-open-issues.d.ts.map +1 -0
  124. package/dist/focus/verify-open-issues.js +265 -0
  125. package/dist/focus/verify-open-issues.js.map +1 -0
  126. package/dist/focus-stage-lifecycle/index.d.ts +1 -1
  127. package/dist/focus-stage-lifecycle/index.d.ts.map +1 -1
  128. package/dist/focus-stage-lifecycle/index.js +1 -1
  129. package/dist/focus-stage-lifecycle/index.js.map +1 -1
  130. package/dist/focus-stage-lifecycle/wedge-watchdog.d.ts +1 -1
  131. package/dist/focus-stage-lifecycle/wedge-watchdog.d.ts.map +1 -1
  132. package/dist/focus-stage-lifecycle/wedge-watchdog.js +1 -1
  133. package/dist/focus-stage-lifecycle/wedge-watchdog.js.map +1 -1
  134. package/dist/git/index.d.ts +2 -0
  135. package/dist/git/index.d.ts.map +1 -1
  136. package/dist/git/index.js +2 -0
  137. package/dist/git/index.js.map +1 -1
  138. package/dist/git/merge-strategies.d.ts +80 -0
  139. package/dist/git/merge-strategies.d.ts.map +1 -0
  140. package/dist/git/merge-strategies.js +218 -0
  141. package/dist/git/merge-strategies.js.map +1 -0
  142. package/dist/git/merge-to-main.d.ts +76 -0
  143. package/dist/git/merge-to-main.d.ts.map +1 -0
  144. package/dist/git/merge-to-main.js +256 -0
  145. package/dist/git/merge-to-main.js.map +1 -0
  146. package/dist/git/merge.d.ts +27 -81
  147. package/dist/git/merge.d.ts.map +1 -1
  148. package/dist/git/merge.js +4 -448
  149. package/dist/git/merge.js.map +1 -1
  150. package/dist/git/state-detector.js +1 -1
  151. package/dist/git/state-detector.js.map +1 -1
  152. package/dist/loops/engine.js +1 -1
  153. package/dist/loops/engine.js.map +1 -1
  154. package/dist/merge/focus-merge.d.ts +1 -1
  155. package/dist/merge/focus-merge.d.ts.map +1 -1
  156. package/dist/merge/focus-merge.js +1 -1
  157. package/dist/merge/focus-merge.js.map +1 -1
  158. package/dist/merge/merge-back-loop.d.ts +1 -1
  159. package/dist/merge/merge-back-loop.d.ts.map +1 -1
  160. package/dist/merge/merge-back-loop.js +2 -2
  161. package/dist/merge/merge-back-loop.js.map +1 -1
  162. package/dist/merge/merge-detector.js +1 -1
  163. package/dist/merge/merge-detector.js.map +1 -1
  164. package/dist/nexus/return.js +1 -1
  165. package/dist/nexus/return.js.map +1 -1
  166. package/dist/prd/controller-shared.d.ts +223 -0
  167. package/dist/prd/controller-shared.d.ts.map +1 -0
  168. package/dist/prd/controller-shared.js +77 -0
  169. package/dist/prd/controller-shared.js.map +1 -0
  170. package/dist/prd/controller.d.ts +5 -256
  171. package/dist/prd/controller.d.ts.map +1 -1
  172. package/dist/prd/controller.js +9 -166
  173. package/dist/prd/controller.js.map +1 -1
  174. package/dist/prd/done-sweep.d.ts +55 -0
  175. package/dist/prd/done-sweep.d.ts.map +1 -0
  176. package/dist/prd/done-sweep.js +112 -0
  177. package/dist/prd/done-sweep.js.map +1 -0
  178. package/dist/prompt-sections/execution-sections.d.ts +1 -1
  179. package/dist/prompt-sections/execution-sections.d.ts.map +1 -1
  180. package/dist/prompt-sections/execution-sections.js +12 -2
  181. package/dist/prompt-sections/execution-sections.js.map +1 -1
  182. package/dist/prompt-sections/shared.d.ts +1 -1
  183. package/dist/prompt-sections/shared.d.ts.map +1 -1
  184. package/dist/queries/agent-resolvable-promotion.d.ts +1 -1
  185. package/dist/queries/agent-resolvable-promotion.d.ts.map +1 -1
  186. package/dist/queries/agent-resolvable-promotion.js +2 -1
  187. package/dist/queries/agent-resolvable-promotion.js.map +1 -1
  188. package/dist/queries/deliveries.d.ts +0 -195
  189. package/dist/queries/deliveries.d.ts.map +1 -1
  190. package/dist/queries/deliveries.js +1 -83
  191. package/dist/queries/deliveries.js.map +1 -1
  192. package/dist/queries/escalation-consumption.d.ts +120 -0
  193. package/dist/queries/escalation-consumption.d.ts.map +1 -0
  194. package/dist/queries/escalation-consumption.js +143 -0
  195. package/dist/queries/escalation-consumption.js.map +1 -0
  196. package/dist/queries/escalation-dispositions.d.ts +19 -0
  197. package/dist/queries/escalation-dispositions.d.ts.map +1 -0
  198. package/dist/queries/escalation-dispositions.js +18 -0
  199. package/dist/queries/escalation-dispositions.js.map +1 -0
  200. package/dist/queries/escalation-suppression.d.ts +1 -1
  201. package/dist/queries/escalation-suppression.d.ts.map +1 -1
  202. package/dist/queries/escalation-suppression.js +1 -1
  203. package/dist/queries/escalation-suppression.js.map +1 -1
  204. package/dist/queries/escalations.d.ts +343 -0
  205. package/dist/queries/escalations.d.ts.map +1 -0
  206. package/dist/queries/escalations.js +493 -0
  207. package/dist/queries/escalations.js.map +1 -0
  208. package/dist/queries/focus-discovery.d.ts +204 -0
  209. package/dist/queries/focus-discovery.d.ts.map +1 -0
  210. package/dist/queries/focus-discovery.js +92 -0
  211. package/dist/queries/focus-discovery.js.map +1 -0
  212. package/dist/queries/index.d.ts +4 -2
  213. package/dist/queries/index.d.ts.map +1 -1
  214. package/dist/queries/index.js +4 -2
  215. package/dist/queries/index.js.map +1 -1
  216. package/dist/queries/issues.d.ts +8 -436
  217. package/dist/queries/issues.d.ts.map +1 -1
  218. package/dist/queries/issues.js +7 -615
  219. package/dist/queries/issues.js.map +1 -1
  220. package/dist/resolvers/agent-escalations.d.ts +20 -0
  221. package/dist/resolvers/agent-escalations.d.ts.map +1 -1
  222. package/dist/resolvers/agent-escalations.js +40 -10
  223. package/dist/resolvers/agent-escalations.js.map +1 -1
  224. package/dist/resolvers/index.d.ts +2 -2
  225. package/dist/resolvers/index.d.ts.map +1 -1
  226. package/dist/resolvers/index.js +1 -1
  227. package/dist/resolvers/index.js.map +1 -1
  228. package/dist/resolvers/shared/git-diff.d.ts +99 -18
  229. package/dist/resolvers/shared/git-diff.d.ts.map +1 -1
  230. package/dist/resolvers/shared/git-diff.js +98 -27
  231. package/dist/resolvers/shared/git-diff.js.map +1 -1
  232. package/dist/shell/control-state.d.ts +1 -1
  233. package/dist/shell/control-state.d.ts.map +1 -1
  234. package/dist/shell/control-state.js +1 -1
  235. package/dist/shell/control-state.js.map +1 -1
  236. package/dist/shell/crash-recovery.d.ts +1 -1
  237. package/dist/shell/crash-recovery.d.ts.map +1 -1
  238. package/dist/shell/crash-recovery.js +2 -2
  239. package/dist/shell/crash-recovery.js.map +1 -1
  240. package/dist/shell/install-probe-tick.d.ts +1 -1
  241. package/dist/shell/install-probe-tick.d.ts.map +1 -1
  242. package/dist/shell/install-probe-tick.js +1 -1
  243. package/dist/shell/install-probe-tick.js.map +1 -1
  244. package/dist/shell/unified-shell.js +1 -1
  245. package/dist/shell/unified-shell.js.map +1 -1
  246. package/dist/spawn/model-routing.d.ts +1 -1
  247. package/dist/spawn/model-routing.d.ts.map +1 -1
  248. package/dist/spawn/model-routing.js +1 -1
  249. package/dist/spawn/model-routing.js.map +1 -1
  250. package/dist/spawn/prompt-assembly.d.ts +1 -1
  251. package/dist/spawn/prompt-assembly.d.ts.map +1 -1
  252. package/dist/spawn/prompt-assembly.js +1 -1
  253. package/dist/spawn/prompt-assembly.js.map +1 -1
  254. package/dist/spawn/spawn-decision.js +1 -1
  255. package/dist/spawn/spawn-decision.js.map +1 -1
  256. package/dist/spawn/worktree-session.d.ts +1 -1
  257. package/dist/spawn/worktree-session.d.ts.map +1 -1
  258. package/dist/spawn/worktree-session.js +1 -1
  259. package/dist/spawn/worktree-session.js.map +1 -1
  260. package/dist/templates/claude-md.d.ts +1 -1
  261. package/dist/templates/claude-md.d.ts.map +1 -1
  262. package/dist/templates/claude-md.js +12 -0
  263. package/dist/templates/claude-md.js.map +1 -1
  264. package/dist/verify/verification-default-on.d.ts +1 -1
  265. package/dist/verify/verification-default-on.d.ts.map +1 -1
  266. package/dist/verify/verification-deps.d.ts +1 -1
  267. package/dist/verify/verification-deps.d.ts.map +1 -1
  268. package/dist/verify/verification-engine.d.ts.map +1 -1
  269. package/dist/verify/verification-engine.js +20 -12
  270. package/dist/verify/verification-engine.js.map +1 -1
  271. package/dist/worktree/provision.js +1 -1
  272. package/dist/worktree/provision.js.map +1 -1
  273. package/dist/worktree/scratch-guard.d.ts.map +1 -1
  274. package/dist/worktree/scratch-guard.js +23 -2
  275. package/dist/worktree/scratch-guard.js.map +1 -1
  276. package/package.json +1 -1
@@ -21,6 +21,9 @@ export { renderClineRules, writeClineProjectRules, renderClineMcpSettings, write
21
21
  export { DEFAULT_IDE_HARNESS_PRELOAD, IDE_MCP_REGISTRATION_SENTENCE, IDE_MCP_CONFIG_PATH, renderIdeMcpConfig, writeIdeMcpConfig, writeIdeHarnessScaffolding, } from './connect/ide.js';
22
22
  export type { IdeHarness } from './connect/ide.js';
23
23
  export { harnessGitignoreEntries, writeHarnessScaffolding } from './connect/scaffolding.js';
24
+ export { resolveCodexCliPath, writeConnectDaemonConfig, writeStarterPromptArtifacts, ensureGitignoreEntries, startDaemonOnDisk, } from './connect/config-write.js';
25
+ export { findExistingProductForRepo, readConnectedIdentity, locateTeloraAi, registerWorkstationLocally, mergeUserClaudeSettingsHooks, } from './connect/registration.js';
26
+ export type { ConnectedIdentity } from './connect/registration.js';
24
27
  /**
25
28
  * Production Telora API URL embedded in the published @telora/daemon package.
26
29
  * Override with TELORA_URL for local dev.
@@ -116,147 +119,6 @@ export declare function defaultIO(io?: Partial<ConnectIO>): ConnectIO;
116
119
  * Validate that the token has the expected `TOK_*` shape.
117
120
  */
118
121
  export declare function validateTokenShape(token: string): boolean;
119
- /**
120
- * Resolve Codex to a stable on-disk executable for daemon config.
121
- *
122
- * The daemon runs detached and may not inherit the operator's login-shell PATH.
123
- * Persisting an absolute path during `connect --harness codex` keeps future
124
- * agent spawns independent of shell startup files.
125
- */
126
- export declare function resolveCodexCliPath(repoPath: string): string | null;
127
- /**
128
- * Write the daemon config to ~/.telora/daemon.json.
129
- *
130
- * Connect-flow config is single-product. If a config already exists,
131
- * we overwrite it and print a warning -- re-running connect is the
132
- * supported recovery path.
133
- *
134
- * The `trackerId` is persisted in this file (mode 0600 in $HOME) so the
135
- * background daemon can read it on startup without an env var. This matches
136
- * the security profile of `.mcp.json`, which already stores the same secret.
137
- */
138
- export declare function writeConnectDaemonConfig(params: {
139
- teloraUrl: string;
140
- trackerId: string;
141
- organizationId: string;
142
- productId: string;
143
- repoPath: string;
144
- io: ConnectIO;
145
- /** Absolute path of the per-product isolated CODEX_HOME (local-model flow). */
146
- codexHome?: string;
147
- /** Default coding engine for the product (local-model flow). */
148
- defaultCodingEngine?: string;
149
- /** Model id the local-model server exposes (local-model flow). */
150
- codexModel?: string;
151
- /** Absolute path to the Codex CLI for detached daemon spawns. */
152
- codexPath?: string;
153
- }): string;
154
- /**
155
- * Write the AHA starter prompt + first-session marker into the repo's
156
- * `.telora/` directory. The bash bootstrap reads `starter-prompt.md` and
157
- * passes it to `claude` as the first user message.
158
- *
159
- * Returns the absolute path of the prompt file (or null on failure -- the
160
- * caller treats prompt injection as best-effort and falls back to plain
161
- * `claude` if this artifact is missing).
162
- */
163
- export declare function writeStarterPromptArtifacts(repoPath: string, io: ConnectIO): string | null;
164
- /**
165
- * Append `.telora/` and `.mcp.json` to .gitignore in the repo root if missing.
166
- *
167
- * `.mcp.json` is per-user-machine (absolute path to the daemon's bundled
168
- * MCP). It's regenerated by `connect` and refreshed by the daemon on every
169
- * startup, so collaborators don't need to share it.
170
- */
171
- export declare function ensureGitignoreEntries(repoPath: string, io: ConnectIO, extra?: readonly string[]): void;
172
- /**
173
- * Start the daemon as a detached background process from a stable on-disk
174
- * install -- never from an ephemeral npx cache (which cannot self-update).
175
- *
176
- * Resolution order:
177
- * 1. Use an existing on-disk binary (global install on PATH, or a repo-local
178
- * `node_modules/.bin/telora-daemon` dev dependency).
179
- * 2. If none exists, run `npm install -g @telora/daemon` best-effort. Global
180
- * install keeps the connect flow language-agnostic -- it leaves no
181
- * `package.json`/`node_modules`/dev-dependency footprint in the user's
182
- * repo (Rust/Python/Go/empty repos stay untouched).
183
- * 3. Spawn the resolved on-disk `telora-daemon run`.
184
- *
185
- * On install failure this throws (the caller surfaces the manual
186
- * `npm install -g @telora/daemon` instruction and skips auto-start); it does
187
- * NOT fall back to npx, because an npx-run daemon is exactly what this focus
188
- * retires.
189
- *
190
- * Bin name is explicit (`telora-daemon`) because the package's bins are
191
- * `telora-daemon` and `telora-daemon-wrapper`; neither matches the unscoped
192
- * package name `daemon`.
193
- */
194
- export declare function startDaemonOnDisk(repoPath: string): number;
195
- /**
196
- * Look up an existing product entry in `~/.telora/daemon.json` whose
197
- * repoPath matches the given path. Returns the product id when found,
198
- * else null. Used by runConnect for re-run idempotency: a second run on
199
- * the same dir reuses the existing binding instead of creating a duplicate
200
- * product on the unbound path.
201
- */
202
- export declare function findExistingProductForRepo(repoPath: string): string | null;
203
- /**
204
- * Workstation identity for an already-connected repo, resolved from the single
205
- * source `~/.telora/daemon.json`. Returned by `readConnectedIdentity` and
206
- * consumed by the token-free `harness add` verb -- which never re-redeems a
207
- * connect token, it just reads what `connect` already persisted.
208
- */
209
- export interface ConnectedIdentity {
210
- teloraUrl: string;
211
- organizationId: string;
212
- productId: string;
213
- }
214
- /**
215
- * Resolve the connected-workstation identity for `repoPath` from
216
- * `~/.telora/daemon.json`: the top-level `teloraUrl` / `organizationId` plus the
217
- * `products[]` entry whose `repoPath` matches. Returns null when there is no
218
- * config, the config lacks url/org, or no product entry binds this repo -- i.e.
219
- * the repo is not connected, so `harness add` must direct the operator to
220
- * `connect` first.
221
- */
222
- export declare function readConnectedIdentity(repoPath: string): ConnectedIdentity | null;
223
- /**
224
- * Locate the `telora-ai` Python CLI on PATH. Returns the absolute path if
225
- * found, else null. Detection is the entire install model -- if the user
226
- * doesn't have it, connect prints a remediation hint and continues
227
- * (tracking is opt-in).
228
- */
229
- export declare function locateTeloraAi(): string | null;
230
- /**
231
- * Pre-populate the user's `~/.syntelyos/ai_tracking.db` config table with
232
- * the redeem-derived credentials. Skips the
233
- * `telora-ai register <code>` round-trip that Settings > AI Trackers
234
- * normally requires -- the tracker row already exists in Telora (the
235
- * redeem RPC inserted it), so all we need is to point the local DB at
236
- * it.
237
- *
238
- * Each `telora-ai config <key> <value>` call is a single sqlite UPSERT;
239
- * idempotent on re-runs.
240
- *
241
- * Returns true on success, false if any sub-call failed (the failure is
242
- * surfaced via io.err but never aborts the connect flow).
243
- */
244
- export declare function registerWorkstationLocally(params: {
245
- teloraAiPath: string;
246
- trackerId: string;
247
- organizationId: string;
248
- teloraUrl: string;
249
- io: ConnectIO;
250
- }): boolean;
251
- /**
252
- * Idempotent merge of `PostToolUse` and `UserPromptSubmit` hook entries
253
- * into `~/.claude/settings.json`. Mirrors the shape of `telora-ai
254
- * setup-hooks` in scripts/telora-ai but runs from the daemon connect flow
255
- * so the user doesn't have to invoke it manually.
256
- *
257
- * Existing hook entries are preserved. Re-runs do not duplicate.
258
- */
259
- export declare function mergeUserClaudeSettingsHooks(io: ConnectIO, homeOverride?: string): boolean;
260
122
  /**
261
123
  * Write `.telora/.product-bootstrapped` -- a marker the starter prompt
262
124
  * detects on first turn to offer a rename of the basename-derived product
@@ -1 +1 @@
1
- {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../src/cli/connect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAoBH,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,sBAAsB,CAA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IAAI,CAAC;IAC7B,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,yEAAyE;IACzE,iBAAiB,EAAE,OAAO,CAAC;IAC3B;kEAC8D;IAC9D,qBAAqB,EAAE,OAAO,CAAC;CAChC;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CA8B/D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,SAAS,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,SAAS,CAM5D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEzD;AAmCD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,GAAG,IAAI,CAY1E;AAED;;;;;;GAMG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CAmP7E"}
@@ -11,28 +11,25 @@
11
11
  * node_modules, no dev dependency) in the user's repo, so Rust/Python/Go/empty
12
12
  * repos stay untouched.
13
13
  */
14
- import { closeSync, existsSync, mkdirSync, openSync, readFileSync, writeFileSync, } from 'node:fs';
15
- import { spawn, spawnSync, execFileSync } from 'node:child_process';
16
- import { resolve, delimiter } from 'node:path';
17
- import { homedir } from 'node:os';
14
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, } from 'node:fs';
15
+ import { resolve } from 'node:path';
18
16
  import { isLegacyMcpConfigShape, resolveMcpServerPath, writeMcpConfigFile, } from '../shell/mcp-resolution.js';
19
- import { ensureGlobalStateDir, resolveDaemonLogPath } from '../shell/daemon-process.js';
20
- import { STARTER_PROMPT } from '../prompts/starter-prompt.js';
21
17
  import { writeProductCodexHome, renderManualCodexProfile, } from './codex-provision.js';
22
18
  import { writeProductCodexAgentsMd } from './connect/agents.js';
23
19
  import { harnessGitignoreEntries, writeHarnessScaffolding, } from './connect/scaffolding.js';
24
- import { cliLog } from '../shell/log.js';
25
- import { convergeGitignore } from '../shell/gitignore-convergence.js';
26
- // Interactive command feedback: plain console text for the operator
27
- // terminal, never JSON envelopes (review TEL-5). The daemon process's own
28
- // modules keep the structured createLogger.
29
- const log = cliLog;
20
+ import { resolveCodexCliPath, writeConnectDaemonConfig, writeStarterPromptArtifacts, ensureGitignoreEntries, startDaemonOnDisk, } from './connect/config-write.js';
21
+ import { findExistingProductForRepo, locateTeloraAi, registerWorkstationLocally, mergeUserClaudeSettingsHooks, } from './connect/registration.js';
30
22
  export { retireClaudeMdSeed, writeOrMergeClaudeSettings } from './connect/claude.js';
31
23
  export { writeOrMergeAgentsMd, writeOrMergeGlobalAgentsMd, writeProductCodexAgentsMd, retireAgentsMdSeed, globalAgentsMdPath, } from './connect/agents.js';
32
24
  export { renderCodexMcpBlock, writeOrMergeCodexMcpToml } from './connect/codex.js';
33
25
  export { renderClineRules, writeClineProjectRules, renderClineMcpSettings, writeOrMergeClineMcpSettings, } from './connect/cline.js';
34
26
  export { DEFAULT_IDE_HARNESS_PRELOAD, IDE_MCP_REGISTRATION_SENTENCE, IDE_MCP_CONFIG_PATH, renderIdeMcpConfig, writeIdeMcpConfig, writeIdeHarnessScaffolding, } from './connect/ide.js';
35
27
  export { harnessGitignoreEntries, writeHarnessScaffolding } from './connect/scaffolding.js';
28
+ // Config + daemon-start writers and workstation registration split out to
29
+ // connect/config-write.ts + connect/registration.ts (file-size limit),
30
+ // re-exported so existing importers keep resolving them from './connect.js'.
31
+ export { resolveCodexCliPath, writeConnectDaemonConfig, writeStarterPromptArtifacts, ensureGitignoreEntries, startDaemonOnDisk, } from './connect/config-write.js';
32
+ export { findExistingProductForRepo, readConnectedIdentity, locateTeloraAi, registerWorkstationLocally, mergeUserClaudeSettingsHooks, } from './connect/registration.js';
36
33
  /**
37
34
  * Production Telora API URL embedded in the published @telora/daemon package.
38
35
  * Override with TELORA_URL for local dev.
@@ -118,243 +115,6 @@ export function defaultIO(io) {
118
115
  export function validateTokenShape(token) {
119
116
  return typeof token === 'string' && token.startsWith('TOK_') && token.length > 8;
120
117
  }
121
- function executableExists(path) {
122
- return existsSync(path);
123
- }
124
- function resolveCommandOnPath(command) {
125
- const pathEnv = process.env.PATH ?? '';
126
- for (const dir of pathEnv.split(delimiter).filter(Boolean)) {
127
- const candidate = resolve(dir, command);
128
- if (executableExists(candidate))
129
- return candidate;
130
- }
131
- return null;
132
- }
133
- function npmGlobalBinDir() {
134
- if (process.env.NPM_CONFIG_PREFIX) {
135
- return resolve(process.env.NPM_CONFIG_PREFIX, 'bin');
136
- }
137
- try {
138
- const prefix = execFileSync('npm', ['prefix', '-g'], {
139
- encoding: 'utf-8',
140
- timeout: 5_000,
141
- }).trim();
142
- return prefix ? resolve(prefix, 'bin') : null;
143
- }
144
- catch {
145
- return null;
146
- }
147
- }
148
- /**
149
- * Resolve Codex to a stable on-disk executable for daemon config.
150
- *
151
- * The daemon runs detached and may not inherit the operator's login-shell PATH.
152
- * Persisting an absolute path during `connect --harness codex` keeps future
153
- * agent spawns independent of shell startup files.
154
- */
155
- export function resolveCodexCliPath(repoPath) {
156
- const onPath = resolveCommandOnPath('codex');
157
- if (onPath)
158
- return onPath;
159
- const npmBinDir = npmGlobalBinDir();
160
- const candidates = [
161
- npmBinDir ? resolve(npmBinDir, 'codex') : null,
162
- resolve(homedir(), '.npm-global', 'bin', 'codex'),
163
- resolve(homedir(), '.local', 'bin', 'codex'),
164
- resolve(repoPath, 'node_modules', '.bin', 'codex'),
165
- ];
166
- for (const candidate of candidates) {
167
- if (candidate && executableExists(candidate))
168
- return candidate;
169
- }
170
- return null;
171
- }
172
- /**
173
- * Write the daemon config to ~/.telora/daemon.json.
174
- *
175
- * Connect-flow config is single-product. If a config already exists,
176
- * we overwrite it and print a warning -- re-running connect is the
177
- * supported recovery path.
178
- *
179
- * The `trackerId` is persisted in this file (mode 0600 in $HOME) so the
180
- * background daemon can read it on startup without an env var. This matches
181
- * the security profile of `.mcp.json`, which already stores the same secret.
182
- */
183
- export function writeConnectDaemonConfig(params) {
184
- const teloraDir = resolve(homedir(), '.telora');
185
- if (!existsSync(teloraDir)) {
186
- mkdirSync(teloraDir, { recursive: true, mode: 0o700 });
187
- }
188
- const configPath = resolve(teloraDir, 'daemon.json');
189
- const alreadyExists = existsSync(configPath);
190
- const config = {
191
- teloraUrl: params.teloraUrl,
192
- trackerId: params.trackerId,
193
- organizationId: params.organizationId,
194
- ...(params.codexPath ? { codexPath: params.codexPath } : {}),
195
- products: [
196
- {
197
- id: params.productId,
198
- repoPath: resolve(params.repoPath),
199
- ...(params.codexHome ? { codexHome: params.codexHome } : {}),
200
- ...(params.defaultCodingEngine
201
- ? { defaultCodingEngine: params.defaultCodingEngine }
202
- : {}),
203
- ...(params.codexModel ? { codexModel: params.codexModel } : {}),
204
- },
205
- ],
206
- engines: {
207
- focus: {
208
- enabled: true,
209
- integrationBranch: 'integration',
210
- maxTotalSessions: 5,
211
- },
212
- // The factory engine is retired. Newly generated configs carry only the
213
- // focus engine; a legacy `engines.factory` block in an existing config is
214
- // still tolerated (ignored, force-disabled) on load by unified-shell.
215
- },
216
- };
217
- writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n', { mode: 0o600 });
218
- if (alreadyExists) {
219
- params.io.err(`Note: replaced existing ${configPath}.\n`);
220
- }
221
- return configPath;
222
- }
223
- /**
224
- * Write the AHA starter prompt + first-session marker into the repo's
225
- * `.telora/` directory. The bash bootstrap reads `starter-prompt.md` and
226
- * passes it to `claude` as the first user message.
227
- *
228
- * Returns the absolute path of the prompt file (or null on failure -- the
229
- * caller treats prompt injection as best-effort and falls back to plain
230
- * `claude` if this artifact is missing).
231
- */
232
- export function writeStarterPromptArtifacts(repoPath, io) {
233
- const teloraDir = resolve(repoPath, '.telora');
234
- try {
235
- if (!existsSync(teloraDir)) {
236
- mkdirSync(teloraDir, { recursive: true });
237
- }
238
- const promptPath = resolve(teloraDir, 'starter-prompt.md');
239
- writeFileSync(promptPath, STARTER_PROMPT);
240
- // First-session marker: presence indicates the AHA prompt has not yet
241
- // been consumed. Future logic (subsequent sessions, idempotent re-runs)
242
- // can read or delete it. This delivery only writes it.
243
- writeFileSync(resolve(teloraDir, '.first-session'), '');
244
- io.out(`Wrote ${promptPath}.\n`);
245
- return promptPath;
246
- }
247
- catch (err) {
248
- io.err(`Warning: could not write starter prompt: ${err instanceof Error ? err.message : String(err)}\n`);
249
- return null;
250
- }
251
- }
252
- /**
253
- * Append `.telora/` and `.mcp.json` to .gitignore in the repo root if missing.
254
- *
255
- * `.mcp.json` is per-user-machine (absolute path to the daemon's bundled
256
- * MCP). It's regenerated by `connect` and refreshed by the daemon on every
257
- * startup, so collaborators don't need to share it.
258
- */
259
- export function ensureGitignoreEntries(repoPath, io, extra = []) {
260
- const entries = ['.telora/', '.mcp.json', ...extra];
261
- const result = convergeGitignore(repoPath, entries);
262
- if (result.created) {
263
- io.out(`Created ${result.gitignorePath}.\n`);
264
- }
265
- else if (result.added.length > 0) {
266
- io.out(`Updated ${result.gitignorePath}: added ${result.added.join(', ')}.\n`);
267
- }
268
- if (result.alreadyTracked.length > 0) {
269
- io.err(`Warning: ${result.alreadyTracked.join(', ')} already tracked by git in ` +
270
- `${repoPath}; the .gitignore entry is a no-op over tracked content. ` +
271
- `Run 'git rm -r --cached ${result.alreadyTracked.join(' ')}' to stop tracking.\n`);
272
- }
273
- }
274
- /**
275
- * Resolve an existing on-disk `telora-daemon` binary.
276
- *
277
- * Checks, in order:
278
- * 1. A global install on PATH (`which telora-daemon`) -- the canonical
279
- * long-running install.
280
- * 2. A repo-local `node_modules/.bin/telora-daemon` dev dependency.
281
- *
282
- * Returns the absolute path to the binary, or null when none is on disk.
283
- * Deliberately does NOT resolve an npx-cache binary: a daemon launched from
284
- * `~/.npm/_npx/<hash>/` cannot self-update (the running process keeps loading
285
- * from the cache while `npm install -g` writes the global prefix), so the
286
- * long-running daemon must run from a stable on-disk install.
287
- */
288
- function resolveOnDiskDaemonBinary(repoPath) {
289
- try {
290
- const resolved = execFileSync('which', ['telora-daemon'], {
291
- encoding: 'utf-8',
292
- timeout: 5_000,
293
- }).trim();
294
- if (resolved && existsSync(resolved))
295
- return resolved;
296
- }
297
- catch (err) {
298
- // Not on PATH -- fall through to the repo-local dev dependency.
299
- log.debug('Not on PATH -- fall through to the repo-local dev dependency', { error: String(err?.message ?? err) });
300
- }
301
- const localBin = resolve(repoPath, 'node_modules', '.bin', 'telora-daemon');
302
- if (existsSync(localBin))
303
- return localBin;
304
- return null;
305
- }
306
- /**
307
- * Start the daemon as a detached background process from a stable on-disk
308
- * install -- never from an ephemeral npx cache (which cannot self-update).
309
- *
310
- * Resolution order:
311
- * 1. Use an existing on-disk binary (global install on PATH, or a repo-local
312
- * `node_modules/.bin/telora-daemon` dev dependency).
313
- * 2. If none exists, run `npm install -g @telora/daemon` best-effort. Global
314
- * install keeps the connect flow language-agnostic -- it leaves no
315
- * `package.json`/`node_modules`/dev-dependency footprint in the user's
316
- * repo (Rust/Python/Go/empty repos stay untouched).
317
- * 3. Spawn the resolved on-disk `telora-daemon run`.
318
- *
319
- * On install failure this throws (the caller surfaces the manual
320
- * `npm install -g @telora/daemon` instruction and skips auto-start); it does
321
- * NOT fall back to npx, because an npx-run daemon is exactly what this focus
322
- * retires.
323
- *
324
- * Bin name is explicit (`telora-daemon`) because the package's bins are
325
- * `telora-daemon` and `telora-daemon-wrapper`; neither matches the unscoped
326
- * package name `daemon`.
327
- */
328
- export function startDaemonOnDisk(repoPath) {
329
- let binary = resolveOnDiskDaemonBinary(repoPath);
330
- if (!binary) {
331
- // No on-disk install -- install globally (no repo footprint), best-effort.
332
- execFileSync('npm', ['install', '-g', '@telora/daemon'], {
333
- stdio: 'inherit',
334
- timeout: 120_000,
335
- });
336
- binary = resolveOnDiskDaemonBinary(repoPath);
337
- if (!binary) {
338
- throw new Error('telora-daemon is not on disk after `npm install -g @telora/daemon`.');
339
- }
340
- }
341
- ensureGlobalStateDir();
342
- const logPath = resolveDaemonLogPath();
343
- const logFd = openSync(logPath, 'a', 0o600);
344
- try {
345
- const child = spawn(binary, ['run'], {
346
- detached: true,
347
- stdio: ['ignore', logFd, logFd],
348
- cwd: repoPath,
349
- env: { ...process.env },
350
- });
351
- child.unref();
352
- return child.pid ?? 0;
353
- }
354
- finally {
355
- closeSync(logFd);
356
- }
357
- }
358
118
  async function redeemToken(token, teloraUrl, proposedProductName, io) {
359
119
  let response;
360
120
  const requestBody = { token };
@@ -379,198 +139,6 @@ async function redeemToken(token, teloraUrl, proposedProductName, io) {
379
139
  }
380
140
  return body;
381
141
  }
382
- /**
383
- * Look up an existing product entry in `~/.telora/daemon.json` whose
384
- * repoPath matches the given path. Returns the product id when found,
385
- * else null. Used by runConnect for re-run idempotency: a second run on
386
- * the same dir reuses the existing binding instead of creating a duplicate
387
- * product on the unbound path.
388
- */
389
- export function findExistingProductForRepo(repoPath) {
390
- const configPath = resolve(homedir(), '.telora', 'daemon.json');
391
- if (!existsSync(configPath))
392
- return null;
393
- try {
394
- const config = JSON.parse(readFileSync(configPath, 'utf-8'));
395
- const target = resolve(repoPath);
396
- for (const entry of config.products ?? []) {
397
- if (entry.repoPath && resolve(entry.repoPath) === target && entry.id) {
398
- return entry.id;
399
- }
400
- }
401
- }
402
- catch (err) {
403
- // Malformed config -- treat as no match; runConnect overwrites it anyway.
404
- log.debug('Malformed config -- treat as no match; runConnect overwrites it anyway', { error: String(err?.message ?? err) });
405
- }
406
- return null;
407
- }
408
- /**
409
- * Resolve the connected-workstation identity for `repoPath` from
410
- * `~/.telora/daemon.json`: the top-level `teloraUrl` / `organizationId` plus the
411
- * `products[]` entry whose `repoPath` matches. Returns null when there is no
412
- * config, the config lacks url/org, or no product entry binds this repo -- i.e.
413
- * the repo is not connected, so `harness add` must direct the operator to
414
- * `connect` first.
415
- */
416
- export function readConnectedIdentity(repoPath) {
417
- const configPath = resolve(homedir(), '.telora', 'daemon.json');
418
- if (!existsSync(configPath))
419
- return null;
420
- try {
421
- const config = JSON.parse(readFileSync(configPath, 'utf-8'));
422
- if (!config.teloraUrl || !config.organizationId)
423
- return null;
424
- const target = resolve(repoPath);
425
- for (const entry of config.products ?? []) {
426
- if (entry.repoPath && resolve(entry.repoPath) === target && entry.id) {
427
- return {
428
- teloraUrl: config.teloraUrl,
429
- organizationId: config.organizationId,
430
- productId: entry.id,
431
- };
432
- }
433
- }
434
- }
435
- catch {
436
- // Malformed config -- treat as not-connected.
437
- return null;
438
- }
439
- return null;
440
- }
441
- // ── Workstation tracking (D4): telora-ai detection + hook merge ─────────
442
- /**
443
- * Locate the `telora-ai` Python CLI on PATH. Returns the absolute path if
444
- * found, else null. Detection is the entire install model -- if the user
445
- * doesn't have it, connect prints a remediation hint and continues
446
- * (tracking is opt-in).
447
- */
448
- export function locateTeloraAi() {
449
- const path = process.env.PATH ?? '';
450
- const entries = path.split(delimiter).filter(Boolean);
451
- for (const entry of entries) {
452
- const candidate = resolve(entry, 'telora-ai');
453
- if (existsSync(candidate))
454
- return candidate;
455
- }
456
- return null;
457
- }
458
- /**
459
- * Pre-populate the user's `~/.syntelyos/ai_tracking.db` config table with
460
- * the redeem-derived credentials. Skips the
461
- * `telora-ai register <code>` round-trip that Settings > AI Trackers
462
- * normally requires -- the tracker row already exists in Telora (the
463
- * redeem RPC inserted it), so all we need is to point the local DB at
464
- * it.
465
- *
466
- * Each `telora-ai config <key> <value>` call is a single sqlite UPSERT;
467
- * idempotent on re-runs.
468
- *
469
- * Returns true on success, false if any sub-call failed (the failure is
470
- * surfaced via io.err but never aborts the connect flow).
471
- */
472
- export function registerWorkstationLocally(params) {
473
- const entries = [
474
- ['telora_url', params.teloraUrl],
475
- ['tracker_id', params.trackerId],
476
- // The python tool's data model treats access_token and tracker_id as
477
- // separate fields, but in our model the tracker_id IS the bearer
478
- // token. Setting both keeps cmd_status / cmd_sync happy.
479
- ['access_token', params.trackerId],
480
- ['org_id', params.organizationId],
481
- ];
482
- for (const [key, value] of entries) {
483
- const result = spawnSync(params.teloraAiPath, ['config', key, value], {
484
- stdio: 'pipe',
485
- encoding: 'utf-8',
486
- });
487
- if (result.status !== 0) {
488
- params.io.err(`Warning: workstation registration step '${key}' failed (${result.status ?? 'no exit'}): ${result.stderr ?? result.stdout ?? ''}\n`);
489
- return false;
490
- }
491
- }
492
- return true;
493
- }
494
- /**
495
- * Idempotent merge of `PostToolUse` and `UserPromptSubmit` hook entries
496
- * into `~/.claude/settings.json`. Mirrors the shape of `telora-ai
497
- * setup-hooks` in scripts/telora-ai but runs from the daemon connect flow
498
- * so the user doesn't have to invoke it manually.
499
- *
500
- * Existing hook entries are preserved. Re-runs do not duplicate.
501
- */
502
- export function mergeUserClaudeSettingsHooks(io, homeOverride) {
503
- const home = homeOverride ?? homedir();
504
- const settingsDir = resolve(home, '.claude');
505
- const settingsPath = resolve(settingsDir, 'settings.json');
506
- const hookBin = locateBinaryOnPath('telora-ai-hook');
507
- const humanHookBin = locateBinaryOnPath('telora-ai-human-hook');
508
- if (!hookBin || !humanHookBin) {
509
- io.err(`Warning: telora-ai-hook / telora-ai-human-hook not on PATH. Skipping ~/.claude/settings.json merge.\n`);
510
- return false;
511
- }
512
- if (!existsSync(settingsDir))
513
- mkdirSync(settingsDir, { recursive: true });
514
- let parsed = {};
515
- if (existsSync(settingsPath)) {
516
- try {
517
- const raw = readFileSync(settingsPath, 'utf-8');
518
- const candidate = JSON.parse(raw);
519
- if (candidate && typeof candidate === 'object' && !Array.isArray(candidate)) {
520
- parsed = candidate;
521
- }
522
- }
523
- catch (err) {
524
- io.err(`Warning: ${settingsPath} is not valid JSON; leaving it alone: ${err instanceof Error ? err.message : String(err)}\n`);
525
- return false;
526
- }
527
- }
528
- const hooks = typeof parsed.hooks === 'object' && parsed.hooks !== null
529
- ? parsed.hooks
530
- : {};
531
- const desired = {
532
- PostToolUse: {
533
- matcher: '',
534
- hooks: [{ type: 'command', command: hookBin }],
535
- },
536
- UserPromptSubmit: {
537
- matcher: '',
538
- hooks: [{ type: 'command', command: humanHookBin }],
539
- },
540
- };
541
- for (const [eventName, entry] of Object.entries(desired)) {
542
- const existing = hooks[eventName] ?? [];
543
- let alreadyPresent = false;
544
- for (const rule of existing) {
545
- for (const h of rule.hooks ?? []) {
546
- const cmd = h.command ?? '';
547
- if (cmd.includes('telora-ai-hook') || cmd.includes('telora-ai-human-hook')) {
548
- alreadyPresent = true;
549
- // Refresh path in case the binary moved between runs.
550
- const desiredCmd = entry.hooks[0].command;
551
- if (cmd !== desiredCmd)
552
- h.command = desiredCmd;
553
- }
554
- }
555
- }
556
- if (!alreadyPresent)
557
- existing.push(entry);
558
- hooks[eventName] = existing;
559
- }
560
- parsed.hooks = hooks;
561
- writeFileSync(settingsPath, JSON.stringify(parsed, null, 2) + '\n');
562
- io.out(`Merged Telora tracking hooks into ${settingsPath}.\n`);
563
- return true;
564
- }
565
- function locateBinaryOnPath(name) {
566
- const path = process.env.PATH ?? '';
567
- for (const entry of path.split(delimiter).filter(Boolean)) {
568
- const candidate = resolve(entry, name);
569
- if (existsSync(candidate))
570
- return candidate;
571
- }
572
- return null;
573
- }
574
142
  /**
575
143
  * Write `.telora/.product-bootstrapped` -- a marker the starter prompt
576
144
  * detects on first turn to offer a rename of the basename-derived product