@hearsay-tools/squawk 0.18.0-pr3793.7075 → 0.18.0-pr3796.7089

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hearsay-tools/squawk",
3
- "version": "0.18.0-pr3793.7075",
3
+ "version": "0.18.0-pr3796.7089",
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",
@@ -63,8 +63,8 @@
63
63
  "devDependencies": {
64
64
  "@babel/parser": "^8.0.8",
65
65
  "@babel/types": "^8.0.8",
66
- "@open-mercato/cezar-api-client": "0.18.0-pr3793.7075",
67
- "@open-mercato/cezar-contract": "0.18.0-pr3793.7075",
66
+ "@open-mercato/cezar-api-client": "0.18.0-pr3796.7089",
67
+ "@open-mercato/cezar-contract": "0.18.0-pr3796.7089",
68
68
  "@types/node": "^24.19.1",
69
69
  "@types/ws": "^8.18.1",
70
70
  "esbuild": "^0.28.1",
@@ -81,5 +81,5 @@
81
81
  "publishConfig": {
82
82
  "access": "public"
83
83
  },
84
- "gitHead": "2a7e32829f397160ee43e8580d8dfe10b59b766d"
84
+ "gitHead": "b54f8a140bc23df397059f08efa0537bac9e09cf"
85
85
  }
@@ -0,0 +1,120 @@
1
+ import { execFileSync, spawnSync } from 'node:child_process';
2
+ import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { tmpdir } from 'node:os';
4
+ import { join, resolve } from 'node:path';
5
+ import { performance } from 'node:perf_hooks';
6
+ import { oxlintBin } from '../src/lint/run.ts';
7
+ import { RULES } from '../src/lint/plugin.ts';
8
+ import { repoRoot } from '../src/lint/source-rule.ts';
9
+ import { PROCESS_OWNER_RULES } from '../src/lint/owner-process-rules.ts';
10
+ import { STATE_OWNER_RULES } from '../src/lint/owner-state-rules.ts';
11
+ import { READER_OWNER_RULES } from '../src/lint/owner-reader-rules.ts';
12
+ import { activeRunWriteRules } from '../src/lint/active-run-write.ts';
13
+
14
+ /**
15
+ * Measures what the `cez` oxlint plugin costs (hearsay-tools/squawk#3774). A developer tool, not a
16
+ * test: its numbers depend on the host and its load, so it prints `/proc/loadavg` beside each run.
17
+ *
18
+ * node packages/cezar/scripts/profile-lint.ts [--alone] [--families] [--runs N] [path...]
19
+ *
20
+ * It runs `oxlint -c <config> <path...>` (default path `packages`) from the repository root with
21
+ * these configs, each written to a scratch directory:
22
+ * builtins `.oxlintrc.json` without `jsPlugins` and without any `cez/*` rule;
23
+ * load built-ins plus a plugin that imports the `cez` plugin and runs one rule with no visitor;
24
+ * transport the same rule visiting `Program` and `CallExpression` with no-op functions, so oxlint
25
+ * sends every file's tree to JS and walks it;
26
+ * full `.oxlintrc.json` as it is.
27
+ * `--families` adds one run per rule family and `--alone` one run per rule: built-ins plus that
28
+ * rule or family. Each run's user and system CPU come from the shell's `times` for its child.
29
+ * Last, it runs the full config once with `--debug timings` and lists oxlint's own JS time per rule
30
+ * (visitor and `create` time only; tree transfer, walking and garbage collection are not in it).
31
+ */
32
+
33
+ interface Measure { label: string; user: number; sys: number; wall: number; load: string }
34
+
35
+ const args = process.argv.slice(2);
36
+ const flag = (name: string) => args.includes(name);
37
+ const runsIndex = args.indexOf('--runs');
38
+ const runs = runsIndex >= 0 ? Number(args[runsIndex + 1]) : 1;
39
+ const paths = args.filter((arg, index) => !arg.startsWith('--') && index !== runsIndex + 1);
40
+ if (paths.length === 0) paths.push('packages');
41
+
42
+ const base = JSON.parse(readFileSync(join(repoRoot, '.oxlintrc.json'), 'utf8')) as { jsPlugins?: string[]; rules: Record<string, unknown> };
43
+ const pluginPath = resolve(repoRoot, base.jsPlugins?.[0] ?? 'packages/cezar/src/lint/plugin.ts');
44
+ const builtinRules = Object.fromEntries(Object.entries(base.rules).filter(([name]) => !name.startsWith('cez/')));
45
+ const scratch = mkdtempSync(join(tmpdir(), 'cez-profile-lint-'));
46
+
47
+ const loadavg = () => (existsSync('/proc/loadavg') ? readFileSync('/proc/loadavg', 'utf8').split(' ').slice(0, 3).join(' ') : 'n/a');
48
+ const seconds = (text: string) => {
49
+ const match = /^(\d+)m([\d.]+)s$/.exec(text);
50
+ return match ? Number(match[1]) * 60 + Number(match[2]) : Number.NaN;
51
+ };
52
+
53
+ function writeConfig(name: string, plugins: string[], rules: Record<string, unknown>): string {
54
+ const file = join(scratch, `${name}.json`);
55
+ const { $schema: _schema, ...rest } = base as Record<string, unknown>;
56
+ writeFileSync(file, JSON.stringify({ ...rest, jsPlugins: plugins, rules: { ...builtinRules, ...rules } }));
57
+ return file;
58
+ }
59
+
60
+ function noopPlugin(name: string, visitors: string[]): string {
61
+ const file = join(scratch, `${name}.mjs`);
62
+ const body = visitors.map(type => `${type}() {}`).join(', ');
63
+ writeFileSync(file, [
64
+ `import ${JSON.stringify(pluginPath)};`,
65
+ `export default { meta: { name: 'noop' }, rules: { noop: { create() { return { ${body} }; } } } };`,
66
+ ].join('\n'));
67
+ return file;
68
+ }
69
+
70
+ /** One oxlint run; `times` in a POSIX shell reports the CPU its children used. */
71
+ function measure(label: string, config: string): Measure {
72
+ const load = loadavg();
73
+ const started = performance.now();
74
+ const shell = spawnSync('/bin/sh', ['-c', '"$@" >/dev/null 2>&1; times', 'sh', process.execPath, oxlintBin(), '-c', config, ...paths], { cwd: repoRoot, encoding: 'utf8' });
75
+ const wall = (performance.now() - started) / 1000;
76
+ const [user = '', sys = ''] = (shell.stdout.trim().split('\n').at(-1) ?? '').split(/\s+/);
77
+ return { label, user: seconds(user), sys: seconds(sys), wall, load };
78
+ }
79
+
80
+ function best(label: string, config: string): Measure {
81
+ const all = Array.from({ length: runs }, () => measure(label, config));
82
+ return all.reduce((low, next) => (next.user < low.user ? next : low));
83
+ }
84
+
85
+ const enabled = (names: string[]) => Object.fromEntries(names.map(name => [`cez/${name}`, 'error']));
86
+ const families: Record<string, string[]> = {
87
+ 'owner-process': PROCESS_OWNER_RULES.map(rule => rule.name),
88
+ 'owner-state': STATE_OWNER_RULES.map(rule => rule.name),
89
+ 'owner-reader': READER_OWNER_RULES.map(rule => rule.name),
90
+ 'active-run-write': activeRunWriteRules.map(rule => rule.name),
91
+ };
92
+
93
+ function main(): void {
94
+ const results: Measure[] = [];
95
+ const row = (m: Measure) => `| ${m.label} | ${m.user.toFixed(2)} | ${m.sys.toFixed(2)} | ${m.wall.toFixed(2)} | ${m.load} |`;
96
+ const add = (m: Measure) => { results.push(m); console.error(row(m)); };
97
+ const plugin = (name: string) => [noopPlugin(name, name === 'load' ? [] : ['Program', 'CallExpression'])];
98
+ add(best('builtins', writeConfig('builtins', [], {})));
99
+ add(best('load', writeConfig('load', plugin('load'), { 'noop/noop': 'error' })));
100
+ add(best('transport', writeConfig('transport', plugin('transport'), { 'noop/noop': 'error' })));
101
+ add(best('full', join(repoRoot, '.oxlintrc.json')));
102
+ if (flag('--families')) for (const [name, rules] of Object.entries(families)) add(best(`family ${name}`, writeConfig(`family-${name}`, [pluginPath], enabled(rules))));
103
+ if (flag('--alone')) for (const rule of RULES) add(best(`cez/${rule.name}`, writeConfig(`rule-${rule.name}`, [pluginPath], enabled([rule.name]))));
104
+ console.log(`Command: oxlint -c <config> ${paths.join(' ')} (cwd ${repoRoot}); best of ${runs}; CPU in seconds.\n`);
105
+ console.log('| Config | User | Sys | Wall | Load (1/5/15 min) |\n| --- | ---: | ---: | ---: | --- |');
106
+ for (const m of results) console.log(row(m));
107
+ const timings = execFileSync(process.execPath, [oxlintBin(), '-c', '.oxlintrc.json', '-f', 'default', '--debug', 'timings', ...paths], { cwd: repoRoot, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
108
+ const lines = timings.split('\n').filter(line => line.startsWith('cez/'));
109
+ console.log(`\nOxlint's JS time per rule (\`--debug timings\`, load ${loadavg()}):\n\n| Rule | ms | Calls |\n| --- | ---: | ---: |`);
110
+ for (const line of lines) {
111
+ const [name, ms, , calls] = line.split(/\s+/);
112
+ console.log(`| ${name} | ${Number(ms).toFixed(0)} | ${calls} |`);
113
+ }
114
+ }
115
+
116
+ try {
117
+ main();
118
+ } finally {
119
+ rmSync(scratch, { recursive: true, force: true });
120
+ }