-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheslint.config.ts
More file actions
990 lines (929 loc) Β· 43.9 KB
/
Copy patheslint.config.ts
File metadata and controls
990 lines (929 loc) Β· 43.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import globals from 'globals';
import reactHooks from 'eslint-plugin-react-hooks';
import sonarjs from 'eslint-plugin-sonarjs';
import type { ESLint, Linter } from 'eslint';
/**
* Layer rules.
*
* domain β nothing (entities + repositories + value objects + validation;
* no third-party libs except typescript-result via
* the single re-export point and zod for parsers)
* business β domain (use cases as `(props) => Promise<Output>` with named
* Props interfaces; no I/O-bearing node modules, no
* chain-framework imports, no AI imports β deps are
* inline function shapes that integration supplies)
* integration β domain, business (concrete impls β persistence, scm, ai (providers,
* prompts, signals, skills, readiness probes), I/O +
* shell wrappers, observability sinks)
* application β everything (chain framework + flow compositions + composition
* root + UI runtime; wires business use cases via
* chain leaves that adapt to integration impls)
*
* Sub-layer rules inside application:
*
* application/flows/** may not import concrete provider/probe/skill/agent impls under
* integration/ai/ β chain compositions speak port-level vocabulary only; the composition root
* and the UI launch path select the concrete impls.
* application/chain/** is the generic kernel flows compose over β it may not import business,
* integration, or the outer application surfaces (ui, bootstrap, flows).
*
* Sibling rules (enforced via per-folder overrides at the bottom):
*
* integration/ai/prompts/<x> may not import from integration/ai/prompts/<y>
* integration/ai/providers/<x> may not import from integration/ai/providers/<y>
* integration/ai/readiness/<x> may not import from integration/ai/readiness/<y>
* integration/ai/skills/<x> may not import from integration/ai/skills/<y>
* (skills siblings cover both per-tool adapter
* implementations and Skill source providers β the
* one switch over them is `skills/adapter-factory.ts`,
* which sits directly under skills/ and is not a sibling)
* integration/ai/agents/<x> may not import from integration/ai/agents/<y>
* application/flows/<x> may not import from application/flows/<y>
*
* In each AI concept, the `_engine/` sub-namespace is the shared abstraction layer β every concrete
* sibling may import freely from its own `_engine/`. Cross-concept access goes through the other
* concept's `_engine/` too, and never into its concrete siblings (e.g. integration/ai/prompts/evaluate
* may import integration/ai/evaluation/_engine/ to declare the dimensions it renders).
*
* Module-level rules:
*
* No barrel exports (export * from ...) anywhere β every import names what it pulls in.
* Domain + business may not import I/O-bearing node:* modules (fs, child_process, http, ...).
* Pure node:* modules (node:path, node:url, node:util, node:assert, node:crypto) are fine.
* AI may use I/O-bearing node:* modules β it owns the provider/template/skill I/O.
*/
const restrictImports = (
forbidden: readonly string[],
extraPaths: readonly {
readonly name: string;
readonly importNames?: readonly string[];
readonly message: string;
}[] = []
): Linter.RuleEntry => [
'error',
{
paths: extraPaths,
patterns: forbidden.map((layer) => ({
group: [`**/${layer}/**`],
message: `Layer dependency violation: cannot import from '${layer}'.`,
})),
},
];
/**
* The Result re-export point is the only file allowed to import `typescript-result` directly.
* Everything else imports from `@src/domain/result.ts` so the underlying library can be swapped
* without churning every file.
*/
const resultLibBan = {
name: 'typescript-result',
message:
"Import `Result` from '@src/domain/result.ts' (the single re-export point) instead. The underlying `typescript-result` library may only be imported by that one file so the implementation can be swapped without churning callers.",
} as const;
/**
* `node:child_process`'s spawn-family functions are fenced to the sanctioned wrappers everywhere
* outside domain/business (which ban the whole module via `nodeIoBans` already). Every
* external-binary spawn routes through `integration/io/cross-platform-spawn.ts`
* (`crossPlatformSpawn`) β see SECURITY.md. Two named exceptions carry their own justification and
* are excluded from this rule instead of routed through the wrapper:
* - `shell-script-runner.ts` β runs a user-authored shell command *string* and needs `shell: true`,
* which `crossPlatformSpawn` intentionally does not support.
* - `os-notification-dispatcher.ts` β needs the *promisified* `execFile` API: a single awaited
* call that buffers stdout/stderr and rejects on a non-zero exit (used both to run
* `osascript` / `notify-send` and to probe `which notify-send`), a shape `crossPlatformSpawn`'s
* event-based `spawn` wrapper doesn't provide. (`spawn` does accept a `timeout` option, so a
* wall-clock cap alone would not justify the exception β it's specifically the buffered,
* promise-shaped result that's missing.)
*
* Scoped by `importNames` (not the whole module) so type-only imports (`ChildProcess`,
* `ChildProcessWithoutNullStreams`, `SpawnOptions`, β¦) β used all over the AI provider adapters for
* test-seam typing β stay unaffected.
*/
const childProcessSpawnBan = {
name: 'node:child_process',
importNames: ['spawn', 'execFile', 'exec', 'fork', 'execSync', 'spawnSync', 'execFileSync'],
message:
'Direct node:child_process spawn/exec imports are fenced outside the sanctioned wrappers β route external-binary spawns through integration/io/cross-platform-spawn.ts (crossPlatformSpawn). shell-script-runner.ts and os-notification-dispatcher.ts are the two named exceptions β see the rationale above this rule (childProcessSpawnBan in eslint.config.ts) and the header comment in each file.',
} as const;
/** Base layer rule for src/integration/** β no imports from application. */
const integrationLayerRule = restrictImports(['application']);
/**
* The integration rule most files get: layer direction + the spawn/exec fence. Also the base
* the integration/ai sibling-isolation blocks compose over (see `mergeRestrictedImports`).
*/
const integrationSpawnFencedRule = restrictImports(['application'], [childProcessSpawnBan]);
/**
* Node modules that perform I/O or expose host-environment state. Banned in domain + business so
* the product model stays portable + testable without a node runtime. Integration / ai may
* import these freely (they own the impure side).
*
* Allowed in domain + business (pure modules): node:path, node:url (parsing only), node:util,
* node:assert, node:crypto.
*/
const nodeIoBans = [
'node:fs',
'node:fs/promises',
'node:child_process',
'node:http',
'node:https',
'node:net',
'node:dgram',
'node:dns',
'node:os',
'node:tty',
'node:readline',
'node:repl',
'node:stream',
'node:cluster',
'node:worker_threads',
'node:perf_hooks',
].map((name) => ({
name,
message: `Domain + business may not import I/O-bearing node modules β '${name}' belongs in integration/ or ai/.`,
}));
/**
* Build a `no-restricted-imports` entry for a sibling-isolation rule. Each item under
* `<rootGlob>/<sibling>/` may only import from itself (the active sibling) or from any of the
* `allowedSiblings` (e.g. underscore-prefixed sub-namespaces like `_engine` / `_partials`).
*
* The rule lists every OTHER sibling explicitly so the patterns stay minimatch-compatible
* (no extglob negation needed β extglob coverage in ESLint's minimatch varies by version).
*/
const siblingIsolationRule = (
rootGlob: string,
active: string,
allSiblings: readonly string[],
allowedSiblings: readonly string[],
noun: string
): Linter.RuleEntry => {
const forbidden = allSiblings.filter((s) => s !== active && !allowedSiblings.includes(s));
return [
'error',
{
paths: [resultLibBan],
patterns: forbidden.map((sibling) => ({
group: [`${rootGlob}/${sibling}/**`],
message: `Sibling-${noun} import violation: '${active}' may not reach into '${sibling}'. Each ${noun} is independent; share via the _engine/ sub-namespace instead.`,
})),
},
];
};
/**
* Union several `no-restricted-imports` entries into one. ESLint flat config REPLACES a
* same-key rule entry wholesale when a later block matches the same file β options are never
* merged β so a block that narrows a broader glob (a sibling-isolation block inside a layer
* glob) silently wipes the broader block's restrictions for its files, and vice versa. Every
* narrower block therefore composes its own restrictions WITH the broader block's via this
* helper, so whichever entry survives carries the full set regardless of declaration order.
* Duplicate paths/patterns (e.g. `resultLibBan`, present in both inputs) are deduped so one
* violation reports once. The liveness suite in tests/unit/eslint-config.test.ts pins every
* overlap this composes.
*/
const mergeRestrictedImports = (...entries: readonly Linter.RuleEntry[]): Linter.RuleEntry => {
const paths: unknown[] = [];
const patterns: unknown[] = [];
const seen = new Set<string>();
const push = (bucket: unknown[], items: readonly unknown[] | undefined, tag: string): void => {
for (const item of items ?? []) {
const key = `${tag}:${JSON.stringify(item)}`;
if (!seen.has(key)) {
seen.add(key);
bucket.push(item);
}
}
};
for (const entry of entries) {
if (!Array.isArray(entry)) continue;
const options = entry[1] as { readonly paths?: readonly unknown[]; readonly patterns?: readonly unknown[] };
push(paths, options.paths, 'path');
push(patterns, options.patterns, 'pattern');
}
return ['error', { paths, patterns }] as Linter.RuleEntry;
};
/**
* Union several `no-restricted-syntax` entries into one. Same flat-config hazard as
* {@link mergeRestrictedImports}: a later block matching the same file REPLACES the whole rule
* entry, so a narrow block (the port-shape check under integration/ai/, the class ban under
* domain/) silently drops the broad bans (barrels, `fs.appendFile`) unless it composes them back
* in. `no-restricted-syntax` options are a flat selector list rather than a `{ paths, patterns }`
* object, so entries are concatenated and deduped by selector identity. The liveness suite in
* tests/unit/eslint-config.test.ts pins every overlap this composes.
*/
const mergeRestrictedSyntax = (...entries: readonly Linter.RuleEntry[]): Linter.RuleEntry => {
const selectors: unknown[] = [];
const seen = new Set<string>();
for (const entry of entries) {
if (!Array.isArray(entry)) continue;
for (const selector of entry.slice(1)) {
const key = JSON.stringify(selector);
if (seen.has(key)) continue;
seen.add(key);
selectors.push(selector);
}
}
return ['error', ...selectors] as Linter.RuleEntry;
};
const FLOWS = [
'close-sprint',
'create-pr',
'create-sprint',
'detect-scripts',
'detect-skills',
'doctor',
'export-context',
'export-requirements',
'ideate',
'implement',
'readiness',
'plan',
'refine',
'review',
'settings',
'settings-apply-preset',
'settings-set',
'settings-set-provider',
'settings-show',
'add-ticket',
'remove-ticket',
] as const;
const PROMPTS = [
'apply-feedback',
'create-pr',
'detect-scripts',
'detect-skills',
'distill-learnings',
'evaluate',
'evaluate-continuation',
'ideate',
'implement',
'implement-continuation',
'plan',
'readiness',
'refine',
'reproduce',
'select-candidate',
] as const;
const BUSINESS_SIBLINGS = [
'feedback',
'interactive',
'io',
'observability',
'project',
'runs',
'scm',
'settings',
'sprint',
'task',
'ticket',
'version',
] as const;
const REPOSITORY_SIBLINGS = ['project', 'settings', 'sprint', 'task'] as const;
const PROVIDERS = ['claude', 'codex', 'copilot', 'opencode'] as const;
const READINESS_PROVIDERS = ['claude', 'codex', 'copilot', 'opencode'] as const;
/**
* Sibling concretes under integration/ai/skills/. Mixes two roles intentionally:
* - per-tool adapter directories (`claude`, `codex`, `copilot`) implementing `SkillsAdapter`
* - skill-source directories (`bundled`, `project`) implementing `SkillSource`
* Both kinds belong to the same `skills/` concept and share `_engine/` for contracts and helpers.
* Cross-sibling reach goes through `skills/_engine/`; the composition switch over the per-tool
* adapters lives at `skills/adapter-factory.ts`, which is not itself a sibling.
*/
const SKILLS = ['bundled', 'claude', 'codex', 'copilot', 'opencode', 'operator', 'phase', 'project'] as const;
/**
* Sibling concretes under integration/ai/agents/ β the portable agent-definitions subsystem.
* Same shape as SKILLS: per-tool adapter directories (`claude`, `codex`, `copilot`) implement
* `AgentDefinitionAdapter`; `bundled` and `operator` are definition-source directories. Cross-
* sibling reach goes through `agents/_engine/`.
*/
const AGENTS = ['bundled', 'claude', 'codex', 'copilot', 'opencode', 'operator'] as const;
/**
* Concept namespaces under src/integration/ai/. A concept exposes itself to the rest of the tree
* through its own `_engine/` sub-namespace; its concrete sibling directories are private to it.
*/
const AI_CONCEPTS = [
'agents',
'contract',
'evaluation',
'prompts',
'providers',
'readiness',
'runs',
'skills',
] as const;
/**
* The concrete sibling directories each AI concept owns. Concepts absent from this map (`contract`,
* `evaluation`, `runs`) have no per-tool/per-variant siblings β nothing to fence.
*/
const AI_CONCEPT_SIBLINGS: Partial<Record<(typeof AI_CONCEPTS)[number], readonly string[]>> = {
agents: AGENTS,
prompts: PROMPTS,
providers: PROVIDERS,
readiness: READINESS_PROVIDERS,
skills: SKILLS,
};
/**
* Cross-concept isolation for one AI concept: files under `integration/ai/<active>/` may not reach
* into any OTHER concept's concrete siblings. Cross-concept access goes through the target
* concept's `_engine/` sub-namespace (e.g. a prompt definition importing an evaluation contract).
*/
const crossConceptRule = (active: string): Linter.RuleEntry => [
'error',
{
paths: [],
patterns: Object.entries(AI_CONCEPT_SIBLINGS)
.filter(([concept]) => concept !== active)
.map(([concept, siblings]) => ({
group: (siblings ?? []).map((sibling) => `**/integration/ai/${concept}/${sibling}/**`),
message: `Cross-concept import violation: '${active}' may not reach into a concrete '${concept}' sibling. Import from integration/ai/${concept}/_engine/ instead β a concept's siblings are private to it.`,
})),
},
];
/**
* Domain layer rule. Pure entities + value objects + errors + Result + observability interfaces.
* May import nothing outside src/domain/. May not import I/O-bearing node modules β domain is
* the purest layer. Pure node modules (node:path, node:url, ...) remain allowed.
*/
const domainLayerRule: Linter.RuleEntry = [
'error',
{
paths: [resultLibBan, ...nodeIoBans],
patterns: ['business', 'ai', 'integration', 'application'].map((layer) => ({
group: [`**/${layer}/**`],
message: `Layer dependency violation: domain must not import from '${layer}'.`,
})),
},
];
/**
* Business layer rule. Bans I/O-bearing node modules and upper layers. May import from domain,
* business (itself), and ai. The chain framework lives in application/, so business is
* structurally prevented from depending on chains, leaves, or flow composition.
*
* Also bans composite `*Repository` imports β business use cases depend on the slim sub-ports
* (`FindById`, `Save`, `Remove`, etc.) from `domain/repository/_base/` so each use case is
* legible from its dependencies, and persistence adapters can implement narrower interfaces.
*/
const businessLayerRule: Linter.RuleEntry = [
'error',
{
paths: [resultLibBan, ...nodeIoBans],
patterns: [
...['integration', 'application'].map((layer) => ({
group: [`**/${layer}/**`],
message: `Layer dependency violation: cannot import from '${layer}'.`,
})),
{
group: ['**/domain/repository/*/!(_base)*-repository*', '**/domain/repository/*/*-repository*'],
importNames: [
'ProjectRepository',
'SprintRepository',
'SprintExecutionRepository',
'TaskRepository',
'SettingsRepository',
],
message:
'Business use cases must depend on the slim sub-ports under domain/repository/_base/ (FindById, Save, Remove, ...) β not on composite `*Repository` interfaces. Composition root in application/bootstrap wires the composite to the use case as a slim port.',
},
],
},
];
/**
* Sub-rule for application/flows/** β chain compositions (regular flows and _shared Element
* factories). May depend freely on domain, business, ai (port level), and the
* chain framework, but NOT on concrete provider / readiness-probe / skill-adapter impls β those
* are picked by the composition root. Chain compositions speak only port-level vocabulary so
* the provider can be swapped without changing flow code.
*/
const chainsBasePatterns = [
{ group: ['**/application/ui/**'], message: 'Chains may not import from UI.' },
{ group: ['**/application/bootstrap/**'], message: 'Chains may not import from bootstrap.' },
{
group: PROVIDERS.map((p) => `**/integration/ai/providers/${p}/**`),
message:
'Chains may not import concrete provider adapters β depend on integration/ai/providers/_engine/ port instead. The composition root (application/bootstrap/provider-factory.ts) picks the concrete provider from settings.',
},
{
group: READINESS_PROVIDERS.map((p) => `**/integration/ai/readiness/${p}/**`),
message:
'Chains may not import concrete readiness probes β depend on integration/ai/readiness/_engine/ port instead. The composition root (application/bootstrap/wire.ts) wires the concrete probes.',
},
{
group: [...SKILLS.map((s) => `**/integration/ai/skills/${s}/**`), '**/integration/ai/skills/adapter-factory.ts'],
message:
'Chains may not import concrete skill adapters / sources β depend on integration/ai/skills/_engine/ ports instead. The composition root and the UI launch path (application/ui/shared/launcher.ts) select the concrete skills adapter.',
},
{
group: [...AGENTS.map((a) => `**/integration/ai/agents/${a}/**`), '**/integration/ai/agents/adapter-factory.ts'],
message:
'Chains may not import concrete agent-definition adapters / sources β depend on integration/ai/agents/_engine/ ports instead. The composition root and the UI launch path (application/ui/shared/launch/implement-agent-bindings.ts) select the concrete agent adapter.',
},
];
/**
* Per-signal Zod schemas are private to the contract engine, with ONE sanctioned exception:
* per-leaf `*.contract.ts` files, which the signal contract makes the single composition
* point declaring which signals a leaf consumes. The contract-file config blocks below use
* `chainsContractFileRule` (this pattern omitted); everything else under flows/ gets
* `chainsLayerRule` (this pattern included).
*/
const chainsSignalSchemaBan = {
group: ['**/integration/ai/contract/_engine/signals/**'],
message:
'Chains may not import per-signal Zod schemas directly β go through the leaf contract (validateSignalsFile / renderSidecars / renderContractSection) under integration/ai/contract/_engine/. Per-signal schemas are private to the contract engine; a per-leaf *.contract.ts file is the one sanctioned import point.',
};
const chainsLayerRule: Linter.RuleEntry = [
'error',
{
paths: [resultLibBan],
patterns: [...chainsBasePatterns, chainsSignalSchemaBan],
},
];
/** The chains rule for per-leaf `*.contract.ts` files β everything except the schema ban. */
const chainsContractFileRule: Linter.RuleEntry = [
'error',
{
paths: [resultLibBan],
patterns: chainsBasePatterns,
},
];
/**
* Sub-rule for application/chain/** β the chain framework kernel (`element` / `leaf` / `sequential`
* / `loop` / `guard`, the runner, the wave scheduler). It is the generic execution machinery every
* flow composes over, so it stays ignorant of what is being executed: no integration adapters, no
* business use cases, and none of the outer application surfaces (UI, composition root, flows) that
* consume it. Domain types (`Result`, `DomainError`, the fatal-error predicate) are its whole
* vocabulary.
*/
const chainKernelRule: Linter.RuleEntry = mergeRestrictedImports(restrictImports(['business', 'integration']), [
'error',
{
paths: [resultLibBan],
patterns: [
{ group: ['**/application/ui/**'], message: 'The chain framework may not import from UI.' },
{
group: ['**/application/bootstrap/**'],
message: 'The chain framework may not import from the composition root.',
},
{
group: ['**/application/flows/**'],
message:
'The chain framework may not import from a flow β flows compose over the kernel, never the other way around.',
},
],
},
]);
/**
* Ban direct `fs.appendFile` / `fs.promises.appendFile` calls outside `integration/io/`. The
* harness routes every append-stream write through the `AppendFile` port; a
* stray `fs.appendFile` would silently bypass the atomicity + structured-error guarantees
* the port adds. Matches both `fs.appendFile(...)` and `fs.promises.appendFile(...)` shapes.
*/
const noFsAppendFile: Linter.RuleEntry = [
'error',
{
selector:
"CallExpression[callee.type='MemberExpression'][callee.property.name='appendFile'][callee.object.name='fs']",
message: 'fs.appendFile is banned outside integration/io/ β go through the AppendFile port instead.',
},
{
selector:
"CallExpression[callee.type='MemberExpression'][callee.property.name='appendFile'][callee.object.type='MemberExpression'][callee.object.property.name='promises']",
message: 'fs.promises.appendFile is banned outside integration/io/ β go through the AppendFile port instead.',
},
];
/** Disallow `class` declarations across the domain + business layers. Errors under src/domain/value/error/ are exempt. */
const noClassInDomainOrBusiness: Linter.RuleEntry = [
'error',
{
selector: 'ClassDeclaration',
message:
'Domain + business types must be modeled as `interface` + standalone functions, not classes. Errors live under src/domain/value/error/.',
},
];
/**
* No barrel exports anywhere under src/. Every importer names what it pulls in directly so
* "where does symbol X come from" is one click away β no chasing re-export chains.
*/
const noBarrels: Linter.RuleEntry = [
'error',
{
selector: 'ExportAllDeclaration',
message: 'No barrel exports β every import must name what it pulls in directly.',
},
];
/**
* The syntax bans that hold across the whole of src/ (outside `integration/io/`, which owns the
* append primitive). Every narrower `no-restricted-syntax` block composes over this β flat config
* replaces a same-key entry wholesale, so a block that only declared its own selectors would
* silently un-ban barrels and `fs.appendFile` for the files it matches.
*/
const baseSyntaxRule: Linter.RuleEntry = mergeRestrictedSyntax(noBarrels, noFsAppendFile);
/**
* Port-shaped names (`*Port`, `*Adapter`, `*Provider`, `*Sink`, `*Loader`, `*Probe`, `*Reader`,
* `*Writer`, `*Renderer`, `*Detector`, `*Contract`) define cross-tool contracts, so they belong in
* the concept's `_engine/` sub-namespace β concrete siblings then depend on a contract rather than
* on each other. Factory-input shapes named `*Deps` don't match the pattern and are unaffected.
*/
const portShapesLiveInEngine: Linter.RuleEntry = [
'error',
{
selector:
'TSInterfaceDeclaration[id.name=/(Port|Adapter|Provider|Sink|Loader|Probe|Reader|Writer|Renderer|Detector|Contract)$/]',
message:
'Port-shaped interfaces must live under integration/ai/<concept>/_engine/. Either move this declaration or rename it (e.g. `*Deps` for factory inputs).',
},
{
selector:
'TSTypeAliasDeclaration[id.name=/(Port|Adapter|Provider|Sink|Loader|Probe|Reader|Writer|Renderer|Detector|Contract)$/]',
message:
'Port-shaped type aliases must live under integration/ai/<concept>/_engine/. Either move this declaration or rename it.',
},
];
/** `*Output` types are the success-side data shape, never the `Result` envelope itself. */
const outputIsNotAResultEnvelope: Linter.RuleEntry = [
'error',
{
selector: "TSTypeAliasDeclaration[id.name=/Output$/] > TSTypeReference[typeName.name='Result']",
message:
'*Output types must be the success-side data shape, not the Result envelope. Put `Result<FooOutput, ErrorUnion>` in the function signature instead.',
},
];
/**
* `src/integration/ai/signals/` is a reserved path β the contract pipeline that replaced the
* removed XML-tag parser lives at `src/integration/ai/contract/`. Any file added under the old
* path errors on sight so the deleted design can't be resurrected by accident.
*/
const reservedSignalsPath: Linter.RuleEntry = [
'error',
{
selector: 'Program',
message:
'src/integration/ai/signals/ is reserved β the signal contract pipeline lives at src/integration/ai/contract/. Add new signal kinds as Zod schemas under src/integration/ai/contract/_engine/signals/<kind>/schema.ts instead.',
},
];
export default [
{
ignores: ['dist/**', 'node_modules/**', '.claude/worktrees/**'],
},
js.configs.recommended,
...tseslint.configs.recommended,
{
languageOptions: {
globals: { ...globals.node },
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
},
},
// ββ memory-leak + correctness hygiene plugins βββββββββββββββββββββββββββββββββ
// `react-hooks/rules-of-hooks` is the plugin that surfaced the conditional-Hook bug
// in execute-view.tsx (suspected root of the recurring 8h OOM). `exhaustive-deps`
// catches stale closures that retain references across re-renders. The sonarjs
// subset is a cheap collection-correctness net for the same class of slow leaks.
//
// react-hooks's exported Plugin type doesn't align with `Linter.Config['plugins']`
// under `exactOptionalPropertyTypes`, so we cast once at the boundary β the rules
// themselves are still type-checked through ESLint's runtime config validator.
{
files: ['src/**/*.{ts,tsx}'],
plugins: {
'react-hooks': reactHooks as unknown as ESLint.Plugin,
sonarjs: sonarjs as unknown as ESLint.Plugin,
},
rules: {
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
'sonarjs/no-unused-collection': 'warn',
'sonarjs/no-ignored-return': 'warn',
'sonarjs/no-element-overwrite': 'warn',
'sonarjs/no-identical-conditions': 'warn',
'sonarjs/no-collection-size-mischeck': 'warn',
// ββ SonarQube-style maintainability rules (warn-only, calibrated) βββββ
// These surface long-running drift without blocking. The B-group TUI splits
// will mop up the bulk of the warnings; they're intentionally not errors so
// refactor work can land incrementally.
'sonarjs/cognitive-complexity': ['warn', 15],
'sonarjs/no-duplicate-string': 'warn',
'sonarjs/no-identical-functions': 'warn',
'sonarjs/no-collapsible-if': 'warn',
'sonarjs/no-redundant-jump': 'warn',
'sonarjs/prefer-immediate-return': 'warn',
},
},
// ββ core ESLint size + complexity rules (warn-only) ββββββββββββββββββββββββββ
// Calibrated thresholds: complexity 15 (matches sonarjs/cognitive-complexity);
// max-lines-per-function 80; max-lines 400 per file. Tests are exempted from
// size limits because table-driven specs and integration scaffolding routinely
// exceed both budgets without indicating production-code drift.
{
files: ['src/**/*.{ts,tsx}'],
rules: {
complexity: ['warn', 15],
'max-lines-per-function': ['warn', { max: 80, skipBlankLines: true, skipComments: true, IIFEs: true }],
'max-lines': ['warn', { max: 400, skipBlankLines: true, skipComments: true }],
},
},
// ββ maintainability hints (Sonar-style) ββββββββββββββββββββββββββββββββββββββ
// Cheap, type-info-free rules that catch the kind of drift a reviewer would catch.
// Typed rules (no-floating-promises, no-misused-promises, no-non-null-assertion) are
// deferred until parserOptions.project is wired β they require typed linting.
{
files: ['src/**/*.{ts,tsx}', 'tests/**/*.{ts,tsx}'],
rules: {
eqeqeq: ['error', 'always'],
'no-else-return': ['error', { allowElseIf: false }],
'no-useless-return': 'error',
'no-shadow': 'error',
'@typescript-eslint/consistent-type-imports': [
'error',
{ prefer: 'type-imports', fixStyle: 'inline-type-imports', disallowTypeAnnotations: true },
],
'@typescript-eslint/array-type': ['error', { default: 'array-simple', readonly: 'array-simple' }],
},
},
// ββ no barrel exports anywhere under src/ ββββββββββββββββββββββββββββββββββββ
{
files: ['src/**/*.{ts,tsx}'],
rules: {
'no-restricted-syntax': noBarrels,
},
},
// ββ fs.appendFile is fenced to integration/io/ ββββββββββββββββββββββββββββββ
// The harness routes every append-stream write through the `AppendFile` port. A stray
// `fs.appendFile` outside `integration/io/` silently bypasses the port's structured-error
// guarantees.
{
files: ['src/**/*.{ts,tsx}'],
ignores: ['src/integration/io/**'],
rules: {
'no-restricted-syntax': baseSyntaxRule,
},
},
// ββ domain βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// Purest layer: entities, value objects, errors, Result, observability interfaces. Imports
// nothing outside src/domain/ and may not pull in I/O-bearing node modules.
{
files: ['src/domain/**/*.{ts,tsx}'],
rules: {
'no-restricted-imports': domainLayerRule,
'no-restricted-syntax': mergeRestrictedSyntax(baseSyntaxRule, noClassInDomainOrBusiness),
},
},
// ββ integration/ai/** β port declarations must live in _engine/ ββββββββββββββ
// See `portShapesLiveInEngine` for the rationale. Composed over `baseSyntaxRule` so the barrel
// and `fs.appendFile` bans keep firing under integration/ai/ β a bare selector list here would
// replace them for every file this block matches.
{
files: ['src/integration/ai/**/*.{ts,tsx}'],
ignores: ['src/integration/ai/**/_engine/**', 'src/integration/ai/**/_partials/**'],
rules: {
'no-restricted-syntax': mergeRestrictedSyntax(baseSyntaxRule, portShapesLiveInEngine),
},
},
// ββ business βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// Use cases + ports/repositories + business helpers (feedback parser, interactive prompt,
// event bus, scm + version port shapes). May depend on domain + business only. No I/O-bearing
// node modules. No imports from integration or application β integration concerns reach
// business via function-shape deps that the composition root wires up. Entities live in
// src/domain/entity/.
{
files: ['src/business/**/*.{ts,tsx}'],
rules: {
'no-restricted-imports': businessLayerRule,
'no-restricted-syntax': mergeRestrictedSyntax(
baseSyntaxRule,
noClassInDomainOrBusiness,
outputIsNotAResultEnvelope
),
},
},
// ββ src/business/<x>/ β sibling-business isolation βββββββββββββββββββββββββββ
// Each business sub-domain is independent. `observability/` is the universal
// cross-cutting target β Logger and the event bus are infra-shaped ports every
// sibling consumes β so it is on the allow-list. Future shared abstractions
// should live under `_engine/` or `_shared/`.
...BUSINESS_SIBLINGS.map((active): Linter.Config => ({
files: [`src/business/${active}/**/*.{ts,tsx}`],
rules: {
// Composed over the layer rule β this block wins over the src/business/** block above
// (same key, later declaration), so it must carry the layer bans too.
'no-restricted-imports': mergeRestrictedImports(
businessLayerRule,
siblingIsolationRule(
'**/business',
active,
BUSINESS_SIBLINGS,
['_engine', '_shared', 'observability'],
'business module'
)
),
},
})),
// ββ src/domain/repository/<x>/ β sibling-repository isolation ββββββββββββββββ
// Each repository contract is per-aggregate. Shared abstractions live under `_base/`.
...REPOSITORY_SIBLINGS.map((active): Linter.Config => ({
files: [`src/domain/repository/${active}/**/*.{ts,tsx}`],
rules: {
// Composed over the domain layer rule β same-key replacement, see mergeRestrictedImports.
'no-restricted-imports': mergeRestrictedImports(
domainLayerRule,
siblingIsolationRule('**/domain/repository', active, REPOSITORY_SIBLINGS, ['_base'], 'repository module')
),
},
})),
// ββ integration ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// Concrete impls of business / ai ports + low-level I/O / shell wrappers. May depend on
// domain + business + ai. The progress-file sink, for instance, implements
// `Sink<HarnessSignal>` β it consumes a type from ai/signals/.
{
files: ['src/integration/**/*.{ts,tsx}'],
rules: {
'no-restricted-imports': integrationLayerRule,
},
},
// ββ integration β node:child_process spawn/exec fence βββββββββββββββββββββββ
// Overrides the block above (same glob, declared later) to additionally ban raw spawn/exec
// imports everywhere under integration/ EXCEPT the two named exceptions, which keep the base
// layer-direction check only. See `childProcessSpawnBan` for the full rationale.
{
files: ['src/integration/**/*.{ts,tsx}'],
ignores: [
'src/integration/io/shell-script-runner.ts',
'src/integration/observability/os-notification-dispatcher.ts',
],
rules: {
'no-restricted-imports': integrationSpawnFencedRule,
},
},
// ββ integration/ai/<concept>/ β cross-concept isolation ββββββββββββββββββββββ
// A concept talks to another concept through that concept's `_engine/` sub-namespace, never to
// its concrete siblings. Declared after the two src/integration/** blocks so it wins for files
// under a concept, and composed over the integration base so layer direction + the spawn fence
// keep firing. The per-sibling blocks below compose this back in for the same reason.
...AI_CONCEPTS.map((concept): Linter.Config => ({
files: [`src/integration/ai/${concept}/**/*.{ts,tsx}`],
rules: {
'no-restricted-imports': mergeRestrictedImports(integrationSpawnFencedRule, crossConceptRule(concept)),
},
})),
// ββ integration/ai/<concept>/<x>/ β sibling isolation ββββββββββββββββββββββββ
// Declared AFTER the blocks above: flat config replaces a same-key rule entry per file (last
// matching block wins), so these must win for sibling files β and each entry composes the
// integration base and the cross-concept fence back in via `mergeRestrictedImports` so every
// broader restriction keeps firing inside sibling directories.
// Each prompt is independent. Shared machinery lives under prompts/_engine/.
...PROMPTS.map((active): Linter.Config => ({
files: [`src/integration/ai/prompts/${active}/**/*.{ts,tsx}`],
rules: {
'no-restricted-imports': mergeRestrictedImports(
integrationSpawnFencedRule,
crossConceptRule('prompts'),
siblingIsolationRule('**/integration/ai/prompts', active, PROMPTS, ['_engine', '_partials'], 'prompt')
),
},
})),
// Each tool adapter is independent. Cross-tool sharing goes through providers/_engine/.
...PROVIDERS.map((active): Linter.Config => ({
files: [`src/integration/ai/providers/${active}/**/*.{ts,tsx}`],
rules: {
'no-restricted-imports': mergeRestrictedImports(
integrationSpawnFencedRule,
crossConceptRule('providers'),
siblingIsolationRule('**/integration/ai/providers', active, PROVIDERS, ['_engine'], 'provider')
),
},
})),
// Each per-tool readiness probe is independent. Cross-tool sharing goes through readiness/_engine/.
...READINESS_PROVIDERS.map((active): Linter.Config => ({
files: [`src/integration/ai/readiness/${active}/**/*.{ts,tsx}`],
rules: {
'no-restricted-imports': mergeRestrictedImports(
integrationSpawnFencedRule,
crossConceptRule('readiness'),
siblingIsolationRule('**/integration/ai/readiness', active, READINESS_PROVIDERS, ['_engine'], 'readiness probe')
),
},
})),
// Per-tool adapter directories (claude/codex/copilot) and skill-source directories
// (bundled/project) are all independent siblings. Cross-sibling sharing goes through
// skills/_engine/. The composition switch over the per-tool adapters lives at
// skills/adapter-factory.ts (directly under skills/, outside the sibling glob).
...SKILLS.map((active): Linter.Config => ({
files: [`src/integration/ai/skills/${active}/**/*.{ts,tsx}`],
rules: {
'no-restricted-imports': mergeRestrictedImports(
integrationSpawnFencedRule,
crossConceptRule('skills'),
siblingIsolationRule('**/integration/ai/skills', active, SKILLS, ['_engine'], 'skill')
),
},
})),
// Per-tool adapter directories (claude/codex/copilot) and definition-source directories
// (bundled/operator) are all independent siblings. Cross-sibling sharing goes through
// agents/_engine/. The composition switch over the per-tool adapters lives at
// agents/adapter-factory.ts (directly under agents/, outside the sibling glob).
...AGENTS.map((active): Linter.Config => ({
files: [`src/integration/ai/agents/${active}/**/*.{ts,tsx}`],
rules: {
'no-restricted-imports': mergeRestrictedImports(
integrationSpawnFencedRule,
crossConceptRule('agents'),
siblingIsolationRule('**/integration/ai/agents', active, AGENTS, ['_engine'], 'agent definition')
),
},
})),
// ββ application ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// Composition root + chain framework + flow compositions + UI runtime. May depend on
// everything else. Only the Result re-export rule applies broadly.
{
files: ['src/application/**/*.{ts,tsx}'],
rules: {
'no-restricted-imports': ['error', { paths: [resultLibBan], patterns: [] }],
},
},
// ββ application/chain/** β the chain framework kernel βββββββββββββββββββββββ
// Generic execution machinery (element / leaf / sequential / loop / guard, the runner, the wave
// scheduler). Speaks domain vocabulary only β no business use cases, no integration adapters,
// and none of the outer application surfaces that compose over it. See `chainKernelRule`.
{
files: ['src/application/chain/**/*.{ts,tsx}'],
rules: {
'no-restricted-imports': chainKernelRule,
},
},
// ββ application/flows/** β chain compositions βββββββββββββββββββββββββββββββ
// Flows + _shared Element factories. May freely use domain, business,
// integration (port-level), and the chain framework β but NOT concrete provider / probe / skill /
// agent adapters under integration/ai/. The composition root and the UI launch path select those.
{
files: ['src/application/flows/**/*.{ts,tsx}'],
rules: {
'no-restricted-imports': chainsLayerRule,
},
},
// ββ application/flows/**/*.contract.ts β per-leaf signal contracts ββββββββββ
// The one sanctioned composition point for per-signal Zod schemas: the schema ban is
// lifted here (and only here); every other chains restriction still applies.
{
files: ['src/application/flows/**/*.contract.ts'],
rules: {
'no-restricted-imports': chainsContractFileRule,
},
},
// ββ application/flows/<x>/ β sibling-flow isolation ββββββββββββββββββββββββββ
// Two blocks per flow: the second re-lifts the schema ban for that flow's *.contract.ts
// files (same-key replacement would otherwise re-impose it via the first block).
...FLOWS.flatMap((active): Linter.Config[] => [
{
files: [`src/application/flows/${active}/**/*.{ts,tsx}`],
rules: {
// Composed over the chains rule β same-key replacement, see mergeRestrictedImports.
'no-restricted-imports': mergeRestrictedImports(
chainsLayerRule,
siblingIsolationRule('**/application/flows', active, FLOWS, [], 'flow')
),
},
},
{
files: [`src/application/flows/${active}/**/*.contract.ts`],
rules: {
'no-restricted-imports': mergeRestrictedImports(
chainsContractFileRule,
siblingIsolationRule('**/application/flows', active, FLOWS, [], 'flow')
),
},
},
]),
// ββ tests ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// Tests wire every layer together β only the typescript-result rule applies.
{
files: ['tests/**/*.{ts,tsx}'],
rules: {
'no-restricted-imports': ['error', { paths: [resultLibBan], patterns: [] }],
'no-restricted-syntax': 'off',
},
},
// The Result re-export point is the only file allowed to import typescript-result directly.
{
files: ['src/domain/result.ts'],
rules: {
'no-restricted-imports': 'off',
},
},
// Domain errors extend the domain Error class β class declarations are intentional here, and
// only the class ban is lifted: the barrel + `fs.appendFile` bans still apply.
{
files: ['src/domain/value/error/**/*.{ts,tsx}'],
rules: {
'no-restricted-syntax': baseSyntaxRule,
},
},
// ββ Reserved path: src/integration/ai/signals/ is gone (replaced by ai/contract/_engine/).
// To re-introduce the path, remove this entry deliberately. See `reservedSignalsPath`.
{
files: ['src/integration/ai/signals/**/*.{ts,tsx}'],
rules: {
'no-restricted-syntax': mergeRestrictedSyntax(baseSyntaxRule, reservedSignalsPath),
},
},
] satisfies Linter.Config[];