@sixb/cli 0.1.24 → 0.1.26

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 (76) hide show
  1. package/README.md +5 -5
  2. package/dist/commands/agent.d.ts +16 -0
  3. package/dist/commands/agent.d.ts.map +1 -0
  4. package/dist/commands/dev-runner.d.ts +0 -1
  5. package/dist/commands/dev-runner.d.ts.map +1 -1
  6. package/dist/commands/worker-group.d.ts +0 -1
  7. package/dist/commands/worker-group.d.ts.map +1 -1
  8. package/dist/commands/worker.d.ts +0 -1
  9. package/dist/commands/worker.d.ts.map +1 -1
  10. package/dist/lib/command-line.d.ts +16 -6
  11. package/dist/lib/command-line.d.ts.map +1 -1
  12. package/dist/lib/deploy-release.d.ts.map +1 -1
  13. package/dist/lib/github-ci.d.ts.map +1 -1
  14. package/dist/lib/runtime.d.ts +0 -1
  15. package/dist/lib/runtime.d.ts.map +1 -1
  16. package/dist/lib/worker-registry.d.ts +0 -1
  17. package/dist/lib/worker-registry.d.ts.map +1 -1
  18. package/dist/tui/app.d.ts +19 -0
  19. package/dist/tui/app.d.ts.map +1 -0
  20. package/dist/tui/brand.d.ts +7 -0
  21. package/dist/tui/brand.d.ts.map +1 -0
  22. package/dist/tui/computer.d.ts +3 -0
  23. package/dist/tui/computer.d.ts.map +1 -0
  24. package/dist/tui/connection.d.ts +45 -0
  25. package/dist/tui/connection.d.ts.map +1 -0
  26. package/dist/tui/folders.d.ts +7 -0
  27. package/dist/tui/folders.d.ts.map +1 -0
  28. package/dist/tui/format.d.ts +33 -0
  29. package/dist/tui/format.d.ts.map +1 -0
  30. package/dist/tui/index.d.ts +12 -0
  31. package/dist/tui/index.d.ts.map +1 -0
  32. package/dist/tui/palette.d.ts +25 -0
  33. package/dist/tui/palette.d.ts.map +1 -0
  34. package/dist/tui/parts.d.ts +66 -0
  35. package/dist/tui/parts.d.ts.map +1 -0
  36. package/dist/tui/runner.d.ts +52 -0
  37. package/dist/tui/runner.d.ts.map +1 -0
  38. package/dist/tui/settings.d.ts +44 -0
  39. package/dist/tui/settings.d.ts.map +1 -0
  40. package/dist/tui/slash.d.ts +14 -0
  41. package/dist/tui/slash.d.ts.map +1 -0
  42. package/dist/tui/theme.d.ts +39 -0
  43. package/dist/tui/theme.d.ts.map +1 -0
  44. package/dist/tui/transcript.d.ts +52 -0
  45. package/dist/tui/transcript.d.ts.map +1 -0
  46. package/dist/tui/ui.d.ts +35 -0
  47. package/dist/tui/ui.d.ts.map +1 -0
  48. package/package.json +17 -15
  49. package/src/commands/agent.ts +337 -0
  50. package/src/commands/dev-runner.ts +0 -4
  51. package/src/commands/worker-group.ts +0 -4
  52. package/src/commands/worker.ts +0 -4
  53. package/src/index.tsx +57 -5
  54. package/src/lib/command-line.ts +52 -15
  55. package/src/lib/deploy-release.ts +0 -11
  56. package/src/lib/github-ci.ts +3 -1
  57. package/src/lib/runtime.ts +0 -2
  58. package/src/lib/worker-registry.ts +0 -2
  59. package/src/tui/app.tsx +1198 -0
  60. package/src/tui/brand.tsx +51 -0
  61. package/src/tui/computer.ts +54 -0
  62. package/src/tui/connection.ts +149 -0
  63. package/src/tui/folders.ts +41 -0
  64. package/src/tui/format.ts +260 -0
  65. package/src/tui/index.tsx +353 -0
  66. package/src/tui/palette.tsx +183 -0
  67. package/src/tui/parts.ts +254 -0
  68. package/src/tui/runner.ts +173 -0
  69. package/src/tui/settings.ts +127 -0
  70. package/src/tui/slash.ts +32 -0
  71. package/src/tui/theme.ts +111 -0
  72. package/src/tui/transcript.tsx +555 -0
  73. package/src/tui/ui.tsx +148 -0
  74. package/dist/lib/agent-turn-timeout.d.ts +0 -8
  75. package/dist/lib/agent-turn-timeout.d.ts.map +0 -1
  76. package/src/lib/agent-turn-timeout.ts +0 -46
@@ -0,0 +1,14 @@
1
+ /** A command typed in the composer, as `/model`. */
2
+ export interface SlashCommand {
3
+ readonly name: string;
4
+ readonly description: string;
5
+ run(): void;
6
+ }
7
+ /** The commands a composer's text starts to name: all of them for a lone `/`. */
8
+ export declare function slashMatches(commands: readonly SlashCommand[], text: string): readonly SlashCommand[];
9
+ /**
10
+ * The command a message runs when it is sent: the one chosen in the menu its text opens, the first
11
+ * when none was. Undefined for anything else, which is sent to the agent.
12
+ */
13
+ export declare function pickSlash(commands: readonly SlashCommand[], text: string, chosen?: number): SlashCommand | undefined;
14
+ //# sourceMappingURL=slash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slash.d.ts","sourceRoot":"","sources":["../../src/tui/slash.ts"],"names":[],"mappings":"AAGA,oDAAoD;AACpD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,GAAG,IAAI,IAAI,CAAA;CACZ;AAED,iFAAiF;AACjF,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,SAAS,YAAY,EAAE,EACjC,IAAI,EAAE,MAAM,GACX,SAAS,YAAY,EAAE,CAIzB;AAED;;;GAGG;AACH,wBAAgB,SAAS,CACvB,QAAQ,EAAE,SAAS,YAAY,EAAE,EACjC,IAAI,EAAE,MAAM,EACZ,MAAM,SAAI,GACT,YAAY,GAAG,SAAS,CAG1B"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The full-screen app's colors. It paints no background of its own: the terminal's shows through,
3
+ * and panels are the terminal's background with a little of its foreground mixed in, so they sit
4
+ * right on any theme. Blue is for what is live or chosen, amber for what waits on you.
5
+ */
6
+ export interface TuiColors {
7
+ /** Always the terminal's own. */
8
+ readonly background: string;
9
+ /** Panels: the composer, a user's message, a dialog. */
10
+ readonly surface: string;
11
+ /** A panel's selected row. */
12
+ readonly raised: string;
13
+ readonly border: string;
14
+ readonly text: string;
15
+ readonly muted: string;
16
+ readonly faint: string;
17
+ readonly blue: string;
18
+ readonly water: readonly string[];
19
+ /** The wordmark's blues, palest first, deep enough to read on this background. */
20
+ readonly wordmark: readonly string[];
21
+ /** Inline code in the agent's answers. */
22
+ readonly code: string;
23
+ readonly green: string;
24
+ readonly amber: string;
25
+ readonly red: string;
26
+ }
27
+ /** What the terminal says its own colors are, when it answers. */
28
+ export interface TerminalColors {
29
+ readonly background: string;
30
+ readonly foreground: string;
31
+ }
32
+ /**
33
+ * The colors for this terminal: from its own background and foreground when it reports them, else
34
+ * Sixb's night or day colors for the mode it reports.
35
+ */
36
+ export declare function tuiColors(mode: "light" | "dark" | null, terminal?: TerminalColors | null): TuiColors;
37
+ /** `amount` of `to` mixed into `from`, both `#rrggbb`. */
38
+ export declare function mix(from: string, to: string, amount: number): string;
39
+ //# sourceMappingURL=theme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/tui/theme.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,iCAAiC;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,wDAAwD;IACxD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,8BAA8B;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;IACjC,kFAAkF;IAClF,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;IACpC,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CACrB;AAED,kEAAkE;AAClE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAC5B;AAoCD;;;GAGG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,EAC7B,QAAQ,GAAE,cAAc,GAAG,IAAW,GACrC,SAAS,CAcX;AAED,0DAA0D;AAC1D,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAOpE"}
@@ -0,0 +1,52 @@
1
+ /** @jsxImportSource @opentui/react */
2
+ import type { SyntaxStyle } from "@opentui/core";
3
+ import type { ListAgentThreadApprovalsResponses, ListAgentThreadRunsResponses } from "@sixb/client";
4
+ import { type LiveRun, type ShownMessage } from "./parts";
5
+ import type { TuiColors } from "./theme";
6
+ export type Run = ListAgentThreadRunsResponses[200]["runs"][number];
7
+ export type Approval = ListAgentThreadApprovalsResponses[200]["approvals"][number];
8
+ /** How a turn's model is named under its answer: its catalog name, else its id. */
9
+ export type ModelNames = ReadonlyMap<string, string>;
10
+ export declare function Transcript({ colors, syntax, messages, runs, live, approvals, modelNames, computerRuns, width, folder, approvalChoice, }: {
11
+ readonly colors: TuiColors;
12
+ readonly syntax: SyntaxStyle;
13
+ readonly messages: readonly ShownMessage[];
14
+ readonly runs: readonly Run[];
15
+ readonly live: LiveRun | null;
16
+ readonly approvals: readonly Approval[];
17
+ readonly modelNames: ModelNames;
18
+ /** Whether the thread's turns run on its owner's computer. */
19
+ readonly computerRuns: boolean;
20
+ /** The terminal's width: rows that must stay one line are cut to it. */
21
+ readonly width: number;
22
+ /** The folder a computer's turns work in: paths in it are shown relative to it. */
23
+ readonly folder?: string;
24
+ /** The choice the first waiting call's card shows chosen. */
25
+ readonly approvalChoice: number;
26
+ }): import("react").ReactNode;
27
+ /** How a call waiting for the person can be decided, in the order the card offers them. */
28
+ export declare const APPROVAL_CHOICES: readonly [{
29
+ readonly key: "y";
30
+ readonly label: "Allow";
31
+ readonly decision: "approve";
32
+ readonly always: false;
33
+ }, {
34
+ readonly key: "a";
35
+ readonly label: "Always in this thread";
36
+ readonly decision: "approve";
37
+ readonly always: true;
38
+ }, {
39
+ readonly key: "n";
40
+ readonly label: "Deny";
41
+ readonly decision: "deny";
42
+ readonly always: false;
43
+ }];
44
+ /** While a turn works: the spinner, how long, and how to stop it. */
45
+ export declare function Working({ colors, since, label, stopping, }: {
46
+ readonly colors: TuiColors;
47
+ readonly since: number;
48
+ readonly label: string;
49
+ /** Waiting for a second esc: the hint is the label then. */
50
+ readonly stopping?: boolean;
51
+ }): import("react").ReactNode;
52
+ //# sourceMappingURL=transcript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcript.d.ts","sourceRoot":"","sources":["../../src/tui/transcript.tsx"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,KAAK,EAAE,iCAAiC,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAEnG,OAAO,EAGL,KAAK,OAAO,EAEZ,KAAK,YAAY,EAClB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAGxC,MAAM,MAAM,GAAG,GAAG,4BAA4B,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAA;AACnE,MAAM,MAAM,QAAQ,GAAG,iCAAiC,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAA;AAElF,mFAAmF;AACnF,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAIpD,wBAAgB,UAAU,CAAC,EACzB,MAAM,EACN,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,UAAU,EACV,YAAY,EACZ,KAAK,EACL,MAAM,EACN,cAAc,GACf,EAAE;IACD,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAA;IAC1B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;IAC5B,QAAQ,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,CAAA;IAC1C,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,CAAA;IAC7B,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAAA;IAC7B,QAAQ,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,CAAA;IACvC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAA;IAC/B,8DAA8D;IAC9D,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAA;IAC9B,wEAAwE;IACxE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,mFAAmF;IACnF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,6DAA6D;IAC7D,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;CAChC,6BA8DA;AA0TD,2FAA2F;AAC3F,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;EAInB,CAAA;AA+DV,qEAAqE;AACrE,wBAAgB,OAAO,CAAC,EACtB,MAAM,EACN,KAAK,EACL,KAAK,EACL,QAAgB,GACjB,EAAE;IACD,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAA;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,4DAA4D;IAC5D,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAC5B,6BAWA"}
@@ -0,0 +1,35 @@
1
+ import type { TuiColors } from "./theme";
2
+ export declare const BOLD: number;
3
+ export declare const ITALIC: number;
4
+ /** One piece of the line under the composer, such as `This Mac` or `Ask first`. */
5
+ export interface StatusItem {
6
+ readonly text: string;
7
+ readonly color: string;
8
+ readonly bold?: boolean;
9
+ }
10
+ /**
11
+ * Where a message is written: a panel with Sixb's blue bar, the line it will be sent with under
12
+ * it. `onSubmit` takes the text; the composer clears once it was taken.
13
+ */
14
+ export declare function Composer({ colors, placeholder, status, focused, accent, allowEmpty, onSubmit, onChange, }: {
15
+ readonly colors: TuiColors;
16
+ readonly placeholder: string;
17
+ readonly status: readonly StatusItem[];
18
+ readonly focused: boolean;
19
+ /** The bar's color: blue, or amber while something waits on the person. */
20
+ readonly accent?: string;
21
+ /** Enter sends an empty composer too, as a form's default does. */
22
+ readonly allowEmpty?: boolean;
23
+ readonly onSubmit: (text: string) => boolean | Promise<boolean>;
24
+ /** The text as it is typed. */
25
+ readonly onChange?: (text: string) => void;
26
+ }): import("react").ReactNode;
27
+ /** Key hints: `tab where shift+tab permissions ctrl+p commands`. */
28
+ export declare function KeyHints({ colors, items, }: {
29
+ readonly colors: TuiColors;
30
+ readonly items: readonly (readonly [key: string, label: string])[];
31
+ }): import("react").ReactNode;
32
+ export declare function useSpinner(active: boolean): string;
33
+ /** Re-renders every `ms` while `active`, for a clock. */
34
+ export declare function useNow(ms: number, active?: boolean): number;
35
+ //# sourceMappingURL=ui.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../../src/tui/ui.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExC,eAAO,MAAM,IAAI,QAAuC,CAAA;AACxD,eAAO,MAAM,MAAM,QAAyC,CAAA;AAU5D,mFAAmF;AACnF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,EACvB,MAAM,EACN,WAAW,EACX,MAAM,EACN,OAAO,EACP,MAAM,EACN,UAAkB,EAClB,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAA;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAA;IACtC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,2EAA2E;IAC3E,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,mEAAmE;IACnE,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;IAC7B,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAC/D,+BAA+B;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAC3C,6BAwDA;AAED,sEAAsE;AACtE,wBAAgB,QAAQ,CAAC,EACvB,MAAM,EACN,KAAK,GACN,EAAE;IACD,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAA;IAC1B,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,EAAE,CAAA;CACnE,6BAYA;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAQlD;AAED,yDAAyD;AACzD,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,UAAO,GAAG,MAAM,CAQxD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sixb/cli",
3
- "version": "0.1.24",
3
+ "version": "0.1.26",
4
4
  "description": "Command-line interface for Sixb projects",
5
5
  "keywords": [
6
6
  "sixb",
@@ -31,23 +31,25 @@
31
31
  "dependencies": {
32
32
  "@opentui/core": "0.6.6",
33
33
  "@opentui/react": "0.6.6",
34
- "@sixb/agent-worker": "0.1.24",
35
- "@sixb/app": "^0.1.16",
36
- "@sixb/client": "^0.1.23",
37
- "@sixb/core": "0.1.24",
38
- "@sixb/cli-core": "^0.1.9",
39
- "@sixb/orchestrator": "0.1.24",
40
- "@sixb/pipeline-worker": "0.1.24",
41
- "@sixb/projection-worker": "0.1.24",
42
- "@sixb/rules-worker": "0.1.24",
43
- "@sixb/server": "0.1.24",
44
- "@sixb/sync-worker": "0.1.24",
45
- "@sixb/workflow-worker": "0.1.24",
46
- "create-sixb": "^0.1.6",
34
+ "@sixb/agent": "0.1.0",
35
+ "@sixb/agent-worker": "0.1.26",
36
+ "@sixb/app": "^0.1.18",
37
+ "@sixb/client": "^0.1.24",
38
+ "@sixb/core": "0.1.26",
39
+ "@sixb/cli-core": "^0.1.10",
40
+ "@sixb/orchestrator": "0.1.26",
41
+ "@sixb/pipeline-worker": "0.1.26",
42
+ "@sixb/projection-worker": "0.1.26",
43
+ "@sixb/rules-worker": "0.1.26",
44
+ "@sixb/sandboxes-local": "^0.1.7",
45
+ "@sixb/server": "0.1.26",
46
+ "@sixb/sync-worker": "0.1.26",
47
+ "@sixb/workflow-worker": "0.1.26",
48
+ "create-sixb": "^0.1.7",
47
49
  "react": "^19.2.0"
48
50
  },
49
51
  "devDependencies": {
50
- "@sixb/deploy-ssh": "0.1.3",
52
+ "@sixb/deploy-ssh": "0.1.4",
51
53
  "@sixb/desktop": "0.1.0",
52
54
  "@sixb/ducklake": "0.1.9",
53
55
  "@types/bun": "latest",
@@ -0,0 +1,337 @@
1
+ import { createInterface } from "node:readline/promises"
2
+ import {
3
+ type AgentRunStreamEvent,
4
+ createAgentRunSocket,
5
+ createAgentThread,
6
+ decideAgentApproval,
7
+ getAgentThread,
8
+ listAgentThreadApprovals,
9
+ listAgentThreadMessages,
10
+ listAgentThreadRuns,
11
+ listModels,
12
+ postAgentThreadMessage,
13
+ } from "@sixb/client"
14
+ import { type Connection, connect } from "../tui/connection"
15
+ import { folderOf, rememberFolder } from "../tui/folders"
16
+ import { toolLine } from "../tui/format"
17
+ import { liveRun, reduceLive, shownMessage } from "../tui/parts"
18
+ import { LocalRunner } from "../tui/runner"
19
+ import {
20
+ APPROVAL_MODES,
21
+ type ApprovalMode,
22
+ approvalLabel,
23
+ loadSettings,
24
+ messageSelection,
25
+ placeLabel,
26
+ } from "../tui/settings"
27
+ import { glyph, paint, palette, tone } from "../ui/theme"
28
+
29
+ /** Exit status when the turn stopped on calls only the person can decide, and nobody could ask. */
30
+ const EXIT_WAITING = 4
31
+
32
+ /**
33
+ * `sixb agent "<message>"`: one message to the agent, answered in the terminal. The turn runs on
34
+ * this computer in the current folder, or in the cloud with `--cloud`; its steps go to stderr and
35
+ * its answer to stdout, so the answer can be piped.
36
+ */
37
+ export async function runAgent(options: {
38
+ readonly text: readonly string[]
39
+ readonly thread?: string
40
+ readonly cloud: boolean
41
+ /** The turn's mode; without it, the person's in the thread applies, as for a message in the web. */
42
+ readonly approvalMode?: string
43
+ readonly json: boolean
44
+ readonly apiUrl?: string
45
+ readonly profile?: string
46
+ }): Promise<void> {
47
+ const approvalMode = parseApprovalMode(options.approvalMode)
48
+ const text = options.text.join(" ").trim() || (await readStdin())
49
+ if (!text) throw new Error('[SixbCLI] Give the agent a message: sixb agent "<message>".')
50
+
51
+ const connection = await connect(options)
52
+ if ("reason" in connection) {
53
+ throw new Error(
54
+ connection.reason === "unreachable"
55
+ ? `[SixbCLI] Sixb isn't answering at ${connection.apiUrl}.`
56
+ : `[SixbCLI] Sign in first: sixb login ${connection.apiUrl || "<api-url>"}.`
57
+ )
58
+ }
59
+ const { client } = connection
60
+ const settings = await loadSettings()
61
+ const models = (await listModels({ client })).data?.language ?? []
62
+
63
+ const threadId =
64
+ options.thread ??
65
+ (
66
+ await createAgentThread({
67
+ client,
68
+ body: {
69
+ title: text.split("\n")[0]?.slice(0, 72) ?? "Conversation",
70
+ ...(options.cloud ? {} : { runsOn: "computer" as const }),
71
+ },
72
+ throwOnError: true,
73
+ })
74
+ ).data.thread.id
75
+ // Read as the person: it says the mode their turns run in there.
76
+ const { data: thread } = await getAgentThread({ client, path: { threadId }, throwOnError: true })
77
+ const onComputer = thread.runsOn === "computer"
78
+ if (onComputer) {
79
+ const folder = await folderOf(thread.id)
80
+ if (options.thread && folder !== process.cwd()) {
81
+ throw new Error(
82
+ folder
83
+ ? `[SixbCLI] This conversation works in ${folder}: run sixb agent there.`
84
+ : "[SixbCLI] This conversation started on another computer: open it with sixb there."
85
+ )
86
+ }
87
+ if (!options.thread) await rememberFolder(thread.id, process.cwd())
88
+ }
89
+ const runner = onComputer
90
+ ? new LocalRunner(connection, process.cwd(), (error) => step(tone.fail(errorText(error))))
91
+ : null
92
+ if (!options.json) {
93
+ const mode = approvalMode ?? thread.approvalMode
94
+ step(
95
+ `${tone.blue(glyph.mark)} ${tone.strong(placeLabel(onComputer ? "computer" : "cloud"))}` +
96
+ tone.faint(` · ${mode ? `${approvalLabel(mode)} · ` : ""}${thread.id}`)
97
+ )
98
+ }
99
+
100
+ const stop = new AbortController()
101
+ process.once("SIGINT", () => stop.abort())
102
+ try {
103
+ const { data: posted } = await postAgentThreadMessage({
104
+ client,
105
+ path: { threadId: thread.id },
106
+ body: {
107
+ text,
108
+ ...(approvalMode ? { approvalMode } : {}),
109
+ timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
110
+ locale: Intl.DateTimeFormat().resolvedOptions().locale,
111
+ ...messageSelection(models, settings),
112
+ },
113
+ throwOnError: true,
114
+ })
115
+ let runId: string | null = posted.run.id
116
+ let followed: Awaited<ReturnType<typeof follow>> = "finished"
117
+ while (runId) {
118
+ // A turn this computer could not claim would wait here for nobody.
119
+ const unclaimed = runner?.claim(runId).then((claimed) => !claimed)
120
+ followed = await follow(connection, runId, options.json, stop.signal, unclaimed)
121
+ if (followed === "unclaimed") {
122
+ process.exitCode = 1
123
+ step(
124
+ tone.fail("This computer couldn't claim the turn: another runner holds it, or it ended.")
125
+ )
126
+ return
127
+ }
128
+ if (followed !== "finished") break
129
+ runId = await afterTurn(connection, thread.id, runId, options.json)
130
+ }
131
+
132
+ // A lost stream or Ctrl+C leaves a turn that may still run: its answer is not the turn's.
133
+ if (followed !== "finished") {
134
+ process.exitCode = 1
135
+ if (followed === "stopped") step(tone.fail(`Stopped waiting for the turn in ${thread.id}.`))
136
+ }
137
+
138
+ await printAnswer(connection, thread.id, options.json)
139
+ } finally {
140
+ await runner?.stop()
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Show a turn's steps as they finish, until it ends, the stream fails, the person stops waiting,
146
+ * or `unclaimed` says this computer could not run it.
147
+ */
148
+ async function follow(
149
+ connection: Connection,
150
+ runId: string,
151
+ json: boolean,
152
+ signal: AbortSignal,
153
+ unclaimed?: Promise<boolean>
154
+ ): Promise<"finished" | "stopped" | "failed" | "unclaimed"> {
155
+ let live = liveRun(runId)
156
+ const shown = new Set<string>()
157
+ return new Promise((resolve) => {
158
+ let settled = false
159
+ const settle = (outcome: "finished" | "stopped" | "failed" | "unclaimed") => {
160
+ if (settled) return
161
+ settled = true
162
+ socket.close()
163
+ signal.removeEventListener("abort", onAbort)
164
+ resolve(outcome)
165
+ }
166
+ const onAbort = () => settle("stopped")
167
+ const socket = createAgentRunSocket({
168
+ client: connection.client,
169
+ runId,
170
+ // A turn that ended before the stream opened: its snapshot says so.
171
+ onRunSnapshot: (run) => {
172
+ if (run.status !== "queued" && run.status !== "running") settle("finished")
173
+ },
174
+ onError: (message) => {
175
+ step(tone.fail(message))
176
+ settle("failed")
177
+ },
178
+ onEvent: (event: AgentRunStreamEvent) => {
179
+ live = reduceLive(live, event)
180
+ if (!json) {
181
+ for (const part of live.parts) {
182
+ if (part.kind !== "tool" || part.state === "running" || shown.has(part.id)) continue
183
+ shown.add(part.id)
184
+ const line = toolLine(part)
185
+ const mark = line.held
186
+ ? tone.warn(glyph.live)
187
+ : line.failed || part.state === "error"
188
+ ? tone.fail(glyph.live)
189
+ : tone.ok(glyph.live)
190
+ step(
191
+ `${mark} ${tone.strong(line.verb)} ${tone.muted(line.detail)}${line.note ? tone.faint(` ${line.note}`) : ""}`
192
+ )
193
+ }
194
+ }
195
+ if (event.type === "agent.run.finished") settle("finished")
196
+ },
197
+ })
198
+ signal.addEventListener("abort", onAbort)
199
+ void unclaimed?.then((refused) => {
200
+ if (refused) settle("unclaimed")
201
+ })
202
+ })
203
+ }
204
+
205
+ /**
206
+ * What follows a turn's end: the turn that resumes once its held calls are decided, asked here
207
+ * when a person is at the terminal. Null when nothing follows.
208
+ */
209
+ async function afterTurn(
210
+ connection: Connection,
211
+ threadId: string,
212
+ runId: string,
213
+ json: boolean
214
+ ): Promise<string | null> {
215
+ const { client } = connection
216
+ const { data: runs } = await listAgentThreadRuns({ client, path: { threadId } })
217
+ const run = runs?.runs.find((entry) => entry.id === runId)
218
+ if (run?.finishReason !== "awaiting_approval") return null
219
+
220
+ const { data } = await listAgentThreadApprovals({
221
+ client,
222
+ path: { threadId },
223
+ query: { status: "pending", runId },
224
+ })
225
+ const approvals = data?.approvals ?? []
226
+ if (approvals.length === 0 || json || !process.stdin.isTTY) {
227
+ for (const approval of approvals) step(tone.warn(`? ${describe(approval.call)}`))
228
+ step(tone.faint(`Decide in the app, or run sixb in this folder and open the conversation.`))
229
+ process.exitCode = EXIT_WAITING
230
+ return null
231
+ }
232
+
233
+ const prompt = createInterface({ input: process.stdin, output: process.stderr })
234
+ try {
235
+ for (const approval of approvals) {
236
+ const answer = (
237
+ await prompt.question(
238
+ `${paint("?", { color: palette.amber })} ${tone.strong(describe(approval.call))} ${tone.muted("[y] allow [a] always in this thread [n] deny ")}`
239
+ )
240
+ )
241
+ .trim()
242
+ .toLowerCase()
243
+ await decideAgentApproval({
244
+ client,
245
+ path: { threadId, approvalId: approval.id },
246
+ body:
247
+ answer === "a"
248
+ ? { decision: "approve", always: true }
249
+ : { decision: answer === "y" ? "approve" : "deny" },
250
+ throwOnError: true,
251
+ })
252
+ }
253
+ } finally {
254
+ prompt.close()
255
+ }
256
+ // Deciding the last one resumes the turn as a new run.
257
+ for (let attempt = 0; attempt < 20; attempt += 1) {
258
+ const { data: thread } = await getAgentThread({ client, path: { threadId } })
259
+ if (thread?.activeRunId && thread.activeRunId !== runId) return thread.activeRunId
260
+ await Bun.sleep(250)
261
+ }
262
+ return null
263
+ }
264
+
265
+ /** The turn's answer: its last message's text, or as JSON. */
266
+ async function printAnswer(connection: Connection, threadId: string, json: boolean) {
267
+ const { client } = connection
268
+ const [{ data: messages }, { data: runs }] = await Promise.all([
269
+ listAgentThreadMessages({ client, path: { threadId }, query: { order: "desc", limit: "1" } }),
270
+ listAgentThreadRuns({ client, path: { threadId }, query: { order: "desc", limit: "1" } }),
271
+ ])
272
+ const last = messages?.messages[0]
273
+ const shown = last ? shownMessage(last) : null
274
+ const answer =
275
+ shown?.role === "assistant"
276
+ ? shown.parts.flatMap((part) => (part.kind === "text" ? [part.text.trim()] : [])).join("\n\n")
277
+ : ""
278
+ const run = runs?.runs[0]
279
+
280
+ // Set before the JSON goes out: a script reads the code, not the status in the answer.
281
+ if (run?.status === "failed" || run?.status === "cancelled") process.exitCode = 1
282
+
283
+ if (json) {
284
+ process.stdout.write(
285
+ `${JSON.stringify({ threadId, runId: run?.id, status: run?.status, finishReason: run?.finishReason, text: answer })}\n`
286
+ )
287
+ return
288
+ }
289
+ if (answer) process.stdout.write(`\n${process.stdout.isTTY ? styled(answer) : answer}\n`)
290
+ if (run?.status === "failed") step(tone.fail(run.error?.message ?? "The turn failed."))
291
+ if (run?.status === "cancelled") step(tone.fail("The turn was stopped."))
292
+ }
293
+
294
+ function parseApprovalMode(value: string | undefined): ApprovalMode | undefined {
295
+ if (value === undefined) return undefined
296
+
297
+ const mode = APPROVAL_MODES.find((entry) => entry.mode === value)?.mode
298
+ if (!mode) {
299
+ throw new Error(
300
+ `[SixbCLI] --approval-mode takes ${APPROVAL_MODES.map((entry) => entry.mode).join(", ")}; got '${value}'.`
301
+ )
302
+ }
303
+ return mode
304
+ }
305
+
306
+ function describe(
307
+ call:
308
+ | { readonly kind: "action"; readonly actionId: string }
309
+ | { readonly kind: "workflow"; readonly workflowId: string }
310
+ ): string {
311
+ return call.kind === "action" ? `Run ${call.actionId}?` : `Start the ${call.workflowId} workflow?`
312
+ }
313
+
314
+ function step(line: string): void {
315
+ process.stderr.write(` ${line}\n`)
316
+ }
317
+
318
+ async function readStdin(): Promise<string> {
319
+ if (process.stdin.isTTY) return ""
320
+ let text = ""
321
+ for await (const chunk of process.stdin) text += chunk.toString()
322
+ return text.trim()
323
+ }
324
+
325
+ function errorText(error: unknown): string {
326
+ return error instanceof Error ? error.message : String(error)
327
+ }
328
+
329
+ /**
330
+ * The answer as a terminal shows it: bold and inline code styled, their markers gone. Piped, the
331
+ * answer stays the markdown it is.
332
+ */
333
+ function styled(markdown: string): string {
334
+ return markdown
335
+ .replace(/\*\*([^*\n]+)\*\*/g, (_, text: string) => tone.strong(text))
336
+ .replace(/`([^`\n]+)`/g, (_, text: string) => tone.blue(text))
337
+ }
@@ -6,7 +6,6 @@ import {
6
6
  createCustomApp,
7
7
  } from "@sixb/app/server"
8
8
  import { createSixbServer } from "@sixb/server"
9
- import { resolveAgentTurnTimeoutMs } from "../lib/agent-turn-timeout"
10
9
  import {
11
10
  apiDocsUrl,
12
11
  apiEventsUrl,
@@ -40,7 +39,6 @@ export interface DevOptions {
40
39
  apiHost?: string
41
40
  apiPublicOrigin?: string
42
41
  appPublicOrigin?: string
43
- agentTurnTimeout?: string
44
42
  concurrency?: readonly string[]
45
43
  vectorConcurrency?: string
46
44
  subagentConcurrency?: string
@@ -52,7 +50,6 @@ export interface DevOptions {
52
50
  export async function runDevRuntime(options: DevOptions = {}) {
53
51
  process.env.NODE_ENV = "development"
54
52
 
55
- const agentTurnTimeoutMs = resolveAgentTurnTimeoutMs(options.agentTurnTimeout)
56
53
  const workerConcurrency = resolveWorkerConcurrency(options.concurrency)
57
54
  const vectorConcurrency = resolveVectorConcurrency(options.vectorConcurrency)
58
55
  const subagents = resolveSubagentConcurrency({
@@ -134,7 +131,6 @@ export async function runDevRuntime(options: DevOptions = {}) {
134
131
  stop: () => server.stop(),
135
132
  },
136
133
  agentApiBaseUrl: topology.apiPublicOrigin,
137
- agentTurnTimeoutMs,
138
134
  workerConcurrency,
139
135
  vectorConcurrency,
140
136
  ...subagents,
@@ -1,4 +1,3 @@
1
- import { resolveAgentTurnTimeoutMs } from "../lib/agent-turn-timeout"
2
1
  import { type LoadedSixbHost, loadSixbFromEntry } from "../lib/loadSixb"
3
2
  import { resolveRuntimeEntry } from "../lib/production"
4
3
  import { runUntilSignal, stopQuietly } from "../lib/role-lifecycle"
@@ -32,7 +31,6 @@ export interface WorkerGroupOptions {
32
31
  noMigrate?: boolean
33
32
  workerTypes?: readonly string[]
34
33
  apiPublicOrigin?: string
35
- agentTurnTimeout?: string
36
34
  concurrency?: readonly string[]
37
35
  vectorConcurrency?: string
38
36
  subagentConcurrency?: string
@@ -45,7 +43,6 @@ export async function runWorkerGroup(options: WorkerGroupOptions = {}) {
45
43
  // Validate explicit worker types before loading the runtime so an unknown type
46
44
  // fails fast, just like `sixb worker`.
47
45
  const requestedTypes = (options.workerTypes ?? []).map(resolveWorkerTypeToStart)
48
- const agentTurnTimeoutMs = resolveAgentTurnTimeoutMs(options.agentTurnTimeout)
49
46
  const workerConcurrency = resolveWorkerConcurrency(options.concurrency)
50
47
  const vectorConcurrency = resolveVectorConcurrency(options.vectorConcurrency)
51
48
  const subagents = resolveSubagentConcurrency({
@@ -98,7 +95,6 @@ export async function runWorkerGroup(options: WorkerGroupOptions = {}) {
98
95
  workers = workerTypes.map((workerType) =>
99
96
  createWorkerForType(host, workerType, {
100
97
  agentApiBaseUrl: options.apiPublicOrigin,
101
- agentTurnTimeoutMs,
102
98
  workerConcurrency,
103
99
  vectorConcurrency,
104
100
  ...subagents,
@@ -1,4 +1,3 @@
1
- import { resolveAgentTurnTimeoutMs } from "../lib/agent-turn-timeout"
2
1
  import { SixbCliError } from "../lib/errors"
3
2
  import { type LoadedSixbHost, loadSixbFromEntry } from "../lib/loadSixb"
4
3
  import { resolveRuntimeEntry } from "../lib/production"
@@ -25,7 +24,6 @@ export interface WorkerOptions {
25
24
  noMigrate?: boolean
26
25
  workerType?: string
27
26
  apiPublicOrigin?: string
28
- agentTurnTimeout?: string
29
27
  concurrency?: string
30
28
  vectorConcurrency?: string
31
29
  subagentConcurrency?: string
@@ -36,7 +34,6 @@ export async function runWorker(options: WorkerOptions = {}) {
36
34
  process.env.NODE_ENV = "production"
37
35
 
38
36
  const workerType = resolveWorkerTypeToStart(options.workerType)
39
- const agentTurnTimeoutMs = resolveAgentTurnTimeoutMs(options.agentTurnTimeout)
40
37
  const workerConcurrency = resolveSingleWorkerConcurrency(workerType, options.concurrency)
41
38
  const vectorConcurrency = resolveVectorConcurrency(options.vectorConcurrency)
42
39
  const subagents = resolveSubagentConcurrency({
@@ -79,7 +76,6 @@ export async function runWorker(options: WorkerOptions = {}) {
79
76
 
80
77
  worker = createWorkerForType(sixb, workerType, {
81
78
  agentApiBaseUrl: options.apiPublicOrigin,
82
- agentTurnTimeoutMs,
83
79
  workerConcurrency,
84
80
  vectorConcurrency,
85
81
  ...subagents,