@granular-software/fractory 0.0.0-stage → 0.1.24
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 +4 -0
- package/README.md +28 -2
- package/dist/activity-volume.d.ts +18 -0
- package/dist/activity-volume.js +94 -0
- package/dist/annotations.d.ts +118 -0
- package/dist/annotations.js +304 -0
- package/dist/benchmark-cli.d.ts +1 -0
- package/dist/benchmark-cli.js +95 -0
- package/dist/benchmark-worker.d.ts +2 -0
- package/dist/benchmark-worker.js +22 -0
- package/dist/benchmarks.d.ts +19 -0
- package/dist/benchmarks.js +414 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +63 -0
- package/dist/block-cli.d.ts +1 -0
- package/dist/block-cli.js +88 -0
- package/dist/block-documents.d.ts +35 -0
- package/dist/block-documents.js +84 -0
- package/dist/change-impact.d.ts +55 -0
- package/dist/change-impact.js +223 -0
- package/dist/check-source.d.ts +2 -0
- package/dist/check-source.js +66 -0
- package/dist/checks-model.d.ts +64 -0
- package/dist/checks-model.js +36 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +359 -0
- package/dist/code-model.d.ts +38 -0
- package/dist/code-model.js +94 -0
- package/dist/code-store.d.ts +9 -0
- package/dist/code-store.js +79 -0
- package/dist/compare-artifact.d.ts +6 -0
- package/dist/compare-artifact.js +277 -0
- package/dist/compare.d.ts +81 -0
- package/dist/compare.js +291 -0
- package/dist/compiler.d.ts +10 -0
- package/dist/compiler.js +1083 -0
- package/dist/compose.d.ts +9 -0
- package/dist/compose.js +72 -0
- package/dist/core.d.ts +86 -0
- package/dist/core.js +206 -0
- package/dist/coverage-cli.d.ts +1 -0
- package/dist/coverage-cli.js +42 -0
- package/dist/declaration-sources.d.ts +3 -0
- package/dist/declaration-sources.js +51 -0
- package/dist/declared-graph.d.ts +3 -0
- package/dist/declared-graph.js +66 -0
- package/dist/display-name.d.ts +2 -0
- package/dist/display-name.js +8 -0
- package/dist/error-heat.d.ts +58 -0
- package/dist/error-heat.js +96 -0
- package/dist/evidence.d.ts +3 -0
- package/dist/evidence.js +68 -0
- package/dist/factory-graph.d.ts +4 -0
- package/dist/factory-graph.js +318 -0
- package/dist/factory-model.d.ts +97 -0
- package/dist/factory-model.js +1 -0
- package/dist/git-code.d.ts +47 -0
- package/dist/git-code.js +352 -0
- package/dist/git-refs.d.ts +4 -0
- package/dist/git-refs.js +37 -0
- package/dist/history-activity.d.ts +4 -0
- package/dist/history-activity.js +129 -0
- package/dist/history-churn.d.ts +36 -0
- package/dist/history-churn.js +302 -0
- package/dist/history-git.d.ts +21 -0
- package/dist/history-git.js +125 -0
- package/dist/history-ledger.d.ts +43 -0
- package/dist/history-ledger.js +450 -0
- package/dist/history-ownership.d.ts +10 -0
- package/dist/history-ownership.js +75 -0
- package/dist/history-source.d.ts +13 -0
- package/dist/history-source.js +100 -0
- package/dist/integrations-cli.d.ts +2 -0
- package/dist/integrations-cli.js +159 -0
- package/dist/issue-cache.d.ts +9 -0
- package/dist/issue-cache.js +68 -0
- package/dist/issue-cli.d.ts +1 -0
- package/dist/issue-cli.js +89 -0
- package/dist/issue-links.d.ts +15 -0
- package/dist/issue-links.js +125 -0
- package/dist/linear-issues.d.ts +19 -0
- package/dist/linear-issues.js +124 -0
- package/dist/local-runtime.d.ts +8 -0
- package/dist/local-runtime.js +59 -0
- package/dist/map-activity.d.ts +73 -0
- package/dist/map-activity.js +234 -0
- package/dist/map-model.d.ts +5 -0
- package/dist/map-model.js +166 -0
- package/dist/map-quality.d.ts +14 -0
- package/dist/map-quality.js +56 -0
- package/dist/mapping-coverage.d.ts +87 -0
- package/dist/mapping-coverage.js +404 -0
- package/dist/model.d.ts +182 -0
- package/dist/model.js +66 -0
- package/dist/operation-benchmark-worker.d.ts +2 -0
- package/dist/operation-benchmark-worker.js +60 -0
- package/dist/operation-benchmark.d.ts +29 -0
- package/dist/operation-benchmark.js +1 -0
- package/dist/otel-metrics.d.ts +21 -0
- package/dist/otel-metrics.js +146 -0
- package/dist/performance-model.d.ts +185 -0
- package/dist/performance-model.js +396 -0
- package/dist/product-map.d.ts +69 -0
- package/dist/product-map.js +168 -0
- package/dist/provider-access.cjs +207 -0
- package/dist/provider-access.d.cts +14 -0
- package/dist/reports-cli.d.ts +1 -0
- package/dist/reports-cli.js +111 -0
- package/dist/reports-model.d.ts +27 -0
- package/dist/reports-model.js +39 -0
- package/dist/reports.d.ts +23 -0
- package/dist/reports.js +223 -0
- package/dist/repository-map.d.ts +22 -0
- package/dist/repository-map.js +151 -0
- package/dist/resource-cache.d.ts +17 -0
- package/dist/resource-cache.js +65 -0
- package/dist/review-cli.d.ts +19 -0
- package/dist/review-cli.js +224 -0
- package/dist/review.d.ts +48 -0
- package/dist/review.js +289 -0
- package/dist/runtime-metrics.d.ts +26 -0
- package/dist/runtime-metrics.js +290 -0
- package/dist/scope.d.ts +12 -0
- package/dist/scope.js +94 -0
- package/dist/sentry-activity.d.ts +39 -0
- package/dist/sentry-activity.js +174 -0
- package/dist/sentry.d.ts +130 -0
- package/dist/sentry.js +369 -0
- package/dist/service-release.d.ts +16 -0
- package/dist/service-release.js +14 -0
- package/dist/setup-cli.d.ts +2 -0
- package/dist/setup-cli.js +52 -0
- package/dist/setup-kit.cjs +163 -0
- package/dist/setup-kit.d.cts +32 -0
- package/dist/source-index.d.ts +37 -0
- package/dist/source-index.js +166 -0
- package/dist/source-review-git.d.ts +7 -0
- package/dist/source-review-git.js +103 -0
- package/dist/source-review.d.ts +16 -0
- package/dist/source-review.js +493 -0
- package/dist/telemetry.d.ts +17 -0
- package/dist/telemetry.js +51 -0
- package/dist/time-window.d.ts +9 -0
- package/dist/time-window.js +35 -0
- package/dist/trace-evidence.d.ts +23 -0
- package/dist/trace-evidence.js +55 -0
- package/dist/trace-model.d.ts +26 -0
- package/dist/trace-model.js +1 -0
- package/dist/tracing.d.ts +44 -0
- package/dist/tracing.js +123 -0
- package/dist/work-check.d.ts +17 -0
- package/dist/work-check.js +110 -0
- package/dist/work-cli.d.ts +1 -0
- package/dist/work-cli.js +148 -0
- package/dist/work-context.d.ts +57 -0
- package/dist/work-context.js +568 -0
- package/dist/work-intents.d.ts +6 -0
- package/dist/work-intents.js +140 -0
- package/dist/work-items.d.ts +58 -0
- package/dist/work-items.js +86 -0
- package/dist/work-model.d.ts +110 -0
- package/dist/work-model.js +261 -0
- package/dist/work-review-git.d.ts +8 -0
- package/dist/work-review-git.js +111 -0
- package/dist/work-review.d.ts +26 -0
- package/dist/work-review.js +426 -0
- package/dist/work-switcher-model.d.ts +43 -0
- package/dist/work-switcher-model.js +79 -0
- package/dist/work-switcher.d.ts +6 -0
- package/dist/work-switcher.js +171 -0
- package/dist/working-cli.d.ts +1 -0
- package/dist/working-cli.js +33 -0
- package/dist/working-code.d.ts +74 -0
- package/dist/working-code.js +421 -0
- package/dist/workspace-notes.d.ts +71 -0
- package/dist/workspace-notes.js +177 -0
- package/dist/workspace-tests.d.ts +21 -0
- package/dist/workspace-tests.js +573 -0
- package/package.json +547 -4
- package/src/activity-volume.ts +149 -0
- package/src/annotations.ts +481 -0
- package/src/benchmark-cli.ts +118 -0
- package/src/benchmark-worker.ts +22 -0
- package/src/benchmarks.ts +493 -0
- package/src/bin.ts +54 -0
- package/src/block-cli.ts +106 -0
- package/src/block-documents.ts +117 -0
- package/src/change-impact.ts +280 -0
- package/src/check-source.ts +82 -0
- package/src/checks-model.ts +108 -0
- package/src/cli.ts +440 -0
- package/src/code-model.ts +159 -0
- package/src/code-store.ts +98 -0
- package/src/compare-artifact.ts +314 -0
- package/src/compare.ts +440 -0
- package/src/compiler.ts +1326 -0
- package/src/compose.ts +94 -0
- package/src/core.ts +357 -0
- package/src/coverage-cli.ts +52 -0
- package/src/declaration-sources.ts +69 -0
- package/src/declared-graph.ts +74 -0
- package/src/display-name.ts +8 -0
- package/src/error-heat.ts +161 -0
- package/src/evidence.ts +94 -0
- package/src/factory-graph.ts +378 -0
- package/src/factory-model.ts +73 -0
- package/src/git-code.ts +461 -0
- package/src/git-refs.ts +43 -0
- package/src/history-activity.ts +146 -0
- package/src/history-churn.ts +416 -0
- package/src/history-git.ts +163 -0
- package/src/history-ledger.ts +636 -0
- package/src/history-ownership.ts +116 -0
- package/src/history-source.ts +117 -0
- package/src/integrations-cli.ts +187 -0
- package/src/issue-cache.ts +96 -0
- package/src/issue-cli.ts +137 -0
- package/src/issue-links.ts +153 -0
- package/src/linear-issues.ts +154 -0
- package/src/local-runtime.ts +70 -0
- package/src/map-activity.ts +309 -0
- package/src/map-model.ts +213 -0
- package/src/map-quality.ts +61 -0
- package/src/mapping-coverage.ts +570 -0
- package/src/model.ts +221 -0
- package/src/operation-benchmark-worker.ts +60 -0
- package/src/operation-benchmark.ts +28 -0
- package/src/otel-metrics.ts +176 -0
- package/src/performance-model.ts +575 -0
- package/src/product-map.ts +236 -0
- package/src/provider-access.cjs +207 -0
- package/src/provider-access.d.cts +14 -0
- package/src/reports-cli.ts +125 -0
- package/src/reports-model.ts +73 -0
- package/src/reports.ts +276 -0
- package/src/repository-map.ts +189 -0
- package/src/resource-cache.ts +76 -0
- package/src/review-cli.ts +256 -0
- package/src/review.ts +376 -0
- package/src/runtime-metrics.ts +386 -0
- package/src/scope.ts +103 -0
- package/src/sentry-activity.ts +234 -0
- package/src/sentry.ts +545 -0
- package/src/service-release.ts +18 -0
- package/src/setup-cli.ts +58 -0
- package/src/setup-kit.cjs +163 -0
- package/src/setup-kit.d.cts +32 -0
- package/src/source-index.ts +205 -0
- package/src/source-review-git.ts +129 -0
- package/src/source-review.ts +637 -0
- package/src/telemetry.ts +68 -0
- package/src/time-window.ts +51 -0
- package/src/trace-evidence.ts +80 -0
- package/src/trace-model.ts +26 -0
- package/src/tracing.ts +165 -0
- package/src/work-check.ts +143 -0
- package/src/work-cli.ts +195 -0
- package/src/work-context.ts +713 -0
- package/src/work-intents.ts +196 -0
- package/src/work-items.ts +151 -0
- package/src/work-model.ts +400 -0
- package/src/work-review-git.ts +130 -0
- package/src/work-review.ts +573 -0
- package/src/work-switcher-model.ts +121 -0
- package/src/work-switcher.ts +191 -0
- package/src/working-cli.ts +38 -0
- package/src/working-code.ts +582 -0
- package/src/workspace-notes.ts +203 -0
- package/src/workspace-tests.ts +654 -0
- package/toolkit/GUIDE.md +305 -0
- package/toolkit/SKILL.md +131 -0
- package/toolkit/bin/fractory +2 -0
- package/toolkit/build.json +1 -0
package/LICENSE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Fractory
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Your software as a factory map. This standalone package contains the block SDK, source compiler, Git/worktree tools, executable test integration, reports, benchmarks and provider connection CLI. It does not depend on Granular services.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @granular-software/fractory
|
|
7
|
+
npx fractory setup --install-skill
|
|
8
|
+
npx fractory doctor
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Ask your agent: `$fractory Map this product from real code and open it in Fractory.`
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { Block, Interface, Method, type InterfaceRef } from '@granular-software/fractory/annotations';
|
|
15
|
+
|
|
16
|
+
@Block({ id: 'builds', label: 'Product builds', description: 'Compile a versioned product.' })
|
|
17
|
+
export class Builds {
|
|
18
|
+
@Interface({ label: "Compile product" })
|
|
19
|
+
static readonly api: InterfaceRef;
|
|
20
|
+
@Method(() => Builds.api, { description: 'Compile the selected product version.' })
|
|
21
|
+
async compile(version: string) { return version; }
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Generate a versioned map with `npx fractory compile --include src --graph --write fractory.json`. Verify it in CI by adding `--check`. `npx fractory --help` lists all commands. Node 22 or newer and Git are required; repository tests and benchmarks use their own configured runners.
|
|
26
|
+
|
|
27
|
+
The Mac app is distributed separately as `Fractory.app`; `npx fractory open` opens the selected repository in the installed app. The npm package alone does not install Electron or require an account. Provider credentials stay on the developer's machine and are never part of a map or npm artifact.
|
|
28
|
+
|
|
29
|
+
Read the complete guide using `npx fractory guide`.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type TimeWindow } from "./time-window.js";
|
|
2
|
+
export interface ActivityVolume {
|
|
3
|
+
warnings?: import("./sentry.js").SentryProjectWarning[];
|
|
4
|
+
window: TimeWindow;
|
|
5
|
+
label: string;
|
|
6
|
+
unit: string;
|
|
7
|
+
buckets: {
|
|
8
|
+
from: number;
|
|
9
|
+
to: number;
|
|
10
|
+
value: number;
|
|
11
|
+
}[];
|
|
12
|
+
total: number;
|
|
13
|
+
partial: boolean;
|
|
14
|
+
latestAt?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function activityVolume(window: TimeWindow, times: (string | undefined)[], label: string, unit: string, partial?: boolean): ActivityVolume;
|
|
17
|
+
export declare function latestHistoryAt(root: string, files: string[], anchor?: string, allFiles?: boolean): Promise<string | undefined>;
|
|
18
|
+
export declare function historyVolume(root: string, files: string[], window: TimeWindow, anchor?: string, allFiles?: boolean): Promise<ActivityVolume>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/** Small time buckets for the range picker; never a source/stack history scan. */
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
import { DAY_MS, inTimeWindow } from "./time-window.js";
|
|
5
|
+
const execute = promisify(execFile);
|
|
6
|
+
export function activityVolume(window, times, label, unit, partial = false) {
|
|
7
|
+
const start = Date.parse(window.from), end = Date.parse(window.to);
|
|
8
|
+
const step = end - start <= 2 * DAY_MS
|
|
9
|
+
? 3600000
|
|
10
|
+
: end - start <= 14 * DAY_MS
|
|
11
|
+
? 21600000
|
|
12
|
+
: Math.ceil((end - start) / DAY_MS / 160) * DAY_MS;
|
|
13
|
+
const buckets = Array.from({ length: Math.ceil((end - start) / step) }, (_, i) => ({
|
|
14
|
+
from: start + i * step,
|
|
15
|
+
to: Math.min(end, start + (i + 1) * step),
|
|
16
|
+
value: 0,
|
|
17
|
+
}));
|
|
18
|
+
let total = 0;
|
|
19
|
+
for (const at of times)
|
|
20
|
+
if (at && inTimeWindow(at, window)) {
|
|
21
|
+
buckets[Math.min(buckets.length - 1, Math.floor((Date.parse(at) - start) / step))].value++;
|
|
22
|
+
total++;
|
|
23
|
+
}
|
|
24
|
+
return { window, label, unit, buckets, total, partial };
|
|
25
|
+
}
|
|
26
|
+
const gitOptions = (root) => ({
|
|
27
|
+
cwd: root,
|
|
28
|
+
encoding: "utf8",
|
|
29
|
+
timeout: 8000,
|
|
30
|
+
maxBuffer: 512000,
|
|
31
|
+
env: { ...process.env, GIT_OPTIONAL_LOCKS: "0", GIT_LITERAL_PATHSPECS: "1" },
|
|
32
|
+
});
|
|
33
|
+
function validate(files, anchor) {
|
|
34
|
+
if (anchor !== "HEAD" && !/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(anchor))
|
|
35
|
+
throw Error("Use a full commit SHA");
|
|
36
|
+
if (files.length > 2000 ||
|
|
37
|
+
files.join("").length > 180000 ||
|
|
38
|
+
files.some((p) => p.startsWith("/") ||
|
|
39
|
+
p.split(/[\\/]/).includes("..") ||
|
|
40
|
+
p.includes("\0")))
|
|
41
|
+
throw Error("Mapped files exceed the activity read budget");
|
|
42
|
+
}
|
|
43
|
+
export async function latestHistoryAt(root, files, anchor = "HEAD", allFiles = false) {
|
|
44
|
+
validate(files, anchor);
|
|
45
|
+
if (!files.length && !allFiles)
|
|
46
|
+
return;
|
|
47
|
+
const { stdout } = await execute("git", [
|
|
48
|
+
"--no-pager",
|
|
49
|
+
"-c",
|
|
50
|
+
"core.fsmonitor=false",
|
|
51
|
+
"log",
|
|
52
|
+
"--first-parent",
|
|
53
|
+
"-1",
|
|
54
|
+
"--format=%ct",
|
|
55
|
+
anchor,
|
|
56
|
+
"--",
|
|
57
|
+
...files,
|
|
58
|
+
], gitOptions(root));
|
|
59
|
+
return /^\d+\s*$/.test(stdout)
|
|
60
|
+
? new Date(Number(stdout.trim()) * 1000).toISOString()
|
|
61
|
+
: undefined;
|
|
62
|
+
}
|
|
63
|
+
export async function historyVolume(root, files, window, anchor = "HEAD", allFiles = false) {
|
|
64
|
+
validate(files, anchor);
|
|
65
|
+
if (!files.length && !allFiles)
|
|
66
|
+
return activityVolume(window, [], "Mapped code commits", "commits");
|
|
67
|
+
const [{ stdout }, latestAt] = await Promise.all([
|
|
68
|
+
execute("git", [
|
|
69
|
+
"--no-pager",
|
|
70
|
+
"-c",
|
|
71
|
+
"core.fsmonitor=false",
|
|
72
|
+
"log",
|
|
73
|
+
"--first-parent",
|
|
74
|
+
`--since-as-filter=${window.from}`,
|
|
75
|
+
`--until=${window.to}`,
|
|
76
|
+
"--format=%ct",
|
|
77
|
+
"--max-count=10001",
|
|
78
|
+
anchor,
|
|
79
|
+
"--",
|
|
80
|
+
...files,
|
|
81
|
+
], gitOptions(root)),
|
|
82
|
+
latestHistoryAt(root, files, anchor, allFiles),
|
|
83
|
+
]);
|
|
84
|
+
const stamps = stdout
|
|
85
|
+
.trim()
|
|
86
|
+
.split(/\s+/)
|
|
87
|
+
.filter((t) => /^\d+$/.test(t));
|
|
88
|
+
return {
|
|
89
|
+
...activityVolume(window, stamps
|
|
90
|
+
.slice(0, 10000)
|
|
91
|
+
.map((t) => new Date(Number(t) * 1000).toISOString()), allFiles ? "Repository commits" : "Mapped code commits", "commits", stamps.length > 10000),
|
|
92
|
+
latestAt,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/** Application annotations. No construction, DI, graph registry or host imports. */
|
|
2
|
+
export interface Attachments {
|
|
3
|
+
benchmarks?: readonly string[];
|
|
4
|
+
docs?: string | readonly string[];
|
|
5
|
+
tests?: readonly string[];
|
|
6
|
+
description?: string;
|
|
7
|
+
}
|
|
8
|
+
type Callable = (this: any, ...args: any[]) => any;
|
|
9
|
+
export interface Invocation {
|
|
10
|
+
readonly receiver: unknown;
|
|
11
|
+
readonly args: readonly unknown[];
|
|
12
|
+
/** Trusted host context, never decoded from a caller's payload. */
|
|
13
|
+
readonly context: unknown;
|
|
14
|
+
}
|
|
15
|
+
export interface RuntimeContract {
|
|
16
|
+
args?: {
|
|
17
|
+
parse(value: unknown): unknown;
|
|
18
|
+
};
|
|
19
|
+
result?: {
|
|
20
|
+
parse(value: unknown): unknown;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface InterfaceOptions extends Attachments {
|
|
24
|
+
/** Optional stable identity when adopting an existing mapped interface. */
|
|
25
|
+
id?: string;
|
|
26
|
+
label?: string;
|
|
27
|
+
auth?: (invocation: Invocation) => boolean | void | Promise<boolean | void>;
|
|
28
|
+
}
|
|
29
|
+
declare const interfaceBrand: unique symbol;
|
|
30
|
+
export interface InterfaceRef {
|
|
31
|
+
readonly [interfaceBrand]: true;
|
|
32
|
+
readonly id: string;
|
|
33
|
+
readonly blockId: string;
|
|
34
|
+
readonly name: string;
|
|
35
|
+
readonly options: InterfaceOptions;
|
|
36
|
+
}
|
|
37
|
+
export interface BlockOptions extends Attachments {
|
|
38
|
+
/** Display names only; shapes still come from actual parameters and props. */
|
|
39
|
+
inputLabel?: string;
|
|
40
|
+
eventLabel?: string;
|
|
41
|
+
id: string;
|
|
42
|
+
label?: string;
|
|
43
|
+
parent?: () => object;
|
|
44
|
+
}
|
|
45
|
+
export interface MethodOptions extends Attachments {
|
|
46
|
+
label?: string;
|
|
47
|
+
contract?: RuntimeContract;
|
|
48
|
+
/** Normally inferred from the declaration; useful for anonymous dynamic functions. */
|
|
49
|
+
name?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface FactoryEvent {
|
|
52
|
+
targetId?: string;
|
|
53
|
+
callerId?: string;
|
|
54
|
+
id: string;
|
|
55
|
+
traceId: string;
|
|
56
|
+
codeRevision?: string;
|
|
57
|
+
parentId?: string;
|
|
58
|
+
runId?: string;
|
|
59
|
+
linkedSpanId?: string;
|
|
60
|
+
linkedTraceId?: string;
|
|
61
|
+
blockId: string;
|
|
62
|
+
interfaceId?: string;
|
|
63
|
+
method: string;
|
|
64
|
+
timestamp: number;
|
|
65
|
+
status: "started" | "completed" | "failed";
|
|
66
|
+
durationMs?: number;
|
|
67
|
+
failure?: "auth" | "input" | "output" | "execution";
|
|
68
|
+
}
|
|
69
|
+
export interface FactoryFrame {
|
|
70
|
+
targetId?: string;
|
|
71
|
+
id: string;
|
|
72
|
+
traceId: string;
|
|
73
|
+
runId?: string;
|
|
74
|
+
linkedSpanId?: string;
|
|
75
|
+
linkedTraceId?: string;
|
|
76
|
+
finished?: boolean;
|
|
77
|
+
}
|
|
78
|
+
export interface FactoryHost {
|
|
79
|
+
current(): FactoryFrame | undefined;
|
|
80
|
+
run<T>(frame: FactoryFrame, execute: () => T): T;
|
|
81
|
+
context?(): unknown;
|
|
82
|
+
codeRevision?(): string | undefined;
|
|
83
|
+
emit(event: FactoryEvent): void;
|
|
84
|
+
}
|
|
85
|
+
/** Host adapters install async context once; application methods need no binding. */
|
|
86
|
+
export declare function installFactoryHost(adapter: FactoryHost): () => void;
|
|
87
|
+
export declare function observeFactory(listener: (event: FactoryEvent) => void): () => void;
|
|
88
|
+
export declare function Block(id: string | BlockOptions, options?: Omit<BlockOptions, "id">): <T extends object>(target: T, _context?: ClassDecoratorContext) => T;
|
|
89
|
+
/** A static field is the single declaration and typed reference for an interface. */
|
|
90
|
+
export interface StandaloneInterfaceOptions extends InterfaceOptions {
|
|
91
|
+
id: string;
|
|
92
|
+
parent: () => object;
|
|
93
|
+
}
|
|
94
|
+
export declare function Interface(id: string, options?: InterfaceOptions & {
|
|
95
|
+
parent?: () => object;
|
|
96
|
+
}): InterfaceRef;
|
|
97
|
+
export declare function Interface(options: StandaloneInterfaceOptions): InterfaceRef;
|
|
98
|
+
export declare function Interface(options?: InterfaceOptions): ReturnType<typeof interfaceDecorator>;
|
|
99
|
+
declare function interfaceDecorator(options: InterfaceOptions): {
|
|
100
|
+
<T>(_: undefined, context: ClassFieldDecoratorContext<T, InterfaceRef>): (this: T, value: InterfaceRef) => InterfaceRef;
|
|
101
|
+
(target: Function, key: string | symbol): void;
|
|
102
|
+
};
|
|
103
|
+
export declare class FactoryViolation extends Error {
|
|
104
|
+
readonly phase: "auth" | "input" | "output";
|
|
105
|
+
readonly cause: unknown;
|
|
106
|
+
constructor(phase: "auth" | "input" | "output", cause: unknown);
|
|
107
|
+
}
|
|
108
|
+
export declare function Method(reference: () => InterfaceRef, options?: MethodOptions): {
|
|
109
|
+
<F extends Callable>(fn: F): F;
|
|
110
|
+
<This, A extends any[], R>(fn: (this: This, ...args: A) => R, context: ClassMethodDecoratorContext<This, (this: This, ...args: A) => R>): (this: This, ...args: A) => R;
|
|
111
|
+
(target: object, key: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor;
|
|
112
|
+
};
|
|
113
|
+
export declare function Process(id: string | BlockOptions, options?: Omit<BlockOptions, "id">): {
|
|
114
|
+
<F extends Callable>(fn: F): F;
|
|
115
|
+
<This, A extends any[], R>(fn: (this: This, ...args: A) => R, context: ClassMethodDecoratorContext<This, (this: This, ...args: A) => R>): (this: This, ...args: A) => R;
|
|
116
|
+
(target: object, key: string | symbol, descriptor: PropertyDescriptor): PropertyDescriptor;
|
|
117
|
+
};
|
|
118
|
+
export {};
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
const interfaceBrand = Symbol("fractal.interface");
|
|
2
|
+
const blocks = new WeakMap();
|
|
3
|
+
const wrappers = new WeakMap();
|
|
4
|
+
const listeners = new Set();
|
|
5
|
+
let host;
|
|
6
|
+
/** Host adapters install async context once; application methods need no binding. */
|
|
7
|
+
export function installFactoryHost(adapter) {
|
|
8
|
+
const previous = host;
|
|
9
|
+
host = adapter;
|
|
10
|
+
return () => {
|
|
11
|
+
if (host === adapter)
|
|
12
|
+
host = previous;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function observeFactory(listener) {
|
|
16
|
+
listeners.add(listener);
|
|
17
|
+
return () => {
|
|
18
|
+
listeners.delete(listener);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function publish(event, adapter) {
|
|
22
|
+
try {
|
|
23
|
+
adapter?.emit(event);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
/* telemetry cannot affect execution */
|
|
27
|
+
}
|
|
28
|
+
for (const listener of listeners) {
|
|
29
|
+
try {
|
|
30
|
+
listener(event);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
/* telemetry only */
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function identity(value) {
|
|
38
|
+
if (!value.trim())
|
|
39
|
+
throw new Error("Fractal identity must not be empty");
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
export function Block(id, options = {}) {
|
|
43
|
+
const definition = typeof id === "string"
|
|
44
|
+
? { ...options, id: identity(id) }
|
|
45
|
+
: { ...id, id: identity(id.id) };
|
|
46
|
+
return (target, _context) => {
|
|
47
|
+
blocks.set(target, definition);
|
|
48
|
+
return target;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function makeInterface(owner, name, options) {
|
|
52
|
+
return Object.freeze({
|
|
53
|
+
[interfaceBrand]: true,
|
|
54
|
+
name,
|
|
55
|
+
options: Object.freeze({ ...options }),
|
|
56
|
+
get blockId() {
|
|
57
|
+
const definition = blocks.get(owner());
|
|
58
|
+
if (!definition)
|
|
59
|
+
throw new Error(`Interface ${name} needs an annotated block`);
|
|
60
|
+
return definition.id;
|
|
61
|
+
},
|
|
62
|
+
get id() {
|
|
63
|
+
return options.id || `${this.blockId}::${name}`;
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
export function Interface(options = {}, details = {}) {
|
|
68
|
+
if (typeof options === "string") {
|
|
69
|
+
const id = identity(options), name = id.split("/").slice(-1)[0];
|
|
70
|
+
if (details.parent)
|
|
71
|
+
return makeInterface(details.parent, name, { ...details, id });
|
|
72
|
+
return Object.freeze({
|
|
73
|
+
[interfaceBrand]: true,
|
|
74
|
+
id,
|
|
75
|
+
name,
|
|
76
|
+
blockId: id.includes("/") ? id.slice(0, id.lastIndexOf("/")) : "factory",
|
|
77
|
+
options: Object.freeze({ ...details, id }),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if ("parent" in options)
|
|
81
|
+
return makeInterface(options.parent, identity(options.id).split("/").slice(-1)[0], options);
|
|
82
|
+
return interfaceDecorator(options);
|
|
83
|
+
}
|
|
84
|
+
function interfaceDecorator(options) {
|
|
85
|
+
function decorate(target, context) {
|
|
86
|
+
if (typeof context === "object") {
|
|
87
|
+
if (!context.static || context.private)
|
|
88
|
+
throw new Error("@Interface requires a public static field");
|
|
89
|
+
context.addInitializer(function () {
|
|
90
|
+
const owner = this;
|
|
91
|
+
if (!owner[context.name]?.[interfaceBrand])
|
|
92
|
+
Object.defineProperty(owner, context.name, {
|
|
93
|
+
value: makeInterface(() => owner, String(context.name), options),
|
|
94
|
+
writable: false,
|
|
95
|
+
configurable: true,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
return function () {
|
|
99
|
+
return makeInterface(() => this, String(context.name), options);
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
// Bun's legacy field decorators execute after class fields initialize.
|
|
103
|
+
const value = makeInterface(() => target, String(context), options);
|
|
104
|
+
Object.defineProperty(target, context, {
|
|
105
|
+
value,
|
|
106
|
+
writable: false,
|
|
107
|
+
configurable: true,
|
|
108
|
+
});
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
return decorate;
|
|
112
|
+
}
|
|
113
|
+
export class FactoryViolation extends Error {
|
|
114
|
+
phase;
|
|
115
|
+
cause;
|
|
116
|
+
constructor(phase, cause) {
|
|
117
|
+
super(`Fractal ${phase} requirement failed`);
|
|
118
|
+
this.phase = phase;
|
|
119
|
+
this.cause = cause;
|
|
120
|
+
this.name = "FactoryViolation";
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function validate(parser, value) {
|
|
124
|
+
const result = parser?.parse(value);
|
|
125
|
+
if (result && typeof result.then === "function") {
|
|
126
|
+
void Promise.resolve(result).catch(() => { });
|
|
127
|
+
throw new Error("Fractal runtime validators must be synchronous");
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function wrap(fn, name, reference, process, options = {}) {
|
|
131
|
+
const previous = wrappers.get(fn);
|
|
132
|
+
if (previous) {
|
|
133
|
+
fn = previous.original;
|
|
134
|
+
reference ||= previous.reference;
|
|
135
|
+
process ||= previous.process;
|
|
136
|
+
options = { ...previous.options, ...options };
|
|
137
|
+
}
|
|
138
|
+
const wrapped = function (...args) {
|
|
139
|
+
const api = reference?.();
|
|
140
|
+
if (reference && (!api || api[interfaceBrand] !== true))
|
|
141
|
+
throw new Error("@Method requires an initialized typed interface reference");
|
|
142
|
+
const adapter = host;
|
|
143
|
+
// Public SDK/browser packages bundle only this portable module. Without an
|
|
144
|
+
// observer or an explicit policy/validator, preserve the original call path.
|
|
145
|
+
if (!adapter && !listeners.size && !options.contract && !api?.options.auth)
|
|
146
|
+
return fn.apply(this, args);
|
|
147
|
+
const parent = adapter?.current();
|
|
148
|
+
const id = crypto.randomUUID();
|
|
149
|
+
const frame = {
|
|
150
|
+
targetId: process?.id ||
|
|
151
|
+
`${api.id}#${options.name || name || fn.name || "call"}`,
|
|
152
|
+
id,
|
|
153
|
+
traceId: parent && !parent.finished ? parent.traceId : id,
|
|
154
|
+
runId: parent?.runId || parent?.traceId || id,
|
|
155
|
+
};
|
|
156
|
+
let codeRevision;
|
|
157
|
+
try {
|
|
158
|
+
codeRevision = adapter?.codeRevision?.();
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
/* metadata is observational */
|
|
162
|
+
}
|
|
163
|
+
const started = performance.now();
|
|
164
|
+
let terminal = false;
|
|
165
|
+
const base = {
|
|
166
|
+
targetId: frame.targetId,
|
|
167
|
+
...(parent?.targetId && !parent.finished
|
|
168
|
+
? { callerId: parent.targetId }
|
|
169
|
+
: {}),
|
|
170
|
+
id,
|
|
171
|
+
traceId: frame.traceId,
|
|
172
|
+
...(codeRevision ? { codeRevision } : {}),
|
|
173
|
+
runId: frame.runId,
|
|
174
|
+
...(parent?.id && !parent.finished ? { parentId: parent.id } : {}),
|
|
175
|
+
...(parent?.finished
|
|
176
|
+
? { linkedSpanId: parent.id, linkedTraceId: parent.traceId }
|
|
177
|
+
: !parent?.id && parent?.linkedSpanId
|
|
178
|
+
? {
|
|
179
|
+
linkedSpanId: parent.linkedSpanId,
|
|
180
|
+
linkedTraceId: parent.linkedTraceId,
|
|
181
|
+
}
|
|
182
|
+
: {}),
|
|
183
|
+
blockId: process?.id || api.blockId,
|
|
184
|
+
...(api ? { interfaceId: api.id } : {}),
|
|
185
|
+
method: options.name || name || fn.name || "call",
|
|
186
|
+
};
|
|
187
|
+
const emit = (status, failure) => {
|
|
188
|
+
if (status !== "started") {
|
|
189
|
+
if (terminal)
|
|
190
|
+
return;
|
|
191
|
+
terminal = true;
|
|
192
|
+
frame.finished = true;
|
|
193
|
+
}
|
|
194
|
+
publish({
|
|
195
|
+
...base,
|
|
196
|
+
timestamp: Date.now(),
|
|
197
|
+
status,
|
|
198
|
+
...(status !== "started"
|
|
199
|
+
? { durationMs: performance.now() - started }
|
|
200
|
+
: {}),
|
|
201
|
+
...(failure ? { failure } : {}),
|
|
202
|
+
}, adapter);
|
|
203
|
+
};
|
|
204
|
+
const execute = () => {
|
|
205
|
+
emit("started");
|
|
206
|
+
let phase = "auth";
|
|
207
|
+
const failed = (error) => {
|
|
208
|
+
emit("failed", phase);
|
|
209
|
+
throw error;
|
|
210
|
+
};
|
|
211
|
+
const invoke = () => {
|
|
212
|
+
phase = "input";
|
|
213
|
+
// Validate without replacing live handles, object identity or caller arguments.
|
|
214
|
+
validate(options.contract?.args, args);
|
|
215
|
+
phase = "execution";
|
|
216
|
+
const value = fn.apply(this, args);
|
|
217
|
+
const complete = (result) => {
|
|
218
|
+
phase = "output";
|
|
219
|
+
validate(options.contract?.result, result);
|
|
220
|
+
emit("completed");
|
|
221
|
+
return result;
|
|
222
|
+
};
|
|
223
|
+
if (value && typeof value.then === "function") {
|
|
224
|
+
if (options.contract?.result)
|
|
225
|
+
return Promise.resolve(value).then(complete).catch(failed);
|
|
226
|
+
// Pure observation must not delay existing promise settlement or recovery scheduling.
|
|
227
|
+
void Promise.resolve(value).then(() => emit("completed"), () => emit("failed", "execution"));
|
|
228
|
+
return value;
|
|
229
|
+
}
|
|
230
|
+
return complete(value);
|
|
231
|
+
};
|
|
232
|
+
try {
|
|
233
|
+
const authorized = api?.options.auth?.({
|
|
234
|
+
receiver: this,
|
|
235
|
+
args,
|
|
236
|
+
context: adapter?.context?.(),
|
|
237
|
+
});
|
|
238
|
+
if (authorized &&
|
|
239
|
+
typeof authorized === "object" &&
|
|
240
|
+
typeof authorized.then === "function") {
|
|
241
|
+
if (fn.constructor.name !== "AsyncFunction") {
|
|
242
|
+
void authorized.catch(() => { });
|
|
243
|
+
throw new Error("Async auth requires an async method");
|
|
244
|
+
}
|
|
245
|
+
return authorized
|
|
246
|
+
.then((allowed) => {
|
|
247
|
+
if (allowed === false)
|
|
248
|
+
throw new FactoryViolation("auth", false);
|
|
249
|
+
return invoke();
|
|
250
|
+
})
|
|
251
|
+
.catch(failed);
|
|
252
|
+
}
|
|
253
|
+
if (authorized === false)
|
|
254
|
+
throw new FactoryViolation("auth", false);
|
|
255
|
+
return invoke();
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
return failed(error);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
const run = () => (adapter ? adapter.run(frame, execute) : execute());
|
|
262
|
+
// Preserve native async rejection semantics even when auth/input validation throws.
|
|
263
|
+
try {
|
|
264
|
+
return run();
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
if (fn.constructor.name === "AsyncFunction")
|
|
268
|
+
return Promise.reject(error);
|
|
269
|
+
throw error;
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
Object.defineProperty(wrapped, "name", {
|
|
273
|
+
value: options.name || name || fn.name,
|
|
274
|
+
configurable: true,
|
|
275
|
+
});
|
|
276
|
+
Object.defineProperty(wrapped, "length", {
|
|
277
|
+
value: fn.length,
|
|
278
|
+
configurable: true,
|
|
279
|
+
});
|
|
280
|
+
if (process)
|
|
281
|
+
blocks.set(wrapped, process);
|
|
282
|
+
wrappers.set(wrapped, { original: fn, reference, process, options });
|
|
283
|
+
return wrapped;
|
|
284
|
+
}
|
|
285
|
+
function callableDecorator(reference, process, options = {}) {
|
|
286
|
+
function decorate(target, context, descriptor) {
|
|
287
|
+
if (descriptor) {
|
|
288
|
+
descriptor.value = wrap(descriptor.value, String(context), reference, process, options);
|
|
289
|
+
return descriptor;
|
|
290
|
+
}
|
|
291
|
+
const fn = target;
|
|
292
|
+
return wrap(fn, typeof context === "object" ? String(context.name) : fn.name, reference, process, options);
|
|
293
|
+
}
|
|
294
|
+
return decorate;
|
|
295
|
+
}
|
|
296
|
+
export function Method(reference, options = {}) {
|
|
297
|
+
return callableDecorator(reference, undefined, options);
|
|
298
|
+
}
|
|
299
|
+
export function Process(id, options = {}) {
|
|
300
|
+
const definition = typeof id === "string"
|
|
301
|
+
? { ...options, id: identity(id) }
|
|
302
|
+
: { ...id, id: identity(id.id) };
|
|
303
|
+
return callableDecorator(undefined, definition);
|
|
304
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runBenchmark(args: string[]): Promise<string>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { readRepositoryMap } from "./repository-map.js";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { BenchmarkRunner } from "./benchmarks.js";
|
|
4
|
+
import { compareBenchmark, benchmarkComparisonReason, durationLabel, } from "./performance-model.js";
|
|
5
|
+
export async function runBenchmark(args) {
|
|
6
|
+
if (args.includes("--help"))
|
|
7
|
+
return "fractal benchmark [--block ID] [--file PATH] [--run] [--baseline RUN_ID] [--functions] [--compare RUN --against REFERENCE] [--json] [--root PATH]\nRuns attached product operations on their configured test deployment. --functions includes local Tinybench checks. Measurements are separate from production metrics.";
|
|
8
|
+
const option = (key) => {
|
|
9
|
+
const i = args.indexOf(key);
|
|
10
|
+
if (i < 0)
|
|
11
|
+
return undefined;
|
|
12
|
+
if (!args[i + 1] || args[i + 1].startsWith("--"))
|
|
13
|
+
throw Error(key + " needs a value");
|
|
14
|
+
return args[i + 1];
|
|
15
|
+
};
|
|
16
|
+
const root = resolve(option("--root") || process.cwd());
|
|
17
|
+
const graph = readRepositoryMap(root);
|
|
18
|
+
if (!graph)
|
|
19
|
+
throw Error("No Fractory map in this repository. Run fractory setup.");
|
|
20
|
+
const runner = new BenchmarkRunner(root, graph), block = option("--block"), file = option("--file");
|
|
21
|
+
if (option("--baseline"))
|
|
22
|
+
runner.baseline(option("--baseline"));
|
|
23
|
+
if (option("--compare")) {
|
|
24
|
+
const view = runner.view(), current = view.runs.find((r) => r.id === option("--compare")), baseline = view.runs.find((r) => r.id === option("--against"));
|
|
25
|
+
if (!current || !baseline)
|
|
26
|
+
throw Error("Choose two recorded run IDs with --compare RUN --against REFERENCE.");
|
|
27
|
+
return JSON.stringify({
|
|
28
|
+
operation: current.file,
|
|
29
|
+
current: {
|
|
30
|
+
id: current.id,
|
|
31
|
+
target: current.target,
|
|
32
|
+
fixture: current.fixture,
|
|
33
|
+
status: current.status,
|
|
34
|
+
},
|
|
35
|
+
reference: {
|
|
36
|
+
id: baseline.id,
|
|
37
|
+
target: baseline.target,
|
|
38
|
+
fixture: baseline.fixture,
|
|
39
|
+
status: baseline.status,
|
|
40
|
+
},
|
|
41
|
+
sameDeployedRevision: !!current.target &&
|
|
42
|
+
current.target.revision === baseline.target?.revision,
|
|
43
|
+
cases: current.cases.map((c) => ({
|
|
44
|
+
name: c.name,
|
|
45
|
+
currentMeanMs: c.meanMs,
|
|
46
|
+
referenceMeanMs: baseline.cases.find((b) => b.name === c.name)
|
|
47
|
+
?.meanMs,
|
|
48
|
+
result: compareBenchmark(current, baseline, c.name),
|
|
49
|
+
reason: benchmarkComparisonReason(current, baseline, c.name),
|
|
50
|
+
})),
|
|
51
|
+
}, null, 2);
|
|
52
|
+
}
|
|
53
|
+
const ids = new Set([block || graph.id]);
|
|
54
|
+
for (let added = true; added;) {
|
|
55
|
+
added = false;
|
|
56
|
+
for (const node of graph.elements)
|
|
57
|
+
if (node.parent && ids.has(node.parent) && !ids.has(node.id)) {
|
|
58
|
+
ids.add(node.id);
|
|
59
|
+
added = true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const plans = runner
|
|
63
|
+
.view()
|
|
64
|
+
.plans.filter((plan) => (file || args.includes("--functions") || plan.kind === "operation") &&
|
|
65
|
+
(!file || plan.file === file) &&
|
|
66
|
+
plan.blocks.some((id) => ids.has(id)));
|
|
67
|
+
if ((block && !graph.elements.some((node) => node.id === block)) ||
|
|
68
|
+
(file && !plans.length))
|
|
69
|
+
throw Error("Choose a mapped block and an attached benchmark.");
|
|
70
|
+
if (args.includes("--run"))
|
|
71
|
+
for (const plan of plans) {
|
|
72
|
+
const started = runner.start(plan.file);
|
|
73
|
+
const finished = await runner.wait(started.id);
|
|
74
|
+
if (finished.status !== "passed")
|
|
75
|
+
process.exitCode = 1;
|
|
76
|
+
}
|
|
77
|
+
const view = runner.view();
|
|
78
|
+
const result = plans.map((plan) => {
|
|
79
|
+
const current = view.runs.find((run) => run.file === plan.file), baseline = view.runs.find((run) => run.id === view.baselines[plan.file]);
|
|
80
|
+
return {
|
|
81
|
+
...plan,
|
|
82
|
+
current,
|
|
83
|
+
baseline: baseline?.id,
|
|
84
|
+
comparison: current?.cases.map((item) => ({
|
|
85
|
+
name: item.name,
|
|
86
|
+
change: compareBenchmark(current, baseline, item.name),
|
|
87
|
+
})),
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
return args.includes("--json")
|
|
91
|
+
? JSON.stringify(result, null, 2)
|
|
92
|
+
: result
|
|
93
|
+
.map(({ label, file, current, baseline, kind }) => `${label}\n${file}\n${current ? `${current.status} · ${current.id}${baseline === current.id ? " · baseline" : ""}\n${current.error || current.cases.map((item) => `${item.name}: ${durationLabel(item.meanMs)} ±${durationLabel(item.marginMs)} · ${item.samples} ${kind === "operation" ? "attempts" : "samples"}`).join("\n")}${current.target ? `\n${current.target.name} · ${current.target.revision.slice(0, 8)} · ${current.target.measurement} timing` : ""}` : "Not run"}`)
|
|
94
|
+
.join("\n\n");
|
|
95
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** Isolated Bun entrypoint; application code is loaded only after an explicit run. */
|
|
2
|
+
export declare const benchmarkWorker = "\nimport { writeFileSync } from 'node:fs';\nimport { pathToFileURL } from 'node:url';\nconst [file, report] = process.argv.slice(1);\ntry {\n const { default: bench } = await import(pathToFileURL(file).href);\n if (!bench || typeof bench.run !== 'function' || typeof bench.warmup !== 'function' || !Array.isArray(bench.tasks)) throw Error('Export a Tinybench Bench instance as default.');\n if (bench.tasks.length < 1 || bench.tasks.length > 12) throw Error('Keep each suite between 1 and 12 cases.');\n bench.time = Math.max(100, Math.min(1000, bench.time || 250));\n bench.iterations = Math.max(20, Math.min(100000, bench.iterations || 20));\n bench.warmupTime = 100; bench.warmupIterations = 20;\n await bench.warmup(); await bench.run();\n const cases = bench.tasks.map(task => {\n const r = task.result; if (r?.error) throw r.error;\n if (!r || !Number.isFinite(r.mean) || r.mean <= 0 || !r.samples.length) throw Error('No valid timing samples for ' + task.name);\n const sorted = [...r.samples].sort((a,b) => a-b);\n return { name: task.name, samples: sorted.length, meanMs: r.mean, marginMs: Number.isFinite(r.moe) ? r.moe : r.mean, p95Ms: sorted[Math.min(sorted.length-1, Math.ceil(sorted.length*.95)-1)], hz: r.hz };\n });\n writeFileSync(report, JSON.stringify({ cases, runtime: Bun.version }));\n} catch (error) { console.error(error); process.exitCode = 1; }\n";
|