@h-rig/cli 0.0.6-alpha.90 → 0.0.6-alpha.92

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 (118) hide show
  1. package/README.md +18 -19
  2. package/dist/bin/build-rig-binaries.js +22 -10
  3. package/dist/bin/rig.d.ts +71 -1
  4. package/dist/bin/rig.js +15078 -11169
  5. package/dist/config/rig-default-config.yml +5 -0
  6. package/dist/src/app/drone-ui.d.ts +11 -14
  7. package/dist/src/app/drone-ui.js +70 -86
  8. package/dist/src/commands/_async-ui.d.ts +1 -4
  9. package/dist/src/commands/_async-ui.js +9 -111
  10. package/dist/src/commands/_cli-format.d.ts +16 -9
  11. package/dist/src/commands/_cli-format.js +167 -295
  12. package/dist/src/commands/_connection-state.d.ts +11 -1
  13. package/dist/src/commands/_connection-state.js +50 -5
  14. package/dist/src/commands/_doctor-checks.d.ts +0 -6
  15. package/dist/src/commands/_doctor-checks.js +79 -382
  16. package/dist/src/commands/_help-catalog.d.ts +1 -1
  17. package/dist/src/commands/_help-catalog.js +217 -157
  18. package/dist/src/commands/_inprocess-services.d.ts +33 -0
  19. package/dist/src/commands/_inprocess-services.js +102 -0
  20. package/dist/src/commands/_json-output.js +4 -0
  21. package/dist/src/commands/_lazy-reconcile.d.ts +34 -0
  22. package/dist/src/commands/_lazy-reconcile.js +102 -0
  23. package/dist/src/commands/_paths.js +1 -1
  24. package/dist/src/commands/_pi-frontend.d.ts +18 -10
  25. package/dist/src/commands/_pi-frontend.js +37 -715
  26. package/dist/src/commands/_pi-install.js +18 -36
  27. package/dist/src/commands/_policy.d.ts +1 -1
  28. package/dist/src/commands/_policy.js +56 -15
  29. package/dist/src/commands/_run-bridge.d.ts +114 -0
  30. package/dist/src/commands/_run-bridge.js +387 -0
  31. package/dist/src/commands/_run-diagnostics.d.ts +9 -0
  32. package/dist/src/commands/_run-diagnostics.js +51 -0
  33. package/dist/src/commands/_run-driver-helpers.d.ts +8 -81
  34. package/dist/src/commands/_run-driver-helpers.js +79 -283
  35. package/dist/src/commands/_run-projection.d.ts +50 -0
  36. package/dist/src/commands/_run-projection.js +349 -0
  37. package/dist/src/commands/_run-subcommands.d.ts +3 -0
  38. package/dist/src/commands/_run-subcommands.js +31 -0
  39. package/dist/src/commands/_spinner.js +1 -1
  40. package/dist/src/commands/agent.d.ts +1 -1
  41. package/dist/src/commands/agent.js +8559 -239
  42. package/dist/src/commands/dist.d.ts +1 -1
  43. package/dist/src/commands/dist.js +27 -19
  44. package/dist/src/commands/doctor.d.ts +1 -1
  45. package/dist/src/commands/doctor.js +93 -475
  46. package/dist/src/commands/github.d.ts +1 -1
  47. package/dist/src/commands/github.js +113 -387
  48. package/dist/src/commands/inbox.d.ts +22 -24
  49. package/dist/src/commands/inbox.js +420 -691
  50. package/dist/src/commands/init.d.ts +6 -16
  51. package/dist/src/commands/init.js +334 -971
  52. package/dist/src/commands/inspect.d.ts +19 -2
  53. package/dist/src/commands/inspect.js +644 -610
  54. package/dist/src/commands/pi.d.ts +1 -1
  55. package/dist/src/commands/plugin.d.ts +1 -1
  56. package/dist/src/commands/plugin.js +486 -7
  57. package/dist/src/commands/profile-and-review.d.ts +1 -1
  58. package/dist/src/commands/profile-and-review.js +94 -56
  59. package/dist/src/commands/queue.js +1 -21
  60. package/dist/src/commands/remote.d.ts +1 -1
  61. package/dist/src/commands/remote.js +837 -14
  62. package/dist/src/commands/repo-git-harness.d.ts +1 -1
  63. package/dist/src/commands/repo-git-harness.js +57 -14
  64. package/dist/src/commands/run.d.ts +20 -2
  65. package/dist/src/commands/run.js +17579 -1759
  66. package/dist/src/commands/server.d.ts +2 -6
  67. package/dist/src/commands/server.js +141 -723
  68. package/dist/src/commands/setup.d.ts +1 -1
  69. package/dist/src/commands/setup.js +102 -484
  70. package/dist/src/commands/stats.d.ts +13 -10
  71. package/dist/src/commands/stats.js +689 -761
  72. package/dist/src/commands/task-run-driver.d.ts +50 -88
  73. package/dist/src/commands/task-run-driver.js +116 -2717
  74. package/dist/src/commands/task.d.ts +34 -13
  75. package/dist/src/commands/task.js +668 -2523
  76. package/dist/src/commands/test.d.ts +1 -1
  77. package/dist/src/commands/triage.d.ts +11 -0
  78. package/dist/src/commands/triage.js +227 -0
  79. package/dist/src/commands/workspace.d.ts +1 -1
  80. package/dist/src/commands.d.ts +0 -16
  81. package/dist/src/commands.js +16657 -12250
  82. package/dist/src/index.js +16528 -12497
  83. package/dist/src/launcher.js +4 -0
  84. package/dist/src/operator-cli.d.ts +2 -0
  85. package/dist/src/operator-cli.js +17837 -0
  86. package/dist/src/operator-entry.d.ts +1 -0
  87. package/dist/src/operator-entry.js +3 -0
  88. package/package.json +18 -12
  89. package/dist/src/app/board.d.ts +0 -23
  90. package/dist/src/app/board.js +0 -1786
  91. package/dist/src/app/theme.d.ts +0 -47
  92. package/dist/src/app/theme.js +0 -150
  93. package/dist/src/commands/_authority-runs.d.ts +0 -22
  94. package/dist/src/commands/_authority-runs.js +0 -110
  95. package/dist/src/commands/_operator-surface.d.ts +0 -34
  96. package/dist/src/commands/_operator-surface.js +0 -220
  97. package/dist/src/commands/_operator-view.d.ts +0 -30
  98. package/dist/src/commands/_operator-view.js +0 -1070
  99. package/dist/src/commands/_preflight.d.ts +0 -22
  100. package/dist/src/commands/_preflight.js +0 -540
  101. package/dist/src/commands/_run-replay.d.ts +0 -24
  102. package/dist/src/commands/_run-replay.js +0 -142
  103. package/dist/src/commands/_server-client.d.ts +0 -186
  104. package/dist/src/commands/_server-client.js +0 -681
  105. package/dist/src/commands/_snapshot-upload.d.ts +0 -39
  106. package/dist/src/commands/_snapshot-upload.js +0 -455
  107. package/dist/src/commands/_task-picker.d.ts +0 -9
  108. package/dist/src/commands/_task-picker.js +0 -201
  109. package/dist/src/commands/browser.d.ts +0 -65
  110. package/dist/src/commands/browser.js +0 -1173
  111. package/dist/src/commands/connect.d.ts +0 -7
  112. package/dist/src/commands/connect.js +0 -419
  113. package/dist/src/commands/inspector.d.ts +0 -3
  114. package/dist/src/commands/inspector.js +0 -263
  115. package/dist/src/commands/task-report-bug.d.ts +0 -19
  116. package/dist/src/commands/task-report-bug.js +0 -1281
  117. package/dist/src/report-bug.d.ts +0 -44
  118. package/dist/src/report-bug.js +0 -260
@@ -1,47 +0,0 @@
1
- export declare const RIG_PALETTE: {
2
- /** --ink: primary text */
3
- readonly ink: "#f2f3f6";
4
- /** --ink-2: body text */
5
- readonly ink2: "#aeb0ba";
6
- /** --ink-3: muted */
7
- readonly ink3: "#6c6e79";
8
- /** --ink-4: faint */
9
- readonly ink4: "#44464f";
10
- /** --ac: acid green accent */
11
- readonly accent: "#ccff4d";
12
- /** --ac-dim */
13
- readonly accentDim: "#a9d63f";
14
- /** --ac-2: cyan secondary */
15
- readonly cyan: "#56d8ff";
16
- /** status colors tuned to sit on the dark site bg */
17
- readonly red: "#ff5d5d";
18
- readonly yellow: "#ffd24d";
19
- };
20
- /** 24-bit foreground colorizer. */
21
- export declare function fg(hex: string): (text: string) => string;
22
- export declare const ink: (text: string) => string;
23
- export declare const ink2: (text: string) => string;
24
- export declare const ink3: (text: string) => string;
25
- export declare const ink4: (text: string) => string;
26
- export declare const accent: (text: string) => string;
27
- export declare const accentDim: (text: string) => string;
28
- export declare const cyan: (text: string) => string;
29
- export declare const red: (text: string) => string;
30
- export declare const yellow: (text: string) => string;
31
- export declare function bold(text: string): string;
32
- /** Run-status color, matching the site's pipeline color story. */
33
- export declare function statusColor(status: string): (text: string) => string;
34
- /** The braille spinner the site's hero terminal mirrors. */
35
- export declare const RIG_SPINNER_FRAMES: readonly ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
36
- /**
37
- * Render one animation frame of the drone. `tick` drives rotor rotation and
38
- * the eye pulse — call with an incrementing counter (the site advances the
39
- * rotor every 4 ticks and pulses the eye on a sine).
40
- */
41
- export declare function renderDroneFrame(tick: number): string[];
42
- export declare const DRONE_WIDTH: number;
43
- export declare const DRONE_HEIGHT: 18;
44
- export declare function microDroneFrame(tick: number): string;
45
- export declare const MICRO_DRONE_FRAMES: readonly string[];
46
- /** Truecolor micro-drone: cyan rotors, acid eye — site colors. */
47
- export declare function renderMicroDroneFrame(tick: number): string;
@@ -1,150 +0,0 @@
1
- // @bun
2
- // packages/cli/src/app/theme.ts
3
- var RIG_PALETTE = {
4
- ink: "#f2f3f6",
5
- ink2: "#aeb0ba",
6
- ink3: "#6c6e79",
7
- ink4: "#44464f",
8
- accent: "#ccff4d",
9
- accentDim: "#a9d63f",
10
- cyan: "#56d8ff",
11
- red: "#ff5d5d",
12
- yellow: "#ffd24d"
13
- };
14
- function hexToRgb(hex) {
15
- const value = hex.replace("#", "");
16
- return [
17
- Number.parseInt(value.slice(0, 2), 16),
18
- Number.parseInt(value.slice(2, 4), 16),
19
- Number.parseInt(value.slice(4, 6), 16)
20
- ];
21
- }
22
- function fg(hex) {
23
- const [r, g, b] = hexToRgb(hex);
24
- return (text) => `\x1B[38;2;${r};${g};${b}m${text}\x1B[39m`;
25
- }
26
- var ink = fg(RIG_PALETTE.ink);
27
- var ink2 = fg(RIG_PALETTE.ink2);
28
- var ink3 = fg(RIG_PALETTE.ink3);
29
- var ink4 = fg(RIG_PALETTE.ink4);
30
- var accent = fg(RIG_PALETTE.accent);
31
- var accentDim = fg(RIG_PALETTE.accentDim);
32
- var cyan = fg(RIG_PALETTE.cyan);
33
- var red = fg(RIG_PALETTE.red);
34
- var yellow = fg(RIG_PALETTE.yellow);
35
- function bold(text) {
36
- return `\x1B[1m${text}\x1B[22m`;
37
- }
38
- function statusColor(status) {
39
- switch (status) {
40
- case "running":
41
- return accent;
42
- case "preparing":
43
- case "created":
44
- case "validating":
45
- case "reviewing":
46
- case "closing-out":
47
- return cyan;
48
- case "needs-attention":
49
- case "needs_attention":
50
- return yellow;
51
- case "failed":
52
- return red;
53
- default:
54
- return ink3;
55
- }
56
- }
57
- var RIG_SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
58
- var DRONE_ART = [
59
- " .-=-. .-=-. ",
60
- " ( !!! ) ( !!! ) ",
61
- " '-=-'._ _.'-=-' ",
62
- " '._ _.' ",
63
- " '=$$$$$$$=.' ",
64
- " =$$$$$$$$$$$= ",
65
- " $$$@@@@@@@@@@$$$ ",
66
- " $$$@@ @@$$$ ",
67
- " $$@ ? @$$$ ",
68
- " $$$@ '-' @$$$ ",
69
- " $$$@@ @@$$$ ",
70
- " $$$@@@@@@@@@@$$$ ",
71
- " =$$$$$$$$$$$= ",
72
- " '=$$$$$$$=.' ",
73
- " _.' '._ ",
74
- " .-=-.' '.-=-. ",
75
- " ( !!! ) ( !!! ) ",
76
- " '-=-' '-=-' "
77
- ];
78
- var BLADE_FRAMES = ["---", "\\\\\\", "|||", "///"];
79
- var EYE_FRAMES = ["@", "o", "."];
80
- function droneCharColor(char) {
81
- if (char === "$" || char === "@")
82
- return accent;
83
- if (char === "=" || char === "%")
84
- return accentDim;
85
- if (char === "\\" || char === "/")
86
- return ink3;
87
- return ink4;
88
- }
89
- function renderDroneFrame(tick) {
90
- const blade = BLADE_FRAMES[Math.floor(tick / 4) % BLADE_FRAMES.length];
91
- const pulse = Math.sin(tick * 0.07);
92
- const eye = pulse > 0.45 ? EYE_FRAMES[0] : pulse > -0.1 ? EYE_FRAMES[1] : EYE_FRAMES[2];
93
- return DRONE_ART.map((line) => {
94
- let out = "";
95
- let index = 0;
96
- while (index < line.length) {
97
- if (line.startsWith("!!!", index)) {
98
- out += cyan(blade);
99
- index += 3;
100
- continue;
101
- }
102
- const char = line[index];
103
- if (char === "?") {
104
- out += bold(cyan(eye));
105
- } else if (char !== " ") {
106
- out += droneCharColor(char)(char);
107
- } else {
108
- out += " ";
109
- }
110
- index += 1;
111
- }
112
- return out;
113
- });
114
- }
115
- var DRONE_WIDTH = DRONE_ART[0].length;
116
- var DRONE_HEIGHT = DRONE_ART.length;
117
- var MICRO_BLADES = ["---", "\\\\\\", "|||", "///"];
118
- function microDroneFrame(tick) {
119
- const blade = MICRO_BLADES[tick % MICRO_BLADES.length];
120
- const eye = EYE_FRAMES[Math.floor(tick / 2) % EYE_FRAMES.length];
121
- return `(${blade})${eye}(${blade})`;
122
- }
123
- var MICRO_DRONE_FRAMES = Array.from({ length: 12 }, (_, index) => microDroneFrame(index));
124
- function renderMicroDroneFrame(tick) {
125
- const blade = MICRO_BLADES[tick % MICRO_BLADES.length];
126
- const eye = EYE_FRAMES[Math.floor(tick / 2) % EYE_FRAMES.length];
127
- return `${ink4("(")}${cyan(blade)}${ink4(")")}${bold(accent(eye))}${ink4("(")}${cyan(blade)}${ink4(")")}`;
128
- }
129
- export {
130
- yellow,
131
- statusColor,
132
- renderMicroDroneFrame,
133
- renderDroneFrame,
134
- red,
135
- microDroneFrame,
136
- ink4,
137
- ink3,
138
- ink2,
139
- ink,
140
- fg,
141
- cyan,
142
- bold,
143
- accentDim,
144
- accent,
145
- RIG_SPINNER_FRAMES,
146
- RIG_PALETTE,
147
- MICRO_DRONE_FRAMES,
148
- DRONE_WIDTH,
149
- DRONE_HEIGHT
150
- };
@@ -1,22 +0,0 @@
1
- import { type AuthorityRunRecord } from "@rig/runtime/control-plane/authority-files";
2
- import type { RunStatus } from "@rig/contracts";
3
- export declare const RIG_WORKSPACE_ID = "rig-local-workspace";
4
- export type RuntimeAdapter = "claude-code" | "codex" | "pi";
5
- export declare function normalizeRuntimeAdapter(value: string | undefined): RuntimeAdapter;
6
- export declare function readLatestBeadRecord(projectRoot: string, taskId: string): Record<string, unknown> | null;
7
- export declare function upsertAgentAuthorityRun(projectRoot: string, input: {
8
- runId: string;
9
- taskId: string;
10
- createdAt: string;
11
- runtimeAdapter?: string;
12
- status: RunStatus;
13
- startedAt?: string | null;
14
- completedAt?: string | null;
15
- worktreePath?: string | null;
16
- artifactRoot?: string | null;
17
- logRoot?: string | null;
18
- sessionPath?: string | null;
19
- sessionLogPath?: string | null;
20
- pid?: number | null;
21
- errorText?: string | null;
22
- }): AuthorityRunRecord & Record<string, unknown>;
@@ -1,110 +0,0 @@
1
- // @bun
2
- // packages/cli/src/commands/_authority-runs.ts
3
- import { existsSync } from "fs";
4
- import { resolve } from "path";
5
- import {
6
- readAuthorityRun,
7
- readJsonlFile,
8
- writeAuthorityRunRecord
9
- } from "@rig/runtime/control-plane/authority-files";
10
-
11
- // packages/cli/src/commands/_paths.ts
12
- import { resolveMonorepoRoot } from "@rig/runtime/control-plane/native/utils";
13
- function resolveControlPlaneMonorepoRoot(projectRoot) {
14
- return resolveMonorepoRoot(projectRoot);
15
- }
16
-
17
- // packages/cli/src/commands/_authority-runs.ts
18
- var RIG_WORKSPACE_ID = "rig-local-workspace";
19
- function normalizeRuntimeAdapter(value) {
20
- const normalized = value?.trim().toLowerCase();
21
- if (!normalized) {
22
- return "pi";
23
- }
24
- if (normalized === "codex" || normalized === "codex-cli" || normalized === "codex-app-server" || normalized === "gpt-codex") {
25
- return "codex";
26
- }
27
- if (normalized === "pi" || normalized === "rig-pi" || normalized === "@rig/pi") {
28
- return "pi";
29
- }
30
- return "claude-code";
31
- }
32
- function readLatestBeadRecord(projectRoot, taskId) {
33
- const issuesPath = resolve(resolveControlPlaneMonorepoRoot(projectRoot), ".beads", "issues.jsonl");
34
- if (!existsSync(issuesPath)) {
35
- return null;
36
- }
37
- let latest = null;
38
- for (const issue of readJsonlFile(issuesPath)) {
39
- if (!issue || typeof issue !== "object") {
40
- continue;
41
- }
42
- const record = issue;
43
- if (record.id === taskId) {
44
- latest = record;
45
- }
46
- }
47
- return latest;
48
- }
49
- function resolveTaskTitleForAuthorityRun(projectRoot, taskId) {
50
- try {
51
- const record = readLatestBeadRecord(projectRoot, taskId);
52
- const title = record && typeof record.title === "string" ? record.title.trim() : "";
53
- if (title) {
54
- return title;
55
- }
56
- } catch {}
57
- return null;
58
- }
59
- function upsertAgentAuthorityRun(projectRoot, input) {
60
- const current = readAuthorityRun(projectRoot, input.runId);
61
- const existing = current;
62
- const createdAt = existing?.createdAt ?? input.createdAt;
63
- const runtimeMode = typeof existing?.runtimeMode === "string" ? existing.runtimeMode : "full-access";
64
- const interactionMode = typeof existing?.interactionMode === "string" ? existing.interactionMode : "default";
65
- const runMode = typeof existing?.runMode === "string" ? existing.runMode : "autonomous";
66
- const runtimeAdapter = normalizeRuntimeAdapter(input.runtimeAdapter ?? existing?.runtimeAdapter ?? "claude-code");
67
- const title = resolveTaskTitleForAuthorityRun(projectRoot, input.taskId) ?? input.taskId;
68
- const next = {
69
- ...existing ?? {},
70
- runId: input.runId,
71
- projectRoot,
72
- workspaceId: existing?.workspaceId ?? RIG_WORKSPACE_ID,
73
- taskId: input.taskId,
74
- threadId: existing?.threadId ?? null,
75
- mode: "local",
76
- runtimeAdapter,
77
- status: input.status,
78
- createdAt,
79
- startedAt: input.startedAt ?? existing?.startedAt ?? null,
80
- completedAt: input.completedAt ?? existing?.completedAt ?? null,
81
- endpointId: existing?.endpointId ?? null,
82
- hostId: existing?.hostId ?? null,
83
- worktreePath: input.worktreePath ?? existing?.worktreePath ?? null,
84
- artifactRoot: input.artifactRoot ?? existing?.artifactRoot ?? null,
85
- logRoot: input.logRoot ?? existing?.logRoot ?? null,
86
- sessionPath: input.sessionPath ?? existing?.sessionPath ?? null,
87
- sessionLogPath: input.sessionLogPath ?? existing?.sessionLogPath ?? null,
88
- pid: input.pid ?? existing?.pid ?? null,
89
- updatedAt: input.createdAt,
90
- title,
91
- model: typeof existing?.model === "string" ? existing.model : null,
92
- runtimeMode,
93
- interactionMode,
94
- runMode,
95
- initialPrompt: typeof existing?.initialPrompt === "string" ? existing.initialPrompt : null
96
- };
97
- if (input.errorText !== undefined) {
98
- next.errorText = input.errorText;
99
- } else if ("errorText" in next) {
100
- delete next.errorText;
101
- }
102
- writeAuthorityRunRecord(projectRoot, input.runId, next);
103
- return next;
104
- }
105
- export {
106
- upsertAgentAuthorityRun,
107
- readLatestBeadRecord,
108
- normalizeRuntimeAdapter,
109
- RIG_WORKSPACE_ID
110
- };
@@ -1,34 +0,0 @@
1
- import type { WorkspaceTaskRecord } from "./_server-client";
2
- export type OperatorSnapshot = {
3
- readonly run: Record<string, unknown>;
4
- readonly logs?: readonly Record<string, unknown>[];
5
- readonly timeline?: readonly Record<string, unknown>[];
6
- };
7
- export declare function renderOperatorSnapshot(snapshot: OperatorSnapshot): string;
8
- export type PiRunStreamRenderer = {
9
- renderSnapshot(snapshot: OperatorSnapshot): void;
10
- renderTimeline(entries: readonly Record<string, unknown>[]): void;
11
- renderLogs(entries: readonly Record<string, unknown>[]): void;
12
- };
13
- export declare function createPiRunStreamRenderer(output?: Pick<NodeJS.WriteStream, "write">): PiRunStreamRenderer;
14
- export type OperatorSurface = PiRunStreamRenderer & {
15
- readonly mode: "text" | "pi-compatible-text";
16
- info(message: string): void;
17
- error(message: string): void;
18
- attachCommandInput(handler: (line: string) => void | Promise<void>): {
19
- close(): void;
20
- } | null;
21
- };
22
- export declare function createOperatorSurface(options?: {
23
- readonly input?: NodeJS.ReadStream;
24
- readonly output?: Pick<NodeJS.WriteStream, "write"> & {
25
- readonly isTTY?: boolean;
26
- };
27
- readonly errorOutput?: Pick<NodeJS.WriteStream, "write">;
28
- readonly interactive?: boolean;
29
- }): OperatorSurface;
30
- export type TaskPickerRenderer = {
31
- readonly writeLine: (line: string) => void;
32
- };
33
- export declare function renderTaskPickerRows(tasks: readonly WorkspaceTaskRecord[]): string[];
34
- export declare function promptForTaskSelection(question: string): Promise<string>;
@@ -1,220 +0,0 @@
1
- // @bun
2
- // packages/cli/src/commands/_operator-surface.ts
3
- import { createInterface } from "readline";
4
- import { createInterface as createPromptInterface } from "readline/promises";
5
- var CANONICAL_STAGES = [
6
- "Connect",
7
- "GitHub/task sync",
8
- "Prepare workspace",
9
- "Launch Pi",
10
- "Plan",
11
- "Implement",
12
- "Validate",
13
- "Commit",
14
- "Open PR",
15
- "Review/CI",
16
- "Merge",
17
- "Complete"
18
- ];
19
- function logDetail(log) {
20
- return typeof log.detail === "string" ? log.detail.trim() : "";
21
- }
22
- function parseProviderProtocolLog(title, detail) {
23
- if (title.trim().toLowerCase() !== "agent output")
24
- return null;
25
- if (!detail.startsWith("{") || !detail.endsWith("}"))
26
- return null;
27
- try {
28
- const record = JSON.parse(detail);
29
- if (!record || typeof record !== "object" || Array.isArray(record))
30
- return null;
31
- const type = record.type;
32
- return typeof type === "string" && [
33
- "assistant",
34
- "message_start",
35
- "message_update",
36
- "message_end",
37
- "stream_event",
38
- "tool_result",
39
- "tool_execution_start",
40
- "tool_execution_update",
41
- "tool_execution_end",
42
- "turn_start",
43
- "turn_end"
44
- ].includes(type) ? record : null;
45
- } catch {
46
- return null;
47
- }
48
- }
49
- function renderProviderProtocolLog(record) {
50
- const type = typeof record.type === "string" ? record.type : "";
51
- if (type === "tool_execution_start" || type === "tool_execution_update" || type === "tool_execution_end") {
52
- const toolName = String(record.toolName ?? record.name ?? "tool");
53
- const status = type === "tool_execution_start" ? "started" : type === "tool_execution_end" ? record.isError === true || record.result && typeof record.result === "object" && !Array.isArray(record.result) && record.result.isError === true ? "failed" : "completed" : "running";
54
- return `[Pi tool] ${toolName} ${status}`;
55
- }
56
- return null;
57
- }
58
- function entryId(entry, fallback) {
59
- return typeof entry.id === "string" && entry.id.trim() ? entry.id : fallback;
60
- }
61
- function renderOperatorSnapshot(snapshot) {
62
- const run = snapshot.run.run && typeof snapshot.run.run === "object" ? snapshot.run.run : snapshot.run;
63
- const runId = String(run.runId ?? run.id ?? "run");
64
- const status = String(run.status ?? "unknown");
65
- const logs = snapshot.logs ?? [];
66
- const latestByStage = new Map;
67
- for (const log of logs) {
68
- const title = String(log.title ?? "").toLowerCase();
69
- const stageName = String(log.stage ?? "").toLowerCase();
70
- const stage = CANONICAL_STAGES.find((candidate) => candidate.toLowerCase() === title || candidate.toLowerCase() === stageName);
71
- if (stage)
72
- latestByStage.set(stage, log);
73
- }
74
- const stageLines = CANONICAL_STAGES.flatMap((stage) => {
75
- const match = latestByStage.get(stage);
76
- return match ? [`${stage}: ${String(match.status ?? status)}${logDetail(match) ? ` \u2014 ${logDetail(match)}` : ""}`] : [];
77
- });
78
- return [`Rig run ${runId}: ${status}`, ...stageLines].join(`
79
- `);
80
- }
81
- function createPiRunStreamRenderer(output = process.stdout) {
82
- let lastSnapshot = "";
83
- const assistantTextById = new Map;
84
- const seenTimeline = new Set;
85
- const seenLogs = new Set;
86
- const writeLine = (line) => output.write(`${line}
87
- `);
88
- return {
89
- renderSnapshot(snapshot) {
90
- const rendered = renderOperatorSnapshot(snapshot);
91
- if (rendered && rendered !== lastSnapshot) {
92
- writeLine(rendered);
93
- lastSnapshot = rendered;
94
- }
95
- },
96
- renderTimeline(entries) {
97
- for (const [index, entry] of entries.entries()) {
98
- const id = entryId(entry, `timeline:${index}:${String(entry.cursor ?? "")}`);
99
- if (entry.type === "assistant_message" && typeof entry.text === "string") {
100
- const text = entry.text;
101
- const previousText = assistantTextById.get(id) ?? "";
102
- if (!previousText && text.trim()) {
103
- writeLine("[Pi assistant]");
104
- }
105
- if (text.startsWith(previousText)) {
106
- const delta = text.slice(previousText.length);
107
- if (delta)
108
- output.write(delta);
109
- } else if (text.trim() && text !== previousText) {
110
- if (previousText)
111
- writeLine(`
112
- [Pi assistant]`);
113
- output.write(text);
114
- }
115
- assistantTextById.set(id, text);
116
- continue;
117
- }
118
- if (seenTimeline.has(id))
119
- continue;
120
- seenTimeline.add(id);
121
- if (entry.type === "tool_execution_start" || entry.type === "tool_execution_update" || entry.type === "tool_execution_end" || entry.type === "mcp_tool_call") {
122
- writeLine(`[Pi tool] ${String(entry.toolName ?? entry.name ?? entry.title ?? entry.type)} ${String(entry.status ?? entry.state ?? "")}`.trim());
123
- continue;
124
- }
125
- if (entry.type === "timeline_warning") {
126
- writeLine(`[Rig timeline] ${String(entry.detail ?? entry.message ?? "timeline unavailable")}`);
127
- continue;
128
- }
129
- if (entry.type === "action") {
130
- const text = String(entry.detail ?? entry.message ?? entry.title ?? "").trim();
131
- if (text)
132
- writeLine(`[Rig action] ${text}`);
133
- continue;
134
- }
135
- if (entry.type === "user_message") {
136
- const text = String(entry.text ?? entry.message ?? entry.detail ?? "").trim();
137
- if (text)
138
- writeLine(`[Operator] ${text}`);
139
- continue;
140
- }
141
- const fallback = String(entry.detail ?? entry.message ?? entry.text ?? entry.title ?? "").trim();
142
- if (fallback)
143
- writeLine(`[${String(entry.type ?? "timeline")}] ${fallback}`);
144
- }
145
- },
146
- renderLogs(entries) {
147
- for (const [index, entry] of entries.entries()) {
148
- const id = entryId(entry, `log:${index}:${String(entry.createdAt ?? "")}:${String(entry.title ?? "")}`);
149
- if (seenLogs.has(id))
150
- continue;
151
- seenLogs.add(id);
152
- const title = String(entry.title ?? "");
153
- if (CANONICAL_STAGES.some((stage) => stage.toLowerCase() === title.toLowerCase()))
154
- continue;
155
- const detail = logDetail(entry);
156
- if (!detail)
157
- continue;
158
- const protocolRecord = parseProviderProtocolLog(title, detail);
159
- if (protocolRecord) {
160
- const protocolLine = renderProviderProtocolLog(protocolRecord);
161
- if (protocolLine)
162
- writeLine(protocolLine);
163
- continue;
164
- }
165
- writeLine(`[${title || "Rig log"}] ${detail}`);
166
- }
167
- }
168
- };
169
- }
170
- function createOperatorSurface(options = {}) {
171
- const input = options.input ?? process.stdin;
172
- const output = options.output ?? process.stdout;
173
- const errorOutput = options.errorOutput ?? process.stderr;
174
- const renderer = createPiRunStreamRenderer(output);
175
- const writeLine = (line) => output.write(`${line}
176
- `);
177
- return {
178
- mode: "pi-compatible-text",
179
- ...renderer,
180
- info: writeLine,
181
- error: (message) => errorOutput.write(`${message}
182
- `),
183
- attachCommandInput(handler) {
184
- if (options.interactive === false || !input.isTTY)
185
- return null;
186
- const rl = createInterface({ input, output: process.stdout, terminal: false });
187
- rl.on("line", (line) => {
188
- Promise.resolve(handler(line)).catch((error) => writeLine(`Operator command failed: ${error instanceof Error ? error.message : String(error)}`));
189
- });
190
- return { close: () => rl.close() };
191
- }
192
- };
193
- }
194
- function taskId(task) {
195
- return typeof task.id === "string" && task.id.trim() ? task.id : "<unknown>";
196
- }
197
- function taskTitle(task) {
198
- return typeof task.title === "string" && task.title.trim() ? task.title : "Untitled task";
199
- }
200
- function taskStatus(task) {
201
- return typeof task.status === "string" && task.status.trim() ? task.status : "unknown";
202
- }
203
- function renderTaskPickerRows(tasks) {
204
- return tasks.map((task, index) => `${index + 1}. ${taskId(task)} \xB7 ${taskStatus(task)} \xB7 ${taskTitle(task)}`);
205
- }
206
- async function promptForTaskSelection(question) {
207
- const rl = createPromptInterface({ input: process.stdin, output: process.stdout });
208
- try {
209
- return await rl.question(question);
210
- } finally {
211
- rl.close();
212
- }
213
- }
214
- export {
215
- renderTaskPickerRows,
216
- renderOperatorSnapshot,
217
- promptForTaskSelection,
218
- createPiRunStreamRenderer,
219
- createOperatorSurface
220
- };
@@ -1,30 +0,0 @@
1
- import { steerRunViaServer, stopRunViaServer } from "./_server-client";
2
- import { createPiRunStreamRenderer, renderOperatorSnapshot } from "./_operator-surface";
3
- import type { RunnerContext } from "../runner";
4
- export { createPiRunStreamRenderer, renderOperatorSnapshot };
5
- export declare function applyOperatorCommand(context: Pick<RunnerContext, "projectRoot">, input: {
6
- readonly runId: string;
7
- readonly line: string;
8
- }, deps?: {
9
- readonly steer?: typeof steerRunViaServer;
10
- readonly stop?: typeof stopRunViaServer;
11
- }): Promise<{
12
- action: "continue" | "detach" | "stopped" | "ignored";
13
- message?: string;
14
- }>;
15
- export declare function attachRunOperatorView(context: Pick<RunnerContext, "projectRoot" | "outputMode">, input: {
16
- readonly runId: string;
17
- readonly message?: string | null;
18
- readonly once?: boolean;
19
- readonly follow?: boolean;
20
- readonly pollMs?: number;
21
- readonly interactive?: boolean;
22
- }): Promise<{
23
- run: Record<string, unknown>;
24
- logs: Record<string, unknown>[];
25
- timeline: Record<string, unknown>[];
26
- timelineCursor: string | null;
27
- steered: boolean;
28
- rendered: string;
29
- detached?: boolean;
30
- }>;