@smithers-orchestrator/cli 0.16.9 → 0.18.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 (49) hide show
  1. package/dist/CliExitCode-dlFKbqup.d.ts +12 -0
  2. package/dist/HijackCandidate-FxLeKpcZ.d.ts +13 -0
  3. package/dist/SemanticToolDefinition-C1UT6pZk.d.ts +71 -0
  4. package/dist/SupervisorOptions-DtiPbGFx.d.ts +27 -0
  5. package/dist/agent-commands/agentAddWizard.d.ts +18 -0
  6. package/dist/agent-commands/regenerateAgentsTsIfPresent.d.ts +15 -0
  7. package/dist/agent-commands/runAgentAdd.d.ts +83 -0
  8. package/dist/agent-detection.d.ts +27 -0
  9. package/dist/ask.d.ts +29 -0
  10. package/dist/chat.d.ts +96 -0
  11. package/dist/diff.d.ts +64 -0
  12. package/dist/event-categories.d.ts +26 -0
  13. package/dist/find-db.d.ts +47 -0
  14. package/dist/format.d.ts +35 -0
  15. package/dist/hijack-session.d.ts +25 -0
  16. package/dist/hijack.d.ts +54 -0
  17. package/dist/index.d.ts +1 -0
  18. package/dist/mcp/semantic-server.d.ts +30 -0
  19. package/dist/mcp/semantic-tools.d.ts +4 -0
  20. package/dist/mdx-plugin.d.ts +3 -0
  21. package/dist/node-detail.d.ts +143 -0
  22. package/dist/output.d.ts +31 -0
  23. package/dist/resume-detached.d.ts +17 -0
  24. package/dist/rewind.d.ts +28 -0
  25. package/dist/scheduler.d.ts +3 -0
  26. package/dist/smithersRuntime.d.ts +23 -0
  27. package/dist/supervisor.d.ts +44 -0
  28. package/dist/tree.d.ts +51 -0
  29. package/dist/util/errorMessage.d.ts +40 -0
  30. package/dist/util/exitCodes.d.ts +19 -0
  31. package/dist/watch.d.ts +44 -0
  32. package/dist/why-diagnosis.d.ts +56 -0
  33. package/dist/workflow-pack.d.ts +38 -0
  34. package/dist/workflows.d.ts +35 -0
  35. package/package.json +25 -15
  36. package/src/InitWorkflowPackOptions.ts +2 -0
  37. package/src/InitWorkflowPackResult.ts +8 -2
  38. package/src/agent-commands/agentAddWizard.js +190 -0
  39. package/src/agent-commands/regenerateAgentsTsIfPresent.js +28 -0
  40. package/src/agent-commands/runAgentAdd.js +147 -0
  41. package/src/agent-detection.js +214 -17
  42. package/src/hijack-session.js +1 -1
  43. package/src/index.js +526 -23
  44. package/src/mcp/semantic-tools.js +1 -1
  45. package/src/mdx-plugin.js +6 -0
  46. package/src/output.js +52 -0
  47. package/src/smithersRuntime.js +2 -1
  48. package/src/util/logger.ts +97 -0
  49. package/src/workflow-pack.js +802 -34
@@ -0,0 +1,6 @@
1
+ import { plugin } from "bun";
2
+ import mdx from "@mdx-js/esbuild";
3
+
4
+ export function mdxPlugin() {
5
+ plugin(mdx());
6
+ }
package/src/output.js CHANGED
@@ -8,6 +8,9 @@ import { NodeOutputRouteError } from "@smithers-orchestrator/server/gatewayRoute
8
8
  import { EXIT_OK } from "./util/exitCodes.js";
9
9
  import { formatCliErrorForStderr, getCliErrorMapping } from "./util/errorMessage.js";
10
10
 
11
+ const RUN_ID_PATTERN = /^[a-z0-9_-]{1,64}$/;
12
+ const NODE_ID_PATTERN = /^[a-zA-Z0-9:_-]{1,128}$/;
13
+
11
14
  /**
12
15
  * @param {any} response
13
16
  * @returns {string}
@@ -69,6 +72,52 @@ async function resolveLatestIteration(adapter, runId, nodeId) {
69
72
  }
70
73
  }
71
74
 
75
+ /**
76
+ * @param {Record<string, unknown> | null} row
77
+ * @returns {Record<string, unknown> | null}
78
+ */
79
+ function stripOutputKeyColumns(row) {
80
+ if (!row || typeof row !== "object") {
81
+ return null;
82
+ }
83
+ const result = { ...row };
84
+ delete result.run_id;
85
+ delete result.runId;
86
+ delete result.node_id;
87
+ delete result.nodeId;
88
+ delete result.iteration;
89
+ return result;
90
+ }
91
+
92
+ /**
93
+ * @param {RunOutputCommandInput} input
94
+ * @param {number} iteration
95
+ * @returns {Promise<RunOutputCommandResult>}
96
+ */
97
+ async function runRawJsonOutput(input, iteration) {
98
+ if (!RUN_ID_PATTERN.test(input.runId)) {
99
+ throw new NodeOutputRouteError("InvalidRunId", "runId must match /^[a-z0-9_-]{1,64}$/.");
100
+ }
101
+ if (!NODE_ID_PATTERN.test(input.nodeId)) {
102
+ throw new NodeOutputRouteError("InvalidNodeId", "nodeId must match /^[a-zA-Z0-9:_-]{1,128}$/.");
103
+ }
104
+ const run = await input.adapter.getRun(input.runId);
105
+ if (!run) {
106
+ throw new NodeOutputRouteError("RunNotFound", `Run not found: ${input.runId}`);
107
+ }
108
+ const node = await input.adapter.getNode(input.runId, input.nodeId, iteration);
109
+ if (!node) {
110
+ throw new NodeOutputRouteError("NodeNotFound", `Node not found: ${input.nodeId}`);
111
+ }
112
+ const outputTable = typeof node.outputTable === "string" ? node.outputTable.trim() : "";
113
+ if (!outputTable) {
114
+ throw new NodeOutputRouteError("NodeHasNoOutput", `Node ${input.nodeId} has no output table.`);
115
+ }
116
+ const row = await input.adapter.getRawNodeOutputForIteration(outputTable, input.runId, input.nodeId, iteration);
117
+ input.stdout.write(`${JSON.stringify(stripOutputKeyColumns(row))}\n`);
118
+ return { exitCode: EXIT_OK };
119
+ }
120
+
72
121
  /**
73
122
  * @param {RunOutputCommandInput} input
74
123
  * @returns {Promise<RunOutputCommandResult>}
@@ -80,6 +129,9 @@ export async function runOutputOnce(input) {
80
129
  iteration = latest ?? 0;
81
130
  }
82
131
  try {
132
+ if (input.json && !input.pretty) {
133
+ return await runRawJsonOutput(input, iteration);
134
+ }
83
135
  const response = await getNodeOutputRoute({
84
136
  runId: input.runId,
85
137
  nodeId: input.nodeId,
@@ -3,10 +3,11 @@ import { Cause, Effect, Exit, Layer, ManagedRuntime } from "effect";
3
3
  import { SchedulerLive, WorkflowSessionLive } from "@smithers-orchestrator/scheduler";
4
4
  import { CorrelationContextLive, MetricsServiceLive, TracingServiceLive, createSmithersRuntimeLayer, getCurrentSmithersTraceAnnotations, getCurrentSmithersTraceSpan, } from "@smithers-orchestrator/observability";
5
5
  import { toSmithersError } from "@smithers-orchestrator/errors/toSmithersError";
6
+ import { SmithersLoggerLayer } from "./util/logger.ts";
6
7
  const ObservabilityLayer = Layer.mergeAll(CorrelationContextLive, MetricsServiceLive, TracingServiceLive);
7
8
  const SmithersCoreLayer = Layer.mergeAll(ObservabilityLayer, SchedulerLive.pipe(Layer.provide(ObservabilityLayer)), WorkflowSessionLive);
8
9
  const SmithersWorkflowEngineLayer = Layer.suspend(() => WorkflowEngine.layerMemory);
9
- const SmithersRuntimeLayer = Layer.mergeAll(SmithersCoreLayer, SmithersWorkflowEngineLayer, createSmithersRuntimeLayer()).pipe(Layer.orDie);
10
+ const SmithersRuntimeLayer = Layer.mergeAll(SmithersLoggerLayer, SmithersCoreLayer, SmithersWorkflowEngineLayer, createSmithersRuntimeLayer()).pipe(Layer.orDie);
10
11
  const runtime = ManagedRuntime.make(SmithersRuntimeLayer);
11
12
  /**
12
13
  * @template A, E, R
@@ -0,0 +1,97 @@
1
+ import { format } from "node:util";
2
+ import { Logger } from "effect";
3
+
4
+ type JsonModeState = {
5
+ jsonMode: boolean;
6
+ consoleRoutingInstalled: boolean;
7
+ originalConsole?: {
8
+ debug: typeof console.debug;
9
+ error: typeof console.error;
10
+ info: typeof console.info;
11
+ log: typeof console.log;
12
+ trace: typeof console.trace;
13
+ warn: typeof console.warn;
14
+ };
15
+ };
16
+
17
+ const STATE_KEY = Symbol.for("smithers.cli.jsonMode");
18
+
19
+ function getState(): JsonModeState {
20
+ const globalState = globalThis as typeof globalThis & {
21
+ [STATE_KEY]?: JsonModeState;
22
+ };
23
+ globalState[STATE_KEY] ??= {
24
+ jsonMode: false,
25
+ consoleRoutingInstalled: false,
26
+ };
27
+ return globalState[STATE_KEY];
28
+ }
29
+
30
+ export function setJsonMode(enabled: boolean): void {
31
+ getState().jsonMode = enabled;
32
+ }
33
+
34
+ export function isJsonMode(): boolean {
35
+ return getState().jsonMode === true;
36
+ }
37
+
38
+ function writeConsoleArgsToStderr(args: ReadonlyArray<unknown>): void {
39
+ process.stderr.write(`${format(...args)}\n`);
40
+ }
41
+
42
+ export function installJsonModeConsoleRouting(): void {
43
+ const state = getState();
44
+ if (state.consoleRoutingInstalled) {
45
+ return;
46
+ }
47
+
48
+ const originalConsole = {
49
+ debug: console.debug.bind(console),
50
+ error: console.error.bind(console),
51
+ info: console.info.bind(console),
52
+ log: console.log.bind(console),
53
+ trace: console.trace.bind(console),
54
+ warn: console.warn.bind(console),
55
+ };
56
+
57
+ console.debug = (...args: unknown[]) => {
58
+ if (isJsonMode()) return writeConsoleArgsToStderr(args);
59
+ return originalConsole.debug(...args);
60
+ };
61
+ console.error = (...args: unknown[]) => {
62
+ if (isJsonMode()) return writeConsoleArgsToStderr(args);
63
+ return originalConsole.error(...args);
64
+ };
65
+ console.info = (...args: unknown[]) => {
66
+ if (isJsonMode()) return writeConsoleArgsToStderr(args);
67
+ return originalConsole.info(...args);
68
+ };
69
+ console.log = (...args: unknown[]) => {
70
+ if (isJsonMode()) return writeConsoleArgsToStderr(args);
71
+ return originalConsole.log(...args);
72
+ };
73
+ console.trace = (...args: unknown[]) => {
74
+ if (isJsonMode()) return writeConsoleArgsToStderr(args);
75
+ return originalConsole.trace(...args);
76
+ };
77
+ console.warn = (...args: unknown[]) => {
78
+ if (isJsonMode()) return writeConsoleArgsToStderr(args);
79
+ return originalConsole.warn(...args);
80
+ };
81
+
82
+ state.originalConsole = originalConsole;
83
+ state.consoleRoutingInstalled = true;
84
+ }
85
+
86
+ export const smithersEffectLogger = Logger.make<unknown, void>((options) => {
87
+ const line = Logger.stringLogger.log(options);
88
+ const stream = isJsonMode() ? process.stderr : process.stdout;
89
+ stream.write(`${line}\n`);
90
+ });
91
+
92
+ export const SmithersLoggerLayer = Logger.replace(
93
+ Logger.defaultLogger,
94
+ smithersEffectLogger,
95
+ );
96
+
97
+ installJsonModeConsoleRouting();