@hearsay-tools/squawk 0.18.0-dev.8217 → 0.18.0-dev.8221
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.
|
@@ -119,9 +119,12 @@ export declare function ciToolRoutes(capabilities: Map<string, Capability>): imp
|
|
|
119
119
|
} & {
|
|
120
120
|
"/api/v1/tools/:name": {
|
|
121
121
|
$post: {
|
|
122
|
-
output:
|
|
122
|
+
output: {
|
|
123
|
+
code: string;
|
|
124
|
+
message: string;
|
|
125
|
+
};
|
|
123
126
|
outputFormat: "json";
|
|
124
|
-
status:
|
|
127
|
+
status: 401;
|
|
125
128
|
input: {
|
|
126
129
|
json: unknown;
|
|
127
130
|
} & {
|
|
@@ -144,12 +147,9 @@ export declare function ciToolRoutes(capabilities: Map<string, Capability>): imp
|
|
|
144
147
|
};
|
|
145
148
|
};
|
|
146
149
|
} | {
|
|
147
|
-
output:
|
|
148
|
-
code: string;
|
|
149
|
-
message: string;
|
|
150
|
-
};
|
|
150
|
+
output: never;
|
|
151
151
|
outputFormat: "json";
|
|
152
|
-
status:
|
|
152
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
153
153
|
input: {
|
|
154
154
|
json: unknown;
|
|
155
155
|
} & {
|
|
@@ -27,18 +27,6 @@ export declare function delegationFailure(error: unknown): {
|
|
|
27
27
|
export declare function createDelegationRoutes(service: DelegationService, credentials: CredentialRegistry): import("hono/hono-base").HonoBase<Env, {
|
|
28
28
|
"/list": {
|
|
29
29
|
$get: {
|
|
30
|
-
output: {
|
|
31
|
-
error: string;
|
|
32
|
-
code?: "invalid_input" | undefined;
|
|
33
|
-
};
|
|
34
|
-
outputFormat: "json";
|
|
35
|
-
status: 400;
|
|
36
|
-
input: {
|
|
37
|
-
query: {
|
|
38
|
-
offset?: string | undefined;
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
} | {
|
|
42
30
|
output: {
|
|
43
31
|
workers: {
|
|
44
32
|
workerId: string;
|
|
@@ -91,6 +79,18 @@ export declare function createDelegationRoutes(service: DelegationService, crede
|
|
|
91
79
|
offset?: string | undefined;
|
|
92
80
|
};
|
|
93
81
|
};
|
|
82
|
+
} | {
|
|
83
|
+
output: {
|
|
84
|
+
error: string;
|
|
85
|
+
code?: "invalid_input" | undefined;
|
|
86
|
+
};
|
|
87
|
+
outputFormat: "json";
|
|
88
|
+
status: 400;
|
|
89
|
+
input: {
|
|
90
|
+
query: {
|
|
91
|
+
offset?: string | undefined;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
94
|
};
|
|
95
95
|
};
|
|
96
96
|
} & {
|
|
@@ -677,18 +677,6 @@ export declare function createDelegationRoutes(service: DelegationService, crede
|
|
|
677
677
|
} & {
|
|
678
678
|
"/:workerId": {
|
|
679
679
|
$get: {
|
|
680
|
-
output: {
|
|
681
|
-
error: string;
|
|
682
|
-
code?: "invalid_input" | undefined;
|
|
683
|
-
};
|
|
684
|
-
outputFormat: "json";
|
|
685
|
-
status: 400;
|
|
686
|
-
input: {
|
|
687
|
-
param: {
|
|
688
|
-
workerId: string;
|
|
689
|
-
};
|
|
690
|
-
};
|
|
691
|
-
} | {
|
|
692
680
|
output: {
|
|
693
681
|
workerId: string;
|
|
694
682
|
settled: boolean;
|
|
@@ -813,11 +801,7 @@ export declare function createDelegationRoutes(service: DelegationService, crede
|
|
|
813
801
|
workerId: string;
|
|
814
802
|
};
|
|
815
803
|
};
|
|
816
|
-
}
|
|
817
|
-
};
|
|
818
|
-
} & {
|
|
819
|
-
"/:workerId/collect": {
|
|
820
|
-
$post: {
|
|
804
|
+
} | {
|
|
821
805
|
output: {
|
|
822
806
|
error: string;
|
|
823
807
|
code?: "invalid_input" | undefined;
|
|
@@ -828,10 +812,12 @@ export declare function createDelegationRoutes(service: DelegationService, crede
|
|
|
828
812
|
param: {
|
|
829
813
|
workerId: string;
|
|
830
814
|
};
|
|
831
|
-
} & {
|
|
832
|
-
json: Record<string, never>;
|
|
833
815
|
};
|
|
834
|
-
}
|
|
816
|
+
};
|
|
817
|
+
};
|
|
818
|
+
} & {
|
|
819
|
+
"/:workerId/collect": {
|
|
820
|
+
$post: {
|
|
835
821
|
output: {
|
|
836
822
|
workerId: string;
|
|
837
823
|
parentRunId: string;
|
|
@@ -954,11 +940,7 @@ export declare function createDelegationRoutes(service: DelegationService, crede
|
|
|
954
940
|
} & {
|
|
955
941
|
json: Record<string, never>;
|
|
956
942
|
};
|
|
957
|
-
}
|
|
958
|
-
};
|
|
959
|
-
} & {
|
|
960
|
-
"/:workerId/steer": {
|
|
961
|
-
$post: {
|
|
943
|
+
} | {
|
|
962
944
|
output: {
|
|
963
945
|
error: string;
|
|
964
946
|
code?: "invalid_input" | undefined;
|
|
@@ -970,11 +952,13 @@ export declare function createDelegationRoutes(service: DelegationService, crede
|
|
|
970
952
|
workerId: string;
|
|
971
953
|
};
|
|
972
954
|
} & {
|
|
973
|
-
json:
|
|
974
|
-
text: string;
|
|
975
|
-
};
|
|
955
|
+
json: Record<string, never>;
|
|
976
956
|
};
|
|
977
|
-
}
|
|
957
|
+
};
|
|
958
|
+
};
|
|
959
|
+
} & {
|
|
960
|
+
"/:workerId/steer": {
|
|
961
|
+
$post: {
|
|
978
962
|
output: {
|
|
979
963
|
workerId: string;
|
|
980
964
|
state: "delivered" | "queued";
|
|
@@ -990,11 +974,7 @@ export declare function createDelegationRoutes(service: DelegationService, crede
|
|
|
990
974
|
text: string;
|
|
991
975
|
};
|
|
992
976
|
};
|
|
993
|
-
}
|
|
994
|
-
};
|
|
995
|
-
} & {
|
|
996
|
-
"/:workerId/stop": {
|
|
997
|
-
$post: {
|
|
977
|
+
} | {
|
|
998
978
|
output: {
|
|
999
979
|
error: string;
|
|
1000
980
|
code?: "invalid_input" | undefined;
|
|
@@ -1006,9 +986,15 @@ export declare function createDelegationRoutes(service: DelegationService, crede
|
|
|
1006
986
|
workerId: string;
|
|
1007
987
|
};
|
|
1008
988
|
} & {
|
|
1009
|
-
json:
|
|
989
|
+
json: {
|
|
990
|
+
text: string;
|
|
991
|
+
};
|
|
1010
992
|
};
|
|
1011
|
-
}
|
|
993
|
+
};
|
|
994
|
+
};
|
|
995
|
+
} & {
|
|
996
|
+
"/:workerId/stop": {
|
|
997
|
+
$post: {
|
|
1012
998
|
output: {
|
|
1013
999
|
workerId: string;
|
|
1014
1000
|
state: "stopping" | "terminated";
|
|
@@ -1022,11 +1008,7 @@ export declare function createDelegationRoutes(service: DelegationService, crede
|
|
|
1022
1008
|
} & {
|
|
1023
1009
|
json: Record<string, never>;
|
|
1024
1010
|
};
|
|
1025
|
-
}
|
|
1026
|
-
};
|
|
1027
|
-
} & {
|
|
1028
|
-
"/:workerId/destroy": {
|
|
1029
|
-
$post: {
|
|
1011
|
+
} | {
|
|
1030
1012
|
output: {
|
|
1031
1013
|
error: string;
|
|
1032
1014
|
code?: "invalid_input" | undefined;
|
|
@@ -1038,11 +1020,13 @@ export declare function createDelegationRoutes(service: DelegationService, crede
|
|
|
1038
1020
|
workerId: string;
|
|
1039
1021
|
};
|
|
1040
1022
|
} & {
|
|
1041
|
-
json:
|
|
1042
|
-
discardWork?: true | undefined;
|
|
1043
|
-
};
|
|
1023
|
+
json: Record<string, never>;
|
|
1044
1024
|
};
|
|
1045
|
-
}
|
|
1025
|
+
};
|
|
1026
|
+
};
|
|
1027
|
+
} & {
|
|
1028
|
+
"/:workerId/destroy": {
|
|
1029
|
+
$post: {
|
|
1046
1030
|
output: {
|
|
1047
1031
|
workerId: string;
|
|
1048
1032
|
state: "complete" | "incomplete";
|
|
@@ -1071,6 +1055,22 @@ export declare function createDelegationRoutes(service: DelegationService, crede
|
|
|
1071
1055
|
discardWork?: true | undefined;
|
|
1072
1056
|
};
|
|
1073
1057
|
};
|
|
1058
|
+
} | {
|
|
1059
|
+
output: {
|
|
1060
|
+
error: string;
|
|
1061
|
+
code?: "invalid_input" | undefined;
|
|
1062
|
+
};
|
|
1063
|
+
outputFormat: "json";
|
|
1064
|
+
status: 400;
|
|
1065
|
+
input: {
|
|
1066
|
+
param: {
|
|
1067
|
+
workerId: string;
|
|
1068
|
+
};
|
|
1069
|
+
} & {
|
|
1070
|
+
json: {
|
|
1071
|
+
discardWork?: true | undefined;
|
|
1072
|
+
};
|
|
1073
|
+
};
|
|
1074
1074
|
} | {
|
|
1075
1075
|
output: {
|
|
1076
1076
|
workerId: string;
|
|
@@ -1106,11 +1106,13 @@ export declare function createDelegationRoutes(service: DelegationService, crede
|
|
|
1106
1106
|
"/:workerId/diff": {
|
|
1107
1107
|
$get: {
|
|
1108
1108
|
output: {
|
|
1109
|
-
|
|
1110
|
-
|
|
1109
|
+
workerId: string;
|
|
1110
|
+
baselineSha: string;
|
|
1111
|
+
diff: string;
|
|
1112
|
+
truncated: boolean;
|
|
1111
1113
|
};
|
|
1112
1114
|
outputFormat: "json";
|
|
1113
|
-
status:
|
|
1115
|
+
status: 200;
|
|
1114
1116
|
input: {
|
|
1115
1117
|
param: {
|
|
1116
1118
|
workerId: string;
|
|
@@ -1118,13 +1120,11 @@ export declare function createDelegationRoutes(service: DelegationService, crede
|
|
|
1118
1120
|
};
|
|
1119
1121
|
} | {
|
|
1120
1122
|
output: {
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
diff: string;
|
|
1124
|
-
truncated: boolean;
|
|
1123
|
+
error: string;
|
|
1124
|
+
code?: "invalid_input" | undefined;
|
|
1125
1125
|
};
|
|
1126
1126
|
outputFormat: "json";
|
|
1127
|
-
status:
|
|
1127
|
+
status: 400;
|
|
1128
1128
|
input: {
|
|
1129
1129
|
param: {
|
|
1130
1130
|
workerId: string;
|
|
@@ -58,29 +58,6 @@ export declare function ciProgressPlugs(): {
|
|
|
58
58
|
export declare function createActivityRoutes(routeDeps: ActivityRouteDeps): import("hono/hono-base").HonoBase<import("hono/types").BlankEnv, {
|
|
59
59
|
"/workspace/activity": {
|
|
60
60
|
$get: {
|
|
61
|
-
output: {
|
|
62
|
-
error: string;
|
|
63
|
-
code?: "invalid_input" | undefined;
|
|
64
|
-
};
|
|
65
|
-
outputFormat: "json";
|
|
66
|
-
status: 400;
|
|
67
|
-
input: {
|
|
68
|
-
query: {
|
|
69
|
-
project?: string | undefined;
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
} | {
|
|
73
|
-
output: {
|
|
74
|
-
error: string;
|
|
75
|
-
};
|
|
76
|
-
outputFormat: "json";
|
|
77
|
-
status: 404 | 409 | 503;
|
|
78
|
-
input: {
|
|
79
|
-
query: {
|
|
80
|
-
project?: string | undefined;
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
} | {
|
|
84
61
|
output: {
|
|
85
62
|
generatedAt: string;
|
|
86
63
|
projects: {
|
|
@@ -327,6 +304,29 @@ export declare function createActivityRoutes(routeDeps: ActivityRouteDeps): impo
|
|
|
327
304
|
project?: string | undefined;
|
|
328
305
|
};
|
|
329
306
|
};
|
|
307
|
+
} | {
|
|
308
|
+
output: {
|
|
309
|
+
error: string;
|
|
310
|
+
code?: "invalid_input" | undefined;
|
|
311
|
+
};
|
|
312
|
+
outputFormat: "json";
|
|
313
|
+
status: 400;
|
|
314
|
+
input: {
|
|
315
|
+
query: {
|
|
316
|
+
project?: string | undefined;
|
|
317
|
+
};
|
|
318
|
+
};
|
|
319
|
+
} | {
|
|
320
|
+
output: {
|
|
321
|
+
error: string;
|
|
322
|
+
};
|
|
323
|
+
outputFormat: "json";
|
|
324
|
+
status: 404 | 409 | 503;
|
|
325
|
+
input: {
|
|
326
|
+
query: {
|
|
327
|
+
project?: string | undefined;
|
|
328
|
+
};
|
|
329
|
+
};
|
|
330
330
|
};
|
|
331
331
|
};
|
|
332
332
|
}, "/", "/workspace/activity">;
|
|
@@ -30,19 +30,10 @@ export declare function createModelsRoutes(options: {
|
|
|
30
30
|
};
|
|
31
31
|
} | {
|
|
32
32
|
output: {
|
|
33
|
-
|
|
34
|
-
models: {
|
|
35
|
-
id: string;
|
|
36
|
-
label: string;
|
|
37
|
-
description: string;
|
|
38
|
-
effortLevels?: import('../contract/index.js').EffortLevel[];
|
|
39
|
-
}[];
|
|
40
|
-
source: import("../core/runner-model-catalog.ts").ModelCatalogSource;
|
|
41
|
-
stale: boolean;
|
|
42
|
-
reason?: string;
|
|
33
|
+
error: string;
|
|
43
34
|
};
|
|
44
35
|
outputFormat: "json";
|
|
45
|
-
status:
|
|
36
|
+
status: 400;
|
|
46
37
|
input: {
|
|
47
38
|
query: {
|
|
48
39
|
runner: string | string[];
|
|
@@ -63,10 +54,19 @@ export declare function createModelsRoutes(options: {
|
|
|
63
54
|
};
|
|
64
55
|
} | {
|
|
65
56
|
output: {
|
|
66
|
-
|
|
57
|
+
runner: string;
|
|
58
|
+
models: {
|
|
59
|
+
id: string;
|
|
60
|
+
label: string;
|
|
61
|
+
description: string;
|
|
62
|
+
effortLevels?: import('../contract/index.js').EffortLevel[];
|
|
63
|
+
}[];
|
|
64
|
+
source: import("../core/runner-model-catalog.ts").ModelCatalogSource;
|
|
65
|
+
stale: boolean;
|
|
66
|
+
reason?: string;
|
|
67
67
|
};
|
|
68
68
|
outputFormat: "json";
|
|
69
|
-
status:
|
|
69
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
70
70
|
input: {
|
|
71
71
|
query: {
|
|
72
72
|
runner: string | string[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hearsay-tools/squawk",
|
|
3
|
-
"version": "0.18.0-dev.
|
|
3
|
+
"version": "0.18.0-dev.8221",
|
|
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-dev.
|
|
72
|
-
"@open-mercato/cezar-contract": "0.18.0-dev.
|
|
71
|
+
"@open-mercato/cezar-api-client": "0.18.0-dev.8221",
|
|
72
|
+
"@open-mercato/cezar-contract": "0.18.0-dev.8221",
|
|
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": "56e5a09205b3f922f7ef37ea62dd28ff1f91c616"
|
|
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
|
}
|