zelio-cli 0.0.0-stage → 0.1.0-beta.10

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 (223) hide show
  1. package/README.md +71 -2
  2. package/dist/attachments.js +121 -0
  3. package/dist/attachments.js.map +1 -0
  4. package/dist/cli-main.js +521 -0
  5. package/dist/cli-main.js.map +1 -0
  6. package/dist/cli.js +22 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/cloud/account.js +109 -0
  9. package/dist/cloud/account.js.map +1 -0
  10. package/dist/cloud/board.js +311 -0
  11. package/dist/cloud/board.js.map +1 -0
  12. package/dist/cloud/command.js +265 -0
  13. package/dist/cloud/command.js.map +1 -0
  14. package/dist/cloud/config.js +132 -0
  15. package/dist/cloud/config.js.map +1 -0
  16. package/dist/cloud/credentials.js +134 -0
  17. package/dist/cloud/credentials.js.map +1 -0
  18. package/dist/cloud/login.js +166 -0
  19. package/dist/cloud/login.js.map +1 -0
  20. package/dist/cloud/pair.js +110 -0
  21. package/dist/cloud/pair.js.map +1 -0
  22. package/dist/cloud/pkce.js +16 -0
  23. package/dist/cloud/pkce.js.map +1 -0
  24. package/dist/cloud/push-nudge.js +65 -0
  25. package/dist/cloud/push-nudge.js.map +1 -0
  26. package/dist/cloud/relay.js +134 -0
  27. package/dist/cloud/relay.js.map +1 -0
  28. package/dist/cloud/token.js +66 -0
  29. package/dist/cloud/token.js.map +1 -0
  30. package/dist/cloud/tunnel.js +474 -0
  31. package/dist/cloud/tunnel.js.map +1 -0
  32. package/dist/db/db.js +1838 -0
  33. package/dist/db/db.js.map +1 -0
  34. package/dist/db/lifecycle.js +146 -0
  35. package/dist/db/lifecycle.js.map +1 -0
  36. package/dist/limits.js +35 -0
  37. package/dist/limits.js.map +1 -0
  38. package/dist/metrics.js +30 -0
  39. package/dist/metrics.js.map +1 -0
  40. package/dist/orchestrator/area-notes.js +87 -0
  41. package/dist/orchestrator/area-notes.js.map +1 -0
  42. package/dist/orchestrator/claude-session.js +208 -0
  43. package/dist/orchestrator/claude-session.js.map +1 -0
  44. package/dist/orchestrator/codex-session.js +327 -0
  45. package/dist/orchestrator/codex-session.js.map +1 -0
  46. package/dist/orchestrator/contract.js +189 -0
  47. package/dist/orchestrator/contract.js.map +1 -0
  48. package/dist/orchestrator/explore.js +176 -0
  49. package/dist/orchestrator/explore.js.map +1 -0
  50. package/dist/orchestrator/new-task-prompt.js +51 -0
  51. package/dist/orchestrator/new-task-prompt.js.map +1 -0
  52. package/dist/orchestrator/pi-session.js +234 -0
  53. package/dist/orchestrator/pi-session.js.map +1 -0
  54. package/dist/orchestrator/prompt.js +110 -0
  55. package/dist/orchestrator/prompt.js.map +1 -0
  56. package/dist/orchestrator/research.js +193 -0
  57. package/dist/orchestrator/research.js.map +1 -0
  58. package/dist/orchestrator/retrieval.js +333 -0
  59. package/dist/orchestrator/retrieval.js.map +1 -0
  60. package/dist/orchestrator/runtime.js +1217 -0
  61. package/dist/orchestrator/runtime.js.map +1 -0
  62. package/dist/orchestrator/session.js +2 -0
  63. package/dist/orchestrator/session.js.map +1 -0
  64. package/dist/orchestrator/types.js +2 -0
  65. package/dist/orchestrator/types.js.map +1 -0
  66. package/dist/orchestrator/web.js +276 -0
  67. package/dist/orchestrator/web.js.map +1 -0
  68. package/dist/repo/code-map.js +152 -0
  69. package/dist/repo/code-map.js.map +1 -0
  70. package/dist/repo/index.js +188 -0
  71. package/dist/repo/index.js.map +1 -0
  72. package/dist/repo/instructions.js +58 -0
  73. package/dist/repo/instructions.js.map +1 -0
  74. package/dist/repo/linked-boards.js +149 -0
  75. package/dist/repo/linked-boards.js.map +1 -0
  76. package/dist/repo/project-repos.js +78 -0
  77. package/dist/repo/project-repos.js.map +1 -0
  78. package/dist/run/actions.js +257 -0
  79. package/dist/run/actions.js.map +1 -0
  80. package/dist/run/auto-review.js +116 -0
  81. package/dist/run/auto-review.js.map +1 -0
  82. package/dist/run/bash-guard.js +183 -0
  83. package/dist/run/bash-guard.js.map +1 -0
  84. package/dist/run/claude-runtime.js +284 -0
  85. package/dist/run/claude-runtime.js.map +1 -0
  86. package/dist/run/claude-stream.js +306 -0
  87. package/dist/run/claude-stream.js.map +1 -0
  88. package/dist/run/codex-client.js +213 -0
  89. package/dist/run/codex-client.js.map +1 -0
  90. package/dist/run/codex-planner-config.js +26 -0
  91. package/dist/run/codex-planner-config.js.map +1 -0
  92. package/dist/run/codex-runtime.js +469 -0
  93. package/dist/run/codex-runtime.js.map +1 -0
  94. package/dist/run/consult.js +109 -0
  95. package/dist/run/consult.js.map +1 -0
  96. package/dist/run/context.js +87 -0
  97. package/dist/run/context.js.map +1 -0
  98. package/dist/run/developer-sandbox.js +67 -0
  99. package/dist/run/developer-sandbox.js.map +1 -0
  100. package/dist/run/diff.js +238 -0
  101. package/dist/run/diff.js.map +1 -0
  102. package/dist/run/evidence.js +48 -0
  103. package/dist/run/evidence.js.map +1 -0
  104. package/dist/run/finish.js +430 -0
  105. package/dist/run/finish.js.map +1 -0
  106. package/dist/run/handoff.js +51 -0
  107. package/dist/run/handoff.js.map +1 -0
  108. package/dist/run/harness-runtime.js +31 -0
  109. package/dist/run/harness-runtime.js.map +1 -0
  110. package/dist/run/harnesses.js +293 -0
  111. package/dist/run/harnesses.js.map +1 -0
  112. package/dist/run/issue.js +79 -0
  113. package/dist/run/issue.js.map +1 -0
  114. package/dist/run/keep-awake.js +58 -0
  115. package/dist/run/keep-awake.js.map +1 -0
  116. package/dist/run/lead.js +183 -0
  117. package/dist/run/lead.js.map +1 -0
  118. package/dist/run/manager.js +2737 -0
  119. package/dist/run/manager.js.map +1 -0
  120. package/dist/run/mentions.js +35 -0
  121. package/dist/run/mentions.js.map +1 -0
  122. package/dist/run/merge-watch.js +425 -0
  123. package/dist/run/merge-watch.js.map +1 -0
  124. package/dist/run/models.js +88 -0
  125. package/dist/run/models.js.map +1 -0
  126. package/dist/run/phases.js +23 -0
  127. package/dist/run/phases.js.map +1 -0
  128. package/dist/run/pi-packages.js +72 -0
  129. package/dist/run/pi-packages.js.map +1 -0
  130. package/dist/run/pi-rpc.js +464 -0
  131. package/dist/run/pi-rpc.js.map +1 -0
  132. package/dist/run/piped-check.js +56 -0
  133. package/dist/run/piped-check.js.map +1 -0
  134. package/dist/run/pr-checks.js +67 -0
  135. package/dist/run/pr-checks.js.map +1 -0
  136. package/dist/run/pr-merge.js +121 -0
  137. package/dist/run/pr-merge.js.map +1 -0
  138. package/dist/run/profiles.js +43 -0
  139. package/dist/run/profiles.js.map +1 -0
  140. package/dist/run/prompt.js +405 -0
  141. package/dist/run/prompt.js.map +1 -0
  142. package/dist/run/pull-request.js +23 -0
  143. package/dist/run/pull-request.js.map +1 -0
  144. package/dist/run/red-check.js +130 -0
  145. package/dist/run/red-check.js.map +1 -0
  146. package/dist/run/result-tool.js +93 -0
  147. package/dist/run/result-tool.js.map +1 -0
  148. package/dist/run/result.js +113 -0
  149. package/dist/run/result.js.map +1 -0
  150. package/dist/run/retro.js +346 -0
  151. package/dist/run/retro.js.map +1 -0
  152. package/dist/run/settings.js +28 -0
  153. package/dist/run/settings.js.map +1 -0
  154. package/dist/run/skills.js +146 -0
  155. package/dist/run/skills.js.map +1 -0
  156. package/dist/run/tests-first.js +146 -0
  157. package/dist/run/tests-first.js.map +1 -0
  158. package/dist/run/thinking.js +41 -0
  159. package/dist/run/thinking.js.map +1 -0
  160. package/dist/run/types.js +2 -0
  161. package/dist/run/types.js.map +1 -0
  162. package/dist/run/watchdog.js +266 -0
  163. package/dist/run/watchdog.js.map +1 -0
  164. package/dist/run/workflow.js +277 -0
  165. package/dist/run/workflow.js.map +1 -0
  166. package/dist/run/worktree.js +354 -0
  167. package/dist/run/worktree.js.map +1 -0
  168. package/dist/server/app.js +3286 -0
  169. package/dist/server/app.js.map +1 -0
  170. package/dist/server/auth.js +93 -0
  171. package/dist/server/auth.js.map +1 -0
  172. package/dist/server/demo.js +96 -0
  173. package/dist/server/demo.js.map +1 -0
  174. package/dist/server/idempotency.js +104 -0
  175. package/dist/server/idempotency.js.map +1 -0
  176. package/dist/server/port.js +36 -0
  177. package/dist/server/port.js.map +1 -0
  178. package/dist/server/principal.js +93 -0
  179. package/dist/server/principal.js.map +1 -0
  180. package/dist/server/provider-auth.js +206 -0
  181. package/dist/server/provider-auth.js.map +1 -0
  182. package/dist/server/repo-picker.js +18 -0
  183. package/dist/server/repo-picker.js.map +1 -0
  184. package/dist/server/terminal.js +285 -0
  185. package/dist/server/terminal.js.map +1 -0
  186. package/dist/setup/components.js +98 -0
  187. package/dist/setup/components.js.map +1 -0
  188. package/dist/setup/config.js +71 -0
  189. package/dist/setup/config.js.map +1 -0
  190. package/dist/setup/ink-ui.js +189 -0
  191. package/dist/setup/ink-ui.js.map +1 -0
  192. package/dist/setup/onboarding.js +157 -0
  193. package/dist/setup/onboarding.js.map +1 -0
  194. package/dist/setup/run.js +69 -0
  195. package/dist/setup/run.js.map +1 -0
  196. package/dist/skills.js +151 -0
  197. package/dist/skills.js.map +1 -0
  198. package/dist/ticket-cli.js +157 -0
  199. package/dist/ticket-cli.js.map +1 -0
  200. package/dist/version.js +13 -0
  201. package/dist/version.js.map +1 -0
  202. package/dist/voice/index.js +69 -0
  203. package/dist/voice/index.js.map +1 -0
  204. package/dist/voice/moonshine.js +247 -0
  205. package/dist/voice/moonshine.js.map +1 -0
  206. package/dist/voice/wav.js +54 -0
  207. package/dist/voice/wav.js.map +1 -0
  208. package/dist/voice/whisper.js +491 -0
  209. package/dist/voice/whisper.js.map +1 -0
  210. package/dist/web/assets/index-TN5sUF2z.css +1 -0
  211. package/dist/web/assets/index-vB3Cucuc.js +258 -0
  212. package/dist/web/icons/apple-touch-icon.png +0 -0
  213. package/dist/web/icons/icon-192.png +0 -0
  214. package/dist/web/icons/icon-512.png +0 -0
  215. package/dist/web/icons/maskable-512.png +0 -0
  216. package/dist/web/index.html +21 -0
  217. package/dist/web/manifest.webmanifest +30 -0
  218. package/dist/web/sw.js +185 -0
  219. package/media/board.png +0 -0
  220. package/media/mobile.png +0 -0
  221. package/media/new-task.png +0 -0
  222. package/media/review.png +0 -0
  223. package/package.json +105 -4
package/dist/skills.js ADDED
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Skills are reusable guidance a person keeps on the board. This module holds
3
+ * the field rules and the GitHub import, so the routes and the tests read the
4
+ * same limits.
5
+ */
6
+ export const MAX_SKILL_NAME_CHARS = 80;
7
+ export const MAX_SKILL_TEXT_CHARS = 50_000;
8
+ /** A skill file bigger than this is not guidance a run can read; refuse it. */
9
+ export const MAX_SKILL_IMPORT_CHARS = 200_000;
10
+ const IMPORT_TIMEOUT_MS = 10_000;
11
+ const MAX_IMPORT_REDIRECTS = 3;
12
+ export function checkSkillName(value) {
13
+ const name = typeof value === "string" ? value.trim() : "";
14
+ if (!name)
15
+ return { ok: false, error: "name is required" };
16
+ if (name.length > MAX_SKILL_NAME_CHARS) {
17
+ return { ok: false, error: `name is limited to ${MAX_SKILL_NAME_CHARS} characters` };
18
+ }
19
+ return { ok: true, value: name };
20
+ }
21
+ /** The text is stored as written, so an imported file keeps its own newlines. */
22
+ export function checkSkillText(value) {
23
+ const text = typeof value === "string" ? value : "";
24
+ if (!text.trim())
25
+ return { ok: false, error: "text is required" };
26
+ if (text.length > MAX_SKILL_TEXT_CHARS) {
27
+ return { ok: false, error: `text is limited to ${MAX_SKILL_TEXT_CHARS} characters` };
28
+ }
29
+ return { ok: true, value: text };
30
+ }
31
+ /** The only hosts a skill may be loaded from. Anything else is refused. */
32
+ const GITHUB_HOSTS = new Set(["github.com", "raw.githubusercontent.com"]);
33
+ function safeDecode(part) {
34
+ try {
35
+ return decodeURIComponent(part);
36
+ }
37
+ catch {
38
+ return part;
39
+ }
40
+ }
41
+ /**
42
+ * Turns a github.com /blob/ link or a raw.githubusercontent.com link into the
43
+ * raw address of the file. Repository, folder and non-https links are refused
44
+ * here, before any request leaves the server.
45
+ */
46
+ export function githubSkillLink(input) {
47
+ const pasted = typeof input === "string" ? input.trim() : "";
48
+ if (!pasted)
49
+ return { ok: false, error: "paste a GitHub link to a skill file" };
50
+ let url;
51
+ try {
52
+ url = new URL(pasted);
53
+ }
54
+ catch {
55
+ return { ok: false, error: "that is not a web link" };
56
+ }
57
+ if (url.protocol !== "https:")
58
+ return { ok: false, error: "the link must start with https://" };
59
+ if (!GITHUB_HOSTS.has(url.hostname)) {
60
+ return {
61
+ ok: false,
62
+ error: "only github.com and raw.githubusercontent.com links can load a skill",
63
+ };
64
+ }
65
+ // The segments stay percent-encoded: they go into the raw address as they are.
66
+ const parts = url.pathname.split("/").filter(Boolean);
67
+ let fileParts;
68
+ let rawParts;
69
+ if (url.hostname === "github.com") {
70
+ // /owner/repo/blob/ref/path/to/file
71
+ if (parts.length < 5 || parts[2] !== "blob") {
72
+ return {
73
+ ok: false,
74
+ error: "link a file on GitHub (a /blob/ link), not a repository or folder",
75
+ };
76
+ }
77
+ fileParts = parts.slice(4);
78
+ rawParts = [parts[0], parts[1], parts[3], ...fileParts];
79
+ }
80
+ else {
81
+ // /owner/repo/ref/path/to/file
82
+ if (parts.length < 4) {
83
+ return { ok: false, error: "link a file on raw.githubusercontent.com, not a folder" };
84
+ }
85
+ fileParts = parts.slice(3);
86
+ rawParts = parts;
87
+ }
88
+ const rawUrl = `https://raw.githubusercontent.com/${rawParts.join("/")}`;
89
+ const decoded = fileParts.map(safeDecode);
90
+ const file = decoded[decoded.length - 1] ?? "";
91
+ const folder = decoded.length > 1 ? decoded[decoded.length - 2] : "";
92
+ const stem = file.replace(/\.md$/i, "");
93
+ const picked = /^skill$/i.test(stem) && folder ? folder : stem;
94
+ const name = picked.slice(0, MAX_SKILL_NAME_CHARS).trim() || safeDecode(parts[1] ?? "") || "skill";
95
+ return { ok: true, value: { source: pasted, rawUrl, name } };
96
+ }
97
+ /**
98
+ * Reads the file's text from GitHub. The caller decides what to save; this only
99
+ * fetches. Redirects are followed by hand: a hop is requested only when its
100
+ * Location names a GitHub host, so the server never connects to any other host.
101
+ */
102
+ export async function fetchSkillText(rawUrl, fetchImpl = fetch) {
103
+ let response;
104
+ let current = rawUrl;
105
+ try {
106
+ for (let hop = 0;; hop += 1) {
107
+ response = await fetchImpl(current, {
108
+ redirect: "manual",
109
+ signal: AbortSignal.timeout(IMPORT_TIMEOUT_MS),
110
+ });
111
+ if (response.status < 300 || response.status > 399)
112
+ break;
113
+ const location = response.headers.get("location");
114
+ if (!location || hop >= MAX_IMPORT_REDIRECTS) {
115
+ return { ok: false, status: 502, error: "GitHub redirected that file too often" };
116
+ }
117
+ const next = new URL(location, current);
118
+ if (next.protocol !== "https:" || !GITHUB_HOSTS.has(next.hostname)) {
119
+ return {
120
+ ok: false,
121
+ status: 502,
122
+ error: "GitHub sent that file somewhere other than GitHub",
123
+ };
124
+ }
125
+ current = next.href;
126
+ }
127
+ }
128
+ catch {
129
+ return { ok: false, status: 502, error: "could not reach GitHub to load that file" };
130
+ }
131
+ if (response.status === 404) {
132
+ return { ok: false, status: 404, error: "GitHub has no file at that link" };
133
+ }
134
+ if (!response.ok) {
135
+ return { ok: false, status: 502, error: `GitHub answered ${response.status} for that file` };
136
+ }
137
+ let text;
138
+ try {
139
+ text = await response.text();
140
+ }
141
+ catch {
142
+ return { ok: false, status: 502, error: "could not read the file from GitHub" };
143
+ }
144
+ if (text.length > MAX_SKILL_IMPORT_CHARS) {
145
+ return { ok: false, status: 413, error: "that file is too large to load as a skill" };
146
+ }
147
+ if (!text.trim())
148
+ return { ok: false, status: 422, error: "that file is empty" };
149
+ return { ok: true, value: { text } };
150
+ }
151
+ //# sourceMappingURL=skills.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skills.js","sourceRoot":"","sources":["../src/skills.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AACvC,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAC3C,+EAA+E;AAC/E,MAAM,CAAC,MAAM,sBAAsB,GAAG,OAAO,CAAC;AAC9C,M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AC"}
@@ -0,0 +1,157 @@
1
+ /**
2
+ * The agent's CLI inside a ticket worktree. It talks to the board over HTTP
3
+ * with the per-run token in the environment; it never opens the database and
4
+ * cannot comment on another ticket.
5
+ */
6
+ import { reportResultFile } from "./run/result-tool.js";
7
+ const USAGE = `Usage:
8
+ zelio ticket comment <ticket-id> --type <comment|decision|blocker|done|review> --text "..."
9
+ zelio ticket report <ticket-id> --file <result.json>
10
+ zelio ticket status <ticket-id> --to <review|blocked> [--reason "..."]
11
+
12
+ Options:
13
+ --blocker-kind <decision|needs_human> required for blocker comments; defaults to decision
14
+ --reply-to <comment-id> link a reply to the comment it answers`;
15
+ function option(args, name) {
16
+ const index = args.indexOf(name);
17
+ return index === -1 ? undefined : args[index + 1];
18
+ }
19
+ function boardUrl(env) {
20
+ if (env.ZELIO_BOARD_URL)
21
+ return env.ZELIO_BOARD_URL.replace(/\/$/, "");
22
+ if (env.ZELIO_STATUS_URL) {
23
+ try {
24
+ return new URL(env.ZELIO_STATUS_URL).origin;
25
+ }
26
+ catch {
27
+ return undefined;
28
+ }
29
+ }
30
+ return undefined;
31
+ }
32
+ export async function ticketCommand(argv, env = process.env) {
33
+ const [subcommand, ticketId, ...rest] = argv;
34
+ if (subcommand === "report" && ticketId) {
35
+ const file = option(rest, "--file");
36
+ if (!file) {
37
+ console.error("--file must name a JSON result report");
38
+ return 1;
39
+ }
40
+ if (env.ZELIO_TICKET_ID !== ticketId) {
41
+ console.error("this report must belong to the active ticket run");
42
+ return 1;
43
+ }
44
+ try {
45
+ await reportResultFile(file, env);
46
+ return 0;
47
+ }
48
+ catch (error) {
49
+ console.error(error instanceof Error ? error.message : "result report failed");
50
+ return 1;
51
+ }
52
+ }
53
+ if (subcommand === "status" && ticketId)
54
+ return statusCommand(ticketId, rest, env);
55
+ if (subcommand !== "comment" || !ticketId) {
56
+ console.error(USAGE);
57
+ return 1;
58
+ }
59
+ const type = option(rest, "--type");
60
+ const text = option(rest, "--text");
61
+ const requestedKind = option(rest, "--blocker-kind");
62
+ const replyTo = option(rest, "--reply-to");
63
+ if (type !== "comment" &&
64
+ type !== "decision" &&
65
+ type !== "blocker" &&
66
+ type !== "done" &&
67
+ type !== "review") {
68
+ console.error("--type must be comment, decision, blocker, done or review");
69
+ return 1;
70
+ }
71
+ if (!text?.trim()) {
72
+ console.error("--text is required");
73
+ return 1;
74
+ }
75
+ if (type !== "blocker" && requestedKind !== undefined) {
76
+ console.error("--blocker-kind only applies to --type blocker");
77
+ return 1;
78
+ }
79
+ if (requestedKind !== undefined &&
80
+ requestedKind !== "decision" &&
81
+ requestedKind !== "needs_human") {
82
+ console.error("--blocker-kind must be decision or needs_human");
83
+ return 1;
84
+ }
85
+ const token = env.ZELIO_TICKET_TOKEN;
86
+ const board = boardUrl(env);
87
+ const ownTicket = env.ZELIO_TICKET_ID;
88
+ if (!token || !board) {
89
+ console.error("not inside a Zelio ticket run: ZELIO_TICKET_TOKEN and ZELIO_BOARD_URL are missing");
90
+ return 1;
91
+ }
92
+ if (ownTicket && ownTicket !== ticketId) {
93
+ console.error(`this run belongs to ${ownTicket}, not ${ticketId}`);
94
+ return 1;
95
+ }
96
+ const response = await fetch(`${board}/api/tickets/${encodeURIComponent(ticketId)}/agent-comments`, {
97
+ method: "POST",
98
+ headers: {
99
+ "x-zelio-ticket-token": token,
100
+ "content-type": "application/json",
101
+ },
102
+ body: JSON.stringify({
103
+ type,
104
+ text: text.trim(),
105
+ ...(replyTo ? { reply_to: replyTo } : {}),
106
+ ...(type === "blocker"
107
+ ? { blocker_kind: requestedKind ?? "decision" }
108
+ : {}),
109
+ }),
110
+ });
111
+ if (!response.ok) {
112
+ const body = (await response.json().catch(() => ({})));
113
+ console.error(body.error ?? `comment failed (${response.status})`);
114
+ return 1;
115
+ }
116
+ console.log(`Recorded ${type} comment on ${ticketId}.`);
117
+ return 0;
118
+ }
119
+ /**
120
+ * Moves the agent's own ticket to Review or Blocked. A board run normally ends
121
+ * its turn instead; this is for the agent a person took the ticket into.
122
+ */
123
+ async function statusCommand(ticketId, rest, env) {
124
+ const to = option(rest, "--to");
125
+ const reason = option(rest, "--reason")?.trim();
126
+ if (to !== "review" && to !== "blocked") {
127
+ console.error("--to must be review or blocked");
128
+ return 1;
129
+ }
130
+ if (to === "blocked" && !reason) {
131
+ console.error("--reason is required for blocked");
132
+ return 1;
133
+ }
134
+ const token = env.ZELIO_TICKET_TOKEN;
135
+ const board = boardUrl(env);
136
+ if (!token || !board) {
137
+ console.error("not inside a Zelio ticket: ZELIO_TICKET_TOKEN and ZELIO_BOARD_URL are missing");
138
+ return 1;
139
+ }
140
+ if (env.ZELIO_TICKET_ID && env.ZELIO_TICKET_ID !== ticketId) {
141
+ console.error(`this token belongs to ${env.ZELIO_TICKET_ID}, not ${ticketId}`);
142
+ return 1;
143
+ }
144
+ const response = await fetch(`${board}/api/tickets/${encodeURIComponent(ticketId)}/status`, {
145
+ method: "POST",
146
+ headers: { "x-zelio-ticket-token": token, "content-type": "application/json" },
147
+ body: JSON.stringify({ to, ...(reason ? { reason } : {}) }),
148
+ });
149
+ if (!response.ok) {
150
+ const body = (await response.json().catch(() => ({})));
151
+ console.error(body.error ?? `status failed (${response.status})`);
152
+ return 1;
153
+ }
154
+ console.log(`Moved ${ticketId} to ${to}.`);
155
+ return 0;
156
+ }
157
+ //# sourceMappingURL=ticket-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ticket-cli.js","sourceRoot":"","sources":["../src/ticket-cli.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAIxD,MAAM,KAAK,GAAG;;;;;;;iFAOmE,CAAC;AAElF,SAAS,MAAM,CAAC,IAAc,EAAE,IAAY;IAC1C,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CA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,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,KAAK,gBAAgB,kBAAkB,CAAC,QAAQ,CAAC,SAAS,EAAE;QAC1F,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,EAAE,sBAAsB,EAAE,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC9E,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;KAC5D,CAAC,CAAC;IACH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAuB,CAAC;QAC7E,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,kBAAkB,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;QAClE,OAAO,CAAC,CAAC;IACX,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,SAAS,QAAQ,OAAO,EAAE,GAAG,CAAC,CAAC;IAC3C,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ /** The version in the package.json that ships one level above `dir` (dist/ or src/). */
4
+ export function readPackageVersion(dir) {
5
+ try {
6
+ const manifest = JSON.parse(readFileSync(join(dir, "..", "package.json"), "utf8"));
7
+ return manifest.version ?? "unknown";
8
+ }
9
+ catch {
10
+ return "unknown";
11
+ }
12
+ }
13
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,wFAAwF;AACxF,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAEhF,CAAC;QACF,OAAO,QAAQ,CAAC,OAAO,IAAI,SAAS,CAAC;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
@@ -0,0 +1,69 @@
1
+ import { moonshineStatus } from "./moonshine.js";
2
+ import { createMoonshine } from "./moonshine.js";
3
+ import { createVoice as createWhisperVoice, } from "./whisper.js";
4
+ export * from "./whisper.js";
5
+ /**
6
+ * Which recognizer answers the microphone.
7
+ *
8
+ * Moonshine when it can: it is built for short utterances, so a phrase comes
9
+ * back in tens of milliseconds instead of about a second, and the field keeps
10
+ * up with the person. Whisper when Moonshine cannot run, when its model cannot
11
+ * be downloaded, or when `ZELIO_VOICE_ENGINE=whisper` says so — its text is
12
+ * better (promptable vocabulary, punctuation) and it is already installed on
13
+ * most machines that had voice working before this engine existed.
14
+ *
15
+ * The choice is made once and remembered, so a status probe and the turn it
16
+ * describes cannot disagree.
17
+ */
18
+ export function createVoice(options = {}) {
19
+ const whisper = createWhisperVoice(options);
20
+ const moonshine = createMoonshine();
21
+ let chosen = null;
22
+ const decide = async () => {
23
+ if (chosen)
24
+ return chosen;
25
+ if (process.env.ZELIO_VOICE_ENGINE?.trim() === "whisper") {
26
+ chosen = "whisper";
27
+ return chosen;
28
+ }
29
+ const status = await moonshineStatus();
30
+ chosen = status.ready || status.canPrepare ? "moonshine" : "whisper";
31
+ return chosen;
32
+ };
33
+ return {
34
+ status: async () => ((await decide()) === "moonshine" ? moonshine.status() : whisper.status()),
35
+ prepare: async () => {
36
+ if ((await decide()) === "moonshine") {
37
+ try {
38
+ return await moonshine.prepare();
39
+ }
40
+ catch (cause) {
41
+ // A failed download is not a reason to lose dictation: fall back to
42
+ // the recognizer that is already on the machine.
43
+ if ((await whisper.status()).ready) {
44
+ chosen = "whisper";
45
+ return whisper.status();
46
+ }
47
+ throw cause;
48
+ }
49
+ }
50
+ return whisper.prepare();
51
+ },
52
+ transcribe: async (wav) => {
53
+ if ((await decide()) === "moonshine") {
54
+ try {
55
+ return await moonshine.transcribe(wav);
56
+ }
57
+ catch (cause) {
58
+ if ((await whisper.status()).ready) {
59
+ chosen = "whisper";
60
+ return whisper.transcribe(wav);
61
+ }
62
+ throw cause;
63
+ }
64
+ }
65
+ return whisper.transcribe(wav);
66
+ },
67
+ };
68
+ }
69
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/voice/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EACL,WAAW,IAAI,kBAAkB,GAGlC,MAAM,cAAc,CAAC;AAEtB,cAAc,cAAc,CAAC;AAE7B;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAC,OAAO,GAAsB,EAAE;IACzD,MAAM,OAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC5C,MAAM,SAAS,GAAG,eAAe,EAAE,CAAC;IACpC,IAAI,MAAM,GAAmC,IAAI,CAAC;IAElD,MAAM,MAAM,GAAG,KAAK,IAAsC,EAAE;QAC1D,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC;QAC1B,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;YACzD,MAAM,GAAG,SAAS,CAAC;YACnB,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,eAAe,EAAE,CAAC;QACvC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AU,CAAC,GAAG,CAAC,CAAC;oBACjC,CAAC;oBACD,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;YACD,OAAO,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,247 @@
1
+ import { spawn } from "node:child_process";
2
+ import { createRequire } from "node:module";
3
+ import { mkdir, mkdtemp, open, readdir, rename, rm } from "node:fs/promises";
4
+ import { cpus, homedir } from "node:os";
5
+ import { dirname, join } from "node:path";
6
+ import { VoiceError } from "./whisper.js";
7
+ import { decodeWav } from "./wav.js";
8
+ /**
9
+ * Moonshine, for people who want the words to keep up.
10
+ *
11
+ * Moonshine is a small encoder–decoder built for short utterances: it does not
12
+ * pad everything to Whisper's 30-second window, so a three-second phrase costs
13
+ * a three-second decode. That is the difference between text that trails you
14
+ * and text that waits for you.
15
+ *
16
+ * The cost is accuracy: no prompt to bias toward repo vocabulary, no
17
+ * punctuation, English only. That is the trade this file makes, and it is why
18
+ * Whisper stays as the fallback rather than being deleted.
19
+ *
20
+ * Inference runs in-process through `sherpa-onnx-node`, which ships prebuilt
21
+ * binaries per platform. The weights come from the sherpa model zoo on first
22
+ * use and are unpacked next to the Whisper model, so a machine that has both
23
+ * downloads neither twice.
24
+ */
25
+ const MODELS = {
26
+ tiny: "sherpa-onnx-moonshine-tiny-en-int8",
27
+ base: "sherpa-onnx-moonshine-base-en-int8",
28
+ };
29
+ function voiceDir() {
30
+ return process.env.ZELIO_VOICE_DIR?.trim() || join(homedir(), ".zelio", "voice");
31
+ }
32
+ function modelName() {
33
+ return process.env.ZELIO_MOONSHINE_MODEL?.trim() === "base" ? "base" : "tiny";
34
+ }
35
+ export function moonshineModelDir() {
36
+ return join(voiceDir(), MODELS[modelName()]);
37
+ }
38
+ const require = createRequire(import.meta.url);
39
+ /** The addon, or null when this platform has no prebuilt binary. */
40
+ function loadAddon() {
41
+ try {
42
+ return require("sherpa-onnx-node");
43
+ }
44
+ catch {
45
+ return null;
46
+ }
47
+ }
48
+ async function files(root) {
49
+ let names;
50
+ try {
51
+ names = await readdir(root);
52
+ }
53
+ catch {
54
+ return null;
55
+ }
56
+ const pick = (pattern) => {
57
+ const matches = typeof pattern === "string"
58
+ ? names.filter((name) => name === pattern)
59
+ : names.filter((name) => pattern.test(name));
60
+ // Prefer the quantized graph when the archive ships both.
61
+ const chosen = matches.find((name) => name.includes("int8")) ?? matches[0];
62
+ return chosen ? join(root, chosen) : null;
63
+ };
64
+ const preprocessor = pick(/^preprocess.*\.onnx$/);
65
+ const encoder = pick(/^encode.*\.onnx$/);
66
+ const uncachedDecoder = pick(/^uncached.*\.onnx$/);
67
+ const cachedDecoder = pick(/^cached.*\.onnx$/);
68
+ const tokens = pick("tokens.txt");
69
+ if (!preprocessor || !encoder || !uncachedDecoder || !cachedDecoder || !tokens)
70
+ return null;
71
+ return { preprocessor, encoder, uncachedDecoder, cachedDecoder, tokens };
72
+ }
73
+ /** Bytes of the archive fetched so far, while an install is running. */
74
+ let fetched = null;
75
+ export function moonshineProgress() {
76
+ return fetched;
77
+ }
78
+ export async function moonshineStatus() {
79
+ if (!loadAddon()) {
80
+ return {
81
+ ready: false,
82
+ canPrepare: false,
83
+ model: null,
84
+ reason: "the streaming recognizer is not available on this platform",
85
+ progress: null,
86
+ };
87
+ }
88
+ const dir = moonshineModelDir();
89
+ if (await files(dir)) {
90
+ return { ready: true, canPrepare: false, model: dir, reason: null, progress: null };
91
+ }
92
+ return { ready: false, canPrepare: true, model: null, reason: null, progress: fetched };
93
+ }
94
+ /** Two presses on the same button are one download, not two. */
95
+ let installing = null;
96
+ function extract(archive, into) {
97
+ return new Promise((resolve, reject) => {
98
+ const child = spawn("tar", ["-xjf", archive, "-C", into], {
99
+ stdio: ["ignore", "ignore", "pipe"],
100
+ });
101
+ let stderr = "";
102
+ child.stderr.on("data", (chunk) => {
103
+ if (stderr.length < 2000)
104
+ stderr += chunk.toString();
105
+ });
106
+ child.on("error", (cause) => {
107
+ reject(new VoiceError("failed", `could not unpack the model: ${cause.message}`));
108
+ });
109
+ child.on("close", (code) => {
110
+ if (code === 0)
111
+ resolve();
112
+ else
113
+ reject(new VoiceError("failed", `could not unpack the model: ${stderr.trim().slice(-200)}`));
114
+ });
115
+ });
116
+ }
117
+ async function downloadModel(target) {
118
+ const name = MODELS[modelName()];
119
+ const url = `https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/${name}.tar.bz2`;
120
+ await mkdir(dirname(target), { recursive: true });
121
+ const staging = await mkdtemp(join(voiceDir(), ".moonshine-"));
122
+ try {
123
+ const response = await fetch(url);
124
+ if (!response.ok || !response.body) {
125
+ throw new VoiceError("unavailable", `could not download ${name} (${response.status})`);
126
+ }
127
+ const total = Number(response.headers.get("content-length")) || 0;
128
+ fetched = { received: 0, total };
129
+ const archive = join(staging, `${name}.tar.bz2`);
130
+ const file = await open(archive, "w");
131
+ try {
132
+ for await (const chunk of response.body) {
133
+ await file.write(chunk);
134
+ fetched = { received: (fetched?.received ?? 0) + chunk.byteLength, total };
135
+ }
136
+ }
137
+ finally {
138
+ await file.close();
139
+ fetched = null;
140
+ }
141
+ // `tar` reads bzip2 and is on every machine that also has git; a JS
142
+ // decompressor would be a dependency for one file format.
143
+ await extract(archive, staging);
144
+ const unpacked = (await readdir(staging)).find((entry) => entry.startsWith(name));
145
+ if (!unpacked)
146
+ throw new VoiceError("failed", "the model archive had no model in it");
147
+ await rm(target, { recursive: true, force: true });
148
+ await rename(join(staging, unpacked), target);
149
+ }
150
+ finally {
151
+ await rm(staging, { recursive: true, force: true });
152
+ }
153
+ }
154
+ export async function prepareMoonshine() {
155
+ if (await files(moonshineModelDir()))
156
+ return;
157
+ if (!loadAddon()) {
158
+ throw new VoiceError("unavailable", "the streaming recognizer is not available on this platform");
159
+ }
160
+ installing ??= downloadModel(moonshineModelDir()).finally(() => {
161
+ installing = null;
162
+ });
163
+ await installing;
164
+ }
165
+ let recognizer = null;
166
+ function recognizerFor(dir, found) {
167
+ if (recognizer?.dir === dir)
168
+ return recognizer.instance;
169
+ const sherpa = loadAddon();
170
+ if (!sherpa) {
171
+ throw new VoiceError("unavailable", "the streaming recognizer is not available on this platform");
172
+ }
173
+ const instance = new sherpa.OfflineRecognizer({
174
+ featConfig: { sampleRate: 16000, featureDim: 80 },
175
+ modelConfig: {
176
+ moonshine: {
177
+ preprocessor: found.preprocessor,
178
+ encoder: found.encoder,
179
+ uncachedDecoder: found.uncachedDecoder,
180
+ cachedDecoder: found.cachedDecoder,
181
+ },
182
+ tokens: found.tokens,
183
+ // Half the cores: the decode is fast enough that a whole laptop's worth
184
+ // of threads would only fight the board's own work.
185
+ numThreads: Math.max(2, Math.min(4, Math.floor(cpus().length / 2))),
186
+ provider: "cpu",
187
+ debug: 0,
188
+ },
189
+ });
190
+ recognizer = { dir, instance };
191
+ return instance;
192
+ }
193
+ const sentenceCase = (text) => {
194
+ const cleaned = text.replace(/\s+/g, " ").trim();
195
+ if (!cleaned)
196
+ return "";
197
+ // Moonshine's vocabulary is lower-case; a field that starts mid-sentence
198
+ // because of that is a fix the person should not have to make by hand.
199
+ return cleaned === cleaned.toLowerCase()
200
+ ? cleaned.charAt(0).toUpperCase() + cleaned.slice(1)
201
+ : cleaned;
202
+ };
203
+ export async function transcribeMoonshine(wav) {
204
+ const dir = moonshineModelDir();
205
+ const found = await files(dir);
206
+ if (!found)
207
+ throw new VoiceError("unavailable", "the streaming model is not downloaded yet");
208
+ const audio = decodeWav(wav);
209
+ if (audio.sampleRate !== 16000) {
210
+ throw new VoiceError("failed", "the streaming model needs 16 kHz audio");
211
+ }
212
+ if (audio.samples.length === 0)
213
+ return "";
214
+ const instance = recognizerFor(dir, found);
215
+ const stream = instance.createStream();
216
+ try {
217
+ stream.acceptWaveform({ samples: audio.samples, sampleRate: audio.sampleRate });
218
+ instance.decode(stream);
219
+ return sentenceCase(instance.getResult(stream).text);
220
+ }
221
+ catch (cause) {
222
+ throw new VoiceError("failed", cause instanceof Error ? cause.message : String(cause));
223
+ }
224
+ }
225
+ function statusOf(status) {
226
+ return {
227
+ ready: status.ready,
228
+ bin: null,
229
+ server: null,
230
+ model: status.model,
231
+ canPrepare: status.canPrepare,
232
+ reason: status.reason,
233
+ engine: "moonshine",
234
+ progress: status.progress,
235
+ };
236
+ }
237
+ export function createMoonshine() {
238
+ return {
239
+ status: async () => statusOf(await moonshineStatus()),
240
+ prepare: async () => {
241
+ await prepareMoonshine();
242
+ return statusOf(await moonshineStatus());
243
+ },
244
+ transcribe: (wav) => transcribeMoonshine(wav),
245
+ };
246
+ }
247
+ //# sourceMappingURL=moonshine.js.map