@getcliqio/cliq-sdk 0.0.0-stage → 1.15.32

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 (338) hide show
  1. package/README.md +28 -2
  2. package/dist/agent_api.d.ts +39 -0
  3. package/dist/agent_api.d.ts.map +1 -0
  4. package/dist/agent_api.js +105 -0
  5. package/dist/agent_api.js.map +1 -0
  6. package/dist/agent_manifest.d.ts +162 -0
  7. package/dist/agent_manifest.d.ts.map +1 -0
  8. package/dist/agent_manifest.js +242 -0
  9. package/dist/agent_manifest.js.map +1 -0
  10. package/dist/agent_payloads.d.ts +103 -0
  11. package/dist/agent_payloads.d.ts.map +1 -0
  12. package/dist/agent_payloads.js +56 -0
  13. package/dist/agent_payloads.js.map +1 -0
  14. package/dist/agents/base_agent.d.ts +113 -0
  15. package/dist/agents/base_agent.d.ts.map +1 -0
  16. package/dist/agents/base_agent.js +413 -0
  17. package/dist/agents/base_agent.js.map +1 -0
  18. package/dist/agents/cli_agent.d.ts +98 -0
  19. package/dist/agents/cli_agent.d.ts.map +1 -0
  20. package/dist/agents/cli_agent.js +303 -0
  21. package/dist/agents/cli_agent.js.map +1 -0
  22. package/dist/agents/cli_rehydrate.d.ts +29 -0
  23. package/dist/agents/cli_rehydrate.d.ts.map +1 -0
  24. package/dist/agents/cli_rehydrate.js +32 -0
  25. package/dist/agents/cli_rehydrate.js.map +1 -0
  26. package/dist/agents/connector_agent.d.ts +20 -0
  27. package/dist/agents/connector_agent.d.ts.map +1 -0
  28. package/dist/agents/connector_agent.js +110 -0
  29. package/dist/agents/connector_agent.js.map +1 -0
  30. package/dist/agents/event_artifacts.d.ts +33 -0
  31. package/dist/agents/event_artifacts.d.ts.map +1 -0
  32. package/dist/agents/event_artifacts.js +73 -0
  33. package/dist/agents/event_artifacts.js.map +1 -0
  34. package/dist/agents/gate_agent.d.ts +40 -0
  35. package/dist/agents/gate_agent.d.ts.map +1 -0
  36. package/dist/agents/gate_agent.js +121 -0
  37. package/dist/agents/gate_agent.js.map +1 -0
  38. package/dist/agents/index.d.ts +32 -0
  39. package/dist/agents/index.d.ts.map +1 -0
  40. package/dist/agents/index.js +26 -0
  41. package/dist/agents/index.js.map +1 -0
  42. package/dist/agents/llm_agent.d.ts +109 -0
  43. package/dist/agents/llm_agent.d.ts.map +1 -0
  44. package/dist/agents/llm_agent.js +285 -0
  45. package/dist/agents/llm_agent.js.map +1 -0
  46. package/dist/agents/llm_contract.d.ts +7 -0
  47. package/dist/agents/llm_contract.d.ts.map +1 -0
  48. package/dist/agents/llm_contract.js +7 -0
  49. package/dist/agents/llm_contract.js.map +1 -0
  50. package/dist/agents/standard_agent.d.ts +15 -0
  51. package/dist/agents/standard_agent.d.ts.map +1 -0
  52. package/dist/agents/standard_agent.js +34 -0
  53. package/dist/agents/standard_agent.js.map +1 -0
  54. package/dist/agents/turn_result.d.ts +67 -0
  55. package/dist/agents/turn_result.d.ts.map +1 -0
  56. package/dist/agents/turn_result.js +81 -0
  57. package/dist/agents/turn_result.js.map +1 -0
  58. package/dist/agents/types.d.ts +314 -0
  59. package/dist/agents/types.d.ts.map +1 -0
  60. package/dist/agents/types.js +20 -0
  61. package/dist/agents/types.js.map +1 -0
  62. package/dist/builtin_teams/hello_hug.d.ts +9 -0
  63. package/dist/builtin_teams/hello_hug.d.ts.map +1 -0
  64. package/dist/builtin_teams/hello_hug.js +68 -0
  65. package/dist/builtin_teams/hello_hug.js.map +1 -0
  66. package/dist/builtin_teams/hello_world.d.ts +8 -0
  67. package/dist/builtin_teams/hello_world.d.ts.map +1 -0
  68. package/dist/builtin_teams/hello_world.js +65 -0
  69. package/dist/builtin_teams/hello_world.js.map +1 -0
  70. package/dist/builtin_teams/hug_example.d.ts +10 -0
  71. package/dist/builtin_teams/hug_example.d.ts.map +1 -0
  72. package/dist/builtin_teams/hug_example.js +94 -0
  73. package/dist/builtin_teams/hug_example.js.map +1 -0
  74. package/dist/builtin_teams/index.d.ts +12 -0
  75. package/dist/builtin_teams/index.d.ts.map +1 -0
  76. package/dist/builtin_teams/index.js +18 -0
  77. package/dist/builtin_teams/index.js.map +1 -0
  78. package/dist/builtin_teams/types.d.ts +29 -0
  79. package/dist/builtin_teams/types.d.ts.map +1 -0
  80. package/dist/builtin_teams/types.js +3 -0
  81. package/dist/builtin_teams/types.js.map +1 -0
  82. package/dist/core_api_client.d.ts +48 -0
  83. package/dist/core_api_client.d.ts.map +1 -0
  84. package/dist/core_api_client.js +132 -0
  85. package/dist/core_api_client.js.map +1 -0
  86. package/dist/daemon_wire.d.ts +122 -0
  87. package/dist/daemon_wire.d.ts.map +1 -0
  88. package/dist/daemon_wire.js +105 -0
  89. package/dist/daemon_wire.js.map +1 -0
  90. package/dist/events/catalog.d.ts +40 -0
  91. package/dist/events/catalog.d.ts.map +1 -0
  92. package/dist/events/catalog.js +76 -0
  93. package/dist/events/catalog.js.map +1 -0
  94. package/dist/http_daemon_client.d.ts +136 -0
  95. package/dist/http_daemon_client.d.ts.map +1 -0
  96. package/dist/http_daemon_client.js +192 -0
  97. package/dist/http_daemon_client.js.map +1 -0
  98. package/dist/hug/ask.d.ts +160 -0
  99. package/dist/hug/ask.d.ts.map +1 -0
  100. package/dist/hug/ask.js +318 -0
  101. package/dist/hug/ask.js.map +1 -0
  102. package/dist/hug/attach.d.ts +60 -0
  103. package/dist/hug/attach.d.ts.map +1 -0
  104. package/dist/hug/attach.js +103 -0
  105. package/dist/hug/attach.js.map +1 -0
  106. package/dist/hug/bridge/index.d.ts +16 -0
  107. package/dist/hug/bridge/index.d.ts.map +1 -0
  108. package/dist/hug/bridge/index.js +13 -0
  109. package/dist/hug/bridge/index.js.map +1 -0
  110. package/dist/hug/bridge/messages.d.ts +559 -0
  111. package/dist/hug/bridge/messages.d.ts.map +1 -0
  112. package/dist/hug/bridge/messages.js +165 -0
  113. package/dist/hug/bridge/messages.js.map +1 -0
  114. package/dist/hug/client.d.ts +70 -0
  115. package/dist/hug/client.d.ts.map +1 -0
  116. package/dist/hug/client.js +144 -0
  117. package/dist/hug/client.js.map +1 -0
  118. package/dist/hug/context.d.ts +54 -0
  119. package/dist/hug/context.d.ts.map +1 -0
  120. package/dist/hug/context.js +27 -0
  121. package/dist/hug/context.js.map +1 -0
  122. package/dist/hug/define.d.ts +116 -0
  123. package/dist/hug/define.d.ts.map +1 -0
  124. package/dist/hug/define.js +119 -0
  125. package/dist/hug/define.js.map +1 -0
  126. package/dist/hug/definitions/approval.d.ts +216 -0
  127. package/dist/hug/definitions/approval.d.ts.map +1 -0
  128. package/dist/hug/definitions/approval.js +50 -0
  129. package/dist/hug/definitions/approval.js.map +1 -0
  130. package/dist/hug/definitions/common.d.ts +122 -0
  131. package/dist/hug/definitions/common.d.ts.map +1 -0
  132. package/dist/hug/definitions/common.js +70 -0
  133. package/dist/hug/definitions/common.js.map +1 -0
  134. package/dist/hug/definitions/form.d.ts +197 -0
  135. package/dist/hug/definitions/form.d.ts.map +1 -0
  136. package/dist/hug/definitions/form.js +29 -0
  137. package/dist/hug/definitions/form.js.map +1 -0
  138. package/dist/hug/definitions/index.d.ts +10 -0
  139. package/dist/hug/definitions/index.d.ts.map +1 -0
  140. package/dist/hug/definitions/index.js +8 -0
  141. package/dist/hug/definitions/index.js.map +1 -0
  142. package/dist/hug/errors.d.ts +30 -0
  143. package/dist/hug/errors.d.ts.map +1 -0
  144. package/dist/hug/errors.js +46 -0
  145. package/dist/hug/errors.js.map +1 -0
  146. package/dist/hug/file_checks.d.ts +41 -0
  147. package/dist/hug/file_checks.d.ts.map +1 -0
  148. package/dist/hug/file_checks.js +105 -0
  149. package/dist/hug/file_checks.js.map +1 -0
  150. package/dist/hug/files.d.ts +137 -0
  151. package/dist/hug/files.d.ts.map +1 -0
  152. package/dist/hug/files.js +283 -0
  153. package/dist/hug/files.js.map +1 -0
  154. package/dist/hug/hug_bundle.d.ts +70 -0
  155. package/dist/hug/hug_bundle.d.ts.map +1 -0
  156. package/dist/hug/hug_bundle.js +299 -0
  157. package/dist/hug/hug_bundle.js.map +1 -0
  158. package/dist/hug/hug_catalog.d.ts +38 -0
  159. package/dist/hug/hug_catalog.d.ts.map +1 -0
  160. package/dist/hug/hug_catalog.js +67 -0
  161. package/dist/hug/hug_catalog.js.map +1 -0
  162. package/dist/hug/hug_definitions.d.ts +32 -0
  163. package/dist/hug/hug_definitions.d.ts.map +1 -0
  164. package/dist/hug/hug_definitions.js +74 -0
  165. package/dist/hug/hug_definitions.js.map +1 -0
  166. package/dist/hug/index.d.ts +37 -0
  167. package/dist/hug/index.d.ts.map +1 -0
  168. package/dist/hug/index.js +23 -0
  169. package/dist/hug/index.js.map +1 -0
  170. package/dist/hug/llm.d.ts +106 -0
  171. package/dist/hug/llm.d.ts.map +1 -0
  172. package/dist/hug/llm.js +250 -0
  173. package/dist/hug/llm.js.map +1 -0
  174. package/dist/hug/policies.d.ts +65 -0
  175. package/dist/hug/policies.d.ts.map +1 -0
  176. package/dist/hug/policies.js +80 -0
  177. package/dist/hug/policies.js.map +1 -0
  178. package/dist/hug/problems.d.ts +35 -0
  179. package/dist/hug/problems.d.ts.map +1 -0
  180. package/dist/hug/problems.js +53 -0
  181. package/dist/hug/problems.js.map +1 -0
  182. package/dist/hug/requested_inputs.d.ts +190 -0
  183. package/dist/hug/requested_inputs.d.ts.map +1 -0
  184. package/dist/hug/requested_inputs.js +220 -0
  185. package/dist/hug/requested_inputs.js.map +1 -0
  186. package/dist/hug/schema_for_inputs.d.ts +20 -0
  187. package/dist/hug/schema_for_inputs.d.ts.map +1 -0
  188. package/dist/hug/schema_for_inputs.js +95 -0
  189. package/dist/hug/schema_for_inputs.js.map +1 -0
  190. package/dist/hug/session.d.ts +113 -0
  191. package/dist/hug/session.d.ts.map +1 -0
  192. package/dist/hug/session.js +210 -0
  193. package/dist/hug/session.js.map +1 -0
  194. package/dist/hug/types.d.ts +141 -0
  195. package/dist/hug/types.d.ts.map +1 -0
  196. package/dist/hug/types.js +80 -0
  197. package/dist/hug/types.js.map +1 -0
  198. package/dist/index.d.ts +72 -0
  199. package/dist/index.d.ts.map +1 -0
  200. package/dist/index.js +54 -0
  201. package/dist/index.js.map +1 -0
  202. package/dist/logging.d.ts +172 -0
  203. package/dist/logging.d.ts.map +1 -0
  204. package/dist/logging.js +306 -0
  205. package/dist/logging.js.map +1 -0
  206. package/dist/mcp.d.ts +119 -0
  207. package/dist/mcp.d.ts.map +1 -0
  208. package/dist/mcp.js +259 -0
  209. package/dist/mcp.js.map +1 -0
  210. package/dist/mcp_client.d.ts +145 -0
  211. package/dist/mcp_client.d.ts.map +1 -0
  212. package/dist/mcp_client.js +374 -0
  213. package/dist/mcp_client.js.map +1 -0
  214. package/dist/paths.d.ts +20 -0
  215. package/dist/paths.d.ts.map +1 -0
  216. package/dist/paths.js +20 -0
  217. package/dist/paths.js.map +1 -0
  218. package/dist/protocol/factory.d.ts +32 -0
  219. package/dist/protocol/factory.d.ts.map +1 -0
  220. package/dist/protocol/factory.js +31 -0
  221. package/dist/protocol/factory.js.map +1 -0
  222. package/dist/protocol/framing.d.ts +35 -0
  223. package/dist/protocol/framing.d.ts.map +1 -0
  224. package/dist/protocol/framing.js +73 -0
  225. package/dist/protocol/framing.js.map +1 -0
  226. package/dist/protocol/index.d.ts +13 -0
  227. package/dist/protocol/index.d.ts.map +1 -0
  228. package/dist/protocol/index.js +13 -0
  229. package/dist/protocol/index.js.map +1 -0
  230. package/dist/protocol/types/agent.d.ts +42 -0
  231. package/dist/protocol/types/agent.d.ts.map +1 -0
  232. package/dist/protocol/types/agent.js +9 -0
  233. package/dist/protocol/types/agent.js.map +1 -0
  234. package/dist/protocol/types/cliq_core.d.ts +79 -0
  235. package/dist/protocol/types/cliq_core.d.ts.map +1 -0
  236. package/dist/protocol/types/cliq_core.js +17 -0
  237. package/dist/protocol/types/cliq_core.js.map +1 -0
  238. package/dist/protocol/types/foundations.d.ts +41 -0
  239. package/dist/protocol/types/foundations.d.ts.map +1 -0
  240. package/dist/protocol/types/foundations.js +10 -0
  241. package/dist/protocol/types/foundations.js.map +1 -0
  242. package/dist/protocol/types/index.d.ts +32 -0
  243. package/dist/protocol/types/index.d.ts.map +1 -0
  244. package/dist/protocol/types/index.js +27 -0
  245. package/dist/protocol/types/index.js.map +1 -0
  246. package/dist/protocol/types/messages.d.ts +827 -0
  247. package/dist/protocol/types/messages.d.ts.map +1 -0
  248. package/dist/protocol/types/messages.js +117 -0
  249. package/dist/protocol/types/messages.js.map +1 -0
  250. package/dist/protocol/types/pipeline.d.ts +122 -0
  251. package/dist/protocol/types/pipeline.d.ts.map +1 -0
  252. package/dist/protocol/types/pipeline.js +16 -0
  253. package/dist/protocol/types/pipeline.js.map +1 -0
  254. package/dist/protocol/types/schemas.d.ts +814 -0
  255. package/dist/protocol/types/schemas.d.ts.map +1 -0
  256. package/dist/protocol/types/schemas.js +772 -0
  257. package/dist/protocol/types/schemas.js.map +1 -0
  258. package/dist/protocol/types/team.d.ts +42 -0
  259. package/dist/protocol/types/team.d.ts.map +1 -0
  260. package/dist/protocol/types/team.js +15 -0
  261. package/dist/protocol/types/team.js.map +1 -0
  262. package/dist/protocol/types/workspace.d.ts +46 -0
  263. package/dist/protocol/types/workspace.d.ts.map +1 -0
  264. package/dist/protocol/types/workspace.js +9 -0
  265. package/dist/protocol/types/workspace.js.map +1 -0
  266. package/dist/settings_keys.d.ts +12 -0
  267. package/dist/settings_keys.d.ts.map +1 -0
  268. package/dist/settings_keys.js +35 -0
  269. package/dist/settings_keys.js.map +1 -0
  270. package/dist/tcp/client.d.ts +15 -0
  271. package/dist/tcp/client.d.ts.map +1 -0
  272. package/dist/tcp/client.js +28 -0
  273. package/dist/tcp/client.js.map +1 -0
  274. package/dist/tcp/connection.d.ts +79 -0
  275. package/dist/tcp/connection.d.ts.map +1 -0
  276. package/dist/tcp/connection.js +153 -0
  277. package/dist/tcp/connection.js.map +1 -0
  278. package/dist/tcp/index.d.ts +10 -0
  279. package/dist/tcp/index.d.ts.map +1 -0
  280. package/dist/tcp/index.js +7 -0
  281. package/dist/tcp/index.js.map +1 -0
  282. package/dist/tcp/server.d.ts +31 -0
  283. package/dist/tcp/server.d.ts.map +1 -0
  284. package/dist/tcp/server.js +54 -0
  285. package/dist/tcp/server.js.map +1 -0
  286. package/dist/team/bundle.d.ts +88 -0
  287. package/dist/team/bundle.d.ts.map +1 -0
  288. package/dist/team/bundle.js +214 -0
  289. package/dist/team/bundle.js.map +1 -0
  290. package/dist/team/identity.d.ts +31 -0
  291. package/dist/team/identity.d.ts.map +1 -0
  292. package/dist/team/identity.js +83 -0
  293. package/dist/team/identity.js.map +1 -0
  294. package/dist/team/index.d.ts +13 -0
  295. package/dist/team/index.d.ts.map +1 -0
  296. package/dist/team/index.js +8 -0
  297. package/dist/team/index.js.map +1 -0
  298. package/dist/team/lint_bundle.d.ts +16 -0
  299. package/dist/team/lint_bundle.d.ts.map +1 -0
  300. package/dist/team/lint_bundle.js +35 -0
  301. package/dist/team/lint_bundle.js.map +1 -0
  302. package/dist/team/ref.d.ts +48 -0
  303. package/dist/team/ref.d.ts.map +1 -0
  304. package/dist/team/ref.js +70 -0
  305. package/dist/team/ref.js.map +1 -0
  306. package/dist/team/roles.d.ts +22 -0
  307. package/dist/team/roles.d.ts.map +1 -0
  308. package/dist/team/roles.js +33 -0
  309. package/dist/team/roles.js.map +1 -0
  310. package/dist/team/tree.d.ts +101 -0
  311. package/dist/team/tree.d.ts.map +1 -0
  312. package/dist/team/tree.js +125 -0
  313. package/dist/team/tree.js.map +1 -0
  314. package/dist/team_lint.d.ts +57 -0
  315. package/dist/team_lint.d.ts.map +1 -0
  316. package/dist/team_lint.js +277 -0
  317. package/dist/team_lint.js.map +1 -0
  318. package/dist/telemetry/stream_json_usage.d.ts +39 -0
  319. package/dist/telemetry/stream_json_usage.d.ts.map +1 -0
  320. package/dist/telemetry/stream_json_usage.js +139 -0
  321. package/dist/telemetry/stream_json_usage.js.map +1 -0
  322. package/dist/telemetry/usage.d.ts +288 -0
  323. package/dist/telemetry/usage.d.ts.map +1 -0
  324. package/dist/telemetry/usage.js +421 -0
  325. package/dist/telemetry/usage.js.map +1 -0
  326. package/dist/utils/duration.d.ts +11 -0
  327. package/dist/utils/duration.d.ts.map +1 -0
  328. package/dist/utils/duration.js +22 -0
  329. package/dist/utils/duration.js.map +1 -0
  330. package/dist/utils/redact.d.ts +26 -0
  331. package/dist/utils/redact.d.ts.map +1 -0
  332. package/dist/utils/redact.js +52 -0
  333. package/dist/utils/redact.js.map +1 -0
  334. package/dist/utils/url.d.ts +6 -0
  335. package/dist/utils/url.d.ts.map +1 -0
  336. package/dist/utils/url.js +11 -0
  337. package/dist/utils/url.js.map +1 -0
  338. package/package.json +72 -5
@@ -0,0 +1,303 @@
1
+ /**
2
+ * CliAgent — base class for CLI wrapper agents (cursor, claude-code, codex).
3
+ *
4
+ * Extends LlmAgent by adding binary spawning, stdout capture, and
5
+ * the project directory the binary operates on.
6
+ *
7
+ * Provides an `on_stream_event` hook that subclasses can override for
8
+ * custom NDJSON-to-typed-event mapping. The default implementation
9
+ * converts standard NDJSON event types to `ctx.emit()` calls.
10
+ */
11
+ import { spawn } from 'node:child_process';
12
+ import { LlmAgent, answers_from_resume } from './llm_agent.js';
13
+ import { extract_usage_from_ndjson } from '../telemetry/stream_json_usage.js';
14
+ import { report_usage } from '../telemetry/usage.js';
15
+ import { Redact } from '../utils/redact.js';
16
+ import { build_cli_turn_prompt } from './cli_rehydrate.js';
17
+ import { turn_from_cli_stdout } from './turn_result.js';
18
+ import { allowed_response_instruction, check_llm_ask, load_phase_hug } from '../hug/llm.js';
19
+ /** How many chars of stderr/stdout to include in a CLI failure error. */
20
+ const ERROR_TAIL_CHARS = 2000;
21
+ /** Tool names that change the workspace (Cursor, Claude Code, Codex, Gemini CLIs). Two patterns to keep each one simple. */
22
+ const WRITE_TOOL = [
23
+ /^(edit|write|create|delete|remove|move|rename|patch|apply|update)/i,
24
+ /^(str_?replace|multi_?edit|notebook_?edit|search_?replace)/i,
25
+ ];
26
+ /**
27
+ * Base class for agents that wrap a coding CLI: spawns `binary` in the project
28
+ * directory, streams its NDJSON output into events, and turns stdout into a turn result.
29
+ */
30
+ export class CliAgent extends LlmAgent {
31
+ binary;
32
+ default_args;
33
+ constructor(options) {
34
+ super(options);
35
+ this.binary = options.binary;
36
+ this.default_args = options.default_args ?? [];
37
+ }
38
+ build_context(invoke, post_event, transport) {
39
+ const llm = super.build_context(invoke, post_event, transport);
40
+ const config = invoke.config;
41
+ const args_override = Array.isArray(config['args']) ? config['args'].map(String) : [];
42
+ const args = args_override.length > 0 ? args_override : [...this.default_args];
43
+ const env_vars = {};
44
+ const raw_env = config['env'];
45
+ if (raw_env && typeof raw_env === 'object') {
46
+ for (const [k, v] of Object.entries(raw_env)) {
47
+ env_vars[k] = String(v);
48
+ }
49
+ }
50
+ return {
51
+ ...llm,
52
+ project_dir: invoke.project_dir,
53
+ binary: this.binary,
54
+ args,
55
+ env_vars,
56
+ };
57
+ }
58
+ /**
59
+ * Spawn the CLI binary and interpret stdout into a TurnResult.
60
+ * Subclasses that understand richer NDJSON may override and map
61
+ * provider-specific pause signals before falling back to the fence.
62
+ */
63
+ async call_llm(ctx) {
64
+ const started_at_unix_ms = Date.now();
65
+ const result = await this.run_binary(ctx.prompt, ctx);
66
+ const ended_at_unix_ms = Date.now();
67
+ // Central usage reporting for CLI-wrapper LLMs (cursor, claude-code,
68
+ // codex, gemini). Providers emit a final stream-json `result` line
69
+ // with `usage`; parse defensively and only report if we get a
70
+ // usable shape. Subclasses can override extract_usage_from_result
71
+ // to hook non-standard formats. Any failure to parse silently
72
+ // falls back to the daemon's baseline record.
73
+ try {
74
+ const partial = this.extract_usage_from_result(result);
75
+ if (partial) {
76
+ const provider = this.usage_provider() ?? this.name;
77
+ void report_usage({
78
+ ...partial,
79
+ agent_kind: 'llm',
80
+ provider,
81
+ model: partial.model ?? ctx.model,
82
+ started_at_unix_ms,
83
+ ended_at_unix_ms,
84
+ duration_ms: ended_at_unix_ms - started_at_unix_ms,
85
+ outcome: partial.outcome ?? (result.exit_code === 0 ? 'success' : 'failure'),
86
+ exit_code: result.exit_code,
87
+ unit_kind: partial.unit_kind ?? 'tokens',
88
+ });
89
+ }
90
+ }
91
+ catch (err) {
92
+ ctx.log.debug?.('usage extraction failed', { error: err?.message });
93
+ }
94
+ // Nonzero exit MUST fail the phase — without this, cursor/claude-code/
95
+ // codex/gemini binaries dying (exit 1, SIGKILL, OOM) silently produced
96
+ // a phase_complete with stderr as "output". Surface a redacted stderr
97
+ // tail so operators can diagnose from Hub logs.
98
+ if (result.exit_code !== 0) {
99
+ const stderr_tail = Redact.tail(Redact.secrets(result.stderr.trim()), ERROR_TAIL_CHARS);
100
+ const stdout_tail = Redact.tail(Redact.secrets(result.stdout.trim()), ERROR_TAIL_CHARS);
101
+ const parts = [`${this.binary} exited ${result.exit_code}`];
102
+ if (stderr_tail)
103
+ parts.push(`stderr:\n${stderr_tail}`);
104
+ if (stdout_tail && !stderr_tail)
105
+ parts.push(`stdout:\n${stdout_tail}`);
106
+ if (!stderr_tail && !stdout_tail)
107
+ parts.push('(no output captured)');
108
+ throw new Error(parts.join('\n'));
109
+ }
110
+ return this.interpret_cli_result(result);
111
+ }
112
+ /**
113
+ * Map CLI stdout into a turn outcome. Default: a cliq_hug fence or QUESTION: → ask,
114
+ * else text → complete / EMPTY_RESPONSE. Override for provider-specific shapes.
115
+ */
116
+ interpret_cli_result(result) {
117
+ const text = this.extract_output(result);
118
+ return turn_from_cli_stdout(text, { changed_files: this.changed_files, pause_on_question: this.pause_on_question });
119
+ }
120
+ /** This turn edited / wrote files (set from tool calls; see {@link note_tool_call}). */
121
+ changed_files = false;
122
+ /** Phase config `pause_on_question: false` turns off the plain-question fallback. */
123
+ pause_on_question = true;
124
+ /**
125
+ * Record a tool call the CLI made. Subclasses with their own stream
126
+ * parsing call this too, so a trailing question after real edits is
127
+ * not mistaken for the agent being blocked.
128
+ */
129
+ note_tool_call(tool_name) {
130
+ if (WRITE_TOOL.some((re) => re.test(tool_name)))
131
+ this.changed_files = true;
132
+ }
133
+ /**
134
+ * Extract a partial UsageRecord from the CLI's completed output.
135
+ * Default implementation scans stdout NDJSON for a `result` event
136
+ * (Anthropic-flavoured tools). Subclasses can override to handle
137
+ * provider-specific formats — return null to fall back to the
138
+ * daemon's baseline.
139
+ */
140
+ extract_usage_from_result(result) {
141
+ return extract_usage_from_ndjson(result.stdout);
142
+ }
143
+ /**
144
+ * Provider name to stamp on the reported usage record. Defaults to
145
+ * the agent name; subclasses like `claude-code` override with
146
+ * "anthropic", cursor with "cursor", etc.
147
+ */
148
+ usage_provider() {
149
+ return undefined;
150
+ }
151
+ async run_binary(prompt, ctx) {
152
+ const args = [...ctx.args, prompt];
153
+ return new Promise((resolve, reject) => {
154
+ const child = spawn(ctx.binary, args, {
155
+ cwd: ctx.project_dir,
156
+ env: { ...process.env, ...ctx.env_vars },
157
+ stdio: ['pipe', 'pipe', 'pipe'],
158
+ });
159
+ const stdout_chunks = [];
160
+ const stderr_chunks = [];
161
+ child.stdout.on('data', (chunk) => stdout_chunks.push(chunk));
162
+ child.stderr.on('data', (chunk) => stderr_chunks.push(chunk));
163
+ child.on('error', reject);
164
+ child.on('close', (code) => {
165
+ resolve({
166
+ stdout: Buffer.concat(stdout_chunks).toString('utf-8'),
167
+ stderr: Buffer.concat(stderr_chunks).toString('utf-8'),
168
+ exit_code: code ?? 1,
169
+ });
170
+ });
171
+ child.stdin.end();
172
+ });
173
+ }
174
+ /**
175
+ * Hook for processing a single NDJSON event from the CLI stream.
176
+ * Default implementation maps standard NDJSON event types to
177
+ * typed ctx.emit() calls. Subclasses can override for custom mapping.
178
+ *
179
+ * Return true if the event was handled, false to skip.
180
+ */
181
+ on_stream_event(ctx, evt, seq) {
182
+ const type = evt.type;
183
+ if (!type)
184
+ return false;
185
+ if (type === 'thinking' || type === 'reasoning') {
186
+ const text = evt.text ?? '';
187
+ if (text) {
188
+ ctx.emit('thinking', { text: text.slice(-500), seq });
189
+ }
190
+ return true;
191
+ }
192
+ if (type === 'assistant') {
193
+ this.on_assistant_event(ctx, evt, seq);
194
+ return true;
195
+ }
196
+ if (type === 'tool_call' || type === 'tool_use') {
197
+ const tool_name = this.extract_tool_name(evt);
198
+ this.note_tool_call(tool_name);
199
+ ctx.emit('tool_call', { tool_name, seq });
200
+ return true;
201
+ }
202
+ if (type === 'tool_result') {
203
+ const tool_name = evt.tool
204
+ ?? evt.name
205
+ ?? '';
206
+ ctx.emit('tool_result', { tool_name, seq });
207
+ return true;
208
+ }
209
+ if (type === 'error') {
210
+ const msg = evt.message ?? JSON.stringify(evt);
211
+ ctx.emit('warning', { message: msg, source: 'cli', seq });
212
+ return true;
213
+ }
214
+ return false;
215
+ }
216
+ /** Handle an `assistant` event: note any tool calls inside it and emit its text. */
217
+ on_assistant_event(ctx, evt, seq) {
218
+ const message = evt.message;
219
+ // Claude Code puts its tool calls inside assistant messages.
220
+ for (const part of message?.content ?? []) {
221
+ if ((part.type === 'tool_use' || part.type === 'tool_call') && part.name)
222
+ this.note_tool_call(part.name);
223
+ }
224
+ const text = (message?.content ?? [])
225
+ .filter((p) => p.type === 'text' && p.text)
226
+ .map((p) => p.text)
227
+ .join('');
228
+ if (text) {
229
+ ctx.emit('assistant_message', { text: text.slice(-500), seq });
230
+ }
231
+ }
232
+ /**
233
+ * Extract tool name from a tool_call/tool_use NDJSON event.
234
+ */
235
+ extract_tool_name(evt) {
236
+ return evt.tool
237
+ ?? evt.name
238
+ ?? evt.tool_name
239
+ ?? (evt.content?.[0]?.name)
240
+ ?? (evt.message?.content?.find((p) => p.type === 'tool_use' || p.type === 'tool_call')?.name)
241
+ ?? 'unknown';
242
+ }
243
+ extract_output(result) {
244
+ return result.stdout.trim() || result.stderr.trim();
245
+ }
246
+ /**
247
+ * CLI chat turn (Yamazaki W11/W12).
248
+ *
249
+ * One binary spawn per invoke. Prompt injection rehydrates the transcript and,
250
+ * after a wait, the answers. call_llm interprets stdout → TurnResult (ask / text / empty).
251
+ * Does not require api_key (Cursor/local auth).
252
+ */
253
+ async on_invoke(ctx) {
254
+ this.changed_files = false;
255
+ this.pause_on_question = ctx.config?.['pause_on_question'] !== false;
256
+ // The hug this phase asks with (PLAN-hug-widgets §9.4): its instruction, and the check of the agent's ask.
257
+ let phase_hug;
258
+ try {
259
+ phase_hug = await load_phase_hug();
260
+ }
261
+ catch (err) {
262
+ ctx.error('HUG_UNKNOWN', err instanceof Error ? err.message : String(err));
263
+ return;
264
+ }
265
+ const prompt = build_cli_turn_prompt({
266
+ prompt: ctx.prompt,
267
+ messages: ctx.messages,
268
+ answers: await answers_from_resume(ctx, ctx.project_dir),
269
+ instruction: allowed_response_instruction(phase_hug),
270
+ });
271
+ if (!prompt.trim()) {
272
+ ctx.error('EMPTY_REQUIREMENT', 'No requirement or upstream context provided — nothing to do');
273
+ return;
274
+ }
275
+ ctx.progress(`Calling ${this.binary}…`, 10);
276
+ const result = await this.call_llm({ ...ctx, prompt });
277
+ if (result.kind === 'fail') {
278
+ ctx.error(result.code, result.message);
279
+ return;
280
+ }
281
+ if (result.kind === 'ask') {
282
+ const checked = check_llm_ask(result.ask, phase_hug);
283
+ if (!checked.ok) {
284
+ // One CLI run per invoke, so it can't resend the block: fail with why.
285
+ ctx.error('INVALID_HUG', `The agent's question was not sent: its cliq_hug block failed the check — ${checked.problems.join('; ')}`);
286
+ return;
287
+ }
288
+ await ctx.ask(checked.definition, { ...checked.options, wait: 'yield' });
289
+ return;
290
+ }
291
+ if (result.kind === 'invalid_ask') {
292
+ // One CLI run per invoke, so it can't resend the block: fail with why, rather than pass its text off as the answer.
293
+ ctx.error('INVALID_HUG', `The agent's question was not sent: its cliq_hug block failed the check — ${result.problems.join('; ')}`);
294
+ return;
295
+ }
296
+ if (result.kind === 'continue') {
297
+ // CLI has no in-process multi-turn; treat as complete text.
298
+ return { text: result.assistant_text };
299
+ }
300
+ return { text: result.text };
301
+ }
302
+ }
303
+ //# sourceMappingURL=cli_agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli_agent.js","s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,CAAC;QAC3C,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;CACJ"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * CliAgent chat-loop helper — the prompt for one CLI turn.
3
+ *
4
+ * CLI wrappers (Cursor, etc.) do not keep an in-process LLM message array the way API LlmAgents
5
+ * do. Continuity is: the daemon's transcript (and, after a wait on a Hug, the answers) on Invoke →
6
+ * build_cli_turn_prompt → one binary turn → optionally a `cliq_hug` fence or `QUESTION:` line →
7
+ * ctx.ask (yield) → cliqd re-invokes when people answer.
8
+ *
9
+ * The allowed ways to end a turn are shared with LlmAgent (`hug/llm.ts`).
10
+ */
11
+ /** Inputs for {@link build_cli_turn_prompt}: the base prompt plus what to replay from earlier turns. */
12
+ export interface CliPromptParts {
13
+ readonly prompt: string;
14
+ readonly messages: ReadonlyArray<{
15
+ role: string;
16
+ content: string;
17
+ }>;
18
+ /** The answers to the turn's ask, when this invoke resumes after one (`answers_message`). */
19
+ readonly answers?: string | null;
20
+ /** The allowed endings for this phase (`allowed_response_instruction`; default: the `form` one). */
21
+ readonly instruction?: string;
22
+ }
23
+ /**
24
+ * Build the text handed to the CLI binary for this turn.
25
+ * Fresh start: base prompt + the allowed endings.
26
+ * Resume: base + transcript + the answers + the allowed endings.
27
+ */
28
+ export declare function build_cli_turn_prompt(parts: CliPromptParts): string;
29
+ //# sourceMappingURL=cli_rehydrate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli_rehydrate.d.ts","sourceRoot":"","sources":["../../src/agents/cli_rehydrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,wGAAwG;AACxG,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACpE,6FAA6F;IAC7F,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,oGAAoG;IACpG,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAgBnE"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * CliAgent chat-loop helper — the prompt for one CLI turn.
3
+ *
4
+ * CLI wrappers (Cursor, etc.) do not keep an in-process LLM message array the way API LlmAgents
5
+ * do. Continuity is: the daemon's transcript (and, after a wait on a Hug, the answers) on Invoke →
6
+ * build_cli_turn_prompt → one binary turn → optionally a `cliq_hug` fence or `QUESTION:` line →
7
+ * ctx.ask (yield) → cliqd re-invokes when people answer.
8
+ *
9
+ * The allowed ways to end a turn are shared with LlmAgent (`hug/llm.ts`).
10
+ */
11
+ import { CLIQ_ALLOWED_RESPONSE_INSTRUCTION } from '../hug/llm.js';
12
+ /**
13
+ * Build the text handed to the CLI binary for this turn.
14
+ * Fresh start: base prompt + the allowed endings.
15
+ * Resume: base + transcript + the answers + the allowed endings.
16
+ */
17
+ export function build_cli_turn_prompt(parts) {
18
+ const sections = [];
19
+ const base = parts.prompt.trim();
20
+ if (base)
21
+ sections.push(base);
22
+ if (parts.messages.length > 0) {
23
+ const lines = parts.messages.map((m) => `### ${m.role}\n${m.content}`);
24
+ sections.push(['## Phase transcript (prior turns)', '', ...lines].join('\n'));
25
+ }
26
+ if (parts.answers) {
27
+ sections.push(`## You asked; the answers\n\n${parts.answers}\n\nContinue the task with these answers.`);
28
+ }
29
+ sections.push(parts.instruction ?? CLIQ_ALLOWED_RESPONSE_INSTRUCTION);
30
+ return sections.join('\n\n');
31
+ }
32
+ //# sourceMappingURL=cli_rehydrate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli_rehydrate.js","sourceRoot":"","sources":["../../src/agents/cli_rehydrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,iCAAiC,EAAE,MAAM,eAAe,CAAC;AAYlE;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAqB;IAC1D,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IACjC,IAAI,IAAI;QAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE9B,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QACvE,QAAQ,CAAC,IAAI,CAAC,CAAC,mCAAmC,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/E,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QACnB,QAAQ,CAAC,IAAI,CAAC,gCAAgC,KAAK,CAAC,OAAO,2CAA2C,CAAC,CAAC;IACzG,CAAC;IAED,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,IAAI,iCAAiC,CAAC,CAAC;IACtE,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * ConnectorAgent — base class for external system connectors
3
+ * (jira, zendesk, gdrive, s3, etc.).
4
+ *
5
+ * No filesystem paths. Connectors talk to external APIs — they
6
+ * receive data via upstream and return data via complete.
7
+ */
8
+ import type { Invoke } from '../protocol/types/index.js';
9
+ import { StandardAgent } from './standard_agent.js';
10
+ import type { EventPoster } from './base_agent.js';
11
+ import type { ConnectorContext, AgentOutput } from './types.js';
12
+ /**
13
+ * Base class for connectors. Its context adds `action`, normalized `sources` /
14
+ * `targets` from the invoke config, and `record_call(ok)` for call-count usage.
15
+ */
16
+ export declare abstract class ConnectorAgent extends StandardAgent {
17
+ protected build_context(invoke: Invoke, post_event: EventPoster, transport?: import('./base_agent.js').AgentDaemonTransport): ConnectorContext;
18
+ protected abstract on_invoke(ctx: ConnectorContext): Promise<AgentOutput | void>;
19
+ }
20
+ //# sourceMappingURL=connector_agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connector_agent.d.ts","sourceRoot":"","sources":["../../src/agents/connector_agent.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAkB,MAAM,YAAY,CAAC;AAGhF;;;GAGG;AACH,8BAAsB,cAAe,SAAQ,aAAa;cACnC,aAAa,CAC5B,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,WAAW,EACvB,SAAS,CAAC,EAAE,OAAO,iBAAiB,EAAE,oBAAoB,GAC3D,gBAAgB;uBAwES,SAAS,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;CAC5F"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * ConnectorAgent — base class for external system connectors
3
+ * (jira, zendesk, gdrive, s3, etc.).
4
+ *
5
+ * No filesystem paths. Connectors talk to external APIs — they
6
+ * receive data via upstream and return data via complete.
7
+ */
8
+ import { StandardAgent } from './standard_agent.js';
9
+ import { report_usage } from '../telemetry/usage.js';
10
+ /**
11
+ * Base class for connectors. Its context adds `action`, normalized `sources` /
12
+ * `targets` from the invoke config, and `record_call(ok)` for call-count usage.
13
+ */
14
+ export class ConnectorAgent extends StandardAgent {
15
+ build_context(invoke, post_event, transport) {
16
+ const standard = super.build_context(invoke, post_event, transport);
17
+ const config = invoke.config;
18
+ const action = String(config['action'] ?? 'default');
19
+ const raw_sources = config['sources'];
20
+ const sources = Array.isArray(raw_sources)
21
+ ? raw_sources.map(normalize_source)
22
+ : [];
23
+ // team.yml names them `target_entries`; `targets` kept for older files.
24
+ const raw_targets = config['target_entries'] ?? config['targets'];
25
+ const targets = Array.isArray(raw_targets)
26
+ ? raw_targets.map(normalize_target)
27
+ : [];
28
+ // Auto-usage: connectors call ctx.record_call(ok) for each
29
+ // external API hit; on complete/error we emit a single usage
30
+ // record with unit_kind='calls'. The daemon also synthesises
31
+ // a baseline record so omitting record_call still produces
32
+ // per-agent telemetry — this path just enriches it.
33
+ const stats = { requests: 0, successes: 0 };
34
+ const started_at_unix_ms = Date.now();
35
+ const provider = this.name;
36
+ const action_label = action;
37
+ let usage_reported = false;
38
+ const report_now = (outcome) => {
39
+ if (usage_reported)
40
+ return;
41
+ if (stats.requests === 0)
42
+ return;
43
+ usage_reported = true;
44
+ const ended_at_unix_ms = Date.now();
45
+ void report_usage({
46
+ agent_kind: 'connector',
47
+ provider,
48
+ started_at_unix_ms,
49
+ ended_at_unix_ms,
50
+ duration_ms: Math.max(0, ended_at_unix_ms - started_at_unix_ms),
51
+ outcome,
52
+ unit_kind: 'calls',
53
+ units_in: stats.requests,
54
+ units_out: stats.successes,
55
+ external_calls: stats.requests,
56
+ extras: { 'connector.action': action_label },
57
+ });
58
+ };
59
+ const original_complete = standard.complete;
60
+ const original_error = standard.error;
61
+ return {
62
+ ...standard,
63
+ action,
64
+ sources,
65
+ targets,
66
+ credentials: standard.settings,
67
+ record_call: (ok) => {
68
+ stats.requests += 1;
69
+ if (ok)
70
+ stats.successes += 1;
71
+ },
72
+ complete: (output) => {
73
+ report_now('success');
74
+ original_complete(output);
75
+ },
76
+ error: (code, message) => {
77
+ report_now('failure');
78
+ original_error(code, message);
79
+ },
80
+ };
81
+ }
82
+ }
83
+ function normalize_source(raw) {
84
+ if (typeof raw === 'string')
85
+ return { ref: raw, name: raw };
86
+ if (raw && typeof raw === 'object') {
87
+ const obj = raw;
88
+ return {
89
+ ...obj, // url, headers, method, body … stay available to the connector
90
+ ref: String(obj['ref'] ?? obj['name'] ?? ''),
91
+ name: String(obj['name'] ?? obj['ref'] ?? ''),
92
+ };
93
+ }
94
+ return { ref: String(raw), name: String(raw) };
95
+ }
96
+ function normalize_target(raw) {
97
+ if (typeof raw === 'string')
98
+ return { ref: raw, name: raw };
99
+ if (raw && typeof raw === 'object') {
100
+ const obj = raw;
101
+ return {
102
+ ...obj, // url, headers, method, title, mode … stay available to the connector
103
+ ref: String(obj['ref'] ?? obj['name'] ?? ''),
104
+ name: String(obj['name'] ?? obj['ref'] ?? ''),
105
+ ...(obj['file'] ? { file: String(obj['file']) } : {}),
106
+ };
107
+ }
108
+ return { ref: String(raw), name: String(raw) };
109
+ }
110
+ //# sourceMappingURL=connector_agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connector_agent.js","sourceRoot":"","sources":["../../src/agents/connector_agent.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD;;;GAGG;AACH,MAAM,OAAgB,cAAe,SAAQ,aAAa;IACnC,aAAa,CAC5B,MAAc,EACd,UAAuB,EACvB,SAA0D;QAE1D,MAAM,QAAQ,GAAG,KAAK,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;QACpE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAiC,CAAC;QAExD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,SAAS,CAAC,CAAC;QAErD,MAAM,WAAW,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;QACtC,MAAM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M,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;SAChD,CAAC;IACN,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;AACnD,CAAC;AAED,SAAS,gBAAgB,CAAC,GAAY;IAClC,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;IAC5D,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QACjC,MAAM,GAAG,GAAG,GAA8B,CAAC;QAC3C,OAAO;YACH,GAAG,GAAG,EAAE,sEAAsE;YAC9E,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YAC5C,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YAC7C,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACxD,CAAC;IACN,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;AACnD,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Artifacts attached to catalog event payloads (Yamazaki W13).
3
+ *
4
+ * Top-level `artifacts` on any event packet. Daemon materializes to
5
+ * local + Hub `run_artifacts`; notify/review packets keep thin refs.
6
+ */
7
+ /** Workspace file referenced by path (relative to workspace root). */
8
+ export interface EventArtifactRef {
9
+ path: string;
10
+ label?: string;
11
+ mime?: string;
12
+ }
13
+ /** Inline body already in memory (no filesystem read). */
14
+ export interface EventArtifactInline {
15
+ name: string;
16
+ content: string;
17
+ kind?: 'design' | 'review' | 'handoff' | 'output';
18
+ mime?: string;
19
+ }
20
+ /** An artifact on an event: a workspace file ref or an inline body. */
21
+ export type EventArtifact = EventArtifactRef | EventArtifactInline;
22
+ /** True when the artifact points at a workspace file. */
23
+ export declare function is_event_artifact_ref(value: EventArtifact): value is EventArtifactRef;
24
+ /** True when the artifact carries its body inline (and is not a ref). */
25
+ export declare function is_event_artifact_inline(value: EventArtifact): value is EventArtifactInline;
26
+ /**
27
+ * Normalize unknown payload.artifacts into EventArtifact[].
28
+ * Invalid entries are dropped.
29
+ */
30
+ export declare function normalize_event_artifacts(raw: unknown): EventArtifact[];
31
+ /** Lift artifacts from event payload or nested output.artifacts. */
32
+ export declare function artifacts_from_event_payload(payload: unknown): EventArtifact[];
33
+ //# sourceMappingURL=event_artifacts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event_artifacts.d.ts","sourceRoot":"","sources":["../../src/agents/event_artifacts.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,sEAAsE;AACtE,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,0DAA0D;AAC1D,MAAM,WAAW,mBAAmB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;IAClD,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,uEAAuE;AACvE,MAAM,MAAM,aAAa,GAAG,gBAAgB,GAAG,mBAAmB,CAAC;AAEnE,yDAAyD;AACzD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,aAAa,GAAG,KAAK,IAAI,gBAAgB,CAErF;AAED,yEAAyE;AACzE,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,aAAa,GAAG,KAAK,IAAI,mBAAmB,CAI3F;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,OAAO,GAAG,aAAa,EAAE,CASvE;AAyBD,oEAAoE;AACpE,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,OAAO,GAAG,aAAa,EAAE,CAQ9E"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Artifacts attached to catalog event payloads (Yamazaki W13).
3
+ *
4
+ * Top-level `artifacts` on any event packet. Daemon materializes to
5
+ * local + Hub `run_artifacts`; notify/review packets keep thin refs.
6
+ */
7
+ /** True when the artifact points at a workspace file. */
8
+ export function is_event_artifact_ref(value) {
9
+ return typeof value?.path === 'string';
10
+ }
11
+ /** True when the artifact carries its body inline (and is not a ref). */
12
+ export function is_event_artifact_inline(value) {
13
+ if (is_event_artifact_ref(value))
14
+ return false;
15
+ const row = value;
16
+ return typeof row.name === 'string' && typeof row.content === 'string';
17
+ }
18
+ /**
19
+ * Normalize unknown payload.artifacts into EventArtifact[].
20
+ * Invalid entries are dropped.
21
+ */
22
+ export function normalize_event_artifacts(raw) {
23
+ if (!Array.isArray(raw))
24
+ return [];
25
+ const out = [];
26
+ for (const item of raw) {
27
+ if (!item || typeof item !== 'object')
28
+ continue;
29
+ const artifact = to_event_artifact(item);
30
+ if (artifact)
31
+ out.push(artifact);
32
+ }
33
+ return out;
34
+ }
35
+ /** Inline artifact kinds accepted from payloads; anything else is left unset. */
36
+ const INLINE_KINDS = new Set(['design', 'review', 'handoff', 'output']);
37
+ /** One payload entry as a ref (non-blank `path` wins) or an inline body, or null when it is neither. */
38
+ function to_event_artifact(row) {
39
+ if (typeof row.path === 'string' && row.path.trim()) {
40
+ const ref = { path: row.path.trim() };
41
+ if (typeof row.label === 'string')
42
+ ref.label = row.label;
43
+ if (typeof row.mime === 'string')
44
+ ref.mime = row.mime;
45
+ return ref;
46
+ }
47
+ if (typeof row.name === 'string' && row.name.trim() && typeof row.content === 'string') {
48
+ const inline = {
49
+ name: row.name.trim(),
50
+ content: row.content,
51
+ };
52
+ if (typeof row.mime === 'string')
53
+ inline.mime = row.mime;
54
+ if (INLINE_KINDS.has(row.kind))
55
+ inline.kind = row.kind;
56
+ return inline;
57
+ }
58
+ return null;
59
+ }
60
+ /** Lift artifacts from event payload or nested output.artifacts. */
61
+ export function artifacts_from_event_payload(payload) {
62
+ if (!payload || typeof payload !== 'object')
63
+ return [];
64
+ const row = payload;
65
+ const top = normalize_event_artifacts(row.artifacts);
66
+ if (top.length > 0)
67
+ return top;
68
+ const output = row.output;
69
+ if (!output || typeof output !== 'object')
70
+ return [];
71
+ return normalize_event_artifacts(output.artifacts);
72
+ }
73
+ //# sourceMappingURL=event_artifacts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event_artifacts.js","sourceRoot":"","sources":["../../src/agents/event_artifacts.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAoBH,yDAAyD;AACzD,MAAM,UAAU,qBAAqB,CAAC,KAAoB;IACzD,OAAO,OAAQ,KAA0B,EAAE,IAAI,KAAK,QAAQ,CAAC;AAC9D,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,wBAAwB,CAAC,KAAoB;IAC5D,IAAI,qBAAqB,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC/C,MAAM,GAAG,GAAG,KAA4B,CAAC;IACzC,OAAO,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,CAAC;AACxE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,GAAY;IACrD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,OAAO,EAAE,CAAC;IACnC,MAAM,GAAG,GAAoB,EAAE,CAAC;IAChC,KAAK,MAAM,IAA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