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
package/src/git.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
import { fail } from "./support.ts";
|
|
4
|
+
|
|
5
|
+
export function gitIn(
|
|
6
|
+
pi: ExtensionAPI,
|
|
7
|
+
cwd: string,
|
|
8
|
+
signal?: AbortSignal,
|
|
9
|
+
maxBuffer = 4 * 1024 * 1024,
|
|
10
|
+
) {
|
|
11
|
+
async function probe(args: string[], at = cwd, limit = maxBuffer) {
|
|
12
|
+
const r = await pi.exec("git", args, {
|
|
13
|
+
cwd: at,
|
|
14
|
+
timeout: 30000,
|
|
15
|
+
maxBuffer: limit,
|
|
16
|
+
...(signal && { signal }),
|
|
17
|
+
});
|
|
18
|
+
return r.truncated || r.killed ? undefined : r;
|
|
19
|
+
}
|
|
20
|
+
async function run(args: string[], at = cwd) {
|
|
21
|
+
const r = await probe(args, at);
|
|
22
|
+
if (!r) fail(`git ${args[0]} failed: output truncated or process stopped`);
|
|
23
|
+
if (r.code !== 0) fail(`git ${args[0]} failed: ${r.stderr}`);
|
|
24
|
+
return r.stdout;
|
|
25
|
+
}
|
|
26
|
+
return { probe, run };
|
|
27
|
+
}
|
|
28
|
+
export type Git = ReturnType<typeof gitIn>;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
import { activePlan } from "../lib/state.ts";
|
|
4
|
+
import { registerCatalog } from "./catalog-ui.ts";
|
|
5
|
+
import { registerDelegation } from "./delegate.ts";
|
|
6
|
+
import { registerForge } from "./forge.ts";
|
|
7
|
+
import { registerModelSetup } from "./models.ts";
|
|
8
|
+
import { registerPlan } from "./plan.ts";
|
|
9
|
+
import { registerRecords } from "./records.ts";
|
|
10
|
+
import { createSession } from "./session.ts";
|
|
11
|
+
import { notifier } from "./support.ts";
|
|
12
|
+
import { registerWorktrees } from "./worktrees.ts";
|
|
13
|
+
|
|
14
|
+
export default function pstack(pi: ExtensionAPI) {
|
|
15
|
+
const notify = notifier(pi);
|
|
16
|
+
const session = createSession(pi);
|
|
17
|
+
const activeWorktrees = new Set<string>();
|
|
18
|
+
registerModelSetup(pi, notify);
|
|
19
|
+
registerPlan(pi, session, notify);
|
|
20
|
+
registerCatalog(pi, notify);
|
|
21
|
+
registerRecords(pi, notify);
|
|
22
|
+
registerWorktrees(pi, activeWorktrees);
|
|
23
|
+
registerDelegation(pi, activeWorktrees);
|
|
24
|
+
registerForge(pi, () => activePlan(session.state())?.route);
|
|
25
|
+
}
|
package/src/models.ts
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
aliases,
|
|
8
|
+
applyConfigPatch,
|
|
9
|
+
budgets,
|
|
10
|
+
defaultConfig,
|
|
11
|
+
effort,
|
|
12
|
+
judgeRole,
|
|
13
|
+
panelRoles,
|
|
14
|
+
parseModelConfig,
|
|
15
|
+
type Role,
|
|
16
|
+
type RoleConfig,
|
|
17
|
+
roles,
|
|
18
|
+
validateConfig,
|
|
19
|
+
} from "../lib/models.ts";
|
|
20
|
+
import { parseJson } from "../lib/validation.ts";
|
|
21
|
+
import { agentDir, atomicWrite, fail, hasErrorCode, type Notify, piBin, text } from "./support.ts";
|
|
22
|
+
|
|
23
|
+
const modelConfigPath = () => join(agentDir(), "pstack-models.json");
|
|
24
|
+
export async function readConfig(configPath = modelConfigPath()): Promise<RoleConfig> {
|
|
25
|
+
let source: string;
|
|
26
|
+
try {
|
|
27
|
+
source = await readFile(configPath, "utf8");
|
|
28
|
+
} catch (e) {
|
|
29
|
+
if (hasErrorCode(e, "ENOENT")) return defaultConfig();
|
|
30
|
+
throw e;
|
|
31
|
+
}
|
|
32
|
+
return parseModelConfig(parseJson(source, "pstack model configuration"));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const workerIsolation = [
|
|
36
|
+
"--no-approve",
|
|
37
|
+
"--no-extensions",
|
|
38
|
+
"--no-skills",
|
|
39
|
+
"--no-prompt-templates",
|
|
40
|
+
"--no-themes",
|
|
41
|
+
"--no-mcp",
|
|
42
|
+
];
|
|
43
|
+
const modelsInScope = (ctx: ExtensionContext) =>
|
|
44
|
+
ctx.scopedModels.length ? ctx.scopedModels.map((m) => m.model) : ctx.modelRegistry.getAvailable();
|
|
45
|
+
export const modelName = (m: { provider: string; id: string }) => `${m.provider}/${m.id}`;
|
|
46
|
+
|
|
47
|
+
async function listedModels(
|
|
48
|
+
pi: ExtensionAPI,
|
|
49
|
+
cwd: string,
|
|
50
|
+
signal?: AbortSignal,
|
|
51
|
+
extension?: string,
|
|
52
|
+
) {
|
|
53
|
+
const run = await pi.exec(
|
|
54
|
+
piBin,
|
|
55
|
+
[...workerIsolation, ...(extension ? ["-e", extension] : []), "--list-models"],
|
|
56
|
+
{ cwd, timeout: 30_000, ...(signal && { signal }) },
|
|
57
|
+
);
|
|
58
|
+
if (run.code !== 0 || run.killed) return undefined;
|
|
59
|
+
// Pi pads each row to the header's columns; ids can contain spaces, so split by position.
|
|
60
|
+
const [header = "", ...rows] = run.stdout.split("\n");
|
|
61
|
+
const [model, context] = [header.indexOf("model"), header.indexOf("context")];
|
|
62
|
+
return rows
|
|
63
|
+
.map((row) => ({ provider: row.slice(0, model).trim(), id: row.slice(model, context).trim() }))
|
|
64
|
+
.filter((listed) => listed.provider && listed.id)
|
|
65
|
+
.map((listed) => ({ provider: listed.provider, model: modelName(listed) }));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Maps each in-scope model of an extension-registered provider to the loaded extension a worker
|
|
70
|
+
* needs for it. Pi does not report which extension registered a provider, so every extension that
|
|
71
|
+
* registers a command is listed alone and compared with the listing without extensions.
|
|
72
|
+
*/
|
|
73
|
+
export async function workerExtensions(
|
|
74
|
+
pi: ExtensionAPI,
|
|
75
|
+
ctx: ExtensionContext,
|
|
76
|
+
signal?: AbortSignal,
|
|
77
|
+
) {
|
|
78
|
+
const registered = new Set(ctx.modelRegistry.getRegisteredProviderIds());
|
|
79
|
+
const wanted = new Set(
|
|
80
|
+
modelsInScope(ctx)
|
|
81
|
+
.filter((m) => registered.has(m.provider))
|
|
82
|
+
.map(modelName),
|
|
83
|
+
);
|
|
84
|
+
const loaded = [
|
|
85
|
+
...new Set(
|
|
86
|
+
pi
|
|
87
|
+
.getCommands()
|
|
88
|
+
.filter((command) => command.source === "extension")
|
|
89
|
+
.map((command) => command.sourceInfo.path),
|
|
90
|
+
),
|
|
91
|
+
];
|
|
92
|
+
if (!wanted.size || !loaded.length) return new Map<string, string>();
|
|
93
|
+
const [builtIn, ...listings] = await Promise.all(
|
|
94
|
+
[undefined, ...loaded].map((extension) => listedModels(pi, ctx.cwd, signal, extension)),
|
|
95
|
+
);
|
|
96
|
+
if (signal?.aborted) fail("Cancelled");
|
|
97
|
+
if (!builtIn) fail(`Could not list worker models: ${piBin} --list-models failed`);
|
|
98
|
+
const builtInProviders = new Set(builtIn.map((listed) => listed.provider));
|
|
99
|
+
return new Map(
|
|
100
|
+
loaded.flatMap((extension, i) =>
|
|
101
|
+
(listings[i] ?? [])
|
|
102
|
+
.filter((listed) => wanted.has(listed.model) && !builtInProviders.has(listed.provider))
|
|
103
|
+
.map((listed) => [listed.model, extension] as const),
|
|
104
|
+
),
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function availableWorkerModels(
|
|
109
|
+
ctx: ExtensionContext,
|
|
110
|
+
extensions: ReadonlyMap<string, string>,
|
|
111
|
+
) {
|
|
112
|
+
const registered = new Set(ctx.modelRegistry.getRegisteredProviderIds());
|
|
113
|
+
const ids = modelsInScope(ctx)
|
|
114
|
+
.filter((m) => !registered.has(m.provider) || extensions.has(modelName(m)))
|
|
115
|
+
.map(modelName);
|
|
116
|
+
return [...new Set(ids)].toSorted();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function chooseRole(ctx: ExtensionContext, role: Role, available: string[]) {
|
|
120
|
+
const panel = panelRoles.has(role);
|
|
121
|
+
const options = [
|
|
122
|
+
...(role === judgeRole ? [] : aliases),
|
|
123
|
+
...available,
|
|
124
|
+
...(panel ? ["Done"] : []),
|
|
125
|
+
];
|
|
126
|
+
const chosen: string[] = [];
|
|
127
|
+
while (chosen.length < (panel ? 8 : 1)) {
|
|
128
|
+
// oxlint-disable-next-line eslint/no-await-in-loop -- Show prior selections in the next dialog.
|
|
129
|
+
const value = await ctx.ui.select(`${role}: ${chosen.join(", ") || "(none)"}`, options);
|
|
130
|
+
if (!value) return undefined;
|
|
131
|
+
if (value === "Done") break;
|
|
132
|
+
chosen.push(value);
|
|
133
|
+
}
|
|
134
|
+
return chosen;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function chooseConfig(ctx: ExtensionContext, config: RoleConfig, available: string[]) {
|
|
138
|
+
const budget = await ctx.ui.select(
|
|
139
|
+
"Reasoning budget",
|
|
140
|
+
budgets.map((b) => `${b} (${effort("feature, refactoring", b)})`),
|
|
141
|
+
);
|
|
142
|
+
if (!budget) return undefined;
|
|
143
|
+
const selections = { ...config.roles };
|
|
144
|
+
for (const role of roles) {
|
|
145
|
+
// oxlint-disable-next-line eslint/no-await-in-loop -- Pi shows one selection dialog at a time.
|
|
146
|
+
const action = await ctx.ui.select(`${role}: ${selections[role].join(", ") || "(empty)"}`, [
|
|
147
|
+
"Keep current",
|
|
148
|
+
"Choose model(s)",
|
|
149
|
+
]);
|
|
150
|
+
if (!action) return undefined;
|
|
151
|
+
if (action === "Keep current") continue;
|
|
152
|
+
// oxlint-disable-next-line eslint/no-await-in-loop -- Finish choosing this role before the next.
|
|
153
|
+
const chosen = await chooseRole(ctx, role, available);
|
|
154
|
+
if (!chosen) return undefined;
|
|
155
|
+
selections[role] = chosen;
|
|
156
|
+
}
|
|
157
|
+
return { ...config, budget: budget.split(" ")[0], roles: selections };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function registerModelSetup(pi: ExtensionAPI, notify: Notify) {
|
|
161
|
+
pi.registerCommand("setup-pstack", {
|
|
162
|
+
description: "Configure pstack role models and reasoning budget",
|
|
163
|
+
handler: async (args, ctx) => {
|
|
164
|
+
const available = availableWorkerModels(ctx, await workerExtensions(pi, ctx));
|
|
165
|
+
const parent = ctx.model && modelName(ctx.model);
|
|
166
|
+
const warning =
|
|
167
|
+
parent && !available.includes(parent)
|
|
168
|
+
? `auto and inherit-parent resolve to ${parent}, which is unavailable to workers in this session. Select an available model explicitly.`
|
|
169
|
+
: undefined;
|
|
170
|
+
const configPath = modelConfigPath();
|
|
171
|
+
const current = await readConfig(configPath);
|
|
172
|
+
const input = args.trim();
|
|
173
|
+
if (input === "show" || (!input && !ctx.hasUI)) {
|
|
174
|
+
notify(ctx, text({ config: current, available, path: configPath, warning }));
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (!ctx.hasUI) fail("Use /setup-pstack interactively to confirm model configuration.");
|
|
178
|
+
if (warning) notify(ctx, warning);
|
|
179
|
+
const chosen = input
|
|
180
|
+
? applyConfigPatch(current, parseJson(input, "setup arguments"))
|
|
181
|
+
: await chooseConfig(ctx, current, available);
|
|
182
|
+
if (!chosen) return;
|
|
183
|
+
const config = validateConfig(chosen, available);
|
|
184
|
+
if (!(await ctx.ui.confirm("Save pstack role configuration?", text(config)))) return;
|
|
185
|
+
await atomicWrite(configPath, JSON.stringify(config, null, 2) + "\n");
|
|
186
|
+
notify(ctx, `Saved ${configPath}. Parent model unchanged.`);
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
|
|
6
|
+
import { gitIn } from "./git.ts";
|
|
7
|
+
|
|
8
|
+
const diffBytes = 2 * 1024 * 1024;
|
|
9
|
+
const untrackedLimit = 500;
|
|
10
|
+
|
|
11
|
+
export interface ParentDiff {
|
|
12
|
+
path: string;
|
|
13
|
+
omitted: string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function saveParentDiff(
|
|
17
|
+
pi: ExtensionAPI,
|
|
18
|
+
cwd: string,
|
|
19
|
+
dir: string,
|
|
20
|
+
signal?: AbortSignal,
|
|
21
|
+
): Promise<ParentDiff | undefined> {
|
|
22
|
+
const git = gitIn(pi, cwd, signal, diffBytes);
|
|
23
|
+
const top = await git.probe(["rev-parse", "--show-toplevel"]);
|
|
24
|
+
if (top?.code !== 0) return undefined;
|
|
25
|
+
const repo = top.stdout.replace(/\r?\n$/, "");
|
|
26
|
+
const [tracked, listed] = await Promise.all([
|
|
27
|
+
git.probe(["diff", "--no-relative", "HEAD"], repo),
|
|
28
|
+
git.probe(["ls-files", "--others", "--exclude-standard", "-z"], repo),
|
|
29
|
+
]);
|
|
30
|
+
if (tracked?.code !== 0 || listed?.code !== 0) return undefined;
|
|
31
|
+
const files = listed.stdout.split("\0").filter(Boolean);
|
|
32
|
+
let remaining = diffBytes - Buffer.byteLength(tracked.stdout);
|
|
33
|
+
if (remaining < 0) return undefined;
|
|
34
|
+
const kept = [tracked.stdout];
|
|
35
|
+
const omitted: string[] = [];
|
|
36
|
+
const limit = Math.min(files.length, untrackedLimit);
|
|
37
|
+
let next = 0;
|
|
38
|
+
while (next < limit && remaining > 0) {
|
|
39
|
+
const batch = files.slice(next, Math.min(next + 8, limit));
|
|
40
|
+
// oxlint-disable-next-line eslint/no-await-in-loop -- Apply the byte budget before fetching another batch.
|
|
41
|
+
const patches = await Promise.allSettled(
|
|
42
|
+
batch.map((file) =>
|
|
43
|
+
git.probe(["diff", "--no-index", "--", "/dev/null", file], repo, remaining),
|
|
44
|
+
),
|
|
45
|
+
);
|
|
46
|
+
for (const [i, file] of batch.entries()) {
|
|
47
|
+
const patch = patches[i];
|
|
48
|
+
const r = patch?.status === "fulfilled" ? patch.value : undefined;
|
|
49
|
+
if (r && (r.code === 0 || r.code === 1)) {
|
|
50
|
+
const bytes = Buffer.byteLength(r.stdout);
|
|
51
|
+
if (bytes <= remaining) {
|
|
52
|
+
kept.push(r.stdout);
|
|
53
|
+
remaining -= bytes;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
omitted.push(file);
|
|
58
|
+
}
|
|
59
|
+
next += batch.length;
|
|
60
|
+
}
|
|
61
|
+
const path = join(dir, "parent.diff");
|
|
62
|
+
await writeFile(path, kept.join(""), { mode: 0o600 });
|
|
63
|
+
return { path, omitted: omitted.concat(files.slice(next)) };
|
|
64
|
+
}
|
package/src/plan.ts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
|
|
3
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { Type } from "typebox";
|
|
5
|
+
|
|
6
|
+
import { nativeNode, routes } from "../lib/catalog.ts";
|
|
7
|
+
import {
|
|
8
|
+
isTaskStatus,
|
|
9
|
+
planComplete,
|
|
10
|
+
startPlan,
|
|
11
|
+
stopped,
|
|
12
|
+
summary,
|
|
13
|
+
taskStatuses,
|
|
14
|
+
updateTask,
|
|
15
|
+
wakeConfig,
|
|
16
|
+
} from "../lib/state.ts";
|
|
17
|
+
import { sendWorkflow } from "./catalog-ui.ts";
|
|
18
|
+
import { mergeRoutes } from "./forge.ts";
|
|
19
|
+
import type { Session } from "./session.ts";
|
|
20
|
+
import {
|
|
21
|
+
artifacts,
|
|
22
|
+
atomicWrite,
|
|
23
|
+
fail,
|
|
24
|
+
type Notify,
|
|
25
|
+
result,
|
|
26
|
+
stringEnum,
|
|
27
|
+
text,
|
|
28
|
+
unreachable,
|
|
29
|
+
} from "./support.ts";
|
|
30
|
+
|
|
31
|
+
const planParameters = Type.Object({
|
|
32
|
+
action: stringEnum(["start", "custom", "show", "update", "finish"]),
|
|
33
|
+
route: Type.Optional(Type.String()),
|
|
34
|
+
goal: Type.Optional(Type.String()),
|
|
35
|
+
steps: Type.Optional(Type.Array(Type.String())),
|
|
36
|
+
task: Type.Optional(Type.Integer()),
|
|
37
|
+
status: Type.Optional(stringEnum(taskStatuses)),
|
|
38
|
+
evidence: Type.Optional(Type.String()),
|
|
39
|
+
});
|
|
40
|
+
async function approveMergeRoute(ctx: ExtensionContext, route: string, goal: string) {
|
|
41
|
+
if (!mergeRoutes.includes(route)) return;
|
|
42
|
+
const approved =
|
|
43
|
+
ctx.hasUI &&
|
|
44
|
+
(await ctx.ui.confirm(
|
|
45
|
+
`Start the merge-capable ${route} plan?`,
|
|
46
|
+
`${goal}\nThis route enables pstack_ship; each merge still needs its own approval.`,
|
|
47
|
+
));
|
|
48
|
+
if (!approved)
|
|
49
|
+
fail(`Starting ${route} requires operator approval; use /pstack-run ${route} <goal>`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function registerPlan(pi: ExtensionAPI, session: Session, notify: Notify) {
|
|
53
|
+
pi.registerCommand("poteto-mode", {
|
|
54
|
+
description: "Run a task with poteto-mode, or persist it with on/off",
|
|
55
|
+
handler: async (args, ctx) => {
|
|
56
|
+
const value = args.trim();
|
|
57
|
+
if (value === "on" || value === "off") return session.commit(ctx, { mode: value === "on" });
|
|
58
|
+
if (value) return sendWorkflow(pi, "poteto-mode", value);
|
|
59
|
+
if (!ctx.hasUI) return notify(ctx, "Use /poteto-mode on or /poteto-mode <goal>.");
|
|
60
|
+
const goal = await ctx.ui.input("Goal and observable completion predicate");
|
|
61
|
+
if (goal) sendWorkflow(pi, "poteto-mode", goal);
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
pi.registerCommand("pstack-run", {
|
|
65
|
+
description: "Run an explicit playbook: /pstack-run <route> <goal>",
|
|
66
|
+
handler: async (args, ctx) => {
|
|
67
|
+
const [route, ...words] = args.trim().split(/\s+/);
|
|
68
|
+
const goal = words.join(" ");
|
|
69
|
+
if (!route || !routes.includes(route) || !goal)
|
|
70
|
+
return notify(ctx, `Choose a route and goal:\n${routes.join(", ")}`);
|
|
71
|
+
session.commit(ctx, { plan: startPlan(route, goal) });
|
|
72
|
+
sendWorkflow(pi, "pb-" + route, goal);
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
pi.registerCommand("pstack-status", {
|
|
76
|
+
description: "Show current goal, route, tasks and loop",
|
|
77
|
+
handler: async (_args, ctx) => notify(ctx, text(summary(session.state()))),
|
|
78
|
+
});
|
|
79
|
+
pi.registerCommand("pstack-clear", {
|
|
80
|
+
description: "Clear the current plan and goal; preserve artifacts",
|
|
81
|
+
handler: async (_args, ctx) => session.commit(ctx, { goal: "", plan: null, wake: null }),
|
|
82
|
+
});
|
|
83
|
+
pi.registerCommand("pstack-goal", {
|
|
84
|
+
description: "Set or clear a persistent branch goal",
|
|
85
|
+
handler: async (args, ctx) => {
|
|
86
|
+
const goal = args.trim();
|
|
87
|
+
if (!goal) return notify(ctx, session.state().goal || "No goal");
|
|
88
|
+
session.commit(ctx, { goal: goal === "clear" ? "" : goal });
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
pi.registerCommand("pstack-loop", {
|
|
92
|
+
description: "Start a bounded interactive wake loop: <seconds> <max> <predicate>, or stop",
|
|
93
|
+
handler: async (args, ctx) => {
|
|
94
|
+
const input = args.trim();
|
|
95
|
+
if (input === "stop") return session.stopWake(ctx);
|
|
96
|
+
if (!input) return notify(ctx, text(session.state().wake));
|
|
97
|
+
if (ctx.mode !== "tui") fail("Wake loops require an open interactive Pi session.");
|
|
98
|
+
const [seconds, max, ...words] = input.split(/\s+/);
|
|
99
|
+
const next = wakeConfig(Number(seconds), Number(max), words.join(" "));
|
|
100
|
+
if (await ctx.ui.confirm("Start bounded autonomous wake loop?", text(next)))
|
|
101
|
+
session.startWake(ctx, next);
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
pi.registerCommand("pstack-pause", {
|
|
105
|
+
description: "Pause wakes and preserve a session resume note",
|
|
106
|
+
handler: async (_args, ctx) => {
|
|
107
|
+
session.stopWake(ctx);
|
|
108
|
+
const path = join(artifacts(ctx), "resume.json");
|
|
109
|
+
const note = {
|
|
110
|
+
...summary(session.state()),
|
|
111
|
+
cwd: ctx.cwd,
|
|
112
|
+
session: ctx.sessionManager.getSessionFile(),
|
|
113
|
+
};
|
|
114
|
+
await atomicWrite(path, JSON.stringify(note, null, 2));
|
|
115
|
+
notify(ctx, `Paused. Resume note: ${path}`);
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
pi.registerTool({
|
|
120
|
+
name: "pstack_plan",
|
|
121
|
+
label: "Pstack plan",
|
|
122
|
+
description:
|
|
123
|
+
"Maintain branch-local plan. Start with a route and goal or custom steps for figure-it-out. Mark tasks with real evidence. Finish only when all are done or justified skips.",
|
|
124
|
+
executionMode: "sequential",
|
|
125
|
+
parameters: planParameters,
|
|
126
|
+
async execute(_id, p, _signal, _update, ctx) {
|
|
127
|
+
const { plan, wake } = session.state();
|
|
128
|
+
let instructions: string | undefined;
|
|
129
|
+
switch (p.action) {
|
|
130
|
+
case "show":
|
|
131
|
+
return result(summary(session.state()));
|
|
132
|
+
case "start": {
|
|
133
|
+
const route = p.route;
|
|
134
|
+
const goal = p.goal ?? "";
|
|
135
|
+
if (!route || !routes.includes(route))
|
|
136
|
+
fail("Choose a known playbook or use action custom");
|
|
137
|
+
await approveMergeRoute(ctx, route, goal);
|
|
138
|
+
instructions = nativeNode("pb-" + route).instructions;
|
|
139
|
+
session.commit(ctx, { plan: startPlan(route, goal) });
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
case "custom":
|
|
143
|
+
session.commit(ctx, { plan: startPlan("figure-it-out", p.goal ?? "", p.steps) });
|
|
144
|
+
break;
|
|
145
|
+
case "update":
|
|
146
|
+
if (p.task === undefined || !isTaskStatus(p.status)) fail("Specify task and status");
|
|
147
|
+
session.commit(ctx, { plan: updateTask(plan, p.task, p.status, p.evidence) });
|
|
148
|
+
break;
|
|
149
|
+
case "finish":
|
|
150
|
+
if (!plan || !planComplete(plan) || !p.evidence?.trim())
|
|
151
|
+
fail("Incomplete plan or missing final evidence");
|
|
152
|
+
session.commit(ctx, {
|
|
153
|
+
plan: { ...plan, finishedEvidence: p.evidence },
|
|
154
|
+
wake: stopped(wake),
|
|
155
|
+
});
|
|
156
|
+
break;
|
|
157
|
+
default:
|
|
158
|
+
unreachable(p.action);
|
|
159
|
+
}
|
|
160
|
+
return result({ state: summary(session.state()), instructions });
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
pi.registerTool({
|
|
164
|
+
name: "pstack_wake",
|
|
165
|
+
label: "Pstack wake status",
|
|
166
|
+
description:
|
|
167
|
+
"Inspect or stop an operator-started wake loop. Starting requires the explicit /pstack-loop command.",
|
|
168
|
+
executionMode: "sequential",
|
|
169
|
+
parameters: Type.Object({
|
|
170
|
+
action: stringEnum(["show", "stop"]),
|
|
171
|
+
evidence: Type.Optional(Type.String()),
|
|
172
|
+
}),
|
|
173
|
+
async execute(_id, p, _signal, _update, ctx) {
|
|
174
|
+
if (p.action === "stop") {
|
|
175
|
+
if (!p.evidence?.trim()) fail("Provide stop evidence or blocker");
|
|
176
|
+
session.stopWake(ctx, p.evidence);
|
|
177
|
+
}
|
|
178
|
+
return result(session.state().wake);
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
}
|
package/src/records.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { appendFile, mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import { Type } from "typebox";
|
|
6
|
+
|
|
7
|
+
import { nativeNode, packageFile } from "../lib/catalog.ts";
|
|
8
|
+
import { isJobKind } from "../lib/jobs.ts";
|
|
9
|
+
import { parseJson } from "../lib/validation.ts";
|
|
10
|
+
import { artifacts, hasErrorCode, type Notify, result, tsvRow } from "./support.ts";
|
|
11
|
+
|
|
12
|
+
export function registerRecords(pi: ExtensionAPI, notify: Notify) {
|
|
13
|
+
pi.registerCommand("pstack-automation", {
|
|
14
|
+
description: "Draft a headless Pi automation (disabled)",
|
|
15
|
+
handler: async (args, ctx) => {
|
|
16
|
+
const kind = args.trim();
|
|
17
|
+
if (!isJobKind(kind)) return notify(ctx, "Choose benny-triage, benny-repro, or custom.");
|
|
18
|
+
const path = join(artifacts(ctx), `${kind}.job.json`);
|
|
19
|
+
const draft =
|
|
20
|
+
kind === "custom"
|
|
21
|
+
? { instructions: "Supply explicit task, approved tools, trigger and finish predicate." }
|
|
22
|
+
: {
|
|
23
|
+
instructions: nativeNode(kind).instructions,
|
|
24
|
+
config: parseJson(
|
|
25
|
+
packageFile("reference/benny/config.example.json"),
|
|
26
|
+
"Benny configuration example",
|
|
27
|
+
),
|
|
28
|
+
};
|
|
29
|
+
const job = { version: 1, enabled: false, kind, cwd: ctx.cwd, tools: [], ...draft };
|
|
30
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
31
|
+
await writeFile(path, JSON.stringify(job, null, 2), { flag: "wx", mode: 0o600 });
|
|
32
|
+
notify(ctx, `Disabled draft: ${path}. No scheduler or service was enabled.`);
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
pi.registerTool({
|
|
36
|
+
name: "pstack_log",
|
|
37
|
+
label: "Pstack decision log",
|
|
38
|
+
description:
|
|
39
|
+
"Append a timestamped decision with phase, rationale, evidence and result to a session TSV.",
|
|
40
|
+
executionMode: "sequential",
|
|
41
|
+
parameters: Type.Object({
|
|
42
|
+
phase: Type.String(),
|
|
43
|
+
decision: Type.String(),
|
|
44
|
+
reason: Type.String(),
|
|
45
|
+
evidence: Type.String(),
|
|
46
|
+
result: Type.String(),
|
|
47
|
+
}),
|
|
48
|
+
async execute(_id, p, _signal, _update, ctx) {
|
|
49
|
+
const dir = artifacts(ctx);
|
|
50
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
51
|
+
const path = join(dir, "decisions.tsv");
|
|
52
|
+
try {
|
|
53
|
+
await writeFile(path, "time\tphase\tdecision\treason\tevidence\tresult\n", {
|
|
54
|
+
flag: "wx",
|
|
55
|
+
mode: 0o600,
|
|
56
|
+
});
|
|
57
|
+
} catch (e) {
|
|
58
|
+
if (!hasErrorCode(e, "EEXIST")) throw e;
|
|
59
|
+
}
|
|
60
|
+
await appendFile(
|
|
61
|
+
path,
|
|
62
|
+
tsvRow([new Date().toISOString(), p.phase, p.decision, p.reason, p.evidence, p.result]),
|
|
63
|
+
);
|
|
64
|
+
return result(path);
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
pi.registerTool({
|
|
68
|
+
name: "pstack_history",
|
|
69
|
+
label: "Pstack session history",
|
|
70
|
+
description:
|
|
71
|
+
"Read bounded current branch session entries and artifact directory; use Pi resume/tree for other sessions.",
|
|
72
|
+
parameters: Type.Object({ limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 100 })) }),
|
|
73
|
+
async execute(_id, p, _signal, _update, ctx) {
|
|
74
|
+
const entries = ctx.sessionManager
|
|
75
|
+
.getBranch()
|
|
76
|
+
.slice(-(p.limit ?? 20))
|
|
77
|
+
.map((e) => ({ type: e.type, id: e.id, data: JSON.stringify(e).slice(0, 4000) }));
|
|
78
|
+
return result({
|
|
79
|
+
session: ctx.sessionManager.getSessionFile(),
|
|
80
|
+
artifacts: artifacts(ctx),
|
|
81
|
+
entries,
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
}
|