supipowers 2.2.0 → 2.2.2

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 (45) hide show
  1. package/README.md +71 -12
  2. package/package.json +11 -15
  3. package/skills/ui-design/SKILL.md +2 -2
  4. package/src/ai/final-message.ts +15 -1
  5. package/src/ai/schema-text.ts +60 -40
  6. package/src/ai/schema-validation.ts +88 -0
  7. package/src/ai/structured-output.ts +19 -19
  8. package/src/bootstrap.ts +2 -1
  9. package/src/commands/doctor.ts +3 -2
  10. package/src/commands/fix-pr.ts +166 -26
  11. package/src/commands/plan.ts +2 -1
  12. package/src/commands/update.ts +7 -5
  13. package/src/config/schema.ts +102 -139
  14. package/src/docs/contracts.ts +13 -23
  15. package/src/fix-pr/assessment.ts +63 -24
  16. package/src/fix-pr/contracts.ts +15 -23
  17. package/src/fix-pr/fetch-comments.ts +119 -0
  18. package/src/fix-pr/prompt-builder.ts +19 -8
  19. package/src/git/commit-contract.ts +13 -19
  20. package/src/git/commit.ts +168 -6
  21. package/src/harness/anti_slop/fallow-adapter.ts +4 -3
  22. package/src/harness/command.ts +12 -7
  23. package/src/harness/pipeline.ts +2 -8
  24. package/src/harness/stage-runner.ts +3 -0
  25. package/src/harness/stages/docs.ts +82 -0
  26. package/src/lsp/capabilities.ts +9 -12
  27. package/src/lsp/contracts.ts +15 -23
  28. package/src/mempalace/uv.ts +15 -7
  29. package/src/planning/approval-flow.ts +15 -17
  30. package/src/planning/planning-ask-tool.ts +13 -2
  31. package/src/planning/spec.ts +21 -27
  32. package/src/planning/system-prompt.ts +1 -1
  33. package/src/planning/validate.ts +4 -7
  34. package/src/platform/progress.ts +11 -0
  35. package/src/quality/contracts.ts +15 -23
  36. package/src/quality/schemas.ts +40 -67
  37. package/src/release/contracts.ts +19 -28
  38. package/src/review/types.ts +142 -186
  39. package/src/types.ts +15 -2
  40. package/src/ui-design/session.ts +13 -2
  41. package/src/ui-design/system-prompt.ts +2 -2
  42. package/src/ultraplan/contracts.ts +458 -524
  43. package/src/utils/exec-cli.ts +106 -0
  44. package/src/visual/scripts/npm-shrinkwrap.json +878 -0
  45. package/src/visual/scripts/package-lock.json +878 -0
@@ -3,7 +3,7 @@ import * as os from "node:os";
3
3
  import * as path from "node:path";
4
4
  import type { Platform } from "../platform/types.js";
5
5
  import type { WorkspaceTarget } from "../types.js";
6
- import { buildWorkspaceTargetOptionLabel, parseTargetArg, selectWorkspaceTarget, stripCliArg, tokenizeCliArgs } from "../workspace/selector.js";
6
+ import { buildWorkspaceTargetOptionLabel, parseTargetArg, stripCliArg, tokenizeCliArgs } from "../workspace/selector.js";
7
7
  import { resolvePackageManager } from "../workspace/package-manager.js";
8
8
  import { resolveRepoRoot } from "../workspace/repo-root.js";
9
9
  import { discoverWorkspaceTargets } from "../workspace/targets.js";
@@ -31,6 +31,45 @@ import { loadModelConfig } from "../config/model-config.js";
31
31
  import { detectBotReviewers } from "../fix-pr/bot-detector.js";
32
32
  import { runFixPrAssessment, groupAssessmentsIntoBatches } from "../fix-pr/assessment.js";
33
33
  import { updateFixPrSession } from "../storage/fix-pr-sessions.js";
34
+ import { createWorkflowProgress } from "../platform/progress.js";
35
+
36
+
37
+ const FIX_PR_ASSESSMENT_TIMEOUT_MS = 5 * 60 * 1_000;
38
+ const FIX_PR_ASSESSMENT_COMMENTS_PER_BATCH = 12;
39
+
40
+ const FIX_PR_STEPS = [
41
+ { key: "fetch-comments", label: "Fetch PR comments" },
42
+ { key: "select-target", label: "Select target" },
43
+ { key: "prepare-session", label: "Prepare session" },
44
+ { key: "llm-assessment", label: "LLM assessment" },
45
+ { key: "send-prompt", label: "Send fix prompt" },
46
+ ] as const;
47
+
48
+ function createFixPrProgress(ctx: any) {
49
+ const progress = createWorkflowProgress(ctx.ui, {
50
+ title: "supi:fix-pr",
51
+ statusKey: "supi-fix-pr",
52
+ statusLabel: "Fixing PR...",
53
+ widgetKey: "supi-fix-pr",
54
+ clearStatusKeys: ["supi-model"],
55
+ steps: [...FIX_PR_STEPS],
56
+ });
57
+
58
+ return {
59
+ activate(stepIndex: number, detail?: string): void {
60
+ progress.activate(FIX_PR_STEPS[stepIndex]!.key, detail);
61
+ },
62
+ complete(stepIndex: number, detail?: string): void {
63
+ progress.complete(FIX_PR_STEPS[stepIndex]!.key, detail);
64
+ },
65
+ fail(stepIndex: number, detail?: string): void {
66
+ progress.fail(FIX_PR_STEPS[stepIndex]!.key, detail);
67
+ },
68
+ dispose(): void {
69
+ progress.dispose();
70
+ },
71
+ };
72
+ }
34
73
 
35
74
  modelRegistry.register({
36
75
  id: "fix-pr",
@@ -47,6 +86,7 @@ modelRegistry.register({
47
86
  harnessRoleHint: "default",
48
87
  });
49
88
 
89
+
50
90
  function getScriptsDir(): string {
51
91
  return path.join(moduleDir(import.meta.url), "..", "fix-pr", "scripts");
52
92
  }
@@ -91,6 +131,12 @@ function formatUnscopedCommentCount(count: number): string {
91
131
  return `${formatCommentCount(count)} without file path`;
92
132
  }
93
133
 
134
+ type FixPrSelectedTarget =
135
+ | { kind: "workspace"; target: WorkspaceTarget }
136
+ | { kind: "all"; target: WorkspaceTarget };
137
+
138
+ const ALL_FIX_PR_TARGET_ID = "all";
139
+
94
140
  function buildCommentTargetOptions(
95
141
  targets: readonly WorkspaceTarget[],
96
142
  commentsByTargetId: ReadonlyMap<string, readonly PrComment[]>,
@@ -109,6 +155,43 @@ function buildCommentTargetOptions(
109
155
  });
110
156
  }
111
157
 
158
+ function createAllCommentsTarget(repoRoot: string, packageManager: WorkspaceTarget["packageManager"]): WorkspaceTarget {
159
+ return {
160
+ id: ALL_FIX_PR_TARGET_ID,
161
+ name: "all",
162
+ kind: "workspace",
163
+ repoRoot,
164
+ packageDir: repoRoot,
165
+ manifestPath: path.join(repoRoot, "package.json"),
166
+ relativeDir: ALL_FIX_PR_TARGET_ID,
167
+ version: "0.0.0",
168
+ private: true,
169
+ packageManager,
170
+ };
171
+ }
172
+
173
+ function describeFixPrSelectedTarget(selected: FixPrSelectedTarget): string {
174
+ return selected.kind === "all" ? "all targets" : describeTarget(selected.target);
175
+ }
176
+
177
+ function getSelectedTargetComments(
178
+ selected: FixPrSelectedTarget,
179
+ commentsByTargetId: ReadonlyMap<string, readonly PrComment[]>,
180
+ unscopedComments: readonly PrComment[],
181
+ ): readonly PrComment[] {
182
+ if (selected.kind === "workspace") {
183
+ return commentsByTargetId.get(selected.target.id) ?? [];
184
+ }
185
+
186
+ const comments: PrComment[] = [];
187
+ for (const targetComments of commentsByTargetId.values()) {
188
+ comments.push(...targetComments);
189
+ }
190
+ comments.push(...unscopedComments);
191
+ return comments;
192
+ }
193
+
194
+
112
195
  function countUnresolvedAssessments(assessment: FixPrAssessmentBatch): number {
113
196
  return assessment.assessments.filter((item: FixPrAssessmentBatch["assessments"][number]) => item.verdict !== "apply").length;
114
197
  }
@@ -211,14 +294,18 @@ export function registerFixPrCommand(platform: Platform): void {
211
294
  return;
212
295
  }
213
296
 
297
+ const progress = createFixPrProgress(ctx);
214
298
  const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "supi-fix-pr-"));
215
299
  try {
300
+ progress.activate(0, `PR #${prNumber}`);
216
301
  const fetchedCommentsPath = path.join(tempDir, "comments.jsonl");
217
302
  const fetchError = await fetchPrComments(platform, repo, prNumber, fetchedCommentsPath, repoRoot);
218
303
  if (fetchError) {
304
+ progress.fail(0, "failed");
219
305
  notifyError(ctx, "Failed to fetch PR comments", fetchError);
220
306
  return;
221
307
  }
308
+ progress.complete(0, `PR #${prNumber}`);
222
309
 
223
310
  const fetchedComments = fs.readFileSync(fetchedCommentsPath, "utf-8").trim();
224
311
  if (!fetchedComments) {
@@ -238,36 +325,74 @@ export function registerFixPrCommand(platform: Platform): void {
238
325
  clusteredComments.commentsByTargetId,
239
326
  );
240
327
 
241
- if (targetOptions.length === 0) {
242
- const detail = clusteredComments.unscopedComments.length > 0
243
- ? `PR comments were fetched but only ${formatUnscopedCommentCount(clusteredComments.unscopedComments.length)} could not be assigned to a workspace target`
244
- : "PR comments were fetched but could not be assigned to a package or root target";
245
- notifyWarning(ctx, "No actionable comments found", detail);
328
+ const allTarget = createAllCommentsTarget(repoRoot, packageManager.id);
329
+ const allOption = {
330
+ target: allTarget,
331
+ changed: true,
332
+ label: buildWorkspaceTargetOptionLabel(
333
+ { target: allTarget, changed: true },
334
+ [formatCommentCount(parsedComments.length)],
335
+ ),
336
+ };
337
+
338
+ if (targetOptions.length === 0 && clusteredComments.unscopedComments.length === 0) {
339
+ notifyWarning(ctx, "No actionable comments found", "PR comments were fetched but could not be assigned to a package or root target");
246
340
  return;
247
341
  }
248
342
 
249
- if (!requestedTarget && !ctx.hasUI && targetOptions.length > 1) {
250
- notifyError(ctx, "Multiple comment targets found", buildAvailableTargetDetail(targetOptions, clusteredComments.unscopedComments.length));
251
- return;
343
+ progress.activate(1, `${formatCommentCount(parsedComments.length)}`);
344
+ let selected: FixPrSelectedTarget | null = null;
345
+ if (requestedTarget === ALL_FIX_PR_TARGET_ID) {
346
+ selected = { kind: "all", target: allTarget };
347
+ } else if (requestedTarget) {
348
+ const target = targetOptions
349
+ .map((option) => option.target)
350
+ .find((optionTarget) => optionTarget.id === requestedTarget || optionTarget.name === requestedTarget);
351
+ selected = target ? { kind: "workspace", target } : null;
352
+ } else if (!ctx.hasUI) {
353
+ selected = { kind: "all", target: allTarget };
354
+ } else {
355
+ const labels = [
356
+ allOption.label,
357
+ ...targetOptions.map((option) => option.label ?? buildWorkspaceTargetOptionLabel(option)),
358
+ ];
359
+ const choice = await ctx.ui.select("Fix-PR target", labels, {
360
+ helpText: "Select all comments or one target to process for this run",
361
+ });
362
+ if (!choice) {
363
+ progress.fail(1, "cancelled");
364
+ return;
365
+ }
366
+ const selectedIndex = labels.indexOf(choice);
367
+ selected = selectedIndex === 0
368
+ ? { kind: "all", target: allTarget }
369
+ : targetOptions[selectedIndex - 1]
370
+ ? { kind: "workspace", target: targetOptions[selectedIndex - 1].target }
371
+ : null;
252
372
  }
253
373
 
254
- const selectedTarget = await selectWorkspaceTarget(ctx, targetOptions, requestedTarget, {
255
- title: "Fix-PR target",
256
- helpText: "Select one target to process for this run",
257
- });
258
- if (!selectedTarget) {
374
+ if (!selected) {
259
375
  if (requestedTarget) {
260
376
  notifyError(ctx, "Target has no review comments", buildAvailableTargetDetail(targetOptions, clusteredComments.unscopedComments.length));
261
377
  }
378
+ progress.fail(1, "empty");
262
379
  return;
263
380
  }
381
+ progress.complete(1, describeFixPrSelectedTarget(selected));
264
382
 
265
- const selectedComments = clusteredComments.commentsByTargetId.get(selectedTarget.id) ?? [];
383
+ const selectedTarget = selected.target;
384
+ const selectedComments = getSelectedTargetComments(
385
+ selected,
386
+ clusteredComments.commentsByTargetId,
387
+ clusteredComments.unscopedComments,
388
+ );
266
389
  if (selectedComments.length === 0) {
267
390
  notifyInfo(ctx, "No comments for selected target", `${selectedTarget.id} has no actionable comments in this PR snapshot`);
268
391
  return;
269
392
  }
270
393
 
394
+ progress.activate(2, `${formatCommentCount(selectedComments.length)}`);
395
+
271
396
  let activeSession = findActiveFixPrSession(platform.paths, selectedTarget, repo, prNumber);
272
397
  if (activeSession && ctx.hasUI) {
273
398
  const choice = await ctx.ui.select(
@@ -278,7 +403,10 @@ export function registerFixPrCommand(platform: Platform): void {
278
403
  ],
279
404
  { helpText: "Select session · Esc to cancel" },
280
405
  );
281
- if (!choice) return;
406
+ if (!choice) {
407
+ progress.fail(2, "cancelled");
408
+ return;
409
+ }
282
410
  if (choice.startsWith("Start new")) activeSession = null;
283
411
  }
284
412
 
@@ -328,12 +456,17 @@ export function registerFixPrCommand(platform: Platform): void {
328
456
 
329
457
  const taskResolved = resolveModelForAction("task", modelRegistry, modelConfig, bridge);
330
458
  const taskModel = taskResolved.model ?? resolved.model ?? "claude-sonnet-4-6";
331
- const deferredCommentsSummary = buildDeferredCommentsSummary(
332
- targetOptions,
333
- clusteredComments.commentsByTargetId,
334
- selectedTarget,
335
- clusteredComments.unscopedComments.length,
336
- );
459
+ const deferredCommentsSummary = selected.kind === "all"
460
+ ? null
461
+ : buildDeferredCommentsSummary(
462
+ targetOptions,
463
+ clusteredComments.commentsByTargetId,
464
+ selectedTarget,
465
+ clusteredComments.unscopedComments.length,
466
+ );
467
+ progress.complete(2, activeSession ? `resume ${ledger.id}` : `new ${ledger.id}`);
468
+
469
+ progress.activate(3, `${formatCommentCount(selectedComments.length)}`);
337
470
 
338
471
  const assessmentResult = await runFixPrAssessment({
339
472
  createAgentSession: platform.createAgentSession,
@@ -342,17 +475,22 @@ export function registerFixPrCommand(platform: Platform): void {
342
475
  comments: selectedComments,
343
476
  repo,
344
477
  prNumber,
345
- selectedTargetLabel: describeTarget(selectedTarget),
478
+ selectedTargetLabel: describeFixPrSelectedTarget(selected),
346
479
  model: resolved.model,
347
480
  thinkingLevel: resolved.thinkingLevel,
481
+ timeoutMs: FIX_PR_ASSESSMENT_TIMEOUT_MS,
482
+ maxCommentsPerBatch: FIX_PR_ASSESSMENT_COMMENTS_PER_BATCH,
348
483
  });
349
484
  if (assessmentResult.status === "blocked") {
485
+ progress.fail(3, "blocked");
350
486
  notifyError(ctx, "Fix-PR assessment failed", assessmentResult.error);
351
487
  return;
352
488
  }
489
+ progress.complete(3, `${formatCommentCount(assessmentResult.output.assessments.length)} assessed`);
353
490
  const assessment = assessmentResult.output;
354
491
  const unresolvedAssessmentCount = countUnresolvedAssessments(assessment);
355
492
  const workBatches = groupAssessmentsIntoBatches(assessment);
493
+ progress.activate(4, `${workBatches.length} batch${workBatches.length === 1 ? "" : "es"}`);
356
494
  ledger.assessment = assessment;
357
495
  updateFixPrSession(platform.paths, selectedTarget, ledger);
358
496
 
@@ -360,7 +498,7 @@ export function registerFixPrCommand(platform: Platform): void {
360
498
  notifyWarning(
361
499
  ctx,
362
500
  "Unresolved comments remain",
363
- `${formatCommentCount(unresolvedAssessmentCount)} for ${describeTarget(selectedTarget)} still need rejection or investigation handling before this run can be considered complete.`,
501
+ `${formatCommentCount(unresolvedAssessmentCount)} for ${describeFixPrSelectedTarget(selected)} still need rejection or investigation handling before this run can be considered complete.`,
364
502
  );
365
503
  }
366
504
 
@@ -374,7 +512,7 @@ export function registerFixPrCommand(platform: Platform): void {
374
512
  iteration: ledger.iteration,
375
513
  skillContent,
376
514
  taskModel,
377
- selectedTargetLabel: describeTarget(selectedTarget),
515
+ selectedTargetLabel: describeFixPrSelectedTarget(selected),
378
516
  deferredCommentsSummary,
379
517
  assessment,
380
518
  workBatches,
@@ -388,14 +526,16 @@ export function registerFixPrCommand(platform: Platform): void {
388
526
  },
389
527
  { deliverAs: "steer", triggerTurn: true },
390
528
  );
529
+ progress.complete(4, "sent");
391
530
 
392
- const detailParts = [`${formatCommentCount(selectedComments.length)} for ${describeTarget(selectedTarget)}`];
531
+ const detailParts = [`${formatCommentCount(selectedComments.length)} for ${describeFixPrSelectedTarget(selected)}`];
393
532
  if (deferredCommentsSummary) {
394
533
  detailParts.push(`deferred: ${deferredCommentsSummary}`);
395
534
  }
396
535
  notifyInfo(ctx, `Fix-PR started: PR #${prNumber}`, `${detailParts.join(" | ")} | session ${ledger.id}`);
397
536
  } finally {
398
537
  fs.rmSync(tempDir, { recursive: true, force: true });
538
+ progress.dispose();
399
539
  }
400
540
  },
401
541
  });
@@ -19,6 +19,7 @@ import { loadModelConfig } from "../config/model-config.js";
19
19
  import { getProjectStatePath } from "../workspace/state-paths.js";
20
20
  import { cancelPlanTracking, startPlanTracking } from "../planning/approval-flow.js";
21
21
  import { stopVisualServer } from "../visual/stop-server.js";
22
+ import { execCli } from "../utils/exec-cli.js";
22
23
 
23
24
  modelRegistry.register({
24
25
  id: "plan",
@@ -111,7 +112,7 @@ export function registerPlanCommand(platform: Platform): void {
111
112
  const nodeModules = path.join(scriptsDir, "node_modules");
112
113
  if (!fs.existsSync(nodeModules)) {
113
114
  notifyInfo(ctx, "Installing visual companion dependencies...");
114
- const installResult = await platform.exec("npm", ["install", "--production"], { cwd: scriptsDir });
115
+ const installResult = await execCli((cmd, args, opts) => platform.exec(cmd, args, opts), "npm", ["install", "--production"], { cwd: scriptsDir });
115
116
  if (installResult.code !== 0) {
116
117
  notifyError(ctx, "Failed to install visual companion dependencies", installResult.stderr);
117
118
  debugLogger.log("visual_companion_dependency_install_failed", {
@@ -11,6 +11,7 @@ import {
11
11
  steerMempalaceInitialization,
12
12
  } from "../mempalace/installer-helper.js";
13
13
  import { loadConfig } from "../config/loader.js";
14
+ import { execCli, wrapExecForCli } from "../utils/exec-cli.js";
14
15
 
15
16
  // ── Options builder ──────────────────────────────────────
16
17
 
@@ -59,7 +60,7 @@ async function updateSupipowers(
59
60
  ctx.ui.notify(`Current version: v${currentVersion}`, "info");
60
61
 
61
62
  // Check latest version on npm
62
- const checkResult = await platform.exec("npm", ["view", "supipowers", "version"], { cwd: tmpdir() });
63
+ const checkResult = await execCli((cmd, args, opts) => platform.exec(cmd, args, opts), "npm", ["view", "supipowers", "version"], { cwd: tmpdir() });
63
64
  if (checkResult.code !== 0) {
64
65
  ctx.ui.notify("Failed to check for updates — npm view failed", "error");
65
66
  return null;
@@ -78,7 +79,8 @@ async function updateSupipowers(
78
79
  mkdirSync(tempDir, { recursive: true });
79
80
 
80
81
  try {
81
- const installResult = await platform.exec(
82
+ const installResult = await execCli(
83
+ (cmd, args, opts) => platform.exec(cmd, args, opts),
82
84
  "npm", ["install", "--prefix", tempDir, `supipowers@${latestVersion}`],
83
85
  { cwd: tempDir },
84
86
  );
@@ -130,10 +132,10 @@ async function updateSupipowers(
130
132
  // Install runtime dependencies (handlebars, etc.)
131
133
  // Without this, the extension fails to load because node_modules/ was deleted above.
132
134
  ctx.ui.notify("Installing dependencies...", "info");
133
- const bunInstall = await platform.exec("bun", ["install", "--production"], { cwd: extDir });
135
+ const bunInstall = await execCli((cmd, args, opts) => platform.exec(cmd, args, opts), "bun", ["install", "--production"], { cwd: extDir });
134
136
  if (bunInstall.code !== 0) {
135
137
  // Fallback to npm if bun is not available (e.g. Windows without global bun)
136
- const npmInstall = await platform.exec("npm", ["install", "--omit=dev"], { cwd: extDir });
138
+ const npmInstall = await execCli((cmd, args, opts) => platform.exec(cmd, args, opts), "npm", ["install", "--omit=dev"], { cwd: extDir });
137
139
  if (npmInstall.code !== 0) {
138
140
  ctx.ui.notify(
139
141
  "Could not install extension dependencies.\n" +
@@ -177,7 +179,7 @@ async function updateSupipowers(
177
179
 
178
180
  export function handleUpdate(platform: Platform, ctx: PlatformContext): void {
179
181
  void (async () => {
180
- const exec = (cmd: string, args: string[]) => platform.exec(cmd, args);
182
+ const exec = wrapExecForCli((cmd: string, args: string[]) => platform.exec(cmd, args));
181
183
 
182
184
  // 1. Scan all dependencies
183
185
  const allStatuses = await scanAll(exec);