sequant 2.2.0 → 2.3.0

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 (137) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +73 -0
  4. package/dist/bin/cli.js +94 -9
  5. package/dist/src/commands/doctor.d.ts +25 -0
  6. package/dist/src/commands/doctor.js +36 -1
  7. package/dist/src/commands/locks.d.ts +67 -0
  8. package/dist/src/commands/locks.js +290 -0
  9. package/dist/src/commands/merge.js +11 -0
  10. package/dist/src/commands/prompt.d.ts +39 -0
  11. package/dist/src/commands/prompt.js +179 -0
  12. package/dist/src/commands/run-display.d.ts +11 -2
  13. package/dist/src/commands/run-display.js +62 -28
  14. package/dist/src/commands/run-progress.d.ts +32 -0
  15. package/dist/src/commands/run-progress.js +76 -0
  16. package/dist/src/commands/run.js +80 -18
  17. package/dist/src/commands/stats.d.ts +2 -0
  18. package/dist/src/commands/stats.js +94 -8
  19. package/dist/src/commands/status.js +12 -0
  20. package/dist/src/commands/watch.d.ts +16 -0
  21. package/dist/src/commands/watch.js +147 -0
  22. package/dist/src/lib/ac-linter.d.ts +1 -1
  23. package/dist/src/lib/ac-linter.js +81 -0
  24. package/dist/src/lib/assess-collision-detect.d.ts +91 -0
  25. package/dist/src/lib/assess-collision-detect.js +217 -0
  26. package/dist/src/lib/assess-comment-parser.d.ts +59 -1
  27. package/dist/src/lib/assess-comment-parser.js +124 -2
  28. package/dist/src/lib/cli-ui/format.d.ts +19 -0
  29. package/dist/src/lib/cli-ui/format.js +34 -0
  30. package/dist/src/lib/cli-ui/run-renderer-types.d.ts +181 -0
  31. package/dist/src/lib/cli-ui/run-renderer-types.js +7 -0
  32. package/dist/src/lib/cli-ui/run-renderer.d.ts +239 -0
  33. package/dist/src/lib/cli-ui/run-renderer.js +1173 -0
  34. package/dist/src/lib/heuristics/behavior-rule-detector.d.ts +94 -0
  35. package/dist/src/lib/heuristics/behavior-rule-detector.js +467 -0
  36. package/dist/src/lib/locks/index.d.ts +7 -0
  37. package/dist/src/lib/locks/index.js +5 -0
  38. package/dist/src/lib/locks/lock-manager.d.ts +168 -0
  39. package/dist/src/lib/locks/lock-manager.js +433 -0
  40. package/dist/src/lib/locks/types.d.ts +59 -0
  41. package/dist/src/lib/locks/types.js +31 -0
  42. package/dist/src/lib/qa/markdown-only-ci.d.ts +46 -0
  43. package/dist/src/lib/qa/markdown-only-ci.js +74 -0
  44. package/dist/src/lib/relay/activation.d.ts +60 -0
  45. package/dist/src/lib/relay/activation.js +122 -0
  46. package/dist/src/lib/relay/archive.d.ts +34 -0
  47. package/dist/src/lib/relay/archive.js +106 -0
  48. package/dist/src/lib/relay/frame.d.ts +20 -0
  49. package/dist/src/lib/relay/frame.js +76 -0
  50. package/dist/src/lib/relay/index.d.ts +13 -0
  51. package/dist/src/lib/relay/index.js +13 -0
  52. package/dist/src/lib/relay/paths.d.ts +43 -0
  53. package/dist/src/lib/relay/paths.js +59 -0
  54. package/dist/src/lib/relay/pid.d.ts +34 -0
  55. package/dist/src/lib/relay/pid.js +72 -0
  56. package/dist/src/lib/relay/reader.d.ts +35 -0
  57. package/dist/src/lib/relay/reader.js +115 -0
  58. package/dist/src/lib/relay/types.d.ts +68 -0
  59. package/dist/src/lib/relay/types.js +76 -0
  60. package/dist/src/lib/relay/writer.d.ts +48 -0
  61. package/dist/src/lib/relay/writer.js +113 -0
  62. package/dist/src/lib/settings.d.ts +31 -1
  63. package/dist/src/lib/settings.js +18 -3
  64. package/dist/src/lib/version-check.d.ts +60 -5
  65. package/dist/src/lib/version-check.js +97 -9
  66. package/dist/src/lib/workflow/batch-executor.d.ts +20 -1
  67. package/dist/src/lib/workflow/batch-executor.js +248 -175
  68. package/dist/src/lib/workflow/config-resolver.js +4 -0
  69. package/dist/src/lib/workflow/heartbeat.d.ts +71 -0
  70. package/dist/src/lib/workflow/heartbeat.js +194 -0
  71. package/dist/src/lib/workflow/phase-executor.d.ts +62 -8
  72. package/dist/src/lib/workflow/phase-executor.js +157 -16
  73. package/dist/src/lib/workflow/phase-mapper.d.ts +3 -2
  74. package/dist/src/lib/workflow/phase-mapper.js +17 -20
  75. package/dist/src/lib/workflow/platforms/github.d.ts +1 -1
  76. package/dist/src/lib/workflow/platforms/github.js +20 -3
  77. package/dist/src/lib/workflow/pr-status.d.ts +18 -2
  78. package/dist/src/lib/workflow/pr-status.js +41 -9
  79. package/dist/src/lib/workflow/qa-stagnation.d.ts +117 -0
  80. package/dist/src/lib/workflow/qa-stagnation.js +179 -0
  81. package/dist/src/lib/workflow/run-orchestrator.d.ts +39 -0
  82. package/dist/src/lib/workflow/run-orchestrator.js +340 -15
  83. package/dist/src/lib/workflow/run-reflect.js +1 -1
  84. package/dist/src/lib/workflow/run-state.d.ts +71 -0
  85. package/dist/src/lib/workflow/run-state.js +14 -0
  86. package/dist/src/lib/workflow/state-cleanup.d.ts +13 -5
  87. package/dist/src/lib/workflow/state-cleanup.js +17 -5
  88. package/dist/src/lib/workflow/state-manager.d.ts +12 -1
  89. package/dist/src/lib/workflow/state-manager.js +37 -0
  90. package/dist/src/lib/workflow/state-schema.d.ts +62 -0
  91. package/dist/src/lib/workflow/state-schema.js +35 -1
  92. package/dist/src/lib/workflow/types.d.ts +74 -1
  93. package/dist/src/lib/workflow/worktree-manager.d.ts +8 -1
  94. package/dist/src/lib/workflow/worktree-manager.js +15 -6
  95. package/dist/src/mcp/tools/run.d.ts +44 -0
  96. package/dist/src/mcp/tools/run.js +104 -13
  97. package/dist/src/ui/tui/App.d.ts +14 -0
  98. package/dist/src/ui/tui/App.js +41 -0
  99. package/dist/src/ui/tui/ElapsedTimer.d.ts +10 -0
  100. package/dist/src/ui/tui/ElapsedTimer.js +31 -0
  101. package/dist/src/ui/tui/Header.d.ts +6 -0
  102. package/dist/src/ui/tui/Header.js +15 -0
  103. package/dist/src/ui/tui/IssueBox.d.ts +16 -0
  104. package/dist/src/ui/tui/IssueBox.js +68 -0
  105. package/dist/src/ui/tui/Spinner.d.ts +9 -0
  106. package/dist/src/ui/tui/Spinner.js +18 -0
  107. package/dist/src/ui/tui/index.d.ts +15 -0
  108. package/dist/src/ui/tui/index.js +29 -0
  109. package/dist/src/ui/tui/theme.d.ts +29 -0
  110. package/dist/src/ui/tui/theme.js +52 -0
  111. package/dist/src/ui/tui/truncate.d.ts +11 -0
  112. package/dist/src/ui/tui/truncate.js +31 -0
  113. package/package.json +10 -3
  114. package/templates/agents/sequant-explorer.md +1 -0
  115. package/templates/agents/sequant-qa-checker.md +2 -1
  116. package/templates/agents/sequant-testgen.md +1 -0
  117. package/templates/hooks/post-tool.sh +11 -0
  118. package/templates/hooks/pre-tool.sh +18 -9
  119. package/templates/hooks/relay-check.sh +107 -0
  120. package/templates/relay/frame.txt +11 -0
  121. package/templates/scripts/cleanup-worktree.sh +25 -3
  122. package/templates/scripts/new-feature.sh +6 -0
  123. package/templates/skills/_shared/references/behavior-rule-detection.md +205 -0
  124. package/templates/skills/_shared/references/subagent-types.md +21 -8
  125. package/templates/skills/assess/SKILL.md +103 -49
  126. package/templates/skills/assess/references/predicted-collision-detection.md +109 -0
  127. package/templates/skills/docs/SKILL.md +141 -22
  128. package/templates/skills/exec/SKILL.md +10 -8
  129. package/templates/skills/fullsolve/SKILL.md +79 -5
  130. package/templates/skills/loop/SKILL.md +28 -0
  131. package/templates/skills/merger/SKILL.md +621 -0
  132. package/templates/skills/qa/SKILL.md +727 -8
  133. package/templates/skills/setup/SKILL.md +6 -0
  134. package/templates/skills/spec/SKILL.md +52 -0
  135. package/templates/skills/spec/references/parallel-groups.md +7 -0
  136. package/templates/skills/spec/references/recommended-workflow.md +4 -2
  137. package/templates/skills/testgen/SKILL.md +24 -17
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Run progress wiring — keeps run.ts thin (#503 AC-2: <200 LOC).
3
+ *
4
+ * Builds the appropriate `onProgress` callback for the run mode:
5
+ * - tui : no callback (the ink dashboard owns its own state)
6
+ * - quiet : LivenessHeartbeat-driven (TTY liveness + stall warning)
7
+ * - default: RunRenderer-driven (live grid + events log, #618)
8
+ */
9
+ import type { RunRenderer } from "../lib/cli-ui/run-renderer-types.js";
10
+ import { LivenessHeartbeat } from "../lib/workflow/heartbeat.js";
11
+ import type { ProgressCallback } from "../lib/workflow/types.js";
12
+ export interface ProgressWiring {
13
+ renderer: RunRenderer | null;
14
+ heartbeat: LivenessHeartbeat | null;
15
+ onProgress: ProgressCallback | undefined;
16
+ }
17
+ /**
18
+ * Construct the renderer + heartbeat + onProgress callback for a run.
19
+ *
20
+ * `tuiEnabled` and `quiet` are mutually exclusive with the renderer path.
21
+ */
22
+ export declare function buildProgressWiring(args: {
23
+ tuiEnabled: boolean;
24
+ quiet: boolean;
25
+ issueNumbers: number[];
26
+ phaseTimeoutSeconds: number;
27
+ /** AC-23: when auto-detect mode is on, the renderer shows `Phase: detecting…`
28
+ * while spec runs (before the resolved plan is known). */
29
+ autoDetectPhases?: boolean;
30
+ /** #624 Item 3 / D2: total allowed quality-loop iterations (from settings). */
31
+ maxLoopIterations?: number;
32
+ }): ProgressWiring;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Run progress wiring — keeps run.ts thin (#503 AC-2: <200 LOC).
3
+ *
4
+ * Builds the appropriate `onProgress` callback for the run mode:
5
+ * - tui : no callback (the ink dashboard owns its own state)
6
+ * - quiet : LivenessHeartbeat-driven (TTY liveness + stall warning)
7
+ * - default: RunRenderer-driven (live grid + events log, #618)
8
+ */
9
+ import { createRunRenderer } from "../lib/cli-ui/run-renderer.js";
10
+ import { LivenessHeartbeat } from "../lib/workflow/heartbeat.js";
11
+ /**
12
+ * Construct the renderer + heartbeat + onProgress callback for a run.
13
+ *
14
+ * `tuiEnabled` and `quiet` are mutually exclusive with the renderer path.
15
+ */
16
+ export function buildProgressWiring(args) {
17
+ const { tuiEnabled, quiet, issueNumbers, phaseTimeoutSeconds, autoDetectPhases, maxLoopIterations, } = args;
18
+ const heartbeat = quiet && !tuiEnabled
19
+ ? new LivenessHeartbeat({ phaseTimeoutSeconds })
20
+ : null;
21
+ // RunRenderer (#618) — single owner of stdout, replaces legacy
22
+ // PhaseSpinner (#244) + parallel-mode `▸/✔` lines (#458).
23
+ // AC-26: derive a stall threshold from the configured phase timeout. Half
24
+ // the timeout is a conservative "expected duration" proxy — phases that
25
+ // routinely take longer would have failed timeout already.
26
+ // #624 Item 1: pass terminal rows so the live zone can cap its height.
27
+ // #624 Item 3 / D2: thread the configured maxLoopIterations through so
28
+ // all three retry-suffix sites display the correct denominator.
29
+ const renderer = !tuiEnabled && !quiet
30
+ ? createRunRenderer({
31
+ stallThresholdMs: phaseTimeoutSeconds > 0
32
+ ? (phaseTimeoutSeconds * 1000) / 2
33
+ : undefined,
34
+ rows: process.stdout.rows,
35
+ maxLoopIterations,
36
+ })
37
+ : null;
38
+ if (renderer) {
39
+ for (const issueNumber of issueNumbers) {
40
+ renderer.registerIssue({ issueNumber, autoDetect: autoDetectPhases });
41
+ }
42
+ }
43
+ let onProgress;
44
+ if (renderer) {
45
+ onProgress = (issue, phase, event, extra) => {
46
+ // #543: activity events only feed the TUI's nowLine — skip the line renderer.
47
+ if (event === "activity")
48
+ return;
49
+ // #624 Item 3: pass the outer-loop iteration through so the renderer can
50
+ // render `(attempt N/M)` / `loop N/M`.
51
+ renderer.onEvent({
52
+ issue,
53
+ phase,
54
+ event,
55
+ durationSeconds: extra?.durationSeconds,
56
+ error: extra?.error,
57
+ iteration: extra?.iteration,
58
+ });
59
+ };
60
+ }
61
+ else if (heartbeat) {
62
+ onProgress = (issue, phase, event) => {
63
+ if (event === "activity")
64
+ return;
65
+ if (event === "start")
66
+ heartbeat.start({
67
+ issueNumber: issue,
68
+ phase,
69
+ startedAt: Date.now(),
70
+ });
71
+ else
72
+ heartbeat.stop({ issueNumber: issue, phase });
73
+ };
74
+ }
75
+ return { renderer, heartbeat, onProgress };
76
+ }
@@ -1,13 +1,13 @@
1
1
  /** sequant run — Thin CLI adapter that delegates to RunOrchestrator. */
2
2
  import chalk from "chalk";
3
3
  import { getManifest } from "../lib/manifest.js";
4
- import { formatElapsedTime } from "../lib/phase-spinner.js";
5
4
  import { getSettings } from "../lib/settings.js";
6
5
  import { checkVersionCached, getVersionWarning } from "../lib/version-check.js";
7
- import { ui, colors } from "../lib/cli-ui.js";
6
+ import { ui } from "../lib/cli-ui.js";
8
7
  import { parseBatches } from "../lib/workflow/batch-executor.js";
9
8
  import { RunOrchestrator } from "../lib/workflow/run-orchestrator.js";
10
9
  import { displayConfig, displaySummary } from "./run-display.js";
10
+ import { buildProgressWiring } from "./run-progress.js";
11
11
  // Re-export public API for backwards compatibility
12
12
  export * from "./run-compat.js";
13
13
  /** Parse CLI args → validate → delegate to RunOrchestrator.run() → display summary. */
@@ -31,6 +31,15 @@ export async function runCommand(issues, options) {
31
31
  return;
32
32
  }
33
33
  const settings = await getSettings();
34
+ // #605: --stacked implies --chain; reject explicit --no-chain combo before
35
+ // we evaluate any --chain-dependent constraint below.
36
+ if (options.stacked && options.chain === false) {
37
+ console.log(chalk.red("❌ --stacked cannot be combined with --no-chain"));
38
+ return;
39
+ }
40
+ if (options.stacked) {
41
+ options.chain = true;
42
+ }
34
43
  // Validate constraints
35
44
  if (options.chain && options.batch?.length) {
36
45
  console.log(chalk.red("❌ --chain cannot be used with --batch"));
@@ -60,22 +69,75 @@ export async function runCommand(issues, options) {
60
69
  };
61
70
  const resolved = RunOrchestrator.resolveConfig(init, issues, batches);
62
71
  displayConfig(resolved);
63
- const onProgress = !options.quiet
64
- ? (issue, phase, event, extra) => {
65
- if (event === "start")
66
- console.log(` ${colors.running("▸")} #${issue} ${phase}`);
67
- else if (event === "complete") {
68
- const dur = extra?.durationSeconds != null
69
- ? ` ${formatElapsedTime(extra.durationSeconds)}`
70
- : "";
71
- console.log(` ${colors.success("✔")} #${issue} ${phase}${dur}`);
72
+ const tuiEnabled = Boolean(options.experimentalTui) && Boolean(process.stdout.isTTY);
73
+ // RunRenderer (#618) + LivenessHeartbeat (#574) wiring lives in
74
+ // run-progress.ts to keep this adapter under the 200-LOC cap (#503 AC-2).
75
+ const { renderer, heartbeat, onProgress } = buildProgressWiring({
76
+ tuiEnabled,
77
+ quiet: Boolean(options.quiet),
78
+ issueNumbers: resolved.issueNumbers,
79
+ phaseTimeoutSeconds: settings.run.timeout,
80
+ autoDetectPhases: resolved.autoDetectPhases,
81
+ // #624 Item 3 / D2: route the resolved maxIterations into the renderer so
82
+ // `(attempt N/M)` and `loop N/M` reflect actual configured limits.
83
+ maxLoopIterations: resolved.config.maxIterations,
84
+ });
85
+ if (tuiEnabled) {
86
+ const { renderTui } = await import("../ui/tui/index.js");
87
+ let tuiHandle = null;
88
+ // Unmount the TUI before ShutdownManager writes its shutdown banner so
89
+ // the two don't race on stdout / leave the terminal in alt-screen buffer.
90
+ // `process.once` fires listeners in registration order, so this runs
91
+ // before ShutdownManager's SIGINT handler registered inside run().
92
+ const sigintHandler = () => {
93
+ tuiHandle?.unmount();
94
+ };
95
+ process.once("SIGINT", sigintHandler);
96
+ try {
97
+ const result = await RunOrchestrator.run({
98
+ ...init,
99
+ onProgress,
100
+ onOrchestratorReady: (orch) => {
101
+ tuiHandle = renderTui(orch);
102
+ },
103
+ }, issues, batches);
104
+ if (tuiHandle) {
105
+ await tuiHandle.done;
72
106
  }
73
- else
74
- console.log(` ${colors.error("✖")} #${issue} ${phase}`);
107
+ displaySummary(result);
108
+ if (result.exitCode !== 0)
109
+ process.exit(result.exitCode);
110
+ return;
111
+ }
112
+ finally {
113
+ process.off("SIGINT", sigintHandler);
75
114
  }
76
- : undefined;
77
- const result = await RunOrchestrator.run({ ...init, onProgress }, issues, batches);
78
- displaySummary(result);
79
- if (result.exitCode !== 0)
80
- process.exit(result.exitCode);
115
+ }
116
+ // SIGINT handler: clear the live zone before ShutdownManager writes its
117
+ // cleanup banner so the two don't collide. See AC-29.
118
+ const sigintHandler = () => {
119
+ renderer?.dispose();
120
+ };
121
+ if (renderer)
122
+ process.once("SIGINT", sigintHandler);
123
+ try {
124
+ const result = await RunOrchestrator.run({ ...init, onProgress }, issues, batches);
125
+ // Record PR info in renderer state before summary so done rows show PR #s.
126
+ if (renderer) {
127
+ for (const r of result.results) {
128
+ if (r.prNumber && r.prUrl) {
129
+ renderer.setPullRequest(r.issueNumber, r.prNumber, r.prUrl);
130
+ }
131
+ }
132
+ }
133
+ displaySummary(result, renderer);
134
+ renderer?.dispose();
135
+ if (result.exitCode !== 0)
136
+ process.exit(result.exitCode);
137
+ }
138
+ finally {
139
+ heartbeat?.dispose();
140
+ if (renderer)
141
+ process.off("SIGINT", sigintHandler);
142
+ }
81
143
  }
@@ -9,6 +9,8 @@ interface StatsOptions {
9
9
  csv?: boolean;
10
10
  json?: boolean;
11
11
  detailed?: boolean;
12
+ label?: string;
13
+ since?: string;
12
14
  }
13
15
  /**
14
16
  * Main stats command
@@ -55,6 +55,37 @@ function parseLogFile(filePath) {
55
55
  return null;
56
56
  }
57
57
  }
58
+ /**
59
+ * Filter runs by label and/or since date.
60
+ *
61
+ * Applied after parseLogFile, before calculateStats / calculateDetailedAnalytics.
62
+ * Metrics file is bypassed when either filter is set — its schema carries only
63
+ * issue numbers (not labels), so per-label filtering is impossible there.
64
+ *
65
+ * Inclusion rules (AND when both filters set):
66
+ * --label <name> — keep a run iff some issue in log.issues carries the label
67
+ * (mirrors the per-issue label scan in calculateDetailedAnalytics)
68
+ * --since YYYY-MM-DD — keep a run iff log.startTime >= <since>T00:00:00Z
69
+ *
70
+ * Caller is responsible for validating `since` format up-front (see statsCommand).
71
+ */
72
+ function filterLogs(logs, filters) {
73
+ const { label, since } = filters;
74
+ const sinceMs = since !== undefined ? Date.parse(`${since}T00:00:00Z`) : undefined;
75
+ return logs.filter((log) => {
76
+ if (label !== undefined) {
77
+ const hasLabel = log.issues.some((issue) => issue.labels.includes(label));
78
+ if (!hasLabel)
79
+ return false;
80
+ }
81
+ if (sinceMs !== undefined) {
82
+ const startMs = Date.parse(log.startTime);
83
+ if (Number.isNaN(startMs) || startMs < sinceMs)
84
+ return false;
85
+ }
86
+ return true;
87
+ });
88
+ }
58
89
  /**
59
90
  * Calculate aggregate statistics from logs
60
91
  */
@@ -566,12 +597,51 @@ function displayDetailedAnalytics(detailed) {
566
597
  }
567
598
  }
568
599
  }
600
+ /**
601
+ * Emit the "no matching runs" empty branch in the active output format.
602
+ * Reuses the shape of the existing empty-data branches (AC-4).
603
+ */
604
+ function emitNoMatchingRuns(options) {
605
+ if (options.json) {
606
+ console.log(JSON.stringify({ error: "No matching runs", runs: [] }));
607
+ return;
608
+ }
609
+ if (options.csv) {
610
+ console.log("runId,startTime,duration,issues,passed,failed,phases");
611
+ return;
612
+ }
613
+ console.log(ui.headerBox("SEQUANT ANALYTICS"));
614
+ console.log(colors.muted("\n Local data only - no telemetry\n"));
615
+ console.log(colors.warning(" No matching runs."));
616
+ console.log("");
617
+ }
569
618
  /**
570
619
  * Main stats command
571
620
  */
572
621
  export async function statsCommand(options) {
573
- // Try to load local metrics first
574
- const metrics = loadMetrics();
622
+ // Validate --since up-front so an invalid date errors before any output.
623
+ // Two-stage check: a strict YYYY-MM-DD regex (rejects 2026/01/01, 2026-1-1,
624
+ // Jan 1 2026 — all of which Date.parse would otherwise accept with engine-
625
+ // dependent UTC interpretation), then Date.parse for semantic validity
626
+ // (rejects 2026-13-45 etc.).
627
+ if (options.since !== undefined) {
628
+ const SINCE_RE = /^\d{4}-\d{2}-\d{2}$/;
629
+ const sinceMs = SINCE_RE.test(options.since)
630
+ ? Date.parse(`${options.since}T00:00:00Z`)
631
+ : NaN;
632
+ if (Number.isNaN(sinceMs)) {
633
+ console.error(colors.error(`Invalid --since date: ${options.since}. Expected YYYY-MM-DD.`));
634
+ process.exitCode = 1;
635
+ return;
636
+ }
637
+ }
638
+ // --label / --since force log-mode: the metrics file has no per-issue labels
639
+ // (metrics-schema.ts MetricRun.issues is number[]), so filtering is impossible
640
+ // against metrics. Bypass the metrics-first path entirely when filters are set.
641
+ const useFilters = options.label !== undefined || options.since !== undefined;
642
+ const filters = { label: options.label, since: options.since };
643
+ // Try to load local metrics first (skipped when filters force log-mode)
644
+ const metrics = useFilters ? null : loadMetrics();
575
645
  // If JSON output requested
576
646
  if (options.json) {
577
647
  if (metrics && metrics.runs.length > 0) {
@@ -611,16 +681,21 @@ export async function statsCommand(options) {
611
681
  console.log(JSON.stringify({ error: "No data found", runs: [] }));
612
682
  return;
613
683
  }
614
- const logs = logFiles
684
+ const allLogs = logFiles
615
685
  .map((filename) => {
616
686
  const filePath = path.join(logDir, filename);
617
687
  return parseLogFile(filePath);
618
688
  })
619
689
  .filter((log) => log !== null);
620
- if (logs.length === 0) {
690
+ if (allLogs.length === 0) {
621
691
  console.log(JSON.stringify({ error: "No valid logs found", runs: [] }));
622
692
  return;
623
693
  }
694
+ const logs = useFilters ? filterLogs(allLogs, filters) : allLogs;
695
+ if (useFilters && logs.length === 0) {
696
+ emitNoMatchingRuns(options);
697
+ return;
698
+ }
624
699
  const stats = calculateStats(logs);
625
700
  const output = {
626
701
  source: "logs",
@@ -646,12 +721,17 @@ export async function statsCommand(options) {
646
721
  console.log("runId,startTime,duration,issues,passed,failed,phases");
647
722
  return;
648
723
  }
649
- const logs = logFiles
724
+ const allLogs = logFiles
650
725
  .map((filename) => {
651
726
  const filePath = path.join(logDir, filename);
652
727
  return parseLogFile(filePath);
653
728
  })
654
729
  .filter((log) => log !== null);
730
+ const logs = useFilters ? filterLogs(allLogs, filters) : allLogs;
731
+ if (useFilters && logs.length === 0) {
732
+ emitNoMatchingRuns(options);
733
+ return;
734
+ }
655
735
  console.log(generateCsv(logs));
656
736
  return;
657
737
  }
@@ -672,16 +752,21 @@ export async function statsCommand(options) {
672
752
  console.log("");
673
753
  return;
674
754
  }
675
- const logs = logFiles
755
+ const allLogs = logFiles
676
756
  .map((filename) => {
677
757
  const filePath = path.join(logDir, filename);
678
758
  return parseLogFile(filePath);
679
759
  })
680
760
  .filter((log) => log !== null);
681
- if (logs.length === 0) {
761
+ if (allLogs.length === 0) {
682
762
  console.log(colors.warning("\n No valid log files found.\n"));
683
763
  return;
684
764
  }
765
+ const logs = useFilters ? filterLogs(allLogs, filters) : allLogs;
766
+ if (useFilters && logs.length === 0) {
767
+ emitNoMatchingRuns(options);
768
+ return;
769
+ }
685
770
  const stats = calculateStats(logs);
686
771
  displayStats(stats, logDir);
687
772
  }
@@ -689,12 +774,13 @@ export async function statsCommand(options) {
689
774
  if (options.detailed) {
690
775
  const logDir = resolveLogPath(options.path);
691
776
  const logFiles = listLogFiles(logDir);
692
- const logs = logFiles
777
+ const allLogs = logFiles
693
778
  .map((filename) => {
694
779
  const filePath = path.join(logDir, filename);
695
780
  return parseLogFile(filePath);
696
781
  })
697
782
  .filter((log) => log !== null);
783
+ const logs = useFilters ? filterLogs(allLogs, filters) : allLogs;
698
784
  if (logs.length > 0) {
699
785
  const detailed = calculateDetailedAnalytics(logs);
700
786
  displayDetailedAnalytics(detailed);
@@ -11,6 +11,7 @@ import { rebuildStateFromLogs, cleanupStaleEntries, } from "../lib/workflow/stat
11
11
  import { reconcileState, getNextActionHint, formatRelativeTime, } from "../lib/workflow/reconcile.js";
12
12
  import { getSettingsWithWarnings } from "../lib/settings.js";
13
13
  import { getSkillVersions } from "../lib/skill-version.js";
14
+ import { LockManager, formatLockedMessage } from "../lib/locks/index.js";
14
15
  /**
15
16
  * Run reconciliation and display warnings.
16
17
  * Returns the reconcile result for use in display.
@@ -182,11 +183,16 @@ function displayIssueSummary(issues) {
182
183
  const hintDisplay = hint
183
184
  ? chalk.gray(`→ ${hint.length > 30 ? hint.substring(0, 27) + "..." : hint}`)
184
185
  : "";
186
+ // Relay column (#383). Shows ✓ when active, "-" otherwise.
187
+ const relayDisplay = issue.relay?.enabled
188
+ ? chalk.green("on")
189
+ : chalk.gray("-");
185
190
  rows.push([
186
191
  `#${issue.number}`,
187
192
  title,
188
193
  colorStatus(issue.status, issue.resolvedAt),
189
194
  issue.currentPhase || "-",
195
+ relayDisplay,
190
196
  hintDisplay,
191
197
  ]);
192
198
  }
@@ -199,6 +205,7 @@ function displayIssueSummary(issues) {
199
205
  { header: "Title", width: 32 },
200
206
  { header: "Status", width: 20 },
201
207
  { header: "Phase", width: 10 },
208
+ { header: "Relay", width: 5 },
202
209
  { header: "Next", width: 34 },
203
210
  ],
204
211
  }));
@@ -356,6 +363,11 @@ async function displayIssueState(options) {
356
363
  else if (issueState) {
357
364
  console.log(chalk.bold(`\nIssue #${options.issue} State\n`));
358
365
  console.log(formatIssueState(issueState));
366
+ const lockManager = new LockManager();
367
+ const holder = lockManager.check(options.issue);
368
+ if (holder) {
369
+ console.log(chalk.yellow(` ! ${formatLockedMessage(options.issue, holder)}`));
370
+ }
359
371
  const hint = getNextActionHint(issueState);
360
372
  if (hint) {
361
373
  console.log(chalk.cyan(`\n Next: ${hint}`));
@@ -0,0 +1,16 @@
1
+ /**
2
+ * `sequant watch <issue>` — tail the relay outbox for replies from a running
3
+ * headless session (#383). Uses `fs.watch()` when available, falls back to
4
+ * polling on platforms where `fs.watch` is unreliable (NFS, some WSL setups).
5
+ */
6
+ export interface WatchCommandOptions {
7
+ json?: boolean;
8
+ /** Poll interval (ms); used when fs.watch is unavailable. Default: 200. */
9
+ pollIntervalMs?: number;
10
+ /** Abort signal for clean shutdown (tests). */
11
+ signal?: AbortSignal;
12
+ }
13
+ export declare function watchCommand(argsAndOptions: {
14
+ args: string[];
15
+ options: WatchCommandOptions;
16
+ }): Promise<void>;
@@ -0,0 +1,147 @@
1
+ /**
2
+ * `sequant watch <issue>` — tail the relay outbox for replies from a running
3
+ * headless session (#383). Uses `fs.watch()` when available, falls back to
4
+ * polling on platforms where `fs.watch` is unreliable (NFS, some WSL setups).
5
+ */
6
+ import { existsSync, statSync, createReadStream, watch } from "fs";
7
+ import chalk from "chalk";
8
+ import { outboxPathFor } from "../lib/relay/paths.js";
9
+ import { StateManager } from "../lib/workflow/state-manager.js";
10
+ import { RelayResponseSchema } from "../lib/relay/types.js";
11
+ function formatTimestamp(iso) {
12
+ try {
13
+ const date = new Date(iso);
14
+ const hh = String(date.getHours()).padStart(2, "0");
15
+ const mm = String(date.getMinutes()).padStart(2, "0");
16
+ const ss = String(date.getSeconds()).padStart(2, "0");
17
+ return `${hh}:${mm}:${ss}`;
18
+ }
19
+ catch {
20
+ return iso;
21
+ }
22
+ }
23
+ function formatLine(reply, json) {
24
+ if (json)
25
+ return JSON.stringify(reply);
26
+ return chalk.gray(`[${formatTimestamp(reply.timestamp)}] `) + reply.message;
27
+ }
28
+ function readNewLines(path, state) {
29
+ return new Promise((resolve, reject) => {
30
+ if (!existsSync(path)) {
31
+ resolve([]);
32
+ return;
33
+ }
34
+ const stat = statSync(path);
35
+ if (stat.size <= state.offset) {
36
+ // File was truncated/rotated — reset offset.
37
+ if (stat.size < state.offset)
38
+ state.offset = 0;
39
+ resolve([]);
40
+ return;
41
+ }
42
+ const stream = createReadStream(path, {
43
+ start: state.offset,
44
+ end: stat.size - 1,
45
+ encoding: "utf-8",
46
+ });
47
+ let buf = state.partial;
48
+ stream.on("data", (chunk) => {
49
+ buf += chunk;
50
+ });
51
+ stream.on("error", (err) => reject(err));
52
+ stream.on("end", () => {
53
+ state.offset = stat.size;
54
+ const lines = buf.split("\n");
55
+ state.partial = lines.pop() ?? "";
56
+ const replies = [];
57
+ for (const line of lines) {
58
+ if (line.trim() === "")
59
+ continue;
60
+ try {
61
+ const parsed = RelayResponseSchema.safeParse(JSON.parse(line));
62
+ if (parsed.success)
63
+ replies.push(parsed.data);
64
+ }
65
+ catch {
66
+ /* skip malformed */
67
+ }
68
+ }
69
+ resolve(replies);
70
+ });
71
+ });
72
+ }
73
+ export async function watchCommand(argsAndOptions) {
74
+ const { args, options } = argsAndOptions;
75
+ const issueArg = args[0];
76
+ if (!issueArg) {
77
+ throw new Error("Usage: sequant watch <issue>");
78
+ }
79
+ const issueNumber = Number.parseInt(issueArg, 10);
80
+ if (!Number.isInteger(issueNumber) || issueNumber <= 0) {
81
+ throw new Error(`Invalid issue number: '${issueArg}'`);
82
+ }
83
+ const stateManager = new StateManager();
84
+ const issueState = await stateManager.getIssueState(issueNumber);
85
+ const outboxPath = outboxPathFor(issueNumber, {
86
+ worktreePath: issueState?.worktree,
87
+ });
88
+ const pollIntervalMs = options.pollIntervalMs ?? 200;
89
+ const tail = { offset: 0, partial: "" };
90
+ // Seed tail offset at current EOF so we only show NEW replies.
91
+ if (existsSync(outboxPath)) {
92
+ tail.offset = statSync(outboxPath).size;
93
+ }
94
+ if (!options.json) {
95
+ console.log(chalk.gray(`Watching #${issueNumber} outbox — Ctrl+C to stop`));
96
+ }
97
+ let stopped = false;
98
+ const stop = () => {
99
+ stopped = true;
100
+ };
101
+ options.signal?.addEventListener("abort", stop);
102
+ process.on("SIGINT", () => {
103
+ stop();
104
+ if (!options.json)
105
+ console.log(chalk.gray("\nStopped watching."));
106
+ process.exit(0);
107
+ });
108
+ let useWatcher = false;
109
+ let watcher = null;
110
+ try {
111
+ if (existsSync(outboxPath)) {
112
+ watcher = watch(outboxPath, { persistent: true }, () => {
113
+ // fs.watch fires on any modification; we still poll readNewLines.
114
+ });
115
+ useWatcher = true;
116
+ }
117
+ }
118
+ catch {
119
+ useWatcher = false;
120
+ }
121
+ const emit = (replies) => {
122
+ for (const r of replies) {
123
+ console.log(formatLine(r, options.json === true));
124
+ }
125
+ };
126
+ // Polling loop — also used as a heartbeat when fs.watch is active so we
127
+ // don't miss events on filesystems where watch is unreliable.
128
+ while (!stopped) {
129
+ try {
130
+ const replies = await readNewLines(outboxPath, tail);
131
+ emit(replies);
132
+ }
133
+ catch {
134
+ /* transient — try again next tick */
135
+ }
136
+ await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
137
+ }
138
+ if (watcher) {
139
+ try {
140
+ watcher.close();
141
+ }
142
+ catch {
143
+ /* swallow */
144
+ }
145
+ }
146
+ void useWatcher; // currently unused beyond best-effort init
147
+ }
@@ -19,7 +19,7 @@ import type { AcceptanceCriterion } from "./workflow/state-schema.js";
19
19
  /**
20
20
  * Types of issues that can be flagged in AC
21
21
  */
22
- export type ACLintIssueType = "vague" | "unmeasurable" | "incomplete" | "open_ended";
22
+ export type ACLintIssueType = "vague" | "unmeasurable" | "incomplete" | "open_ended" | "title-body-tension";
23
23
  /**
24
24
  * A lint issue found in an acceptance criterion
25
25
  */