paseo-plugin-genui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/OVERVIEW.md +21 -0
- package/README.md +77 -2
- package/assets/fonts/Excalifont-OFL.txt +109 -0
- package/assets/fonts/Excalifont-Regular-latin.woff2 +0 -0
- package/assets/icon.png +0 -0
- package/assets/icon.svg +1 -0
- package/assets/screenshot-chat.png +0 -0
- package/assets/screenshot-gallery.png +0 -0
- package/assets/screenshot-playground.png +0 -0
- package/client/components/content.tsx +468 -0
- package/client/components/data.tsx +967 -0
- package/client/components/dev.tsx +998 -0
- package/client/components/diagram.tsx +513 -0
- package/client/components/inputs.tsx +994 -0
- package/client/components/layout.tsx +239 -0
- package/client/components/media.tsx +428 -0
- package/client/components/project.tsx +641 -0
- package/client/components/widgets.tsx +836 -0
- package/client/gallery.tsx +449 -0
- package/client/live-ui.tsx +525 -0
- package/client/loaders.ts +342 -0
- package/client/markdown.tsx +172 -0
- package/client/node-renderer.tsx +149 -0
- package/client/render.tsx +186 -0
- package/client/runtime.ts +103 -0
- package/client/settings.tsx +57 -0
- package/client/web.ts +186 -0
- package/gallery/Acceptance-baseline.ui +1 -0
- package/gallery/Acceptance-checklist.ui +14 -0
- package/gallery/Acceptance-evidence.ui +9 -0
- package/gallery/Acceptance.ui +1 -0
- package/gallery/Badge.ui +3 -0
- package/gallery/Benchmark-context.ui +8 -0
- package/gallery/Benchmark-hyperfine.ui +1 -0
- package/gallery/Benchmark-runs-list.ui +9 -0
- package/gallery/Benchmark-runs.ui +1 -0
- package/gallery/Benchmark-vitest.ui +1 -0
- package/gallery/Benchmark.ui +9 -0
- package/gallery/Board-bb-tasks.ui +1 -0
- package/gallery/Board-gh-issues.ui +1 -0
- package/gallery/Board-gh-prs.ui +1 -0
- package/gallery/Board.ui +12 -0
- package/gallery/Button-destructive.ui +4 -0
- package/gallery/Button.ui +5 -0
- package/gallery/Calendar.ui +15 -0
- package/gallery/CalendarHeatmap-short.ui +11 -0
- package/gallery/CalendarHeatmap.ui +4 -0
- package/gallery/Callout.ui +4 -0
- package/gallery/Card.ui +4 -0
- package/gallery/Carousel.ui +8 -0
- package/gallery/Changes-paths.ui +1 -0
- package/gallery/Changes-uncommitted.ui +1 -0
- package/gallery/Changes.ui +1 -0
- package/gallery/Chart-area.ui +3 -0
- package/gallery/Chart-funnel.ui +3 -0
- package/gallery/Chart-heatmap.ui +11 -0
- package/gallery/Chart-pie.ui +3 -0
- package/gallery/Chart-radar.ui +3 -0
- package/gallery/Chart-scatter.ui +4 -0
- package/gallery/Chart-stacked.ui +5 -0
- package/gallery/Chart.ui +3 -0
- package/gallery/Checklist.ui +6 -0
- package/gallery/Choice.ui +8 -0
- package/gallery/Code.ui +3 -0
- package/gallery/Commits-limit.ui +1 -0
- package/gallery/Commits.ui +1 -0
- package/gallery/Compare-conditions.ui +4 -0
- package/gallery/Compare-three.ui +7 -0
- package/gallery/Compare.ui +4 -0
- package/gallery/Coverage-go.ui +1 -0
- package/gallery/Coverage-lcov.ui +1 -0
- package/gallery/Coverage-python.ui +1 -0
- package/gallery/Coverage.ui +1 -0
- package/gallery/DateInput.ui +5 -0
- package/gallery/Decision-percent.ui +10 -0
- package/gallery/Decision.ui +12 -0
- package/gallery/Dependencies-audit.ui +1 -0
- package/gallery/Dependencies-both.ui +1 -0
- package/gallery/Dependencies-list.ui +7 -0
- package/gallery/Dependencies-pip.ui +1 -0
- package/gallery/Dependencies-pnpm.ui +1 -0
- package/gallery/Dependencies.ui +1 -0
- package/gallery/Details.ui +4 -0
- package/gallery/Diagram-flow.ui +16 -0
- package/gallery/Diagram-sequence.ui +15 -0
- package/gallery/Diagram.ui +16 -0
- package/gallery/Diff.ui +3 -0
- package/gallery/Divider.ui +5 -0
- package/gallery/EditableTable.ui +9 -0
- package/gallery/Entity-list.ui +6 -0
- package/gallery/Entity.ui +8 -0
- package/gallery/Environments.ui +1 -0
- package/gallery/Estimate-points.ui +6 -0
- package/gallery/Estimate.ui +8 -0
- package/gallery/File.ui +4 -0
- package/gallery/Findings-biome.ui +1 -0
- package/gallery/Findings-eslint.ui +1 -0
- package/gallery/Findings-oxlint.ui +1 -0
- package/gallery/Findings-review.ui +1 -0
- package/gallery/Findings-ruff.ui +1 -0
- package/gallery/Findings-sarif.ui +1 -0
- package/gallery/Findings-ship.ui +11 -0
- package/gallery/Findings-tsc.ui +1 -0
- package/gallery/Findings.ui +7 -0
- package/gallery/Flashcards.ui +3 -0
- package/gallery/FollowUps.ui +4 -0
- package/gallery/Form.ui +8 -0
- package/gallery/Gallery-links.ui +8 -0
- package/gallery/Gallery-strip.ui +14 -0
- package/gallery/Gallery.ui +10 -0
- package/gallery/Gauge.ui +7 -0
- package/gallery/Grid.ui +8 -0
- package/gallery/Hotspots-photo.ui +8 -0
- package/gallery/Hotspots.ui +11 -0
- package/gallery/Icon.ui +5 -0
- package/gallery/Image.ui +4 -0
- package/gallery/ImageSearch-aspects.ui +6 -0
- package/gallery/ImageSearch.ui +4 -0
- package/gallery/Input.ui +5 -0
- package/gallery/Json-api.ui +1 -0
- package/gallery/Json.ui +8 -0
- package/gallery/KeyValue.ui +3 -0
- package/gallery/List-dots.ui +8 -0
- package/gallery/List.ui +8 -0
- package/gallery/ListEditor.ui +5 -0
- package/gallery/Logs-jsonl.ui +1 -0
- package/gallery/Logs-lines.ui +11 -0
- package/gallery/Logs-python.ui +1 -0
- package/gallery/Logs.ui +1 -0
- package/gallery/Map-city.ui +8 -0
- package/gallery/Map.ui +8 -0
- package/gallery/Metric.ui +3 -0
- package/gallery/OptionCards-multi.ui +10 -0
- package/gallery/OptionCards.ui +10 -0
- package/gallery/Pipeline-checks.ui +1 -0
- package/gallery/Pipeline-passed.ui +1 -0
- package/gallery/Pipeline-running.ui +1 -0
- package/gallery/Pipeline-stages.ui +13 -0
- package/gallery/Pipeline.ui +1 -0
- package/gallery/Plan.ui +9 -0
- package/gallery/Progress.ui +4 -0
- package/gallery/Provenance-deploy.ui +6 -0
- package/gallery/Provenance-no-receipt.ui +1 -0
- package/gallery/Provenance.ui +1 -0
- package/gallery/PullRequest.ui +1 -0
- package/gallery/Quiz.ui +6 -0
- package/gallery/Radio.ui +5 -0
- package/gallery/Rating.ui +5 -0
- package/gallery/Roadmap-sprint.ui +8 -0
- package/gallery/Roadmap-year.ui +9 -0
- package/gallery/Roadmap.ui +12 -0
- package/gallery/Row.ui +3 -0
- package/gallery/SegmentedBar-status.ui +8 -0
- package/gallery/SegmentedBar.ui +8 -0
- package/gallery/Select.ui +5 -0
- package/gallery/Slider.ui +7 -0
- package/gallery/Snippet.ui +3 -0
- package/gallery/Sources-chips.ui +4 -0
- package/gallery/Sources.ui +8 -0
- package/gallery/Sparkline.ui +6 -0
- package/gallery/Stack.ui +7 -0
- package/gallery/StackTrace-aggregate.ui +1 -0
- package/gallery/StackTrace-browser.ui +1 -0
- package/gallery/StackTrace-go.ui +1 -0
- package/gallery/StackTrace-java.ui +1 -0
- package/gallery/StackTrace-python.ui +1 -0
- package/gallery/StackTrace-rust.ui +1 -0
- package/gallery/StackTrace.ui +1 -0
- package/gallery/Status.ui +9 -0
- package/gallery/Stepper.ui +5 -0
- package/gallery/Steps.ui +8 -0
- package/gallery/Swatches-long-names.ui +4 -0
- package/gallery/Swatches-picker.ui +5 -0
- package/gallery/Swatches.ui +10 -0
- package/gallery/Table.ui +7 -0
- package/gallery/Tabs.ui +8 -0
- package/gallery/Tests-junit.ui +1 -0
- package/gallery/Tests-vitest-junit.ui +1 -0
- package/gallery/Tests-vitest.ui +1 -0
- package/gallery/Tests.ui +9 -0
- package/gallery/Text.ui +4 -0
- package/gallery/TextArea.ui +5 -0
- package/gallery/Threads-ids.ui +1 -0
- package/gallery/Threads.ui +1 -0
- package/gallery/Timeline.ui +8 -0
- package/gallery/Timer.ui +4 -0
- package/gallery/Toggle.ui +5 -0
- package/gallery/Transcript-text.ui +1 -0
- package/gallery/Transcript-untimed.ui +1 -0
- package/gallery/Transcript-whisper.ui +1 -0
- package/gallery/Transcript.ui +1 -0
- package/gallery/Tree.ui +3 -0
- package/gallery/Treemap-du.ui +1 -0
- package/gallery/Treemap-esbuild.ui +1 -0
- package/gallery/Treemap-tree.ui +7 -0
- package/gallery/Treemap.ui +18 -0
- package/gallery/Walkthrough.ui +9 -0
- package/gallery/Waterfall-har.ui +1 -0
- package/gallery/Waterfall-trace.ui +1 -0
- package/gallery/Waterfall.ui +11 -0
- package/gallery/data/acceptance/coil/viewport-lifecycle.json +25 -0
- package/gallery/data/acceptance/coil-gate.json +153 -0
- package/gallery/data/acceptance/orbit-baseline.json +163 -0
- package/gallery/data/acceptance/shots/gate-cell-opened.png +0 -0
- package/gallery/data/acceptance/shots/gate-light.png +0 -0
- package/gallery/data/acceptance/shots/gate-phone-dark.png +0 -0
- package/gallery/data/activity.json +1 -0
- package/gallery/data/bb-tasks-orb.json +420 -0
- package/gallery/data/biome.json +229 -0
- package/gallery/data/compare/status-after.png +0 -0
- package/gallery/data/compare/status-before.png +0 -0
- package/gallery/data/compare/status-dark-2x.png +0 -0
- package/gallery/data/compare/status-rerender.png +0 -0
- package/gallery/data/coverage-py.json +1 -0
- package/gallery/data/coverage-summary.json +1 -0
- package/gallery/data/coverage.out +23 -0
- package/gallery/data/deploys.json +1 -0
- package/gallery/data/device-runs.json +285 -0
- package/gallery/data/du-node-modules.txt +359 -0
- package/gallery/data/esbuild-meta.json +292 -0
- package/gallery/data/eslint.json +266 -0
- package/gallery/data/eslint.sarif +343 -0
- package/gallery/data/findings-review.json +76 -0
- package/gallery/data/gh-issues-nextjs.json +293 -0
- package/gallery/data/gh-pr-checks.json +272 -0
- package/gallery/data/gh-prs-nextjs.json +419 -0
- package/gallery/data/gh-run-failed.json +1 -0
- package/gallery/data/gh-run-passed.json +1 -0
- package/gallery/data/gh-run-running.json +1 -0
- package/gallery/data/github-release.json +57 -0
- package/gallery/data/hyperfine-startup.json +187 -0
- package/gallery/data/lcov.info +234 -0
- package/gallery/data/logs/media-sync.log +127 -0
- package/gallery/data/logs/thumbnailer.jsonl +17 -0
- package/gallery/data/logs/vitest-run.log +89 -0
- package/gallery/data/npm-audit.json +672 -0
- package/gallery/data/npm-outdated.json +179 -0
- package/gallery/data/oxlint.json +156 -0
- package/gallery/data/pip-outdated.json +68 -0
- package/gallery/data/pnpm-outdated.json +58 -0
- package/gallery/data/provenance/devicectl-install.json +35 -0
- package/gallery/data/provenance/install-timeout.log +4 -0
- package/gallery/data/provenance/iphone-install.json +72 -0
- package/gallery/data/provenance/iphone-no-receipt.json +57 -0
- package/gallery/data/provenance/live-home.jpg +0 -0
- package/gallery/data/provenance/live-probe.txt +10 -0
- package/gallery/data/provenance/xcodebuild-2811.log +19 -0
- package/gallery/data/provenance/xcodebuild-4712.log +19 -0
- package/gallery/data/pytest-junit.xml +64 -0
- package/gallery/data/python-org-trace.json +35 -0
- package/gallery/data/python-org.har +31 -0
- package/gallery/data/retry.ts +13 -0
- package/gallery/data/ruff.json +261 -0
- package/gallery/data/src/durations.py +63 -0
- package/gallery/data/src/json-logic.ts +156 -0
- package/gallery/data/src/mapMath.ts +135 -0
- package/gallery/data/src/semver/bump.go +73 -0
- package/gallery/data/traces/browser-error.json +5 -0
- package/gallery/data/traces/go/main.go +27 -0
- package/gallery/data/traces/go-panic.txt +16 -0
- package/gallery/data/traces/java-caused-by.txt +15 -0
- package/gallery/data/traces/node-aggregate.txt +30 -0
- package/gallery/data/traces/node-cause.txt +21 -0
- package/gallery/data/traces/py/deploy.json +5 -0
- package/gallery/data/traces/py/deploy.py +17 -0
- package/gallery/data/traces/py/settings.py +19 -0
- package/gallery/data/traces/python-chain.txt +30 -0
- package/gallery/data/traces/rust/main.rs +11 -0
- package/gallery/data/traces/rust-panic.txt +16 -0
- package/gallery/data/traces/shop/cart.mjs +19 -0
- package/gallery/data/traces/shop/pricing.mjs +12 -0
- package/gallery/data/traces/shop/status.mjs +9 -0
- package/gallery/data/traces/web/app.js +11 -0
- package/gallery/data/traces/web/index.html +1 -0
- package/gallery/data/traces/web/search.js +10 -0
- package/gallery/data/transcript/call-noisy.wav +0 -0
- package/gallery/data/transcript/call.json +362 -0
- package/gallery/data/transcript/call.wav +0 -0
- package/gallery/data/transcript/mlx-whisper-tiny.en-noisy.json +1 -0
- package/gallery/data/transcript/whisper-cpp-base.en-noisy.json +658 -0
- package/gallery/data/transcript/whisper-cpp-base.en.json +658 -0
- package/gallery/data/transcript/whisper-cpp-base.en.srt +16 -0
- package/gallery/data/transcript/whisper-cpp-tiny.en-noisy.json +619 -0
- package/gallery/data/tsc.txt +4 -0
- package/gallery/data/vitest-bench.json +119 -0
- package/gallery/data/vitest-junit.xml +133 -0
- package/gallery/data/vitest-report.json +612 -0
- package/gallery/images/bell.svg +10 -0
- package/gallery/images/bike.svg +47 -0
- package/gallery/images/footer-planet.webp +0 -0
- package/gallery/images/front-light.svg +13 -0
- package/gallery/images/golden-hour.webp +0 -0
- package/gallery/images/option-flowers.webp +0 -0
- package/gallery/images/option-hilltop.webp +0 -0
- package/gallery/images/option-meadow.webp +0 -0
- package/gallery/images/option-sky.webp +0 -0
- package/gallery/images/u-lock.svg +10 -0
- package/index.client.tsx +164 -0
- package/index.server.ts +216 -0
- package/package.json +50 -4
- package/paseo-plugin.json +14 -0
- package/server/data-source.ts +407 -0
- package/server/project.ts +981 -0
- package/server/web/address.ts +57 -0
- package/server/web/cache.ts +85 -0
- package/server/web/commons.ts +126 -0
- package/server/web/geocode.ts +40 -0
- package/server/web/image.ts +35 -0
- package/server/web/lookups.ts +248 -0
- package/server/web/net.ts +210 -0
- package/shared/core/acceptance.ts +744 -0
- package/shared/core/ast.ts +76 -0
- package/shared/core/benchmark.ts +743 -0
- package/shared/core/catalog.ts +733 -0
- package/shared/core/compare.ts +225 -0
- package/shared/core/coverage.ts +456 -0
- package/shared/core/data.ts +334 -0
- package/shared/core/decisions.ts +527 -0
- package/shared/core/dependencies.ts +604 -0
- package/shared/core/diagnostics.ts +24 -0
- package/shared/core/environments.ts +212 -0
- package/shared/core/evaluate.ts +737 -0
- package/shared/core/fields.ts +66 -0
- package/shared/core/findings.ts +1172 -0
- package/shared/core/form.ts +69 -0
- package/shared/core/index.ts +44 -0
- package/shared/core/junit.ts +252 -0
- package/shared/core/lexer.ts +275 -0
- package/shared/core/logs.ts +496 -0
- package/shared/core/markdown.ts +2374 -0
- package/shared/core/parser.ts +355 -0
- package/shared/core/perf-units.ts +228 -0
- package/shared/core/pipeline.ts +679 -0
- package/shared/core/project.ts +472 -0
- package/shared/core/provenance.ts +725 -0
- package/shared/core/stack-trace.ts +718 -0
- package/shared/core/streaming.ts +136 -0
- package/shared/core/test-results.ts +562 -0
- package/shared/core/thread-activity.ts +203 -0
- package/shared/core/tracking.ts +887 -0
- package/shared/core/transcript.ts +1364 -0
- package/shared/core/treemap.ts +446 -0
- package/shared/core/types.ts +70 -0
- package/shared/core/validate.ts +574 -0
- package/shared/core/waterfall.ts +536 -0
- package/shared/diagram/flowchart.ts +205 -0
- package/shared/diagram/layout.ts +440 -0
- package/shared/diagram/markdown.ts +135 -0
- package/shared/diagram/sequence.ts +122 -0
- package/shared/diagram/zoom.ts +114 -0
- package/shared/fallback.ts +120 -0
- package/shared/genui.test.ts +122 -0
- package/shared/instructions.ts +144 -0
- package/shared/logic/calendarMath.ts +130 -0
- package/shared/logic/chartMath.ts +289 -0
- package/shared/logic/choose-logic.ts +196 -0
- package/shared/logic/compare-logic.ts +270 -0
- package/shared/logic/content-model.ts +227 -0
- package/shared/logic/environments-logic.ts +53 -0
- package/shared/logic/explain-logic.ts +315 -0
- package/shared/logic/fieldLogic.ts +138 -0
- package/shared/logic/gallery-search.ts +71 -0
- package/shared/logic/icons.ts +322 -0
- package/shared/logic/json-logic.ts +153 -0
- package/shared/logic/mapMath.ts +133 -0
- package/shared/logic/project-logic.ts +39 -0
- package/shared/logic/references-model.ts +201 -0
- package/shared/logic/sketch.ts +165 -0
- package/shared/logic/supersession.ts +77 -0
- package/shared/logic/values.ts +133 -0
- package/shared/logic/widget-logic.ts +163 -0
- package/shared/rpc.ts +252 -0
- package/shared/segment.ts +81 -0
- package/shared/settings.ts +12 -0
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
// What the BB-backed Project components (Changes, Commits, PullRequest,
|
|
2
|
+
// Threads, Environments) show: the shapes the backend (project/) answers
|
|
3
|
+
// with, which the renderer and the markdown fallback both read, and the pure
|
|
4
|
+
// helpers they share. Nothing here talks to BB; project/source.ts does.
|
|
5
|
+
// Environments' own shapes are in environments.ts.
|
|
6
|
+
import type { EnvironmentsView } from "./environments";
|
|
7
|
+
import type { LastMessage, PendingAsk } from "./thread-activity";
|
|
8
|
+
|
|
9
|
+
/** Paseo agent / thread ids. */
|
|
10
|
+
export const THREAD_ID = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
11
|
+
|
|
12
|
+
/** A full or abbreviated git commit sha, lowercase. */
|
|
13
|
+
const COMMIT_SHA = /^[0-9a-f]{7,40}$/;
|
|
14
|
+
|
|
15
|
+
/** Most paths a Changes filter may name. */
|
|
16
|
+
export const MAX_PATH_FILTERS = 50;
|
|
17
|
+
|
|
18
|
+
/** Most thread ids a Threads list may name. */
|
|
19
|
+
export const MAX_THREAD_IDS = 50;
|
|
20
|
+
|
|
21
|
+
/** Most commits a Commits list keeps. */
|
|
22
|
+
export const MAX_COMMITS = 500;
|
|
23
|
+
|
|
24
|
+
// ── Requests ────────────────────────────────────────────────────────────────
|
|
25
|
+
|
|
26
|
+
/** Which changes Changes shows. */
|
|
27
|
+
export type ChangesTarget =
|
|
28
|
+
/** The branch's work against the default branch, committed and uncommitted. */
|
|
29
|
+
| { readonly kind: "branch" }
|
|
30
|
+
| { readonly kind: "uncommitted" }
|
|
31
|
+
| { readonly kind: "commit"; readonly sha: string };
|
|
32
|
+
|
|
33
|
+
export type Parsed<T> = { readonly ok: true; readonly value: T } | { readonly ok: false; readonly error: string };
|
|
34
|
+
|
|
35
|
+
/** `target` as written: omitted, `"uncommitted"`, or a commit sha (7–40 hex digits). */
|
|
36
|
+
export function parseChangesTarget(value: unknown): Parsed<ChangesTarget> {
|
|
37
|
+
if (value === undefined || value === null) return { ok: true, value: { kind: "branch" } };
|
|
38
|
+
const written = typeof value === "string" ? value.trim().toLowerCase() : null;
|
|
39
|
+
if (written === "") return { ok: true, value: { kind: "branch" } };
|
|
40
|
+
if (written === "uncommitted") return { ok: true, value: { kind: "uncommitted" } };
|
|
41
|
+
if (written !== null && COMMIT_SHA.test(written)) return { ok: true, value: { kind: "commit", sha: written } };
|
|
42
|
+
return {
|
|
43
|
+
ok: false,
|
|
44
|
+
error: `Changes target must be omitted, "uncommitted" or a commit sha, not ${JSON.stringify(value)}`,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* `paths` as written: null (no filter) or the repository-relative paths and
|
|
50
|
+
* directory prefixes to keep, without `./` or a trailing slash.
|
|
51
|
+
*/
|
|
52
|
+
export function parsePathFilter(value: unknown): Parsed<readonly string[] | null> {
|
|
53
|
+
if (value === undefined || value === null) return { ok: true, value: null };
|
|
54
|
+
if (!Array.isArray(value)) return { ok: false, error: "Changes paths must be a list of paths" };
|
|
55
|
+
if (value.length > MAX_PATH_FILTERS) return { ok: false, error: `Changes takes at most ${MAX_PATH_FILTERS} paths` };
|
|
56
|
+
const paths: string[] = [];
|
|
57
|
+
for (const item of value) {
|
|
58
|
+
if (typeof item !== "string") return { ok: false, error: "Changes paths must be strings" };
|
|
59
|
+
const path = item.trim().replace(/^(?:\.\/)+/, "").replace(/\/+$/, "");
|
|
60
|
+
if (path === "" || path === ".") return { ok: false, error: `"${item}" is not a path in the repository` };
|
|
61
|
+
if (!paths.includes(path)) paths.push(path);
|
|
62
|
+
}
|
|
63
|
+
// An empty list keeps everything, like no list.
|
|
64
|
+
return { ok: true, value: paths.length === 0 ? null : paths };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** True when `path` is one of `filter` or inside one of its directories. */
|
|
68
|
+
export function matchesPathFilter(path: string, filter: readonly string[] | null): boolean {
|
|
69
|
+
return filter === null || filter.some((kept) => path === kept || path.startsWith(`${kept}/`));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** `limit` as written: null (all) or a whole number of commits from 1. */
|
|
73
|
+
export function parseCommitLimit(value: unknown): Parsed<number | null> {
|
|
74
|
+
if (value === undefined || value === null) return { ok: true, value: null };
|
|
75
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 1) {
|
|
76
|
+
return { ok: false, error: "Commits limit must be a number from 1" };
|
|
77
|
+
}
|
|
78
|
+
return { ok: true, value: Math.min(MAX_COMMITS, Math.floor(value)) };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** `ids` as written: null (the thread's subthreads) or the ids, repeats dropped. */
|
|
82
|
+
export function parseThreadIds(value: unknown): Parsed<readonly string[] | null> {
|
|
83
|
+
if (value === undefined || value === null) return { ok: true, value: null };
|
|
84
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
|
|
85
|
+
return { ok: false, error: "Threads ids must be a list of thread ids" };
|
|
86
|
+
}
|
|
87
|
+
const ids = [...new Set((value as string[]).map((id) => id.trim()).filter((id) => id !== ""))];
|
|
88
|
+
if (ids.length > MAX_THREAD_IDS) return { ok: false, error: `Threads takes at most ${MAX_THREAD_IDS} ids` };
|
|
89
|
+
return { ok: true, value: ids };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** One read of BB state a rendered reply needs, as the markdown fallback collects them. */
|
|
93
|
+
export type ProjectRequest =
|
|
94
|
+
| { readonly kind: "changes"; readonly target: ChangesTarget; readonly paths: readonly string[] | null }
|
|
95
|
+
| { readonly kind: "commits" }
|
|
96
|
+
| { readonly kind: "pullRequest" }
|
|
97
|
+
| { readonly kind: "threads"; readonly ids: readonly string[] | null }
|
|
98
|
+
| { readonly kind: "environments" };
|
|
99
|
+
|
|
100
|
+
export function projectRequestKey(request: ProjectRequest): string {
|
|
101
|
+
return JSON.stringify(request);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// ── Answers ─────────────────────────────────────────────────────────────────
|
|
105
|
+
|
|
106
|
+
/** Why BB state couldn't be read, in one sentence for the user. */
|
|
107
|
+
export interface ProjectFailure {
|
|
108
|
+
readonly ok: false;
|
|
109
|
+
readonly reason: "no-thread" | "not-found" | "no-environment" | "not-git" | "unavailable" | "invalid";
|
|
110
|
+
readonly message: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export type ChangeKind = "added" | "copied" | "deleted" | "modified" | "renamed" | "type_changed";
|
|
114
|
+
|
|
115
|
+
/** How a file's diff can be shown: BB sent it, fetches it on request, or won't show text. */
|
|
116
|
+
export type DiffAvailability = "inline" | "on-demand" | "too-large" | "binary";
|
|
117
|
+
|
|
118
|
+
export interface ChangedFile {
|
|
119
|
+
readonly path: string;
|
|
120
|
+
/** Where a renamed or copied file came from. */
|
|
121
|
+
readonly previousPath: string | null;
|
|
122
|
+
readonly kind: ChangeKind;
|
|
123
|
+
readonly additions: number;
|
|
124
|
+
readonly deletions: number;
|
|
125
|
+
/** A new file git doesn't track yet. */
|
|
126
|
+
readonly untracked: boolean;
|
|
127
|
+
readonly diff: DiffAvailability;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface FilePatch {
|
|
131
|
+
readonly path: string;
|
|
132
|
+
readonly patch: string;
|
|
133
|
+
/** BB cut the patch short. */
|
|
134
|
+
readonly truncated: boolean;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** What the changes are measured against, for the header. */
|
|
138
|
+
export type ChangesScope =
|
|
139
|
+
/** The branch against `base`, uncommitted work included. `onBase`: the checkout is on `base`, so only uncommitted work differs. */
|
|
140
|
+
| {
|
|
141
|
+
readonly kind: "branch";
|
|
142
|
+
readonly branch: string | null;
|
|
143
|
+
/** Short sha of a detached HEAD. */
|
|
144
|
+
readonly head: string | null;
|
|
145
|
+
readonly base: string;
|
|
146
|
+
readonly onBase: boolean;
|
|
147
|
+
}
|
|
148
|
+
| { readonly kind: "uncommitted"; readonly branch: string | null; readonly unborn: boolean }
|
|
149
|
+
| { readonly kind: "commit"; readonly sha: string; readonly subject: string | null };
|
|
150
|
+
|
|
151
|
+
export interface ChangesView {
|
|
152
|
+
readonly ok: true;
|
|
153
|
+
readonly scope: ChangesScope;
|
|
154
|
+
/** Files the path filter keeps, in BB's order. */
|
|
155
|
+
readonly files: readonly ChangedFile[];
|
|
156
|
+
/** Files before the filter. */
|
|
157
|
+
readonly totalFiles: number;
|
|
158
|
+
readonly filter: readonly string[] | null;
|
|
159
|
+
/** BB listed only part of the changed files (or the snapshot kept only part). */
|
|
160
|
+
readonly listTruncated: boolean;
|
|
161
|
+
/** The patches at hand; a stored snapshot carries every one that fit. */
|
|
162
|
+
readonly patches: readonly FilePatch[];
|
|
163
|
+
/** Whether a patch not at hand may be fetched now. False for a snapshot: today's diff isn't what it showed. */
|
|
164
|
+
readonly livePatches: boolean;
|
|
165
|
+
/** When BB was read (epoch ms). */
|
|
166
|
+
readonly takenAt: number;
|
|
167
|
+
/** Kept in plugin storage for this reply: later renders show this, not today's state. */
|
|
168
|
+
readonly stored: boolean;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface CommitInfo {
|
|
172
|
+
readonly sha: string;
|
|
173
|
+
readonly shortSha: string;
|
|
174
|
+
readonly subject: string;
|
|
175
|
+
readonly author: string;
|
|
176
|
+
/** Epoch ms. */
|
|
177
|
+
readonly authoredAt: number;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export interface CommitsView {
|
|
181
|
+
readonly ok: true;
|
|
182
|
+
readonly branch: string | null;
|
|
183
|
+
readonly checkout: "branch" | "detached" | "unborn";
|
|
184
|
+
/** Short sha of HEAD, when there is one. */
|
|
185
|
+
readonly head: string | null;
|
|
186
|
+
readonly base: string;
|
|
187
|
+
/** The checkout is on the default branch itself. */
|
|
188
|
+
readonly onBase: boolean;
|
|
189
|
+
/** Null when BB couldn't find a merge base. */
|
|
190
|
+
readonly ahead: number | null;
|
|
191
|
+
readonly behind: number | null;
|
|
192
|
+
/** Newest first. */
|
|
193
|
+
readonly commits: readonly CommitInfo[];
|
|
194
|
+
/** More commits than were kept. */
|
|
195
|
+
readonly commitsTruncated: boolean;
|
|
196
|
+
readonly takenAt: number;
|
|
197
|
+
readonly stored: boolean;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export type PullRequestState = "open" | "draft" | "merged" | "closed";
|
|
201
|
+
export type ChecksState = "passing" | "failing" | "pending" | "no_checks" | "unknown";
|
|
202
|
+
export type ReviewState = "approved" | "changes_requested" | "review_requested" | "review_required" | "none";
|
|
203
|
+
export type MergeabilityState = "mergeable" | "conflicts" | "blocked" | "draft" | "unknown";
|
|
204
|
+
export type PullRequestAttention =
|
|
205
|
+
| "blocked"
|
|
206
|
+
| "changes_requested"
|
|
207
|
+
| "checks_failed"
|
|
208
|
+
| "checks_pending"
|
|
209
|
+
| "closed"
|
|
210
|
+
| "conflicts"
|
|
211
|
+
| "draft"
|
|
212
|
+
| "merged"
|
|
213
|
+
| "none"
|
|
214
|
+
| "queued"
|
|
215
|
+
| "ready_to_merge"
|
|
216
|
+
| "review_requested";
|
|
217
|
+
|
|
218
|
+
export interface PullRequestInfo {
|
|
219
|
+
readonly number: number;
|
|
220
|
+
readonly title: string;
|
|
221
|
+
readonly url: string;
|
|
222
|
+
readonly state: PullRequestState;
|
|
223
|
+
readonly baseRef: string;
|
|
224
|
+
readonly headRef: string;
|
|
225
|
+
readonly checks: {
|
|
226
|
+
readonly state: ChecksState;
|
|
227
|
+
readonly passed: number;
|
|
228
|
+
readonly failed: number;
|
|
229
|
+
readonly pending: number;
|
|
230
|
+
readonly total: number;
|
|
231
|
+
};
|
|
232
|
+
readonly review: { readonly state: ReviewState; readonly requests: number };
|
|
233
|
+
readonly mergeability: MergeabilityState;
|
|
234
|
+
readonly attention: PullRequestAttention;
|
|
235
|
+
readonly autoMerge: boolean;
|
|
236
|
+
readonly inMergeQueue: boolean;
|
|
237
|
+
/** Epoch ms, or null when GitHub's time didn't parse. */
|
|
238
|
+
readonly updatedAt: number | null;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export interface PullRequestView {
|
|
242
|
+
readonly ok: true;
|
|
243
|
+
readonly branch: string | null;
|
|
244
|
+
/** Null: the branch has no pull request. */
|
|
245
|
+
readonly pullRequest: PullRequestInfo | null;
|
|
246
|
+
readonly fetchedAt: number;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export type ThreadDisplayStatus =
|
|
250
|
+
| "active"
|
|
251
|
+
| "error"
|
|
252
|
+
| "idle"
|
|
253
|
+
| "pending"
|
|
254
|
+
| "provisioning"
|
|
255
|
+
| "starting"
|
|
256
|
+
| "stopping"
|
|
257
|
+
| "waiting-for-host";
|
|
258
|
+
|
|
259
|
+
export interface ThreadInfo {
|
|
260
|
+
readonly found: true;
|
|
261
|
+
readonly id: string;
|
|
262
|
+
readonly title: string;
|
|
263
|
+
readonly status: ThreadDisplayStatus;
|
|
264
|
+
/** The thread waits for the user to answer a question or approve something. */
|
|
265
|
+
readonly needsInput: boolean;
|
|
266
|
+
readonly archived: boolean;
|
|
267
|
+
readonly provider: { readonly id: string; readonly name: string | null; readonly logoUrl: string | null };
|
|
268
|
+
readonly model: string | null;
|
|
269
|
+
/** The reasoning level BB runs the thread with ("high"); null when unknown or "none". */
|
|
270
|
+
readonly reasoning: string | null;
|
|
271
|
+
/** Epoch ms of the last change BB recorded. */
|
|
272
|
+
readonly updatedAt: number;
|
|
273
|
+
/** Its latest assistant message; null when it has none yet or BB couldn't say. */
|
|
274
|
+
readonly lastMessage: LastMessage | null;
|
|
275
|
+
/** The question or approval it waits on the user for; null when none (or BB couldn't say which). */
|
|
276
|
+
readonly pending: PendingAsk | null;
|
|
277
|
+
/** Its subthreads BB is running right now. */
|
|
278
|
+
readonly runningWorkers: number;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** An id that names no thread this one may see: unknown, deleted, or in another project. */
|
|
282
|
+
export interface MissingThread {
|
|
283
|
+
readonly found: false;
|
|
284
|
+
readonly id: string;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export interface ThreadsView {
|
|
288
|
+
readonly ok: true;
|
|
289
|
+
/** Subthreads of the reply's thread, or the ids the spec named. */
|
|
290
|
+
readonly mode: "subthreads" | "ids";
|
|
291
|
+
readonly threads: readonly (ThreadInfo | MissingThread)[];
|
|
292
|
+
/** BB had more subthreads than were listed. */
|
|
293
|
+
readonly truncated: boolean;
|
|
294
|
+
readonly fetchedAt: number;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export type ChangesResult = ChangesView | ProjectFailure;
|
|
298
|
+
export type PatchesResult =
|
|
299
|
+
| { readonly ok: true; readonly patches: readonly FilePatch[] }
|
|
300
|
+
| ProjectFailure;
|
|
301
|
+
export type CommitsResult = CommitsView | ProjectFailure;
|
|
302
|
+
export type PullRequestResult = PullRequestView | ProjectFailure;
|
|
303
|
+
export type ThreadsResult = ThreadsView | ProjectFailure;
|
|
304
|
+
export type EnvironmentsResult = EnvironmentsView | ProjectFailure;
|
|
305
|
+
export type ProjectResult = ChangesResult | CommitsResult | PullRequestResult | ThreadsResult | EnvironmentsResult;
|
|
306
|
+
|
|
307
|
+
// ── Shared wording ──────────────────────────────────────────────────────────
|
|
308
|
+
|
|
309
|
+
/** "feat/x vs main, incl. uncommitted", "uncommitted", "commit a1b2c3d". */
|
|
310
|
+
export function scopeLabel(scope: ChangesScope): string {
|
|
311
|
+
switch (scope.kind) {
|
|
312
|
+
case "branch": {
|
|
313
|
+
const name = scope.branch ?? (scope.head === null ? "HEAD" : `detached ${scope.head}`);
|
|
314
|
+
return scope.onBase ? `${name}, uncommitted` : `${name} vs ${scope.base}, incl. uncommitted`;
|
|
315
|
+
}
|
|
316
|
+
case "uncommitted":
|
|
317
|
+
return scope.unborn ? "uncommitted, no commits yet" : "uncommitted";
|
|
318
|
+
case "commit":
|
|
319
|
+
return `commit ${scope.sha.slice(0, 7)}`;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** One-letter git status per change kind, as BB's diff panel and `git status` show them. */
|
|
324
|
+
export const CHANGE_LETTER: Record<ChangeKind, string> = {
|
|
325
|
+
added: "A",
|
|
326
|
+
copied: "C",
|
|
327
|
+
deleted: "D",
|
|
328
|
+
modified: "M",
|
|
329
|
+
renamed: "R",
|
|
330
|
+
type_changed: "T",
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
export const CHANGE_LABEL: Record<ChangeKind, string> = {
|
|
334
|
+
added: "Added",
|
|
335
|
+
copied: "Copied",
|
|
336
|
+
deleted: "Deleted",
|
|
337
|
+
modified: "Modified",
|
|
338
|
+
renamed: "Renamed",
|
|
339
|
+
type_changed: "Type changed",
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
export function changeTotals(files: readonly ChangedFile[]): { files: number; additions: number; deletions: number } {
|
|
343
|
+
let additions = 0;
|
|
344
|
+
let deletions = 0;
|
|
345
|
+
for (const file of files) {
|
|
346
|
+
additions += file.additions;
|
|
347
|
+
deletions += file.deletions;
|
|
348
|
+
}
|
|
349
|
+
return { files: files.length, additions, deletions };
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** A path's directory (with its trailing slash, or "") and its file name. */
|
|
353
|
+
export function splitPath(path: string): { directory: string; name: string } {
|
|
354
|
+
const slash = path.lastIndexOf("/");
|
|
355
|
+
return slash < 0 ? { directory: "", name: path } : { directory: path.slice(0, slash + 1), name: path.slice(slash + 1) };
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** Statuses in which the thread is doing (or about to do) work, so its status will change by itself. */
|
|
359
|
+
export const RUNNING: Record<ThreadDisplayStatus, boolean> = {
|
|
360
|
+
active: true,
|
|
361
|
+
pending: true,
|
|
362
|
+
provisioning: true,
|
|
363
|
+
starting: true,
|
|
364
|
+
stopping: true,
|
|
365
|
+
"waiting-for-host": true,
|
|
366
|
+
idle: false,
|
|
367
|
+
error: false,
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
export function threadStatusLabel(thread: Pick<ThreadInfo, "status" | "needsInput" | "archived">): string {
|
|
371
|
+
if (thread.needsInput) return "Needs input";
|
|
372
|
+
switch (thread.status) {
|
|
373
|
+
case "active":
|
|
374
|
+
return "Running";
|
|
375
|
+
case "error":
|
|
376
|
+
return "Failed";
|
|
377
|
+
case "idle":
|
|
378
|
+
return thread.archived ? "Archived" : "Idle";
|
|
379
|
+
case "pending":
|
|
380
|
+
return "Queued";
|
|
381
|
+
case "provisioning":
|
|
382
|
+
return "Preparing";
|
|
383
|
+
case "starting":
|
|
384
|
+
return "Starting";
|
|
385
|
+
case "stopping":
|
|
386
|
+
return "Stopping";
|
|
387
|
+
case "waiting-for-host":
|
|
388
|
+
return "Waiting for machine";
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export const PR_STATE_LABEL: Record<PullRequestState, string> = {
|
|
393
|
+
open: "Open",
|
|
394
|
+
draft: "Draft",
|
|
395
|
+
merged: "Merged",
|
|
396
|
+
closed: "Closed",
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
export const CHECKS_LABEL: Record<ChecksState, string> = {
|
|
400
|
+
passing: "Checks passing",
|
|
401
|
+
failing: "Checks failing",
|
|
402
|
+
pending: "Checks running",
|
|
403
|
+
no_checks: "No checks",
|
|
404
|
+
unknown: "Checks unknown",
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
export const REVIEW_LABEL: Record<ReviewState, string> = {
|
|
408
|
+
approved: "Approved",
|
|
409
|
+
changes_requested: "Changes requested",
|
|
410
|
+
review_requested: "Review requested",
|
|
411
|
+
review_required: "Review required",
|
|
412
|
+
none: "No reviews",
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
export const MERGEABILITY_LABEL: Record<MergeabilityState, string> = {
|
|
416
|
+
mergeable: "Mergeable",
|
|
417
|
+
conflicts: "Conflicts",
|
|
418
|
+
blocked: "Blocked",
|
|
419
|
+
draft: "Draft",
|
|
420
|
+
unknown: "Mergeability unknown",
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
/** BB's attention reason: what the pull request waits for now. Null when nothing does. */
|
|
424
|
+
export const ATTENTION_LABEL: Record<PullRequestAttention, string | null> = {
|
|
425
|
+
blocked: "Blocked by branch rules",
|
|
426
|
+
changes_requested: "Changes requested",
|
|
427
|
+
checks_failed: "Checks failed",
|
|
428
|
+
checks_pending: "Waiting for checks",
|
|
429
|
+
closed: null,
|
|
430
|
+
conflicts: "Has merge conflicts",
|
|
431
|
+
draft: "Draft: not ready for review",
|
|
432
|
+
merged: null,
|
|
433
|
+
none: null,
|
|
434
|
+
queued: "In the merge queue",
|
|
435
|
+
ready_to_merge: "Ready to merge",
|
|
436
|
+
review_requested: "Waiting for review",
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
/** "2 failed · 5 passed · 1 running", only the counts that aren't zero. */
|
|
440
|
+
export function checkCounts(checks: PullRequestInfo["checks"]): string {
|
|
441
|
+
return [
|
|
442
|
+
checks.failed > 0 ? `${checks.failed} failed` : "",
|
|
443
|
+
checks.passed > 0 ? `${checks.passed} passed` : "",
|
|
444
|
+
checks.pending > 0 ? `${checks.pending} running` : "",
|
|
445
|
+
]
|
|
446
|
+
.filter((part) => part !== "")
|
|
447
|
+
.join(" · ");
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/** Something on the pull request will change without anyone acting: checks running, mergeability being computed, the queue. */
|
|
451
|
+
export function pullRequestSettling(pullRequest: PullRequestInfo): boolean {
|
|
452
|
+
if (pullRequest.state === "merged" || pullRequest.state === "closed") return false;
|
|
453
|
+
return pullRequest.checks.state === "pending" || pullRequest.mergeability === "unknown" || pullRequest.inMergeQueue;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
const MINUTE = 60_000;
|
|
457
|
+
const HOUR = 60 * MINUTE;
|
|
458
|
+
const DAY = 24 * HOUR;
|
|
459
|
+
const SHORT_DATE = new Intl.DateTimeFormat("en-US", { month: "short", day: "numeric" });
|
|
460
|
+
const LONG_DATE = new Intl.DateTimeFormat("en-US", { month: "short", day: "numeric", year: "numeric" });
|
|
461
|
+
|
|
462
|
+
/** "just now", "5 min ago", "3 h ago", "yesterday", "4 days ago", then the date. */
|
|
463
|
+
export function relativeTime(at: number, now: number): string {
|
|
464
|
+
const elapsed = now - at;
|
|
465
|
+
if (elapsed < MINUTE) return "just now";
|
|
466
|
+
if (elapsed < HOUR) return `${Math.floor(elapsed / MINUTE)} min ago`;
|
|
467
|
+
if (elapsed < DAY) return `${Math.floor(elapsed / HOUR)} h ago`;
|
|
468
|
+
if (elapsed < 2 * DAY) return "yesterday";
|
|
469
|
+
if (elapsed < 7 * DAY) return `${Math.floor(elapsed / DAY)} days ago`;
|
|
470
|
+
const date = new Date(at);
|
|
471
|
+
return (date.getFullYear() === new Date(now).getFullYear() ? SHORT_DATE : LONG_DATE).format(date);
|
|
472
|
+
}
|