zelio-cli 0.0.0-stage → 0.1.0-beta.3
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.
- package/README.md +185 -2
- package/dist/attachments.js +121 -0
- package/dist/attachments.js.map +1 -0
- package/dist/cli.js +496 -0
- package/dist/cli.js.map +1 -0
- package/dist/cloud/board.js +311 -0
- package/dist/cloud/board.js.map +1 -0
- package/dist/cloud/command.js +281 -0
- package/dist/cloud/command.js.map +1 -0
- package/dist/cloud/config.js +132 -0
- package/dist/cloud/config.js.map +1 -0
- package/dist/cloud/credentials.js +134 -0
- package/dist/cloud/credentials.js.map +1 -0
- package/dist/cloud/login.js +165 -0
- package/dist/cloud/login.js.map +1 -0
- package/dist/cloud/pair.js +110 -0
- package/dist/cloud/pair.js.map +1 -0
- package/dist/cloud/pkce.js +16 -0
- package/dist/cloud/pkce.js.map +1 -0
- package/dist/cloud/push-nudge.js +65 -0
- package/dist/cloud/push-nudge.js.map +1 -0
- package/dist/cloud/relay.js +134 -0
- package/dist/cloud/relay.js.map +1 -0
- package/dist/cloud/token.js +66 -0
- package/dist/cloud/token.js.map +1 -0
- package/dist/cloud/tunnel.js +474 -0
- package/dist/cloud/tunnel.js.map +1 -0
- package/dist/db/db.js +1741 -0
- package/dist/db/db.js.map +1 -0
- package/dist/db/lifecycle.js +146 -0
- package/dist/db/lifecycle.js.map +1 -0
- package/dist/limits.js +35 -0
- package/dist/limits.js.map +1 -0
- package/dist/metrics.js +30 -0
- package/dist/metrics.js.map +1 -0
- package/dist/orchestrator/claude-session.js +208 -0
- package/dist/orchestrator/claude-session.js.map +1 -0
- package/dist/orchestrator/codex-session.js +326 -0
- package/dist/orchestrator/codex-session.js.map +1 -0
- package/dist/orchestrator/contract.js +184 -0
- package/dist/orchestrator/contract.js.map +1 -0
- package/dist/orchestrator/explore.js +176 -0
- package/dist/orchestrator/explore.js.map +1 -0
- package/dist/orchestrator/new-task-prompt.js +51 -0
- package/dist/orchestrator/new-task-prompt.js.map +1 -0
- package/dist/orchestrator/pi-session.js +228 -0
- package/dist/orchestrator/pi-session.js.map +1 -0
- package/dist/orchestrator/prompt.js +110 -0
- package/dist/orchestrator/prompt.js.map +1 -0
- package/dist/orchestrator/research.js +178 -0
- package/dist/orchestrator/research.js.map +1 -0
- package/dist/orchestrator/runtime.js +1207 -0
- package/dist/orchestrator/runtime.js.map +1 -0
- package/dist/orchestrator/session.js +2 -0
- package/dist/orchestrator/session.js.map +1 -0
- package/dist/orchestrator/types.js +2 -0
- package/dist/orchestrator/types.js.map +1 -0
- package/dist/orchestrator/web.js +276 -0
- package/dist/orchestrator/web.js.map +1 -0
- package/dist/repo/index.js +188 -0
- package/dist/repo/index.js.map +1 -0
- package/dist/repo/instructions.js +58 -0
- package/dist/repo/instructions.js.map +1 -0
- package/dist/repo/linked-boards.js +137 -0
- package/dist/repo/linked-boards.js.map +1 -0
- package/dist/repo/project-repos.js +78 -0
- package/dist/repo/project-repos.js.map +1 -0
- package/dist/run/actions.js +257 -0
- package/dist/run/actions.js.map +1 -0
- package/dist/run/auto-review.js +102 -0
- package/dist/run/auto-review.js.map +1 -0
- package/dist/run/bash-guard.js +183 -0
- package/dist/run/bash-guard.js.map +1 -0
- package/dist/run/claude-runtime.js +270 -0
- package/dist/run/claude-runtime.js.map +1 -0
- package/dist/run/claude-stream.js +306 -0
- package/dist/run/claude-stream.js.map +1 -0
- package/dist/run/codex-client.js +202 -0
- package/dist/run/codex-client.js.map +1 -0
- package/dist/run/codex-runtime.js +460 -0
- package/dist/run/codex-runtime.js.map +1 -0
- package/dist/run/consult.js +105 -0
- package/dist/run/consult.js.map +1 -0
- package/dist/run/context.js +87 -0
- package/dist/run/context.js.map +1 -0
- package/dist/run/diff.js +238 -0
- package/dist/run/diff.js.map +1 -0
- package/dist/run/evidence.js +48 -0
- package/dist/run/evidence.js.map +1 -0
- package/dist/run/finish.js +408 -0
- package/dist/run/finish.js.map +1 -0
- package/dist/run/handoff.js +51 -0
- package/dist/run/handoff.js.map +1 -0
- package/dist/run/harness-runtime.js +31 -0
- package/dist/run/harness-runtime.js.map +1 -0
- package/dist/run/harnesses.js +273 -0
- package/dist/run/harnesses.js.map +1 -0
- package/dist/run/issue.js +79 -0
- package/dist/run/issue.js.map +1 -0
- package/dist/run/keep-awake.js +58 -0
- package/dist/run/keep-awake.js.map +1 -0
- package/dist/run/lead.js +159 -0
- package/dist/run/lead.js.map +1 -0
- package/dist/run/manager.js +2546 -0
- package/dist/run/manager.js.map +1 -0
- package/dist/run/mentions.js +35 -0
- package/dist/run/mentions.js.map +1 -0
- package/dist/run/merge-watch.js +425 -0
- package/dist/run/merge-watch.js.map +1 -0
- package/dist/run/models.js +88 -0
- package/dist/run/models.js.map +1 -0
- package/dist/run/phases.js +23 -0
- package/dist/run/phases.js.map +1 -0
- package/dist/run/pi-rpc.js +439 -0
- package/dist/run/pi-rpc.js.map +1 -0
- package/dist/run/piped-check.js +56 -0
- package/dist/run/piped-check.js.map +1 -0
- package/dist/run/pr-checks.js +67 -0
- package/dist/run/pr-checks.js.map +1 -0
- package/dist/run/pr-merge.js +121 -0
- package/dist/run/pr-merge.js.map +1 -0
- package/dist/run/profiles.js +43 -0
- package/dist/run/profiles.js.map +1 -0
- package/dist/run/prompt.js +388 -0
- package/dist/run/prompt.js.map +1 -0
- package/dist/run/pull-request.js +23 -0
- package/dist/run/pull-request.js.map +1 -0
- package/dist/run/red-check.js +130 -0
- package/dist/run/red-check.js.map +1 -0
- package/dist/run/result-tool.js +93 -0
- package/dist/run/result-tool.js.map +1 -0
- package/dist/run/result.js +113 -0
- package/dist/run/result.js.map +1 -0
- package/dist/run/retro.js +346 -0
- package/dist/run/retro.js.map +1 -0
- package/dist/run/settings.js +27 -0
- package/dist/run/settings.js.map +1 -0
- package/dist/run/skills.js +146 -0
- package/dist/run/skills.js.map +1 -0
- package/dist/run/tests-first.js +146 -0
- package/dist/run/tests-first.js.map +1 -0
- package/dist/run/thinking.js +41 -0
- package/dist/run/thinking.js.map +1 -0
- package/dist/run/types.js +2 -0
- package/dist/run/types.js.map +1 -0
- package/dist/run/watchdog.js +259 -0
- package/dist/run/watchdog.js.map +1 -0
- package/dist/run/workflow.js +277 -0
- package/dist/run/workflow.js.map +1 -0
- package/dist/run/worktree.js +354 -0
- package/dist/run/worktree.js.map +1 -0
- package/dist/server/app.js +2946 -0
- package/dist/server/app.js.map +1 -0
- package/dist/server/auth.js +93 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/demo.js +96 -0
- package/dist/server/demo.js.map +1 -0
- package/dist/server/idempotency.js +104 -0
- package/dist/server/idempotency.js.map +1 -0
- package/dist/server/port.js +36 -0
- package/dist/server/port.js.map +1 -0
- package/dist/server/principal.js +93 -0
- package/dist/server/principal.js.map +1 -0
- package/dist/server/repo-picker.js +18 -0
- package/dist/server/repo-picker.js.map +1 -0
- package/dist/server/terminal.js +285 -0
- package/dist/server/terminal.js.map +1 -0
- package/dist/setup/components.js +98 -0
- package/dist/setup/components.js.map +1 -0
- package/dist/setup/config.js +102 -0
- package/dist/setup/config.js.map +1 -0
- package/dist/setup/ink-ui.js +189 -0
- package/dist/setup/ink-ui.js.map +1 -0
- package/dist/setup/onboarding.js +167 -0
- package/dist/setup/onboarding.js.map +1 -0
- package/dist/setup/run.js +70 -0
- package/dist/setup/run.js.map +1 -0
- package/dist/skills.js +151 -0
- package/dist/skills.js.map +1 -0
- package/dist/ticket-cli.js +157 -0
- package/dist/ticket-cli.js.map +1 -0
- package/dist/version.js +13 -0
- package/dist/version.js.map +1 -0
- package/dist/voice/index.js +69 -0
- package/dist/voice/index.js.map +1 -0
- package/dist/voice/moonshine.js +247 -0
- package/dist/voice/moonshine.js.map +1 -0
- package/dist/voice/wav.js +54 -0
- package/dist/voice/wav.js.map +1 -0
- package/dist/voice/whisper.js +491 -0
- package/dist/voice/whisper.js.map +1 -0
- package/dist/web/assets/index-CCQMrUIF.js +255 -0
- package/dist/web/assets/index-lzGSgTRQ.css +1 -0
- package/dist/web/icons/apple-touch-icon.png +0 -0
- package/dist/web/icons/icon-192.png +0 -0
- package/dist/web/icons/icon-512.png +0 -0
- package/dist/web/icons/maskable-512.png +0 -0
- package/dist/web/index.html +21 -0
- package/dist/web/manifest.webmanifest +30 -0
- package/dist/web/sw.js +185 -0
- package/package.json +96 -4
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { clip, stripWorktreeCd, toolResultText } from "./actions.js";
|
|
3
|
+
import { BASH_GUARD_EXTENSION } from "./bash-guard.js";
|
|
4
|
+
import { RESULT_TOOL_EXTENSION } from "./result-tool.js";
|
|
5
|
+
import { CODING_AGENT_PROMPT } from "./prompt.js";
|
|
6
|
+
import { resolveThinkingLevel, thinkingArgs } from "./thinking.js";
|
|
7
|
+
/**
|
|
8
|
+
* A ticket can be a long job, so a developer is timed by silence, not by the
|
|
9
|
+
* clock: this is how long one turn may go without a record. A read-only job
|
|
10
|
+
* keeps it as its whole budget.
|
|
11
|
+
*/
|
|
12
|
+
const DEFAULT_TIMEOUT_MS = 30 * 60_000;
|
|
13
|
+
const KILL_GRACE_MS = 2_000;
|
|
14
|
+
/** Stable, machine-independent tools for ticket runs; local pi defaults are irrelevant. */
|
|
15
|
+
export const DEVELOPER_TOOLS = ["read", "bash", "edit", "write", "grep", "find", "ls"];
|
|
16
|
+
/** The same honest labels as the panel, without depending on the planner. */
|
|
17
|
+
export function runToolLabel(tool, args) {
|
|
18
|
+
const fields = (args ?? {});
|
|
19
|
+
const text = (key) => typeof fields[key] === "string" ? fields[key] : "";
|
|
20
|
+
switch (tool) {
|
|
21
|
+
case "read": {
|
|
22
|
+
const path = text("path") || text("file_path");
|
|
23
|
+
return path ? `Reading ${clip(path, 46)}` : "Reading a file";
|
|
24
|
+
}
|
|
25
|
+
case "grep": {
|
|
26
|
+
const pattern = text("pattern") || text("query");
|
|
27
|
+
return pattern ? `Searching for “${clip(pattern, 32)}”` : "Searching the repo";
|
|
28
|
+
}
|
|
29
|
+
case "find": {
|
|
30
|
+
const pattern = text("pattern");
|
|
31
|
+
return pattern ? `Finding “${clip(pattern, 32)}”` : "Finding files";
|
|
32
|
+
}
|
|
33
|
+
case "ls": {
|
|
34
|
+
const path = text("path");
|
|
35
|
+
return path ? `Listing ${clip(path, 46)}` : "Listing the repo";
|
|
36
|
+
}
|
|
37
|
+
case "bash": {
|
|
38
|
+
// Ticket commands start with `cd <worktree> &&`; spending the label on a
|
|
39
|
+
// path the person already knows hides the part that says what it runs.
|
|
40
|
+
const command = stripWorktreeCd(text("command"));
|
|
41
|
+
return command ? `Running ${clip(command, 44)}` : "Running a command";
|
|
42
|
+
}
|
|
43
|
+
case "edit":
|
|
44
|
+
case "write": {
|
|
45
|
+
const path = text("path") || text("file_path");
|
|
46
|
+
return path ? `Editing ${clip(path, 46)}` : "Editing a file";
|
|
47
|
+
}
|
|
48
|
+
default:
|
|
49
|
+
return clip(tool, 40);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The token counts and the dollar cost worth keeping. Providers and pi versions
|
|
54
|
+
* disagree about the field names, so both the short and the snake_case
|
|
55
|
+
* spellings are read; a message with no numeric usage is not a zero, it is
|
|
56
|
+
* silence.
|
|
57
|
+
*
|
|
58
|
+
* A provider reports prompt tokens in three buckets: fresh input, cache reads
|
|
59
|
+
* and cache writes. Counting only `input` recorded the smallest one, so a long
|
|
60
|
+
* cached run looked nearly free. Input here is every token the model was sent,
|
|
61
|
+
* which also makes input + output match pi's own `totalTokens`.
|
|
62
|
+
*
|
|
63
|
+
* The cost is whatever the harness says it spent. pi reports a priced message as
|
|
64
|
+
* `cost: { input, output, cacheRead, cacheWrite, total }`, while older harnesses
|
|
65
|
+
* put one number on `cost`; both are read. A usage object that carries tokens
|
|
66
|
+
* but no cost is `cost: null`, not zero: a harness that does not price its own
|
|
67
|
+
* messages must not look free.
|
|
68
|
+
*/
|
|
69
|
+
export function readUsage(usage) {
|
|
70
|
+
if (!usage || typeof usage !== "object")
|
|
71
|
+
return null;
|
|
72
|
+
const fields = usage;
|
|
73
|
+
const count = (...names) => {
|
|
74
|
+
for (const name of names) {
|
|
75
|
+
const value = fields[name];
|
|
76
|
+
if (typeof value === "number" && Number.isFinite(value) && value >= 0)
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
};
|
|
81
|
+
const input = count("input", "input_tokens", "inputTokens");
|
|
82
|
+
const output = count("output", "output_tokens", "outputTokens");
|
|
83
|
+
// pi 1.4 nests the dollars under `cost.total`, so the flat lookup finds no
|
|
84
|
+
// number there; reading only `cost` reported every real run as unpriced.
|
|
85
|
+
const costField = fields.cost;
|
|
86
|
+
const nestedTotal = costField && typeof costField === "object"
|
|
87
|
+
? costField.total
|
|
88
|
+
: undefined;
|
|
89
|
+
const cost = count("cost", "cost_usd", "totalCost", "total_cost", "total_cost_usd") ??
|
|
90
|
+
(typeof nestedTotal === "number" && Number.isFinite(nestedTotal) && nestedTotal >= 0
|
|
91
|
+
? nestedTotal
|
|
92
|
+
: null);
|
|
93
|
+
if (input === undefined && output === undefined && cost === null)
|
|
94
|
+
return null;
|
|
95
|
+
const cacheRead = count("cacheRead", "cache_read", "cacheReadTokens", "cache_read_tokens") ?? 0;
|
|
96
|
+
const cacheWrite = count("cacheWrite", "cache_write", "cacheWriteTokens", "cache_write_tokens") ?? 0;
|
|
97
|
+
return { input: (input ?? 0) + cacheRead + cacheWrite, output: output ?? 0, cost };
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* pi over RPC, with the event shapes the M0 spike documented: LF-delimited
|
|
101
|
+
* JSONL, `agent_settled` as the only reliable end of work, and no exit until
|
|
102
|
+
* stdin closes.
|
|
103
|
+
*/
|
|
104
|
+
export class PiRpcRuntime {
|
|
105
|
+
command;
|
|
106
|
+
fixedCommand;
|
|
107
|
+
timeoutMs;
|
|
108
|
+
messageTimeoutMs;
|
|
109
|
+
fallbackThinking;
|
|
110
|
+
constructor(options = {}) {
|
|
111
|
+
this.command = options.command ?? process.env.ZELIO_HARNESS ?? "pi";
|
|
112
|
+
this.fixedCommand = options.command?.trim() || undefined;
|
|
113
|
+
this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
114
|
+
this.messageTimeoutMs = options.messageTimeoutMs ?? 2_000;
|
|
115
|
+
this.fallbackThinking =
|
|
116
|
+
options.thinking ??
|
|
117
|
+
resolveThinkingLevel(process.env.ZELIO_AGENT_THINKING, "ZELIO_AGENT_THINKING", "low");
|
|
118
|
+
}
|
|
119
|
+
spawn(cwd, prompt, options = {}) {
|
|
120
|
+
const thinking = options.thinking ?? this.fallbackThinking;
|
|
121
|
+
const reporting = options.reporting === true && !options.readOnly;
|
|
122
|
+
// A profile may name its own harness; an empty value means the server's
|
|
123
|
+
// default (ZELIO_HARNESS, then `pi`).
|
|
124
|
+
const command = this.fixedCommand || options.command?.trim() || this.command;
|
|
125
|
+
// A session is how a run outlives the process that was running it: the
|
|
126
|
+
// board opens the same id again after a restart, so the agent keeps its
|
|
127
|
+
// conversation instead of being briefed a second time. `--no-session` is
|
|
128
|
+
// only the fallback for a caller that has nowhere to keep one.
|
|
129
|
+
const sessionArgs = options.sessionId
|
|
130
|
+
? [
|
|
131
|
+
"--session-id",
|
|
132
|
+
options.sessionId,
|
|
133
|
+
...(options.sessionDir ? ["--session-dir", options.sessionDir] : []),
|
|
134
|
+
]
|
|
135
|
+
: ["--no-session"];
|
|
136
|
+
const child = spawn(command, [
|
|
137
|
+
"--mode",
|
|
138
|
+
"rpc",
|
|
139
|
+
...sessionArgs,
|
|
140
|
+
"--no-mcp",
|
|
141
|
+
"--no-extensions",
|
|
142
|
+
// RunManager already supplies repository instructions and the resolved workflow.
|
|
143
|
+
...(reporting ? ["--no-context-files"] : []),
|
|
144
|
+
...(options.shellGuard ? ["--extension", BASH_GUARD_EXTENSION.href] : []),
|
|
145
|
+
...(reporting ? ["--extension", RESULT_TOOL_EXTENSION.href] : []),
|
|
146
|
+
"--tools",
|
|
147
|
+
[...(options.tools ?? DEVELOPER_TOOLS), ...(reporting ? ["report_result"] : [])].join(","),
|
|
148
|
+
"--no-skills",
|
|
149
|
+
"--no-prompt-templates",
|
|
150
|
+
"--system-prompt",
|
|
151
|
+
options.systemPrompt ?? CODING_AGENT_PROMPT,
|
|
152
|
+
...(options.model?.trim() ? ["--model", options.model.trim()] : []),
|
|
153
|
+
...thinkingArgs(thinking),
|
|
154
|
+
], {
|
|
155
|
+
cwd,
|
|
156
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
157
|
+
env: options.env ? { ...process.env, ...options.env } : process.env,
|
|
158
|
+
});
|
|
159
|
+
const events = [];
|
|
160
|
+
let finished = false;
|
|
161
|
+
let terminal = false;
|
|
162
|
+
let wake;
|
|
163
|
+
let stderr = "";
|
|
164
|
+
let timedOut = false;
|
|
165
|
+
let aborted = false;
|
|
166
|
+
let turnSettled = false;
|
|
167
|
+
let turnCanContinue = false;
|
|
168
|
+
let nextMessageId = 1;
|
|
169
|
+
const pendingMessages = new Map();
|
|
170
|
+
const settleMessages = (accepted) => {
|
|
171
|
+
for (const pending of pendingMessages.values()) {
|
|
172
|
+
clearTimeout(pending.timer);
|
|
173
|
+
pending.resolve(accepted);
|
|
174
|
+
}
|
|
175
|
+
pendingMessages.clear();
|
|
176
|
+
};
|
|
177
|
+
let killTimer;
|
|
178
|
+
let timer;
|
|
179
|
+
const signal = () => {
|
|
180
|
+
const resume = wake;
|
|
181
|
+
wake = undefined;
|
|
182
|
+
resume?.();
|
|
183
|
+
};
|
|
184
|
+
const push = (event) => {
|
|
185
|
+
events.push(event);
|
|
186
|
+
signal();
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Tools disagree about `partialResult`: bash reports the whole output so
|
|
190
|
+
* far, others report only the newest chunk. Both collapse to a delta here,
|
|
191
|
+
* so the board can append what it receives without thinking about it.
|
|
192
|
+
*/
|
|
193
|
+
const toolOutputs = new Map();
|
|
194
|
+
const pushToolText = (record, raw) => {
|
|
195
|
+
const tool = record.toolName ?? "tool";
|
|
196
|
+
const id = record.toolCallId ?? tool;
|
|
197
|
+
const text = toolResultText(raw);
|
|
198
|
+
if (!text)
|
|
199
|
+
return;
|
|
200
|
+
const seen = toolOutputs.get(id) ?? "";
|
|
201
|
+
const cumulative = text.startsWith(seen);
|
|
202
|
+
const delta = cumulative ? text.slice(seen.length) : text;
|
|
203
|
+
toolOutputs.set(id, cumulative ? text : seen + text);
|
|
204
|
+
if (delta)
|
|
205
|
+
push({
|
|
206
|
+
type: "tool_output",
|
|
207
|
+
tool,
|
|
208
|
+
text: delta,
|
|
209
|
+
...(record.toolCallId ? { callId: record.toolCallId } : {}),
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
const finish = (event) => {
|
|
213
|
+
if (terminal)
|
|
214
|
+
return;
|
|
215
|
+
terminal = true;
|
|
216
|
+
finished = true;
|
|
217
|
+
settleMessages(false);
|
|
218
|
+
clearTimeout(timer);
|
|
219
|
+
timer = undefined;
|
|
220
|
+
clearTimeout(killTimer);
|
|
221
|
+
push(event);
|
|
222
|
+
};
|
|
223
|
+
// Read-only jobs keep one wall-clock budget. A developer times out only when
|
|
224
|
+
// its active turn goes silent: the clock stops while the board runs its
|
|
225
|
+
// checks between turns, and the next prompt starts it again.
|
|
226
|
+
const startClock = () => {
|
|
227
|
+
if (finished || (options.readOnly && timer))
|
|
228
|
+
return;
|
|
229
|
+
clearTimeout(timer);
|
|
230
|
+
timer = setTimeout(() => {
|
|
231
|
+
timedOut = true;
|
|
232
|
+
child.kill("SIGKILL");
|
|
233
|
+
}, this.timeoutMs);
|
|
234
|
+
};
|
|
235
|
+
const pauseClock = () => {
|
|
236
|
+
if (options.readOnly)
|
|
237
|
+
return;
|
|
238
|
+
clearTimeout(timer);
|
|
239
|
+
timer = undefined;
|
|
240
|
+
};
|
|
241
|
+
startClock();
|
|
242
|
+
child.stderr.setEncoding("utf8");
|
|
243
|
+
child.stderr.on("data", (chunk) => {
|
|
244
|
+
stderr = (stderr + chunk).slice(-4000);
|
|
245
|
+
});
|
|
246
|
+
child.stdin.on("error", () => {
|
|
247
|
+
// The harness can exit before the prompt is written; `exit` below is the
|
|
248
|
+
// event that matters, not EPIPE on a dead pipe.
|
|
249
|
+
});
|
|
250
|
+
const sendMessage = (kind, message) => {
|
|
251
|
+
const id = `${kind}-${nextMessageId++}`;
|
|
252
|
+
return new Promise((resolve) => {
|
|
253
|
+
const rejectMessage = () => {
|
|
254
|
+
const pending = pendingMessages.get(id);
|
|
255
|
+
if (!pending)
|
|
256
|
+
return;
|
|
257
|
+
pendingMessages.delete(id);
|
|
258
|
+
clearTimeout(pending.timer);
|
|
259
|
+
pending.resolve(false);
|
|
260
|
+
};
|
|
261
|
+
const messageTimer = setTimeout(rejectMessage, this.messageTimeoutMs);
|
|
262
|
+
pendingMessages.set(id, { resolve, timer: messageTimer, command: kind });
|
|
263
|
+
try {
|
|
264
|
+
child.stdin.write(JSON.stringify({ id, type: kind, message }) + "\n", (error) => {
|
|
265
|
+
if (error)
|
|
266
|
+
rejectMessage();
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
rejectMessage();
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
// LF only: `readline` also splits U+2028/U+2029, which are legal in JSON.
|
|
275
|
+
let buffer = "";
|
|
276
|
+
child.stdout.setEncoding("utf8");
|
|
277
|
+
child.stdout.on("data", (chunk) => {
|
|
278
|
+
buffer += chunk;
|
|
279
|
+
let newline;
|
|
280
|
+
while ((newline = buffer.indexOf("\n")) !== -1) {
|
|
281
|
+
const line = buffer.slice(0, newline).replace(/\r$/, "");
|
|
282
|
+
buffer = buffer.slice(newline + 1);
|
|
283
|
+
if (!line.trim())
|
|
284
|
+
continue;
|
|
285
|
+
let record;
|
|
286
|
+
try {
|
|
287
|
+
record = JSON.parse(line);
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
if (!options.readOnly && !finished)
|
|
293
|
+
timer?.refresh();
|
|
294
|
+
if (typeof record.id === "string" && pendingMessages.has(record.id)) {
|
|
295
|
+
const pending = pendingMessages.get(record.id);
|
|
296
|
+
pendingMessages.delete(record.id);
|
|
297
|
+
clearTimeout(pending.timer);
|
|
298
|
+
pending.resolve(record.type === "response" &&
|
|
299
|
+
record.success === true &&
|
|
300
|
+
(pending.command !== "prompt" || record.data?.disposition !== "handled"));
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
if (record.type === "message_update" &&
|
|
304
|
+
record.assistantMessageEvent?.type === "text_delta") {
|
|
305
|
+
push({ type: "text", text: record.assistantMessageEvent.delta ?? "" });
|
|
306
|
+
}
|
|
307
|
+
if (record.type === "tool_execution_start" && record.toolName) {
|
|
308
|
+
push({
|
|
309
|
+
type: "tool_start",
|
|
310
|
+
tool: record.toolName,
|
|
311
|
+
args: record.args,
|
|
312
|
+
label: runToolLabel(record.toolName, record.args),
|
|
313
|
+
...(record.toolCallId ? { callId: record.toolCallId } : {}),
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
// A long command is the one case where nothing else moves for minutes.
|
|
317
|
+
if (record.type === "tool_execution_update")
|
|
318
|
+
pushToolText(record, record.partialResult);
|
|
319
|
+
// The per-message usage is authoritative; `message_update` usage is
|
|
320
|
+
// cumulative per response and must not be summed.
|
|
321
|
+
if (record.type === "message_end") {
|
|
322
|
+
if (record.message?.role === "assistant") {
|
|
323
|
+
turnCanContinue = ["stop", "length"].includes(record.message.stopReason ?? "");
|
|
324
|
+
}
|
|
325
|
+
const usage = readUsage(record.message?.usage);
|
|
326
|
+
if (usage)
|
|
327
|
+
push({ type: "usage", ...usage });
|
|
328
|
+
}
|
|
329
|
+
if (record.type === "tool_execution_end" && record.toolName) {
|
|
330
|
+
// Belt and braces: the final result fills in whatever the updates missed.
|
|
331
|
+
pushToolText(record, record.result);
|
|
332
|
+
toolOutputs.delete(record.toolCallId ?? record.toolName);
|
|
333
|
+
push({
|
|
334
|
+
type: "tool_end",
|
|
335
|
+
tool: record.toolName,
|
|
336
|
+
isError: Boolean(record.isError),
|
|
337
|
+
...(record.toolCallId ? { callId: record.toolCallId } : {}),
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
if (record.type === "agent_settled") {
|
|
341
|
+
turnSettled = true;
|
|
342
|
+
settleMessages(false);
|
|
343
|
+
pauseClock();
|
|
344
|
+
push({ type: "settled" });
|
|
345
|
+
const endStdin = () => {
|
|
346
|
+
// The clock is the only backstop for a harness that ignores a closed stdin.
|
|
347
|
+
startClock();
|
|
348
|
+
if (!child.stdin.destroyed && !child.stdin.writableEnded)
|
|
349
|
+
child.stdin.end();
|
|
350
|
+
};
|
|
351
|
+
const mayContinue = !finished && !aborted && !timedOut && turnCanContinue && !options.readOnly;
|
|
352
|
+
if (!mayContinue || !options.continuationPrompt) {
|
|
353
|
+
endStdin();
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
// The hook may be async; stdin stays open until it resolves.
|
|
357
|
+
const decision = new Promise((resolve) => resolve(options.continuationPrompt?.()));
|
|
358
|
+
void decision.then((continuation) => {
|
|
359
|
+
// State may have changed while the hook was pending.
|
|
360
|
+
if (continuation?.trim() && !finished && !aborted && !timedOut) {
|
|
361
|
+
turnSettled = false;
|
|
362
|
+
turnCanContinue = false;
|
|
363
|
+
startClock();
|
|
364
|
+
void sendMessage("prompt", continuation).then((accepted) => {
|
|
365
|
+
if (!accepted)
|
|
366
|
+
endStdin();
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
endStdin();
|
|
371
|
+
}
|
|
372
|
+
}, () => endStdin());
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
child.on("error", (error) => {
|
|
378
|
+
finish({
|
|
379
|
+
type: "exit",
|
|
380
|
+
code: null,
|
|
381
|
+
stderr: `${command}: ${error.message}`,
|
|
382
|
+
timedOut,
|
|
383
|
+
// A command that cannot be found ends before it ever speaks; the run
|
|
384
|
+
// manager has to record a failure, not a silent clean exit.
|
|
385
|
+
spawnError: true,
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
child.on("exit", (code) => {
|
|
389
|
+
finish({ type: "exit", code, stderr: stderr.trim(), timedOut });
|
|
390
|
+
});
|
|
391
|
+
child.stdin.write(JSON.stringify({ id: "ticket-1", type: "prompt", message: prompt }) + "\n");
|
|
392
|
+
const abort = () => {
|
|
393
|
+
if (finished || aborted)
|
|
394
|
+
return;
|
|
395
|
+
aborted = true;
|
|
396
|
+
settleMessages(false);
|
|
397
|
+
child.kill("SIGTERM");
|
|
398
|
+
killTimer = setTimeout(() => child.kill("SIGKILL"), KILL_GRACE_MS);
|
|
399
|
+
};
|
|
400
|
+
const iterator = (async function* iterate() {
|
|
401
|
+
for (;;) {
|
|
402
|
+
if (events.length === 0) {
|
|
403
|
+
if (finished)
|
|
404
|
+
return;
|
|
405
|
+
// Waiting for the next process event is the generator's whole job.
|
|
406
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
407
|
+
await new Promise((resolve) => {
|
|
408
|
+
wake = resolve;
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
const event = events.shift();
|
|
412
|
+
if (!event)
|
|
413
|
+
continue;
|
|
414
|
+
yield event;
|
|
415
|
+
if (event.type === "exit")
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
})();
|
|
419
|
+
return {
|
|
420
|
+
events: iterator,
|
|
421
|
+
get aborted() {
|
|
422
|
+
return aborted;
|
|
423
|
+
},
|
|
424
|
+
abort,
|
|
425
|
+
sendMessage: (text) => {
|
|
426
|
+
if (finished ||
|
|
427
|
+
aborted ||
|
|
428
|
+
turnSettled ||
|
|
429
|
+
!text.trim() ||
|
|
430
|
+
child.stdin.destroyed ||
|
|
431
|
+
!child.stdin.writable) {
|
|
432
|
+
return Promise.resolve(false);
|
|
433
|
+
}
|
|
434
|
+
return sendMessage("steer", text);
|
|
435
|
+
},
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
//# sourceMappingURL=pi-rpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-rpc.js","sourceRoot":"","sources":["../../src/run/pi-rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAsB,MAAM,eAAe,CAAC;AAGvF;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,EAAE,GAAG,MAAM,CAAC;AACvC,MAAM,aAAa,GAAG,KAAK,CAAC;AAC5B,2FAA2F;AAC3F,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAU,CAAC;AAChG,6EAA6E;AAC7E,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,IAAa;IACtD,MAAM,MAAM,GAAG,CAAC,IAAI,IAAI,EAAE,CAA4B,CAAC;IACvD,MAAM,IAAI,GAAG,CAAC,GAAW,EAAU,EAAE,CACnC,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAE,MAAM,CAAC,GAAG,CAAY,CAAC,CAAC,CAAC,EAAE,CAAC;IAEjE,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,GAAG,IAAI,CAAC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AAO,CAAC;oBACjB,CAAC,CAAC,CAAC;gBACL,CAAC;gBACD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;gBAC7B,IAAI,CAAC,KAAK;oBAAE,SAAS;gBACrB,MAAM,KAAK,CAAC;gBACZ,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM;oBAAE,OAAO;YACpC,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;QAEL,OAAO;YACL,MAAM,EAAE,QAAQ;YAChB,IAAI,OAAO;gBACT,OAAO,OAAO,CAAC;YACjB,CAAC;YACD,KAAK;YACL,WAAW,EAAE,CAAC,IAAY,EAAE,EAAE;gBAC5B,IACE,QAAQ;oBACR,OAAO;oBACP,WAAW;oBACX,CAAC,IAAI,CAAC,IAAI,EAAE;oBACZ,KAAK,CAAC,KAAK,CAAC,SAAS;oBACrB,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EACrB,CAAC;oBACD,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBAChC,CAAC;gBACD,OAAO,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACpC,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A developer often runs a Verify command as `pnpm test x 2>&1 | tail -15` to
|
|
3
|
+
* keep the transcript short. The shell then reports the exit code of `tail`, so
|
|
4
|
+
* the call reads as passed whatever the tests did, and the command no longer
|
|
5
|
+
* matches the Verify command the board waits for. This module undoes both: it
|
|
6
|
+
* finds the command under an output-only filter, and reads the result from the
|
|
7
|
+
* test runner's own summary instead of from the pipe's exit code.
|
|
8
|
+
*/
|
|
9
|
+
/** `2>&1`, then one or more `| tail …`, `| head …` or `| grep …` stages. */
|
|
10
|
+
const FILTER_TAIL = /\s*(?:2>&1\s*)?((?:\|\s*(?:tail|head|grep)\b[^|;&`$()]*)+)$/;
|
|
11
|
+
/**
|
|
12
|
+
* The command under an output-only filter, or null when there is no filter or
|
|
13
|
+
* the part before it is itself a pipeline or a command list.
|
|
14
|
+
*/
|
|
15
|
+
export function unpipedCommand(command) {
|
|
16
|
+
const match = FILTER_TAIL.exec(command);
|
|
17
|
+
if (!match || match.index === 0)
|
|
18
|
+
return null;
|
|
19
|
+
const base = command
|
|
20
|
+
.slice(0, match.index)
|
|
21
|
+
.replace(/\s*2>&1\s*$/, "")
|
|
22
|
+
.trim();
|
|
23
|
+
if (!base || /[|;&`]|\$\(/.test(base))
|
|
24
|
+
return null;
|
|
25
|
+
return base;
|
|
26
|
+
}
|
|
27
|
+
const ANSI = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
|
|
28
|
+
/**
|
|
29
|
+
* What a test runner's summary says: `passed` when it printed a passing count
|
|
30
|
+
* and no failing one, `failed` when it printed a failing count, and null when
|
|
31
|
+
* the output carries no summary (a filter cut it, or the command is not a test
|
|
32
|
+
* runner). Null never counts as a pass.
|
|
33
|
+
*/
|
|
34
|
+
export function summaryOutcome(output) {
|
|
35
|
+
const body = output?.replace(ANSI, "") ?? "";
|
|
36
|
+
const summary = body.split(/\r?\n/).filter((line) => /^\s*(?:Test Files|Tests)\s+\S/.test(line));
|
|
37
|
+
if (summary.length === 0)
|
|
38
|
+
return null;
|
|
39
|
+
if (summary.some((line) => /\b\d+\s+failed\b/.test(line)))
|
|
40
|
+
return "failed";
|
|
41
|
+
return summary.some((line) => /^\s*Tests\s+.*\b\d+\s+passed\b/.test(line)) ? "passed" : null;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A finished piped call, read as the command it filtered. Null when the call is
|
|
45
|
+
* not a filtered command or its output does not say how the tests went.
|
|
46
|
+
*/
|
|
47
|
+
export function pipedEvidence(command, output, isError) {
|
|
48
|
+
const base = unpipedCommand(command);
|
|
49
|
+
if (!base)
|
|
50
|
+
return null;
|
|
51
|
+
if (isError)
|
|
52
|
+
return { command: base, outcome: "failed" };
|
|
53
|
+
const outcome = summaryOutcome(output);
|
|
54
|
+
return outcome ? { command: base, outcome } : null;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=piped-check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"piped-check.js","sourceRoot":"","sources":["../../src/run/piped-check.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,4EAA4E;AAC5E,MAAM,WAAW,GAAG,6DAA6D,CAAC;AAElF;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7C,MAAM,IAAI,GAAG,OAAO;SACjB,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC;SACrB,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;SAC1B,IAAI,EAAE,CAAC;IACV,IAAI,CAAC,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACnD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,IAAI,GAAG,IAAI,MAAM,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;AAEtE;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,MAA0B;IACvD,MAAM,IAAI,GAAG,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;IAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,+BAA+B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACjG,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACtC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC3E,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gCAAgC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/F,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAC3B,OAAe,EACf,MAA0B,EAC1B,OAAgB;IAEhB,MAAM,IAAI,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACrC,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,IAAI,OAAO;QAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;IACzD,MAAM,OAAO,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IACvC,OAAO,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
const exec = promisify(execFile);
|
|
4
|
+
const GH_TIMEOUT_MS = 15_000;
|
|
5
|
+
/**
|
|
6
|
+
* The bucket `gh` files each check under. A bucket this board does not know is
|
|
7
|
+
* not guessed at: the whole list is refused instead.
|
|
8
|
+
*/
|
|
9
|
+
const BUCKETS = new Map([
|
|
10
|
+
["pass", "passing"],
|
|
11
|
+
["skipping", "passing"],
|
|
12
|
+
["fail", "failing"],
|
|
13
|
+
["cancel", "failing"],
|
|
14
|
+
["pending", "pending"],
|
|
15
|
+
]);
|
|
16
|
+
/**
|
|
17
|
+
* Every check GitHub reports on the recorded pull request. `gh` exits non-zero
|
|
18
|
+
* while a check is failing or pending, but it still prints the list, so the
|
|
19
|
+
* output is read from the error as well as from a clean exit.
|
|
20
|
+
*
|
|
21
|
+
* `null` means the checks could not be read: no `gh`, no login, no network,
|
|
22
|
+
* output that does not parse, or a check the board cannot classify. A read that
|
|
23
|
+
* failed is not a list of zero checks.
|
|
24
|
+
*/
|
|
25
|
+
export async function readPullRequestChecks(path, prUrl, ghCommand = "gh") {
|
|
26
|
+
// Never let an empty value or a branch name select the checkout's PR.
|
|
27
|
+
if (!/^https:\/\/[^/\s]+\/[^/\s]+\/[^/\s]+\/pull\/[1-9]\d*\/?$/.test(prUrl))
|
|
28
|
+
return null;
|
|
29
|
+
const output = await checksOutput(path, prUrl, ghCommand);
|
|
30
|
+
if (output === null)
|
|
31
|
+
return null;
|
|
32
|
+
let body;
|
|
33
|
+
try {
|
|
34
|
+
body = JSON.parse(output);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
if (!Array.isArray(body))
|
|
40
|
+
return null;
|
|
41
|
+
const checks = [];
|
|
42
|
+
for (const item of body) {
|
|
43
|
+
const name = typeof item?.name === "string" ? item.name : "";
|
|
44
|
+
const state = typeof item?.bucket === "string" ? BUCKETS.get(item.bucket) : undefined;
|
|
45
|
+
if (!name || !state)
|
|
46
|
+
return null;
|
|
47
|
+
checks.push({
|
|
48
|
+
name,
|
|
49
|
+
state,
|
|
50
|
+
link: typeof item?.link === "string" && item.link ? item.link : null,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return checks;
|
|
54
|
+
}
|
|
55
|
+
async function checksOutput(path, prUrl, ghCommand) {
|
|
56
|
+
const args = ["pr", "checks", prUrl, "--json", "name,state,link,bucket"];
|
|
57
|
+
try {
|
|
58
|
+
const { stdout } = await exec(ghCommand, args, { cwd: path, timeout: GH_TIMEOUT_MS });
|
|
59
|
+
return String(stdout);
|
|
60
|
+
}
|
|
61
|
+
catch (cause) {
|
|
62
|
+
// A failing or pending check exits non-zero with the list still on stdout.
|
|
63
|
+
const stdout = cause.stdout;
|
|
64
|
+
return typeof stdout === "string" || Buffer.isBuffer(stdout) ? String(stdout) : null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=pr-checks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pr-checks.js","sourceRoot":"","sources":["../../src/run/pr-checks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AACjC,MAAM,aAAa,GAAG,MAAM,CAAC;AAW7B;;;GAGG;AACH,MAAM,OAAO,GAAG,IAAI,GAAG,CAAgC;IACrD,CAAC,MAAM,EAAE,SAAS,CAAC;IACnB,CAAC,UAAU,EAAE,SAAS,CAAC;IACvB,CAAC,MAAM,EAAE,SAAS,CAAC;IACnB,CAAC,QAAQ,EAAE,SAAS,CAAC;IACrB,CAAC,SAAS,EAAE,SAAS,CAAC;CACvB,CAAC,CAAC;AAEH;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,IAAY,EACZ,KAAa,EACb,SAAS,GAAG,IAAI;IAEhB,sEAAsE;IACtE,IAAI,CAAC,0DAA0D,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzF,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;IAC1D,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACjC,IAAI,IAAa,CAAC;IAClB,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAAC,MAAM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