@microvac/plugin-blocked 0.0.0-stage → 0.1.0-rc.17

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Paperclip AI
4
+ Copyright (c) 2026 Microvac contributors
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/lib/client.js ADDED
@@ -0,0 +1,299 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "@microvac/plugin-blocked",
3
+ factory: (require) => {
4
+ require("@microvac/ui").requireVersion("^1.2.0", "@microvac/plugin-blocked");
5
+ const module = { exports: {} };
6
+ const exports = module.exports;
7
+ "use strict";
8
+ var __defProp = Object.defineProperty;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropNames = Object.getOwnPropertyNames;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __export = (target, all) => {
13
+ for (var name2 in all)
14
+ __defProp(target, name2, { get: all[name2], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+
26
+ // src/client.tsx
27
+ var client_exports = {};
28
+ __export(client_exports, {
29
+ apply: () => apply,
30
+ inject: () => inject,
31
+ name: () => name
32
+ });
33
+ module.exports = __toCommonJS(client_exports);
34
+ var import_ui3 = require("@microvac/ui");
35
+
36
+ // src/page.tsx
37
+ var import_react2 = require("react");
38
+ var import_ui2 = require("@microvac/ui");
39
+
40
+ // src/model.ts
41
+ var STATUS_BLOCKED_GROUP = "status_blocked";
42
+ var DECISION_REASON = "awaiting_human_answer";
43
+ function groupRank(task) {
44
+ return task.blockReason ? task.blockReason.priority : Number.POSITIVE_INFINITY;
45
+ }
46
+ function groupBlockedTasks(lists, label) {
47
+ const tasks3 = /* @__PURE__ */ new Map();
48
+ for (const list of lists) for (const task of list ?? []) if (!tasks3.has(task.id) || task.blockReason) tasks3.set(task.id, task);
49
+ const groups = /* @__PURE__ */ new Map();
50
+ for (const task of tasks3.values()) {
51
+ if (!task.blockReason && task.status !== "blocked") continue;
52
+ if (task.blockReason?.id === DECISION_REASON) continue;
53
+ const id = task.blockReason?.id ?? STATUS_BLOCKED_GROUP;
54
+ let group = groups.get(id);
55
+ if (!group) {
56
+ const name2 = task.blockReason ? label(task.blockReason.id, task.blockReason.label) : "Status: blocked";
57
+ group = { id, label: name2, tasks: [], rank: groupRank(task) };
58
+ groups.set(id, group);
59
+ }
60
+ group.tasks.push(task);
61
+ }
62
+ return [...groups.values()].sort((a, b) => a.rank - b.rank || a.label.localeCompare(b.label)).map(({ rank: _rank, ...group }) => ({
63
+ ...group,
64
+ tasks: group.tasks.sort((a, b) => Date.parse(a.updatedAt) - Date.parse(b.updatedAt) || a.id.localeCompare(b.id))
65
+ }));
66
+ }
67
+ function blockedDetail(task) {
68
+ const detail = task.blockReason?.detail;
69
+ const where = detail?.identifier ?? detail?.title;
70
+ if (where) return `blocked by ${where}`;
71
+ if (detail?.text) return detail.text;
72
+ const blockers = (task.blockedBy ?? []).map((blocker) => blocker.identifier ?? blocker.title);
73
+ return blockers.length > 0 ? `blocked by ${blockers.join(", ")}` : null;
74
+ }
75
+ function reportSubtask(task, agentId, reason) {
76
+ const name2 = task.identifier ?? task.title;
77
+ return {
78
+ parentId: task.id,
79
+ title: `Unblock ${name2}: ${task.title}`,
80
+ description: [`${name2} is blocked${reason ? `: ${reason}` : "."}`, "Find what it waits on and unblock it, or say why it cannot be unblocked."].join("\n\n"),
81
+ status: "todo",
82
+ assigneeAgentId: agentId
83
+ };
84
+ }
85
+
86
+ // src/useBlockedTasks.ts
87
+ var import_react = require("react");
88
+ var import_ui = require("@microvac/ui");
89
+ var REFRESH_MS = 6e4;
90
+ function blockedTasksQueryKey(companyId) {
91
+ return ["issues", companyId, "microvac-blocked"];
92
+ }
93
+ function useBlockedTasks(companyId) {
94
+ const query = (0, import_ui.useQuery)({
95
+ queryKey: blockedTasksQueryKey(companyId ?? ""),
96
+ queryFn: () => Promise.all([
97
+ import_ui.tasks.list(companyId, { blockReason: "*", includeBlockedBy: true }),
98
+ import_ui.tasks.list(companyId, { status: "blocked", includeBlockedBy: true })
99
+ ]),
100
+ enabled: Boolean(companyId),
101
+ refetchInterval: REFRESH_MS,
102
+ refetchOnWindowFocus: true
103
+ });
104
+ const groups = (0, import_react.useMemo)(() => groupBlockedTasks(query.data ?? [], import_ui.blockReasons.label), [query.data]);
105
+ return {
106
+ groups,
107
+ total: groups.reduce((sum, group) => sum + group.tasks.length, 0),
108
+ isLoading: Boolean(companyId) && query.isPending,
109
+ error: query.error instanceof Error ? query.error : query.error ? new Error(String(query.error)) : null,
110
+ refetch: () => void query.refetch()
111
+ };
112
+ }
113
+ function useBlockedCount({ companyId }) {
114
+ const state = useBlockedTasks(companyId);
115
+ return state.isLoading || state.error ? void 0 : state.total;
116
+ }
117
+
118
+ // src/page.tsx
119
+ var import_jsx_runtime = require("react/jsx-runtime");
120
+ var NO_TARGET = { get: () => void 0 };
121
+ var noSubscription = () => () => {
122
+ };
123
+ function useReportAgentId(target) {
124
+ const value = (0, import_react2.useSyncExternalStore)(target.subscribe ?? noSubscription, () => target.get(), () => target.get());
125
+ const id = typeof value === "string" ? value.trim() : "";
126
+ return id || null;
127
+ }
128
+ function errorMessage(error) {
129
+ return error instanceof Error ? error.message : void 0;
130
+ }
131
+ function useDaneelAgentId(companyId, enabled) {
132
+ const query = (0, import_ui2.useQuery)({
133
+ queryKey: ["microvac-daneel", companyId ?? ""],
134
+ queryFn: () => import_ui2.api.get(`/microvac/daneel/companies/${encodeURIComponent(companyId)}`).catch(() => ({ agent: null })),
135
+ enabled: enabled && Boolean(companyId)
136
+ });
137
+ return enabled ? query.data?.agent?.id ?? null : null;
138
+ }
139
+ function createBlockedPage(target = NO_TARGET) {
140
+ return function BlockedPage() {
141
+ const { companyId } = (0, import_ui2.useSelectedCompany)();
142
+ const configuredAgentId = useReportAgentId(target);
143
+ const daneelAgentId = useDaneelAgentId(companyId, configuredAgentId === null);
144
+ const reportAgentId = configuredAgentId ?? daneelAgentId;
145
+ if (!companyId) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "p-4 text-sm text-muted-foreground", children: "Select a company to see its blocked tasks." });
146
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BlockedList, { companyId, reportAgentId });
147
+ };
148
+ }
149
+ function BlockedList({ companyId, reportAgentId }) {
150
+ const state = useBlockedTasks(companyId);
151
+ const queryClient = (0, import_ui2.useQueryClient)();
152
+ const toast = (0, import_ui2.useToast)();
153
+ const [busy, setBusy] = (0, import_react2.useState)({});
154
+ const refresh = (0, import_react2.useCallback)(
155
+ () => queryClient.invalidateQueries({ queryKey: ["issues", companyId] }),
156
+ [queryClient, companyId]
157
+ );
158
+ const run = (0, import_react2.useCallback)(
159
+ async (task, action, work) => {
160
+ setBusy((current) => ({ ...current, [task.id]: action }));
161
+ try {
162
+ await work();
163
+ await refresh();
164
+ } finally {
165
+ setBusy((current) => ({ ...current, [task.id]: void 0 }));
166
+ }
167
+ },
168
+ [refresh]
169
+ );
170
+ const actions = {
171
+ retry: (task) => run(task, "retry", async () => {
172
+ try {
173
+ const outcome = await import_ui2.tasks.retry(task);
174
+ toast(outcome.started ? { title: "Run restarted", tone: "success" } : { title: "Nothing started", body: outcome.message ?? void 0, tone: "warn" });
175
+ } catch (error) {
176
+ toast({ title: "Retry failed", body: errorMessage(error), tone: "error" });
177
+ }
178
+ }),
179
+ reassign: (task, next) => run(task, "reassign", async () => {
180
+ try {
181
+ await import_ui2.tasks.update(task.id, { ...next });
182
+ toast({ title: "Task reassigned", tone: "success" });
183
+ } catch (error) {
184
+ toast({ title: "Reassign failed", body: errorMessage(error), tone: "error" });
185
+ }
186
+ }),
187
+ unblock: (task) => run(task, "unblock", async () => {
188
+ try {
189
+ await import_ui2.tasks.update(task.id, { status: "todo" });
190
+ toast({ title: "Task unblocked", body: "It is back in To do.", tone: "success" });
191
+ } catch (error) {
192
+ toast({ title: "Unblock failed", body: errorMessage(error), tone: "error" });
193
+ }
194
+ }),
195
+ report: reportAgentId ? (task) => run(task, "report", async () => {
196
+ try {
197
+ const reason = task.blockReason ? import_ui2.blockReasons.description(task.blockReason) : blockedDetail(task);
198
+ const created = await import_ui2.tasks.create(companyId, reportSubtask(task, reportAgentId, reason));
199
+ toast({ title: `Reported in ${created.identifier ?? "a subtask"}`, tone: "success" });
200
+ } catch (error) {
201
+ toast({ title: "Report failed", body: errorMessage(error), tone: "error" });
202
+ }
203
+ }) : null
204
+ };
205
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "max-w-3xl space-y-4", "data-microvac-blocked": "", children: [
206
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-baseline gap-2", children: [
207
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", { className: "text-xl font-bold", children: "Blocked" }),
208
+ !state.isLoading && !state.error ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "text-sm text-muted-foreground", "data-testid": "blocked-total", children: [
209
+ state.total,
210
+ " ",
211
+ state.total === 1 ? "task" : "tasks"
212
+ ] }) : null
213
+ ] }),
214
+ state.error ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-2 rounded-md border border-destructive/40 p-3 text-sm", children: [
215
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
216
+ "Blocked tasks could not load: ",
217
+ state.error.message
218
+ ] }),
219
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui2.Button, { variant: "outline", size: "sm", onClick: state.refetch, children: "Retry" })
220
+ ] }) : state.isLoading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-sm text-muted-foreground", children: "Loading blocked tasks\u2026" }) : state.groups.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "rounded-md border border-dashed p-6 text-center text-sm text-muted-foreground", children: "Nothing is blocked." }) : state.groups.map((group) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Group, { group, companyId, busy, actions }, group.id))
221
+ ] });
222
+ }
223
+ function Group({
224
+ group,
225
+ companyId,
226
+ busy,
227
+ actions
228
+ }) {
229
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "space-y-2", "data-blocked-group": group.id, children: [
230
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("h2", { className: "flex items-center gap-2 text-sm font-semibold text-muted-foreground", children: [
231
+ group.label,
232
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui2.Badge, { variant: "secondary", children: group.tasks.length })
233
+ ] }),
234
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", { className: "space-y-2", children: group.tasks.map((task) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TaskRow, { task, companyId, busy: busy[task.id], actions }, task.id)) })
235
+ ] });
236
+ }
237
+ function TaskRow({
238
+ task,
239
+ companyId,
240
+ busy,
241
+ actions
242
+ }) {
243
+ const detail = blockedDetail(task);
244
+ const disabled = Boolean(busy);
245
+ const { RotateCcw, LockOpen, MessageSquareWarning } = import_ui2.icons;
246
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { className: "rounded-lg border bg-card p-3", "data-blocked-task": task.id, children: [
247
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-wrap items-baseline gap-x-2 gap-y-1", children: [
248
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui2.Link, { to: `/issues/${task.identifier ?? task.id}`, className: "min-w-0 break-words font-medium hover:underline", children: [
249
+ task.identifier ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "mr-1.5 font-mono text-xs text-muted-foreground", children: task.identifier }) : null,
250
+ task.title
251
+ ] }),
252
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-xs text-muted-foreground", children: (0, import_ui2.relativeTime)(task.updatedAt) })
253
+ ] }),
254
+ detail ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "mt-1 text-sm text-muted-foreground", children: detail }) : null,
255
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "mt-2 flex flex-wrap items-center gap-2", children: [
256
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui2.Button, { variant: "outline", size: "sm", disabled, onClick: () => void actions.retry(task), children: [
257
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RotateCcw, { className: "size-3.5" }),
258
+ busy === "retry" ? "Retrying\u2026" : "Retry run"
259
+ ] }),
260
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui2.Button, { variant: "outline", size: "sm", disabled, onClick: () => void actions.unblock(task), children: [
261
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LockOpen, { className: "size-3.5" }),
262
+ busy === "unblock" ? "Unblocking\u2026" : "Unblock"
263
+ ] }),
264
+ actions.report ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_ui2.Button, { variant: "outline", size: "sm", disabled, onClick: () => void actions.report(task), children: [
265
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MessageSquareWarning, { className: "size-3.5" }),
266
+ busy === "report" ? "Reporting\u2026" : "Report to agent"
267
+ ] }) : null,
268
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "flex items-center gap-1 text-xs text-muted-foreground", "aria-label": "Reassign", children: [
269
+ "Reassign",
270
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
271
+ import_ui2.AssigneePicker,
272
+ {
273
+ companyId,
274
+ disabled,
275
+ value: { assigneeAgentId: task.assigneeAgentId, assigneeUserId: task.assigneeUserId },
276
+ onChange: (next) => void actions.reassign(task, next)
277
+ }
278
+ )
279
+ ] })
280
+ ] })
281
+ ] });
282
+ }
283
+
284
+ // src/client.tsx
285
+ var name = "@microvac/plugin-blocked";
286
+ var inject = ["pages", "bottomBar"];
287
+ function apply(ctx, config = {}) {
288
+ ctx.pages.provide("blocked", {
289
+ id: name,
290
+ component: createBlockedPage(config.reportToAgentId),
291
+ useCount: useBlockedCount,
292
+ navigation: { label: "Blocked", icon: import_ui3.icons.OctagonAlert, to: "/blocked" }
293
+ });
294
+ ctx.bottomBar.provide({ id: "blocked", label: "Blocked", icon: import_ui3.icons.OctagonAlert, to: "/blocked", slot: "blocked" });
295
+ }
296
+
297
+ return module.exports;
298
+ },
299
+ });
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "@microvac/plugin-blocked",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-rc.17",
4
+ "license": "MIT",
5
+ "description": "Microvac plugin: the Blocked page, blocked tasks grouped by reason with their actions.",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": "./src/index.js",
9
+ "./client": "./lib/client.js",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "files": [
13
+ "src",
14
+ "lib"
15
+ ],
16
+ "microvac": {
17
+ "ui": "^1.2.0"
18
+ },
19
+ "dsh": {
20
+ "client": {
21
+ "platform": "web",
22
+ "inject": [
23
+ "pages",
24
+ "bottomBar"
25
+ ],
26
+ "external": [
27
+ "@microvac/ui"
28
+ ],
29
+ "immediately": true
30
+ }
31
+ },
32
+ "dependencies": {
33
+ "@deepseek-ai/schemastery": "3.20.0-alpha.2"
34
+ },
35
+ "scripts": {
36
+ "build:client": "node ../../scripts/microvac/build-client-plugin.mjs .",
37
+ "typecheck": "tsc --noEmit"
38
+ },
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/microvac-ai/microvac"
42
+ }
43
+ }
package/src/client.tsx ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Client face of the `blocked` plugin (`docs/microvac/decisions.md`): the
3
+ * Blocked page, its count and its sidebar entry (under Decisions), given to
4
+ * the `blocked` page slot, and a `blocked` bottom bar entry the instance
5
+ * layout can list (not in the default layout). The host face's
6
+ * volatile `reportToAgentId` arrives synced in `config`. The build checks the
7
+ * Microvac UI range (`microvac.ui` in `package.json`).
8
+ */
9
+ import { icons } from "@microvac/ui";
10
+ import { createBlockedPage, type ReportTarget } from "./page.js";
11
+ import { useBlockedCount } from "./useBlockedTasks.js";
12
+
13
+ export const name = "@microvac/plugin-blocked";
14
+ export const inject = ["pages", "bottomBar"];
15
+
16
+ interface BlockedContext {
17
+ pages: {
18
+ provide(
19
+ slot: string,
20
+ occupant: {
21
+ id: string;
22
+ component: unknown;
23
+ useCount?: (context: { companyId: string | null }) => number | undefined;
24
+ navigation?: { label: string; icon: unknown; to: string };
25
+ },
26
+ ): () => void;
27
+ };
28
+ bottomBar: {
29
+ provide(entry: { id: string; label: string; icon: unknown; to: string; slot?: string }): () => void;
30
+ };
31
+ }
32
+
33
+ export function apply(ctx: BlockedContext, config: { reportToAgentId?: ReportTarget } = {}) {
34
+ ctx.pages.provide("blocked", {
35
+ id: name,
36
+ component: createBlockedPage(config.reportToAgentId),
37
+ useCount: useBlockedCount,
38
+ navigation: { label: "Blocked", icon: icons.OctagonAlert, to: "/blocked" },
39
+ });
40
+ ctx.bottomBar.provide({ id: "blocked", label: "Blocked", icon: icons.OctagonAlert, to: "/blocked", slot: "blocked" });
41
+ }
package/src/index.js ADDED
@@ -0,0 +1,30 @@
1
+ // @ts-check
2
+ /**
3
+ * Host face of the `blocked` plugin. Its client face (`src/client.tsx`, built
4
+ * into `lib/client.js`) provides the Blocked page (`/:prefix/blocked`), its
5
+ * count and a `blocked` bottom bar entry (`docs/microvac/decisions.md`).
6
+ * `reportToAgentId` is volatile, so `dsh-client-modules` syncs it to the
7
+ * client face: the agent "Report to agent" assigns its subtask to. Unset,
8
+ * the company's Daneel takes it (ADR 0013); with no Daneel, the action is
9
+ * hidden.
10
+ *
11
+ * # microvac.yml
12
+ * - id: blocked
13
+ * name: "@microvac/plugin-blocked"
14
+ * config:
15
+ * reportToAgentId: 4f0c…
16
+ */
17
+ import z from "@deepseek-ai/schemastery";
18
+
19
+ export const name = "@microvac/plugin-blocked";
20
+
21
+ export const Config = z.object({
22
+ reportToAgentId: z
23
+ .string()
24
+ .default("")
25
+ .volatile()
26
+ .description('Agent id "Report to agent" assigns a subtask to on the Blocked page. Empty: the company\'s Daneel, or no action without one.'),
27
+ });
28
+
29
+ /** The host face has nothing to start. */
30
+ export function apply() {}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * The part of Microvac UI (`ui/src/microvac/ui-module`) this plugin uses; the
3
+ * page provides the module at run time. `tsconfig.json` maps `@microvac/ui`
4
+ * here for type checking; the build keeps it external.
5
+ */
6
+ import type { ComponentType } from "react";
7
+ import type { AssigneeValue, BlockedTask, BlockReason } from "./types.js";
8
+
9
+ type AnyComponent = ComponentType<any>;
10
+ type Icon = ComponentType<{ className?: string }>;
11
+
12
+ export declare const version: string;
13
+ export declare function requireVersion(range: string, plugin?: string): void;
14
+
15
+ export declare function useQuery<T>(options: {
16
+ queryKey: readonly unknown[];
17
+ queryFn: () => Promise<T>;
18
+ enabled?: boolean;
19
+ refetchInterval?: number;
20
+ refetchOnWindowFocus?: boolean;
21
+ }): { data?: T; error: unknown; isPending: boolean; refetch(): Promise<unknown> };
22
+ export declare function useQueryClient(): { invalidateQueries(filters: { queryKey: readonly unknown[] }): Promise<void> };
23
+ export declare function useSelectedCompany(): { companyId: string | null; company: { issuePrefix?: string | null } | null };
24
+ export declare function useToast(): (input: { title: string; body?: string; tone?: "info" | "success" | "warn" | "error" }) => void;
25
+
26
+ export declare const api: { get<T>(path: string): Promise<T> };
27
+
28
+ export declare const Link: AnyComponent;
29
+ export declare const Button: AnyComponent;
30
+ export declare const Badge: AnyComponent;
31
+ export declare function cn(...classes: unknown[]): string;
32
+ export declare function relativeTime(value: string | Date): string;
33
+
34
+ export declare const tasks: {
35
+ list(
36
+ companyId: string,
37
+ filters?: { status?: string; blockReason?: string | readonly string[]; includeBlockedBy?: boolean },
38
+ ): Promise<BlockedTask[]>;
39
+ update(id: string, patch: Record<string, unknown>): Promise<unknown>;
40
+ create(companyId: string, data: Record<string, unknown>): Promise<{ id: string; identifier: string | null }>;
41
+ retry(task: BlockedTask): Promise<{ started: boolean; message: string | null }>;
42
+ };
43
+ export declare const blockReasons: {
44
+ label(reasonId: string, fallback?: string): string;
45
+ description(reason: BlockReason): string;
46
+ };
47
+ export declare const AssigneePicker: ComponentType<{
48
+ companyId: string;
49
+ value: AssigneeValue;
50
+ onChange: (next: AssigneeValue) => void;
51
+ disabled?: boolean;
52
+ className?: string;
53
+ }>;
54
+ export declare const icons: {
55
+ LockOpen: Icon;
56
+ MessageSquareWarning: Icon;
57
+ OctagonAlert: Icon;
58
+ RotateCcw: Icon;
59
+ UserRoundPen: Icon;
60
+ };
package/src/model.ts ADDED
@@ -0,0 +1,74 @@
1
+ import type { BlockedTask } from "./types.js";
2
+
3
+ /** Group of tasks set to `blocked` with no computed block reason. */
4
+ export const STATUS_BLOCKED_GROUP = "status_blocked";
5
+
6
+ /** Tasks waiting on a human answer are on the Decisions page, not here. */
7
+ export const DECISION_REASON = "awaiting_human_answer";
8
+
9
+ export interface BlockedGroup {
10
+ /** Block reason id, or `STATUS_BLOCKED_GROUP`. */
11
+ id: string;
12
+ label: string;
13
+ tasks: BlockedTask[];
14
+ }
15
+
16
+ /** Order of the groups: the reason's priority (lower first), "Status: blocked" last. */
17
+ function groupRank(task: BlockedTask): number {
18
+ return task.blockReason ? task.blockReason.priority : Number.POSITIVE_INFINITY;
19
+ }
20
+
21
+ /**
22
+ * The Blocked page's list: tasks with a block reason other than
23
+ * `awaiting_human_answer` and tasks set to `blocked`, each once, grouped by reason (`docs/microvac/decisions.md`).
24
+ * Groups follow the reason priority; inside a group, the task blocked the
25
+ * longest comes first (oldest `updatedAt`).
26
+ */
27
+ export function groupBlockedTasks(
28
+ lists: readonly (readonly BlockedTask[] | undefined)[],
29
+ label: (reasonId: string, fallback?: string) => string,
30
+ ): BlockedGroup[] {
31
+ const tasks = new Map<string, BlockedTask>();
32
+ for (const list of lists) for (const task of list ?? []) if (!tasks.has(task.id) || task.blockReason) tasks.set(task.id, task);
33
+ const groups = new Map<string, BlockedGroup & { rank: number }>();
34
+ for (const task of tasks.values()) {
35
+ if (!task.blockReason && task.status !== "blocked") continue;
36
+ if (task.blockReason?.id === DECISION_REASON) continue;
37
+ const id = task.blockReason?.id ?? STATUS_BLOCKED_GROUP;
38
+ let group = groups.get(id);
39
+ if (!group) {
40
+ const name = task.blockReason ? label(task.blockReason.id, task.blockReason.label) : "Status: blocked";
41
+ group = { id, label: name, tasks: [], rank: groupRank(task) };
42
+ groups.set(id, group);
43
+ }
44
+ group.tasks.push(task);
45
+ }
46
+ return [...groups.values()]
47
+ .sort((a, b) => a.rank - b.rank || a.label.localeCompare(b.label))
48
+ .map(({ rank: _rank, ...group }) => ({
49
+ ...group,
50
+ tasks: group.tasks.sort((a, b) => Date.parse(a.updatedAt) - Date.parse(b.updatedAt) || a.id.localeCompare(b.id)),
51
+ }));
52
+ }
53
+
54
+ /** What the task waits on, in a few words: "blocked by MON-965", the reason's text, ... */
55
+ export function blockedDetail(task: BlockedTask): string | null {
56
+ const detail = task.blockReason?.detail;
57
+ const where = detail?.identifier ?? detail?.title;
58
+ if (where) return `blocked by ${where}`;
59
+ if (detail?.text) return detail.text;
60
+ const blockers = (task.blockedBy ?? []).map((blocker) => blocker.identifier ?? blocker.title);
61
+ return blockers.length > 0 ? `blocked by ${blockers.join(", ")}` : null;
62
+ }
63
+
64
+ /** The subtask "Report to agent" creates for `task`. */
65
+ export function reportSubtask(task: BlockedTask, agentId: string, reason: string | null) {
66
+ const name = task.identifier ?? task.title;
67
+ return {
68
+ parentId: task.id,
69
+ title: `Unblock ${name}: ${task.title}`,
70
+ description: [`${name} is blocked${reason ? `: ${reason}` : "."}`, "Find what it waits on and unblock it, or say why it cannot be unblocked."].join("\n\n"),
71
+ status: "todo",
72
+ assigneeAgentId: agentId,
73
+ };
74
+ }
package/src/page.tsx ADDED
@@ -0,0 +1,255 @@
1
+ /**
2
+ * The Microvac Blocked page (`docs/microvac/decisions.md`): blocked tasks,
3
+ * one group per block reason, each with its detail, a link to the issue and
4
+ * the actions Retry run, Reassign, Unblock and Report to agent.
5
+ */
6
+ import { useCallback, useState, useSyncExternalStore } from "react";
7
+ import {
8
+ api,
9
+ AssigneePicker,
10
+ Badge,
11
+ blockReasons,
12
+ Button,
13
+ icons,
14
+ Link,
15
+ relativeTime,
16
+ tasks,
17
+ useQuery,
18
+ useQueryClient,
19
+ useSelectedCompany,
20
+ useToast,
21
+ } from "@microvac/ui";
22
+ import { blockedDetail, reportSubtask, type BlockedGroup } from "./model.js";
23
+ import type { AssigneeValue, BlockedTask } from "./types.js";
24
+ import { blockedTasksQueryKey, useBlockedTasks } from "./useBlockedTasks.js";
25
+
26
+ /** The configured "Report to agent" target, synced from the host face. */
27
+ export interface ReportTarget {
28
+ get(): string | undefined;
29
+ subscribe?(listener: () => void): () => void;
30
+ }
31
+
32
+ const NO_TARGET: ReportTarget = { get: () => undefined };
33
+ const noSubscription = () => () => {};
34
+
35
+ export function useReportAgentId(target: ReportTarget): string | null {
36
+ const value = useSyncExternalStore(target.subscribe ?? noSubscription, () => target.get(), () => target.get());
37
+ const id = typeof value === "string" ? value.trim() : "";
38
+ return id || null;
39
+ }
40
+
41
+ function errorMessage(error: unknown): string | undefined {
42
+ return error instanceof Error ? error.message : undefined;
43
+ }
44
+
45
+ /**
46
+ * The company's Daneel (ADR 0013), the default "Report to agent" target when
47
+ * the setting is empty. `null` when the Daneel plugin does not run.
48
+ */
49
+ export function useDaneelAgentId(companyId: string | null, enabled: boolean): string | null {
50
+ const query = useQuery({
51
+ queryKey: ["microvac-daneel", companyId ?? ""],
52
+ queryFn: () =>
53
+ api
54
+ .get<{ agent: { id: string } | null }>(`/microvac/daneel/companies/${encodeURIComponent(companyId!)}`)
55
+ .catch(() => ({ agent: null })),
56
+ enabled: enabled && Boolean(companyId),
57
+ });
58
+ return enabled ? (query.data?.agent?.id ?? null) : null;
59
+ }
60
+
61
+ export function createBlockedPage(target: ReportTarget = NO_TARGET) {
62
+ return function BlockedPage() {
63
+ const { companyId } = useSelectedCompany();
64
+ const configuredAgentId = useReportAgentId(target);
65
+ const daneelAgentId = useDaneelAgentId(companyId, configuredAgentId === null);
66
+ const reportAgentId = configuredAgentId ?? daneelAgentId;
67
+ if (!companyId) return <p className="p-4 text-sm text-muted-foreground">Select a company to see its blocked tasks.</p>;
68
+ return <BlockedList companyId={companyId} reportAgentId={reportAgentId} />;
69
+ };
70
+ }
71
+
72
+ function BlockedList({ companyId, reportAgentId }: { companyId: string; reportAgentId: string | null }) {
73
+ const state = useBlockedTasks(companyId);
74
+ const queryClient = useQueryClient();
75
+ const toast = useToast();
76
+ const [busy, setBusy] = useState<Record<string, string | undefined>>({});
77
+
78
+ const refresh = useCallback(
79
+ () => queryClient.invalidateQueries({ queryKey: ["issues", companyId] }),
80
+ [queryClient, companyId],
81
+ );
82
+
83
+ const run = useCallback(
84
+ async (task: BlockedTask, action: string, work: () => Promise<void>) => {
85
+ setBusy((current) => ({ ...current, [task.id]: action }));
86
+ try {
87
+ await work();
88
+ await refresh();
89
+ } finally {
90
+ setBusy((current) => ({ ...current, [task.id]: undefined }));
91
+ }
92
+ },
93
+ [refresh],
94
+ );
95
+
96
+ const actions: TaskActions = {
97
+ retry: (task) =>
98
+ run(task, "retry", async () => {
99
+ try {
100
+ const outcome = await tasks.retry(task);
101
+ toast(outcome.started ? { title: "Run restarted", tone: "success" } : { title: "Nothing started", body: outcome.message ?? undefined, tone: "warn" });
102
+ } catch (error) {
103
+ toast({ title: "Retry failed", body: errorMessage(error), tone: "error" });
104
+ }
105
+ }),
106
+ reassign: (task, next) =>
107
+ run(task, "reassign", async () => {
108
+ try {
109
+ await tasks.update(task.id, { ...next });
110
+ toast({ title: "Task reassigned", tone: "success" });
111
+ } catch (error) {
112
+ toast({ title: "Reassign failed", body: errorMessage(error), tone: "error" });
113
+ }
114
+ }),
115
+ unblock: (task) =>
116
+ run(task, "unblock", async () => {
117
+ try {
118
+ await tasks.update(task.id, { status: "todo" });
119
+ toast({ title: "Task unblocked", body: "It is back in To do.", tone: "success" });
120
+ } catch (error) {
121
+ toast({ title: "Unblock failed", body: errorMessage(error), tone: "error" });
122
+ }
123
+ }),
124
+ report: reportAgentId
125
+ ? (task) =>
126
+ run(task, "report", async () => {
127
+ try {
128
+ const reason = task.blockReason ? blockReasons.description(task.blockReason) : blockedDetail(task);
129
+ const created = await tasks.create(companyId, reportSubtask(task, reportAgentId, reason));
130
+ toast({ title: `Reported in ${created.identifier ?? "a subtask"}`, tone: "success" });
131
+ } catch (error) {
132
+ toast({ title: "Report failed", body: errorMessage(error), tone: "error" });
133
+ }
134
+ })
135
+ : null,
136
+ };
137
+
138
+ return (
139
+ <div className="max-w-3xl space-y-4" data-microvac-blocked="">
140
+ <div className="flex items-baseline gap-2">
141
+ <h1 className="text-xl font-bold">Blocked</h1>
142
+ {!state.isLoading && !state.error ? (
143
+ <span className="text-sm text-muted-foreground" data-testid="blocked-total">
144
+ {state.total} {state.total === 1 ? "task" : "tasks"}
145
+ </span>
146
+ ) : null}
147
+ </div>
148
+
149
+ {state.error ? (
150
+ <div className="flex items-center gap-2 rounded-md border border-destructive/40 p-3 text-sm">
151
+ <span>Blocked tasks could not load: {state.error.message}</span>
152
+ <Button variant="outline" size="sm" onClick={state.refetch}>
153
+ Retry
154
+ </Button>
155
+ </div>
156
+ ) : state.isLoading ? (
157
+ <p className="text-sm text-muted-foreground">Loading blocked tasks…</p>
158
+ ) : state.groups.length === 0 ? (
159
+ <p className="rounded-md border border-dashed p-6 text-center text-sm text-muted-foreground">Nothing is blocked.</p>
160
+ ) : (
161
+ state.groups.map((group) => (
162
+ <Group key={group.id} group={group} companyId={companyId} busy={busy} actions={actions} />
163
+ ))
164
+ )}
165
+ </div>
166
+ );
167
+ }
168
+
169
+ interface TaskActions {
170
+ retry(task: BlockedTask): Promise<void>;
171
+ reassign(task: BlockedTask, next: AssigneeValue): Promise<void>;
172
+ unblock(task: BlockedTask): Promise<void>;
173
+ report: ((task: BlockedTask) => Promise<void>) | null;
174
+ }
175
+
176
+ function Group({
177
+ group,
178
+ companyId,
179
+ busy,
180
+ actions,
181
+ }: {
182
+ group: BlockedGroup;
183
+ companyId: string;
184
+ busy: Record<string, string | undefined>;
185
+ actions: TaskActions;
186
+ }) {
187
+ return (
188
+ <section className="space-y-2" data-blocked-group={group.id}>
189
+ <h2 className="flex items-center gap-2 text-sm font-semibold text-muted-foreground">
190
+ {group.label}
191
+ <Badge variant="secondary">{group.tasks.length}</Badge>
192
+ </h2>
193
+ <ul className="space-y-2">
194
+ {group.tasks.map((task) => (
195
+ <TaskRow key={task.id} task={task} companyId={companyId} busy={busy[task.id]} actions={actions} />
196
+ ))}
197
+ </ul>
198
+ </section>
199
+ );
200
+ }
201
+
202
+ function TaskRow({
203
+ task,
204
+ companyId,
205
+ busy,
206
+ actions,
207
+ }: {
208
+ task: BlockedTask;
209
+ companyId: string;
210
+ busy: string | undefined;
211
+ actions: TaskActions;
212
+ }) {
213
+ const detail = blockedDetail(task);
214
+ const disabled = Boolean(busy);
215
+ const { RotateCcw, LockOpen, MessageSquareWarning } = icons;
216
+ return (
217
+ <li className="rounded-lg border bg-card p-3" data-blocked-task={task.id}>
218
+ <div className="flex flex-wrap items-baseline gap-x-2 gap-y-1">
219
+ <Link to={`/issues/${task.identifier ?? task.id}`} className="min-w-0 break-words font-medium hover:underline">
220
+ {task.identifier ? <span className="mr-1.5 font-mono text-xs text-muted-foreground">{task.identifier}</span> : null}
221
+ {task.title}
222
+ </Link>
223
+ <span className="text-xs text-muted-foreground">{relativeTime(task.updatedAt)}</span>
224
+ </div>
225
+ {detail ? <p className="mt-1 text-sm text-muted-foreground">{detail}</p> : null}
226
+ <div className="mt-2 flex flex-wrap items-center gap-2">
227
+ <Button variant="outline" size="sm" disabled={disabled} onClick={() => void actions.retry(task)}>
228
+ <RotateCcw className="size-3.5" />
229
+ {busy === "retry" ? "Retrying…" : "Retry run"}
230
+ </Button>
231
+ <Button variant="outline" size="sm" disabled={disabled} onClick={() => void actions.unblock(task)}>
232
+ <LockOpen className="size-3.5" />
233
+ {busy === "unblock" ? "Unblocking…" : "Unblock"}
234
+ </Button>
235
+ {actions.report ? (
236
+ <Button variant="outline" size="sm" disabled={disabled} onClick={() => void actions.report!(task)}>
237
+ <MessageSquareWarning className="size-3.5" />
238
+ {busy === "report" ? "Reporting…" : "Report to agent"}
239
+ </Button>
240
+ ) : null}
241
+ <span className="flex items-center gap-1 text-xs text-muted-foreground" aria-label="Reassign">
242
+ Reassign
243
+ <AssigneePicker
244
+ companyId={companyId}
245
+ disabled={disabled}
246
+ value={{ assigneeAgentId: task.assigneeAgentId, assigneeUserId: task.assigneeUserId }}
247
+ onChange={(next) => void actions.reassign(task, next)}
248
+ />
249
+ </span>
250
+ </div>
251
+ </li>
252
+ );
253
+ }
254
+
255
+ export { blockedTasksQueryKey };
package/src/types.ts ADDED
@@ -0,0 +1,42 @@
1
+ /**
2
+ * The task fields the Blocked page reads, as the board API returns them
3
+ * (`Issue` in `@paperclipai/shared`, copied so the plugin depends on Microvac
4
+ * UI only).
5
+ */
6
+
7
+ export interface BlockReasonDetail {
8
+ issueId?: string;
9
+ identifier?: string | null;
10
+ title?: string | null;
11
+ reasonId?: string;
12
+ text?: string | null;
13
+ }
14
+
15
+ export interface BlockReason {
16
+ id: string;
17
+ label: string;
18
+ priority: number;
19
+ detail?: BlockReasonDetail | null;
20
+ }
21
+
22
+ export interface TaskSummary {
23
+ id: string;
24
+ identifier: string | null;
25
+ title: string;
26
+ }
27
+
28
+ export interface BlockedTask extends TaskSummary {
29
+ status: string;
30
+ assigneeAgentId: string | null;
31
+ assigneeUserId: string | null;
32
+ updatedAt: string;
33
+ blockReason?: BlockReason | null;
34
+ blockedBy?: TaskSummary[];
35
+ interruption?: { observedRunId?: string | null; retryAction?: string | null } | null;
36
+ executionBlocker?: { runId?: string | null } | null;
37
+ }
38
+
39
+ export interface AssigneeValue {
40
+ assigneeAgentId: string | null;
41
+ assigneeUserId: string | null;
42
+ }
@@ -0,0 +1,51 @@
1
+ import { useMemo } from "react";
2
+ import { blockReasons, tasks, useQuery } from "@microvac/ui";
3
+ import { groupBlockedTasks, type BlockedGroup } from "./model.js";
4
+
5
+ /** The list refreshes on its own every minute and when the tab regains focus. */
6
+ const REFRESH_MS = 60_000;
7
+
8
+ /** Under the upstream `issues` key, so upstream task changes refresh the page too. */
9
+ export function blockedTasksQueryKey(companyId: string) {
10
+ return ["issues", companyId, "microvac-blocked"] as const;
11
+ }
12
+
13
+ export interface BlockedTasksState {
14
+ groups: BlockedGroup[];
15
+ total: number;
16
+ isLoading: boolean;
17
+ error: Error | null;
18
+ refetch: () => void;
19
+ }
20
+
21
+ /**
22
+ * Tasks with any registered block reason, plus tasks set to `blocked`
23
+ * without one, grouped. The page and its count both read it.
24
+ */
25
+ export function useBlockedTasks(companyId: string | null): BlockedTasksState {
26
+ const query = useQuery({
27
+ queryKey: blockedTasksQueryKey(companyId ?? ""),
28
+ queryFn: () =>
29
+ Promise.all([
30
+ tasks.list(companyId!, { blockReason: "*", includeBlockedBy: true }),
31
+ tasks.list(companyId!, { status: "blocked", includeBlockedBy: true }),
32
+ ]),
33
+ enabled: Boolean(companyId),
34
+ refetchInterval: REFRESH_MS,
35
+ refetchOnWindowFocus: true,
36
+ });
37
+ const groups = useMemo(() => groupBlockedTasks(query.data ?? [], blockReasons.label), [query.data]);
38
+ return {
39
+ groups,
40
+ total: groups.reduce((sum, group) => sum + group.tasks.length, 0),
41
+ isLoading: Boolean(companyId) && query.isPending,
42
+ error: query.error instanceof Error ? query.error : query.error ? new Error(String(query.error)) : null,
43
+ refetch: () => void query.refetch(),
44
+ };
45
+ }
46
+
47
+ /** Navigation count of the Blocked page; `undefined` until loaded. */
48
+ export function useBlockedCount({ companyId }: { companyId: string | null }): number | undefined {
49
+ const state = useBlockedTasks(companyId);
50
+ return state.isLoading || state.error ? undefined : state.total;
51
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.