@smithers-orchestrator/cli 0.16.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 (110) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +55 -0
  3. package/src/AgentAvailability.ts +13 -0
  4. package/src/AgentAvailabilityStatus.ts +5 -0
  5. package/src/AggregateNodeDetailParams.ts +5 -0
  6. package/src/AskOptions.ts +12 -0
  7. package/src/ChatAttemptMeta.ts +7 -0
  8. package/src/ChatAttemptRow.ts +12 -0
  9. package/src/ChatOutputEvent.ts +6 -0
  10. package/src/DiffBundleLike.ts +6 -0
  11. package/src/DiscoveredWorkflow.ts +9 -0
  12. package/src/EnrichedNodeDetail.ts +60 -0
  13. package/src/EventCategory.ts +18 -0
  14. package/src/FindDbWaitOptions.ts +4 -0
  15. package/src/FormatEventLineOptions.ts +4 -0
  16. package/src/HijackCandidate.ts +11 -0
  17. package/src/HijackLaunchSpec.ts +6 -0
  18. package/src/InitWorkflowPackOptions.ts +4 -0
  19. package/src/InitWorkflowPackResult.ts +6 -0
  20. package/src/NativeHijackEngine.ts +8 -0
  21. package/src/NodeDetailAttempt.ts +22 -0
  22. package/src/NodeDetailTokenUsage.ts +11 -0
  23. package/src/NodeDetailToolCall.ts +12 -0
  24. package/src/ParsedNodeOutputEvent.ts +9 -0
  25. package/src/RenderNodeDetailOptions.ts +4 -0
  26. package/src/RunAutoResumeSkipReason.ts +4 -0
  27. package/src/RunDiffCommandInput.ts +13 -0
  28. package/src/RunDiffCommandResult.ts +3 -0
  29. package/src/RunOutputCommandInput.ts +12 -0
  30. package/src/RunOutputCommandResult.ts +3 -0
  31. package/src/RunRewindCommandInput.ts +14 -0
  32. package/src/RunRewindCommandResult.ts +3 -0
  33. package/src/RunTreeCommandInput.ts +14 -0
  34. package/src/RunTreeCommandResult.ts +3 -0
  35. package/src/SmithersEventType.ts +3 -0
  36. package/src/SupervisorOptions.ts +33 -0
  37. package/src/SupervisorPollSummary.ts +6 -0
  38. package/src/TreeRenderOptions.ts +5 -0
  39. package/src/WatchLoopOptions.ts +9 -0
  40. package/src/WatchLoopResult.ts +8 -0
  41. package/src/WatchRenderContext.ts +4 -0
  42. package/src/WhyBlocker.ts +17 -0
  43. package/src/WhyBlockerKind.ts +9 -0
  44. package/src/WhyDiagnosis.ts +10 -0
  45. package/src/WorkflowCta.ts +4 -0
  46. package/src/WorkflowSourceType.ts +1 -0
  47. package/src/agent-detection.js +257 -0
  48. package/src/ask.js +491 -0
  49. package/src/chat.js +226 -0
  50. package/src/diff.js +221 -0
  51. package/src/event-categories.js +141 -0
  52. package/src/find-db.js +93 -0
  53. package/src/format.js +272 -0
  54. package/src/hijack-session.js +207 -0
  55. package/src/hijack.js +226 -0
  56. package/src/index.d.ts +1 -0
  57. package/src/index.js +4868 -0
  58. package/src/mcp/SemanticMcpServerOptions.ts +4 -0
  59. package/src/mcp/SemanticToolCallResult.ts +14 -0
  60. package/src/mcp/SemanticToolContext.ts +6 -0
  61. package/src/mcp/SemanticToolDefinition.ts +13 -0
  62. package/src/mcp/SemanticToolError.ts +6 -0
  63. package/src/mcp/semantic-server.js +41 -0
  64. package/src/mcp/semantic-tools.js +1242 -0
  65. package/src/node-detail.js +682 -0
  66. package/src/output.js +111 -0
  67. package/src/resume-detached.js +37 -0
  68. package/src/rewind.js +88 -0
  69. package/src/scheduler.js +112 -0
  70. package/src/smithersRuntime.js +63 -0
  71. package/src/supervisor.js +418 -0
  72. package/src/tree.js +307 -0
  73. package/src/tui/app.jsx +139 -0
  74. package/src/tui/app.tsx +5 -0
  75. package/src/tui/components/AskModal.jsx +109 -0
  76. package/src/tui/components/AskModal.tsx +3 -0
  77. package/src/tui/components/AttentionPane.jsx +112 -0
  78. package/src/tui/components/AttentionPane.tsx +6 -0
  79. package/src/tui/components/ChatPane.jsx +57 -0
  80. package/src/tui/components/ChatPane.tsx +7 -0
  81. package/src/tui/components/CronList.jsx +87 -0
  82. package/src/tui/components/CronList.tsx +5 -0
  83. package/src/tui/components/DetailsPane.jsx +96 -0
  84. package/src/tui/components/DetailsPane.tsx +7 -0
  85. package/src/tui/components/FramesPane.jsx +147 -0
  86. package/src/tui/components/FramesPane.tsx +8 -0
  87. package/src/tui/components/LogsPane.jsx +46 -0
  88. package/src/tui/components/LogsPane.tsx +6 -0
  89. package/src/tui/components/MetricsPane.jsx +108 -0
  90. package/src/tui/components/MetricsPane.tsx +5 -0
  91. package/src/tui/components/NodeDetailView.jsx +284 -0
  92. package/src/tui/components/NodeDetailView.tsx +7 -0
  93. package/src/tui/components/NodeInspector.jsx +51 -0
  94. package/src/tui/components/NodeInspector.tsx +7 -0
  95. package/src/tui/components/RunDetailView.jsx +190 -0
  96. package/src/tui/components/RunDetailView.tsx +7 -0
  97. package/src/tui/components/RunsList.jsx +184 -0
  98. package/src/tui/components/RunsList.tsx +7 -0
  99. package/src/tui/components/SqliteBrowser.jsx +131 -0
  100. package/src/tui/components/SqliteBrowser.tsx +5 -0
  101. package/src/tui/components/WorkflowLauncher.jsx +63 -0
  102. package/src/tui/components/WorkflowLauncher.tsx +3 -0
  103. package/src/util/CliErrorMapping.ts +7 -0
  104. package/src/util/CliExitCode.ts +10 -0
  105. package/src/util/errorMessage.js +212 -0
  106. package/src/util/exitCodes.js +18 -0
  107. package/src/watch.js +128 -0
  108. package/src/why-diagnosis.js +1000 -0
  109. package/src/workflow-pack.js +2151 -0
  110. package/src/workflows.js +122 -0
package/src/watch.js ADDED
@@ -0,0 +1,128 @@
1
+ // @smithers-type-exports-begin
2
+ /** @typedef {import("./WatchRenderContext.ts").WatchRenderContext} WatchRenderContext */
3
+ // @smithers-type-exports-end
4
+
5
+
6
+ /**
7
+ * @template T
8
+ * @typedef {import("./WatchLoopOptions.ts").WatchLoopOptions<T>} WatchLoopOptions
9
+ */
10
+ /**
11
+ * @template T
12
+ * @typedef {import("./WatchLoopResult.ts").WatchLoopResult<T>} WatchLoopResult
13
+ */
14
+ const CLEAR_SCREEN_SEQUENCE = "\x1B[2J\x1B[0f";
15
+ export const WATCH_MIN_INTERVAL_MS = 500;
16
+ /**
17
+ * @param {number} ms
18
+ */
19
+ function sleep(ms) {
20
+ return new Promise((resolve) => setTimeout(resolve, ms));
21
+ }
22
+ /**
23
+ * @param {number} requestedMs
24
+ * @returns {number}
25
+ */
26
+ export function clampWatchIntervalMs(requestedMs) {
27
+ if (!Number.isFinite(requestedMs) || requestedMs <= 0) {
28
+ throw new Error("Watch interval must be greater than 0 seconds.");
29
+ }
30
+ return Math.max(Math.floor(requestedMs), WATCH_MIN_INTERVAL_MS);
31
+ }
32
+ /**
33
+ * @param {number} intervalSeconds
34
+ * @returns {number}
35
+ */
36
+ export function watchIntervalSecondsToMs(intervalSeconds) {
37
+ return clampWatchIntervalMs(intervalSeconds * 1_000);
38
+ }
39
+ function clearTerminalScreen() {
40
+ process.stdout.write(CLEAR_SCREEN_SEQUENCE);
41
+ }
42
+ /**
43
+ * @template T
44
+ * @param {WatchLoopOptions<T>} options
45
+ * @returns {Promise<WatchLoopResult<T>>}
46
+ */
47
+ export async function runWatchLoop(options) {
48
+ const intervalMs = watchIntervalSecondsToMs(options.intervalSeconds);
49
+ let tickCount = 0;
50
+ let stoppedBySignal = false;
51
+ let signal;
52
+ let signalHandled = false;
53
+ let resolveSignalPromise;
54
+ const signalPromise = new Promise((resolve) => {
55
+ resolveSignalPromise = resolve;
56
+ });
57
+ /**
58
+ * @param {NodeJS.Signals} nextSignal
59
+ */
60
+ const handleSignal = (nextSignal) => {
61
+ if (signalHandled)
62
+ return;
63
+ signalHandled = true;
64
+ stoppedBySignal = true;
65
+ signal = nextSignal;
66
+ resolveSignalPromise?.("signal");
67
+ };
68
+ const onSigint = () => handleSignal("SIGINT");
69
+ const onSigterm = () => handleSignal("SIGTERM");
70
+ process.once("SIGINT", onSigint);
71
+ process.once("SIGTERM", onSigterm);
72
+ try {
73
+ /**
74
+ * @param {T} snapshot
75
+ * @param {boolean} initial
76
+ */
77
+ const renderSnapshot = async (snapshot, initial) => {
78
+ if (!initial && (options.clearScreen ?? true)) {
79
+ clearTerminalScreen();
80
+ }
81
+ await options.render(snapshot, { tickCount, initial });
82
+ };
83
+ const initial = await options.fetch();
84
+ await renderSnapshot(initial, true);
85
+ if (options.isTerminal?.(initial)) {
86
+ return {
87
+ intervalMs,
88
+ tickCount,
89
+ stoppedBySignal: false,
90
+ reachedTerminal: true,
91
+ lastData: initial,
92
+ };
93
+ }
94
+ let latest = initial;
95
+ while (true) {
96
+ const waitResult = await Promise.race([
97
+ sleep(intervalMs).then(() => "tick"),
98
+ signalPromise,
99
+ ]);
100
+ if (waitResult === "signal") {
101
+ return {
102
+ intervalMs,
103
+ tickCount,
104
+ stoppedBySignal,
105
+ reachedTerminal: false,
106
+ signal,
107
+ lastData: latest,
108
+ };
109
+ }
110
+ tickCount += 1;
111
+ latest = await options.fetch();
112
+ await renderSnapshot(latest, false);
113
+ if (options.isTerminal?.(latest)) {
114
+ return {
115
+ intervalMs,
116
+ tickCount,
117
+ stoppedBySignal: false,
118
+ reachedTerminal: true,
119
+ lastData: latest,
120
+ };
121
+ }
122
+ }
123
+ }
124
+ finally {
125
+ process.off("SIGINT", onSigint);
126
+ process.off("SIGTERM", onSigterm);
127
+ }
128
+ }