supipowers 1.5.3 → 2.0.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/README.md +14 -8
- package/bin/install.mjs +20 -5
- package/bin/install.ts +95 -0
- package/package.json +8 -4
- package/skills/context-mode/SKILL.md +17 -10
- package/skills/harness/SKILL.md +94 -0
- package/skills/ui-design/SKILL.md +63 -0
- package/skills/ui-design/sub-agent-templates/component-builder.md +29 -0
- package/skills/ui-design/sub-agent-templates/design-critic.md +46 -0
- package/skills/ui-design/sub-agent-templates/pencil/component-builder.md +29 -0
- package/skills/ui-design/sub-agent-templates/pencil/design-critic.md +42 -0
- package/skills/ui-design/sub-agent-templates/pencil/section-assembler.md +27 -0
- package/skills/ui-design/sub-agent-templates/section-assembler.md +27 -0
- package/skills/ultraplan-discover/SKILL.md +96 -0
- package/skills/ultraplan-intake/SKILL.md +89 -0
- package/skills/ultraplan-research/SKILL.md +129 -0
- package/skills/ultraplan-review/SKILL.md +86 -0
- package/skills/ultraplan-review-scope/SKILL.md +111 -0
- package/skills/ultraplan-review-structure/SKILL.md +120 -0
- package/skills/ultraplan-review-tdd/SKILL.md +142 -0
- package/skills/ultraplan-scout/SKILL.md +110 -0
- package/skills/ultraplan-synthesize/SKILL.md +124 -0
- package/src/{quality/ai-session.ts → ai/final-message.ts} +27 -0
- package/src/ai/schema-text.ts +129 -0
- package/src/ai/structured-output.ts +274 -0
- package/src/ai/template.ts +27 -0
- package/src/bootstrap.ts +63 -28
- package/src/commands/agents.ts +131 -42
- package/src/commands/ai-review.ts +251 -30
- package/src/commands/clear.ts +434 -0
- package/src/commands/commit.ts +1 -0
- package/src/commands/config.ts +242 -44
- package/src/commands/context.ts +55 -28
- package/src/commands/doctor.ts +234 -6
- package/src/commands/fix-pr.ts +306 -131
- package/src/commands/generate.ts +111 -21
- package/src/commands/memory.ts +192 -0
- package/src/commands/model-picker.ts +28 -21
- package/src/commands/model.ts +18 -8
- package/src/commands/optimize-context.ts +408 -29
- package/src/commands/plan.ts +2 -0
- package/src/commands/qa.ts +312 -137
- package/src/commands/release.ts +259 -76
- package/src/commands/review.ts +293 -59
- package/src/commands/status.ts +200 -13
- package/src/commands/supi.ts +3 -35
- package/src/commands/ui-design.ts +394 -0
- package/src/commands/ultraplan.ts +1518 -0
- package/src/commands/update.ts +86 -0
- package/src/config/defaults.ts +62 -0
- package/src/config/loader.ts +448 -60
- package/src/config/schema.ts +108 -2
- package/src/context/optimizer.ts +25 -33
- package/src/context/rule-renderer.ts +223 -0
- package/src/context/savings.ts +258 -0
- package/src/context/startup-check.ts +380 -0
- package/src/context/startup-optimizer.ts +355 -0
- package/src/context/tokenignore.ts +146 -0
- package/src/context-mode/cache-handle.ts +49 -0
- package/src/context-mode/cache-preview.ts +71 -0
- package/src/context-mode/cache-store.ts +738 -0
- package/src/context-mode/compressor.ts +131 -26
- package/src/context-mode/dedup.ts +108 -0
- package/src/context-mode/detector.ts +35 -4
- package/src/context-mode/event-extractor.ts +14 -12
- package/src/context-mode/event-store.ts +91 -36
- package/src/context-mode/hooks.ts +798 -56
- package/src/context-mode/knowledge/store.ts +255 -11
- package/src/context-mode/memory-store.ts +325 -0
- package/src/context-mode/metrics-recorder.ts +158 -0
- package/src/context-mode/metrics-store.ts +765 -0
- package/src/context-mode/model.ts +24 -0
- package/src/context-mode/processor-keys.ts +29 -0
- package/src/context-mode/processors/build.ts +66 -0
- package/src/context-mode/processors/docker.ts +57 -0
- package/src/context-mode/processors/git.ts +111 -0
- package/src/context-mode/processors/json.ts +112 -0
- package/src/context-mode/processors/k8s.ts +67 -0
- package/src/context-mode/processors/lint.ts +67 -0
- package/src/context-mode/processors/log.ts +86 -0
- package/src/context-mode/processors/registry.ts +116 -0
- package/src/context-mode/processors/test-runner.ts +102 -0
- package/src/context-mode/processors/types.ts +20 -0
- package/src/context-mode/repomap.ts +400 -0
- package/src/context-mode/routing.ts +97 -24
- package/src/context-mode/sandbox/runners.ts +5 -1
- package/src/context-mode/snapshot-builder.ts +106 -11
- package/src/context-mode/source-hash.ts +173 -0
- package/src/context-mode/tool-name.ts +11 -0
- package/src/context-mode/tools.ts +654 -22
- package/src/context-mode/web/fetcher.ts +31 -12
- package/src/debug/logger.ts +2 -1
- package/src/deps/registry.ts +1 -1
- package/src/discipline/failure-summarizer.ts +170 -0
- package/src/discipline/failure-taxonomy.ts +131 -0
- package/src/discipline/workflow-invariants.ts +125 -0
- package/src/discovery/index.ts +31 -0
- package/src/discovery/lsp.ts +87 -0
- package/src/discovery/rank.ts +144 -0
- package/src/discovery/sources.ts +89 -0
- package/src/discovery/workflow.ts +87 -0
- package/src/docs/contracts.ts +39 -0
- package/src/docs/drift.ts +117 -87
- package/src/fix-pr/assessment.ts +200 -0
- package/src/fix-pr/contracts.ts +47 -0
- package/src/fix-pr/fetch-comments.ts +80 -0
- package/src/fix-pr/prompt-builder.ts +58 -40
- package/src/fix-pr/scripts/exec.ts +34 -0
- package/src/fix-pr/scripts/trigger-review.ts +106 -0
- package/src/fix-pr/scripts/wait-and-check.ts +108 -0
- package/src/fix-pr/types.ts +4 -0
- package/src/git/branch-finish.ts +5 -0
- package/src/git/commit-contract.ts +83 -0
- package/src/git/commit.ts +121 -184
- package/src/git/status.ts +62 -8
- package/src/harness/anti_slop/architecture-parser.ts +210 -0
- package/src/harness/anti_slop/backend-factory.ts +30 -0
- package/src/harness/anti_slop/backend.ts +140 -0
- package/src/harness/anti_slop/desloppify-adapter.ts +319 -0
- package/src/harness/anti_slop/fallow-adapter.ts +305 -0
- package/src/harness/anti_slop/installer.ts +227 -0
- package/src/harness/anti_slop/queue.ts +216 -0
- package/src/harness/anti_slop/recommend.ts +84 -0
- package/src/harness/anti_slop/score.ts +180 -0
- package/src/harness/anti_slop/synthetic-edit-test.ts +128 -0
- package/src/harness/artifacts/agents-md.ts +88 -0
- package/src/harness/artifacts/checks-wiring.ts +57 -0
- package/src/harness/artifacts/docs-tree.ts +79 -0
- package/src/harness/artifacts/lint-configs.ts +136 -0
- package/src/harness/artifacts/review-agents.ts +67 -0
- package/src/harness/bare-entry.ts +108 -0
- package/src/harness/command.ts +1010 -0
- package/src/harness/default-agents/design.md +23 -0
- package/src/harness/default-agents/discover.md +18 -0
- package/src/harness/default-agents/implement.md +24 -0
- package/src/harness/default-agents/plan.md +19 -0
- package/src/harness/default-agents/research.md +21 -0
- package/src/harness/default-agents/validate.md +22 -0
- package/src/harness/gc/reporter.ts +28 -0
- package/src/harness/gc/runner.ts +136 -0
- package/src/harness/hooks/layer-context-inject.ts +155 -0
- package/src/harness/hooks/post-session-sweep.ts +130 -0
- package/src/harness/hooks/pre-edit-dupe-probe.ts +224 -0
- package/src/harness/hooks/register.ts +118 -0
- package/src/harness/model.ts +117 -0
- package/src/harness/pipeline.ts +348 -0
- package/src/harness/project-paths.ts +235 -0
- package/src/harness/stage-runner.ts +107 -0
- package/src/harness/stages/design.ts +386 -0
- package/src/harness/stages/discover.ts +454 -0
- package/src/harness/stages/implement.ts +162 -0
- package/src/harness/stages/plan.ts +335 -0
- package/src/harness/stages/research.ts +263 -0
- package/src/harness/stages/validate.ts +684 -0
- package/src/harness/storage.ts +467 -0
- package/src/harness/tools.ts +426 -0
- package/src/lsp/bridge.ts +56 -95
- package/src/lsp/capabilities.ts +108 -0
- package/src/lsp/contracts.ts +35 -0
- package/src/lsp/detector.ts +8 -12
- package/src/markdown-frontmatter.ts +68 -0
- package/src/mempalace/bridge.ts +135 -0
- package/src/mempalace/config.ts +75 -0
- package/src/mempalace/format.ts +163 -0
- package/src/mempalace/hooks.ts +370 -0
- package/src/mempalace/installer-helper.ts +194 -0
- package/src/mempalace/python/mempalace_bridge.py +440 -0
- package/src/mempalace/runtime.ts +565 -0
- package/src/mempalace/schema.ts +268 -0
- package/src/mempalace/session-summary.ts +198 -0
- package/src/mempalace/tool.ts +186 -0
- package/src/mempalace/uv.ts +256 -0
- package/src/migrate/runner.ts +354 -0
- package/src/planning/approval-flow.ts +206 -9
- package/src/planning/plan-writer-prompt.ts +4 -3
- package/src/planning/planning-ask-tool.ts +39 -0
- package/src/planning/render-markdown.ts +74 -0
- package/src/planning/spec.ts +42 -0
- package/src/planning/system-prompt.ts +11 -8
- package/src/planning/validate.ts +84 -0
- package/src/platform/omp.ts +15 -2
- package/src/platform/system-prompt.ts +37 -0
- package/src/platform/test-utils.ts +3 -0
- package/src/platform/types.ts +6 -1
- package/src/qa/config.ts +12 -6
- package/src/qa/detect-app-type.ts +13 -6
- package/src/qa/matrix.ts +12 -6
- package/src/qa/prompt-builder.ts +28 -30
- package/src/qa/scripts/dev-server-utils.ts +72 -0
- package/src/qa/scripts/run-e2e-tests.ts +226 -0
- package/src/qa/scripts/start-dev-server.ts +138 -0
- package/src/qa/scripts/stop-dev-server.ts +77 -0
- package/src/qa/session.ts +13 -7
- package/src/quality/ai-setup.ts +27 -25
- package/src/quality/contracts.ts +34 -0
- package/src/quality/gates/ai-review.ts +20 -58
- package/src/quality/gates/command.ts +249 -46
- package/src/quality/review-gates.ts +18 -2
- package/src/quality/runner.ts +63 -22
- package/src/quality/schemas.ts +37 -2
- package/src/quality/setup.ts +96 -16
- package/src/release/changelog.ts +1 -1
- package/src/release/channels/custom.ts +13 -3
- package/src/release/channels/types.ts +5 -0
- package/src/release/contracts.ts +90 -0
- package/src/release/executor.ts +122 -45
- package/src/release/prompt.ts +18 -2
- package/src/release/targets.ts +86 -0
- package/src/release/version.ts +96 -71
- package/src/review/agent-loader.ts +221 -109
- package/src/review/fixer.ts +10 -6
- package/src/review/multi-agent-runner.ts +114 -13
- package/src/review/output.ts +12 -139
- package/src/review/runner.ts +12 -6
- package/src/review/scope.ts +144 -24
- package/src/review/types.ts +1 -20
- package/src/review/validator.ts +12 -6
- package/src/storage/fix-pr-sessions.ts +21 -14
- package/src/storage/plans.ts +14 -5
- package/src/storage/qa-sessions.ts +25 -19
- package/src/storage/reliability-metrics.ts +180 -0
- package/src/storage/reports.ts +8 -7
- package/src/storage/review-sessions.ts +55 -20
- package/src/tool-catalog/active-tool-controller.ts +164 -0
- package/src/tool-catalog/active-tool-planner.ts +212 -0
- package/src/tool-catalog/tool-groups.ts +102 -0
- package/src/types.ts +1399 -5
- package/src/ui-design/backend-adapter.ts +78 -0
- package/src/ui-design/backends/local-html.ts +82 -0
- package/src/ui-design/backends/pencil-mcp.ts +111 -0
- package/src/ui-design/components-scanner.ts +124 -0
- package/src/ui-design/config.ts +55 -0
- package/src/ui-design/pen-scanner.ts +95 -0
- package/src/ui-design/pen-selector.ts +72 -0
- package/src/ui-design/prompt-builder.ts +73 -0
- package/src/ui-design/scanner.ts +136 -0
- package/src/ui-design/session.ts +974 -0
- package/src/ui-design/system-prompt.ts +312 -0
- package/src/ui-design/tokens-scanner.ts +181 -0
- package/src/ui-design/types.ts +96 -0
- package/src/ultraplan/agent-catalog.ts +522 -0
- package/src/ultraplan/authoring/agent-catalog.ts +310 -0
- package/src/ultraplan/authoring/authoring-tools.ts +552 -0
- package/src/ultraplan/authoring/command-handlers.ts +339 -0
- package/src/ultraplan/authoring/markdown.ts +510 -0
- package/src/ultraplan/authoring/model.ts +162 -0
- package/src/ultraplan/authoring/pipeline.ts +319 -0
- package/src/ultraplan/authoring/stage-runner.ts +141 -0
- package/src/ultraplan/authoring/stages/approve.ts +249 -0
- package/src/ultraplan/authoring/stages/discover.ts +289 -0
- package/src/ultraplan/authoring/stages/intake.ts +203 -0
- package/src/ultraplan/authoring/stages/research.ts +399 -0
- package/src/ultraplan/authoring/stages/review.ts +333 -0
- package/src/ultraplan/authoring/stages/scout.ts +188 -0
- package/src/ultraplan/authoring/stages/synthesize.ts +348 -0
- package/src/ultraplan/authoring/storage.ts +594 -0
- package/src/ultraplan/authoring/synth-gate.ts +165 -0
- package/src/ultraplan/authoring-draft.ts +653 -0
- package/src/ultraplan/authoring-persist.ts +180 -0
- package/src/ultraplan/authoring-tool.ts +608 -0
- package/src/ultraplan/authoring-wizard.ts +587 -0
- package/src/ultraplan/batch/merge.ts +98 -0
- package/src/ultraplan/batch/planner.ts +150 -0
- package/src/ultraplan/batch/presenter.ts +97 -0
- package/src/ultraplan/batch/storage.ts +420 -0
- package/src/ultraplan/batch/supervisor.ts +317 -0
- package/src/ultraplan/batch/worker.ts +26 -0
- package/src/ultraplan/batch/worktree.ts +110 -0
- package/src/ultraplan/contracts.ts +1593 -0
- package/src/ultraplan/default-agents/authoring/discoverer.md +12 -0
- package/src/ultraplan/default-agents/authoring/intake.md +12 -0
- package/src/ultraplan/default-agents/authoring/planner.md +12 -0
- package/src/ultraplan/default-agents/authoring/researcher.md +12 -0
- package/src/ultraplan/default-agents/authoring/scope-checker.md +12 -0
- package/src/ultraplan/default-agents/authoring/scout.md +12 -0
- package/src/ultraplan/default-agents/authoring/structure-checker.md +12 -0
- package/src/ultraplan/default-agents/authoring/tdd-checker.md +12 -0
- package/src/ultraplan/default-agents/backend-domain-reviewer.md +10 -0
- package/src/ultraplan/default-agents/backend-executor.md +10 -0
- package/src/ultraplan/default-agents/backend-stack-reviewer.md +10 -0
- package/src/ultraplan/default-agents/backend-tester.md +10 -0
- package/src/ultraplan/default-agents/frontend-domain-reviewer.md +10 -0
- package/src/ultraplan/default-agents/frontend-executor.md +10 -0
- package/src/ultraplan/default-agents/frontend-stack-reviewer.md +10 -0
- package/src/ultraplan/default-agents/frontend-tester.md +10 -0
- package/src/ultraplan/default-agents/infrastructure-domain-reviewer.md +10 -0
- package/src/ultraplan/default-agents/infrastructure-executor.md +10 -0
- package/src/ultraplan/default-agents/infrastructure-stack-reviewer.md +10 -0
- package/src/ultraplan/default-agents/infrastructure-tester.md +10 -0
- package/src/ultraplan/execution/contract.ts +71 -0
- package/src/ultraplan/execution/policy.ts +217 -0
- package/src/ultraplan/execution/runtime-tools.ts +107 -0
- package/src/ultraplan/execution/session-runner.ts +281 -0
- package/src/ultraplan/next-router.ts +85 -0
- package/src/ultraplan/presenter.ts +359 -0
- package/src/ultraplan/project-paths.ts +342 -0
- package/src/ultraplan/runtime/active-execution.ts +72 -0
- package/src/ultraplan/runtime/apply-mutation.ts +416 -0
- package/src/ultraplan/runtime/blockers.ts +243 -0
- package/src/ultraplan/runtime/hook-bridge.ts +486 -0
- package/src/ultraplan/runtime/launch-context.ts +207 -0
- package/src/ultraplan/runtime/migration.ts +524 -0
- package/src/ultraplan/runtime/normalize.ts +281 -0
- package/src/ultraplan/runtime/proof.ts +260 -0
- package/src/ultraplan/runtime/reducer.ts +416 -0
- package/src/ultraplan/runtime/repair.ts +251 -0
- package/src/ultraplan/runtime/tracker-storage.ts +368 -0
- package/src/ultraplan/session-selection.ts +291 -0
- package/src/ultraplan/storage.ts +374 -0
- package/src/utils/editor.ts +38 -0
- package/src/utils/executable.ts +80 -0
- package/src/utils/paths.ts +1 -20
- package/src/utils/shell.ts +31 -0
- package/src/visual/companion.ts +2 -1
- package/src/visual/scripts/frame-template.html +60 -0
- package/src/visual/scripts/index.js +59 -13
- package/src/visual/scripts/package.json +3 -0
- package/src/visual/start-server.ts +2 -1
- package/src/workspace/git-scope.ts +64 -0
- package/src/workspace/locks.ts +23 -0
- package/src/workspace/package-manager.ts +117 -0
- package/src/workspace/path-mapping.ts +75 -0
- package/src/workspace/project-slug.ts +92 -0
- package/src/workspace/repo-root.ts +137 -0
- package/src/workspace/selector.ts +115 -0
- package/src/workspace/state-paths.ts +118 -0
- package/src/workspace/targets.ts +313 -0
- package/src/fix-pr/scripts/diff-comments.sh +0 -33
- package/src/fix-pr/scripts/fetch-pr-comments.sh +0 -25
- package/src/fix-pr/scripts/trigger-review.sh +0 -36
- package/src/fix-pr/scripts/wait-and-check.sh +0 -37
- package/src/qa/scripts/detect-app-type.sh +0 -68
- package/src/qa/scripts/discover-routes.sh +0 -143
- package/src/qa/scripts/run-e2e-tests.sh +0 -131
- package/src/qa/scripts/start-dev-server.sh +0 -46
- package/src/qa/scripts/stop-dev-server.sh +0 -36
- package/src/review/prompts/fix-output-schema.md +0 -18
- package/src/review/prompts/review-output-schema.md +0 -38
- package/src/review/template.ts +0 -15
- /package/src/{review → ai}/prompts/invalid-output-retry.md +0 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
UltraPlanBatchNode,
|
|
3
|
+
UltraPlanBatchNodeBlockerKind,
|
|
4
|
+
UltraPlanBatchRun,
|
|
5
|
+
} from "../../types.js";
|
|
6
|
+
import type { UltraPlanRunOutcome } from "../execution/session-runner.js";
|
|
7
|
+
import { computeUltraPlanBatchEligibleFrontier } from "./planner.js";
|
|
8
|
+
import type { UltraPlanBatchMergeResult } from "./merge.js";
|
|
9
|
+
|
|
10
|
+
export type UltraPlanBatchWorkerOutcome =
|
|
11
|
+
| UltraPlanRunOutcome
|
|
12
|
+
| {
|
|
13
|
+
kind: "blocked";
|
|
14
|
+
blockerKind: Exclude<UltraPlanBatchNodeBlockerKind, "dependency" | "merge">;
|
|
15
|
+
summary: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export interface UltraPlanBatchSupervisorDeps {
|
|
19
|
+
computeFrontier(run: UltraPlanBatchRun): UltraPlanBatchNode[];
|
|
20
|
+
runWorker(
|
|
21
|
+
node: UltraPlanBatchNode,
|
|
22
|
+
run: UltraPlanBatchRun,
|
|
23
|
+
): Promise<UltraPlanBatchWorkerOutcome | null> | UltraPlanBatchWorkerOutcome | null;
|
|
24
|
+
mergeNode(
|
|
25
|
+
node: UltraPlanBatchNode,
|
|
26
|
+
run: UltraPlanBatchRun,
|
|
27
|
+
): Promise<UltraPlanBatchMergeResult | null> | UltraPlanBatchMergeResult | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface RunUltraPlanBatchSupervisorInput {
|
|
31
|
+
run: UltraPlanBatchRun;
|
|
32
|
+
deps?: Partial<UltraPlanBatchSupervisorDeps>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ResumeUltraPlanBatchSupervisorInput {
|
|
36
|
+
run: UltraPlanBatchRun;
|
|
37
|
+
deps?: Partial<UltraPlanBatchSupervisorDeps>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function buildDeps(overrides: RunUltraPlanBatchSupervisorInput["deps"]): UltraPlanBatchSupervisorDeps {
|
|
41
|
+
return {
|
|
42
|
+
computeFrontier: overrides?.computeFrontier ?? computeUltraPlanBatchEligibleFrontier,
|
|
43
|
+
runWorker: overrides?.runWorker ?? (async () => null),
|
|
44
|
+
mergeNode: overrides?.mergeNode ?? (async () => null),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function cloneRun(run: UltraPlanBatchRun): UltraPlanBatchRun {
|
|
49
|
+
return {
|
|
50
|
+
...run,
|
|
51
|
+
nodes: run.nodes.map((node) => ({ ...node })),
|
|
52
|
+
waves: run.waves.map((wave) => ({ ...wave, sessionIds: [...wave.sessionIds] })),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function clearBatchBlocker(run: UltraPlanBatchRun): void {
|
|
57
|
+
run.batchBlockerCode = null;
|
|
58
|
+
run.batchBlockerSummary = null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function assertLegalStateTransition(run: UltraPlanBatchRun): void {
|
|
62
|
+
const allTerminal = run.nodes.every((node) => node.state === "merged" || node.state === "abandoned");
|
|
63
|
+
if (run.state === "blocked" && !run.batchResumeRequestedAt && allTerminal) {
|
|
64
|
+
throw new Error("blocked batch cannot complete without resume approval");
|
|
65
|
+
}
|
|
66
|
+
if (
|
|
67
|
+
(run.state === "paused" || run.state === "blocked")
|
|
68
|
+
&& !run.batchResumeRequestedAt
|
|
69
|
+
&& run.nodes.some((node) => node.state === "merge-pending")
|
|
70
|
+
) {
|
|
71
|
+
throw new Error(`${run.state} batch cannot enter merge-pending without resume approval`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function findNode(run: UltraPlanBatchRun, sessionId: string): UltraPlanBatchNode {
|
|
76
|
+
const node = run.nodes.find((candidate) => candidate.sessionId === sessionId);
|
|
77
|
+
if (!node) {
|
|
78
|
+
throw new Error(`unknown batch node ${sessionId}`);
|
|
79
|
+
}
|
|
80
|
+
return node;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function countRunningWorkers(run: UltraPlanBatchRun): number {
|
|
84
|
+
return run.nodes.filter((node) => node.state === "preparing" || node.state === "running").length;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function settleMergeResult(run: UltraPlanBatchRun, node: UltraPlanBatchNode, result: UltraPlanBatchMergeResult): void {
|
|
88
|
+
if (result.kind === "merged") {
|
|
89
|
+
node.state = "merged";
|
|
90
|
+
node.blockerKind = null;
|
|
91
|
+
node.blockerSummary = null;
|
|
92
|
+
node.worktreePath = result.worktreePath;
|
|
93
|
+
run.currentBaseHead = result.currentBaseHead;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
node.state = "blocked";
|
|
98
|
+
node.blockerSummary = result.summary;
|
|
99
|
+
node.blockerKind = result.code === "merge-blocked" ? "merge" : "supervisor";
|
|
100
|
+
node.worktreePath = result.worktreePath;
|
|
101
|
+
|
|
102
|
+
if (result.code !== "merge-blocked") {
|
|
103
|
+
run.state = "blocked";
|
|
104
|
+
run.batchBlockerCode = result.code;
|
|
105
|
+
run.batchBlockerSummary = result.summary;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
blockDependentNodes(run, node.sessionId);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function blockDependentNodes(run: UltraPlanBatchRun, dependencySessionId: string): void {
|
|
113
|
+
for (const node of run.nodes) {
|
|
114
|
+
if (!node.dependencies.includes(dependencySessionId)) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (node.state === "merged" || node.state === "abandoned") {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
node.state = "blocked";
|
|
121
|
+
node.blockerKind = "dependency";
|
|
122
|
+
node.blockerSummary = `waiting for ${dependencySessionId}`;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function settleWorkerOutcome(node: UltraPlanBatchNode, outcome: UltraPlanBatchWorkerOutcome | null): void {
|
|
127
|
+
if (outcome === null) {
|
|
128
|
+
node.state = "running";
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (outcome.kind === "blocked") {
|
|
133
|
+
node.state = "blocked";
|
|
134
|
+
node.blockerKind = outcome.blockerKind;
|
|
135
|
+
node.blockerSummary = outcome.summary;
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (outcome.kind === "completed") {
|
|
140
|
+
node.state = "merge-pending";
|
|
141
|
+
node.blockerKind = null;
|
|
142
|
+
node.blockerSummary = null;
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (outcome.session.state === "awaiting-user") {
|
|
147
|
+
node.state = "awaiting-user";
|
|
148
|
+
} else {
|
|
149
|
+
node.state = "blocked";
|
|
150
|
+
}
|
|
151
|
+
node.blockerKind = "session";
|
|
152
|
+
node.blockerSummary = outcome.session.blocker?.message ?? `worker returned ${outcome.session.state}`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function finalizeBatchState(run: UltraPlanBatchRun): UltraPlanBatchRun {
|
|
156
|
+
if (run.batchBlockerCode) {
|
|
157
|
+
run.state = "blocked";
|
|
158
|
+
return run;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (run.nodes.some((node) => node.state === "preparing" || node.state === "running" || node.state === "merge-pending")) {
|
|
162
|
+
run.state = "running";
|
|
163
|
+
clearBatchBlocker(run);
|
|
164
|
+
return run;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (run.nodes.every((node) => node.state === "merged" || node.state === "abandoned")) {
|
|
168
|
+
run.state = "complete";
|
|
169
|
+
clearBatchBlocker(run);
|
|
170
|
+
return run;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
run.state = "paused";
|
|
174
|
+
clearBatchBlocker(run);
|
|
175
|
+
return run;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function resetNodeForResume(node: UltraPlanBatchNode): void {
|
|
179
|
+
if (node.state === "preparing") {
|
|
180
|
+
node.state = "pending";
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (node.state === "running") {
|
|
185
|
+
node.state = "blocked";
|
|
186
|
+
node.blockerKind = "session";
|
|
187
|
+
node.blockerSummary = "restart reconciliation requires an explicit retry";
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (!node.resumeRequestedAt) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (node.state === "paused" || node.state === "awaiting-user") {
|
|
196
|
+
node.state = "pending";
|
|
197
|
+
} else if (node.state === "blocked" && node.blockerKind === "merge") {
|
|
198
|
+
node.state = "merge-pending";
|
|
199
|
+
} else if (node.state === "blocked" && node.blockerKind !== "dependency") {
|
|
200
|
+
node.state = "pending";
|
|
201
|
+
} else {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
node.blockerKind = null;
|
|
206
|
+
node.blockerSummary = null;
|
|
207
|
+
node.resumeRequestedAt = null;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function reconcileRunForResume(run: UltraPlanBatchRun): UltraPlanBatchRun {
|
|
211
|
+
const next = cloneRun(run);
|
|
212
|
+
if (next.state === "blocked" && next.batchBlockerCode !== null && next.batchResumeRequestedAt !== null) {
|
|
213
|
+
next.state = "running";
|
|
214
|
+
next.batchResumeRequestedAt = null;
|
|
215
|
+
clearBatchBlocker(next);
|
|
216
|
+
} else if (next.state === "paused") {
|
|
217
|
+
next.state = "running";
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
for (const node of next.nodes) {
|
|
221
|
+
resetNodeForResume(node);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return next;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function hasInFlightWork(run: UltraPlanBatchRun): boolean {
|
|
228
|
+
return run.nodes.some((node) => node.state === "preparing" || node.state === "running" || node.state === "merge-pending");
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async function runSupervisorPass(input: RunUltraPlanBatchSupervisorInput): Promise<UltraPlanBatchRun> {
|
|
232
|
+
assertLegalStateTransition(input.run);
|
|
233
|
+
const deps = buildDeps(input.deps);
|
|
234
|
+
const next = cloneRun(input.run);
|
|
235
|
+
|
|
236
|
+
const mergePending = next.nodes.find((node) => node.state === "merge-pending");
|
|
237
|
+
if (mergePending) {
|
|
238
|
+
const mergeResult = await deps.mergeNode(mergePending, next);
|
|
239
|
+
if (mergeResult) {
|
|
240
|
+
settleMergeResult(next, mergePending, mergeResult);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const blockNewLaunches = next.state === "blocked" && next.batchBlockerCode !== null;
|
|
245
|
+
|
|
246
|
+
const inFlightNodes = next.nodes.filter((candidate) => candidate.state === "preparing" || candidate.state === "running");
|
|
247
|
+
const inFlightOutcomes = await Promise.all(
|
|
248
|
+
inFlightNodes.map(async (node) => [node.sessionId, await deps.runWorker(node, next)] as const),
|
|
249
|
+
);
|
|
250
|
+
for (const [sessionId, outcome] of inFlightOutcomes) {
|
|
251
|
+
settleWorkerOutcome(findNode(next, sessionId), outcome);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (!blockNewLaunches) {
|
|
255
|
+
const availableSlots = Math.max(0, next.maxParallelism - countRunningWorkers(next));
|
|
256
|
+
const frontierNodes = deps.computeFrontier(next)
|
|
257
|
+
.slice(0, availableSlots)
|
|
258
|
+
.map((node) => findNode(next, node.sessionId));
|
|
259
|
+
for (const node of frontierNodes) {
|
|
260
|
+
node.blockerKind = null;
|
|
261
|
+
node.blockerSummary = null;
|
|
262
|
+
}
|
|
263
|
+
const frontierOutcomes = await Promise.all(
|
|
264
|
+
frontierNodes.map(async (node) => [node.sessionId, await deps.runWorker(node, next)] as const),
|
|
265
|
+
);
|
|
266
|
+
for (const [sessionId, outcome] of frontierOutcomes) {
|
|
267
|
+
settleWorkerOutcome(findNode(next, sessionId), outcome);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return finalizeBatchState(next);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export async function runUltraPlanBatchSupervisor(
|
|
275
|
+
input: RunUltraPlanBatchSupervisorInput,
|
|
276
|
+
): Promise<UltraPlanBatchRun> {
|
|
277
|
+
return runSupervisorPass(input);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export async function resumeUltraPlanBatchSupervisor(
|
|
281
|
+
input: ResumeUltraPlanBatchSupervisorInput,
|
|
282
|
+
): Promise<UltraPlanBatchRun> {
|
|
283
|
+
return runSupervisorPass({
|
|
284
|
+
run: reconcileRunForResume(input.run),
|
|
285
|
+
deps: input.deps,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export function abandonUltraPlanBatchRun(run: UltraPlanBatchRun): UltraPlanBatchRun {
|
|
290
|
+
if (hasInFlightWork(run)) {
|
|
291
|
+
throw new Error("cannot abandon a batch while work is in flight");
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const next = cloneRun(run);
|
|
295
|
+
next.state = "abandoned";
|
|
296
|
+
clearBatchBlocker(next);
|
|
297
|
+
next.nodes = next.nodes.map((node) => ({
|
|
298
|
+
...node,
|
|
299
|
+
state: node.state === "merged" ? "merged" : "abandoned",
|
|
300
|
+
blockerKind: null,
|
|
301
|
+
blockerSummary: null,
|
|
302
|
+
}));
|
|
303
|
+
return next;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export function abandonUltraPlanBatchNode(run: UltraPlanBatchRun, sessionId: string): UltraPlanBatchRun {
|
|
307
|
+
if (hasInFlightWork(run)) {
|
|
308
|
+
throw new Error("cannot abandon a batch node while work is in flight");
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const next = cloneRun(run);
|
|
312
|
+
const node = findNode(next, sessionId);
|
|
313
|
+
node.state = "abandoned";
|
|
314
|
+
node.blockerKind = null;
|
|
315
|
+
node.blockerSummary = null;
|
|
316
|
+
return finalizeBatchState(next);
|
|
317
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Platform } from "../../platform/types.js";
|
|
2
|
+
import {
|
|
3
|
+
runUltraPlanSession,
|
|
4
|
+
type RunUltraPlanSessionInput,
|
|
5
|
+
type UltraPlanRunOutcome,
|
|
6
|
+
} from "../execution/session-runner.js";
|
|
7
|
+
|
|
8
|
+
export interface RunUltraPlanBatchWorkerInput {
|
|
9
|
+
platform: Platform;
|
|
10
|
+
sessionId: string;
|
|
11
|
+
worktreeCwd: string;
|
|
12
|
+
deps?: {
|
|
13
|
+
runSession?: (input: RunUltraPlanSessionInput) => Promise<UltraPlanRunOutcome>;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function runUltraPlanBatchWorker(
|
|
18
|
+
input: RunUltraPlanBatchWorkerInput,
|
|
19
|
+
): Promise<UltraPlanRunOutcome> {
|
|
20
|
+
const runSession = input.deps?.runSession ?? runUltraPlanSession;
|
|
21
|
+
return runSession({
|
|
22
|
+
platform: input.platform,
|
|
23
|
+
cwd: input.worktreeCwd,
|
|
24
|
+
sessionId: input.sessionId,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { assertSafeRef } from "../../git/sanitize.js";
|
|
4
|
+
|
|
5
|
+
export interface UltraPlanBatchWorktreeDeps {
|
|
6
|
+
exists(candidate: string): boolean;
|
|
7
|
+
hasGitEntry(worktreePath: string): boolean;
|
|
8
|
+
readBranchName(worktreePath: string): string | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ResolveUltraPlanBatchWorktreeRootDirInput {
|
|
12
|
+
repoRoot: string;
|
|
13
|
+
globalWorktreesRoot: string;
|
|
14
|
+
deps?: Partial<UltraPlanBatchWorktreeDeps>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ResolveUltraPlanBatchWorktreePathInput extends ResolveUltraPlanBatchWorktreeRootDirInput {
|
|
18
|
+
runId: string;
|
|
19
|
+
sessionId: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type UltraPlanBatchWorktreePreparation =
|
|
23
|
+
| { kind: "create"; branchName: string; worktreePath: string }
|
|
24
|
+
| { kind: "reused"; branchName: string; worktreePath: string }
|
|
25
|
+
| { kind: "blocked"; code: "partial-state" | "mismatched-state"; branchName: string; worktreePath: string; summary: string };
|
|
26
|
+
|
|
27
|
+
function buildDeps(overrides: ResolveUltraPlanBatchWorktreeRootDirInput["deps"]): UltraPlanBatchWorktreeDeps {
|
|
28
|
+
return {
|
|
29
|
+
exists: overrides?.exists ?? ((candidate) => fs.existsSync(candidate)),
|
|
30
|
+
hasGitEntry: overrides?.hasGitEntry ?? ((worktreePath) => fs.existsSync(path.join(worktreePath, ".git"))),
|
|
31
|
+
readBranchName: overrides?.readBranchName ?? (() => null),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function pathApiFor(basePath: string): typeof path.posix | typeof path {
|
|
36
|
+
if (basePath.startsWith("/") && !basePath.startsWith("//") && !basePath.includes("\\")) {
|
|
37
|
+
return path.posix;
|
|
38
|
+
}
|
|
39
|
+
return path;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function joinLike(basePath: string, ...segments: string[]): string {
|
|
43
|
+
return pathApiFor(basePath).join(basePath, ...segments);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function basenameLike(basePath: string): string {
|
|
47
|
+
return pathApiFor(basePath).basename(basePath);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
export function buildUltraPlanBatchBranchName(runId: string, sessionId: string): string {
|
|
52
|
+
const branchName = `ultraplan/${runId}/${sessionId}`;
|
|
53
|
+
assertSafeRef(branchName, "branchName");
|
|
54
|
+
return branchName;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function resolveUltraPlanBatchWorktreeRootDir(input: ResolveUltraPlanBatchWorktreeRootDirInput): string {
|
|
58
|
+
const deps = buildDeps(input.deps);
|
|
59
|
+
const dotWorktrees = joinLike(input.repoRoot, ".worktrees");
|
|
60
|
+
if (deps.exists(dotWorktrees)) {
|
|
61
|
+
return dotWorktrees;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const worktrees = joinLike(input.repoRoot, "worktrees");
|
|
65
|
+
if (deps.exists(worktrees)) {
|
|
66
|
+
return worktrees;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return joinLike(input.globalWorktreesRoot, basenameLike(input.repoRoot));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function resolveUltraPlanBatchWorktreePath(input: ResolveUltraPlanBatchWorktreePathInput): string {
|
|
73
|
+
const rootDir = resolveUltraPlanBatchWorktreeRootDir(input);
|
|
74
|
+
return joinLike(rootDir, `${input.runId}-${input.sessionId}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function prepareUltraPlanBatchWorktree(input: ResolveUltraPlanBatchWorktreePathInput): UltraPlanBatchWorktreePreparation {
|
|
78
|
+
const deps = buildDeps(input.deps);
|
|
79
|
+
const branchName = buildUltraPlanBatchBranchName(input.runId, input.sessionId);
|
|
80
|
+
const worktreePath = resolveUltraPlanBatchWorktreePath(input);
|
|
81
|
+
|
|
82
|
+
if (!deps.exists(worktreePath)) {
|
|
83
|
+
return { kind: "create", branchName, worktreePath };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!deps.hasGitEntry(worktreePath)) {
|
|
87
|
+
return {
|
|
88
|
+
kind: "blocked",
|
|
89
|
+
code: "partial-state",
|
|
90
|
+
branchName,
|
|
91
|
+
worktreePath,
|
|
92
|
+
summary: `Existing worktree path ${worktreePath} is missing git metadata.`,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const existingBranchName = deps.readBranchName(worktreePath);
|
|
97
|
+
if (existingBranchName === branchName) {
|
|
98
|
+
return { kind: "reused", branchName, worktreePath };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
kind: "blocked",
|
|
103
|
+
code: existingBranchName ? "mismatched-state" : "partial-state",
|
|
104
|
+
branchName,
|
|
105
|
+
worktreePath,
|
|
106
|
+
summary: existingBranchName
|
|
107
|
+
? `Existing worktree path ${worktreePath} is bound to ${existingBranchName}, expected ${branchName}.`
|
|
108
|
+
: `Existing worktree path ${worktreePath} is missing git metadata.`,
|
|
109
|
+
};
|
|
110
|
+
}
|