pi-pstack-workflow-kit 0.0.0-stage → 0.1.1
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 +21 -0
- package/README.md +146 -2
- package/agents/ci-watcher.md +1 -0
- package/agents/comment-sicko.md +1 -0
- package/agents/poteto-agent.md +1 -0
- package/agents/quality-agent.md +1 -0
- package/agents/worker.md +3 -0
- package/lib/catalog-data.json +560 -0
- package/lib/catalog.ts +160 -0
- package/lib/jobs.ts +5 -0
- package/lib/models.ts +125 -0
- package/lib/pool.ts +27 -0
- package/lib/state.ts +127 -0
- package/lib/transcript.ts +48 -0
- package/lib/validation.ts +16 -0
- package/package.json +65 -4
- package/reference/GAPS.md +21 -0
- package/reference/PARITY.md +169 -0
- package/reference/benny/config.example.json +12 -0
- package/reference/benny/repro.md +3 -0
- package/reference/benny/setup.md +3 -0
- package/reference/benny/triage.md +3 -0
- package/reference/parity.json +3095 -0
- package/reference/rules/no-inline-imports.md +3 -0
- package/reference/rules/typescript-exhaustive-switch.md +3 -0
- package/reference/source-map.json +8594 -0
- package/scripts/job-input.ts +190 -0
- package/scripts/run-job.mjs +121 -0
- package/skills/architect/SKILL.md +16 -0
- package/skills/arena/SKILL.md +16 -0
- package/skills/automate-me/SKILL.md +10 -0
- package/skills/benchmark-checklist/SKILL.md +10 -0
- package/skills/blast-radius/SKILL.md +10 -0
- package/skills/bro/SKILL.md +10 -0
- package/skills/check-compiler-errors/SKILL.md +10 -0
- package/skills/control-cli/SKILL.md +10 -0
- package/skills/control-ui/SKILL.md +10 -0
- package/skills/correct/SKILL.md +10 -0
- package/skills/create-formal-verification-skill/SKILL.md +16 -0
- package/skills/create-verification-skill/SKILL.md +16 -0
- package/skills/deslop/SKILL.md +10 -0
- package/skills/figure-it-out/SKILL.md +17 -0
- package/skills/fix-ci/SKILL.md +10 -0
- package/skills/fix-merge-conflicts/SKILL.md +10 -0
- package/skills/get-pr-comments/SKILL.md +10 -0
- package/skills/how/SKILL.md +10 -0
- package/skills/in-your-own-words/SKILL.md +11 -0
- package/skills/interrogate/SKILL.md +17 -0
- package/skills/ketchup/SKILL.md +10 -0
- package/skills/ketchup-video/SKILL.md +10 -0
- package/skills/loop-on-ci/SKILL.md +10 -0
- package/skills/maintain-formal-verification-skill/SKILL.md +16 -0
- package/skills/maintain-verification-skill/SKILL.md +16 -0
- package/skills/make-bot-ui/SKILL.md +10 -0
- package/skills/make-pr-easy-to-review/SKILL.md +10 -0
- package/skills/new-branch-and-pr/SKILL.md +10 -0
- package/skills/no-comments/SKILL.md +16 -0
- package/skills/poteto-help/SKILL.md +11 -0
- package/skills/poteto-mode/SKILL.md +60 -0
- package/skills/poteto-mode/playbooks/authoring-a-skill.md +20 -0
- package/skills/poteto-mode/playbooks/autonomous-run.md +20 -0
- package/skills/poteto-mode/playbooks/autopilot-full.md +25 -0
- package/skills/poteto-mode/playbooks/autopilot-stack.md +20 -0
- package/skills/poteto-mode/playbooks/babysit.md +21 -0
- package/skills/poteto-mode/playbooks/bug-fix.md +26 -0
- package/skills/poteto-mode/playbooks/eval.md +20 -0
- package/skills/poteto-mode/playbooks/feature.md +26 -0
- package/skills/poteto-mode/playbooks/hillclimb.md +24 -0
- package/skills/poteto-mode/playbooks/investigation.md +19 -0
- package/skills/poteto-mode/playbooks/multi-phase-plan.md +19 -0
- package/skills/poteto-mode/playbooks/opening-a-pr.md +20 -0
- package/skills/poteto-mode/playbooks/pause-safely.md +18 -0
- package/skills/poteto-mode/playbooks/perf-issue.md +24 -0
- package/skills/poteto-mode/playbooks/prototype.md +21 -0
- package/skills/poteto-mode/playbooks/refactoring.md +23 -0
- package/skills/poteto-mode/playbooks/runtime-forensics.md +20 -0
- package/skills/poteto-mode/playbooks/session-pickup.md +20 -0
- package/skills/poteto-mode/playbooks/shipping.md +24 -0
- package/skills/poteto-mode/playbooks/trace-forensics.md +20 -0
- package/skills/poteto-mode/playbooks/visual-parity.md +22 -0
- package/skills/poteto-mode/playbooks/worktree-cleanup.md +19 -0
- package/skills/pr-review-canvas/SKILL.md +10 -0
- package/skills/principle-attack-the-premise/SKILL.md +12 -0
- package/skills/principle-boundary-discipline/SKILL.md +12 -0
- package/skills/principle-build-the-lever/SKILL.md +12 -0
- package/skills/principle-encode-lessons-in-structure/SKILL.md +12 -0
- package/skills/principle-exhaust-the-design-space/SKILL.md +12 -0
- package/skills/principle-experience-first/SKILL.md +12 -0
- package/skills/principle-explain-the-number/SKILL.md +12 -0
- package/skills/principle-fix-root-causes/SKILL.md +12 -0
- package/skills/principle-foundational-thinking/SKILL.md +12 -0
- package/skills/principle-guard-the-context-window/SKILL.md +12 -0
- package/skills/principle-laziness-protocol/SKILL.md +12 -0
- package/skills/principle-make-operations-idempotent/SKILL.md +12 -0
- package/skills/principle-migrate-callers-then-delete-legacy-apis/SKILL.md +12 -0
- package/skills/principle-minimize-reader-load/SKILL.md +12 -0
- package/skills/principle-model-the-domain/SKILL.md +12 -0
- package/skills/principle-never-block-on-the-human/SKILL.md +12 -0
- package/skills/principle-outcome-oriented-execution/SKILL.md +12 -0
- package/skills/principle-prove-it-works/SKILL.md +12 -0
- package/skills/principle-redesign-from-first-principles/SKILL.md +12 -0
- package/skills/principle-separate-before-serializing-shared-state/SKILL.md +12 -0
- package/skills/principle-sequence-verifiable-units/SKILL.md +12 -0
- package/skills/principle-subtract-before-you-add/SKILL.md +12 -0
- package/skills/principle-test-behavior-not-implementation/SKILL.md +12 -0
- package/skills/principle-type-system-discipline/SKILL.md +12 -0
- package/skills/recall/SKILL.md +10 -0
- package/skills/reflect/SKILL.md +10 -0
- package/skills/review-and-ship/SKILL.md +10 -0
- package/skills/run-smoke-tests/SKILL.md +10 -0
- package/skills/setup-pstack/SKILL.md +17 -0
- package/skills/sharpen/SKILL.md +11 -0
- package/skills/show-me-your-work/SKILL.md +16 -0
- package/skills/statechart/SKILL.md +10 -0
- package/skills/swarm/SKILL.md +16 -0
- package/skills/tdd/SKILL.md +10 -0
- package/skills/teach/SKILL.md +17 -0
- package/skills/technical-writing/SKILL.md +10 -0
- package/skills/thermo-nuclear-code-quality-review/SKILL.md +10 -0
- package/skills/typescript-best-practices/SKILL.md +10 -0
- package/skills/unslop/SKILL.md +10 -0
- package/skills/verify-this/SKILL.md +17 -0
- package/skills/weekly-review/SKILL.md +10 -0
- package/skills/what-did-i-get-done/SKILL.md +10 -0
- package/skills/why/SKILL.md +10 -0
- package/skills/workflow-from-chats/SKILL.md +10 -0
- package/src/catalog-ui.ts +86 -0
- package/src/delegate.ts +367 -0
- package/src/forge.ts +246 -0
- package/src/git.ts +28 -0
- package/src/index.ts +25 -0
- package/src/models.ts +189 -0
- package/src/parent-diff.ts +64 -0
- package/src/plan.ts +181 -0
- package/src/records.ts +85 -0
- package/src/session.ts +124 -0
- package/src/support.ts +47 -0
- package/src/worktrees.ts +188 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
lookup,
|
|
6
|
+
nativeNode,
|
|
7
|
+
nodes,
|
|
8
|
+
routeTriggers,
|
|
9
|
+
slashSkills,
|
|
10
|
+
view,
|
|
11
|
+
views,
|
|
12
|
+
workflowPrompt,
|
|
13
|
+
} from "../lib/catalog.ts";
|
|
14
|
+
import { type Notify, result, stringEnum, text } from "./support.ts";
|
|
15
|
+
|
|
16
|
+
const ownCommands = new Set(["setup-pstack", "poteto-mode"]);
|
|
17
|
+
|
|
18
|
+
async function browse(pi: ExtensionAPI, ctx: ExtensionContext, start: string) {
|
|
19
|
+
let current = start;
|
|
20
|
+
for (;;) {
|
|
21
|
+
const v = view(current);
|
|
22
|
+
const choices = [
|
|
23
|
+
...(v.parent ? [`view:${v.parent} (back)`] : []),
|
|
24
|
+
...v.children.map((c) => `view:${c}`),
|
|
25
|
+
...v.nodes.map((n) => `node:${n.id}`),
|
|
26
|
+
"Exit",
|
|
27
|
+
];
|
|
28
|
+
// oxlint-disable-next-line eslint/no-await-in-loop -- The next screen depends on the user's choice.
|
|
29
|
+
const chosen = await ctx.ui.select(`${v.title}\n${v.caption}`, choices);
|
|
30
|
+
if (!chosen || chosen === "Exit") return;
|
|
31
|
+
if (chosen.startsWith("view:")) {
|
|
32
|
+
current = chosen.slice(5).split(" ")[0] ?? current;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const n = nativeNode(chosen.slice(5));
|
|
36
|
+
const links = n.outgoing.map((e) => `${e.to}: ${e.label} (${e.when})`).join("\n");
|
|
37
|
+
// oxlint-disable-next-line eslint/no-await-in-loop -- Wait for the node action before navigating.
|
|
38
|
+
const action = await ctx.ui.select(
|
|
39
|
+
`${n.id}: ${n.what}\n${n.when}\n${n.implementation}\n${links}`,
|
|
40
|
+
["Back", "Send full details to transcript"],
|
|
41
|
+
);
|
|
42
|
+
if (action === "Send full details to transcript")
|
|
43
|
+
pi.sendMessage({ customType: "pstack-map", content: text(n), display: true });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const sendWorkflow = (pi: ExtensionAPI, id: string, request: string) =>
|
|
48
|
+
pi.sendUserMessage(workflowPrompt(id, request), { deliverAs: "followUp" });
|
|
49
|
+
|
|
50
|
+
export function registerCatalog(pi: ExtensionAPI, notify: Notify) {
|
|
51
|
+
for (const n of slashSkills.filter((skill) => !ownCommands.has(skill.id))) {
|
|
52
|
+
pi.registerCommand(n.label.slice(1), {
|
|
53
|
+
description: n.what,
|
|
54
|
+
handler: async (args) => sendWorkflow(pi, n.id, args.trim()),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
pi.registerCommand("pstack-create-skill", {
|
|
58
|
+
description: "Author a project-local Agent Skill",
|
|
59
|
+
handler: async (args) => sendWorkflow(pi, "pb-authoring-a-skill", args),
|
|
60
|
+
});
|
|
61
|
+
pi.registerCommand("pstack-map", {
|
|
62
|
+
description: "Browse all source map nodes, relationships and views",
|
|
63
|
+
handler: async (args, ctx) => {
|
|
64
|
+
const id = args.trim() || "root";
|
|
65
|
+
if (!views.has(id)) return notify(ctx, text(nodes.has(id) ? nativeNode(id) : lookup(id)));
|
|
66
|
+
if (!ctx.hasUI) return notify(ctx, text(view(id)));
|
|
67
|
+
await browse(pi, ctx, id);
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
pi.registerTool({
|
|
71
|
+
name: "pstack_catalog",
|
|
72
|
+
label: "Pstack catalog",
|
|
73
|
+
description:
|
|
74
|
+
"Read a skill/playbook or native implementation mapping, search the map, list routes, or inspect a view. Conditional edges are not a call sequence.",
|
|
75
|
+
parameters: Type.Object({
|
|
76
|
+
action: stringEnum(["node", "routes", "view", "search"]),
|
|
77
|
+
id: Type.Optional(Type.String()),
|
|
78
|
+
}),
|
|
79
|
+
async execute(_id, p) {
|
|
80
|
+
if (p.action === "routes") return result(routeTriggers());
|
|
81
|
+
if (p.action === "search") return result(lookup(p.id ?? ""));
|
|
82
|
+
if (p.action === "view") return result(view(p.id ?? "root"));
|
|
83
|
+
return result(nativeNode(p.id ?? ""));
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
}
|
package/src/delegate.ts
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { mkdir, readdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
import { type Static, Type } from "typebox";
|
|
7
|
+
|
|
8
|
+
import { root } from "../lib/catalog.ts";
|
|
9
|
+
import {
|
|
10
|
+
type Budget,
|
|
11
|
+
crossJudge,
|
|
12
|
+
type Effort,
|
|
13
|
+
effort,
|
|
14
|
+
isRole,
|
|
15
|
+
judgeRole,
|
|
16
|
+
modelFor,
|
|
17
|
+
type Role,
|
|
18
|
+
type RoleConfig,
|
|
19
|
+
selectPanel,
|
|
20
|
+
} from "../lib/models.ts";
|
|
21
|
+
import { pool, type PoolResult } from "../lib/pool.ts";
|
|
22
|
+
import { blindTranscript, readPaths } from "../lib/transcript.ts";
|
|
23
|
+
import { errorMessage } from "../lib/validation.ts";
|
|
24
|
+
import { gitIn } from "./git.ts";
|
|
25
|
+
import {
|
|
26
|
+
availableWorkerModels,
|
|
27
|
+
modelName,
|
|
28
|
+
readConfig,
|
|
29
|
+
workerExtensions,
|
|
30
|
+
workerIsolation,
|
|
31
|
+
} from "./models.ts";
|
|
32
|
+
import { type ParentDiff, saveParentDiff } from "./parent-diff.ts";
|
|
33
|
+
import { artifacts, fail, piBin, result, stringEnum } from "./support.ts";
|
|
34
|
+
import { createWorktree } from "./worktrees.ts";
|
|
35
|
+
|
|
36
|
+
const modes = ["single", "swarm", "arena", "interrogate"] as const;
|
|
37
|
+
type Mode = (typeof modes)[number];
|
|
38
|
+
|
|
39
|
+
interface WorkerRole {
|
|
40
|
+
alwaysReadOnly: boolean;
|
|
41
|
+
modelRole: Role;
|
|
42
|
+
contract?: string;
|
|
43
|
+
}
|
|
44
|
+
const reviewer = (contract: string): WorkerRole => ({
|
|
45
|
+
alwaysReadOnly: true,
|
|
46
|
+
modelRole: "judgment and prose",
|
|
47
|
+
contract,
|
|
48
|
+
});
|
|
49
|
+
export const workerRoles = new Map<string, WorkerRole>([
|
|
50
|
+
[
|
|
51
|
+
"poteto-agent",
|
|
52
|
+
{ alwaysReadOnly: false, modelRole: "feature, refactoring", contract: "poteto-agent.md" },
|
|
53
|
+
],
|
|
54
|
+
["comment-sicko", reviewer("comment-sicko.md")],
|
|
55
|
+
["ci-watcher", reviewer("ci-watcher.md")],
|
|
56
|
+
["quality-agent", reviewer("quality-agent.md")],
|
|
57
|
+
["general-purpose", { alwaysReadOnly: false, modelRole: "judgment and prose" }],
|
|
58
|
+
]);
|
|
59
|
+
const panelModelRoles: Partial<Record<Mode, Role>> = {
|
|
60
|
+
arena: "arena runners",
|
|
61
|
+
interrogate: "interrogate reviewers",
|
|
62
|
+
swarm: "swarm workers",
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const parameters = Type.Object({
|
|
66
|
+
mode: stringEnum(modes),
|
|
67
|
+
tasks: Type.Array(Type.String({ minLength: 1 }), { minItems: 1, maxItems: 8 }),
|
|
68
|
+
role: Type.Optional(Type.String()),
|
|
69
|
+
modelRole: Type.Optional(Type.String()),
|
|
70
|
+
readOnly: Type.Optional(Type.Boolean()),
|
|
71
|
+
rubric: Type.Optional(Type.String()),
|
|
72
|
+
base: Type.Optional(Type.String()),
|
|
73
|
+
concurrency: Type.Optional(Type.Integer({ minimum: 1, maximum: 8 })),
|
|
74
|
+
});
|
|
75
|
+
type DelegateParams = Static<typeof parameters>;
|
|
76
|
+
|
|
77
|
+
function resolveWorkers(
|
|
78
|
+
p: DelegateParams,
|
|
79
|
+
config: RoleConfig,
|
|
80
|
+
parent: string,
|
|
81
|
+
available: ReadonlySet<string>,
|
|
82
|
+
) {
|
|
83
|
+
const role = p.role ?? (p.mode === "single" ? "poteto-agent" : "general-purpose");
|
|
84
|
+
const worker = workerRoles.get(role);
|
|
85
|
+
if (!worker) fail("Unknown worker role");
|
|
86
|
+
const modelRole = p.modelRole ?? panelModelRoles[p.mode] ?? worker.modelRole;
|
|
87
|
+
if (!isRole(modelRole)) fail("Unknown model role");
|
|
88
|
+
const readOnly = worker.alwaysReadOnly || p.mode === "interrogate" || p.readOnly !== false;
|
|
89
|
+
if (p.mode !== "swarm" && p.tasks.length !== 1)
|
|
90
|
+
fail("Single, arena and interrogate require one shared task");
|
|
91
|
+
if (p.mode === "arena" && !p.rubric?.trim()) fail("Arena requires a common evaluation rubric");
|
|
92
|
+
const choices = config.roles[modelRole];
|
|
93
|
+
const panel = p.mode === "arena" || p.mode === "interrogate";
|
|
94
|
+
if (panel && choices.length < 2) fail("Configure at least two panel seats in /setup-pstack");
|
|
95
|
+
const tasks = panel ? choices.flatMap(() => p.tasks) : p.tasks;
|
|
96
|
+
const models = selectPanel(config, modelRole, tasks.length).map((m) => modelFor(m, parent));
|
|
97
|
+
assertReachable(available, models);
|
|
98
|
+
const judge = p.mode === "arena" ? crossJudge(config, parent, models, available) : undefined;
|
|
99
|
+
if (p.mode === "arena" && !judge)
|
|
100
|
+
fail(
|
|
101
|
+
`Configure an available judge from another provider than the parent and all candidates in /setup-pstack. Configured pool: ${config.roles[judgeRole].join(", ") || "(empty)"}.`,
|
|
102
|
+
);
|
|
103
|
+
const workers = tasks.flatMap((task, i) =>
|
|
104
|
+
models.slice(i, i + 1).map((model) => ({ task, model })),
|
|
105
|
+
);
|
|
106
|
+
return { role, modelRole, readOnly, workers, judge };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function workerArgs(options: {
|
|
110
|
+
model: string;
|
|
111
|
+
thinking: Effort;
|
|
112
|
+
readOnly: boolean;
|
|
113
|
+
extension?: string | undefined;
|
|
114
|
+
sessionDir: string;
|
|
115
|
+
sessionId: string;
|
|
116
|
+
prompt: string;
|
|
117
|
+
}) {
|
|
118
|
+
return [
|
|
119
|
+
"--print",
|
|
120
|
+
...workerIsolation,
|
|
121
|
+
...(options.extension ? ["-e", options.extension] : []),
|
|
122
|
+
"--tools",
|
|
123
|
+
options.readOnly ? "read,grep,find,ls" : "read,grep,find,ls,bash,edit,write",
|
|
124
|
+
"--session-dir",
|
|
125
|
+
options.sessionDir,
|
|
126
|
+
"--session-id",
|
|
127
|
+
options.sessionId,
|
|
128
|
+
"--model",
|
|
129
|
+
options.model,
|
|
130
|
+
"--thinking",
|
|
131
|
+
options.thinking,
|
|
132
|
+
"--",
|
|
133
|
+
options.prompt,
|
|
134
|
+
];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
interface WorkerRequest {
|
|
138
|
+
task: string;
|
|
139
|
+
model: string;
|
|
140
|
+
index: number;
|
|
141
|
+
readOnly: boolean;
|
|
142
|
+
role: string;
|
|
143
|
+
modelRole: Role;
|
|
144
|
+
}
|
|
145
|
+
interface RunnerOptions {
|
|
146
|
+
dir: string;
|
|
147
|
+
budget: Budget;
|
|
148
|
+
extensions: ReadonlyMap<string, string>;
|
|
149
|
+
rubric: string | undefined;
|
|
150
|
+
base: string | undefined;
|
|
151
|
+
diff: ParentDiff | undefined;
|
|
152
|
+
signal: AbortSignal | undefined;
|
|
153
|
+
progress: (message: string) => void;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function diffNotes(diff: ParentDiff | undefined) {
|
|
157
|
+
if (!diff)
|
|
158
|
+
return [
|
|
159
|
+
"Parent diff artifact unavailable; uncommitted parent changes are not described anywhere.",
|
|
160
|
+
];
|
|
161
|
+
const more = diff.omitted.length > 50 ? ` and ${diff.omitted.length - 50} more` : "";
|
|
162
|
+
return [
|
|
163
|
+
`Parent diff artifact (tracked changes and untracked files): ${diff.path}. Write worktrees start at the selected committed base and do not include uncommitted changes.`,
|
|
164
|
+
diff.omitted.length &&
|
|
165
|
+
`Untracked files omitted from the artifact (too large, too many or unreadable): ${diff.omitted.slice(0, 50).join(", ")}${more}.`,
|
|
166
|
+
];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function workerPrompt(request: WorkerRequest, options: RunnerOptions) {
|
|
170
|
+
const kickoffPath = join(root, "agents", "worker.md");
|
|
171
|
+
const contract = workerRoles.get(request.role)?.contract;
|
|
172
|
+
return [
|
|
173
|
+
`Read ${kickoffPath} before anything else.`,
|
|
174
|
+
await readFile(kickoffPath, "utf8"),
|
|
175
|
+
contract
|
|
176
|
+
? await readFile(join(root, "agents", contract), "utf8")
|
|
177
|
+
: "Independent scoped worker.",
|
|
178
|
+
request.role === "poteto-agent" &&
|
|
179
|
+
(await readFile(join(root, "skills", "poteto-mode", "SKILL.md"), "utf8")),
|
|
180
|
+
`Assigned task: ${request.task}`,
|
|
181
|
+
options.rubric && `Finish predicate / rubric: ${options.rubric}`,
|
|
182
|
+
...diffNotes(options.diff),
|
|
183
|
+
"Return evidence and artifact paths; do not perform external side effects.",
|
|
184
|
+
]
|
|
185
|
+
.filter(Boolean)
|
|
186
|
+
.join("\n");
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function createRunner(
|
|
190
|
+
pi: ExtensionAPI,
|
|
191
|
+
ctx: ExtensionContext,
|
|
192
|
+
active: Set<string>,
|
|
193
|
+
options: RunnerOptions,
|
|
194
|
+
) {
|
|
195
|
+
return async (request: WorkerRequest) => {
|
|
196
|
+
const { dir, signal } = options;
|
|
197
|
+
if (signal?.aborted) fail("Cancelled");
|
|
198
|
+
const { index, readOnly, model, modelRole } = request;
|
|
199
|
+
const id = `worker-${index + 1}-${randomUUID().slice(0, 8)}`;
|
|
200
|
+
const tree = readOnly
|
|
201
|
+
? { path: ctx.cwd, base: null }
|
|
202
|
+
: await createWorktree(gitIn(pi, ctx.cwd, signal), ctx, id, options.base);
|
|
203
|
+
if (!readOnly) active.add(tree.path);
|
|
204
|
+
try {
|
|
205
|
+
const sessionDir = join(dir, id);
|
|
206
|
+
await mkdir(sessionDir, { mode: 0o700 });
|
|
207
|
+
const args = workerArgs({
|
|
208
|
+
model,
|
|
209
|
+
thinking: effort(modelRole, options.budget, model),
|
|
210
|
+
readOnly,
|
|
211
|
+
extension: options.extensions.get(model),
|
|
212
|
+
sessionDir,
|
|
213
|
+
sessionId: id,
|
|
214
|
+
prompt: await workerPrompt(request, options),
|
|
215
|
+
});
|
|
216
|
+
options.progress(`Running ${id}`);
|
|
217
|
+
const run = await pi.exec(piBin, args, {
|
|
218
|
+
cwd: tree.path,
|
|
219
|
+
timeout: 30 * 60 * 1000,
|
|
220
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
221
|
+
...(signal && { signal }),
|
|
222
|
+
});
|
|
223
|
+
const report = join(dir, `${id}.txt`);
|
|
224
|
+
await Promise.all([
|
|
225
|
+
writeFile(report, run.stdout, { mode: 0o600 }),
|
|
226
|
+
writeFile(join(dir, `${id}.stderr.txt`), run.stderr, { mode: 0o600 }),
|
|
227
|
+
]);
|
|
228
|
+
if (run.code !== 0 || run.truncated || run.killed)
|
|
229
|
+
fail(`Worker ${id} failed (${run.code}); inspect ${report}`);
|
|
230
|
+
const sessions = (await readdir(sessionDir, { recursive: true })).filter((path) =>
|
|
231
|
+
path.endsWith(".jsonl"),
|
|
232
|
+
);
|
|
233
|
+
const [session, ...others] = sessions;
|
|
234
|
+
const transcript = session !== undefined && !others.length ? join(sessionDir, session) : null;
|
|
235
|
+
return {
|
|
236
|
+
id,
|
|
237
|
+
model,
|
|
238
|
+
...tree,
|
|
239
|
+
report,
|
|
240
|
+
transcript,
|
|
241
|
+
sessionDir,
|
|
242
|
+
summary: run.stdout.slice(-6000),
|
|
243
|
+
};
|
|
244
|
+
} finally {
|
|
245
|
+
if (!readOnly) active.delete(tree.path);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
type RunWorker = ReturnType<typeof createRunner>;
|
|
251
|
+
type WorkerReport = Awaited<ReturnType<RunWorker>>;
|
|
252
|
+
async function judgeArena(
|
|
253
|
+
dir: string,
|
|
254
|
+
outputs: PoolResult<WorkerReport>[],
|
|
255
|
+
rubric: string | undefined,
|
|
256
|
+
judge: string,
|
|
257
|
+
run: RunWorker,
|
|
258
|
+
) {
|
|
259
|
+
if (!outputs.every((entry) => entry.status === "fulfilled"))
|
|
260
|
+
return { status: "INCONCLUSIVE: a candidate failed" };
|
|
261
|
+
const candidates = outputs.map((entry) => entry.value);
|
|
262
|
+
const blindDir = join(dir, "blinded");
|
|
263
|
+
await mkdir(blindDir, { mode: 0o700 });
|
|
264
|
+
const files = await Promise.all(
|
|
265
|
+
candidates.map(async ({ model, transcript }, i) => {
|
|
266
|
+
if (!transcript) return null;
|
|
267
|
+
const projection = blindTranscript(await readFile(transcript, "utf8"), model);
|
|
268
|
+
if (!projection.trim()) return null;
|
|
269
|
+
const path = join(blindDir, `candidate-${i + 1}.jsonl`);
|
|
270
|
+
await writeFile(path, projection, { mode: 0o600 });
|
|
271
|
+
return path;
|
|
272
|
+
}),
|
|
273
|
+
);
|
|
274
|
+
if (!files.every((path) => path !== null))
|
|
275
|
+
return { status: "INCONCLUSIVE: missing or empty candidate transcript" };
|
|
276
|
+
const worktrees = candidates
|
|
277
|
+
.map((candidate, i) => `Candidate ${i + 1}: ${candidate.path}`)
|
|
278
|
+
.join("; ");
|
|
279
|
+
const assessment = await run({
|
|
280
|
+
task: `Judge these ${files.length} anonymous candidate message transcripts: ${files.join(", ")}. Read every file in full, including tool results; rubric: ${rubric}. Rank by actual evidence; note missing artifacts or unverifiable claims. For write candidates, inspect candidate worktrees if necessary: ${worktrees}. Do not infer provider identity.`,
|
|
281
|
+
model: judge,
|
|
282
|
+
index: candidates.length,
|
|
283
|
+
readOnly: true,
|
|
284
|
+
role: "general-purpose",
|
|
285
|
+
modelRole: judgeRole,
|
|
286
|
+
});
|
|
287
|
+
const reads = new Set(
|
|
288
|
+
assessment.transcript ? readPaths(await readFile(assessment.transcript, "utf8")) : [],
|
|
289
|
+
);
|
|
290
|
+
const readAudit = files.map((path) => ({ path, read: reads.has(path) }));
|
|
291
|
+
return {
|
|
292
|
+
...assessment,
|
|
293
|
+
readAudit,
|
|
294
|
+
status: readAudit.every((entry) => entry.read)
|
|
295
|
+
? "reviewed"
|
|
296
|
+
: "INCONCLUSIVE: judge did not read every projected transcript",
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function assertReachable(available: ReadonlySet<string>, models: string[]) {
|
|
301
|
+
const unreachable = [...new Set(models)].filter((model) => !available.has(model));
|
|
302
|
+
if (unreachable.length)
|
|
303
|
+
fail(
|
|
304
|
+
`Workers load no extension except the one that provides their model. Unavailable in the current worker scope: ${unreachable.join(", ")}. Choose an available model in /setup-pstack.`,
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export function registerDelegation(pi: ExtensionAPI, active: Set<string>) {
|
|
309
|
+
pi.registerTool({
|
|
310
|
+
name: "pstack_delegate",
|
|
311
|
+
label: "Pstack Pi workers",
|
|
312
|
+
description:
|
|
313
|
+
"Run independent native Pi CLI sessions: single, swarm, arena or interrogate. Read-only by default; write workers use detached worktrees. Child sessions and reports are retained.",
|
|
314
|
+
parameters,
|
|
315
|
+
async execute(_id, p, signal, onUpdate, ctx) {
|
|
316
|
+
const config = await readConfig();
|
|
317
|
+
if (!ctx.model) fail("Select a parent model first");
|
|
318
|
+
const parent = modelName(ctx.model);
|
|
319
|
+
const extensions = await workerExtensions(pi, ctx, signal);
|
|
320
|
+
const available = new Set(availableWorkerModels(ctx, extensions));
|
|
321
|
+
const { role, modelRole, readOnly, workers, judge } = resolveWorkers(
|
|
322
|
+
p,
|
|
323
|
+
config,
|
|
324
|
+
parent,
|
|
325
|
+
available,
|
|
326
|
+
);
|
|
327
|
+
if (
|
|
328
|
+
!readOnly &&
|
|
329
|
+
(!ctx.hasUI ||
|
|
330
|
+
!(await ctx.ui.confirm(
|
|
331
|
+
"Authorize isolated write workers?",
|
|
332
|
+
`${workers.length} worker(s), detached worktrees from ${p.base ?? "HEAD"}. Workers can execute shell commands; worktrees are not a security sandbox.`,
|
|
333
|
+
)))
|
|
334
|
+
)
|
|
335
|
+
fail("Write delegation not authorized");
|
|
336
|
+
const dir = join(artifacts(ctx), "workers", randomUUID());
|
|
337
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
338
|
+
const run = createRunner(pi, ctx, active, {
|
|
339
|
+
dir,
|
|
340
|
+
signal,
|
|
341
|
+
diff: await saveParentDiff(pi, ctx.cwd, dir, signal),
|
|
342
|
+
budget: config.budget,
|
|
343
|
+
extensions,
|
|
344
|
+
base: p.base,
|
|
345
|
+
rubric: p.rubric,
|
|
346
|
+
progress: (message) => onUpdate?.(result(message)),
|
|
347
|
+
});
|
|
348
|
+
const outputs = await pool(workers, p.concurrency ?? 3, ({ task, model }, index) =>
|
|
349
|
+
run({ task, index, model, readOnly, role, modelRole }),
|
|
350
|
+
);
|
|
351
|
+
const judgment =
|
|
352
|
+
judge &&
|
|
353
|
+
(await judgeArena(dir, outputs, p.rubric, judge, run).catch((error: unknown) => ({
|
|
354
|
+
status: "INCONCLUSIVE: could not complete arena judgment",
|
|
355
|
+
model: judge,
|
|
356
|
+
error: errorMessage(error),
|
|
357
|
+
})));
|
|
358
|
+
return result({
|
|
359
|
+
outputs,
|
|
360
|
+
judgment,
|
|
361
|
+
dir,
|
|
362
|
+
warning:
|
|
363
|
+
"Local workers only. Review actual artifacts and rerun acceptance checks; report text is not proof.",
|
|
364
|
+
});
|
|
365
|
+
},
|
|
366
|
+
});
|
|
367
|
+
}
|
package/src/forge.ts
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
|
|
4
|
+
import { errorMessage, isRecord, parseJson } from "../lib/validation.ts";
|
|
5
|
+
import { fail, result, text } from "./support.ts";
|
|
6
|
+
|
|
7
|
+
const checksFields =
|
|
8
|
+
"number,url,headRefOid,state,isDraft,mergeable,mergeStateStatus,statusCheckRollup,reviewDecision,baseRefName";
|
|
9
|
+
|
|
10
|
+
export interface Proof {
|
|
11
|
+
number: number;
|
|
12
|
+
head: string;
|
|
13
|
+
evidence: string;
|
|
14
|
+
independent: boolean;
|
|
15
|
+
}
|
|
16
|
+
interface PullRequestStatus {
|
|
17
|
+
number: number;
|
|
18
|
+
url: string;
|
|
19
|
+
headRefOid: string;
|
|
20
|
+
state: string;
|
|
21
|
+
isDraft: boolean;
|
|
22
|
+
mergeable: string;
|
|
23
|
+
mergeStateStatus: string;
|
|
24
|
+
statusCheckRollup: { status?: string; conclusion?: string; state?: string }[] | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const passingConclusions = new Set(["SUCCESS", "NEUTRAL", "SKIPPED"]);
|
|
28
|
+
const checksPass = (pr: PullRequestStatus) =>
|
|
29
|
+
!!pr.statusCheckRollup?.length &&
|
|
30
|
+
pr.statusCheckRollup.every((check) =>
|
|
31
|
+
check.status === "COMPLETED"
|
|
32
|
+
? passingConclusions.has(check.conclusion ?? "")
|
|
33
|
+
: check.state === "SUCCESS",
|
|
34
|
+
);
|
|
35
|
+
const mergeReady = (proof: Proof, pr: PullRequestStatus) =>
|
|
36
|
+
!!proof.evidence.trim() &&
|
|
37
|
+
proof.independent &&
|
|
38
|
+
proof.head === pr.headRefOid &&
|
|
39
|
+
pr.state === "OPEN" &&
|
|
40
|
+
!pr.isDraft &&
|
|
41
|
+
pr.mergeable === "MERGEABLE" &&
|
|
42
|
+
pr.mergeStateStatus === "CLEAN" &&
|
|
43
|
+
checksPass(pr);
|
|
44
|
+
|
|
45
|
+
type Approved = Proof & { url: string };
|
|
46
|
+
|
|
47
|
+
export function verifiedPrefix(proofs: Proof[], statuses: PullRequestStatus[]): Approved[] {
|
|
48
|
+
const byNumber = new Map(statuses.map((status) => [status.number, status]));
|
|
49
|
+
const prefix: Approved[] = [];
|
|
50
|
+
for (const proof of proofs) {
|
|
51
|
+
const pr = byNumber.get(proof.number);
|
|
52
|
+
if (!pr || !mergeReady(proof, pr)) break;
|
|
53
|
+
const { number, head, evidence, independent } = proof;
|
|
54
|
+
prefix.push({ number, head, evidence, independent, url: pr.url });
|
|
55
|
+
}
|
|
56
|
+
return prefix;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function prUrl(value: unknown, number: number): value is string {
|
|
60
|
+
return (
|
|
61
|
+
typeof value === "string" &&
|
|
62
|
+
/^https:\/\/[a-z0-9.:-]+\/[a-z0-9_.-]+\/[a-z0-9_.-]+\/pull\/\d+$/i.test(value) &&
|
|
63
|
+
value.endsWith(`/pull/${number}`)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function isStatus(value: unknown, number: number): value is PullRequestStatus {
|
|
68
|
+
return (
|
|
69
|
+
isRecord(value) &&
|
|
70
|
+
value["number"] === number &&
|
|
71
|
+
prUrl(value["url"], number) &&
|
|
72
|
+
typeof value["headRefOid"] === "string" &&
|
|
73
|
+
/^[0-9a-f]{40}$/i.test(value["headRefOid"]) &&
|
|
74
|
+
typeof value["state"] === "string" &&
|
|
75
|
+
typeof value["isDraft"] === "boolean" &&
|
|
76
|
+
typeof value["mergeable"] === "string" &&
|
|
77
|
+
typeof value["mergeStateStatus"] === "string" &&
|
|
78
|
+
(value["statusCheckRollup"] === null ||
|
|
79
|
+
(Array.isArray(value["statusCheckRollup"]) &&
|
|
80
|
+
value["statusCheckRollup"].every(
|
|
81
|
+
(check: unknown) =>
|
|
82
|
+
isRecord(check) &&
|
|
83
|
+
[check["status"], check["conclusion"], check["state"]].every(
|
|
84
|
+
(field) => field === undefined || typeof field === "string",
|
|
85
|
+
),
|
|
86
|
+
)))
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function fetchPr(
|
|
91
|
+
pi: ExtensionAPI,
|
|
92
|
+
ctx: ExtensionContext,
|
|
93
|
+
id: number | string,
|
|
94
|
+
signal?: AbortSignal,
|
|
95
|
+
) {
|
|
96
|
+
const r = await pi.exec("gh", ["pr", "view", String(id), "--json", checksFields], {
|
|
97
|
+
cwd: ctx.cwd,
|
|
98
|
+
timeout: 30000,
|
|
99
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
100
|
+
...(signal && { signal }),
|
|
101
|
+
});
|
|
102
|
+
if (r.truncated || r.killed) fail("gh pr view failed: output truncated or process stopped");
|
|
103
|
+
if (r.code !== 0) fail(`gh pr view failed: ${r.stderr}`);
|
|
104
|
+
const payload = parseJson(r.stdout, "gh pr response");
|
|
105
|
+
const number = typeof id === "number" ? id : Number(id.split("/").at(-1));
|
|
106
|
+
if (!isStatus(payload, number) || (typeof id === "string" && payload.url !== id)) {
|
|
107
|
+
fail(`Unexpected GitHub PR response for ${id}`);
|
|
108
|
+
}
|
|
109
|
+
return payload;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export const mergeRoutes = ["shipping", "autopilot-full"];
|
|
113
|
+
|
|
114
|
+
async function previewPrefix(
|
|
115
|
+
pi: ExtensionAPI,
|
|
116
|
+
ctx: ExtensionContext,
|
|
117
|
+
proofs: Proof[],
|
|
118
|
+
signal?: AbortSignal,
|
|
119
|
+
) {
|
|
120
|
+
signal?.throwIfAborted();
|
|
121
|
+
const reads = await Promise.allSettled(
|
|
122
|
+
proofs.map((proof) => fetchPr(pi, ctx, proof.number, signal)),
|
|
123
|
+
);
|
|
124
|
+
signal?.throwIfAborted();
|
|
125
|
+
const statuses = reads.flatMap((read) => (read.status === "fulfilled" ? [read.value] : []));
|
|
126
|
+
const prefix = verifiedPrefix(proofs, statuses);
|
|
127
|
+
const next = reads[prefix.length];
|
|
128
|
+
const unread = proofs[prefix.length];
|
|
129
|
+
const lookupFailure =
|
|
130
|
+
unread && next?.status === "rejected"
|
|
131
|
+
? { number: unread.number, error: errorMessage(next.reason) }
|
|
132
|
+
: undefined;
|
|
133
|
+
if (!prefix.length)
|
|
134
|
+
fail(
|
|
135
|
+
lookupFailure
|
|
136
|
+
? `Could not check PR #${lookupFailure.number}: ${lookupFailure.error}`
|
|
137
|
+
: "No verified merge-ready prefix",
|
|
138
|
+
);
|
|
139
|
+
return { prefix, lookupFailure };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function mergePrefix(
|
|
143
|
+
pi: ExtensionAPI,
|
|
144
|
+
ctx: ExtensionContext,
|
|
145
|
+
prefix: Approved[],
|
|
146
|
+
requireActivePlan: () => void,
|
|
147
|
+
signal?: AbortSignal,
|
|
148
|
+
) {
|
|
149
|
+
const merged: { number: number; head: string; url: string }[] = [];
|
|
150
|
+
for (const proof of prefix) {
|
|
151
|
+
const stopped = { merged, stopped: proof.number };
|
|
152
|
+
let fresh;
|
|
153
|
+
try {
|
|
154
|
+
requireActivePlan();
|
|
155
|
+
// oxlint-disable-next-line eslint/no-await-in-loop -- Recheck each approved PR immediately before merging it.
|
|
156
|
+
fresh = await fetchPr(pi, ctx, proof.url, signal);
|
|
157
|
+
requireActivePlan();
|
|
158
|
+
} catch (error) {
|
|
159
|
+
return {
|
|
160
|
+
...stopped,
|
|
161
|
+
reason: "Could not recheck readiness; merge not attempted",
|
|
162
|
+
error: errorMessage(error),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
if (!mergeReady(proof, fresh)) {
|
|
166
|
+
return { ...stopped, reason: "Head or readiness changed" };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const uncertain = {
|
|
170
|
+
...stopped,
|
|
171
|
+
unconfirmed: proof.number,
|
|
172
|
+
reason: "Merge not confirmed; inspect forge state",
|
|
173
|
+
};
|
|
174
|
+
try {
|
|
175
|
+
// oxlint-disable-next-line eslint/no-await-in-loop -- Stack merges must run in order.
|
|
176
|
+
const r = await pi.exec(
|
|
177
|
+
"gh",
|
|
178
|
+
["pr", "merge", proof.url, "--merge", "--match-head-commit", proof.head],
|
|
179
|
+
{ cwd: ctx.cwd, timeout: 60000, maxBuffer: 1024 * 1024, ...(signal && { signal }) },
|
|
180
|
+
);
|
|
181
|
+
if (r.code !== 0 || r.killed || r.truncated) return { ...uncertain, error: r.stderr };
|
|
182
|
+
|
|
183
|
+
// oxlint-disable-next-line eslint/no-await-in-loop -- Confirm the merge before advancing.
|
|
184
|
+
const after = await fetchPr(pi, ctx, proof.url, signal);
|
|
185
|
+
if (after.state !== "MERGED" || after.headRefOid !== proof.head) return uncertain;
|
|
186
|
+
merged.push({ number: proof.number, head: after.headRefOid, url: after.url });
|
|
187
|
+
} catch (error) {
|
|
188
|
+
return { ...uncertain, error: errorMessage(error) };
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return { merged, ceiling: prefix.at(-1)?.number };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function registerForge(pi: ExtensionAPI, currentRoute: () => string | undefined) {
|
|
195
|
+
pi.registerTool({
|
|
196
|
+
name: "pstack_pr",
|
|
197
|
+
label: "Pstack PR state",
|
|
198
|
+
description: "Fetch live GitHub PR head and CI state. Requires configured gh. No writes.",
|
|
199
|
+
parameters: Type.Object({ number: Type.Integer({ minimum: 1 }) }),
|
|
200
|
+
async execute(_id, p, signal, _update, ctx) {
|
|
201
|
+
return result(await fetchPr(pi, ctx, p.number, signal));
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
pi.registerTool({
|
|
205
|
+
name: "pstack_ship",
|
|
206
|
+
label: "Pstack shipping gate",
|
|
207
|
+
description:
|
|
208
|
+
"Merge an explicitly approved contiguous verified GitHub PR prefix bottom-up. Requires independent evidence per head and fresh green checks, then explicit UI confirmation. Never used for autopilot-stack or Benny.",
|
|
209
|
+
executionMode: "sequential",
|
|
210
|
+
parameters: Type.Object({
|
|
211
|
+
proofs: Type.Array(
|
|
212
|
+
Type.Object({
|
|
213
|
+
number: Type.Integer({ minimum: 1 }),
|
|
214
|
+
head: Type.String(),
|
|
215
|
+
evidence: Type.String(),
|
|
216
|
+
independent: Type.Boolean(),
|
|
217
|
+
}),
|
|
218
|
+
{ minItems: 1, maxItems: 25 },
|
|
219
|
+
),
|
|
220
|
+
}),
|
|
221
|
+
async execute(_id, p, signal, _update, ctx) {
|
|
222
|
+
const requireActivePlan = () => {
|
|
223
|
+
if (!ctx.hasUI || !mergeRoutes.includes(currentRoute() ?? ""))
|
|
224
|
+
fail("Merging requires a shipping or autopilot-full plan and interactive approval");
|
|
225
|
+
};
|
|
226
|
+
requireActivePlan();
|
|
227
|
+
if (new Set(p.proofs.map((proof) => proof.number)).size !== p.proofs.length)
|
|
228
|
+
fail("Duplicate PR");
|
|
229
|
+
const { prefix, lookupFailure } = await previewPrefix(pi, ctx, p.proofs, signal);
|
|
230
|
+
requireActivePlan();
|
|
231
|
+
if (!(await ctx.ui.confirm("Merge these exact PR heads bottom-up?", text(prefix))))
|
|
232
|
+
fail("Merge not authorized");
|
|
233
|
+
signal?.throwIfAborted();
|
|
234
|
+
const outcome = await mergePrefix(pi, ctx, prefix, requireActivePlan, signal);
|
|
235
|
+
const unconfirmed = "unconfirmed" in outcome ? outcome.unconfirmed : undefined;
|
|
236
|
+
return result({
|
|
237
|
+
...outcome,
|
|
238
|
+
lookupFailure,
|
|
239
|
+
unmerged: p.proofs
|
|
240
|
+
.slice(outcome.merged.length)
|
|
241
|
+
.map((proof) => proof.number)
|
|
242
|
+
.filter((number) => number !== unconfirmed),
|
|
243
|
+
});
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
}
|