@sixb/cli-core 0.1.7 → 0.1.9

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.
@@ -1,6 +1,7 @@
1
+ import { randomUUID } from "node:crypto"
1
2
  import type { ApiClient } from "../api-client"
2
3
  import { isHelp, parseCommandArgs, requestsHelp } from "../arguments"
3
- import { fail, writeJson, writeText } from "../output"
4
+ import { fail, writeJson, writeRequestResult, writeText } from "../output"
4
5
  import { GROUP_HELP } from "./metadata"
5
6
  import { readJson } from "./shared"
6
7
 
@@ -21,13 +22,18 @@ export async function workflows(api: ApiClient, args: readonly string[]): Promis
21
22
  const {
22
23
  positionals: [workflowId],
23
24
  options,
24
- } = parseCommandArgs(rest, { "--file": "string" }, "workflows start", 1)
25
+ } = parseCommandArgs(rest, { "--file": "string", "--run-id": "string" }, "workflows start", 1)
25
26
  const input: unknown = options["--file"] ? await readJson(options["--file"]) : {}
26
27
  if (Array.isArray(input) || typeof input !== "object" || input === null) {
27
28
  fail("Workflow input must be a JSON object.")
28
29
  }
29
- return writeJson(
30
- await api.post(`/api/workflows/${encodeURIComponent(workflowId ?? "")}/runs`, { input })
30
+ // Every start names its run, so a repeated request returns the same run instead of another.
31
+ const runId = options["--run-id"] ?? `run_${randomUUID()}`
32
+ return writeRequestResult(
33
+ await api.post(`/api/workflows/${encodeURIComponent(workflowId ?? "")}/runs`, {
34
+ input,
35
+ runId,
36
+ })
31
37
  )
32
38
  }
33
39
  fail(`Unknown workflows command '${sub}'.`)
package/src/output.ts CHANGED
@@ -2,6 +2,8 @@
2
2
  export const INSTANCE_CLI_VERSION = "1"
3
3
  export const EXIT_USAGE = 2
4
4
  export const EXIT_API = 3
5
+ /** The request waits for its user's approval: it did not run. */
6
+ export const EXIT_AWAITING_APPROVAL = 4
5
7
 
6
8
  export interface CliErrorBody {
7
9
  readonly code: string
@@ -31,11 +33,30 @@ export function writeJson(value: unknown): void {
31
33
  process.stdout.write(`${JSON.stringify(value)}\n`)
32
34
  }
33
35
 
36
+ /** Ends a command that already wrote its output, with an exit code that is not a success. */
37
+ export class CliExit extends Error {
38
+ constructor(readonly exitCode: number) {
39
+ super(`The Sixb CLI exited with code ${exitCode}.`)
40
+ this.name = "CliExit"
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Print what a request that changes state answered. A request held for the user's approval prints
46
+ * as the API answered it, and exits with {@link EXIT_AWAITING_APPROVAL}: `a && b` does not run `b`.
47
+ */
48
+ export function writeRequestResult(value: unknown): void {
49
+ writeJson(value)
50
+ const status = typeof value === "object" && value !== null ? Reflect.get(value, "status") : null
51
+ if (status === "awaiting_approval") throw new CliExit(EXIT_AWAITING_APPROVAL)
52
+ }
53
+
34
54
  export function writeText(value: string): void {
35
55
  process.stdout.write(value.endsWith("\n") ? value : `${value}\n`)
36
56
  }
37
57
 
38
58
  export function reportError(error: unknown): number {
59
+ if (error instanceof CliExit) return error.exitCode
39
60
  const cliError =
40
61
  error instanceof CliError
41
62
  ? error
package/src/policies.ts CHANGED
@@ -6,6 +6,8 @@ export const CLI_LIMITS = {
6
6
  vectorSearchText: { maximum: 8_000 },
7
7
  telemetryHistory: { default: 100, maximum: 1_000 },
8
8
  linkPage: { default: 100, maximum: 1_000 },
9
+ /** The server lists at most 200 members per page. */
10
+ users: { default: 20, maximum: 200 },
9
11
  inspect: {
10
12
  depth: { default: 2, maximum: 3 },
11
13
  objects: { default: 20, maximum: 100 },