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,72 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ResolvedUltraPlanSlotBinding,
|
|
3
|
+
UltraPlanLaunchContext,
|
|
4
|
+
} from "../../types.js";
|
|
5
|
+
import type { UltraPlanExecutionTarget } from "../execution/policy.js";
|
|
6
|
+
|
|
7
|
+
export interface ActiveUltraPlanExecution {
|
|
8
|
+
sessionId: string;
|
|
9
|
+
cwd: string;
|
|
10
|
+
target: UltraPlanExecutionTarget;
|
|
11
|
+
launchContext: UltraPlanLaunchContext;
|
|
12
|
+
slotBinding?: ResolvedUltraPlanSlotBinding | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const activeExecutions = new Map<string, ActiveUltraPlanExecution>();
|
|
16
|
+
|
|
17
|
+
function buildActiveExecutionKey(sessionId: string, cwd: string, attemptId: string): string {
|
|
18
|
+
return `${sessionId}\u0000${cwd}\u0000${attemptId}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function buildExecutionKey(execution: ActiveUltraPlanExecution): string {
|
|
22
|
+
return buildActiveExecutionKey(execution.sessionId, execution.cwd, execution.launchContext.attemptId);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function bindActiveUltraPlanExecution(execution: ActiveUltraPlanExecution): void {
|
|
26
|
+
activeExecutions.set(buildExecutionKey(execution), execution);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function listActiveUltraPlanExecutions(): ActiveUltraPlanExecution[] {
|
|
30
|
+
return [...activeExecutions.values()];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function readActiveUltraPlanExecution(): ActiveUltraPlanExecution | null {
|
|
34
|
+
if (activeExecutions.size !== 1) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return activeExecutions.values().next().value ?? null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function readActiveUltraPlanExecutionForSession(sessionId: string, cwd: string): ActiveUltraPlanExecution | null {
|
|
41
|
+
const matches = listActiveUltraPlanExecutions().filter((execution) => execution.sessionId === sessionId && execution.cwd === cwd);
|
|
42
|
+
return matches.length === 1 ? matches[0]! : null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function readActiveUltraPlanExecutionForAttempt(
|
|
46
|
+
sessionId: string,
|
|
47
|
+
cwd: string,
|
|
48
|
+
attemptId: string,
|
|
49
|
+
): ActiveUltraPlanExecution | null {
|
|
50
|
+
return activeExecutions.get(buildActiveExecutionKey(sessionId, cwd, attemptId)) ?? null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function readActiveUltraPlanExecutionForCwd(cwd: string | null): ActiveUltraPlanExecution | null {
|
|
54
|
+
if (!cwd) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
const matches = listActiveUltraPlanExecutions().filter((execution) => execution.cwd === cwd);
|
|
58
|
+
return matches.length === 1 ? matches[0]! : null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function clearMatchedActiveUltraPlanExecution(sessionId: string, cwd: string, attemptId: string): void {
|
|
62
|
+
activeExecutions.delete(buildActiveExecutionKey(sessionId, cwd, attemptId));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function clearActiveUltraPlanExecution(execution?: ActiveUltraPlanExecution): void {
|
|
66
|
+
if (!execution) {
|
|
67
|
+
activeExecutions.clear();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
clearMatchedActiveUltraPlanExecution(execution.sessionId, execution.cwd, execution.launchContext.attemptId);
|
|
72
|
+
}
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import type { Platform } from "../../platform/types.js";
|
|
4
|
+
import type {
|
|
5
|
+
UltraPlanAttemptRecord,
|
|
6
|
+
UltraPlanCursor,
|
|
7
|
+
UltraPlanDomain,
|
|
8
|
+
UltraPlanHookObservation,
|
|
9
|
+
UltraPlanManifest,
|
|
10
|
+
UltraPlanManifestReviewReference,
|
|
11
|
+
UltraPlanMutationPlan,
|
|
12
|
+
UltraPlanPendingMutation,
|
|
13
|
+
UltraPlanRuntimeTracker,
|
|
14
|
+
UltraPlanScenario,
|
|
15
|
+
UltraPlanSessionState,
|
|
16
|
+
UltraPlanStack,
|
|
17
|
+
} from "../../types.js";
|
|
18
|
+
import { hasRequiredUltraPlanScenarioProof } from "../contracts.js";
|
|
19
|
+
import {
|
|
20
|
+
getUltraplanDomainReviewPath,
|
|
21
|
+
getUltraplanManifestPath,
|
|
22
|
+
getUltraplanStackReviewPath,
|
|
23
|
+
} from "../project-paths.js";
|
|
24
|
+
import { resolveUltraPlanCurrentCursor } from "../session-selection.js";
|
|
25
|
+
import {
|
|
26
|
+
loadUltraPlanAuthoredArtifact,
|
|
27
|
+
loadUltraPlanManifest,
|
|
28
|
+
saveUltraPlanAuthoredArtifact,
|
|
29
|
+
saveUltraPlanManifest,
|
|
30
|
+
validateUltraPlanManifestReviewReferences,
|
|
31
|
+
} from "../storage.js";
|
|
32
|
+
import {
|
|
33
|
+
appendExecutionLog,
|
|
34
|
+
appendHookLog,
|
|
35
|
+
loadTracker,
|
|
36
|
+
saveTrackerAtomic,
|
|
37
|
+
} from "./tracker-storage.js";
|
|
38
|
+
|
|
39
|
+
export interface ApplyUltraPlanMutationInput {
|
|
40
|
+
platform: Platform;
|
|
41
|
+
cwd: string;
|
|
42
|
+
sessionId: string;
|
|
43
|
+
observation: UltraPlanHookObservation;
|
|
44
|
+
mutationPlan: UltraPlanMutationPlan;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function applyUltraPlanMutation(input: ApplyUltraPlanMutationInput): void {
|
|
48
|
+
const tracker = loadTrackerOrEmpty(input);
|
|
49
|
+
if (tracker.appliedFingerprints.includes(input.observation.fingerprint)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
assertStorageResult(appendHookLog(input.platform.paths, input.cwd, input.sessionId, input.observation));
|
|
54
|
+
if (input.mutationPlan.kind !== "noop") {
|
|
55
|
+
assertStorageResult(
|
|
56
|
+
appendExecutionLog(input.platform.paths, input.cwd, input.sessionId, buildExecutionLogEntry(input)),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const stagedTracker = buildNextTracker(tracker, input);
|
|
61
|
+
const needsCanonicalWrites = requiresPendingMutation(input.mutationPlan);
|
|
62
|
+
|
|
63
|
+
if (!needsCanonicalWrites) {
|
|
64
|
+
assertStorageResult(saveTrackerAtomic(input.platform.paths, input.cwd, input.sessionId, stagedTracker));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Stage tracker truth first so an interrupted manifest/authored write leaves a durable replay point.
|
|
69
|
+
assertStorageResult(saveTrackerAtomic(input.platform.paths, input.cwd, input.sessionId, stagedTracker));
|
|
70
|
+
|
|
71
|
+
const authoredResult = loadUltraPlanAuthoredArtifact(input.platform.paths, input.cwd, input.sessionId);
|
|
72
|
+
if (!authoredResult.ok) {
|
|
73
|
+
throwStorageError(authoredResult.error);
|
|
74
|
+
}
|
|
75
|
+
const manifestResult = loadUltraPlanManifest(input.platform.paths, input.cwd, input.sessionId);
|
|
76
|
+
if (!manifestResult.ok) {
|
|
77
|
+
throwStorageError(manifestResult.error);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const nextAuthored = structuredClone(authoredResult.value);
|
|
81
|
+
const nextManifest = structuredClone(manifestResult.value);
|
|
82
|
+
|
|
83
|
+
applyScenarioStatusUpdate(nextAuthored, input.mutationPlan);
|
|
84
|
+
applyReviewStatusUpdate(input, nextManifest);
|
|
85
|
+
applyBlockerUpdate(nextManifest, input.mutationPlan);
|
|
86
|
+
|
|
87
|
+
nextManifest.updatedAt = input.observation.occurredAt;
|
|
88
|
+
nextManifest.stacks = buildManifestStacks(nextAuthored, nextManifest);
|
|
89
|
+
nextManifest.progress = buildSessionProgress(nextManifest.stacks, nextManifest.blocker);
|
|
90
|
+
nextManifest.cursor = resolveUltraPlanCurrentCursor(nextManifest, nextAuthored).cursor;
|
|
91
|
+
nextManifest.state = resolveManifestState(nextManifest, stagedTracker, input.mutationPlan.sessionStateUpdate);
|
|
92
|
+
|
|
93
|
+
assertStorageResult(validateUltraPlanManifestReviewReferences(input.platform.paths, input.cwd, input.sessionId, nextManifest));
|
|
94
|
+
|
|
95
|
+
assertStorageResult(saveUltraPlanAuthoredArtifact(input.platform.paths, input.cwd, input.sessionId, nextAuthored));
|
|
96
|
+
assertStorageResult(saveUltraPlanManifest(input.platform.paths, input.cwd, input.sessionId, nextManifest));
|
|
97
|
+
|
|
98
|
+
const finalizedTracker: UltraPlanRuntimeTracker = {
|
|
99
|
+
...stagedTracker,
|
|
100
|
+
pendingMutation: null,
|
|
101
|
+
updatedAt: input.observation.occurredAt,
|
|
102
|
+
};
|
|
103
|
+
assertStorageResult(saveTrackerAtomic(input.platform.paths, input.cwd, input.sessionId, finalizedTracker));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function loadTrackerOrEmpty(input: ApplyUltraPlanMutationInput): UltraPlanRuntimeTracker {
|
|
107
|
+
const loaded = loadTracker(input.platform.paths, input.cwd, input.sessionId);
|
|
108
|
+
if (loaded.ok) {
|
|
109
|
+
return loaded.value;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (loaded.error.kind !== "missing") {
|
|
113
|
+
const detail = loaded.error.details?.length ? `\n${loaded.error.details.join("\n")}` : "";
|
|
114
|
+
throw new Error(`${loaded.error.message}${detail}`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
version: 1,
|
|
119
|
+
sessionId: input.sessionId,
|
|
120
|
+
activeAttempt: null,
|
|
121
|
+
finalizedAttempts: [],
|
|
122
|
+
appliedFingerprints: [],
|
|
123
|
+
pendingMutation: null,
|
|
124
|
+
updatedAt: input.observation.occurredAt,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function buildNextTracker(
|
|
129
|
+
tracker: UltraPlanRuntimeTracker,
|
|
130
|
+
input: ApplyUltraPlanMutationInput,
|
|
131
|
+
): UltraPlanRuntimeTracker {
|
|
132
|
+
const { observation, mutationPlan } = input;
|
|
133
|
+
const next: UltraPlanRuntimeTracker = {
|
|
134
|
+
...tracker,
|
|
135
|
+
activeAttempt: tracker.activeAttempt ? updateActiveAttempt(tracker.activeAttempt, observation, mutationPlan) : null,
|
|
136
|
+
updatedAt: observation.occurredAt,
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
if (mutationPlan.kind === "start-attempt") {
|
|
140
|
+
next.activeAttempt = buildActiveAttempt(observation, mutationPlan);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (mutationPlan.trackerAttemptFinalization && next.activeAttempt?.attemptId === mutationPlan.trackerAttemptFinalization.attemptId) {
|
|
144
|
+
next.finalizedAttempts = [
|
|
145
|
+
...next.finalizedAttempts,
|
|
146
|
+
{
|
|
147
|
+
...next.activeAttempt,
|
|
148
|
+
outcome: mutationPlan.trackerAttemptFinalization.outcome,
|
|
149
|
+
finalizedAt: mutationPlan.trackerAttemptFinalization.finalizedAt,
|
|
150
|
+
},
|
|
151
|
+
];
|
|
152
|
+
next.activeAttempt = null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (mutationPlan.appendObservationFingerprint) {
|
|
156
|
+
next.appliedFingerprints = [
|
|
157
|
+
...next.appliedFingerprints,
|
|
158
|
+
mutationPlan.appendObservationFingerprint,
|
|
159
|
+
];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (requiresPendingMutation(mutationPlan)) {
|
|
163
|
+
next.pendingMutation = buildPendingMutation(input);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return next;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function buildActiveAttempt(
|
|
170
|
+
observation: UltraPlanHookObservation,
|
|
171
|
+
mutationPlan: UltraPlanMutationPlan,
|
|
172
|
+
): UltraPlanAttemptRecord | null {
|
|
173
|
+
if (!observation.attemptId || !observation.attemptKey) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
attemptId: observation.attemptId,
|
|
179
|
+
attemptKey: observation.attemptKey,
|
|
180
|
+
launchContext: {
|
|
181
|
+
attemptId: observation.attemptId,
|
|
182
|
+
attemptKey: observation.attemptKey,
|
|
183
|
+
sourceAgent: observation.sourceAgent,
|
|
184
|
+
launchedAt: observation.occurredAt,
|
|
185
|
+
},
|
|
186
|
+
cursorSnapshot: mutationPlan.cursorUpdate,
|
|
187
|
+
observations: [observation],
|
|
188
|
+
proofCandidates: [],
|
|
189
|
+
blockerCandidates: [],
|
|
190
|
+
outcome: null,
|
|
191
|
+
startedAt: observation.occurredAt,
|
|
192
|
+
finalizedAt: null,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function updateActiveAttempt(
|
|
197
|
+
attempt: UltraPlanAttemptRecord,
|
|
198
|
+
observation: UltraPlanHookObservation,
|
|
199
|
+
mutationPlan: UltraPlanMutationPlan,
|
|
200
|
+
): UltraPlanAttemptRecord {
|
|
201
|
+
if (!observation.attemptId || observation.attemptId !== attempt.attemptId) {
|
|
202
|
+
return attempt;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return {
|
|
206
|
+
...attempt,
|
|
207
|
+
cursorSnapshot: mutationPlan.cursorUpdate ?? attempt.cursorSnapshot,
|
|
208
|
+
observations: [...attempt.observations, observation],
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function requiresPendingMutation(mutationPlan: UltraPlanMutationPlan): boolean {
|
|
213
|
+
return mutationPlan.cursorUpdate !== null
|
|
214
|
+
|| mutationPlan.scenarioStatusUpdate !== null
|
|
215
|
+
|| mutationPlan.reviewStatusUpdate !== null
|
|
216
|
+
|| mutationPlan.blockerUpdate !== null
|
|
217
|
+
|| mutationPlan.sessionStateUpdate !== null
|
|
218
|
+
|| mutationPlan.recomputeProgress;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function buildPendingMutation(input: ApplyUltraPlanMutationInput): UltraPlanPendingMutation {
|
|
222
|
+
return {
|
|
223
|
+
attemptId: input.observation.attemptId ?? input.sessionId,
|
|
224
|
+
mutationPlan: input.mutationPlan,
|
|
225
|
+
expectedManifestFingerprint: computeManifestFingerprint(input),
|
|
226
|
+
stagedAt: input.observation.occurredAt,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function computeManifestFingerprint(input: ApplyUltraPlanMutationInput): string {
|
|
231
|
+
const manifestPath = getUltraplanManifestPath(input.platform.paths, input.cwd, input.sessionId);
|
|
232
|
+
if (!fs.existsSync(manifestPath)) {
|
|
233
|
+
return `missing:${manifestPath}`;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return `sha256:${createHash("sha256").update(fs.readFileSync(manifestPath)).digest("hex")}`;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function applyScenarioStatusUpdate(authored: { stacks: UltraPlanStack[] }, mutationPlan: UltraPlanMutationPlan): void {
|
|
240
|
+
const update = mutationPlan.scenarioStatusUpdate;
|
|
241
|
+
if (!update) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const stack = authored.stacks.find((candidate) => candidate.stack === update.stack);
|
|
246
|
+
const domain = stack?.domains.find((candidate) => candidate.id === update.domainId);
|
|
247
|
+
const scenarios = domain?.[update.level];
|
|
248
|
+
const scenario = scenarios?.find((candidate) => candidate.id === update.scenarioId);
|
|
249
|
+
if (!scenario) {
|
|
250
|
+
throw new Error(`UltraPlan scenario not found for mutation: ${update.stack}/${update.domainId}/${update.level}/${update.scenarioId}`);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
scenario.status = update.nextStatus;
|
|
254
|
+
if (update.appendProof) {
|
|
255
|
+
scenario.proofs = [...scenario.proofs, update.appendProof];
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function applyReviewStatusUpdate(input: ApplyUltraPlanMutationInput, manifest: UltraPlanManifest): void {
|
|
260
|
+
const update = input.mutationPlan.reviewStatusUpdate;
|
|
261
|
+
if (!update) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (update.type === "domain" && !update.domainId) {
|
|
266
|
+
throw new Error("Domain review updates must include a domainId");
|
|
267
|
+
}
|
|
268
|
+
if (update.type === "stack" && update.domainId !== null) {
|
|
269
|
+
throw new Error("Stack review updates must not include a domainId");
|
|
270
|
+
}
|
|
271
|
+
if (update.nextStatus === "passed" && !update.artifactRef) {
|
|
272
|
+
throw new Error("Passed review updates must include an artifactRef");
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const existingIndex = manifest.reviews.findIndex(
|
|
276
|
+
(candidate) => candidate.type === update.type && candidate.stack === update.stack && candidate.domainId === update.domainId,
|
|
277
|
+
);
|
|
278
|
+
const reviewPath = update.artifactRef
|
|
279
|
+
?? (update.type === "domain"
|
|
280
|
+
? getUltraplanDomainReviewPath(input.platform.paths, input.cwd, input.sessionId, update.stack, update.domainId!)
|
|
281
|
+
: getUltraplanStackReviewPath(input.platform.paths, input.cwd, input.sessionId, update.stack));
|
|
282
|
+
|
|
283
|
+
const nextReference: UltraPlanManifestReviewReference = {
|
|
284
|
+
type: update.type,
|
|
285
|
+
stack: update.stack,
|
|
286
|
+
domainId: update.type === "domain" ? update.domainId! : null,
|
|
287
|
+
path: reviewPath,
|
|
288
|
+
status: update.nextStatus,
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
if (existingIndex === -1) {
|
|
292
|
+
manifest.reviews.push(nextReference);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
manifest.reviews[existingIndex] = nextReference;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function applyBlockerUpdate(manifest: UltraPlanManifest, mutationPlan: UltraPlanMutationPlan): void {
|
|
300
|
+
if (!mutationPlan.blockerUpdate) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
manifest.blocker = mutationPlan.blockerUpdate.nextValue;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function buildManifestStacks(authored: { stacks: UltraPlanStack[] }, manifest: UltraPlanManifest): UltraPlanManifest["stacks"] {
|
|
308
|
+
return authored.stacks.map((stack) => {
|
|
309
|
+
if (stack.applicability === "not-applicable") {
|
|
310
|
+
return {
|
|
311
|
+
stack: stack.stack,
|
|
312
|
+
applicability: stack.applicability,
|
|
313
|
+
progress: { total: 0, terminal: 0, blocked: 0 },
|
|
314
|
+
domainCount: 0,
|
|
315
|
+
terminalDomainCount: 0,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const scenarios = stack.domains.flatMap((domain) => [...domain.unit, ...domain.integration, ...domain.e2e]);
|
|
320
|
+
const blockedReviews = stack.domains.filter((domain) => readDomainReviewStatus(manifest, stack.stack, domain.id) === "blocked").length;
|
|
321
|
+
const stackReviewBlocked = readStackReviewStatus(manifest, stack.stack) === "blocked" ? 1 : 0;
|
|
322
|
+
|
|
323
|
+
return {
|
|
324
|
+
stack: stack.stack,
|
|
325
|
+
applicability: stack.applicability,
|
|
326
|
+
progress: {
|
|
327
|
+
total: scenarios.length,
|
|
328
|
+
terminal: scenarios.filter(isScenarioTerminal).length,
|
|
329
|
+
blocked: scenarios.filter((scenario) => scenario.status === "blocked").length + blockedReviews + stackReviewBlocked,
|
|
330
|
+
},
|
|
331
|
+
domainCount: stack.domains.length,
|
|
332
|
+
terminalDomainCount: stack.domains.filter((domain) => isDomainTerminal(domain, manifest, stack.stack)).length,
|
|
333
|
+
};
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function buildSessionProgress(
|
|
338
|
+
stacks: UltraPlanManifest["stacks"],
|
|
339
|
+
blocker: UltraPlanManifest["blocker"],
|
|
340
|
+
): UltraPlanManifest["progress"] {
|
|
341
|
+
return stacks.reduce(
|
|
342
|
+
(acc, stack) => ({
|
|
343
|
+
total: acc.total + stack.progress.total,
|
|
344
|
+
terminal: acc.terminal + stack.progress.terminal,
|
|
345
|
+
blocked: acc.blocked + stack.progress.blocked,
|
|
346
|
+
}),
|
|
347
|
+
{ total: 0, terminal: 0, blocked: blocker ? 1 : 0 },
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function isDomainTerminal(domain: UltraPlanDomain, manifest: UltraPlanManifest, stack: UltraPlanStack["stack"]): boolean {
|
|
352
|
+
const scenarios = [...domain.unit, ...domain.integration, ...domain.e2e];
|
|
353
|
+
if (!scenarios.every(isScenarioTerminal)) {
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (!domain.review.enabled) {
|
|
358
|
+
return true;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return readDomainReviewStatus(manifest, stack, domain.id) === "passed";
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function isScenarioTerminal(scenario: UltraPlanScenario): boolean {
|
|
365
|
+
return ["green-proved", "review-passed", "done"].includes(scenario.status)
|
|
366
|
+
&& hasRequiredUltraPlanScenarioProof(scenario);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function readDomainReviewStatus(manifest: UltraPlanManifest, stack: UltraPlanStack["stack"], domainId: string) {
|
|
370
|
+
return manifest.reviews.find((review) => review.type === "domain" && review.stack === stack && review.domainId === domainId)?.status ?? null;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function readStackReviewStatus(manifest: UltraPlanManifest, stack: UltraPlanStack["stack"]) {
|
|
374
|
+
return manifest.reviews.find((review) => review.type === "stack" && review.stack === stack)?.status ?? null;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function resolveManifestState(
|
|
378
|
+
manifest: UltraPlanManifest,
|
|
379
|
+
tracker: UltraPlanRuntimeTracker,
|
|
380
|
+
explicitState: UltraPlanMutationPlan["sessionStateUpdate"],
|
|
381
|
+
): UltraPlanSessionState {
|
|
382
|
+
const derived = explicitState
|
|
383
|
+
?? (manifest.blocker
|
|
384
|
+
? (manifest.blocker.recoveryMode === "await-user" ? "awaiting-user" : "blocked")
|
|
385
|
+
: (manifest.cursor?.targetType === "session" && manifest.cursor.status === "complete")
|
|
386
|
+
? "complete"
|
|
387
|
+
: tracker.activeAttempt
|
|
388
|
+
? "running"
|
|
389
|
+
: "ready");
|
|
390
|
+
|
|
391
|
+
return derived ?? manifest.state ?? "ready";
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function buildExecutionLogEntry(input: ApplyUltraPlanMutationInput): Record<string, unknown> {
|
|
395
|
+
return {
|
|
396
|
+
ts: input.observation.occurredAt,
|
|
397
|
+
sessionId: input.sessionId,
|
|
398
|
+
attemptId: input.observation.attemptId,
|
|
399
|
+
observationFingerprint: input.observation.fingerprint,
|
|
400
|
+
hookEvent: input.observation.hookEvent,
|
|
401
|
+
mutation: input.mutationPlan,
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function assertStorageResult(result: { ok: boolean; error?: { message: string; details?: string[] } }): void {
|
|
406
|
+
if (result.ok) {
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
throwStorageError(result.error);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function throwStorageError(error: { message: string; details?: string[] } | undefined): never {
|
|
414
|
+
const detail = error?.details?.length ? `\n${error.details.join("\n")}` : "";
|
|
415
|
+
throw new Error(`${error?.message ?? "UltraPlan runtime storage failure"}${detail}`);
|
|
416
|
+
}
|