@coresource/hz 0.20.3 → 0.20.4

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 (2) hide show
  1. package/dist/hz.mjs +47 -4
  2. package/package.json +2 -2
package/dist/hz.mjs CHANGED
@@ -3986,11 +3986,36 @@ function asNonEmptyString8(value) {
3986
3986
  function asStringArray2(value) {
3987
3987
  return Array.isArray(value) ? value.map((item) => asNonEmptyString8(item)).filter((item) => item !== null) : [];
3988
3988
  }
3989
+ function asCodeSnippets(value) {
3990
+ if (!Array.isArray(value)) {
3991
+ return [];
3992
+ }
3993
+ const snippets = [];
3994
+ const dedupe = /* @__PURE__ */ new Set();
3995
+ for (const entry of value) {
3996
+ const snippet = asNonEmptyString8(
3997
+ typeof entry === "string" ? entry : isRecord7(entry) ? entry.snippet ?? entry.code ?? entry.code_evidence ?? entry.content : void 0
3998
+ );
3999
+ if (!snippet) {
4000
+ continue;
4001
+ }
4002
+ const pathValue = isRecord7(entry) ? asNonEmptyString8(entry.path ?? entry.file_path ?? entry.filePath) : null;
4003
+ const key = `${pathValue ?? ""}\0${snippet}`;
4004
+ if (dedupe.has(key)) {
4005
+ continue;
4006
+ }
4007
+ dedupe.add(key);
4008
+ snippets.push(pathValue ? { path: pathValue, snippet } : { snippet });
4009
+ }
4010
+ return snippets;
4011
+ }
3989
4012
  function extractQuestions(payload) {
3990
4013
  if (!payload || !Array.isArray(payload.questions)) {
3991
4014
  return [];
3992
4015
  }
3993
4016
  return payload.questions.filter((question) => isRecord7(question)).map((question) => ({
4017
+ codeSnippets: asCodeSnippets(question.codeSnippets ?? question.code_snippets ?? question.snippets),
4018
+ context: asNonEmptyString8(question.context) ?? void 0,
3994
4019
  detailPrompt: asNonEmptyString8(question.detailPrompt) ?? void 0,
3995
4020
  freeTextOptionId: asNonEmptyString8(question.freeTextOptionId) ?? void 0,
3996
4021
  id: asNonEmptyString8(question.id) ?? "question",
@@ -4203,11 +4228,28 @@ function writeSection3(stdout, title) {
4203
4228
  writeLine(stdout);
4204
4229
  writeLine(stdout, pc9.bold(title));
4205
4230
  }
4231
+ function formatInlineSnippet(snippet) {
4232
+ return snippet.replace(/\s+/g, " ").trim();
4233
+ }
4234
+ function isFreeTextQuestion(question) {
4235
+ return Boolean(question.freeTextOptionId) || !question.options || question.options.length === 0;
4236
+ }
4206
4237
  function renderQuestion(stdout, question, index) {
4207
4238
  writeLine(stdout, `${index + 1}. ${question.text}`);
4208
4239
  if (question.references && question.references.length > 0) {
4209
4240
  writeLine(stdout, ` ${pc9.dim(`References: ${question.references.join(", ")}`)}`);
4210
4241
  }
4242
+ if (question.context) {
4243
+ writeLine(stdout, ` ${pc9.dim(`Context: ${question.context}`)}`);
4244
+ }
4245
+ if (question.codeSnippets && question.codeSnippets.length > 0) {
4246
+ writeLine(stdout, ` ${pc9.dim("Code:")}`);
4247
+ for (const codeSnippet of question.codeSnippets) {
4248
+ const renderedSnippet = formatInlineSnippet(codeSnippet.snippet);
4249
+ const label = codeSnippet.path ? `${codeSnippet.path}: ` : "";
4250
+ writeLine(stdout, ` ${label}${renderedSnippet}`);
4251
+ }
4252
+ }
4211
4253
  }
4212
4254
  function renderMilestones(stdout, milestones, reviewRound) {
4213
4255
  writeSection3(stdout, `Milestone review round ${reviewRound}`);
@@ -4307,9 +4349,10 @@ async function promptForAnswers(options, interruption, questions, round) {
4307
4349
  const transcript = [];
4308
4350
  for (const question of questions) {
4309
4351
  throwIfInterrupted3(interruption);
4310
- if (question.options && question.options.length > 0) {
4352
+ if (!isFreeTextQuestion(question)) {
4353
+ const selectableOptions = question.options ?? [];
4311
4354
  const autoSelectedOption = options.autoApprove ? pickAutoApprovedOption(question, options.taskDescription, options.repoPaths) : null;
4312
- const choices = question.options.map((option) => ({
4355
+ const choices = selectableOptions.map((option) => ({
4313
4356
  description: option.description,
4314
4357
  name: option.label,
4315
4358
  value: option.id
@@ -4320,7 +4363,7 @@ async function promptForAnswers(options, interruption, questions, round) {
4320
4363
  signal: interruption.abortController.signal
4321
4364
  });
4322
4365
  throwIfInterrupted3(interruption);
4323
- const selectedOption = question.options.find((option) => option.id === optionId2);
4366
+ const selectedOption = selectableOptions.find((option) => option.id === optionId2);
4324
4367
  answers.push({
4325
4368
  optionId: optionId2,
4326
4369
  questionId: question.id
@@ -4341,7 +4384,7 @@ async function promptForAnswers(options, interruption, questions, round) {
4341
4384
  signal: interruption.abortController.signal
4342
4385
  });
4343
4386
  throwIfInterrupted3(interruption);
4344
- const optionId = question.freeTextOptionId ?? FREE_TEXT_OPTION_ID;
4387
+ const optionId = FREE_TEXT_OPTION_ID;
4345
4388
  answers.push({
4346
4389
  detail,
4347
4390
  optionId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coresource/hz",
3
- "version": "0.20.3",
3
+ "version": "0.20.4",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "hz": "dist/hz.mjs"
@@ -28,7 +28,7 @@
28
28
  "devDependencies": {
29
29
  "@types/node": "^25.5.0",
30
30
  "@types/ws": "^8.18.1",
31
- "tsup": "^8.5.0",
31
+ "tsup": "^8.5.1",
32
32
  "typescript": "^5.9.3",
33
33
  "vitest": "^3.2.4"
34
34
  }