@hearsay-tools/squawk 0.18.0-pr4243.8199 → 0.18.0-pr4244.8211
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.
|
@@ -2,18 +2,6 @@ import type { DelegationRoutes } from './routes.ts';
|
|
|
2
2
|
export declare function createDelegationApp(routes: DelegationRoutes): import("hono/hono-base").HonoBase<import("hono/types").BlankEnv, import("hono/types").BlankSchema | import("hono/types").MergeSchemaPath<{
|
|
3
3
|
"/list": {
|
|
4
4
|
$get: {
|
|
5
|
-
output: {
|
|
6
|
-
error: string;
|
|
7
|
-
code?: "invalid_input" | undefined;
|
|
8
|
-
};
|
|
9
|
-
outputFormat: "json";
|
|
10
|
-
status: 400;
|
|
11
|
-
input: {
|
|
12
|
-
query: {
|
|
13
|
-
offset?: string | undefined;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
} | {
|
|
17
5
|
output: {
|
|
18
6
|
workers: {
|
|
19
7
|
workerId: string;
|
|
@@ -66,6 +54,18 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
|
|
|
66
54
|
offset?: string | undefined;
|
|
67
55
|
};
|
|
68
56
|
};
|
|
57
|
+
} | {
|
|
58
|
+
output: {
|
|
59
|
+
error: string;
|
|
60
|
+
code?: "invalid_input" | undefined;
|
|
61
|
+
};
|
|
62
|
+
outputFormat: "json";
|
|
63
|
+
status: 400;
|
|
64
|
+
input: {
|
|
65
|
+
query: {
|
|
66
|
+
offset?: string | undefined;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
69
|
};
|
|
70
70
|
};
|
|
71
71
|
} & {
|
|
@@ -652,18 +652,6 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
|
|
|
652
652
|
} & {
|
|
653
653
|
"/:workerId": {
|
|
654
654
|
$get: {
|
|
655
|
-
output: {
|
|
656
|
-
error: string;
|
|
657
|
-
code?: "invalid_input" | undefined;
|
|
658
|
-
};
|
|
659
|
-
outputFormat: "json";
|
|
660
|
-
status: 400;
|
|
661
|
-
input: {
|
|
662
|
-
param: {
|
|
663
|
-
workerId: string;
|
|
664
|
-
};
|
|
665
|
-
};
|
|
666
|
-
} | {
|
|
667
655
|
output: {
|
|
668
656
|
workerId: string;
|
|
669
657
|
settled: boolean;
|
|
@@ -788,11 +776,7 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
|
|
|
788
776
|
workerId: string;
|
|
789
777
|
};
|
|
790
778
|
};
|
|
791
|
-
}
|
|
792
|
-
};
|
|
793
|
-
} & {
|
|
794
|
-
"/:workerId/collect": {
|
|
795
|
-
$post: {
|
|
779
|
+
} | {
|
|
796
780
|
output: {
|
|
797
781
|
error: string;
|
|
798
782
|
code?: "invalid_input" | undefined;
|
|
@@ -803,10 +787,12 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
|
|
|
803
787
|
param: {
|
|
804
788
|
workerId: string;
|
|
805
789
|
};
|
|
806
|
-
} & {
|
|
807
|
-
json: Record<string, never>;
|
|
808
790
|
};
|
|
809
|
-
}
|
|
791
|
+
};
|
|
792
|
+
};
|
|
793
|
+
} & {
|
|
794
|
+
"/:workerId/collect": {
|
|
795
|
+
$post: {
|
|
810
796
|
output: {
|
|
811
797
|
workerId: string;
|
|
812
798
|
parentRunId: string;
|
|
@@ -929,11 +915,7 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
|
|
|
929
915
|
} & {
|
|
930
916
|
json: Record<string, never>;
|
|
931
917
|
};
|
|
932
|
-
}
|
|
933
|
-
};
|
|
934
|
-
} & {
|
|
935
|
-
"/:workerId/steer": {
|
|
936
|
-
$post: {
|
|
918
|
+
} | {
|
|
937
919
|
output: {
|
|
938
920
|
error: string;
|
|
939
921
|
code?: "invalid_input" | undefined;
|
|
@@ -945,11 +927,13 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
|
|
|
945
927
|
workerId: string;
|
|
946
928
|
};
|
|
947
929
|
} & {
|
|
948
|
-
json:
|
|
949
|
-
text: string;
|
|
950
|
-
};
|
|
930
|
+
json: Record<string, never>;
|
|
951
931
|
};
|
|
952
|
-
}
|
|
932
|
+
};
|
|
933
|
+
};
|
|
934
|
+
} & {
|
|
935
|
+
"/:workerId/steer": {
|
|
936
|
+
$post: {
|
|
953
937
|
output: {
|
|
954
938
|
workerId: string;
|
|
955
939
|
state: "delivered" | "queued";
|
|
@@ -965,11 +949,7 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
|
|
|
965
949
|
text: string;
|
|
966
950
|
};
|
|
967
951
|
};
|
|
968
|
-
}
|
|
969
|
-
};
|
|
970
|
-
} & {
|
|
971
|
-
"/:workerId/stop": {
|
|
972
|
-
$post: {
|
|
952
|
+
} | {
|
|
973
953
|
output: {
|
|
974
954
|
error: string;
|
|
975
955
|
code?: "invalid_input" | undefined;
|
|
@@ -981,9 +961,15 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
|
|
|
981
961
|
workerId: string;
|
|
982
962
|
};
|
|
983
963
|
} & {
|
|
984
|
-
json:
|
|
964
|
+
json: {
|
|
965
|
+
text: string;
|
|
966
|
+
};
|
|
985
967
|
};
|
|
986
|
-
}
|
|
968
|
+
};
|
|
969
|
+
};
|
|
970
|
+
} & {
|
|
971
|
+
"/:workerId/stop": {
|
|
972
|
+
$post: {
|
|
987
973
|
output: {
|
|
988
974
|
workerId: string;
|
|
989
975
|
state: "stopping" | "terminated";
|
|
@@ -997,11 +983,7 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
|
|
|
997
983
|
} & {
|
|
998
984
|
json: Record<string, never>;
|
|
999
985
|
};
|
|
1000
|
-
}
|
|
1001
|
-
};
|
|
1002
|
-
} & {
|
|
1003
|
-
"/:workerId/destroy": {
|
|
1004
|
-
$post: {
|
|
986
|
+
} | {
|
|
1005
987
|
output: {
|
|
1006
988
|
error: string;
|
|
1007
989
|
code?: "invalid_input" | undefined;
|
|
@@ -1013,11 +995,13 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
|
|
|
1013
995
|
workerId: string;
|
|
1014
996
|
};
|
|
1015
997
|
} & {
|
|
1016
|
-
json:
|
|
1017
|
-
discardWork?: true | undefined;
|
|
1018
|
-
};
|
|
998
|
+
json: Record<string, never>;
|
|
1019
999
|
};
|
|
1020
|
-
}
|
|
1000
|
+
};
|
|
1001
|
+
};
|
|
1002
|
+
} & {
|
|
1003
|
+
"/:workerId/destroy": {
|
|
1004
|
+
$post: {
|
|
1021
1005
|
output: {
|
|
1022
1006
|
workerId: string;
|
|
1023
1007
|
state: "complete" | "incomplete";
|
|
@@ -1046,6 +1030,22 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
|
|
|
1046
1030
|
discardWork?: true | undefined;
|
|
1047
1031
|
};
|
|
1048
1032
|
};
|
|
1033
|
+
} | {
|
|
1034
|
+
output: {
|
|
1035
|
+
error: string;
|
|
1036
|
+
code?: "invalid_input" | undefined;
|
|
1037
|
+
};
|
|
1038
|
+
outputFormat: "json";
|
|
1039
|
+
status: 400;
|
|
1040
|
+
input: {
|
|
1041
|
+
param: {
|
|
1042
|
+
workerId: string;
|
|
1043
|
+
};
|
|
1044
|
+
} & {
|
|
1045
|
+
json: {
|
|
1046
|
+
discardWork?: true | undefined;
|
|
1047
|
+
};
|
|
1048
|
+
};
|
|
1049
1049
|
} | {
|
|
1050
1050
|
output: {
|
|
1051
1051
|
workerId: string;
|
|
@@ -1081,11 +1081,13 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
|
|
|
1081
1081
|
"/:workerId/diff": {
|
|
1082
1082
|
$get: {
|
|
1083
1083
|
output: {
|
|
1084
|
-
|
|
1085
|
-
|
|
1084
|
+
workerId: string;
|
|
1085
|
+
baselineSha: string;
|
|
1086
|
+
diff: string;
|
|
1087
|
+
truncated: boolean;
|
|
1086
1088
|
};
|
|
1087
1089
|
outputFormat: "json";
|
|
1088
|
-
status:
|
|
1090
|
+
status: 200;
|
|
1089
1091
|
input: {
|
|
1090
1092
|
param: {
|
|
1091
1093
|
workerId: string;
|
|
@@ -1093,13 +1095,11 @@ export declare function createDelegationApp(routes: DelegationRoutes): import("h
|
|
|
1093
1095
|
};
|
|
1094
1096
|
} | {
|
|
1095
1097
|
output: {
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
diff: string;
|
|
1099
|
-
truncated: boolean;
|
|
1098
|
+
error: string;
|
|
1099
|
+
code?: "invalid_input" | undefined;
|
|
1100
1100
|
};
|
|
1101
1101
|
outputFormat: "json";
|
|
1102
|
-
status:
|
|
1102
|
+
status: 400;
|
|
1103
1103
|
input: {
|
|
1104
1104
|
param: {
|
|
1105
1105
|
workerId: string;
|
|
@@ -40,7 +40,7 @@ export declare const reportsRoutes: import("hono/hono-base").HonoBase<ProjectApi
|
|
|
40
40
|
error: string;
|
|
41
41
|
};
|
|
42
42
|
outputFormat: "json";
|
|
43
|
-
status:
|
|
43
|
+
status: 400;
|
|
44
44
|
input: {
|
|
45
45
|
query: {
|
|
46
46
|
q?: string | undefined;
|
|
@@ -53,7 +53,7 @@ export declare const reportsRoutes: import("hono/hono-base").HonoBase<ProjectApi
|
|
|
53
53
|
error: string;
|
|
54
54
|
};
|
|
55
55
|
outputFormat: "json";
|
|
56
|
-
status:
|
|
56
|
+
status: 409;
|
|
57
57
|
input: {
|
|
58
58
|
query: {
|
|
59
59
|
q?: string | undefined;
|
|
@@ -52,11 +52,15 @@ export declare function createRunnerInstallRoutes(options: {
|
|
|
52
52
|
"/runner-install/:runner": {
|
|
53
53
|
$post: {
|
|
54
54
|
output: {
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
supported: boolean;
|
|
56
|
+
installedVersion: string | null;
|
|
57
|
+
latestVersion: string | null;
|
|
58
|
+
updateAvailable: boolean;
|
|
59
|
+
phase: "activating" | "checking" | "downloading" | "extracting" | "failed" | "idle" | "removing" | "verifying";
|
|
60
|
+
error: string | null;
|
|
57
61
|
};
|
|
58
62
|
outputFormat: "json";
|
|
59
|
-
status:
|
|
63
|
+
status: 202;
|
|
60
64
|
input: {
|
|
61
65
|
param: {
|
|
62
66
|
runner: string;
|
|
@@ -68,15 +72,11 @@ export declare function createRunnerInstallRoutes(options: {
|
|
|
68
72
|
};
|
|
69
73
|
} | {
|
|
70
74
|
output: {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
latestVersion: string | null;
|
|
74
|
-
updateAvailable: boolean;
|
|
75
|
-
phase: "activating" | "checking" | "downloading" | "extracting" | "failed" | "idle" | "removing" | "verifying";
|
|
76
|
-
error: string | null;
|
|
75
|
+
error: string;
|
|
76
|
+
code?: "invalid_input" | undefined;
|
|
77
77
|
};
|
|
78
78
|
outputFormat: "json";
|
|
79
|
-
status:
|
|
79
|
+
status: 400;
|
|
80
80
|
input: {
|
|
81
81
|
param: {
|
|
82
82
|
runner: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hearsay-tools/squawk",
|
|
3
|
-
"version": "0.18.0-
|
|
3
|
+
"version": "0.18.0-pr4244.8211",
|
|
4
4
|
"description": "Local cockpit for running and tracking AI agent tasks in your repo. Uses your logged-in `claude` CLI and `gh` — zero config, zero database.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@babel/parser": "^8.0.8",
|
|
70
70
|
"@babel/types": "^8.0.8",
|
|
71
|
-
"@open-mercato/cezar-api-client": "0.18.0-
|
|
72
|
-
"@open-mercato/cezar-contract": "0.18.0-
|
|
71
|
+
"@open-mercato/cezar-api-client": "0.18.0-pr4244.8211",
|
|
72
|
+
"@open-mercato/cezar-contract": "0.18.0-pr4244.8211",
|
|
73
73
|
"@types/node": "^24.19.1",
|
|
74
74
|
"@types/ws": "^8.18.1",
|
|
75
75
|
"esbuild": "^0.28.1",
|
|
@@ -86,5 +86,5 @@
|
|
|
86
86
|
"publishConfig": {
|
|
87
87
|
"access": "public"
|
|
88
88
|
},
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "1ef8c4cc40cc94bfc8a335c53f930f481276ab97"
|
|
90
90
|
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The report of `profile-lint.ts --compare` (hearsay-tools/squawk#4238): pure functions over the
|
|
3
|
+
* rounds that the script measured, so a test can pin the format without running oxlint.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { isAbsolute, relative, sep } from 'node:path';
|
|
7
|
+
|
|
8
|
+
export interface CompareMeasure { user: number; sys: number }
|
|
9
|
+
|
|
10
|
+
/** One alternating round: base, then candidate, each with its user-CPU run and its `--debug timings` run. */
|
|
11
|
+
export interface CompareRound {
|
|
12
|
+
/** The 1-minute load before each user-CPU run of the round. */
|
|
13
|
+
loads: number[];
|
|
14
|
+
base: CompareMeasure;
|
|
15
|
+
candidate: CompareMeasure;
|
|
16
|
+
baseTimings: Record<string, number>;
|
|
17
|
+
candidateTimings: Record<string, number>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface CompareInput { base: string; command: string; rounds: CompareRound[]; cores: number }
|
|
21
|
+
|
|
22
|
+
export function median(values: readonly number[]): number {
|
|
23
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
24
|
+
const middle = Math.floor(sorted.length / 2);
|
|
25
|
+
const upper = sorted[middle] ?? Number.NaN;
|
|
26
|
+
return sorted.length % 2 === 1 ? upper : ((sorted[middle - 1] ?? Number.NaN) + upper) / 2;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The `cez/*` rows of oxlint's `--debug timings` table: rule name to JS milliseconds. */
|
|
30
|
+
export function ruleTimings(output: string): Record<string, number> {
|
|
31
|
+
const timings: Record<string, number> = {};
|
|
32
|
+
for (const line of output.split('\n')) {
|
|
33
|
+
const [name, ms] = line.trim().split(/\s+/);
|
|
34
|
+
if (name?.startsWith('cez/') && Number.isFinite(Number(ms))) timings[name] = Number(ms);
|
|
35
|
+
}
|
|
36
|
+
return timings;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The file count of oxlint's `Finished in … on N files` line, or undefined when the line is missing. */
|
|
40
|
+
export function lintedFiles(output: string): number | undefined {
|
|
41
|
+
const match = /^Finished in .* on (\d+) files?\b/m.exec(output);
|
|
42
|
+
return match ? Number(match[1]) : undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Lint paths relative to the repository root, so each side lints its own tree: an absolute path would
|
|
47
|
+
* make an extracted base tree lint the working tree's files. A path outside the root is refused.
|
|
48
|
+
*/
|
|
49
|
+
export function rootRelativePaths(paths: readonly string[], root: string): string[] {
|
|
50
|
+
return paths.map(path => {
|
|
51
|
+
if (!isAbsolute(path)) return path;
|
|
52
|
+
const inside = relative(root, path);
|
|
53
|
+
if (inside === '..' || inside.startsWith(`..${sep}`) || isAbsolute(inside)) throw new Error(`${path} is outside ${root}`);
|
|
54
|
+
return inside === '' ? '.' : inside;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const sum = (timings: Record<string, number>) => Object.values(timings).reduce((total, ms) => total + ms, 0);
|
|
59
|
+
const fixed = (value: number, digits = 2) => value.toFixed(digits);
|
|
60
|
+
const ratio = (candidate: number, base: number) => (base > 0 ? fixed(candidate / base) : 'n/a');
|
|
61
|
+
|
|
62
|
+
function sideRow(label: string, measures: CompareMeasure[], timings: Record<string, number>[]): { row: string; user: number; js: number } {
|
|
63
|
+
const users = measures.map(m => m.user);
|
|
64
|
+
const user = median(users);
|
|
65
|
+
const js = median(timings.map(sum));
|
|
66
|
+
const row = `| ${label} | ${fixed(user)} | ${fixed(Math.min(...users))}–${fixed(Math.max(...users))} | ${fixed(median(measures.map(m => m.sys)))} | ${fixed(js, 0)} |`;
|
|
67
|
+
return { row, user, js };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function ruleRows(rounds: readonly CompareRound[]): string[] {
|
|
71
|
+
const names = [...new Set(rounds.flatMap(r => [...Object.keys(r.baseTimings), ...Object.keys(r.candidateTimings)]))];
|
|
72
|
+
const rows = names.map(name => {
|
|
73
|
+
const base = median(rounds.map(r => r.baseTimings[name] ?? 0));
|
|
74
|
+
const candidate = median(rounds.map(r => r.candidateTimings[name] ?? 0));
|
|
75
|
+
return { name, base, candidate };
|
|
76
|
+
});
|
|
77
|
+
rows.sort((a, b) => b.candidate - a.candidate || a.name.localeCompare(b.name));
|
|
78
|
+
return rows.map(r => `| ${r.name} | ${fixed(r.base, 0)} | ${fixed(r.candidate, 0)} | ${r.candidate - r.base >= 0 ? '+' : ''}${fixed(r.candidate - r.base, 0)} |`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The Markdown report: per-side medians and ranges, the ratios, host load against the ceiling, and per-rule JS time. */
|
|
82
|
+
export function compareReport({ base, command, rounds, cores }: CompareInput): string {
|
|
83
|
+
const baseSide = sideRow('base', rounds.map(r => r.base), rounds.map(r => r.baseTimings));
|
|
84
|
+
const candidateSide = sideRow('candidate', rounds.map(r => r.candidate), rounds.map(r => r.candidateTimings));
|
|
85
|
+
const load = median(rounds.flatMap(r => r.loads));
|
|
86
|
+
const ceiling = cores / 2;
|
|
87
|
+
const lines = [
|
|
88
|
+
`Base: ${base}. Candidate: the working tree. Command: ${command}; ${rounds.length} alternating rounds; CPU in seconds, JS time in ms.`,
|
|
89
|
+
'',
|
|
90
|
+
'| Side | User median | User range | Sys median | `cez/*` JS ms median |',
|
|
91
|
+
'| --- | ---: | ---: | ---: | ---: |',
|
|
92
|
+
baseSide.row,
|
|
93
|
+
candidateSide.row,
|
|
94
|
+
'',
|
|
95
|
+
`Candidate/base: user CPU ${ratio(candidateSide.user, baseSide.user)}, \`cez/*\` JS time ${ratio(candidateSide.js, baseSide.js)}.`,
|
|
96
|
+
`Host: ${cores} cores; median 1-minute load ${fixed(load)}; user-CPU ceiling ${fixed(ceiling)} (half the cores).`,
|
|
97
|
+
];
|
|
98
|
+
if (load >= ceiling) lines.push('', '**Load above ceiling: user CPU is not evidence; report the `--debug timings` sums.**');
|
|
99
|
+
lines.push('', '| Rule | Base ms | Candidate ms | Delta |', '| --- | ---: | ---: | ---: |', ...ruleRows(rounds));
|
|
100
|
+
return lines.join('\n');
|
|
101
|
+
}
|
package/scripts/profile-lint.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { execFileSync, spawnSync } from 'node:child_process';
|
|
2
|
-
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { availableParallelism, loadavg as osLoadavg, tmpdir } from 'node:os';
|
|
4
4
|
import { join, resolve } from 'node:path';
|
|
5
5
|
import { performance } from 'node:perf_hooks';
|
|
6
6
|
import { oxlintBin } from '../src/lint/run.ts';
|
|
@@ -10,12 +10,15 @@ import { PROCESS_OWNER_RULES } from '../src/lint/owner-process-rules.ts';
|
|
|
10
10
|
import { STATE_OWNER_RULES } from '../src/lint/owner-state-rules.ts';
|
|
11
11
|
import { READER_OWNER_RULES } from '../src/lint/owner-reader-rules.ts';
|
|
12
12
|
import { activeRunWriteRules } from '../src/lint/active-run-write.ts';
|
|
13
|
+
import { gitEnv, gitSync } from '../src/git-command.ts';
|
|
14
|
+
import { type CompareRound, compareReport, lintedFiles, rootRelativePaths, ruleTimings } from './profile-lint-compare.ts';
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Measures what the `cez` oxlint plugin costs (hearsay-tools/squawk#3774). A developer tool, not a
|
|
16
18
|
* test: its numbers depend on the host and its load, so it prints `/proc/loadavg` beside each run.
|
|
17
19
|
*
|
|
18
20
|
* node packages/cezar/scripts/profile-lint.ts [--alone] [--families] [--runs N] [path...]
|
|
21
|
+
* node packages/cezar/scripts/profile-lint.ts --compare <ref|config> [--runs N] [path...]
|
|
19
22
|
*
|
|
20
23
|
* It runs `oxlint -c <config> <path...>` (default path `packages`) from the repository root with
|
|
21
24
|
* these configs, each written to a scratch directory:
|
|
@@ -28,32 +31,69 @@ import { activeRunWriteRules } from '../src/lint/active-run-write.ts';
|
|
|
28
31
|
* rule or family. Each run's user and system CPU come from the shell's `times` for its child.
|
|
29
32
|
* Last, it runs the full config once with `--debug timings` and lists oxlint's own JS time per rule
|
|
30
33
|
* (visitor and `create` time only; tree transfer, walking and garbage collection are not in it).
|
|
34
|
+
*
|
|
35
|
+
* `--compare` measures a base against the working tree in N alternating rounds (default 5); see
|
|
36
|
+
* `profile-lint-compare.ts` for the report. A base that names an existing file is an oxlint config,
|
|
37
|
+
* linted over the working tree. Any other base is a commit: its tree is extracted with `git archive`
|
|
38
|
+
* and linted with its own `.oxlintrc.json`, because the rules locate files relative to their own
|
|
39
|
+
* repository root. Both sides use the working tree's oxlint binary.
|
|
31
40
|
*/
|
|
32
41
|
|
|
33
42
|
interface Measure { label: string; user: number; sys: number; wall: number; load: string }
|
|
34
43
|
|
|
35
|
-
export interface ProfileOptions { paths: string[]; runs: number; alone: boolean; families: boolean }
|
|
44
|
+
export interface ProfileOptions { paths: string[]; runs: number; alone: boolean; families: boolean; compare?: string }
|
|
45
|
+
|
|
46
|
+
/** The value after `flag`, or undefined without the flag; a flag with no value throws. */
|
|
47
|
+
function flagValue(args: readonly string[], flag: string): string | undefined {
|
|
48
|
+
const index = args.indexOf(flag);
|
|
49
|
+
if (index < 0) return undefined;
|
|
50
|
+
const value = args[index + 1];
|
|
51
|
+
if (value === undefined || value.startsWith('--')) throw new Error(`${flag} needs a value`);
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** `--runs N`: a positive integer, or the statistics describe no run at all. */
|
|
56
|
+
function roundCount(value: string): number {
|
|
57
|
+
const count = Number(value);
|
|
58
|
+
if (!/^\d+$/.test(value) || count < 1) throw new Error(`--runs needs a positive integer, not ${value}`);
|
|
59
|
+
return count;
|
|
60
|
+
}
|
|
36
61
|
|
|
37
|
-
/** The command line: flags, `--runs N`, and the paths to lint (default `packages`). */
|
|
62
|
+
/** The command line: flags, `--runs N`, `--compare <ref|config>`, and the paths to lint (default `packages`). */
|
|
38
63
|
export function profileArgs(args: readonly string[]): ProfileOptions {
|
|
39
|
-
const
|
|
40
|
-
const
|
|
64
|
+
const runs = flagValue(args, '--runs');
|
|
65
|
+
const compare = flagValue(args, '--compare');
|
|
66
|
+
const values = new Set(['--runs', '--compare'].map(flag => args.indexOf(flag) + 1).filter(index => index > 0));
|
|
67
|
+
const paths = args.filter((arg, index) => !arg.startsWith('--') && !values.has(index));
|
|
41
68
|
return {
|
|
42
69
|
paths: paths.length > 0 ? paths : ['packages'],
|
|
43
|
-
runs:
|
|
70
|
+
runs: runs === undefined ? (compare === undefined ? 1 : 5) : roundCount(runs),
|
|
44
71
|
alone: args.includes('--alone'),
|
|
45
72
|
families: args.includes('--families'),
|
|
73
|
+
...(compare === undefined ? {} : { compare }),
|
|
46
74
|
};
|
|
47
75
|
}
|
|
48
76
|
|
|
49
|
-
|
|
77
|
+
// The test imports `profileArgs`; only a direct run reads the command line, inside its error handler.
|
|
78
|
+
let paths: string[] = [];
|
|
79
|
+
let runs = 1;
|
|
80
|
+
let alone = false;
|
|
81
|
+
let byFamily = false;
|
|
82
|
+
let compare: string | undefined;
|
|
83
|
+
|
|
84
|
+
function readCommandLine(): void {
|
|
85
|
+
const options = profileArgs(process.argv.slice(2));
|
|
86
|
+
paths = rootRelativePaths(options.paths, repoRoot);
|
|
87
|
+
({ runs, alone, families: byFamily, compare } = options);
|
|
88
|
+
}
|
|
50
89
|
|
|
51
90
|
const base = JSON.parse(readFileSync(join(repoRoot, '.oxlintrc.json'), 'utf8')) as { jsPlugins?: string[]; rules: Record<string, unknown> };
|
|
52
91
|
const pluginPath = resolve(repoRoot, base.jsPlugins?.[0] ?? 'packages/cezar/src/lint/plugin.ts');
|
|
53
92
|
const builtinRules = Object.fromEntries(Object.entries(base.rules).filter(([name]) => !name.startsWith('cez/')));
|
|
54
93
|
let scratch = '';
|
|
55
94
|
|
|
56
|
-
const loadavg = () => (
|
|
95
|
+
const loadavg = () => osLoadavg().map(value => value.toFixed(2)).join(' ');
|
|
96
|
+
const oneMinute = () => osLoadavg()[0] ?? Number.NaN;
|
|
57
97
|
const seconds = (text: string) => {
|
|
58
98
|
const match = /^(\d+)m([\d.]+)s$/.exec(text);
|
|
59
99
|
return match ? Number(match[1]) * 60 + Number(match[2]) : Number.NaN;
|
|
@@ -77,10 +117,10 @@ function noopPlugin(name: string, visitors: string[]): string {
|
|
|
77
117
|
}
|
|
78
118
|
|
|
79
119
|
/** One oxlint run; `times` in a POSIX shell reports the CPU its children used. */
|
|
80
|
-
function measure(label: string, config: string): Measure {
|
|
120
|
+
function measure(label: string, config: string, cwd = repoRoot): Measure {
|
|
81
121
|
const load = loadavg();
|
|
82
122
|
const started = performance.now();
|
|
83
|
-
const shell = spawnSync('/bin/sh', ['-c', '"$@" >/dev/null 2>&1; times', 'sh', process.execPath, oxlintBin(), '-c', config, ...paths], { cwd
|
|
123
|
+
const shell = spawnSync('/bin/sh', ['-c', '"$@" >/dev/null 2>&1; times', 'sh', process.execPath, oxlintBin(), '-c', config, ...paths], { cwd, encoding: 'utf8' });
|
|
84
124
|
const wall = (performance.now() - started) / 1000;
|
|
85
125
|
const [user = '', sys = ''] = (shell.stdout.trim().split('\n').at(-1) ?? '').split(/\s+/);
|
|
86
126
|
return { label, user: seconds(user), sys: seconds(sys), wall, load };
|
|
@@ -113,8 +153,7 @@ function main(): void {
|
|
|
113
153
|
console.log(`Command: oxlint -c <config> ${paths.join(' ')} (cwd ${repoRoot}); best of ${runs}; CPU in seconds.\n`);
|
|
114
154
|
console.log('| Config | User | Sys | Wall | Load (1/5/15 min) |\n| --- | ---: | ---: | ---: | --- |');
|
|
115
155
|
for (const m of results) console.log(row(m));
|
|
116
|
-
const
|
|
117
|
-
const lines = timings.split('\n').filter(line => line.startsWith('cez/'));
|
|
156
|
+
const lines = timingsOutput('.oxlintrc.json').split('\n').filter(line => line.startsWith('cez/'));
|
|
118
157
|
console.log(`\nOxlint's JS time per rule (\`--debug timings\`, load ${loadavg()}):\n\n| Rule | ms | Calls |\n| --- | ---: | ---: |`);
|
|
119
158
|
for (const line of lines) {
|
|
120
159
|
const [name, ms, , calls] = line.split(/\s+/);
|
|
@@ -122,10 +161,73 @@ function main(): void {
|
|
|
122
161
|
}
|
|
123
162
|
}
|
|
124
163
|
|
|
164
|
+
/** Oxlint's `--debug timings` output for one run; lint findings make it exit 1, which is not a failure here. */
|
|
165
|
+
function timingsOutput(config: string, cwd = repoRoot): string {
|
|
166
|
+
const run = spawnSync(process.execPath, [oxlintBin(), '-c', config, '-f', 'default', '--debug', 'timings', ...paths], { cwd, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
|
|
167
|
+
if (run.status !== 0 && run.status !== 1) throw new Error(`oxlint --debug timings exited ${run.status}: ${run.stderr}`);
|
|
168
|
+
return run.stdout;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
interface Side { config: string; cwd: string }
|
|
172
|
+
|
|
173
|
+
/** The base side: an existing file is a config over the working tree; anything else is a commit's own tree. */
|
|
174
|
+
function baseSide(arg: string): { side: Side; describe: string } {
|
|
175
|
+
const file = resolve(arg);
|
|
176
|
+
if (existsSync(file)) return { side: { config: file, cwd: repoRoot }, describe: `config ${arg}` };
|
|
177
|
+
// The git helpers drop inherited `GIT_DIR`-style variables (a hook, `rebase --exec`), so git acts on `cwd`.
|
|
178
|
+
let sha: string;
|
|
179
|
+
try {
|
|
180
|
+
sha = gitSync(['rev-parse', '--verify', '--quiet', `${arg}^{commit}`], { cwd: repoRoot, stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
|
181
|
+
} catch {
|
|
182
|
+
throw new Error(`--compare ${arg}: not a file and not a commit`);
|
|
183
|
+
}
|
|
184
|
+
const tree = join(scratch, 'base');
|
|
185
|
+
mkdirSync(tree);
|
|
186
|
+
execFileSync('/bin/sh', ['-c', 'git archive "$1" | tar -x -C "$2"', 'sh', sha, tree], { cwd: repoRoot, env: gitEnv() });
|
|
187
|
+
// Oxlint applies the `.gitignore` of an enclosing repository. A temp directory inside an ignored
|
|
188
|
+
// path (a task's TMPDIR) would hide every file, so the tree gets a repository boundary of its own.
|
|
189
|
+
gitSync(['init', '--quiet', tree]);
|
|
190
|
+
for (const dir of ['.', ...readdirSync(join(repoRoot, 'packages')).map(name => join('packages', name))]) {
|
|
191
|
+
const modules = join(repoRoot, dir, 'node_modules');
|
|
192
|
+
if (existsSync(modules) && existsSync(join(tree, dir)) && !existsSync(join(tree, dir, 'node_modules'))) symlinkSync(modules, join(tree, dir, 'node_modules'), 'dir');
|
|
193
|
+
}
|
|
194
|
+
return { side: { config: join(tree, '.oxlintrc.json'), cwd: tree }, describe: `commit ${arg} (${sha.slice(0, 9)})` };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** One side's per-rule JS time. A side that lints no files fails: a CPU time from that run measures nothing. */
|
|
198
|
+
function sideTimings(label: string, side: Side): Record<string, number> {
|
|
199
|
+
const output = timingsOutput(side.config, side.cwd);
|
|
200
|
+
if (!lintedFiles(output)) throw new Error(`${label}: oxlint linted no files for ${paths.join(' ')} in ${side.cwd}`);
|
|
201
|
+
return ruleTimings(output);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function compareMain(arg: string): void {
|
|
205
|
+
const { side: base, describe } = baseSide(arg);
|
|
206
|
+
const candidate: Side = { config: join(repoRoot, '.oxlintrc.json'), cwd: repoRoot };
|
|
207
|
+
const rounds: CompareRound[] = [];
|
|
208
|
+
for (let round = 1; round <= runs; round++) {
|
|
209
|
+
const loads = [oneMinute()];
|
|
210
|
+
const baseRun = measure('base', base.config, base.cwd);
|
|
211
|
+
loads.push(oneMinute());
|
|
212
|
+
const candidateRun = measure('candidate', candidate.config, candidate.cwd);
|
|
213
|
+
const baseTimings = sideTimings('base', base);
|
|
214
|
+
const candidateTimings = sideTimings('candidate', candidate);
|
|
215
|
+
rounds.push({ loads, base: baseRun, candidate: candidateRun, baseTimings, candidateTimings });
|
|
216
|
+
const [baseLoad = Number.NaN, candidateLoad = Number.NaN] = loads;
|
|
217
|
+
console.error(`round ${round}/${runs}: base ${baseRun.user.toFixed(2)} s user at load ${baseLoad.toFixed(2)}, candidate ${candidateRun.user.toFixed(2)} s user at load ${candidateLoad.toFixed(2)}`);
|
|
218
|
+
}
|
|
219
|
+
console.log(compareReport({ base: describe, command: `oxlint -c <config> ${paths.join(' ')}`, rounds, cores: availableParallelism() }));
|
|
220
|
+
}
|
|
221
|
+
|
|
125
222
|
if (import.meta.main) {
|
|
126
223
|
scratch = mkdtempSync(join(tmpdir(), 'cez-profile-lint-'));
|
|
127
224
|
try {
|
|
128
|
-
|
|
225
|
+
readCommandLine();
|
|
226
|
+
if (compare === undefined) main();
|
|
227
|
+
else compareMain(compare);
|
|
228
|
+
} catch (error) {
|
|
229
|
+
console.error(`profile-lint: ${error instanceof Error ? error.message : String(error)}`);
|
|
230
|
+
process.exitCode = 2;
|
|
129
231
|
} finally {
|
|
130
232
|
rmSync(scratch, { recursive: true, force: true });
|
|
131
233
|
}
|