pi-pstack-workflow-kit 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.
- package/LICENSE +21 -0
- package/README.md +122 -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/extensions/catalog-ui.ts +86 -0
- package/extensions/delegate.ts +357 -0
- package/extensions/forge.ts +245 -0
- package/extensions/git.ts +23 -0
- package/extensions/index.ts +25 -0
- package/extensions/models.ts +115 -0
- package/extensions/parent-diff.ts +63 -0
- package/extensions/plan.ts +181 -0
- package/extensions/records.ts +81 -0
- package/extensions/session.ts +124 -0
- package/extensions/support.ts +46 -0
- package/extensions/worktrees.ts +188 -0
- package/lib/catalog-data.json +560 -0
- package/lib/catalog.ts +111 -0
- package/lib/jobs.ts +5 -0
- package/lib/models.ts +124 -0
- package/lib/pool.ts +29 -0
- package/lib/state.ts +127 -0
- package/lib/transcript.ts +44 -0
- package/lib/validation.ts +16 -0
- package/package.json +68 -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 +191 -0
- package/scripts/run-job.mjs +119 -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/lib/catalog.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
export interface NodeRecord {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
kind: string;
|
|
9
|
+
what: string;
|
|
10
|
+
when: string;
|
|
11
|
+
how: string;
|
|
12
|
+
source: string[];
|
|
13
|
+
opensView?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface Edge {
|
|
16
|
+
id: string;
|
|
17
|
+
from: string;
|
|
18
|
+
to: string;
|
|
19
|
+
label: string;
|
|
20
|
+
when: string;
|
|
21
|
+
kind: string;
|
|
22
|
+
}
|
|
23
|
+
interface MapView {
|
|
24
|
+
id: string;
|
|
25
|
+
parent: string | null;
|
|
26
|
+
title: string;
|
|
27
|
+
caption: string;
|
|
28
|
+
nodeIds: string[];
|
|
29
|
+
edges: (string | Edge)[];
|
|
30
|
+
}
|
|
31
|
+
interface SourceMap {
|
|
32
|
+
nodes: NodeRecord[];
|
|
33
|
+
edges: Edge[];
|
|
34
|
+
views: MapView[];
|
|
35
|
+
}
|
|
36
|
+
interface Catalog {
|
|
37
|
+
paths: Record<string, string>;
|
|
38
|
+
steps: Record<string, string[]>;
|
|
39
|
+
implementations: Record<string, [classification: string, implementation: string]>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const root = fileURLToPath(new URL("../", import.meta.url));
|
|
43
|
+
export const packageFile = (path: string) => readFileSync(join(root, path), "utf8");
|
|
44
|
+
export const map: SourceMap = JSON.parse(packageFile("reference/source-map.json"));
|
|
45
|
+
export const catalog: Catalog = JSON.parse(packageFile("lib/catalog-data.json"));
|
|
46
|
+
export const nodes = new Map(map.nodes.map((n) => [n.id, n]));
|
|
47
|
+
export const views = new Map(map.views.map((v) => [v.id, v]));
|
|
48
|
+
const edges = new Map(map.edges.map((e) => [e.id, e]));
|
|
49
|
+
const outgoing = Map.groupBy(map.edges, (e) => e.from);
|
|
50
|
+
const incoming = Map.groupBy(map.edges, (e) => e.to);
|
|
51
|
+
export const routes = Object.keys(catalog.steps);
|
|
52
|
+
export const slashSkills = map.nodes.filter(
|
|
53
|
+
(n) =>
|
|
54
|
+
(n.kind === "public" || (n.id.startsWith("kit-") && n.label.startsWith("/"))) &&
|
|
55
|
+
!n.id.startsWith("principle-"),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
function known(id: string) {
|
|
59
|
+
const n = nodes.get(id);
|
|
60
|
+
if (!n) throw Error(`Unknown node: ${id}`);
|
|
61
|
+
return n;
|
|
62
|
+
}
|
|
63
|
+
export const routeTriggers = () => routes.map((id) => ({ id, when: known("pb-" + id).when }));
|
|
64
|
+
|
|
65
|
+
export function nativeNode(id: string) {
|
|
66
|
+
const n = known(id);
|
|
67
|
+
const [classification, implementation] = catalog.implementations[id];
|
|
68
|
+
const path = catalog.paths[id];
|
|
69
|
+
return {
|
|
70
|
+
id,
|
|
71
|
+
label: n.label,
|
|
72
|
+
kind: n.kind,
|
|
73
|
+
what: n.what,
|
|
74
|
+
when: n.when,
|
|
75
|
+
classification,
|
|
76
|
+
implementation,
|
|
77
|
+
sources: n.source,
|
|
78
|
+
instructions: path ? packageFile(path) : undefined,
|
|
79
|
+
outgoing: outgoing.get(id) ?? [],
|
|
80
|
+
incoming: incoming.get(id) ?? [],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export function workflowPrompt(id: string, request: string) {
|
|
84
|
+
const node = nativeNode(id);
|
|
85
|
+
return `Execute the Pi-native workflow ${id} for the operator's request.\n\n${node.instructions ?? node.implementation}\n\nOperator request:\n${request || "(Use the current conversation context.)"}`;
|
|
86
|
+
}
|
|
87
|
+
export function view(id: string) {
|
|
88
|
+
const v = views.get(id);
|
|
89
|
+
if (!v) throw Error(`Unknown view: ${id}`);
|
|
90
|
+
return {
|
|
91
|
+
id,
|
|
92
|
+
parent: v.parent,
|
|
93
|
+
title: v.title,
|
|
94
|
+
caption: v.caption,
|
|
95
|
+
children: map.views.filter((x) => x.parent === id).map((x) => x.id),
|
|
96
|
+
nodes: v.nodeIds.map((n) => ({
|
|
97
|
+
id: n,
|
|
98
|
+
label: known(n).label,
|
|
99
|
+
implementation: catalog.implementations[n][1],
|
|
100
|
+
})),
|
|
101
|
+
edges: v.edges.map((e) => edges.get(typeof e === "string" ? e : e.id)),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export function lookup(query: string) {
|
|
105
|
+
const words = query.toLowerCase().trim().split(/\s+/).filter(Boolean);
|
|
106
|
+
return map.nodes
|
|
107
|
+
.filter((n) =>
|
|
108
|
+
words.every((w) => `${n.id} ${n.label} ${n.what} ${n.when}`.toLowerCase().includes(w)),
|
|
109
|
+
)
|
|
110
|
+
.map((n) => ({ id: n.id, kind: n.kind, when: n.when }));
|
|
111
|
+
}
|
package/lib/jobs.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const jobKinds = ["custom", "benny-triage", "benny-repro"] as const;
|
|
2
|
+
export type JobKind = (typeof jobKinds)[number];
|
|
3
|
+
export type BennyKind = Exclude<JobKind, "custom">;
|
|
4
|
+
export const isJobKind = (value: unknown): value is JobKind =>
|
|
5
|
+
jobKinds.some((kind) => kind === value);
|
package/lib/models.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { isRecord } from "./validation.ts";
|
|
2
|
+
|
|
3
|
+
export const aliases = ["auto", "inherit-parent"];
|
|
4
|
+
|
|
5
|
+
export const roles = [
|
|
6
|
+
"feature, refactoring",
|
|
7
|
+
"bug-fix",
|
|
8
|
+
"perf-issue",
|
|
9
|
+
"hillclimb",
|
|
10
|
+
"judgment and prose",
|
|
11
|
+
"arena runners",
|
|
12
|
+
"arena cross-judge pool",
|
|
13
|
+
"swarm workers",
|
|
14
|
+
"interrogate reviewers",
|
|
15
|
+
] as const;
|
|
16
|
+
export type Role = (typeof roles)[number];
|
|
17
|
+
export const isRole = (value: string): value is Role => roles.some((role) => role === value);
|
|
18
|
+
export const panelRoles: ReadonlySet<Role> = new Set([
|
|
19
|
+
"arena runners",
|
|
20
|
+
"arena cross-judge pool",
|
|
21
|
+
"interrogate reviewers",
|
|
22
|
+
]);
|
|
23
|
+
export const judgeRole = "arena cross-judge pool" satisfies Role;
|
|
24
|
+
|
|
25
|
+
export const budgets = ["large", "medium", "small"] as const;
|
|
26
|
+
export type Budget = (typeof budgets)[number];
|
|
27
|
+
const isBudget = (value: unknown): value is Budget => budgets.some((budget) => budget === value);
|
|
28
|
+
|
|
29
|
+
const levels = ["low", "medium", "high", "xhigh"] as const;
|
|
30
|
+
export type Effort = (typeof levels)[number];
|
|
31
|
+
|
|
32
|
+
export interface RoleConfig {
|
|
33
|
+
defaults: 3;
|
|
34
|
+
budget: Budget;
|
|
35
|
+
roles: Record<Role, string[]>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const baseEffort = (role: Role): Effort =>
|
|
39
|
+
panelRoles.has(role) || role === "swarm workers" ? "high" : "xhigh";
|
|
40
|
+
export function effort(role: Role, budget: Budget, model = ""): Effort {
|
|
41
|
+
const target = panelRoles.has(role) && /gemini/i.test(model) ? "xhigh" : baseEffort(role);
|
|
42
|
+
return levels[Math.max(0, levels.indexOf(target) - budgets.indexOf(budget))];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function assertSelections(
|
|
46
|
+
selections: Record<string, unknown>,
|
|
47
|
+
): asserts selections is Record<Role, string[]> {
|
|
48
|
+
if (Object.keys(selections).length !== roles.length) throw Error("Invalid model configuration");
|
|
49
|
+
for (const r of roles) {
|
|
50
|
+
const values = selections[r];
|
|
51
|
+
if (
|
|
52
|
+
!Array.isArray(values) ||
|
|
53
|
+
(!panelRoles.has(r) && values.length !== 1) ||
|
|
54
|
+
(r !== judgeRole && values.length === 0) ||
|
|
55
|
+
values.length > 8 ||
|
|
56
|
+
values.some((v) => typeof v !== "string" || !v.trim())
|
|
57
|
+
)
|
|
58
|
+
throw Error(`Invalid selection for ${r}`);
|
|
59
|
+
if (r === judgeRole && values.some((v) => aliases.includes(v)))
|
|
60
|
+
throw Error("Judge pool requires explicit models");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function parseModelConfig(config: unknown): RoleConfig {
|
|
65
|
+
if (
|
|
66
|
+
!isRecord(config) ||
|
|
67
|
+
config.defaults !== 3 ||
|
|
68
|
+
!isBudget(config.budget) ||
|
|
69
|
+
!isRecord(config.roles)
|
|
70
|
+
)
|
|
71
|
+
throw Error("Invalid model configuration");
|
|
72
|
+
assertSelections(config.roles);
|
|
73
|
+
return { defaults: config.defaults, budget: config.budget, roles: config.roles };
|
|
74
|
+
}
|
|
75
|
+
export function defaultConfig(): RoleConfig {
|
|
76
|
+
return parseModelConfig({
|
|
77
|
+
defaults: 3,
|
|
78
|
+
budget: "large",
|
|
79
|
+
roles: Object.fromEntries(roles.map((r) => [r, r === judgeRole ? [] : ["inherit-parent"]])),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
export function applyConfigPatch(config: RoleConfig, patch: unknown): RoleConfig {
|
|
83
|
+
const selections = isRecord(patch) && "roles" in patch ? patch.roles : {};
|
|
84
|
+
if (!isRecord(patch) || !isRecord(selections)) throw Error("Invalid model configuration patch");
|
|
85
|
+
return parseModelConfig({ ...config, ...patch, roles: { ...config.roles, ...selections } });
|
|
86
|
+
}
|
|
87
|
+
export function validateConfig(input: unknown, available: readonly string[]): RoleConfig {
|
|
88
|
+
const config = parseModelConfig(input);
|
|
89
|
+
const allowed = new Set([...aliases, ...available]);
|
|
90
|
+
for (const r of roles) {
|
|
91
|
+
if (config.roles[r].some((v) => !allowed.has(v))) throw Error(`Unavailable model for ${r}`);
|
|
92
|
+
}
|
|
93
|
+
return config;
|
|
94
|
+
}
|
|
95
|
+
export function modelFor(value: string, parent: string) {
|
|
96
|
+
if (!aliases.includes(value)) return value;
|
|
97
|
+
if (!parent) throw Error("No parent model selected");
|
|
98
|
+
return parent;
|
|
99
|
+
}
|
|
100
|
+
export function vendor(model: string) {
|
|
101
|
+
const [provider, ...rest] = model.toLowerCase().split("/");
|
|
102
|
+
const id = rest.join("/");
|
|
103
|
+
if (/(^|[/.-])claude|anthropic/.test(id)) return "anthropic";
|
|
104
|
+
if (/(^|[/.-])gemini|google/.test(id)) return "google";
|
|
105
|
+
if (/(^|[/.-])(gpt|o[1-9]|codex)([/.-]|$)|openai/.test(id)) return "openai";
|
|
106
|
+
if (/(^|[/.-])grok|xai/.test(id)) return "xai";
|
|
107
|
+
return provider;
|
|
108
|
+
}
|
|
109
|
+
export function crossJudge(
|
|
110
|
+
config: RoleConfig,
|
|
111
|
+
parent: string,
|
|
112
|
+
candidates: readonly string[],
|
|
113
|
+
available: ReadonlySet<string>,
|
|
114
|
+
) {
|
|
115
|
+
const excluded = new Set([parent, ...candidates].map(vendor));
|
|
116
|
+
return config.roles[judgeRole].find((m) => available.has(m) && !excluded.has(vendor(m)));
|
|
117
|
+
}
|
|
118
|
+
export function selectPanel(config: RoleConfig, role: Role, count: number) {
|
|
119
|
+
if (!Number.isInteger(count) || count < 1 || count > 8)
|
|
120
|
+
throw Error("Worker count must be 1 to 8");
|
|
121
|
+
const choices = config.roles[role];
|
|
122
|
+
if (!choices.length) throw Error(`No models configured for ${role}`);
|
|
123
|
+
return Array.from({ length: count }, (_, i) => choices[i % choices.length]);
|
|
124
|
+
}
|
package/lib/pool.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { errorMessage } from "./validation.ts";
|
|
2
|
+
|
|
3
|
+
export type PoolResult<T> =
|
|
4
|
+
| { status: "fulfilled"; value: T }
|
|
5
|
+
| { status: "rejected"; reason: string };
|
|
6
|
+
|
|
7
|
+
export async function pool<T, U>(
|
|
8
|
+
items: readonly T[],
|
|
9
|
+
concurrency: number,
|
|
10
|
+
fn: (item: T, index: number) => Promise<U>,
|
|
11
|
+
): Promise<PoolResult<U>[]> {
|
|
12
|
+
if (!Number.isInteger(concurrency) || concurrency < 1 || concurrency > 8)
|
|
13
|
+
throw Error("Concurrency must be 1 to 8");
|
|
14
|
+
const results: PoolResult<U>[] = [];
|
|
15
|
+
let cursor = 0;
|
|
16
|
+
async function worker() {
|
|
17
|
+
while (cursor < items.length) {
|
|
18
|
+
const i = cursor++;
|
|
19
|
+
try {
|
|
20
|
+
// oxlint-disable-next-line eslint/no-await-in-loop -- One item at a time per worker.
|
|
21
|
+
results[i] = { status: "fulfilled", value: await fn(items[i], i) };
|
|
22
|
+
} catch (error) {
|
|
23
|
+
results[i] = { status: "rejected", reason: errorMessage(error) };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
await Promise.all(Array.from({ length: Math.min(items.length, concurrency) }, worker));
|
|
28
|
+
return results;
|
|
29
|
+
}
|
package/lib/state.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { catalog } from "./catalog.ts";
|
|
2
|
+
import { isRecord } from "./validation.ts";
|
|
3
|
+
|
|
4
|
+
export const taskStatuses = ["pending", "active", "done", "blocked", "skipped"] as const;
|
|
5
|
+
export type TaskStatus = (typeof taskStatuses)[number];
|
|
6
|
+
export interface Task {
|
|
7
|
+
id: number;
|
|
8
|
+
text: string;
|
|
9
|
+
status: TaskStatus;
|
|
10
|
+
evidence: string;
|
|
11
|
+
}
|
|
12
|
+
export interface Plan {
|
|
13
|
+
route: string;
|
|
14
|
+
goal: string;
|
|
15
|
+
tasks: Task[];
|
|
16
|
+
finishedEvidence?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface Wake {
|
|
19
|
+
seconds: number;
|
|
20
|
+
max: number;
|
|
21
|
+
predicate: string;
|
|
22
|
+
count: number;
|
|
23
|
+
running: boolean;
|
|
24
|
+
stopEvidence?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface State {
|
|
27
|
+
version: 1;
|
|
28
|
+
mode: boolean;
|
|
29
|
+
goal: string;
|
|
30
|
+
plan: Plan | null;
|
|
31
|
+
wake: Wake | null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const activePlan = ({ plan }: State) => (plan?.finishedEvidence === undefined ? plan : null);
|
|
35
|
+
|
|
36
|
+
export const initialState = (): State => ({
|
|
37
|
+
version: 1,
|
|
38
|
+
mode: false,
|
|
39
|
+
goal: "",
|
|
40
|
+
plan: null,
|
|
41
|
+
wake: null,
|
|
42
|
+
});
|
|
43
|
+
export const isTaskStatus = (status: unknown): status is TaskStatus =>
|
|
44
|
+
taskStatuses.some((known) => known === status);
|
|
45
|
+
const optionalText = (value: unknown) => value === undefined || typeof value === "string";
|
|
46
|
+
const isTask = (task: unknown, i: number): task is Task =>
|
|
47
|
+
isRecord(task) &&
|
|
48
|
+
task.id === i + 1 &&
|
|
49
|
+
typeof task.text === "string" &&
|
|
50
|
+
isTaskStatus(task.status) &&
|
|
51
|
+
typeof task.evidence === "string";
|
|
52
|
+
const isPlan = (plan: unknown): plan is Plan =>
|
|
53
|
+
isRecord(plan) &&
|
|
54
|
+
typeof plan.route === "string" &&
|
|
55
|
+
typeof plan.goal === "string" &&
|
|
56
|
+
Array.isArray(plan.tasks) &&
|
|
57
|
+
plan.tasks.length > 0 &&
|
|
58
|
+
plan.tasks.every(isTask) &&
|
|
59
|
+
optionalText(plan.finishedEvidence);
|
|
60
|
+
const inRange = (value: unknown, min: number, max: number): value is number =>
|
|
61
|
+
typeof value === "number" && Number.isInteger(value) && value >= min && value <= max;
|
|
62
|
+
const isWake = (wake: unknown): wake is Wake =>
|
|
63
|
+
isRecord(wake) &&
|
|
64
|
+
inRange(wake.seconds, 5, 86400) &&
|
|
65
|
+
inRange(wake.max, 1, 100) &&
|
|
66
|
+
inRange(wake.count, 0, wake.max) &&
|
|
67
|
+
typeof wake.predicate === "string" &&
|
|
68
|
+
typeof wake.running === "boolean" &&
|
|
69
|
+
optionalText(wake.stopEvidence);
|
|
70
|
+
const isState = (state: unknown): state is State =>
|
|
71
|
+
isRecord(state) &&
|
|
72
|
+
state.version === 1 &&
|
|
73
|
+
typeof state.mode === "boolean" &&
|
|
74
|
+
typeof state.goal === "string" &&
|
|
75
|
+
(state.plan === null || isPlan(state.plan)) &&
|
|
76
|
+
(state.wake === null || isWake(state.wake));
|
|
77
|
+
|
|
78
|
+
export const stateType = "pstack-state";
|
|
79
|
+
export const stopped = (wake: Wake | null, stopEvidence?: string): Wake | null =>
|
|
80
|
+
wake && { ...wake, running: false, ...(stopEvidence === undefined ? {} : { stopEvidence }) };
|
|
81
|
+
export function restore(entries: readonly unknown[]): State {
|
|
82
|
+
const saved = entries.findLast(
|
|
83
|
+
(entry) => isRecord(entry) && entry.type === "custom" && entry.customType === stateType,
|
|
84
|
+
);
|
|
85
|
+
if (!isRecord(saved) || !isState(saved.data)) return initialState();
|
|
86
|
+
const state = structuredClone(saved.data);
|
|
87
|
+
return { ...state, wake: stopped(state.wake) };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function startPlan(route: string, goal: string, customSteps?: string[]): Plan {
|
|
91
|
+
if (!goal.trim()) throw Error("A goal is required");
|
|
92
|
+
const steps = route === "figure-it-out" ? customSteps : catalog.steps[route];
|
|
93
|
+
if (!steps?.length || steps.some((s) => !s.trim()))
|
|
94
|
+
throw Error("Choose a known playbook or supply custom steps");
|
|
95
|
+
return {
|
|
96
|
+
route,
|
|
97
|
+
goal,
|
|
98
|
+
tasks: steps.map((text, i) => ({ id: i + 1, text, status: "pending", evidence: "" })),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
export function updateTask(plan: Plan | null, id: number, status: TaskStatus, evidence = ""): Plan {
|
|
102
|
+
if (!plan) throw Error("No active plan");
|
|
103
|
+
const current = plan.tasks.find((t) => t.id === id);
|
|
104
|
+
if (!current) throw Error("Unknown task");
|
|
105
|
+
if (["done", "blocked", "skipped"].includes(status) && !evidence.trim())
|
|
106
|
+
throw Error("Evidence or a reason is required");
|
|
107
|
+
const { finishedEvidence, ...open } = plan;
|
|
108
|
+
const tasks = plan.tasks.map((t) => (t.id === id ? { ...t, status, evidence } : t));
|
|
109
|
+
return current.status === status && finishedEvidence !== undefined
|
|
110
|
+
? { ...open, tasks, finishedEvidence }
|
|
111
|
+
: { ...open, tasks };
|
|
112
|
+
}
|
|
113
|
+
export function planComplete(plan: Plan | null) {
|
|
114
|
+
return !!plan && plan.tasks.every((t) => t.status === "done" || t.status === "skipped");
|
|
115
|
+
}
|
|
116
|
+
export const summary = (state: State) => ({
|
|
117
|
+
mode: state.mode,
|
|
118
|
+
goal: state.goal,
|
|
119
|
+
plan: state.plan,
|
|
120
|
+
wake: state.wake,
|
|
121
|
+
complete: planComplete(state.plan),
|
|
122
|
+
});
|
|
123
|
+
export function wakeConfig(seconds: number, max: number, predicate: string): Wake {
|
|
124
|
+
if (!inRange(seconds, 5, 86400) || !inRange(max, 1, 100) || !predicate.trim())
|
|
125
|
+
throw Error("Wake requires 5–86400 seconds, 1–100 iterations, and a predicate");
|
|
126
|
+
return { seconds, max, predicate, count: 0, running: true };
|
|
127
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { isRecord } from "./validation.ts";
|
|
2
|
+
|
|
3
|
+
function sessionMessages(raw: string) {
|
|
4
|
+
return raw
|
|
5
|
+
.split("\n")
|
|
6
|
+
.filter(Boolean)
|
|
7
|
+
.map((line): unknown => JSON.parse(line))
|
|
8
|
+
.flatMap((entry) =>
|
|
9
|
+
isRecord(entry) && entry.type === "message" && isRecord(entry.message) ? [entry.message] : [],
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
export function blindTranscript(raw: string, model: string) {
|
|
13
|
+
return sessionMessages(raw)
|
|
14
|
+
.map((m) =>
|
|
15
|
+
JSON.stringify({
|
|
16
|
+
role: m.role,
|
|
17
|
+
content: m.content,
|
|
18
|
+
toolName: m.toolName,
|
|
19
|
+
toolCallId: m.toolCallId,
|
|
20
|
+
isError: m.isError,
|
|
21
|
+
})
|
|
22
|
+
.replaceAll(model, "[redacted-model]")
|
|
23
|
+
.replaceAll(model.split("/").slice(1).join("/"), "[redacted-model]"),
|
|
24
|
+
)
|
|
25
|
+
.join("\n");
|
|
26
|
+
}
|
|
27
|
+
export function readPaths(raw: string) {
|
|
28
|
+
const messages = sessionMessages(raw);
|
|
29
|
+
const succeeded = new Set(
|
|
30
|
+
messages
|
|
31
|
+
.filter((m) => m.role === "toolResult" && m.isError !== true && m.toolCallId)
|
|
32
|
+
.map((m) => m.toolCallId),
|
|
33
|
+
);
|
|
34
|
+
const readPath = (call: unknown) =>
|
|
35
|
+
isRecord(call) &&
|
|
36
|
+
call.type === "toolCall" &&
|
|
37
|
+
call.name === "read" &&
|
|
38
|
+
isRecord(call.arguments) &&
|
|
39
|
+
typeof call.arguments.path === "string" &&
|
|
40
|
+
succeeded.has(call.id)
|
|
41
|
+
? [call.arguments.path]
|
|
42
|
+
: [];
|
|
43
|
+
return messages.flatMap((m) => (Array.isArray(m.content) ? m.content.flatMap(readPath) : []));
|
|
44
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function isRecord(value: unknown): value is Record<string, unknown> {
|
|
2
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export const errorMessage = (error: unknown) =>
|
|
6
|
+
error instanceof Error ? error.message : String(error);
|
|
7
|
+
|
|
8
|
+
export function parseJson(source: string, label: string): unknown {
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(source);
|
|
11
|
+
} catch (error) {
|
|
12
|
+
if (!(error instanceof SyntaxError)) throw error;
|
|
13
|
+
// oxlint-disable-next-line eslint/preserve-caught-error -- JSON.parse errors may expose file contents.
|
|
14
|
+
throw new Error(`Invalid JSON in ${label}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-pstack-workflow-kit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Map-driven pstack and Team Kit workflows for Pi",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package"
|
|
7
|
+
],
|
|
8
|
+
"homepage": "https://github.com/just-joshn/pi-pstack/tree/feature/pi-native-workflow-kit#readme",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/just-joshn/pi-pstack/issues"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/just-joshn/pi-pstack.git"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"agents",
|
|
19
|
+
"extensions",
|
|
20
|
+
"lib",
|
|
21
|
+
"reference",
|
|
22
|
+
"scripts/job-input.ts",
|
|
23
|
+
"scripts/run-job.mjs",
|
|
24
|
+
"skills"
|
|
25
|
+
],
|
|
26
|
+
"type": "module",
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public",
|
|
29
|
+
"registry": "https://registry.npmjs.org/"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"lint": "oxlint",
|
|
33
|
+
"lint:fix": "oxlint --fix",
|
|
34
|
+
"format": "oxfmt",
|
|
35
|
+
"format:check": "oxfmt --check",
|
|
36
|
+
"generate": "python3 scripts/generate.py",
|
|
37
|
+
"check:generated": "python3 scripts/generate.py --check",
|
|
38
|
+
"typecheck": "tsrs --noEmit",
|
|
39
|
+
"typecheck:fast": "tsrs --noEmit --fast",
|
|
40
|
+
"typecheck:ci": "tsc --noEmit",
|
|
41
|
+
"test": "node --test tests/*.test.mjs",
|
|
42
|
+
"test:coverage": "node --test --experimental-test-coverage --test-coverage-lines=80 --test-coverage-branches=80 --test-coverage-functions=80 --test-coverage-include='extensions/**' --test-coverage-include='lib/**' --test-coverage-include='scripts/run-job.mjs' --test-coverage-include='scripts/job-input.ts' tests/*.test.mjs",
|
|
43
|
+
"smoke": "node scripts/smoke.mjs",
|
|
44
|
+
"check": "bun run check:generated && oxlint && oxfmt --check && tsrs --noEmit && bun run test:coverage",
|
|
45
|
+
"check:ci": "bun run check:generated && oxlint && oxfmt --check && tsc --noEmit && bun run test:coverage"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "22.20.5",
|
|
49
|
+
"oxfmt": "0.80.0",
|
|
50
|
+
"oxlint": "1.95.0",
|
|
51
|
+
"tsrs": "7.1.0-beta.tsrs5",
|
|
52
|
+
"typescript": "7.0.2"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"@earendil-works/pi-ai": "*",
|
|
56
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
57
|
+
"typebox": "*"
|
|
58
|
+
},
|
|
59
|
+
"engines": {
|
|
60
|
+
"node": ">=22.19.0"
|
|
61
|
+
},
|
|
62
|
+
"pi": {
|
|
63
|
+
"extensions": [
|
|
64
|
+
"extensions/index.ts"
|
|
65
|
+
],
|
|
66
|
+
"skills": [
|
|
67
|
+
"skills"
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Parity and verification gaps
|
|
2
|
+
|
|
3
|
+
This is a map-based implementation, not a tested port of every original upstream skill. The source attachment is the acceptance inventory. `PARITY.md` and `parity.json` classify every node; classification is not a behavior test result.
|
|
4
|
+
|
|
5
|
+
| Area | Implemented | Remaining |
|
|
6
|
+
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
7
|
+
| Catalog | All source IDs, relationships, view definitions and original source URLs; native select-based browsing. | Source map graphical coordinates are preserved, not rendered pixel-for-pixel in the terminal. |
|
|
8
|
+
| Ordinary skills and principles | 76 native SKILL.md entries; map-based instructions. | Original full pinned leaf files, scripts and reference templates not downloaded; model-mediated behavior not exercised. |
|
|
9
|
+
| Playbooks | 22 ordered, evidence-tracked routes; conditional graph links retained. | Reconstructed steps rather than exact full upstream sequences; no deterministic enforcement of every skill invocation. |
|
|
10
|
+
| Models | Registry selection, nine roles, budget and aliases, cross-vendor judge. | Exact Cursor defaults/legacy migration and service-specific fast models have no reliable native model-ID correspondence. |
|
|
11
|
+
| Workers | Fresh local Pi CLI sessions, tool allowlists, isolated write worktrees, bounded parallelism, artifacts. | No hosted Cursor-equivalent remote agent execution, true security sandbox, background worker resumption, or live model tests. |
|
|
12
|
+
| Arena/eval | Candidate sessions and blinded projections, cross-vendor selection, read-call audit. | Strong blinding, artifact-level blind eval, per-provider independence and full transcript coverage are not proven. |
|
|
13
|
+
| Goals/loops | Native extension goal state and bounded local wakes; restores paused. | No always-on daemon or autonomous wake after Pi exits. |
|
|
14
|
+
| PRs | GitHub CLI state and approved exact-head merge prefix. | Live forge tests, automatic verification provenance, actual Origin implementation, hosted Bugbot not supplied. |
|
|
15
|
+
| Verification | Real-surface/formal verifier creation and maintenance instructions. | App-specific scripts and proof tools must be configured and tested. No bundled browser controller, TLA+ checker, or terminal profiler. |
|
|
16
|
+
| Team Kit | Direct and optional skills, two reviewer contracts, two rule instructions. | Rules are advisory, not an automatic lint implementation; interactive review HTML/video generated per project, not a bundled template/renderer. |
|
|
17
|
+
| Benny | Dormant configuration, workflow drafts, signed event entrypoint, thread-level deduplication, narrow tool allowlist. | External Slack event adapter, scheduler, tracker/MCP tool implementation, app adapter, trusted marker publishing, live triage/repro and draft PR verification. |
|
|
18
|
+
| Optional Grok Bot | Native workflow instructions. | Existing Grok Bot, webhook and Tailscale service must be available. |
|
|
19
|
+
| Native Pi runtime | Typechecked against Pi 1.6.0; local RPC smoke covers discovery and mode persistence without model calls. | Authenticated model, forge and MCP runs are not covered by the local checks. |
|
|
20
|
+
|
|
21
|
+
No runtime dependency on Cursor or a third-party coding-agent framework. External project tooling and services are normal conditional dependencies, not Pi runtime substitutes. Full functional parity and production readiness remain unverified. Do not equate 161 mapped nodes with 161 proven implementations.
|