@operad-io/dev 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/dev.schema.json +631 -0
  4. package/flows/chat-worktree.flow.ts +18 -0
  5. package/flows/dev.flow.ts +7 -0
  6. package/package.json +29 -4
  7. package/src/actions.ts +591 -0
  8. package/src/announce.ts +225 -0
  9. package/src/chat.ts +234 -0
  10. package/src/check.ts +80 -0
  11. package/src/commands.ts +417 -0
  12. package/src/editor.ts +55 -0
  13. package/src/flaky.ts +716 -0
  14. package/src/flow-compiler.ts +858 -0
  15. package/src/followups.ts +223 -0
  16. package/src/gate.ts +2950 -0
  17. package/src/git.ts +138 -0
  18. package/src/index.ts +227 -0
  19. package/src/integrate.ts +1213 -0
  20. package/src/integration-queue.ts +393 -0
  21. package/src/lock.ts +36 -0
  22. package/src/mainclone.ts +102 -0
  23. package/src/marks.ts +126 -0
  24. package/src/model.ts +1171 -0
  25. package/src/notcode.ts +305 -0
  26. package/src/place-order.ts +161 -0
  27. package/src/place-wait.ts +64 -0
  28. package/src/places.ts +368 -0
  29. package/src/prepare.ts +106 -0
  30. package/src/progress.ts +115 -0
  31. package/src/project-flows.ts +160 -0
  32. package/src/project-settings.ts +192 -0
  33. package/src/refusals.ts +336 -0
  34. package/src/rerun.ts +390 -0
  35. package/src/reruns.ts +62 -0
  36. package/src/retry.ts +212 -0
  37. package/src/rework.ts +366 -0
  38. package/src/schedule.ts +1052 -0
  39. package/src/service.ts +2160 -0
  40. package/src/settings.ts +1495 -0
  41. package/src/standing.ts +87 -0
  42. package/src/stdin.ts +105 -0
  43. package/src/steps.ts +1775 -0
  44. package/src/stops.ts +103 -0
  45. package/src/throughput.ts +347 -0
  46. package/src/timeouts.ts +60 -0
  47. package/src/views.ts +1167 -0
  48. package/src/waits.ts +105 -0
@@ -0,0 +1,225 @@
1
+ /**
2
+ * Step `dev/announce`: the flow runs it in front of every person wait. It tells
3
+ * the outside world that a task now needs a person, once, and says the task
4
+ * waits (a task still running or in review is not one a person can act on).
5
+ * The reason comes from the edge that led here and from what the
6
+ * task recorded, so the gate steps stay as they are.
7
+ */
8
+
9
+ import type { PluginStepResult, StepContext } from "@operad-io/engine";
10
+ import { messageOf } from "@operad-io/engine";
11
+ import type { TaskData } from "./model.ts";
12
+ import {
13
+ cancelledStep,
14
+ claimAllows,
15
+ mergeInProgress,
16
+ saveTaskGuarded,
17
+ taskContext,
18
+ } from "./steps.ts";
19
+
20
+ /** The event type a waiting task emits. */
21
+ export const WAITING_EVENT = "dev.waiting";
22
+
23
+ /** The edge a task took into the wait, as the flow names it in its params. */
24
+ export interface AnnounceParams {
25
+ readonly from: string;
26
+ readonly result: string;
27
+ }
28
+
29
+ /** Why a task waits: the short reason for the key, and what to add to the line. */
30
+ export interface WaitingReason {
31
+ readonly reason: string;
32
+ readonly detail?: string | undefined;
33
+ /** The step that stopped, when the run did not reach an edge. */
34
+ readonly step?: string | undefined;
35
+ }
36
+
37
+ function paramsOf(params: unknown): AnnounceParams {
38
+ const record =
39
+ typeof params === "object" && params !== null && !Array.isArray(params)
40
+ ? (params as Record<string, unknown>)
41
+ : {};
42
+ const from = typeof record.from === "string" ? record.from : "";
43
+ const result = typeof record.result === "string" ? record.result : "";
44
+ return { from, result };
45
+ }
46
+
47
+ /** The step a repair run says stopped, from the line the worktree step wrote. */
48
+ function stoppedStep(task: TaskData, fallback: string): string {
49
+ const lines = task.brief.replace(/\r\n/g, "\n").split("\n");
50
+ for (let index = lines.length - 1; index >= 0; index -= 1) {
51
+ const match = /^- (?:\[[^\]]*\] )?waiting: (\S+) stopped$/.exec(lines[index] ?? "");
52
+ if (match !== null) return match[1] ?? fallback;
53
+ }
54
+ return fallback;
55
+ }
56
+
57
+ function nonEmpty(text: string | null | undefined): string | undefined {
58
+ return typeof text === "string" && text.trim().length > 0
59
+ ? text.trim()
60
+ : undefined;
61
+ }
62
+
63
+ /**
64
+ * The reason a task waits after an edge. `maxAutoRework` tells a rework that
65
+ * ran out of automatic passes from one that was never allowed any.
66
+ */
67
+ export function waitingReason(
68
+ edge: AnnounceParams,
69
+ task: TaskData,
70
+ maxAutoRework: number,
71
+ conflicted: boolean,
72
+ ): WaitingReason {
73
+ const attempt = task.attempt;
74
+ if (edge.result === "environment") {
75
+ // The one automatic retry did not help: the line says what was wrong.
76
+ const cause = task.retry?.cause ?? `run stopped during ${edge.from}`;
77
+ return { reason: cause, step: edge.from };
78
+ }
79
+ if (edge.result === "not_code") {
80
+ // A check that was not the code twice: the line says what and under which load.
81
+ const verify = attempt?.verify;
82
+ const said = typeof verify?.notCode === "string" ? verify.notCode : undefined;
83
+ return { reason: said ?? "check was not the code" };
84
+ }
85
+ switch (edge.from) {
86
+ case "worktree":
87
+ if (edge.result === "blocked") {
88
+ return { reason: "dependency cancelled" };
89
+ }
90
+ {
91
+ const step = stoppedStep(task, "worktree");
92
+ return { reason: `run stopped during ${step}`, step };
93
+ }
94
+ case "work":
95
+ if (edge.result === "interrupted") {
96
+ return { reason: "run stopped during work", step: "work" };
97
+ }
98
+ if (conflicted) return { reason: "conflict" };
99
+ if (edge.result === "nothing") return { reason: "work did nothing" };
100
+ if (attempt?.workTimedOut === true) {
101
+ return { reason: "work timed out", detail: nonEmpty(attempt.workNote) };
102
+ }
103
+ return {
104
+ reason: "work failed",
105
+ detail: nonEmpty(attempt?.workNote),
106
+ };
107
+ case "review":
108
+ if (edge.result === "pass") {
109
+ return { reason: "ready to merge" };
110
+ }
111
+ {
112
+ const review = attempt?.review;
113
+ const said = `${review?.reason ?? ""} ${review?.message ?? ""}`;
114
+ if (/wall|stall|time/i.test(said)) {
115
+ return { reason: "review timed out twice" };
116
+ }
117
+ return { reason: "review did not finish", detail: nonEmpty(review?.message) };
118
+ }
119
+ case "rework": {
120
+ const rework = attempt?.rework;
121
+ if (rework?.twice === true) {
122
+ return { reason: "review failed twice in a row" };
123
+ }
124
+ if (maxAutoRework > 0) return { reason: "rework limit" };
125
+ return {
126
+ reason: rework?.source === "review" ? "review findings" : "gate failed",
127
+ };
128
+ }
129
+ case "integrate": {
130
+ const integration = attempt?.integration;
131
+ const verified = attempt?.verified;
132
+ if (typeof verified !== "string" || verified.length === 0) {
133
+ return { reason: "no verified commit" };
134
+ }
135
+ if (typeof integration?.notCode === "string") {
136
+ return { reason: integration.notCode };
137
+ }
138
+ return {
139
+ reason: "merge refused",
140
+ detail: nonEmpty(integration?.message),
141
+ };
142
+ }
143
+ default:
144
+ return { reason: "waiting" };
145
+ }
146
+ }
147
+
148
+ /** One line a person reads: the task, why it waits, and the detail if any. */
149
+ export function waitingSummary(taskId: string, found: WaitingReason): string {
150
+ const detail = found.detail === undefined ? "" : ` (${found.detail})`;
151
+ return `${taskId} waiting: ${found.reason}${detail}`;
152
+ }
153
+
154
+ /** Step `dev/announce`. */
155
+ export async function runAnnounce(
156
+ ctx: StepContext,
157
+ stepParams: unknown,
158
+ ): Promise<PluginStepResult> {
159
+ const context = await taskContext(ctx);
160
+ if (!claimAllows(ctx, context.task)) return cancelledStep();
161
+ const edge = paramsOf(stepParams);
162
+ const path = context.task.attempt?.worktree;
163
+ const conflicted =
164
+ edge.from === "work" &&
165
+ edge.result !== "interrupted" &&
166
+ edge.result !== "environment" &&
167
+ typeof path === "string" &&
168
+ mergeInProgress(path);
169
+ const found = waitingReason(
170
+ edge,
171
+ context.task,
172
+ context.settings.maxAutoRework,
173
+ conflicted,
174
+ );
175
+ const attempt = Math.max(
176
+ context.task.attempts,
177
+ context.task.attempt?.number ?? 0,
178
+ );
179
+ const summary = waitingSummary(context.taskId, found);
180
+ try {
181
+ await ctx.emit({
182
+ type: WAITING_EVENT,
183
+ key: `${context.taskId}:${attempt}:${found.reason}`,
184
+ summary,
185
+ data: {
186
+ task: context.taskId,
187
+ attempt,
188
+ reason: found.reason,
189
+ ...(found.detail === undefined ? {} : { detail: found.detail }),
190
+ },
191
+ });
192
+ } catch (error) {
193
+ // The task still waits for a person; a lost notice must not stop that.
194
+ await ctx.logger.write(`could not announce: ${messageOf(error)}`);
195
+ }
196
+ // The wait this step leads to is a person's: the phase and the wait say so.
197
+ // An older review wait's kind is replaced even when the phase is already
198
+ // waiting, so a later wait for a person takes every action it offers. A
199
+ // failed write leaves the scheduler to repair the phase on its next tick.
200
+ if (
201
+ context.task.phase === "running" ||
202
+ context.task.phase === "review" ||
203
+ context.task.waitKind !== "person"
204
+ ) {
205
+ try {
206
+ await saveTaskGuarded(
207
+ ctx,
208
+ context.taskKey,
209
+ { ...context.task, phase: "waiting", waitKind: "person" },
210
+ "dev:announce-waiting",
211
+ );
212
+ } catch (error) {
213
+ await ctx.logger.write(`could not mark the task waiting: ${messageOf(error)}`);
214
+ }
215
+ }
216
+ // A stopped run keeps its result, so the wait can say which step stopped.
217
+ return {
218
+ result: found.step === undefined ? "done" : "interrupted",
219
+ data: {
220
+ reason: found.reason,
221
+ summary,
222
+ ...(found.step === undefined ? {} : { step: found.step }),
223
+ },
224
+ };
225
+ }
package/src/chat.ts ADDED
@@ -0,0 +1,234 @@
1
+ /**
2
+ * Chats on a repository: `dev:chat` opens one in the main clone, read-only, and
3
+ * `dev:chat-worktree` (the step a "yes" to the worktree question starts) gives
4
+ * it a worktree of its own to change code in. Nothing here merges: the worktree's
5
+ * changes reach main only through a task, through integrate.
6
+ */
7
+
8
+ import { CHAT_TYPE, agentConditionals, type AgentChoices, chatData, createChat, sendMessage, startingEffort, startingModel, titleFromMessage } from "@operad-io/chat";
9
+ import type {
10
+ ActionArgsSchema,
11
+ ActionTypeDefinition,
12
+ JsonValue,
13
+ ObjectStore,
14
+ PluginStepResult,
15
+ StepContext,
16
+ } from "@operad-io/engine";
17
+ import { existsSync } from "node:fs";
18
+ import { DevError, DevRefusal, repositoryData, type RepositoryData } from "./model.ts";
19
+ import { readDevSettings } from "./settings.ts";
20
+ import { isRegistered, prepareWorktree, workBranch, worktreePath } from "./steps.ts";
21
+
22
+ /**
23
+ * The harnesses a repository chat offers, in order: the ones that can stop a
24
+ * tool call before it starts, so the main clone stays read-only
25
+ * (ADR 0028 D2, D3). radian is not one.
26
+ */
27
+ export const CHAT_HARNESSES = ["claude", "pi"] as const;
28
+
29
+ /** Why radian is not offered; said up front in the action's description. */
30
+ export const RADIAN_NOTE =
31
+ "radian is not offered as an agent here: it cannot stop a tool call before it starts and cannot continue a session in another directory, so it cannot keep the main clone read-only or move to a worktree; use it for a bot chat.";
32
+
33
+ /** The access profile of a chat in the main clone: read-only, and no secrets. */
34
+ export const CHAT_ACCESS: Readonly<Record<string, JsonValue>> = {
35
+ readOnly: true,
36
+ denyPaths: ["~/.ssh", "~/.gnupg", "~/.aws", "~/.config/gh"],
37
+ // The agent reaches operad through its tools, never through a shell.
38
+ denyCommands: ["operad"],
39
+ };
40
+
41
+ /** The directory name and branch suffix of a chat's worktree. */
42
+ export function chatWorktreeName(chatId: string): string {
43
+ return `chat-${chatId}`;
44
+ }
45
+
46
+ /**
47
+ * The worktree name a task opened from chat `chatId` works in. The chat must be
48
+ * about this repository and must already have been given its worktree.
49
+ */
50
+ export async function chatWorktreeOf(
51
+ store: ObjectStore,
52
+ repository: RepositoryData,
53
+ chatId: string,
54
+ ): Promise<string> {
55
+ const stored = await store.get(CHAT_TYPE, chatId);
56
+ if (stored === undefined) throw new DevError("chat", `there is no chat ${chatId}`);
57
+ if (stored.data.parent !== `repo:${repository.name}`) {
58
+ throw new DevError("chat", `chat ${chatId} is not a chat about repository "${repository.name}"`);
59
+ }
60
+ if (typeof stored.data.worktree !== "object" || stored.data.worktree === null) {
61
+ throw new DevError("chat", `chat ${chatId} has no worktree yet`);
62
+ }
63
+ const recorded = (stored.data.worktree as { readonly path?: unknown }).path;
64
+ if (typeof recorded !== "string" || !existsSync(recorded) || !isRegistered(repository.path, recorded)) {
65
+ throw new DevError("chat", `the worktree of chat ${chatId} is gone`);
66
+ }
67
+ return chatWorktreeName(chatId);
68
+ }
69
+
70
+ /** The `dev:chat` arguments; `models` and `efforts` are the ones the offered agents list. */
71
+ function chatArgs(
72
+ models: readonly string[],
73
+ efforts: readonly string[],
74
+ agents: readonly AgentChoices[] = [],
75
+ ): ActionArgsSchema {
76
+ return {
77
+ type: "object",
78
+ description: `Opens a chat about this repository. ${RADIAN_NOTE}`,
79
+ properties: {
80
+ agent: {
81
+ type: "string",
82
+ enum: [...CHAT_HARNESSES],
83
+ description: "Which agent answers in this chat; the first loaded one when left out. It cannot change later.",
84
+ },
85
+ model: {
86
+ type: "string",
87
+ ...(models.length === 0 ? {} : { enum: [...models] }),
88
+ description: "The model the agent uses; one from that agent's list. The agent's default when left out. It can be changed later.",
89
+ },
90
+ effort: {
91
+ type: "string",
92
+ ...(efforts.length === 0 ? {} : { enum: [...efforts] }),
93
+ description: "The effort the agent uses; one from that agent's list. The agent's default when left out. It can be changed later.",
94
+ },
95
+ title: {
96
+ type: "string",
97
+ minLength: 1,
98
+ maxLength: 120,
99
+ description: "What the chat is called.",
100
+ },
101
+ message: {
102
+ type: "string",
103
+ role: "note",
104
+ minLength: 1,
105
+ description:
106
+ "The first message; the chat is created and the message sent in one step. The title is taken from its start when none is given.",
107
+ },
108
+ },
109
+ ...(agents.length === 0 ? {} : { allOf: agentConditionals(agents) }),
110
+ additionalProperties: false,
111
+ };
112
+ }
113
+
114
+ const chatAction: ActionTypeDefinition = {
115
+ name: "chat",
116
+ on: "repo",
117
+ creates: "chat",
118
+ args: chatArgs([], []),
119
+ argsFor: (_object, env) => {
120
+ const offered = CHAT_HARNESSES.filter((name) => (env.harnesses ?? []).includes(name));
121
+ return chatArgs(
122
+ [...new Set(offered.flatMap((name) => env.models?.[name]?.list ?? []))],
123
+ [...new Set(offered.flatMap((name) => env.efforts?.[name]?.list ?? []))],
124
+ offered.map((name) => ({ name, models: env.models?.[name], efforts: env.efforts?.[name] })),
125
+ );
126
+ },
127
+ when: (state) => repositoryData(state).removed !== true,
128
+ async run(ctx, args) {
129
+ const input = args as {
130
+ readonly agent?: string;
131
+ readonly model?: string;
132
+ readonly effort?: string;
133
+ readonly title?: string;
134
+ readonly message?: string;
135
+ };
136
+ const repository = repositoryData(ctx.object.data);
137
+ const offered = CHAT_HARNESSES.filter((name) => ctx.harnesses.includes(name));
138
+ const harness = input.agent ?? offered[0];
139
+ if (harness === undefined) {
140
+ throw new DevRefusal(`no agent for a repository chat is loaded; load one of ${CHAT_HARNESSES.join(", ")}`);
141
+ }
142
+ if (harness === "radian") throw new DevRefusal(RADIAN_NOTE);
143
+ if (!offered.includes(harness as (typeof CHAT_HARNESSES)[number])) {
144
+ throw new DevRefusal(
145
+ `agent "${harness}" is not offered for a repository chat; the loaded ones that are: ${offered.join(", ") || "none"}`,
146
+ );
147
+ }
148
+ let model: string | undefined;
149
+ let effort: string | undefined;
150
+ try {
151
+ model = startingModel(harness, ctx.models[harness], input.model);
152
+ effort = startingEffort(harness, ctx.efforts[harness], input.effort);
153
+ } catch (error) {
154
+ throw new DevRefusal(error instanceof Error ? error.message : String(error));
155
+ }
156
+ const effortDefault = ctx.efforts[harness]?.default ?? undefined;
157
+ const id = await createChat(
158
+ ctx.store,
159
+ {
160
+ parent: `repo:${ctx.object.id}`,
161
+ harness,
162
+ ...(model === undefined ? {} : { model }),
163
+ ...(effort === undefined ? {} : { effort }),
164
+ ...(effort === undefined || effortDefault === undefined ? {} : { effortDefault }),
165
+ cwd: repository.path,
166
+ access: CHAT_ACCESS,
167
+ title:
168
+ input.title ??
169
+ (input.message === undefined ? undefined : titleFromMessage(input.message)) ??
170
+ `Chat about ${repository.name}`,
171
+ },
172
+ "action:dev/chat",
173
+ );
174
+ const sent = input.message === undefined ? undefined : await sendMessage(ctx, id, input.message);
175
+ return { text: `opened chat ${id}${sent === undefined ? "" : `; ${sent}`}`, opens: `chat:${id}` };
176
+ },
177
+ };
178
+
179
+ /** The actions of the chat part of dev. */
180
+ export const chatActions: readonly ActionTypeDefinition[] = [chatAction];
181
+
182
+ function failed(message: string): PluginStepResult {
183
+ return { result: "failed", data: { message } };
184
+ }
185
+
186
+ /**
187
+ * Step `dev/chat_worktree`: opens `work/chat-<id>` for a chat of a repository
188
+ * and moves the chat's working directory there, once. The chat is writable in
189
+ * the worktree; a chat that already has one is left as it is.
190
+ */
191
+ export async function runChatWorktree(ctx: StepContext): Promise<PluginStepResult> {
192
+ const object = ctx.object;
193
+ if (object === undefined || object.type !== CHAT_TYPE) return failed("this runs on a chat");
194
+ const stored = await ctx.store.get(CHAT_TYPE, object.id);
195
+ if (stored === undefined) return failed(`there is no chat ${object.id}`);
196
+ if (typeof stored.data.worktree === "object" && stored.data.worktree !== null) {
197
+ return { result: "done", data: { moved: false } };
198
+ }
199
+ const chat = chatData(stored.data);
200
+ const parent = typeof chat.parent === "string" ? chat.parent : "";
201
+ const name = parent.startsWith("repo:") ? parent.slice("repo:".length) : undefined;
202
+ const repoObject = name === undefined ? undefined : await ctx.store.get("repo", name);
203
+ if (repoObject === undefined) return failed(`chat ${object.id} is not a chat about a repository`);
204
+ const repository = repositoryData(repoObject.data);
205
+
206
+ let settings;
207
+ try {
208
+ settings = await readDevSettings(repository.path);
209
+ } catch (error) {
210
+ return failed(error instanceof DevError ? error.message : String(error));
211
+ }
212
+ const worktreeName = chatWorktreeName(object.id);
213
+ const prepared = prepareWorktree(repository, settings, worktreeName);
214
+ if (prepared.kind !== "ready") {
215
+ return failed(prepared.message ?? `cannot open a worktree for chat ${object.id}`);
216
+ }
217
+ const path = worktreePath(repository.path, settings, worktreeName);
218
+ const branch = workBranch(worktreeName);
219
+
220
+ // Read again: the reply step may have moved the session while git ran.
221
+ const fresh = await ctx.store.get(CHAT_TYPE, object.id);
222
+ if (fresh === undefined) return failed(`there is no chat ${object.id}`);
223
+ if (typeof fresh.data.worktree === "object" && fresh.data.worktree !== null) {
224
+ return { result: "done", data: { moved: false } };
225
+ }
226
+ const access = chatData(fresh.data).access;
227
+ await ctx.store.put(
228
+ CHAT_TYPE,
229
+ object.id,
230
+ { ...fresh.data, cwd: path, access: { ...access, readOnly: false }, worktree: { path, branch } },
231
+ "step:dev/chat_worktree",
232
+ );
233
+ return { result: "done", data: { moved: true, path, branch } };
234
+ }
package/src/check.ts ADDED
@@ -0,0 +1,80 @@
1
+ /**
2
+ * The dev plugin's `init` check: every registered repository has a remote that
3
+ * answers and publishes its main branch. The check only reads: it asks the
4
+ * remote for its heads through the remote's name, so git's URL rewriting and
5
+ * credentials apply as they would for a real command, and writes nothing.
6
+ */
7
+
8
+ import { messageOf, type PluginBaseContext } from "@operad-io/engine";
9
+ import { git as runGit, type GitResult } from "./git.ts";
10
+ import { listRepositories } from "./service.ts";
11
+ import { readDevSettings } from "./settings.ts";
12
+
13
+ function git(cwd: string, args: readonly string[]): GitResult {
14
+ // The init check must never wait for a credential prompt; the shared runner
15
+ // retries an empty success under load.
16
+ return runGit(cwd, args, { env: { ...process.env, GIT_TERMINAL_PROMPT: "0" } });
17
+ }
18
+
19
+ /** Git's own explanation, every line of it, or a plain note when it said nothing. */
20
+ function detail(text: string): string {
21
+ return text.length === 0 ? "no detail" : text;
22
+ }
23
+
24
+ /** True when `git ls-remote` listed the branch under its full ref name. */
25
+ function listsBranch(output: string, branch: string): boolean {
26
+ const ref = `refs/heads/${branch}`;
27
+ return output
28
+ .split("\n")
29
+ .some((line) => line.split("\t")[1]?.trim() === ref);
30
+ }
31
+
32
+ /** Checks one repository and returns the remote it used. */
33
+ async function checkRepository(
34
+ repository: { readonly name: string; readonly path: string },
35
+ ): Promise<string> {
36
+ const settings = await readDevSettings(repository.path);
37
+ const remote = git(repository.path, [
38
+ "remote",
39
+ "get-url",
40
+ settings.remote,
41
+ ]);
42
+ if (!remote.ok || remote.out.length === 0) {
43
+ throw new Error(`remote "${settings.remote}" does not exist`);
44
+ }
45
+
46
+ const listed = git(repository.path, [
47
+ "ls-remote",
48
+ "--heads",
49
+ settings.remote,
50
+ settings.mainBranch,
51
+ ]);
52
+ if (!listed.ok) {
53
+ throw new Error(
54
+ `cannot reach remote "${settings.remote}": ${detail(listed.err)}`,
55
+ );
56
+ }
57
+ if (!listsBranch(listed.out, settings.mainBranch)) {
58
+ throw new Error(
59
+ `remote "${settings.remote}" has no branch "${settings.mainBranch}"`,
60
+ );
61
+ }
62
+ return settings.remote;
63
+ }
64
+
65
+ /** Runs the repository loop and reports one line, or throws with every failure. */
66
+ export async function checkDev(ctx: PluginBaseContext): Promise<string> {
67
+ const repositories = await listRepositories(ctx.store);
68
+ if (repositories.length === 0) return "no repositories registered";
69
+
70
+ const failures: string[] = [];
71
+ for (const repository of repositories) {
72
+ try {
73
+ await checkRepository(repository);
74
+ } catch (error) {
75
+ failures.push(`repository "${repository.name}": ${messageOf(error)}`);
76
+ }
77
+ }
78
+ if (failures.length > 0) throw new Error(failures.join("; "));
79
+ return `${repositories.length} repositories checked`;
80
+ }